SlideShare una empresa de Scribd logo
1 de 33
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

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Debugging Python with gdb
Debugging Python with gdbDebugging Python with gdb
Debugging Python with gdb
 
Gdb tutorial-handout
Gdb tutorial-handoutGdb tutorial-handout
Gdb tutorial-handout
 
C under Linux
C under LinuxC under Linux
C under Linux
 
GDB Rocks!
GDB Rocks!GDB Rocks!
GDB Rocks!
 
Compiling Under Linux
Compiling Under LinuxCompiling Under Linux
Compiling Under Linux
 
Gccgdb
GccgdbGccgdb
Gccgdb
 
C compiler-ide
C compiler-ideC compiler-ide
C compiler-ide
 
Turbo C Compiler Reports
Turbo C Compiler Reports Turbo C Compiler Reports
Turbo C Compiler Reports
 
GCC, GNU compiler collection
GCC, GNU compiler collectionGCC, GNU compiler collection
GCC, GNU compiler collection
 
How it's made: C++ compilers (GCC)
How it's made: C++ compilers (GCC)How it's made: C++ compilers (GCC)
How it's made: C++ compilers (GCC)
 
Rails
RailsRails
Rails
 
Introduction to gdb
Introduction to gdbIntroduction to gdb
Introduction to gdb
 
C Under Linux
C Under LinuxC Under Linux
C Under Linux
 
C compilation process
C compilation processC compilation process
C compilation process
 
GCC compiler
GCC compilerGCC compiler
GCC compiler
 
File handling With Solve Programs
File handling With Solve ProgramsFile handling With Solve Programs
File handling With Solve Programs
 
Slides
SlidesSlides
Slides
 
Turbo C
Turbo CTurbo C
Turbo C
 
淺入淺出 GDB
淺入淺出 GDB淺入淺出 GDB
淺入淺出 GDB
 
Introduction to MPI
Introduction to MPIIntroduction to MPI
Introduction to MPI
 

Destacado

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
 
Adding valuethroughdatacuration
Adding valuethroughdatacurationAdding valuethroughdatacuration
Adding valuethroughdatacurationAPLICwebmaster
 
Ijirsm amrutha-s-efficient-complaint-registration-to-government-bodies
Ijirsm amrutha-s-efficient-complaint-registration-to-government-bodiesIjirsm amrutha-s-efficient-complaint-registration-to-government-bodies
Ijirsm amrutha-s-efficient-complaint-registration-to-government-bodiesIJIR JOURNALS IJIRUSA
 
Ijirsm choudhari-priyanka-backup-and-restore-in-smartphone-using-mobile-cloud...
Ijirsm choudhari-priyanka-backup-and-restore-in-smartphone-using-mobile-cloud...Ijirsm choudhari-priyanka-backup-and-restore-in-smartphone-using-mobile-cloud...
Ijirsm choudhari-priyanka-backup-and-restore-in-smartphone-using-mobile-cloud...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-servicesIJIR JOURNALS IJIRUSA
 
Repzo presentation
Repzo presentationRepzo presentation
Repzo presentationHassan Atmeh
 
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
 
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-computingIJIR JOURNALS IJIRUSA
 
Interactional view student (5)
Interactional view student (5)Interactional view student (5)
Interactional view student (5)Sharoyal Nicole
 
laxman final new cv
laxman final new cvlaxman final new cv
laxman final new cvLaxman Das
 
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
 
Astrologer, Vastu & Fengshui consultant
Astrologer, Vastu & Fengshui consultantAstrologer, Vastu & Fengshui consultant
Astrologer, Vastu & Fengshui consultantSanjeev166
 
An Integrated DHS system
An Integrated DHS systemAn Integrated DHS system
An Integrated DHS systemAPLICwebmaster
 

Destacado (18)

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-...
 
Deber deinformatica
Deber deinformaticaDeber deinformatica
Deber deinformatica
 
Adding valuethroughdatacuration
Adding valuethroughdatacurationAdding valuethroughdatacuration
Adding valuethroughdatacuration
 
Ijirsm amrutha-s-efficient-complaint-registration-to-government-bodies
Ijirsm amrutha-s-efficient-complaint-registration-to-government-bodiesIjirsm amrutha-s-efficient-complaint-registration-to-government-bodies
Ijirsm amrutha-s-efficient-complaint-registration-to-government-bodies
 
Perilaku dalam teori sosial
Perilaku dalam teori sosialPerilaku dalam teori sosial
Perilaku dalam teori sosial
 
Ijirsm choudhari-priyanka-backup-and-restore-in-smartphone-using-mobile-cloud...
Ijirsm choudhari-priyanka-backup-and-restore-in-smartphone-using-mobile-cloud...Ijirsm choudhari-priyanka-backup-and-restore-in-smartphone-using-mobile-cloud...
Ijirsm choudhari-priyanka-backup-and-restore-in-smartphone-using-mobile-cloud...
 
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
 
Repzo presentation
Repzo presentationRepzo presentation
Repzo presentation
 
Hello sp
Hello spHello sp
Hello sp
 
Final exam review game (5) (2)
Final exam review game (5) (2)Final exam review game (5) (2)
Final exam review game (5) (2)
 
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
 
Interactional view student (5)
Interactional view student (5)Interactional view student (5)
Interactional view student (5)
 
Final exam review game
Final exam review gameFinal exam review game
Final exam review game
 
laxman final new cv
laxman final new cvlaxman final new cv
laxman final new cv
 
Dangers of facebook by sani
Dangers of facebook by saniDangers of facebook by sani
Dangers of facebook by sani
 
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 ...
 
Astrologer, Vastu & Fengshui consultant
Astrologer, Vastu & Fengshui consultantAstrologer, Vastu & Fengshui consultant
Astrologer, Vastu & Fengshui consultant
 
An Integrated DHS system
An Integrated DHS systemAn Integrated DHS system
An Integrated DHS system
 

Similar a GNU Debugger

Debugging Modern C++ Application with Gdb
Debugging Modern C++ Application with GdbDebugging Modern C++ Application with Gdb
Debugging Modern C++ Application with GdbSenthilKumar Selvaraj
 
gdb-tutorial.pdf
gdb-tutorial.pdfgdb-tutorial.pdf
gdb-tutorial.pdfligi14
 
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 oSHarrytoye2
 
Debugging of (C)Python applications
Debugging of (C)Python applicationsDebugging of (C)Python applications
Debugging of (C)Python applicationsRoman Podoliaka
 
Debugging embedded devices using GDB
Debugging embedded devices using GDBDebugging embedded devices using GDB
Debugging embedded devices using GDBChris Simmonds
 
Extending GDB with Python
Extending GDB with PythonExtending GDB with Python
Extending GDB with PythonLisa 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 debuggerNaoto Ono
 
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 GolangMender.io
 
Compiler design notes phases of compiler
Compiler design notes phases of compilerCompiler design notes phases of compiler
Compiler design notes phases of compilerovidlivi91
 
C++ language basic
C++ language basicC++ language basic
C++ language basicWaqar Younis
 
Klement_0902_v2F (complete article)
Klement_0902_v2F (complete article)Klement_0902_v2F (complete article)
Klement_0902_v2F (complete article)Mike Friehauf
 
ELC-E Linux Awareness
ELC-E Linux AwarenessELC-E Linux Awareness
ELC-E Linux AwarenessPeter Griffin
 
Autotools, Design Patterns and more
Autotools, Design Patterns and moreAutotools, Design Patterns and more
Autotools, Design Patterns and moreVicente Bolea
 
Writing mruby Debugger
Writing mruby DebuggerWriting mruby Debugger
Writing mruby Debuggeryamanekko
 

Similar a 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
 
lab1-ppt.pdf
lab1-ppt.pdflab1-ppt.pdf
lab1-ppt.pdf
 
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
 
MSL2009. Gdb
MSL2009. GdbMSL2009. Gdb
MSL2009. Gdb
 
Comparing C and Go
Comparing C and GoComparing C and Go
Comparing C and Go
 
Klement_0902_v2F (complete article)
Klement_0902_v2F (complete article)Klement_0902_v2F (complete article)
Klement_0902_v2F (complete article)
 
ELC-E Linux Awareness
ELC-E Linux AwarenessELC-E Linux Awareness
ELC-E Linux Awareness
 
Autotools, Design Patterns and more
Autotools, Design Patterns and moreAutotools, Design Patterns and more
Autotools, Design Patterns and more
 
Writing mruby Debugger
Writing mruby DebuggerWriting mruby Debugger
Writing mruby Debugger
 

Último

Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)simmis5
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdfankushspencer015
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxfenichawla
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduitsrknatarajan
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
Glass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesGlass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesPrabhanshu Chaturvedi
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college projectTonystark477637
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfKamal Acharya
 

Último (20)

Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
Glass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesGlass Ceramics: Processing and Properties
Glass Ceramics: Processing and Properties
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 

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