Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/external/bsd/libproc/dist Add a proc_breakpoint_t and a proc...



details:   https://anonhg.NetBSD.org/src/rev/490479a84782
branches:  trunk
changeset: 340713:490479a84782
user:      christos <christos%NetBSD.org@localhost>
date:      Fri Sep 25 16:07:32 2015 +0000

description:
Add a proc_breakpoint_t and a proc_regval_t to abstract some types.

diffstat:

 external/bsd/libproc/dist/libproc.h         |  17 ++++++--
 external/bsd/libproc/dist/proc_bkpt.c       |  58 +++++++++-------------------
 external/bsd/libproc/dist/proc_regs.c       |  58 ++--------------------------
 external/bsd/libproc/dist/tests/proc_test.c |  12 +++---
 4 files changed, 42 insertions(+), 103 deletions(-)

diffs (truncated from 349 to 300 lines):

diff -r cccb97278872 -r 490479a84782 external/bsd/libproc/dist/libproc.h
--- a/external/bsd/libproc/dist/libproc.h       Fri Sep 25 16:05:17 2015 +0000
+++ b/external/bsd/libproc/dist/libproc.h       Fri Sep 25 16:07:32 2015 +0000
@@ -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 @@
 #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 @@
 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
 
diff -r cccb97278872 -r 490479a84782 external/bsd/libproc/dist/proc_bkpt.c
--- a/external/bsd/libproc/dist/proc_bkpt.c     Fri Sep 25 16:05:17 2015 +0000
+++ b/external/bsd/libproc/dist/proc_bkpt.c     Fri Sep 25 16:07:32 2015 +0000
@@ -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 @@
 #include <sys/wait.h>
 
 #include <assert.h>
+#include <string.h>
 #include <err.h>
 #include <errno.h>
 #include <inttypes.h>
@@ -46,26 +47,7 @@
 #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 @@
 
 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 @@
        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 @@
 
 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 @@
         * 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 @@
 
 /*
  * 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 @@
 {
 
        (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 @@
  * 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 @@
                DPRINTFX("ERROR: couldn't restore breakpoint");
                return (-1);
        }
-       assert(samesaved == saved);
+
+       assert(memcmp(saved, &samesaved, sizeof(samesaved)) == 0);
 
        return (0);
 }
diff -r cccb97278872 -r 490479a84782 external/bsd/libproc/dist/proc_regs.c
--- a/external/bsd/libproc/dist/proc_regs.c     Fri Sep 25 16:05:17 2015 +0000
+++ b/external/bsd/libproc/dist/proc_regs.c     Fri Sep 25 16:07:32 2015 +0000
@@ -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 @@
 #ifdef PTRACE_REG_PC
                *regvalue = PTRACE_REG_PC(&regs);
 #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(&regs);
 #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 @@
 #ifdef PTRACE_REG_SET_PC
                PTRACE_REG_SET_PC(&regs, 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(&regs) = 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:
diff -r cccb97278872 -r 490479a84782 external/bsd/libproc/dist/tests/proc_test.c
--- a/external/bsd/libproc/dist/tests/proc_test.c       Fri Sep 25 16:05:17 2015 +0000
+++ b/external/bsd/libproc/dist/tests/proc_test.c       Fri Sep 25 16:07:32 2015 +0000
@@ -28,7 +28,7 @@
 #ifdef __FBSDID



Home | Main Index | Thread Index | Old Index