diff --git a/breakpoint.c b/breakpoint.c index 83559b1..aae569d 100644 --- a/breakpoint.c +++ b/breakpoint.c @@ -25,6 +25,7 @@ #include #include +#include #include #include #include diff --git a/client/binfile.c b/client/binfile.c index 47f2a49..b1536fe 100644 --- a/client/binfile.c +++ b/client/binfile.c @@ -26,6 +26,7 @@ #include #include #include +#include #include "binfile.h" #include "process.h" @@ -150,7 +151,7 @@ struct rb_sym *bin_file_lookup(struct bin_file *binfile, bfd_vma addr, unsigned if (!name || !*name) name = "?"; else { - alloc = bfd_demangle(binfile->abfd, name, 27); + alloc = bfd_demangle(binfile->abfd, name, DMGL_TYPES | DMGL_VERBOSE | DMGL_ANSI | DMGL_PARAMS); if (alloc) name = alloc; } diff --git a/client/process.c b/client/process.c index a643abe..80c8204 100644 --- a/client/process.c +++ b/client/process.c @@ -79,6 +79,7 @@ struct map { unsigned long offset; unsigned long addr; unsigned long size; + unsigned long bias; char *filename; struct bin_file *binfile; unsigned int ignore:1; @@ -347,7 +348,7 @@ static struct rb_sym *resolv_address(struct process *process, bfd_vma addr) struct map *map = open_map(process, addr); if (map) { - sym = bin_file_lookup(map->binfile, addr, map->addr); + sym = bin_file_lookup(map->binfile, addr, map->bias); if (sym) return sym; } @@ -729,13 +730,14 @@ static int process_rb_insert_block(struct process *process, unsigned long addr, return 0; } -static struct map *_process_add_map(struct process *process, unsigned long addr, unsigned long offset, unsigned long size, const char *filename, size_t len, struct bin_file *binfile) +static struct map *_process_add_map(struct process *process, unsigned long addr, unsigned long offset, unsigned long size, unsigned long bias, const char *filename, size_t len, struct bin_file *binfile) { struct map *map = malloc(sizeof(*map)); map->addr = addr; map->offset = offset; map->size = size; + map->bias = bias; map->filename = malloc(len + 1); map->binfile = binfile; map->ignore = 0; @@ -764,8 +766,9 @@ void process_add_map(struct process *process, void *payload, uint32_t payload_le uint64_t addr = process->val64(mt_map->addr); uint64_t offset = process->val64(mt_map->offset); uint64_t size = process->val64(mt_map->size); + uint64_t bias = process->val64(mt_map->bias); - _process_add_map(process, addr, offset, size, mt_map->filename, payload_len - sizeof(*mt_map), NULL); + _process_add_map(process, addr, offset, size, bias, mt_map->filename, payload_len - sizeof(*mt_map), NULL); } static void _process_del_map(struct map *map) @@ -921,7 +924,7 @@ void process_duplicate(struct process *process, struct process *copy) list_for_each(it, ©->map_list) { struct map *map = container_of(it, struct map, list); - _process_add_map(process, map->addr, map->offset, map->size, map->filename, strlen(map->filename), map->binfile); + _process_add_map(process, map->addr, map->offset, map->size, map->bias, map->filename, strlen(map->filename), map->binfile); } process->total_allocations = copy->total_allocations; diff --git a/dict.c b/dict.c index ff19789..3246fd1 100644 --- a/dict.c +++ b/dict.c @@ -25,6 +25,7 @@ #include #include #include +#include #include "common.h" #include "dict.h" diff --git a/dwarf.c b/dwarf.c index 86994c1..6f7fcdc 100644 --- a/dwarf.c +++ b/dwarf.c @@ -36,6 +36,7 @@ #include #include #include +#include #include "backend.h" #include "common.h" diff --git a/event.c b/event.c index d93ed61..cf44e1d 100644 --- a/event.c +++ b/event.c @@ -155,7 +155,7 @@ fail: static void handle_signal(struct task *task) { if (unlikely(options.verbose > 1)) { - if (task->event.e_un.signum && (task->event.e_un.signum != SIGSTOP || !task->was_stopped)) + if (task->event.e_un.signum && task->event.e_un.signum != SIGSTOP) fprintf(stderr, "+++ process pid=%d signal %d: %s +++\n", task->pid, task->event.e_un.signum, strsignal(task->event.e_un.signum)); } diff --git a/library.h b/library.h index 84d753a..3d2e667 100644 --- a/library.h +++ b/library.h @@ -63,6 +63,7 @@ struct libref { unsigned long load_offset; unsigned long load_addr; unsigned long load_size; + unsigned long bias; /* mapped image */ void *image_addr; diff --git a/memtrace.h b/memtrace.h index b215640..15a9a0e 100644 --- a/memtrace.h +++ b/memtrace.h @@ -31,7 +31,7 @@ #define IS64BIT 0 #endif -#define MEMTRACE_SI_VERSION 7 +#define MEMTRACE_SI_VERSION 8 #define MEMTRACE_SI_FORK 1 #define MEMTRACE_SI_EXEC 2 @@ -135,6 +135,7 @@ struct __attribute__((packed)) mt_map_payload { uint64_t addr; uint64_t offset; uint64_t size; + uint64_t bias; char filename[0]; }; diff --git a/mtelf.c b/mtelf.c index cbbb6dd..00709f4 100644 --- a/mtelf.c +++ b/mtelf.c @@ -247,8 +247,10 @@ static int elf_lib_init(struct mt_elf *mte, struct task *task, struct libref *li libref->load_offset = mte->txt_hdr.p_offset; libref->load_addr = mte->txt_hdr.p_vaddr + mte->bias; libref->load_size = mte->txt_hdr.p_filesz; + libref->bias = mte->bias; libref->seg_offset = mte->eh_hdr.p_offset; libref->gp = mte->pltgot; + libref->key = mte->dyn; #ifdef __arm__ if (mte->exidx_hdr.p_filesz) { @@ -288,7 +290,6 @@ static int elf_read(struct mt_elf *mte, struct task *task, const char *filename, memset(&mte->txt_hdr, 0, sizeof(mte->txt_hdr)); memset(&mte->eh_hdr, 0, sizeof(mte->eh_hdr)); - memset(&mte->dyn_hdr, 0, sizeof(mte->dyn_hdr)); memset(&mte->exidx_hdr, 0, sizeof(mte->exidx_hdr)); for (i = 0; gelf_getphdr(mte->elf, i, &phdr) != NULL; ++i) { @@ -312,6 +313,9 @@ static int elf_read(struct mt_elf *mte, struct task *task, const char *filename, case PT_INTERP: mte->interp = phdr.p_vaddr + bias; break; + case PT_DYNAMIC: + mte->dyn = phdr.p_vaddr + bias; + break; default: break; } @@ -511,8 +515,6 @@ struct libref *elf_read_main_binary(struct task *task) mte.bias = (GElf_Addr) (uintptr_t) entry - mte.ehdr.e_entry; mte.entry_addr = (GElf_Addr) (uintptr_t) entry; - libref->key = ARCH_ADDR_T(mte.bias); - if (elf_lib_init(&mte, task, libref)) goto fail3; @@ -541,8 +543,6 @@ struct libref *elf_read_main_binary(struct task *task) mte_ld.bias = (GElf_Addr)base; mte_ld.entry_addr = mte_ld.ehdr.e_entry + (GElf_Addr)base; - libref->key = ARCH_ADDR_T(mte_ld.bias); - ret = elf_lib_init(&mte_ld, task, libref); if (!ret) { library_add(task, libref); diff --git a/mtelf.h b/mtelf.h index 0578525..4030f44 100644 --- a/mtelf.h +++ b/mtelf.h @@ -48,7 +48,7 @@ struct mt_elf { GElf_Addr interp; GElf_Phdr txt_hdr; GElf_Phdr eh_hdr; - GElf_Phdr dyn_hdr; + GElf_Addr dyn; GElf_Phdr exidx_hdr; GElf_Addr pltgot; }; diff --git a/report.c b/report.c index c25dfa5..4dae89d 100644 --- a/report.c +++ b/report.c @@ -388,6 +388,7 @@ int _report_map(struct task *task, struct library *lib, enum mt_operation op) payload->addr = libref->load_addr; payload->offset = libref->load_offset; payload->size = libref->load_size; + payload->bias = libref->bias; memcpy(payload->filename, libref->filename, len); diff --git a/sysdeps/linux-gnu/proc.c b/sysdeps/linux-gnu/proc.c index ba8c1ff..8c09312 100644 --- a/sysdeps/linux-gnu/proc.c +++ b/sysdeps/linux-gnu/proc.c @@ -396,7 +396,7 @@ static void linkmap_add(struct task *task, struct lt_r_debug_64 *dbg) } /* Do we have that library already? */ - lib = library_find_with_key(&task->libraries_list, ARCH_ADDR_T(rlm.l_addr)); + lib = library_find_with_key(&task->libraries_list, ARCH_ADDR_T(rlm.l_ld)); if (lib) continue; @@ -426,8 +426,6 @@ static void linkmap_add(struct task *task, struct lt_r_debug_64 *dbg) continue; } - libref->key = ARCH_ADDR_T(rlm.l_addr); - library_add(task, libref); } diff --git a/task.c b/task.c index 8b6b242..3a9377a 100644 --- a/task.c +++ b/task.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include