Consistently use error_msg instead of fprintf(stderr)

* 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.
This commit is contained in:
Дмитрий Левин 2015-05-25 22:51:19 +00:00
parent df3899149e
commit 6c8ef051f7
12 changed files with 66 additions and 89 deletions

2
exit.c
View File

@ -3,7 +3,7 @@
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 */

View File

@ -10,7 +10,7 @@ if (upeek(tcp->pid, REG_R0, &scno) < 0)
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;
}
}

View File

@ -15,7 +15,7 @@ if (errno)
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;
}
@ -39,8 +39,7 @@ scno = shuffle_scno(scno);
*/
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;
}

View File

@ -3,7 +3,7 @@ scno = mips_REG_V0;
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;
}
}

View File

@ -10,10 +10,8 @@ if (scno < 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;
}

View File

@ -56,9 +56,9 @@ switch (x86_64_regs.cs) {
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;
}
@ -73,8 +73,7 @@ rip -= 2;
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;
@ -82,10 +81,9 @@ switch (call & 0xffff) {
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
@ -96,9 +94,8 @@ switch (call & 0xffff) {
* 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 */

View File

@ -141,8 +141,7 @@ pathtrace_select(const char *path)
return;
}
fprintf(stderr, "Requested path '%s' resolved into '%s'\n",
path, rpath);
error_msg("Requested path '%s' resolved into '%s'", path, rpath);
storepath(rpath);
}
@ -271,7 +270,7 @@ pathtrace_match(struct tcb *tcp)
if (umoven(tcp, tcp->u_arg[0], sizeof oldargs,
oldargs) < 0)
{
fprintf(stderr, "umoven() failed\n");
error_msg("umoven() failed");
return 0;
}
args = oldargs;
@ -292,7 +291,7 @@ pathtrace_match(struct tcb *tcp)
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++) {

View File

@ -701,7 +701,8 @@ alloctcb(int pid)
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;
}
}
@ -722,7 +723,8 @@ droptcb(struct tcb *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) {
@ -851,8 +853,8 @@ detach(struct tcb *tcp)
}
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*/) {
@ -905,7 +907,7 @@ detach(struct tcb *tcp)
drop:
if (!qflag && (tcp->flags & TCB_ATTACHED))
fprintf(stderr, "Process %u detached\n", tcp->pid);
error_msg("Process %u detached", tcp->pid);
droptcb(tcp);
}
@ -1007,11 +1009,11 @@ startup_attach(void)
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);
@ -1032,9 +1034,9 @@ startup_attach(void)
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)) {
@ -1055,7 +1057,7 @@ startup_attach(void)
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) {
/*
@ -1066,9 +1068,7 @@ startup_attach(void)
}
if (!qflag)
fprintf(stderr,
"Process %u attached\n",
tcp->pid);
error_msg("Process %u attached", tcp->pid);
} /* for each tcbtab[] */
ret:
@ -1343,7 +1343,7 @@ test_ptrace_seize(void)
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);
@ -1651,7 +1651,7 @@ init(int argc, char *argv[])
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. */
@ -1782,8 +1782,7 @@ cleanup(void)
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);
@ -1844,7 +1843,7 @@ print_debug_info(const int pid, int status)
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 *
@ -1869,7 +1868,7 @@ maybe_allocate_tcb(const int pid, int status)
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
@ -1992,15 +1991,14 @@ static void
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 */
@ -2187,7 +2185,7 @@ trace(void)
*/
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;
}

View File

@ -313,35 +313,23 @@ update_personality(struct tcb *tcp, unsigned int personality)
return;
tcp->currpers = personality;
# if defined(POWERPC64)
# 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]);
}
# 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)
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
}
@ -1072,8 +1060,7 @@ trace_syscall_exiting(struct tcb *tcp)
*/
#endif
default:
fprintf(stderr,
"invalid rval format\n");
error_msg("invalid rval format");
break;
}
}
@ -1295,8 +1282,7 @@ get_scno(struct tcb *tcp)
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;
}

View File

@ -20,8 +20,8 @@ run_strace_redir -enone ./set_ptracer_any false
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"

View File

@ -10,7 +10,7 @@ run_prog_skip_if_failed \
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

View File

@ -38,7 +38,7 @@
# 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,