From: Vinay Sridhar <vinay@linux.vnet.ibm.com>
To: gdb-patches@sourceware.org
Cc: luisgpm@linux.vnet.ibm.com
Subject: [RFC][Patch] Fix gdb failure to access tls data for parent thread
Date: Fri, 09 Jan 2009 08:47:00 -0000 [thread overview]
Message-ID: <200901091416.10563.vinay@linux.vnet.ibm.com> (raw)
Hello,
While using gdb to access tls data for a parent thread of a multi-threaded program, we get the following error :
"Cannot find thread-local storage for LWP 11884, executable file /home/test/test
TLS not supported on this target"
This can be recreated as follows :
$ cat test.c
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <omp.h>
__thread int thread;
void initTlsData() {
printf("Initialising %d\n",thread);
}
int main(int argc, char *argv[]) {
#pragma omp parallel
{
thread = omp_get_thread_num();
initTlsData();
}
return(0);
}
0. export "OMP_NUM_THREADS=5" // 5 for example
1. gdb ./test
2. break initTlsData
3. run
4. thread 1 // Switch to the parent thread
5. print thread
The above stated error occurs.
The reason for this is gdb does not fill in the private field of the thread_info structure of the
parent thread. The below patch sets up this private field before the child
threads are added to gdb's list.
I'm not sure if the patch below breaks any existing behaviour. I'm also not sure if this is the right way to go about this.
This is purely RFC.
If there's a better way of doing this please let me know.
--- linux-thread-db.c.old 2008-12-11 14:19:12.000000000 -0500
+++ linux-thread-db.c 2008-12-30 00:26:52.000000000 -0500
@@ -879,9 +879,33 @@ check_event (ptid_t ptid)
while (loop);
}
+void set_private_data (ptid_t ptid)
+{
+ td_thrhandle_t th;
+ struct thread_info *thread_info;
+ td_thrinfo_t ti;
+ td_err_e err;
+ struct private_thread_info *private;
+
+ private = xmalloc (sizeof (struct private_thread_info));
+ memset (private, 0, sizeof (struct private_thread_info));
+
+ err = td_ta_map_lwp2thr_p (thread_agent, GET_LWP (ptid), &th);
+ thread_get_info_callback (&th, &thread_info);
+ err = td_thr_get_info_p (&th, &ti);
+
+ if (ti.ti_tid == 0)
+ err = td_thr_event_enable_p (&th, 1);
+
+ private->th = th;
+ private->tid = ti.ti_tid;
+ thread_info->private = private;
+}
+
static ptid_t
thread_db_wait (ptid_t ptid, struct target_waitstatus *ourstatus)
{
+ struct thread_info *tp;
ptid = target_beneath->to_wait (ptid, ourstatus);
if (ourstatus->kind == TARGET_WAITKIND_IGNORE)
@@ -900,6 +924,13 @@ thread_db_wait (ptid_t ptid, struct targ
return ptid;
}
+ tp = find_thread_pid (ptid);
+
+ if (!tp->private)
+ set_private_data(ptid);
+ else if (tp->private->tid == 0)
+ set_private_data(ptid);
+
/* If we do not know about the main thread yet, this would be a good time to
find it. */
if (ourstatus->kind == TARGET_WAITKIND_STOPPED && !have_threads ())
Regards,
VInay
---
Vinay Sridhar,
Linux Technology Center,
IBM ISTL,
Bangalore, India
next reply other threads:[~2009-01-09 8:47 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-01-09 8:47 Vinay Sridhar [this message]
2009-02-04 13:29 ` Daniel Jacobowitz
2009-02-11 8:33 ` Vinay Sridhar
2009-02-11 15:53 ` Daniel Jacobowitz
2009-02-12 5:45 ` Vinay Sridhar
2009-02-16 3:19 ` Daniel Jacobowitz
2009-02-16 15:04 ` Vinay Sridhar
2009-02-16 15:20 ` Daniel Jacobowitz
2009-02-17 7:01 ` Vinay Sridhar
2009-02-17 16:20 ` Daniel Jacobowitz
2009-02-20 8:31 ` Vinay Sridhar
2009-02-23 0:17 ` Daniel Jacobowitz
2009-02-23 9:20 ` Vinay Sridhar
2009-02-23 16:10 ` Daniel Jacobowitz
2009-02-24 7:11 ` Pedro Alves
2009-02-24 13:33 ` Vinay Sridhar
2009-02-24 13:39 ` Vinay Sridhar
2009-02-24 17:16 ` Daniel Jacobowitz
2009-02-24 18:52 ` Pedro Alves
2009-02-24 18:58 ` Pedro Alves
2009-02-25 18:28 ` Vinay Sridhar
2009-02-27 21:49 ` Pedro Alves
2009-02-24 10:57 ` Vinay Sridhar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200901091416.10563.vinay@linux.vnet.ibm.com \
--to=vinay@linux.vnet.ibm.com \
--cc=gdb-patches@sourceware.org \
--cc=luisgpm@linux.vnet.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox