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 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/coregrind/m_gdbserver/remote-utils.c b/coregrind/m_gdbserver/remote-utils.c
index 1cdb491..a633c2b 100644
--- a/coregrind/m_gdbserver/remote-utils.c
+++ b/coregrind/m_gdbserver/remote-utils.c
@@ -311,7 +311,7 @@
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 5dd2d84..c7bcd97 100644
--- a/coregrind/pub_core_gdbserver.h
+++ b/coregrind/pub_core_gdbserver.h
@@ -190,6 +190,7 @@
// 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 @@
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 bccf957..df9e232 100644
--- a/coregrind/vgdb-invoker-ptrace.c
+++ b/coregrind/vgdb-invoker-ptrace.c
@@ -194,7 +194,8 @@
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 @@
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 @@
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 @@
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 @@
}
}
+ free (vgdb_threads);
+
if (!pid_found && pid) {
/* No threads are live. Process is busy stopping.
We need to detach from pid explicitely. */