mirror of
https://github.com/tobast/libunwind-eh_elf.git
synced 2024-11-26 00:57:39 +01:00
Use flags from eh_elfs
This commit is contained in:
parent
b47bfdd204
commit
e8941a4c73
2 changed files with 27 additions and 10 deletions
|
@ -1,7 +1,17 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
UNWF_RIP=0,
|
||||||
|
UNWF_RSP=1,
|
||||||
|
UNWF_RBP=2,
|
||||||
|
UNWF_RBX=3,
|
||||||
|
|
||||||
|
UNWF_ERROR=7
|
||||||
|
} unwind_flags_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uintptr_t rip, rsp, rbp;
|
uint8_t flags;
|
||||||
|
uintptr_t rip, rsp, rbp, rbx;
|
||||||
} unwind_context_t;
|
} unwind_context_t;
|
||||||
|
|
||||||
typedef uintptr_t (*deref_func_t)(uintptr_t);
|
typedef uintptr_t (*deref_func_t)(uintptr_t);
|
||||||
|
|
|
@ -58,8 +58,8 @@ static uintptr_t fetchw_here(uintptr_t addr) {
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
dwarf_loc_t of_eh_elf_loc(uintptr_t eh_elf_loc) {
|
dwarf_loc_t of_eh_elf_loc(uintptr_t eh_elf_loc, uint8_t flags, int flag_id) {
|
||||||
if(eh_elf_loc + 1 == 0) // Undefined
|
if((flags & (1 << flag_id)) == 0)
|
||||||
return DWARF_NULL_LOC;
|
return DWARF_NULL_LOC;
|
||||||
return DWARF_LOC(eh_elf_loc, DWARF_LOC_TYPE_VAL);
|
return DWARF_LOC(eh_elf_loc, DWARF_LOC_TYPE_VAL);
|
||||||
}
|
}
|
||||||
|
@ -106,6 +106,8 @@ int eh_elf_step_cursor(struct cursor *cursor) {
|
||||||
eh_elf_context.rsp = cursor->dwarf.cfa;
|
eh_elf_context.rsp = cursor->dwarf.cfa;
|
||||||
dwarf_get(&cursor->dwarf,
|
dwarf_get(&cursor->dwarf,
|
||||||
cursor->dwarf.loc[UNW_TDEP_BP], &eh_elf_context.rbp);
|
cursor->dwarf.loc[UNW_TDEP_BP], &eh_elf_context.rbp);
|
||||||
|
dwarf_get(&cursor->dwarf,
|
||||||
|
cursor->dwarf.loc[UNW_X86_64_RBX], &eh_elf_context.rbx);
|
||||||
|
|
||||||
// Set _fetch_state before passing fetchw_here
|
// Set _fetch_state before passing fetchw_here
|
||||||
_fetch_state.cursor = cursor;
|
_fetch_state.cursor = cursor;
|
||||||
|
@ -116,6 +118,7 @@ int eh_elf_step_cursor(struct cursor *cursor) {
|
||||||
ip - mmap_entry->offset,
|
ip - mmap_entry->offset,
|
||||||
eh_elf_context.rsp);
|
eh_elf_context.rsp);
|
||||||
|
|
||||||
|
eh_elf_context.flags = 0;
|
||||||
// Call fde_func
|
// Call fde_func
|
||||||
eh_elf_context = fde_func(
|
eh_elf_context = fde_func(
|
||||||
eh_elf_context,
|
eh_elf_context,
|
||||||
|
@ -127,11 +130,10 @@ int eh_elf_step_cursor(struct cursor *cursor) {
|
||||||
return -4;
|
return -4;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(eh_elf_context.rbp + 1 == 0
|
if(((eh_elf_context.flags & (1 << UNWF_ERROR))) != 0) {
|
||||||
&& eh_elf_context.rsp + 1 == 0
|
|
||||||
&& eh_elf_context.rip + 1 == 0) {
|
|
||||||
// Error, somehow
|
// Error, somehow
|
||||||
Debug(2, "eh_elf unwinding FAILED\n");
|
Debug(3, "eh_elf unwinding FAILED (fl=%02x), IP=0x%016lx\n",
|
||||||
|
eh_elf_context.flags, ip);
|
||||||
return -3;
|
return -3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,9 +152,14 @@ int eh_elf_step_cursor(struct cursor *cursor) {
|
||||||
for (int i = 0; i < DWARF_NUM_PRESERVED_REGS; ++i)
|
for (int i = 0; i < DWARF_NUM_PRESERVED_REGS; ++i)
|
||||||
cursor->dwarf.loc[i] = DWARF_NULL_LOC;
|
cursor->dwarf.loc[i] = DWARF_NULL_LOC;
|
||||||
|
|
||||||
cursor->dwarf.loc[UNW_TDEP_BP] = of_eh_elf_loc(eh_elf_context.rbp);
|
cursor->dwarf.loc[UNW_TDEP_BP] = of_eh_elf_loc(
|
||||||
cursor->dwarf.loc[UNW_TDEP_SP] = of_eh_elf_loc(eh_elf_context.rsp);
|
eh_elf_context.rbp, eh_elf_context.flags, UNWF_RBP);
|
||||||
cursor->dwarf.loc[UNW_TDEP_IP] = of_eh_elf_loc(eh_elf_context.rip);
|
cursor->dwarf.loc[UNW_TDEP_SP] = of_eh_elf_loc(
|
||||||
|
eh_elf_context.rsp, eh_elf_context.flags, UNWF_RSP);
|
||||||
|
cursor->dwarf.loc[UNW_TDEP_IP] = of_eh_elf_loc(
|
||||||
|
eh_elf_context.rip, eh_elf_context.flags, UNWF_RIP);
|
||||||
|
cursor->dwarf.loc[UNW_X86_64_RBX] = of_eh_elf_loc(
|
||||||
|
eh_elf_context.rbx, eh_elf_context.flags, UNWF_RBX);
|
||||||
cursor->dwarf.use_prev_instr = 0;
|
cursor->dwarf.use_prev_instr = 0;
|
||||||
|
|
||||||
cursor->frame_info.frame_type = UNW_X86_64_FRAME_GUESSED;
|
cursor->frame_info.frame_type = UNW_X86_64_FRAME_GUESSED;
|
||||||
|
|
Loading…
Reference in a new issue