]> granicus.if.org Git - strace/commitdiff
Get rid of TCB_INUSE and TCB_STRACE_CHILD
authorDenys Vlasenko <dvlasenk@redhat.com>
Wed, 26 Jun 2013 12:14:29 +0000 (14:14 +0200)
committerDenys Vlasenko <dvlasenk@redhat.com>
Wed, 26 Jun 2013 12:58:03 +0000 (14:58 +0200)
We can use tcb::pid == 0 as an indicator of free tcb,
and we already have strace_child variable which holds
pid of our child, if any.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
defs.h
strace.c

diff --git a/defs.h b/defs.h
index fbbe48cfa1c4f1ab958bd96b003892990b6fe735..1f1602a2e69ab0024f3b9d3bd2ffd6c1a681e5d0 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -393,7 +393,7 @@ typedef struct ioctlent {
 /* Trace Control Block */
 struct tcb {
        int flags;              /* See below for TCB_ values */
-       int pid;                /* Process Id of this entry */
+       int pid;                /* If 0, this tcb is free */
        int qual_flg;           /* qual_flags[scno] or DEFAULT_QUAL_FLAGS + RAW */
        int u_error;            /* Error code */
        long scno;              /* System call number */
@@ -418,10 +418,9 @@ struct tcb {
 };
 
 /* TCB flags */
-#define TCB_INUSE              00001   /* This table entry is in use */
 /* We have attached to this process, but did not see it stopping yet */
-#define TCB_STARTUP            00002
-#define TCB_IGNORE_ONE_SIGSTOP 00004   /* Next SIGSTOP is to be ignored */
+#define TCB_STARTUP            0x01
+#define TCB_IGNORE_ONE_SIGSTOP 0x02    /* Next SIGSTOP is to be ignored */
 /*
  * Are we in system call entry or in syscall exit?
  *
@@ -440,14 +439,13 @@ struct tcb {
  *
  * Use entering(tcp) / exiting(tcp) to check this bit to make code more readable.
  */
-#define TCB_INSYSCALL  00010
-#define TCB_ATTACHED   00020   /* It is attached already */
-/* Are we PROG from "strace PROG [ARGS]" invocation? */
-#define TCB_STRACE_CHILD 0040
-#define TCB_BPTSET     00100   /* "Breakpoint" set after fork(2) */
-#define TCB_REPRINT    00200   /* We should reprint this syscall on exit */
-#define TCB_FILTERED   00400   /* This system call has been filtered out */
-/* x86 does not need TCB_WAITEXECVE.
+#define TCB_INSYSCALL  0x04
+#define TCB_ATTACHED   0x08    /* We attached to it already */
+#define TCB_BPTSET     0x10    /* "Breakpoint" set after fork(2) */
+#define TCB_REPRINT    0x20    /* We should reprint this syscall on exit */
+#define TCB_FILTERED   0x40    /* This system call has been filtered out */
+/*
+ * x86 does not need TCB_WAITEXECVE.
  * It can detect post-execve SIGTRAP by looking at eax/rax.
  * See "not a syscall entry (eax = %ld)\n" message.
  *
@@ -468,7 +466,7 @@ struct tcb {
 /* This tracee has entered into execve syscall. Expect post-execve SIGTRAP
  * to happen. (When it is detected, tracee is continued and this bit is cleared.)
  */
-# define TCB_WAITEXECVE        01000
+# define TCB_WAITEXECVE        0x80
 #endif
 
 /* qualifier flags */
index 3fd35d9208d2ad87df88a96180287ff69fa71c0e..1415aab31d4a5894c24c8304232e4b2d50d17d6f 100644 (file)
--- a/strace.c
+++ b/strace.c
@@ -678,10 +678,9 @@ alloctcb(int pid)
 
        for (i = 0; i < tcbtabsize; i++) {
                tcp = tcbtab[i];
-               if ((tcp->flags & TCB_INUSE) == 0) {
+               if (!tcp->pid) {
                        memset(tcp, 0, sizeof(*tcp));
                        tcp->pid = pid;
-                       tcp->flags = TCB_INUSE;
 #if SUPPORTED_PERSONALITIES > 1
                        tcp->currpers = current_personality;
 #endif
@@ -959,7 +958,7 @@ startup_attach(void)
        for (tcbi = 0; tcbi < tcbtabsize; tcbi++) {
                tcp = tcbtab[tcbi];
 
-               if (!(tcp->flags & TCB_INUSE))
+               if (!tcp->pid)
                        continue;
 
                /* Is this a process we should attach to, but not yet attached? */
@@ -1252,9 +1251,9 @@ startup_child(char **argv)
                }
                tcp = alloctcb(pid);
                if (!NOMMU_SYSTEM)
-                       tcp->flags |= TCB_ATTACHED | TCB_STRACE_CHILD | TCB_STARTUP | post_attach_sigstop;
+                       tcp->flags |= TCB_ATTACHED | TCB_STARTUP | post_attach_sigstop;
                else
-                       tcp->flags |= TCB_ATTACHED | TCB_STRACE_CHILD | TCB_STARTUP;
+                       tcp->flags |= TCB_ATTACHED | TCB_STARTUP;
                newoutf(tcp);
        }
        else {
@@ -1916,7 +1915,7 @@ pid2tcb(int pid)
 
        for (i = 0; i < tcbtabsize; i++) {
                struct tcb *tcp = tcbtab[i];
-               if (tcp->pid == pid && (tcp->flags & TCB_INUSE))
+               if (tcp->pid == pid)
                        return tcp;
        }
 
@@ -1937,12 +1936,12 @@ cleanup(void)
 
        for (i = 0; i < tcbtabsize; i++) {
                tcp = tcbtab[i];
-               if (!(tcp->flags & TCB_INUSE))
+               if (!tcp->pid)
                        continue;
                if (debug_flag)
                        fprintf(stderr,
                                "cleanup: looking at pid %u\n", tcp->pid);
-               if (tcp->flags & TCB_STRACE_CHILD) {
+               if (tcp->pid == strace_child) {
                        kill(tcp->pid, SIGCONT);
                        kill(tcp->pid, fatal_sig);
                }