bootstrap: Standardize on autoreconf -vi
[babeltrace.git] / lib / debuginfo.c
index 7d12ebd27da0fa66d38294e9efd53c623896dc8b..229307919f01ddd8e1d448b4c91b5ddbdc05c7e3 100644 (file)
 #include <babeltrace/types.h>
 #include <babeltrace/ctf-ir/metadata.h>
 #include <babeltrace/debuginfo.h>
-#include <babeltrace/so-info.h>
+#include <babeltrace/bin-info.h>
 #include <babeltrace/babeltrace-internal.h>
+#include <babeltrace/utils.h>
 
 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 *);
@@ -53,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;
@@ -63,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(
@@ -73,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
@@ -86,42 +87,12 @@ void debug_info_source_destroy(struct debug_info_source *debug_info_src)
        free(debug_info_src->func);
        free(debug_info_src->src_path);
        free(debug_info_src->bin_path);
+       free(debug_info_src->bin_loc);
        g_free(debug_info_src);
 }
 
-/*
- * Returns the location of a path's file (the last element of the path).
- * Returns the original path on error.
- */
 static
-const char *get_filename_from_path(const char *path)
-{
-       size_t i = strlen(path);
-
-       if (i == 0) {
-               goto end;
-       }
-
-       if (path[i - 1] == '/') {
-               /*
-                * Path ends with a trailing slash, no filename to return.
-                * Return the original path.
-                */
-               goto end;
-       }
-
-       while (i-- > 0) {
-               if (path[i] == '/') {
-                       path = &path[i + 1];
-                       goto end;
-               }
-       }
-end:
-       return path;
-}
-
-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;
@@ -135,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;
                }
@@ -159,21 +130,25 @@ struct debug_info_source *debug_info_source_create_from_so(struct so_info *so,
                        }
 
                        debug_info_src->short_src_path = get_filename_from_path(
-                                       src_loc->filename);
-
+                                       debug_info_src->src_path);
                }
 
                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;
                }
 
                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:
@@ -192,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) {
@@ -213,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;
        }
 
@@ -291,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;
                }
 
@@ -309,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,
@@ -405,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;
@@ -472,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);
@@ -500,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;
@@ -559,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;
@@ -572,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 *)
@@ -613,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;
@@ -631,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;
        }
 
@@ -641,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;
        }
 
@@ -666,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;
 
@@ -687,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)
@@ -715,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:
@@ -772,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);
This page took 0.029427 seconds and 4 git commands to generate.