Source-Changes-HG archive

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

[src/trunk]: src Add new ptrace(2) API: PT_SETSTEP & PT_CLEARSTEP



details:   https://anonhg.NetBSD.org/src/rev/0588fcfe865f
branches:  trunk
changeset: 822796:0588fcfe865f
user:      kamil <kamil%NetBSD.org@localhost>
date:      Sat Apr 08 00:25:49 2017 +0000

description:
Add new ptrace(2) API: PT_SETSTEP & PT_CLEARSTEP

These operations allow to mark thread as a single-stepping one.

This allows to i.a.:
 - single step and emit a signal (PT_SETSTEP & PT_CONTINUE)
 - single step and trace syscall entry and exit (PT_SETSTEP & PT_SYSCALL)

The former is useful for debuggers like GDB or LLDB. The latter can be used
to singlestep a usermode kernel. These examples don't limit use-cases of
this interface.

Define PT_*STEP only for platforms defining PT_STEP.

Add new ATF tests setstep[1234].

These ptrace(2) operations first appeared in FreeBSD.

Sponsored by <The NetBSD Foundation>

diffstat:

 sys/arch/amd64/include/ptrace.h    |   8 ++-
 sys/arch/arc/include/ptrace.h      |   6 +-
 sys/arch/arm/include/ptrace.h      |  12 +++-
 sys/arch/hppa/include/ptrace.h     |   8 ++-
 sys/arch/ia64/include/ptrace.h     |   8 ++-
 sys/arch/m68k/include/ptrace.h     |   8 ++-
 sys/arch/mips/include/ptrace.h     |  15 ++++-
 sys/arch/powerpc/include/ptrace.h  |   7 +-
 sys/arch/sh3/include/ptrace.h      |  11 +++-
 sys/arch/vax/include/ptrace.h      |   8 ++-
 sys/kern/sys_ptrace_common.c       |  55 +++++++++++++++++++-
 sys/sys/lwp.h                      |   3 +-
 tests/lib/libc/sys/t_ptrace_wait.c |  98 ++++++++++++++++++++++++++++++++++---
 13 files changed, 208 insertions(+), 39 deletions(-)

diffs (truncated from 580 to 300 lines):

diff -r 27a1050ee446 -r 0588fcfe865f sys/arch/amd64/include/ptrace.h
--- a/sys/arch/amd64/include/ptrace.h   Fri Apr 07 17:07:09 2017 +0000
+++ b/sys/arch/amd64/include/ptrace.h   Sat Apr 08 00:25:49 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ptrace.h,v 1.10 2017/02/23 03:34:22 kamil Exp $        */
+/*     $NetBSD: ptrace.h,v 1.11 2017/04/08 00:25:49 kamil Exp $        */
 
 /*
  * Copyright (c) 1993 Christopher G. Demetriou
@@ -43,6 +43,8 @@
 #define        PT_SETFPREGS            (PT_FIRSTMACH + 4)
 #define        PT_GETDBREGS            (PT_FIRSTMACH + 5)
 #define        PT_SETDBREGS            (PT_FIRSTMACH + 6)
+#define        PT_SETSTEP              (PT_FIRSTMACH + 7)
+#define        PT_CLEARSTEP            (PT_FIRSTMACH + 8)
 
 #define PT_MACHDEP_STRINGS \
        "PT_STEP", \
@@ -51,7 +53,9 @@
        "PT_GETFPREGS", \
        "PT_SETFPREGS", \
        "PT_GETDBREGS", \
-       "PT_SETDBREGS",
+       "PT_SETDBREGS", \
+       "PT_SETSTEP", \
+       "PT_CLEARSTEP",
 
 #include <machine/reg.h>
 #define PTRACE_REG_PC(r)       (r)->regs[_REG_RIP]
diff -r 27a1050ee446 -r 0588fcfe865f sys/arch/arc/include/ptrace.h
--- a/sys/arch/arc/include/ptrace.h     Fri Apr 07 17:07:09 2017 +0000
+++ b/sys/arch/arc/include/ptrace.h     Sat Apr 08 00:25:49 2017 +0000
@@ -1,6 +1,6 @@
-/*     $NetBSD: ptrace.h,v 1.4 2000/01/23 21:01:58 soda Exp $  */
+/*     $NetBSD: ptrace.h,v 1.5 2017/04/08 00:25:49 kamil Exp $ */
 /*      $OpenBSD: ptrace.h,v 1.1.1.1 1996/06/24 09:07:18 pefo Exp $    */
 
-#include <mips/ptrace.h>
+#define        PT_STEP         (PT_FIRSTMACH + 0)
 
-#define        PT_STEP         (PT_FIRSTMACH + 0)
+#include <mips/ptrace.h>
diff -r 27a1050ee446 -r 0588fcfe865f sys/arch/arm/include/ptrace.h
--- a/sys/arch/arm/include/ptrace.h     Fri Apr 07 17:07:09 2017 +0000
+++ b/sys/arch/arm/include/ptrace.h     Sat Apr 08 00:25:49 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ptrace.h,v 1.9 2016/11/25 02:19:19 christos Exp $      */
+/*     $NetBSD: ptrace.h,v 1.10 2017/04/08 00:25:49 kamil Exp $        */
 
 /*
  * Copyright (c) 1995 Frank Lancaster
@@ -42,15 +42,21 @@
 /* 3 and 4 are for FPE registers */
 #define        PT_GETFPREGS    (PT_FIRSTMACH + 5)
 #define        PT_SETFPREGS    (PT_FIRSTMACH + 6)
+#ifndef _KERNEL
+#define PT_SETSTEP     (PT_FIRSTMACH + 7) /* Not implemented */
+#define PT_CLEARSTEP   (PT_FIRSTMACH + 8) /* Not implemented */
+#endif
 
 #define PT_MACHDEP_STRINGS \
-       "(unused)", \
+       "PT_STEP", \
        "PT_GETREGS", \
        "PT_SETREGS", \
        "old PT_GETFPREGS", \
        "old PT_SETFPREGS", \
        "PT_GETFPREGS", \
-       "PT_SETFPREGS",
+       "PT_SETFPREGS", \
+       "PT_SETSTEP", \
+       "PT_CLEARSTEP",
 
 #include <machine/reg.h>
 #define PTRACE_REG_PC(_r)              (_r)->r_pc
diff -r 27a1050ee446 -r 0588fcfe865f sys/arch/hppa/include/ptrace.h
--- a/sys/arch/hppa/include/ptrace.h    Fri Apr 07 17:07:09 2017 +0000
+++ b/sys/arch/hppa/include/ptrace.h    Sat Apr 08 00:25:49 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ptrace.h,v 1.6 2016/11/25 02:27:43 christos Exp $      */
+/*     $NetBSD: ptrace.h,v 1.7 2017/04/08 00:25:49 kamil Exp $ */
 
 /*     $OpenBSD: ptrace.h,v 1.2 1998/12/01 03:05:44 mickey Exp $       */
 
@@ -36,13 +36,17 @@
 #define        PT_SETREGS      (PT_FIRSTMACH + 2)
 #define        PT_GETFPREGS    (PT_FIRSTMACH + 3)
 #define        PT_SETFPREGS    (PT_FIRSTMACH + 4)
+#define        PT_SETSTEP      (PT_FIRSTMACH + 5)
+#define        PT_CLEARSTEP    (PT_FIRSTMACH + 6)
 
 #define PT_MACHDEP_STRINGS \
        "PT_STEP", \
        "PT_GETREGS", \
        "PT_SETREGS", \
        "PT_GETFPREGS", \
-       "PT_SETFPREGS",
+       "PT_SETFPREGS", \
+       "PT_SETSTEP", \
+       "PT_CLEARSTEP",
 
 #include <machine/reg.h>
 #define PTRACE_REG_PC(r)       (r)->r_pcoqh
diff -r 27a1050ee446 -r 0588fcfe865f sys/arch/ia64/include/ptrace.h
--- a/sys/arch/ia64/include/ptrace.h    Fri Apr 07 17:07:09 2017 +0000
+++ b/sys/arch/ia64/include/ptrace.h    Sat Apr 08 00:25:49 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ptrace.h,v 1.3 2015/09/15 15:49:02 christos Exp $      */
+/*     $NetBSD: ptrace.h,v 1.4 2017/04/08 00:25:49 kamil Exp $ */
 
 /*
  * Copyright (c) 1994 Christopher G. Demetriou
@@ -38,13 +38,17 @@
 #define        PT_SETREGS      (PT_FIRSTMACH + 2)
 #define        PT_GETFPREGS    (PT_FIRSTMACH + 3)
 #define        PT_SETFPREGS    (PT_FIRSTMACH + 4)
+#define        PT_SETSTEP      (PT_FIRSTMACH + 5)
+#define        PT_CLEARSTEP    (PT_FIRSTMACH + 6)
 
 #define PT_MACHDEP_STRINGS \
        "PT_STEP", \
        "PT_GETREGS", \
        "PT_SETREGS", \
        "PT_GETFPREGS", \
-       "PT_SETFPREGS",
+       "PT_SETFPREGS", \
+       "PT_SETSTEP", \
+       "PT_CLEARSTEP",
 
 #include <machine/reg.h>
 #define PTRACE_REG_PC(r)       (r)->r_special.iip
diff -r 27a1050ee446 -r 0588fcfe865f sys/arch/m68k/include/ptrace.h
--- a/sys/arch/m68k/include/ptrace.h    Fri Apr 07 17:07:09 2017 +0000
+++ b/sys/arch/m68k/include/ptrace.h    Sat Apr 08 00:25:49 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ptrace.h,v 1.10 2015/09/25 16:05:17 christos Exp $     */
+/*     $NetBSD: ptrace.h,v 1.11 2017/04/08 00:25:49 kamil Exp $        */
 
 /*
  * Copyright (c) 1993 Christopher G. Demetriou
@@ -40,13 +40,17 @@
 #define        PT_SETREGS      (PT_FIRSTMACH + 2)
 #define        PT_GETFPREGS    (PT_FIRSTMACH + 3)
 #define        PT_SETFPREGS    (PT_FIRSTMACH + 4)
+#define        PT_SETSTEP      (PT_FIRSTMACH + 5)
+#define        PT_CLEARSTEP    (PT_FIRSTMACH + 6)
 
 #define PT_MACHDEP_STRINGS \
        "PT_STEP", \
        "PT_GETREGS", \
        "PT_SETREGS", \
        "PT_GETFPREGS", \
-       "PT_SETFPREGS",
+       "PT_SETFPREGS", \
+       "PT_SETSTEP", \
+       "PT_CLEARSTEP",
 
 #include <machine/reg.h>
 #define PTRACE_REG_PC(r)       (r)->r_pc
diff -r 27a1050ee446 -r 0588fcfe865f sys/arch/mips/include/ptrace.h
--- a/sys/arch/mips/include/ptrace.h    Fri Apr 07 17:07:09 2017 +0000
+++ b/sys/arch/mips/include/ptrace.h    Sat Apr 08 00:25:49 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ptrace.h,v 1.14 2015/09/25 16:05:17 christos Exp $     */
+/*     $NetBSD: ptrace.h,v 1.15 2017/04/08 00:25:49 kamil Exp $        */
 
 /*
  * Copyright (c) 1992, 1993
@@ -39,19 +39,26 @@
 #ifndef _MIPS_PTRACE_H_
 #define _MIPS_PTRACE_H_
 
-/*#define      PT_STEP         (PT_FIRSTMACH + 0)*/
+/* MIPS PT_STEP PT_FIRSTMACH+0 might be defined by a port specific header */
 #define        PT_GETREGS      (PT_FIRSTMACH + 1)
 #define        PT_SETREGS      (PT_FIRSTMACH + 2)
 
 #define        PT_GETFPREGS    (PT_FIRSTMACH + 3)
 #define        PT_SETFPREGS    (PT_FIRSTMACH + 4)
 
+#ifdef PT_STEP
+#define        PT_SETSTEP      (PT_FIRSTMACH + 5)
+#define        PT_CLEARSTEP    (PT_FIRSTMACH + 6)
+#endif
+
 #define PT_MACHDEP_STRINGS \
-       "(unused)", \
+       "PT_STEP", \
        "PT_GETREGS", \
        "PT_SETREGS", \
        "PT_GETFPREGS", \
-       "PT_SETFPREGS",
+       "PT_SETFPREGS", \
+       "PT_SETSTEP", \
+       "PT_CLEARSTEP",
 
 #include <machine/reg.h>
 #define PTRACE_REG_PC(r)       (r)->r_regs[35]
diff -r 27a1050ee446 -r 0588fcfe865f sys/arch/powerpc/include/ptrace.h
--- a/sys/arch/powerpc/include/ptrace.h Fri Apr 07 17:07:09 2017 +0000
+++ b/sys/arch/powerpc/include/ptrace.h Sat Apr 08 00:25:49 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ptrace.h,v 1.12 2015/09/15 15:49:03 christos Exp $     */
+/*     $NetBSD: ptrace.h,v 1.13 2017/04/08 00:25:49 kamil Exp $        */
 
 #ifndef _POWERPC_PTRACE_H
 #define        _POWERPC_PTRACE_H
@@ -10,12 +10,15 @@
 #define        PT_SETFPREGS    (PT_FIRSTMACH + 4)
 #define        PT_GETVECREGS   (PT_FIRSTMACH + 5)
 #define        PT_SETVECREGS   (PT_FIRSTMACH + 6)
+#define        PT_SETSTEP      (PT_FIRSTMACH + 7)
+#define        PT_CLEARSTEP    (PT_FIRSTMACH + 8)
 
 #define        PT_MACHDEP_STRINGS                              \
        "PT_STEP",                                      \
        "PT_GETREGS",           "PT_SETREGS",           \
        "PT_GETFPREGS",         "PT_SETFPREGS",         \
-       "PT_GETVECREGS",        "PT_SETVECREGS",
+       "PT_GETVECREGS",        "PT_SETVECREGS",        \
+       "PT_SETSTEP",           "PT_CLEARSTEP",
 
 #include <machine/reg.h>
 #define PTRACE_REG_PC(r)       (r)->pc
diff -r 27a1050ee446 -r 0588fcfe865f sys/arch/sh3/include/ptrace.h
--- a/sys/arch/sh3/include/ptrace.h     Fri Apr 07 17:07:09 2017 +0000
+++ b/sys/arch/sh3/include/ptrace.h     Sat Apr 08 00:25:49 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ptrace.h,v 1.12 2015/09/25 16:05:17 christos Exp $     */
+/*     $NetBSD: ptrace.h,v 1.13 2017/04/08 00:25:49 kamil Exp $        */
 
 /*
  * Copyright (c) 1993 Christopher G. Demetriou
@@ -51,12 +51,19 @@
 #define        PT_SETFPREGS    (PT_FIRSTMACH + 6)
 #endif
 
+#define        PT_SETSTEP      (PT_FIRSTMACH + 7)
+#define        PT_CLEARSTEP    (PT_FIRSTMACH + 8)
+
 #define PT_MACHDEP_STRINGS \
        "PT_STEP", \
        "PT___GETREGS40", \
        "PT___SETREGS40", \
        "PT_GETREGS", \
-       "PT_SETREGS",
+       "PT_SETREGS", \
+       "PT_GETFPREGS", \
+       "PT_SETFPREGS", \
+       "PT_SETSTEP", \
+       "PT_CLEARSTEP"
 
 #include <machine/reg.h>
 #define PTRACE_REG_PC(r)       r->r_spc
diff -r 27a1050ee446 -r 0588fcfe865f sys/arch/vax/include/ptrace.h
--- a/sys/arch/vax/include/ptrace.h     Fri Apr 07 17:07:09 2017 +0000
+++ b/sys/arch/vax/include/ptrace.h     Sat Apr 08 00:25:49 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ptrace.h,v 1.6 2015/09/25 16:05:18 christos Exp $      */
+/*     $NetBSD: ptrace.h,v 1.7 2017/04/08 00:25:49 kamil Exp $ */
 
 /*
  * Copyright (c) 1994 Ludd, University of Lule}, Sweden.
@@ -36,11 +36,15 @@
 #define PT_STEP         (PT_FIRSTMACH + 0)
 #define PT_GETREGS      (PT_FIRSTMACH + 1)
 #define PT_SETREGS      (PT_FIRSTMACH + 2)
+#define PT_SETSTEP      (PT_FIRSTMACH + 3)
+#define PT_CLEARSTEP    (PT_FIRSTMACH + 4)
 
 #define PT_MACHDEP_STRINGS \
        "PT_STEP", \
        "PT_GETREGS", \
-       "PT_SETREGS",
+       "PT_SETREGS", \
+       "PT_SETSTEP", \
+       "PT_CLEARSTEP",
 
 #include <machine/reg.h>
 
diff -r 27a1050ee446 -r 0588fcfe865f sys/kern/sys_ptrace_common.c
--- a/sys/kern/sys_ptrace_common.c      Fri Apr 07 17:07:09 2017 +0000
+++ b/sys/kern/sys_ptrace_common.c      Sat Apr 08 00:25:49 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sys_ptrace_common.c,v 1.20 2017/03/29 22:48:03 kamil Exp $     */
+/*     $NetBSD: sys_ptrace_common.c,v 1.21 2017/04/08 00:25:50 kamil Exp $     */
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -118,7 +118,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sys_ptrace_common.c,v 1.20 2017/03/29 22:48:03 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_ptrace_common.c,v 1.21 2017/04/08 00:25:50 kamil Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ptrace.h"
@@ -229,6 +229,8 @@
 



Home | Main Index | Thread Index | Old Index