SlideShare a Scribd company logo
GDB - Tutorial



c Anurag (anurag@gnuer.org)
March 9, 2006

1 Starting and invoking gdb
1. Inserting debugging information inside the output executable
les created
after compilation and to start debugging session.
$ gcc -o fact fact.c -g
$ gdb fact
2. Giving shell commands from within gdb
(gdb) shell clear
3. Set breakpoint at the function main()
(gdb) break main
4. Delete break point number 1
(gdb) delete 1
Note: Pressing enter with no command executes the previous command

2 Running and navigating in gdb
1. Run program to be debugged
(gdb) run
2. See where program stopped
(gdb) list
3. Execute next line of the program
(gdb) next (gdb) n
4. Step inside
(gdb) step

1
5. Print stack trace
(gdb) where
(gdb) frame 0
(gdb) frame 1
6. Return back from function
(gdb) return
7. Continue execution until the next break point.
(gdb) continue

3 Retrieving values of variables
1. Display the value of a variable "i"
(gdb) display i
2. Set hardware/software watch point for variable "i"
(gdb) watch i
3. Print the value of variable "i"
(gdb) print i
4. Print the address of variable "i"
(gdb) print &i
5. Reassign a value to n
(gdb) set variable n=6
(gdb) continue
6. Call fact() function with dierent parameters.
(gdb) call fact(4)
7. Display the data type of a variable:
(gdb) ptype i
(gdb) whatis i

4 Segmentation faults
1. Segmentation faults Here we compile and execute a program with results
in a segmentation fault. The snapshot of memory is saved in a

More Related Content

ODP
Extreme JavaScript Minification and Obfuscation
PDF
Open GL Programming Training Session I
PPTX
Brief GAUT tutorial
PPTX
Equipment 'Time Away Theory' in the opencut coal mining industry
PDF
ECMAScript 2017
PPT
Measuring SGX Texturing Performance
PDF
Formalising Graph Pattern Matching Gremlin traversals in Graph Alegra
PPTX
Performance in Geode: How Fast Is It, How Is It Measured, and How Can It Be I...
Extreme JavaScript Minification and Obfuscation
Open GL Programming Training Session I
Brief GAUT tutorial
Equipment 'Time Away Theory' in the opencut coal mining industry
ECMAScript 2017
Measuring SGX Texturing Performance
Formalising Graph Pattern Matching Gremlin traversals in Graph Alegra
Performance in Geode: How Fast Is It, How Is It Measured, and How Can It Be I...

Similar to GDB tutorial (20)

PDF
Gdb tutorial-handout
PDF
gdb-tutorial.pdf
PDF
Q2.12: Debugging with GDB
PPT
Debugging Applications with GNU Debugger
PPTX
Rasperry pi Part 8
PPT
Gccgdb
PDF
Usage of GDB
PDF
lab1-ppt.pdf
PPTX
Debuging like a pro
PPTX
Advanced Debugging with GDB
PDF
Debugging embedded devices using GDB
PPTX
Wavedigitech gdb
PPT
Introduction to gdb
PPTX
Debugging Modern C++ Application with Gdb
PPTX
Reversing with gdb
PDF
HKG15-207: Advanced Toolchain Usage Part 3
PPTX
Gnu debugger
PPTX
GNU Debugger
PDF
HKG15-211: Advanced Toolchain Usage Part 4
PPTX
GDB: A Lot More Than You Knew
Gdb tutorial-handout
gdb-tutorial.pdf
Q2.12: Debugging with GDB
Debugging Applications with GNU Debugger
Rasperry pi Part 8
Gccgdb
Usage of GDB
lab1-ppt.pdf
Debuging like a pro
Advanced Debugging with GDB
Debugging embedded devices using GDB
Wavedigitech gdb
Introduction to gdb
Debugging Modern C++ Application with Gdb
Reversing with gdb
HKG15-207: Advanced Toolchain Usage Part 3
Gnu debugger
GNU Debugger
HKG15-211: Advanced Toolchain Usage Part 4
GDB: A Lot More Than You Knew
Ad

Recently uploaded (20)

PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Encapsulation theory and applications.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPT
Teaching material agriculture food technology
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Empathic Computing: Creating Shared Understanding
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
Cloud computing and distributed systems.
PPTX
Big Data Technologies - Introduction.pptx
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Encapsulation_ Review paper, used for researhc scholars
Encapsulation theory and applications.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
NewMind AI Weekly Chronicles - August'25 Week I
Teaching material agriculture food technology
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Empathic Computing: Creating Shared Understanding
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Unlocking AI with Model Context Protocol (MCP)
MYSQL Presentation for SQL database connectivity
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Chapter 3 Spatial Domain Image Processing.pdf
Cloud computing and distributed systems.
Big Data Technologies - Introduction.pptx
Per capita expenditure prediction using model stacking based on satellite ima...
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Ad

GDB tutorial

  • 1. GDB - Tutorial c Anurag (anurag@gnuer.org) March 9, 2006 1 Starting and invoking gdb 1. Inserting debugging information inside the output executable
  • 2. les created after compilation and to start debugging session. $ gcc -o fact fact.c -g $ gdb fact 2. Giving shell commands from within gdb (gdb) shell clear 3. Set breakpoint at the function main() (gdb) break main 4. Delete break point number 1 (gdb) delete 1 Note: Pressing enter with no command executes the previous command 2 Running and navigating in gdb 1. Run program to be debugged (gdb) run 2. See where program stopped (gdb) list 3. Execute next line of the program (gdb) next (gdb) n 4. Step inside (gdb) step 1
  • 3. 5. Print stack trace (gdb) where (gdb) frame 0 (gdb) frame 1 6. Return back from function (gdb) return 7. Continue execution until the next break point. (gdb) continue 3 Retrieving values of variables 1. Display the value of a variable "i" (gdb) display i 2. Set hardware/software watch point for variable "i" (gdb) watch i 3. Print the value of variable "i" (gdb) print i 4. Print the address of variable "i" (gdb) print &i 5. Reassign a value to n (gdb) set variable n=6 (gdb) continue 6. Call fact() function with dierent parameters. (gdb) call fact(4) 7. Display the data type of a variable: (gdb) ptype i (gdb) whatis i 4 Segmentation faults 1. Segmentation faults Here we compile and execute a program with results in a segmentation fault. The snapshot of memory is saved in a
  • 4. le called core $ gcc -o demo demo.c -g 2
  • 5. $ gdb demo core (gdb) disassembly note: sethi = an assembly instruction A Made with L TEX 3