7.5. Debugging with the truss command

The truss command traces library and system calls and signal activity for a process.[3] It allows you to see all the system calls being made by a process, the parameters passed by those calls, and any data or errors returned from those calls. You can watch what your application is requesting from AIX and the results of those requests on live.

[3] The truss command has been supported on AIX, starting from Version 5.1. Several enhancements have been made in AIX 5L Version 5.2.

To demonstrate how it works, we present an application, which is composed of the four source files shown in Example 7-4.

Example 7-4. Source codes of prog_to_truss
/* main.c */
int main(int argc, char *argv[])
{
    func9_1(1);
    func9_3(2);
    exit(0);
}
/* sample9a.c */
void func9_1(int i)
{
    int     offset;

    offset = 10;
    func9_2(i);
    func9_3(i + offset);
}
/* sample9b.c */
void func9_2(int i)
{
    func9_3(i);
}
/* sample9c.c */
#include <stdio.h>
#include <stdlib.h>

void func9_3(int i)
{
    printf("I am here in func9_3 with %d !!
", i);
}

We have built the application, prog_to_truss, as follows:

$ cc -G -o libs91.so sample9a.c
$ cc -G -o libs92.so sample9b.c
$ cc -G -o libs93.so sample9c.c
$ cc -brtl prog9.c  -L. libs91.so libs92.so libs93.so -o prog_to_truss

The prog_to_truss application contains an object module, main.o, and references to three run-time linking shared objects (see 2.5, “Run-time linking” on page 68).

By default, truss does not trace library calls. In the following example, we have specified the -t!__loadx option, which means that any calls of the system call __loadx will be excluded from the output. Because the program calls three functions in run-time linking shared objects, if we do not specify this option, the output becomes very unclear for our demonstration:

$ truss -t!__loadx prog_to_truss
execve("./prog_to_truss", 0x2FF229FC, 0x2FF22A04)  argc: 1
sbrk(0x00000000)                                = 0x2000050C
sbrk(0x00000004)                                = 0x2000050C
sbrk(0x00010010)                                = 0x20000510
kioctl(1, 22528, 0x00000000, 0x00000000)        = 0
I am here in func9_3 with 1 !!
kwrite(1, 0xF01B5168, 24)                       = 24
I am here in func9_3 with 11 !!
kwrite(1, 0xF01B5168, 25)                       = 25
I am here in func9_3 with 2 !!
kwrite(1, 0xF01B5168, 24)                       = 24
kfcntl(1, F_GETFL, 0x00000000)                  = 67110914
kfcntl(2, F_GETFL, 0xF01B5168)                  = 67110914
_exit(0)

In the following example, we have specified the -u’*’ option to display the tracing output of any library function calls:

$ truss -t!__loadx -u'*' prog_to_truss
execve("./prog_to_truss", 0x2FF229FC, 0x2FF22A04)  argc: 1
sbrk(0x00000000)                                = 0x2000050C
sbrk(0x00000004)                                = 0x2000050C
sbrk(0x00010010)                                = 0x20000510
->librtl.a:func9_1(0x1)
->librtl.a:func9_3(0x1)
kioctl(1, 22528, 0x00000000, 0x00000000)        = 0
I am here in func9_3 with 1 !!
kwrite(1, 0xF01B5168, 24)                       = 24
<-librtl.a:func9_3() = 18               0.000000
->librtl.a:func9_3(0xb)
I am here in func9_3 with 11 !!
kwrite(1, 0xF01B5168, 25)                       = 25
<-librtl.a:func9_3() = 19               0.000000
<-librtl.a:func9_1() = 19               0.000000
->librtl.a:func9_3(0x2)
I am here in func9_3 with 2 !!
kwrite(1, 0xF01B5168, 24)                       = 24
<-librtl.a:func9_3() = 18               0.000000
->librtl.a:exit(0x0)
kfcntl(1, F_GETFL, 0x00000000)                  = 67110914
kfcntl(2, F_GETFL, 0xF01B5168)                  = 67110914
_exit(0)

As shown in the high-lighted lines, func9_3() called three times with an integer parameter, 1 (0x1), 11 (0xb), and 2 (0x2). Apparently, these values are passed by the parent function, func9_2(), as shown in Example 7-4 on page 265.

For further information about the truss command and its enhancements, please refer to the AIX 5L Differences Guide Version 5.2 Edition, SG24-5765 and the AIX 5L Version 5.2 Reference Documentation: Commands Reference.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset