98 Commits

Author SHA1 Message Date
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