From 025b320e1036168ef2862b3db27e24a42f33095e Mon Sep 17 00:00:00 2001 From: Philippe Waroquiers Date: Mon, 9 Feb 2015 21:30:58 +0000 Subject: [PATCH] Ensure vgdb gets the nr of threads from Valgrind via shared memory, 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 | 2 +- coregrind/pub_core_gdbserver.h | 2 ++ coregrind/vgdb-invoker-ptrace.c | 14 +++++++++++--- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/coregrind/m_gdbserver/remote-utils.c b/coregrind/m_gdbserver/remote-utils.c index 1cdb49179b..a633c2bd61 100644 --- a/coregrind/m_gdbserver/remote-utils.c +++ b/coregrind/m_gdbserver/remote-utils.c @@ -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}; diff --git a/coregrind/pub_core_gdbserver.h b/coregrind/pub_core_gdbserver.h index 5dd2d84380..c7bcd973f6 100644 --- a/coregrind/pub_core_gdbserver.h +++ b/coregrind/pub_core_gdbserver.h @@ -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; diff --git a/coregrind/vgdb-invoker-ptrace.c b/coregrind/vgdb-invoker-ptrace.c index bccf9571d7..df9e232180 100644 --- a/coregrind/vgdb-invoker-ptrace.c +++ b/coregrind/vgdb-invoker-ptrace.c @@ -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. */ -- 2.47.3