]> granicus.if.org Git - strace/commitdiff
Consistently use error_msg instead of fprintf(stderr)
authorDmitry V. Levin <ldv@altlinux.org>
Mon, 25 May 2015 22:51:19 +0000 (22:51 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Mon, 25 May 2015 23:31:31 +0000 (23:31 +0000)
* 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.

12 files changed:
exit.c
linux/alpha/get_scno.c
linux/arm/get_scno.c
linux/mips/get_scno.c
linux/sh/get_scno.c
linux/x86_64/get_scno.c
pathtrace.c
strace.c
syscall.c
tests/bexecve.test
tests/detach-stopped.test
unwind.c

diff --git a/exit.c b/exit.c
index d23e528004a204083d25d14a5d1e2e190439c0ca..aec01da18fe03b340e2115bf6645b881a4ad2186 100644 (file)
--- a/exit.c
+++ b/exit.c
@@ -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 */
index 4959e1539d919fb4d1707a7d12567c89321202ab..bf8c3ada594ef4bf0e1fdceca2d4a1a68b578a79 100644 (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;
        }
 }
index f9dcd651f9a4eb9a1718786a7758b8b69f595b00..6591aa84259197b717aa483904c89fd67d415fae 100644 (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;
 }
index 967235dc0b7c31d001ad0a401425a3ec8e505791..126cedecb36f76706087d9d4fd1f16b1848bb458 100644 (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;
        }
 }
index 90dbf0f4983f29741949aaf1090626d701c322e1..b8ce272c3ecaa99c8958e85064a43f65345bde35 100644 (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;
 }
index 2eb0d5d5a24fb67331bf47011d58d09450f5ba01..02ff0a734387939c418ee42d01713a3c4a086aac 100644 (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 */
index 894dd5c963eb30c8162c956c40e3add1f0fad01e..6b3a20909d3d5dd67de88fcfbdd848ae0952273a 100644 (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++) {
index 0bffd5e1832d934efe1f5118a750de49f1e6e0e1..738c49459b3d1d98d8fdffa0c3d292929c4de8aa 100644 (file)
--- a/strace.c
+++ b/strace.c
@@ -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;
        }
index 1a9c5fc297fc104773a6d1c3054f555e66d2e681..23ed53fe2d5ff4a1903753f583281a43f53d5cdd 100644 (file)
--- a/syscall.c
+++ b/syscall.c
@@ -313,35 +313,23 @@ update_personality(struct tcb *tcp, unsigned int personality)
                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
 }
@@ -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;
 }
index 467f370141ec816df22dc57b1b0192737c5057eb..2706481e1fb9a2332cf07199ea37418ca060a107 100755 (executable)
@@ -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"
index 3d1c67e0592fc3b8d1622efa12c148ed8076bc70..1c11c10137b2f5a5285d224a57d7f57bd4addd6c 100755 (executable)
@@ -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
 
index 7c091f1b982b317b5e0dba04d5b8c613ec964f83..238e215d0003c96138d3553ee41016818ee4bea7 100644 (file)
--- a/unwind.c
+++ b/unwind.c
@@ -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,