Expand the decoding of kevent structures.

- Print the ident value as decimal instead of hexadecimal for filter types
  that use "small" values such as file descriptors and PIDs.
- Decode NOTE_* flags in the fflags field of kevents for several system
  filter types.
This commit is contained in:
John Baldwin 2015-08-19 01:44:56 +00:00
parent f083f6894c
commit c915ff0349

View File

@ -397,6 +397,30 @@ static struct xlat kevent_flags[] = {
X(EV_DROP) X(EV_FLAG1) X(EV_ERROR) X(EV_EOF) XEND
};
static struct xlat kevent_user_ffctrl[] = {
X(NOTE_FFNOP) X(NOTE_FFAND) X(NOTE_FFOR) X(NOTE_FFCOPY)
XEND
};
static struct xlat kevent_rdwr_fflags[] = {
X(NOTE_LOWAT) X(NOTE_FILE_POLL) XEND
};
static struct xlat kevent_vnode_fflags[] = {
X(NOTE_DELETE) X(NOTE_WRITE) X(NOTE_EXTEND) X(NOTE_ATTRIB)
X(NOTE_LINK) X(NOTE_RENAME) X(NOTE_REVOKE) XEND
};
static struct xlat kevent_proc_fflags[] = {
X(NOTE_EXIT) X(NOTE_FORK) X(NOTE_EXEC) X(NOTE_TRACK) X(NOTE_TRACKERR)
X(NOTE_CHILD) XEND
};
static struct xlat kevent_timer_fflags[] = {
X(NOTE_SECONDS) X(NOTE_MSECONDS) X(NOTE_USECONDS) X(NOTE_NSECONDS)
XEND
};
static struct xlat poll_flags[] = {
X(POLLSTANDARD) X(POLLIN) X(POLLPRI) X(POLLOUT) X(POLLERR)
X(POLLHUP) X(POLLNVAL) X(POLLRDNORM) X(POLLRDBAND)
@ -742,6 +766,64 @@ strsig2(int sig)
return (ret);
}
static void
print_kevent(FILE *fp, struct kevent *ke, int input)
{
switch (ke->filter) {
case EVFILT_READ:
case EVFILT_WRITE:
case EVFILT_VNODE:
case EVFILT_PROC:
case EVFILT_TIMER:
case EVFILT_PROCDESC:
fprintf(fp, "%ju", (uintmax_t)ke->ident);
break;
case EVFILT_SIGNAL:
fputs(strsig2(ke->ident), fp);
break;
default:
fprintf(fp, "%p", (void *)ke->ident);
}
fprintf(fp, ",%s,%s,", xlookup(kevent_filters, ke->filter),
xlookup_bits(kevent_flags, ke->flags));
switch (ke->filter) {
case EVFILT_READ:
case EVFILT_WRITE:
fputs(xlookup_bits(kevent_rdwr_fflags, ke->fflags), fp);
break;
case EVFILT_VNODE:
fputs(xlookup_bits(kevent_vnode_fflags, ke->fflags), fp);
break;
case EVFILT_PROC:
case EVFILT_PROCDESC:
fputs(xlookup_bits(kevent_proc_fflags, ke->fflags), fp);
break;
case EVFILT_TIMER:
fputs(xlookup_bits(kevent_timer_fflags, ke->fflags), fp);
break;
case EVFILT_USER: {
int ctrl, data;
ctrl = ke->fflags & NOTE_FFCTRLMASK;
data = ke->fflags & NOTE_FFLAGSMASK;
if (input) {
fputs(xlookup(kevent_user_ffctrl, ctrl), fp);
if (ke->fflags & NOTE_TRIGGER)
fputs("|NOTE_TRIGGER", fp);
if (data != 0)
fprintf(fp, "|%#x", data);
} else {
fprintf(fp, "%#x", data);
}
break;
}
default:
fprintf(fp, "%#x", ke->fflags);
}
fprintf(fp, ",%p,%p", (void *)ke->data, (void *)ke->udata);
}
/*
* print_arg
* Converts a syscall argument into a string. Said string is
@ -1281,14 +1363,10 @@ print_arg(struct syscall_args *sc, unsigned long *args, long retval,
if (numevents >= 0 && get_struct(pid, (void *)args[sc->offset],
ke, bytes) != -1) {
fputc('{', fp);
for (i = 0; i < numevents; i++)
fprintf(fp, " %p,%s,%s,%d,%p,%p",
(void *)ke[i].ident,
xlookup(kevent_filters, ke[i].filter),
xlookup_bits(kevent_flags, ke[i].flags),
ke[i].fflags,
(void *)ke[i].data,
(void *)ke[i].udata);
for (i = 0; i < numevents; i++) {
fputc(' ', fp);
print_kevent(fp, &ke[i], sc->offset == 1);
}
fputs(" }", fp);
} else {
fprintf(fp, "0x%lx", args[sc->offset]);