2006-10-23 08:13:51 +04:00
|
|
|
/* $NetBSD: dump.c,v 1.27 2006/10/23 04:21:51 mrg Exp $ */
|
1999-07-12 08:13:34 +04:00
|
|
|
|
1999-07-12 07:20:17 +04:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1988, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* 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.
|
2003-08-07 15:13:06 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1999-07-12 07:20:17 +04:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
#ifndef lint
|
|
|
|
__COPYRIGHT("@(#) Copyright (c) 1988, 1993\n\
|
|
|
|
The Regents of the University of California. All rights reserved.\n");
|
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#ifndef lint
|
|
|
|
#if 0
|
|
|
|
static char sccsid[] = "@(#)kdump.c 8.4 (Berkeley) 4/28/95";
|
|
|
|
#endif
|
2006-10-23 08:13:51 +04:00
|
|
|
__RCSID("$NetBSD: dump.c,v 1.27 2006/10/23 04:21:51 mrg Exp $");
|
1999-07-12 07:20:17 +04:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#define _KERNEL
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#undef _KERNEL
|
2004-02-27 01:00:57 +03:00
|
|
|
#include <sys/ioctl.h>
|
1999-07-12 07:20:17 +04:00
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/uio.h>
|
|
|
|
#include <sys/ktrace.h>
|
|
|
|
#include <sys/ptrace.h>
|
2004-02-27 01:00:57 +03:00
|
|
|
#include <sys/queue.h>
|
1999-07-12 07:20:17 +04:00
|
|
|
|
|
|
|
#include <err.h>
|
|
|
|
#include <signal.h>
|
2004-02-27 01:00:57 +03:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stddef.h>
|
1999-07-12 07:20:17 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <vis.h>
|
|
|
|
|
|
|
|
#include "ktrace.h"
|
|
|
|
#include "misc.h"
|
2000-04-10 13:42:37 +04:00
|
|
|
#include "setemul.h"
|
1999-07-12 07:20:17 +04:00
|
|
|
|
|
|
|
int timestamp, decimal, fancy = 1, tail, maxdata;
|
|
|
|
|
2004-02-27 01:00:57 +03:00
|
|
|
int width; /* Keep track of current columns. */
|
1999-07-12 07:20:17 +04:00
|
|
|
|
|
|
|
#include <sys/syscall.h>
|
|
|
|
|
2004-02-27 01:00:57 +03:00
|
|
|
static const char *const ptrace_ops[] = {
|
1999-07-12 07:20:17 +04:00
|
|
|
"PT_TRACE_ME", "PT_READ_I", "PT_READ_D", "PT_READ_U",
|
|
|
|
"PT_WRITE_I", "PT_WRITE_D", "PT_WRITE_U", "PT_CONTINUE",
|
|
|
|
"PT_KILL", "PT_ATTACH", "PT_DETACH",
|
|
|
|
};
|
|
|
|
|
2004-02-27 01:00:57 +03:00
|
|
|
struct ktr_entry {
|
|
|
|
TAILQ_ENTRY(ktr_entry) kte_list;
|
|
|
|
struct ktr_header kte_kth;
|
|
|
|
};
|
1999-07-12 07:20:17 +04:00
|
|
|
|
2004-02-27 01:00:57 +03:00
|
|
|
TAILQ_HEAD(kteq, ktr_entry) ktependq = TAILQ_HEAD_INITIALIZER(ktependq);
|
|
|
|
|
|
|
|
void argprint(const char *, register_t **, int *);
|
|
|
|
void dumpheader(struct ktr_header *);
|
|
|
|
int dumprecord(int, FILE *);
|
|
|
|
void flushpendq(struct ktr_entry *);
|
|
|
|
int fread_tail(void *, int, int, FILE *);
|
|
|
|
void genioprint(struct ktr_header *);
|
|
|
|
struct ktr_entry *
|
|
|
|
getpendq(struct ktr_header *, int, struct kteq *);
|
|
|
|
struct ktr_entry *
|
|
|
|
getrecord(FILE *);
|
|
|
|
void indent(int);
|
|
|
|
void ioctldecode(u_long);
|
|
|
|
void ktrcsw(struct ktr_entry *);
|
|
|
|
void ktremul(struct ktr_entry *);
|
|
|
|
void ktrgenio(struct ktr_entry *);
|
|
|
|
void ktrnamei(struct ktr_entry *);
|
|
|
|
void ktrpsig(struct ktr_entry *);
|
|
|
|
void ktrsyscall(struct ktr_entry *);
|
|
|
|
void ktrsysret(struct ktr_entry *);
|
|
|
|
void nameiargprint(const char *, struct ktr_header *, register_t **, int *);
|
|
|
|
void nameiprint(struct ktr_header *);
|
|
|
|
void newline(void);
|
|
|
|
void putpendq(struct ktr_entry *);
|
|
|
|
void syscallnameprint(int);
|
|
|
|
void syscallprint(struct ktr_header *);
|
|
|
|
void sysretprint(struct ktr_header *);
|
|
|
|
int wprintf(const char *, ...);
|
|
|
|
void *xrealloc(void *, size_t *, size_t);
|
1999-07-12 07:20:17 +04:00
|
|
|
|
2004-02-27 01:00:57 +03:00
|
|
|
int
|
|
|
|
wprintf(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
int w;
|
1999-07-12 07:20:17 +04:00
|
|
|
|
2004-02-27 01:00:57 +03:00
|
|
|
va_start(ap, fmt);
|
|
|
|
w = vprintf(fmt, ap);
|
|
|
|
if (w == -1)
|
|
|
|
warn("vprintf");
|
|
|
|
else
|
|
|
|
width += w;
|
|
|
|
va_end(ap);
|
|
|
|
return (w);
|
|
|
|
}
|
1999-07-12 07:20:17 +04:00
|
|
|
|
|
|
|
void
|
2004-02-27 01:00:57 +03:00
|
|
|
newline(void)
|
1999-07-12 07:20:17 +04:00
|
|
|
{
|
2004-02-27 01:00:57 +03:00
|
|
|
|
|
|
|
if (width > 0) {
|
|
|
|
printf("\n");
|
|
|
|
width = 0;
|
1999-07-12 07:20:17 +04:00
|
|
|
}
|
2004-02-27 01:00:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
indent(int col)
|
|
|
|
{
|
|
|
|
|
|
|
|
while (width < col)
|
|
|
|
if (wprintf(" ") < 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
xrealloc(void *p, size_t *siz, size_t req)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (*siz < req) {
|
|
|
|
if (*siz == 0)
|
|
|
|
*siz = 1;
|
|
|
|
while (*siz < req)
|
|
|
|
*siz <<= 1;
|
|
|
|
p = realloc(p, *siz);
|
|
|
|
if (p == NULL)
|
|
|
|
err(EXIT_FAILURE, "realloc: %lu bytes",
|
|
|
|
(u_long)*siz);
|
|
|
|
}
|
|
|
|
return (p);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ktr_entry *
|
|
|
|
getrecord(FILE *fp)
|
|
|
|
{
|
|
|
|
struct ktr_entry *kte;
|
|
|
|
struct ktr_header *kth;
|
|
|
|
char *cp;
|
|
|
|
size_t siz, len;
|
|
|
|
|
|
|
|
siz = 0;
|
|
|
|
kte = xrealloc(NULL, &siz, sizeof(struct ktr_entry));
|
|
|
|
kth = &kte->kte_kth;
|
|
|
|
if (fread_tail(kth, sizeof(struct ktr_header), 1, fp) == 0) {
|
|
|
|
free(kte);
|
|
|
|
return (NULL);
|
1999-07-12 07:20:17 +04:00
|
|
|
}
|
2000-04-10 13:42:37 +04:00
|
|
|
|
2006-10-22 20:20:39 +04:00
|
|
|
if (kth->ktr_len < 0)
|
|
|
|
errx(EXIT_FAILURE, "bogus length 0x%x", kth->ktr_len);
|
2004-02-27 01:00:57 +03:00
|
|
|
len = kth->ktr_len;
|
|
|
|
if (len > 0) {
|
|
|
|
/* + 1 to ensure room for NUL terminate */
|
|
|
|
kte = xrealloc(kte, &siz, sizeof(struct ktr_entry) + len + 1);
|
|
|
|
if (fread_tail(cp = (char *)(&kte->kte_kth + 1),
|
|
|
|
len, 1, fp) == 0)
|
|
|
|
errx(EXIT_FAILURE, "data too short");
|
|
|
|
cp[len] = 0;
|
|
|
|
}
|
2000-04-10 13:42:37 +04:00
|
|
|
|
2004-02-27 01:00:57 +03:00
|
|
|
return (kte);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX: lwp. */
|
|
|
|
#define KTE_TYPE(kte) ((kte)->kte_kth.ktr_type)
|
|
|
|
#define KTE_PID(kte) ((kte)->kte_kth.ktr_pid)
|
|
|
|
#define KTE_MATCH(kte, type, pid) \
|
|
|
|
(KTE_TYPE(kte) == (type) && KTE_PID(kte) == (pid))
|
|
|
|
|
|
|
|
void
|
|
|
|
putpendq(struct ktr_entry *kte)
|
|
|
|
{
|
|
|
|
|
|
|
|
TAILQ_INSERT_TAIL(&ktependq, kte, kte_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
flushpendq(struct ktr_entry *us)
|
|
|
|
{
|
|
|
|
struct ktr_entry *kte, *kte_next;
|
|
|
|
int pid = KTE_PID(us);
|
|
|
|
|
|
|
|
for (kte = TAILQ_FIRST(&ktependq); kte != NULL; kte = kte_next) {
|
|
|
|
kte_next = TAILQ_NEXT(kte, kte_list);
|
|
|
|
if (KTE_PID(kte) == pid) {
|
|
|
|
TAILQ_REMOVE(&ktependq, kte, kte_list);
|
|
|
|
free(kte);
|
1999-07-12 07:20:17 +04:00
|
|
|
}
|
2004-02-27 01:00:57 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ktr_entry *
|
|
|
|
getpendq(struct ktr_header *us, int type, struct kteq *kteq)
|
|
|
|
{
|
|
|
|
struct ktr_entry *kte, *kte_next;
|
|
|
|
int pid = us->ktr_pid;
|
|
|
|
|
|
|
|
if (kteq != NULL)
|
|
|
|
TAILQ_INIT(kteq);
|
|
|
|
for (kte = TAILQ_FIRST(&ktependq); kte != NULL; kte = kte_next) {
|
|
|
|
kte_next = TAILQ_NEXT(kte, kte_list);
|
|
|
|
if (KTE_MATCH(kte, type, pid)) {
|
|
|
|
TAILQ_REMOVE(&ktependq, kte, kte_list);
|
|
|
|
if (kteq != NULL)
|
|
|
|
TAILQ_INSERT_TAIL(kteq, kte, kte_list);
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (kteq ? TAILQ_FIRST(kteq) : kte);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
dumprecord(int trpoints, FILE *fp)
|
|
|
|
{
|
|
|
|
struct ktr_entry *kte;
|
|
|
|
struct ktr_header *kth;
|
|
|
|
|
|
|
|
kte = getrecord(fp);
|
|
|
|
if (kte == NULL)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
kth = &kte->kte_kth;
|
|
|
|
if ((trpoints & (1 << kth->ktr_type)) == 0) {
|
|
|
|
free(kte);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update context to match currently processed record. */
|
|
|
|
ectx_sanify(kth->ktr_pid);
|
|
|
|
|
|
|
|
switch (kth->ktr_type) {
|
|
|
|
case KTR_SYSCALL:
|
|
|
|
ktrsyscall(kte);
|
1999-07-12 07:20:17 +04:00
|
|
|
break;
|
|
|
|
case KTR_SYSRET:
|
2004-02-27 01:00:57 +03:00
|
|
|
ktrsysret(kte);
|
1999-07-12 07:20:17 +04:00
|
|
|
break;
|
|
|
|
case KTR_NAMEI:
|
2004-02-27 01:00:57 +03:00
|
|
|
putpendq(kte);
|
1999-07-12 07:20:17 +04:00
|
|
|
break;
|
|
|
|
case KTR_GENIO:
|
2004-02-27 01:00:57 +03:00
|
|
|
putpendq(kte);
|
1999-07-12 07:20:17 +04:00
|
|
|
break;
|
|
|
|
case KTR_PSIG:
|
2004-02-27 01:00:57 +03:00
|
|
|
ktrpsig(kte);
|
1999-07-12 07:20:17 +04:00
|
|
|
break;
|
|
|
|
case KTR_CSW:
|
2004-02-27 01:00:57 +03:00
|
|
|
ktrcsw(kte);
|
1999-07-12 07:20:17 +04:00
|
|
|
break;
|
|
|
|
case KTR_EMUL:
|
2004-02-27 01:00:57 +03:00
|
|
|
ktremul(kte);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/*
|
|
|
|
* XXX: Other types added recently.
|
|
|
|
*/
|
|
|
|
free(kte);
|
1999-07-12 07:20:17 +04:00
|
|
|
break;
|
|
|
|
}
|
2004-02-27 01:00:57 +03:00
|
|
|
newline();
|
1999-07-12 07:20:17 +04:00
|
|
|
|
2004-02-27 01:00:57 +03:00
|
|
|
out:
|
|
|
|
return (1);
|
1999-07-12 07:20:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-02-27 01:00:57 +03:00
|
|
|
dumpfile(const char *file, int fd, int trpoints)
|
1999-07-12 07:20:17 +04:00
|
|
|
{
|
|
|
|
FILE *fp;
|
2004-02-27 01:00:57 +03:00
|
|
|
|
|
|
|
if (file == NULL || *file == 0) {
|
|
|
|
if ((fp = fdopen(fd, "r")) == NULL)
|
|
|
|
err(EXIT_FAILURE, "fdopen(%d)", fd);
|
|
|
|
} else if (strcmp(file, "-") == 0)
|
1999-07-12 07:20:17 +04:00
|
|
|
fp = stdin;
|
2004-02-27 01:00:57 +03:00
|
|
|
else if ((fp = fopen(file, "r")) == NULL)
|
|
|
|
err(EXIT_FAILURE, "fopen: %s", file);
|
1999-07-12 07:20:17 +04:00
|
|
|
|
2004-02-27 01:00:57 +03:00
|
|
|
for (width = 0; dumprecord(trpoints, fp) != 0;)
|
1999-07-12 07:20:17 +04:00
|
|
|
if (tail)
|
|
|
|
(void)fflush(stdout);
|
|
|
|
|
2004-02-27 01:00:57 +03:00
|
|
|
newline();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX: Dump pending KTR_SYSCALL if any?
|
|
|
|
*/
|
|
|
|
}
|
1999-07-12 07:20:17 +04:00
|
|
|
|
|
|
|
int
|
2004-02-27 01:00:57 +03:00
|
|
|
fread_tail(void *buf, int size, int num, FILE *fp)
|
1999-07-12 07:20:17 +04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
while ((i = fread(buf, size, num, fp)) == 0 && tail) {
|
|
|
|
(void)sleep(1);
|
1999-07-29 05:53:26 +04:00
|
|
|
clearerr(fp);
|
1999-07-12 07:20:17 +04:00
|
|
|
}
|
|
|
|
return (i);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-02-27 01:00:57 +03:00
|
|
|
dumpheader(struct ktr_header *kth)
|
1999-07-12 07:20:17 +04:00
|
|
|
{
|
2005-12-11 14:30:06 +03:00
|
|
|
union timeholder {
|
|
|
|
struct timeval tv;
|
|
|
|
struct timespec ts;
|
|
|
|
};
|
|
|
|
static union timeholder prevtime;
|
|
|
|
union timeholder temp;
|
|
|
|
|
|
|
|
wprintf("%6d ", kth->ktr_pid);
|
|
|
|
if (kth->ktr_version > KTRFACv0)
|
|
|
|
wprintf("%6d ", kth->ktr_lid);
|
|
|
|
wprintf("%-8.*s ", MAXCOMLEN, kth->ktr_comm);
|
1999-07-12 07:20:17 +04:00
|
|
|
if (timestamp) {
|
|
|
|
if (timestamp == 2) {
|
2005-12-11 14:30:06 +03:00
|
|
|
if (kth->ktr_version == KTRFACv0) {
|
|
|
|
if (prevtime.tv.tv_sec == 0)
|
|
|
|
temp.tv.tv_sec = temp.tv.tv_usec = 0;
|
|
|
|
else
|
|
|
|
timersub(&kth->ktr_tv,
|
|
|
|
&prevtime.tv, &temp.tv);
|
|
|
|
prevtime.tv = kth->ktr_tv;
|
|
|
|
} else {
|
|
|
|
if (prevtime.ts.tv_sec == 0)
|
|
|
|
temp.ts.tv_sec = temp.ts.tv_nsec = 0;
|
|
|
|
else
|
|
|
|
timespecsub(&kth->ktr_time,
|
|
|
|
&prevtime.ts, &temp.ts);
|
|
|
|
prevtime.ts = kth->ktr_time;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (kth->ktr_version == KTRFACv0)
|
|
|
|
temp.tv = kth->ktr_tv;
|
|
|
|
else
|
|
|
|
temp.ts = kth->ktr_time;
|
|
|
|
}
|
|
|
|
if (kth->ktr_version == KTRFACv0)
|
|
|
|
wprintf("%ld.%06ld ",
|
|
|
|
(long)temp.tv.tv_sec, (long)temp.tv.tv_usec);
|
|
|
|
else
|
|
|
|
wprintf("%ld.%09ld ",
|
|
|
|
(long)temp.ts.tv_sec, (long)temp.ts.tv_nsec);
|
1999-07-12 07:20:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-02-27 01:00:57 +03:00
|
|
|
ioctldecode(u_long cmd)
|
1999-07-12 07:20:17 +04:00
|
|
|
{
|
|
|
|
char dirbuf[4], *dir = dirbuf;
|
|
|
|
|
|
|
|
if (cmd & IOC_OUT)
|
|
|
|
*dir++ = 'W';
|
|
|
|
if (cmd & IOC_IN)
|
|
|
|
*dir++ = 'R';
|
|
|
|
*dir = '\0';
|
|
|
|
|
2004-02-27 01:00:57 +03:00
|
|
|
wprintf(decimal ? ", _IO%s('%c',%ld" : ", _IO%s('%c',%#lx",
|
2000-10-12 23:02:17 +04:00
|
|
|
dirbuf, (int) ((cmd >> 8) & 0xff), cmd & 0xff);
|
1999-07-12 07:20:17 +04:00
|
|
|
if ((cmd & IOC_VOID) == 0)
|
2004-02-27 01:00:57 +03:00
|
|
|
wprintf(decimal ? ",%ld)" : ",%#lx)",
|
|
|
|
(cmd >> 16) & 0xff);
|
1999-07-12 07:20:17 +04:00
|
|
|
else
|
2004-02-27 01:00:57 +03:00
|
|
|
wprintf(")");
|
1999-07-12 07:20:17 +04:00
|
|
|
}
|
|
|
|
|
2004-02-27 01:00:57 +03:00
|
|
|
void
|
|
|
|
nameiargprint(const char *prefix, struct ktr_header *kth,
|
|
|
|
register_t **ap, int *argsize)
|
1999-07-12 07:20:17 +04:00
|
|
|
{
|
2004-02-27 01:00:57 +03:00
|
|
|
struct ktr_entry *kte;
|
|
|
|
|
|
|
|
if (*argsize == 0)
|
|
|
|
errx(EXIT_FAILURE, "argument expected");
|
|
|
|
/*
|
|
|
|
* XXX: binary emulation mode.
|
|
|
|
*/
|
|
|
|
kte = getpendq(kth, KTR_NAMEI, NULL);
|
|
|
|
if (kte == NULL)
|
|
|
|
argprint(prefix, ap, argsize);
|
|
|
|
else {
|
|
|
|
wprintf("%s", prefix);
|
|
|
|
nameiprint(&kte->kte_kth);
|
|
|
|
free(kte);
|
|
|
|
(*ap)++;
|
|
|
|
*argsize -= sizeof(register_t);
|
1999-07-12 07:20:17 +04:00
|
|
|
}
|
2004-02-27 01:00:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
syscallnameprint(int code)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (code >= cur_emul->nsysnames || code < 0)
|
|
|
|
wprintf("[%d]", code);
|
|
|
|
else
|
|
|
|
wprintf("%s", cur_emul->sysnames[code]);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
argprint(const char *prefix, register_t **ap, int *argsize)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (decimal)
|
|
|
|
wprintf("%s%ld", prefix, (long)**ap);
|
|
|
|
else
|
|
|
|
wprintf("%s%#lx", prefix, (long)**ap);
|
|
|
|
(*ap)++;
|
|
|
|
*argsize -= sizeof(register_t);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
syscallprint(struct ktr_header *kth)
|
|
|
|
{
|
|
|
|
struct ktr_syscall *ktr = (struct ktr_syscall *)(kth + 1);
|
|
|
|
register_t *ap;
|
2005-07-17 12:44:08 +04:00
|
|
|
const char *s;
|
2004-02-27 01:00:57 +03:00
|
|
|
int argsize;
|
|
|
|
|
|
|
|
syscallnameprint(ktr->ktr_code);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Arguments processing.
|
|
|
|
*/
|
|
|
|
argsize = ktr->ktr_argsize;
|
|
|
|
if (argsize == 0) {
|
|
|
|
wprintf("(");
|
|
|
|
goto noargument;
|
1999-07-12 07:20:17 +04:00
|
|
|
}
|
2004-02-27 01:00:57 +03:00
|
|
|
|
|
|
|
ap = (register_t *)(ktr + 1);
|
|
|
|
if (!fancy)
|
|
|
|
goto print_first;
|
|
|
|
|
|
|
|
switch (ktr->ktr_code) {
|
|
|
|
/*
|
|
|
|
* All these have a path as the first param.
|
|
|
|
* The order is same as syscalls.master.
|
|
|
|
*/
|
|
|
|
case SYS_open:
|
|
|
|
case SYS_link:
|
|
|
|
case SYS_unlink:
|
|
|
|
case SYS_chdir:
|
|
|
|
case SYS_mknod:
|
|
|
|
case SYS_chmod:
|
|
|
|
case SYS_chown:
|
|
|
|
case SYS_unmount:
|
|
|
|
case SYS_access:
|
|
|
|
case SYS_chflags:
|
|
|
|
case SYS_acct:
|
|
|
|
case SYS_revoke:
|
|
|
|
case SYS_symlink:
|
|
|
|
case SYS_readlink:
|
|
|
|
case SYS_execve:
|
|
|
|
case SYS_chroot:
|
|
|
|
case SYS_rename:
|
|
|
|
case SYS_mkfifo:
|
|
|
|
case SYS_mkdir:
|
|
|
|
case SYS_rmdir:
|
|
|
|
case SYS_utimes:
|
|
|
|
case SYS_quotactl:
|
2004-04-21 05:05:31 +04:00
|
|
|
case SYS_statvfs1:
|
2006-07-13 16:00:24 +04:00
|
|
|
case SYS_compat_30_getfh:
|
2004-02-27 01:00:57 +03:00
|
|
|
case SYS_pathconf:
|
|
|
|
case SYS_truncate:
|
|
|
|
case SYS_undelete:
|
|
|
|
case SYS___posix_rename:
|
|
|
|
case SYS_lchmod:
|
|
|
|
case SYS_lchown:
|
|
|
|
case SYS_lutimes:
|
2005-08-19 06:07:18 +04:00
|
|
|
case SYS___stat30:
|
|
|
|
case SYS___lstat30:
|
2004-02-27 01:00:57 +03:00
|
|
|
case SYS___posix_chown:
|
|
|
|
case SYS___posix_lchown:
|
|
|
|
case SYS_lchflags:
|
2006-07-13 16:00:24 +04:00
|
|
|
case SYS___getfh30:
|
2004-02-27 01:00:57 +03:00
|
|
|
nameiargprint("(", kth, &ap, &argsize);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 2nd argument is also pathname.
|
|
|
|
*/
|
|
|
|
switch (ktr->ktr_code) {
|
|
|
|
case SYS_link:
|
|
|
|
case SYS_rename:
|
|
|
|
case SYS___posix_rename:
|
|
|
|
nameiargprint(", ", kth, &ap, &argsize);
|
|
|
|
break;
|
1999-07-12 07:20:17 +04:00
|
|
|
}
|
2004-02-27 01:00:57 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SYS_compat_16___sigaction14 :
|
|
|
|
wprintf("(%s", signals[(int)*ap].name);
|
|
|
|
ap++;
|
|
|
|
argsize -= sizeof(register_t);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SYS_ioctl :
|
|
|
|
argprint("(", &ap, &argsize);
|
|
|
|
if ((s = ioctlname(*ap)) != NULL)
|
|
|
|
wprintf(", %s", s);
|
|
|
|
else
|
|
|
|
ioctldecode(*ap);
|
|
|
|
ap++;
|
|
|
|
argsize -= sizeof(register_t);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SYS_ptrace :
|
2006-10-23 08:13:51 +04:00
|
|
|
if ((long)*ap >= 0 &&
|
2004-02-28 01:48:56 +03:00
|
|
|
*ap < sizeof(ptrace_ops) / sizeof(ptrace_ops[0]))
|
2004-02-27 01:00:57 +03:00
|
|
|
wprintf("(%s", ptrace_ops[*ap]);
|
|
|
|
else
|
|
|
|
wprintf("(%ld", (long)*ap);
|
|
|
|
ap++;
|
|
|
|
argsize -= sizeof(register_t);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
print_first:
|
|
|
|
argprint("(", &ap, &argsize);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Print rest of argument. */
|
|
|
|
while (argsize > 0)
|
|
|
|
argprint(", ", &ap, &argsize);
|
|
|
|
|
|
|
|
noargument:
|
|
|
|
wprintf(")");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ktrsyscall(struct ktr_entry *kte)
|
|
|
|
{
|
|
|
|
struct ktr_header *kth = &kte->kte_kth;
|
|
|
|
struct ktr_syscall *ktr = (struct ktr_syscall *)(kth + 1);
|
|
|
|
|
|
|
|
switch (ktr->ktr_code) {
|
|
|
|
case SYS_exit:
|
|
|
|
dumpheader(kth);
|
|
|
|
syscallprint(kth);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
putpendq(kte);
|
|
|
|
return;
|
1999-07-12 07:20:17 +04:00
|
|
|
}
|
|
|
|
|
2004-02-27 01:00:57 +03:00
|
|
|
free(kte);
|
1999-07-12 07:20:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-02-27 01:00:57 +03:00
|
|
|
sysretprint(struct ktr_header *kth)
|
1999-07-12 07:20:17 +04:00
|
|
|
{
|
2004-02-27 01:00:57 +03:00
|
|
|
struct ktr_sysret *ktr = (struct ktr_sysret *)(kth + 1);
|
|
|
|
register_t ret = ktr->ktr_retval;
|
|
|
|
int error = ktr->ktr_error;
|
1999-07-12 07:20:17 +04:00
|
|
|
|
2004-02-27 01:00:57 +03:00
|
|
|
indent(50);
|
1999-07-12 07:20:17 +04:00
|
|
|
if (error == EJUSTRETURN)
|
2004-02-27 01:00:57 +03:00
|
|
|
wprintf(" JUSTRETURN");
|
1999-07-12 07:20:17 +04:00
|
|
|
else if (error == ERESTART)
|
2004-02-27 01:00:57 +03:00
|
|
|
wprintf(" RESTART");
|
1999-07-12 07:20:17 +04:00
|
|
|
else if (error) {
|
2004-02-27 01:00:57 +03:00
|
|
|
wprintf(" Err#%d", error);
|
1999-07-12 07:20:17 +04:00
|
|
|
if (error < MAXERRNOS && error >= -2)
|
2004-02-27 01:00:57 +03:00
|
|
|
wprintf(" %s", errnos[error].name);
|
1999-07-12 07:20:17 +04:00
|
|
|
} else
|
2004-02-27 01:00:57 +03:00
|
|
|
switch (ktr->ktr_code) {
|
|
|
|
case SYS_mmap:
|
|
|
|
wprintf(" = %p", (long)ret);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
wprintf(" = %ld", (long)ret);
|
|
|
|
if (kth->ktr_len > offsetof(struct ktr_sysret,
|
|
|
|
ktr_retval_1) && ktr->ktr_retval_1 != 0)
|
|
|
|
wprintf(", %ld", (long)ktr->ktr_retval_1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ktrsysret(struct ktr_entry *kte)
|
|
|
|
{
|
|
|
|
struct ktr_header *kth = &kte->kte_kth;
|
|
|
|
struct ktr_sysret *ktr = (struct ktr_sysret *)(kth + 1);
|
|
|
|
struct ktr_entry *genio;
|
2005-07-17 13:45:50 +04:00
|
|
|
struct ktr_entry *syscall_ent;
|
2004-02-27 01:00:57 +03:00
|
|
|
|
|
|
|
dumpheader(kth);
|
|
|
|
|
|
|
|
/* Print syscall name and arguments. */
|
2005-07-17 13:45:50 +04:00
|
|
|
syscall_ent = getpendq(kth, KTR_SYSCALL, NULL);
|
|
|
|
if (syscall_ent == NULL)
|
2004-02-27 01:00:57 +03:00
|
|
|
/*
|
|
|
|
* Possibilly a child of fork/vfork, or tracing of
|
|
|
|
* process started during system call.
|
|
|
|
*/
|
|
|
|
syscallnameprint(ktr->ktr_code);
|
|
|
|
else {
|
2005-07-17 13:45:50 +04:00
|
|
|
syscallprint(&syscall_ent->kte_kth);
|
|
|
|
free(syscall_ent);
|
2004-02-27 01:00:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Print return value and an error if any. */
|
|
|
|
sysretprint(kth);
|
|
|
|
|
|
|
|
genio = getpendq(kth, KTR_GENIO, NULL);
|
|
|
|
if (genio != NULL) {
|
|
|
|
genioprint(&genio->kte_kth);
|
|
|
|
free(genio);
|
|
|
|
}
|
|
|
|
|
|
|
|
flushpendq(kte);
|
|
|
|
free(kte);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nameiprint(struct ktr_header *kth)
|
|
|
|
{
|
|
|
|
|
|
|
|
wprintf("\"%.*s\"", kth->ktr_len, (char *)(kth + 1));
|
1999-07-12 07:20:17 +04:00
|
|
|
}
|
|
|
|
|
2004-02-27 01:00:57 +03:00
|
|
|
#ifdef notused
|
1999-07-12 07:20:17 +04:00
|
|
|
void
|
2004-02-27 01:00:57 +03:00
|
|
|
ktrnamei(struct ktr_entry *kte)
|
1999-07-12 07:20:17 +04:00
|
|
|
{
|
2004-02-27 01:00:57 +03:00
|
|
|
struct ktr_header *kth = &kte->kte_kth;
|
|
|
|
|
|
|
|
dumpheader(kth);
|
|
|
|
wprintf("namei(");
|
|
|
|
nameiprint(kth);
|
|
|
|
wprintf(")");
|
|
|
|
|
|
|
|
free(kte);
|
1999-07-12 07:20:17 +04:00
|
|
|
}
|
2004-02-27 01:00:57 +03:00
|
|
|
#endif
|
1999-07-12 07:20:17 +04:00
|
|
|
|
|
|
|
void
|
2004-02-27 01:00:57 +03:00
|
|
|
ktremul(struct ktr_entry *kte)
|
1999-07-12 07:20:17 +04:00
|
|
|
{
|
2004-02-27 01:00:57 +03:00
|
|
|
struct ktr_header *kth = &kte->kte_kth;
|
|
|
|
char *emul = (char *)(kth + 1);
|
1999-07-12 07:20:17 +04:00
|
|
|
|
2004-02-27 01:00:57 +03:00
|
|
|
dumpheader(kth);
|
|
|
|
wprintf("emul(%s)", emul);
|
|
|
|
setemul(emul, kth->ktr_pid, 1);
|
|
|
|
|
|
|
|
free(kte);
|
1999-07-12 07:20:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-02-27 01:00:57 +03:00
|
|
|
genioprint(struct ktr_header *kth)
|
1999-07-12 07:20:17 +04:00
|
|
|
{
|
2004-02-27 01:00:57 +03:00
|
|
|
struct ktr_genio *ktr = (struct ktr_genio *)(kth + 1);
|
1999-07-12 07:20:17 +04:00
|
|
|
static int screenwidth = 0;
|
2004-02-27 01:00:57 +03:00
|
|
|
int datalen = kth->ktr_len - sizeof(struct ktr_genio);
|
|
|
|
/*
|
|
|
|
* Need to be unsigned type so that positive value is passed
|
|
|
|
* to vis(), which will call isgraph().
|
|
|
|
*/
|
|
|
|
unsigned char *dp = (unsigned char *)(ktr + 1);
|
|
|
|
int w;
|
|
|
|
char visbuf[5];
|
|
|
|
|
1999-07-12 07:20:17 +04:00
|
|
|
if (screenwidth == 0) {
|
|
|
|
struct winsize ws;
|
|
|
|
|
|
|
|
if (fancy && ioctl(fileno(stderr), TIOCGWINSZ, &ws) != -1 &&
|
|
|
|
ws.ws_col > 8)
|
|
|
|
screenwidth = ws.ws_col;
|
|
|
|
else
|
|
|
|
screenwidth = 80;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (maxdata && datalen > maxdata)
|
|
|
|
datalen = maxdata;
|
2004-02-27 01:00:57 +03:00
|
|
|
newline();
|
|
|
|
wprintf(" \"");
|
1999-07-12 07:20:17 +04:00
|
|
|
for (; datalen > 0; datalen--, dp++) {
|
2004-02-27 01:00:57 +03:00
|
|
|
(void) vis(visbuf, *dp, VIS_NL|VIS_TAB|VIS_CSTYLE,
|
|
|
|
/* We put NUL at the end of buffer when reading */
|
|
|
|
*(dp + 1));
|
1999-07-12 07:20:17 +04:00
|
|
|
visbuf[4] = '\0';
|
2004-02-27 01:00:57 +03:00
|
|
|
w = strlen(visbuf);
|
|
|
|
if (width + w + 2 >= screenwidth)
|
1999-07-12 07:20:17 +04:00
|
|
|
break;
|
2004-02-27 01:00:57 +03:00
|
|
|
wprintf("%s", visbuf);
|
|
|
|
if (width + 2 >= screenwidth)
|
1999-07-12 07:20:17 +04:00
|
|
|
break;
|
|
|
|
}
|
2004-02-27 01:00:57 +03:00
|
|
|
wprintf("\"");
|
1999-07-12 07:20:17 +04:00
|
|
|
}
|
|
|
|
|
2004-02-27 01:00:57 +03:00
|
|
|
#ifdef notused
|
1999-07-12 07:20:17 +04:00
|
|
|
void
|
2004-02-27 01:00:57 +03:00
|
|
|
ktrgenio(struct ktr_entry *kte)
|
1999-07-12 07:20:17 +04:00
|
|
|
{
|
2004-02-27 01:00:57 +03:00
|
|
|
struct ktr_header *kth = &kte->kte_kth;
|
|
|
|
struct ktr_genio *ktr = (struct ktr_genio *)(kth + 1);
|
|
|
|
|
|
|
|
dumpheader(kth);
|
|
|
|
wprintf("genio fd %d %s",
|
|
|
|
ktr->ktr_fd, ktr->ktr_rw ? "write" : "read");
|
|
|
|
genioprint(kth);
|
|
|
|
|
|
|
|
free(kte);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void
|
|
|
|
ktrpsig(struct ktr_entry *kte)
|
|
|
|
{
|
|
|
|
struct ktr_header *kth = &kte->kte_kth;
|
|
|
|
struct ktr_psig *psig = (struct ktr_psig *)(kth + 1);
|
|
|
|
|
|
|
|
dumpheader(kth);
|
|
|
|
wprintf("SIG%s ", sys_signame[psig->signo]);
|
1999-07-12 07:20:17 +04:00
|
|
|
if (psig->action == SIG_DFL)
|
2004-02-27 01:00:57 +03:00
|
|
|
wprintf("SIG_DFL");
|
1999-07-12 07:20:17 +04:00
|
|
|
else {
|
2004-02-27 01:00:57 +03:00
|
|
|
wprintf("caught handler=0x%lx mask=0x%lx code=0x%x",
|
2000-01-26 17:23:41 +03:00
|
|
|
(u_long)psig->action, (unsigned long)psig->mask.__bits[0],
|
|
|
|
psig->code);
|
1999-07-12 07:20:17 +04:00
|
|
|
}
|
2004-02-27 01:00:57 +03:00
|
|
|
|
|
|
|
free(kte);
|
1999-07-12 07:20:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-02-27 01:00:57 +03:00
|
|
|
ktrcsw(struct ktr_entry *kte)
|
1999-07-12 07:20:17 +04:00
|
|
|
{
|
2004-02-27 01:00:57 +03:00
|
|
|
struct ktr_header *kth = &kte->kte_kth;
|
|
|
|
struct ktr_csw *cs = (struct ktr_csw *)(kth + 1);
|
|
|
|
|
|
|
|
dumpheader(kth);
|
|
|
|
wprintf("%s %s", cs->out ? "stop" : "resume",
|
1999-07-12 07:20:17 +04:00
|
|
|
cs->user ? "user" : "kernel");
|
2004-02-27 01:00:57 +03:00
|
|
|
|
|
|
|
free(kte);
|
1999-07-12 07:20:17 +04:00
|
|
|
}
|