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
Sergey Ilinsky
 
PDF
Open GL Programming Training Session I
NEEVEE Technologies
 
PPTX
Brief GAUT tutorial
Daniel Gomez-Prado
 
PPTX
Equipment 'Time Away Theory' in the opencut coal mining industry
Totius Mining
 
PDF
ECMAScript 2017
max peng
 
PPT
Measuring SGX Texturing Performance
Prabindh Sundareson
 
PDF
Formalising Graph Pattern Matching Gremlin traversals in Graph Alegra
Harsh Thakkar
 
PPTX
Performance in Geode: How Fast Is It, How Is It Measured, and How Can It Be I...
VMware Tanzu
 
Extreme JavaScript Minification and Obfuscation
Sergey Ilinsky
 
Open GL Programming Training Session I
NEEVEE Technologies
 
Brief GAUT tutorial
Daniel Gomez-Prado
 
Equipment 'Time Away Theory' in the opencut coal mining industry
Totius Mining
 
ECMAScript 2017
max peng
 
Measuring SGX Texturing Performance
Prabindh Sundareson
 
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...
VMware Tanzu
 

Similar to GDB tutorial (20)

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

Recently uploaded (20)

PDF
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
PDF
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
PPTX
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
PPTX
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
PDF
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
PDF
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
OFFOFFBOX™ – A New Era for African Film | Startup Presentation
ambaicciwalkerbrian
 
PDF
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
PDF
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
PDF
Get More from Fiori Automation - What’s New, What Works, and What’s Next.pdf
Precisely
 
PPTX
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
PPTX
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
PPTX
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
PDF
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
PDF
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
PDF
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
PDF
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
PPTX
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
OFFOFFBOX™ – A New Era for African Film | Startup Presentation
ambaicciwalkerbrian
 
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
Get More from Fiori Automation - What’s New, What Works, and What’s Next.pdf
Precisely
 
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
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