SlideShare a Scribd company logo
Advanced Debugging with gdbDavid KhosidSept 21, 2009david.kh@gmail.com
Agenda Techniques for debugging big, modern software: STL containers and algorithms, Boost Ex: how to see containers Signals Multi-threaded (ex.: how to follow a thread?) Repetitive tasks on the almost unchanging code base Remote debugging Examples 2
GDB was first written by Richard Stallman  in 1986 as part of his GNU system Richard Stallman, “Debugging with gdb” www.gnu.org/software/gdb/documentation Help: 	$gdb –h 		(gdb) h 		(gdb) aproposCommand names may be truncated if the abbreviation is unambiguous. TAB completion.  Command Cheat Sheetwww.yolinux.com/TUTORIALS/GDB-Commands.html Last GDB version is 6.8, new 7.0 soon: 2009-09-23 3 Sources of information
Item #1: C++ and STL - Containers How to see container’s content? Commands file, ex. .gdbinithttp://www.yolinux.com/TUTORIALS/src/dbinit_stl_views-1.03.txtLimitations: a little libstdc++ compiled in debug modeLimitations: - different product , not for QA, not for client, not in performance tuning stage- performance  4
Item #1: C++ and STL - Containers How to see container’s content? Auxiliary functionstypedef map<string, float> MapStringFloat;void mapPrint(const MapStringFloat& m){       for(MapStringFloat::const_iterator pos = m.begin(); pos != m.end(); ++pos){                     cout << pos->first << " : " << pos->second << ""; }Limitations: - you can’t do that without a process to debug (investigating core files)- optimization of unused functions. Solution: ‘volatile’ Pretty-printing of STL containers in future versions of GDB 5
Item #2: Extending GDB – User-defined commands (gdb) show user commandname Example: (gdb)define adder	print $arg0 + $arg1 + $arg2 end(gdb) adder 1 2 3  6
Item #3: Automating repetitive tasks  What GDB Does During Startup1. Executes all commands from system init file 2. Executes all the commands from ~/.gdbinit3. Process command line options and operands 4. Executes all the commands from ./.gdbinit5. reads command files specified by the `-x' option 6. … 7
Automating tasks - history, recording continueWhat GDB Does During Startup… 6. Reads the command history recorded in the history file.  (gdb) set history filename fname(gdb) set history save on/off (gdb) show history (gdb) show commands 8
Item #4: Signals ‘i handle’ or ‘i signals’Print a table of all the signals and how gdb has been told to handle each one. handle signal [keywords...]keywords: nostop|stop,  print|noprint and pass|nopassEx: handle SIG35 nostop print pass 	handle SIG36 stop (implies the ‘print’ as well)	handle SIG37 nostop print nopass	handle SIG38 nostopnoprintnopass 9
Item #5: Multi-threads Use case: debugging specific thread, while controlling behavior of others. facilities for debugging multi-thread programs:• automatic notification of new threads• ‘thread threadno’, to switch among threads• ‘info threads’, to inquire about existing threads• thread-specific breakpoints• set mode for locking scheduler during execution 	(gdb) set scheduler-locking step/on/offothers: Interrupted System Calls Example:(gdb) i threads(gbd) b foo.cpp:13 thread 28 if x > lim 10
Item #5: Remote debugging Use case: - GDB runs on one machine (host) and the program  being debugged (exe.verXYZ.stripped ) runs on another (target). - GDB communicates via Serial or TCP/IP.- Host and target: exactly match between the executables and libraries, with one exception: stripped on the target.- Complication: compiling on one machine (CC view), keeping code in different place (ex. /your/path/verXYZ) Solution: - Connect gdb to source in the given place:(gdb) set substitute-path /usr/src /mnt/cross (gdb) dir /your/path/verXYZ 11
Remote debugging - example Using gdbserver through TCP connection: remote (10.10.0.225)>  gdbserver :9999 program_strippedor remote> ./gdbserver :9999 –attach <pid> host> gdb programhost>(gdb) handle SIGTRAP nostopnoprint pass			 to avoid pausing when launching the threadshost> (gdb) target remote 10.10.0.225:9999 TARGET (Android Dev phone)	 HOST (Fedora Linux) 12
Item #6: Back to the past  Convenience variables are used to store values that you may want to refer later. Any string preceded by $ is regarded as a convenience variable. Ex.:set $table = *table_ptr 	(gdb) show conv Checkpoint - a snapshot of a program’s state(gdb) checkpoint(gdb) i checkpoint(gdb) restartcheckpoint-id Value history- values printed by the print command. 13
Small Items: #7, #8  #7. 	How to see macros? 	$ g++ -gdwarf-2 -g3 a.cpp -o prog #8. 	64 bit .vs. 32bit  -m32 flag On 64-bit machine, install another 32-bit version of GDB 	$ ls -l `which gdb32` 	/usr/bin/gdb32 ->  ‘/your/install/path’ 14
Lightweight how-to's How to remove a symbol table from a file?A: 	strip How to supply arguments to your program in GDB?A1: With --args option 	#sudo gdb -silent --args /bin/ping google.comA2: As arguments to run: (gdb) runarg1 arg2run without arguments uses the same arguments used by the previous run. A3: With set args  command: 		(gdb) set args arg1 arg2(gdb) show args set args without arguments – removes all arguments.  How to know where you are (file, next execution line)?A:  	(gdb) f 15
Lightweight how-to's - continue How to find out the crash file executable? A1: #file core.1234A2: #gdb core.1234A3: use /proc/sys/kernel/core_pattern#echo "core_%e.%p" > /proc/sys/kernel/core_pattern 	if the program foo dumps its core, 	the core_foo.1234 will be created. How to find out why your program stopped?A: (gdb) iprog Which command(s) can be used to exit from loops?A:(gdb)until lineNo ‘print’, ‘info’, ‘show’- what is a difference?‘print’ – print value of expression‘info’ – showing things about the program being debugged‘show’ – showing things about the debugger 16

More Related Content

What's hot

from Source to Binary: How GNU Toolchain Works
from Source to Binary: How GNU Toolchain Worksfrom Source to Binary: How GNU Toolchain Works
from Source to Binary: How GNU Toolchain Works
National Cheng Kung University
 
Git Grundlagen
Git GrundlagenGit Grundlagen
Git Grundlagen
Benjamin Schürmann
 
Introduction To Linux Kernel Modules
Introduction To Linux Kernel ModulesIntroduction To Linux Kernel Modules
Introduction To Linux Kernel Modules
dibyajyotig
 
Conan.io - The C/C++ package manager for Developers
Conan.io - The C/C++ package manager for DevelopersConan.io - The C/C++ package manager for Developers
Conan.io - The C/C++ package manager for Developers
Uilian Ries
 
TIP1 - Overview of C/C++ Debugging/Tracing/Profiling Tools
TIP1 - Overview of C/C++ Debugging/Tracing/Profiling ToolsTIP1 - Overview of C/C++ Debugging/Tracing/Profiling Tools
TIP1 - Overview of C/C++ Debugging/Tracing/Profiling ToolsXiaozhe Wang
 
Git Introduction Tutorial
Git Introduction TutorialGit Introduction Tutorial
Git Introduction Tutorial
Thomas Rausch
 
Let's trace Linux Lernel with KGDB @ COSCUP 2021
Let's trace Linux Lernel with KGDB @ COSCUP 2021Let's trace Linux Lernel with KGDB @ COSCUP 2021
Let's trace Linux Lernel with KGDB @ COSCUP 2021
Jian-Hong Pan
 
Filesystem Comparison: NFS vs GFS2 vs OCFS2
Filesystem Comparison: NFS vs GFS2 vs OCFS2Filesystem Comparison: NFS vs GFS2 vs OCFS2
Filesystem Comparison: NFS vs GFS2 vs OCFS2Giuseppe Paterno'
 
Linux kernel memory allocators
Linux kernel memory allocatorsLinux kernel memory allocators
Linux kernel memory allocators
Hao-Ran Liu
 
Coding with golang
Coding with golangCoding with golang
Coding with golang
HannahMoss14
 
The Linux Block Layer - Built for Fast Storage
The Linux Block Layer - Built for Fast StorageThe Linux Block Layer - Built for Fast Storage
The Linux Block Layer - Built for Fast Storage
Kernel TLV
 
Debugging linux kernel tools and techniques
Debugging linux kernel tools and  techniquesDebugging linux kernel tools and  techniques
Debugging linux kernel tools and techniques
Satpal Parmar
 
Unit II - 3 - Operating System - Process Synchronization
Unit II - 3 - Operating System - Process SynchronizationUnit II - 3 - Operating System - Process Synchronization
Unit II - 3 - Operating System - Process Synchronization
cscarcas
 
ceph::errorator<> throw/catch-free, compile time-checked exceptions for seast...
ceph::errorator<> throw/catch-free, compile time-checked exceptions for seast...ceph::errorator<> throw/catch-free, compile time-checked exceptions for seast...
ceph::errorator<> throw/catch-free, compile time-checked exceptions for seast...
ScyllaDB
 
Windbg cmds
Windbg cmdsWindbg cmds
Windbg cmdskewuc
 
Linux Memory Management
Linux Memory ManagementLinux Memory Management
Linux Memory ManagementNi Zo-Ma
 
Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021
Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021
Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021
Valeriy Kravchuk
 
User management
User managementUser management
User management
Mufaddal Haidermota
 
Linux Kernel - Virtual File System
Linux Kernel - Virtual File SystemLinux Kernel - Virtual File System
Linux Kernel - Virtual File System
Adrian Huang
 
[Container Plumbing Days 2023] Why was nerdctl made?
[Container Plumbing Days 2023] Why was nerdctl made?[Container Plumbing Days 2023] Why was nerdctl made?
[Container Plumbing Days 2023] Why was nerdctl made?
Akihiro Suda
 

What's hot (20)

from Source to Binary: How GNU Toolchain Works
from Source to Binary: How GNU Toolchain Worksfrom Source to Binary: How GNU Toolchain Works
from Source to Binary: How GNU Toolchain Works
 
Git Grundlagen
Git GrundlagenGit Grundlagen
Git Grundlagen
 
Introduction To Linux Kernel Modules
Introduction To Linux Kernel ModulesIntroduction To Linux Kernel Modules
Introduction To Linux Kernel Modules
 
Conan.io - The C/C++ package manager for Developers
Conan.io - The C/C++ package manager for DevelopersConan.io - The C/C++ package manager for Developers
Conan.io - The C/C++ package manager for Developers
 
TIP1 - Overview of C/C++ Debugging/Tracing/Profiling Tools
TIP1 - Overview of C/C++ Debugging/Tracing/Profiling ToolsTIP1 - Overview of C/C++ Debugging/Tracing/Profiling Tools
TIP1 - Overview of C/C++ Debugging/Tracing/Profiling Tools
 
Git Introduction Tutorial
Git Introduction TutorialGit Introduction Tutorial
Git Introduction Tutorial
 
Let's trace Linux Lernel with KGDB @ COSCUP 2021
Let's trace Linux Lernel with KGDB @ COSCUP 2021Let's trace Linux Lernel with KGDB @ COSCUP 2021
Let's trace Linux Lernel with KGDB @ COSCUP 2021
 
Filesystem Comparison: NFS vs GFS2 vs OCFS2
Filesystem Comparison: NFS vs GFS2 vs OCFS2Filesystem Comparison: NFS vs GFS2 vs OCFS2
Filesystem Comparison: NFS vs GFS2 vs OCFS2
 
Linux kernel memory allocators
Linux kernel memory allocatorsLinux kernel memory allocators
Linux kernel memory allocators
 
Coding with golang
Coding with golangCoding with golang
Coding with golang
 
The Linux Block Layer - Built for Fast Storage
The Linux Block Layer - Built for Fast StorageThe Linux Block Layer - Built for Fast Storage
The Linux Block Layer - Built for Fast Storage
 
Debugging linux kernel tools and techniques
Debugging linux kernel tools and  techniquesDebugging linux kernel tools and  techniques
Debugging linux kernel tools and techniques
 
Unit II - 3 - Operating System - Process Synchronization
Unit II - 3 - Operating System - Process SynchronizationUnit II - 3 - Operating System - Process Synchronization
Unit II - 3 - Operating System - Process Synchronization
 
ceph::errorator<> throw/catch-free, compile time-checked exceptions for seast...
ceph::errorator<> throw/catch-free, compile time-checked exceptions for seast...ceph::errorator<> throw/catch-free, compile time-checked exceptions for seast...
ceph::errorator<> throw/catch-free, compile time-checked exceptions for seast...
 
Windbg cmds
Windbg cmdsWindbg cmds
Windbg cmds
 
Linux Memory Management
Linux Memory ManagementLinux Memory Management
Linux Memory Management
 
Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021
Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021
Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021
 
User management
User managementUser management
User management
 
Linux Kernel - Virtual File System
Linux Kernel - Virtual File SystemLinux Kernel - Virtual File System
Linux Kernel - Virtual File System
 
[Container Plumbing Days 2023] Why was nerdctl made?
[Container Plumbing Days 2023] Why was nerdctl made?[Container Plumbing Days 2023] Why was nerdctl made?
[Container Plumbing Days 2023] Why was nerdctl made?
 

Viewers also liked

Crash Dump Analysis 101
Crash Dump Analysis 101Crash Dump Analysis 101
Crash Dump Analysis 101
John Howard
 
Gdb remote debugger
Gdb remote debuggerGdb remote debugger
Gdb remote debugger
shanghai jiaotong university
 
From printk to QEMU: Xen/Linux Kernel debugging
From printk to QEMU: Xen/Linux Kernel debuggingFrom printk to QEMU: Xen/Linux Kernel debugging
From printk to QEMU: Xen/Linux Kernel debugging
The Linux Foundation
 
Advanced Tracing features using GDB and LTTng
Advanced Tracing features using GDB and LTTngAdvanced Tracing features using GDB and LTTng
Advanced Tracing features using GDB and LTTng
marckhouzam
 
Debugger Principle Overview & GDB Tricks
Debugger Principle Overview & GDB TricksDebugger Principle Overview & GDB Tricks
Debugger Principle Overview & GDB Tricksdutor
 
Aag c45 697761
Aag c45 697761Aag c45 697761
Aag c45 697761
HP IN Rajesh Goel
 
Reverse, Multi-Process and Non-Stop Debugging come to the CDT
Reverse, Multi-Process and Non-Stop Debugging come to the CDTReverse, Multi-Process and Non-Stop Debugging come to the CDT
Reverse, Multi-Process and Non-Stop Debugging come to the CDT
marckhouzam
 
Real time debugging: using non-intrusive tracepoints to debug live systems
Real time debugging: using non-intrusive tracepoints to debug live systemsReal time debugging: using non-intrusive tracepoints to debug live systems
Real time debugging: using non-intrusive tracepoints to debug live systems
marckhouzam
 
Working Remotely (via SSH) Rocks!
Working Remotely (via SSH) Rocks!Working Remotely (via SSH) Rocks!
Working Remotely (via SSH) Rocks!
Kent Chen
 
LAS16-403: GDB Linux Kernel Awareness
LAS16-403: GDB Linux Kernel AwarenessLAS16-403: GDB Linux Kernel Awareness
LAS16-403: GDB Linux Kernel Awareness
Linaro
 
Linux booting process!!
Linux booting process!!Linux booting process!!
Linux booting process!!
sourav verma
 
Vim Rocks!
Vim Rocks!Vim Rocks!
Vim Rocks!
Kent Chen
 
Linux booting Process
Linux booting ProcessLinux booting Process
Linux booting Process
Gaurav Sharma
 
DPDK Summit - 08 Sept 2014 - Futurewei - Jun Xu - Revisit the IP Stack in Lin...
DPDK Summit - 08 Sept 2014 - Futurewei - Jun Xu - Revisit the IP Stack in Lin...DPDK Summit - 08 Sept 2014 - Futurewei - Jun Xu - Revisit the IP Stack in Lin...
DPDK Summit - 08 Sept 2014 - Futurewei - Jun Xu - Revisit the IP Stack in Lin...
Jim St. Leger
 
Linux installation and booting process
Linux installation and booting processLinux installation and booting process
Linux installation and booting process
Siddharth Jain
 
kubernetes, pourquoi et comment
kubernetes, pourquoi et commentkubernetes, pourquoi et comment
kubernetes, pourquoi et comment
Jean-Baptiste Claramonte
 
Simple Belief - Mosky @ TEDxNTUST 2015
Simple Belief - Mosky @ TEDxNTUST 2015Simple Belief - Mosky @ TEDxNTUST 2015
Simple Belief - Mosky @ TEDxNTUST 2015
Mosky Liu
 
introduction to linux kernel tcp/ip ptocotol stack
introduction to linux kernel tcp/ip ptocotol stack introduction to linux kernel tcp/ip ptocotol stack
introduction to linux kernel tcp/ip ptocotol stack
monad bobo
 
Virtualization with KVM (Kernel-based Virtual Machine)
Virtualization with KVM (Kernel-based Virtual Machine)Virtualization with KVM (Kernel-based Virtual Machine)
Virtualization with KVM (Kernel-based Virtual Machine)
Novell
 

Viewers also liked (20)

Crash Dump Analysis 101
Crash Dump Analysis 101Crash Dump Analysis 101
Crash Dump Analysis 101
 
Gdb remote debugger
Gdb remote debuggerGdb remote debugger
Gdb remote debugger
 
From printk to QEMU: Xen/Linux Kernel debugging
From printk to QEMU: Xen/Linux Kernel debuggingFrom printk to QEMU: Xen/Linux Kernel debugging
From printk to QEMU: Xen/Linux Kernel debugging
 
Advanced Tracing features using GDB and LTTng
Advanced Tracing features using GDB and LTTngAdvanced Tracing features using GDB and LTTng
Advanced Tracing features using GDB and LTTng
 
Debugger Principle Overview & GDB Tricks
Debugger Principle Overview & GDB TricksDebugger Principle Overview & GDB Tricks
Debugger Principle Overview & GDB Tricks
 
Aag c45 697761
Aag c45 697761Aag c45 697761
Aag c45 697761
 
Reverse, Multi-Process and Non-Stop Debugging come to the CDT
Reverse, Multi-Process and Non-Stop Debugging come to the CDTReverse, Multi-Process and Non-Stop Debugging come to the CDT
Reverse, Multi-Process and Non-Stop Debugging come to the CDT
 
Real time debugging: using non-intrusive tracepoints to debug live systems
Real time debugging: using non-intrusive tracepoints to debug live systemsReal time debugging: using non-intrusive tracepoints to debug live systems
Real time debugging: using non-intrusive tracepoints to debug live systems
 
Working Remotely (via SSH) Rocks!
Working Remotely (via SSH) Rocks!Working Remotely (via SSH) Rocks!
Working Remotely (via SSH) Rocks!
 
Udev
UdevUdev
Udev
 
LAS16-403: GDB Linux Kernel Awareness
LAS16-403: GDB Linux Kernel AwarenessLAS16-403: GDB Linux Kernel Awareness
LAS16-403: GDB Linux Kernel Awareness
 
Linux booting process!!
Linux booting process!!Linux booting process!!
Linux booting process!!
 
Vim Rocks!
Vim Rocks!Vim Rocks!
Vim Rocks!
 
Linux booting Process
Linux booting ProcessLinux booting Process
Linux booting Process
 
DPDK Summit - 08 Sept 2014 - Futurewei - Jun Xu - Revisit the IP Stack in Lin...
DPDK Summit - 08 Sept 2014 - Futurewei - Jun Xu - Revisit the IP Stack in Lin...DPDK Summit - 08 Sept 2014 - Futurewei - Jun Xu - Revisit the IP Stack in Lin...
DPDK Summit - 08 Sept 2014 - Futurewei - Jun Xu - Revisit the IP Stack in Lin...
 
Linux installation and booting process
Linux installation and booting processLinux installation and booting process
Linux installation and booting process
 
kubernetes, pourquoi et comment
kubernetes, pourquoi et commentkubernetes, pourquoi et comment
kubernetes, pourquoi et comment
 
Simple Belief - Mosky @ TEDxNTUST 2015
Simple Belief - Mosky @ TEDxNTUST 2015Simple Belief - Mosky @ TEDxNTUST 2015
Simple Belief - Mosky @ TEDxNTUST 2015
 
introduction to linux kernel tcp/ip ptocotol stack
introduction to linux kernel tcp/ip ptocotol stack introduction to linux kernel tcp/ip ptocotol stack
introduction to linux kernel tcp/ip ptocotol stack
 
Virtualization with KVM (Kernel-based Virtual Machine)
Virtualization with KVM (Kernel-based Virtual Machine)Virtualization with KVM (Kernel-based Virtual Machine)
Virtualization with KVM (Kernel-based Virtual Machine)
 

Similar to Advanced Debugging with GDB

ELC-E Linux Awareness
ELC-E Linux AwarenessELC-E Linux Awareness
ELC-E Linux AwarenessPeter Griffin
 
gdb-tutorial.pdf
gdb-tutorial.pdfgdb-tutorial.pdf
gdb-tutorial.pdf
ligi14
 
Debugging Applications with GNU Debugger
Debugging Applications with GNU DebuggerDebugging Applications with GNU Debugger
Debugging Applications with GNU Debugger
Priyank Kapadia
 
lab1-ppt.pdf
lab1-ppt.pdflab1-ppt.pdf
lab1-ppt.pdf
AbdelrahmanElewah1
 
Debugging Modern C++ Application with Gdb
Debugging Modern C++ Application with GdbDebugging Modern C++ Application with Gdb
Debugging Modern C++ Application with Gdb
SenthilKumar Selvaraj
 
LAS16-403 - GDB Linux Kernel Awareness
LAS16-403 - GDB Linux Kernel Awareness LAS16-403 - GDB Linux Kernel Awareness
LAS16-403 - GDB Linux Kernel Awareness Peter Griffin
 
Debuging like a pro
Debuging like a proDebuging like a pro
Debuging like a pro
Vicente Bolea
 
Usage of GDB
Usage of GDBUsage of GDB
Usage of GDB
Jongseok Choi
 
Gdb tutorial-handout
Gdb tutorial-handoutGdb tutorial-handout
Gdb tutorial-handoutSuraj Kumar
 
Anatomy of ROCgdb presentation at gcc cauldron 2022
Anatomy of ROCgdb presentation at gcc cauldron 2022Anatomy of ROCgdb presentation at gcc cauldron 2022
Anatomy of ROCgdb presentation at gcc cauldron 2022
ssuser866937
 
Debugging of (C)Python applications
Debugging of (C)Python applicationsDebugging of (C)Python applications
Debugging of (C)Python applications
Roman Podoliaka
 
Debugging Python with gdb
Debugging Python with gdbDebugging Python with gdb
Debugging Python with gdb
Roman Podoliaka
 
Analyze corefile and backtraces with GDB for Mysql/MariaDB on Linux - Nilanda...
Analyze corefile and backtraces with GDB for Mysql/MariaDB on Linux - Nilanda...Analyze corefile and backtraces with GDB for Mysql/MariaDB on Linux - Nilanda...
Analyze corefile and backtraces with GDB for Mysql/MariaDB on Linux - Nilanda...
Mydbops
 
Debugging Hung Python Processes With GDB
Debugging Hung Python Processes With GDBDebugging Hung Python Processes With GDB
Debugging Hung Python Processes With GDB
bmbouter
 
Linux kernel debugging
Linux kernel debuggingLinux kernel debugging
Linux kernel debugging
libfetion
 
Wavedigitech gdb
Wavedigitech gdbWavedigitech gdb
Wavedigitech gdb
Wave Digitech
 
Roll your own toy unix clone os
Roll your own toy unix clone osRoll your own toy unix clone os
Roll your own toy unix clone os
eramax
 
Linux Kernel Debugging
Linux Kernel DebuggingLinux Kernel Debugging
Linux Kernel Debugging
GlobalLogic Ukraine
 

Similar to Advanced Debugging with GDB (20)

ELC-E Linux Awareness
ELC-E Linux AwarenessELC-E Linux Awareness
ELC-E Linux Awareness
 
gdb-tutorial.pdf
gdb-tutorial.pdfgdb-tutorial.pdf
gdb-tutorial.pdf
 
Debugging Applications with GNU Debugger
Debugging Applications with GNU DebuggerDebugging Applications with GNU Debugger
Debugging Applications with GNU Debugger
 
lab1-ppt.pdf
lab1-ppt.pdflab1-ppt.pdf
lab1-ppt.pdf
 
Debugging Modern C++ Application with Gdb
Debugging Modern C++ Application with GdbDebugging Modern C++ Application with Gdb
Debugging Modern C++ Application with Gdb
 
Gnu debugger
Gnu debuggerGnu debugger
Gnu debugger
 
GNU Debugger
GNU DebuggerGNU Debugger
GNU Debugger
 
LAS16-403 - GDB Linux Kernel Awareness
LAS16-403 - GDB Linux Kernel Awareness LAS16-403 - GDB Linux Kernel Awareness
LAS16-403 - GDB Linux Kernel Awareness
 
Debuging like a pro
Debuging like a proDebuging like a pro
Debuging like a pro
 
Usage of GDB
Usage of GDBUsage of GDB
Usage of GDB
 
Gdb tutorial-handout
Gdb tutorial-handoutGdb tutorial-handout
Gdb tutorial-handout
 
Anatomy of ROCgdb presentation at gcc cauldron 2022
Anatomy of ROCgdb presentation at gcc cauldron 2022Anatomy of ROCgdb presentation at gcc cauldron 2022
Anatomy of ROCgdb presentation at gcc cauldron 2022
 
Debugging of (C)Python applications
Debugging of (C)Python applicationsDebugging of (C)Python applications
Debugging of (C)Python applications
 
Debugging Python with gdb
Debugging Python with gdbDebugging Python with gdb
Debugging Python with gdb
 
Analyze corefile and backtraces with GDB for Mysql/MariaDB on Linux - Nilanda...
Analyze corefile and backtraces with GDB for Mysql/MariaDB on Linux - Nilanda...Analyze corefile and backtraces with GDB for Mysql/MariaDB on Linux - Nilanda...
Analyze corefile and backtraces with GDB for Mysql/MariaDB on Linux - Nilanda...
 
Debugging Hung Python Processes With GDB
Debugging Hung Python Processes With GDBDebugging Hung Python Processes With GDB
Debugging Hung Python Processes With GDB
 
Linux kernel debugging
Linux kernel debuggingLinux kernel debugging
Linux kernel debugging
 
Wavedigitech gdb
Wavedigitech gdbWavedigitech gdb
Wavedigitech gdb
 
Roll your own toy unix clone os
Roll your own toy unix clone osRoll your own toy unix clone os
Roll your own toy unix clone os
 
Linux Kernel Debugging
Linux Kernel DebuggingLinux Kernel Debugging
Linux Kernel Debugging
 

Recently uploaded

Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 

Recently uploaded (20)

Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 

Advanced Debugging with GDB

  • 1. Advanced Debugging with gdbDavid KhosidSept 21, 2009david.kh@gmail.com
  • 2. Agenda Techniques for debugging big, modern software: STL containers and algorithms, Boost Ex: how to see containers Signals Multi-threaded (ex.: how to follow a thread?) Repetitive tasks on the almost unchanging code base Remote debugging Examples 2
  • 3. GDB was first written by Richard Stallman in 1986 as part of his GNU system Richard Stallman, “Debugging with gdb” www.gnu.org/software/gdb/documentation Help: $gdb –h (gdb) h (gdb) aproposCommand names may be truncated if the abbreviation is unambiguous. TAB completion. Command Cheat Sheetwww.yolinux.com/TUTORIALS/GDB-Commands.html Last GDB version is 6.8, new 7.0 soon: 2009-09-23 3 Sources of information
  • 4. Item #1: C++ and STL - Containers How to see container’s content? Commands file, ex. .gdbinithttp://www.yolinux.com/TUTORIALS/src/dbinit_stl_views-1.03.txtLimitations: a little libstdc++ compiled in debug modeLimitations: - different product , not for QA, not for client, not in performance tuning stage- performance 4
  • 5. Item #1: C++ and STL - Containers How to see container’s content? Auxiliary functionstypedef map&lt;string, float&gt; MapStringFloat;void mapPrint(const MapStringFloat& m){ for(MapStringFloat::const_iterator pos = m.begin(); pos != m.end(); ++pos){ cout &lt;&lt; pos-&gt;first &lt;&lt; &quot; : &quot; &lt;&lt; pos-&gt;second &lt;&lt; &quot;&quot;; }Limitations: - you can’t do that without a process to debug (investigating core files)- optimization of unused functions. Solution: ‘volatile’ Pretty-printing of STL containers in future versions of GDB 5
  • 6. Item #2: Extending GDB – User-defined commands (gdb) show user commandname Example: (gdb)define adder print $arg0 + $arg1 + $arg2 end(gdb) adder 1 2 3 6
  • 7. Item #3: Automating repetitive tasks What GDB Does During Startup1. Executes all commands from system init file 2. Executes all the commands from ~/.gdbinit3. Process command line options and operands 4. Executes all the commands from ./.gdbinit5. reads command files specified by the `-x&apos; option 6. … 7
  • 8. Automating tasks - history, recording continueWhat GDB Does During Startup… 6. Reads the command history recorded in the history file. (gdb) set history filename fname(gdb) set history save on/off (gdb) show history (gdb) show commands 8
  • 9. Item #4: Signals ‘i handle’ or ‘i signals’Print a table of all the signals and how gdb has been told to handle each one. handle signal [keywords...]keywords: nostop|stop, print|noprint and pass|nopassEx: handle SIG35 nostop print pass handle SIG36 stop (implies the ‘print’ as well) handle SIG37 nostop print nopass handle SIG38 nostopnoprintnopass 9
  • 10. Item #5: Multi-threads Use case: debugging specific thread, while controlling behavior of others. facilities for debugging multi-thread programs:• automatic notification of new threads• ‘thread threadno’, to switch among threads• ‘info threads’, to inquire about existing threads• thread-specific breakpoints• set mode for locking scheduler during execution (gdb) set scheduler-locking step/on/offothers: Interrupted System Calls Example:(gdb) i threads(gbd) b foo.cpp:13 thread 28 if x &gt; lim 10
  • 11. Item #5: Remote debugging Use case: - GDB runs on one machine (host) and the program being debugged (exe.verXYZ.stripped ) runs on another (target). - GDB communicates via Serial or TCP/IP.- Host and target: exactly match between the executables and libraries, with one exception: stripped on the target.- Complication: compiling on one machine (CC view), keeping code in different place (ex. /your/path/verXYZ) Solution: - Connect gdb to source in the given place:(gdb) set substitute-path /usr/src /mnt/cross (gdb) dir /your/path/verXYZ 11
  • 12. Remote debugging - example Using gdbserver through TCP connection: remote (10.10.0.225)&gt; gdbserver :9999 program_strippedor remote&gt; ./gdbserver :9999 –attach &lt;pid&gt; host&gt; gdb programhost&gt;(gdb) handle SIGTRAP nostopnoprint pass to avoid pausing when launching the threadshost&gt; (gdb) target remote 10.10.0.225:9999 TARGET (Android Dev phone) HOST (Fedora Linux) 12
  • 13. Item #6: Back to the past Convenience variables are used to store values that you may want to refer later. Any string preceded by $ is regarded as a convenience variable. Ex.:set $table = *table_ptr (gdb) show conv Checkpoint - a snapshot of a program’s state(gdb) checkpoint(gdb) i checkpoint(gdb) restartcheckpoint-id Value history- values printed by the print command. 13
  • 14. Small Items: #7, #8 #7. How to see macros? $ g++ -gdwarf-2 -g3 a.cpp -o prog #8. 64 bit .vs. 32bit -m32 flag On 64-bit machine, install another 32-bit version of GDB $ ls -l `which gdb32` /usr/bin/gdb32 -&gt; ‘/your/install/path’ 14
  • 15. Lightweight how-to&apos;s How to remove a symbol table from a file?A: strip How to supply arguments to your program in GDB?A1: With --args option #sudo gdb -silent --args /bin/ping google.comA2: As arguments to run: (gdb) runarg1 arg2run without arguments uses the same arguments used by the previous run. A3: With set args command: (gdb) set args arg1 arg2(gdb) show args set args without arguments – removes all arguments. How to know where you are (file, next execution line)?A: (gdb) f 15
  • 16. Lightweight how-to&apos;s - continue How to find out the crash file executable? A1: #file core.1234A2: #gdb core.1234A3: use /proc/sys/kernel/core_pattern#echo &quot;core_%e.%p&quot; &gt; /proc/sys/kernel/core_pattern if the program foo dumps its core, the core_foo.1234 will be created. How to find out why your program stopped?A: (gdb) iprog Which command(s) can be used to exit from loops?A:(gdb)until lineNo ‘print’, ‘info’, ‘show’- what is a difference?‘print’ – print value of expression‘info’ – showing things about the program being debugged‘show’ – showing things about the debugger 16
  • 17. Problem Determination Tools for Linux -Wall  Code review Program’s traces, syslog, profilers Static Source Code Analysis: scan.coverity.com – free for FOSS Flexelint Dynamic analysis: Valgrind, strace, /proc filesystem, lsof, ldd, nm, objdump, wireshark 17
  • 18. Summary Start from thinking of Use Case, then look in the manual, use ‘apropos’ and ‘help’ Productivity:Stepping through a program is less productive than thinking harder and adding output statements and self-checking code at critical places. When to use GDB? - core file, - when a problem can be reproduced, repeating errors - self-educating When not?Other tools, traces Questions? 18