A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
-bash/zsh: ltrace command not not found # Windows (WSL2) sudo apt-get update sudo apt-get install ltrace # Debian apt-get install ltrace # Ubuntu apt-get install ltrace # Alpine apk add ltrace # Arch Linux pacman -S ltrace # Kali Linux apt-get install ltrace # CentOS yum install ltrace # Fedora dnf install ltrace # Raspbian apt-get install ltrace # Docker docker run cmd.cat/ltrace ltrace
ltrace 是一个程序,它会运行指定的命令直到程序退出。
ltrace 会拦截并记录正在执行的进程调用的动态库函数以及该进程接收到的信号。
ltrace 还可以拦截并打印程序执行的系统调用。
ltrace [-e filter|-L] [-l|--library=library_pattern] [-x filter] [-S]
[-b|--no-signals] [-i] [-w|--where=nr] [-r|-t|-tt|-ttt] [-T]
[[-F|--config] pathlist] [-A maxelts] [-s strsize] [-C|--demangle]
[-a|--align column] [-n|--indent nr] [-o|--output filename] [-D|--debug
mask] [-u username] [-f] [-p pid] [[--] command [arg ...]]
ltrace -c [-e filter|-L] [-l|--library=library_pattern] [-x filter] [-S]
[-o|--output filename] [-f] [-p pid] [[--] command [arg ...]]
ltrace -V|--version
ltrace -h|--help
-a, --align column
Align return values in a specific column (default column is 5/8 of
screen width).
-A maxelts
Maximum number of array elements to print before suppressing the
rest with an ellipsis ("..."). This also limits number of
recursive structure expansions.
-b, --no-signals
Disable printing of signals received by the traced process.
-c Count time and calls for each library call and report a summary on
program exit.
-C, --demangle
Decode (demangle) low-level symbol names into user-level names.
Besides removing any initial underscore prefix used by the system,
this makes C++ function names readable.
-D, --debug mask
Show debugging output of ltrace itself. mask is a number
describing which debug messages should be displayed. Use the
option -Dh to see what can be used, but note that currently the
only reliable debugmask is 77, which shows all debug messages.
-e filter
A qualifying expression which modifies which library calls (i.e.
calls done through PLT slots, which are typically calls from the
main binary to a library, or inter-library calls) to trace. Usage
examples and the syntax description appear below in sections
FILTER SPECIFICATIONS and FILTER EXPRESSIONS. If more than one -e
option appears on the command line, the library calls that match
any of them are traced. If no -e is given, @MAIN is assumed as a
default.
-f Trace child processes as they are created by currently traced
processes as a result of the fork(2) or clone(2) system calls.
The new process is attached immediately.
-F, --config pathlist
Contains a colon-separated list of paths. If a path refers to a
directory, that directory is considered when prototype libraries
are searched (see the section PROTOTYPE LIBRARY DISCOVERY). If it
refers to a file, that file is imported implicitly to all loaded
prototype libraries.
-h, --help
Show a summary of the options to ltrace and exit.
-i Print the instruction pointer at the time of the library call.
-l, --library library_pattern
Display only calls to functions implemented by libraries that
match library_pattern. This is as if you specified one -e for
every symbol implemented in a library specified by
library_pattern. Multiple library patters can be specified with
several instances of this option. Usage examples and the syntax
description of library_pattern appear below in sections FILTER
SPECIFICATIONS and FILTER EXPRESSIONS.
Note that while this option selects calls that might be directed
to the selected libraries, there's no actual guarantee that the
call won't be directed elsewhere due to e.g. LD_PRELOAD or simply
dependency ordering. If you want to make sure that symbols in
given library are actually called, use -x @library_pattern
instead.
-L When no -e option is given, don't assume the default action of
@MAIN. In practice this means that library calls will not be
traced.
-n, --indent nr
Indent trace output by nr spaces for each level of call nesting.
Using this option makes the program flow visualization easy to
follow. This indents uselessly also functions that never return,
such as service functions for throwing exceptions in the C++
runtime.
-o, --output filename
Write the trace output to the file filename rather than to stderr.
-p pid Attach to the process with the process ID pid and begin tracing.
This option can be used together with passing a command to
execute. It is possible to attach to several processes by passing
more than one option -p.
-r Print a relative timestamp with each line of the trace. This
records the time difference between the beginning of successive
lines.
-s strsize
Specify the maximum string size to print (the default is 32).
-S Display system calls as well as library calls
-t Prefix each line of the trace with the time of day.
-tt If given twice, the time printed will include the microseconds.
-ttt If given thrice, the time printed will include the microseconds
and the leading portion will be printed as the number of seconds
since the epoch.
-T Show the time spent inside each call. This records the time
difference between the beginning and the end of each call.
-u username
Run command with the userid, groupid and supplementary groups of
username. This option is only useful when running as root and
enables the correct execution of setuid and/or setgid binaries.
-w, --where nr
Show backtrace of nr stack frames for each traced function. This
option enabled only if elfutils or libunwind support was enabled
at compile time.
-x filter
A qualifying expression which modifies which symbol table entry
points to trace (those are typically calls inside a library or
main binary, though PLT calls, traced by -e, land on entry points
as well). Usage examples and the syntax description appear below
in sections FILTER SPECIFICATIONS and FILTER EXPRESSIONS. If more
than one -x option appears on the command line, the symbols that
match any of them are traced. No entry points are traced if no -x
is given.
-V, --version
Show the version number of ltrace and exit.
/etc/ltrace.conf System configuration file ˜/.ltrace.conf Personal config file, overrides /etc/ltrace.conf
ltrace 打印(跟踪)程序二进制文件的库调用:
ltrace ./program
ltrace 统计库的调用次数。在底部打印一份简明摘要:
ltrace -c path/to/program
ltrace 跟踪对 malloc 和 free 的调用,忽略 libc 执行的调用:
ltrace -e malloc+free-@libc.so* path/to/program
ltrace 写入文件而不是终端:
ltrace -o file path/to/program