]> granicus.if.org Git - strace/commitdiff
2004-06-03 Roland McGrath <roland@redhat.com>
authorRoland McGrath <roland@redhat.com>
Fri, 4 Jun 2004 01:50:45 +0000 (01:50 +0000)
committerRoland McGrath <roland@redhat.com>
Fri, 4 Jun 2004 01:50:45 +0000 (01:50 +0000)
* 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.

defs.h
process.c
strace.c

diff --git a/defs.h b/defs.h
index 6d22d34f2c08d0e4b609088576a617c8d6f73bff..95cd897b9be43c264388b60f52046b1ca482a91a 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -413,6 +413,7 @@ extern char *xlookup P((struct xlat *, int));
 extern struct tcb *alloctcb P((int));
 extern struct tcb *pid2tcb P((int));
 extern void droptcb P((struct tcb *));
+extern int expand_tcbtab P((void));
 
 extern void set_sortby P((char *));
 extern void set_overhead P((int));
index 038fc14ee793720c2ddea46d7781644937460b75..77647256d56e6030086ad4178fd15d58dc45f325 100644 (file)
--- a/process.c
+++ b/process.c
@@ -402,27 +402,10 @@ static int
 fork_tcb(struct tcb *tcp)
 {
        if (nprocs == tcbtabsize) {
-               /* Allocate some more TCBs and expand the table.
-                  We don't want to relocate the TCBs because our
-                  callers have pointers and it would be a pain.
-                  So tcbtab is a table of pointers.  Since we never
-                  free the TCBs, we allocate a single chunk of many.  */
-               struct tcb **newtab = (struct tcb **)
-                       realloc(tcbtab, 2 * tcbtabsize * sizeof tcbtab[0]);
-               struct tcb *newtcbs = (struct tcb *) calloc(tcbtabsize,
-                                                           sizeof *newtcbs);
-               int i;
-               if (newtab == NULL || newtcbs == NULL) {
-                       if (newtab != NULL)
-                               free(newtab);
+               if (expand_tcbtab()) {
                        tcp->flags &= ~TCB_FOLLOWFORK;
                        fprintf(stderr, "sys_fork: tcb table full\n");
-                       return 1;
                }
-               for (i = tcbtabsize; i < 2 * tcbtabsize; ++i)
-                       newtab[i] = &newtcbs[i - tcbtabsize];
-               tcbtabsize *= 2;
-               tcbtab = newtab;
        }
 
        tcp->flags |= TCB_FOLLOWFORK;
index a8a1e400acb775f6b39e12e4622cca349cd552f0..5fc640d33f48e4291a0cd6de84235939aaec0ba7 100644 (file)
--- a/strace.c
+++ b/strace.c
@@ -403,7 +403,7 @@ char *argv[];
 # ifdef LINUX
                if (tcp->flags & TCB_CLONE_THREAD)
                        continue;
-               {
+               if (followfork) {
                        char procdir[MAXPATHLEN];
                        DIR *dir;
                        sprintf(procdir, "/proc/%d/task", tcp->pid);
@@ -424,13 +424,17 @@ char *argv[];
                                                   (char *) 1, 0) < 0)
                                                ++nerr;
                                        else if (tid != tcbtab[c]->pid) {
-                                               tcp = alloctcb(tid);
+                                               if (nprocs == tcbtabsize &&
+                                                   expand_tcbtab())
+                                                       tcp = NULL;
+                                               else
+                                                       tcp = alloctcb(tid);
                                                if (tcp == NULL) {
                                                        fprintf(stderr, "%s: out of memory\n",
                                                                progname);
                                                        exit(1);
                                                }
-                                               tcp->flags |= TCB_ATTACHED|TCB_CLONE_THREAD|TCB_CLONE_DETACHED;
+                                               tcp->flags |= TCB_ATTACHED|TCB_CLONE_THREAD|TCB_CLONE_DETACHED|TCB_FOLLOWFORK;
                                                tcbtab[c]->nchildren++;
                                                tcbtab[c]->nclone_threads++;
                                                tcbtab[c]->nclone_detached++;
@@ -688,6 +692,33 @@ struct tcb *tcp;
        return;
 }
 
+int
+expand_tcbtab()
+{
+       /* Allocate some more TCBs and expand the table.
+          We don't want to relocate the TCBs because our
+          callers have pointers and it would be a pain.
+          So tcbtab is a table of pointers.  Since we never
+          free the TCBs, we allocate a single chunk of many.  */
+       struct tcb **newtab = (struct tcb **)
+               realloc(tcbtab, 2 * tcbtabsize * sizeof tcbtab[0]);
+       struct tcb *newtcbs = (struct tcb *) calloc(tcbtabsize,
+                                                   sizeof *newtcbs);
+       int i;
+       if (newtab == NULL || newtcbs == NULL) {
+               if (newtab != NULL)
+                       free(newtab);
+               return 1;
+       }
+       for (i = tcbtabsize; i < 2 * tcbtabsize; ++i)
+               newtab[i] = &newtcbs[i - tcbtabsize];
+       tcbtabsize *= 2;
+       tcbtab = newtab;
+
+       return 0;
+}
+
+
 struct tcb *
 alloctcb(pid)
 int pid;