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

What's hot

Git and github fundamentals
Git and github fundamentalsGit and github fundamentals
Git and github fundamentals
RajKharvar
 
Go Programming language, golang
Go Programming language, golangGo Programming language, golang
Go Programming language, golang
Basil N G
 
Introduction to Makefile
Introduction to MakefileIntroduction to Makefile
Introduction to Makefile
Zakaria El ktaoui
 
Git & Github for beginners
Git & Github for beginnersGit & Github for beginners
Git & Github for beginners
Paulo Henrique Nonaka
 
C Programming - Refresher - Part I
C Programming - Refresher - Part I C Programming - Refresher - Part I
C Programming - Refresher - Part I
Emertxe Information Technologies Pvt Ltd
 
Go lang
Go langGo lang
Linux programming - Getting self started
Linux programming - Getting self started Linux programming - Getting self started
Linux programming - Getting self started
Emertxe Information Technologies Pvt Ltd
 
BusyBox for Embedded Linux
BusyBox for Embedded LinuxBusyBox for Embedded Linux
BusyBox for Embedded Linux
Emertxe Information Technologies Pvt Ltd
 
Git 101: Git and GitHub for Beginners
Git 101: Git and GitHub for Beginners Git 101: Git and GitHub for Beginners
Git 101: Git and GitHub for Beginners
HubSpot
 
GCC RTL and Machine Description
GCC RTL and Machine DescriptionGCC RTL and Machine Description
GCC RTL and Machine Description
Priyatham Bollimpalli
 
GCC compiler
GCC compilerGCC compiler
GCC compiler
Anil Pokhrel
 
Working Remotely (via SSH) Rocks!
Working Remotely (via SSH) Rocks!Working Remotely (via SSH) Rocks!
Working Remotely (via SSH) Rocks!
Kent Chen
 
Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell Scripting
Raghu nath
 
Linux Programming
Linux ProgrammingLinux Programming
TMUX Rocks!
TMUX Rocks!TMUX Rocks!
TMUX Rocks!
Kent Chen
 
Advanced debugging  techniques in different environments
Advanced debugging  techniques in different environmentsAdvanced debugging  techniques in different environments
Advanced debugging  techniques in different environments
Andrii Soldatenko
 
The Go programming language - Intro by MyLittleAdventure
The Go programming language - Intro by MyLittleAdventureThe Go programming language - Intro by MyLittleAdventure
The Go programming language - Intro by MyLittleAdventure
mylittleadventure
 
Write microservice in golang
Write microservice in golangWrite microservice in golang
Write microservice in golang
Bo-Yi Wu
 

What's hot (20)

Git and github fundamentals
Git and github fundamentalsGit and github fundamentals
Git and github fundamentals
 
Go Programming language, golang
Go Programming language, golangGo Programming language, golang
Go Programming language, golang
 
Introduction to Makefile
Introduction to MakefileIntroduction to Makefile
Introduction to Makefile
 
Git & Github for beginners
Git & Github for beginnersGit & Github for beginners
Git & Github for beginners
 
C Programming - Refresher - Part I
C Programming - Refresher - Part I C Programming - Refresher - Part I
C Programming - Refresher - Part I
 
Go lang
Go langGo lang
Go lang
 
Linux programming - Getting self started
Linux programming - Getting self started Linux programming - Getting self started
Linux programming - Getting self started
 
BusyBox for Embedded Linux
BusyBox for Embedded LinuxBusyBox for Embedded Linux
BusyBox for Embedded Linux
 
Git 101: Git and GitHub for Beginners
Git 101: Git and GitHub for Beginners Git 101: Git and GitHub for Beginners
Git 101: Git and GitHub for Beginners
 
GCC RTL and Machine Description
GCC RTL and Machine DescriptionGCC RTL and Machine Description
GCC RTL and Machine Description
 
GCC compiler
GCC compilerGCC compiler
GCC compiler
 
Working Remotely (via SSH) Rocks!
Working Remotely (via SSH) Rocks!Working Remotely (via SSH) Rocks!
Working Remotely (via SSH) Rocks!
 
Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell Scripting
 
GCC, GNU compiler collection
GCC, GNU compiler collectionGCC, GNU compiler collection
GCC, GNU compiler collection
 
Linux Programming
Linux ProgrammingLinux Programming
Linux Programming
 
TMUX Rocks!
TMUX Rocks!TMUX Rocks!
TMUX Rocks!
 
Advanced debugging  techniques in different environments
Advanced debugging  techniques in different environmentsAdvanced debugging  techniques in different environments
Advanced debugging  techniques in different environments
 
The Go programming language - Intro by MyLittleAdventure
The Go programming language - Intro by MyLittleAdventureThe Go programming language - Intro by MyLittleAdventure
The Go programming language - Intro by MyLittleAdventure
 
LLVM
LLVMLLVM
LLVM
 
Write microservice in golang
Write microservice in golangWrite microservice in golang
Write microservice in golang
 

Viewers also liked

Improving awareness pescador san diego air & space museum
Improving awareness  pescador san diego air & space museumImproving awareness  pescador san diego air & space museum
Improving awareness pescador san diego air & space museum
APLICwebmaster
 
Brain computer interface
Brain computer interfaceBrain computer interface
Brain computer interfaceDisi Dc
 
Show and Tell : Medium
Show and Tell : MediumShow and Tell : Medium
Show and Tell : Medium
APLICwebmaster
 
APLIC 2014 - Building a Technical Knowledge Hub: Applying library science to ...
APLIC 2014 - Building a Technical Knowledge Hub: Applying library science to ...APLIC 2014 - Building a Technical Knowledge Hub: Applying library science to ...
APLIC 2014 - Building a Technical Knowledge Hub: Applying library science to ...
APLICwebmaster
 
Ijiret archana-kv-increasing-memory-performance-using-cache-optimizations-in-...
Ijiret archana-kv-increasing-memory-performance-using-cache-optimizations-in-...Ijiret archana-kv-increasing-memory-performance-using-cache-optimizations-in-...
Ijiret archana-kv-increasing-memory-performance-using-cache-optimizations-in-...
IJIR JOURNALS IJIRUSA
 
Ijirsm poornima-km-a-survey-on-security-circumstances-for-mobile-cloud-computing
Ijirsm poornima-km-a-survey-on-security-circumstances-for-mobile-cloud-computingIjirsm poornima-km-a-survey-on-security-circumstances-for-mobile-cloud-computing
Ijirsm poornima-km-a-survey-on-security-circumstances-for-mobile-cloud-computing
IJIR JOURNALS IJIRUSA
 
Ijirsm ashok-kumar-ps-compulsiveness-of-res tful-web-services
Ijirsm ashok-kumar-ps-compulsiveness-of-res tful-web-servicesIjirsm ashok-kumar-ps-compulsiveness-of-res tful-web-services
Ijirsm ashok-kumar-ps-compulsiveness-of-res tful-web-services
IJIR JOURNALS IJIRUSA
 
Sharing Promising Practices Internally and Externally: Lessons Learned from PCI
Sharing Promising Practices Internally and Externally: Lessons Learned from PCISharing Promising Practices Internally and Externally: Lessons Learned from PCI
Sharing Promising Practices Internally and Externally: Lessons Learned from PCI
APLICwebmaster
 
Final exam review game (5) (2)
Final exam review game (5) (2)Final exam review game (5) (2)
Final exam review game (5) (2)Sharoyal Nicole
 
APLIC 2014 - Sharing IS the point
APLIC 2014 - Sharing IS the pointAPLIC 2014 - Sharing IS the point
APLIC 2014 - Sharing IS the point
APLICwebmaster
 
La revolució del gessamí
La revolució del gessamíLa revolució del gessamí
La revolució del gessamíNúria Martos
 
APLIC 2014 - Social Observatories Coordinating Network
APLIC 2014 - Social Observatories Coordinating NetworkAPLIC 2014 - Social Observatories Coordinating Network
APLIC 2014 - Social Observatories Coordinating Network
APLICwebmaster
 
Final exam review game
Final exam review gameFinal exam review game
Final exam review game
Sharoyal Nicole
 
Astrologer, Vastu & Fengshui consultant
Astrologer, Vastu & Fengshui consultantAstrologer, Vastu & Fengshui consultant
Astrologer, Vastu & Fengshui consultant
Sanjeev166
 
Adding value : the foundation on which to build community
Adding value : the foundation on which to build communityAdding value : the foundation on which to build community
Adding value : the foundation on which to build community
APLICwebmaster
 
Dangers of facebook by sani
Dangers of facebook by saniDangers of facebook by sani
Dangers of facebook by sani
Sani Muhammad Sabo
 
Adding valuethroughdatacuration
Adding valuethroughdatacurationAdding valuethroughdatacuration
Adding valuethroughdatacuration
APLICwebmaster
 
Terra Populus: Integrated Data on Population and Environment
Terra Populus: Integrated Data on Population and EnvironmentTerra Populus: Integrated Data on Population and Environment
Terra Populus: Integrated Data on Population and Environment
APLICwebmaster
 

Viewers also liked (20)

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

Similar to Gnu debugger

Debugging Modern C++ Application with Gdb
Debugging Modern C++ Application with GdbDebugging Modern C++ Application with Gdb
Debugging Modern C++ Application with Gdb
SenthilKumar Selvaraj
 
gdb-tutorial.pdf
gdb-tutorial.pdfgdb-tutorial.pdf
gdb-tutorial.pdf
ligi14
 
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
Harrytoye2
 
Gdb tutorial-handout
Gdb tutorial-handoutGdb tutorial-handout
Gdb tutorial-handoutSuraj Kumar
 
lab1-ppt.pdf
lab1-ppt.pdflab1-ppt.pdf
lab1-ppt.pdf
AbdelrahmanElewah1
 
G++ & GCC
G++ & GCCG++ & GCC
G++ & GCC
Beste Ekmen
 
Debugging of (C)Python applications
Debugging of (C)Python applicationsDebugging of (C)Python applications
Debugging of (C)Python applications
Roman Podoliaka
 
Wavedigitech gdb
Wavedigitech gdbWavedigitech gdb
Wavedigitech gdb
Wave Digitech
 
gdb.ppt
gdb.pptgdb.ppt
gdb.ppt
LavishGupta22
 
Debugging embedded devices using GDB
Debugging embedded devices using GDBDebugging embedded devices using GDB
Debugging embedded devices using GDB
Chris Simmonds
 
Extending GDB with Python
Extending GDB with PythonExtending GDB with Python
Extending GDB with Python
Lisa Roach
 
Introduction of Tools for providing rich user experience in debugger
Introduction of Tools for providing rich user experience in debuggerIntroduction of Tools for providing rich user experience in debugger
Introduction of Tools for providing rich user experience in debugger
Naoto Ono
 
Mesa and Its Debugging
Mesa and Its DebuggingMesa and Its Debugging
Mesa and Its Debugging
GlobalLogic Ukraine
 
Mender.io | Develop embedded applications faster | Comparing C and Golang
Mender.io | Develop embedded applications faster | Comparing C and GolangMender.io | Develop embedded applications faster | Comparing C and Golang
Mender.io | Develop embedded applications faster | Comparing C and Golang
Mender.io
 
Compiler design notes phases of compiler
Compiler design notes phases of compilerCompiler design notes phases of compiler
Compiler design notes phases of compiler
ovidlivi91
 
C++ language basic
C++ language basicC++ language basic
C++ language basic
Waqar Younis
 
Debugging Python with gdb
Debugging Python with gdbDebugging Python with gdb
Debugging Python with gdb
Roman Podoliaka
 
MSL2009. Gdb
MSL2009. GdbMSL2009. Gdb
Comparing C and Go
Comparing C and GoComparing C and Go
Comparing C and Go
Marcin Pasinski
 

Similar to Gnu debugger (20)

Debugging Modern C++ Application with Gdb
Debugging Modern C++ Application with GdbDebugging Modern C++ Application with Gdb
Debugging Modern C++ Application with Gdb
 
gdb-tutorial.pdf
gdb-tutorial.pdfgdb-tutorial.pdf
gdb-tutorial.pdf
 
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
 
Gdb tutorial-handout
Gdb tutorial-handoutGdb tutorial-handout
Gdb tutorial-handout
 
lab1-ppt.pdf
lab1-ppt.pdflab1-ppt.pdf
lab1-ppt.pdf
 
G++ & GCC
G++ & GCCG++ & GCC
G++ & GCC
 
Gccgdb
GccgdbGccgdb
Gccgdb
 
Debugging of (C)Python applications
Debugging of (C)Python applicationsDebugging of (C)Python applications
Debugging of (C)Python applications
 
Wavedigitech gdb
Wavedigitech gdbWavedigitech gdb
Wavedigitech gdb
 
gdb.ppt
gdb.pptgdb.ppt
gdb.ppt
 
Debugging embedded devices using GDB
Debugging embedded devices using GDBDebugging embedded devices using GDB
Debugging embedded devices using GDB
 
Extending GDB with Python
Extending GDB with PythonExtending GDB with Python
Extending GDB with Python
 
Introduction of Tools for providing rich user experience in debugger
Introduction of Tools for providing rich user experience in debuggerIntroduction of Tools for providing rich user experience in debugger
Introduction of Tools for providing rich user experience in debugger
 
Mesa and Its Debugging
Mesa and Its DebuggingMesa and Its Debugging
Mesa and Its Debugging
 
Mender.io | Develop embedded applications faster | Comparing C and Golang
Mender.io | Develop embedded applications faster | Comparing C and GolangMender.io | Develop embedded applications faster | Comparing C and Golang
Mender.io | Develop embedded applications faster | Comparing C and Golang
 
Compiler design notes phases of compiler
Compiler design notes phases of compilerCompiler design notes phases of compiler
Compiler design notes phases of compiler
 
C++ language basic
C++ language basicC++ language basic
C++ language basic
 
Debugging Python with gdb
Debugging Python with gdbDebugging Python with gdb
Debugging Python with gdb
 
MSL2009. Gdb
MSL2009. GdbMSL2009. Gdb
MSL2009. Gdb
 
Comparing C and Go
Comparing C and GoComparing C and Go
Comparing C and Go
 

Recently uploaded

Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
MdTanvirMahtab2
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
Jayaprasanna4
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
Pipe Restoration Solutions
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
thanhdowork
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
obonagu
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
Kamal Acharya
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
Pratik Pawar
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
seandesed
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
zwunae
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Teleport Manpower Consultant
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
JoytuBarua2
 
English lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdfEnglish lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdf
BrazilAccount1
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
Jayaprasanna4
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
Amil Baba Dawood bangali
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
gdsczhcet
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
SamSarthak3
 
Fundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptxFundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptx
manasideore6
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
R&R Consult
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
Kerry Sado
 

Recently uploaded (20)

Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
 
English lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdfEnglish lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdf
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
 
Fundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptxFundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptx
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
 

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

  1. 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.
  2. 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.
  3. GDBoffers us remotemodewhich is mostlyused in debuggingembeddedsystem.
  4. Host system: (themachinerunninggdb)
  5. 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
  6. then you would compile with the following command:
  7. (If we'd used next, it would have stepped over ComputeFactorial.)