1 #include <elfutils/libdwfl.h> 2 #include "../../util/unwind-libdw.h" 3 #include "../../util/perf_regs.h" 4 #include "../../util/event.h" 5 6 bool libdw__arch_set_initial_registers(Dwfl_Thread *thread, void *arg) 7 { 8 struct unwind_info *ui = arg; 9 struct regs_dump *user_regs = &ui->sample->user_regs; 10 Dwarf_Word dwarf_regs[17]; 11 unsigned nregs; 12 13 #define REG(r) ({ \ 14 Dwarf_Word val = 0; \ 15 perf_reg_value(&val, user_regs, PERF_REG_X86_##r); \ 16 val; \ 17 }) 18 19 if (user_regs->abi == PERF_SAMPLE_REGS_ABI_32) { 20 dwarf_regs[0] = REG(AX); 21 dwarf_regs[1] = REG(CX); 22 dwarf_regs[2] = REG(DX); 23 dwarf_regs[3] = REG(BX); 24 dwarf_regs[4] = REG(SP); 25 dwarf_regs[5] = REG(BP); 26 dwarf_regs[6] = REG(SI); 27 dwarf_regs[7] = REG(DI); 28 dwarf_regs[8] = REG(IP); 29 nregs = 9; 30 } else { 31 dwarf_regs[0] = REG(AX); 32 dwarf_regs[1] = REG(DX); 33 dwarf_regs[2] = REG(CX); 34 dwarf_regs[3] = REG(BX); 35 dwarf_regs[4] = REG(SI); 36 dwarf_regs[5] = REG(DI); 37 dwarf_regs[6] = REG(BP); 38 dwarf_regs[7] = REG(SP); 39 dwarf_regs[8] = REG(R8); 40 dwarf_regs[9] = REG(R9); 41 dwarf_regs[10] = REG(R10); 42 dwarf_regs[11] = REG(R11); 43 dwarf_regs[12] = REG(R12); 44 dwarf_regs[13] = REG(R13); 45 dwarf_regs[14] = REG(R14); 46 dwarf_regs[15] = REG(R15); 47 dwarf_regs[16] = REG(IP); 48 nregs = 17; 49 } 50 51 return dwfl_thread_state_registers(thread, 0, nregs, dwarf_regs); 52 } 53