Presentation is loading. Please wait.

Presentation is loading. Please wait.

GNU DEBUGGER TOOL. What is the GDB ? GNU Debugger It Works for several languages – including C/C++ [Assembly, Fortran,Go,Objective-C,Pascal]

Similar presentations


Presentation on theme: "GNU DEBUGGER TOOL. What is the GDB ? GNU Debugger It Works for several languages – including C/C++ [Assembly, Fortran,Go,Objective-C,Pascal]"— Presentation transcript:

1 GNU DEBUGGER TOOL

2 What is the GDB ? GNU Debugger It Works for several languages – including C/C++ [Assembly, Fortran,Go,Objective-C,Pascal]

3 Not Every Exe Debugging Friendly 1. The executable has to carry debugging symbols The symbols tell GDB where to look in the source To include symbols, use the – g flag for gcc – E.g. :gcc Hello.c –g –o Hello 2. The source tree needs to remain the same. It was when the program was compiled

4 Starting GDB gdb --help - Display all available options gdb - - silent prog - invoking gdb in silent mode, to stop printing the front material, which describes gdb. Let GDB be able to read all the information line by line from the symbol table, - we need to compile it a bit differently. Normally we compile our programs Ex: gcc Hello.cc -o Hello - Instead of doing this, we need to compile with the -g flag. Ex : gcc -g hello.cc -o hello

5 Quitting GDB To exit GDB - Type quit(abbreviated q) at the GDB prompt.

6 GDB COMMANDS Most of the commands in GDB can be issued by simply giving the starting letter For ex : ‘b’ can be used instead of ‘break’. A blank line as input to GDB means to repeat the previous command.

7 Running the program run (r) to start program under GDB. run arg1 arg2 to run with command line args run > outfile.txt diverting output to the file 'outfile.txt'

8 Breakpoints(1/3) Breakpoints stops the program when certain point is reached. - break (b) command is used to set break points. Setting break points : break fun_name ex: break main or b main - Sets a break point at entry to function name break lineumber ex : b 3 - Set a break point at line line num in current sourcefile

9 Breakpoints(2/3) break filename:linenum ex:- b value.c : 2 - Set a break point at the linenum in source file filename break filename:linenum ex:- b value.c : fun - Set a breakpoint at entry to function function found in file filename. break - When called without any arguments, break sets a breakpoint at the next instruction to be executed.

10 Breakpoints(3/3) info breakpoints ex: info b - Prints a table of all breakpoints. clear - Delete any breakpoints at the next instruction to be executed c lear function - Delete any breakpoints set at entry to the function. Clear linennum -Delete any breakpoints at the particular linenum delete -Delete all breakpoints.

11 Continuing & Stepping(1/2) Continuing means resuming program execution until your program completes normally. Stepping means executing just one line of source code, or one machine instruction. continue (c) - After resume program execution. Next (n) - Executes next instruction & stops. Stop (s) - Executes next instruction & stops.

12 Continuing & Stepping(2/2) step [count] & next [count] ex: next 5 - We can execute count no of instructions by giving a count. Diff b/w next & step is that,if there is a function call it proceeds until the function returns in case of step.

13 Printing Source lines print linenum - prints lines centered around linenum in the current source file. Print function - prints lines centered around beginning of the function l ist show listsize set listsize count

14 Examining Data print expr - value of expr is printed. print variable print file :: variable print function :: variable - Ex :- p func::z To display automatically use display - Ex:- display expr or variable.

15 Jump It helps to go to a specific line of instruction jump func:line - jumps to a particular line in function func. jump linenum - jumps to a specific line.

16 logging set logging on - Enable logging set logging off - Disable logging set logging file out.txt - Change the name of the current logfile, default is gdb.txt help - displays a short list of classes of commands

17 Backtraces backtrace is a summary of how your program got where it is. It shows one line per frame, for many frames.The backtrace (or where ) command prints information about the call stack. backtrace (bt) - bt Print a backtrace of the entire stack: one line per frame for all frames in the stack. backtrace n (bt n) - Similar, but print only the innermost n frames. backtrace full (bt full) - Print the values of the local variables also. n specifies the number of frames to print.

18 References https://www.tecmint.com/debug-source-code-in- linux-using-gdb/ https://www.eecs.umich.edu/courses/eecs373/reading s/Debugger.pdf

19 THANK Q ANY QUERIES ?


Download ppt "GNU DEBUGGER TOOL. What is the GDB ? GNU Debugger It Works for several languages – including C/C++ [Assembly, Fortran,Go,Objective-C,Pascal]"

Similar presentations


Ads by Google