Debuggin g 09/06/22
Jan 19, 2016
Debugging
21/04/23
Debugging
21/04/23
Debugging
Debugging is a methodical process of finding and reducing the number of bugs, or defects, in a program or a piece of electronic hardware.
It is the most important activity in the software and program development.
It is used in order to remove or identify logical errors in the program.
Debugging is not testing but testing can be a part of debugging. Testing finds errors; debugging localizes and repairs them.
Debugging is a black art.
2
Debugging
21/04/23
What is a Debugger?
“A software tool that is used to detect the source of program or script errors, by performing step-by-step execution of application code and viewing the content of code variables.”
3
Debugging
21/04/23
Why Debug?
When your program crashes Finding out where it crashed Examining program memory at that point
When a bug occurs in your program Watching program variables Identifying where the problem occurs (and
why) Tracing through a program
Learning what a program does Good basic testing approach
4
Debugging
21/04/23
Steps in Debugging Process
1. Compile your program(s) enabling the same for Debugging. i.e. gcc –g –o p prg.c
2. Execute the debugger3. Run the program as you normally would.
When the error occurs, Debugger will provide information regarding the location of the error, and possible reasons for its occurrence. (It also provides more detail about the error than the initial error messages you may have received without using the debugger)
5
Debugging
21/04/23
Debuggers
Command-line debuggers : gdb (C, C++), jdb (java), “perl –d”
DDD – Data Display Debugger – Linux Debugger
6
Debugging
21/04/23
GDB
Compile with the "-g" option (for most GNU and Intel compilers) which generates added information in the object code so the debugger can match a line of source code with the step of execution.gcc -g eg.c -o eg
Running gdb gdb name-of-executable (gbd ./eg)
7
Debugging
21/04/23
When gdb is started, it should look somewhat like this:GNU gdb 2002-08-18-cvsCopyright 2002 Free Software Foundation, Inc.GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions.Type "show copying" to see the conditions.There is absolutely no warranty for GDB. Type "show warranty" for details.This GDB was configured as "powerpc-linux".(gdb)
(gdb) quit
(gdb) list
(gdb) run
(gdb) print x
8
Debugging
21/04/23
Breakpoints
gdb returns control back to you when it reaches that exact point.
Breakpoints are created using the break command. For instance, this is telling gdb to pass back control on line 19 and 21:
RUNNING NAVIGATION(gdb) next
(gdb) step
(gdb) continue
9
Debugging
21/04/23
GDB Breakpoints
• Useful breakpoint commands:b[reak] [<where>] sets breakpoints. <where> can be
a number of things, including a hex
address, a function name, a line
number, or a relative line offset[r]watch <expr> sets a watchpoint, which will break
when <expr> is written to [or read]info break[points] prints out a listing of all breakpointsclear [<where>] clears a breakpoint at <where>d[elete] [<nums>] deletes breakpoints by number
DDD: Best Visual Debugger
10
Debugging
21/04/23
Starting DDD
Open your executable program in DDD ddd ./eg OR ddd ./a.out
(sudo apt-get install ddd)
11
Debugging
21/04/23
Debugger Console and Data Window
12
Set Breakpoint
s13