Debugging with GDB Manual The GNU Source-Level Debugger HP Part Number: 5900-1473 Published: March 2011 Edition: 22
© Copyright 2011 Hewlett-Packard Development Company, L.P. Confidential computer software. Valid license from HP required for possession, use or copying. Consistent with FAR 12.211 and 12.212, Commercial Computer Software, Computer Software Documentation, and Technical Data for Commercial Items are licensed to the U.S. Government under vendor's standard commercial license. The information contained herein is subject to change without notice.
Contents Summary of GDB.....................................................................................................................14 Free Software.........................................................................................................14 Contributors to GDB...............................................................................................14 1 A Sample GDB Session..........................................................................................................
.10 Debugging programs with multiple processes......................................................44 5 Stopping and Continuing.......................................................................................................46 5.1 Breakpoints......................................................................................................46 5.1.1 Setting breakpoints.....................................................................................47 5.1.2 Setting catchpoints..................
8.12 Floating point hardware...................................................................................92 8.13 Functions........................................................................................................92 9 Using GDB with Different Languages........................................................................................94 9.1 Switching between source languages...................................................................94 9.1.
13 Specifying a Debugging Target............................................................................................126 13.1 Active targets................................................................................................126 13.2 Commands for managing targets....................................................................126 13.3 Choosing target byte order.............................................................................129 14 HP-UX Configuration-Specific Information...
14.10.8.3 Specifying minimum block size.......................................................168 14.10.9 Scenarios in memory debugging............................................................168 14.10.9.1 Stop when freeing unallocated or deallocated blocks.........................168 14.10.9.2 Stop when freeing a block if bad writes occurred outside block boundary...................................................................................................169 14.10.9.
14.15.1 Generating core files with packcore /unpackcore/getcore..........................194 14.15.2 Support for the info target Command......................................................195 14.15.3 Support for the dumpcore command.......................................................196 14.15.3.1 Enhancements to the dumpcore command........................................196 14.15.4 Support for display of run time type information.......................................197 14.15.
14.25 Additional Support for binary floating point data type.....................................217 14.25.1 Support for Binary Floating Point constants f, l..........................................217 14.25.2 Support Binary Floating Point variables with format specifier......................217 14.26 Language support.......................................................................................217 14.26.1 Enhanced Java Debugging Support........................................................
14.34 Support for XDB commands..........................................................................240 14.34.1 stop in/at dbx commands.....................................................................240 14.35 GDB Logging Commands.............................................................................240 14.36 Support for command line calls in a stripped executable..................................241 14.36.1 Support for command line calls in a stripped executable on PA-RISC systems............
16.1.4 Source directory mapping commands.......................................................259 16.1.5 Data Viewing and modification commands................................................259 16.1.6 Stack viewing commands........................................................................261 16.1.7 Status-viewing command.........................................................................262 16.1.8 Job control commands............................................................................
18 Canned Sequences of Commands........................................................................................289 18.1 User-defined commands.................................................................................289 18.2 User-defined command hooks.........................................................................290 18.3 Command files.............................................................................................291 18.4 Commands for controlled output...................
22 Reporting Bugs in GDB......................................................................................................359 22.1 Have you found a bug?..................................................................................359 22.2 How to report bugs.......................................................................................359 A Installing GDB....................................................................................................................362 A.
Summary of GDB The 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 program was doing at the moment it crashed. GDB allows you to do the following: • Load the executable along with any required arguments. • Stop your program on specified blocks of code. • Examine your program when it has stopped running due to an error.
Changes much prior to version 2.0 are lost in the mists of time. Plea: Additions to this section are particularly welcome. If you or your friends (or enemies, to be evenhanded) have been unfairly omitted from this list, we would like to add your names! So that they may not regard their many labors as thankless, we particularly thank those who shepherded GDB through major releases: Andrew Cagney (release 5.0); Jim Blandy (release 4.18); Jason Molenda (release 4.17); Stan Shebs (release 4.
Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped develop remote debugging. Intel Corporation, Wind River Systems, AMD, and ARM contributed remote debugging modules for the i960, VxWorks, A29K UDI, and RDI targets, respectively. Brian Fox is the author of the readline libraries providing command-line editing and command history. Andrew Beers of SUNY Buffalo wrote the language-switching code, the Modula-2 support, and contributed the Languages chapter of this manual.
Tromey, Ron Unrau, Jim Wilson, and David Zuhn have made contributions both large and small.
1 A Sample GDB Session This chapter describes the most common GDB commands with the help of an example.
1.1 Loading the Executable Let us use GDB to try to see what is going on. $ (gdb) m4 HP 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 (based on GDB ) is covered by the GNU General Public License. Type "show copying" to see the conditions to change it and/or distribute copies. Type "show warranty" for warranty/support.
1.5 Stepping to the next line in the source program Now we use the command n (next) to advance execution to the next line of the current function. ((gdb)) n 882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\ : nil, 1.6 Stepping into a subroutine The set_quotes looks like a promising subroutine. We can go into it by using the command s (step) instead of next. step goes to the next line to be executed in any subroutine, so it steps into set_quotes.
1.8 Printing Variable Values The last line displayed looks a little odd in the listing above; we can examine the variables lquote and rquote to see if they are in fact the new left and right quotes we specified. We use the command p (print) to view their values. ((gdb)) p lquote $1 = 0x35d40 "" ((gdb)) p rquote $2 = 0x35d50 "" 1.9 Listing Source Code lquote and rquote are indeed the new left and right quotes.
((gdb)) p len_rquote=strlen(rquote) $6 = 9 Is that enough to fix the problem of using the new quotes with the m4 built-in defn? We can allow m4 to continue executing with the c (continue) command, and then try the example that caused trouble initially: ((gdb)) c Continuing. define(baz,defn(foo)) baz 0000 Success! The new quotes now work just as well as the default ones. The problem seems to have been just the two typos defining the wrong lengths.
2 Getting In and Out of GDB This chapter discusses how to start GDB, and exit out of it. The essentials are: • type '(gdb)' to start GDB. • type quit or C-d to exit. 2.1 Invoking GDB Invoke GDB by running the program (gdb). Once started, GDB reads commands from the terminal until you tell it to exit. You can also run (gdb) with a variety of arguments and options, to specify more of your debugging environment at the outset.
2.1.1 Choosing files When GDB starts, it reads any arguments other than options as specifying an executable file and core file (or process ID). This is the same as if the arguments were specified by the '-se' and '-c' options respectively.
you are debugging is called '/tmp/fred', the mapped symbol file is '/tmp/fred.syms'. Future GDB debugging sessions notice the presence of this file, and can quickly map in symbol information from it, rather than reading the symbol table from the executable program. The '.syms' file is specific to the host machine where GDB is run. It holds an exact image of the internal GDB symbol table. It cannot be shared across multiple host platforms.
(which is ordinarily issued whenever a program running under GDB control terminates) is not issued when running in batch mode. 26 -nowindows, -nw “No windows”. If GDB comes with a graphical user interface (GUI) built in, then this option tells GDB to only use the command-line interface. If no GUI is available, this option has no effect. -windows, -w If GDB includes a GUI, then this option requires it to be used if possible.
much information does GDB print together with its prompt, values of expressions, source lines, and other types of output. Level 0 is the normal, level 1 is for use when GDB is run as a subprocess of GNU Emacs, level 2 is the maximum annotation suitable for programs that control GDB. -async Use the asynchronous event loop for the command-line interface. GDB processes all events, such as user1 keyboard input, via a special event loop.
programs which communicate with GDB using it as a back end. For example, '--interpreter=mi' causes GDB to use the gdbmi interface (see “The GDB/MI Interface” (page 306)). -write Open the executable and core files for both reading and writing. This is equivalent to the 'set write on' command inside GDB (see “Patching programs” (page 116)). -statistics This option causes GDB to print statistics about time and memory usage after it completes each command and returns to the prompt.
2.3 Shell commands If you need to execute occasional shell commands during your debugging session, there is no need to leave or suspend GDB; you can just use the shell command. shell command string Invoke a standard shell to execute command string. If it exists, the environment variable SHELL determines which shell to run. Otherwise GDB uses the default shell ('/bin/sh' on UNIX systems, 'COMMAND.COM' on MS-DOS, and so on.). The utility make is often needed in development environments.
3 GDB Commands You can abbreviate a GDB command to the first few letters of the command name, if that abbreviation is unambiguous; and you can repeat certain GDB commands by typing just RET ). You can also use the TAB key to get GDB to fill out the rest of a word in a command (or to show you the alternatives available, if there is more than one possibility). 3.1 Command syntax • A GDB command is a single line of input. There is no limit on how long it can be.
GDB fills in the rest of the word 'breakpoints', since that is the only info subcommand beginning with 'bre': ((gdb)) info breakpoints You can either press RET at this point, to run the info breakpoints command, or backspace and enter something else, if 'breakpoints' does not look like the command you expected. (If you were sure you wanted info breakpoints in the first place, you might as well just type RET immediately after 'info bre', to exploit command abbreviations rather than command completion.
bubble(double,double) bubble(int,int) ((gdb)) b 'bubble( In some cases, GDB can tell that completing a name requires using quotes.
help class Using one of the general help classes as an argument, you can get a list of the individual commands in that class. For example, here is the help display for the class status: ((gdb)) help status Status inquiries. List of commands: info -- Generic command for showing things about the program being debugged show -- Generic command for showing things about the debugger Type "help" followed by command name for full documentation. Command name abbreviations are allowed if unambiguous.
of inquiry; this manual introduces each of them in the appropriate context. The listings under info and under show point to all the sub-commands. info This command (abbreviated i) is for describing the state of your program. For example, you can list the arguments given to your program with info args, list the registers currently in use with info registers, or list the breakpoints you have set with info breakpoints. You can get a complete list of the info sub-commands with help info.
4 Running Programs Under GDB When you run a program under GDB, you must first generate debugging information when you compile it using compiler option cc -g -O. You may start GDB with its arguments, if any, in an environment of your choice. If you are doing native debugging, you may redirect your program's input and output, debug an already running process, or kill a child process. 4.
variable substitution) in describing the arguments. On Unix systems, you can control which shell is used with the SHELL environment variable. GDB uses the C shell (/usr/bin/csh). See “Arguments To Your Program” (page 36). environment. Your program inherits its environment from GDB. However, you can use the GDB commands set environment and unset environment to change parts of the environment that affect your program. See“Program Environment” (page 37). working directory.
On non-Unix systems, the program is usually invoked directly by GDB, which emulates I/O redirection via the appropriate system calls, and the wildcard characters are expanded by the startup code of the program, not by the shell. The run command used with no arguments uses the same arguments used by the previous run, or those set by the set args command. Following commands are used to pass the argument values to your program: set args Specify the arguments to be used the next time your program is run.
around '=' are used for clarity here; they are not actually required.) unset environment varname Remove variable varname from the environment to be passed to your program. This is different from 'set env varname ='; unset environment removes the variable from the environment, rather than assigning it an empty value. path directory Add directory to the front of the PATH environment variable (the search path for executables), for both GDB and your program.
info terminal Displays information recorded by GDB about the terminal modes your program is using. tty Another way to specify where your program should do input and output is with the tty command. This command accepts a file name as argument, and causes this file to be the default for future run commands. It also resets the controlling terminal for the child process, for future run commands.
NOTE: • To use attach, your program must be running in an environment which supports processes; for example, attach does not work for programs on bare-board targets that lack an operating system. • You must also have permission to send the process a signal. • When you use attach, the debugger finds the program running in the process first by looking in the current working directory, then (if the program is not found) by using the source file search path (see “Specifying source directories” (page 73)).
On some operating systems, a program cannot be executed outside GDB while you have breakpoints set on it inside GDB. You can use the kill command in this situation to permit running your program outside the debugger. The kill command is also useful if you wish to recompile and relink your program, since on many systems it is impossible to modify an executable file while it is running in a process.
Whenever GDB detects a new thread in your program, it displays the target system's identification for the thread with a message in the form '[New systag]'. systag is a 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 a new thread. In contrast, on an SGI system, the systag is simply something like 'process 368', with no further qualifier.
3. 4. the current stack frame summary for that thread the priority of a thread An asterisk '*' to the left of the GDB thread number indicates the current thread. For example, ((gdb)) info threads * 3 system thread 26607 worker (wptr=0x7b09c318 "@") \ at quicksort.c:137 2 system thread 26606 0x7b0030d8 in __ksleep () \ from /usr/lib/libc.2 1 system thread 27905 0x7b003498 in _brk () \ from /usr/lib/libc.2 thread threadno Make thread number threadno the current thread.
See “Stopping and starting multi-thread programs” (page 64), for more information about how GDB behaves when you stop and start programs with multiple threads. See “Killing the child process” (page 40), for information about watchpoints in programs with multiple threads. NOTE: On HP-UX 11.x, debugging a multi-thread process can cause a deadlock if the process is waiting for an NFS-server response. A thread can be stopped while asleep in this state, and NFS holds a lock on the rnode while asleep.
show follow-fork-mode Display the current debugger response to a fork or vfork call. If you ask to debug a child process and a vfork is followed by an exec, GDB executes the new target up to the first breakpoint in the new target. If you have a breakpoint set on main in your original program, the breakpoint will also be set on the child process's main. When a child process is spawned by vfork, you cannot debug the child or parent until an exec call completes.
5 Stopping and Continuing The principal purpose of a debugger is to let you stop your program before it terminates abnormally or runs into trouble, so that you can investigate and determine the reason. Inside GDB, your program can stop for several reasons, such as a signal, a breakpoint, or reaching a new line after a GDB command such as step. You can then examine and change variables, set new breakpoints or remove old ones, and then continue execution.
5.1.1 Setting breakpoints Breakpoints are set with the break command (abbreviated b). The debugger convenience variable '$bpnum' records the number of the breakpoint you have set most recently; see “Convenience variables” (page 89), for a discussion of what you can do with convenience variables. You have several ways to say where the breakpoint should go. break function Set a breakpoint at entry to function function.
argument in the innermost frame, GDB stops the next time it reaches the current location; this may be useful inside loops. GDB normally ignores breakpoints when it resumes execution, until at least one instruction has been executed. If it did not do this, you would be unable to proceed past a breakpoint without first disabling the breakpoint. This rule applies whether or not the breakpoint already existed when your program stopped. 48 break ...
breakpoints before setting new ones (see “Disabling breakpoints” (page 53)). See “Break conditions” (page 54). thbreak args Set a hardware-assisted breakpoint enabled only for one stop. args are the same as for the hbreak command and the breakpoint is set in the same way. However, like the tbreak command, the breakpoint is automatically deleted after the first time your program stops there.
disabled or deleted when hit. Enabled or Disabled Enabled breakpoints are marked with 'y'. 'n' marks breakpoints that are not enabled. Address Where the breakpoint is in your program, as a memory address. What Where the breakpoint is in the source for your program, as a file and line number. If a breakpoint is conditional, info break shows the condition on the line following the affected breakpoint; breakpoint commands, if any, are listed after that.
You can see these breakpoints with the GDB maintenance command 'maint info breakpoints'. maint info breakpoints Using the same format as 'info breakpoints', display both the breakpoints you have set explicitly, and those GDB is using for internal purposes. Internal breakpoints are shown with negative breakpoint numbers. The type column identifies what kind of breakpoint is shown: breakpoint Normal, explicitly set breakpoint. watchpoint Normal, explicitly set watchpoint.
tcatch event load, load libname The dynamic loading of any shared library, or the loading of the library libname. This is currently only available for HP-UX. unload, unload libname The unloading of any dynamically loaded shared library, or the unloading of the library libname. This is currently only available for HP-UX. Set a catchpoint that is enabled only for one stop. The catchpoint is automatically deleted after the first time the event is caught.
5.1.3 Deleting breakpoints It is often necessary to eliminate a breakpoint, watchpoint, or catchpoint once it has done its job and you no longer want your program to stop there. This is called deleting the breakpoint. A breakpoint that has been deleted no longer exists; it is forgotten. With the clear command you can delete breakpoints according to where they are in your program.
A breakpoint, watchpoint, or catchpoint can have any of four different states of enablement: • Enabled. The breakpoint stops your program. A breakpoint set with the break command starts out in this state. • Disabled. The breakpoint has no effect on your program. • Enabled once. The breakpoint stops your program, but then becomes disabled. • Enabled for deletion. The breakpoint stops your program, but immediately after it does so it is deleted permanently.
This is the converse of using assertions for program validation; in that situation, you want to stop when the assertion is violated―that is, when the condition is false. In C, if you want to test an assertion expressed by the condition assert, you should set the condition '! assert' on the appropriate breakpoint.
condition bnum Remove the condition from breakpoint number bnum. It becomes an ordinary unconditional breakpoint. A special case of a breakpoint condition is to stop only when the breakpoint has been reached a certain number of times. This is so useful that there is a special way to do it, using the ignore count of the breakpoint. Every breakpoint has an ignore count, which is an integer. Most of the time, the ignore count is zero, and therefore has no effect.
Type a line containing just end to terminate the commands. To remove all commands from a breakpoint, type commands and follow it immediately with end; that is, give no commands. With no bnum argument, commands refers to the last breakpoint, watchpoint, or catchpoint set (not to the breakpoint most recently encountered). Pressing RET as a means of repeating the last GDB command is disabled within a command-list. You can use breakpoint commands to start your program up again.
break 403 commands silent set x = y + 4 cont end 5.1.7 Breakpoint menus Some programming languages (notably C++) permit a single function name to be defined several times, for application in different contexts. This is called overloading. When a function name is overloaded, 'break function' is not enough to tell GDB where you want a breakpoint. If you realize this is a problem, you can use something like 'break function(types)' to specify which particular version of the function you want.
1. 2. 3. Remove or disable the breakpoints, then continue. Suspend GDB, and copy the file containing your program to a new name. Resume GDB and use the exec-file command to specify that GDB should run your program under that name. Then start your program again. Relink your program so that the text segment is nonsharable, using the linker option '-N'. The operating system limitation may not apply to nonsharable executables.
To resume execution at a different place, you can use return (see “Returning from a function” (page 116)) to go back to the calling function; or jump (see “Continuing at a different address” (page 114)) to go to an arbitrary location in your program.
The next command only stops at the first instruction of a source line. This prevents multiple stops that could otherwise occur in switch statements, for loops, and so on. finish Continue running until just after function in the selected stack frame returns. Print the returned value (if any). Contrast this with the return command (see “Returning from a function” (page 116)). until, u Continue running until a source line past the current line, in the current stack frame, is reached.
until location, u location Continue running your program until either the specified location is reached, or the current stack frame returns. location is any of the forms of argument acceptable to break (see “Setting breakpoints” (page 47)). This form of the command uses breakpoints, and hence is quicker than until without an argument. stepi, stepi arg, Execute one machine instruction, then stop and return to the debugger. si It is often useful to do 'display/i $pc' when stepping by machine instructions.
NOTE: Use caution if you disable all signals from certain processes. Disabling 'SIGTRAP' in your program may cause your program to hang. HP-UX uses 'SIGTRAP' to communicate with the debugger. If you disable all signals from certain processes so that signals will be delivered to the right process, your program may hang when you try to debug it.
print GDB should print a message when this signal happens. noprint GDB should not mention the occurrence of the signal at all. This implies the nostop keyword as well. pass GDB should allow your program to see this signal; your program can handle the signal, or else it may terminate if the signal is fatal and not handled. nopass GDB should not allow your program to see this signal. When a signal stops your program, the signal is not visible to the program until you continue.
((gdb)) break frik.c:13 thread 28 if bartab > lim 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 overall state of the program, including switching between threads, without worrying that things may change underfoot. Conversely, whenever you restart the program, all threads start executing. This is true even when single-stepping with commands like step or next.
6 Examining the Stack When your program has stopped, the first thing you need to know is where it stopped and how it got there. Each time your program performs a function call, information about the call is generated. The information includes the location of the call in your program, the arguments of the call, and the local variables of the function being called. The information is saved in a block of data called a stack frame. The stack frames are allocated in a region of memory called the call stack.
6.2 Stacks Without frames Some compilers provide a way to compile functions so that they operate without stack frames. (For example, the gcc option '-fomit-frame-pointer' generates functions without a frame.) This is occasionally done with heavily used library functions to save the frame setup time. GDB has limited facilities for dealing with these function invocations.
The names where and info stack (abbreviated info s) are additional aliases for backtrace. Each line in the backtrace shows the frame number and the function name. The program counter value is also shown―unless you use set print address off. The backtrace also shows the source file name and line number, as well as the arguments to the function. The program counter value is omitted if it is at the beginning of the code for that line number. Here is an example of a backtrace.
NOTE: • On the SPARC architecture, frame needs two addresses to select an arbitrary frame: a frame pointer and a stack pointer. • On the MIPS and Alpha architecture, it needs two addresses: a stack pointer and a program counter. • On the 29k architecture, it needs three addresses: a register stack pointer, a program counter, and a memory stack pointer. up n Move n frames up the stack.
info frame, info f This command prints a verbose description of the selected stack frame, including: • the address of the frame • the address of the next frame down (called by this frame) • the address of the next frame up (caller of this frame) • the language in which the source code corresponding to this frame is written • the address of the frame's arguments • the address of the frame's local variables • the program counter saved in it (the address of execution in the caller frame) • whic
7 Examining Source Files GDB can print parts of the source code of your program, since the debugging information recorded in the program tells GDB what source files were used to build it. When your program stops, GDB spontaneously prints the line where it stopped. Likewise, when you select a stack frame (see “Selecting a frame” (page 68)), GDB prints the line where execution in that frame has stopped. You can print other portions of source files by explicit command.
The following arguments can be given to the list command: list linespec Print lines centered around the line specified by linespec. list first,last Print lines from first to last. Both arguments must be linespecs. list, last Print lines ending with last. list first, Print lines starting with first. list + Print lines just after the lines last printed. list - Print lines just before the lines last printed. list As described in the preceding table.
reverse-search regexp The command 'reverse-search regexp' checks each line, starting with the one before the last line listed and going backward, for a match for the regexp. It lists the line(s) that is found. You can abbreviate this command as rev. 7.3 Specifying source directories Executable programs sometimes do not record the directories of the source files from which they were compiled. Even when they do, the directories can be moved between the compilation and your debugging session.
Print the source path and display the directories it contains. show directories If your source path is cluttered with directories that are no longer of interest, GDB can end up detecting the wrong version of the source. To correct this situation, follow these steps: 1. 2. Use directory with no arguments to reset the source path to empty. Use directory with suitable arguments to reinstall the directories you want in the source path. You can add all the directories in one command. 7.
The following example shows the disassembly of a range of addresses of HP PA-RISC 2.0 code: ((gdb)) disas 0x32c4 0x32e4 Dump of assembler code from 0x32c4 to 0x32e4: 0x32c4 : addil 0,dp 0x32c8 : ldw 0x22c(sr0,r1),r26 0x32cc : ldil 0x3000,r31 0x32d0 : ble 0x3f8(sr4,r31) 0x32d4 : ldo 0(r31),rp 0x32d8 : addil -0x800,dp 0x32dc : ldo 0x588(r1),r26 0x32e0 : ldil 0x3000,r31 End of assembler dump.
8 Examining Data The usual way to examine data in your program is with the print command (abbreviated p), or its synonym inspect. It evaluates and prints the value of an expression of the language your program is written in (see Chapter 9 (page 94)). The following forms of print command are supported: print expr, print /f expr expr is an expression (in the source language).
@ '@' is a binary operator for treating parts of memory as arrays. Refer to See “Artificial arrays” (page 78), for more information. :: '::' allows you to specify a variable in terms of the file or function where it is defined. See “Program variables” (page 77). {type} addr Refers to an object of type type stored at address addr in memory. addr may be any expression whose value is an integer or pointer (but parentheses are required around binary operators, just as in a cast).
((gdb)) p 'f2.c'::x This use of '::' is very rarely in conflict with the very similar use of the same notation in C++. GDB also supports use of the C++ scope resolution operator in GDB expressions. WARNING! Occasionally, a local variable may appear to have the wrong value at certain points in a function just after entry to a new scope, and just before exit. You may see this problem when you are stepping by machine instructions.
p *array@len The left operand of '@' must reside in memory. Array values made with '@' in this way behave just like other arrays in terms of subscripting, and are coerced to pointers when used in expressions. Artificial arrays most often appear in expressions via the value history (see “Value history” (page 89)), after printing one out. Another way to create an artificial array is to use a cast. This re-interprets a value as if it were an array.
t a 2 Print as integer in binary. The letter 't' stands for “two”2. Print as an address, both absolute in hexadecimal and as an offset from the nearest preceding symbol. You can use this format used to discover where (in what function) an unknown address is located: ((gdb)) p/a 0x54320 $3 = 0x54320 <_initialize_vx+396> c Regard as an integer and print it as a character constant. f Regard the bits of the value as a floating point number and print using typical floating point syntax.
w Words (four bytes). This is the initial default. g Giant words (eight bytes). Each time you specify a unit size with x, that size becomes the default unit the next time you use x. (For the 's' and 'i' formats, the unit size is ignored and is normally not written.) addr, starting display address addr is the address where you want GDB to begin displaying memory. The expression need not have a pointer value (though it may); it is always interpreted as an integer address of a byte of memory.
available for use in expressions in the convenience variable $_. The contents of that address, as examined, are available in the convenience variable $__. If the x command has a repeat count, the address and contents saved are from the last memory unit printed; this is not the same as the last address printed if several units were printed on the last line of output. 8.
disable display dnums... Disable the display of item numbers dnums. A disabled display item is not printed automatically, but is not forgotten. It may be enabled again later. enable display dnums... Enable display of item numbers dnums. It becomes effective once again in auto display of its expression, until you specify otherwise. display Display the current values of the expressions on the list, just as is done when your program stops.
">>") at input.c:530 530 if (lquote != def_lquote) set print address off Do not print addresses when displaying their contents. For example, this is the same stack frame displayed with set print address off: ((gdb)) set print addr off ((gdb)) f #0 set_quotes (lq="<<", rq=">>") at input.c:530 530 if (lquote != def_lquote) You can use 'set print address off' to eliminate all machine dependent displays from the GDB interface.
symbolic form of an address if any symbol precedes it. show print max-symbolic-offset Ask how large the maximum offset is that GDB prints in a symbolic address. If you have a pointer and you are not sure where it points, try 'set print symbol-filename on'. Then you can determine the name and source file location of the variable where it points, using 'p/a pointer'. This interprets the address in symbolic form. For example, here GDB shows that a variable ptt points at another variable t, defined in 'hi2.
$1 = { next = 0x0, flags = { sweet = 1, sour = 1 }, meat = 0x54 "Pork" } set print pretty off Cause GDB to print structures in a compact format, like this: $1 = {next = 0x0, flags = {sweet = 1, sour = 1}, \ meat = 0x54 "Pork"} This is the default format. show print pretty Show which format GDB is using to print structures.
Species it; union { Tree_forms tree; Bug_forms bug; } form; }; struct thing foo = {Tree, {Acorn}}; with set print union on in effect 'p foo' would print $1 = {it = Tree, form = {tree = Acorn, bug = Cocoon}} and with set print union off in effect it would print $1 = {it = Tree, form = {...
lucid Decode based on the Lucid C++ compiler (lcc) encoding algorithm. arm Decode using the algorithm in the C++ Annotated Reference Manual. WARNING! This setting alone is not sufficient to allow debugging cfront generated executables. GDB would require further enhancement to permit that. If you omit style, you will see a list of possible formats. 88 show demangle-style Display the encoding style currently in use for decoding C++ symbols.
8.8 Value history Values printed by the print command are saved in the GDB value history. This allows you to refer to them in other expressions. Values are kept until the symbol table is re-read or discarded (for example with the file or symbol-file commands). When the symbol table changes, the value history is discarded, since the values may contain pointers back to the types defined in the symbol table. The values printed are given history numbers by which you can refer to them.
program, and setting a convenience variable has no direct effect on further execution of your program. That is why you can use them freely. Convenience variables are prefixed with '$'. Any name preceded by '$' can be used for a convenience variable, unless it is one of the predefined machine-specific register names (see “Registers” (page 91)). (Value history references, in contrast, are numbers preceded by '$'. See “Value history” (page 89).
8.10 Registers You can refer to machine register contents, in expressions, as variables with names starting with '$'. The names of registers are different for each machine. Use info registers to view the names used on your machine. info registers Print the names and values of all registers except floating-point registers (in the selected stack frame). info all-registers Print the names and values of all registers, including floating-point registers. info registers regname ...
Some registers have distinct raw and virtual data formats. This means that the data format in which the register contents are saved by the operating system is not the same one that your program normally sees. For example, the registers of the 68881 floating point coprocessor are always saved in “extended” (raw) format, but all C programs expect to work with “double” (virtual) format.
info functions [regexp] Display the declaration of all functions, or of those matching regexp. set max-function-matches integer Set maximum number of function matches reported by the info functions command. By default it is set to zero. NOTE: This is an HP-UX specific command. You must set max-function-matches to zero to report all matches. show max-function-matches Display maximum number of function matches reported by the info functions command.
9 Using GDB with Different Languages Although programming languages generally have common aspects, they are rarely expressed in the same manner. For instance, in ANSI C, dereferencing a pointer p is accomplished by *p, but in Modula-2, it is accomplished by p^. Values can also be represented (and displayed) differently. Hex numbers in C appear as '0x1ae', while in Modula-2 they appear as '1AEH'.
'.cxx', '.c++' '.f', '.F', '.f90' Fortran source file. GDB does not distinguish between Fortran 77 and Fortran 90 files. '.s', '.S' Assembler source file. This actually behaves almost like C, but GDB does not skip over function prologues when stepping. In addition, you may set the language associated with a filename extension. See “Displaying the language” (page 96). 9.1.
9.2 Displaying the language The following commands help you find out which language is the working language, and also what language source files were written in. show language Display the current working language. This is the language you can use with commands such as print to build and compute expressions that may involve variables in your program. info frame Display the source language for this frame. This language becomes the working language if you use an identifier from this frame.
error 1 + 2.3 The second example fails because the CARDINAL 1 is not type-compatible with the REAL 2.3. For the expressions you use in GDB commands, you can tell the GDB type checker to skip checking; to treat any mismatches as errors and abandon the expression; or to only issue warnings when type mismatches occur, and evaluate the expression anyway. When you choose the last of these, GDB evaluates expressions like the second example above, but also issues a warning.
For expressions you use in GDB commands, you can tell GDB to treat range errors in one of three ways: ignore them, always treat them as errors and abandon the expression, or issue warnings but evaluate the expression anyway. A range error can result from numerical overflow, from exceeding an array index bound, or when you type a constant that is not a member of any type. Some languages, however, do not treat overflows as an error.
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 languages together. The C++ debugging facilities are jointly implemented by the C++ compiler and GDB. Therefore, to debug your C++ code effectively, you must compile your C++ programs with a supported C++ compiler, such as GNU g++, or the HP ANSI C++ compiler (aCC). For best results when using GNU C++, use the stabs debugging format.
& Bitwise AND. Defined on integral types. ==, != Equality and inequality. Defined on scalar types. The value of these expressions is 0 for false and non-zero for true. <, >, <=, >= Less than, greater than, less than or equal, greater than or equal. Defined on scalar types. The value of these expressions is 0 for false and non-zero for true. <<, >> left shift, and right shift. Defined on integral types. @ The GDB “artificial array” operator (see “Expressions” (page 76)).
:: C++ scope resolution operator. Defined on struct, union, and class types. :: Double colons also represent the GDB scope operator (see “Expressions” (page 76)). Same precedence as ::, above. If an operator is redefined in the user code, GDB usually attempts to invoke the redefined version instead of using the original meaning. 9.4.1.2 C and C++ constants GDB allows you to express the constants of C and C++ in the following ways: • Integer constants are a sequence of digits.
9.4.1.3 C++ expressions GDB expression handling can interpret most C++ expressions. WARNING! GDB can only debug C++ code if you use the proper compiler. Typically, C++ debugging depends on the use of additional debugging information in the symbol table, and thus requires special support. In particular, if your compiler generates a.out, MIPS ECOFF, RS/6000 XCOFF, or ELF with stabs extensions to the symbol table, these facilities are all available.
references are often used for large structures. The address of a reference variable is always shown, unless you have specified 'set print address off'. 5. GDB supports the C++ name resolution operator ::―your expressions can use it just as expressions in your program do. Since one scope may be defined in another, you can use :: repeatedly if necessary, for example in an expression like 'scope1::scope2::name'.
Range checking, if turned on, is done on mathematical operations. Array indices are not checked, since they are often used to index a pointer that is not itself an array. 9.4.1.6 GDB and C The set print union and show print union commands apply to the union type. When set to 'on', any union that is inside a struct or class is also printed. Otherwise, it appears as '{...}'. The @ operator aids in the debugging of dynamic arrays, formed with pointers and a memory allocation function.
searches for a function whose signature matches the argument types, using the standard C++ conversion rules (see “C++ expressions” (page 102), for details). If it cannot find a match, it emits a message. set overload-resolution off Disable overload resolution for C++ expression evaluation. For overloaded functions that are not class member functions, GDB chooses the first function of the specified name that it finds in the symbol table, whether or not its arguments are of the correct type.
9.4.2.1 Fortran types Fortran types supported: integer*1, integer*2, integer*4, integer*8 logical*1, logical*2, logical*4, logical*8 byte, real*4, real*8, real*16 complex*8, complex*16 character*len, character*(*) [len is a user supplied length] arrays • allocatable • assumed-size • assumed-shape • adjustable • automatic • explicit-shape Array elements are displayed in column-major order. Use () for array member access (for example, arr(i) instead of arr[i]).
GDB includes support for viewing Fortran common blocks. info common Lists common blocks visible in the current frame. info common Lists values of variables in the named common block. Fortran entry points are supported. You can set a break point specifying an entry point name. 9.4.2.3 Fortran special issues Fortran allows main™ to be a non-main™ procedure; therefore, to set a breakpoint in the main program, use break _MAIN_ or break .
10 Examining the Symbol Table The commands described in this chapter allow you to inquire about the symbols (names of variables, functions, and types) defined in your program. This information is inherent in the text of your program and does not change as your program executes. GDB finds it in your program's symbol table, in the file indicated when you started GDB (see “Choosing files” (page 24)), or by one of the file-management commands (see “Commands to specify files” (page 118)).
ptype expr, ptype Print a description of the type of expression expr. ptype differs from whatis by printing a detailed description, instead of just the name of the type.
info functions regexp Print the names and data types of all defined functions whose names contain a match for regular expression regexp. Thus, 'info fun step' finds all functions whose names include step; 'info fun ^step' finds those whose names start with step. info symbol address Describes the symbol at location address for symbols. info module address The info module command identifies load modules, and determines whether it lies in the text or data region for a given address.
discard symbols when linking large programs, that may contain several modules (from different directories or libraries) with the same name. show Show the current on or off symbol-reloading setting. set opaque-type-resolution on Tell GDB to resolve opaque types. An opaque type is a type declared as a pointer to a struct, class, or union―for example, struct MyType *―that is used in one source file although the full declaration of struct MyType is in another source file. The default is on.
(page 118), for a discussion of how GDB reads symbols (in the description of symbol-file). 112 set symbol-reloading on Tell GDB to replace symbol definitions for the corresponding source file when an object file with a particular name is seen again. set symbol-reloading off Tell GDB not to replace the symbol definitions when encountering object files of the same name more than once.
11 Altering Execution Once you think you have found an error in your program, you might want to find out for certain whether correcting the apparent error would lead to correct results in the rest of the run. You can find the answer by experiment, using the GDB features for altering execution of the program. For example, you can store new values into variables or memory locations, give your program a signal, restart it at a different address, or even return prematurely from a function. 11.
((gdb)) whatis g type = double ((gdb)) p g $1 = 1 ((gdb)) set g=4 ((gdb)) p g $2 = 1 ((gdb)) r The program being debugged has been started already. Start it from the beginning? (y or n) y Starting program: /home/smith/cc_progs/a.out "/home/smith/cc_progs/a.out": can't open to read symbols: Invalid bfd target. ((gdb)) show g The current BFD target is "=4". The steps shown above sets the gnutarget to an invalid value in place of the program variable g.
function from the one currently executing, the results may be bizarre if the two functions expect different patterns of arguments or of local variables. For this reason, the jump command requests confirmation if the specified line is not in the function currently executing. However, even bizarre results are predictable if you are well acquainted with the machine-language code of your program. jump *address Resume execution at the instruction at address address.
11.4 Returning from a function You can use the following command to return from a function: You can cancel execution of a function call with the return command. If you give an expression argument, its value is used as the return value from the function value. return, return expression When you use return, GDB discards the selected stack frame (and all frames within it). You can think of this as making the discarded frame return prematurely.
show write Display whether executable files and core files are opened for writing as well as reading. 11.
12 GDB Files GDB needs to know the file name of the program to be debugged, both in order to read its symbol table and in order to start your program. To debug a core dump of a previous run, you must also tell GDB the name of the core dump file. 12.1 Commands to specify files You can specify executable and core dump file names as arguments to the GDB start-up command (see“Getting In and Out of GDB” (page 23)). Occasionally it is necessary to change to a different file during a GDB session.
symbol-file [ filename ] Read symbol table information from file filename. PATH is searched when necessary. Use the file command to get both symbol table and program to run from the same file. symbol-file with no argument clears out GDB information on the symbol table of your program. The symbol-file command causes GDB to forget the contents of its convenience variables, the value history, and all breakpoints and auto-display expressions.
another option, `-mapped', to cause GDB to write the symbols for your program into a reusable file. Future GDB debugging sessions map in symbol information from this auxiliary symbol file (if the program has not changed), rather than spending time reading the symbol table from the executable program. Using the `-mapped' option has the same effect as starting GDB with the `-mapped' command-line option.
filename address data_address bss_address, add-symbol-file filename -section address into the program that is running. address should be the memory address at which the file has been loaded; GDB cannot figure this out for itself. You can specify up to three addresses, in which case they are taken to be the addresses of the text, data, and bss segments respectively.
All file-specifying commands allow both absolute and relative file names as arguments. GDB always converts the file name to an absolute file name and remembers it that way. GDB automatically loads symbol definitions from shared libraries when you use the run command, or when you examine a core file. (Before you issue the run command, GDB does not understand references to a function in a shared library, however ― unless you are debugging a core file).
show stop-on-solib-events Display the status of stopping for shared library events. 12.2 Specifying shared library locations On HP-UX, when the shared libraries your program uses are in a different directory than the path specified in the source or object files, specify the correct files to use with one of two environment variables. `GDB_SHLIB_PATH' Set this variable to a colon-separated list of directory path names where the desired shared libraries reside.
libsubs.sl, GDB looks at /tmp/usr/lib/libsubs.sl and /tmp/usr/share/ lib/libsubs.sl respectively. 12.3 Errors reading symbol files While reading a symbol file, GDB occasionally encounters problems, such as symbol types it does not recognize, or known bugs in compiler output. By default, GDB does not notify you of such problems, since they are relatively common and primarily of interest to people debugging compilers.
bad string table offset in symbol n Symbol number n contains a pointer into the string table which is larger than the size of the string table. GDB circumvents the problem by considering the symbol to have the name foo, which may cause other problems if many symbols end up with this name. unknown symbol type 0xnn The symbol information contains new data types that GDB does not yet know how to read. 0xnn is the symbol type of the uncomprehended information, in hexadecimal.
13 Specifying a Debugging Target A target is the execution environment occupied by your program. Often, GDB runs in the same host environment as your program; in that case, the debugging target is specified as a side effect when you use the file or core commands. For HP-UX specific information, see undefined [HP-UX Targets], page undefined.
names or host names to connect with, process numbers, and baud rates. The target command does not repeat if you press RET again after executing the command. help target Displays the names of all targets available. To display targets currently selected, use either info target or info files (see “Commands to specify files” (page 118)). help target name Describe a particular target, including any parameters necessary to select it. set gnutarget args GDB uses its own library BFD to read your files.
transfer is also limited by the size of the target packet and the memory cache. show download-write-size Displays the current value of the write size. Here are some common targets (available, or not, depending on the GDB configuration): target exec program An executable file. target exec program is the same as exec-file program. target core filename A core dump file. target core filename is the same as core-file filename. target remote dev Remote serial target in GDB-specific protocol.
linking, for example. load also records the filename symbol table in GDB, like the add-symbol-file command. If your GDB does not have a load command, attempting to execute it gets the error message "You can't do that when your target is ...". The file is loaded at whatever address is specified in the executable. For some object file formats, you can specify the load address when you link the program; for other formats, like a.out, the object file format specifies a fixed address.
14 HP-UX Configuration-Specific Information While nearly all GDB commands are available for all native and cross versions of the debugger, there are some exceptions. This chapter describes features, commands, and enhancements available only on HP-UX. 14.
• “Enhanced Java Debugging Support” (page 217) • “Enhanced support for C++ templates” (page 222) • “Support for _ _fpreg data type on IPF” (page 223) • “Support for _Complex variables in HP C” (page 223) • “Support for debugging namespaces” (page 223) • “Command for evaluating the address of an expression” (page 224) • “Viewing Wide Character Strings” (page 224) • “Support for dumping array in an ASCII file” (page 225) • “Support for Fortran array slices” (page 226) • “Displaying enumerat
asynchronous signals but are always passed to the debugger whether [nopass] is set or not. 132 • For PA 64-bit applications, HP WDB can step into shared library bind-on-reference calls. This support is available for PA 32-bit as well. • Support for deferred breakpoints on dlopened and shl_loaded libraries with stripped main program. • C99 variable arrays implemented on Integrity systems. This support is available on PA-RISC as well.
NOTE: For new commands see HP WDB Release Notes available at http:// www.hp.com/go/wdb. 14.2 HP-UX dependencies 14.2.1 Linker Dependencies Several features available in HP WDB depend on specific versions of the linker or the compiler. • Linker patch required for +objdebug For releases prior to HP-UX 11i v2 (for IA) and HP-UX 11i v1 (for PA-RISC), you must install the latest linker patch to generate object modules that enable faster linking and smaller executable file sizes for large applications.
ctime() dlclose() memchr() strrchr() dlgetname() dlget() clock_gettime() strlen() dlhook() dlmodinfo() environ() getenv() strlen() execl() exit() fclose() fork() strdup() fopen() fprintf() fscanf() sscanf() strcasecmp() getcwd() getpagesize() getpid() srand() printf() pthread_self() putenv() shmctl() strchr() rand() uwx_self_lookupip() shl_get() shl_unload() shl_findsym () strtok_r() time() uwx_get_reg() shl_get_r() perror() uwx_init() uwx_self_copyin() creat() uwx_step() write() uwx_self_init_context() pt
14.3 Supported Platforms and Modes • Supported Platforms HP WDB supports source-level debugging of programs written in HP C, HP aC++, and Fortran 90 on Integrity systems running on HP-UX 11i v2 or later and PA- RISC systems running HP-UX 11i v1 and later. • Support for assembly-level debugging HP WDB provides support for assembly-level debugging.
NOTE: HP WDB cannot be attached to a process that is traced by tools which use ttrace, such as Caliper, adb, and tusc. The debugger displays the following error message on attempting to attach to such a process: Attaching to process failed. Hint: Check if this process is already being traced by another gdb or other trace tools like caliper and tusc. Hint: Check whether program is on an NFS-mounted file-system.
librtc.sl location $WDB_ROOT/bin None $WDB_ROOT/bin /opt/langtools/ $WDB_ROOT/lib bin /opt/langtools/ n/a bin GDB_SERVER n/a n/a $LIBRTC_SERVER NOTE: If you define WDB_ROOT or GDB_ROOT but do not create the correct directory structure below it, the debugger may fail. 14.6 Specifying object file directories GDB enables automatic loading of debug information from object modules when an application is compiled with the +objdebug option.
show objectdir Display the current search path for finding object files. By default it is $cdir:$cwd. Where the variables $cwd and $cdir have following information: $cwd contains the path of Current Working Directory. $cdir contains the path of the Compilation Directory of the source file. pathmap Enables you to define a list of substitution rules to be applied to path names to identify object files and the corresponding source files.
14.7 Fix and continue debugging Fix and continue enables you to see the result of changes you make to a program you are debugging without having to re-compile and re-link the entire program. For example, you can edit a function and use the fix command, which automatically re-compiles the code, links it into a shared library, and continues execution of the program, without leaving the debugger.
14.7.2 Fix and Continue restrictions Fix and Continue has the following restrictions and behaviors: • You cannot recompile code that has been optimized. • You cannot add, delete, or reorder the local variables and parameters in a function currently active on the stack. • If you x a routine in a file that contains function pointers, those function pointers become invalid and will likely cause the program to receive a SIGSEGV error if the pointers are used.
When you use the edit command, HP WDB then monitors any edited source files for additional changes. After you enter the initial fix command, HP WDB checks for additional saved changes to a source file each time you enter a program execution command. If a saved source file has been changed, HP WDB asks if you want to fix the changed source, allowing you to apply repeated fixes without explicitly entering the fix command.
The sum from 1 to 10 is = 0 This result is obviously wrong. We need to debug the program. 3. Run the debugger: gdb mysum HP 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 (based on GDB ) is covered by the GNU General Public License. Type "show copying" to see the conditions to change it and/or distribute copies. Type "show warranty" for warranty/support.
Compiling /dev/src/sum.c... Linking... Applying code changes to sum.c. Fix succeeded. The fix command creates a new executable that includes the changes you made to the source file. The debugger automatically uses the new executable and picks up the debugging session where you stopped before using the edit command. For example, you can continue stepping through the program and you will find the new return total; statement in the source view. You can print the value of total, and see that the result is 110.
$ gdb --inline= a.out or (gdb) set inline-debug 3. You can use the following commands for debugging inline functions in HP 9000 systems: step next list backtrace frame info locals info args The following commands are not available for debugging inline functions in HP 9000 systems: breakpoint info frame disassembly NOTE: Inline debugging commands are not available for inlined template functions and inlined functions which are defined after the call site. 14.8.
The set inline-debug on command enables the inline debugging feature without the inline breakpoints options in Integrity systems. This command is enabled by default. The set inline-debug off command disables the inline debugging feature. You can disable inline debugging by entering this command before attaching the debugger to the application. The set inline-debug inline_bp_all command enables you to set and modify break- points on all instances of a particular inline function.
(gdb) set inline-debug on or $ gdb --inline = on • To set and modify breakpoints collectively on all instances of inline functions and enable inline debugging, enter either of the following commands: (gdb) set inline-debug inline_bp_all or $ gdb --inline = inline_bp_all • To set and modify individual breakpoints on specific instances of inline functions and enable inline debugging, enter either of the following commands be- fore debugging the application: (gdb) set inline-debug inline_bp_individual or $
14.9.1 Viewing and Evaluating Macro Definitions HP WDB 5.7 and later versions of the debugger provide the following support for debugging macros: • Displaying Macro Definitions Displaying Macro Definitions HP WDB provides the following commands to display macro definitions: - macro show [macro-name] or info macro [macro-name] Displays the macro definition, source file name, and the line number. For example: (gdb) info macro VAR2 Defined at scope.
all To view and evaluate all the macro expressions in the program, you must compile the program with +macro_debug=all. This option can cause a significant increase in object file size. ref To view and evaluate only the reference macros in the program, you must compile the program with +macro_debug=ref. This is the default for -g, -g0, or -g1.
Sample Debugging Session • The following debugging session illustrates macro debugging when the program is com- piled with +macro_debug=all option: $ cc -g +macro_debug=all -o sc scope.c $ gdb sc HP gdb for HP Itanium (32 or 64 bit) and target Copyright 1986 - 2001 Free Software Foundation, ... (gdb) b 13 Breakpoint 1 at 0x40007d0:0: file scope.c, line (gdb) b 23 Breakpoint 2 at 0x40007d0:2: file scope.c, line (gdb) b 30 Breakpoint 3 at 0x40007e0:0: file scope.
The macro `USED2' has no definition in the current scope. (gdb) • The following debugging session illustrates macro debugging when the program is com- piled with +macro_debug=referenced option: $ cc -g +macro_debug=referenced -o sc1 scope.c $ gdb sc1 HP gdb for HP Itanium (32 or 64 bit) and target Copyright 1986 - 2001 Free Software Foundation, ... (gdb) b 13 Breakpoint 1 at 0x40007d0:0: file scope.c, line (gdb) b 23 Breakpoint 2 at 0x40007d0:2: file scope.
(gdb) q The program is running. Exit anyway? (y or n) y. 14.10 Debugging Memory Problems You can use HP WDB to find leaks, profile heap usage and detect other heap-related errors in HP C, HP aC++, and HP Fortran programs written for HP-UX 11.x systems. (Both 32-bit and 64-bit programs are supported.) On HP-UX 11.x, the memory debugging features of HP WDB work with both single-threaded and multi-threaded programs that use POSIX threads.
NOTE: Linker with version number B.11.19 or higher is required for debugging memory problems. • From HP WDB 5.7 onwards, the archive version of the run time check library, librtc.a, is not available. You must use the shared version of the library, librtc.[sl|so], instead. 14.10.3 Memory Debugging Methodologies HP WDB enables you to debug memory problems in applications written for HP-UX 11.x or later using C, aC++, FORTRAN 77, and Fortran 90.
14.10.4 Debugging Memory in Interactive Mode This section describes the various commands which help in debugging memory problems when the debugger is used in the interactive mode. 14.10.4.1 Commands for interactive memory debugging To debug memory problems, use these commands: set heap-check [on|off] This toggles the capability for detection of leaks, heap profiles, bounds checking, and checking for double free.
set heap-check reset GDB stores incremental heap growth data in an internal file. During one session data is appended to this file. If the session is very long, it is possible that this file may become very large. This command discards the data existing in the file and creates a new data file. Once this command is executed, the user cannot see the old data. info heap-interval < file name > This command creates the report of heap growth.
set heap-check null-check-size N Force malloc to return NULL after N bytes have been allocated by the program. catch nomem Allows the user to get control of an out-of-memory event. The user can step through once the nomem event is caught to see whether the out-of-memory event is handled correctly.
or depending on initial values of malloc() blocks, cause the program to fail. info dangling Displays a list of all the dangling pointers and dangling blocks that are potential sources of memory corruption( may have false positives). info corruption Checks for corruption in the currently allocated heap blocks.In addition, it lists the potential in-block corruptions in all the freed blocks.
(gdb) set heap-check leaks on 4. Set one or more breakpoints in the code where you want to examine cumulative leaks: (gdb) b myfunction 5. Run the program in the debugger: (gdb) run 6. Use the info command to show list of memory leaks: (gdb) info leaks Scanning for memory leaks...done 2439 bytes leaked in 25 blocks No. Total bytes Blocks Address Function 0 1234 1 0x40419710 foo() 1 333 1 0x40410bf8 main() 2 245 8 0x40410838 strdup() [...] The debugger assigns each leak a numeric identifier. 7.
check_heap|heap=on|off (or) Enables heap profiling. set heap-check check_leaks|leaks=on|off (or) set heap-check leaks Enables leak detection. check_string=on|off (or) set heap-check string Enables detection for writing out of boundary for strcpy, strncpy, memcpy, memccpy, memset, memmove, bzero, bcopy. check_bounds|bounds=on|off (or) set heap-check bounds Enables checking of bounds corruption. files=
files=batchrtc4 $ Incorrect Usage: $ cat rtcconfig check_leaks=on check_heap = on files=batchrtc4 $ Steps for Batch Mode Memory Debugging To use batch memory debugging, complete the following steps: 1. 2. 3. Compile the source files. Create an rtcconfig file in the current directory. Set an environment variable BATCH_RTC. If you are using the Korn or Posix shell, enter the following command at the HP-UX prompt: export BATCH_RTC=on 4.
NOTE: The chatr +rtc option preloads the librtc runtime library from the following default paths: – For 32 bit IPF applications, /opt/langtools/lib/hpux32/librtc.so – For 64 bit IPF applications, /opt/langtools/lib/hpux64/librtc.so – For 32 bit PA applications, opt/langtools/lib/librtc.sl – For 64 bit PA applications, /opt/langtools/lib/pa20_64/librtc.sl To preload the librtc runtime library from a path that is different from the default paths, you must use the LD_PRELOAD environment variable.
NOTE: Batch Mode RTC displays one of the following errors and causes the program to temporarily hang if the version of HP WDB and librtc.[sl|so] do not match, or if HP WDB is not available on the system: "/opt/langtools/bin/gdb: unrecognized option `-brtc' Use `/opt/langtools/bin/gdb --help' for a complete list of options." OR "execl failed. Cannot print RTC info: No such file or directory" This error does not occur under normal usage where HP WDB or librtc.
export GDBRTC_CONFIG=./ export GDBRTC_CONFIG=/tmp ◦ Correct usage: export GDBRTC_CONFIG=/tmp/yet_another_config export GDBRTC_CONFIG=/tmp/rtcconfig • BATCH_RTC enables or disables batch memory leak detection. • On Itanium systems, from librtc version 6.1, gdb is not invoked in batch mode. Prior to librtc version 6.1, the GDB_SERVER is used to override the default path from where the gdb executable is used to provide the information on memory leak.
mem_logfile=stderr[+]filename heap_logfile=stderr[+]filename ◦ • Specify config_strings for +check=malloc on Itanium or HP WDB memory check batch mode on Integrity systems. Processing of the .gdbinit file is not enabled in batch mode from librtc 6.1 version and later. On Itanium system for librtc versions prior to 6.1, RTC_PROCESS_GDBINIT is an optional environment variable used to enable processing of the .gdbinit file. You can use the .
4. Complete one of the following steps: – Map the shared libraries privately using chatr, as follows: chatr +dbg enable On HP-UX 11i v3 Integrity systems, HP WDB enables automatic debugging of shared libraries without them being mapped private while attaching to a running program. For enabling automatic debugging of shared libraries, you must install the kernel patches PHKL_38651 and PHKL_38778.
$ chatr +rtc enable 5. Run the program as follows: ./ • Example from Integrity Systems: Example-2 1. Compile the source files. 2. The rtcconfig file should contain entries such as the following: check_heap=on check_leaks=on check_free=on files=exec1:exec2:exec3 output_dir=/tmp/results 3. Set the following environment variables as follows: export BATCH_RTC=on 4.
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 for the chatr command.In addition to automatically loading the librtc library, the +rtc option for the chatr command also maps the shared libraries as private.
2. 3. Run the program. Start a debugging session as follows: gdb -leaks 4. Use info heap and info leaks commands to obtain a memory analysis report of the application. NOTE: From HP WDB 5.7 onwards, the archive version of the run time check library, librtc.a, is not available. You must use the shared version of the library, librtc.[sl|so], instead. 14.10.7 Open-files reporting From version 6.
$ set heap-check frame-count [num] The stack depth, [num], is the number of stack frames that HP WDB collects for each allocation. You can specify a higher value for [num] to view more stack frames for each reported allocation. However, the performance of the application is reduced because of the increased stack depth. 14.10.8.2 Specifying minimum leak size HP WDB enables you to specify the minimum leak size for stack trace collection to improve the program's performance.
If HP WDB detects an erroneous call to free(), it stops the program and reports this condition. You can then look at the stack trace to understand where and how the problem occurred. 14.10.9.
When this setting is turned on, any time a memory block is allocated or deallocated, HP WDB scrambles the space and overwrites it with a specific pattern. This change to the memory contents increases the chance that erroneous behaviors will cause the program to fail. Examples of such behavior include attempting to access space that is freed or depending on initial values of malloc() blocks. You can now look at the stack trace to understand where and how the problem occurred.
14.10.9.7 Specify the amount of guard bytes for every block of allocated memory HP WDB enables you to programmatically control the size of guard bytes for every block of the allocated memory. You can use these guard bytes to spot very rare and non-trivial boundary (buffer over-run and buffer under-run) corruptions. This again is available optionally when the user specifies set heap-check retain-freed-blocks . 14.10.10 Comparison of Memory Debugging Commands in Interactive Mode and Batch Mode HP WDB 5.
Table 2 Memory Debugging Commands in Interactive and Batch Mode (continued) Command Description Interactive mode Batch mode Specify the minimum size of a block set heap-check for stack trace collection. GDB report min-leak-size leaks of blocks, smaller than this value. However, no stack trace is provided.
NOTE: The files= and output_dir= options are exclusive to batch mode debugging. 14.10.11 Heap Profiling The heap profile is useful for identifying how memory is being used by the program. You can use HP WDB to profile an application's current heap usage. 14.10.11.1 Commands for heap profiling info heap Displays a heap report, listing information such as the start of the heap, end of the heap, heap allocations, size of blocks, and number of instances.
14.10.11.4 info heap process The info heap process command enables the user to view a high level memory usage report of a process. This command is available only for applications running on 11i v3 or later. 14.10.11.5 Example for heap profiling This example shows how to use this feature on HP-UX 11.x: 1. If the linker version is earlier than B.11.19, link with /opt/langtools/lib/ pa20_ 64/librtc.sl for PA-64 programs. For a 32-bit program, you must link with /opt/langtools/lib/librtc.sl.
in _start () in $START$ () 14.10.12 Memory Checking Analysis for User Defined Memory Management Routines Many user applications have their own memory management routines. These custom allocator routines are either user defined or sometimes wrappers to the default memory management routines. Memory checking features has been extended for user defined memory management routines. Memory leak, profile of heap memory or memory errors can be obtained for user defined memory management routines.
export LD_PRELOAD=/opt/langtools/lib/hpux64/librtc.so:/usr/lib/hpux64/libmallocng.so • For 32–bit executable export LD_PRELOAD=/opt/langtools/lib/hpux32/librtc.so:/usr/lib/hpux32/libmallocng.so This feature is available only on HP Integrity systems. 14.11 Thread Debugging Support HP WDB provides thread-debugging support for kernel, user, and MxN threads. You can exclusively disable or enable specific thread execution.
means gdb reports only those kernel threads that are associated with user threads. show show-all-kthreads Displays the status of current set show-all-kthreads command. 14.11.2 Backtrace Support for Thread Debugging The following commands are available as backtrace support for thread debugging: bt The bt command provides the stack trace of the current thread that is being executed or the thread that accepts the signal in case of a core file.
• The thread terminates execution without unlocking the associated mutexes or read-write locks. • The thread waits on a condition variable for which the associated mutex is not locked. • The thread terminates execution, and the resources associated with the terminated thread continues to exist in the application because the thread has not been joined or detached. • The thread uses more than the specified percentage of the stack allocated to the thread.
This command automatically enables dynamic library path look-up. No additional environmental variables are required to be set. 14.11.3.2 Enabling and Disabling Advanced Thread Debugging Features HP WDB 5.6 and later versions of the debugger provide advanced thread debugging features for debugging multi-threaded applications running on 11i v2, or 11i v3. These features are available as options to the set thread-check command.
deadlock. However, it degrades the application performance. The debugger transfers the execution control to the user and prints a warning message when this condition is detected. cv-multiple-mxs [on|off] The set thread-check cv-multiple-mxs [on|off] command checks if an application uses the same condition variable in multiple calls, by different threads to pthread_cond_wait() or pthread_cond_timedwait(), but specifies different mutexes.
pthread_cond_wait() routine. It is an additional check provided by HP WDB. thread-exit-own-mutex [on|off] The set thread-check thread-exit-own-mutex [on|off] command checks if any thread has terminated execution without unlocking the mutexes or read-write locks that are associated with the thread. The debugger transfers the execution control to the user and prints a warning message when this condition is detected.
allocated stack space, it results in a stack overflow. Stack over flow can result in memory access violations, bus errors, or segmentation faults. num-waiters [num] The set thread-check num-waiters [num] command checks if the number of threads waiting on any pthread object exceeds the specified threshold number [num]. The debugger transfers the execution control to the user and prints a warning message when this condition is detected. 14.11.3.3 Commands to view information on pthread primitives HP WDB 5.
1. Set LD_LIBRARY_PATH to include the appropriate directory, by entering one of the following commands: • For 32 bit IPF applications, export LD_LIBRARY_PATH=/opt/langtools/wdb/lib/hpux32 • For 64 bit IPF applications, export LD_LIBRARY_PATH=/opt/langtools/wdb/lib/hpux64 • For 32 bit PA applications, export LD_LIBRARY_PATH=/opt/langtools/wdb/lib • For 64-bit PA applications, export LD_LIBRARY_PATH=/opt/langtools/wdb/lib/pa20_64 2. 3.
OR • Instead of automatically preloading librtc and mapping the shared libraries, you can explicitly preload the required librtc library after mapping the shared libraries private. In the case of HP 9000 systems, you must explicitly map the share libraries as private by using the +dbg enable option for the chatr command, as follows: $ chatr +dbg enable ./ (This step is not required on Integrity systems.
debugger provides a log file with the list of thread-related errors that occur in the application. In batch mode, the debugger detects the all the thread-conditions that are detected during an interactive debugging session. The debugger reports extended information such as variable address, name, id and other specifications related to the involved pthread objects. In addition, it displays the stack trace of the executing thread at the point of error.
NOTE: The configuration file contains lines of the following form: set thread-check [on|off] | [option] [on|off] | [option] [num] And/Or set frame-count [num] And/Or files= For more information, see “Enabling and Disabling Advanced Thread Debugging Features” (page 179). 4.
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 for the chatr command. In addition to automatically loading the librtc library, the +rtc option for the chatr command also maps the shared libraries as private.
If LD_PRELOAD and chatr +rtc are used to preload the librtc runtime library , the librtc runtime library is loaded from the path specified by LD_PRELOAD. If HP WDB detects any thread error condition during the application run, the error log is output to a file in the current working directory. The output file has the following naming convention: ..threads where, is the process id. 14.11.5.
Behavior of the +check=thread option can be changed by users by providing their own rtcconfig file. The user specified rtcconfig file can be in the current directory or in a directory specified by the GDBRTC_CONFIG environment variable. If any thread error condition is detected during the application run, the error log will be output to a file in the current working directory. The output file will have the following naming convention: ..threads, where is the process identifier.
14.13 Debugging multiple processes (programs with fork and vfork calls) 14.13.1 Ask mode for set follow-fork-mode The ask command prompts the user to select between parent and child as the debugger response to a program call of fork/vfork. Based on the user selection, the parent or the child process is debugged. For example, (gdb) set follow-fork-mode ask (gdb) show follow-fork-mode The debugger response to a program call to fork or vfork is ask.
0x40172b25: 0x40172b27: 0x40172b29: 0x40172b2b: 0x40172b2c: 0x40172b2e: 0x40172b2f: (ea) (b2) (61) (81) (c0) (00) (00) P7lc_when t=7 P3lc_gr gr=40 R3body rlen=33 B1label_state label=1 B2epilogue t=44 R1prologue rlen=0 R1prologue rlen=0 14.14 Command to Search for a Pattern in the Memory Address Space The HP WDB find command searches for a pattern in the given memory address range for both live and corefile debugging.
Example 1 Sample Output for the find command $ cat example.c #include #include int main() { char *str; str = (char *) malloc (15); strcpy(str,"hihi-hikh"); return 0; } (gdb) find &str[0], &str[15], "hi" 0x400123e0 0x400123e2 0x400123e5 3 patterns found. (gdb) find/2 &str[0], &str[15], "hi" 0x400123e0 0x400123e2 2 patterns found. (gdb) find/2b &str[0], &str[15], 0x68 0x400123e0 0x400123e2 2 patterns found. (gdb) find/2b &str[0], +10, 0x68 0x400123e0 0x400123e2 2 patterns found.
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' Specifies the pattern. Using the start address (start-address), length (+length) parameter, and a pattern (expr1) find &str[0], +11, "hihi" • &str[0] Specifies the starting address. +11 Specifies the length of the memory address range, starting from &str[0]. "hihi" Specifies the pattern (expr1).
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 matching pattern. b Specifies that the size of the pattern is 8 bits. 14.15 Debugging Core Files 14.15.1 Generating core files with packcore /unpackcore/getcore The contents of a core file can be viewed only on a system which has all the shared libraries that were in use on the system on which the core file was generated.
this second argument causes a symbolic link to be created in the packcore directory in place of the missing core file. The getcore command can be used to examine a packcore directory which was previously created by unpackcore. It takes one optional argument, the name of the packcore directory, which defaults to packcore. 14.15.2 Support for the info target Command The info target command is enhanced to display the memory segments for the corefile.
NOTE: Limitations for the enhanced info target command on corefile are as follows: • The enhanced info target command is not supported when the expanded_node_host_names kernel parameter is set. It is supported only for the default utsname. • The heap segment listed in the memory segment does not contain mmapped memory for the given core file. 14.15.
To analyze this core file with HP WDB on HP-UX 11i version 2, you must do the following: • When starting from HP WDB command line: (gdb) core-file [core.pid | core-filename] • When starting from shell prompt: $ gdb -core a.out [core.pid | core-filename] 14.15.4 Support for display of run time type information HP WDB enables you to view the run time type information for C++ polymorphic object. info rtti address This command displays run time type information for C++ polymorphic object.
NOTE: Only the 64-bit version of the libaries64.so library can be used to read in data about the emulated stack frames. 14.15.5.2 Command to Support Core File Debugging in Mixed More Applications A new command set debug-aries is introduced in HP WDB to support core file debugging in mixed mode applications. The set debug-aries command is used to determine whether the frames of the emulator library (libaries32.
up/down Traverses through frames including PA-RISC frames, if any. 14.15.5.4 Command and Features Applicable to PA-RISC Libraries The following commands and features are applicable for PA-RISC libraries (for both live and corefile debugging), in addition to Integrity libraries: disass or disass Displays the PA-RISC disassembly instructions of the specified PA-RISC routine or at the specified PA-RISC address.
Following are known issues in mixed mode debugging: • Listing of registers currently in use for PA-RISC 32-bit shared library frames causes the unswizzled 32-bit values to be displayed. • Clicking on the registers tab for a PA-RISC frame in the HP WDB-GUI results in incorrect register information being displayed. Alternatively, execute the info reg command at the gdb prompt in the Commands tab.
return -1; } fd = open("testfile", O_RDWR); if ( fd == -1 ) { perror("open"); return -1; } p = mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); assert( p != (void *)-1 ); q = mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE, devzfd, 0); assert( q != (void *)-1 ); r = mmap(NULL, 4096, PROT_READ, MAP_PRIVATE, fd, 0); assert( r != (void *)-1 ); s = mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0); assert( s != (void *)-1 ); t = mmap(NULL, 4096, PROT_READ, MAP_SHARED, fd,
(gdb) p u $7 = 0x60000000c4406000
The pointers r, s, t are from mmap-ed regions which are missing in corefile. (gdb) help mmapfile Add contents of memory mapped files missing from core dump. Usage: mmapfile This can be used if the core file does not contain mmap-ed regions from the live run. This can happen for files mmap-ed with MAP_PRIVATE with RO permissions, or for files mmap-ed with MAP_SHARED.mmapfile = testfile can not be added Specifying an unknown file, or providing an incomplete or wrong command reports appropriate error messages. (gdb) mmapfile xyz 0x60000000c1a91000 0 0xe1 mmapfile = xyz can not be opened (errno = 2) (gdb) mmapfile testfile 0x60000000c1a91000 Usage: mmapfile 14.16 Debugging with debug information available in the side debug file HP-UX/Integrity linker version B.12.56 onwards, includes an option +dbgfile .
◦ The directory where the executable resides, say /tmp/executable_dir/ ◦ If the debug file is not found where the executable resides, the debugger searches the directory /tmp/executable_dir/.debug You can specify the directory where the side file is kept using the environment variable GDB_DEBUG_ABSPATH. For example, if the side file is kept at /tmp, then specify the side file path to debugger by doing an export GDB_DEBUG_ABSPATH=/tmp.
• info global-exec-path [start_index] [end_index](aliased to info gep) Lists all the global execution path entries for the current thread. The [start_index] and [end_index] indicate the range of table indexes (execution path entries) that must be displayed. If [end_index] is not specified, the debugger displays the complete table of execution path entries, starting from [start_index]. If [start_index] and [end_index] are not specified, the complete table of execution path entries is displayed.
Sample Program: $cat execpath.c #include #include #include int main() { int a = 3, b = 0, c = 4; if (a) printf("Value of a greater than 0\n"); if (b) printf("Value of b greater than 0\n"); if (c) printf("Value of c greater than 0\n"); printf("All condition checking done\n"); return 0; } Sample Debugging Session: $cc +pathtrace -g execpath.c $gdb a.out HP gdb ... Type "show warranty" for warranty/support. ... (gdb) b main Breakpoint 1 at 0x4000a60:0: file execpath.
15 if (c) (gdb) i ep Local execution path table for main(): 0 0x4000a80:2 (execpath.c:10) (gdb) i gep Global execution path table: G0 0x4000a80:2 main (execpath.c:10) (gdb) n 16 printf("Value of c greater than 0\n"); (gdb) n Value of c greater than 0 18 printf("All condition checking done\n"); (gdb) i ep Local execution path table for main(): 0 0x4000a80:2 (execpath.c:10) 2 0x4000bd0:2 (execpath.
commands. This option enables you to debug a live process instead of getting a core dump if the program is about to abort. You can examine the state of the process, make changes to the state and continue program execution, force a core dump, or terminate execution. It enables you to control program execution under the debugger if the program is about to abort. You can load a new process or attach to a running process for monitoring.
(gdb) quit The program is running. Exit anyway? (y or n) y 14.21 Instruction Level Stepping During instruction level stepping with nexti and stepi, HP WDB prints the assembly instruction along with the next source line. (gdb) stepi 0x101530:0 st4 [r9]=r34 1337 args.argc = argc; It also prints DOC line information, which includes actual line number and the column number, when debugging a binary with -g -O. (gdb) stepi ;;; [8, 1] 0x4000820:1 nop.
There are only two hardware breakpoints that can be set on Integrity systems. This is useful in ROM code debugging and shared library debugging for libraries, including dld, that are not loaded private. The normal breakpoints are converted to a hardware breakpoint when HP WDB cannot set a normal breakpoint in the shared library. 14.22.3.
14.22.5 Support for template breakpoints With HP WDB 5.0, you can set breakpoints on all instantiations of the template class by just specifying the template name with member function name. For example: (gdb) break :: It is not necessary to specify the instantiation type. Setting a breakpoint on a template method with multiple instantiations displays a menu showing all instantiations and the user can choose to set breakpoints on all or any one or none.
Breakpoint deferred until a shared library containing "main" is loaded. (gdb) r Once the program has started running, it will hit the breakpoint. In addition, the debugger will then already know about the sources for main, since it gets this information when the shared library is loaded. 14.23.2 Setting Deferred Breakpoints in Shared Library On HP-UX, GDB automatically loads symbol definitions from shared libraries when you use the run command, or when you examine a core file.
To set the breakpoint you must kill the program and then rerun it so that the dynamic linker maps a copy of the shared library privately. There are two ways to run the program: • Rerun the program under GDB to have the debugger cause dld to map all shared libraries as private, enabling breakpoint debugging.
The -mapshared option is implemented on both PA-RISC and Itanium platforms in HP WDB 5.2. This option is provided in the HP WDB GUI and HP WDB. The default behavior does not change if the -mapshared option for all shared libraries in processes started under the debugger, or dynamically loaded after an attach, are mapped private. 14.23.6 Setting breakpoints in shared library Breakpoints can be set on functions in a shared library, by specifying the library name with the function name. (gdb) b libutil.
14.24.1.1 Printing Decimal floating point constant (gdb) print df, DF - _Decimal32 dd, DD - _Decimal64 dl, DL - _Decimal128 This prints the decimal floating point constant based on the data type. 14.24.1.2 Printing Decimal floating point variable (gdb) print/ = df, dd, dl - variable name This prints the decimal floating point variable. If you specify format then it prints the variable based on its data type. 14.24.
Arithmetic Operations: (gdb) print a(op1)b (gdb) print (op2)a op1 = addition, subtraction, multiplication and division. op2 = negation This performs arithmetic operation with decimal floating point data types. Comparison Operations: (gdb) p (op) where, op = ==, !=, >, >=, <, <= If expression contains comparison operation, then GDB compares the decimal floating point data types accordingly. (gdb) p 1.2dd == 1.2dd (gdb) 2.4 14.24.3.
NOTE: HP WDB will not support: • Command line calls of intrinsic functions(Mathematical functions like cos, sin, log etc) • Decimal Floating Point data type support for Fortran and C++ • HP-UX 11iv2 Integrity and HP 9000 systems 14.25 Additional Support for binary floating point data type 14.25.1 Support for Binary Floating Point constants f, l If the binary floating point constant contains the letter f or l then HP WDB recognizes it as float or long double binary floating point constant.
In order to use this functionality, the GDB_JAVA_UNWINDLIB environment variable must be set to the path name of the Java unwind library. This environment variable must be set for normal java debugging and java corefile debugging. The default location of the Java unwind library on various systems is shown following. The examples are for SDK 1.4; if you are using JDK 1.5, substitute /opt/java1.5 for /opt/java1.4. • For 32 bit IPF applications, export GDB_JAVA_UNWINDLIB = /opt/java1.
These additional features are available as part of Java heap support: • View Java heap parameters. • Dump Java object. • Print Java heap histogram. • Find all the instances of a given Java class. • Find all the references to a given object in the Java heap. • Find out the object OOP (object-oriented pointer) of the given field address. These additional features are available as part of Java threads support: • View Java threads state information. • View current Java thread information.
info frame Prints Java frame specific information for a Java frame. Standard frame command of GDB has been enhanced to interpret a Java stack frame. info threads Prints state information for Java threads. thread Prints detailed state information for the current Java thread.
1. Invoke gdb on a core file generated when running a 32-bit Java application on an Integrity system with /opt/java1.4/bin/java: $ gdb /opt/java1.4/bin/IA64N/java core.java 2. Invoke gdb on a core file generated when running a 64-bit Java application on an Integrity system with /opt/java1.4/bin/java -d64: $ gdb /opt/java1.4/bin/IA64W/java core.java 3. Invoke gdb on a core file generated when running a 32-bit Java application on PA-RISC using /opt/java1.4/bin/java: $ gdb /opt/java1.4/bin/PA_RISC2.
2. Attach gdb to the running process: $ gdb -p 23989 HP gdb 5.0 for HP Itanium (32 or 64 bit) and target HP-UX 11.2x. Copyright 1986 - 2001 Free Software Foundation, Inc. Hewlett-Packard Wildebeest 5.0 (based on GDB) is covered by the GNU General Public License.Type "show copying" to see the conditions to change it and/or distribute copies. Type "show warranty" for warranty/support. Reading symbols from /opt/java1.4/bin/IA64N/java... (no debugging symbols found)...done. Attaching to program: /opt/java1.
/* off 453 bits, len 27 bits */ float f; /* off 480 bits, len 32 bits */ 14.26.3 Support for _ _fpreg data type on IPF HP WDB internally converts __fpreg data type to long double data type to evaluate an expression or to print the value of the expression. Since long double data type has only 15 bit exponent as opposed to 17 bit exponent of __fpreg, some precision is lost when the exponent is larger than that can t in 15 bits. 14.26.
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 that you are in and, when possible, choose an appropriate symbol. The debugger recognizes using declarations, using directives, namespace aliases, nested namespaces, and unqualified lookup within a namespace. It also recognizes using directives and aliases, and using declarations within namespaces.
14.28 Support for output logging The Visual Interface for HP WDB terminal user interface (TUI) mode supports the command, log logfile_name, that saves the content of a session to the specified log file. When you use the log command, the debugger saves a snapshot of the current session, from the start of the session to the point where you issued the log command. Each time you use the log command, HP WDB overwrites the specified log file with a new snapshot from the start of the session.
The first two lines are comments about this file and the array. The third line denotes the array coordinates. From the fourth line, the elements of the array are listed. Note: This feature is not supported for the Fortran array slices. 14.28.2 Support for Fortran array slices HP WDB prints Fortran array slices if you specify a range of elements by the Fortran 90 array section syntax.
For example, (gdb) 4 int k = 10; (gdb) sl ---> alias to "steplast" command error: Steplast is not meaningful for the current line To execute the steplast command in C++ compiled applications, you must compile the application using the HP aC++ version A.03.50 or later with the -g0 option. In C++, the steplast command is helpful while debugging heavy templated functions, because it directly steps into the call, thus skipping the constructor calls, if any.
The following commands evaluate the name of a function and hence are affected by the optimization level of the program being debugged (in particular, due to inlining): • break • call • clear • disassem • list The following commands evaluate an expression referring to variables in the user program and hence, are affected by the optimization level of the program being debugged: • break • call • cond • jump • return • print • set • watch • whatis x NOTE: The break and call com
• rbreak • up The following commands are not affected by the optimization level of the program being debugged: • attach • catch • commands • continue • core • delete • define • detach • disable • enable * • file • forw • handle * • help * • ignore • kill • load • nexti • path • quit • rev • run • set args, set env, set • show args, show • signal • source • stepi 14.
• symbol • target • tty • undisplay • unset env • until 14.30.1 Debugging Optimized Code at Various Optimization Levels The following sections describe debugging optimized code support at each optimization level. 14.30.1.1 +O0 and +O1 At +O1 level, optimizations that affect the user visible state of a program are avoided. Line numbers are accurately associated with each machine instruction. Global or local variables may be examined, except for unused variables (which may be eliminated).
the variable at a source code location either before or after the reported source code location.(If the printed value is not current with respect to the current source line, the printed value will be the immediately previous or immediately later value for the variable.) Backtrace commands (backtrace) can be used to display the current nest of function calls, including calls that are inlined.
Complete support is available for debugging at the assembly language level. Stepping by instructions (stepi/nexti) steps as expected and reports the associated source line numbers for each instruction. NOTE: The -ipo compilation implies the +noobjdebug option because the -ipo object files do not store executable code or debug info. 14.31 Debugging with ARIES The ARIES fast interpreter emulates a complete set of non-privileged PA-RISC instructions with no user intervention.
3. The rest of the debugging operations are the same as that on the HP 9000 HP-UX platform. NOTE: Make sure that the user has write permission on /tmp directory and that there is enough space to create a temporary file of one page size as obtained by sysconf(_SC_PAGE_SIZE) system call. 14.31.1.1 Limitations of GDB Support under ARIES • No support for debuggers other than HP 9000 HP-UX GDB for debugging HP 9000 applications under ARIES on HP-UX 11i Integrity servers.
Use the steps below to attach GDB to HP 9000 application process under ARIES on HP-UX 11i Integrity servers: • Perform the same preparatory steps as required for debugging an HP 9000 HP-UX application using GDB under ARIES on HP-UX 11i Integrity server.
NOTE: If the program expects unbuffered input or uses curses, termcap, or terminfo, or otherwise transmits escape or control sequences to the terminal, you must use one of the following methods to run Visual Interface for HP WDB: • Start the process in one terminal and attach to it with Visual Interface for HP WDB. • Use the tty command at the debugger prompt so the program's input and output are directed to another terminal.
You can use the arrow and pagination keys on the keyboard to move the cursor: • Pagination keys move the cursor in the source window, at the top, above the status line. • Holding the shift key down while using the pagination keys moves the cursor in the debugger window. • The up and down arrow keys move the cursor in the source window. • Holding the shift key down while using the up and down arrow keys move the cursor in the debugger window.
The function keys F1 through F8 correspond to the bottom row of softkeys. The function keys F9 and up correspond to the top row. 14.32.3 Specifying foreground and background colors To change the foreground and background colors, update the `.Xdefaults' file in the home directory. The resources are the same as for `hpterm'. Here is a sample entry: HPterm*foreground: white HPterm*background: rgb:68/90/C4 14.32.
NOTE: A defect in dtterm may truncate the display of lines that do not t within the window. To work around this defect, refresh the display with CTRL-L or widen the terminal window so source lines do not wrap. If you use xterm and dtterm, update the `.Xdefaults' file with keyboard translations to get the shifted arrows and shifted paging keys to work. For xterm, use the following: XTerm*vt100.
`n' `N' Repeat search `%' Match braces `[[', `]]' Skip to the next procedure `:line number' Go to any line number All these commands require you to escape to `vi' command mode first. When you are done, type a for append or i for insert or other `vi' commands to return to text insertion mode. Or you can simply click the Prompt softkey. 14.32.8 Loading source files Escape to `vi' command mode and use the :e command to load a source file.
14.33 Support for ddd GDB works with ddd, the free GDB GUI shell available at http://mumm.ibr.cs.tu-bs.de/. While this is not formally supported by Hewlett-Packard, these two do work together. Note however if you have ddd issues, you'll need to report them to the ddd support channel. 14.34 Support for XDB commands HP WDB provides support for a subset of XDB commands, enabled with the -xdb option. 14.34.
• show logging redirect: Display the logging-mode. • show redirect: Display all current logging settings. 14.36 Support for command line calls in a stripped executable HP WDB enables you to perform command line calls in a stripped executable. 14.36.1 Support for command line calls in a stripped executable on PA-RISC systems In HP WDB, to perform command line calls in a shared library without the help of dynamic linker (using end.
To avoid changing of the run-time binding behavior of a program to BIND_IMMEDIATE, to perform command line call, do the following: • Use the linker option, +ea, to export symbols from an object file. • Install the linker patch, PHSS 28870 (for 11.0) or PHSS 28871 (for 11i). • Execute the following commands: cc -c file.c cc file.o -Wl,+ea,/opt/langtools/lib/end.o -s 14.36.2.2 For 64-bit applications To perform command line calls in a stripped executable, linked with end.
GDB will be able to place breakpoints using symbol names in the unstripped shared libraries loaded into the stripped executable. 14.37 Displaying the current block scope information The which command takes a symbol as an argument and prints the information on a given symbol.
except for the files in system libraries. The valid options are: Options Description none Source level debugging is not available when the program is compiled without -g. no_sys_libs Source level debugging is available for all the source files except the source files in the system libraries. This option is the default setting, when no options are specified. all show src-no-g Source level debugging is available for all the source files. Displays the current setting of source level debugging feature.
Example 2 Sample Commands to Print CFM and PFS registers Use the following command to print the PFS or ar64 register: (gdb) info reg ar64 pfs: 0xc000000000000c20 (sor:0, sol:24, sof:32) In the above example, 0xc000000000000c20 is the raw value and (sor:0, sol:24, sof:32) is the format for identifying rotating registers, frames and locals.
15 The HP-UX Terminal User Interface By default, GDB runs in line mode. For users who prefer an interface similar (though not identical) to that of the XDB debugger, HP provides a terminal user interface (TUI), which appears when you invoke the gdb command with the -tui option. Use the -xdb option to enable the use of a number of XDB commands. See the “XDB to HP WDB Transition Guide” (page 256). 15.1 Starting the TUI Invoke the debugger using a command like the following: gdb -xdb -tui a.
When you execute the program up to the first breakpoint by issuing the command run a right angle bracket (>) points to the current location. So after you issue those commands, the window looks something like this: |----------------------------------------------------------------------| |27 } | |28 | |29 int main(void) | |30 { | |31 /* Try two test cases.
The Command pane is always present. The possible configurations of the other panes are: • Source • Disassembly • Source/Disassembly • Disassembly/Register • Source/Register The layout command (abbreviated la) enables you to change from one window configuration to another. NOTE: You can abbreviate any command to its shortest unambiguous form. 15.3.1 Source pane The Source pane, Figure 1, appears by default when you invoke the debugger.
(gdb) la asm (gdb) 15.3.3 Source/Disassembly pane The Source/Disassembly pane appears when you issue the command: la split You can also reach this pane from the Source pane with the XDB command: td The window looks like this: :......................................................................: *>:32 print_average (my_list, first, last); : :33 print_average (my_list, first, last - 3); : :34 } : :35 : :36 : :37 : :......................................................................
:r12 1 r13 0 r14 0 : :r15 0 r16 40003fb8 r17 4 : :.........................................................................: |;;; print_average (my_list, first, last); | *> |0x3524 addil L'-0x800,%dp,%r1 | |0x3528 ldo 0x730(%r1),%r26 | |0x352c ldi 9,%r24 | |0x3530 ldi 0,%r25 | |0x3534 ldil L'0x3000,%r31 | |----------------------------------------------------------------------| File: average.
15.4 Cycling through the panes Use the commands la next and la prev to move from one pane to another without specifying a window name. If you specify la next repeatedly, the order the debugger uses is: • Source (src) • Disassembly (asm) • Source/Disassembly (split) • Source/Register • Disassembly/Register If you invoked the gdb command with the -xdb option as well as the -tui option, you can also use the following commands: td Toggle between Source and Disassembly/Register panes.
:.........................................................................: :flags 29000041 r1 51a800 rp 7f6ce597 : :r3 7f7f0000 r4 1 r5 7f7f06f4 : :r6 7f7f06fc r7 7f7f0800 r8 7f7f0800 : :r9 40006b10 r10 0 r11 40004b78 : :r12 1 r13 0 r14 0 : :r15 0 r16 40003fb8 r17 4 : :.........................................................................
(gdb) (gdb) (gdb) (gdb) (gdb) Focus (gdb) la split la regs la src la regs foc next set to REGS window. 15.6 Scrolling panes To scroll within a pane, you can use the arrow keys or the Page Up and Page Down keys (on some keyboards these are Prev and Next). You can also use the following commands: {+ | -} [num_lines] [win_name] Vertically scroll the pane forward (+) or backward (-). + or - with no arguments scrolls the pane forward or backward one page.
:33 print_average (my_list, first, last - 3); : :34 } : :35 : :......................................................................: File: average.c Procedure: main Line: 32 pc: 0x3524 (gdb) la regs (gdb) la src (gdb) la regs (gdb) foc next Focus set to REGS window. (gdb) fr #0 main () at average.c:32 (gdb) The default floating-point register display is single-precision.
If you omit win_name, the pane with logical focus is resized. When you increase the height of a pane, the height of the Command pane is decreased by the same amount, and vice versa. The height of any other panes remains unchanged. For example, the command wh src +3 increases the size of the source pane, and decreases the size of the command pane, by 3 lines. To find out the current sizes of all panes, use the info win command.
16 XDB to HP WDB Transition Guide This transition aid is designed for XDB users who are learning HP WDB, an HP-supported version of the industry-standard GDB debugger. Select one of these lists for a table that shows HP WDB equivalents for many common XDB commands and other features. Invoke HP WDB with the command gdb -tui to obtain a terminal user interface (TUI) similar to that provided by XDB. Commands marked "(with -tui)" are valid when you use the -tui option.
• “Breakpoint creation commands” • “Breakpoint status commands” • “All-procedures breakpoint commands” • “Global breakpoint commands” • “Assertion control commands” • “Record and playback commands” • “Macro facility commands” • “Signal control commands” • “Miscellaneous commands” 16.1.1 Invocation commands By default, HP WDB runs in line mode. To run it with a terminal user interface similar to that of XDB, use the -tui option.
Table 4 Window mode commands XDB Command HP WDB Equivalent Meaning {+ | -}r {+ | -}r (with -xdb -tui), {+ | -} data (with -tui), gdb -xdb -tui program Scroll floating-point registers forward or backward (src, cmd, and asm are also valid window names) fr fr (with -xdb -tui), display $fregs (with -tui) Display floating-point registers gr gr (with -xdb -tui), Display general registers display $regs (with -tui) sr sr (with -xdb -tui), display $sregs (with -tui) Display special registers td td (wi
Table 5 File viewing commands (continued) XDB Command HP WDB Equivalent Meaning Search source backward for [last] string ?[string] ?[string] (with -xdb), rev regexp D "dir" D "dir" (with -xdb), dir Add a directory search path for source files pathname L L (with -xdb) Show current viewing location or current point of execution ld ld (with -xdb), show directories List source directory search path (list all directories) lf lf (with -xdb), info sources List all source files lf [string] No equiv
The following table lists the XDB and equivalent HP WDB commands for viewing and modifying the program data: Table 6 Data viewing and modification commands XDB Command HP WDB Equivalent Meaning l l (with -xdb), info args followed by info locals Move view location forward or backward in source file number lines lc [string] lc [string] (with -xdb), info common string Search source forward for [last] string lg [string] lg [string] (with -xdb), info variables [string] Search source backward for [last
Table 6 Data viewing and modification commands (continued) XDB Command HP WDB Equivalent Meaning p expr[\format p[/format expr [Note: The Print value using the specified count and size portions of formats format are not allowed in the p (print) command. They are allowed in the x command (examine memory).
Table 7 Stack viewing commands (continued) XDB Command HP WDB Equivalent Meaning t [depth] t [depth] (with -xdb), bt Print stack trace to depth [depth] T [depth] T [depth] (with -xdb), bt full [depth] Print stack trace and show local vars top frame 0 View procedure at innermost frame of stack up down View procedure one level nearer innermost frame of stack (lower number) up number down number View procedure number levels nearer innermost frame of stack V [depth] V [depth] (with -xdb), fram
Table 9 Job control commands (continued) XDB Command HP WDB Equivalent Meaning C [location] until location Continue, allowing any pending signal, set temporary breakpoint at location g line g line (with -xdb), go line, tb line followed by jump line Go to line in current procedure g #label No equivalent Go to label in current procedure g {+ | -}lines g {+ | -}lines (with Go forward or back given # -xdb), go {+ | -}lines, tb lines {+ | -}lines followed by jump {+ | -}lines g {+ | -} g {+ | -} (
16.2.1 Auxiliary breakpoint commands The following table lists the XDB and equivalent HP WDB auxiliary breakpoint related commands: Table 11 Auxillary breakpoint commands XDB Command HP WDB Equivalent Meaning Print any string any_string p "any string" if expr {cmds} [{cmds}] if expr cmds [else cmds] Conditionally execute cmds end Q Q (with -xdb), silent (must Quiet breakpoints be first command in a commands list) 16.2.
Table 12 Breakpoint creation commands (continued) XDB Command HP WDB Equivalent Meaning bi -C expr No equivalent Set an instance breakpoint at first executable line of all non- static member functions of the instance's class (base classes included). bpc -c class rb ^class::* Set a class breakpoint at first executable line of all member functions of the instance's class (no base classes).
Table 13 Overall breakpoint commands (continued) XDB Command HP WDB Equivalent Meaning ab @shared- library No equivalent Activate suspended breakpoints in named shared library bc number expr bc number expr (with -xdb), Set a breakpoint count ignorenumber expr (within a commands list) db clear Delete breakpoint at current line db number delete number Delete breakpoint of the given number db * delete Delete all breakpoints sb number disable number Suspend breakpoint of the given number sb
16.2.6 Assertion control commands GDB does not provide the ability to trace by instruction. Watchpoints, however, provide similar functionality to xdb assertions. For example, watchpoints can be: • Enabled (corresponds to aa) • Disabled (corresponds to da) • Listed (corresponds to info watch) • Added (corresponds to x) HP WDB does not have explicit equivalents for the following commands: a aa da la sa ta x 16.2.7 Record and playback commands Use the source command to read commands from a file.
Table 15 Macro facility commands XDB Command HP WDB Equivalent def name replacement-text def name [GDB prompts for commands] Meaning Define a user-defined command tm No equivalent Toggle the macro substitution mechanism undef name def name [follow with empty command list] Remove the macro definition for name undef * No equivalent Remove all macro definitions 16.2.
Table 17 Miscellaneous commands (continued) XDB Command HP WDB Equivalent Meaning ! cmd line ! cmd line (with -xdb), she cmd line Invoke a shell {cmd list} commands [number] ... end Execute command list (group commands) Control-C Control-C Interrupt the program # [text] # [text] A comment am am (with -xdb), set height num Activate more (turn on pagination) f ["printf-style- fmt"] No equivalent Set address printing format h h Help M[{t | c} [expr[; expr...
Table 18 Data format commands (continued) XDB Command HP WDB Equivalent Meaning d d Decimal integer D (1) d Long decimal integer e No equivalent e Floating-point notation as float E (1) No equivalent e Foating-point notation as double f No equivalent f floating-point notation as float F (1) No equivalent f floating-point notation as double g f g floating-point notation as float G (1) f g floating-point notation as double i Use x/i command Machine instruction (disassembly) k No
Table 18 Data format commands (continued) XDB Command HP WDB Equivalent Meaning z t Print in binary Z (1) t Print in long binary (1) HP WDB will display data in the size appropriate for the data. It will not extend the length displayed in response to one of the uppercase formchars (for example, O, D, F). 16.
Table 20 Special language operators XDB Language Operator HP WDB Equivalent Meaning $addr Depends on language Unary operator, address of object $in No equivalent Unary Boolean operator, execution in procedure $sizeof sizeof Unary operator, size of object 16.6 XDB special variables and HP WDB equivalents GDB does not provide special variables of the kind that XDB has, but you can use show and set to display and modify many debugger settings.
16.7 XDB variable identifiers and HP WDB equivalents Table 22 Variable Identifiers XDB Variable Identifier HP WDB Equivalent Meaning var var Search for var class:: class:: Search class for var (bug: not yet) [[class]::]proc:[class::]var proc::var Search proc for var (static variables only) [[class]::]proc:depth:[class::] No equivalent Search proc for depth on stack . (dot) Empty string; for example, p is the Shorthand for last thing you looked equivalent of p .
Table 23 A (continued) XDB Command Equivalent HP WDB Command ab * enable ab @shared-library No equivalent abc cmds No exact equivalent, but display expr is equivalent to abc print expr am am (with -xdb), set height num apm oldpath [newpath] No equivalent apm "" [newpath] No equivalent 16.8.
Table 24 B (continued) XDB Command Equivalent HP WDB Command bpx cmds No equivalent bt proc b proc commands bnum finish c end bu [depth] bu [depth] (with -xdb). The finish command is equivalent to the sequence bu, c, db (to continue out of the current routine). bx [depth] bx [depth] (with -xdb) 16.8.
16.8.
Table 27 L (continued) XDB Command Equivalent HP WDB Command lm [string] show user [string] lo [[class]::][string] info func [[class]::][string] lp info functions lp [[class]::]string info func [[class]::]string info addr [[class]::]string lpm No equivalent lr lr (with -xdb), info all-reg lr string lr string (with -xdb), info reg string ls [string] No equivalent lz lz (with -xdb), info signals 16.8.
Table 28 M through P (continued) XDB Command Equivalent HP WDB Command pq class:: No equivalent pq [+ | -][\format No equivalent 16.8.
Table 30 T (continued) XDB Command Equivalent HP WDB Command ta No equivalent tb No equivalent tc No equivalent td td (with -xdb -tui) tf tf (with -xdb -tui), toggle $fregs (with -tui) tm No equivalent top frame 0 tr [@] No equivalent ts ts (with -xdb -tui) 16.8.
Table 31 U through Z (continued) XDB Command Equivalent HP WDB Command xdb program corefile gdb -xdb program -c corefile xdb -d dir gdb -xdb -d dir xdb -P pid program gdb -xdb program pid xdb -i (after starting) run < file xdb -o (after starting) run > file z number s z number s (with -xdb), handle number stop, handle number nostop z number i z number i (with -xdb), handle number nopass, handle number pass z number r z number r (with -xdb), handle number print, handle number noprint z numb
Table 32 Symbols (continued) XDB Command Equivalent HP WDB Command Return Return "any string" p "any string" . (dot) Empty string; for example, p is the equivalent of p.
Table 32 Symbols (continued) XDB Command Equivalent HP WDB Command Control-C Control-C # [text] # [text] #label No equivalent 282 XDB to HP WDB Transition Guide
17 Controlling GDB You can alter the way GDB interacts with you by using the set command. For commands controlling how GDB displays data, see “Print settings” (page 83). Other settings are described here. 17.1 Setting the GDB Prompt GDB indicates its readiness to read a command by printing a string called the prompt. This string is normally `((gdb))'. You can change the prompt string with the set prompt command.
To make command history understand your vi key bindings you need to create a ~/ .inputrc file with the following contents: set editing-mode vi The readline interface uses the .inputrc file to control the settings. set history filename fname Set the name of the GDB command history file to fname. This is the file where GDB reads an initial command history list, and where it writes the command history from this session when it exits.
show history, show history filename, These commands display the state of the GDB show history save, show history size, history parameters. show history by itself show history expansion displays all four states. show commands Display the last ten commands in the command history. show commands n Print ten commands centered on command number n. show commands + Print ten commands just after the commands last printed. 17.
set input-radix base Set the default base for numeric input. Supported choices for base are decimal 8, 10, or 16. base must itself be specified either unambiguously or using the current default radix; for example, any of set radix 012 set radix 10 set radix 0xa sets the base to decimal. On the other hand, set radix 10 leaves the radix unchanged no matter what it was. set output-radix base Set the default base for numeric display. Supported choices for base are decimal 8, 10, or 16.
((gdb)) run The program being debugged has been started already. Start it from the beginning? (y or n) If you are willing to unflinchingly face the consequences of your own commands, you can disable this feature: set confirm off Disables confirmation requests. set confirm on Enables confirmation requests (the default). show confirm Displays state of confirmation requests. 17.7 Optional messages about internal happenings set debug arch Turns on or off display of gdbarch debugging info.
show debug target Displays the current state of displaying GDB target debugging info. set debug varobj Turns on or o display of GDB variable object debugging info. The default is o. show debug varobj Displays the current state of displaying GDB variable object debugging info. 17.8 Configuring the Current Application Binary Interface (ABI) Some pre-release versions of C++ used an old ABI definition. Use the following commands to modify or display C++ ABI setting.
18 Canned Sequences of Commands In addition to breakpoint commands (see “Breakpoint command lists” (page 56)), GDB provides the following two ways to store sequence of commands for execution as a unit: • user-defined commands • command files 18.1 User-defined commands A user-defined command is a sequence of GDB commands to which you assign a new name as a command. This is done with the define command. User commands may accept up to 10 arguments separated by whitespace.
while The syntax is similar to if: the command takes a single argument, which is an expression to evaluate, and must be followed by the commands to execute, one per line, terminated by an end. The commands are executed repeatedly as long as the expression evaluates to true. document commandname Document the user-defined command commandname, so that it can be accessed by help. The command commandname must already be defined.
For example, to ignore SIGALRM signals while single-stepping, and treat them normally during normal execution, you could define: define handle end define handle end define handle end hook-stop SIGALRM nopass hook-run SIGALRM pass hook-continue SIGLARM pass You can define a hook for any single-word command in GDB, and not for command aliases; Also you should define a hook for the basic command name, for example, backtrace rather than bt.
to set breakpoints on fatal error routines or diagnostic routines. On some configurations of GDB, the init file is known by a different name (these are typically environments where a specialized form of GDB may need to coexist with other forms, hence a different name for the specialized version's init file). These are the environments with special init file names: • VxWorks (Wind River Systems real-time OS): .vxgdbinit • OS68K (Enea Data Systems real-time OS): .
echo This is some text\n echo which is continued\n echo onto several lines.\n output expression Print the value of expression and nothing but that value: no newlines, no `$nn = '. The value is not entered in the value history either. See “Expressions” (page 76). output/fmt expression Print the value of expression in format fmt. You can use the same formats as for print. See “Output formats” (page 79). printf string, expressions... Print the values of the expressions under the control of string.
19 Using GDB under gnu Emacs A special interface allows you to use gnu Emacs to view (and edit) the source files for the program you are debugging with GDB. To use this interface, use the command M-x gdb in Emacs. Give the executable file you want to debug as an argument. This command starts GDB as a subprocess of Emacs, with input and output through a newly created Emacs buffer.
In the GDB I/O buffer, you can use these special Emacs commands in addition to the standard Shell mode commands: C-h m Describe the features of Emacs' GDB Mode. M-s Execute to another source line, like the GDB step command; also update the display window to show the current file and location. M-n Execute to next source line in this function, skipping all function calls, like the GDB next command. Then update the display window to show the current file and location.
using the Emacs function format; otherwise the number is passed as an argument to the corresponding list element. In any source file, the Emacs command C-x SPC (gdb-break) tells GDB to set a break- point on the source line point is on. If you accidentally delete the source-display buffer, an easy way to get it back is to type the command f in the GDB buffer, to request a frame display; when you run under Emacs, this recreates the source buffer if necessary to show you the context of the current frame.
20 GDB Annotations This chapter describes annotations in GDB. Annotations are designed to interface GDB to graphical user interfaces or other similar programs which want to interact with GDB at a relatively high level. 20.1 What is an annotation? To produce annotations, start GDB with the --annotate=2 option. Annotations start with a newline character, two control-z characters, and the name of the annotation.
history, nor will it affect GDB's notion of which command to repeat if RET is pressed on a line by itself. The server prefix does not affect the recording of values into the value history; to print a value without recording it into the value history, use the output command instead of the print command. 20.3 Values When a value is printed in various contexts, GDB uses annotations to delimit the value from the surrounding text.
the-value ^Z^Zfield-end where field-name is the name of the field, separator-string is text which separates the name from the value for the user's benefit (such as `='), and value-flags and the-value have the same meanings as in a value-history-begin annotation. When printing an array, GDB annotates it as follows: ^Z^Zarray-section-begin array-index value-flags where array-index is the index of the first element being annotated and value-flags has the same meaning as in a value-history-begin annotation.
• ^Z^Zfunction-call function-call-string where function-call-string is text designed to convey to the user that this frame is associated with a function call made by GDB to a function in the program being debugged.
where source-intro-string separates for the user's benefit the reference from the text which precedes it, filename is the name of the source file, and line-number is the line number within that file (the first line is line 1). If GDB prints some information about where the frame is from (which library, which load segment, etc.
^Z^Zpre-prompt ^Z^Zprompt ^Z^Zpost-prompt The input types are: prompt When GDB is prompting for a command (the main GDB prompt). commands When GDB prompts for a set of commands, like in the commands command. The annotations are repeated for each command which is input. overload-choice When GDB wants the user to select between various overloaded functions. query When GDB wants the user to confirm a potentially dangerous operation.
where header-entry has the same syntax as an entry (see below) but instead of containing data, it contains strings which are intended to convey the meaning of each field to the user. This is followed by any number of entries. If a field does not apply for this entry, it is omitted. Fields may contain trailing whitespace.
is output. Before the stopped annotation, a variety of annotations describe how the program stopped. ^Z^Zexited exit-status The program exited, and exit-status is the exit status (zero for successful exit, otherwise nonzero). ^Z^Zsignalled The program exited with a signal.
20.12 Annotations We Might Want in the Future • target-invalid the target might have changed (registers, heap contents, or execution status). For performance, we might eventually want to hit registers-invalid and all-registers-invalid with greater precision • systematic annotation for set/show parameters (including invalidation notices). • similarly, `info' returns a list of candidates for invalidation notices. 20.
21 The GDB/MI Interface Function and purpose GDB/MI is a line based machine oriented text interface to GDB. It is specifically intended to support the development of systems which use the debugger as just one small component of a larger system. This chapter is a specification of the GDB/MI interface. It is written in the form of a reference manual. Notation and terminology This chapter uses the following notation: • | separates two alternatives.
nl → CR | CR-LF Notes: • The CLI commands are still handled by the MI interpreter; their output is described below. • The token, when present, is passed back when the command finishes. • Some MI commands accept optional arguments as part of the parameter list. Each option is identified by a leading `-' (dash) and may be followed by an optional argument parameter.
result → variable "=" value variable → string value → const | tuple | list const → c-string tuple → "{}" | "{" result ( "," result )* "}" list → "[]" | "[" value ( "," value )* "]" | "[" result ( "," result )* "]" stream-record → console-stream-output | target-stream-output | log-stream-output console-stream-output → "~" c-string target-stream-output → "@" c-string log-stream-output → "&" c-string nl → CR | CR-LF token → any sequence of digits.
• log-stream-output is output text coming from GDB's internals, for instance messages that should be displayed as part of an error log. All the log output is prefixed by '&'. • New GDB/MI commands should only output lists containing values. See “GDB/MI stream records” (page 310), for more details about the various output records. 21.1.3 Simple examples of GDB/MI interaction This subsection presents several simple examples of interaction using the GDB/MI interface.
This mechanism is provided as an aid to developers of GDB/MI clients and not as a reliable interface into the CLI. Since the command is being interpreted in an environment that assumes GDB/MI behaviour, the exact output of such commands is likely to end up being an un-supported hybrid of GDB/MI and CLI output. 21.3 GDB/MI output records 21.3.
21.4 GDB/MI command description format The remaining sections describe blocks of commands. Each block of commands is laid out in a fashion similar to this section. Note the line breaks shown in the examples are here only for readability. They do not appear in the real output. Also note that the commands with a non-available example (N.A.) are not yet implemented. Motivation The motivation for this collection of commands. Introduction A brief introduction to this collection of commands as a whole.
GDB command The corresponding GDB command is 'ignore'. Example (gdb) -break-insert main ^done,bkpt=number="1",type="breakpoint",disp="keep",enabled="y", addr="0x000100d0",func="main",file="hello.
{width="3",alignment="-1",col_name="enabled",colhdr="Enb"}, {width="10",alignment="-1",col_name="addr",colhdr="Address"}, {width="40",alignment="2",col_name="what",colhdr="What"}], body=[bkpt={number="1",type="breakpoint",disp="keep",enabled="y", addr="0x000100d0",func="main",file="hello.c",line="5",cond="1", times="0",ignore="3"}]} (gdb) The -break-delete command Synopsis -break-delete ( breakpoint )+ Delete the breakpoint(s) whose number(s) are specified in the argument list.
Example (gdb) -break-disable 2 ^done (gdb) -break-list ^done,BreakpointTable={nr_rows="1",nr_cols="6", hdr=[{width="3",alignment="-1",col_name="number",colhdr="Num"}, {width="14",alignment="-1",col_name="type",colhdr="Type"}, {width="4",alignment="-1",col_name="disp",colhdr="Disp"}, {width="3",alignment="-1",col_name="enabled",colhdr="Enb"}, {width="10",alignment="-1",col_name="addr",colhdr="Address"}, {width="40",alignment="2",col_name="what",colhdr="What"}], body=[bkpt={number="2",type="breakpoint",disp="
Get information about a single breakpoint. GDB command The corresponding GDB command is 'info break breakpoint'. Example N.A. The -break-insert command Synopsis -break-insert [ -t ] [ -h ] [ -r ] [ -c condition ] [ -i ignore-count ] [ -p thread ] [ line | addr ] If specified, line, can be one of: • function • filename:linenum • filename:function • *address The possible optional parameters of this command are: '-t' Insert a temporary breakpoint. '[-h]' Insert a hardware breakpoint.
NOTE: This format is open to change. GDB command The corresponding GDB commands are 'break', 'tbreak', 'hbreak', 'thbreak', and 'rbreak'. Example (gdb) -break-insert main ^done,bkpt=number="1",type="breakpoint",disp="keep",enabled="y",addr="0x0001072c", file="recursive2.c",line="4",times="0" (gdb) -break-insert -t foo ^done,bkpt=number="2",type="breakpoint",disp="keep",enabled="y",addr="0x00010774", file="recursive2.
If there are no breakpoints or watchpoints, the BreakpointTable body field is an empty list. GDB command The corresponding GDB command is 'info break'.
GDB command The corresponding GDB commands are 'watch', 'awatch', and 'rwatch'. Example Setting a watchpoint on a variable in the main function: (gdb) -break-watch i ^done,wpt=number="2",exp="i" (gdb) -exec-continue ^running (gdb) *stopped,reason="watchpoint-trigger",wpt=number="2",exp="i",value=old="0",new="7" ,thread-id="1",frame=addr="0x000029c4",func="main",args=[],file="hello.c",line="8" (gdb) Setting a watchpoint on a variable local to a function.
width="4",alignment="-1",col_name="disp",colhdr="Disp",width="3",alinment="-1", col_name="enabled",colhdr="Enb",width="10",alignment="-1",col_name"addr",colhdr="Address", width="40",alignment="2",col_name="what",colhdr="What],body=[bkpt=number="1", type="breakpoint",disp="keep",enabled="y",addr="0x00029b4",func="call",file="hello.
Result The output for each instruction is composed of four fields: • Address • Func-name • Offset • Instruction Note that whatever included in the instruction field, is not manipulated directly by GDB/MI, that is it is not possible to adjust its format. GDB command There is no direct mapping from this command to the CLI.
(gdb) -data-disassemble -f basics.c -l 32 -n 3 -- 0 ^done,asm_insns=[ {address="0x000107bc",func-name="main",offset="0", inst="save %sp, -112, %sp"}, {address="0x000107c0",func-name="main",offset="4", inst="mov 2, %o0"}, {address="0x000107c4",func-name="main",offset="8", inst="sethi %hi(0x11800), %o2"}] (gdb) Disassemble 3 instructions from the start of main in mixed mode: (gdb) -data-disassemble -f basics.
(gdb) 311-data-evaluate-expression &A 311^done,value="0xefffeb7c" (gdb) 411-data-evaluate-expression A+3 411^done,value="4" (gdb) 511-data-evaluate-expression "A + 3" 511^done,value="4" (gdb) The -data-list-changed-registers Command Synopsis -data-list-changed-registers Display a list of the registers that have changed. GDB command GDB does not have a direct analog for this command; gdbtk has the corresponding command 'gdb_changed_register_list'.
GDB command GDB does not have a command which corresponds to '-data-list-register-names'. In gdbtk there is a corresponding command 'gdb_regnames'.
Example For a PPC MBX board (note: line breaks are for readability only, they do not appear in the actual output): (gdb) -data-list-register-values r 64 65 ^done,register-values=[{number="64",value="0xfe00a300"}, {number="65",value="0x00029002"}] (gdb) -data-list-register-values x ^done,register-values=[{number="0",value="0xfe0043c8"}, {number="1",value="0x3fff88"},{number="2",value="0xfffffffe"}, {number="3",value="0x0"},{number="4",value="0xa"}, {number="5",value="0x3fff68"},{number="6",value="0x3fff58"},
The -data-read-memory command Synopsis -data-read-memory [ -o byte-offset ] address word-format word-size nr-rows nr-cols [ aschar ] where: 'address' An expression specifying the address of the first memory word to be read. Complex expressions containing embedded white space should be quoted using the C convention. 'word-format' The format to be used to print the memory words. The notation is the same as for GDB print command (see“Output formats” (page 79)).
9^done,addr="0x00001390",nr-bytes="6",total-bytes="6", next-row="0x00001396",prev-row="0x0000138e",next-page="0x00001396", prev-page="0x0000138a",memory=[ {addr="0x00001390",data=["0x00","0x01"]}, {addr="0x00001392",data=["0x02","0x03"]}, {addr="0x00001394",data=["0x04","0x05"]}] (gdb) Read two bytes of memory starting at address shorts + 64 and display as a single word formatted in decimal.
The -display-disable Command Synopsis -display-disable number Disable display number. GDB command The corresponding GDB command is 'disable display'. Example N.A. The -display-enable command Synopsis -display-enable number Enable display number. GDB command The corresponding GDB command is 'enable display'. Example N.A. The -display-insert Command Synopsis -display-insert expression Display expression every time the program stops. GDB command The corresponding GDB command is 'display'. Example N.
List the displays. Do not show the current values. GDB command The corresponding GDB command is 'info display'. Example N.A. The -environment-cd command Synopsis -environment-cd pathdir Set the GDB working directory. GDB command The corresponding GDB command is 'cd'. Example (gdb) -environment-cd /kwikemart/marge/ezannoni/flathead-dev/devo/gdb ^done (gdb) The -environment-directory command Synopsis -environment-directory pathdir Add directory pathdir to the beginning of search path for source files.
Add directories pathdir to beginning of search path for object files. GDB command The corresponding GDB command is 'path'. Example (gdb) -environment-path /kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb ^done (gdb) The -environment-pwd command Synopsis -environment-pwd Show the current working directory. GDB command The corresponding GDB command is 'pwd'. Example (gdb) -environment-pwd ~Working directory /kwikemart/marge/ezannoni/flathead-dev/devo/gdb. ^done (gdb) 21.
(gdb) -exec-run ^running (gdb) x = 55 *stopped,reason="exited",exit-code="01" (gdb) Another way the program can terminate is if it receives a signal such as SIGINT. In this case, GDB/MI displays this: (gdb) *stopped,reason="exited-signalled",signal-name="SIGINT", signal-meaning="Interrupt" The -exec-abort command Synopsis -exec-abort Kill the inferior running program. GDB command The corresponding GDB command is 'kill'. Example N.A.
Asynchronous command. Resumes the execution of the inferior program until a breakpoint is encountered, or until the inferior exits. GDB command The corresponding GDB is 'continue'. Example -exec-continue ^running (gdb) @Hello world *stopped,reason="breakpoint-hit",bkptno="2",thread-id="1",frame=addr="0x000029d8", func="foo",args=[],file="hello.c",line="16"file="hello.c",line="13"} (gdb) The -exec-finish command Synopsis -exec-finish Asynchronous command.
The -exec-interrupt command Synopsis -exec-interrupt Asynchronous command. Interrupts the background execution of the target. Note how the token associated with the stop message is the one for the execution command that has been interrupted. The token for the interrupt itself only appears in the '^done' output. If the user is trying to interrupt a non-running program, an error message will be printed. GDB command The corresponding GDB command is 'interrupt'.
The -exec-next-instruction command Synopsis -exec-next-instruction Asynchronous command. Executes one machine instruction. If the instruction is a function, call continues until the function returns. If the program stops at an instruction in the middle of a source line, the address will be printed as well. GDB command The corresponding GDB command is 'nexti'.
file="hello.c",line="17" (gdb) The -exec-run command Synopsis -exec-run Asynchronous command. Starts execution of the inferior from the beginning. The inferior executes until either a breakpoint is encountered or the program exits. GDB command The corresponding GDB command is 'run'. Example (gdb) -break-insert main ^done,bkpt=number="1",type="breakpoint",disp="keep",enabled="y",addr="0x00002a08", func="main",file="hello.
GDB command The corresponding GDB command is 'step'. Example Stepping into a function: -exec-step ^running (gdb) ~"2" ~"3" *stopped,reason="end-stepping-range",thread-id="1",frame=addr="0x000029d0", func="call",args=[name="a",name="b"],file="hello.c",line="15" (gdb) Regular stepping: -exec-step ^running (gdb) ~"2" ~"3" *stopped,reason="end-stepping-range",thread-id="1",frame=addr="0x000029d8", func="call",args=[name="a",name="b"],file="hello.
(gdb) *stopped,reason="end-stepping-range", frame={addr="0x000100f4",func="foo",args=[],file="try.c",line="10"} (gdb) The -exec-until command Synopsis -exec-until [ location ] Asynchronous command. Executes the inferior until the location specified in the argument is reached. If there is no argument, the inferior executes until a source line greater than the current one is reached. The reason for stopping in this case will be 'location-reached'. GDB command The corresponding GDB command is 'until'.
The -file-exec-file command Synopsis -file-exec-file file Specify the executable file to be debugged. Unlike '-file-exec-and-symbols', the symbol table is not read from this file. If used without argument, GDB clears the information about the executable file. No output is produced, except a completion notification. GDB command The corresponding GDB command is 'exec-file'. Example (gdb) -file-exec-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.
Example N.A. The -file-list-shared-libraries command Synopsis -file-list-shared-libraries List the shared libraries in the program. GDB command The corresponding GDB command is info shared. Example N.A. The -file-list-symbol-files command Synopsis -file-list-symbol-files List symbol files. GDB command The corresponding GDB command is 'info file' (part of it). Example N.A. The -file-symbol-file command Synopsis -file-symbol-file file Read symbol table info from the specified file argument.
^done (gdb) 21.8 Miscellaneous GDB commands in GDB/MI The -gdb-exit command Synopsis -gdb-exit Exit GDB immediately. GDB command Approximately corresponds to 'quit'. Example (gdb) -gdb-exit The -gdb-set command Synopsis -gdb-set Set an internal GDB variable. GDB command The corresponding GDB command is 'set'. Example (gdb) -gdb-set $foo=3 ^done (gdb) The -gdb-show command Synopsis -gdb-show Show the current value of a GDB variable. GDB command The corresponding GDB command is 'show'. 21.
Example (gdb) -gdb-show annotate ^done,value="0" (gdb) The -gdb-version command Synopsis -gdb-version Show version information for GDB. Used mostly in testing. GDB command The corresponding GDB command is 'show version'. Example (gdb) -gdb-version ~GNU gdb 5.2.1 ~Copyright 2000 Free Software Foundation, Inc. ~GDB is free software, covered by the GNU General Public License, and ~you are welcome to change it and/or distribute copies of it under ~ certain conditions.
The -stack-info-depth command Synopsis -stack-info-depth [ max-depth ] Return the depth of the stack. If the integer argument max-depth is specified, do not count beyond max-depth frames. GDB command There is no equivalent GDB command.
Example (gdb) -stack-list-frames ^done, stack=[ frame={level="0 ",addr="0x00010734",func="callee4", file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"}, frame={level="1 ",addr="0x0001076c",func="callee3", file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="17"}, frame={level="2 ",addr="0x0001078c",func="callee2", file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="22"}, frame={level="3 ",addr="0x000107b4",func="callee1", file="../../../devo/gdb/testsuite/gdb.mi/basics.
'level' The frame number, 0 being the topmost frame, that is the innermost function. 'addr' The $pc value for that frame. 'func' Function name. 'file' File name of the source file where the function lives. 'line' Line number corresponding to the $pc. If invoked without arguments, this command prints a backtrace for the whole stack. If given two integer arguments, it shows the frames whose levels are between the two arguments (inclusive).
(gdb) -stack-list-frames 3 5 ^done,stack= [frame={level="3 ",addr="0x000107a4",func="foo", file="recursive2.c",line="14"}, frame={level="4 ",addr="0x000107a4",func="foo", file="recursive2.c",line="14"}, frame={level="5 ",addr="0x000107a4",func="foo", file="recursive2.c",line="14"}] (gdb) Show a single frame: (gdb) -stack-list-frames 3 3 ^done,stack= [frame={level="3 ",addr="0x000107a4",func="foo", file="recursive2.
GDB command The corresponding GDB commands are 'frame', 'up', 'down', 'select-frame', 'up-silent', and 'down-silent'. Example (gdb) -stack-select-frame 2 ^done (gdb) 21.10 GDB/MI Symbol query commands The -symbol-info-address command Synopsis -symbol-info-address symbol Describe where symbol is stored. GDB command The corresponding GDB command is 'info address'. Example N.A. The -symbol-info-file command Synopsis -symbol-info-file Show the file for the symbol.
GDB command 'gdb_get_function' in gdbtk. Example N.A. The -symbol-info-line command Synopsis -symbol-info-line Show the core addresses of the code for a source line. GDB command The corresponding GDB command is 'info line'. gdbtk has the 'gdb_get_line' and 'gdb_get_file' commands. Example N.A. The -symbol-info-symbol command Synopsis -symbol-info-symbol addr Describe what symbol is at location addr. GDB command The corresponding GDB command is 'info symbol'. Example N.A.
Example N.A. The -symbol-list-types command Synopsis -symbol-list-types List all the type names. GDB command The corresponding commands are 'info types' in GDB, 'gdb_search' in gdbtk. Example N.A. The -symbol-list-variables command Synopsis -symbol-list-variables List all the global and static variable names. GDB command 'info variables' in GDB, 'gdb_search' in gdbtk. Example N.A. The -symbol-locate command Synopsis -symbol-locate GDB command 'gdb_loc' in gdbtk. Example N.A. 21.
The -symbol-type command Synopsis -symbol-type variable Show type of variable. GDB command The corresponding GDB command is 'ptype', gdbtk has 'gdb_obj_variable'. Example N.A. 21.11 GDB/MI Target Manipulation Commands The -target-attach command Synopsis -target-attach pid | file Attach to a process pid or a file file outside of GDB. GDB command The corresponding GDB command is 'attach'. Example N.A.
The -target-detach command Synopsis -target-detach Disconnect from the remote target. There is no output. GDB command The corresponding GDB command is 'detach'. Example (gdb) -target-detach ^done (gdb) The -target-download command Synopsis -target-download Loads the executable onto the remote target. It prints out an update message every half second, which includes the fields: 'section' The name of the section. 'section-sent' The size of what has been sent so far for that section.
Example NOTE: Each status message appears on a single line. Here the messages have been broken down so that they can fit onto a page. (gdb) -target-download +download,{section=".text",section-size="6668",total-size="9880"} +download,{section=".text",section-sent="512",section-size="6668", total-sent="512",total-size="9880"} +download,{section=".text",section-sent="1024",section-size="6668", total-sent="1024",total-size="9880"} +download,{section=".
write-rate="429" (gdb) The -target-exec-status command Synopsis -target-exec-status Provide information on the state of the target (whether it is running or not, for instance). GDB command There is no equivalent GDB command. Example N.A. The -target-list-available-targets command Synopsis -target-list-available-targets List the possible targets to connect to. GDB command The corresponding GDB command is 'help target'. Example N.A.
The -target-list-parameters command Synopsis -target-list-parameters GDB command No equivalent. Example N.A. The -target-select command Synopsis -target-select type parameters ... Connect GDB to the remote target. This command takes two args: 'type' The type of target, for instance 'async', 'remote', and so on. 'parameters' Device names, host names and the like. See “Commands for managing targets” (page 126), for more details.
GDB command No equivalent. Example N.A. The -thread-list-all-threads command Synopsis -thread-list-all-threads GDB command The equivalent GDB command is 'info threads'. Example N.A. The -thread-list-ids command Synopsis -thread-list-ids Produces a list of the currently known GDB thread ids. At the end of the list it also prints the total number of such threads. GDB command Part of 'info threads' supplies the same information.
The -thread-select command Synopsis -thread-select threadnum Make threadnum the current thread. It prints the number of the new current thread, and the topmost frame for that thread. GDB command The corresponding GDB command is 'thread'. Example (gdb) -exec-next ^running (gdb) ~"0x7f7f0aec" *stopped,reason="end-stepping-range",thread-id="2",frame=addr="0x00002ca4",func ="printme",args=[name="ip"],file="multithread.
NOTE: In addition to the set of operations described here, we expect the GUI implementation of a variable window to require, at least, the following operations: • -gdb-show output-radix • -stack-list-arguments • -stack-list-locals • -stack-select-frame Introduction to variable objects in GDB/MI The basic idea behind variable objects is the creation of a named object to represent a variable, an expression, a memory location or even a CPU register.
Table 33 GDB/MI Operations (continued) -var-assign set the value of this variable -var-update update the variable and its children In the next subsection we describe each operation in detail and suggest how it can be used.
The -var-set-format command Synopsis -var-set-format name format-spec Sets the output format for the value of the object name to be format-spec. The syntax for the format-spec is as follows: format-spec → {binary | decimal | hexadecimal | octal | natural} The -var-show-format command Synopsis -var-show-format name Returns the format used to display the value of the object name.
The -var-info-expression command Synopsis -var-info-expression name Returns what is represented by the variable object name: lang=lang-spec,exp=expression where lang-spec is {"C" | "C++" | "Java"}. The -var-show-attributes command Synopsis -var-show-attributes name List attributes of the specified variable object name: status=attr [ ( ,attr )* ] where attr is { { editable | noneditable } | TBD }.
22 Reporting Bugs in GDB Your bug reports play an essential role in making GDB reliable. Reporting a bug may help you by bringing a solution to your problem, or it may not. But in any case the principal function of a bug report is to help the entire community by making the next version of GDB work better. Bug reports are your contribution to the maintenance of GDB. In order for a bug report to serve its purpose, you must include the information that enables us to x the bug. 22.
despite the bug. Play it safe and give a specific, complete example. That is the easiest thing for you to do, and the most helpful. Keep in mind that the purpose of a bug report is to enable us to x the bug. It may be that the bug has been reported previously, but neither you nor we can know that unless your bug report is complete and self-contained.
Here are some things that are not necessary: • A description of the envelope of the bug. Often people who encounter a bug spend a lot of time investigating which changes to the input file will make the bug go away and which changes will not affect it. This is often time consuming and not very useful, because the way we will find the bug is by running a single example under the debugger with breakpoints, not by pure deduction from a series of examples.
A Installing GDB If you obtain GDB (HP WDB) as part of the HP ANSI C, HP ANSI C++ Developer's Kit for HP-UX Release 11.x, or HP Fortran, you do not have to take any special action to build or install GDB. If you obtain GDB (HP WDB) from an HP web site, you may download either an swinstall package or a source tree, or both. Most customers will want to install the GDB binary that is part of the swinstall package.
gdb-gdb-199991101/mmalloc source for the gnu memory-mapped malloc package The simplest way to configure and build GDB is to run configure from the gdb-version-number source directory, which in this example is the gdb-gdb-199991101 directory. First switch to the gdb-version-number source directory if you are not already in it; then run configure. Pass the identifier for the platform on which GDB will run as an argument. For example: cd gdb-gdb-199991101 .
(GNU make does), running make in each of these directories builds the gdb program specified there. To build gdb in a separate directory, run configure with the --srcdir option to specify where to find the source. (You also need to specify a path to find configure itself from your working directory. If the path to configure would be the same as the argument to --srcdir, you can leave out the --srcdir option; it is assumed.
% sh config.sub i386-linux i386-pc-linux-gnu % sh config.sub alpha-linux alpha-unknown-linux-gnu % sh config.sub hp9k700 hppa1.1-hp-hpux % sh config.sub sun4 sparc-sun-sunos4.1.1 % sh config.sub sun3 m68k-sun-sunos4.1.1 % sh config.sub i986v Invalid configuration `i986v': machine `i986v' not recognized config.sub is also distributed in the GDB source directory (gdb-gdb-199991101, for version gdb-199991101). A.
--target=target Configure GDB for cross-debugging programs running on the specified target. Without this option, GDB is configured to debug programs that run on the same machine (host) as GDB itself. There is no convenient way to generate a list of all available targets. host ... Configure GDB to run on the specified host. There is no convenient way to generate a list of all available hosts. There are many other options available as well, but they are generally needed for special purposes only.