Skip to content

Commit

Permalink
Fix ptrace library build on FreeBSD/x86_64.
Browse files Browse the repository at this point in the history
Restore FreeBSD _UPT_access_reg() implementation.
  • Loading branch information
lemul authored and bregma committed Jun 13, 2023
1 parent e3d35b6 commit dd5c2da
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion src/ptrace/_UPT_access_reg.c
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ _UPT_access_reg (unw_addr_space_t as, unw_regnum_t reg, unw_word_t *val,
Debug (1, "bad register %s [%u] (error: %s)\n", unw_regname(reg), reg, strerror (errno));
return -UNW_EBADREG;
}
#elif HAVE_DECL_PT_GETREGS
#elif defined(HAVE_DECL_PT_GETREGS) && defined(__linux__)
# include <sys/user.h>

int
Expand Down Expand Up @@ -359,6 +359,44 @@ _UPT_access_reg (unw_addr_space_t as, unw_regnum_t reg, unw_word_t *val,
Debug (1, "bad register %s [%u] (error: %s)\n", unw_regname(reg), reg, strerror (errno));
return -UNW_EBADREG;
}

#elif defined(HAVE_DECL_PT_GETREGS) && defined(__FreeBSD__)
int
_UPT_access_reg (unw_addr_space_t as, unw_regnum_t reg, unw_word_t *val,
int write, void *arg)
{
struct UPT_info *ui = arg;
pid_t pid = ui->pid;
gregset_t regs;
char *r;

#if UNW_DEBUG
Debug(16, "using getregs: reg: %s [%u], val: %lx, write: %u\n", unw_regname(reg), (unsigned) reg, (long) val, write);

if (write)
Debug (16, "%s [%u] <- %lx\n", unw_regname (reg), (unsigned) reg, (long) *val);
#endif

if ((unsigned) reg >= ARRAY_SIZE (_UPT_reg_offset))
{
errno = EINVAL;
goto badreg;
}
r = (char *)&regs + _UPT_reg_offset[reg];
if (ptrace(PT_GETREGS, pid, (caddr_t)&regs, 0) == -1)
goto badreg;
if (write) {
memcpy(r, val, sizeof(unw_word_t));
if (ptrace(PT_SETREGS, pid, (caddr_t)&regs, 0) == -1)
goto badreg;
} else
memcpy(val, r, sizeof(unw_word_t));
return 0;

badreg:
Debug (1, "bad register %s [%u] (error: %s)\n", unw_regname(reg), reg, strerror (errno));
return -UNW_EBADREG;
}
#else
#error Port me
#endif

0 comments on commit dd5c2da

Please sign in to comment.