1. 程式人生 > >ltrace 除錯

ltrace 除錯

轉自 http://hi.baidu.com/yuanhuiyong/item/eba859d111e6e28f6dce3fea

說明:本文件簡要描述了ltrace的命令,在文末有本命令的基本應用。

ltrace - A library call tracer
Trace library calls of a given program.

1。 -a, --align=COLUMN align return values in a secific column.
對齊具體某個列的返回值

2。 -c                  count time and calls, and report a summary on exit.
計算時間和呼叫,並在程式退出時列印摘要

3。 -C, --demangle      decode low-level symbol names into user-level names.
解碼低級別名稱(核心級)為使用者級名稱

4。 -d, --debug         print debugging info.
列印除錯資訊

5。 -e expr             modify which events to trace.
改變跟蹤的事件

6。 -f                  follow forks.
跟蹤子程序

7。 -h, --help          display this help and exit.
列印幫助資訊

8。 -i                  print instruction pointer at time of library call.
列印指令指標,當庫呼叫時

9。 -l, --library=FILE print library calls from this library only.
只打印某個庫中的呼叫

10。 -L                  do NOT display library calls.
不列印庫呼叫(注,不列印庫呼叫資訊,咱要你做什麼呀)

11。 -n, --indent=NR     indent output by NR spaces for each call level nesting.
對每個呼叫級別巢狀以NR個空格進行縮排輸出

12。 -o, --output=FILE   write the trace output to that file.
把輸出定向到檔案

13。 -p PID              attach to the process with the process ID pid.
附著在值為PID的程序號上進行ltrace

14。 -r                  print relative timestamps.
列印相對時間戳

15。 -s STRLEN           specify the maximum string size to print.
設定列印的字串最大長度

16。 -S                  display system calls.
顯示系統呼叫

17。 -t, -tt, -ttt       print absolute timestamps.
列印絕對時間戳

18。 -T                  show the time spent inside each call.
輸出每個呼叫過程的時間開銷

19。 -u USERNAME         run command with the userid, groupid of username.
使用某個使用者ID或組ID來執行命令

20。 -V, --version       output version information and exit.
列印版本資訊,然後退出

21。 -x NAME             treat the global NAME like a library subroutine.
----- 不好意思,這句話還真不知怎麼翻譯好 --------

#########################################################################################
下面是常見的幾種應用場景

1。最基本應用,不帶任何引數
[[email protected] tmp]$ ltrace ./a.out
__libc_start_main(0x80484aa, 1, 0xbfc07744, 0x8048550, 0x8048540 <unfinished ...>
printf("no1:%d \t no2:%d \t diff:%d\n", 10, 6, 4no1:10   no2:6   diff:4 ) = 24
printf("no1:%d \t no2:%d \t diff:%d\n", 9, 7, 2no1:9     no2:7   diff:2 ) = 23
printf("no1:%d \t no2:%d \t diff:%d\n", 8, 8, 0no1:8     no2:8   diff:0 ) = 23
--- SIGFPE (Floating point exception) ---
+++ killed by SIGFPE +++

2。輸出呼叫時間開銷
[[email protected] tmp]$ ltrace -T ./a.out
__libc_start_main(0x80484aa, 1, 0xbf81d394, 0x8048550, 0x8048540 <unfinished ...>
printf("no1:%d \t no2:%d \t diff:%d\n", 10, 6, 4no1:10   no2:6   diff:4 ) = 24 <0.000972>
printf("no1:%d \t no2:%d \t diff:%d\n", 9, 7, 2no1:9     no2:7   diff:2 ) = 23 <0.000155>
printf("no1:%d \t no2:%d \t diff:%d\n", 8, 8, 0no1:8     no2:8   diff:0 ) = 23 <0.000153>
--- SIGFPE (Floating point exception) ---
+++ killed by SIGFPE +++

3。顯示系統呼叫
[[email protected] tmp]$ ltrace -S ./a.out
SYS_brk(NULL)                                                                = 0x9e20000
SYS_access(0xa4710f, 4, 0xa4afc0, 0, 0xa4b644)                               = 0
SYS_open("/etc/ld.so.preload", 0, 02)                                        = 3
SYS_fstat64(3, 0xbfbd7a94, 0xa4afc0, -1, 3)                                  = 0
SYS_mmap2(0, 17, 3, 2, 3)                                                    = 0xb7f2a000
SYS_close(3)                                                                 = 0
SYS_open("/lib/libcwait.so", 0, 00)                                          = 3
SYS_read(3, "\177ELF\001\001\001", 512)                                      = 512
SYS_fstat64(3, 0xbfbd76fc, 0xa4afc0, 4, 0xa4b658)                            = 0
SYS_mmap2(0, 4096, 3, 34, -1)                                                = 0xb7f29000
SYS_mmap2(0, 5544, 5, 2050, 3)                                               = 0x423000
SYS_mmap2(0x424000, 4096, 3, 2066, 3)                                        = 0x424000
.............省去若干行