On Tue, Jul 12, 2011 at 05:52:09PM +0200, Otto Moerbeek wrote:
Hi,
The diff below implements utrace(2), a syscall to introduce data into
a ktrace stream from a userland program.
The interface is taken from netbsd, freebsd also has a utrace(2)
syscall, but lacks the label argument.
You could uise this as a debugging aid, to get tarce information
intermixed with sysclal info, or set more specific tracepoint and only
see the utrace records.
Do we want this? If so, this should be reviewed and tested. And a man
page for utrace(2) should be written.
Output of utrace(It is I, some data, 10) looks like:
24413 a.outCALL utrace(0x500a09,0x5009ff,0xa)
24413 a.outUSER It is I: 10 bytes
some data\0
24413 a.outRET utrace 0
new diff, with comments incorporated and a manpage. Since the
utrace(2) syscall always exists now, I've put it in sys_generic.c. Is
that a right place?
-0tto
Index: lib/libc/sys/Makefile.inc
===
RCS file: /cvs/src/lib/libc/sys/Makefile.inc,v
retrieving revision 1.92
diff -u -p -r1.92 Makefile.inc
--- lib/libc/sys/Makefile.inc 3 Jul 2010 04:44:51 - 1.92
+++ lib/libc/sys/Makefile.inc 18 Jul 2011 09:28:15 -
@@ -64,7 +64,7 @@ ASM= accept.o access.o acct.o adjfreq.o
setuid.o shmat.o shmctl.o shmdt.o shmget.o shutdown.o sigaction.o \
sigaltstack.o socket.o socketpair.o stat.o statfs.o swapctl.o \
symlink.o sync.o sysarch.o umask.o unlink.o unmount.o \
- utimes.o wait4.o write.o writev.o nnpfspioctl.o __semctl.o \
+ utimes.o utrace.o wait4.o write.o writev.o nnpfspioctl.o __semctl.o \
__syscall.o __sysctl.o __getcwd.o sched_yield.o getthrid.o \
thrsleep.o thrwakeup.o threxit.o thrsigdivert.o \
setrtable.o getrtable.o
@@ -233,7 +233,7 @@ MAN+= accept.2 access.2 acct.2 adjfreq.2
shutdown.2 sigaction.2 sigaltstack.2 sigpending.2 sigprocmask.2 \
sigreturn.2 sigstack.2 sigsuspend.2 socket.2 socketpair.2 stat.2 \
statfs.2 swapctl.2 symlink.2 sync.2 sysarch.2 syscall.2 truncate.2 \
- umask.2 unlink.2 utimes.2 vfork.2 wait.2 write.2
+ umask.2 unlink.2 utimes.2 utrace.2 vfork.2 wait.2 write.2
MAN+= msgctl.2 shmctl.2 shmat.2 semop.2 semget.2 semctl.2 msgsnd.2 msgrcv.2 \
msgget.2 shmget.2
Index: lib/libc/sys/ktrace.2
===
RCS file: /cvs/src/lib/libc/sys/ktrace.2,v
retrieving revision 1.20
diff -u -p -r1.20 ktrace.2
--- lib/libc/sys/ktrace.2 8 Jul 2011 19:30:32 - 1.20
+++ lib/libc/sys/ktrace.2 18 Jul 2011 09:28:15 -
@@ -94,6 +94,8 @@ generate much output).
.It Dv KTRFAC_EMUL Trace emulation changes.
.It Dv KTRFAC_CSW Trace context switch points.
.It Dv KTRFAC_STRUCT Trace various structs
+.It Dv KTRFAC_USER Trace user data coming from
+.Xr utrace 2
.It Dv KTRFAC_INHERIT Inherit tracing to future children.
.El
.Pp
@@ -174,7 +176,8 @@ No process can be found corresponding to
.El
.Sh SEE ALSO
.Xr kdump 1 ,
-.Xr ktrace 1
+.Xr ktrace 1 ,
+.Xr utrace 2
.Sh HISTORY
A
.Fn ktrace
Index: lib/libc/sys/utrace.2
===
RCS file: lib/libc/sys/utrace.2
diff -N lib/libc/sys/utrace.2
--- /dev/null 1 Jan 1970 00:00:00 -
+++ lib/libc/sys/utrace.2 18 Jul 2011 09:28:15 -
@@ -0,0 +1,93 @@
+.\$OpenBSD: utrace.2,v 1.13 2008/05/02 18:38:32 martin Exp $
+.\$NetBSD: utrace.2,v 1.13 2008/05/02 18:38:32 martin Exp $
+.\
+.\ Copyright (c) 2000 The NetBSD Foundation, Inc.
+.\ All rights reserved.
+.\
+.\ This code is derived from software contributed to The NetBSD Foundation
+.\ by Gregory McGarry g.mcga...@ieee.org.
+.\
+.\ Redistribution and use in source and binary forms, with or without
+.\ modification, are permitted provided that the following conditions
+.\ are met:
+.\ 1. Redistributions of source code must retain the above copyright
+.\notice, this list of conditions and the following disclaimer.
+.\ 2. Redistributions in binary form must reproduce the above copyright
+.\notice, this list of conditions and the following disclaimer in the
+.\documentation and/or other materials provided with the distribution.
+.\
+.\ THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+.\ ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+.\ TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+.\ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+.\ BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+.\ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+.\ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+.\ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING