[ Previous | Next | Contents | Glossary | Home | Search ]
AIX Version 4.3 General Programming Concepts: Writing and Debugging Programs

Example of Tracing Multiple Functions in adb Debugging

Note: The example program used in this section, adbsamp3, contains an infinite recursion of subfunction calls. If you run this program to completion, it causes a memory fault error and quits.

The following example shows how to execute a program under adb control and carry out the basic debugging operations described in the following sections.

The source program for this example is stored in a file named adbsamp3.c. Compile this program to an executable file named adbsamp3 using the cc command:

cc adbsamp3.c -o adbsamp3

Starting the adb Program

To start the session and open the program file, use the following command (no core file is used):

adb adbsamp3

Setting Breakpoints

First, set breakpoints at the beginning of each function using the :b subcommand:


Displaying a Set of Instructions

Next, display the first five instructions in the f function:

.f:              mflr  r0
.f+4:            st  r0, 0x8(r1)
.f+8:            stu  r1, -64(r1)
.f+c:            st  r3,  0x58(r1)
.f+10:           st  r4,  0x5c(r1)

Display five instructions in function g without their addresses:

.g:    mflr  r0
        st  r0, 0x8(r1)
        stu  r1, -64(r1)
        st  r3,  0x58(r1)
        st  r4,  0x5c(r1)

Starting the adsamp3 Program

Start the program by entering the following command:

adbsamp3: running
breakpoint   .f:       mflr  r0

The adb program runs the sample program until it reaches the first breakpoint where it stops.

Removing a Breakpoint

Since running the program to this point causes no errors, you can remove the first breakpoint:


Continuing the Program

Use the :c subcommand to continue the program:

adbsamp3: running
breakpoint   .g:       mflr  r0

The adb program restarts the adbsamp3 program at the next instruction. The program operation continues until the next breakpoint, where it stops.

Tracing the Path of Execution

Trace the path of execution by entering:

.g(0,0) .f+2a
.f(1,1) .main+e
.main(0,0,0) start+fa

The $c subcommand displays a report that shows the three active functions: main , f and g .

Displaying a Variable Value

Display the contents of the fcnt integer variable by entering the command:

fcnt:     1

Skipping Breakpoints

Next, continue running the program and skip the first 10 breakpoints by entering:

adbsamp3: running
breakpoint   .g:       mflr  r0

The adb program starts the adbsamp3 program and displays the running message again. It does not stop the program until exactly 10 breakpoints have been encountered. To ensure that these breakpoints have been skipped, display the backtrace again:

.g(0,0) .f+2a
.f(2,11) .h+28
.h(10,f) .g+2a
.g(11,20) .f+2a
.f(2,f) .h+28
.h(e,d) .g+2a
.g(f,1c) .f+2a
.f(2,d) .h+28
.h(c,b) .g+2a
.g(d,18) .f+2a
.f(2,b) .h+28
.h(a,9) .g+2a
.g(b,14) .f+2a
.f(2,9) .h+28
.h(8,7) .g+2a
.g(9,10) .f+2a
.f(2,7) .h+28
.h(6,5) .g+2a
.g(7,c) .f+2ae
.f(2,5) .h+28
.h(4,3) .g+2a
.g(5,8) .f+2a
.f(2,3) .h+28
.h(2,1) .g+2a
.g(2,3) .f+2a
.f(1,1) .main+e
.main(0,0,0) start+fa

Related Information

adb Debug Program Overview.

Using adb Expressions.

Displaying and Manipulating the Source File with the adb Program.

Example adb Program: adbsamp2.

Example adb Program: adbsamp3.

[ Previous | Next | Contents | Glossary | Home | Search ]