Tests: dynamically create test list based on enabled features
[babeltrace.git] / doc / debuginfo.txt
CommitLineData
34a4aed0
AB
1Babeltrace Debug Info Analysis
2-----------------------------
3
4The babeltrace debug info analysis is a set of features which allow
5mapping events from a trace to their location in source code or within
6a binary file, based on their `ip` (instruction pointer) field.
7
8Prerequisites
9-------------
10
11In order to install a version of babeltrace with debug info support,
12the following libraries are required:
13
14 * libelf
15 * libdw
16
17Both of them are provided by the elfutils project
18(https://fedorahosted.org/elfutils/), and can be installed through the
19elfutils package on Ubuntu, Debian, RHEL, and others.
20
21Compiling for Debug Info Analysis
22---------------------------------
23
24Traced programs on which debug info analysis is to be performed can be
25compiled in a few different ways, and still lead to useful results.
26
27Ideally, one should compile the program in debug mode, which is
28achieved on gcc by simply using the `-g` flag. This generates debug
29information in the operating system's native format, which is then
30used by babeltrace to map an event's source location to a file and
31line number, and the name of the surrounding function.
32
33Do note that only debug information in DWARF format, version 2 or
34later, is currently supported by babeltrace. Use the `-gdwarf` or
35`-gdwarf-(VERSION)` to explicitly generate DWARF debug information.
36
37If the executable is not compiled with `-g` or an equivalent option
38enabled, and thus no DWARF information is available, babeltrace will
39use ELF symbols from the executable. Instead of providing source file,
40line number and function name, however, the analysis will provide the
41name of the nearest function symbol, plus an offset in bytes to the
42location in the executable from which the event originated.
43
44If the executable has neither ELF symbols nor DWARF information,
45babeltrace will be unable to map an event to its source location and
46will simply display the instruction pointer (address), as in prior
47versions of babeltrace.
48
49Getting the Right Tracer
50------------------------
51
52Debug info analysis is performed automatically by babeltrace, provided
53the trace contains sufficient information. In order to be able to
54trace all the necessary information, the following software is
55required:
56
57 * lttng-ust version 2.8.0 or later
58 * lttng-tools, corresponding version
59
60You can get these from source at:
61
62 * https://github.com/lttng/lttng-ust
63 * https://github.com/lttng/lttng-tools
64
65Ubuntu users also have the option of installing via the LTTng daily
66PPA:
67
68 * https://launchpad.net/~lttng/+archive/ubuntu/daily
69
70Tracing for Debug Info Analysis
71-------------------------------
72
73Babeltrace needs some extra information from contexts, namely ip and
74vpid, to perform its analysis. These can be enabled after the creation
75of a tracing session as follows:
76
77 $ lttng add-context --userspace --type ip --type vpid
78
79The tracing can then be performed as it normally would. Once the trace
80is collected, it can the be read by babeltrace for analysis.
81
82Analysing the Trace
83-------------------
84
85To perform the analysis, the trace can simply be read as it normally
86would:
87
88 $ babeltrace <path/to/trace>
89
90Debug info analysis is on by default and will automatically print the
91extra source location information if it can find it. A sample output
92may look like this:
93
94 [...]
95 [19:53:41.648394410] (+0.000022616) colossus my_provider:my_first_tracepoint: { cpu_id = 2 }, { ip = 0x7F75AEDFB4D4, debug_info = { func = "foo", source_loc = "/home/efficios/example/libhello.c:7" }, vpid = 25577 }, { my_string_field = "hello, tracer", my_integer_field = 42 }
96 [19:53:41.648423786] (+0.000029376) colossus my_provider:my_first_tracepoint: { cpu_id = 2 }, { ip = 0x7F75AEDFB5A6, debug_info = { func = "bar", source_loc = "/home/efficios/example/libhello.c:13" }, vpid = 25577 }, { my_string_field = "recoltes et semailles", my_integer_field = 57 }
97 [19:53:41.648435726] (+0.000011940) colossus my_provider:my_other_tracepoint: { cpu_id = 2 }, { ip = 0x7F75AEDFB66B, debug_info = { func = "baz", source_loc = "/home/efficios/example/libhello.c:20" }, vpid = 25577 }, { some_field = 1729 }
98 [...]
99
100The interesting part is the debug_info section of the context:
101
102 debug_info = { func = "foo", source_loc = "/home/efficios/example/libhello.c:7" }
103
104This is the expected output for events generated by an executable for
105which DWARF information is available. It shows the name of the
106function containing the tracepoint instance which generated the event
107("foo"), and its source location ("libhello.c", line 7).
108
109The second event in the sample output is of the same type
110("my_first_tracepoint"), but it was generated by a different
111tracepoint instance, hence the different source location (line 13) and
112function ("bar").
113
114The third event, of a different type, also shows debug information.
115
116If DWARF info is absent, but ELF symbols are not stripped, the output
117will instead look like this:
118
119 [...]
120 [19:53:41.648394410] (+0.000022616) colossus my_provider:my_first_tracepoint: { cpu_id = 2 }, { ip = 0x7F75AEDFB4D4, debug_info = { func = "foo+0xa9" }, vpid = 25577 }, { my_string_field = "hello, tracer", my_integer_field = 42 }
121 [19:53:41.648423786] (+0.000029376) colossus my_provider:my_first_tracepoint: { cpu_id = 2 }, { ip = 0x7F75AEDFB5A6, debug_info = { func = "bar+0xa9" }, vpid = 25577 }, { my_string_field = "recoltes et semailles", my_integer_field = 57 }
122 [19:53:41.648435726] (+0.000011940) colossus my_provider:my_other_tracepoint: { cpu_id = 2 }, { ip = 0x7F75AEDFB66B, debug_info = { func = "baz+0x9c" }, vpid = 25577 }, { some_field = 1729 }
123 [...]
124
125The debug information now provides only the function name as given by
126ELF symbols, plus an offset in bytes from the symbol to the actual
127location of the tracepoint instance.
128
129Debug Info and Dynamic Loading
130------------------------------
131
132Babeltrace can resolve addresses of events originating from
133dynamically loaded libraries, provided that some extra information is
134collected at tracing time.
135
136This can be achieved by preloading LTTng UST's libdl helper when
137launching the program to be traced, like so:
138
139 $ LD_PRELOAD="liblttng-ust-dl.so" <path/to/executable>
140
141The tracing and analysis can now be performed as described in prior
142sections, and events from tracepoints in dlopened libraries will be
143resolved automatically by babeltrace.
144
145Separate Debug Info
146-------------------
147
148It is possible to store DWARF debug information separate from an
149executable, whether for concerns of file size, or simply to facilitate
150the sharing of the debug information.
151
152This is usually achieved via one of two mechanisms, namely build ID
153and debug link. Both methods permit separate executables and debug
154information. Their use and operation is described in GDB's
155documentation at:
156
157 https://sourceware.org/gdb/onlinedocs/gdb/Separate-Debug-Files.html
158
159Babeltrace will find separate debug files automatically, provided they
160follow the requirements described in the documentation above. The
161debug information lookup order is the same as GDB's, that is first
162debug info is looked for within the executable, then through the build
163ID method in the standard /usr/lib/debug/.build-id/ location, and
164finally in the various possible debug link locations. The first debug
165information file found is used.
166
167Debug Info Directory
168--------------------
169
170When performing debug info analysis, babeltrace uses an executable's
171path from when it was traced to resolve debug information. If,
172however, the trace was taken on a different machine, or the executable
173was simply moved since the trace was taken, it is possible to override
174the base path from which to look for the debug information. To do so,
175the --debug-info-dir babeltrace command-line flag is available.
176
177If a --debug-info-dir value is given, it will replace the default
178/usr/lib/debug path used in build ID and debug link lookups.
179
180Note that multiple debug directories are not currently supported.
This page took 0.028192 seconds and 4 git commands to generate.