Debugging toolsDebugging tools
Мариян HackMan Маринов
<mm@1h.com>
Кой съм аз?Кой съм аз?
➢ Chief system architect of
➢ Sysadmin since the stone age
➢ The longest course in SoftUni
Linux System Administration
What is this talk about?What is this talk about?
Debugging is twice as hard as writing the code inDebugging is twice as hard as writing the code in
the first place.the first place.
Therefore, if you write the code AS CLEVERLY ASTherefore, if you write the code AS CLEVERLY AS
POSSIBLE, you are by DEFINITION, not smartPOSSIBLE, you are by DEFINITION, not smart
enough to debug it.enough to debug it.
-- Brian Kernighan-- Brian Kernighan
LDDLDD
$ ldd
$ ldd -r
$ ldd -v
STRACESTRACE
stracestrace
-o logfile
-f follow
-s string size
-p PID
-n NUM
stracestrace
-e
trace=open (syscall)
trace=file
trace=network
trace=desc
LTRACELTRACE
Nasty bugsNasty bugs
-o logfile
-f follow
-p PID
-n 4
$ ltrace -n 4 sed -v
-l library
{[+-][symbol_pattern][@library_pattern]}
GDBGDB
GDB ­ GNU debuggerGDB ­ GNU debugger
$ gcc -g$ gcc -g
➢ backtrace (bt)backtrace (bt)
➢ bt with core.dumpbt with core.dump
➢ frameframe
➢ printprint
GDB configurationGDB configuration
➢set follow-fork-mode childset follow-fork-mode child
➢parent - do not trace the childparent - do not trace the child
➢child - trace the child alsochild - trace the child also
➢ask - ask the userask - ask the user
GDB configurationGDB configuration
Should we stop the trace after exec ?Should we stop the trace after exec ?
➢set follow-exec-mode newset follow-exec-mode new
➢ new - follow the new processnew - follow the new process
➢ same - keep the same processsame - keep the same process
GDB configurationGDB configuration
Should we trace the child processes?Should we trace the child processes?
➢set detach-on-fork onset detach-on-fork on
➢ on - detach the child processon - detach the child process
➢ off - do not detachoff - do not detach
Въпроси?Въпроси?
Мариян HackMan MarinovМариян HackMan Marinov
E-Mail:E-Mail: mm@1h.commm@1h.com
IRC: irc.freenode.net HackManIRC: irc.freenode.net HackMan
ICQ: 7556201ICQ: 7556201
Jabber/Gtalk:Jabber/Gtalk: hackman@jabber.orghackman@jabber.org
http://github.com/hackman/http://github.com/hackman/

Tools used for debugging