The symbolic debugger, dbx, is the most commonly used debugger on UNIX operating systems, including AIX. The command provides many useful functions to debug application problems, including:
Examines object and core files
Provides a controlled environment for running a program
Sets break points
Traces program flow
Supervises symbolic variables
Although the usage of dbx is well explained in Chapter 3, “Debugging Programs”, in AIX 5L Version 5.2 General Programming Concepts: Writing and Debugging Programs, we describe the basic use of dbx and show useful customization examples.
Note
dbx does not support lightweight core file.
If an application aborted and generated a core file, run dbx as follows:
dbx ObjectFile CoreFile
If you do not specify the core file name, then the core file in the current directory is assumed to be the correct file. After starting a dbx session, it prints the sub-command prompt (dbx). The following example shows that the core file, core.30330.30144523, generated by prog1, is core dumped at line number 13 in main() because of the segmentation fault:
$ dbx prog1 core.30330.30144523 Type 'help' for help. reading symbolic information ... [using memory image in core.30330.30144523] Segmentation fault in main at line 13 13 s[j] = j;
To exit from a dbx session, type quit on the dbx sub-command prompt:
(dbx) quit
If you need to debug a running process, for example, your application seems to run into an endless loop, you can attach a dbx session to the process by specifying the process ID (PID) with the -a option, as shown in the following example:
$ dbx -a 25952 Waiting to attach to process 25952 ... Successfully attached to prog6. Type 'help' for help. reading symbolic information ... stopped in main at line 15 15 while (i >= j) { (dbx) quit [2] + Killed prog6 &
Note
If you type the quit sub-command on the sub-command prompt, the attached process will be killed as well as the dbx session. To exit from the dbx session without terminating the attached process, use the detach sub-command.
The dbx command reads in an initial configuration file, .dbxinit, in the following order:
The current directory
User’s home directory
If the .dbxinit file is found in the current directory, the command does not read the one in the user’s home directory. Or, you can explicitly specify the file name using the -c option.
By defining aliases of frequently used sub-commands or macros, you can customize your dbx session.
After starting the dbx session, you can also instruct dbx to dynamically read the configuration file by using the source sub-command as follows:
(dbx) source /home/ausres01/.dbxinit
The following settings are useful to customize your dbx session.
Using the print sub-command, you can print the value of a variable in a dbx session. If you have to print complex C or C++ structures or unions, it could be difficult to read and interpret the resulting output. Use the following sub-command to display more readable output.
Use the set $pretty=“on” sub-command to make your output more readable. Every value is print on its own line, with its scope value indented, as shown in the following example:
(dbx) set $pretty="off" (dbx) print names[0] (effort = (low = (0, 0), name1 = "Fabian", name2 = "Julian", name3 = "Manuel", high = ( (a = (0), b = 0) (a = (0), b = 0) )), range = (0)) (dbx) set $pretty="on" (dbx) print names[0] { effort = { low[0] = 0 low[1] = 0 name1 = "Fabian" name2 = "Julian" name3 = "Manuel" high[0] = { a[0] = 0 b = 0 } high[1] = { a[0] = 0 b = 0 } } range[0] = 0 }
You can also use the set $pretty=“verbose” sub-command for other printing styles, with each value on its own line and with qualified names:
(dbx) set $pretty="verbose" (dbx) print names[0] effort.low[0] = 0 effort.low[1] = 0 effort.name1 = "Fabian" effort.name2 = "Julian" effort.name3 = "Manuel" effort.high[0].a[0] = 0 effort.high[0].b = 0 effort.high[1].a[0] = 0 effort.high[1].b = 0 range[0] = 0 (dbx)
You can set the dbx’s sub-command line editor mode to either vi or emacs by using the sub-command set edit [vi/emacs] or set -o [vi/emacs].
The stop subcommand halts the application program when certain conditions are fulfilled. The program is stopped when:
The Condition is true when the if Condition flag is used.
The Procedure is called if the in Procedure flag is used.
The Variable is changed if the Variable parameter is specified.
The SourceLine line number is reached if the at SourceLine flag is used.
If you examine a core file, dbx has to resolve all references for libraries and shared objects loaded by the application when the core file is generated. The information is kept in the loader section of the core file. All file names except the main executable module are treated as absolute path names. The dbx command uses this table, not the LIBPATH environment variable.
If you bring the core file to another system to examine it, the libraries can be missing or in another location. Starting with AIX 5L Version 5.2, the -p flag of dbx allows you to map the old library names to the new ones. You do not need to alter the core file.
In the following example, the ./libone.so library (listed as entry 5) is used, which is located in the current directory:
(dbx) map Entry 1: Object name: prog8 Text origin: 0x10000000 ... Entry 5: Object name: ./libone.so Text origin: 0xd00d7000 Text length: 0x2fd Data origin: 0xf0323210 Data length: 0x34 File descriptor: 0x8 (dbx)
If the library is no longer at its original location, you will get an error upon the dbx session start:
$ dbx prog8 core Type 'help' for help. reading symbolic information ...dbx: fatal error: 1283-012 cannot open ./libone.so
To solve this problem, use the -p option to map the missing library to its new location, as shown in the following example:
$ dbx -p ./libone.so=./lib/libone.so prog8 core
Type 'help' for help.
[using memory image in core]
reading symbolic information ...
Segmentation fault in func8 at 0xd00d7158
0xd00d7158 (func8+0x30) 98640048 stb r3,0x48(r4)
(dbx) map
Entry 1:
Object name: prog8
...
Entry 5:
Object name: ./lib/libone.so
Text origin: 0xd00d7000
Text length: 0x2fd
Data origin: 0xf0323210
Data length: 0x34
File descriptor: 0x9
You can also put the mapping information in a file and call the -p flag as -pfilename.
Starting with AIX 5L Version 5.2, dbx has been modified to support broad compatibility with the GNU C compiler (gcc), so the command now can be used to debug applications compiled with gcc.
To debug application compiled with dbx, you have to specify the -gxcoff option when building an executable file as follows:
$ gcc -gxcoff prog.c -o prog