From 1ee9a2e1e1979beddeee67829b79ac5789a08cd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophile=20Bastian?= Date: Mon, 11 Jun 2018 16:15:03 +0200 Subject: [PATCH] eh_elf: tentative changes to integrate --- util/unwind-libunwind-local.c | 39 +++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/util/unwind-libunwind-local.c b/util/unwind-libunwind-local.c index af87304..5017bb4 100644 --- a/util/unwind-libunwind-local.c +++ b/util/unwind-libunwind-local.c @@ -472,6 +472,39 @@ get_proc_name(unw_addr_space_t __maybe_unused as, return -UNW_EINVAL; } +static void +get_mmap(unw_mmap_entry_t* entries, size_t* count, void* arg) { + struct unwind_info* unw_info = arg; + struct map_groups* mgroups = unw_info->thread->mg; + int id; + + // == Count entries == + *count = 0; + for(struct map* map = map_groups__first(mgroups, MAP__FUNCTION); + map; + map = map_groups__next(map)) + { + ++(*count); + } + + // == Allocate == + entries = (unw_mmap_entry_t*) + malloc(sizeof(unw_mmap_entry_t) * (*count)); // Will be free'd + + // == Fill entries == + id = 0; + for(struct map* map = map_groups__first(mgroups, MAP__FUNCTION); + map; + map = map_groups__next(map), ++id) + { + entries[id].beg_ip = map->start; + entries[id].end_ip = map->end; + entries[id].offset = map->start - map->map_ip(map, map->start); + entries[id].object_name = malloc(strlen(map->dso->long_name) + 1); + strcpy(entries[id].object_name, map->dso->long_name); + } +} + static int access_dso_mem(struct unwind_info *ui, unw_word_t addr, unw_word_t *data) { @@ -627,6 +660,12 @@ static unw_accessors_t accessors = { .access_fpreg = access_fpreg, .resume = resume, .get_proc_name = get_proc_name, + .eh_elf_init = { + .init_mode = UNW_EH_ELF_INIT_MMAP, + .init_data = { + .get_mmap = get_mmap, + } + } }; static int _unwind__prepare_access(struct thread *thread)