Commit Graph

333 Commits

Author SHA1 Message Date
Denys Vlasenko
5940e65939 Fix "format not a string literal" warning caused by tprintf(str)
* defs.h: Declare tprints().
* strace.c: Define tprints().
(tabto): Use tprints(str), since tprintf(str) was throwing a warning.
* desc.c: Use tprints(str) instead of tprintf("%s", str).
* file.c: Likewise.
* io.c: Likewise.
* net.c: Likewise.
* process.c: Likewise.
* signal.c: Likewise.
* syscall.c: Likewise.
* util.c: Likewise.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2011-09-01 09:55:05 +02:00
Denys Vlasenko
1d46ba57a8 Make out-of-memory handling more uniform
This fixes one real bug in dumpstr().

* defs.h: Declare die_out_of_memory().
* strace.c (die_out_of_memory): New function.
(strace_popen): If allocation fails, call die_out_of_memory().
(main): Likewise.
(expand_tcbtab): Likewise.
(rebuild_pollv): Likewise.
* count.c (count_syscall): Likewise.
(call_summary_pers): Likewise.
* desc.c (decode_select): Likewise.
* file.c (sys_getdents): Likewise.
(sys_getdents64): Likewise.
(sys_getdirentries): Likewise.
* pathtrace.c (pathtrace_match): Likewise.
* syscall.c (qualify): Likewise.
* util.c (printstr): Likewise.
(dumpiov): Likewise.
(dumpstr): Likewise.
(fixvfork): Likewise.
* mem.c (sys_mincore): Don't check free() parameter for NULL.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2011-08-31 14:00:02 +02:00
a673f3fa62 Do not include <limits.h>
* strace.c: Do not include <limits.h> explicitly, it is already included
implicitly by <sys/param.h>.
2011-08-30 16:07:01 +00:00
Denys Vlasenko
102ec49354 Optimize tabto()
tabto is used in many lines of strace output.
On glibc, tprintf("%*s", col - curcol, "") is noticeably slow
compared to tprintf("                 "). Use the latter.
Observed ~15% reduction of time spent in userspace.

* defs.h: Drop extern declaration of acolumn. Make tabto()
take no parameters.
* process.c (sys_exit): Call tabto() with no parameters.
* syscall.c (trace_syscall_exiting): Call tabto() with no parameters.
* strace.c: Make acolumn static, add static char *acolumn_spaces.
(main): Allocate acolumn_spaces as a string of spaces.
(printleader): Call tabto() with no parameters.
(tabto): Use simpler method to print lots of spaces.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2011-08-25 01:27:59 +02:00
Denys Vlasenko
06602d99b7 Rename some functions, delete unused one. No code changes
* defs.h: Rename get_scno_on_sysenter() to get_scno();
delete force_result() declaration.
* strace.c (proc_open): Rename get_scno_on_sysenter() to get_scno().
* syscall.c: Rename get_scno_on_sysenter() to get_scno().
Rename get_scno_on_sysexit() to get_syscall_result().
Delete unused force_result().

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2011-08-24 17:53:52 +02:00
Denys Vlasenko
9a36ae5e88 get_scno is an unholy mess, make it less horrible
Currently, get_scno does *much* more than "get syscall no".
It checks for post-execve SIGTRAP. It checks for changes
in personality. It retrieves params on entry and registers on exit.
Worse still, it is different in different architectures: for example,
for AVR32 regs are fetched in get_scno(), while for e.g. I386
it is done in syscall_enter().

Another problem is that get_scno() is called on both syscall entry and
syscall exit, which is stupid: we don't need to know scno on syscall
exit, it is already known from last syscall entry and stored in
tcp->scno! In essence, get_scno() does two completely different things
on syscall entry and on exit, they are just mixed into one bottle, like
shampoo and conditioner.

The following patches will try to improve this situation.

This change duplicates get_scno into identical get_scno_on_sysenter,
get_scno_on_sysexit functions. Call them in syscall enter and syscall
exit, correspondingly.

* defs.h: Rename get_scno to get_scno_on_sysenter; declare it only
if USE_PROCFS.
* strace.c (proc_open): Call get_scno_on_sysenter instead of get_scno.
* syscall.c (get_scno): Split into two (so far identical) functions
get_scno_on_sysenter and get_scno_on_sysexit.
(trace_syscall_entering): Call get_scno_on_sysenter instead of get_scno.
(trace_syscall_exiting): Call get_scno_on_sysexit instead of get_scno.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2011-08-24 16:47:32 +02:00
Denys Vlasenko
b88f96129f Straighten up confused comments/messages about post-execve SIGTRAP handling
* defs.h: Explain TCB_INSYSCALL and TCB_WAITEXECVE bits in detail.
* strace.c (choose_pfd): Use entering/exiting macros instead of direct check
for TCB_INSYSCALL.
* syscall.c (get_scno): Use entering/exiting macros instead of direct check
for TCB_INSYSCALL. Fix comments about post-execve SIGTRAP.
(syscall_fixup): Use entering/exiting instead of direct check
for TCB_INSYSCALL. Add a comment what "not a syscall entry" message
usually means. Change wrong "stray syscall exit" messages into
"not a syscall entry" ones.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2011-08-23 12:53:02 +02:00
Denys Vlasenko
2ecba32d52 Optimize out dummy PC printing on signal delivery
* strace.c (trace): Optimize out dummy PC printing on signal delivery.
While at it, tweak comments.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2011-08-23 12:53:02 +02:00
Denys Vlasenko
0890c8a403 Cosmetic improvement in ifdefs. No code changes
* strace.c (proc_open): Change ifdefs so that braces are properly paired.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2011-08-23 12:53:02 +02:00
Denys Vlasenko
8dc0c8c5ef Exclude tcp->pfd from non-procfs systems
* defs.h: Make struct tcb::pfd fields conditional on USE_PROCFS.
* strace.c (alloc_tcb): Use tcp->pfd only if USE_PROCFS.
(droptcb): Likewise.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2011-08-23 12:53:01 +02:00
Denys Vlasenko
cfd364b011 Small optimizations related to memory allocation
* strace (expand_tcbtab): Shorten "out of memory" message.
(rebuild_pollv): Remove unnecessary NULL check before free().
* util.c (dumpstr): Add a comment about likely bug.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2011-08-23 12:53:01 +02:00
Denys Vlasenko
5d64581e10 Improve code readability by avoiding assignments inside if()
* desc.c (decode_select): Move assignment out of if() condition.
* file.c (sprinttime): Likewise.
(sys_getdirentries): Likewise.
* io.c (sys_ioctl): Likewise.
* strace.c (test_ptrace_setoptions_followfork): Likewise.
(main): Likewise.
(proc_open): Likewise.
(detach): Likewise.
(proc_poll): Likewise.
(trace): Likewise.
* syscall.c (qualify): Likewise.
(sys_indir): Likewise.
* test/procpollable.c (main): Likewise.
* test/sfd.c (main): Likewise.
* time.c (printtv_bitness): Likewise.
(sprinttv): Likewise.
(print_timespec): Likewise.
(void sprint_timespec): Likewise.
(printitv_bitness): Likewise.
* util.c (dumpstr): Likewise.
(umovestr): Likewise.
(fixvfork): Likewise.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2011-08-23 12:53:01 +02:00
04f8b4860f Fix PTRACE_SETOPTIONS tests
* strace.c [LINUX] (kill_save_errno): New function.
(test_ptrace_setoptions_followfork): Change return type to void.
Fix and harden error handling.  Use kill_save_errno() to avoid errno
clobbering.  Treat EIO from ptrace() the same way as EINVAL.
(test_ptrace_setoptions_for_all): Use kill_save_errno() to avoid errno
clobbering.  Treat EIO from ptrace() the same way as EINVAL.
(main): Update use of test_ptrace_setoptions_followfork().
2011-08-23 12:53:00 +02:00
Denys Vlasenko
44f87efc67 Remove tcp->parent and TCB_CLONE_THREAD.
tcp->parent is used for only two things:
(1) to send signal on detach via tgkill (need to know tgid).
Solution: use tkill, it needs only tid.
(2) to optimize out ptrace options setting for new tracees.
Not a big deal if we drop this optimization: "set options" op is fast,
doing it just one extra time once per each tracee is hardly measurable.

TCB_CLONE_THREAD is a misnomer. It used only to flag sibling we attached to
in startup_attach. This is used to prevent infinite recursive rescanning
of /proc/PID/task.
Despite the name, there is no guarantee it is set only on non-leader:
if one would run "strace -f -p THREAD_ID" and THREAD_ID is *not*
a thread leader, strace will happily attach to it and all siblings
and will think that THREAD_ID is the leader! Which is a bug, but
since we no longer detach when we think tracee is going to die,
this bug no longer matters, because we do not use the knowledge
about thread group leaders for anything. (We used it to delay
leader's exit).

IOW: after this patch strace has no need to know about threads, parents
and children, and so on. Therefore it does not track that information.
It treats all tracees as independent entities. Overall,
this simplifies code a lot.

* defs.h: Add TCB_ATTACH_DONE flag, remove TCB_CLONE_THREAD flag
and struct tcb::parent field.
* process.c (internal_fork): Don't set tcpchild->parent.
* strace.c (startup_attach): Use TCB_ATTACH_DONE flag instead of
TCB_CLONE_THREAD to avoid attach attempts on already-attached threads.
Unlike TCB_CLONE_THREAD, TCB_ATTACH_DONE bit is used only temporarily,
and only in this function. We clear it on every tcb before we return.
(detach): Use tkill instead of tgkill.
(trace): Set ptrace options on new tracees unconditionally,
not only when tcp->parent == NULL.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2011-08-17 15:18:21 +02:00
Denys Vlasenko
833fb13cef Remove TCB_SUSPENDED constant and related code.
Since we no longer suspend waitpid'ing tracees, we have only one case when
we suspend tracee: when we pick up a new tracee created by clone/fork/vfork.

Background: on some other OSes, attach to child is done this way:
get fork's result (pid), loop ptrace(PTRACE_ATTACH) until you hook up
new process/thread. This is ugly and not safe, but what matters for us
is that it doesn't require suspending. Suspending is required
on Linux only, because on Linux attach to child is done differently.

On Linux, we use two methods of catching new tracee:
adding CLONE_THREAD bit to syscall (if needed, we change
[v]fork into clone before that), or using ptrace options.
In both cases, it may be so that new tracee appears before one which
created it returns from syscall. In this case, current code
suspends new tracee until its creator returns. Only then
strace can determine who is its parent (it needs child's pid for this,
which is visible in parent's [v]fork/clone result).
This is inherently racy. For example, what if SIGKILL kills
creator after it succeeded creating child, but before it returns?
Looks like we will have child suspended forever.

But after previous commit, we DO NOT NEED parent<->child link for anything.
Therefore we do not need suspending too. Bingo!

This patch removes suspending code. Now new tracees will be continued
right away. Next patch will remove tcp->parent member.

* defs.h: Remove TCB_SUSPENDED constant
* process.c (handle_new_child): Delete this function.
  (internal_fork): Do not call handle_new_child on syscall exit.
* strace.c (handle_ptrace_event): Delete this function.
  (trace): Do not suspend new child; remove all handling
  of now impossible TCB_SUSPENDED condition.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2011-08-17 11:30:56 +02:00
Denys Vlasenko
19cdada5b4 Do not detach when we think tracee is going to die.
Current code plays some ungodly tricks, trying to not detach
thread group leader until all threads exit.

Also, it detaches from a tracee when signal delivery is detected
which will cause tracee to exit.
This operation is racy (not to mention the determination
whether signal is set to SIG_DFL is a horrible hack):
after we determined that this signal is indeed fatal
but before we detach and let process die,
*other thread* may set a handler to this signal, and
we will leak the process, falsely displaying it as killed!

I need to look in the past to figure out why we even do it.
First guess is that it's a workaround for old kernel bugs:
kernel used to deliver exit notifications to the tracer,
not to real parent. These workarounds are ancient
(internal_exit is from 1995).

The patch deletes the hacks. We no longer need tcp->nclone_threads,
TCB_EXITING and TCB_GROUP_EXITING. We also lose a few rather
ugly functions.

I also added a new message: "+++ exited with EXITCODE +++"
which shows exact moment strace got exit notification.
It is analogous to existing "+++ killed by SIG +++" message.

* defs.h: Delete struct tcb::nclone_threads field,
  TCB_EXITING and TCB_GROUP_EXITING constants,
  declarations of sigishandled() and internal_exit().
* process.c (internal_exit): Delete this function.
  (handle_new_child): Don't ++tcp->nclone_threads.
* signal.c (parse_sigset_t): Delete this function.
  (sigishandled): Delete this function.
* strace.c (startup_attach): Don't tcbtab[tcbi]->nclone_threads++.
  (droptcb): Don't delay dropping if tcp->nclone_threads > 0,
  don't drop parent if its nclone_threads reached 0:
  just drop (only) this tcb unconditionally.
  (detach): don't drop parent.
  (handle_group_exit): Delete this function.
  (handle_ptrace_event): Instead of handle_group_exit, just drop tcb;
  do not panic if we see WIFEXITED from an attached pid;
  print "+++ exited with EXITCODE +++" for every WIFEXITED pid.
* syscall.c (internal_syscall):	Do not treat sys_exit specially -
  don't call internal_exit on it.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2011-08-17 10:45:32 +02:00
Denys Vlasenko
26d1b1eaa8 Slight optimization and cleanup in trace()
* strace.c (trace): Do not recalculate "cflag ? &ru : NULL"
again and again. Do not clear errno unnecessarily.
Consistently check wait errors as pid < 0, not pid == -1.
Indent ifdefs for better readability.
Remove comments after endif if ifdef/endif block is really tiny.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2011-08-15 12:24:14 +02:00
Denys Vlasenko
5bd67c86a9 Fix compilation on 2.4.20 kernel based system
* block.c (block_ioctl): add ifdef/endif around BLKGETSIZE64 usage
* strace.c (trace): add ifdef/endif around WIFCONTINUED usage

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2011-08-15 11:36:09 +02:00
Denys Vlasenko
13d22f1aa3 Trivial cleanups
* strace.c (trace): Change ifdef LINUX to make a bit more sense,
  remove wrong comment at its endif. Slightly optimize
  "+++ killed by SIG +++" message for systems without WCOREDUMP macro.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2011-06-24 23:01:57 +02:00
Denys Vlasenko
e18314ed0f Remove redundant include <stdarg.h>
* strace.c: Remove redundant include <stdarg.h>

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2011-06-24 22:58:00 +02:00
Denys Vlasenko
178de007d1 Clean up two old comments
* strace.c (startup_attach): Remove misplaced comment.
  (trace) Remove incomplete part of a comment.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2011-06-24 22:54:25 +02:00
Denys Vlasenko
ead73bd349 Make a few variables static.
* defs.h: Remove tcbtab declaration.
* strace.c: Make run_uid, run_gid, outf, tcbtab, progname
  global variables static

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2011-06-24 22:49:58 +02:00
Denys Vlasenko
f95397afb8 Add debug output in initial attachment code
* strace.c (startup_attach): If -d, report pid and success/failure
  of every attach attempt.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2011-06-24 16:51:16 +02:00
Denys Vlasenko
1d5f12ecb8 Better debug logging of allocations and waitpit results
* strace.c (alloc_tcb): Print number of allocated tcb's if -d.
  (droptcb): Likewise.
  (handle_ptrace_event): Remove PTRACE_EVENT_EXEC debug message.
  (trace): Improve logging of waitpid: show WIFxxx, exitcode/signal,
  ptrace event name, WCOREDUMP - all on one line.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2011-06-24 16:41:35 +02:00
Denys Vlasenko
65d7c4d66c Remove TCB_FOLLOWFORK
TCB_FOLLOWFORK flag seems to be unnecessary, because we either follow
all [v]forks/clones or don't follow any, therefore global variable
followfork is an already existing indicator of what we want to do.
This patch drops all setting/clearing of TCB_FOLLOWFORK bit,
and replaces checks for this bit by checks of followfork value.
In internal_fork, check is moved to in front of if(), since
the check is needed on both "entering" and "exiting" branch.

* defs.h: Remove TCB_FOLLOWFORK define.
* process.c (internal_fork): Do not set/clear TCB_FOLLOWFORK,
  test followfork instead of tcp->flags & TCB_FOLLOWFORK.
  (handle_new_child): Likewise.
* strace.c (startup_attach): Likewise.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2011-06-23 21:46:37 +02:00
Denys Vlasenko
4f12af24e4 Make initial tcb allocation more readable. No logic changes.
* strace.c (main): Make initial tcb allocation more readable.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2011-06-23 13:16:23 +02:00
Denys Vlasenko
cb2ad00652 Use [p]error_msg[_and_die] where appropriate. No logic changes.
Resulting size changes:
   text    data     bss     dec     hex filename
  17445      16    8572   26033    65b1 strace.o.old
  16850      16    8572   25438    635e strace.o

* strace.c: Replace fprintf[+cleanup]+exit with [p]error_msg_and_die,
  fprintf("progname: ...") with [p]error_msg where appropriate.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2011-06-23 13:05:29 +02:00
Denys Vlasenko
7b609d5ba0 Whitespace cleanups. No code changes.
* count.c: Place opening curly brace after if (),
  not on the next line. Almost all strace code alredy
  uses this style.
* desc.c: Likewise.
* file.c: Likewise.
* net.c: Likewise.
* pathtrace.c: Likewise.
* process.c: Likewise.
* quota.c: Likewise.
* signal.c: Likewise.
* strace.c: Likewise.
* syscall.c: Likewise.
* time.c: Likewise.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2011-06-22 14:32:43 +02:00
Denys Vlasenko
3d5ed41252 Make strace_fopen abort on error
Error from strace_fopen in main results in call to exit(1).
Error from strace_fopen in newoutf is propagated to newoutf
callers: startup_attach (where it results in exit(1))
and alloc_tcb (where error is ignored). In second case,
the behavior doesn't seem to be right: it means with -ff
on open error for new LOGFILE.PID the output will continue
to go into *the same file as the previous process* - which
would be confusing. Moreover, on droptcb outf may be closed
and the output of other, still running process outputting
to the same outf will be lost. I don't think this is sane.
IOW: in all cases, error in strace_fopen should be fatal.

* strace.c (strace_fopen): Abort on error instead of returning NULL.
  (newoutf): Change return type to void.
  (startup_attach): Remove error check on newoutf return value.
  (main): Remove error check on strace_fopen return value.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2011-06-22 13:17:16 +02:00
Denys Vlasenko
1f532ab27d Make set_cloexec_flag abort on error
set_cloexec_flag() may fail only if we pass it a bad fd,
such as -1 or non-opened one. If we do, we have a bug
in the caller. It makes no sense to try to continue
running when we detect such a blatant bug in our own code.

* strace (set_cloexec_flag): Abort instead of returning error
  indicator. Change function to return void.
  (strace_fopen): Remove error check on set_cloexec_flag return value.
  (proc_open): Likewise.
  (proc_poll_open): Likewise.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2011-06-22 13:11:23 +02:00
Denys Vlasenko
7dd23384f7 Make strace_popen abort on error
It makes no sense to postpone abort on strace_popen error
unti it returns. Moreover, out-of-memory error was exiting
without any message.
While at it, use 0 as "none" for popen_pid, as optimization.

* strace: Initialize popen_pid to 0 - this puts it in bss.
  (trace): Reset popen_pid to 0 instead of -1.
  (strace_popen): Never return NULL as error indicator,
  abort with good error message instead.
  (main): Remove NULL check of strace_popen result.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2011-06-22 13:03:56 +02:00
Denys Vlasenko
2b60c35b33 Delete fork_tcb()
Get rid of fork_tcb() function. It used to do what the comment
above it says, but now it doesn't do much:
it only sets tcp->flags |= TCB_FOLLOWFORK and maybe calls
expand_tcbtab(). The second operation is not necessary, since
alloc_tcp() will do it itself when needed.
This patch deletes fork_tcb(), open-coding tcp->flags |= TCB_FOLLOWFORK
where it was formerly called. It also makes nprocs, tcbtabsize and
expand_tcbtab() static. (While at it, I nuked redundant
extern char **environ declaration: strace.c had *two* of them...)

* defs.h: Remove declarations of nprocs, tcbtabsize and
  expand_tcbtab.
* process.c (fork_tcb): Remove this function.
  (internal_fork): Open-code fork_tcb.
  (handle_new_child): Likewise.
* strace.c: Remove redundant "extern char **environ". Declare
  nprocs and tcbtabsize static.
  (expand_tcbtab): Make it static.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2011-06-22 12:45:25 +02:00
Denys Vlasenko
18da273675 Simplify expand_tcbtab and alloc_tcb
Get rid of a few intermediate variables, simplifies a few expressions,
and uses error_msg_and_die instead of more verbose
fprintf+cleanup+exit sequence.
In alloc_tcp, I use memset to clear entire new tcp.
This not only saves a few bytes of code, but lowers the chances
of future bugs where some data "leaks out" into new tcb's
from old ones because we forgot to re-initialize it.

* strace.c (expand_tcbtab): Simplify this function. No logic changes.
  (alloc_tcb): Likewise.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2011-06-22 12:41:57 +02:00
Denys Vlasenko
b56d6d3bfe Remove write-only nchildren member from struct tcb
* defs.h: Remove nchildren member from struct tcb.
* process.c (handle_new_child): Remove inc/decrements of tcp->nchildren.
  (internal_fork): Likewise.
* strace.c (startup_attach): Likewise.
  (droptcb): Likewise.
  (alloc_tcb): Remove initialization of tcp->nchildren.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2011-06-21 16:06:28 +02:00
Denys Vlasenko
f0a5f6d710 Remove write-only nzombies member from struct tcb
* defs.h: Remove nzombies member from struct tcb.
* strace.c (droptcb): Remove "tcp->parent->nzombies++".
  (alloc_tcb): Remove "tcp->nzombies = 0".

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2011-06-21 15:34:40 +02:00
Denys Vlasenko
f44cce48bb Fix regression introduced by "Properly handle real SIGTRAPs" change
Commit 3454e4b463
introduced a bug: sometimes, TRACECLONE/TRACE[V]FORK opts were not set.
The check (tcp->parent == NULL) in old code was meant to check
"if we are not a child created by auto-attach" - in this case,
options need to be set on the child; otherwise they are inherited
and do not need to be set.
I misunderstood the check and if tcp->parent is not NULL, I was
setting only ptrace_setoptions_for_all bits.
This change fixes the problem. Since the fixed logic makes it
unnecessary to keep two sets of options in separate variables,
I merge them back into one variable, ptrace_setoptions.

* defs.h: Merge ptrace_setoptions_followfork and ptrace_setoptions_for_all
  into one variable, ptrace_setoptions.
* strace.c: Likewise.
  (test_ptrace_setoptions_followfork): Use ptrace_setoptions variable.
  (test_ptrace_setoptions_for_all): Likewise.
  (main): Likewise.
* process.c (internal_fork): Likewise.
  (internal_exec): Likewise.
* strace.c (trace): Fix the bug where different options were set
  depending on "tcp->parent == NULL" condition. Add a comment
  which makes it more clear why this condition is checked.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2011-06-21 14:34:10 +02:00
Denys Vlasenko
0df9ed47af Do not suspend waitpid.
strace used to suspend waitpid until there is a child
for waitpid'ing process to collect status from.
Apparently, it was done because in some very old kernels
(circa 2002 or even earlier) there were ptrace bugs which
were making waitpid in real parent to not see children.
This kernel bug is fixed long ago. This change removes the workaround.
test/wait_must_be_interruptible.c is a test program which
illustrates why without this change strace changes
programs's behavior.

* defs.h: Delete waitpid and nclone_waiting members from from struct tcb.
  Remove declaration of internal_wait().
* process.c (internal_wait): Remove this function.
* strace.c (alloc_tcb): Do not set tcp->nclone_waiting.
  (resume): Remove this function.
  (resume_from_tcp): Remove this function.
  (detach): Do not call resume_from_tcp().
  (handle_group_exit): Do not call resume_from_tcp().
* syscall.c (internal_syscall): Do not call internal_wait().

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2011-06-18 11:38:51 +02:00
44d053218b * strace.c (verror_msg): Rewrite without use of heap memory allocation 2011-06-09 15:50:41 +00:00
Denys Vlasenko
e62df004ce Print at least one space between SYSCALL(ARGS) and = RESULT if tracee is killed
We already do it in the normal case, but in rare code path where
tracee is gone (SIGKILLed?) sometimes we were printing this:
"SYSCALL(ARGS <unavailable>)= ? <unavailable>" - note jammed together ")=".
test/sigkill_rain.c can be used to verify the fix.

* strace.c (printleader): add a space after ")" in " <unavailable>)"

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2011-06-08 16:15:04 +02:00
Denys Vlasenko
b63256e69b Whitespace cleanups. no code changes.
* bjm.c: Fix tabulation (such as extra spaces before tabs),
convert punctuation where it deviates from prevalent form
elsewhere in strace code, convert sizeof and offsetof where
it deviates from from prevalent form, remove space between
function/macro/array names and (parameters) or [index],
add space between "if" and (condition), correct non-standard
or wrong indentaion.
* defs.h: Likewise
* desc.c: Likewise
* file.c: Likewise
* ipc.c: Likewise
* linux/arm/syscallent.h: Likewise
* linux/avr32/syscallent.h: Likewise
* linux/hppa/syscallent.h: Likewise
* linux/i386/syscallent.h: Likewise
* linux/ioctlsort.c: Likewise
* linux/m68k/syscallent.h: Likewise
* linux/microblaze/syscallent.h: Likewise
* linux/powerpc/syscallent.h: Likewise
* linux/s390/syscallent.h: Likewise
* linux/s390x/syscallent.h: Likewise
* linux/sh/syscallent.h: Likewise
* linux/sh64/syscallent.h: Likewise
* linux/tile/syscallent.h: Likewise
* linux/x86_64/syscallent.h: Likewise
* mem.c: Likewise
* net.c: Likewise
* pathtrace.c: Likewise
* process.c: Likewise
* signal.c: Likewise
* sock.c: Likewise
* strace.c: Likewise
* stream.c: Likewise
* sunos4/syscall.h: Likewise
* sunos4/syscallent.h: Likewise
* svr4/syscall.h: Likewise
* svr4/syscallent.h: Likewise
* syscall.c: Likewise
* system.c: Likewise
* test/childthread.c: Likewise
* test/leaderkill.c: Likewise
* test/skodic.c: Likewise
* time.c: Likewise
* util.c: Likewise

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2011-06-07 12:13:24 +02:00
Denys Vlasenko
1201426dd4 "Modernize" all old-style function parameter declarations
* bjm.c: Convert all remaining old-style C function definitions
to a "modern" form. This does not change any actual code.
* io.c: Likewise
* ioctl.c: Likewise
* net.c: Likewise
* proc.c: Likewise
* process.c: Likewise
* signal.c: Likewise
* sock.c: Likewise
* strace.c: Likewise
* stream.c: Likewise
* syscall.c: Likewise
* system.c: Likewise
* time.c: Likewise
* util.c: Likewise

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2011-05-30 14:00:14 +02:00
Denys Vlasenko
75422766d5 Cleanups on top of "handle SIGTRAP properly" change,
based on Dmitry's comments.

* defs.h ([p]error_msg[_and_die]): Declare new functions.
* strace.c (SYSCALLTRAP): Rename to syscall_trap_sig.
([p]error_msg[_and_die]): Define new functions.
(strace_tracer_pid): New variable, it controls which pid will
do cleanup on exit via [p]error_msg_and_die.
(main): Set strace_tracer_pid to our initial pid.
(startup_attach): Change strace_tracer_pid if we are in -D mode.
(test_ptrace_setoptions_for_all): Minor changes to logic,
such as better diagnostic messages.
2011-05-27 14:36:01 +02:00
Denys Vlasenko
35aba6a8dd Identifier "errno" may be a macro, it's unsafe to use it
* strace.c (strerror): Rename parameter errno to err_no
2011-05-25 15:33:26 +02:00
Denys Vlasenko
f8bc0655a0 Don't perform TCB_WAITEXECVE wait if not needed.
* defs.h (ptrace_setoptions_for_all): Expose this variable.
* strace.c (ptrace_setoptions_for_all): Remove "static".
* process.c (internal_exec): Don't set TCB_WAITEXECVE bit
if we know that post-execve SIGTRAP is not going to happen.
2011-05-24 20:30:24 +02:00
Denys Vlasenko
3454e4b463 Properly handle real SIGTRAPs.
* defs.h (ptrace_setoptions): Variable renamed to ptrace_setoptions_followfork.
* process.c (internal_fork): Ditto.
* strace.c (ptrace_setoptions_for_all): New variable.
(SYSCALLTRAP): New variable.
(error_msg_and_die): New function.
(test_ptrace_setoptions_for_all): New function.
(main): Call test_ptrace_setoptions_for_all() at init.
(handle_ptrace_event): Handle PTRACE_EVENT_EXEC (by ignoring it).
(trace): Check events and set ptrace options without -f too.
Check WSTOPSIG(status) not for SIGTRAP, but for SYSCALLTRAP.
2011-05-23 21:29:03 +02:00
Grant Edwards
8a08277d13 Add ability to print file descriptor paths and filter by those paths
* pathtrace.c: New file, implements matching syscall arguments to
user-specified file paths.
* Makefile.am (strace_SOURCES): Add pathtrace.c.
* defs.h (TCB_FILTERED, filtered): New defines.
(getfdpath, pathtrace_select, pathtrace_match, show_fd_path,
tracing_paths): New declarations.
* strace.c (show_fd_path, tracing_paths): New global variables.
(usage, main): Implement handling of -y and -P options.
* strace.1: Add descriptions of -y and -P options.
* syscall.c (trace_syscall_entering): Add path matching logic to the
print/noprint decision and set the TCB_FILTERED bit appropriately.
(trace_syscall_exiting): Use filtered() macro that checks the
TCB_FILTERED bit to determine print/noprint status.
* util.c (printfd): Use getfdpath().
2011-04-08 20:47:56 +00:00
6b7a261ff8 Show more details about signals received by traced processess
* strace.c [!USE_PROCFS] (trace): Differentiate output format depending
on PTRACE_GETSIGINFO success or failure.  In the former case, use
printsiginfo() to show more details about received signal.
2011-03-10 22:25:03 +00:00
c15dfc7961 Get rid of PT_GETSIGINFO
* strace.c [!USE_PROCFS] (trace): Assume that PTRACE_GETSIGINFO is
available.  Replace PT_GETSIGINFO with PTRACE_GETSIGINFO.  Use
PTRACE_GETSIGINFO for all signals.
2011-03-10 22:25:03 +00:00
2fabd0eaf0 Fix PTRACE_GETEVENTMSG usage and enhance test_ptrace_setoptions()
* strace.c (handle_ptrace_event): Fix PTRACE_GETEVENTMSG usage.
(test_ptrace_setoptions): Test that PTRACE_GETEVENTMSG works properly.
2011-02-19 21:33:50 +00:00
21ccf5ed07 Test PTRACE_O_TRACECLONE and PTRACE_O_TRACEVFORK along with PTRACE_O_TRACEFORK
* strace.c (test_ptrace_setoptions): Add PTRACE_O_TRACECLONE and
PTRACE_O_TRACEVFORK to PTRACE_SETOPTIONS call, to test exactly
the same set of options that is going to be used later in trace().
2011-01-13 14:49:39 +00:00
8044bc1463 Fix strace -f -o '|command' hangup
* strace.c (main): Call test_ptrace_setoptions() before parsing
-o option, otherwise a forked command will cause a hangup inside
test_ptrace_setoptions().
2010-12-07 12:50:49 +00:00
b1467440f7 Cleanup test_ptrace_setoptions()
* strace.c (test_ptrace_setoptions): Cleanup.
(main): Fix test_ptrace_setoptions() error diagnostics message.
Print ptrace_setoptions value in debug mode.
2010-11-30 17:19:09 +00:00
Wang Chao
ca8ab8d295 Handle followfork using ptrace_setoptions if available
If PTRACE_O_TRACECLONE et al options are supported by kernel,
use them to do followfork rather than the original setbpt
method that changes registers ourselves.

* defs.h [LINUX] (handle_new_child): New function prototype.
* process.c [LINUX] (handle_new_child): New function based on the
code from internal_fork(), with a trivial change: do reparent only
for sys_clone.
[LINUX] (internal_fork): Use handle_new_child().  Do nothing if
ptrace_setoptions is in effect.
* strace.c [LINUX] (handle_ptrace_event): New function.
[LINUX] (trace): If ptrace_setoptions is in effect, then
call the new function to handle PTRACE_EVENT_* status, and
set PTRACE_SETOPTIONS when we see the initial stop of tracee.

Signed-off-by: Wang Chao <wang.chao@cn.fujitsu.com>
2010-11-30 17:19:09 +00:00
Wang Chao
b13c0de058 Test how PTRACE_SETOPTIONS support works
Currently test fork related options only.  Fork a child that uses
PTRACE_TRACEME at startup and then does a fork so strace can test
how the PTRACE_SETOPTIONS support works before it handles any real
tracee.  Since PTRACE_O_TRACECLONE/*FORK were introduced to kernel
at the same time, this test seems to be enough for these 3 options.

* defs.h [LINUX]: Define PTRACE_O_TRACECLONE et al macros here.
(ptrace_setoptions): New variable declaration.
* strace.c [LINUX] (test_ptrace_setoptions): New function, tests
whether kernel supports PTRACE_O_CLONE/*FORK, the result is stored
in the new variable ptrace_setoptions for later use.
(main): Call test_ptrace_setoptions() if followfork option is set.

Signed-off-by: Wang Chao <wang.chao@cn.fujitsu.com>
2010-11-30 17:19:09 +00:00
Roland McGrath
54e931fb85 Clean up pid2tcb usage
* strace.c (pid2tcb): Always match pid.  Fail for argument <= 0.
[USE_PROCFS] (first_used_tcb): New function.
[USE_PROCFS] (trace): Use that instead of pid2tcb(0).
2010-09-14 19:03:37 -07:00
30145dda9d Fix const-correctness issues uncovered by gcc -Wwrite-strings
* defs.h (struct xlat): Add const qualifier to the field of
type "char *".
(set_sortby, qualify, printnum, printnum_int): Add const qualifier to
arguments of type "char *".
* count.c (set_sortby): Add const qualifier to the argument and
automatic variable of type "char *".
* desc.c (decode_select): Add const qualifier to automatic variables of
type "char *".
* ioctlsort.c (struct ioctlent): Add const qualifier to fields of
type "char *".
(main):  Add const qualifier to argv.
* process.c (printargv): Add const qualifier to the argument and
automatic variable of type "char *".
(printargc) Add const qualifier to argument of type "char *".
* signal.c (sprintsigmask, parse_sigset_t): Add const qualifier to
arguments of type "char *".
* strace.c (progname): Add const qualifier.
(detach): Add const qualifier to automatic variable of type "char *".
* stream.c (struct strbuf): Add const qualifier to the field of
type "char *".
* syscall.c (struct qual_options): Add const qualifier to fields of
type "char *".
(qual_syscall, qual_fault, qual_desc, lookup_class): Add const qualifier
to arguments of type "char *".
(qual_signal): Add const qualifier to the argument of type "char *",
avoid modification of constant argument.
(qualify): Likewise.
* util.c (printflags): Add const qualifier to automatic variable of
type "char *".
(printnum, printnum_int): Add const qualifier to arguments of
type "char *".
2010-09-07 00:59:18 +00:00
Wang Chao
21b8db4eb9 Drop nclone_detached and related flags
Remove nclone_detached since CLONE_DETACHED flag was no-op for a very
long time in kernel.

* defs.h (struct tcb): Remove nclone_detached field.
Remove TCB_CLONE_DETACHED flag.
* process.c: Remove CLONE_DETACHED flag.
(clone_flags): Remove CLONE_DETACHED entry.
(internal_fork, internal_wait): Remove code dealing with CLONE_DETACHED
flag and nclone_detached.
* strace.c (startup_attach, alloc_tcb, droptcb, handle_group_exit):
Likewise.

Signed-off-by: Wang Chao <wang.chao@cn.fujitsu.com>
2010-08-28 22:36:54 +00:00
Wang Chao
d322a4bbe1 Forbid using mutually exclusive options -D and -p together
If we use -D and -p option together to trace a multi-thread program, in
addition to the main thread, other threads could not be traced even if we
present -f option. Moreover, when executing 'strace -D -p <non-exist pid>',
strace could not terminate normally.

* strace.c (main): Check it.

Signed-off-by: Wang Chao <wang.chao@cn.fujitsu.com>
2010-08-09 21:28:35 +00:00
Andreas Schwab
372cc84c97 Balance braces
* strace.c (proc_open): Avoid unbalanced braces.
(trace): Likewise.
2010-07-09 12:01:17 +02:00
Andreas Schwab
b87d30c785 Document -C/-D
* strace.c (usage): Document -C.
* strace.1: Document -D.
2010-06-24 17:14:01 +02:00
e3a7ef5a2a Implement -C option to combine regular and -c output
* defs.h (cflag_t): New enum.
* strace.1: Document -C option.
* strace.c (cflag): Update type.
(main): Handle -C option.
(trace): Update use of cflag.
* count.c (count_syscall): Move clearing of TCB_INSYSCALL to ...
* syscall.c (trace_syscall): ... here.  Update use of cflag.
Based on patch by Adrien Kunysz.
2010-04-07 10:19:26 +00:00
e5e6085806 Remove dead code
* defs.h (tv_tv): Remove.
* net.c (sys_xsetsockaddr): Remove commented out dead code.
* process.c (setarg, sys_execv, sys_execve, struct_user_offsets):
Likewise.
* signal.c (sys_sigsuspend): Likewise.
* strace.c (reaper, trace): Likewise.
* stream.c (internal_stream_ioctl): Likewise.
* syscall.c (trace_syscall): Likewise.
* term.c (term_ioctl): Likewise.
* util.c (tv_tv, umoven, uload, getpc, fixvfork, setbpt, clearbpt):
Likewise.
2010-02-04 22:40:57 +00:00
Andreas Schwab
840d85b3e5 Don't kill the process when detaching
* strace.c (detach): Call clearbpt when TCB_BPTSET is set.
2010-01-12 11:16:32 +01:00
Andreas Schwab
e5355de95c Remove support for pre-C89
* defs.h: Remove references to __STDC__ and P macros.
* strace.c: Likewise.
2009-11-16 11:16:36 +00:00
Andreas Schwab
ccdff481c0 Maintain separate print column for each process
* defs.h (struct tcp): Add curcol.
* strace.c: (alloc_tcb): Initialize it.
(trace): Use curcol from current process and save it before
continuing.
(tprintf): Don't modify curcol on output error.
2009-10-27 16:30:41 +01:00
Mike Frysinger
c1a5b7e8c4 Add support for Linux/no-mmu with vfork
* configure.ac (AC_CHECK_FUNCS): Add fork.
* strace.c (strace_vforked): Define.
(startup_child): Do not raise SIGSTOP if vforked.
(trace): Skip first exec when starting up after vforked.
* syscall.c [BFIN] (get_scno): Drop waitexec checks.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2009-10-08 14:25:01 +00:00
Roland McGrath
eb9e2e8904 Revert unapproved commits. 2009-06-02 16:49:22 -07:00
4ac9d627f4 * strace.c (handle_stopped_tcbs): Fix cast for 4th argument passed to ptrace(). 2009-06-01 18:45:41 +00:00
Denys Vlasenko
246f42ff5a * strace.c (collect_stopped_tcbs): Do not enable/disable signals
multiple times, do it just once per collecting pass.
2009-04-20 18:20:18 +00:00
Denys Vlasenko
1e20921216 As it turned out, "if (interrupted) break;" is needed in both loops,
in "collect tasks" loop and in enclosing "collect/process" loop.
Before this patch, "strace cat" + "killall -INT strace" wasn't
making strace stop and exit. This patch restores 4.5.18 behavior
in this regard.
2009-03-20 13:28:00 +00:00
Denys Vlasenko
aab52cae4c Remove "better attach to SIGSTOP", it is not correct...
(^C fix remains).
2009-03-17 14:46:54 +00:00
Denys Vlasenko
222713aa40 * strace.c (startup_attach): Take care to correctly attach
to stopped processes by resending SIGSTOP.
(collect_stopped_tcbs): Check for ^C here, not in trace().
(trace): Remove check for ^C.
2009-03-17 14:29:59 +00:00
Denys Vlasenko
5ae2b7c601 AVR32 support by Hans-Christian Egtvedt
(hans-christian.egtvedt AT atmel.com).
* configure.ac: Make it recognize avr32.
* defs.h: Define LINUX_AVR32.
* linux/avr32/syscallent.h: New file.
* Makefile.am: Reference linux/avr32/syscallent.h.
* proc.c (change_syscall, setarg): Add support for avr32.
(struct xlat struct_user_offsets[]): Ditto.
* syscall.c (get_scno): Ditto.
(get_error, force_result, syscall_enter): Ditto.
* util.c (getpc, printcall): Ditto.
2009-02-27 20:32:52 +00:00
Denys Vlasenko
8ed5727642 By Hans-Christian Egtvedt (hans-christian.egtvedt AT atmel.com):
strace.c: suppress "warning: unused static" message by adding #ifdef's around
 a variable
.gitignore: trivial
test/*.c: cleanup (suppress warnings, much better style).
2009-02-25 14:24:02 +00:00
Denys Vlasenko
4dedd561d6 Replace many more bare ptrace calls with calls to wrappers
which do proper error-checking and set tcp->ptrace_errno.
In some cases, missing error checking is added.
Error handling for trace_syscall() failures and other cases
where tcp->ptrace_errno is nonzero is cleaned up a bit
and made more verbose if we see error other than ESRC.
Some comments are added or expanded.
* defs.h: Declare ptrace_cmds[]. Modify do_ptrace
declaration (last parameter is long, not void *).
* process.c: Make ptrace_cmds[] non-static.
(change_syscall): Use do_ptrace() instead of bare ptrace().
* signal.c: Use do_ptrace() instead of bare ptrace().
* strace.c: Update trace_syscall() failure handling.
* syscall.c: Use do_ptrace() instead of bare ptrace().
* util.c: Use do_ptrace() instead of bare ptrace().
Update do_ptrace() wrapper.
(str_PTRACE_xxx): New function - helper returning "PTRACE_xxx".
(do_ptrace_peekdata): New function - wrapper for PTRACE_PEEKDATA
(do_ptrace5): New function - wrapper for 5-argument ptrace calls.
2009-02-24 15:17:53 +00:00
Denys Vlasenko
84e20af5a6 Cleanup after tcb table expansion simplification.
There was code which was trying to continue tracing
even if table expansion fails. Now we treat it as fatal
failure, so this code is removed by this change.
* defs.h: Delete TCB_FOLLOWFORK constant.
* process.c: Delete fork_tcb() and all calls of it.
* strace.c (startup_attach): Remove usage of TCB_FOLLOWFORK.
* syscall.c: Indent preprocessor directives.
2009-02-10 16:03:20 +00:00
Denys Vlasenko
3bb7cd6660 * defs.h: Correct the comment about TCB_SUSPENDED.
* strace.c: Fix misplaced #endif.
* util.c: Indent preprocessor directives, mark code parts
which can never be reached by compilation because of
the combination of #if directives. These are likely dead code,
I want to remove them later.
2009-02-09 18:55:59 +00:00
Denys Vlasenko
7a8bf06580 * strace.c (newoutf): Prevent -o FILENAME overflowing the stack.
(startup_attach): Fix wrong pid in "Process <PID> attached".
(handle_group_exit): Do not consider exit to be spurious if
tcb has TCB_STARTUP bit set - we can attach to the task
right before its death, it can legitimately happen.
(handle_stopped_tcbs): Ditto.
2009-01-29 20:38:20 +00:00
Denys Vlasenko
7e0615f3ae * process.c (internal_clone): Check and complain if pid value
looks insane.
* strace.c (alloc_tcb): Clear *all* fields in reused tcb.
(main): Query and remember uname() info on startup.
(handle_stopped_tcbs): Do not use PTRACE_SETOPTIONS on Linux < 2.6.29.
(printleader): Correct printing of "<unavailable>" markers.
2009-01-28 19:00:54 +00:00
Denys Vlasenko
47ce6dfc9f * strace.c (collect_stopped_tcbs): Guard against the case when
waitpid() reports the same task multiple times.
Run tested.
2009-01-27 19:38:44 +00:00
Denys Vlasenko
2c8a258361 * strace.c (collect_stopped_tcbs): Do not return NULL when ECHILD
is detected, return collected list instead. Fixes symptom when
the last "+++ killed by SIGxxx +++" is not printed.
2009-01-21 19:05:43 +00:00
Denys Vlasenko
418d66a847 Two cleanups: tcb table expansion failure is not really a survivable
event, we do not have any viable way to continue. No wonder most
places where that is detected have FIXMEs.
It's way simpler to treat as fatal failure, and handle it inside
tcb table expansion finctions.
Second cleanup: tidy up haphazard locations of a few externs.

* defs.h: Change return type of expand_tcbtab() to void.
Declare change_syscall().
* process.c: Change all callsites of alloctcb(), alloc_tcb() and
fork_tcb(), removing now-redundant error checks.
(fork_tcb): Change return type to void - it can't fail now.
* strace.c: Move extern declarations out of function bodies.
Change all callsites of alloctcb(), alloc_tcb() and
fork_tcb(), removing now-redundant error checks.
(expand_tcbtab): Change return type to void - it can't fail now.
On failure to expand, print a message, clean up, and exit.
(alloc_tcb): On failure to expand, print a message, clean up, and exit.
* util.c (setbpt): Remove extern declaration from function body.
2009-01-17 01:52:54 +00:00
Denys Vlasenko
1d5b113f8c * defs.h: Update a comment. No code changes.
* strace.c (handle_stopped_tcbs): Discard all execve stops
and clear TCB_WAITEXECVE bit.
* syscall.c (get_scno): Add the code to not mistakenly
treat ptrace stop as execve stop (execve stops can be blocked
by traced program).
Fixes RH#477775 "strace hangs if the target process blocks SIGTRAP".
2009-01-17 01:06:18 +00:00
Denys Vlasenko
f9a7e63a1a * process.c: Add a comment. No code changes.
* strace.c (collect_stopped_tcbs): Stop reversing list of stopped
tcp's. I'm not totally convinced it is crucial, but this is surely
fits the concept of "least surprise".
Do not collect TCB_SUSPENDED tcp's (this is closer to how
it was before).
(handle_stopped_tcbs): Remove the code to reject TCB_SUSPENDED tcp's,
it's done earlier now. In an unobvious way, this was causing
SIGSTOPs from freshly attached children to be misinterpreted.
2009-01-17 00:21:31 +00:00
Denys Vlasenko
f535b54bc4 Fixes for ptrace() argument parsing.
* process.c: Add parsing of PTRACE_SETOPTIONS, PTRACE_GETEVENTMSG,
PTRACE_GETSIGINFO, PTRACE_SETSIGINFO.
* strace.c (handle_stopped_tcbs): Make PTRACE_SETOPTIONS
define check more robust.
* defs.h: Declare several "extern const struct xlat" arrays here.
* desc.c: Remove open_mode_flags[] and open_access_modes[]
extern declarations.
* net.c: Remove open_mode_flags[] extern declaration.
* sock.c: Remove addrfams[] extern declaration.
* util.c: Remove struct_user_offsets[] extern declaration.
* signal.c: Remove open_mode_flags[] extern declaration.
2009-01-13 18:30:55 +00:00
Denys Vlasenko
215cc27037 * defs.h: Add new struct tcb fields: wait_status, next_need_service.
make flags field wider (ints are easier to work with on many CPUs).
* strace.c (trace): Split this function into two:
collect_stopped_tcbs() and handle_stopped_tcbs().
Now we collect *all* waitable tasks, then handle them all,
then repeat.
Fixes RH#478419 "Some threads stop when strace with -f option
is executed on a multi-thread process"
* test/many_looping_threads.c: example program which cna't be straced
successfully without this fix.
2009-01-09 17:22:56 +00:00
Denys Vlasenko
ef2fbf856c Output format fixes, improving the situation after recent
change which added better handling of processes suddenly
disappearing. Now we often do not finish last line
before exiting in those cases.
The only change affecting something other than output
is change in umovestr where we were calling
abort() on ptrace error.

* strace.c (trace): If trace_syscall() failed with ESRCH,
finish current output line with " <unfinished ...>".
(mp_ioctl): While we are at it, fix gross style mismatch
in this function definition. No code chages.
* syscall.c (trace_syscall): If decode fails on syscall exit,
finish current output line with "= ? <unavailable>".
* util.c (umoven): Do not complain if error is ESRCH.
(umovestr): Do not complain and do not abort() if error is ESRCH.
* defs.h: Remove unused tcp parameter from printtrailer().
* process.c: Adjust printtrailer() calls accordingly.
* strace.c: Adjust printtrailer() calls accordingly.
* syscall.c: Adjust printtrailer() calls accordingly.
2009-01-06 21:45:06 +00:00
Denys Vlasenko
0861ecbb44 * strace.c: Fix compile failure: on some systems PTRACE_O_xxx
and PTRACE_EVENT_xxx constants are not defined.
2009-01-02 16:55:24 +00:00
Denys Vlasenko
ecfe2f19f9 Experimental support for -D option.
Unlike normal case, with -D *grandparent* process exec's,
becoming a traced process. Child exits (this prevents traced process
from having children it doesn't expect to have), and grandchild
attaches to grandparent similarly to strace -p PID.
This allows for more transparent interaction in cases
when process and its parent are communicating via signals,
wait() etc. Without -D, strace process gets lodged in between,
disrupting parent<->child link.

* strace.c: Add global flag variable daemonized_tracer for -D option.
(startup_attach): If -D, fork and block parent in pause().
In this case we are already a child, we in fact created a grandchild.
After attaching to grandparent, grandchild SIGKILLs parent.
(startup_child): If -D, parent blocks in wait(), then
execs the program to strace. Normally (w/o -D), it is child
who execs the program.
(main): Detect -D option, call startup_attach() if it is given.
2008-12-30 20:51:30 +00:00
Denys Vlasenko
96d5a76109 * defs.h: Remove sigtrap80 field from struct tcb.
* strace.c: Add ptrace_stop_sig static variable
and use it in place of tcp->sigtrap80.
Add ptrace_opts_set static flag variable.
(trace): Set ptrace options once, not per-process.
If unexpected SIGTRAP is later received,
revert back to using SIGTRAP
(assume old, broken kernel).
2008-12-29 19:13:27 +00:00
Denys Vlasenko
b1efe53531 Fix build breakage from my previous commit.
Now I test for PT_SETOPTIONS being #defined.
Remove trailing whitespace.
No actual code changes.
2008-12-23 16:14:42 +00:00
Denys Vlasenko
1e3ce32a4f Make strace correctly handle SIGTRAP produced by e.g.
kill(2) and by trapping instruction.
* defs.h: Add sigtrap80 field to struct tcb.
* strace.c (alloc_tcb): Initialize it to SIGTRAP.
(detach): Use tcp->sigtrap80 instead of SIGTRAP constant.
(trace): Attempt to set PTRACE_O_TRACESYSGOOD and
PTRACE_O_TRACEEXEC options on each newly attached process,
distinquish between SIGTRAP and (SIGTRAP | 0x80) stops.
Fixes RH#162774 "strace ignores int3 SIGTRAP".
2008-12-22 19:14:47 +00:00
Denys Vlasenko
732d1bf4d4 Make strace somewhat resilient against process disappearing
under its claws. Prime example is sudden SIGKILL.
Fixes RH#472053
2008-12-17 19:21:59 +00:00
Denys Vlasenko
932fc7d4fc This patch does not change any logic.
It merely passes tcp pointer to upeek instead of pid.
This is needed if one wants to check or change
some tcp fields.

I have patches which require this. I can imagine someone else
eventually needing to look at tcp for completely orthogonal reasons.
2008-12-16 18:18:40 +00:00
a68096576a 2008-09-29 Dmitry V. Levin <ldv@altlinux.org>
* strace.c (startup_child): Save child pid for future use.
	(main): Exit/kill ourself with straced child's exitcode/signal.
	(trace): If signalled process pid matches the saved child pid,
	save the signal number.  If terminated process pid matches the
	saved child pid, save its exit status.
	Patch from Denys Vlasenko <dvlasenk@redhat.com>
2008-11-10 17:14:58 +00:00
Jan Kratochvil
1f942710a5 2008-08-06 Jan Kratochvil <jan.kratochvil@redhat.com>
Fix compiler warnings.
	* signal.c (sys_signal): Cast to SIG_* to the matching type LONG.
	* strace.c (trace): Variables PSR and PC are now signed.
	* syscall.c (syscall_enter): Variable RBS_END is now signed long.
	Remove/add the RBS_END casts appropriately.
	* util.c [IA64] (arg_setup): Variable BSP is now signed long.
	Remove/add the BSP casts appropriately.
	<ia32>: Initialize *STATE.
2008-08-06 21:38:52 +00:00
06350dba75 2008-07-24 Dmitry V. Levin <ldv@altlinux.org>
* strace.c (main): Fix -F option backwards compatibility.
2008-07-25 15:42:34 +00:00
Roland McGrath
41c48227a8 2008-07-03 Jan Kratochvil <jan.kratochvil@redhat.com>
Trace even VFORK on -f on all the platforms.
	* strace.1 <-f>: Describe Linux catches new children immediately.
	<-F>: Make the option obsolete.  Move the SunOS VFORK comment to the
	`-f' option description.
	* defs.h (followvfork): Declaration removed.
	* strace.c (followvfork): Variable removed.
	(main) <-F>: Merge with the `-f' option.
	(trace): Make !FOLLOWVFORK unconditional.
	* process.c (internal_fork): Make !FOLLOWVFORK unconditional.
2008-07-18 00:25:10 +00:00
Roland McGrath
276ceb33f2 2007-11-06 Jan Kratochvil <jan.kratochvil@redhat.com>
* strace.c [LINUX] (droptcb): Recurse on TCP->parent if it is a
	TCB_EXITING zombie group leader.
	* test/childthread.c: New file.
	* test/.cvsignore, test/Makefile: Add it.
	Code advisory: Roland McGrath
	Fixes RH#354261.
2007-11-13 08:12:12 +00:00
Roland McGrath
54cc1c8ae2 2007-11-03 Jan Kratochvil <jan.kratochvil@redhat.com>
* strace.c (main): Move the STARTUP_CHILD call before setting up the
	signal handlers.  New comment about the valid internal states.
2007-11-03 23:34:11 +00:00
08b623eb84 2007-09-25 Dmitry V. Levin <ldv@altlinux.org>
* strace (main): Use calloc for tcbtab allocation.
	Check calloc return value.
	Reported by Bai Weidong.
2007-10-08 21:04:41 +00:00
Roland McGrath
1bfd310325 2007-08-02 Jan Kratochvil <jan.kratochvil@redhat.com>
* strace.c (detach): Moved the resume notification code to ...
	(resume_from_tcp): ... a new function here.
	(handle_group_exit): No longer detach also the thread group leader.
	(trace): Fixed panic on exit of the TCB_GROUP_EXITING leader itself.
2007-08-03 10:02:00 +00:00
Roland McGrath
d6a32f176c 2007-07-11 Roland McGrath <roland@redhat.com>
* strace.c (handle_group_exit): Detach TCP before LEADER.
	Don't use PTRACE_KILL on LEADER.
2007-07-11 08:35:11 +00:00
Roland McGrath
4bfa6266eb 2007-07-05 Roland McGrath <roland@redhat.com>
* strace.c (strace_fopen): [_LFS64_LARGEFILE]: Use fopen64.
	Fixes Debian#385310.
2007-07-05 20:03:16 +00:00
Roland McGrath
09553f85cd 2007-07-05 Roland McGrath <roland@redhat.com>
* strace.c (main): Fix error message for unfound -u user.
	From Srinivasa Ds <srinivasa@in.ibm.com>.
2007-07-05 19:31:49 +00:00
Roland McGrath
0a46388034 2007-07-05 Jan Kratochvil <jan.kratochvil@redhat.com>
* strace.c (detach): New prototype.  Extended the function comment.
	[LINUX] (detach): Call droptcb() instead of the wrongly parametrized
	detach() call.
	(handle_group_exit): Call droptcb() instead of the wrongly parametrized
	detach() call.	Always call detach() only once from the group leader.
	Comment the leader killing known bug tested by `test/leaderkill.c'.
	Code advisory: Roland McGrath
	Fixes RH#240961.
2007-07-05 18:43:16 +00:00
Roland McGrath
02203311e9 2007-06-11 Jan Kratochvil <jan.kratochvil@redhat.com>
Never interrupt when the attached traced process would be left stopped.
	* strace.c (main): `-p' attaching moved to ...
	(startup_attach): ... a new function, renamed a variable C to TCBI.
	Block interrupting signals since the first tracee has been attached.
	New comment about INTERRUPTED in the nonthreaded case.
	[LINUX] (startup_attach): Check INTERRUPTED after each attached thread.
	(main): Command spawning moved to ...
	(startup_child): ... a new function, replaced RETURN with EXIT.
	[LINUX] (detach): New variable CATCH_SIGSTOP, do not signal
	new SIGSTOP for processes still in TCB_STARTUP.
	(main): Move signals and BLOCKED_SET init before the tracees attaching,
	[SUNOS4] (trace): Removed fixvfork () call as a dead code, SIGSTOP must
	have been already caught before clearing TCB_STARTUP.
	(trace): Removed the `!WIFSTOPPED(status)' dead code.
	Clear TCB_STARTUP only in the case the received signal was SIGSTOP.
	New comment when `TCB_BPTSET && TCB_STARTUP' combination can be set.
	Code advisory: Roland McGrath
	Fixes RH#240986.
2007-06-11 22:06:31 +00:00
Roland McGrath
134813ae1e 2007-05-24 Jan Kratochvil <jan.kratochvil@redhat.com>
* strace.c [LINUX] (my_tgkill): New macro.
	[LINUX] (detach): Use my_tgkill () instead of kill(2).
	Fixes RH#240962.
2007-06-02 00:07:33 +00:00
10de62bb05 2006-12-12 Dmitry V. Levin <ldv@altlinux.org>
Fix -ff -o behaviour.  Fix piping trace output.
	* defs.h (newoutf): Remove.
	(alloctcb): Rename to alloc_tcb.  Add alloctcb() macro wrapper
	around alloc_tcb().
	* process.c [!USE_PROCFS] (internal_clone, internal_fork):
	Remove newoutf() call.
	* strace.c (set_cloexec_flag, strace_fopen, strace_popen,
	swap_uid): New functions.
	(popen_pid): New variable.
	(newoutf): Make static, use strace_fopen().
	(main): Use strace_fopen() and strace_popen(), remove uids
	swapping.  Do not open outfname when followfork > 1.
	Reinitialize tcp->outf properly.
	(alloctcb): Rename to alloc_tcb.  Use newoutf().
	(trace): Check popen_pid.  Remove newoutf() call.
	[USE_PROCFS] (proc_open, proc_poll_open): Use set_cloexec_flag().
	Fixes RH#204950, RH#218435.
2006-12-13 21:45:31 +00:00
b9fe011cdf 2006-12-10 Dmitry V. Levin <ldv@altlinux.org>
Make several global variables static.
	#ifdef definitions of rarely unused functions.
	* defs.h (rflag, tflag, outfname): Remove.
	* strace.c (iflag, interactive, pflag_seen, rflag, tflag,
	outfname, username): Make static.
	* desc.c (sys_getdtablesize): Define only for
	ALPHA || FREEBSD || SUNOS4.
	* file.c (sys_fchroot): Define only for SUNOS4 || SVR4.
	(sys_mkfifo): Define only for FREEBSD.
	* mem.c (sys_sbrk): Define only for FREEBSD || SUNOS4.
	(sys_getpagesize): Define only for
	ALPHA || FREEBSD || IA64 || SUNOS4 || SVR4.
	* net.c (sys_so_socket): Define only for SVR4.
	* process.c (sys_gethostid): Define only for
	FREEBSD || SUNOS4 || SVR4.
	(sys_gethostname): Define only for
	ALPHA || FREEBSD || SUNOS4 || SVR4.
	(sys_setpgrp): Define only for ALPHA || SUNOS4 || SVR4.
	(sys_execv): Define only for SPARC || SPARC64 || SUNOS4.
	* signal.c (sys_sigblock): Define only for FREEBSD || SUNOS4.
	(sys_sighold, sys_sigwait): Define only for SVR4.
	(sys_killpg): Define only for FREEBSD || SUNOS4.
	* stream.c (sys_getmsg): Define only for
	SPARC || SPARC64 || SUNOS4 || SVR4.
	* syscall.c (sys_indir): Define only for SUNOS4.
2006-12-13 16:59:44 +00:00
cbd470fc9d 2006-10-14 Dmitry V. Levin <ldv@altlinux.org>
* strace.c (main): Check getcwd() return code.
2006-10-14 14:23:57 +00:00
9633942c07 2006-10-06 Dmitry V. Levin <ldv@altlinux.org>
* strace.c [!USE_PROCFS] (trace): Presence of PT_GETSIGINFO
	macro does not mean that PT_CR_IPSR and PT_CR_IIP macros are
	also defined, so check them along with PT_GETSIGINFO.
	Fixes RH#209856.
2006-10-11 23:11:43 +00:00
76860f60d7 2006-03-29 Dmitry V. Levin <ldv@altlinux.org>
Fix race conditions in tcb allocation.
	* process.c (fork_tcb): Return error code as documented.  Do not
	print "tcb table full" error message.
	[USE_PROCFS] (internal_fork): Do not print "tcb table full"
	error message.
	[SYS_clone || SYS_clone2] (internal_clone, internal_fork): Call
	fork_tcb() before alloctcb().  Do not print "tcb table full"
	error message.
	* strace.c (main): Do not print "tcb table full" error message.
	(expand_tcbtab): Print error message in case of memory allocation
	failure.
	(alloctcb): Print error message when tcb table is full.
	(trace): Expand tcb table if necessary prior to allocating
	entry there.  Do not print "tcb table full" error message.
	Fixes RH#180293.
2006-10-11 22:55:25 +00:00
Roland McGrath
cb9def6975 2006-04-25 Roland McGrath <roland@redhat.com>
* strace.c (main): Fail when -c is given with -ff.
	* strace.1: Note their incompatibility.
	Fixes RH#187847.
2006-04-25 07:48:03 +00:00
Roland McGrath
d0c4c0cb88 2006-04-25 Roland McGrath <roland@redhat.com>
* strace.c (main): Fail when nonoption args follow -p switches.
	Fixes Debian#361302.
2006-04-25 07:39:40 +00:00
Roland McGrath
138c6a334f 2005-11-17 Dmitry V. Levin <ldv@altlinux.org>
Implement qual_flags support for each personality.
	* strace.c (main): Move qualify calls after set_personality call.
	* syscall.c (qual_flags0): New variable..
	[SUPPORTED_PERSONALITIES >= 2] (qual_flags1): New variable.
	[SUPPORTED_PERSONALITIES >= 3] (qual_flags2): New variable.
	(qual_flags): Change variable definition from array to pointer.
	(set_personality): Initialize qual_flags variable.
	(qualify_one): Add "pers" argument to specify personality.
	[SUPPORTED_PERSONALITIES >= 2]: Set qual_flags1 if requested.
	[SUPPORTED_PERSONALITIES >= 3]: Set qual_flags2 if requested.
	(qual_syscall): Pass personality to qualify_one.
	[SUPPORTED_PERSONALITIES >= 2]: Look for syscall also in sysent1
	table.
	[SUPPORTED_PERSONALITIES >= 3]: Look for syscall also in sysent2
	table.
	(qual_signal): Pass personality to qualify_one.
	(qual_desc): Likewise.
	(qualify): Use qualify_one instead of manual qual_flags
	manipulations.
	[SUPPORTED_PERSONALITIES >= 2]: Look for syscall also in sysent1
	table.
	[SUPPORTED_PERSONALITIES >= 3]: Look for syscall also in sysent2
	table.
	* defs.h: Update qual_flags declaration.
	Fixes RH#173986.
2006-01-12 09:50:49 +00:00
Roland McGrath
a08a97eff3 2005-08-03 Roland McGrath <roland@redhat.com>
* strace.c (detach): If detaching the last live thread in a group with
	a zombie leader, then detach the leader too.
	(handle_group_exit): Use detach, not droptcb, for predeceased thread.
	Mark process about to take a signal with TCB_GROUP_EXITING flag.
	Fixes RH#161919.
2005-08-03 11:23:46 +00:00
Roland McGrath
76989d7a16 2005-06-06 Roland McGrath <roland@redhat.com>
* defs.h (struct sysent): New member `native_scno'.
	(known_scno): Declare new function.
	* linux/syscallent.h: Add new final field to interesting syscalls.
	* syscall.c (known_scno): New function.
	(dumpio, internal_syscall, syscall_fixup, trace_syscall): Use it.
	* process.c (internal_fork, internal_exit): Likewise.
	[IA64] (ARG_STACKSIZE, ARG_PTID, ARG_CTID, ARG_TLS): Likewise.
	* strace.c (proc_open): Likewise.
	* util.c [LINUX] (setbpt): Likewise.
	* linux/syscall.h: Remove [!defined(X86_64)] from conditional
	for defining SYS_socket_subcall et al.
	* linux/syscallent.h: Likewise for #error check.
	* syscall.c (trace_syscall): Likewise for SYS_{socketcall,ipc} cases.
	Fixes RH#158934.
2005-06-07 23:21:31 +00:00
Roland McGrath
46100d0725 2005-05-31 Dmitry V. Levin <ldv@altlinux.org>
* bjm.c (sys_query_module) [LINUX]: Unitize "out of memory"
	errors reporting style.
	* strace.c (rebuild_pollv) [USE_PROCFS]: Likewise.
	* system.c (sys_capget, sys_capset) [SYS_capget]: Likewise.
	* util.c (printstr): Likewise.
	(dumpiov) [HAVE_SYS_UIO_H]: Likewise.
	(fixvfork) [SUNOS4]: Likewise.
	* desc.c (decode_select): Continue to decode syscall arguments
	in case of OOM condition.
	* file.c (sys_getdents): Likewise.
	(sys_getdents64) [_LFS64_LARGEFILE]: Likewise.
	(sys_getdirentries) [FREEBSD]: Likewise.
	* mem.c (sys_mincore): Changed type of variables which deal with
	malloc size from int to unsigned long.
	Fixes RH#159308.
2005-06-01 18:55:42 +00:00
Roland McGrath
dccec72a72 2005-05-09 Roland McGrath <roland@redhat.com>
* strace.c (main): Refuse negative -s argument value.
	Fixes Debian bug #303256.
2005-05-09 07:45:47 +00:00
Roland McGrath
3a055d7d64 2005-03-06 Roland McGrath <roland@redhat.com>
* strace.c (trace) [PTRACE_GETSIGINFO]: Fetch siginfo_t for SIGSEGV
	and SIGBUS signals, use si_addr in output.
2005-03-06 22:24:29 +00:00
Roland McGrath
15dca8e307 2004-12-19 Dmitry V. Levin <ldv@altlinux.org>
* strace.c (main) [!USE_PROCFS]: In child process, raise SIGSTOP
	right before execv() call.  Remove fake_execve() call.
	* defs.h (fake_execve): Remove unused declaration.
	* process.c (fake_execve): Remove unused function.
	Fixes RH#143365.
2005-02-06 01:16:32 +00:00
Roland McGrath
795edb1148 2004-12-20 Dmitry V. Levin <ldv@altlinux.org>
* configure.ac: Use AC_GNU_SOURCE macro instead of changing CFLAGS.
	* defs.h [HAVE_CONFIG_H]: Include config.h first.
	* strace.c: Include "defs.h" first.
	Fixes RH#143370.
2005-02-02 04:44:57 +00:00
Roland McGrath
00dc13fbe7 2004-10-19 Roland McGrath <roland@redhat.com>
* strace.c (handle_group_exit): Don't detach leader that wasn't
	TCB_ATTACHED.  Instead mark it with TCB_GROUP_EXITING.
	Remove droptcb loop at end, no longer required since 2.6 reports each
	thread death.
	Fixes RH#135254.
2004-10-20 02:04:15 +00:00
Roland McGrath
0569095472 2004-10-19 Roland McGrath <roland@redhat.com>
* strace.c (trace): Use handle_group_exit for non-TCB_ATTACHED child
	taking signal when it has nclone_threads > 0.
	* strace.c (handle_group_exit): Don't detach leader that wasn't
	TCB_ATTACHED.
	* strace.c (handle_group_exit, trace): Mark leader with
	TCB_GROUP_EXITING and don't be surprised at child deaths when their
	leader has it set.
	Fixes RH#132150.
2004-10-20 01:00:27 +00:00
Roland McGrath
08f0ae30fd 2004-08-30 Roland McGrath <roland@redhat.com>
* strace.c (main): Don't call fake_execve under -c.
	From Ulrich Drepper <drepper@redhat.com>.
	Fixes RH#129166.
2004-08-31 07:01:56 +00:00
Roland McGrath
7b54a7ae61 2004-06-03 Roland McGrath <roland@redhat.com>
* strace.c (main) [LINUX]: Expand TCBTAB as necessary for threads
	attached.  Attach threads only under -f.  Set TCB_FOLLOWFORK in them.
	(expand_tcbtab): New function, broken out of ...
	* process.c (fork_tcb): ... here, call that.
	* defs.h: Declare expand_tcbtab.
2004-06-04 01:50:45 +00:00
Roland McGrath
70b08530b8 2004-04-08 Roland McGrath <roland@redhat.com>
* strace.c (main) [LINUX]: When attaching for -p, look in
	/proc/PID/task for all threads and attach them as presumed
	CLONE_THREAD children.
2004-04-09 00:25:21 +00:00
Roland McGrath
bdb09df186 2004-03-01 Roland McGrath <roland@redhat.com>
* strace.c (main): Avoid potential buffer overruns from ludicrous
	arguments or PATH values.
2004-03-02 06:50:04 +00:00
Roland McGrath
c3266d51f0 2004-02-19 Roland McGrath <roland@redhat.com>
* strace.c (main): Use TCP->pid, not PID, in -p message.
	Fixes Debian bug #229802.
2004-02-20 02:23:52 +00:00
Roland McGrath
2efe879fa8 2003-12-15 Dmitry V. Levin <ldv@altlinux.org>
* strace.c (trace) [WCOREDUMP]: Show coredump status of the
	killed process if available.
2004-01-13 09:59:45 +00:00
Roland McGrath
ce0d15442e 2003-11-11 Roland McGrath <roland@redhat.com>
* strace.c (main): Bail with usage error for missing command before we
	open the -o file or fiddle uids.
2003-11-11 21:24:23 +00:00
Roland McGrath
37b9a66dd4 2003-11-06 Roland McGrath <roland@redhat.com>
* strace.c (main): Treat piped output more like file output.
	Disallow -ff with piped output.  Fixes RH#105366.
	Reported by Dmitry V. Levin <ldv@altlinux.org>
2003-11-07 02:26:54 +00:00
Roland McGrath
b310a0c26b 2003-11-06 Roland McGrath <roland@redhat.com>
* strace.c (tprintf): Check result of vfprintf and use perror when it
	fails while not writing to stderr itself.  Fixes Debian bug #218762.
2003-11-06 23:41:22 +00:00
Roland McGrath
0a39690698 2003-06-09 Roland McGrath <roland@redhat.com>
* strace.c (trace): Print a message and newline for a WIFEXITED report
	from the process we just printed an unterminated syscall line for.
2003-06-10 03:05:53 +00:00
Roland McGrath
ed64516fa4 2003-06-03 Roland McGrath <roland@redhat.com>
* strace.c (main): In PATH search, accept only a regular file with
	execute bits set.  Fixes Debian bug #137103.
2003-06-03 07:18:19 +00:00
Roland McGrath
369310502b 2003-06-02 Roland McGrath <roland@redhat.com>
* strace.c (main): Set -q when given -o and not -p, and not when not
	given -o, to match what the man page always said.
	Fixes Debian bug #47113, #153678.
2003-06-03 01:35:20 +00:00
Roland McGrath
0962345a57 2003-05-22 Roland McGrath <roland@redhat.com>
* defs.h (struct tcb): New member `nzombies'.
	* strace.c (alloctcb): Initialize it.
	(droptcb): Increment our parent's zombie count.
	* process.c (internal_wait): Don't go into TCB_SUSPENDED if the
	process has zombies it can reap.  On the way out, if we reaped
	an untraced process, decrement the zombie count.
2003-05-23 02:27:13 +00:00
Roland McGrath
9c9a2534e3 2003-02-19 Roland McGrath <roland@redhat.com>
* version.c: Removed.
	* Makefile.am (strace_SOURCES): Remove it.
	* strace.c: Use PACKAGE_NAME and VERSION macros instead of version var.
2003-02-20 02:56:29 +00:00
Roland McGrath
de6e53308c 2003-01-21 Roland McGrath <roland@redhat.com>
* strace.c (usage): Omit -z, since it has never worked properly.
	* NEWS: Likewise.
	* strace.c (main): Grok new option `-E var=val' or `-E var' to put
	var=val in environ or to remove var, respectively.
	(usage): Mention it.
	* strace.1, NEWS: Document it.
2003-01-24 04:31:23 +00:00
Roland McGrath
8f474e087e 2003-01-13 Roland McGrath <roland@redhat.com>
* strace.c [! HAVE_STRSIGNAL]: Clean up #ifdefs on decls for
	sys_siglist and _sys_siglist.
	Reported by John Hughes <john@Calva.COM>.
2003-01-14 07:53:33 +00:00
Roland McGrath
e29341c02f 2003-01-10 Roland McGrath <roland@redhat.com>
* strace.c (droptcb): Clear flags word before calling rebuild_pollv.
2003-01-10 20:14:20 +00:00
Roland McGrath
c012d223a6 2003-01-10 Roland McGrath <roland@redhat.com>
* strace.c (rebuild_pollv): Fix typo: struct poll -> struct pollfd.
2003-01-10 20:05:56 +00:00
Roland McGrath
ca16be8be9 2003-01-10 Roland McGrath <roland@redhat.com>
* strace.c (pfd2tcb): Fix for new tcbtab type.
	(rebuild_pollv): Likewise.
	(detach): Put variables used under [LINUX] inside #ifdef.
2003-01-10 19:55:28 +00:00
Roland McGrath
e85bbfe9ab 2003-01-08 Roland McGrath <roland@redhat.com>
Support for new Linux 2.5 thread features.
	* defs.h [LINUX]: Define __NR_exit_group if not defined.
	(struct tcb): New members nclone_threads, nclone_detached,
	and nclone_waiting.
	(TCB_CLONE_DETACHED, TCB_CLONE_THREAD, TCB_GROUP_EXITING): New macros.
	(waiting_parent): Macro removed.
	(pid2tcb): Declare it.
	* process.c (internal_clone) [TCB_CLONE_THREAD]: Reparent the new
	child to our parent if we are a CLONE_THREAD child ourselves.
	Maintain TCB_CLONE_THREAD and TCB_CLONE_DETACHED flags and counts.
	(internal_wait) [TCB_CLONE_THREAD]: Factor out detached children when
	determining if we have any.  If TCB_CLONE_THREAD is set, check
	parent's children instead of our own, and bump nclone_waiting count.
	(internal_exit) [__NR_exit_group]: Set the TCB_GROUP_EXITING flag if
	the syscall was exit_group.
	* syscall.c (internal_syscall): Use internal_exit for exit_group.
	* strace.c (pid2tcb): No longer static.
	(alloctcb) [TCB_CLONE_THREAD]: Initialize new fields.
	(droptcb) [TCB_CLONE_THREAD]: Maintain new fields.
	If we have thread children, set TCB_EXITING and don't clear the TCB.
	(resume) [TCB_CLONE_THREAD]: Decrement parent's nclone_waiting.
	(detach) [TCB_CLONE_THREAD]: When calling resume, check all thread
	children of our parent that might be waiting for us too.
	[TCB_GROUP_EXITING] (handle_group_exit): New function.
	(trace) [TCB_GROUP_EXITING]: Use that in place of detach or droptcb.
	Revamp -f support for Linux.
	* util.c [LINUX] (setbpt, clearbpt): New implementations that tweak
	the system call to be clone with CLONE_PTRACE set.  Various new static
	helper functions.
	* process.c (internal_clone): Define also #ifdef SYS_clone2.
	Initialize TCPCHILD->parent field.
	[CLONE_PTRACE]: Don't do PTRACE_ATTACH here, because it's preattached.
	Check in case the new child is in the tcb already.
	(internal_fork) [LINUX]: Just call internal_clone.
	* strace.c (trace) [LINUX]: Under -f/-F, grok an unknown pid
	reporting to wait, put it in the TCB with TCB_ATTACHED|TCB_SUSPENDED.
2003-01-09 06:53:31 +00:00
Roland McGrath
fd3e042300 2002-12-30 Roland McGrath <roland@redhat.com>
* version.c (version): Make const, bump to 4.4.90.
	* strace.c: Update decl.
2002-12-30 09:33:22 +00:00
Roland McGrath
6d2b34971b 2002-12-22 Roland McGrath <roland@redhat.com>
Update to Autoconf 2.57, and Automakify with version 1.7.
	* Makefile.am: New file.
	* Makefile.in: File removed.
	* configure.in: Moved to ...
	* configure.ac: ... here.  Update for Autoconf 2.5x and Automake.
	* aclocal.m4: Moved to ...
	* acinclude.m4: ... here.  Update for Autoconf 2.5x.
	* AUTHORS: New file, makes automake happy.
	* autogen.sh: File removed.
	* README-CVS: Update to recommend autoreconf instead.
	* file.c: HAVE_ST_* -> HAVE_STRUCT_STAT_ST_*.
	* net.c: HAVE_SIN6_SCOPE_ID -> HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID,
	HAVE_MSG_CONTROL -> HAVE_STRUCT_MSGHDR_MSG_CONTROL.
	* strace.c: *_DECLARED -> HAVE_DECL_*
	* stream.c: HAVE_* -> HAVE_STRUCT_*
2002-12-30 00:51:30 +00:00
Roland McGrath
ee9d435275 2002-12-17 Roland McGrath <roland@redhat.com>
* strace.c (tcbtab): Make this a pointer to pointers, not an array.
	(tcbtabsize): New variable.
	(main): Initialize them using dynamic allocation.
	(alloctcb, main): Use tcbtabsize in place of MAX_PROCS; indirect.
	(pid2tcb, cleanup): Likewise.
	[USE_PROCFS] (pollv): Make this a pointer, not an array; make static.
	(rebuild_pollv): Dynamically allocate the vector.
	* defs.h (tcbtab): Update decls.
	(MAX_PROCS): Macro removed, no more static limit on this.
	* process.c (fork_tcb): New function.
	(internal_clone, internal_fork): Use it instead of checking nprocs.
2002-12-18 04:16:10 +00:00
Roland McGrath
7508cb4678 2002-12-17 Roland McGrath <roland@redhat.com>
* strace.c (detach) [LINUX]: Use __WALL (or a second try with __WCLONE)
	in wait after sending SIGSTOP.
2002-12-17 10:48:05 +00:00
Roland McGrath
5bc05558bb 2002-12-16 Roland McGrath <roland@redhat.com>
* strace.c (trace) [LINUX]: Only check errno if wait4 actually fails,
	so we don't repeat a wait and thus drop a status.  Fixes RH#62591.
2002-12-17 04:50:47 +00:00
Roland McGrath
7bf10474b9 Fix botched commit. 2002-12-16 20:42:50 +00:00
Roland McGrath
553a609807 2002-12-15 Roland McGrath <roland@redhat.com>
* strace.c (main) [! USE_PROCFS]: Always reset SIGCHLD to SIG_DFL.
2002-12-16 20:40:39 +00:00
Michal Ludvig
17f8fb3484 Added switch for printing only succeeding syscalls. 2002-11-06 13:17:21 +00:00
John Hughes
b664308560 Fix warning if not using POLL_HACK 2002-05-23 11:02:22 +00:00
John Hughes
d870b3c31a fix warning will POLL_HACK 2002-05-21 11:24:18 +00:00
Wichert Akkerman
822f0c9a84 Fix closing of outputfiles in droptcb() 2002-04-03 10:55:14 +00:00
Wichert Akkerman
eb8ebdad12 close tcp->outf in droptcb() 2002-04-01 17:48:02 +00:00
John Hughes
19e49984ac only trace syscalls/signals/faults of interest 2001-10-19 08:59:12 +00:00
John Hughes
5826589d8e Merge SVR4/Linux printsiginfo 2001-10-18 15:13:53 +00:00
Wichert Akkerman
7b3346be42 Import lots of ia64 related changes from David Mosberger 2001-10-09 23:47:38 +00:00
Wichert Akkerman
54b4f79216 set CLOEXEC flag for outputfile 2001-08-03 11:43:35 +00:00
John Hughes
1d08dcf46d Merge iov fixes from Richard Kettlewell 2001-07-10 13:48:44 +00:00
Wichert Akkerman
2f1d87e74f use __WALL for wait4 if we can 2001-03-28 14:40:14 +00:00
Wichert Akkerman
2e4ffe59b5 more FreeBSD updates 2000-09-03 23:57:48 +00:00
Wichert Akkerman
bf79f2e16b Add FreeBSD support 2000-09-01 21:03:06 +00:00
Wichert Akkerman
16a03d2e97 test/clone.c: minor fixup
Another bunch of patches from John Hughes merged:
signal.c:
+ SVR4 printcontext(): sigset_t != sigset_t*
+ getcontext returns a value, so print on exit of syscall
+ add UC_FP to ucontext_flags for OS writers that can't spell
+ sys_signal(): special case SIG_{ERR,DFL,IGN}
+ decode_subcall(): only do subcall range checking when needed
bunch of UnixWare updates
aclocal.m4, acconfig.h, configure.in: add test for long long type
2000-08-10 02:14:04 +00:00
Wichert Akkerman
7987cdf192 net.c: add SOL_PACKET and SOL_RAW socket options, update SOL_IP and SOL_TCP 2000-07-05 16:05:39 +00:00
Wichert Akkerman
bd4125c6bc Close outf fd when forking 2000-06-27 17:28:06 +00:00
Wichert Akkerman
5ae21ead9f The `too much stuff, just check the ChangeLog' update 2000-05-01 01:53:59 +00:00
Wichert Akkerman
faf722234d test/vfork.c: new file to test vfork traces
test/.cvsignore: new file
defs.h: Up maximum number of traced processed to 64
strace.c: Disable some debugging code from davidm
implement setarg for more architectures
implement change_syscall
2000-02-19 23:59:03 +00:00
Wichert Akkerman
2ee6e45f36 Fixup isdigit calls 2000-02-18 15:36:12 +00:00
Wichert Akkerman
8b1b40cd8b Merge Trillian patches (Linux ia64) 2000-02-03 21:58:30 +00:00
Wichert Akkerman
4dc8a2aec6 Bunch of stuff 1999-12-23 14:20:14 +00:00
Wichert Akkerman
ea78f0f771 Add UnixWare support to configure 1999-11-29 15:34:02 +00:00
Wichert Akkerman
9dbf15466e Add pollhack 1999-11-26 13:11:29 +00:00
Wichert Akkerman
54a4767f86 Add missing newline in error 1999-10-17 00:57:34 +00:00
Wichert Akkerman
9ce1a63eb2 Catching up on my mail-backlog, see ChangeLog for details 1999-08-29 23:15:07 +00:00
Wichert Akkerman
e68d61c7d6 Remove stupid error in strace.c. Looks like I pasted something
I shouldn't have in there :(
1999-06-28 13:17:16 +00:00
Wichert Akkerman
360815ecc2 Update documentation somewhat 1999-06-28 13:16:03 +00:00
Wichert Akkerman
789ed35db5 avoid leaking fd into child 1999-06-14 10:45:01 +00:00
Wichert Akkerman
dacfb6ebd6 Add sparc patches from Jakub Jelinek 1999-06-03 14:21:07 +00:00
Nate Sammons
ce780fc9e6 Add new function `signame', which returns name (SIGXXX) of numeric
signal, and replace lookups in signalent[] with calls to it.
1999-03-29 23:23:13 +00:00
Wichert Akkerman
76baf7c9f6 Initial revision 1999-02-19 00:21:36 +00:00