SlideShare ist ein Scribd-Unternehmen logo
1 von 49
Downloaden Sie, um offline zu lesen
How to Debug
Anything
@jamesgolick
well ok, not anything, but most stuff on
unixy operating systems that have
the tooling i’m going to talk
about today
https://packagecloud.io
“better than google”
- PC Weekly
Everything is
Terrible
Everything is
Broken
“Correct Code”™
“If you want to deploy high
quality software that performs,
you should expect to fix bugs at
every level.”
- me
“I don’t understand
how this is possible.”
- every programmer ever
0. php
a blind debugging session
the website is down
what we have to work with
• The source code. (nope)
• Knowledge of the system. (nope)
• Familiarity with the programming language.
(nope)
• SSH Access. (yup)
logging in the real world
(often useless)
#cool
find a pid
sudo strace -ff -s 2048 -p 22935
write(1, "hin", 3) = 3
function name arguments return value
how to read strace output
man 2 write
learn more about your favorite system calls
{sa_family=AF_INET, sin_port=htons(50318), sin_addr=inet_addr("192.168.212.2")}, [16]) = 12	
fcntl(12, F_GETFD) = 0	
fcntl(12, F_SETFD, FD_CLOEXEC) = 0	
getsockname(12, {sa_family=AF_INET, sin_port=htons(80), sin_addr=inet_addr("192.168.212.182")}, [16]) = 0	
fcntl(12, F_GETFL) = 0x2 (flags O_RDWR)	
fcntl(12, F_SETFL, O_RDWR|O_NONBLOCK) = 0	
read(12, "GET / HTTP/1.1rnHost: localhost:8181rnConnection: keep-alivernCache-Control: max-age=0rnAccept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8rnUser-Agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36rnAccept-Encoding: gzip,deflate,sdchrnAccept-Language: en-US,en;q=0.8rnCookie:
_jsuid=3899596137;
_packages_session=d2NrM3RZMUJXRE8zcFB0aXNGVk83Ny9lRDR3Y09uSVNoRUcrREV0VnF2UjFxRjk1NjAyUzZ5ZG81M1JyczRzUU10ZTBqMXI5QkJXZzFqZnM1RUNmdEdGYmN2eG92SUsvU24wOWhJSlhNZzYrQXdYN2tMYnRZaEhWN3ArbEpiZVpMUWNjWHNRWHc2VjkwQzZ2S
0Y4aGlLeks3MmhoTXBXN2NRWUEwbGFFekpENHdveCtTNXl1MllDUTFzUzZMSU5WZlRqUlQ1aXB2bWVsZDVGVFE1Tlp0UT09LS1vYWdoMk9mZHUvS3U5OWpoME1ZY3pBPT0%3D--8e4ac5c1aebe1e9226063c3d2b83b4176535377arnrn", 8000) = 792	
stat("/var/www/", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0	
stat("/var/www/index.php", {st_mode=S_IFREG|0664, st_size=447, ...}) = 0	
setitimer(ITIMER_PROF, {it_interval={0, 0}, it_value={60, 0}}, NULL) = 0	
rt_sigaction(SIGPROF, {0x7f8a898930c0, [PROF], SA_RESTORER|SA_RESTART, 0x7f8a8c6d14a0}, {0x7f8a898930c0, [PROF], SA_RESTORER|SA_RESTART, 0x7f8a8c6d14a0}, 8) = 0	
rt_sigprocmask(SIG_UNBLOCK, [PROF], NULL, 8) = 0	
umask(077) = 022	
umask(022) = 077	
getcwd("/", 4095) = 2	
chdir("/var/www") = 0	
setitimer(ITIMER_PROF, {it_interval={0, 0}, it_value={30, 0}}, NULL) = 0	
lstat("/var/www/index.php", {st_mode=S_IFREG|0664, st_size=447, ...}) = 0	
open("/var/www/index.php", O_RDONLY) = 13	
fstat(13, {st_mode=S_IFREG|0664, st_size=447, ...}) = 0	
fstat(13, {st_mode=S_IFREG|0664, st_size=447, ...}) = 0	
fstat(13, {st_mode=S_IFREG|0664, st_size=447, ...}) = 0	
fstat(13, {st_mode=S_IFREG|0664, st_size=447, ...}) = 0	
mmap(NULL, 447, PROT_READ, MAP_SHARED, 13, 0) = 0x7f8a8d34f000	
munmap(0x7f8a8d34f000, 447) = 0	
close(13) = 0	
getcwd("/var/www", 4096) = 9	
lstat("/var/www/./oh-fuck.php", 0x7fff11342620) = -1 ENOENT (No such file or directory)	
lstat("/usr/share/php/oh-fuck.php", 0x7fff11342620) = -1 ENOENT (No such file or directory)	
lstat("/usr/share/pear/oh-fuck.php", 0x7fff11342620) = -1 ENOENT (No such file or directory)	
lstat("/var/www/oh-fuck.php", 0x7fff11342620) = -1 ENOENT (No such file or directory)	
getcwd("/var/www", 4096) = 9	
lstat("/var/www/./oh-fuck.php", 0x7fff11342580) = -1 ENOENT (No such file or directory)	
lstat("/usr/share/php/oh-fuck.php", 0x7fff11342580) = -1 ENOENT (No such file or directory)	
lstat("/usr/share/pear/oh-fuck.php", 0x7fff11342580) = -1 ENOENT (No such file or directory)	
lstat("/var/www/oh-fuck.php", 0x7fff11342580) = -1 ENOENT (No such file or directory)	
getcwd("/var/www", 4096) = 9	
lstat("/var/www/oh-fuck.php", 0x7fff113446e0) = -1 ENOENT (No such file or directory)	
open("/var/www/oh-fuck.php", O_RDONLY) = -1 ENOENT (No such file or directory)	
chdir("/") = 0	
umask(022) = 022	
open("/dev/urandom", O_RDONLY) = 13	
read(13, "33260300377gK222d", 8) = 8	
close(13) = 0	
open("/dev/urandom", O_RDONLY) = 13	
read(13, "427417x3516336260", 8) = 8	
close(13) = 0	
open("/dev/urandom", O_RDONLY) = 13	
read(13, "&M330225-P340345", 8) = 8	
close(13) = 0	
setitimer(ITIMER_PROF, {it_interval={0, 0}, it_value={0, 0}}, NULL) = 0	
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f8a8d34e000	
writev(12, [{"HTTP/1.0 500 Internal Server ErrorrnDate: Sat, 14 Jun 2014 17:40:32 GMTrnServer: Apache/2.2.22 (Ubuntu)rnX-Powered-By: PHP/5.3.10-1ubuntu3.11rnVary: Accept-EncodingrnContent-Encoding:
gziprnContent-Length: 20rnConnection: closernContent-Type: text/htmlrnrn", 256}, {"37213100000003", 10}, {"30", 2}, {"00000000", 8}], 4) = 276	
write(7, "192.168.212.2 - - [14/Jun/2014:17:40:32 +0000] "GET / HTTP/1.1" 500 276 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/
537.36"n", 199) = 199	
times({tms_utime=6, tms_stime=56, tms_cutime=0, tms_cstime=0}) = 1718165756	
shutdown(12, 1 /* send */) = 0	
poll([{fd=12, events=POLLIN}], 1, 2000) = 1 ([{fd=12, revents=POLLIN|POLLHUP}])	
read(12, "", 512) = 0	
close(12) = 0	
read(4, 0x7fff113490cf, 1) = -1 EAGAIN (Resource temporarily unavailable)	
ETOOMUCHOUTPUT
writev(12, [{"HTTP/1.0 500 Internal
Server Err"..., 256},
{"37213100000003", 10},
{"30", 2}, {"00000000",
8}], 4) = 276
find failure
always work backwards
open("/var/www/db.in.php", O_RDONLY)	
=	
-1 ENOENT (No such file or directory)
find the cause
hopefully.
open("/var/www/index.php", O_RDONLY)	
=	
13
find the offender
prove your hypothesis
find the offender
fix the bug!
#cool
“I don’t understand
how this is possible.”
- every programmer ever
0. Forget everything you think you know.
1. Get a third party opinion.
third parties
i have known and loved
source: http://www.brendangregg.com/linuxperf.html
1. apt
building a cloud for packages is hard
sudo apt-get update
sudo strace -ff apt-get update
write(1, "Ign http://
192.168.212.136:3000 trusty
Releasen", 62) = 62
find failure
always work backwards
read(6, "400 URI FailurenURI:
https://packagecloud-repositories-
dev2.s3.amazonaws.com/1/1/ubuntu/
dists/trusty/Release?
AWSAccessKeyId=AKIAILW54TIPGLUGWOYA&Si
gnature=s/c0fzVQhxpBPbpyTIzCxAfo/
8g=&Expires=1402837136nMessage: Bad
header line nn", 64000) = 230
find the cause
confirm your hypothesis
#cool
apt-get source apt
read(6, "400 URI FailurenURI: https://
packagecloud-repositories-
dev2.s3.amazonaws.com/1/1/ubuntu/dists/
trusty/Release?
AWSAccessKeyId=AKIAILW54TIPGLUGWOYA&Sig
nature=s/c0fzVQhxpBPbpyTIzCxAfo/
8g=&Expires=1402837136nMessage: Bad
header line nn", 64000) = 230
locate a hook
locate a hook
stare at the code
confirm your hypothesis
> Content-Type:
> Content-Type: text/
plain
#cool
2. Locate the correct source code.
3. Identify a hard-coded string to grep for.
4. Stare at the code until it makes sense.
5. Fix whatever is broken.
How to Debug Anything
!
!
0. Forget everything you think you know.
1. Get a third party opinion.
2. Locate the correct source code.
3. Identify a hard-coded string to grep for.
4. Stare at the code until it makes sense.
5. Fix whatever is broken.
Questions?
@jamesgolick
https://packagecloud.io

Weitere ähnliche Inhalte

Andere mochten auch

Debugging PHP With Xdebug
Debugging PHP With XdebugDebugging PHP With Xdebug
Debugging PHP With XdebugMark Niebergall
 
Defining Data Protection in the Cloud 디지탈링스
Defining Data Protection in the Cloud 디지탈링스Defining Data Protection in the Cloud 디지탈링스
Defining Data Protection in the Cloud 디지탈링스FaclconStorKR
 
Effective debugging
Effective debuggingEffective debugging
Effective debuggingAndy Dawson
 
Advanced debugging techniques (PHP)
Advanced debugging techniques (PHP)Advanced debugging techniques (PHP)
Advanced debugging techniques (PHP)Patrick Allaert
 
Leadership Styles Your Team Needs
Leadership Styles Your Team NeedsLeadership Styles Your Team Needs
Leadership Styles Your Team NeedsJoshua Howard
 
Startup Metrics for Pirates (KAUST, Nov 2013)
Startup Metrics for Pirates (KAUST, Nov 2013)Startup Metrics for Pirates (KAUST, Nov 2013)
Startup Metrics for Pirates (KAUST, Nov 2013)Dave McClure
 
PHP data structures (and the impact of php 7 on them), phpDay Verona 2015, Italy
PHP data structures (and the impact of php 7 on them), phpDay Verona 2015, ItalyPHP data structures (and the impact of php 7 on them), phpDay Verona 2015, Italy
PHP data structures (and the impact of php 7 on them), phpDay Verona 2015, ItalyPatrick Allaert
 
Doors, Walls and Old Trees: Prioritizing to Get Simple
Doors, Walls and Old Trees: Prioritizing to Get SimpleDoors, Walls and Old Trees: Prioritizing to Get Simple
Doors, Walls and Old Trees: Prioritizing to Get SimpleJason Ulaszek
 
The Art Of Debugging
The Art Of DebuggingThe Art Of Debugging
The Art Of Debuggingsvilen.ivanov
 
Static Analysis Primer
Static Analysis PrimerStatic Analysis Primer
Static Analysis PrimerCoverity
 
A Brief Talk On High-Performing Organisations
A Brief Talk On High-Performing OrganisationsA Brief Talk On High-Performing Organisations
A Brief Talk On High-Performing OrganisationsPhil Calçado
 
How to stop sucking and be awesome instead
How to stop sucking and be awesome insteadHow to stop sucking and be awesome instead
How to stop sucking and be awesome insteadcodinghorror
 

Andere mochten auch (19)

Debugging PHP With Xdebug
Debugging PHP With XdebugDebugging PHP With Xdebug
Debugging PHP With Xdebug
 
Defining Data Protection in the Cloud 디지탈링스
Defining Data Protection in the Cloud 디지탈링스Defining Data Protection in the Cloud 디지탈링스
Defining Data Protection in the Cloud 디지탈링스
 
Effective debugging
Effective debuggingEffective debugging
Effective debugging
 
Advanced debugging techniques (PHP)
Advanced debugging techniques (PHP)Advanced debugging techniques (PHP)
Advanced debugging techniques (PHP)
 
랜섬웨어
랜섬웨어랜섬웨어
랜섬웨어
 
Notes on Debugging
Notes on DebuggingNotes on Debugging
Notes on Debugging
 
Debugging
DebuggingDebugging
Debugging
 
Debugging Debugging
Debugging DebuggingDebugging Debugging
Debugging Debugging
 
Business Models
Business ModelsBusiness Models
Business Models
 
Agile Experience Design Framework
Agile Experience Design FrameworkAgile Experience Design Framework
Agile Experience Design Framework
 
Leadership Styles Your Team Needs
Leadership Styles Your Team NeedsLeadership Styles Your Team Needs
Leadership Styles Your Team Needs
 
Access by Default
Access by DefaultAccess by Default
Access by Default
 
Startup Metrics for Pirates (KAUST, Nov 2013)
Startup Metrics for Pirates (KAUST, Nov 2013)Startup Metrics for Pirates (KAUST, Nov 2013)
Startup Metrics for Pirates (KAUST, Nov 2013)
 
PHP data structures (and the impact of php 7 on them), phpDay Verona 2015, Italy
PHP data structures (and the impact of php 7 on them), phpDay Verona 2015, ItalyPHP data structures (and the impact of php 7 on them), phpDay Verona 2015, Italy
PHP data structures (and the impact of php 7 on them), phpDay Verona 2015, Italy
 
Doors, Walls and Old Trees: Prioritizing to Get Simple
Doors, Walls and Old Trees: Prioritizing to Get SimpleDoors, Walls and Old Trees: Prioritizing to Get Simple
Doors, Walls and Old Trees: Prioritizing to Get Simple
 
The Art Of Debugging
The Art Of DebuggingThe Art Of Debugging
The Art Of Debugging
 
Static Analysis Primer
Static Analysis PrimerStatic Analysis Primer
Static Analysis Primer
 
A Brief Talk On High-Performing Organisations
A Brief Talk On High-Performing OrganisationsA Brief Talk On High-Performing Organisations
A Brief Talk On High-Performing Organisations
 
How to stop sucking and be awesome instead
How to stop sucking and be awesome insteadHow to stop sucking and be awesome instead
How to stop sucking and be awesome instead
 

Kürzlich hochgeladen

Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf31events.com
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 

Kürzlich hochgeladen (20)

Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
Advantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your BusinessAdvantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your Business
 
Odoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting ServiceOdoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting Service
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 

How to Debug Anything

  • 1. How to Debug Anything @jamesgolick well ok, not anything, but most stuff on unixy operating systems that have the tooling i’m going to talk about today
  • 6. “If you want to deploy high quality software that performs, you should expect to fix bugs at every level.” - me
  • 7. “I don’t understand how this is possible.” - every programmer ever
  • 8. 0. php a blind debugging session
  • 10. what we have to work with • The source code. (nope) • Knowledge of the system. (nope) • Familiarity with the programming language. (nope) • SSH Access. (yup)
  • 11. logging in the real world (often useless)
  • 12. #cool
  • 14. sudo strace -ff -s 2048 -p 22935
  • 15. write(1, "hin", 3) = 3 function name arguments return value how to read strace output
  • 16. man 2 write learn more about your favorite system calls
  • 17. {sa_family=AF_INET, sin_port=htons(50318), sin_addr=inet_addr("192.168.212.2")}, [16]) = 12 fcntl(12, F_GETFD) = 0 fcntl(12, F_SETFD, FD_CLOEXEC) = 0 getsockname(12, {sa_family=AF_INET, sin_port=htons(80), sin_addr=inet_addr("192.168.212.182")}, [16]) = 0 fcntl(12, F_GETFL) = 0x2 (flags O_RDWR) fcntl(12, F_SETFL, O_RDWR|O_NONBLOCK) = 0 read(12, "GET / HTTP/1.1rnHost: localhost:8181rnConnection: keep-alivernCache-Control: max-age=0rnAccept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8rnUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36rnAccept-Encoding: gzip,deflate,sdchrnAccept-Language: en-US,en;q=0.8rnCookie: _jsuid=3899596137; _packages_session=d2NrM3RZMUJXRE8zcFB0aXNGVk83Ny9lRDR3Y09uSVNoRUcrREV0VnF2UjFxRjk1NjAyUzZ5ZG81M1JyczRzUU10ZTBqMXI5QkJXZzFqZnM1RUNmdEdGYmN2eG92SUsvU24wOWhJSlhNZzYrQXdYN2tMYnRZaEhWN3ArbEpiZVpMUWNjWHNRWHc2VjkwQzZ2S 0Y4aGlLeks3MmhoTXBXN2NRWUEwbGFFekpENHdveCtTNXl1MllDUTFzUzZMSU5WZlRqUlQ1aXB2bWVsZDVGVFE1Tlp0UT09LS1vYWdoMk9mZHUvS3U5OWpoME1ZY3pBPT0%3D--8e4ac5c1aebe1e9226063c3d2b83b4176535377arnrn", 8000) = 792 stat("/var/www/", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0 stat("/var/www/index.php", {st_mode=S_IFREG|0664, st_size=447, ...}) = 0 setitimer(ITIMER_PROF, {it_interval={0, 0}, it_value={60, 0}}, NULL) = 0 rt_sigaction(SIGPROF, {0x7f8a898930c0, [PROF], SA_RESTORER|SA_RESTART, 0x7f8a8c6d14a0}, {0x7f8a898930c0, [PROF], SA_RESTORER|SA_RESTART, 0x7f8a8c6d14a0}, 8) = 0 rt_sigprocmask(SIG_UNBLOCK, [PROF], NULL, 8) = 0 umask(077) = 022 umask(022) = 077 getcwd("/", 4095) = 2 chdir("/var/www") = 0 setitimer(ITIMER_PROF, {it_interval={0, 0}, it_value={30, 0}}, NULL) = 0 lstat("/var/www/index.php", {st_mode=S_IFREG|0664, st_size=447, ...}) = 0 open("/var/www/index.php", O_RDONLY) = 13 fstat(13, {st_mode=S_IFREG|0664, st_size=447, ...}) = 0 fstat(13, {st_mode=S_IFREG|0664, st_size=447, ...}) = 0 fstat(13, {st_mode=S_IFREG|0664, st_size=447, ...}) = 0 fstat(13, {st_mode=S_IFREG|0664, st_size=447, ...}) = 0 mmap(NULL, 447, PROT_READ, MAP_SHARED, 13, 0) = 0x7f8a8d34f000 munmap(0x7f8a8d34f000, 447) = 0 close(13) = 0 getcwd("/var/www", 4096) = 9 lstat("/var/www/./oh-fuck.php", 0x7fff11342620) = -1 ENOENT (No such file or directory) lstat("/usr/share/php/oh-fuck.php", 0x7fff11342620) = -1 ENOENT (No such file or directory) lstat("/usr/share/pear/oh-fuck.php", 0x7fff11342620) = -1 ENOENT (No such file or directory) lstat("/var/www/oh-fuck.php", 0x7fff11342620) = -1 ENOENT (No such file or directory) getcwd("/var/www", 4096) = 9 lstat("/var/www/./oh-fuck.php", 0x7fff11342580) = -1 ENOENT (No such file or directory) lstat("/usr/share/php/oh-fuck.php", 0x7fff11342580) = -1 ENOENT (No such file or directory) lstat("/usr/share/pear/oh-fuck.php", 0x7fff11342580) = -1 ENOENT (No such file or directory) lstat("/var/www/oh-fuck.php", 0x7fff11342580) = -1 ENOENT (No such file or directory) getcwd("/var/www", 4096) = 9 lstat("/var/www/oh-fuck.php", 0x7fff113446e0) = -1 ENOENT (No such file or directory) open("/var/www/oh-fuck.php", O_RDONLY) = -1 ENOENT (No such file or directory) chdir("/") = 0 umask(022) = 022 open("/dev/urandom", O_RDONLY) = 13 read(13, "33260300377gK222d", 8) = 8 close(13) = 0 open("/dev/urandom", O_RDONLY) = 13 read(13, "427417x3516336260", 8) = 8 close(13) = 0 open("/dev/urandom", O_RDONLY) = 13 read(13, "&M330225-P340345", 8) = 8 close(13) = 0 setitimer(ITIMER_PROF, {it_interval={0, 0}, it_value={0, 0}}, NULL) = 0 mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f8a8d34e000 writev(12, [{"HTTP/1.0 500 Internal Server ErrorrnDate: Sat, 14 Jun 2014 17:40:32 GMTrnServer: Apache/2.2.22 (Ubuntu)rnX-Powered-By: PHP/5.3.10-1ubuntu3.11rnVary: Accept-EncodingrnContent-Encoding: gziprnContent-Length: 20rnConnection: closernContent-Type: text/htmlrnrn", 256}, {"37213100000003", 10}, {"30", 2}, {"00000000", 8}], 4) = 276 write(7, "192.168.212.2 - - [14/Jun/2014:17:40:32 +0000] "GET / HTTP/1.1" 500 276 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/ 537.36"n", 199) = 199 times({tms_utime=6, tms_stime=56, tms_cutime=0, tms_cstime=0}) = 1718165756 shutdown(12, 1 /* send */) = 0 poll([{fd=12, events=POLLIN}], 1, 2000) = 1 ([{fd=12, revents=POLLIN|POLLHUP}]) read(12, "", 512) = 0 close(12) = 0 read(4, 0x7fff113490cf, 1) = -1 EAGAIN (Resource temporarily unavailable) ETOOMUCHOUTPUT
  • 18. writev(12, [{"HTTP/1.0 500 Internal Server Err"..., 256}, {"37213100000003", 10}, {"30", 2}, {"00000000", 8}], 4) = 276 find failure always work backwards
  • 19. open("/var/www/db.in.php", O_RDONLY) = -1 ENOENT (No such file or directory) find the cause hopefully.
  • 24. #cool
  • 25. “I don’t understand how this is possible.” - every programmer ever
  • 26. 0. Forget everything you think you know.
  • 27. 1. Get a third party opinion.
  • 28. third parties i have known and loved source: http://www.brendangregg.com/linuxperf.html
  • 29. 1. apt building a cloud for packages is hard
  • 31. sudo strace -ff apt-get update
  • 32. write(1, "Ign http:// 192.168.212.136:3000 trusty Releasen", 62) = 62 find failure always work backwards
  • 33. read(6, "400 URI FailurenURI: https://packagecloud-repositories- dev2.s3.amazonaws.com/1/1/ubuntu/ dists/trusty/Release? AWSAccessKeyId=AKIAILW54TIPGLUGWOYA&Si gnature=s/c0fzVQhxpBPbpyTIzCxAfo/ 8g=&Expires=1402837136nMessage: Bad header line nn", 64000) = 230 find the cause
  • 35. #cool
  • 37. read(6, "400 URI FailurenURI: https:// packagecloud-repositories- dev2.s3.amazonaws.com/1/1/ubuntu/dists/ trusty/Release? AWSAccessKeyId=AKIAILW54TIPGLUGWOYA&Sig nature=s/c0fzVQhxpBPbpyTIzCxAfo/ 8g=&Expires=1402837136nMessage: Bad header line nn", 64000) = 230 locate a hook
  • 39. stare at the code
  • 43. #cool
  • 44. 2. Locate the correct source code.
  • 45. 3. Identify a hard-coded string to grep for.
  • 46. 4. Stare at the code until it makes sense.
  • 47. 5. Fix whatever is broken.
  • 48. How to Debug Anything ! ! 0. Forget everything you think you know. 1. Get a third party opinion. 2. Locate the correct source code. 3. Identify a hard-coded string to grep for. 4. Stare at the code until it makes sense. 5. Fix whatever is broken.