LATRACE(1)
π LATRACE(1) β the latrace manual, but make it make sense π
ok so bestie, this is latrace, and it's a whole vibe. it's the LD_AUDIT 2.4+ libc frontend. let's get into it π¦
β¨ NAME β¨
latrace β LD_AUDIT 2.4+ libc frontend π«Ά
β¨ SYNOPSIS β¨
latrace [-snltfvhiBdISbcCyYLpoaNADVTFERq] command [arg ... ]
β¨ DESCRIPTION β¨
ok so the latrace tracer can run a command and show you its dynamic library calls, and it does this using the LD_AUDIT libc feature β which has been a thing since libc version 2.4 onward, so we're good. it can ALSO measure and display all kinds of statistics of dynamic calls. more deets in the section called βDISCUSSIONβ π
if you hand it the header file with functions' declarations, latrace will straight up display the function's arguments. the header file syntax is similar to the C language, with several exceptions β see the section called βHEADERSβ for all that.
by default, latrace does all its work fully inside of the traced program. BUT β there's another mode called "pipe mode" that moves the main work over to the tracer β that's the latrace binary itself. see the section called βPIPE modeβ for more.
and the latrace use is similar to strace(1) and ltrace(1). iykyk π
β¨ OPTIONS β¨
-l,--libslib1[,lib2,...] β audit from and to lib1, lib2 ...-t,--libs-tolib1[,lib2,...] β audit to lib1, lib2 ...-f,--libs-fromlib1[,lib2,...] β audit from lib1, lib2 ...-s,--symsym1[,sym2,...] β audit symbols sym1, sym2 ...-n,--sym-omitsym1[,sym2,...] β omit symbols sym1, sym2 ...-L,--lib-substs1[,s2,...] β objsearchLD_AUDITinterface (see the section called βOBJSEARCHβ)-c,--countsβ display statistics counts of symbols β implies pipe mode (see the section called βPIPE modeβ) an no symbol output is displayed-C,--sort-countsstat β implies-c, plus sort the statistics by stat with following values:time,per,call,ucall,lib,sym(default iscall)-p,--pipeβ use pipe to latrace process to send audit data (see the section called βPIPE modeβ)-N,--confβ config file (see the section called βCONFIGβ)-A,--enable-argsβ enable arguments output (definitions from/etc/latrace.conf)-D,--detail-argsβ display struct arguments in more detail-a,--argsfile β specify arguments definition file, implies-A(without the default definition file of course)-y,--framesizenumber β framesize for storing the stack beforepltexit(default100)-Y,--no-framesize-checkβ disable framesize check-F,--no-follow-forkβ dont follow fork calls (childs). this is just supressing the latrace output from new childs. the nature of theLD_AUDITfeature prevents to disable it completely. β οΈ-E,--no-follow-execβ dont follow exec calls-S,--timestampβ display timestamp for each symbol-b,--flow-belowsym1[,sym2,...] β display flow for sym1, sym2 ...-I,--no-indent-symβ do no indent symbols based on the their stack depth-i,--indent-symindent_size β indent size specification in indent_size-B,--bracesβ allways display{ }for the around the symbol body-d,--demangleβ C++ demangle symbols on the output-T,--hide-tidβ dont display thread id-o,--outputfile β store output to file-R,--ctl-configβ controled config feature-q,--disableβ run with disabled auditing-v,--verboseβ verbose output-V,--versionβ display version-h,--helpβ display help
β¨ EXAMPLES β¨
- The simplest way to run latrace is like this:
latrace cat
- To see the argument values specified by default config file run:
latrace -A cat
- Same as above but using the pipe mode to get all the end symbols printed:
latrace -Ap cat
- To see the argument values specified by specified config file run:
latrace -a latrace.conf cat
- To get output only for specified symbol (eg. read and write) run:
latrace -A -s read,write cat
- To get flow under the specified symbol (eg. sysconf) run:
latrace -b sysconf kill
- To get output only for specified library (eg. libproc) run:
latrace -Al libproc w
- To get symbol statistics run:
latrace -c ls
- To get symbol statistics sorted by time run:
latrace -C time ls
- To get output stored to the text file run:
latrace -o output.latrace ls
- To change the
libkrava1.sodependency to thelibkrava2.sorun one of these:
latrace -L krava1%krava2 ex
latrace -L krava1~libkrava2.so ex
latrace -L libkrava1.so=libkrava2.so ex
πΈ that's part 1 bestie, more parts incoming, don't go anywhere πΈ
π¬ DISCUSSION π¬
π NAMES CHECK π
ok so for these options β -l, -t, -f, -s, -n, -b β you can drop a * in there and it flips over to substring search. no *? then it's a straight-up exact match on the name, no vibes, no wiggle room. π
Examples, bestie, look:
-s "*krava" checks for symbols with "krava" substring.
-s "krava" checks only for "krava" symbol
π§ LD_AUDIT π§
so this is just a lil brief-and-vague rundown of the LD_AUDIT situation, ok? for the real tea go read rtld-audit(7), that man page was done by Petr Baudis, or go study the glibc/latrace source code yourself. anyway, super brief explanation incoming. π
The libc dynamic linker audit feature lets you trace/audit a program's symbols and libraries. You switch it on with the LD_AUDIT environment variable. That variable has to hold the path to the audit shared library. This audit library has to follow a specific interface β the interface functions get called by the dynamic linker at the appropriate moments.
The audit library needs to export these symbols (and heads up, the "la_PLTENTER" and "la_PLTEXIT" names are architecture dependent, iykyk):
"la_activity"
"la_objsearch"
"la_objopen"
"la_preinit"
"la_symbind32"
"la_symbind64"
"la_PLTENTER"
"la_PLTEXIT"
"la_objclose"
And for the latrace package specifically, that audit shared library is called libltaudit.so. π¦
π OBJSEARCH π
The objsearch LD_AUDIT interface gives you the means to change the traced program's shared object names and locations. The -L option argument should look like this:
-L s1[,s2,...] where sN is src [=%~] dst
Where src is the source pattern/name and dst is the destination name/pattern. Now the three flavours of matching, periodt:
=β comparessrcwith the library name. If matched, it replaces the library name withdst.
library name - /lib/krava1.so
src - /lib/krava1.so
dst - /lib/krava2.so
final library name - /lib/krava2.so
%β looks for thesrcin the library name. If found, it replaces thesrcwith thedstpart.
library name - /lib/krava1.so
src - krava1
dst - krava2
final library name - /lib/krava2.so
~β looks for thesrcin the library name. If found, it replaces the library name withdst.
library name - /lib/krava1.so
src - krava1
dst - /lib/krava2.so
final library name - /lib/krava2.so
π° PIPE mode π°
latrace can work in two modes, bestie. The first one, native, does the output directly in the traced program process. The other one, pipe mode</>, uses the IPC fifo mechanism to send the data from the traced process over to the latrace process. Then the latrace process is the one responsible for the output. Heads up though: using pipe mode means you lose the traced program standard output context with the printed symbols. π
By using pipe mode, latrace isn't dependent on the trace program's usage/manipulation of the standard output descriptor. Also, the symbol statistics counts β that's the -c and -C options β use pipe mode to transfer symbol information to the latrace binary, and then the latrace binary does the counts at the end.
βοΈ CONFIG βοΈ
latrace lets you enable/disable some of the options through a configuration file. Some options are linked to the command line arguments, some of them are not. When latrace starts, the global configuration file gets read. This file is usually placed right here:
/etc/latrace.d/latrace.conf
Once the default values are read from this file, you can overload any of them with command line options, or by supplying another config file via the -N, --conf option. πΈ
The configuration file syntax is roughly:
INCLUDE <anotherconfigfile>
OPTIONS {
OPTION1 = VALUE
OPTION2 = YES|NO
...
OPTIONN = VALUE
}
# comment
π Configuration file options π
HEADERS = FILEβ-a,--argsINDENT_SYM = VALUEβ-i,--indent-symPIPE = BOOLβ-p,--pipeTIMESTAMP = BOOLβ-S,--timestampFRAMESIZE = VALUEβ-y,--framesizeFRAMESIZE_CHECK = BOOLβ-Y,--no-framesize-checkHIDE_TID = BOOLβ-T,--hide-tidFOLLOW_FORK = BOOLβ-F,--no-follow-forkFOLLOW_EXEC = BOOLβ-E,--no-follow-execDEMANGLE = BOOLβ-d,--demangleBRACES = BOOLβ-B,--bracesENABLE_ARGS = BOOLβ-A,--enable-argsDETAIL_ARGS = BOOLβ-D,--detail-argsOUTPUT_TTY = FILE- stores tracee terminal output to the file
LIBS = LIB1[,LIB2,...]β-l,--libsLIBS_TO = LIB1[,LIB2,...]β-t,--libs-toLIBS_FROM = LIB1[,LIB2,...]β-f,--libs-fromSYM = SYM1[,SYM2,...]β-s,--symSYM_OMIT = SYM1[,SYM2,...]β-n,--sym-omitSYM_BELOW = SYM1[,SYM2,...]β-b,--flow-belowSYM_NOEXIT = SYM1[,SYM2,...]- symbols which do no run exit callback (plt_exit)
ARGS_STRING_POINTER_LENGTH = BOOL- function arguments - display string length and pointer value
π HEADERS π
The latrace header file lets you define symbols as classic C functions with arguments. Argument names get displayed together with values in the latrace output. And real talk: the more arguments you define, the more performance and memory penalties you should expect. no cap.
The package ships with several predefined header files for the most commonly used functions. Here's the list of glibc header files used (this list mostly follows the ltrace header files list, and the author is willing to update it according to needs):
ctype.h dirent.h dlfcn.h fcntl.h getopt.h inet.h ioctl.h
libintl.h libio.h locale.h misc.h mman.h ncurses.h netdb.h
pthread.h pwd.h resource.h signal.h socket.h stat.h stdio.h
stdlib.h string.h syslog.h term.h termios.h time.h typedefs.h
unistd.h utmp.h wait.h
The latrace header files are usually stored under this directory:
/etc/latrace.d/headers/
You can specify a single header file using a command line option or the configuration file. That file can then include other needed headers. And like we already said, the latrace config file syntax lightly follows the C language syntax. The next bit describes the latrace config file language. β¨
- Several POD types (plain old data) are hardcoded in latrace. The size of those arguments is determined by the
sizeofmacro. List follows.
void
char u_char
short u_short
int u_int
long u_long
llong u_llong # (long long)
float double
- The
typedefkeyword lets you specify a new type based on an already existing one (POD or typedefed). Eventhough there's a way for multiple pointer layers in the type definition (*), only one is taken.
typedef base_type new_type;
typedef base_type * new_type;
typedef base_type ** new_type;
- Comments follow the C style
/* */logic.
/* comments */
- The
includekeyword lets you include another config file.
#include "filename"
- The
structkeyword lets you define the structure. The syntax folows following grammar rules.
START:: struct NAME { STRUCT_DEF };
STRUCT_DEF:: DEF | EMPTY
DEF:: NAME NAME |
NAME '*' NAME |
struct NAME NAME |
struct NAME '*' NAME
NAME:: [-0-9a-zA-Z_]+
- The function definition follows following syntax (
DEFandNAMEare the same as for struct definition).
START:: DEF '(' ARGS ')' ';'
ARGS:: ARGS ',' DEF | DEF | EMPTY
- The
enumdefinition follows following syntax (NAMEis same as for struct definition).
START:: ENUM NAME '{' ENUM_DEF '}' ';'
ENUM_DEF:: ENUM_DEF ',' ENUM_ELEM | ENUM_ELEM
ENUM_ELEM:: NAME '=' NAME | NAME
- Example of a simple latrace config file.
---[ cut here ]-----------------------------
enum krava {
krava1 = 1,
krava2,
krava3 = 100
};
#include "krava.conf"
typedef u_int pid_t;
struct ex_st {
pid_t p;
int cnt;
char *name;
};
int f1(pid_t p, struct ex_st *k);
int f2(char* name, struct ex_st k, int k = krava);
struct ex_st* f3(pid_t *p, struct ex_st k);
---[ cut here ]-----------------------------
- > Arrays are not supported yet, so there's no way to define some structures. For such structures use
void*type where the structure argument is passed by pointer. If it is passed by value, there's no workaround so far (aside from filling the structure body with POD types up to the actual length of the structure :). π - > Variable argument lists (
va_list/...) are not supported yet. The function definition needs to stop before the first variable argument list argument.
π οΈ PORTS π οΈ
latrace should work on any glibc system with LD_AUDIT support. However, argument details are architecture specific and need special support inside latrace itself.
The author is willing to port latrace to any architecture, as long as he gets access to the corresponding system. Currently functional ports are:
x86β ok βx86_64β ok βarmβ ok β
π BUGS π
MANY, plz report bugs to latrace@lists.fedorahosted.org or olsajiri@gmail.com.
You can also visit the http://people.redhat.com/jolsa/latrace/ page to see the latest release notes information.
LD_AUDIT related glibc bugs:
- Bug 7055 (no longer reproducible)
- Bug 9893 (FIXED in 2.10)
- Bug 3924 (FIXED in 2.7-2)
π AUTHOR π
Jiri Olsa olsajiri@gmail.com
π«Ά CONTRIBUTORS π«Ά
- Nix
nix@esperi.org.uk - Akos Pasztory
akos.pasztory@gmail.com - Artur Skawina
art.08.09@gmail.com - Dr. David Alan Gilbert
david.gilbert@linaro.org - Sebastian Pipping
sping@gentoo.org
π LICENSE π
This is free software, distributed under the GPLv3 license.
π SEE ALSO π
π AUTHOR π
Jiri Olsa olsajiri@gmail.com
- Author.
π NOTES π
okay bestie, these are the little footnote linkies that got referenced all over the place up above π« here they are, every single one, nothing skipped, no cap:
1.βlatrace@lists.fedorahosted.orgπ©· β link target:mailto:latrace@lists.fedorahosted.org2.βolsajiri@gmail.comβ¨ β link target:mailto:olsajiri@gmail.com3.βnix@esperi.org.ukπ¦ β link target:mailto:nix@esperi.org.uk4.βakos.pasztory@gmail.comπΈ β link target:mailto:akos.pasztory@gmail.com5.βart.08.09@gmail.comπ β link target:mailto:art.08.09@gmail.com6.βdavid.gilbert@linaro.orgπ β link target:mailto:david.gilbert@linaro.org7.βsping@gentoo.orgβ β link target:mailto:sping@gentoo.org
and that's the whole entire page, bestie π you made it to the very end, I'm so proud of you fr fr π
little footer moment for the road: this manual page is latrace 0.5.11, dated October 2011, and it's filed under LATRACE(1). iconic. periodt. π
β¨π¦
π¦ where this page comes from
- ubuntu jammy: latrace 0.5.11-1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms