1
0
Fork 0
mirror of https://github.com/tobast/libunwind-eh_elf.git synced 2024-12-22 19:43:42 +01:00

eh_elf: fix memory map parsing problem

Now correctly parsed, but all unwinding tentatives end up returning -1
(ie mmap_entry not found)
This commit is contained in:
Théophile Bastian 2018-06-04 18:26:23 +02:00
parent 7a3518d325
commit 3691f0c18d
2 changed files with 14 additions and 6 deletions

View file

@ -4,6 +4,7 @@
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "libunwind_i.h"
static mmap_entry_t* _memory_map = NULL;
static size_t _memory_map_size = 0;
@ -42,8 +43,9 @@ int mmap_init_procdir(const char* procdir) {
int nb_entries = 0;
int lastch;
while((lastch = fgetc(map_handle)) != EOF) {
if(lastch == '\n')
if(lastch == '\n') {
nb_entries++;
}
}
rewind(map_handle);
_memory_map = (mmap_entry_t*) calloc(nb_entries, sizeof(mmap_entry_t));
@ -54,10 +56,15 @@ int mmap_init_procdir(const char* procdir) {
char is_x;
char path[256];
int cur_entry = 0;
while(fscanf(map_handle,
"%lX-%lX %*c%*c%c%*c %lX %*[0-9a-fA-F:] %ld %s",
&ip_beg, &ip_end, &is_x, &offset, &inode, path) != EOF)
int pos_before_path;
char* line = malloc(512 * sizeof(char));
size_t line_size = 512;
while(getline(&line, &line_size, map_handle) >= 0)
{
sscanf(line,
"%lX-%lX %*c%*c%c%*c %lX %*[0-9a-fA-F:] %ld %n",
&ip_beg, &ip_end, &is_x, &offset, &inode, &pos_before_path);
sscanf(line + pos_before_path, "%s", path);
if(cur_entry >= nb_entries) {
mmap_clear();
return -2; // Bad entry count, somehow
@ -78,6 +85,7 @@ int mmap_init_procdir(const char* procdir) {
cur_entry++;
}
free(line);
// Shrink _memory_map to only use up the number of relevant entries
assert(_memory_map_size >= cur_entry);

View file

@ -42,13 +42,13 @@ unw_init_local (unw_cursor_t *cursor, ucontext_t *uc)
PROTECTED int
unw_init_local (unw_cursor_t *cursor, ucontext_t *uc)
{
eh_elf_init_local();
struct cursor *c = (struct cursor *) cursor;
if (unlikely (!tdep_init_done))
tdep_init ();
eh_elf_init_local();
Debug (1, "(cursor=%p)\n", c);
c->dwarf.as = unw_local_addr_space;