Debugging with GDB ManualThe GNU Source-Level DebuggerHP Part Number: 5992-4701Published: February 2009Edition: 19
14.35.3.1 Printing of locals and globals in a stripped module...24014.35.3.2 Backtrace on stripped frames...
9 Using GDB with Different LanguagesAlthough programming languages generally have common aspects, they are rarelyexpressed in the same manner. For ins
'.cxx','.c++''.f', '.F','.f90'Fortran source file. GDB does not distinguish between Fortran 77 and F
9.2 Displaying the languageThe following commands help you find out which language is the working language,and also what language source files were wr
error 1 + 2.3The second example fails because the CARDINAL 1 is not type-compatible with theREAL 2.3.For the expressions you use in GDB commands, you
For expressions you use in GDB commands, you can tell GDB to treat range errors inone of three ways: ignore them, always treat them as errors and aban
9.4.1 C and C++Since C and C++ are so closely related, many features of GDB apply to both languages.Whenever this is the case, we discuss those langua
==, !=Equality and inequality. Defined on scalar types. The value of theseexpressions is 0 for false and non-zero for true.<, >, <=, >=Les
:: C++ scope resolution operator. Defined on struct, union, andclass types.::Double colons also represent the GDB scope operator (see“Expressions” (pa
9.4.1.3 C++ expressionsGDB expression handling can interpret most C++ expressions.WARNING! GDB can only debug C++ code if you use the proper compiler.
16.2.10 Miscellaneous commands...26516.3 XDB data formats and HP WDB equi
references are often used for large structures. The address of a reference variableis always shown, unless you have specified 'set print address
Range checking, if turned on, is done on mathematical operations. Array indices arenot checked, since they are often used to index a pointer that is n
searches for a function whose signature matchesthe argument types, using the standard C++conversion rules (see “C++ expressions”(page 109), for detail
integer*1, integer*2,integer*4, integer*8• allocatable• assumed-sizelogical*1, logical*2,• assumed-shapelogical*4, logical*8 byte,• adjustablereal*4,
info common<common_block_name>Lists values of variables in the named commonblock.Fortran entry points are supported.You can set a break point sp
10 Examining the Symbol TableThe commands described in this chapter allow you to inquire about the symbols (namesof variables, functions, and types) d
detailed description, instead of just the name ofthe type.For example, for this variable declaration:struct complex {double real; double imag;} v;the
info functions regexpPrint the names and data types of all definedfunctions whose names contain a match forregular expression regexp. Thus, 'info
showsymbol-reloadingShow the current on or offsetting.set opaque-type-resolutiononTell GDB to resolve opaque types. An opaquetype is a type declared a
11 Altering ExecutionOnce you think you have found an error in your program, you might want to find outfor certain whether correcting the apparent err
20.7 Errors...30220.8 Informatio
((gdb)) p g$1 = 1((gdb)) set g=4((gdb)) p g$2 = 1((gdb)) rThe program being debugged has been started already.Start it from the beginning? (y or n) yS
or of local variables. For this reason, the jump command requestsconfirmation if the specified line is not in the function currentlyexecuting. However
return, returnexpressionYou can cancel execution of a function call with the returncommand. If you give an expression argument, its valueis used as th
show writeDisplay whether executable files and core files are opened forwriting as well as reading.11.6 Patching programs 123
12 GDB FilesGDB needs to know the file name of the program to be debugged, both in order to readits symbol table and in order to start your program. T
filename means to discard information on theexecutable file.symbol-file [ filename ]Read symbol table information from file filename.PATH is searched
option with any of the commands that loadsymbol table information, if you want to be sureGDB has the entire symbol table available.If memory-mapped fi
To do this, use the kill command (see “Killingthe child process” (page 45)).add-symbol-file filenameaddress, add-symbol-fileThe add-symbol-file comman
info files, info target info files and info target aresynonymous; both commands print the currenttarget (see Chapter 13 (page 133)), including thename
List of Tables14-1 Memory Debugging Commands in Interactive and Batch Mode...17716-1 Invocation commands...
show auto-solib-addDisplay the current autoloading size threshold,in megabytes.12.2 Specifying shared library locationsOn HP-UX, when the shared libra
For example, if you want to use /tmp/usr/lib/libsubs.sl and /tmp/usr/share/lib/libsubs.sl, you can set GDB_SHLIB_ROOT' to /tmp. Now whenever GDBe
the preceding source line. This is known to occurin the SunOS 4.1.1 (and earlier) C compiler.GDB circumvents the problem by treating thesymbol scope b
13 Specifying a Debugging TargetA target is the execution environment occupied by your program.Often, GDB runs in the same host environment as your pr
names or host names to connect with, processnumbers, and baud rates.The target command does not repeat if you pressRET again after executing the comma
target simBuiltin CPU simulator. GDB includes simulators formost architectures. In general,the following commandswork:target simloadrunHowever, you ca
set endian bigInstruct GDB to assume the target is big-endian.set endian littleInstruct GDB to assume the target is little-endian.set endian autoInstr
14 HP-UX Configuration-Specific InformationWhile nearly all GDB commands are available for all native and cross versions of thedebugger, there are som
• Serial debugging of a parent and child process.• Support for Parallel Processing limited to pthread parallelism, but not the compilergenerated paral
• Enhanced info symbol ADDRESS command. The info symbol ADDRESScommand has been enhanced to search for a symbol at the given address.Previously, the i
List of Examples14-1 Sample Output for the find command...19814-2 Sample Commands to
• Support for evaluating macros.• Support for printing the execution path entries in the current frame, or thread.• New Command for Searching a Patter
the standard library routines under libc.so and libdld.so. The following standardlibraries are dependencies for runtime checking:unlink()abort()uwx_re
14.3 Supported Platforms and Modes• Supported PlatformsHP WDB supports source-level debugging of programs written in HP C, HP aC++,and Fortran 90 on I
NOTE: HP WDB cannot be attached to a process that is traced by tools which usettrace, such as Caliper, adb, and tusc. The debugger displays the follow
n/a/opt/langtools/bin$WDB_ROOT/binlibrtc.sl locationn/aGDB_SERVER$WDB_ROOT/binNone$LIBRTC_SERVERn/a$WDB_ROOT/lib/opt/langtools/binNOTE: If you define
however, may not find source files if the object files arenot available.This minimizes or eliminates the need to specify multipleobjectdir commands wh
The advantages include:• You do not have to recompile and relink the entire program.• You do not have to reload the program into the debugger.• You ca
• You cannot add an alloca() function to a frame that did not previously usealloca().• New structure fields can be added at the end of a structure obj
NOTE: You must rebuild the program after you use the fix command because thechanges you make are temporarily patched into the executable image. The ch
The problem might be that there is no return for the num function. You can correctthis without leaving the debugger.4. Set a break point at main:(gdb)
Summary of GDBThe purpose of a debugger such as GDB is to allow you to see what is going on “inside”another program while it executes―or what another
10. When you finish with the debugging session, you can exit the debugger normally:(gdb) qThe following modules in /dev/src/mysum have been fixed:/dev
3. You can use the following commands for debugging inline functions in HP 9000systems:stepnextlistbacktraceframe <n>info localsinfo argsThe fol
The set inline-debug off command disables the inline debugging feature. Youcan disable inline debugging by entering this command before attaching the
(gdb) set inline-debug inline_bp_all or$ gdb --inline = inline_bp_all• To set and modify individual breakpoints on specific instances of inlinefunctio
- show macro [macro-name] or info macro [macro-name]Displays the macro definition, source file name, and the line number. For example:(gdb) info macro
The macro debugging features are supported for +objdebug and +noobjdebugcompiler options.14.9.2 Examples for Macro DebuggingThe following example illu
(gdb) b 13Breakpoint 1 at 0x40007d0:0: file scope.c, line 13 from sc.(gdb) b 23Breakpoint 2 at 0x40007d0:2: file scope.c, line 23 from sc.(gdb) b 30Br
Breakpoint 2 at 0x40007d0:2: file scope.c, line 23 from sc1.(gdb) b 30Breakpoint 3 at 0x40007e0:0: file scope.c, line 30 from sc1.(gdb) rStarting prog
For more information on memory debugging with WDB, see the Debugging DynamicMemory Usage Errors Using HP WDB whitepaper at the HP WDB Documentationweb
HP WDB offers the following memory-debugging capabilities:• Reports memory leaks• Reports heap allocation profile• Stops program execution if bad writ
Plea: Additions to this section are particularly welcome. If you or your friends (orenemies, to be evenhanded) have been unfairly omitted from this li
use info heap, the result does not show anyallocations.info heap filenameWrites heap report output to the specified file.info heap idnumberProduces de
info leaks filenameWrites the complete leak report output to thespecified file.info leak leaknumberProduces detailed information on the specifiedleak
and, bcopy. WDB 5.6 and later versions of thedebugger also validates calls to strcat andstrncat.NOTE: HP WDB 6.0 and later versions of thedebugger imp
for the footer is 16 bytes if this option is not used.If the user specifies a value less than 16 for thenumber of bytes, the debugger ignores it andta
The debugger assigns each leak a numeric identifier.7. To display a stack trace for a specific leak, use the info leak command andspecify the number f
frame_count=no_frames (or)set heap-check frame-count<no_frames>Sets the number of frames to be printed for leakcontext.min_heap_size=block_size(
4. Complete one of the following steps to preload the librtc runtime library:• Set the target application to preload librtc by using the +rtc option f
LD_PRELOAD=/opt/langtools/lib/librtc.sl <executable>– For 64-bit IPF applications,LD_PRELOAD=/opt/langtools/lib/pa20_64/librtc.sl <executable
has the filename rtcconfig. If user prefers to set this option, it must include thefilename.◦ Incorrect usage:export GDBRTC_CONFIG=./export GDBRTC_CON
mem_logfile=stderr[+]filenameheap_logfile=stderr[+]filename◦ Specify config_strings for +check=malloc on Itanium or WDB memorycheck batch mode on Inte
Brian Fox is the author of the readline libraries providing command-line editing andcommand history.Andrew Beers of SUNY Buffalo wrote the language-sw
4. Complete one of the following steps:– Map the shared libraries privately using chatr, as follows:chatr +dbg enable <executable>On HP-UX 11i v
2. The rtcconfig file should contain entries such as the following:check_heap=oncheck_leaks=oncheck_free=onfiles=exec1:exec2:exec3output_dir=/tmp/resu
1. Complete one of the following steps to preload the librtc runtime library:– Set the target application to preload librtc by using the +rtc option f
2. Run the program.3. Start a debugging session as follows:gdb -leaks <executable-name> <process-id>4. Use info heap and info leaks comman
set heap-check min-leak-size numFor example, if you use,set heap-check min-leak-size 100WDB does not collect stack traces for allocations smaller than
Syntax:info corruption [<file name>]The run time memory checking must be enabled before using the info corruptioncommand to detect memory corrup
NOTE: Software literature names this concept as premature free or Reading/writing freedmemory using a pointer.WDB tracks the dangling pointers and dan
Table 14-1 Memory Debugging Commands in Interactive and Batch ModeBatch modeInteractive modeCommand Descriptioncheck_heap= [on | off] (or)set heap-che
Table 14-1 Memory Debugging Commands in Interactive and Batch Mode (continued)Batch modeInteractive modeCommand DescriptionNot supported in batch mode
show heap-checkDisplays all current settings for memorychecking.14.10.10.2 info heap arenaThe info heap arena command enables the user to view high le
4. When the program is stopped at a breakpoint, use the info heap command:(gdb) info heapAnalyzing heap ...doneActual Heap Usage:Heap Start = 0x404080
set heap-check high-mem-countX_numberStops when brk() value has moved X_numberof times.Limitations:• This feature assumes that an application has a de
14.11.2 Backtrace Support for Thread DebuggingThe following commands are available as backtrace support for thread debugging:bt The bt command provide
• The thread terminates execution, and the resources associated with the terminatedthread continues to exist in the application because the thread has
features are available as options to the set thread-check command. The syntax forthe set thread-check command is as follows:set thread check { [on|off
uses the same condition variable in multiple calls,by different threads to pthread_cond_wait()or pthread_cond_timedwait(), but specifiesdifferent mute
read-write locks that are associated with thethread. The debugger transfers the executioncontrol to the user and prints a warning messagewhen this con
num-waiters [num] The set thread-check num-waiters[num] command checks if the number of threadswaiting on any pthread object exceeds thespecified thre
1. Set LD_LIBRARY_PATH to include the appropriate directory, by entering one ofthe following commands:• For 32 bit IPF applications,LD_LIBRARY_PATH=/o
$ chatr +dbg enable ./<executable>(This step is not required on Integrity systems.)To explicitly preload the librtc runtime library and start th
1 A Sample GDB SessionThis chapter describes the most common GDB commands with the help of an example.The following topics are discussed:• Loading the
NOTE: Use the set frame-count setting in the rtconfig file to control the depthof the stack trace file. This command controls the depth of the call st
NOTE: The configuration file contains lines of the following form:set thread-check [on|off] | [option] [on|off] | [option] [num]And/Orset frame-count
5. Complete one of the following steps to preload the librtc runtime library:• Set the target application to preload librtc by using the +rtc option f
If LD_PRELOAD and chatr +rtc are used to preload the librtc runtimelibrary , the librtc runtime library is loaded from the path specified byLD_PRELOAD
Behavior of the +check=thread option can be changed by users by providing theirown rtcconfig file. The user specified rtcconfig file can be in the cur
14.13 Debugging multiple processes ( programs with fork and vforkcalls)14.13.1 Ask mode for set follow-fork-modeThe ask command prompts the user to se
0x40172b27: (b2) P3lc_gr gr=400x40172b29: (61) R3body rlen=330x40172b2b: (81) B1label_state label=10x40172b2c: (c0) B2epilogue t=440x40172b2e: (00) R1
+lengthSpecifies the length of the memory address range. Thisparameter is mandatory when end-address is notspecified.expr1, expr2, ...Specifies a var
Example 14-1 Sample Output for the find command$ cat example.c#include <stdio.h>#include <stdlib.h>int main(){ char *str; str = (char *)
where:&a[0] Specifies the start address of the memory address range.&a[10] Specifies the end address of the memory address range.“el”, 'l
© Copyright 2009 Hewlett-Packard Development Company, L.P.Confidential computer software. Valid license from HP required for possession, use or copyin
$ (gdb) m4HP gdb 3.0 for PA-RISC 1.1 or 2.0 (narrow), HP-UX 11.00.Copyright 1986 - 2001 Free Software Foundation, Inc.Hewlett-Packard Wildebeest 3.0 (
NOTE: Following are different ways of representing the /size-char and/max-count parameters:/1b/b1/b /1/1 /b where:1 Specifies that find must display 1
the core file to be used if the packcore directory does not contain a core file. If used,this second argument causes a symbolic link to be created in
NOTE: Limitations for the enhanced info target command on corefile are asfollows:• The enhanced info target command is not supported when theexpanded_
To analyze this core file with HP WDB on HP-UX 11i version 2, you must do thefollowing:• When starting from HP WDB command line:(gdb) core-file [core.
For example,(gdb) i ep 4 10• info exec-path summaryPrints the summary information about all the local execution path entries in thecurrent frame. This
For more information on this feature, see the following example.14.16.2 Example Illustrating Execution Path RecoveryThe following example illustrates
(gdb) i epLocal execution path table for main():0 0x4000a80:2 (execpath.c:10)(gdb) i gepGlobal execution path table:G0 0x4000a80:2 main (execpath.c:10
14.18 Invoking GDB Before a Program AbortsThis -crashdebug option enables GDB to monitor the execution of a process or aprogram. It invokes GDB when t
Abort gdb command line call? (y or n) y#0 main () at ./address_error.c:4141 fun (count, count*1.1);(gdb) bt#0 main () at ./address_error.c:41(gdb) qui
14.21.3.1 Setting breakpoints in unstripped shared libraryGDB will not be able to put breakpoints using symbolic names(of the symbols not inexport lis
((gdb)) n882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\: nil,1.6 Stepping into a subroutineThe set_quotes looks like a promising subroutine
Setting a breakpoint on a template method with multiple instantiations displays a menushowing all instantiations and the user can choose to set breakp
14.22.2 Setting Deferred Breakpoints in Shared LibraryOn HP-UX, GDB automatically loads symbol definitions from shared libraries whenyou use the run c
To set the breakpoint you must kill the program and then rerun it so that the dynamiclinker maps a copy of the shared library privately. There are two
The -mapshared option is implemented on both PA-RISC and Itanium platforms inHP WDB 5.2. This option is provided in the WDB GUI and HP WDB. The defaul
14.23.1.1 Printing Decimal floating point constant(gdb) print <num><df/dd/dl/DF/DD/DL>df, DF - _Decimal32dd, DD - _Decimal64dl, DL - _Deci
HP WDB supports:• Evaluation of expressions with decimal floating point constants and variables.• Setting or assignment of decimal floating point cons
Conversion of types:GDB handles conversion of data types during assignment, printing, and arithmeticand comparison operation.(gdb) p 1.2df +1.2ddThis
14.25 Language support14.25.1 Enhanced Java Debugging SupportHP WDB shows stack traces of mixed Java, C, and C++ programs. It supports unwindingacross
Additional stack unwind features are available starting with SDK 1.4.2. These featuresfall into three categories: Java stack unwind enhancements, Java
Java VM Debugging CommandsThe following commands have been added to enhance Java debugging support:brbacktrace Prints backtrace of mixed Java and nati
((gdb)) p lquote$1 = 0x35d40 "<QUOTE>"((gdb)) p rquote$2 = 0x35d50 "<UNQUOTE>"1.9 Listing Source Codelquote and rquote
14.25.1.3 Java corefile debugging supportHP WDB shows stack traces of mixed Java, C, and C++ programs for java corefile.GDB_JAVA_UNWINDLIB environment
2. Attach gdb to the running process:$ gdb -p 23989HP gdb 5.0 for HP Itanium (32 or 64 bit) and target HP-UX 11.2x.Copyright 1986 - 2001 Free Software
/* off 453 bits, len 27 bits */float f;/* off 480 bits, len 32 bits */14.25.3 Support for _ _fpreg data type on IPFWDB internally converts __fpreg dat
You do not need to use fully qualified names to access symbols within a namespace.The debugger can compile a list of namespaces active in the scope th
14.27 Support for output loggingThe Visual Interface for HP WDB terminal user interface (TUI) mode supports thecommand, log logfile_name, that saves t
where, ARRAY is the name of the array, and its size is 5x5.The first two lines are comments about this file and the array. The third line denotesthe a
"Steplast is not meaningful for the current line."For example,(gdb) 4 int k = 10; (gdb) sl ---> alias to "steplast" command err
14.29 Debugging optimized codeHP WDB supports debugging of optimized code (compiled with both -g and -O) forHP aC++, HP ANSI C and HP WDB for HP Itani
The following commands are not affected by the optimization level of the programbeing debugged:• attach• catch• commands• continue• core• delete• defi
14.29.1 Debugging Optimized Code at Various Optimization LevelsThe following sections describe debugging optimized code support at each optimizationle
((gdb)) cContinuing.define(baz,defn(<QUOTE>foo<UNQUOTE>))baz0000Success! The new quotes now work just as well as the default ones. The pro
and later versions provide support to prevent the debugged program from stoppingat instructions that are predicated false. The program execution can b
execution pattern and translates only the frequently executed code into native Itanium(R)code at runtime.14.30.1 Debugging the application using GDB u
identically. The exact behavior shown by HP 9000 GDB under ARIES may differfrom that on a HP 9000 HP-UX server.• If the debugged process is blocking i
14.31 Visual Interface for WDBWDB includes an HP-supported Visual Interface for WDB with both graphical andterminal modes. The interface is based on V
(wdb) quit14.31.2 Navigating the Visual Interface for WDB displayThe Visual Interface for WDB window consists of two areas:• Source pane at the top• D
Run Resume Stop Up Visual Finish Print Type List Interface for WDBFaq Stop
14.31.5 Using the TUI modeTo start Visual Interface for WDB in terminal user interface (TUI) mode, run VisualInterface for WDB with the command: /opt/
14.31.7 Using commands to browse through source filesbrowse. For example, CTRL-B, CTRL-F, CTRL-D, CTRL-U are useful for browsing thedebugger window. T
To save a session to a file:1. Right-click an empty region of the source or debugger pane.2. Choose "Save Session to vdb.pid" from the pop-u
14.35.1 Support for command line calls in a stripped executable on PA-RISC systemsIn WDB, to perform command line calls in a shared library without th
24
14.35.2.2 For 64-bit applicationsTo perform command line calls in a stripped executable, linked with end.o, you needto do the following:• In the +std
14.36 Displaying the current block scope informationThe which command takes a symbol as an argument and prints the information on agiven symbol. It pr
242
15 The HP-UX Terminal User InterfaceBy default, GDB runs in line mode. For users who prefer an interface similar (thoughnot identical) to that of the
When you execute the program up to the first breakpoint by issuing the commandruna right angle bracket (>) points to the current location. So after
The Command pane is always present. The possible configurations of the other panesare:• Source• Disassembly• Source/Disassembly• Disassembly/Register•
15.3.3 Source/Disassembly paneThe Source/Disassembly pane appears when you issue the command:la splitYou can also reach this pane from the Source pane
|;;; print_average (my_list, first, last); |*> |0x3524 <main+8> addil L'-0x800,%dp,%r1
15.4 Cycling through the panesUse the commandsla nextandla prevto move from one pane to another without specifying a window name. If you specifyla nex
:...::flags 29000041 r1 51a800 rp 7f6ce597 :
2 Getting In and Out of GDBThis chapter discusses how to start GDB, and exit out of it. The essentials are:• type '(gdb)' to start GDB.• typ
(gdb) la split(gdb) la regs(gdb) la src(gdb) la regs(gdb) foc nextFocus set to REGS window.(gdb)15.6 Scrolling panesTo scroll within a pane, you can u
*>:32 print_average (my_list, first, last); : :33 print_average (my_list, first, last - 3);
winheight [win_name] [+ | -] num_linesIf you omit win_name, the pane with logical focus is resized. When you increase theheight of a pane, the height
16 XDB to WDB Transition GuideThis transition aid is designed for XDB users who are learning WDB, an HP-supportedversion of the industry-standard GDB
• “Assertion control commands”• “Record and playback commands”• “Macro facility commands”• “Signal control commands”• “Miscellaneous commands”16.1.1 I
Table 16-2 Window mode commands (continued)MeaningWDB EquivalentXDB CommandDisplay general registersgr (with -xdb -tui),display $regs (with -tui)grDis
Table 16-3 File viewing commands (continued)MeaningWDB EquivalentXDB CommandList source directory search path(list all directories)ld (with -xdb), sho
Table 16-4 Data viewing and modification commandsMeaningWDB EquivalentXDB CommandMove view location forward orbackward in source file numberlinesl (wi
Table 16-4 Data viewing and modification commands (continued)MeaningWDB EquivalentXDB CommandPrint address using specified for-matp/format &ex
Table 16-5 Stack viewing commands (continued)MeaningWDB EquivalentXDB CommandView procedure one level nearerinnermost frame of stack (lowernumber)down
All options and command-line arguments you give are processed in sequential order.The order makes a difference when the `-x' option is used.2.1.1
Table 16-7 Job control commands (continued)MeaningWDB EquivalentXDB CommandGo forward or back given # linesg {+ | -}lines (with-xdb), go {+ | -}lines,
Table 16-9 Auxillary breakpoint commandsMeaningWDB EquivalentXDB CommandPrint any stringp "any string"any_stringConditionally execute cmdsif
Table 16-10 Breakpoint creation commands (continued)MeaningWDB EquivalentXDB CommandSet a class breakpoint at firstexecutable line of all memberfuncti
Table 16-11 Overall breakpoint commands (continued)MeaningWDB EquivalentXDB CommandSet a breakpoint countbc number expr (with -xdb),ignorenumber expr
16.2.6 Assertion control commandsGDB does not provide the ability to trace by instruction. Watchpoints, however, providesimilar functionality to xdb a
Table 16-13 Macro facility commandsMeaningWDB EquivalentXDB CommandDefine a user-defined commanddef name [GDB prompts forcommands]def name replacement
Table 16-15 Miscellaneous commands (continued)MeaningWDB EquivalentXDB CommandInvoke a shell! cmd line (with -xdb), shecmd line! cmd lineExecute comma
Table 16-16 Data format commands (continued)MeaningWDB EquivalentXDB CommandDecimal integerddLong decimal integerdD (1)e Floating-point notation as fl
Table 16-16 Data format commands (continued)MeaningWDB EquivalentXDB CommandPrint in binarytzPrint in long binarytZ (1)(1) HP WDB will display data in
Table 16-18 Special language operatorsMeaningWDB EquivalentXDB Language OperatorUnary operator, address of objectDepends on language$addrUnary Boolean
-m, -mappedWarning: this option depends on operating system facilitiesthat are not supported on all systems.If memory-mapped files are available on yo
16.7 XDB variable identifiers and HP WDB equivalentsTable 16-20 Variable IdentifiersMeaningWDB EquivalentXDB Variable IdentifierSearch for varvarvarSe
Table 16-21 A (continued)Equivalent WDB CommandXDB CommandNo exact equivalent, but display expr is equivalentto abc print exprabc cmdsam (with -xdb),
Table 16-22 B (continued)Equivalent WDB CommandXDB Commandbu [depth] (with -xdb). The finish command isequivalent to the sequence bu, c, db (to contin
16.8.4 F through KTable 16-24 F through KEquivalent WDB CommandXDB CommandNo equivalentf ["printf-style-fmt"]fr (with -xdb -tui), display $f
Table 16-25 L (continued)Equivalent WDB CommandXDB Commandshow user [string]lm [string]info func [[class]::][string]lo [[class]::][string]info functio
Table 16-26 M through P (continued)Equivalent WDB CommandXDB CommandNo equivalentpq class::No equivalentpq [+ | -][\format16.8.7 Q through STable 16-2
Table 16-28 T (continued)Equivalent WDB CommandXDB CommandNo equivalenttaNo equivalenttbNo equivalenttctd (with -xdb -tui)tdtf (with -xdb -tui), toggl
Table 16-29 U through Z (continued)Equivalent WDB CommandXDB Commandgdb -xdb program -c corefilexdb program corefilegdb -xdb -d dirxdb -d dirgdb -xdb
Table 16-30 Symbols (continued)Equivalent WDB CommandXDB CommandReturnReturnp "any string""any string"Empty string; for example, p
Table 16-30 Symbols (continued)Equivalent WDB CommandXDB CommandControl-CControl-C# [text]# [text]No equivalent#label16.8 Alphabetical lists of XDB co
'-n'). Exit with nonzero status if an error occurs inexecuting the GDB commands in the command files.Batch mode may be useful for running GD
280
17 Controlling GDBYou can alter the way GDB interacts with you by using the set command. For commandscontrolling how GDB displays data, see “Print set
set editing-mode viThe readline interface uses the .inputrc file tocontrol the settings.set history filename fnameSet the name of the GDB command hist
show commands Display the last ten commands in the commandhistory.show commands nPrint ten commands centered on commandnumber n.show commands + Print
set radix 0xasets the base to decimal. On the other hand, setradix 10 leaves the radix unchanged no matterwhat it was.set output-radix baseSet the def
set confirm on Enables confirmation requests (the default).show confirm Displays state of confirmation requests.17.7 Optional messages about internal
show debug varobj Displays the current state of displaying GDB variableobject debugging info.286 Controlling GDB
18 Canned Sequences of CommandsIn addition to breakpoint commands (see “Breakpoint command lists” (page 61)), GDBprovides the following two ways to st
are executed repeatedly as long as the expressionevaluates to true.document commandname Document the user-defined command commandname,so that it can b
enddefine hook-continuehandle SIGLARM passendYou can define a hook for any single-word command in GDB, and not for commandaliases; Also you should def
print routines so as to allow Epoch to display values ofexpressions in a separate window.-annotate levelThis option sets the annotation level inside G
• VxWorks (Wind River Systems real-time OS): .vxgdbinit• OS68K (Enea Data Systems real-time OS): .os68gdbinit• ES-1800 (Ericsson Telecom AB M68000 emu
not entered in the value history either. See“Expressions” (page 83).output/fmt expression Print the value of expression in format fmt. Youcan use the
292
19 Using GDB under gnu EmacsA special interface allows you to use gnu Emacs to view (and edit) the source files forthe program you are debugging with
In the GDB I/O buffer, you can use these special Emacs commands in addition to thestandard Shell mode commands:C-h mDescribe the features of Emacs&apo
is formatted using the Emacs function format; otherwise thenumber is passed as an argument to the corresponding listelement.In any source file, the Em
20 GDB AnnotationsThis chapter describes annotations in GDB. Annotations are designed to interface GDBto graphical user interfaces or other similar pr
command history, nor will it affect GDB's notion of which command to repeat if RETis pressed on a line by itself.The server prefix does not affec
^Z^Zfield-valuethe-value^Z^Zfield-endwhere field-name is the name of the field, separator-string is text whichseparates the name from the value for th
Table of ContentsSummary of GDB...
'xdb_trans.html', which is usually installed in thedirectory /opt/langtools/wdb/doc on HP-UXsystems.-interpreter interpUse the interpreter i
• ^Z^Zfunction-callfunction-call-stringwhere function-call-string is text designed to convey to the user that thisframe is associated with a function
where source-intro-string separates for the user's benefit the reference fromthe text which precedes it, filename is the name of the source file,
^Z^Zpre-prompt^Z^Zprompt^Z^Zpost-promptThe input types are:prompt When GDB is prompting for a command (the main GDBprompt).commands When GDB prompts f
where header-entry has the same syntax as an entry (see below) but instead ofcontaining data, it contains strings which are intended to convey the mea
is output. Before the stopped annotation, a variety of annotations describe how theprogram stopped.^Z^Zexited exit-status The program exited, and exit
20.12 Annotations We Might Want in the Future• target-invalidthe target might have changed (registers, heap contents, or execution status). Forperform
306
21 The GDB/MI InterfaceFunction and purposeGDB/MI is a line based machine oriented text interface to GDB. It is specifically intendedto support the de
Notes:• The CLI commands are still handled by the MI interpreter; their output is describedbelow.• The token, when present, is passed back when the co
value const | tuple | listconst c-stringtuple → "{}" | "{" result ( "," result )* "}"list "[]"
type the interrupt character at any time because GDB does not allow it to take effectuntil a time when it is safe.You can use the detach command to re
21.1.3 Simple examples of GDB/MI interactionThis subsection presents several simple examples of interaction using the GDB/MIinterface. In these exampl
21.3 GDB/MI output records21.3.1 GDB/MI result recordsIn addition to a number of out-of-band notifications, the response to a GDB/MI commandincludes o
Note the line breaks shown in the examples are here only for readability. They do notappear in the real output. Also note that the commands with a non
Example(gdb)-break-insert main^done,bkpt=number="1",type="breakpoint",disp="keep",enabled="y",addr="0x000
addr="0x000100d0",func="main",file="hello.c",line="5",cond="1",times="0",ignore="3&qu
-break-list^done,BreakpointTable={nr_rows="1",nr_cols="6",hdr=[{width="3",alignment="-1",col_name="number
ExampleN.A.The -break-insert commandSynopsis-break-insert [ -t ] [ -h ] [ -r ][ -c condition ] [ -i ignore-count ][ -p thread ] [ line | addr ]If spec
^done,bkpt=number="1",type="breakpoint",disp="keep",enabled="y",addr="0x0001072c",file="recursi
hdr=[{width="3",alignment="-1",col_name="number",colhdr="Num"},{width="14",alignment="-1",
(gdb)-exec-continue^running(gdb)*stopped,reason="watchpoint-trigger",wpt=number="2",exp="i",value=old="0",new=
32
^done,BreakpointTable=nr_rows="1",nr_cols="6",hdr=[width="3",alignment="-1",col_name="number",colhdr
GDB commandThere is no direct mapping from this command to the CLI.ExampleDisassemble from the current value of $pc to $pc + 20:(gdb)-data-disassemble
^done,asm_insns=[src_and_asm_line={line="31",file="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \testsuite/gdb.mi/basics.c",li
The -data-list-changed-registers CommandSynopsis-data-list-changed-registersDisplay a list of the registers that have changed.GDB commandGDB does not
(gdb)-data-list-register-names^done,register-names=["r0","r1","r2","r3","r4","r5","r6
^done,register-values=[{number="0",value="0xfe0043c8"},{number="1",value="0x3fff88"},{number="2",val
'word-format'The format to be used to print the memory words. The notationis the same as for GDB print command (see“Output formats”(page 86)
next-row="0x00001512",prev-row="0x0000150e",next-page="0x00001512",prev-page="0x0000150e",memory=[{addr="
The -display-enable commandSynopsis-display-enable numberEnable display number.GDB commandThe corresponding GDB command is 'enable display'.
Set the GDB working directory.GDB commandThe corresponding GDB command is 'cd'.Example(gdb)-environment-cd /kwikemart/marge/ezannoni/flathea
3 GDB CommandsYou can abbreviate a GDB command to the first few letters of the command name, ifthat abbreviation is unambiguous; and you can repeat ce
The -environment-pwd commandSynopsis-environment-pwdShow the current working directory.GDB commandThe corresponding GDB command is 'pwd'.Exa
The -exec-abort commandSynopsis-exec-abortKill the inferior running program.GDB commandThe corresponding GDB command is 'kill'.ExampleN.A.Th
The -exec-finish commandSynopsis-exec-finishAsynchronous command. Resumes the execution of the inferior program until thecurrent function is exited. D
Example(gdb)111-exec-continue111^running(gdb)222-exec-interrupt222^done(gdb)111*stopped,signal-name="SIGINT",signal-meaning="Interrupt&
Example(gdb)-exec-next-instruction^running(gdb)*stopped,reason="end-stepping-range",thread-id="1",frame=addr="0x00002a14"
Example(gdb)-break-insert main^done,bkpt=number="1",type="breakpoint",disp="keep",enabled="y",addr="0x000
Regular stepping:-exec-step^running(gdb)~"2"~"3"*stopped,reason="end-stepping-range",thread-id="1",frame=addr=
greater than the current one is reached. The reason for stopping in this case will be'location-reached'.GDB commandThe corresponding GDB com
GDB commandThe corresponding GDB command is 'exec-file'.Example(gdb)-file-exec-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx^done(gdb)T
GDB commandThe corresponding GDB command is info shared.ExampleN.A.The -file-list-symbol-files commandSynopsis-file-list-symbol-filesList symbol files
GDB fills in the rest of the word 'breakpoints', since that is the only infosubcommand beginning with 'bre':((gdb)) info breakpoin
Exit GDB immediately.GDB commandApproximately corresponds to 'quit'.Example(gdb)-gdb-exitThe -gdb-set commandSynopsis-gdb-setSet an internal
Show version information for GDB. Used mostly in testing.GDB commandThe corresponding GDB command is 'show version'.Example(gdb)-gdb-version
ExampleFor a stack with frame levels 0 through 11:(gdb)-stack-info-depth^done,depth="12"(gdb)-stack-info-depth 4^done,depth="4"(gd
file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="27"},frame={level="4 ",addr="0x000107e0",func="m
arguments (inclusive). If the two arguments are equal, it shows the single frame at thecorresponding level.GDB commandThe corresponding GDB commands a
(gdb)-stack-list-frames 3 3^done,stack=[frame={level="3 ",addr="0x000107a4",func="foo",file="recursive2.c",lin
21.10 GDB/MI Symbol query commandsThe -symbol-info-address commandSynopsis-symbol-info-address symbolDescribe where symbol is stored.GDB commandThe co
The -symbol-info-line commandSynopsis-symbol-info-lineShow the core addresses of the code for a source line.GDB commandThe corresponding GDB command i
List all the type names.GDB commandThe corresponding commands are 'info types' in GDB, 'gdb_search' in gdbtk.ExampleN.A.The -symbo
ExampleN.A.21.11 GDB/MI Target Manipulation CommandsThe -target-attach commandSynopsis-target-attach pid | fileAttach to a process pid or a file file
bubble(double,double) bubble(int,int)((gdb)) b 'bubble(In some cases, GDB can tell that completing a name requires using quotes. When thishappens
Example(gdb)-target-detach^done(gdb)The -target-download commandSynopsis-target-downloadLoads the executable onto the remote target. It prints out an
+download,{section=".text",section-sent="1536",section-size="6668",total-sent="1536",total-size="9880&quo
ExampleN.A.The -target-list-available-targets commandSynopsis-target-list-available-targetsList the possible targets to connect to.GDB commandThe corr
The -target-select commandSynopsis-target-select type parameters ...Connect GDB to the remote target. This command takes two args:'type' The
GDB commandThe equivalent GDB command is 'info threads'.ExampleN.A.The -thread-list-ids commandSynopsis-thread-list-idsProduces a list of th
^running(gdb)~"0x7f7f0aec"*stopped,reason="end-stepping-range",thread-id="2",frame=addr="0x00002ca4",func=&quo
binary, decimal, hexadecimal, octal, and natural. Natural refers to a default formatautomatically chosen based on the variable type (like decimal for
The frame under which the expression should be evaluated can be specified byframe-addr. A '*' indicates that the current frame should be use
Returns the number of children of a variable object name:numchild=nThe -var-list-children commandSynopsis-var-list-children nameReturns a list of the
value=valueThe -var-assign commandSynopsis-var-assign name expressionAssigns the value of expression to the variable object specified by name. The obj
help classUsing one of the general help classes as an argument, you canget a list of the individual commands in that class. For example,here is the he
360
22 Reporting Bugs in GDBYour bug reports play an essential role in making GDB reliable.Reporting a bug may help you by bringing a solution to your pro
Keep in mind that the purpose of a bug report is to enable us to x the bug. It may bethat the bug has been reported previously, but neither you nor we
• A description of the envelope of the bug.Often people who encounter a bug spend a lot of time investigating which changesto the input file will make
364
A Installing GDBIf you obtain GDB (WDB) as part of the HP ANSI C, HP ANSI C++ Developer's Kit forHP-UX Release 11.x, or HP Fortran, you do not ha
gdb-gdb-199991101/mmalloc source for the gnu memory-mapped mallocpackageThe simplest way to configure and build GDB is to run configure from thegdb-ve
(GNU make does), running make in each of these directories builds the gdb programspecified there.To build gdb in a separate directory, run configure w
% sh config.sub i386-linuxi386-pc-linux-gnu% sh config.sub alpha-linuxalpha-unknown-linux-gnu% sh config.sub hp9k700hppa1.1-hp-hpux% sh config.sub sun
--norecursionConfigure only the directory level where configure isexecuted; do not propagate configuration to subdirectories.--target=target Configure
listings under info and under show in the Index point to all the sub-commands. See???.info This command (abbreviated i) is for describing the state of
4 Running Programs Under GDBWhen you run a program under GDB, you must first generate debugging informationwhen you compile it using compiler option c
4.9 Debugging programs with multiple threads...464.10 Debugging programs with multiple pr
variable substitution) in describing thearguments. On Unix systems, you can controlwhich shell is used with the SHELL environmentvariable. GDB uses th
program. See “Program Input and Output”(page 43).WARNING! You can redirect input and output,but you cannot use pipes to pass the output ofthe program
programs you run. When debugging, it can be useful to try running your programwith a modified environment without having to start GDB over again.show
You can use the string '$cwd' to refer to whatever is the current working directory atthe time GDB searches the path. If you use '.&apo
NOTE:• You can redirect your program input and output using shell redirection with therun command. For example,run > outfilestarts your program, di
NOTE:• To use attach, your program must be running in an environment which supportsprocesses; for example, attach does not work for programs on bare-b
On some operating systems, a program cannot be executed outside GDB while youhave breakpoints set on it inside GDB. You can use the kill command in th
thread identifier whose form varies depending on the particular system. For example,on LynxOS, you might see[New process 35 thread 27]when GDB notices
show threadverbose Display whether set threadverbose is on oroff.Here are commands to get more information about threads:info threadsDisplay a summary
threadno is the internal GDB thread number,as shown in the first field of the 'info threads'display. To apply a command to all threads, uset
8.11 Printing Floating Point Values...998.12 Floating point hardware.
set follow-fork-mode modeSet the debugger response to a program call offork or vfork. A call to fork or vfork createsa new process. The mode can be:pa
5 Stopping and ContinuingThe principal purpose of a debugger is to let you stop your program before it terminatesabnormally or runs into trouble, so t
5.1.1 Setting breakpointsBreakpoints are set with the break command (abbreviated b). The debuggerconvenience variable '$bpnum' records the n
does not leave an active breakpoint. If you usebreak without an argument in the innermostframe, GDB stops the next time it reaches thecurrent location
are used. Delete or disable unused hardwarebreakpoints before setting new ones (see“Disabling breakpoints” (page 58)). See “Breakconditions” (page 59)
marked to bedisabled or deletedwhen hit.Enabled or DisabledEnabledbreakpoints aremarked with 'y'. 'n'marks breakpointsthat are not
GDB itself sometimes sets breakpoints in your program for special purposes, such asproper handling of longjmp (in C programs). These internal breakpoi
vfork A call to vfork. This is currently onlyavailable for HP-UX.load, loadlibnameThe dynamic loading of any shared library,or the loading of the libr
5.1.3 Deleting breakpointsIt is often necessary to eliminate a breakpoint, watchpoint, or catchpoint once it hasdone its job and you no longer want yo
• Enabled once. The breakpoint stops your program, but then becomes disabled.• Enabled for deletion. The breakpoint stops your program, but immediatel
13 Specifying a Debugging Target...13313.1 Active targets..
say, to just set a watchpoint on a variable name, and specify a condition that testswhether the new value is an interesting one.Break conditions can h
instead of stopping, it just decrements the ignore count by one and continues. As aresult, if the ignore count value is n, the breakpoint does not sto
You can use breakpoint commands to start your program up again. Simply use thecontinue command, or step, or any other command that resumes execution.A
always '[0] cancel' and '[1] all'. Typing 1 sets a breakpoint at each definition offunction, and typing 0 aborts the break command
When this message is printed, you need to disable or remove some of thehardware-assisted breakpoints and watchpoints, and then continue.5.2 Continuing
stepContinue running your program until control reaches a differentsource line, then stop it and return control to GDB. Thiscommand is abbreviated s.W
until, uContinue running until a source line past the current line, in thecurrent stack frame, is reached. This command is used to avoidsingle steppin
stepi, stepi arg,siExecute one machine instruction, then stop and return to thedebugger.It is often useful to do 'display/i $pc' when steppi
NOTE: Use caution if you disable all signals from certain processes. Disabling'SIGTRAP' in your program may cause your program to hang.HP-UX
passGDB should allow your program to see this signal; your program canhandle the signal, or else it may terminate if the signal is fatal and nothandle
14.10.8 Scenarios in memory debugging...17414.10.8.1 Stop when freeing unallocated o
Whenever your program stops under GDB for any reason, all threads of execution stop,not just the current thread. This allows you to examine the overal
6 Examining the StackWhen your program has stopped, the first thing you need to know is where it stoppedand how it got there.Each time your program pe
6.2 Stacks Without framesSome compilers provide a way to compile functions so that they operate without stackframes. (For example, the gcc option&apos
The names where and info stack (abbreviated info s) are additional aliases forbacktrace.Each line in the backtrace shows the frame number and the func
NOTE:• On the SPARC architecture, frame needs two addresses to selectan arbitrary frame: a frame pointer and a stack pointer.• On the MIPS and Alpha a
info frame, infofThis command prints a verbose description of the selectedstack frame, including:• the address of the frame• the address of the next f
76
7 Examining Source FilesGDB can print parts of the source code of your program, since the debugginginformation recorded in the program tells GDB what
The following arguments can be given to the list command:list linespec Print lines centered around the line specified by linespec.list first,last Prin
reverse-search regexp The command 'reverse-search regexp' checkseach line, starting with the one before the last linelisted and going backwa
14.15.2 Support for the info target Command...20114.15.3 Support for the dumpcore command...
show directoriesPrint the source path and display the directories itcontains.If your source path is cluttered with directories that are no longer of i
The following example shows the disassembly of a range of addresses of HP PA-RISC2.0 code:((gdb)) disas 0x32c4 0x32e4Dump of assembler code from 0x32c
82
8 Examining DataThe usual way to examine data in your program is with the print command(abbreviated p), or its synonym inspect. It evaluates and print
:: '::' allows you to specify a variable in terms of the file or functionwhere it is defined. See “Program variables” (page 84).{type} addr
This use of '::' is very rarely in conflict with the very similar use of the same notationin C++. GDB also supports use of the C++ scope res
p *array@lenThe left operand of '@' must reside in memory. Array values made with '@' in this waybehave just like other arrays in
t2Print as integer in binary. The letter 't' stands for “two”2.aPrint as an address, both absolute in hexadecimal and as an offset from the
wWords (four bytes). This is the initial default.gGiant words (eight bytes).Each time you specify a unit size with x, thatsize becomes the default uni
available for use in expressions in the convenience variable $_. The contents of thataddress, as examined, are available in the convenience variable $
14.25.3 Support for _ _fpreg data type on IPF...22214.25.4 Support for _Complex variables in HP
disable display dnums... Disable the display of item numbers dnums. Adisabled display item is not printedautomatically, but is not forgotten. It may b
set print address offDo not print addresses when displaying theircontents. For example, this is the same stack framedisplayed with set print address o
If you have a pointer and you are not sure where it points, try 'set printsymbol-filename on'. Then you can determine the name and source fi
},meat = 0x54 "Pork"}set print pretty offCause GDB to print structures in a compactformat, like this:$1 = {next = 0x0, flags = {sweet = 1, s
} form;};struct thing foo = {Tree, {Acorn}};with set print union on in effect 'p foo'would print$1 = {it = Tree, form = {tree = Acorn, bug
armDecode using the algorithm in the C++Annotated Reference Manual.WARNING! This setting alone is notsufficient to allow debugging cfrontgenerated exe
re-read or discarded (for example with the file or symbol-file commands). Whenthe symbol table changes, the value history is discarded, since the valu
Convenience variables are prefixed with '$'. Any name preceded by '$' can be used fora convenience variable, unless it is one of t
8.10 RegistersYou can refer to machine register contents, in expressions, as variables with namesstarting with '$'. The names of registers a
Some registers have distinct raw and virtual data formats. This means that the dataformat in which the register contents are saved by the operating sy
Kommentare zu diesen Handbüchern