From dae52e7673333cf41828c8686158948ce93ef104 Mon Sep 17 00:00:00 2001 From: Antoine Busque Date: Thu, 21 Apr 2016 01:55:10 -0400 Subject: [PATCH] Rename so-info to bin-info MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Antoine Busque Signed-off-by: Jérémie Galarneau --- .gitignore | 4 +- include/Makefile.am | 2 +- include/babeltrace/{so-info.h => bin-info.h} | 65 ++-- lib/Makefile.am | 2 +- lib/{so-info.c => bin-info.c} | 300 +++++++++--------- lib/debuginfo.c | 78 ++--- tests/lib/Makefile.am | 10 +- tests/lib/{test_so_info.c => test_bin_info.c} | 168 +++++----- ...o_info_complete => test_bin_info_complete} | 2 +- tests/tests_debuginfo | 2 +- 10 files changed, 318 insertions(+), 315 deletions(-) rename include/babeltrace/{so-info.h => bin-info.h} (76%) rename lib/{so-info.c => bin-info.c} (76%) rename tests/lib/{test_so_info.c => test_bin_info.c} (50%) rename tests/lib/{test_so_info_complete => test_bin_info_complete} (93%) diff --git a/.gitignore b/.gitignore index 420f2440..177307d1 100644 --- a/.gitignore +++ b/.gitignore @@ -5,10 +5,10 @@ /tests/lib/test_bitfield /tests/lib/test_seek /tests/lib/test_ctf_writer -/tests/lib/test_durin -/tests/lib/test_so_info /tests/lib/test_seek_big_trace /tests/lib/test_seek_empty_packet +/tests/lib/test_dwarf +/tests/lib/test_bin_info *.o *.a *.la diff --git a/include/Makefile.am b/include/Makefile.am index ba6d9127..eb58604a 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -36,7 +36,7 @@ noinst_HEADERS = \ babeltrace/debuginfo.h \ babeltrace/trace-debuginfo.h \ babeltrace/dwarf.h \ - babeltrace/so-info.h \ + babeltrace/bin-info.h \ babeltrace/utils.h \ babeltrace/ctf-ir/metadata.h \ babeltrace/ctf/events-internal.h \ diff --git a/include/babeltrace/so-info.h b/include/babeltrace/bin-info.h similarity index 76% rename from include/babeltrace/so-info.h rename to include/babeltrace/bin-info.h index 17d0f59c..e2af8952 100644 --- a/include/babeltrace/so-info.h +++ b/include/babeltrace/bin-info.h @@ -1,5 +1,5 @@ -#ifndef _BABELTRACE_SO_INFO_H -#define _BABELTRACE_SO_INFO_H +#ifndef _BABELTRACE_BIN_INFO_H +#define _BABELTRACE_BIN_INFO_H /* * Babeltrace - Executable and Shared Object Debug Info Reader @@ -38,7 +38,7 @@ #define BUILD_ID_SUBDIR ".build-id/" #define BUILD_ID_SUFFIX ".debug" -struct so_info { +struct bin_info { /* Base virtual memory address. */ uint64_t low_addr; /* Upper bound of exec address space. */ @@ -62,7 +62,10 @@ struct so_info { int dwarf_fd; /* Denotes whether the executable is position independent code. */ bool is_pic:1; - /* Denotes whether the SO only has ELF symbols and no DWARF info. */ + /* + * Denotes whether the executable only has ELF symbols and no + * DWARF info. + */ bool is_elf_only:1; }; @@ -72,13 +75,13 @@ struct source_location { }; /** - * Initializes the so_info framework. Call this before calling + * Initializes the bin_info framework. Call this before calling * anything else. * * @returns 0 on success, -1 on failure */ BT_HIDDEN -int so_info_init(void); +int bin_info_init(void); /** * Instantiate a structure representing an ELF executable, possibly @@ -89,63 +92,63 @@ int so_info_init(void); * @param memsz In-memory size of the executable * @param is_pic Whether the executable is position independent * code (PIC) - * @returns Pointer to the new so_info on success, + * @returns Pointer to the new bin_info on success, * NULL on failure. */ BT_HIDDEN -struct so_info *so_info_create(const char *path, uint64_t low_addr, +struct bin_info *bin_info_create(const char *path, uint64_t low_addr, uint64_t memsz, bool is_pic); /** - * Destroy the given so_info instance + * Destroy the given bin_info instance * - * @param so so_info instance to destroy + * @param bin bin_info instance to destroy */ BT_HIDDEN -void so_info_destroy(struct so_info *so); +void bin_info_destroy(struct bin_info *bin); /** - * Sets the build ID information for a given so_info instance. + * Sets the build ID information for a given bin_info instance. * - * @param so The so_info instance for which to set + * @param bin The bin_info instance for which to set * the build ID * @param build_id Array of bytes containing the actual ID * @param build_id_len Length in bytes of the build_id * @returns 0 on success, -1 on failure */ BT_HIDDEN -int so_info_set_build_id(struct so_info *so, uint8_t *build_id, +int bin_info_set_build_id(struct bin_info *bin, uint8_t *build_id, size_t build_id_len); /** - * Sets the debug link information for a given so_info instance. + * Sets the debug link information for a given bin_info instance. * - * @param so The so_info instance for which to set + * @param bin The bin_info instance for which to set * the debug link * @param filename Name of the separate debug info file * @param crc Checksum for the debug info file * @returns 0 on success, -1 on failure */ BT_HIDDEN -int so_info_set_debug_link(struct so_info *so, char *filename, uint32_t crc); +int bin_info_set_debug_link(struct bin_info *bin, char *filename, uint32_t crc); /** - * Returns whether or not the given SO info \p so contains the address - * \p addr. + * Returns whether or not the given bin info \p bin contains the + * address \p addr. * - * @param so so_info instance + * @param bin bin_info instance * @param addr Address to lookup - * @returns 1 if \p so contains \p addr, 0 if it does not, + * @returns 1 if \p bin contains \p addr, 0 if it does not, * -1 on failure */ static inline -int so_info_has_address(struct so_info *so, uint64_t addr) +int bin_info_has_address(struct bin_info *bin, uint64_t addr) { - if (!so) { + if (!bin) { return -1; } - return addr >= so->low_addr && addr < so->high_addr; + return addr >= bin->low_addr && addr < bin->high_addr; } /** @@ -160,7 +163,7 @@ int so_info_has_address(struct so_info *so, uint64_t addr) * of `func_name` is passed to the caller. On failure, `func_name` remains * unchanged. * - * @param so so_info instance for the executable containing + * @param bin bin_info instance for the executable containing * the address * @param addr Virtual memory address for which to find the * function name @@ -168,7 +171,7 @@ int so_info_has_address(struct so_info *so, uint64_t addr) * @returns 0 on success, -1 on failure */ BT_HIDDEN -int so_info_lookup_function_name(struct so_info *so, uint64_t addr, +int bin_info_lookup_function_name(struct bin_info *bin, uint64_t addr, char **func_name); /** @@ -182,7 +185,7 @@ int so_info_lookup_function_name(struct so_info *so, uint64_t addr, * of `src_loc` is passed to the caller. On failure, `src_loc` remains * unchanged. * - * @param so so_info instance for the executable containing + * @param bin bin_info instance for the executable containing * the address * @param addr Virtual memory address for which to find the * source location @@ -190,7 +193,7 @@ int so_info_lookup_function_name(struct so_info *so, uint64_t addr, * @returns 0 on success, -1 on failure */ BT_HIDDEN -int so_info_lookup_source_location(struct so_info *so, uint64_t addr, +int bin_info_lookup_source_location(struct bin_info *bin, uint64_t addr, struct source_location **src_loc); /** * Get a string representing the location within the binary of a given @@ -202,7 +205,7 @@ int so_info_lookup_source_location(struct so_info *so, uint64_t addr, * On success, the out parameter `bin_loc` is set. The ownership is * passed to the caller. On failure, `bin_loc` remains unchanged. * - * @param so so_info instance for the executable containing + * @param bin bin_info instance for the executable containing * the address * @param addr Virtual memory address for which to find the * binary location @@ -210,7 +213,7 @@ int so_info_lookup_source_location(struct so_info *so, uint64_t addr, * @returns 0 on success, -1 on failure */ BT_HIDDEN -int so_info_get_bin_loc(struct so_info *so, uint64_t addr, char **bin_loc); +int bin_info_get_bin_loc(struct bin_info *bin, uint64_t addr, char **bin_loc); /** * Destroy the given source_location instance @@ -220,4 +223,4 @@ int so_info_get_bin_loc(struct so_info *so, uint64_t addr, char **bin_loc); BT_HIDDEN void source_location_destroy(struct source_location *src_loc); -#endif /* _BABELTRACE_SO_INFO_H */ +#endif /* _BABELTRACE_BIN_INFO_H */ diff --git a/lib/Makefile.am b/lib/Makefile.am index 1587af89..17a92f71 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -17,7 +17,7 @@ if ENABLE_DEBUGINFO noinst_LTLIBRARIES = libdebuginfo.la libdebuginfo_la_SOURCES = debuginfo.c \ - so-info.c \ + bin-info.c \ dwarf.c \ crc32.c \ utils.c diff --git a/lib/so-info.c b/lib/bin-info.c similarity index 76% rename from lib/so-info.c rename to lib/bin-info.c index a5c38604..023515ef 100644 --- a/lib/so-info.c +++ b/lib/bin-info.c @@ -1,5 +1,5 @@ /* - * so-info.c + * bin-info.c * * Babeltrace - Executable and Shared Object Debug Info Reader * @@ -37,7 +37,7 @@ #include #include #include -#include +#include #include #include #include @@ -50,7 +50,7 @@ #define ADDR_STR_LEN 20 BT_HIDDEN -int so_info_init(void) +int bin_info_init(void) { int ret = 0; @@ -64,88 +64,88 @@ int so_info_init(void) } BT_HIDDEN -struct so_info *so_info_create(const char *path, uint64_t low_addr, +struct bin_info *bin_info_create(const char *path, uint64_t low_addr, uint64_t memsz, bool is_pic) { - struct so_info *so = NULL; + struct bin_info *bin = NULL; if (!path) { goto error; } - so = g_new0(struct so_info, 1); - if (!so) { + bin = g_new0(struct bin_info, 1); + if (!bin) { goto error; } if (opt_debug_info_target_prefix) { - so->elf_path = g_build_path("/", opt_debug_info_target_prefix, + bin->elf_path = g_build_path("/", opt_debug_info_target_prefix, path, NULL); } else { - so->elf_path = strdup(path); + bin->elf_path = strdup(path); } - if (!so->elf_path) { + if (!bin->elf_path) { goto error; } - so->is_pic = is_pic; - so->memsz = memsz; - so->low_addr = low_addr; - so->high_addr = so->low_addr + so->memsz; + bin->is_pic = is_pic; + bin->memsz = memsz; + bin->low_addr = low_addr; + bin->high_addr = bin->low_addr + bin->memsz; - return so; + return bin; error: - so_info_destroy(so); + bin_info_destroy(bin); return NULL; } BT_HIDDEN -void so_info_destroy(struct so_info *so) +void bin_info_destroy(struct bin_info *bin) { - if (!so) { + if (!bin) { return; } - dwarf_end(so->dwarf_info); + dwarf_end(bin->dwarf_info); - free(so->elf_path); - free(so->dwarf_path); - free(so->build_id); - free(so->dbg_link_filename); + free(bin->elf_path); + free(bin->dwarf_path); + free(bin->build_id); + free(bin->dbg_link_filename); - elf_end(so->elf_file); + elf_end(bin->elf_file); - close(so->elf_fd); - close(so->dwarf_fd); + close(bin->elf_fd); + close(bin->dwarf_fd); - g_free(so); + g_free(bin); } BT_HIDDEN -int so_info_set_build_id(struct so_info *so, uint8_t *build_id, +int bin_info_set_build_id(struct bin_info *bin, uint8_t *build_id, size_t build_id_len) { - if (!so || !build_id) { + if (!bin || !build_id) { goto error; } - so->build_id = malloc(build_id_len); - if (!so->build_id) { + bin->build_id = malloc(build_id_len); + if (!bin->build_id) { goto error; } - memcpy(so->build_id, build_id, build_id_len); - so->build_id_len = build_id_len; + memcpy(bin->build_id, build_id, build_id_len); + bin->build_id_len = build_id_len; /* * Reset the is_elf_only flag in case it had been set * previously, because we might find separate debug info using * the new build id information. */ - so->is_elf_only = false; + bin->is_elf_only = false; return 0; @@ -155,25 +155,25 @@ error: } BT_HIDDEN -int so_info_set_debug_link(struct so_info *so, char *filename, uint32_t crc) +int bin_info_set_debug_link(struct bin_info *bin, char *filename, uint32_t crc) { - if (!so || !filename) { + if (!bin || !filename) { goto error; } - so->dbg_link_filename = strdup(filename); - if (!so->dbg_link_filename) { + bin->dbg_link_filename = strdup(filename); + if (!bin->dbg_link_filename) { goto error; } - so->dbg_link_crc = crc; + bin->dbg_link_crc = crc; /* * Reset the is_elf_only flag in case it had been set * previously, because we might find separate debug info using * the new build id information. */ - so->is_elf_only = false; + bin->is_elf_only = false; return 0; @@ -184,20 +184,20 @@ error: /** * Tries to read DWARF info from the location given by path, and - * attach it to the given so_info instance if it exists. + * attach it to the given bin_info instance if it exists. * - * @param so so_info instance for which to set DWARF info + * @param bin bin_info instance for which to set DWARF info * @param path Presumed location of the DWARF info * @returns 0 on success, -1 on failure */ static -int so_info_set_dwarf_info_from_path(struct so_info *so, char *path) +int bin_info_set_dwarf_info_from_path(struct bin_info *bin, char *path) { int fd = -1, ret = 0; struct bt_dwarf_cu *cu = NULL; Dwarf *dwarf_info = NULL; - if (!so || !path) { + if (!bin || !path) { goto error; } @@ -212,8 +212,8 @@ int so_info_set_dwarf_info_from_path(struct so_info *so, char *path) } /* - * Check if the dwarf info has any CU. If not, the SO's object - * file contains no DWARF info. + * Check if the dwarf info has any CU. If not, the + * executable's object file contains no DWARF info. */ cu = bt_dwarf_cu_create(dwarf_info); if (!cu) { @@ -225,12 +225,12 @@ int so_info_set_dwarf_info_from_path(struct so_info *so, char *path) goto error; } - so->dwarf_fd = fd; - so->dwarf_path = strdup(path); - if (!so->dwarf_path) { + bin->dwarf_fd = fd; + bin->dwarf_path = strdup(path); + if (!bin->dwarf_path) { goto error; } - so->dwarf_info = dwarf_info; + bin->dwarf_info = dwarf_info; free(cu); return 0; @@ -245,22 +245,22 @@ error: } /** - * Try to set the dwarf_info for a given so_info instance via the + * Try to set the dwarf_info for a given bin_info instance via the * build ID method. * - * @param so so_info instance for which to retrieve the + * @param bin bin_info instance for which to retrieve the * DWARF info via build ID * @returns 0 on success (i.e. dwarf_info set), -1 on failure */ static -int so_info_set_dwarf_info_build_id(struct so_info *so) +int bin_info_set_dwarf_info_build_id(struct bin_info *bin) { int i = 0, ret = 0; char *path = NULL, *build_id_file = NULL; const char *dbg_dir = NULL; size_t build_id_file_len; - if (!so || !so->build_id) { + if (!bin || !bin->build_id) { goto error; } @@ -268,18 +268,18 @@ int so_info_set_dwarf_info_build_id(struct so_info *so) /* 2 characters per byte printed in hex, +1 for '/' and +1 for * '\0' */ - build_id_file_len = (2 * so->build_id_len) + 1 + + build_id_file_len = (2 * bin->build_id_len) + 1 + strlen(BUILD_ID_SUFFIX) + 1; build_id_file = malloc(build_id_file_len); if (!build_id_file) { goto error; } - snprintf(build_id_file, 4, "%02x/", so->build_id[0]); - for (i = 1; i < so->build_id_len; ++i) { + snprintf(build_id_file, 4, "%02x/", bin->build_id[0]); + for (i = 1; i < bin->build_id_len; ++i) { int path_idx = 3 + 2 * (i - 1); - snprintf(&build_id_file[path_idx], 3, "%02x", so->build_id[i]); + snprintf(&build_id_file[path_idx], 3, "%02x", bin->build_id[i]); } strcat(build_id_file, BUILD_ID_SUFFIX); @@ -288,7 +288,7 @@ int so_info_set_dwarf_info_build_id(struct so_info *so) goto error; } - ret = so_info_set_dwarf_info_from_path(so, path); + ret = bin_info_set_dwarf_info_from_path(bin, path); if (ret) { goto error; } @@ -347,72 +347,72 @@ end: } /** - * Try to set the dwarf_info for a given so_info instance via the + * Try to set the dwarf_info for a given bin_info instance via the * build ID method. * - * @param so so_info instance for which to retrieve the + * @param bin bin_info instance for which to retrieve the * DWARF info via debug link * @returns 0 on success (i.e. dwarf_info set), -1 on failure */ static -int so_info_set_dwarf_info_debug_link(struct so_info *so) +int bin_info_set_dwarf_info_debug_link(struct bin_info *bin) { int ret = 0; const char *dbg_dir = NULL; - char *dir_name = NULL, *so_dir = NULL, *path = NULL; + char *dir_name = NULL, *bin_dir = NULL, *path = NULL; size_t max_path_len = 0; - if (!so || !so->dbg_link_filename) { + if (!bin || !bin->dbg_link_filename) { goto error; } dbg_dir = opt_debug_info_dir ? : DEFAULT_DEBUG_DIR; - dir_name = dirname(so->elf_path); + dir_name = dirname(bin->elf_path); if (!dir_name) { goto error; } - /* so_dir is just dir_name with a trailing slash */ - so_dir = malloc(strlen(dir_name) + 2); - if (!so_dir) { + /* bin_dir is just dir_name with a trailing slash */ + bin_dir = malloc(strlen(dir_name) + 2); + if (!bin_dir) { goto error; } - strcpy(so_dir, dir_name); - strcat(so_dir, "/"); + strcpy(bin_dir, dir_name); + strcat(bin_dir, "/"); - max_path_len = strlen(dbg_dir) + strlen(so_dir) + - strlen(DEBUG_SUBDIR) + strlen(so->dbg_link_filename) + max_path_len = strlen(dbg_dir) + strlen(bin_dir) + + strlen(DEBUG_SUBDIR) + strlen(bin->dbg_link_filename) + 1; path = malloc(max_path_len); if (!path) { goto error; } - /* First look in the SO's dir */ - strcpy(path, so_dir); - strcat(path, so->dbg_link_filename); + /* First look in the executable's dir */ + strcpy(path, bin_dir); + strcat(path, bin->dbg_link_filename); - if (is_valid_debug_file(path, so->dbg_link_crc)) { + if (is_valid_debug_file(path, bin->dbg_link_crc)) { goto found; } /* If not found, look in .debug subdir */ - strcpy(path, so_dir); + strcpy(path, bin_dir); strcat(path, DEBUG_SUBDIR); - strcat(path, so->dbg_link_filename); + strcat(path, bin->dbg_link_filename); - if (is_valid_debug_file(path, so->dbg_link_crc)) { + if (is_valid_debug_file(path, bin->dbg_link_crc)) { goto found; } /* Lastly, look under the global debug directory */ strcpy(path, dbg_dir); - strcat(path, so_dir); - strcat(path, so->dbg_link_filename); + strcat(path, bin_dir); + strcat(path, bin->dbg_link_filename); - if (is_valid_debug_file(path, so->dbg_link_crc)) { + if (is_valid_debug_file(path, bin->dbg_link_crc)) { goto found; } @@ -420,12 +420,12 @@ error: ret = -1; end: free(path); - free(so_dir); + free(bin_dir); return ret; found: - ret = so_info_set_dwarf_info_from_path(so, path); + ret = bin_info_set_dwarf_info_from_path(bin, path); if (ret) { goto error; } @@ -436,20 +436,20 @@ found: /** * Initialize the DWARF info for a given executable. * - * @param so so_info instance + * @param bin bin_info instance * @returns 0 on success, -1 on failure */ static -int so_info_set_dwarf_info(struct so_info *so) +int bin_info_set_dwarf_info(struct bin_info *bin) { int ret = 0; - if (!so) { + if (!bin) { goto error; } /* First try to set the DWARF info from the ELF file */ - ret = so_info_set_dwarf_info_from_path(so, so->elf_path); + ret = bin_info_set_dwarf_info_from_path(bin, bin->elf_path); if (!ret) { goto end; } @@ -458,12 +458,12 @@ int so_info_set_dwarf_info(struct so_info *so) * If that fails, try to find separate debug info via build ID * and debug link. */ - ret = so_info_set_dwarf_info_build_id(so); + ret = bin_info_set_dwarf_info_build_id(bin); if (!ret) { goto end; } - ret = so_info_set_dwarf_info_debug_link(so); + ret = bin_info_set_dwarf_info_debug_link(bin); if (!ret) { goto end; } @@ -477,22 +477,22 @@ end: /** * Initialize the ELF file for a given executable. * - * @param so so_info instance + * @param bin bin_info instance * @returns 0 on success, -1 on failure */ static -int so_info_set_elf_file(struct so_info *so) +int bin_info_set_elf_file(struct bin_info *bin) { int elf_fd; Elf *elf_file = NULL; - if (!so) { + if (!bin) { goto error; } - elf_fd = open(so->elf_path, O_RDONLY); + elf_fd = open(bin->elf_path, O_RDONLY); if (elf_fd < 0) { - printf_verbose("Failed to open %s\n", so->elf_path); + printf_verbose("Failed to open %s\n", bin->elf_path); goto error; } @@ -504,12 +504,12 @@ int so_info_set_elf_file(struct so_info *so) if (elf_kind(elf_file) != ELF_K_ELF) { printf_verbose("Error: %s is not an ELF object\n", - so->elf_path); + bin->elf_path); goto error; } - so->elf_fd = elf_fd; - so->elf_file = elf_file; + bin->elf_fd = elf_fd; + bin->elf_file = elf_file; return 0; error: @@ -546,7 +546,7 @@ void source_location_destroy(struct source_location *src_loc) * @returns 0 on success, -1 on failure */ static -int so_info_append_offset_str(const char *base_str, uint64_t low_addr, +int bin_info_append_offset_str(const char *base_str, uint64_t low_addr, uint64_t high_addr, char **result) { int ret; @@ -599,7 +599,7 @@ error: * @returns 0 on success, -1 on failure */ static -int so_info_get_nearest_symbol_from_section(Elf_Scn *scn, uint64_t addr, +int bin_info_get_nearest_symbol_from_section(Elf_Scn *scn, uint64_t addr, GElf_Sym **sym, GElf_Shdr **shdr) { int i; @@ -691,7 +691,7 @@ error: * If found, the out parameter `func_name` is set on success. On failure, * it remains unchanged. * - * @param so so_info instance for the executable containing + * @param bin bin_info instance for the executable containing * the address * @param addr Virtual memory address for which to find the * function name @@ -699,7 +699,7 @@ error: * @returns 0 on success, -1 on failure */ static -int so_info_lookup_elf_function_name(struct so_info *so, uint64_t addr, +int bin_info_lookup_elf_function_name(struct bin_info *bin, uint64_t addr, char **func_name) { /* @@ -715,37 +715,37 @@ int so_info_lookup_elf_function_name(struct so_info *so, uint64_t addr, char *sym_name = NULL; /* Set ELF file if it hasn't been accessed yet. */ - if (!so->elf_file) { - ret = so_info_set_elf_file(so); + if (!bin->elf_file) { + ret = bin_info_set_elf_file(bin); if (ret) { /* Failed to set ELF file. */ goto error; } } - scn = elf_nextscn(so->elf_file, scn); + scn = elf_nextscn(bin->elf_file, scn); if (!scn) { goto error; } while (scn && !sym) { - ret = so_info_get_nearest_symbol_from_section( + ret = bin_info_get_nearest_symbol_from_section( scn, addr, &sym, &shdr); if (ret) { goto error; } - scn = elf_nextscn(so->elf_file, scn); + scn = elf_nextscn(bin->elf_file, scn); } if (sym) { - sym_name = elf_strptr(so->elf_file, shdr->sh_link, + sym_name = elf_strptr(bin->elf_file, shdr->sh_link, sym->st_name); if (!sym_name) { goto error; } - ret = so_info_append_offset_str(sym_name, sym->st_value, addr, + ret = bin_info_append_offset_str(sym_name, sym->st_value, addr, func_name); if (ret) { goto error; @@ -776,7 +776,7 @@ error: * @returns 0 on success, -1 on failure */ static -int so_info_lookup_cu_function_name(struct bt_dwarf_cu *cu, uint64_t addr, +int bin_info_lookup_cu_function_name(struct bt_dwarf_cu *cu, uint64_t addr, char **func_name) { int ret = 0, found = 0; @@ -825,7 +825,7 @@ int so_info_lookup_cu_function_name(struct bt_dwarf_cu *cu, uint64_t addr, goto error; } - ret = so_info_append_offset_str(die_name, low_addr, addr, + ret = bin_info_append_offset_str(die_name, low_addr, addr, func_name); if (ret) { goto error; @@ -847,7 +847,7 @@ error: * If found, the out parameter `func_name` is set on success. On * failure, it remains unchanged. * - * @param so so_info instance for the executable containing + * @param bin bin_info instance for the executable containing * the address * @param addr Virtual memory address for which to find the * function name @@ -855,24 +855,24 @@ error: * @returns 0 on success, -1 on failure */ static -int so_info_lookup_dwarf_function_name(struct so_info *so, uint64_t addr, +int bin_info_lookup_dwarf_function_name(struct bin_info *bin, uint64_t addr, char **func_name) { int ret = 0; char *_func_name = NULL; struct bt_dwarf_cu *cu = NULL; - if (!so || !func_name) { + if (!bin || !func_name) { goto error; } - cu = bt_dwarf_cu_create(so->dwarf_info); + cu = bt_dwarf_cu_create(bin->dwarf_info); if (!cu) { goto error; } while (bt_dwarf_cu_next(cu) == 0) { - ret = so_info_lookup_cu_function_name(cu, addr, &_func_name); + ret = bin_info_lookup_cu_function_name(cu, addr, &_func_name); if (ret) { goto error; } @@ -895,26 +895,26 @@ error: } BT_HIDDEN -int so_info_lookup_function_name(struct so_info *so, uint64_t addr, +int bin_info_lookup_function_name(struct bin_info *bin, uint64_t addr, char **func_name) { int ret = 0; char *_func_name = NULL; - if (!so || !func_name) { + if (!bin || !func_name) { goto error; } /* Set DWARF info if it hasn't been accessed yet. */ - if (!so->dwarf_info && !so->is_elf_only) { - ret = so_info_set_dwarf_info(so); + if (!bin->dwarf_info && !bin->is_elf_only) { + ret = bin_info_set_dwarf_info(bin); if (ret) { /* Failed to set DWARF info, fallback to ELF. */ - so->is_elf_only = true; + bin->is_elf_only = true; } } - if (!so_info_has_address(so, addr)) { + if (!bin_info_has_address(bin, addr)) { goto error; } @@ -922,14 +922,14 @@ int so_info_lookup_function_name(struct so_info *so, uint64_t addr, * Addresses in ELF and DWARF are relative to base address for * PIC, so make the address argument relative too if needed. */ - if (so->is_pic) { - addr -= so->low_addr; + if (bin->is_pic) { + addr -= bin->low_addr; } - if (so->is_elf_only) { - ret = so_info_lookup_elf_function_name(so, addr, &_func_name); + if (bin->is_elf_only) { + ret = bin_info_lookup_elf_function_name(bin, addr, &_func_name); } else { - ret = so_info_lookup_dwarf_function_name(so, addr, &_func_name); + ret = bin_info_lookup_dwarf_function_name(bin, addr, &_func_name); } if (ret || !_func_name) { @@ -944,17 +944,17 @@ error: } BT_HIDDEN -int so_info_get_bin_loc(struct so_info *so, uint64_t addr, char **bin_loc) +int bin_info_get_bin_loc(struct bin_info *bin, uint64_t addr, char **bin_loc) { int ret = 0; char *_bin_loc = NULL; - if (!so || !bin_loc) { + if (!bin || !bin_loc) { goto error; } - if (so->is_pic) { - addr -= so->low_addr; + if (bin->is_pic) { + addr -= bin->low_addr; ret = asprintf(&_bin_loc, "+%#0" PRIx64, addr); } else { ret = asprintf(&_bin_loc, "@%#0" PRIx64, addr); @@ -991,7 +991,7 @@ error: * @returns Returns 1 if the address was found, 0 if not */ static -int so_info_child_die_has_address(struct bt_dwarf_die *die, uint64_t addr) +int bin_info_child_die_has_address(struct bt_dwarf_die *die, uint64_t addr) { int ret = 0, contains = 0; @@ -1045,7 +1045,7 @@ error: * @returns 0 on success, -1 on failure */ static -int so_info_lookup_cu_src_loc_inl(struct bt_dwarf_cu *cu, uint64_t addr, +int bin_info_lookup_cu_src_loc_inl(struct bt_dwarf_cu *cu, uint64_t addr, struct source_location **src_loc) { int ret = 0, found = 0; @@ -1082,7 +1082,7 @@ int so_info_lookup_cu_src_loc_inl(struct bt_dwarf_cu *cu, uint64_t addr, * Try to find an inlined subroutine * child of this DIE containing addr. */ - found = so_info_child_die_has_address( + found = bin_info_child_die_has_address( die, addr); goto end; } @@ -1139,7 +1139,7 @@ error: * @returns 0 on success, -1 on failure */ static -int so_info_lookup_cu_src_loc_no_inl(struct bt_dwarf_cu *cu, uint64_t addr, +int bin_info_lookup_cu_src_loc_no_inl(struct bt_dwarf_cu *cu, uint64_t addr, struct source_location **src_loc) { struct source_location *_src_loc = NULL; @@ -1209,7 +1209,7 @@ error: * On success, the out parameter `src_loc` is set if found. On * failure, it remains unchanged. * - * @param so bt_dwarf_cu instance for the compile unit which + * @param cu bt_dwarf_cu instance for the compile unit which * may contain the address * @param addr Virtual memory address for which to find the * source location @@ -1217,7 +1217,7 @@ error: * @returns 0 on success, -1 on failure */ static -int so_info_lookup_cu_src_loc(struct bt_dwarf_cu *cu, uint64_t addr, +int bin_info_lookup_cu_src_loc(struct bt_dwarf_cu *cu, uint64_t addr, struct source_location **src_loc) { int ret = 0; @@ -1227,7 +1227,7 @@ int so_info_lookup_cu_src_loc(struct bt_dwarf_cu *cu, uint64_t addr, goto error; } - ret = so_info_lookup_cu_src_loc_inl(cu, addr, &_src_loc); + ret = bin_info_lookup_cu_src_loc_inl(cu, addr, &_src_loc); if (ret) { goto error; } @@ -1236,7 +1236,7 @@ int so_info_lookup_cu_src_loc(struct bt_dwarf_cu *cu, uint64_t addr, goto end; } - ret = so_info_lookup_cu_src_loc_no_inl(cu, addr, &_src_loc); + ret = bin_info_lookup_cu_src_loc_no_inl(cu, addr, &_src_loc); if (ret) { goto error; } @@ -1258,30 +1258,30 @@ error: } BT_HIDDEN -int so_info_lookup_source_location(struct so_info *so, uint64_t addr, +int bin_info_lookup_source_location(struct bin_info *bin, uint64_t addr, struct source_location **src_loc) { struct bt_dwarf_cu *cu = NULL; struct source_location *_src_loc = NULL; - if (!so || !src_loc) { + if (!bin || !src_loc) { goto error; } /* Set DWARF info if it hasn't been accessed yet. */ - if (!so->dwarf_info && !so->is_elf_only) { - if (so_info_set_dwarf_info(so)) { + if (!bin->dwarf_info && !bin->is_elf_only) { + if (bin_info_set_dwarf_info(bin)) { /* Failed to set DWARF info. */ - so->is_elf_only = true; + bin->is_elf_only = true; } } - if (so->is_elf_only) { + if (bin->is_elf_only) { /* We cannot lookup source location without DWARF info. */ goto error; } - if (!so_info_has_address(so, addr)) { + if (!bin_info_has_address(bin, addr)) { goto error; } @@ -1289,11 +1289,11 @@ int so_info_lookup_source_location(struct so_info *so, uint64_t addr, * Addresses in ELF and DWARF are relative to base address for * PIC, so make the address argument relative too if needed. */ - if (so->is_pic) { - addr -= so->low_addr; + if (bin->is_pic) { + addr -= bin->low_addr; } - cu = bt_dwarf_cu_create(so->dwarf_info); + cu = bt_dwarf_cu_create(bin->dwarf_info); if (!cu) { goto error; } @@ -1301,7 +1301,7 @@ int so_info_lookup_source_location(struct so_info *so, uint64_t addr, while (bt_dwarf_cu_next(cu) == 0) { int ret; - ret = so_info_lookup_cu_src_loc(cu, addr, &_src_loc); + ret = bin_info_lookup_cu_src_loc(cu, addr, &_src_loc); if (ret) { goto error; } diff --git a/lib/debuginfo.c b/lib/debuginfo.c index 40514f25..22930791 100644 --- a/lib/debuginfo.c +++ b/lib/debuginfo.c @@ -30,16 +30,16 @@ #include #include #include -#include +#include #include #include struct proc_debug_info_sources { /* - * Hash table: base address (pointer to uint64_t) to so info; owned by + * Hash table: base address (pointer to uint64_t) to bin info; owned by * proc_debug_info_sources. */ - GHashTable *baddr_to_so_info; + GHashTable *baddr_to_bin_info; /* * Hash table: IP (pointer to uint64_t) to (struct debug_info_source *); @@ -74,7 +74,7 @@ int debug_info_init(struct debug_info *info) "lttng_ust_statedump:start"); info->q_dl_open = g_quark_from_string("lttng_ust_dl:dlopen"); - return so_info_init(); + return bin_info_init(); } static @@ -92,7 +92,7 @@ void debug_info_source_destroy(struct debug_info_source *debug_info_src) } static -struct debug_info_source *debug_info_source_create_from_so(struct so_info *so, +struct debug_info_source *debug_info_source_create_from_bin(struct bin_info *bin, uint64_t ip) { int ret; @@ -106,15 +106,15 @@ struct debug_info_source *debug_info_source_create_from_so(struct so_info *so, } /* Lookup function name */ - ret = so_info_lookup_function_name(so, ip, &debug_info_src->func); + ret = bin_info_lookup_function_name(bin, ip, &debug_info_src->func); if (ret) { goto error; } /* Can't retrieve src_loc from ELF only, skip it */ - if (!so->is_elf_only) { + if (!bin->is_elf_only) { /* Lookup source location */ - ret = so_info_lookup_source_location(so, ip, &src_loc); + ret = bin_info_lookup_source_location(bin, ip, &src_loc); if (ret) { goto error; } @@ -136,8 +136,8 @@ struct debug_info_source *debug_info_source_create_from_so(struct so_info *so, source_location_destroy(src_loc); } - if (so->elf_path) { - debug_info_src->bin_path = strdup(so->elf_path); + if (bin->elf_path) { + debug_info_src->bin_path = strdup(bin->elf_path); if (!debug_info_src->bin_path) { goto error; } @@ -145,7 +145,7 @@ struct debug_info_source *debug_info_source_create_from_so(struct so_info *so, debug_info_src->short_bin_path = get_filename_from_path( debug_info_src->bin_path); - ret = so_info_get_bin_loc(so, ip, &(debug_info_src->bin_loc)); + ret = bin_info_get_bin_loc(bin, ip, &(debug_info_src->bin_loc)); if (ret) { goto error; } @@ -167,8 +167,8 @@ void proc_debug_info_sources_destroy( return; } - if (proc_dbg_info_src->baddr_to_so_info) { - g_hash_table_destroy(proc_dbg_info_src->baddr_to_so_info); + if (proc_dbg_info_src->baddr_to_bin_info) { + g_hash_table_destroy(proc_dbg_info_src->baddr_to_bin_info); } if (proc_dbg_info_src->ip_to_debug_info_src) { @@ -188,10 +188,10 @@ struct proc_debug_info_sources *proc_debug_info_sources_create(void) goto end; } - proc_dbg_info_src->baddr_to_so_info = g_hash_table_new_full( + proc_dbg_info_src->baddr_to_bin_info = g_hash_table_new_full( g_int64_hash, g_int64_equal, (GDestroyNotify) g_free, - (GDestroyNotify) so_info_destroy); - if (!proc_dbg_info_src->baddr_to_so_info) { + (GDestroyNotify) bin_info_destroy); + if (!proc_dbg_info_src->baddr_to_bin_info) { goto error; } @@ -266,14 +266,14 @@ struct debug_info_source *proc_debug_info_sources_get_entry( goto end; } - /* Check in all so_infos. */ - g_hash_table_iter_init(&iter, proc_dbg_info_src->baddr_to_so_info); + /* Check in all bin_infos. */ + g_hash_table_iter_init(&iter, proc_dbg_info_src->baddr_to_bin_info); while (g_hash_table_iter_next(&iter, &baddr, &value)) { - struct so_info *so = value; + struct bin_info *bin = value; - if (!so_info_has_address(value, ip)) { + if (!bin_info_has_address(value, ip)) { continue; } @@ -284,7 +284,7 @@ struct debug_info_source *proc_debug_info_sources_get_entry( * a caching policy), and entries should be prunned when * libraries are unmapped. */ - debug_info_src = debug_info_source_create_from_so(so, ip); + debug_info_src = debug_info_source_create_from_bin(bin, ip); if (debug_info_src) { g_hash_table_insert( proc_dbg_info_src->ip_to_debug_info_src, @@ -380,7 +380,7 @@ void handle_statedump_build_id_event(struct debug_info *debug_info, struct bt_definition *vpid_def = NULL; struct bt_definition *build_id_def = NULL; struct definition_sequence *build_id_seq; - struct so_info *so = NULL; + struct bin_info *bin = NULL; int i; int64_t vpid; uint64_t baddr; @@ -447,17 +447,17 @@ void handle_statedump_build_id_event(struct debug_info *debug_info, goto end; } - so = g_hash_table_lookup(proc_dbg_info_src->baddr_to_so_info, + bin = g_hash_table_lookup(proc_dbg_info_src->baddr_to_bin_info, (gpointer) &baddr); - if (!so) { + if (!bin) { /* - * The build_id event comes after the so has been + * The build_id event comes after the bin has been * created. If it isn't found, just ignore this event. */ goto end; } - so_info_set_build_id(so, build_id, build_id_len); + bin_info_set_build_id(bin, build_id, build_id_len); end: free(build_id); @@ -475,7 +475,7 @@ void handle_statedump_debug_link_event(struct debug_info *debug_info, struct bt_definition *vpid_def = NULL; struct bt_definition *filename_def = NULL; struct bt_definition *crc32_def = NULL; - struct so_info *so = NULL; + struct bin_info *bin = NULL; int64_t vpid; uint64_t baddr; char *filename = NULL; @@ -534,11 +534,11 @@ void handle_statedump_debug_link_event(struct debug_info *debug_info, goto end; } - so = g_hash_table_lookup(proc_dbg_info_src->baddr_to_so_info, + bin = g_hash_table_lookup(proc_dbg_info_src->baddr_to_bin_info, (gpointer) &baddr); - if (!so) { + if (!bin) { /* - * The debug_link event comes after the so has been + * The debug_link event comes after the bin has been * created. If it isn't found, just ignore this event. */ goto end; @@ -547,7 +547,7 @@ void handle_statedump_debug_link_event(struct debug_info *debug_info, filename = bt_get_string(filename_def); crc32 = bt_get_unsigned_int(crc32_def); - so_info_set_debug_link(so, filename, crc32); + bin_info_set_debug_link(bin, filename, crc32); end: return; @@ -565,7 +565,7 @@ void handle_bin_info_event(struct debug_info *debug_info, struct bt_definition *event_fields_def = NULL; struct bt_definition *sec_def = NULL; struct proc_debug_info_sources *proc_dbg_info_src; - struct so_info *so; + struct bin_info *bin; uint64_t baddr, memsz; int64_t vpid; const char *path; @@ -662,19 +662,19 @@ void handle_bin_info_event(struct debug_info *debug_info, *((uint64_t *) key) = baddr; - so = g_hash_table_lookup(proc_dbg_info_src->baddr_to_so_info, + bin = g_hash_table_lookup(proc_dbg_info_src->baddr_to_bin_info, key); - if (so) { + if (bin) { goto end; } - so = so_info_create(path, baddr, memsz, is_pic); - if (!so) { + bin = bin_info_create(path, baddr, memsz, is_pic); + if (!bin) { goto end; } - g_hash_table_insert(proc_dbg_info_src->baddr_to_so_info, - key, so); + g_hash_table_insert(proc_dbg_info_src->baddr_to_bin_info, + key, bin); /* Ownership passed to ht. */ key = NULL; @@ -726,7 +726,7 @@ void handle_statedump_start(struct debug_info *debug_info, goto end; } - g_hash_table_remove_all(proc_dbg_info_src->baddr_to_so_info); + g_hash_table_remove_all(proc_dbg_info_src->baddr_to_bin_info); g_hash_table_remove_all(proc_dbg_info_src->ip_to_debug_info_src); end: diff --git a/tests/lib/Makefile.am b/tests/lib/Makefile.am index 9bb50605..f55d88a1 100644 --- a/tests/lib/Makefile.am +++ b/tests/lib/Makefile.am @@ -39,14 +39,14 @@ test_dwarf_LDADD = $(LIBTAP) \ $(top_builddir)/lib/libdebuginfo.la test_dwarf_SOURCES = test_dwarf.c -test_so_info_LDFLAGS = -static -test_so_info_LDADD = $(LIBTAP) \ +test_bin_info_LDFLAGS = -static +test_bin_info_LDADD = $(LIBTAP) \ $(top_builddir)/lib/libbabeltrace.la \ $(top_builddir)/lib/libdebuginfo.la -test_so_info_SOURCES = test_so_info.c +test_bin_info_SOURCES = test_bin_info.c -noinst_PROGRAMS += test_dwarf test_so_info -SCRIPT_LIST += test_dwarf_complete test_so_info_complete +noinst_PROGRAMS += test_dwarf test_bin_info +SCRIPT_LIST += test_dwarf_complete test_bin_info_complete endif dist_noinst_SCRIPTS = $(SCRIPT_LIST) diff --git a/tests/lib/test_so_info.c b/tests/lib/test_bin_info.c similarity index 50% rename from tests/lib/test_so_info.c rename to tests/lib/test_bin_info.c index 4ef14ed6..011b09a1 100644 --- a/tests/lib/test_so_info.c +++ b/tests/lib/test_bin_info.c @@ -1,5 +1,5 @@ /* - * test_so_info.c + * test_bin_info.c * * Babeltrace SO info tests * @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include "tap/tap.h" #define NR_TESTS 36 @@ -49,196 +49,196 @@ char *opt_debug_info_dir; char *opt_debug_info_target_prefix; static -void test_so_info_build_id(const char *data_dir) +void test_bin_info_build_id(const char *data_dir) { int ret; char path[PATH_MAX]; char *func_name = NULL; - struct so_info *so = NULL; + struct bin_info *bin = NULL; struct source_location *src_loc = NULL; uint8_t build_id[BUILD_ID_LEN] = { 0xcd, 0xd9, 0x8c, 0xdd, 0x87, 0xf7, 0xfe, 0x64, 0xc1, 0x3b, 0x6d, 0xaa, 0xd5, 0x53, 0x98, 0x7e, 0xaf, 0xd4, 0x0c, 0xbb }; - diag("so-info tests - separate DWARF via build ID"); + diag("bin-info tests - separate DWARF via build ID"); snprintf(path, PATH_MAX, "%s/%s", data_dir, SO_NAME_BUILD_ID); - so = so_info_create(path, SO_LOW_ADDR, SO_MEMSZ, true); - ok(so != NULL, "so_info_create succesful"); + bin = bin_info_create(path, SO_LOW_ADDR, SO_MEMSZ, true); + ok(bin != NULL, "bin_info_create succesful"); /* Test setting build_id */ - ret = so_info_set_build_id(so, build_id, BUILD_ID_LEN); - ok(ret == 0, "so_info_set_build_id succesful"); + ret = bin_info_set_build_id(bin, build_id, BUILD_ID_LEN); + ok(ret == 0, "bin_info_set_build_id succesful"); /* Test function name lookup (with DWARF) */ - ret = so_info_lookup_function_name(so, FUNC_FOO_ADDR, &func_name); - ok(ret == 0, "so_info_lookup_function_name succesful"); + ret = bin_info_lookup_function_name(bin, FUNC_FOO_ADDR, &func_name); + ok(ret == 0, "bin_info_lookup_function_name succesful"); ok(strcmp(func_name, FUNC_FOO_NAME) == 0, - "so_info_lookup_function_name - correct func_name value"); + "bin_info_lookup_function_name - correct func_name value"); free(func_name); /* Test source location lookup */ - ret = so_info_lookup_source_location(so, FUNC_FOO_ADDR, &src_loc); - ok(ret == 0, "so_info_lookup_source_location succesful"); + ret = bin_info_lookup_source_location(bin, FUNC_FOO_ADDR, &src_loc); + ok(ret == 0, "bin_info_lookup_source_location succesful"); ok(src_loc->line_no == FUNC_FOO_LINE_NO, - "so_info_lookup_source_location - correct line_no"); + "bin_info_lookup_source_location - correct line_no"); ok(strcmp(src_loc->filename, FUNC_FOO_FILENAME) == 0, - "so_info_lookup_source_location - correct filename"); + "bin_info_lookup_source_location - correct filename"); source_location_destroy(src_loc); - so_info_destroy(so); + bin_info_destroy(bin); } static -void test_so_info_debug_link(const char *data_dir) +void test_bin_info_debug_link(const char *data_dir) { int ret; char path[PATH_MAX]; char *func_name = NULL; - struct so_info *so = NULL; + struct bin_info *bin = NULL; struct source_location *src_loc = NULL; char *dbg_filename = "libhello_debug_link.so.debug"; uint32_t crc = 0xe55c2b98; - diag("so-info tests - separate DWARF via debug link"); + diag("bin-info tests - separate DWARF via debug link"); snprintf(path, PATH_MAX, "%s/%s", data_dir, SO_NAME_DEBUG_LINK); - so = so_info_create(path, SO_LOW_ADDR, SO_MEMSZ, true); - ok(so != NULL, "so_info_create succesful"); + bin = bin_info_create(path, SO_LOW_ADDR, SO_MEMSZ, true); + ok(bin != NULL, "bin_info_create succesful"); /* Test setting debug link */ - ret = so_info_set_debug_link(so, dbg_filename, crc); - ok(ret == 0, "so_info_set_debug_link succesful"); + ret = bin_info_set_debug_link(bin, dbg_filename, crc); + ok(ret == 0, "bin_info_set_debug_link succesful"); /* Test function name lookup (with DWARF) */ - ret = so_info_lookup_function_name(so, FUNC_FOO_ADDR_DBG_LINK, + ret = bin_info_lookup_function_name(bin, FUNC_FOO_ADDR_DBG_LINK, &func_name); - ok(ret == 0, "so_info_lookup_function_name succesful"); + ok(ret == 0, "bin_info_lookup_function_name succesful"); ok(strcmp(func_name, FUNC_FOO_NAME) == 0, - "so_info_lookup_function_name - correct func_name value"); + "bin_info_lookup_function_name - correct func_name value"); free(func_name); /* Test source location lookup */ - ret = so_info_lookup_source_location(so, FUNC_FOO_ADDR_DBG_LINK, + ret = bin_info_lookup_source_location(bin, FUNC_FOO_ADDR_DBG_LINK, &src_loc); - ok(ret == 0, "so_info_lookup_source_location succesful"); + ok(ret == 0, "bin_info_lookup_source_location succesful"); ok(src_loc->line_no == FUNC_FOO_LINE_NO, - "so_info_lookup_source_location - correct line_no"); + "bin_info_lookup_source_location - correct line_no"); ok(strcmp(src_loc->filename, FUNC_FOO_FILENAME) == 0, - "so_info_lookup_source_location - correct filename"); + "bin_info_lookup_source_location - correct filename"); source_location_destroy(src_loc); - so_info_destroy(so); + bin_info_destroy(bin); } static -void test_so_info_elf(const char *data_dir) +void test_bin_info_elf(const char *data_dir) { int ret; char path[PATH_MAX]; char *func_name = NULL; - struct so_info *so = NULL; + struct bin_info *bin = NULL; struct source_location *src_loc = NULL; - diag("so-info tests - ELF only"); + diag("bin-info tests - ELF only"); snprintf(path, PATH_MAX, "%s/%s", data_dir, SO_NAME_ELF); - so = so_info_create(path, SO_LOW_ADDR, SO_MEMSZ, true); - ok(so != NULL, "so_info_create succesful"); + bin = bin_info_create(path, SO_LOW_ADDR, SO_MEMSZ, true); + ok(bin != NULL, "bin_info_create succesful"); /* Test function name lookup (with ELF) */ - ret = so_info_lookup_function_name(so, FUNC_FOO_ADDR_ELF, &func_name); - ok(ret == 0, "so_info_lookup_function_name succesful"); + ret = bin_info_lookup_function_name(bin, FUNC_FOO_ADDR_ELF, &func_name); + ok(ret == 0, "bin_info_lookup_function_name succesful"); ok(strcmp(func_name, FUNC_FOO_NAME_ELF) == 0, - "so_info_lookup_function_name - correct func_name value"); + "bin_info_lookup_function_name - correct func_name value"); free(func_name); func_name = NULL; /* Test function name lookup - erroneous address */ - ret = so_info_lookup_function_name(so, 0, &func_name); + ret = bin_info_lookup_function_name(bin, 0, &func_name); ok(ret == -1 && func_name == NULL, - "so_info_lookup_function_name - fail on addr not found"); + "bin_info_lookup_function_name - fail on addr not found"); /* Test source location location - should fail on ELF only file */ - ret = so_info_lookup_source_location(so, FUNC_FOO_ADDR_ELF, &src_loc); - ok(ret == -1, "so_info_lookup_source_location - fail on ELF only file"); + ret = bin_info_lookup_source_location(bin, FUNC_FOO_ADDR_ELF, &src_loc); + ok(ret == -1, "bin_info_lookup_source_location - fail on ELF only file"); source_location_destroy(src_loc); - so_info_destroy(so); + bin_info_destroy(bin); } static -void test_so_info(const char *data_dir) +void test_bin_info(const char *data_dir) { int ret; char path[PATH_MAX]; char *func_name = NULL; - struct so_info *so = NULL; + struct bin_info *bin = NULL; struct source_location *src_loc = NULL; - diag("so-info tests - DWARF bundled with SO file"); + diag("bin-info tests - DWARF bundled with SO file"); snprintf(path, PATH_MAX, "%s/%s", data_dir, SO_NAME); - so = so_info_create(path, SO_LOW_ADDR, SO_MEMSZ, true); - ok(so != NULL, "so_info_create succesful"); - - /* Test so_info_has_address */ - ret = so_info_has_address(so, 0); - ok(ret == 0, "so_info_has_address - address under so's range"); - ret = so_info_has_address(so, SO_LOW_ADDR); - ok(ret == 1, "so_info_has_address - lower bound of so's range"); - ret = so_info_has_address(so, FUNC_FOO_ADDR); - ok(ret == 1, "so_info_has_address - address in so's range"); - ret = so_info_has_address(so, SO_LOW_ADDR + SO_MEMSZ - 1); - ok(ret == 1, "so_info_has_address - upper bound of so's range"); - ret = so_info_has_address(so, SO_LOW_ADDR + SO_MEMSZ); - ok(ret == 0, "so_info_has_address - address above so's range"); + bin = bin_info_create(path, SO_LOW_ADDR, SO_MEMSZ, true); + ok(bin != NULL, "bin_info_create succesful"); + + /* Test bin_info_has_address */ + ret = bin_info_has_address(bin, 0); + ok(ret == 0, "bin_info_has_address - address under so's range"); + ret = bin_info_has_address(bin, SO_LOW_ADDR); + ok(ret == 1, "bin_info_has_address - lower bound of so's range"); + ret = bin_info_has_address(bin, FUNC_FOO_ADDR); + ok(ret == 1, "bin_info_has_address - address in so's range"); + ret = bin_info_has_address(bin, SO_LOW_ADDR + SO_MEMSZ - 1); + ok(ret == 1, "bin_info_has_address - upper bound of so's range"); + ret = bin_info_has_address(bin, SO_LOW_ADDR + SO_MEMSZ); + ok(ret == 0, "bin_info_has_address - address above so's range"); /* Test function name lookup (with DWARF) */ - ret = so_info_lookup_function_name(so, FUNC_FOO_ADDR, &func_name); - ok(ret == 0, "so_info_lookup_function_name succesful"); + ret = bin_info_lookup_function_name(bin, FUNC_FOO_ADDR, &func_name); + ok(ret == 0, "bin_info_lookup_function_name succesful"); ok(strcmp(func_name, FUNC_FOO_NAME) == 0, - "so_info_lookup_function_name - correct func_name value"); + "bin_info_lookup_function_name - correct func_name value"); free(func_name); func_name = NULL; /* Test function name lookup - erroneous address */ - ret = so_info_lookup_function_name(so, 0, &func_name); + ret = bin_info_lookup_function_name(bin, 0, &func_name); ok(ret == -1 && func_name == NULL, - "so_info_lookup_function_name - fail on addr not found"); + "bin_info_lookup_function_name - fail on addr not found"); /* Test source location lookup */ - ret = so_info_lookup_source_location(so, FUNC_FOO_ADDR, &src_loc); - ok(ret == 0, "so_info_lookup_source_location succesful"); + ret = bin_info_lookup_source_location(bin, FUNC_FOO_ADDR, &src_loc); + ok(ret == 0, "bin_info_lookup_source_location succesful"); ok(src_loc->line_no == FUNC_FOO_LINE_NO, - "so_info_lookup_source_location - correct line_no"); + "bin_info_lookup_source_location - correct line_no"); ok(strcmp(src_loc->filename, FUNC_FOO_FILENAME) == 0, - "so_info_lookup_source_location - correct filename"); + "bin_info_lookup_source_location - correct filename"); source_location_destroy(src_loc); src_loc = NULL; /* Test source location lookup - inlined function */ - ret = so_info_lookup_source_location(so, FUNC_FOO_TP_ADDR, &src_loc); + ret = bin_info_lookup_source_location(bin, FUNC_FOO_TP_ADDR, &src_loc); ok(ret == 0, - "so_info_lookup_source_location (inlined func) succesful"); + "bin_info_lookup_source_location (inlined func) succesful"); ok(src_loc->line_no == FUNC_FOO_TP_LINE_NO, - "so_info_lookup_source_location (inlined func) - correct line_no"); + "bin_info_lookup_source_location (inlined func) - correct line_no"); ok(strcmp(src_loc->filename, FUNC_FOO_TP_FILENAME) == 0, - "so_info_lookup_source_location (inlined func) - correct filename"); + "bin_info_lookup_source_location (inlined func) - correct filename"); source_location_destroy(src_loc); src_loc = NULL; /* Test source location lookup - erroneous address */ - ret = so_info_lookup_source_location(so, 0, &src_loc); + ret = bin_info_lookup_source_location(bin, 0, &src_loc); ok(ret == -1 && src_loc == NULL, - "so_info_lookup_source_location - fail on addr not found"); + "bin_info_lookup_source_location - fail on addr not found"); - so_info_destroy(so); + bin_info_destroy(bin); } int main(int argc, char **argv) @@ -253,13 +253,13 @@ int main(int argc, char **argv) opt_debug_info_dir = argv[1]; } - ret = so_info_init(); - ok(ret == 0, "so_info_init succesful"); + ret = bin_info_init(); + ok(ret == 0, "bin_info_init succesful"); - test_so_info(opt_debug_info_dir); - test_so_info_elf(opt_debug_info_dir); - test_so_info_build_id(opt_debug_info_dir); - test_so_info_debug_link(opt_debug_info_dir); + test_bin_info(opt_debug_info_dir); + test_bin_info_elf(opt_debug_info_dir); + test_bin_info_build_id(opt_debug_info_dir); + test_bin_info_debug_link(opt_debug_info_dir); return EXIT_SUCCESS; } diff --git a/tests/lib/test_so_info_complete b/tests/lib/test_bin_info_complete similarity index 93% rename from tests/lib/test_so_info_complete rename to tests/lib/test_bin_info_complete index 771fbfb7..0f930109 100755 --- a/tests/lib/test_so_info_complete +++ b/tests/lib/test_bin_info_complete @@ -19,4 +19,4 @@ CURDIR=$(dirname $0)/ ROOTDIR=$CURDIR../.. -$CURDIR/test_so_info $ROOTDIR/tests/debuginfo-data +$CURDIR/test_bin_info $ROOTDIR/tests/debuginfo-data diff --git a/tests/tests_debuginfo b/tests/tests_debuginfo index 4917f448..df87fc1d 100644 --- a/tests/tests_debuginfo +++ b/tests/tests_debuginfo @@ -1,2 +1,2 @@ lib/test_dwarf_complete -lib/test_so_info_complete +lib/test_bin_info_complete -- 2.34.1