Commit Graph

58 Commits

Author SHA1 Message Date
Diomidis Spinellis
ee3b0f6e2e Add -c option to summarize number of calls, errors, and system time.
Reviewed by:	alfred
2009-05-12 20:42:12 +00:00
Dag-Erling Smørgrav
d8984f48cb Try to make this code slightly less painful to read. 2008-07-31 17:15:21 +00:00
Jason Evans
9a62623a15 The break() system call takes a pointer argument, not an integer. This
change fixes output for break() on LP64 systems.
2008-01-03 00:18:03 +00:00
Marcel Moolenaar
f235995090 Print integer-typed arguments as integers. This makes sure that
on 64-bit platforms the result is more reliable. For example,
-1 was previously printed as 0xffffffff.

Approved by: re (kensmith)
2007-07-28 23:18:39 +00:00
Marcel Moolenaar
2c02627ff8 Fix handling of Quad-type arguments. Previously, syscalls
containing 64-bit arguments would have explicit padding.
On 64-bit platforms there was no padding, so the dummy
argument was not covering anything. On 32-bit platforms
with weak alignment (i.e. i386) the 64-bit argument did
not need to be aligned, so there too an aditional argument
was introduced. On 32-bit platforms with strong alignment
(i.e. PowerPC) the dummy argument in fact cover the padding.
By elimininating the dummy argument, 64-bit platforms now
have 1 argument less. This also applies to 32-bit platforms
with weak alignment. On PowerPC this doesn't matter, because
the padding is still there. We just don't "name" it.
Deal with those 3 cases.

Approved by: re (kensmith)
2007-07-28 23:15:04 +00:00
Xin LI
5d2d083c92 Make use of ptrace(2) instead of procfs in truss(1), eliminating
yet another need of an available /proc/ mount.

Tested with:	make universe
Submitted by:	howardsu
Reviewed by:	alfred
2007-04-10 04:03:34 +00:00
Pav Lucistnik
081e5c4890 - Add decoding of kse_release, kevent, sigprocmask, unmount, socket, getrusage,
rename, __getcwd, shutdown, getrlimit, setrlimit, _umtx_lock, _umtx_unlock,
  pathconf, truncate, ftruncate, kill

- Decode more arguments of open, mprot, *stat, and fcntl.

- Convert all constant-macro and bitfield decoding to lookup tables; much
  cleaner than previous code.

- Print the timestamp of process exit and signal reception when -d or -D are in
  use

- Try six times with 1/2 second delay to debug the child

PR:		bin/52190 (updated)
Submitted by:	Dan Nelson <dnelson@allantgroup.com>
Approved by:	alfred
2006-05-15 21:18:28 +00:00
Brian Somers
0cf21b4f58 Add a -s flag for the same functionality as strace. Introduce a Name
type which is a String type that has no -s limitations applied to it.
Change most Strings in the code to Names and add a few extra syscalls,
namely munmap, read, rename and symlink.  This was enough to facilitate
following file descriptor allocations in the code more easily and
getting a hint at what's being read/written from/to files.  More
syscalls should really be added.

While here, fix an off-by-one bug in the buffer truncation code and
add a fflush so that truss's output reflects the syscall that the
program is stuck in.

Sponsored by:	Sophos/Activestate
MFC after:	2 weeks
2006-01-02 08:36:25 +00:00
Alfred Perlstein
6a6567612d The kernel accepts sockaddrs with len set to zero for sockaddr_in
types, so refactor the code here to grab them when length is zero.
2005-10-15 06:17:29 +00:00
Alfred Perlstein
3969f0fa13 Decode chroot(2) args.
Approved by: re
2005-06-14 21:51:08 +00:00
Alfred Perlstein
dfafebf72e decode utimes, lutimes, futimes, chflags, lchflags. 2005-05-26 22:49:06 +00:00
Alfred Perlstein
42af4f5099 decode mkdir args. 2005-05-26 20:06:57 +00:00
Alfred Perlstein
9c6519b0a2 Change fix a bug where the length of data written by snprintf was
being mishandled by using accumulation (into an uninitialized
variable) instead of direct assignment.

Reviewed by: scottl
2005-03-03 17:20:36 +00:00
Marcel Moolenaar
10aeefc913 Fix Quad handling on 64-bit architectures. On 64-bit machines, a Quad
also occupies a single slot. There's no need for any special handling
of Quads. While here, remove the silly make_quad() function. We have
the 2 longs on 32-bit machines already lined up in the argument array,
so we can fetch the Quad with a simple cast.

Before:
  lseek(1,0x123456789,0xd0d0d0d0d0d0d0d0) = 4886718345 (0x123456789)
After:
  lseek(1,0x123456789,SEEK_SET)           = 4886718345 (0x123456789)
2004-09-05 05:27:30 +00:00
Alfred Perlstein
d10f73b311 don't seg if the syscall is invalid for i386fbsd. 2004-08-08 23:29:36 +00:00
Stefan Farfeleder
14cc87e479 Use the length modifier 'll' instead of 'q' to print long longs. 2004-07-28 16:03:13 +00:00
Alfred Perlstein
2bae4eb308 Support readlink(2) better. Readlink does not nul terminate the
result buffer, so we need to format it ourselves.  The problem is
that the length is stored as the return value from readlink, so we
need to pass the return value from our syscall into print_arg.

Motivated by: truss garbage on my screen from reading /etc/malloc.conf.
2004-07-17 19:48:49 +00:00
Alfred Perlstein
d75300bfa5 When reporting reciept of a signal, print the signal's name. 2004-07-17 19:19:36 +00:00
Alfred Perlstein
fde3a7d1e9 Decode the "wence" arg to lseek and linux_lseek. 2004-07-10 09:23:53 +00:00
Poul-Henning Kamp
01b8b4dc80 COMPAT_SUNOS is gone. 2004-06-11 11:58:07 +00:00
David Malone
e45a5a0d08 Add support for decoding Timespec, Timeval, Itimerval, Pollfd,
Fd_set and Sigaction structures. Use these for printing the arguments
to sigaction(), nanosleep(), select(), poll(), gettimeofday(),
clock_gettime(), recvfrom(), getitimer() and setitimer().

This is based on Dan's patch from the PR but I've hacked it for
style and some other issues. While Dan has checked this patch, any
goofs are probably my fault.

(The PR also contains support for the dual return values of pipe().
These will follow once I've ported that support to platforms other
than i386.)

PR:		52190
Submitted by:	Dan Nelson <dnelson@allantgroup.com>
2004-03-23 12:37:02 +00:00
David Malone
b637237cba Use pread to implement pread, rather than taking a detour throug stdio.
PR:		52190
Submitted by:	Dan Nelson <dnelson@allantgroup.com>
2004-03-23 12:29:17 +00:00
Alfred Perlstein
5214320f76 decode mprotect args while i'm here. 2004-03-23 09:16:18 +00:00
Alfred Perlstein
894b8f7afb decode fcntl and mmap arguments. 2004-03-23 09:04:06 +00:00
David Malone
9b83b9f75c Fix a printf format warning. 2004-01-07 14:27:30 +00:00
Marcel Moolenaar
4e92419dcd Do not ignore any possible errors that fseeko() may have. The fact
is that fseeko() fails in very predictable and frequent ways on ia64.
This is because the offset is actually an address in the process'
address space, which on ia64 can be larger than long (for lseek) or
off_t (for fseeko). The crux is the signedness. The register stack
and memory stack are in region 4 on ia64. This means that the sign bit
is 1. The large positive virtual address is wrongly interpreted as
a negative file offset.

There's no quick fix. Even if you get around the API by using a
SEEK_SET up to LONG_MAX and follow it up with a SEEK_CUR for the
remainder, the kernel simply cannot deal with it. and the second
seek will just fail.

Therefore, this change does not actually fix the root cause. It just
makes sure we're not spitting out all kinds of garbage or that the
get_struct() function in particular does not cause truss(1) to exit.
This, I might add, invariably happened way too soon for truss(1) to
be of any use on ia64...
2003-11-13 09:04:24 +00:00
Marcel Moolenaar
1bcb5f5a96 Port truss(1) to 64-bit architectures:
o  Syscall return values do not fit in int on 64-bit architectures.
   Change the type of retval in <arch>_syscall_exit() to long and
   change the prototype of said function to return a long as well.
o  Change the prototype of print_syscall_ret() to take a long for
   the return address and change the format string accordingly.
o  Replace the code sequence
	tmp = malloc(X);
	sprintf(tmp, format, ...);
   with X by definition too small on 64-bit platforms by
        asprintf(&tmp, format, ...);

With these changes the output makes sense again, although it does
mess up the tabulation on ia64. Go widescreen...

Not tested on: alpha, sparc64.
2003-11-09 03:48:13 +00:00
Marcel Moolenaar
a7a08c7e63 Fix truss so that it doesn't abort/exit when a syscall has been given
a NULL-pointer for a sockaddr argument.
2003-10-27 06:50:57 +00:00
Dag-Erling Smørgrav
99d1300607 send() and recv() are just wrappers, not actual syscalls. 2003-08-05 19:34:36 +00:00
Dag-Erling Smørgrav
9b2f78c553 Add recv(2), recvfrom(2), send(2) and sendfrom(2). 2003-08-05 10:45:06 +00:00
Matthew N. Dodd
726c2ca080 Decode a few more syscalls. 2003-04-15 06:12:12 +00:00
David Malone
967706f308 Check if name is NULL before we strcmp the syscall name. This was
sometimes triggered if you began trussing a process while it was
in a syscall, as the name is filled in when the syscall is made.
2002-11-09 22:28:38 +00:00
Mike Barcroft
1d631f7ef1 Don't depend on <signal.h> to include <sys/time.h>, instead include
<sys/time.h> directly.  This is mostly bogus since CLOCK_REALTIME
should be defined in <time.h>, which these files already include.
2002-10-06 21:46:04 +00:00
Matthew N. Dodd
fb034d05ac Remove an unnecessary cast. 2002-08-07 11:35:18 +00:00
Matthew N. Dodd
37169f9446 - Use time.h not sys/time.h.
- Fix printf format errors.

Submitted by:	 bde
2002-08-06 12:46:14 +00:00
Matthew N. Dodd
28c4ea6da8 Remove extra space in output. 2002-08-05 14:56:20 +00:00
Matthew N. Dodd
203098d816 Use timespec not timeval. 2002-08-05 12:22:55 +00:00
Matthew N. Dodd
9897b20356 Add options to print the argument and environment string parameters to
execve().

This could be done in a more general manner but it still wouldn't
be very pretty.

MFC after:	 3 weeks
2002-08-04 02:24:21 +00:00
Matthew N. Dodd
0d0bd00edd Add options to print absolute and relative timestamps.
PR:		 bin/25587 (in part)
MFC after:	 3 weeks
2002-08-04 01:27:31 +00:00
Matthew N. Dodd
c03bfcc871 Allow tracking fork()ed children.
PR:		 bin/25587 (in part)
MFC after:	3 weeks
2002-08-04 01:02:52 +00:00
Matthew N. Dodd
ec0bed25ba Parameterize globals.
PR:		bin/25587 (in part)
MFC after:	3 weeks
2002-08-04 00:46:48 +00:00
David Malone
7c8225cab8 Use fseeko and uintptr_t to make sure that we get a sensible offset
when trying to read from the stack.

PR:		37104
Submitted by:	Thomas Quinot <thomas@cuivre.fr.eu.org>
MFC after:	3 weeks
2002-04-21 19:04:26 +00:00
Alfred Perlstein
09bf11699f Print open(2) flags in hex instread of decimal for clarity. 2001-12-30 23:11:52 +00:00
Mark Murray
1be5d70444 Partial WARNS=1 fizes with NO_WERROR set to prevent world breakage.
Use __FBSDID().
2001-12-11 23:34:02 +00:00
Brian Feldman
dec17687ad Add missing include for <ctype.h>
Make sockaddr printing code unbad.

Always copy in sizeof(sockaddr_un) bytes for an AF_UNIX sockaddr,
despite what the length may be.
2001-11-06 19:26:51 +00:00
Dag-Erling Smørgrav
9ddd141263 Teach truss(1) to display sockaddrs. It currently knows about AF_INET,
AF_INET6 and AF_UNIX sockaddrs, and will recognize accept(), bind(),
connect(), getpeername() and getsockname() as syscalls taking sockaddr
arguments.  Some enterprising soul might want to add (and test) support
for the send() / recv() family of syscalls as well.

MFC after:	1 week
2001-10-21 21:57:10 +00:00
Joerg Wunsch
8a2ecea916 In get_string(), 0-terminate the contents of buf ``just in case'';
otherwise, if the very first fgetc() already yielded EOF, the returned
string won't get terminated at all.

MFC after:	1 day
2001-08-28 21:27:36 +00:00
Sean Eric Fagan
6cb533fe1c Change the output of truss to more closely resemble SysV's. (Yes, it
really is much nicer looking.)

Submitted by:	"Matthew N. Dodd" <winter@jurai.net>
2000-03-18 08:49:41 +00:00
Sean Eric Fagan
05d5ca3587 Fix a leak. (Thanks Bruce, this was a bonehead mistake on my part :).)
Submitted by:	Bruce Evans
2000-02-15 20:25:47 +00:00
Peter Wemm
c3aac50f28 $Id$ -> $FreeBSD$ 1999-08-28 01:08:13 +00:00