1 #ifndef _BABELTRACE_SO_INFO_H
2 #define _BABELTRACE_SO_INFO_H
5 * Babeltrace - Executable and Shared Object Debug Info Reader
7 * Copyright 2015 Antoine Busque <abusque@efficios.com>
9 * Author: Antoine Busque <abusque@efficios.com>
11 * Permission is hereby granted, free of charge, to any person obtaining a copy
12 * of this software and associated documentation files (the "Software"), to deal
13 * in the Software without restriction, including without limitation the rights
14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 * copies of the Software, and to permit persons to whom the Software is
16 * furnished to do so, subject to the following conditions:
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33 #include <elfutils/libdw.h>
34 #include <babeltrace/babeltrace-internal.h>
36 #define DEFAULT_DEBUG_DIR "/usr/lib/debug"
37 #define DEBUG_SUBDIR ".debug/"
38 #define BUILD_ID_SUBDIR ".build-id/"
39 #define BUILD_ID_SUFFIX ".debug"
42 /* Base virtual memory address. */
44 /* Upper bound of exec address space. */
46 /* Size of exec address space. */
48 /* Paths to ELF and DWARF files. */
51 /* libelf and libdw objects representing the files. */
54 /* Optional build ID info. */
57 /* Optional debug link info. */
58 char *dbg_link_filename
;
59 uint32_t dbg_link_crc
;
60 /* FDs to ELF and DWARF files. */
63 /* Denotes whether the executable is position independent code. */
65 /* Denotes whether the SO only has ELF symbols and no DWARF info. */
69 struct source_location
{
75 * Initializes the so_info framework. Call this before calling
78 * @returns 0 on success, -1 on failure
81 int so_info_init(void);
84 * Instantiate a structure representing an ELF executable, possibly
85 * with DWARF info, located at the given path.
87 * @param path Path to the ELF file
88 * @param low_addr Base address of the executable
89 * @param memsz In-memory size of the executable
90 * @param is_pic Whether the executable is position independent
92 * @returns Pointer to the new so_info on success,
96 struct so_info
*so_info_create(const char *path
, uint64_t low_addr
,
97 uint64_t memsz
, bool is_pic
);
100 * Destroy the given so_info instance
102 * @param so so_info instance to destroy
105 void so_info_destroy(struct so_info
*so
);
108 * Sets the build ID information for a given so_info instance.
110 * @param so The so_info instance for which to set
112 * @param build_id Array of bytes containing the actual ID
113 * @param build_id_len Length in bytes of the build_id
114 * @returns 0 on success, -1 on failure
117 int so_info_set_build_id(struct so_info
*so
, uint8_t *build_id
,
118 size_t build_id_len
);
121 * Sets the debug link information for a given so_info instance.
123 * @param so The so_info instance for which to set
125 * @param filename Name of the separate debug info file
126 * @param crc Checksum for the debug info file
127 * @returns 0 on success, -1 on failure
130 int so_info_set_debug_link(struct so_info
*so
, char *filename
, uint32_t crc
);
133 * Returns whether or not the given SO info \p so contains the address
136 * @param so so_info instance
137 * @param addr Address to lookup
138 * @returns 1 if \p so contains \p addr, 0 if it does not,
142 int so_info_has_address(struct so_info
*so
, uint64_t addr
)
148 return addr
>= so
->low_addr
&& addr
< so
->high_addr
;
152 * Get the name of the function containing a given address within an
155 * If no DWARF info is available, the function falls back to ELF
156 * symbols and the "function name" is in fact the name of the closest
157 * symbol, followed by the offset between the symbol and the address.
159 * On success, if found, the out parameter `func_name` is set. The ownership
160 * of `func_name` is passed to the caller. On failure, `func_name` remains
163 * @param so so_info instance for the executable containing
165 * @param addr Virtual memory address for which to find the
167 * @param func_name Out parameter, the function name.
168 * @returns 0 on success, -1 on failure
171 int so_info_lookup_function_name(struct so_info
*so
, uint64_t addr
,
175 * Get the source location (file name and line number) for a given
176 * address within an executable.
178 * If no DWARF info is available, the source location cannot be found
179 * and the function will return unsuccesfully.
181 * On success, if found, the out parameter `src_loc` is set. The ownership
182 * of `src_loc` is passed to the caller. On failure, `src_loc` remains
185 * @param so so_info instance for the executable containing
187 * @param addr Virtual memory address for which to find the
189 * @param src_loc Out parameter, the source location
190 * @returns 0 on success, -1 on failure
193 int so_info_lookup_source_location(struct so_info
*so
, uint64_t addr
,
194 struct source_location
**src_loc
);
196 * Get a string representing the location within the binary of a given
199 * In the case of a PIC binary, the location is relative (+0x1234).
200 * For a non-PIC binary, the location is absolute (@0x1234)
202 * On success, the out parameter `bin_loc` is set. The ownership is
203 * passed to the caller. On failure, `bin_loc` remains unchanged.
205 * @param so so_info instance for the executable containing
207 * @param addr Virtual memory address for which to find the
209 * @param bin_loc Out parameter, the binary location
210 * @returns 0 on success, -1 on failure
213 int so_info_get_bin_loc(struct so_info
*so
, uint64_t addr
, char **bin_loc
);
216 * Destroy the given source_location instance
218 * @param src_loc source_location instance to destroy
221 void source_location_destroy(struct source_location
*src_loc
);
223 #endif /* _BABELTRACE_SO_INFO_H */
This page took 0.035833 seconds and 4 git commands to generate.