]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Ensure vgdb gets the nr of threads from Valgrind via shared memory,
authorPhilippe Waroquiers <philippe.waroquiers@skynet.be>
Mon, 9 Feb 2015 21:30:58 +0000 (21:30 +0000)
committerPhilippe Waroquiers <philippe.waroquiers@skynet.be>
Mon, 9 Feb 2015 21:30:58 +0000 (21:30 +0000)
rather than using a compile time constant.
This is in preparation for a future change by Florian, to have
the max nr of threads specifiable at startup via a clo

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14924

coregrind/m_gdbserver/remote-utils.c
coregrind/pub_core_gdbserver.h
coregrind/vgdb-invoker-ptrace.c

index 1cdb49179bd356dcd2c6f56e7a4b156af0425987..a633c2bd6120248ab92b6b5327b2461eeba06b9f 100644 (file)
@@ -311,7 +311,7 @@ void remote_open (const HChar *name)
    int len;
    VgdbShared vgdbinit = 
       {0, 0, (Addr) VG_(invoke_gdbserver),
-       (Addr) VG_(threads), sizeof(ThreadState), 
+       (Addr) VG_(threads), VG_N_THREADS, sizeof(ThreadState), 
        offsetof(ThreadState, status),
        offsetof(ThreadState, os_state) + offsetof(ThreadOSstate, lwpid),
        0};
index 5dd2d843805c0d5f9ecbc5e24bd32c1b3b88660f..c7bcd973f638ecd33171fccc76ffda918ca504d2 100644 (file)
@@ -190,6 +190,7 @@ typedef
       // address of VG_(threads) and various sizes
       // and offset needed by vgdb.
       Addr32 threads;
+      int vg_n_threads;
       int sizeof_ThreadState;
       int offset_status;
       int offset_lwpid;
@@ -208,6 +209,7 @@ typedef
       Addr64 invoke_gdbserver;
 
       Addr64 threads;
+      int vg_n_threads;
       int sizeof_ThreadState;
       int offset_status;
       int offset_lwpid;
index bccf9571d71631707673e36e6acd8bf7a2191024..df9e232180abeb82fa8cd34135abced37f681b23 100644 (file)
@@ -194,7 +194,8 @@ typedef struct {
    Int lwpid;
 }
 VgdbThreadState;
-static VgdbThreadState vgdb_threads[VG_N_THREADS];
+static VgdbThreadState *vgdb_threads;
+static int vg_n_threads;
 
 static const
 HChar* name_of_ThreadStatus ( ThreadStatus status )
@@ -393,12 +394,14 @@ Bool acquire_and_suspend_threads (pid_t pid)
 
    if (shared32 != NULL) {
       vgt = shared32->threads;
+      vg_n_threads = shared32->vg_n_threads;
       sz_tst = shared32->sizeof_ThreadState;
       off_status = shared32->offset_status;
       off_lwpid = shared32->offset_lwpid;
    }
    else if (shared64 != NULL) {
       vgt = shared64->threads;
+      vg_n_threads = shared64->vg_n_threads;
       sz_tst = shared64->sizeof_ThreadState;
       off_status = shared64->offset_status;
       off_lwpid = shared64->offset_lwpid;
@@ -406,8 +409,11 @@ Bool acquire_and_suspend_threads (pid_t pid)
       assert (0);
    }
 
+   vgdb_threads = vmalloc(vg_n_threads * sizeof vgdb_threads[0]);
+
    /* note: the entry 0 is unused */
-   for (i = 1; i < VG_N_THREADS; i++) {
+   DEBUG(1, "examining thread entries from tid 1 to tid %d\n", vg_n_threads-1);
+   for (i = 1; i < vg_n_threads; i++) {
       vgt += sz_tst;
       rw = ptrace_read_memory(pid, vgt+off_status,
                               &(vgdb_threads[i].status),
@@ -474,7 +480,7 @@ void detach_from_all_threads (pid_t pid)
    Bool pid_found = False;
 
    /* detach from all the threads  */
-   for (i = 1; i < VG_N_THREADS; i++) {
+   for (i = 1; i < vg_n_threads; i++) {
       if (vgdb_threads[i].status != VgTs_Empty) {
          if (vgdb_threads[i].status == VgTs_Init
              && vgdb_threads[i].lwpid == 0) {
@@ -500,6 +506,8 @@ void detach_from_all_threads (pid_t pid)
       }
    }
 
+   free (vgdb_threads);
+
    if (!pid_found && pid) {
       /* No threads are live. Process is busy stopping.
          We need to detach from pid explicitely. */