SlideShare a Scribd company logo
GNU DEBUGGER / GDB
OPERATING SYSTEMS
AGH UNIVERSITY SCIENCE AND TECHNOLOGY
What is Debugger?
• A debugger is a program that is used to test and debug
other programs.
There are many ways to do debugging such as
• printing out messages to the screen using a debugger
• just thinking about what the program is doing and
making an educated guess as to what the problem is.
WHAT IS DEBUGGER?
• Step by step running of program
• Stopping debugging when
program encounter a breakpoint
• Tracking values of variables.
• Debugging while program is
running.
Debuggers
have
functions
like
BASIC FUNCTIONS OF DEBUGGER
• To learn which statement or expression causes a error
• To specify which line/lines contains error
• To learn the instant values of variables at particular point during
execution of program.
• To learn result of program at particular point
• To learn execution sequence of statements in a program.
What is GDB?
GNU Debugger which is also known as GDB is debugger for GNU operating system
that provides to see and distunguish the errors inside of computer program while
the program executes.
History of GDB
• Written by Richard Stallman
in 1986.
• Developed by John Gilmore
between 1990 and 1993.
• Now maintained by GDB
Steering Committee which is
part of Free Software
Foundation.
Mascot of GDB
FEATURES OF GDB
GDB has mainly 4 functionality to find bugs in program
• GDB can specify any thread in program which might affect program’s
behavior
• User can monitor and modify values of programs’ variables
• GDB can be stop your program in specific conditions.
• GDB can check and analyze all program when program stops.
• GDB can correct bugs in program after detecting it.
USAGE AREAS OF GDB
• GDB is not only used in GNU operating system but also use like
portable debugger which runs Unix-like systems. GDB can run on
UNIX and Microsoft Windows systems
GDB Works for
• Ada
• C++
• C
• Objective C
• Pascal languages
TECHNICAL DETAILS
Main Target Processors of GDB
• Alpha
• ARM
• AVR
• H8/300
• System/370
• System/390
• x86 / x86-64
• Motorola 68000
• PowerPC
• GDB is actively developing and
New versions are releasing
periodically. With version 7.0
It supports ‘reverse
debugging’.
• Reverse debugging in gdb
means gdb can allow you to
"step" or "continue" your
program backward in time,
reverting it to an earlier
execution state.
REMOTE DEBUGGING
Remote operation is when GDB runs on one machine and the program being
debugged runs on another.
• For example, you might use remote debugging on an operating system
kernel or on a another system which does not have a general purpose
operating system powerful enough to run a full featured debugger.
If you want to remote debugging there are 5 stages that you can do
1. Connecting: Connecting to a remote target
2. File Transfer: Sending files to a remote system
3. Server: Using the gdbserver program
4. Remote Configuration: Remote configuration
5. Remote Stub: Implementing a remote stub
REMOTE DEBUGGING
1. Connecting
GDB can communicate with the target over a serial line, or over an IP network
using TCP or UDP. In each case, gdb uses the same protocol for debugging your
program.The target remote command establishes a connection to the target.
For example, to connect to port 8080 on a terminal server named webpages:
target remote webpages:8080
Disconnecting:
The disconnect command disconnects the connection with remote target. After
this command gdb is free to connect another target.
REMOTE DEBUGGING
2. File Transfer
Commands for sending to remote system:
remote put hostfile targetfile:
Copy file hostfile from the host system to targetfile on the target system.
remote get targetfile hostfile:
Copy file targetfile from the target system to hostfile on the host system.
remote delete targetfile:
Delete targetfile from the target system.
REMOTE DEBUGGING
3. Server
• gdbserver is a control program for Unix-like systems, which allows you to
connect your program with a remote gdb via target remote but without
linking in the usual debugging stub.
• To use the server, you must tell it how to communicate with gdb; the
name of your program; and the arguments for your program. The usual
syntax is:
target> gdbserver comm program [ args ... ]
REMOTE DEBUGGING
4. Remote Configuration
Remote Configuration commands show configuration options available when
debugging remote programs.
set remoteaddresssize bits:
Set the maximum size of address in a memory packet to the specified number of
bits.
show remoteaddresssize:
Show the current value of remote address size in bits.
REMOTE DEBUGGING
• 5. Remote Stub
• The stub files provided with gdb implement the target side of the communication protocol, and
the gdb side is implemented in the gdb source file for example in remote.c
• The debugging stub is specific to the architecture of the remote machine; for example, use
sparc-stub.c to debug programs on sparc boards.
• These working remote stubs are distributed with gdb:
• i386-stub.c
• For Intel 386 and compatible architectures.
• m68k-stub.c
• For Motorola 680x0 architectures.
FEATURES OF GDB
GDB uses command line interface.
GDB has 3 feature which are commonly used:
1. Compiling
2. Invoking and Quitting GDB
3. Commands
COMPILING
To prepare program for
debugging with gdb, it must be
compiled it with the -g flag. So,
if your program is in a source
file called gizem.cpp and you
want to put the executable in
the file gizem;
$ g++ -g gizem.cpp
$ gdb ./a.out
$ (gdb) run
GCC’s C++ Compiler
The g++ compiler accepts both single-letter options, such as -o, and
multiletter options, such as -ansi. Because it accepts both types of options
you cannot group multiple single-letter options together, as you may be
used to doing in many GNU and Unix/Linux programs.
• For example, the multiletter option -pg is not the same as the two
single-letter options -p -g. The -pg option creates extra code in the final
binary that outputs profile information for the GNU code profiler, gprof.
On the other hand, the -p -g options generate extra code in the resulting
binary that produces profiling information for use by the prof code
profiler (-p) and causes gcc to generate debugging information using the
operating system’s normal format (-g).
COMPILING AND RUNNING PROGRAM
C++ CODE EXAMPLE
• $ g++ -g gizem.cpp:
Command for compiling source file. Invoke g++ passing name of the source file.
–g flag used in order to include appropriate debug information on the binary
generated.
• $ gdb ./a.out:
Result on Linux and Unix systems generates executable file named a.out in the
current directory. We can execute this executable file by typing ./a.out
• $ (gdb) run:
You can run the program by typing run. Program runs with current arguments.
GCC’s C++ Compiler
Despite its sensitivity to the grouping of multiple single-letter options, you are generally free to
mix the order of options and compiler arguments on the gcc command line.
$ g++ example.cpp -g –o example = $ g++ -g –o gcc example.cpp example
• g++: compiler is for c++ language.
• example.cpp: Source file name of c++ code
• -g: Flag of Compiling for given source file
• -o: Flag for specifying the name of the output file. The executable will be named a.out unless you
use this option.
• example: Output file name
./example
This command used to execute output of compiled program. After executing this code output of
program can be seen.
COMPILING C CODE
• Compiling a single source file, add.c, using gcc is easy—just invoke gcc, passing the
name of the source file as the argument.
$ gcc add.c
$ ./a.out
• To define the name of output file that gcc produces, -o option can be used as in c++
mode.
$gcc add.c –o output
$./output
• If you are compiling multiple source files using gcc, you can simply specify them all on
the gcc command line, as in the following example, which leaves the compiled and
linked executable in the file named addition.
$gcc add.c helper.c –o addition
./addition
COMPILING C CODE
Example of executing predefined named output and executing default output.
Debugging
Debugging program named
broken.cpp with logical error:
After completing compile and
execute processes of program in
order to start to debugger using
output file named broken:
$ gdb broken
To set breakpoint at specific line
we can use b command and
number of line
(gdb) b 43
Debugging
• After setting breakpoints, we start to run program in debugger with;
(gdb) run
• Now program runs and ask us for input after entering inputs of program,
program execution stops at first breakpoint.
Debugging
• If we want to investigate function’s inside where program stopped executing at
breakpoint, we can step into function’s inside with
(gdb) step
• Program controls it’s first statement of the function ComputeSeriesValue (x=2,
n=3)
Debugging
• To continue to debug program we can
use some specific commands such as
(gdb) next
• Next command is similar to step
command except it will step over
functions and also we can use n and s
instead of next and step respectively.
(gdb) n
(gdb) s
• If the command is simply a repeat of the
previous command, you can just hit
return, which will execute the last
command.
(gdb)
Debugging
• If you want to know where you are in the program's execution you
can view the contents of the stack using the backtrace command.
(gdb) bt
Debugging
• We can step through the program and examine the values using the print
command.
• The print command reveals that the value of fact variable never
changes. Note that the function is returning a value of 0 for the
function call ComputeFactorial(number=0). This is an ERROR.
Debugging program with Floating Point exception
error
After debugging program and executing it we see that program has
floating point exception error.
Debugging program with Floating Point exception
error
This means problems occur in line 17 and in return a/b expression.
Invoking and Quitting GDB
To start gdb, just type gdb at the unix prompt. Gdb will give you a prompt that
looks like this:
We can quit GDB using quit command
(gdb) quit
COMMANDS
• Help
• File
• Run
• Break
• Delete
• Clear
• Continue
• Step
• Next
• Until
• List
• print
THANKS FOR LISTENING

More Related Content

PDF
GoLang Introduction
PDF
Git best practices workshop
PPTX
Introduction to GoLang
KEY
Ch6 file, saving states, and preferences
PPTX
Introduction to Java
PDF
PDF
Android Components
PPTX
System Booting Process overview
GoLang Introduction
Git best practices workshop
Introduction to GoLang
Ch6 file, saving states, and preferences
Introduction to Java
Android Components
System Booting Process overview

What's hot (20)

PPTX
Golang (Go Programming Language)
PPTX
Introduction 2 linux
PPTX
Grokking opensource with github
PDF
BPF Internals (eBPF)
PPT
Learning AOSP - Android Booting Process
PDF
Understanding a kernel oops and a kernel panic
PDF
Embedded Android : System Development - Part IV
ODT
Testing in-python-and-pytest-framework
PDF
Linux systems - Linux Commands and Shell Scripting
PDF
Introduction to kotlin
PDF
CI/CD with Github Actions
PDF
An Introduction to the Android Framework -- a core architecture view from app...
PPT
Ipc in linux
PDF
Understanding the Android System Server
PDF
Kernel Recipes 2017 - Understanding the Linux kernel via ftrace - Steven Rostedt
PPTX
Basic malware analysis
PPTX
Introduction to go lang
ODP
Inter-process communication of Android
PDF
Introducing GitLab (June 2018)
PDF
Android Multimedia Support
Golang (Go Programming Language)
Introduction 2 linux
Grokking opensource with github
BPF Internals (eBPF)
Learning AOSP - Android Booting Process
Understanding a kernel oops and a kernel panic
Embedded Android : System Development - Part IV
Testing in-python-and-pytest-framework
Linux systems - Linux Commands and Shell Scripting
Introduction to kotlin
CI/CD with Github Actions
An Introduction to the Android Framework -- a core architecture view from app...
Ipc in linux
Understanding the Android System Server
Kernel Recipes 2017 - Understanding the Linux kernel via ftrace - Steven Rostedt
Basic malware analysis
Introduction to go lang
Inter-process communication of Android
Introducing GitLab (June 2018)
Android Multimedia Support
Ad

Viewers also liked (20)

PPT
Improving awareness pescador san diego air & space museum
PPT
Karakter akhlak islam
PPTX
Brain computer interface
PPTX
Show and Tell : Medium
PPTX
APLIC 2014 - Building a Technical Knowledge Hub: Applying library science to ...
PDF
Ijiret archana-kv-increasing-memory-performance-using-cache-optimizations-in-...
PDF
Ijirsm poornima-km-a-survey-on-security-circumstances-for-mobile-cloud-computing
PDF
Ijirsm ashok-kumar-ps-compulsiveness-of-res tful-web-services
PPTX
Sharing Promising Practices Internally and Externally: Lessons Learned from PCI
PPT
Final exam review game (5) (2)
PPTX
APLIC 2014 - Sharing IS the point
PPSX
La revolució del gessamí
PPTX
GNU Debugger
PPTX
APLIC 2014 - Social Observatories Coordinating Network
PPTX
Final exam review game
DOCX
Astrologer, Vastu & Fengshui consultant
PPTX
Adding value : the foundation on which to build community
PPTX
Dangers of facebook by sani
PPTX
Adding valuethroughdatacuration
PPTX
Terra Populus: Integrated Data on Population and Environment
Improving awareness pescador san diego air & space museum
Karakter akhlak islam
Brain computer interface
Show and Tell : Medium
APLIC 2014 - Building a Technical Knowledge Hub: Applying library science to ...
Ijiret archana-kv-increasing-memory-performance-using-cache-optimizations-in-...
Ijirsm poornima-km-a-survey-on-security-circumstances-for-mobile-cloud-computing
Ijirsm ashok-kumar-ps-compulsiveness-of-res tful-web-services
Sharing Promising Practices Internally and Externally: Lessons Learned from PCI
Final exam review game (5) (2)
APLIC 2014 - Sharing IS the point
La revolució del gessamí
GNU Debugger
APLIC 2014 - Social Observatories Coordinating Network
Final exam review game
Astrologer, Vastu & Fengshui consultant
Adding value : the foundation on which to build community
Dangers of facebook by sani
Adding valuethroughdatacuration
Terra Populus: Integrated Data on Population and Environment
Ad

Similar to Gnu debugger (20)

PPTX
Debugging Modern C++ Application with Gdb
PDF
gdb-tutorial.pdf
PPTX
Process (OS),GNU,Introduction to Linux oS
PDF
Gdb tutorial-handout
PDF
lab1-ppt.pdf
PPTX
G++ & GCC
PPT
Gccgdb
PDF
Debugging of (C)Python applications
PPTX
Wavedigitech gdb
PPTX
Advanced Debugging with GDB
PPT
gdb.ppt
PDF
Debugging embedded devices using GDB
PPTX
Extending GDB with Python
PDF
Introduction of Tools for providing rich user experience in debugger
PPTX
Mesa and Its Debugging
PDF
Mender.io | Develop embedded applications faster | Comparing C and Golang
PDF
Compiler design notes phases of compiler
PPTX
C++ language basic
PDF
Debugging Python with gdb
PPTX
Lab1GoBasicswithgo_foundationofgolang.pptx
Debugging Modern C++ Application with Gdb
gdb-tutorial.pdf
Process (OS),GNU,Introduction to Linux oS
Gdb tutorial-handout
lab1-ppt.pdf
G++ & GCC
Gccgdb
Debugging of (C)Python applications
Wavedigitech gdb
Advanced Debugging with GDB
gdb.ppt
Debugging embedded devices using GDB
Extending GDB with Python
Introduction of Tools for providing rich user experience in debugger
Mesa and Its Debugging
Mender.io | Develop embedded applications faster | Comparing C and Golang
Compiler design notes phases of compiler
C++ language basic
Debugging Python with gdb
Lab1GoBasicswithgo_foundationofgolang.pptx

Recently uploaded (20)

PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PDF
composite construction of structures.pdf
PPTX
web development for engineering and engineering
PPTX
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
PPTX
Sustainable Sites - Green Building Construction
PPT
Project quality management in manufacturing
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPTX
Internet of Things (IOT) - A guide to understanding
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PDF
PPT on Performance Review to get promotions
PPTX
Welding lecture in detail for understanding
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PDF
Well-logging-methods_new................
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PPT
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
composite construction of structures.pdf
web development for engineering and engineering
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
Sustainable Sites - Green Building Construction
Project quality management in manufacturing
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
Internet of Things (IOT) - A guide to understanding
Automation-in-Manufacturing-Chapter-Introduction.pdf
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PPT on Performance Review to get promotions
Welding lecture in detail for understanding
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
Well-logging-methods_new................
Model Code of Practice - Construction Work - 21102022 .pdf
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
Foundation to blockchain - A guide to Blockchain Tech
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
UNIT-1 - COAL BASED THERMAL POWER PLANTS

Gnu debugger

  • 1. GNU DEBUGGER / GDB OPERATING SYSTEMS AGH UNIVERSITY SCIENCE AND TECHNOLOGY
  • 2. What is Debugger? • A debugger is a program that is used to test and debug other programs. There are many ways to do debugging such as • printing out messages to the screen using a debugger • just thinking about what the program is doing and making an educated guess as to what the problem is.
  • 3. WHAT IS DEBUGGER? • Step by step running of program • Stopping debugging when program encounter a breakpoint • Tracking values of variables. • Debugging while program is running. Debuggers have functions like
  • 4. BASIC FUNCTIONS OF DEBUGGER • To learn which statement or expression causes a error • To specify which line/lines contains error • To learn the instant values of variables at particular point during execution of program. • To learn result of program at particular point • To learn execution sequence of statements in a program.
  • 5. What is GDB? GNU Debugger which is also known as GDB is debugger for GNU operating system that provides to see and distunguish the errors inside of computer program while the program executes.
  • 6. History of GDB • Written by Richard Stallman in 1986. • Developed by John Gilmore between 1990 and 1993. • Now maintained by GDB Steering Committee which is part of Free Software Foundation. Mascot of GDB
  • 7. FEATURES OF GDB GDB has mainly 4 functionality to find bugs in program • GDB can specify any thread in program which might affect program’s behavior • User can monitor and modify values of programs’ variables • GDB can be stop your program in specific conditions. • GDB can check and analyze all program when program stops. • GDB can correct bugs in program after detecting it.
  • 8. USAGE AREAS OF GDB • GDB is not only used in GNU operating system but also use like portable debugger which runs Unix-like systems. GDB can run on UNIX and Microsoft Windows systems GDB Works for • Ada • C++ • C • Objective C • Pascal languages
  • 9. TECHNICAL DETAILS Main Target Processors of GDB • Alpha • ARM • AVR • H8/300 • System/370 • System/390 • x86 / x86-64 • Motorola 68000 • PowerPC • GDB is actively developing and New versions are releasing periodically. With version 7.0 It supports ‘reverse debugging’. • Reverse debugging in gdb means gdb can allow you to "step" or "continue" your program backward in time, reverting it to an earlier execution state.
  • 10. REMOTE DEBUGGING Remote operation is when GDB runs on one machine and the program being debugged runs on another. • For example, you might use remote debugging on an operating system kernel or on a another system which does not have a general purpose operating system powerful enough to run a full featured debugger. If you want to remote debugging there are 5 stages that you can do 1. Connecting: Connecting to a remote target 2. File Transfer: Sending files to a remote system 3. Server: Using the gdbserver program 4. Remote Configuration: Remote configuration 5. Remote Stub: Implementing a remote stub
  • 11. REMOTE DEBUGGING 1. Connecting GDB can communicate with the target over a serial line, or over an IP network using TCP or UDP. In each case, gdb uses the same protocol for debugging your program.The target remote command establishes a connection to the target. For example, to connect to port 8080 on a terminal server named webpages: target remote webpages:8080 Disconnecting: The disconnect command disconnects the connection with remote target. After this command gdb is free to connect another target.
  • 12. REMOTE DEBUGGING 2. File Transfer Commands for sending to remote system: remote put hostfile targetfile: Copy file hostfile from the host system to targetfile on the target system. remote get targetfile hostfile: Copy file targetfile from the target system to hostfile on the host system. remote delete targetfile: Delete targetfile from the target system.
  • 13. REMOTE DEBUGGING 3. Server • gdbserver is a control program for Unix-like systems, which allows you to connect your program with a remote gdb via target remote but without linking in the usual debugging stub. • To use the server, you must tell it how to communicate with gdb; the name of your program; and the arguments for your program. The usual syntax is: target> gdbserver comm program [ args ... ]
  • 14. REMOTE DEBUGGING 4. Remote Configuration Remote Configuration commands show configuration options available when debugging remote programs. set remoteaddresssize bits: Set the maximum size of address in a memory packet to the specified number of bits. show remoteaddresssize: Show the current value of remote address size in bits.
  • 15. REMOTE DEBUGGING • 5. Remote Stub • The stub files provided with gdb implement the target side of the communication protocol, and the gdb side is implemented in the gdb source file for example in remote.c • The debugging stub is specific to the architecture of the remote machine; for example, use sparc-stub.c to debug programs on sparc boards. • These working remote stubs are distributed with gdb: • i386-stub.c • For Intel 386 and compatible architectures. • m68k-stub.c • For Motorola 680x0 architectures.
  • 16. FEATURES OF GDB GDB uses command line interface. GDB has 3 feature which are commonly used: 1. Compiling 2. Invoking and Quitting GDB 3. Commands
  • 17. COMPILING To prepare program for debugging with gdb, it must be compiled it with the -g flag. So, if your program is in a source file called gizem.cpp and you want to put the executable in the file gizem; $ g++ -g gizem.cpp $ gdb ./a.out $ (gdb) run
  • 18. GCC’s C++ Compiler The g++ compiler accepts both single-letter options, such as -o, and multiletter options, such as -ansi. Because it accepts both types of options you cannot group multiple single-letter options together, as you may be used to doing in many GNU and Unix/Linux programs. • For example, the multiletter option -pg is not the same as the two single-letter options -p -g. The -pg option creates extra code in the final binary that outputs profile information for the GNU code profiler, gprof. On the other hand, the -p -g options generate extra code in the resulting binary that produces profiling information for use by the prof code profiler (-p) and causes gcc to generate debugging information using the operating system’s normal format (-g).
  • 19. COMPILING AND RUNNING PROGRAM C++ CODE EXAMPLE • $ g++ -g gizem.cpp: Command for compiling source file. Invoke g++ passing name of the source file. –g flag used in order to include appropriate debug information on the binary generated. • $ gdb ./a.out: Result on Linux and Unix systems generates executable file named a.out in the current directory. We can execute this executable file by typing ./a.out • $ (gdb) run: You can run the program by typing run. Program runs with current arguments.
  • 20. GCC’s C++ Compiler Despite its sensitivity to the grouping of multiple single-letter options, you are generally free to mix the order of options and compiler arguments on the gcc command line. $ g++ example.cpp -g –o example = $ g++ -g –o gcc example.cpp example • g++: compiler is for c++ language. • example.cpp: Source file name of c++ code • -g: Flag of Compiling for given source file • -o: Flag for specifying the name of the output file. The executable will be named a.out unless you use this option. • example: Output file name ./example This command used to execute output of compiled program. After executing this code output of program can be seen.
  • 21. COMPILING C CODE • Compiling a single source file, add.c, using gcc is easy—just invoke gcc, passing the name of the source file as the argument. $ gcc add.c $ ./a.out • To define the name of output file that gcc produces, -o option can be used as in c++ mode. $gcc add.c –o output $./output • If you are compiling multiple source files using gcc, you can simply specify them all on the gcc command line, as in the following example, which leaves the compiled and linked executable in the file named addition. $gcc add.c helper.c –o addition ./addition
  • 22. COMPILING C CODE Example of executing predefined named output and executing default output.
  • 23. Debugging Debugging program named broken.cpp with logical error: After completing compile and execute processes of program in order to start to debugger using output file named broken: $ gdb broken To set breakpoint at specific line we can use b command and number of line (gdb) b 43
  • 24. Debugging • After setting breakpoints, we start to run program in debugger with; (gdb) run • Now program runs and ask us for input after entering inputs of program, program execution stops at first breakpoint.
  • 25. Debugging • If we want to investigate function’s inside where program stopped executing at breakpoint, we can step into function’s inside with (gdb) step • Program controls it’s first statement of the function ComputeSeriesValue (x=2, n=3)
  • 26. Debugging • To continue to debug program we can use some specific commands such as (gdb) next • Next command is similar to step command except it will step over functions and also we can use n and s instead of next and step respectively. (gdb) n (gdb) s • If the command is simply a repeat of the previous command, you can just hit return, which will execute the last command. (gdb)
  • 27. Debugging • If you want to know where you are in the program's execution you can view the contents of the stack using the backtrace command. (gdb) bt
  • 28. Debugging • We can step through the program and examine the values using the print command. • The print command reveals that the value of fact variable never changes. Note that the function is returning a value of 0 for the function call ComputeFactorial(number=0). This is an ERROR.
  • 29. Debugging program with Floating Point exception error After debugging program and executing it we see that program has floating point exception error.
  • 30. Debugging program with Floating Point exception error This means problems occur in line 17 and in return a/b expression.
  • 31. Invoking and Quitting GDB To start gdb, just type gdb at the unix prompt. Gdb will give you a prompt that looks like this: We can quit GDB using quit command (gdb) quit
  • 32. COMMANDS • Help • File • Run • Break • Delete • Clear • Continue • Step • Next • Until • List • print

Editor's Notes

  • #3: A debugger is a program that runs other programs, allowing its user to exercise some degree ofcontrol over these programs, and to examine them when things go amiss.
  • #7: GDB is free software released under the GNU General Public License (GPL). It was modeled after the DBX debugger, which came with Berkeley Unix distributions.
  • #11: GDBoffers us remotemodewhich is mostlyused in debuggingembeddedsystem.
  • #13: Host system: (themachinerunninggdb)
  • #15: set remoteaddresssize bits:gdb will mask off the address bits above that number, when it passes addresses to the remote target. The default value is the number of bits in the target's address
  • #18: then you would compile with the following command:
  • #27: (If we'd used next, it would have stepped over ComputeFactorial.)