* linux/alpha/get_scno.c: Use error_msg.
* linux/arm/get_scno.c: Likewise.
* linux/mips/get_scno.c: Likewise.
* linux/sh/get_scno.c: Likewise.
* linux/x86_64/get_scno.c: Likewise.
* exit.c (sys_exit): Likewise.
* pathtrace.c (pathtrace_select, pathtrace_match): Likewise.
* strace.c (alloctcb, droptcb, detach, startup_attach,
test_ptrace_seize, init, cleanup, print_debug_info,
maybe_allocate_tcb, startup_tcb, trace): Likewise.
* syscall.c (update_personality, trace_syscall_exiting,
get_scno): Likewise.
* unwind.c (DPRINTF): Likewise.
* tests/bexecve.test: Update patterns.
* tests/detach-stopped.test: Likewise.
SYS_FUNC(exit)
{
if (exiting(tcp)) {
- fprintf(stderr, "_exit returned!\n");
+ error_msg("_exit returned!");
return -1;
}
/* special case: we stop tracing this process, finish line now */
if (!SCNO_IN_RANGE(scno)) {
if (alpha_a3 == 0 || alpha_a3 == -1) {
if (debug_flag)
- fprintf(stderr, "stray syscall exit: r0 = %ld\n", scno);
+ error_msg("stray syscall exit: r0 = %ld", scno);
return 0;
}
}
if ((unsigned long) scno != 0xef000000) {
/* No, it's OABI */
if ((scno & 0x0ff00000) != 0x0f900000) {
- fprintf(stderr, "pid %d unknown syscall trap 0x%08lx\n",
+ error_msg("pid %d unknown syscall trap 0x%08lx",
tcp->pid, scno);
return -1;
}
*/
if (arm_regs.ARM_ip && !SCNO_IN_RANGE(scno)) {
if (debug_flag)
- fprintf(stderr,
- "pid %d stray syscall exit: ARM_ip = %ld, scno = %ld\n",
- tcp->pid, arm_regs.ARM_ip, shuffle_scno(scno));
+ error_msg("pid %d stray syscall exit: ARM_ip = %ld, scno = %ld",
+ tcp->pid, arm_regs.ARM_ip, shuffle_scno(scno));
return 0;
}
if (!SCNO_IN_RANGE(scno)) {
if (mips_REG_A3 == 0 || mips_REG_A3 == (uint64_t) -1) {
if (debug_flag)
- fprintf(stderr, "stray syscall exit: v0 = %ld\n", scno);
+ error_msg("stray syscall exit: v0 = %ld", scno);
return 0;
}
}
our purposes, make strace print what it *should* have been */
long correct_scno = (scno & 0xff);
if (debug_flag)
- fprintf(stderr,
- "Detected glibc bug: bogus system call"
- " number = %ld, correcting to %ld\n",
- scno,
- correct_scno);
+ error_msg("Detected glibc bug: bogus system call"
+ " number = %ld, correcting to %ld",
+ scno, correct_scno);
scno = correct_scno;
}
currpers = 0;
break;
default:
- fprintf(stderr, "Unknown value CS=0x%08X while "
- "detecting personality of process "
- "PID=%d\n", (int)x86_64_regs.cs, tcp->pid);
+ error_msg("Unknown value CS=0x%08X while "
+ "detecting personality of process PID=%d",
+ (int)x86_64_regs.cs, tcp->pid);
currpers = current_personality;
break;
}
errno = 0;
call = ptrace(PTRACE_PEEKTEXT, tcp->pid, (char *)rip, (char *)0);
if (errno)
- fprintf(stderr, "ptrace_peektext failed: %s\n",
- strerror(errno));
+ perror_msg("ptrace_peektext failed");
switch (call & 0xffff) {
/* x86-64: syscall = 0x0f 0x05 */
case 0x050f: currpers = 0; break;
case 0x80cd: currpers = 1; break;
default:
currpers = current_personality;
- fprintf(stderr,
- "Unknown syscall opcode (0x%04X) while "
- "detecting personality of process "
- "PID=%d\n", (int)call, tcp->pid);
+ error_msg("Unknown syscall opcode (0x%04X) while "
+ "detecting personality of process PID=%d",
+ (int)call, tcp->pid);
break;
}
#endif
* Stracing of i386 apps is still supported.
*/
if (currpers == 0) {
- fprintf(stderr, "syscall_%lu(...) in unsupported "
- "64-bit mode of process PID=%d\n",
- scno, tcp->pid);
+ error_msg("syscall_%lu(...) in unsupported "
+ "64-bit mode of process PID=%d", scno, tcp->pid);
return 0;
}
currpers &= ~2; /* map 2,1 to 0,1 */
return;
}
- fprintf(stderr, "Requested path '%s' resolved into '%s'\n",
- path, rpath);
+ error_msg("Requested path '%s' resolved into '%s'", path, rpath);
storepath(rpath);
}
if (umoven(tcp, tcp->u_arg[0], sizeof oldargs,
oldargs) < 0)
{
- fprintf(stderr, "umoven() failed\n");
+ error_msg("umoven() failed");
return 0;
}
args = oldargs;
if (args[i] == 0)
continue;
if (umoven(tcp, args[i], fdsize, fds) < 0) {
- fprintf(stderr, "umoven() failed\n");
+ error_msg("umoven() failed");
continue;
}
for (j = 0;; j++) {
nprocs++;
if (debug_flag)
- fprintf(stderr, "new tcb for pid %d, active tcbs:%d\n", tcp->pid, nprocs);
+ error_msg("new tcb for pid %d, active tcbs:%d",
+ tcp->pid, nprocs);
return tcp;
}
}
nprocs--;
if (debug_flag)
- fprintf(stderr, "dropped tcb for pid %d, %d remain\n", tcp->pid, nprocs);
+ error_msg("dropped tcb for pid %d, %d remain",
+ tcp->pid, nprocs);
if (tcp->outf) {
if (followfork >= 2) {
}
sig = WSTOPSIG(status);
if (debug_flag)
- fprintf(stderr, "detach wait: event:%d sig:%d\n",
- (unsigned)status >> 16, sig);
+ error_msg("detach wait: event:%d sig:%d",
+ (unsigned)status >> 16, sig);
if (use_seize) {
unsigned event = (unsigned)status >> 16;
if (event == PTRACE_EVENT_STOP /*&& sig == SIGTRAP*/) {
drop:
if (!qflag && (tcp->flags & TCB_ATTACHED))
- fprintf(stderr, "Process %u detached\n", tcp->pid);
+ error_msg("Process %u detached", tcp->pid);
droptcb(tcp);
}
if (ptrace_attach_or_seize(tid) < 0) {
++nerr;
if (debug_flag)
- fprintf(stderr, "attach to pid %d failed\n", tid);
+ error_msg("attach to pid %d failed", tid);
continue;
}
if (debug_flag)
- fprintf(stderr, "attach to pid %d succeeded\n", tid);
+ error_msg("attach to pid %d succeeded", tid);
cur_tcp = tcp;
if (tid != tcp->pid)
cur_tcp = alloctcb(tid);
continue;
}
if (!qflag) {
- fprintf(stderr, ntid > 1
-? "Process %u attached with %u threads\n"
-: "Process %u attached\n",
+ error_msg(ntid > 1
+? "Process %u attached with %u threads"
+: "Process %u attached",
tcp->pid, ntid);
}
if (!(tcp->flags & TCB_ATTACHED)) {
tcp->flags |= TCB_ATTACHED | TCB_STARTUP | post_attach_sigstop;
newoutf(tcp);
if (debug_flag)
- fprintf(stderr, "attach to pid %d (main) succeeded\n", tcp->pid);
+ error_msg("attach to pid %d (main) succeeded", tcp->pid);
if (daemonized_tracer) {
/*
}
if (!qflag)
- fprintf(stderr,
- "Process %u attached\n",
- tcp->pid);
+ error_msg("Process %u attached", tcp->pid);
} /* for each tcbtab[] */
ret:
if (ptrace(PTRACE_SEIZE, pid, 0, 0) == 0) {
post_attach_sigstop = 0; /* this sets use_seize to 1 */
} else if (debug_flag) {
- fprintf(stderr, "PTRACE_SEIZE doesn't work\n");
+ error_msg("PTRACE_SEIZE doesn't work");
}
kill(pid, SIGKILL);
PTRACE_O_TRACEFORK |
PTRACE_O_TRACEVFORK;
if (debug_flag)
- fprintf(stderr, "ptrace_setoptions = %#x\n", ptrace_setoptions);
+ error_msg("ptrace_setoptions = %#x", ptrace_setoptions);
test_ptrace_seize();
/* Check if they want to redirect the output. */
if (!tcp->pid)
continue;
if (debug_flag)
- fprintf(stderr,
- "cleanup: looking at pid %u\n", tcp->pid);
+ error_msg("cleanup: looking at pid %u", tcp->pid);
if (tcp->pid == strace_child) {
kill(tcp->pid, SIGCONT);
kill(tcp->pid, fatal_sig);
e = "STOP";
sprintf(evbuf, ",EVENT_%s (%u)", e, event);
}
- fprintf(stderr, " [wait(0x%06x) = %u] %s%s\n", status, pid, buf, evbuf);
+ error_msg("[wait(0x%06x) = %u] %s%s", status, pid, buf, evbuf);
}
static struct tcb *
tcp->flags |= TCB_ATTACHED | TCB_STARTUP | post_attach_sigstop;
newoutf(tcp);
if (!qflag)
- fprintf(stderr, "Process %d attached\n", pid);
+ error_msg("Process %d attached", pid);
return tcp;
} else {
/* This can happen if a clone call used
startup_tcb(struct tcb *tcp)
{
if (debug_flag)
- fprintf(stderr, "pid %d has TCB_STARTUP, initializing it\n",
- tcp->pid);
+ error_msg("pid %d has TCB_STARTUP, initializing it", tcp->pid);
tcp->flags &= ~TCB_STARTUP;
if (!use_seize) {
if (debug_flag)
- fprintf(stderr, "setting opts 0x%x on pid %d\n",
- ptrace_setoptions, tcp->pid);
+ error_msg("setting opts 0x%x on pid %d",
+ ptrace_setoptions, tcp->pid);
if (ptrace(PTRACE_SETOPTIONS, tcp->pid, NULL, ptrace_setoptions) < 0) {
if (errno != ESRCH) {
/* Should never happen, really */
*/
if (sig == SIGSTOP && (tcp->flags & TCB_IGNORE_ONE_SIGSTOP)) {
if (debug_flag)
- fprintf(stderr, "ignored SIGSTOP on pid %d\n", tcp->pid);
+ error_msg("ignored SIGSTOP on pid %d", tcp->pid);
tcp->flags &= ~TCB_IGNORE_ONE_SIGSTOP;
goto restart_tracee_with_sig_0;
}
return;
tcp->currpers = personality;
-# if defined(POWERPC64)
- if (!qflag) {
- static const char *const names[] = {"64 bit", "32 bit"};
- fprintf(stderr, "[ Process PID=%d runs in %s mode. ]\n",
- tcp->pid, names[personality]);
- }
-# elif defined(X86_64)
- if (!qflag) {
- static const char *const names[] = {"64 bit", "32 bit", "x32"};
- fprintf(stderr, "[ Process PID=%d runs in %s mode. ]\n",
- tcp->pid, names[personality]);
- }
-# elif defined(X32)
- if (!qflag) {
- static const char *const names[] = {"x32", "32 bit"};
- fprintf(stderr, "[ Process PID=%d runs in %s mode. ]\n",
- tcp->pid, names[personality]);
- }
-# elif defined(AARCH64)
- if (!qflag) {
- static const char *const names[] = {"32-bit", "AArch64"};
- fprintf(stderr, "[ Process PID=%d runs in %s mode. ]\n",
- tcp->pid, names[personality]);
- }
-# elif defined(TILE)
+# undef PERSONALITY_NAMES
+# if defined POWERPC64
+# define PERSONALITY_NAMES {"64 bit", "32 bit"}
+# elif defined X86_64
+# define PERSONALITY_NAMES {"64 bit", "32 bit", "x32"}
+# elif defined X32
+# define PERSONALITY_NAMES {"x32", "32 bit"}
+# elif defined AARCH64
+# define PERSONALITY_NAMES {"32-bit", "AArch64"}
+# elif defined TILE
+# define PERSONALITY_NAMES {"64-bit", "32-bit"}
+# endif
+# ifdef PERSONALITY_NAMES
if (!qflag) {
- static const char *const names[] = {"64-bit", "32-bit"};
- fprintf(stderr, "[ Process PID=%d runs in %s mode. ]\n",
- tcp->pid, names[personality]);
+ static const char *const names[] = PERSONALITY_NAMES;
+ error_msg("[ Process PID=%d runs in %s mode. ]",
+ tcp->pid, names[personality]);
}
# endif
}
*/
#endif
default:
- fprintf(stderr,
- "invalid rval format\n");
+ error_msg("invalid rval format");
break;
}
}
tcp->s_ent = &unknown;
tcp->qual_flg = UNDEFINED_SCNO | QUAL_RAW | DEFAULT_QUAL_FLAGS;
if (debug_flag)
- fprintf(stderr, "pid %d invalid syscall %ld\n",
- tcp->pid, scno);
+ error_msg("pid %d invalid syscall %ld", tcp->pid, scno);
}
return 1;
}
run_strace_redir -bexecve -enone ./set_ptracer_any false ||
dump_log_and_fail_with "$STRACE $args: unexpected exit status"
-pattern_detached='Process [1-9][0-9]* detached'
-pattern_personality='\[ Process PID=[1-9][0-9]* runs in .* mode. \]'
+pattern_detached='[^:]*strace: Process [1-9][0-9]* detached'
+pattern_personality='[^:]*strace: \[ Process PID=[1-9][0-9]* runs in .* mode. \]'
LC_ALL=C grep -x "$pattern_detached" "$LOG" > /dev/null ||
dump_log_and_fail_with "$STRACE $args: output mismatch"
check_prog sleep
$STRACE -d -enone / > /dev/null 2> "$LOG"
-if grep -F -x "PTRACE_SEIZE doesn't work" "$LOG" > /dev/null; then
+if grep -x "[^:]*strace: PTRACE_SEIZE doesn't work" "$LOG" > /dev/null; then
skip_ "PTRACE_SEIZE doesn't work"
fi
# define fopen_for_input fopen
#endif
-#define DPRINTF(F, A, ...) if (debug_flag) fprintf(stderr, " [unwind(" A ")] " F "\n", __VA_ARGS__)
+#define DPRINTF(F, A, ...) if (debug_flag) error_msg("[unwind(" A ")] " F, __VA_ARGS__)
/*
* Кeep a sorted array of cache entries,