Hi, I'm newbie to OpenBSD.
I'm trying to learn OpenBSD kernel by btrace.
It is really helpful tool to me.
Thanks for the development and 6.7 release.

I found that brace sometimes read more than one event at the same time.
After that, same events are always read and evaluated by my btrace script.

I think btrace command reuses the read buffer for '/dev/dt' in each read.
It is cleared by nobody and overwritten by the kernel.
It seems that btrace expects zero is written at the end of the buffer,
But kernel doesn't write zeroes.

So if more than one events are read and then one event is read in next time,
the second event is still written and evaluated by btrace script.

I think number of read events should be determined by return value of read(2).
Following patch works for me.

Index: btrace.c
===================================================================
RCS file: /cvs/src/usr.sbin/btrace/btrace.c,v
retrieving revision 1.18
diff -u -p -r1.18 btrace.c
--- btrace.c    24 Apr 2020 14:56:43 -0000      1.18
+++ btrace.c    17 Jun 2020 08:25:49 -0000
@@ -339,12 +339,8 @@ rules_do(int fd)
                        err(1, "incorrect read");
 
 
-               for (i = 0; i < nitems(devtbuf); i++) {
+               for (i = 0; i < rlen / sizeof(struct dt_evt); i++) {
                        struct dt_evt *dtev = &devtbuf[i];
-
-                       if (dtev->dtev_tid == 0)
-                               break;
-
                        rules_apply(dtev);
                }
        }

-- 
Yuichiro NAITO (naito.yuich...@gmail.com)

Reply via email to