Module Name: src
Committed By: christos
Date: Fri Sep 25 16:07:32 UTC 2015
Modified Files:
src/external/bsd/libproc/dist: libproc.h proc_bkpt.c proc_regs.c
src/external/bsd/libproc/dist/tests: proc_test.c
Log Message:
Add a proc_breakpoint_t and a proc_regval_t to abstract some types.
To generate a diff of this commit:
cvs rdiff -u -r1.1.1.1 -r1.2 src/external/bsd/libproc/dist/libproc.h
cvs rdiff -u -r1.2 -r1.3 src/external/bsd/libproc/dist/proc_bkpt.c \
src/external/bsd/libproc/dist/proc_regs.c
cvs rdiff -u -r1.3 -r1.4 src/external/bsd/libproc/dist/tests/proc_test.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/external/bsd/libproc/dist/libproc.h
diff -u src/external/bsd/libproc/dist/libproc.h:1.1.1.1 src/external/bsd/libproc/dist/libproc.h:1.2
--- src/external/bsd/libproc/dist/libproc.h:1.1.1.1 Thu Sep 24 10:05:35 2015
+++ src/external/bsd/libproc/dist/libproc.h Fri Sep 25 12:07:32 2015
@@ -36,6 +36,7 @@
#include <gelf.h>
#include <rtld_db.h>
#include <limits.h>
+#include <sys/ptrace.h>
struct ctf_file;
struct proc_handle;
@@ -113,6 +114,12 @@ typedef struct lwpstatus {
#define FLTBPT -1
} lwpstatus_t;
+typedef struct {
+ uint8_t data[PTRACE_BREAKPOINT_SIZE];
+} proc_breakpoint_t;
+
+typedef unsigned long proc_regvalue_t;
+
/* Function prototype definitions. */
__BEGIN_DECLS
@@ -145,12 +152,12 @@ const lwpstatus_t *proc_getlwpstatus(str
void proc_free(struct proc_handle *);
rd_agent_t *proc_rdagent(struct proc_handle *);
void proc_updatesyms(struct proc_handle *);
-int proc_bkptset(struct proc_handle *, uintptr_t, unsigned long *);
-int proc_bkptdel(struct proc_handle *, uintptr_t, unsigned long);
+int proc_bkptset(struct proc_handle *, uintptr_t, proc_breakpoint_t *);
+int proc_bkptdel(struct proc_handle *, uintptr_t, proc_breakpoint_t *);
void proc_bkptregadj(unsigned long *);
-int proc_bkptexec(struct proc_handle *, unsigned long);
-int proc_regget(struct proc_handle *, proc_reg_t, unsigned long *);
-int proc_regset(struct proc_handle *, proc_reg_t, unsigned long);
+int proc_bkptexec(struct proc_handle *, proc_breakpoint_t *);
+int proc_regget(struct proc_handle *, proc_reg_t, proc_regvalue_t *);
+int proc_regset(struct proc_handle *, proc_reg_t, proc_regvalue_t);
__END_DECLS
Index: src/external/bsd/libproc/dist/proc_bkpt.c
diff -u src/external/bsd/libproc/dist/proc_bkpt.c:1.2 src/external/bsd/libproc/dist/proc_bkpt.c:1.3
--- src/external/bsd/libproc/dist/proc_bkpt.c:1.2 Thu Sep 24 10:12:48 2015
+++ src/external/bsd/libproc/dist/proc_bkpt.c Fri Sep 25 12:07:32 2015
@@ -31,7 +31,7 @@
#ifdef __FBSDID
__FBSDID("$FreeBSD: head/lib/libproc/proc_bkpt.c 287106 2015-08-24 12:17:15Z andrew $");
#else
-__RCSID("$NetBSD: proc_bkpt.c,v 1.2 2015/09/24 14:12:48 christos Exp $");
+__RCSID("$NetBSD: proc_bkpt.c,v 1.3 2015/09/25 16:07:32 christos Exp $");
#endif
#include <sys/types.h>
@@ -39,6 +39,7 @@ __RCSID("$NetBSD: proc_bkpt.c,v 1.2 2015
#include <sys/wait.h>
#include <assert.h>
+#include <string.h>
#include <err.h>
#include <errno.h>
#include <inttypes.h>
@@ -46,26 +47,7 @@ __RCSID("$NetBSD: proc_bkpt.c,v 1.2 2015
#include <stdio.h>
#include "_libproc.h"
-#if defined(__aarch64__)
-#define AARCH64_BRK 0xd4200000
-#define AARCH64_BRK_IMM16_SHIFT 5
-#define AARCH64_BRK_IMM16_VAL (0xd << AARCH64_BRK_IMM16_SHIFT)
-#define BREAKPOINT_INSTR (AARCH64_BRK | AARCH64_BRK_IMM16_VAL)
-#define BREAKPOINT_INSTR_SZ 4
-#elif defined(__amd64__) || defined(__i386__)
-#define BREAKPOINT_INSTR 0xcc /* int 0x3 */
-#define BREAKPOINT_INSTR_SZ 1
-#define BREAKPOINT_ADJUST_SZ BREAKPOINT_INSTR_SZ
-#elif defined(__arm__)
-#define BREAKPOINT_INSTR 0xe7ffffff /* bkpt */
-#define BREAKPOINT_INSTR_SZ 4
-#elif defined(__mips__)
-#define BREAKPOINT_INSTR 0xd /* break */
-#define BREAKPOINT_INSTR_SZ 4
-#elif defined(__powerpc__)
-#define BREAKPOINT_INSTR 0x7fe00008 /* trap */
-#define BREAKPOINT_INSTR_SZ 4
-#else
+#ifndef PTRACE_BREAKPOINT
#error "Add support for your architecture"
#endif
@@ -90,13 +72,13 @@ proc_stop(struct proc_handle *phdl)
int
proc_bkptset(struct proc_handle *phdl, uintptr_t address,
- unsigned long *saved)
+ proc_breakpoint_t *saved)
{
struct ptrace_io_desc piod;
unsigned long paddr, caddr;
int ret = 0, stopped;
+ proc_breakpoint_t copy;
- *saved = 0;
if (phdl->status == PS_DEAD || phdl->status == PS_UNDEAD ||
phdl->status == PS_IDLE) {
errno = ENOENT;
@@ -119,24 +101,22 @@ proc_bkptset(struct proc_handle *phdl, u
paddr = 0;
piod.piod_op = PIOD_READ_I;
piod.piod_offs = (void *)caddr;
- piod.piod_addr = &paddr;
- piod.piod_len = BREAKPOINT_INSTR_SZ;
+ piod.piod_addr = (void *)saved->data;
+ piod.piod_len = sizeof(saved->data);
if (ptrace(PT_IO, proc_getpid(phdl), (caddr_t)&piod, 0) < 0) {
DPRINTF("ERROR: couldn't read instruction at address 0x%"
PRIuPTR, address);
ret = -1;
goto done;
}
- *saved = paddr;
/*
* Write a breakpoint instruction to that address.
*/
caddr = address;
- paddr = BREAKPOINT_INSTR;
piod.piod_op = PIOD_WRITE_I;
piod.piod_offs = (void *)caddr;
- piod.piod_addr = &paddr;
- piod.piod_len = BREAKPOINT_INSTR_SZ;
+ piod.piod_addr = (void *)PTRACE_BREAKPOINT;
+ piod.piod_len = sizeof(PTRACE_BREAKPOINT);
if (ptrace(PT_IO, proc_getpid(phdl), (caddr_t)&piod, 0) < 0) {
DPRINTF("ERROR: couldn't write instruction at address 0x%"
PRIuPTR, address);
@@ -154,7 +134,7 @@ done:
int
proc_bkptdel(struct proc_handle *phdl, uintptr_t address,
- unsigned long saved)
+ proc_breakpoint_t *saved)
{
struct ptrace_io_desc piod;
unsigned long paddr, caddr;
@@ -179,11 +159,10 @@ proc_bkptdel(struct proc_handle *phdl, u
* Overwrite the breakpoint instruction that we setup previously.
*/
caddr = address;
- paddr = saved;
piod.piod_op = PIOD_WRITE_I;
piod.piod_offs = (void *)caddr;
- piod.piod_addr = &paddr;
- piod.piod_len = BREAKPOINT_INSTR_SZ;
+ piod.piod_addr = (void *)saved->data;
+ piod.piod_len = sizeof(saved->data);
if (ptrace(PT_IO, proc_getpid(phdl), (caddr_t)&piod, 0) < 0) {
DPRINTF("ERROR: couldn't write instruction at address 0x%"
PRIuPTR, address);
@@ -199,7 +178,7 @@ proc_bkptdel(struct proc_handle *phdl, u
/*
* Decrement pc so that we delete the breakpoint at the correct
- * address, i.e. at the BREAKPOINT_INSTR address.
+ * address, i.e. at the breakpoint instruction address.
*
* This is only needed on some architectures where the pc value
* when reading registers points at the instruction after the
@@ -210,8 +189,8 @@ proc_bkptregadj(unsigned long *pc)
{
(void)pc;
-#ifdef BREAKPOINT_ADJUST_SZ
- *pc = *pc - BREAKPOINT_ADJUST_SZ;
+#ifdef PTRACE_BREAKPOINT_ADJ
+ *pc = *pc - PTRACE_BREAKPOINT_ADJ;
#endif
}
@@ -219,10 +198,10 @@ proc_bkptregadj(unsigned long *pc)
* Step over the breakpoint.
*/
int
-proc_bkptexec(struct proc_handle *phdl, unsigned long saved)
+proc_bkptexec(struct proc_handle *phdl, proc_breakpoint_t *saved)
{
unsigned long pc;
- unsigned long samesaved;
+ proc_breakpoint_t samesaved;
int status;
if (proc_regget(phdl, REG_PC, &pc) < 0) {
@@ -257,7 +236,8 @@ proc_bkptexec(struct proc_handle *phdl,
DPRINTFX("ERROR: couldn't restore breakpoint");
return (-1);
}
- assert(samesaved == saved);
+
+ assert(memcmp(saved, &samesaved, sizeof(samesaved)) == 0);
return (0);
}
Index: src/external/bsd/libproc/dist/proc_regs.c
diff -u src/external/bsd/libproc/dist/proc_regs.c:1.2 src/external/bsd/libproc/dist/proc_regs.c:1.3
--- src/external/bsd/libproc/dist/proc_regs.c:1.2 Thu Sep 24 10:12:48 2015
+++ src/external/bsd/libproc/dist/proc_regs.c Fri Sep 25 12:07:32 2015
@@ -31,7 +31,7 @@
#ifdef __FBSDID
__FBSDID("$FreeBSD: head/lib/libproc/proc_regs.c 285003 2015-07-01 13:59:26Z br $");
#else
-__RCSID("$NetBSD: proc_regs.c,v 1.2 2015/09/24 14:12:48 christos Exp $");
+__RCSID("$NetBSD: proc_regs.c,v 1.3 2015/09/25 16:07:32 christos Exp $");
#endif
#include <sys/types.h>
@@ -62,38 +62,14 @@ proc_regget(struct proc_handle *phdl, pr
#ifdef PTRACE_REG_PC
*regvalue = PTRACE_REG_PC(®s);
#else
-#if defined(__aarch64__)
- *regvalue = regs.elr;
-#elif defined(__amd64__)
- *regvalue = regs.r_rip;
-#elif defined(__arm__)
- *regvalue = regs.r_pc;
-#elif defined(__i386__)
- *regvalue = regs.r_eip;
-#elif defined(__mips__)
- *regvalue = regs.r_regs[PC];
-#elif defined(__powerpc__)
- *regvalue = regs.pc;
-#endif
+# error "Add support for your architecture"
#endif
break;
case REG_SP:
#ifdef PTRACE_REG_SP
*regvalue = PTRACE_REG_SP(®s);
#else
-#if defined(__aarch64__)
- *regvalue = regs.sp;
-#elif defined(__amd64__)
- *regvalue = regs.r_rsp;
-#elif defined(__arm__)
- *regvalue = regs.r_sp;
-#elif defined(__i386__)
- *regvalue = regs.r_esp;
-#elif defined(__mips__)
- *regvalue = regs.r_regs[SP];
-#elif defined(__powerpc__)
- *regvalue = regs.fixreg[1];
-#endif
+# error "Add support for your architecture"
#endif
break;
default:
@@ -121,38 +97,14 @@ proc_regset(struct proc_handle *phdl, pr
#ifdef PTRACE_REG_SET_PC
PTRACE_REG_SET_PC(®s, regvalue);
#else
-#if defined(__aarch64__)
- regs.elr = regvalue;
-#elif defined(__amd64__)
- regs.r_rip = regvalue;
-#elif defined(__arm__)
- regs.r_pc = regvalue;
-#elif defined(__i386__)
- regs.r_eip = regvalue;
-#elif defined(__mips__)
- regs.r_regs[PC] = regvalue;
-#elif defined(__powerpc__)
- regs.pc = regvalue;
-#endif
+# error "Add support for your architecture"
#endif
break;
case REG_SP:
#ifdef PTRACE_REG_SP
PTRACE_REG_SP(®s) = regvalue;
#else
-#if defined(__aarch64__)
- regs.sp = regvalue;
-#elif defined(__amd64__)
- regs.r_rsp = regvalue;
-#elif defined(__arm__)
- regs.r_sp = regvalue;
-#elif defined(__i386__)
- regs.r_esp = regvalue;
-#elif defined(__mips__)
- regs.r_regs[PC] = regvalue;
-#elif defined(__powerpc__)
- regs.fixreg[1] = regvalue;
-#endif
+# error "Add support for your architecture"
#endif
break;
default:
Index: src/external/bsd/libproc/dist/tests/proc_test.c
diff -u src/external/bsd/libproc/dist/tests/proc_test.c:1.3 src/external/bsd/libproc/dist/tests/proc_test.c:1.4
--- src/external/bsd/libproc/dist/tests/proc_test.c:1.3 Thu Sep 24 15:25:37 2015
+++ src/external/bsd/libproc/dist/tests/proc_test.c Fri Sep 25 12:07:32 2015
@@ -28,7 +28,7 @@
#ifdef __FBSDID
__FBSDID("$FreeBSD: head/lib/libproc/tests/proc_test.c 286863 2015-08-17 23:19:36Z emaste $");
#endif
-__RCSID("$NetBSD: proc_test.c,v 1.3 2015/09/24 19:25:37 christos Exp $");
+__RCSID("$NetBSD: proc_test.c,v 1.4 2015/09/25 16:07:32 christos Exp $");
#include <sys/types.h>
#include <sys/wait.h>
@@ -102,7 +102,7 @@ start_prog(const struct atf_tc *tc, bool
#if !defined(__aarch64__)
static void
-set_bkpt(struct proc_handle *phdl, uintptr_t addr, u_long *saved)
+set_bkpt(struct proc_handle *phdl, uintptr_t addr, proc_breakpoint_t *saved)
{
int error;
@@ -112,7 +112,7 @@ set_bkpt(struct proc_handle *phdl, uintp
}
static void
-remove_bkpt(struct proc_handle *phdl, uintptr_t addr, u_long val)
+remove_bkpt(struct proc_handle *phdl, uintptr_t addr, proc_breakpoint_t *val)
{
int error;
@@ -297,7 +297,7 @@ ATF_TC_BODY(symbol_lookup, tc)
{
GElf_Sym main_sym, r_debug_state_sym;
struct proc_handle *phdl;
- u_long saved;
+ proc_breakpoint_t saved;
int error;
phdl = start_prog(tc, false);
@@ -312,12 +312,12 @@ ATF_TC_BODY(symbol_lookup, tc)
set_bkpt(phdl, (uintptr_t)r_debug_state_sym.st_value, &saved);
ATF_CHECK_EQ_MSG(proc_continue(phdl), 0, "failed to resume execution");
verify_bkpt(phdl, &r_debug_state_sym, r_debug_state, ldelf_object);
- remove_bkpt(phdl, (uintptr_t)r_debug_state_sym.st_value, saved);
+ remove_bkpt(phdl, (uintptr_t)r_debug_state_sym.st_value, &saved);
set_bkpt(phdl, (uintptr_t)main_sym.st_value, &saved);
ATF_CHECK_EQ_MSG(proc_continue(phdl), 0, "failed to resume execution");
verify_bkpt(phdl, &main_sym, "main", target_prog_file);
- remove_bkpt(phdl, (uintptr_t)main_sym.st_value, saved);
+ remove_bkpt(phdl, (uintptr_t)main_sym.st_value, &saved);
ATF_CHECK_EQ_MSG(proc_continue(phdl), 0, "failed to resume execution");