SlideShare une entreprise Scribd logo
1  sur  15
© Copyright 2013, wavedigitech.com.
Latest update: June 15, 2013,
http://www.wavedigitech.com/
Call us on : 91-9632839173
E-Mail : info@wavedigitech.com
E-mail: info@wavedigitech.com; http://www.wavedigitech.com Phone : 91-9632839173
Presentation on ARM Basics
E-mail: info@wavedigitech.com; http://www.wavedigitech.com Phone : 91-9632839173
Presentation on
GDB
Presentation on ARM Basics
E-mail: info@wavedigitech.com; http://www.wavedigitech.com Phone : 91-9632839173
The GNU Debugger, usually called just GDB it is a portable debugger that runs
on many Unix-like systems and works for many programming
languages, including Ada, C, C++, Objective-C, Free Pascal, Fortran, Java and
partially others.
GDB offers extensive facilities for tracing and altering the execution of
computer programs. The user can monitor and modify the values of programs'
internal variables, and even call functions independently of the program's
normal behavior.
Remote debugging
GDB offers a 'remote' mode often used when debugging embedded
systems. Remote operation is when GDB runs on one machine and the
program being debugged runs on another.
The GNU Debugger
Compiling for debugging
• We usually compile a program as
gcc [flags] <source files> -o <output file>
• A -g option is added to enable the built-in debugging support
(which gdb needs):
gcc [other flags] -g <source files> -o <output file>
Ex: gcc -Wall -Werror -ansi -pedantic-errors -g prog1.c -o prog1.x
E-mail: info@wavedigitech.com; http://www.wavedigitech.com Phone : 91-9632839173
Starting up gdb
• To get the gdb prompt, type “gdb”
• The program to be debugged now is loaded using
(gdb) file prog1.x
• Here, prog1.x is the program you want to load, and “file” is
the command to load it.
• To run the program, we use
(gdb) run
E-mail: info@wavedigitech.com; http://www.wavedigitech.com Phone : 91-9632839173
Setting breakpoints
• Breakpoints can be used to stop the program run in the middle,
at a designated point. The simplest way is the command
“break.” This sets a breakpoint at a specified file-line pair
(gdb) break file1.c:6
• This sets a breakpoint at line 6, of file1.c. Now, if the program
ever reaches that location when running, the program will
pause and prompt you for another command.
• To break at a particular function, we use
(gdb) break function
E-mail: info@wavedigitech.com; http://www.wavedigitech.com Phone : 91-9632839173
• We can proceed onto the next breakpoint by typing “continue”
(gdb) continue
• step Executes the current line of the program and stops on the next
statement to be executed
(gdb) step
• Like step, however, if the current line of the program contains a
function call, it executes the function and stops at the next line.
(gdb) next
• Until is like next, except that if you are at the end of a loop, until will
continue execution until the loop is exited, whereas next will just take
you back up to the beginning of the loop. This is convenient if you
want to see what happens after the loop, but don't want to step through
every iteration.
(gdb) until
E-mail: info@wavedigitech.com; http://www.wavedigitech.com Phone : 91-9632839173
Print and Watchpoints
• The print command prints the value of the variable specified, and
print/x prints the value in hexadecimal:
(gdb) print variable
(gdb) print/x variable
• We can also modify variables' values by
(gdb) set < variable > = <value>
• Whereas breakpoints interrupt the program at a particular line or
function, watchpoints act on variables. They pause the program
whenever a watched variable’s value is modified.
(gdb) watch variable
• Now, whenever my var’s value is modified, the program will
interrupt and print out the old and new values.
E-mail: info@wavedigitech.com; http://www.wavedigitech.com Phone : 91-9632839173
• backtrace - produces a stack trace of the function calls that
lead to a segmentation fault
• where - same as backtrace; you can think of this version as
working even when you’re still in the middle of the program
• finish - runs until the current function is finished
• delete N - deletes a specified N breakpoint
• info breakpoints - shows information about all declared
breakpoints
E-mail: info@wavedigitech.com; http://www.wavedigitech.com Phone : 91-9632839173
info commands for examining
runtime debugger state:
• gdb has a large set of info X commands for displaying information about
different types of runtime state and about debugger state. Here is how to list
all the info commands in help, and a description of what a few of the info
commands do:
• (gdb) help status lists a bunch of info X commands
• (gdb) info frame list information about the current stack
frame
• (gdb) info locals list local variable values of current stack
frame
• (gdb) info args list argument values of current stack frame
• (gdb) info registers list register values
• (gdb) info breakpoints list status of all breakpoints
E-mail: info@wavedigitech.com; http://www.wavedigitech.com Phone : 91-9632839173
.
• (gdb) up – Move to the function that called the present function. Useful if
your program crashes in a library function; use up to get to the last function
call in your program
• (gdb) down – Reverses the action of up
• (gdb) delete – Removes breakpoint by number (see example following). If
no number, all deleted.
• (gdb) kill – Terminates the program.
• (gdb) list – List 10 lines of the program being debugged. The sixth line is
the preset statement. Subsequent, consecutive entry of list will list the next
10 lines.
E-mail: info@wavedigitech.com; http://www.wavedigitech.com Phone : 91-9632839173
Breakpoints
• In this, we get to specify some criterion that must be met for
the breakpoint to trigger. We use the same break command as
before:
(gdb) break file1.c:6 if i >= ARRAYSIZE
• This command sets a breakpoint at line 6 of file file1.c, which
triggers only if the variable i is greater than or equal to the size
of the array
E-mail: info@wavedigitech.com; http://www.wavedigitech.com Phone : 91-9632839173
Using pointers with gdb
• Suppose we’re in gdb, and are at some point in the execution
after a line that looks like:
struct entry * e1 = <something>;
• To see the value (memory address) of the pointer:
(gdb) print e1
• To see a particular field of the struct the pointer is referencing:
(gdb) print e1->key
(gdb) print e1->name
(gdb) print e1->price
(gdb) print e1->serial number
E-mail: info@wavedigitech.com; http://www.wavedigitech.com Phone : 91-9632839173
• We can also use the dereference (*) and dot (.) operators in
place of the arrow operator (->):
(gdb) print (*e1).key
(gdb) print (*e1).name
(gdb) print (*e1).price
(gdb) print (*e1).serial number
• To see the entire contents of the struct the pointer references
(gdb) print *e1
E-mail: info@wavedigitech.com; http://www.wavedigitech.com Phone : 91-9632839173
Using pointers with gdb
Thank You
© Copyright 2013, wavedigitech.com.
Latest update: June 30, 2013,
http://www.wavedigitech.com/
Call us on : +91-91-9632839173
E-Mail : info@wavedigitech.com
E-mail: info@wavedigitech.com; http://www.wavedigitech.com Phone : 91-9632839173

Contenu connexe

Similaire à Wavedigitech gdb

Gdb tutorial-handout
Gdb tutorial-handoutGdb tutorial-handout
Gdb tutorial-handout
Suraj Kumar
 
gdb-tutorial.pdf
gdb-tutorial.pdfgdb-tutorial.pdf
gdb-tutorial.pdf
ligi14
 
Compiler design notes phases of compiler
Compiler design notes phases of compilerCompiler design notes phases of compiler
Compiler design notes phases of compiler
ovidlivi91
 

Similaire à Wavedigitech gdb (20)

GNU Debugger
GNU DebuggerGNU Debugger
GNU Debugger
 
Gnu debugger
Gnu debuggerGnu debugger
Gnu debugger
 
Gdb tutorial-handout
Gdb tutorial-handoutGdb tutorial-handout
Gdb tutorial-handout
 
gdb-tutorial.pdf
gdb-tutorial.pdfgdb-tutorial.pdf
gdb-tutorial.pdf
 
Debugging Modern C++ Application with Gdb
Debugging Modern C++ Application with GdbDebugging Modern C++ Application with Gdb
Debugging Modern C++ Application with Gdb
 
gdb.ppt
gdb.pptgdb.ppt
gdb.ppt
 
lab1-ppt.pdf
lab1-ppt.pdflab1-ppt.pdf
lab1-ppt.pdf
 
Advanced Debugging with GDB
Advanced Debugging with GDBAdvanced Debugging with GDB
Advanced Debugging with GDB
 
Uwaga na buga! GDB w służbie programisty. Barcamp Semihalf S09:E01
Uwaga na buga! GDB w służbie programisty.  Barcamp Semihalf S09:E01Uwaga na buga! GDB w służbie programisty.  Barcamp Semihalf S09:E01
Uwaga na buga! GDB w służbie programisty. Barcamp Semihalf S09:E01
 
Introduction to gdb
Introduction to gdbIntroduction to gdb
Introduction to gdb
 
Process (OS),GNU,Introduction to Linux oS
Process (OS),GNU,Introduction to Linux oSProcess (OS),GNU,Introduction to Linux oS
Process (OS),GNU,Introduction to Linux oS
 
Compiler design notes phases of compiler
Compiler design notes phases of compilerCompiler design notes phases of compiler
Compiler design notes phases of compiler
 
Debugging of (C)Python applications
Debugging of (C)Python applicationsDebugging of (C)Python applications
Debugging of (C)Python applications
 
Debugging Applications with GNU Debugger
Debugging Applications with GNU DebuggerDebugging Applications with GNU Debugger
Debugging Applications with GNU Debugger
 
Debuging like a pro
Debuging like a proDebuging like a pro
Debuging like a pro
 
Gccgdb
GccgdbGccgdb
Gccgdb
 
05-Debug.pdf
05-Debug.pdf05-Debug.pdf
05-Debug.pdf
 
Computer Graphics - Lecture 01 - 3D Programming I
Computer Graphics - Lecture 01 - 3D Programming IComputer Graphics - Lecture 01 - 3D Programming I
Computer Graphics - Lecture 01 - 3D Programming I
 
Python Programming Essentials - M28 - Debugging with pdb
Python Programming Essentials - M28 - Debugging with pdbPython Programming Essentials - M28 - Debugging with pdb
Python Programming Essentials - M28 - Debugging with pdb
 
C tutorials
C tutorialsC tutorials
C tutorials
 

Plus de Wave Digitech

Plus de Wave Digitech (17)

54 sms based irrigation system
54 sms based irrigation system54 sms based irrigation system
54 sms based irrigation system
 
54 a automatic irrigation system
54 a automatic irrigation system54 a automatic irrigation system
54 a automatic irrigation system
 
Implementation of solar illumination system with three-stage charging and dim...
Implementation of solar illumination system with three-stage charging and dim...Implementation of solar illumination system with three-stage charging and dim...
Implementation of solar illumination system with three-stage charging and dim...
 
Zl embd045 wireless telemedia system based on arm and web server
Zl embd045 wireless telemedia system based on arm and web serverZl embd045 wireless telemedia system based on arm and web server
Zl embd045 wireless telemedia system based on arm and web server
 
Zl embd029 arm and rfid based event management monitoring system
Zl embd029 arm and rfid based event management monitoring systemZl embd029 arm and rfid based event management monitoring system
Zl embd029 arm and rfid based event management monitoring system
 
Arm
ArmArm
Arm
 
8051
80518051
8051
 
Projects wavedigitech-2013
Projects wavedigitech-2013Projects wavedigitech-2013
Projects wavedigitech-2013
 
Unix Linux Commands Presentation 2013
Unix Linux Commands Presentation 2013Unix Linux Commands Presentation 2013
Unix Linux Commands Presentation 2013
 
Difference bw android4.2 to android 4.3
Difference bw android4.2 to android 4.3Difference bw android4.2 to android 4.3
Difference bw android4.2 to android 4.3
 
Unix Process management
Unix Process managementUnix Process management
Unix Process management
 
U-Boot presentation 2013
U-Boot presentation  2013U-Boot presentation  2013
U-Boot presentation 2013
 
Android debug bridge
Android debug bridgeAndroid debug bridge
Android debug bridge
 
Useful Linux and Unix commands handbook
Useful Linux and Unix commands handbookUseful Linux and Unix commands handbook
Useful Linux and Unix commands handbook
 
Wavedigitech training-broucher-june2013
Wavedigitech training-broucher-june2013Wavedigitech training-broucher-june2013
Wavedigitech training-broucher-june2013
 
Wavedigitech presentation-2013-v1
Wavedigitech presentation-2013-v1Wavedigitech presentation-2013-v1
Wavedigitech presentation-2013-v1
 
Wavedigitech presentation-2013
Wavedigitech presentation-2013Wavedigitech presentation-2013
Wavedigitech presentation-2013
 

Dernier

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 

Dernier (20)

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 

Wavedigitech gdb

  • 1. © Copyright 2013, wavedigitech.com. Latest update: June 15, 2013, http://www.wavedigitech.com/ Call us on : 91-9632839173 E-Mail : info@wavedigitech.com E-mail: info@wavedigitech.com; http://www.wavedigitech.com Phone : 91-9632839173
  • 2. Presentation on ARM Basics E-mail: info@wavedigitech.com; http://www.wavedigitech.com Phone : 91-9632839173 Presentation on GDB
  • 3. Presentation on ARM Basics E-mail: info@wavedigitech.com; http://www.wavedigitech.com Phone : 91-9632839173 The GNU Debugger, usually called just GDB it is a portable debugger that runs on many Unix-like systems and works for many programming languages, including Ada, C, C++, Objective-C, Free Pascal, Fortran, Java and partially others. GDB offers extensive facilities for tracing and altering the execution of computer programs. The user can monitor and modify the values of programs' internal variables, and even call functions independently of the program's normal behavior. Remote debugging GDB offers a 'remote' mode often used when debugging embedded systems. Remote operation is when GDB runs on one machine and the program being debugged runs on another. The GNU Debugger
  • 4. Compiling for debugging • We usually compile a program as gcc [flags] <source files> -o <output file> • A -g option is added to enable the built-in debugging support (which gdb needs): gcc [other flags] -g <source files> -o <output file> Ex: gcc -Wall -Werror -ansi -pedantic-errors -g prog1.c -o prog1.x E-mail: info@wavedigitech.com; http://www.wavedigitech.com Phone : 91-9632839173
  • 5. Starting up gdb • To get the gdb prompt, type “gdb” • The program to be debugged now is loaded using (gdb) file prog1.x • Here, prog1.x is the program you want to load, and “file” is the command to load it. • To run the program, we use (gdb) run E-mail: info@wavedigitech.com; http://www.wavedigitech.com Phone : 91-9632839173
  • 6. Setting breakpoints • Breakpoints can be used to stop the program run in the middle, at a designated point. The simplest way is the command “break.” This sets a breakpoint at a specified file-line pair (gdb) break file1.c:6 • This sets a breakpoint at line 6, of file1.c. Now, if the program ever reaches that location when running, the program will pause and prompt you for another command. • To break at a particular function, we use (gdb) break function E-mail: info@wavedigitech.com; http://www.wavedigitech.com Phone : 91-9632839173
  • 7. • We can proceed onto the next breakpoint by typing “continue” (gdb) continue • step Executes the current line of the program and stops on the next statement to be executed (gdb) step • Like step, however, if the current line of the program contains a function call, it executes the function and stops at the next line. (gdb) next • Until is like next, except that if you are at the end of a loop, until will continue execution until the loop is exited, whereas next will just take you back up to the beginning of the loop. This is convenient if you want to see what happens after the loop, but don't want to step through every iteration. (gdb) until E-mail: info@wavedigitech.com; http://www.wavedigitech.com Phone : 91-9632839173
  • 8. Print and Watchpoints • The print command prints the value of the variable specified, and print/x prints the value in hexadecimal: (gdb) print variable (gdb) print/x variable • We can also modify variables' values by (gdb) set < variable > = <value> • Whereas breakpoints interrupt the program at a particular line or function, watchpoints act on variables. They pause the program whenever a watched variable’s value is modified. (gdb) watch variable • Now, whenever my var’s value is modified, the program will interrupt and print out the old and new values. E-mail: info@wavedigitech.com; http://www.wavedigitech.com Phone : 91-9632839173
  • 9. • backtrace - produces a stack trace of the function calls that lead to a segmentation fault • where - same as backtrace; you can think of this version as working even when you’re still in the middle of the program • finish - runs until the current function is finished • delete N - deletes a specified N breakpoint • info breakpoints - shows information about all declared breakpoints E-mail: info@wavedigitech.com; http://www.wavedigitech.com Phone : 91-9632839173
  • 10. info commands for examining runtime debugger state: • gdb has a large set of info X commands for displaying information about different types of runtime state and about debugger state. Here is how to list all the info commands in help, and a description of what a few of the info commands do: • (gdb) help status lists a bunch of info X commands • (gdb) info frame list information about the current stack frame • (gdb) info locals list local variable values of current stack frame • (gdb) info args list argument values of current stack frame • (gdb) info registers list register values • (gdb) info breakpoints list status of all breakpoints E-mail: info@wavedigitech.com; http://www.wavedigitech.com Phone : 91-9632839173
  • 11. . • (gdb) up – Move to the function that called the present function. Useful if your program crashes in a library function; use up to get to the last function call in your program • (gdb) down – Reverses the action of up • (gdb) delete – Removes breakpoint by number (see example following). If no number, all deleted. • (gdb) kill – Terminates the program. • (gdb) list – List 10 lines of the program being debugged. The sixth line is the preset statement. Subsequent, consecutive entry of list will list the next 10 lines. E-mail: info@wavedigitech.com; http://www.wavedigitech.com Phone : 91-9632839173
  • 12. Breakpoints • In this, we get to specify some criterion that must be met for the breakpoint to trigger. We use the same break command as before: (gdb) break file1.c:6 if i >= ARRAYSIZE • This command sets a breakpoint at line 6 of file file1.c, which triggers only if the variable i is greater than or equal to the size of the array E-mail: info@wavedigitech.com; http://www.wavedigitech.com Phone : 91-9632839173
  • 13. Using pointers with gdb • Suppose we’re in gdb, and are at some point in the execution after a line that looks like: struct entry * e1 = <something>; • To see the value (memory address) of the pointer: (gdb) print e1 • To see a particular field of the struct the pointer is referencing: (gdb) print e1->key (gdb) print e1->name (gdb) print e1->price (gdb) print e1->serial number E-mail: info@wavedigitech.com; http://www.wavedigitech.com Phone : 91-9632839173
  • 14. • We can also use the dereference (*) and dot (.) operators in place of the arrow operator (->): (gdb) print (*e1).key (gdb) print (*e1).name (gdb) print (*e1).price (gdb) print (*e1).serial number • To see the entire contents of the struct the pointer references (gdb) print *e1 E-mail: info@wavedigitech.com; http://www.wavedigitech.com Phone : 91-9632839173 Using pointers with gdb
  • 15. Thank You © Copyright 2013, wavedigitech.com. Latest update: June 30, 2013, http://www.wavedigitech.com/ Call us on : +91-91-9632839173 E-Mail : info@wavedigitech.com E-mail: info@wavedigitech.com; http://www.wavedigitech.com Phone : 91-9632839173