Start on a new library (libsysdecode) that provides routines for decoding
system call information such as system call arguments. Initially this will consist of pulling duplicated code out of truss and kdump though it may prove useful for other utilities in the future. This commit moves the shared utrace(2) record parser out of kdump into the library and updates kdump and truss to use it. One difference from the previous version is that the library version treats unknown events that start with the "RTLD" signature as unknown events. This simplifies the interface and allows the consumer to decide how to handle all non-recognized events. Instead, this function only generates a string description for known malloc() and RTLD records. Reviewed by: bdrewery Differential Revision: https://reviews.freebsd.org/D4537
This commit is contained in:
parent
37ded2a72c
commit
d6fb489498
@ -110,6 +110,7 @@ LINE("libsdp", "Bluetooth Service Discovery Protocol User Library (libsdp, \\-l
|
||||
LINE("libssp", "Buffer Overflow Protection Library (libssp, \\-lssp)")
|
||||
LINE("libstdthreads", "C11 Threads Library (libstdthreads, \\-lstdthreads)")
|
||||
LINE("libSystem", "System Library (libSystem, \\-lSystem)")
|
||||
LINE("libsysdcode", "System Argument Decoding Library (libsysdecode, \\-lsysdecode)")
|
||||
LINE("libtacplus", "TACACS+ Client Library (libtacplus, \\-ltacplus)")
|
||||
LINE("libtcplay", "TrueCrypt-compatible API library (libtcplay, \\-ltcplay)")
|
||||
LINE("libtermcap", "Termcap Access Library (libtermcap, \\-ltermcap)")
|
||||
|
@ -98,6 +98,7 @@ SUBDIR= ${SUBDIR_ORDERED} \
|
||||
libstand \
|
||||
libstdbuf \
|
||||
libstdthreads \
|
||||
libsysdecode \
|
||||
libtacplus \
|
||||
${_libtelnet} \
|
||||
${_libthr} \
|
||||
|
@ -28,7 +28,7 @@
|
||||
.\"
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd October 5, 2015
|
||||
.Dd December 11, 2015
|
||||
.Dt UTRACE 2
|
||||
.Os
|
||||
.Sh NAME
|
||||
@ -71,7 +71,8 @@ support
|
||||
.Xr kdump 1 ,
|
||||
.Xr ktrace 1 ,
|
||||
.Xr ktrace 2 ,
|
||||
.Xr truss 1
|
||||
.Xr truss 1 ,
|
||||
.Xr sysdecode_utrace 3
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Fn utrace
|
||||
|
13
lib/libsysdecode/Makefile
Normal file
13
lib/libsysdecode/Makefile
Normal file
@ -0,0 +1,13 @@
|
||||
# $FreeBSD$
|
||||
|
||||
.include <src.opts.mk>
|
||||
|
||||
LIB= sysdecode
|
||||
|
||||
SRCS= utrace.c
|
||||
INCS= sysdecode.h
|
||||
|
||||
MAN+= sysdecode.3 \
|
||||
sysdecode_utrace.3
|
||||
|
||||
.include <bsd.lib.mk>
|
47
lib/libsysdecode/sysdecode.3
Normal file
47
lib/libsysdecode/sysdecode.3
Normal file
@ -0,0 +1,47 @@
|
||||
.\"
|
||||
.\" Copyright (c) 2015 John Baldwin <jhb@FreeBSD.org>
|
||||
.\" 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.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
|
||||
.\"
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd December 10, 2015
|
||||
.Dt SYSDECODE 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm sysdecode
|
||||
.Nd system argument decoding library
|
||||
.Sh LIBRARY
|
||||
.Lb libsysdecode
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Nm
|
||||
library includes several functions that provide descriptive names of
|
||||
values associated with system calls.
|
||||
.Sh SEE ALSO
|
||||
.Xr sysdecode_utrace 3
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Nm
|
||||
library first appeared in
|
||||
.Fx 11.0 .
|
34
lib/libsysdecode/sysdecode.h
Normal file
34
lib/libsysdecode/sysdecode.h
Normal file
@ -0,0 +1,34 @@
|
||||
/*-
|
||||
* Copyright (c) 2015 John H. Baldwin <jhb@FreeBSD.org>
|
||||
* 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef __SYSDECODE_H__
|
||||
#define __SYSDECODE_H__
|
||||
|
||||
int sysdecode_utrace(FILE *_fp, void *_buf, size_t _len);
|
||||
|
||||
#endif /* !__SYSDECODE_H__ */
|
73
lib/libsysdecode/sysdecode_utrace.3
Normal file
73
lib/libsysdecode/sysdecode_utrace.3
Normal file
@ -0,0 +1,73 @@
|
||||
.\"
|
||||
.\" Copyright (c) 2015 John Baldwin <jhb@FreeBSD.org>
|
||||
.\" 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.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
|
||||
.\"
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd December 11, 2015
|
||||
.Dt sysdecode_utrace 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm sysdecode_utrace
|
||||
.Nd produce text description of a utrace record
|
||||
.Sh LIBRARY
|
||||
.Lb libsysdecode
|
||||
.Sh SYNOPSIS
|
||||
.Ft int
|
||||
.Fn sysdecode_utrace "FILE *fp" "void *buf" "size_t len" "int decimal"
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Fn sysdecode_utrace
|
||||
function outputs a textual representation of a
|
||||
.Xr utrace 2
|
||||
record identified by
|
||||
.Fa buf
|
||||
and
|
||||
.Fa len
|
||||
to the output stream
|
||||
.Fa fp .
|
||||
.Pp
|
||||
The function only outputs a representation for certain types of records.
|
||||
If a record is recognized,
|
||||
the function outputs the description and returns a non-zero value.
|
||||
If the record is not recognized,
|
||||
the function does not output anything and returns zero.
|
||||
The
|
||||
.Fn sysdecode_utrace
|
||||
function currently recognizes
|
||||
.Xr utrace 2
|
||||
records generated by
|
||||
.Xr malloc 3
|
||||
and
|
||||
.Xr rtld 1 .
|
||||
.Sh RETURN VALUES
|
||||
The
|
||||
.Fn sysdecode_utrace
|
||||
function returns a non-zero value if it recognizes a
|
||||
.Xr utrace 2
|
||||
record;
|
||||
otherwise it returns zero.
|
||||
.Sh SEE ALSO
|
||||
.Xr utrace 2 ,
|
||||
.Xr sysdecode 3
|
@ -34,8 +34,7 @@ __FBSDID("$FreeBSD$");
|
||||
#include <dlfcn.h>
|
||||
#include <stdio.h>
|
||||
#include <strings.h>
|
||||
|
||||
int kdump_print_utrace(FILE *, void *, size_t, int);
|
||||
#include <sysdecode.h>
|
||||
|
||||
#define UTRACE_DLOPEN_START 1
|
||||
#define UTRACE_DLOPEN_STOP 2
|
||||
@ -60,11 +59,10 @@ struct utrace_rtld {
|
||||
char name[MAXPATHLEN];
|
||||
};
|
||||
|
||||
static void
|
||||
print_utrace_rtld(FILE *fp, void *p, size_t len, int decimal)
|
||||
static int
|
||||
print_utrace_rtld(FILE *fp, void *p)
|
||||
{
|
||||
struct utrace_rtld *ut = p;
|
||||
unsigned char *cp;
|
||||
void *parent;
|
||||
int mode;
|
||||
|
||||
@ -136,16 +134,9 @@ print_utrace_rtld(FILE *fp, void *p, size_t len, int decimal)
|
||||
ut->name);
|
||||
break;
|
||||
default:
|
||||
cp = p;
|
||||
cp += 4;
|
||||
len -= 4;
|
||||
fprintf(fp, "RTLD: %zu ", len);
|
||||
while (len--)
|
||||
if (decimal)
|
||||
fprintf(fp, " %d", *cp++);
|
||||
else
|
||||
fprintf(fp, " %02x", *cp++);
|
||||
return (0);
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
struct utrace_malloc {
|
||||
@ -170,12 +161,11 @@ print_utrace_malloc(FILE *fp, void *p)
|
||||
}
|
||||
|
||||
int
|
||||
kdump_print_utrace(FILE *fp, void *p, size_t len, int decimal)
|
||||
sysdecode_utrace(FILE *fp, void *p, size_t len)
|
||||
{
|
||||
|
||||
if (len >= 8 && bcmp(p, "RTLD", 4) == 0) {
|
||||
print_utrace_rtld(fp, p, len, decimal);
|
||||
return (1);
|
||||
if (len == sizeof(struct utrace_rtld) && bcmp(p, "RTLD", 4) == 0) {
|
||||
return (print_utrace_rtld(fp, p));
|
||||
}
|
||||
|
||||
if (len == sizeof(struct utrace_malloc)) {
|
@ -134,6 +134,7 @@ LIBSSP_NONSHARED?= ${DESTDIR}${LIBDIR}/libssp_nonshared.a
|
||||
LIBSTAND?= ${DESTDIR}${LIBDIR}/libstand.a
|
||||
LIBSTDCPLUSPLUS?= ${DESTDIR}${LIBDIR}/libstdc++.a
|
||||
LIBSTDTHREADS?= ${DESTDIR}${LIBDIR}/libstdthreads.a
|
||||
LIBSYSDECODE?= ${DESTDIR}${LIBDIR}/libsysdecode.a
|
||||
LIBTACPLUS?= ${DESTDIR}${LIBDIR}/libtacplus.a
|
||||
LIBTERMCAP?= ${DESTDIR}${LIBDIR}/libtermcap.a
|
||||
LIBTERMCAPW?= ${DESTDIR}${LIBDIR}/libtermcapw.a
|
||||
|
@ -148,6 +148,7 @@ _LIBRARIES= \
|
||||
ssp_nonshared \
|
||||
stdthreads \
|
||||
supcplusplus \
|
||||
sysdecode \
|
||||
tacplus \
|
||||
termcap \
|
||||
termcapw \
|
||||
|
@ -6,11 +6,12 @@
|
||||
.PATH: ${.CURDIR}/../ktrace
|
||||
|
||||
PROG= kdump
|
||||
SRCS= kdump_subr.c kdump_subr.h kdump.c ioctl.c subr.c utrace.c
|
||||
SRCS= kdump_subr.c kdump_subr.h kdump.c ioctl.c subr.c
|
||||
CFLAGS+= -I${.CURDIR}/../ktrace -I${.CURDIR} -I${.CURDIR}/../.. -I.
|
||||
|
||||
LIBADD= sysdecode
|
||||
.if ${MK_CASPER} != "no"
|
||||
LIBADD= capsicum
|
||||
LIBADD+= capsicum
|
||||
CFLAGS+=-DHAVE_LIBCAPSICUM
|
||||
.endif
|
||||
|
||||
|
@ -13,6 +13,7 @@ DIRDEPS = \
|
||||
lib/libcapsicum \
|
||||
lib/libcompiler_rt \
|
||||
lib/libnv \
|
||||
lib/libsysdecode \
|
||||
|
||||
|
||||
.include <dirdeps.mk>
|
||||
|
@ -83,6 +83,7 @@ extern int errno;
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sysdecode.h>
|
||||
#include <termios.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
@ -116,7 +117,6 @@ void ktrfaultend(struct ktr_faultend *);
|
||||
void limitfd(int fd);
|
||||
void usage(void);
|
||||
void ioctlname(unsigned long, int);
|
||||
int kdump_print_utrace(FILE *, void *, size_t, int);
|
||||
|
||||
#define TIMESTAMP_NONE 0x0
|
||||
#define TIMESTAMP_ABSOLUTE 0x1
|
||||
@ -1541,7 +1541,7 @@ ktruser(int len, void *p)
|
||||
{
|
||||
unsigned char *cp;
|
||||
|
||||
if (kdump_print_utrace(stdout, p, len, decimal)) {
|
||||
if (sysdecode_utrace(stdout, p, len)) {
|
||||
printf("\n");
|
||||
return;
|
||||
}
|
||||
|
@ -4,8 +4,7 @@ NO_WERROR=
|
||||
PROG= truss
|
||||
SRCS= cloudabi.c ioctl.c main.c setup.c syscalls.c
|
||||
|
||||
.PATH: ${.CURDIR:H}/kdump
|
||||
SRCS+= utrace.c
|
||||
LIBADD= sysdecode
|
||||
|
||||
CFLAGS+= -I${.CURDIR} -I. -I${.CURDIR}/../../sys
|
||||
CLEANFILES= ioctl.c
|
||||
|
@ -11,6 +11,7 @@ DIRDEPS = \
|
||||
lib/${CSU_DIR} \
|
||||
lib/libc \
|
||||
lib/libcompiler_rt \
|
||||
lib/libsysdecode \
|
||||
|
||||
|
||||
.include <dirdeps.mk>
|
||||
|
@ -65,6 +65,7 @@ __FBSDID("$FreeBSD$");
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sysdecode.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <vis.h>
|
||||
@ -75,9 +76,6 @@ __FBSDID("$FreeBSD$");
|
||||
#include "extern.h"
|
||||
#include "syscall.h"
|
||||
|
||||
/* usr.bin/kdump/utrace.c */
|
||||
int kdump_print_utrace(FILE *, void *, size_t, int);
|
||||
|
||||
/* 64-bit alignment on 32-bit platforms. */
|
||||
#if !defined(__LP64__) && defined(__powerpc__)
|
||||
#define QUAD_ALIGN 1
|
||||
@ -1108,7 +1106,7 @@ print_utrace(FILE *fp, void *utrace_addr, size_t len)
|
||||
unsigned char *utrace_buffer;
|
||||
|
||||
fprintf(fp, "{ ");
|
||||
if (kdump_print_utrace(fp, utrace_addr, len, 0)) {
|
||||
if (sysdecode_utrace(fp, utrace_addr, len)) {
|
||||
fprintf(fp, " }");
|
||||
return;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user