Example of tracing multiple functions in adb debugging
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 adbsamp3Starting the adb program
To start the session and open the program file, use the following command (no core file is used):
adb adbsamp3Setting breakpoints
First, set breakpoints at the beginning of each function using the :b subcommand:
.f:b
.g:b
.h:bDisplaying a set of instructions
Next, display the first five instructions in the f function:
.f,5?ia
.f:
.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)
.f+14:Display five instructions in function g without their addresses:
.g,5?i
.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:
:r
adbsamp3: running
breakpoint .f: mflr r0The 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:
.f:dContinuing the program
Use the :c subcommand to continue the program:
:c
adbsamp3: running
breakpoint .g: mflr r0The 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:
Displaying a variable value
Display the contents of the fcnt integer variable by entering the command:
fcnt/D
fcnt:
fcnt: 1Skipping breakpoints
Next, continue running the program and skip the first 10 breakpoints by entering:
,10:c
adbsamp3: running
breakpoint .g: mflr r0The 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:
$c
.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