[PATCH 2009-01-14] improve ptrace() argument parsing; move "extern const struct xlat" to defs.h
Denys Vlasenko
dvlasenk at redhat.com
Mon Feb 23 13:56:08 UTC 2009
diff -x CVS -urpN 2009-01-13/ChangeLog 2009-01-14/ChangeLog
--- 2009-01-13/ChangeLog 2009-01-09 18:22:56.000000000 +0100
+++ 2009-01-14/ChangeLog 2009-01-13 19:30:55.000000000 +0100
@@ -1,3 +1,18 @@
+2009-01-13 Denys Vlasenko <dvlasenk at redhat.com>
+
+ Fixes for ptrace() argument parsing.
+ * process.c: Add parsing of PTRACE_SETOPTIONS, PTRACE_GETEVENTMSG,
+ PTRACE_GETSIGINFO, PTRACE_SETSIGINFO.
+ * strace.c (handle_stopped_tcbs): Make PTRACE_SETOPTIONS
+ define check more robust.
+ * defs.h: Declare several "extern const struct xlat" arrays here.
+ * desc.c: Remove open_mode_flags[] and open_access_modes[]
+ extern declarations.
+ * net.c: Remove open_mode_flags[] extern declaration.
+ * sock.c: Remove addrfams[] extern declaration.
+ * util.c: Remove struct_user_offsets[] extern declaration.
+ * signal.c: Remove open_mode_flags[] extern declaration.
+
2009-01-09 Denys Vlasenko <dvlasenk at redhat.com>
* defs.h: Add new struct tcb fields: wait_status, next_need_service.
diff -x CVS -urpN 2009-01-13/defs.h 2009-01-14/defs.h
--- 2009-01-13/defs.h 2009-01-09 18:22:56.000000000 +0100
+++ 2009-01-14/defs.h 2009-01-13 19:30:55.000000000 +0100
@@ -26,7 +26,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * $Id: defs.h,v 1.93 2009/01/09 17:22:56 vda_linux Exp $
+ * $Id: defs.h,v 1.94 2009/01/13 18:30:55 vda_linux Exp $
*/
#ifdef HAVE_CONFIG_H
@@ -417,6 +417,11 @@ struct xlat {
char *str;
};
+extern const struct xlat open_mode_flags[];
+extern const struct xlat addrfams[];
+extern const struct xlat struct_user_offsets[];
+extern const struct xlat open_access_modes[];
+
/* Format of syscall return values */
#define RVAL_DECIMAL 000 /* decimal format */
#define RVAL_HEX 001 /* hex format */
diff -x CVS -urpN 2009-01-13/desc.c 2009-01-14/desc.c
--- 2009-01-13/desc.c 2009-01-06 16:12:52.000000000 +0100
+++ 2009-01-14/desc.c 2009-01-13 19:30:55.000000000 +0100
@@ -27,7 +27,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * $Id: desc.c,v 1.38 2009/01/06 15:12:52 vda_linux Exp $
+ * $Id: desc.c,v 1.39 2009/01/13 18:30:55 vda_linux Exp $
*/
#include "defs.h"
@@ -261,8 +261,6 @@ printflock64(struct tcb *tcp, long addr,
}
#endif
-extern const struct xlat open_mode_flags[];
-
/*
* low bits of the open(2) flags define access mode,
* other bits are real flags.
@@ -270,7 +268,6 @@ extern const struct xlat open_mode_flags
static const char *
sprint_open_modes(mode_t flags)
{
- extern const struct xlat open_access_modes[];
static char outstr[1024];
const char *str = xlookup(open_access_modes, flags & 3);
const char *sep = "";
diff -x CVS -urpN 2009-01-13/net.c 2009-01-14/net.c
--- 2009-01-13/net.c 2009-01-01 23:47:51.000000000 +0100
+++ 2009-01-14/net.c 2009-01-13 19:30:55.000000000 +0100
@@ -27,7 +27,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * $Id: net.c,v 1.59 2009/01/01 22:47:51 ldv Exp $
+ * $Id: net.c,v 1.60 2009/01/13 18:30:55 vda_linux Exp $
*/
#include "defs.h"
@@ -1499,8 +1499,6 @@ struct tcb *tcp;
return sys_accept(tcp);
}
-extern const struct xlat open_mode_flags[];
-
static int
do_pipe(struct tcb *tcp, int flags_arg)
{
diff -x CVS -urpN 2009-01-13/process.c 2009-01-14/process.c
--- 2009-01-13/process.c 2009-01-06 22:45:06.000000000 +0100
+++ 2009-01-14/process.c 2009-01-13 19:30:55.000000000 +0100
@@ -34,7 +34,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * $Id: process.c,v 1.122 2009/01/06 21:45:06 vda_linux Exp $
+ * $Id: process.c,v 1.123 2009/01/13 18:30:55 vda_linux Exp $
*/
#include "defs.h"
@@ -2231,7 +2231,7 @@ struct tcb *tcp;
else if (umove(tcp, tcp->u_arg[2], &si) < 0)
tprintf("{???}");
else
- printsiginfo(&si, verbose (tcp));
+ printsiginfo(&si, verbose(tcp));
/* options */
tprintf(", ");
printflags(wait4_options, tcp->u_arg[3], "W???");
@@ -2332,6 +2332,18 @@ static const struct xlat ptrace_cmds[] =
#ifdef PTRACE_SETVRREGS
{ PTRACE_SETVRREGS, "PTRACE_SETVRREGS", },
#endif
+#ifdef PTRACE_SETOPTIONS
+ { PTRACE_SETOPTIONS, "PTRACE_SETOPTIONS", },
+#endif
+#ifdef PTRACE_GETEVENTMSG
+ { PTRACE_GETEVENTMSG, "PTRACE_GETEVENTMSG", },
+#endif
+#ifdef PTRACE_GETSIGINFO
+ { PTRACE_GETSIGINFO, "PTRACE_GETSIGINFO", },
+#endif
+#ifdef PTRACE_SETSIGINFO
+ { PTRACE_SETSIGINFO, "PTRACE_SETSIGINFO", },
+#endif
#ifdef SUNOS4
{ PTRACE_READDATA, "PTRACE_READDATA" },
{ PTRACE_WRITEDATA, "PTRACE_WRITEDATA" },
@@ -2361,7 +2373,9 @@ static const struct xlat ptrace_cmds[] =
#endif /* !I386 */
{ PTRACE_GETUCODE, "PTRACE_GETUCODE" },
#endif /* SUNOS4 */
+
#else /* FREEBSD */
+
{ PT_TRACE_ME, "PT_TRACE_ME" },
{ PT_READ_I, "PT_READ_I" },
{ PT_READ_D, "PT_READ_D" },
@@ -2386,9 +2400,35 @@ static const struct xlat ptrace_cmds[] =
};
#ifndef FREEBSD
-#ifndef SUNOS4_KERNEL_ARCH_KLUDGE
-static
-#endif /* !SUNOS4_KERNEL_ARCH_KLUDGE */
+#ifdef PTRACE_SETOPTIONS
+static const struct xlat ptrace_setoptions_flags[] = {
+#ifdef PTRACE_O_TRACESYSGOOD
+ { PTRACE_O_TRACESYSGOOD,"PTRACE_O_TRACESYSGOOD" },
+#endif
+#ifdef PTRACE_O_TRACEFORK
+ { PTRACE_O_TRACEFORK, "PTRACE_O_TRACEFORK" },
+#endif
+#ifdef PTRACE_O_TRACEVFORK
+ { PTRACE_O_TRACEVFORK, "PTRACE_O_TRACEVFORK" },
+#endif
+#ifdef PTRACE_O_TRACECLONE
+ { PTRACE_O_TRACECLONE, "PTRACE_O_TRACECLONE" },
+#endif
+#ifdef PTRACE_O_TRACEEXEC
+ { PTRACE_O_TRACEEXEC, "PTRACE_O_TRACEEXEC" },
+#endif
+#ifdef PTRACE_O_TRACEVFORKDONE
+ { PTRACE_O_TRACEVFORKDONE,"PTRACE_O_TRACEVFORKDONE"},
+#endif
+#ifdef PTRACE_O_TRACEEXIT
+ { PTRACE_O_TRACEEXIT, "PTRACE_O_TRACEEXIT" },
+#endif
+ { 0, NULL },
+};
+#endif
+#endif
+
+#ifndef FREEBSD
const struct xlat struct_user_offsets[] = {
#ifdef LINUX
#if defined(S390) || defined(S390X)
@@ -3192,6 +3232,30 @@ struct tcb *tcp;
case PTRACE_DETACH:
printsignal(tcp->u_arg[3]);
break;
+#ifdef PTRACE_SETOPTIONS
+ case PTRACE_SETOPTIONS:
+ printflags(ptrace_setoptions_flags, tcp->u_arg[3], "PTRACE_O_???");
+ break;
+#endif
+#ifdef PTRACE_SETSIGINFO
+ case PTRACE_SETSIGINFO: {
+ siginfo_t si;
+ if (!tcp->u_arg[3])
+ tprintf("NULL");
+ else if (syserror(tcp))
+ tprintf("%#lx", tcp->u_arg[3]);
+ else if (umove(tcp, tcp->u_arg[3], &si) < 0)
+ tprintf("{???}");
+ else
+ printsiginfo(&si, verbose(tcp));
+ break;
+ }
+#endif
+#ifdef PTRACE_GETSIGINFO
+ case PTRACE_GETSIGINFO:
+ /* Don't print anything, do it at syscall return. */
+ break;
+#endif
default:
tprintf("%#lx", tcp->u_arg[3]);
break;
@@ -3207,6 +3271,20 @@ struct tcb *tcp;
printnum(tcp, tcp->u_arg[3], "%#lx");
break;
#endif
+#ifdef PTRACE_GETSIGINFO
+ case PTRACE_GETSIGINFO: {
+ siginfo_t si;
+ if (!tcp->u_arg[3])
+ tprintf("NULL");
+ else if (syserror(tcp))
+ tprintf("%#lx", tcp->u_arg[3]);
+ else if (umove(tcp, tcp->u_arg[3], &si) < 0)
+ tprintf("{???}");
+ else
+ printsiginfo(&si, verbose(tcp));
+ break;
+ }
+#endif
}
}
#endif /* LINUX */
diff -x CVS -urpN 2009-01-13/signal.c 2009-01-14/signal.c
--- 2009-01-13/signal.c 2008-12-17 18:22:03.000000000 +0100
+++ 2009-01-14/signal.c 2009-01-13 19:30:55.000000000 +0100
@@ -30,7 +30,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * $Id: signal.c,v 1.72 2008/12/17 17:22:03 vda_linux Exp $
+ * $Id: signal.c,v 1.73 2009/01/13 18:30:55 vda_linux Exp $
*/
#include "defs.h"
@@ -1967,7 +1967,7 @@ sys_rt_sigqueueinfo(tcp)
if (umove(tcp, tcp->u_arg[2], &si) < 0)
tprintf("%#lx", tcp->u_arg[2]);
else
- printsiginfo(&si, verbose (tcp));
+ printsiginfo(&si, verbose(tcp));
}
return 0;
}
@@ -1993,7 +1993,7 @@ int sys_rt_sigtimedwait(tcp)
if (umove(tcp, tcp->u_arg[1], &si) < 0)
tprintf("%#lx", tcp->u_arg[1]);
else
- printsiginfo(&si, verbose (tcp));
+ printsiginfo(&si, verbose(tcp));
/* XXX For now */
tprintf(", %#lx", tcp->u_arg[2]);
tprintf(", %d", (int) tcp->u_arg[3]);
@@ -2011,8 +2011,6 @@ struct tcb *tcp;
return 0;
}
-extern const struct xlat open_mode_flags[];
-
static int
do_signalfd(struct tcb *tcp, int flags_arg)
{
diff -x CVS -urpN 2009-01-13/sock.c 2009-01-14/sock.c
--- 2009-01-13/sock.c 2008-12-30 19:47:56.000000000 +0100
+++ 2009-01-14/sock.c 2009-01-13 19:30:55.000000000 +0100
@@ -24,7 +24,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * $Id: sock.c,v 1.16 2008/12/30 18:47:56 vda_linux Exp $
+ * $Id: sock.c,v 1.17 2009/01/13 18:30:55 vda_linux Exp $
*/
#include "defs.h"
@@ -47,8 +47,6 @@
#endif
#include <net/if.h>
-extern const struct xlat addrfams[];
-
static const struct xlat iffflags[] = {
{ IFF_UP, "IFF_UP" },
{ IFF_BROADCAST, "IFF_BROADCAST" },
diff -x CVS -urpN 2009-01-13/strace.c 2009-01-14/strace.c
--- 2009-01-13/strace.c 2009-01-09 18:22:56.000000000 +0100
+++ 2009-01-14/strace.c 2009-01-13 19:30:55.000000000 +0100
@@ -27,7 +27,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * $Id: strace.c,v 1.98 2009/01/09 17:22:56 vda_linux Exp $
+ * $Id: strace.c,v 1.99 2009/01/13 18:30:55 vda_linux Exp $
*/
#include "defs.h"
@@ -2525,8 +2525,10 @@ handle_stopped_tcbs(struct tcb *tcp)
}
}
/* Add more OSes after you verified it works for them. */
-/* PTRACE_SETOPTIONS is not a #define. PT_SETOPTIONS is. */
-#if defined LINUX && defined PT_SETOPTIONS
+/* PTRACE_SETOPTIONS may be an enum, not a #define.
+ * But sometimes we can test for it by checking PT_SETOPTIONS.
+ */
+#if defined LINUX && (defined PTRACE_SETOPTIONS || defined PT_SETOPTIONS)
# ifndef PTRACE_O_TRACESYSGOOD
# define PTRACE_O_TRACESYSGOOD 0x00000001
# endif
@@ -2557,7 +2559,7 @@ handle_stopped_tcbs(struct tcb *tcp)
goto tracing;
}
-#if defined LINUX && defined PT_SETOPTIONS
+#if defined LINUX && (defined PTRACE_SETOPTIONS || defined PT_SETOPTIONS)
if (ptrace_stop_sig != SIGTRAP && WSTOPSIG(status) == SIGTRAP) {
/*
* We told ptrace to report SIGTRAP | 0x80 on this process
diff -x CVS -urpN 2009-01-13/util.c 2009-01-14/util.c
--- 2009-01-13/util.c 2009-01-06 22:45:06.000000000 +0100
+++ 2009-01-14/util.c 2009-01-13 19:30:55.000000000 +0100
@@ -30,7 +30,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * $Id: util.c,v 1.85 2009/01/06 21:45:06 vda_linux Exp $
+ * $Id: util.c,v 1.86 2009/01/13 18:30:55 vda_linux Exp $
*/
#include "defs.h"
@@ -1116,7 +1116,6 @@ long *res;
}
is_sun4m = strcmp(name.machine, "sun4m") == 0;
if (is_sun4m) {
- extern const struct xlat struct_user_offsets[];
const struct xlat *x;
for (x = struct_user_offsets; x->str; x++)
More information about the Strace-devel
mailing list