Displaying Program Variables Displaying Variables
5.5.4 Modifying Variables
Using the set command, you can modify any program variable during the debugging process. The following session shows an example where you entered a value 34 for program variable num1 but modified it to 11 using set command before the sum was calculated. You can see that the sum calculation process takes into account the new value. Enter first number : 34 11 printfEnter second number : ; gdb n 12 scanfd, num2; 156 Chapter 5 • Working with GNU Debugger gdb n Enter second number : 12 14 total = sumnum1, num2; gdb print num1 1 = 34 gdb set num1=11 gdb print num1 2 = 11 gdb print num2 3 = 12 gdb n Calculation complete. Returning ... 15 printf\nThe sum is : d\n, total; gdb n The sum is : 23 16 } gdb5.6 Adding Break Points
When you start debugging a program, you use the run command. This command executes the program until the end of the program or a break point is met. A break point is a place in your source code file where you temporarily want to stop execution of the program being debugged. Break points in GNU debugger can be placed using the break command. Look at the fol- lowing list of the source code file sum.c which you already have used: gdb list 1 include stdio.h 2 main 3 { 4 int num1, num2, total ; 5 6 printfEnter first number : ; 7 scanfd, num1; 8 printfEnter second number : ; 9 scanfd, num2; 10 gdb To place a break point at line number 6 in file sum.c displayed above, you can use the following command: gdb break sum.c:6 Breakpoint 1 at 0x8048496: file sum.c, line 6. gdb Adding Break Points 157 As you can see from the above lines, when you set a break point, GNU debugger will dis- play its information in the next line. This information contains the number of the breakpoint, memory address, file name and line number. You can also see a list of currently set break points using the following command: gdb info break Num Type Disp Enb Address What 1 breakpoint keep y 0x08048496 in main at sum.c:6 gdb Break points can also be set on function names. The following command sets a break point where function main starts: gdb break main Breakpoint 1 at 0x8048496: file sum.c, line 6. gdb Note that although the function main starts at line number 2, the break point is set at line number 6. This is because the first executable instruction of the function main is located at this line number. You can also set a break point at a particular line number in the currently loaded file. The following command creates a break point at line number 8: gdb break 8 Breakpoint 2 at 0x80484ba: file sum.c, line 8. gdb In a multi-source file project, you set up a break point by including the file name and line number on the command line. The following command sets up a break point at line number 9 in file sum.c. gdb break sum.c:9 Breakpoint 3 at 0x80484ca: file sum.c, line 9. gdb You can also use an offset value to set up a break point. For example if the execution pointer is on line number 6, you can set up a break point at line number 9 using the following command. Note that you can also use a minus symbol to specify an offset. 6 printfEnter first number : ; gdb break +3 Note: breakpoint 3 also set at pc 0x80484ca. Breakpoint 4 at 0x80484ca: file sum.c, line 9. gdb All break points can be displayed using the info command. The following command dis- plays three break points that we have specified: gdb info break Num Type Disp Enb Address WhatParts
» the linux development platform 2003
» Requirement Gathering Life Cycle of a Software Development Project
» Writing Functional Specifications Life Cycle of a Software Development Project
» Creating Architecture and Design Documents
» Implementation and Coding Life Cycle of a Software Development Project
» Testing Life Cycle of a Software Development Project
» Technical documentation developed during the development process. This includes
» Technical documentation prepared for technical support staff. This includes technical
» End-user manuals and guides. This is the documentation for the end user to assist the
» Software Releases Support and New Features
» Hardware Platform Components of a Development System
» Operating System Components of a Development System
» Editors Components of a Development System
» Compilers and Assemblers Components of a Development System
» Debuggers Components of a Development System
» Version Control Systems Components of a Development System
» Selection Criteria for Hardware Platform Selection Criteria for Software Development Tools
» Creating Deadlines Managing Development Process
» Managing the Development Team
» Resolving Dependencies Managing Development Process
» Libraries Linux Development Platform Specifications LDPS and Linux
» Open Source Developers Network at http:www.osdn.org
» Extensibility What to Look for in an Editor
» References and Resources the linux development platform 2003
» Target machine. This is the machine for which the newly built compiler will generate
» Post-Installation Tasks Installing GNU Compiler
» Compiling to Intermediate Levels
» Compilation with Debug Support
» Compilation with Optimization Compiling a Program
» Compiling Source Code for Other Languages
» Linking a program Assembling a Program
» Creating Libraries the linux development platform 2003
» Standard Libraries the linux development platform 2003
» Compiling Fortran Programs the linux development platform 2003
» Smalltalk Oberon Other Compilers
» The target 2. Dependencies Basic Terminology
» The explicit rules 2. The implicit rules
» Input Files Introduction to GNU make
» Typical Contents of a Makefile
» Running make Introduction to GNU make
» Shell to Execute Commands Include Files
» The ftp server The The dnsresolver
» FTPOBJS OBJS Another Example of Makefile
» Explicit Rules The make Rules
» Implicit Rules The make Rules
» Defining Variables Types of Variables
» Pre-Defined Variables Automatic Variables
» Makefile in The Top Directory
» Makefile in common-dir Directory
» Makefile in the ftp-dir Directory
» Makefile in the tftp-dir Directory Makefile in the dns-dir Directory
» Building Everything Working with Multiple Makefiles and Directories
» The ifdef Directive Control Structures and Directives
» The ifndef Directive Control Structures and Directives
» Compilation Getting the Latest Version and Installation
» Most Commonly Used gdb Commands
» Passing Command Line Arguments to the Program Being Debugged
» The step and finish Commands
» Introduction to GDB Working with the Stack
» Displaying Program Variables Displaying Variables
» Automatic Displaying Variables with Each Command
» Displaying Environment Variables Displaying Variables
» Modifying Variables Displaying Variables
» Disabling Break Points Enabling Break Points
» Debugging Optimized Code the linux development platform 2003
» Debugging Running Processes the linux development platform 2003
» The kdbg Debugger Other Open Source Debuggers
» The ddd Debugger Other Open Source Debuggers
» The xxgdb Debugger Other Open Source Debuggers
» CVS Policies the linux development platform 2003
» Project Management and Communication
» Remote Repositories Checking out a Project
» Finding the Status of a Project
» Finding Differences Using the CVS Client
» Resolving Conflicts Using the CVS Client
» Checking the Project Back In Adding Files to a Project
» Removing Files from a Project
» Tags and Releases Using the CVS Client
» System Requirements Introduction to jCVS
» Installation Instructions Introduction to jCVS
» Using jCVS Introduction to jCVS
» Installing pcl-cvs Using Emacs with CVS
» Using pcl-cvs Using Emacs with CVS
» Have a shell account on the CVS server. 2. Create a publicprivate key pair on the client.
» Selecting Coding Styles Using indent Utility
» Formatting Braces Using indent Utility
» Formatting Declarations Using indent Utility
» Breaking Long Lines Using indent Utility
» Summary of Options Using indent Utility
» Using sed Utility Using cscope and cbrowser
» Generating C Function Prototypes from C Source Code Using cproto
» Using ltrace and strace Utilities
» Value 2. Type Name Using the nm Utility
» Using the ranlib Utility Using the strip Utility
» Using the strings Utility Using the addr2line Utility
» Host Machine Introduction to the Cross-Platform Development Process
» Target Machine Introduction to the Cross-Platform Development Process
» Cross Platform Development Cycle
» Embedded Systems and Moving Parts
» Embedded Systems and Power Consumption
» Embedded Operating Systems What are Embedded Systems?
» Knowledge of Target System Hardware
» Software Emulators Cross Compilations
» Using gdbserver with GNU Debugger
» Attaching to a Running Process Using gdbserver
» Arcom SBC-GX1 Board Hardware Used for Cross-Platform and Embedded Systems
» Artesyn PMPPC Mezzanine Card
» References the linux development platform 2003
» Java Compiler Java Virtual Machine
» Kaffe the linux development platform 2003
» The Jboss Java Development System
» Getting and Installing Java SDK from Sun Creating jar Files
» Creating Source Code File Compiling Java Code
» Running Java Applications Building Java Applications
» Using gcj to Build Java Applications
» Building Applets the linux development platform 2003
» Testing Applets with Netscape
» Jikes for Java the linux development platform 2003
Show more