X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=blobdiff_plain;f=lib%2Fdebuginfo.c;h=229307919f01ddd8e1d448b4c91b5ddbdc05c7e3;hp=4284f8e15d1d47e0d47029d355895983f0bf4371;hb=7d7466d89f0d46afc31a1520903b9f9e2aa183b1;hpb=71235b6d1dbc98345dcfa0d01a4aadf66fc24b6e diff --git a/lib/debuginfo.c b/lib/debuginfo.c index 4284f8e1..22930791 100644 --- a/lib/debuginfo.c +++ b/lib/debuginfo.c @@ -4,6 +4,7 @@ * Copyright (c) 2015 EfficiOS Inc. and Linux Foundation * Copyright (c) 2015 Philippe Proulx * Copyright (c) 2015 Antoine Busque + * Copyright (c) 2016 Jérémie Galarneau * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,14 +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 *); @@ -51,7 +54,7 @@ struct debug_info { * (struct ctf_proc_debug_infos*); owned by debug_info. */ GHashTable *vpid_to_proc_dbg_info_src; - GQuark q_statedump_soinfo; + GQuark q_statedump_bin_info; GQuark q_statedump_debug_link; GQuark q_statedump_build_id; GQuark q_statedump_start; @@ -61,8 +64,8 @@ struct debug_info { static int debug_info_init(struct debug_info *info) { - info->q_statedump_soinfo = g_quark_from_string( - "lttng_ust_statedump:soinfo"); + info->q_statedump_bin_info = g_quark_from_string( + "lttng_ust_statedump:bin_info"); info->q_statedump_debug_link = g_quark_from_string( "lttng_ust_statedump:debug_link)"); info->q_statedump_build_id = g_quark_from_string( @@ -71,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 @@ -82,12 +85,14 @@ void debug_info_source_destroy(struct debug_info_source *debug_info_src) } free(debug_info_src->func); - free(debug_info_src->filename); + free(debug_info_src->src_path); + free(debug_info_src->bin_path); + free(debug_info_src->bin_loc); g_free(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; @@ -101,36 +106,51 @@ 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) { - goto end; - } - - /* Lookup source location */ - ret = so_info_lookup_source_location(so, ip, &src_loc); - if (ret) { - goto error; + if (!bin->is_elf_only) { + /* Lookup source location */ + ret = bin_info_lookup_source_location(bin, ip, &src_loc); + if (ret) { + goto error; + } } if (src_loc) { debug_info_src->line_no = src_loc->line_no; if (src_loc->filename) { - debug_info_src->filename = strdup(src_loc->filename); - - if (!debug_info_src->filename) { + debug_info_src->src_path = strdup(src_loc->filename); + if (!debug_info_src->src_path) { goto error; } + + debug_info_src->short_src_path = get_filename_from_path( + debug_info_src->src_path); } source_location_destroy(src_loc); } + if (bin->elf_path) { + debug_info_src->bin_path = strdup(bin->elf_path); + if (!debug_info_src->bin_path) { + goto error; + } + + debug_info_src->short_bin_path = get_filename_from_path( + debug_info_src->bin_path); + + ret = bin_info_get_bin_loc(bin, ip, &(debug_info_src->bin_loc)); + if (ret) { + goto error; + } + } + end: return debug_info_src; @@ -147,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) { @@ -168,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; } @@ -246,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; } @@ -264,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, @@ -360,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; @@ -427,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); @@ -455,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; @@ -514,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; @@ -527,28 +547,30 @@ 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; } static -void handle_statedump_soinfo_event(struct debug_info *debug_info, - struct ctf_event_definition *event_def) +void handle_bin_info_event(struct debug_info *debug_info, + struct ctf_event_definition *event_def, bool has_pic_field) { struct bt_definition *baddr_def = NULL; struct bt_definition *memsz_def = NULL; - struct bt_definition *sopath_def = NULL; + struct bt_definition *path_def = NULL; + struct bt_definition *is_pic_def = NULL; struct bt_definition *vpid_def = NULL; 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 *sopath; + const char *path; gpointer key = NULL; + bool is_pic; event_fields_def = (struct bt_definition *) event_def->event_fields; sec_def = (struct bt_definition *) @@ -568,11 +590,30 @@ void handle_statedump_soinfo_event(struct debug_info *debug_info, goto end; } - sopath_def = bt_lookup_definition(event_fields_def, "_sopath"); - if (!sopath_def) { + path_def = bt_lookup_definition(event_fields_def, "_path"); + if (!path_def) { goto end; } + if (has_pic_field) { + is_pic_def = bt_lookup_definition(event_fields_def, "_is_pic"); + if (!is_pic_def) { + goto end; + } + + if (is_pic_def->declaration->id != CTF_TYPE_INTEGER) { + goto end; + } + + is_pic = (bt_get_unsigned_int(is_pic_def) == 1); + } else { + /* + * dlopen has no is_pic field, because the shared + * object is always PIC. + */ + is_pic = true; + } + vpid_def = bt_lookup_definition(sec_def, "_vpid"); if (!vpid_def) { goto end; @@ -586,7 +627,7 @@ void handle_statedump_soinfo_event(struct debug_info *debug_info, goto end; } - if (sopath_def->declaration->id != CTF_TYPE_STRING) { + if (path_def->declaration->id != CTF_TYPE_STRING) { goto end; } @@ -596,10 +637,10 @@ void handle_statedump_soinfo_event(struct debug_info *debug_info, baddr = bt_get_unsigned_int(baddr_def); memsz = bt_get_unsigned_int(memsz_def); - sopath = bt_get_string(sopath_def); + path = bt_get_string(path_def); vpid = bt_get_signed_int(vpid_def); - if (!sopath) { + if (!path) { goto end; } @@ -621,19 +662,19 @@ void handle_statedump_soinfo_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(sopath, baddr, memsz); - 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; @@ -642,6 +683,21 @@ end: return; } +static inline +void handle_statedump_bin_info_event(struct debug_info *debug_info, + struct ctf_event_definition *event_def) +{ + handle_bin_info_event(debug_info, event_def, true); +} + +static inline +void handle_dlopen_event(struct debug_info *debug_info, + struct ctf_event_definition *event_def) +{ + handle_bin_info_event(debug_info, event_def, false); +} + + static void handle_statedump_start(struct debug_info *debug_info, struct ctf_event_definition *event_def) @@ -670,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: @@ -727,10 +783,11 @@ void debug_info_handle_event(struct debug_info *debug_info, event_class = g_ptr_array_index(stream_class->events_by_id, event->stream->event_id); - if (event_class->name == debug_info->q_statedump_soinfo || - event_class->name == debug_info->q_dl_open) { - /* State dump/dlopen() */ - handle_statedump_soinfo_event(debug_info, event); + if (event_class->name == debug_info->q_statedump_bin_info) { + /* State dump */ + handle_statedump_bin_info_event(debug_info, event); + } else if (event_class->name == debug_info->q_dl_open) { + handle_dlopen_event(debug_info, event); } else if (event_class->name == debug_info->q_statedump_start) { /* Start state dump */ handle_statedump_start(debug_info, event);