Home | 简体中文 | 繁体中文 | 杂文 | Github | 知乎专栏 | 51CTO学院 | CSDN程序员研修院 | OSChina 博客 | 腾讯云社区 | 阿里云栖社区 | Facebook | Linkedin | Youtube | 打赏(Donations) | About
知乎专栏多维度架构

30.5. ltrace - A library call tracer

它的作用:库调用跟踪器。一个库可以包含数百个函数。在这几百个函数中,哪些是我们的二进制程序正在使用的实际函数?

ltrace 命令可以显示运行时从库中调用的所有函数。在下面的例子中,你可以看到被调用的函数名称,以及传递给该函数的参数。你也可以在输出的最右边看到这些函数返回的内容。

ltrace ls

		
neo@netkiller:~/workspace/Document$ ltrace ls
__libc_start_main(0x407bb0, 1, 0x7fff827aea38, 0x413730, 0x413720 <unfinished ...>
strrchr("ls", '/')                                                                                            = NULL
setlocale(6, "")                                                                                              = "en_US.UTF-8"
bindtextdomain("coreutils", "/usr/share/locale")                                                              = "/usr/share/locale"
textdomain("coreutils")                                                                                       = "coreutils"
__cxa_atexit(0x40abb0, 0, 0, 0x736c6974756572, 1)                                                             = 0
isatty(1)                                                                                                     = 1
getenv("QUOTING_STYLE")                                                                                       = NULL
getenv("LS_BLOCK_SIZE")                                                                                       = NULL
getenv("BLOCK_SIZE")                                                                                          = NULL
getenv("BLOCKSIZE")                                                                                           = NULL
getenv("POSIXLY_CORRECT")                                                                                     = NULL
getenv("BLOCK_SIZE")                                                                                          = NULL
getenv("COLUMNS")                                                                                             = NULL
ioctl(1, 21523, 0x7fff827ae910)                                                                               = 0
getenv("TABSIZE")                                                                                             = NULL
getopt_long(1, 0x7fff827aea38, "abcdfghiklmnopqrstuvw:xABCDFGHI:"..., 0x00416a60, -1)                         = -1
__errno_location()                                                                                            = 0x7f89323f16a8
malloc(40)                                                                                                    = 0x02543870
memcpy(0x02543870, "", 40)                                                                                    = 0x02543870
__errno_location()                                                                                            = 0x7f89323f16a8
malloc(40)                                                                                                    = 0x025438a0
memcpy(0x025438a0, "", 40)                                                                                    = 0x025438a0
malloc(18400)                                                                                                 = 0x025438d0
malloc(32)                                                                                                    = 0x025434c0
strlen(".")                                                                                                   = 1
malloc(2)                                                                                                     = 0x025480c0
memcpy(0x025480c0, ".", 2)                                                                                    = 0x025480c0
__errno_location()                                                                                            = 0x7f89323f16a8
opendir(".")                                                                                                  = 0x025480e0
readdir(0x025480e0)                                                                                           = 0x02548108
readdir(0x025480e0)                                                                                           = 0x02548120
readdir(0x025480e0)                                                                                           = 0x02548138
readdir(0x025480e0)                                                                                           = 0x02548150
strlen("Tex")                                                                                                 = 3
malloc(4)                                                                                                     = 0x02550110
memcpy(0x02550110, "Tex", 4)                                                                                  = 0x02550110
readdir(0x025480e0)                                                                                           = 0x02548168
readdir(0x025480e0)                                                                                           = 0x02548188
strlen("makedoc")                                                                                             = 7
malloc(8)                                                                                                     = 0x02550130
memcpy(0x02550130, "makedoc", 8)                                                                              = 0x02550130
readdir(0x025480e0)                                                                                           = 0x025481a8
readdir(0x025480e0)                                                                                           = 0x025481c8
strlen("Docbook")                                                                                             = 7
malloc(8)                                                                                                     = 0x02550150
memcpy(0x02550150, "Docbook", 8)                                                                              = 0x02550150
readdir(0x025480e0)                                                                                           = NULL
closedir(0x025480e0)                                                                                          = 0
free(NULL)                                                                                                    = <void>
malloc(72)                                                                                                    = 0x025480e0
_setjmp(0x61c040, 0x25480e0, 0x2543af8, 3, 1)                                                                 = 0
__errno_location()                                                                                            = 0x7f89323f16a8
strcoll("makedoc", "Docbook")                                                                                 = 9
__errno_location()                                                                                            = 0x7f89323f16a8
strcoll("Tex", "Docbook")                                                                                     = 16
__errno_location()                                                                                            = 0x7f89323f16a8
strcoll("Tex", "makedoc")                                                                                     = 7
memcpy(0x025480f0, "\3208T\002", 8)                                                                           = 0x025480f0
realloc(NULL, 144)                                                                                            = 0x02548130
malloc(168)                                                                                                   = 0x025481d0
__errno_location()                                                                                            = 0x7f89323f16a8
__ctype_get_mb_cur_max(0x7fff827ac0e0, 8192, 0x2550150, -1, 0)                                                = 6
__ctype_get_mb_cur_max(0x7fff827ac0e0, 8192, 0x2550150, 0x7fff827ac0e0, 0)                                    = 6
__errno_location()                                                                                            = 0x7f89323f16a8
__ctype_get_mb_cur_max(0x7fff827ac0e0, 8192, 0x2550130, -1, 0)                                                = 6
__ctype_get_mb_cur_max(0x7fff827ac0e0, 8192, 0x2550130, 0x7fff827ac0e0, 0)                                    = 6
__errno_location()                                                                                            = 0x7f89323f16a8
__ctype_get_mb_cur_max(0x7fff827ac0e0, 8192, 0x2550110, -1, 0)                                                = 6
__ctype_get_mb_cur_max(0x7fff827ac0e0, 8192, 0x2550110, 0x7fff827ac0e0, 0)                                    = 6
__errno_location()                                                                                            = 0x7f89323f16a8
__ctype_get_mb_cur_max(0x7fff827ac110, 8192, 0x2550150, -1, 0)                                                = 6
__ctype_get_mb_cur_max(0x7fff827ac110, 8192, 0x2550150, 0x7fff827ac110, 0)                                    = 6
__errno_location()                                                                                            = 0x7f89323f16a8
__ctype_get_mb_cur_max(0x7fff827ac050, 8192, 0x2550150, -1, 0)                                                = 6
__ctype_get_mb_cur_max(0x7fff827ac050, 8192, 0x2550150, 0x7fff827ac050, 0)                                    = 6
fwrite_unlocked("Docbook", 1, 7, 0x7f8931bab780)                                                              = 7
__overflow(0x7f8931bab780, 32, 0, 8, 0xffffffff)                                                              = 32
__overflow(0x7f8931bab780, 32, 1, 8, 0xffffffff)                                                              = 32
__errno_location()                                                                                            = 0x7f89323f16a8
__ctype_get_mb_cur_max(0x7fff827ac110, 8192, 0x2550130, -1, 0)                                                = 6
__ctype_get_mb_cur_max(0x7fff827ac110, 8192, 0x2550130, 0x7fff827ac110, 0)                                    = 6
__errno_location()                                                                                            = 0x7f89323f16a8
__ctype_get_mb_cur_max(0x7fff827ac050, 8192, 0x2550130, -1, 0)                                                = 6
__ctype_get_mb_cur_max(0x7fff827ac050, 8192, 0x2550130, 0x7fff827ac050, 0)                                    = 6
fwrite_unlocked("makedoc", 1, 7, 0x7f8931bab780)                                                              = 7
__overflow(0x7f8931bab780, 32, 1, 8, 7)                                                                       = 32
__overflow(0x7f8931bab780, 32, 2, 8, 7)                                                                       = 32
__errno_location()                                                                                            = 0x7f89323f16a8
__ctype_get_mb_cur_max(0x7fff827ac110, 8192, 0x2550110, -1, 0)                                                = 6
__ctype_get_mb_cur_max(0x7fff827ac110, 8192, 0x2550110, 0x7fff827ac110, 0)                                    = 6
__errno_location()                                                                                            = 0x7f89323f16a8
__ctype_get_mb_cur_max(0x7fff827ac050, 8192, 0x2550110, -1, 0)                                                = 6
__ctype_get_mb_cur_max(0x7fff827ac050, 8192, 0x2550110, 0x7fff827ac050, 0)                                    = 6
fwrite_unlocked("Tex", 1, 3, 0x7f8931bab780)                                                                  = 3
__overflow(0x7f8931bab780, 10, 0, 120, 3Docbook  makedoc  Tex
)                                                                     = 10
free(0x025480c0)                                                                                              = <void>
free(NULL)                                                                                                    = <void>
free(0x025434c0)                                                                                              = <void>
exit(0 <unfinished ...>
__fpending(0x7f8931bab780, 0, 0x7f8931bac330, 0x7f8931bac330, 0x25434b0)                                      = 0
fclose(0x7f8931bab780)                                                                                        = 0
__fpending(0x7f8931bab860, 0, 0x7f8931bacdf0, 0, 0x7f89323f17a0)                                              = 0
fclose(0x7f8931bab860)                                                                                        = 0
+++ exited (status 0) +++