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
Ad

Recommended

Extreme JavaScript Minification and Obfuscation
Extreme JavaScript Minification and Obfuscation
Sergey Ilinsky
 
Open GL Programming Training Session I
Open GL Programming Training Session I
NEEVEE Technologies
 
Brief GAUT tutorial
Brief GAUT tutorial
Daniel Gomez-Prado
 
Equipment 'Time Away Theory' in the opencut coal mining industry
Equipment 'Time Away Theory' in the opencut coal mining industry
Totius Mining
 
ECMAScript 2017
ECMAScript 2017
max peng
 
Measuring SGX Texturing Performance
Measuring SGX Texturing Performance
Prabindh Sundareson
 
Formalising Graph Pattern Matching Gremlin traversals in Graph Alegra
Formalising Graph Pattern Matching Gremlin traversals in Graph Alegra
Harsh Thakkar
 
Performance in Geode: How Fast Is It, How Is It Measured, and How Can It Be I...
Performance in Geode: How Fast Is It, How Is It Measured, and How Can It Be I...
VMware Tanzu
 
gdb-tutorial.pdf
gdb-tutorial.pdf
ligi14
 
Gdb tutorial-handout
Gdb tutorial-handout
Suraj Kumar
 
Usage of GDB
Usage of GDB
Jongseok Choi
 
Debugging Applications with GNU Debugger
Debugging Applications with GNU Debugger
Priyank Kapadia
 
lab1-ppt.pdf
lab1-ppt.pdf
AbdelrahmanElewah1
 
Advanced Debugging with GDB
Advanced Debugging with GDB
David Khosid
 
GDB Rocks!
GDB Rocks!
Kent Chen
 
Introduction to gdb
Introduction to gdb
Owen Hsu
 
Writing mruby Debugger
Writing mruby Debugger
yamanekko
 
Debug JNI code with ndk-gdb and eclipse GUI
Debug JNI code with ndk-gdb and eclipse GUI
Tom Chen
 
Debugging Modern C++ Application with Gdb
Debugging Modern C++ Application with Gdb
SenthilKumar Selvaraj
 
Debuging like a pro
Debuging like a pro
Vicente Bolea
 
Gccgdb
Gccgdb
selva raj
 
Отладка в GDB
Отладка в GDB
Anthony Shoumikhin
 
GNU Debugger
GNU Debugger
Gizem Çetin
 
Gnu debugger
Gnu debugger
Gizem Çetin
 
ELC-E Linux Awareness
ELC-E Linux Awareness
Peter Griffin
 
HKG15-207: Advanced Toolchain Usage Part 3
HKG15-207: Advanced Toolchain Usage Part 3
Linaro
 
HKG15-211: Advanced Toolchain Usage Part 4
HKG15-211: Advanced Toolchain Usage Part 4
Linaro
 
05-Debug.pdf
05-Debug.pdf
KalaiselviDevaraj
 
Information Security Response Team Nepal_npCERT_Vice_President_Sudan_Jha.pdf
Information Security Response Team Nepal_npCERT_Vice_President_Sudan_Jha.pdf
ICT Frame Magazine Pvt. Ltd.
 
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Safe Software
 

More Related Content

Similar to GDB tutorial (20)

gdb-tutorial.pdf
gdb-tutorial.pdf
ligi14
 
Gdb tutorial-handout
Gdb tutorial-handout
Suraj Kumar
 
Usage of GDB
Usage of GDB
Jongseok Choi
 
Debugging Applications with GNU Debugger
Debugging Applications with GNU Debugger
Priyank Kapadia
 
lab1-ppt.pdf
lab1-ppt.pdf
AbdelrahmanElewah1
 
Advanced Debugging with GDB
Advanced Debugging with GDB
David Khosid
 
GDB Rocks!
GDB Rocks!
Kent Chen
 
Introduction to gdb
Introduction to gdb
Owen Hsu
 
Writing mruby Debugger
Writing mruby Debugger
yamanekko
 
Debug JNI code with ndk-gdb and eclipse GUI
Debug JNI code with ndk-gdb and eclipse GUI
Tom Chen
 
Debugging Modern C++ Application with Gdb
Debugging Modern C++ Application with Gdb
SenthilKumar Selvaraj
 
Debuging like a pro
Debuging like a pro
Vicente Bolea
 
Gccgdb
Gccgdb
selva raj
 
Отладка в GDB
Отладка в GDB
Anthony Shoumikhin
 
GNU Debugger
GNU Debugger
Gizem Çetin
 
Gnu debugger
Gnu debugger
Gizem Çetin
 
ELC-E Linux Awareness
ELC-E Linux Awareness
Peter Griffin
 
HKG15-207: Advanced Toolchain Usage Part 3
HKG15-207: Advanced Toolchain Usage Part 3
Linaro
 
HKG15-211: Advanced Toolchain Usage Part 4
HKG15-211: Advanced Toolchain Usage Part 4
Linaro
 
05-Debug.pdf
05-Debug.pdf
KalaiselviDevaraj
 
gdb-tutorial.pdf
gdb-tutorial.pdf
ligi14
 
Gdb tutorial-handout
Gdb tutorial-handout
Suraj Kumar
 
Debugging Applications with GNU Debugger
Debugging Applications with GNU Debugger
Priyank Kapadia
 
Advanced Debugging with GDB
Advanced Debugging with GDB
David Khosid
 
Introduction to gdb
Introduction to gdb
Owen Hsu
 
Writing mruby Debugger
Writing mruby Debugger
yamanekko
 
Debug JNI code with ndk-gdb and eclipse GUI
Debug JNI code with ndk-gdb and eclipse GUI
Tom Chen
 
Debugging Modern C++ Application with Gdb
Debugging Modern C++ Application with Gdb
SenthilKumar Selvaraj
 
ELC-E Linux Awareness
ELC-E Linux Awareness
Peter Griffin
 
HKG15-207: Advanced Toolchain Usage Part 3
HKG15-207: Advanced Toolchain Usage Part 3
Linaro
 
HKG15-211: Advanced Toolchain Usage Part 4
HKG15-211: Advanced Toolchain Usage Part 4
Linaro
 

Recently uploaded (20)

Information Security Response Team Nepal_npCERT_Vice_President_Sudan_Jha.pdf
Information Security Response Team Nepal_npCERT_Vice_President_Sudan_Jha.pdf
ICT Frame Magazine Pvt. Ltd.
 
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Safe Software
 
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
biswajitbanerjee38
 
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
Fwdays
 
Using the SQLExecutor for Data Quality Management: aka One man's love for the...
Using the SQLExecutor for Data Quality Management: aka One man's love for the...
Safe Software
 
Powering Multi-Page Web Applications Using Flow Apps and FME Data Streaming
Powering Multi-Page Web Applications Using Flow Apps and FME Data Streaming
Safe Software
 
UserCon Belgium: Honey, VMware increased my bill
UserCon Belgium: Honey, VMware increased my bill
stijn40
 
OWASP Barcelona 2025 Threat Model Library
OWASP Barcelona 2025 Threat Model Library
PetraVukmirovic
 
Cluster-Based Multi-Objective Metamorphic Test Case Pair Selection for Deep N...
Cluster-Based Multi-Objective Metamorphic Test Case Pair Selection for Deep N...
janeliewang985
 
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance
 
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Alliance
 
Curietech AI in action - Accelerate MuleSoft development
Curietech AI in action - Accelerate MuleSoft development
shyamraj55
 
You are not excused! How to avoid security blind spots on the way to production
You are not excused! How to avoid security blind spots on the way to production
Michele Leroux Bustamante
 
Coordinated Disclosure for ML - What's Different and What's the Same.pdf
Coordinated Disclosure for ML - What's Different and What's the Same.pdf
Priyanka Aash
 
Security Tips for Enterprise Azure Solutions
Security Tips for Enterprise Azure Solutions
Michele Leroux Bustamante
 
Cyber Defense Matrix Workshop - RSA Conference
Cyber Defense Matrix Workshop - RSA Conference
Priyanka Aash
 
Lessons Learned from Developing Secure AI Workflows.pdf
Lessons Learned from Developing Secure AI Workflows.pdf
Priyanka Aash
 
Securing AI - There Is No Try, Only Do!.pdf
Securing AI - There Is No Try, Only Do!.pdf
Priyanka Aash
 
The Future of Technology: 2025-2125 by Saikat Basu.pdf
The Future of Technology: 2025-2125 by Saikat Basu.pdf
Saikat Basu
 
PyCon SG 25 - Firecracker Made Easy with Python.pdf
PyCon SG 25 - Firecracker Made Easy with Python.pdf
Muhammad Yuga Nugraha
 
Information Security Response Team Nepal_npCERT_Vice_President_Sudan_Jha.pdf
Information Security Response Team Nepal_npCERT_Vice_President_Sudan_Jha.pdf
ICT Frame Magazine Pvt. Ltd.
 
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Safe Software
 
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
biswajitbanerjee38
 
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
Fwdays
 
Using the SQLExecutor for Data Quality Management: aka One man's love for the...
Using the SQLExecutor for Data Quality Management: aka One man's love for the...
Safe Software
 
Powering Multi-Page Web Applications Using Flow Apps and FME Data Streaming
Powering Multi-Page Web Applications Using Flow Apps and FME Data Streaming
Safe Software
 
UserCon Belgium: Honey, VMware increased my bill
UserCon Belgium: Honey, VMware increased my bill
stijn40
 
OWASP Barcelona 2025 Threat Model Library
OWASP Barcelona 2025 Threat Model Library
PetraVukmirovic
 
Cluster-Based Multi-Objective Metamorphic Test Case Pair Selection for Deep N...
Cluster-Based Multi-Objective Metamorphic Test Case Pair Selection for Deep N...
janeliewang985
 
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance
 
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Alliance
 
Curietech AI in action - Accelerate MuleSoft development
Curietech AI in action - Accelerate MuleSoft development
shyamraj55
 
You are not excused! How to avoid security blind spots on the way to production
You are not excused! How to avoid security blind spots on the way to production
Michele Leroux Bustamante
 
Coordinated Disclosure for ML - What's Different and What's the Same.pdf
Coordinated Disclosure for ML - What's Different and What's the Same.pdf
Priyanka Aash
 
Security Tips for Enterprise Azure Solutions
Security Tips for Enterprise Azure Solutions
Michele Leroux Bustamante
 
Cyber Defense Matrix Workshop - RSA Conference
Cyber Defense Matrix Workshop - RSA Conference
Priyanka Aash
 
Lessons Learned from Developing Secure AI Workflows.pdf
Lessons Learned from Developing Secure AI Workflows.pdf
Priyanka Aash
 
Securing AI - There Is No Try, Only Do!.pdf
Securing AI - There Is No Try, Only Do!.pdf
Priyanka Aash
 
The Future of Technology: 2025-2125 by Saikat Basu.pdf
The Future of Technology: 2025-2125 by Saikat Basu.pdf
Saikat Basu
 
PyCon SG 25 - Firecracker Made Easy with Python.pdf
PyCon SG 25 - Firecracker Made Easy with Python.pdf
Muhammad Yuga Nugraha
 
Ad

GDB tutorial

  • 1. GDB - Tutorial c Anurag ([email protected]) 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