dtrace anonymous tracing
Prashanth Kumar
pra_udupi at yahoo.co.in
Thu Nov 21 11:55:19 UTC 2013
Looks like code for anonymous tracing is already present. If you read the /boot/dtrace.dof
file from the loader and set it as a environment variable it will work.
I tested it with the following patch just to see whether it would work.
------------------------------------------------------------------------------------------------------------------------
--- main.c 2013-11-21 12:03:57.000000000 +0400
+++ /usr/src/sys/boot/i386/loader/main.c 2013-11-21 12:44:23.000000000 +0400
@@ -84,6 +84,11 @@
main(void)
{
int i;
+
+ char *dtracedof = "/boot/dtrace.dof";
+ int fd, n=0, l=0;
+ char *buf, *s, *e, c[32];
+ struct stat dstat;
/* Pick up arguments */
kargs = (void *)__args;
@@ -190,6 +195,40 @@
extract_currdev(); /* set $currdev and $loaddev */
setenv("LINES", "24", 1); /* optional */
+ if ((fd = open(dtracedof, O_RDONLY)) == -1)
+ printf("Error opening dtrace file %s\n", dtracedof);
+ else if (fstat(fd, &dstat) == -1)
+ printf("Can't access %s\n", dtracedof);
+ else if ((buf = malloc(dstat.st_size+1)) == NULL)
+ printf("Error allocating mem size %d - %s\n", dstat.st_size, dtracedof);
+ else if (read(fd, buf, dstat.st_size) < dstat.st_size)
+ printf("Error reading file %s size %d\n", dtracedof, dstat.st_size);
+ else {
+ for (i = 0; ; i++) {
+ (void) sprintf(c, "dof-data-%d", i);
+ l = strlen(c);
+ if (strncmp(c, buf, l) != 0) {
+ printf("Malformed name %s\n", c);
+ close(fd);
+ free(buf);
+ break;
+ }
+ s = e = &buf[l+1];
+ n += l+1;
+ while(*e != '\n')
+ e++;
+ *e = 0;
+ //printf("string %s %s\n",c, s);
+ setenv(c, s, 1);
+ n += e - s;
+ n++;
+ if (n < dstat.st_size)
+ buf = ++e;
+ else
+ break;
+ }
+ }
+
bios_getsmap();
interact(); /* doesn't return */
-----------------------------------------------------------------------------------------------------------------------------
Kernel environment variable value has to be in increased.
In sys/kenv.h,
--------------------------------------------------------------------------
--- kenv.h 2013-11-21 14:31:50.000000000 +0400
+++ /usr/src/sys/sys/kenv.h 2013-11-21 14:32:05.000000000 +0400
@@ -38,6 +38,6 @@
#define KENV_DUMP 3
#define KENV_MNAMELEN 128 /* Maximum name length (for the syscall) */
-#define KENV_MVALLEN 128 /* Maximum value length (for the syscall) */
+#define KENV_MVALLEN 3000 /* Maximum value length (for the syscall) */
#endif /* !_SYS_KENV_H_ */
----------------------------------------------------------------------------------------------------------------
example : $> dtrace -A vboxguest
$> reboot
$>dtrace -a
Probably be better to read dtrace.dof from dtrace module itself.
regards
Prashanth
--------------------------------------------
On Wed, 20/11/13, Andriy Gapon <avg at FreeBSD.org> wrote:
Subject: Re: dtrace anonymous tracing
To: "Prashanth Kumar" <pra_udupi at yahoo.co.in>, freebsd-dtrace at FreeBSD.org
Date: Wednesday, 20 November, 2013, 4:45 PM
on 20/11/2013 12:18 Prashanth Kumar
said the following:
> Is it possible to enable dtrace anonymous tracing in
freebsd?
>
Not without some kernel coding, I believe :-)
--
Andriy Gapon
More information about the freebsd-dtrace
mailing list