From 9d325e17868ae67a5617b4fe585fee65d790d750 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Fri, 5 May 2017 12:53:54 -0400 Subject: [PATCH] debug-info.debug-info: do not use global opt_* symbols anymore MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Philippe Proulx Signed-off-by: Jérémie Galarneau --- plugins/debug-info/bin-info.c | 23 ++++++++++++++++------- plugins/debug-info/bin-info.h | 8 +++++++- plugins/debug-info/copy.c | 2 +- plugins/debug-info/debug-info.c | 9 +++++++-- plugins/debug-info/debug-info.h | 2 +- plugins/debug-info/plugin.c | 2 +- 6 files changed, 33 insertions(+), 13 deletions(-) diff --git a/plugins/debug-info/bin-info.c b/plugins/debug-info/bin-info.c index 81bfe63e..170b351f 100644 --- a/plugins/debug-info/bin-info.c +++ b/plugins/debug-info/bin-info.c @@ -66,7 +66,8 @@ int bin_info_init(void) BT_HIDDEN struct bin_info *bin_info_create(const char *path, uint64_t low_addr, - uint64_t memsz, bool is_pic) + uint64_t memsz, bool is_pic, const char *debug_info_dir, + const char *target_prefix) { struct bin_info *bin = NULL; @@ -79,8 +80,8 @@ struct bin_info *bin_info_create(const char *path, uint64_t low_addr, goto error; } - if (opt_debug_info_target_prefix) { - bin->elf_path = g_build_path("/", opt_debug_info_target_prefix, + if (target_prefix) { + bin->elf_path = g_build_path("/", target_prefix, path, NULL); } else { bin->elf_path = strdup(path); @@ -90,6 +91,13 @@ struct bin_info *bin_info_create(const char *path, uint64_t low_addr, goto error; } + if (debug_info_dir) { + bin->debug_info_dir = strdup(debug_info_dir); + if (!bin->debug_info_dir) { + goto error; + } + } + bin->is_pic = is_pic; bin->memsz = memsz; bin->low_addr = low_addr; @@ -111,6 +119,7 @@ void bin_info_destroy(struct bin_info *bin) dwarf_end(bin->dwarf_info); + free(bin->debug_info_dir); free(bin->elf_path); free(bin->dwarf_path); g_free(bin->build_id); @@ -270,7 +279,7 @@ int bin_info_set_dwarf_info_build_id(struct bin_info *bin) goto error; } - dbg_dir = opt_debug_info_dir ? : DEFAULT_DEBUG_DIR; + dbg_dir = bin->debug_info_dir ? : DEFAULT_DEBUG_DIR; /* 2 characters per byte printed in hex, +1 for '/' and +1 for '\0' */ build_id_file_len = (2 * bin->build_id_len) + 1 + @@ -372,7 +381,7 @@ int bin_info_set_dwarf_info_debug_link(struct bin_info *bin) goto error; } - dbg_dir = opt_debug_info_dir ? : DEFAULT_DEBUG_DIR; + dbg_dir = bin->debug_info_dir ? : DEFAULT_DEBUG_DIR; dir_name = dirname(bin->elf_path); if (!dir_name) { @@ -909,8 +918,8 @@ error: } BT_HIDDEN -int bin_info_lookup_function_name(struct bin_info *bin, uint64_t addr, - char **func_name) +int bin_info_lookup_function_name(struct bin_info *bin, + uint64_t addr, char **func_name) { int ret = 0; char *_func_name = NULL; diff --git a/plugins/debug-info/bin-info.h b/plugins/debug-info/bin-info.h index c4da928a..05d0d797 100644 --- a/plugins/debug-info/bin-info.h +++ b/plugins/debug-info/bin-info.h @@ -60,6 +60,8 @@ struct bin_info { /* FDs to ELF and DWARF files. */ int elf_fd; int dwarf_fd; + /* Configuration. */ + char *debug_info_dir; /* Denotes whether the executable is position independent code. */ bool is_pic:1; /* @@ -92,12 +94,16 @@ int bin_info_init(void); * @param memsz In-memory size of the executable * @param is_pic Whether the executable is position independent * code (PIC) + * @param debug_info_dir Directory containing debug info or NULL. + * @param target_prefix Path to the root file system of the target + * or NULL. * @returns Pointer to the new bin_info on success, * NULL on failure. */ BT_HIDDEN struct bin_info *bin_info_create(const char *path, uint64_t low_addr, - uint64_t memsz, bool is_pic); + uint64_t memsz, bool is_pic, const char *debug_info_dir, + const char *target_prefix); /** * Destroy the given bin_info instance diff --git a/plugins/debug-info/copy.c b/plugins/debug-info/copy.c index 824774ff..2689a703 100644 --- a/plugins/debug-info/copy.c +++ b/plugins/debug-info/copy.c @@ -479,7 +479,7 @@ struct debug_info *insert_new_debug_info(struct debug_info_iterator *debug_it, } BT_PUT(field); - debug_info = debug_info_create(); + debug_info = debug_info_create(debug_it->debug_info_component); if (!debug_info) { fprintf(debug_it->err, "[error] %s in %s:%d\n", __func__, __FILE__, __LINE__); diff --git a/plugins/debug-info/debug-info.c b/plugins/debug-info/debug-info.c index 93e51081..bc8fa6dd 100644 --- a/plugins/debug-info/debug-info.c +++ b/plugins/debug-info/debug-info.c @@ -47,6 +47,8 @@ struct proc_debug_info_sources { }; struct debug_info { + struct debug_info_component *comp; + /* * Hash table of VPIDs (pointer to int64_t) to * (struct ctf_proc_debug_infos*); owned by debug_info. @@ -320,7 +322,7 @@ end: } BT_HIDDEN -struct debug_info *debug_info_create(void) +struct debug_info *debug_info_create(struct debug_info_component *comp) { int ret; struct debug_info *debug_info; @@ -337,6 +339,7 @@ struct debug_info *debug_info_create(void) goto error; } + debug_info->comp = comp; ret = debug_info_init(debug_info); if (ret) { goto error; @@ -600,7 +603,9 @@ void handle_bin_info_event(FILE *err, struct debug_info *debug_info, goto end; } - bin = bin_info_create(path, baddr, memsz, is_pic); + bin = bin_info_create(path, baddr, memsz, is_pic, + debug_info->comp->arg_debug_dir, + debug_info->comp->arg_target_prefix); if (!bin) { goto end; } diff --git a/plugins/debug-info/debug-info.h b/plugins/debug-info/debug-info.h index 974e5c01..41618b0a 100644 --- a/plugins/debug-info/debug-info.h +++ b/plugins/debug-info/debug-info.h @@ -80,7 +80,7 @@ struct debug_info_source { }; BT_HIDDEN -struct debug_info *debug_info_create(void); +struct debug_info *debug_info_create(struct debug_info_component *comp); BT_HIDDEN void debug_info_destroy(struct debug_info *debug_info); diff --git a/plugins/debug-info/plugin.c b/plugins/debug-info/plugin.c index c9ae94fa..85b12a67 100644 --- a/plugins/debug-info/plugin.c +++ b/plugins/debug-info/plugin.c @@ -476,7 +476,7 @@ error: /* Initialize plug-in entry points. */ BT_PLUGIN(debug_info); BT_PLUGIN_DESCRIPTION("Babeltrace Debug Informations Plug-In."); -BT_PLUGIN_AUTHOR("Jérémie Galarneau"); +BT_PLUGIN_AUTHOR("Julien Desfossez"); BT_PLUGIN_LICENSE("MIT"); BT_PLUGIN_FILTER_COMPONENT_CLASS(debug_info, debug_info_iterator_next); -- 2.34.1