Institute of Radio Physics and Electronics ILug-Cal Introduction to GDB Institute of Radio Physics and Electronics and Indian GNU/Linux Users Group Kolkata.

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

Module R2 CS450. Next Week R1 is due next Friday ▫Bring manuals in a binder - make sure to have a cover page with group number, module, and date. You.
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,
Inline Assembly Section 1: Recitation 7. In the early days of computing, most programs were written in assembly code. –Unmanageable because No type checking,
CSE 303 Lecture 13a Debugging C programs
DEBUGGERS For CS302 Data Structures Course Slides prepared by TALHA OZ (most of the text is from
Homework Reading –Finish K&R Chapter 1 (if not done yet) –Start K&R Chapter 2 for next time. Programming Assignments –DON’T USE and string library functions,
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.
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.
Debugging Cluster Programs using symbolic debuggers.
Memory & Storage Architecture Seoul National University GDB commands Hyeon-gyu School of Computer Science and Engineering.
Copyright © 2009 Techtronics'09 by GCECT 1 Presents, De Code C De Code C is a C Programming competition, which challenges the participants to solve problems.
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.
C Tutorial Session #2 Type conversions More on looping Common errors Control statements Pointers and Arrays C Pre-processor Makefile Debugging.
A Tutorial on Introduction to gdb By Sasanka Madiraju Graduate Assistant Center for Computation and Technology.
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.
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.
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.
CS252: Systems Programming Ninghui Li Based on Slides by Gustavo Rodriguez-Rivera Topic 2: Program Structure and Using GDB.
CSE 303 Concepts and Tools for Software Development Richard C. Davis UW CSE – 10/11/2006 Lecture 7 – Introduction to C.
HP-SEE Debugging with GDB Vladimir Slavnic Research Assistant SCL, Institute of Physics Belgrade The HP-SEE initiative.
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.
Introduction to GCC Department of Radio Physics and Electronics ILug-Cal Introduction to GCC Department of Radio Physics and Electronics, Calcutta University.
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.
Computer System Laboratory
Instructions for test_function
Gnu Debugger (gdb) Debuggers are used to: Find semantic errors
Winter 2009 Tutorial #6 Arrays Part 2, Structures, Debugger
Dynamic Analysis ddaa.
CSE 374 Programming Concepts & Tools
CSCE 212Honors Computer Organization
Debugging with gdb gdb is the GNU debugger on our CS machines.
Editor, Compiler, Linker, Debugger, Makefiles
Introduction to C Topics Compilation Using the gcc Compiler
gdb gdb is the GNU debugger on our CS machines.
TRANSLATORS AND IDEs Key Revision Points.
Debugging with Eclipse
Debuggers.
Getting Started: Developing Code with Cloud9
Govt. Polytechnic,Dhangar
Introduction to C Topics Compilation Using the gcc Compiler
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]
Testing, debugging, and using support libraries
Homework Reading Programming Assignments Finish K&R Chapter 1
Introduction to C Topics Compilation Using the gcc Compiler
CSE 303 Concepts and Tools for Software Development
Chapter 15 Debugging.
CSCE 212Honors Computer Organization
Debugging.
Makefiles, GDB, Valgrind
Corresponds with Chapter 5
Debugging with Eclipse
SPL – PS1 Introduction to C++.
Introduction to C CS 3410.
Presentation transcript:

Institute of Radio Physics and Electronics ILug-Cal Introduction to GDB Institute of Radio Physics and Electronics and Indian GNU/Linux Users Group Kolkata Chapter

Institute of Radio Physics and Electronics ILug-Cal Introduction to GDB Here We Start  Crashes, errors and warnings are part of a C programmer’s life  Debugger allows the programmer to take a look at the program in execution to deduce the cause of crashes and erroneous results

Institute of Radio Physics and Electronics ILug-Cal Introduction to GDB Debugger over naïve printf  printf pollutes the code  Difficult to probe the cause of a failure if printfs are absent at appropriate places  Inserting a new code may change program behavior and therefore the nature and/or existance of error and/or crash  Inserting new debug code implies recompilation

Institute of Radio Physics and Electronics ILug-Cal Introduction to GDB Debugger over naïve printf (contd.)  With debugger, program needs to be compiled only once with debug flag  The program run from within a debugger may be stopped at specified points and the state of the program (variables, etc) observed  Allows post-mortem of program crashes

Institute of Radio Physics and Electronics ILug-Cal Introduction to GDB GDB  GDB is the GNU Source-Level Debugger for C/C++ programs  GDB may be used to debug programs that either crash or produce incorrect results when run  Allows for debugging of single as well as multi-threaded programs

Institute of Radio Physics and Electronics ILug-Cal Introduction to GDB Compiling for Debugging  Use “ -g ” or “ -ggdb ” compile option to add debugging information to the object files  Preserves type information from variables  Preserves function prototypes  provides correspondence between instructions and source code line numbers  A numerical argument may follow “ –g ” or “ –ggdb ”, 1 meaning least amount of debugging information and 3 maximum. Default is 2  With “ –g3 ” or “ -ggdb3 ”, preprocessor macros can be accessed

Institute of Radio Physics and Electronics ILug-Cal Introduction to GDB Compiling for Debugging (contd.)  Best to turn off compiler optimizations  With high optimization levels, variables may get optimized out of existence and functions get inlined  Example: $ gcc –Wall –g3 –O0 –o hello hello.c

Institute of Radio Physics and Electronics ILug-Cal Introduction to GDB Running gdb  Common ways to run GDB :  gdb Ex: $ gdb hello  gdb Ex: $ gdb hello core.123  gdb Ex: $ gdb hello 123  Once program is loaded, run it:  (gdb) r hello  You can also specify arguments to the program:  (gdb) r hello GNU

Institute of Radio Physics and Electronics ILug-Cal Introduction to GDB Debugger Features  Stop program execution (breakpoints)  Stop program execution under certain conditions (conditional breakpoints)  Display values of variables, pointers, and contents of structures  Execute program line by line  Hop from stack frame to stack frame  Create watchpoints  Alter data and program execution

Institute of Radio Physics and Electronics ILug-Cal Introduction to GDB Breakpoints  Specifies point in the program at which the debugger should stop executing (gdb) b main (gdb) b HelloWorld.c:5 The above is useful in multifile projects (gdb) b printHelloWorld  Each breakpoint gets an identifier which can be used later to enable, disable or delete the breakpoint

Institute of Radio Physics and Electronics ILug-Cal Introduction to GDB Deleting Breakpoints  Breakpoints can be removed in the following ways: To remove a breakpoint by its location, use clear To remove a breakpoint by its identifier, use delete (gdb) clear main Deleted breakpoint 1 (gdb) clear HelloWorld.c:5 Deleted breakpoint 2  delete n deletes the breakpoint with identifier n (gdb) delete 1 Deleted breakpoint 1

Institute of Radio Physics and Electronics ILug-Cal Introduction to GDB Stepping and Resuming ● Once a program has stopped at a specified point, it can be made to resume execution using one of the following ways: ● Execute next program line (after stopping); step over any function calls in the line (gdb) next ● Execute next program line (after stopping); step into any function calls in the line (gdb) step ● Continue running your program (after stopping, e.g. at a breakpoint) (gdb) c

Institute of Radio Physics and Electronics ILug-Cal Introduction to GDB Inspecting Variables ● Values and types of variables can be inspected with gdb ● ptype allows looking at the types of variables (can be structures) (gdb) ptype mystring type = unsigned char * (gdb) ptype mystruct type = struct map { int key; char* val; } ●

Institute of Radio Physics and Electronics ILug-Cal Introduction to GDB Displaying variables Values of variables can be printed: (gdb) print num With display, variables are printed whenever they change (gdb) display num

Institute of Radio Physics and Electronics ILug-Cal Introduction to GDB Stack Frames  Stack Frame: A structure which holds execution information for a function call  Components of the structure are: - return pointer - space for the function’s return value (to be populated) - arguments to the function - local variables  A stack frame is created for each function call and placed on the top of the stack  When a function call returns, the frame corresponding to the function call is removed from the top of the stack

Institute of Radio Physics and Electronics ILug-Cal Introduction to GDB Navigating Stack Frames ● The commands to list the program stacks are: ● Display backtrace (that is the program stack upto the current point) (gdb) bt ● Move up the stack frame (gdb) up ● Move down the stack frame (gdb) down ● Display frame 1 (gdb) frame 1

Institute of Radio Physics and Electronics ILug-Cal Introduction to GDB Wrapping up ● To complete the function being currently executed, use “finish”. It also shows the value the function returned. (gdb) finish ● To quit gdb, use: (gdb) quit