Gdb is the GNU debugger on our CS machines. gdb is most effective when it is debugging a program that has debugging symbols linked in to it. With gcc and.

Slides:



Advertisements
Similar presentations
Introduction to the Omega Server CSE Overview Intro to Omega Basic Unix Command Files Directories Printing C and C++ compilers GNU Debugger.
Advertisements

Utilizing the GDB debugger to analyze programs Background and application.
Debugging What can debuggers do? Run programs Make the program stops on specified places or on specified conditions Give information about current variables’
Gdb: GNU Debugger Lecturer: Prof. Andrzej (AJ) Bieszczad Phone: “UNIX for Programmers and Users” Third Edition, Prentice-Hall,
MT311 Tutorial Li Tak Sing( 李德成 ). Uploading your work You need to upload your work for tutorials and assignments at the following site:
The IDE (Integrated Development Environment) provides a DEBUGGER for locating and correcting errors in program logic (logic errors not syntax errors) The.
Fall 2007CS 2251 Programming Tools Eclipse JUnit Testing make and ant.
CSE 303 Lecture 13a Debugging C programs
Memory & Storage Architecture Seoul National University Computer Architecture “ Bomb Lab Hints” 2nd semester, 2014 Modified version : The original.
Testing a program Remove syntax and link errors: Look at compiler comments where errors occurred and check program around these lines Run time errors:
C Slides and captured lecture (video and sound) are available at:
Debugger Presented by 李明璋 2012/05/08. The Definition of Bug –Part of the code which would result in an error, fault or malfunctioning of the program.
Embedded Systems Principle of Debugger. Reference Materials kl.de/avr_projects/arm_projects/#winarmhttp://
Debugging Cluster Programs using symbolic debuggers.
Memory & Storage Architecture Seoul National University GDB commands Hyeon-gyu School of Computer Science and Engineering.
Introduction to Shell Script Programming
Programming Tools gcc make utility Open Source code Static and Shared Libraries gdb Memory debugging tools.
Compiling & Debugging Quick tutorial. What is gcc? Gcc is the GNU Project C compiler A command-line program Gcc takes C source files as input Outputs.
Goals: To gain an understanding of assembly To get your hands dirty in GDB.
Some Basics && GDB overview Ram Sheshadri –
Debugging Dwight Deugo Nesa Matic
Debugging. 2 © 2003, Espirity Inc. Module Road Map 1.Eclipse Debugging  Debug Perspective  Debug Session  Breakpoint  Debug Views  Breakpoint Types.
Debugging in Java. Common Bugs Compilation or syntactical errors are the first that you will encounter and the easiest to debug They are usually the result.
A Tutorial on Introduction to gdb By Sasanka Madiraju Graduate Assistant Center for Computation and Technology.
CSE 332: C++ debugging Why Debug a Program? When your program crashes –Finding out where it crashed –Examining program memory at that point When a bug.
CSI605 Introduction to gdb. Compiling for gdb Execution I often compile as follows gcc -g -Wall -omyprog myprog.c g++ -g -Wall -omyprog myprog.c It suffices.
1 SEEM3460 Tutorial Compiling and Debugging C programs.
CSE 351 GDB Introduction. Lab 1 Status? How is Lab 1 going? I’ll be available at the end of class to answer questions There are office hours later today.
Data Display Debugger (DDD)
C++ crash course Class 9 flight times program, using gdb.
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 11 – gdb and Debugging.
S OME USEFUL D EBUG C OMMANDS FOR C LEAR -S PEED S OFTWARE D EVELOPMENT K IT -- COMMANDS FROM CHAP.7 By: Pallav Laskar.
Debugging 1/6/2016. Debugging 1/6/2016 Debugging  Debugging is a methodical process of finding and reducing the number of bugs, or defects, in a program.
COP 3530 Spring2012 Data Structures & Algorithms Discussion Session Week 2.
Dale Roberts Debugger Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and Information Science, School.
Unit - V. Debugging GNU Debugger helps you in getting information about the following: 1.If a core dump happened, then what statement or expression did.
CSI605 Introduction to ddd. ddd ddd stands for the Data Display Debugger ddd is a graphical environment that resides on top of gdb We recall that gdb.
COP 3530 Spring 12 Discussion Session 1. Agenda 1.Introduction 2.Remote programming 3.Separate code 4.Compile -- g++,makefile 5.Debug -- gdb 6.Questions?
CSc 352 Debugging Tools Saumya Debray Dept. of Computer Science The University of Arizona, Tucson
17/02/2016S. Ponce / EP-LBC1 Debugging Under Linux Sebastien Ponce Friday, 8 March 2002.
CMSC 104, Version 8/061L14AssignmentOps.ppt Assignment Operators Topics Increment and Decrement Operators Assignment Operators Debugging Tips Reading Section.
CSE 332: C++ expressions Expressions: Operators and Operands Operators obey arity, associativity, and precedence int result = 2 * 3 + 5; // assigns 11.
HP-SEE Debugging with GDB Vladimir Slavnic Research Assistant SCL, Institute of Physics Belgrade The HP-SEE initiative.
GDB Introduction And Lab 2
Gnu Debugger (GDB) Topics Overview Quick Reference Card Readings: Quick Reference Card February 4, 2010 CSCE 212Honors Computer Organization.
Dale Roberts Debugger Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and Information Science, School.
Using the GNU Debugger (GDB)‏ Techzemplary Pvt.Ltd February 24 th 2008 Pranav Peshwe.
Institute of Radio Physics and Electronics ILug-Cal Introduction to GDB Institute of Radio Physics and Electronics and Indian GNU/Linux Users Group Kolkata.
Gnu Debugger (gdb) Debuggers are used to: Find semantic errors Locate seg faults and bus errors Prepared by Dr. Spiegel.
CSCI 4061 Recitation 2 1.
DEBUG.
Gnu Debugger (gdb) Debuggers are used to: Find semantic errors
Winter 2009 Tutorial #6 Arrays Part 2, Structures, Debugger
Dynamic Analysis ddaa.
Debugging Dwight Deugo
Debugging with gdb gdb is the GNU debugger on our CS machines.
gdb gdb is the GNU debugger on our CS machines.
Introduction to Computer Systems
Important terms Black-box testing White-box testing Regression testing
Computer Architecture “Bomb Lab Hints”
Important terms Black-box testing White-box testing Regression testing
Debugging with Eclipse
Debuggers.
CSc 352 Debugging Tools Saumya Debray Dept. of Computer Science
GNU DEBUGGER TOOL. What is the GDB ? GNU Debugger It Works for several languages – including C/C++ [Assembly, Fortran,Go,Objective-C,Pascal]
Debugging Dwight Deugo
CSE 303 Concepts and Tools for Software Development
Debugging.
Makefiles, GDB, Valgrind
Debugging with Eclipse
Presentation transcript:

gdb is the GNU debugger on our CS machines. gdb is most effective when it is debugging a program that has debugging symbols linked in to it. With gcc and g++, this is accomplished using the -g option, for example, to compile colortest.c and have the executable stored in testcolor, use the following: gcc -Wall -g -o testcolor colortest.c Once you have an executable file (in this case prog.o) you can use gdb to debug it. First you must launch the debugger. To launch the debugger you type gdb For the above program, this will be gdb testcolor gdb

Valgrind is another suite of tools for debugging and profiling your programs. First compile your program using the -g option as above, then launch valgrind: valgrind [valgrind-options] [your-prog] [your-prog-options] For example, if you execute testcolor using the command./testcolor colordata1.txt you would could use the following command valgrind --leak-check=yes./testcolor colordata1.txt For more information about valgrind, refer to the man page: man valgrind Valgrind

The gdb debugger is a handy tool for identifying the location at which a program failed. At the (gdb) prompt you will usually want to tell the debugger to halt the program when it reaches the start of the main() function. The b command is short for breakpoint and tells the debugger where to stop. After a function is entered, source code line numbers can be used to specify breakpoints. Using gdb to find the point of failure

(gdb) b main Breakpoint 1 at 0x804833b: file p18.c, line 11. To start the program use the run command: (gdb) run Starting program: /home/rlowe/cs2100/examples/p18 When the program reaches a breakpoint gdb will tell you and display the next line of code to be executed. Breakpoint 1, main () at p18.c:11 11 printf("val of ptr is %p \n", ptr); Using gdb to find the point of failure

Use the next command to execute a single source statement. The next command will treat a function call as a single statement and not single step into the function being called. If you want to single step through the function use the step command to step into it. The output of the printf() is intermixed with gdb's output and is shown in blue below. (gdb) next val of ptr is (nil) 13 *ptr = 99; Using gdb to find the point of failure

Saying next again will cause the program to execute the flawed assignment. gdb will show you the line that caused the error (line # 13). (gdb) next Program received signal SIGSEGV, Segmentation fault. 0x in main () at p18.c:13 13 *ptr = 99; Using gdb to find the point of failure

The where command can show you where the failure occurred (along with a complete function activation trace. (gdb) where #0 0x in main () at p18.c:13 #1 0x in __libc_start_main () from /lib/libc.so.6 (gdb) To print the value of a variable use the print command. (gdb) print ptr $1 = (int *) 0x0 Attempting to print what ptr points to reaffirms what the problem is: (gdb) print *ptr Cannot access memory at address 0x0 Using gdb to find the point of failure

Use the q (quit) command to terminate gdb (gdb) quit The program is running. Exit anyway? (y or n) y home/rlowe/cs2100/examples ==> Using gdb to find the point of failure

Common gdb commands CommandDescription helpList gdb command topics. help topic-classesList gdb command within class. help commandCommand description. apropos search-word Search for commands and command topics containing search-word. info args i args List program command line arguments info breakpoints Print info about breakpoints and watchpoints info breakPrint breakpoint numbers. info break breakpoint- number Print info about specific breakpoint. info watchpointsPrint info about watchpoints

Common gdb commands tbreakTemporary break. Break once only. Break is then removed. See "break" above for options. watch conditionSuspend processing when condition is met. i.e. x > 5 clear clear function clear line-number Delete breakpoints as identified by command option. delete d Delete all breakpoints, watchpoints, or catchpoints. delete breakpoint-number delete range Delete the breakpoints, watchpoints, or catchpoints of the breakpoint ranges specified as arguments. disable breakpoint- number-or-range enable breakpoint- number-or-range Does not delete breakpoints. Just enables/disables them. Example: Show breakpoints: info break Disable: disable 2-9

Common gdb commands Break and Watch break funtion-name break line-number break ClassName::functionName Suspend program at specified function of line number. break +offset break -offset Set a breakpoint specified number of lines forward or back from the position at which execution stopped. break filename:functionDon't specify path, just the file name and function name. break filename:line-numberDon't specify path, just the file name and line number. break Directory/Path/filename.cpp:62 break line-number if conditionWhere condition is an expression. i.e. x > 5 Suspend when boolean expression is true.

Common gdb commands enable breakpoint-number once Enables once continue c Continue executing until next break point/watchpoint. continue numberContinue but ignore current breakpoint number times. Usefull for breakpoints within a loop. finishContinue to end of function. Line Execution step s step number-of-steps-to- perform Step to next line of code. Will step into a function. next n next number Execute next line of code. Will not enter functions.

Common gdb commands until until line-number Continue processing until you reacha aspecified line number. Also: function name, address, filename:function or filename:line-number. whereShows current line number and which function you are in. Source Code list l list line-number list function list - list start#,end# list filename:function List source code. set listsize count show listsize Number of lines listed when list command given.

Common gdb commands Examine Variables print variable-name p variable-name p file-name::variable-name p 'file-name'::variable-name Print value stored in variable. Start and Stop run r run command-line- arguments run outfile Start program execution from the beginning of the program. The command break main will get you started. Also allows basic I/O redirection. continue c Continue execution to next break point. kill k Stop program execution. quit q Exit GDB debugger.

gdb – Quick reference guid run -- run the program run args-- run program with command line args. break function-- set breakpoint at function entry break linenum -- set breakpoint at line break … if cond-- set breakpoint; break if condition clear funct-- remove breakpoint at function entry delete bnum-- delete breakpoint bnum disable bnum-- disable breakpoint bnum enable bnum-- enable breakpoint bnum condition bnum-- set conditions for breakpoint bnum commands bnum-- set commands for breakpoint bnum cont -- continue execution to next break point

gdb – Quick reference guid next -- step next source level statement or function nexti -- step next machine instruction or function step -- step next source level statement stepi -- step next machine instruction print expr -- print value of expression info data -- information about break, display, registers, functions, variables list -- list ten source lines where -- show call stack kill -- stop program execution quit -- exit gdb Note: pressing Enter repeats the last command.