This is the mail archive of the
gdb@sourceware.org
mailing list for the GDB project.
Trouble with python API when read std::thread members
- From: Gonzalo Sanchez <gonzalo dot sanchez at tallertechnologies dot com>
- To: gdb at sourceware dot org
- Cc: palves at redhat dot com
- Date: Tue, 12 Apr 2016 18:22:49 -0300
- Subject: Trouble with python API when read std::thread members
- Authentication-results: sourceware.org; auth=none
Hello,
I'm trying to write a gdb pretty-printer for std:thread and I'm having
some problems:
When a new thread is triggered in the app, the following message is shown:
[New Thread 0x7ffff6fd6700 (LWP 15551)]
The first number is the one provided by the std:thread struct (and can
be obtained through the python API):
(pretty-printer script)
class ThreadPrinter(object):
def __init__(self, value):
self.value = value
self.th_id = value['_M_id'] # Inner class
self.thread_id = self.th_id['_M_thread']
print 'Thread system ID: {}'.format(int(self.thread_id))
out:
(gdb) p first
$1 = Thread system ID: 140737337190144
That results are equals, one of them is in hex format.
But when I'm trying to obtain that same value with the functions
provided by python API, I only see the LWP id and can't match it:
(pretty-printer script)
for thread_ in gdb.selected_inferior().threads():
print thread_.ptid
out:
(15547, 15551, 0)
(15547, 15547, 0)
As you can see, the tuple ptid, contains as first element the pid of
the parent process, and the second element is the lwpid of the child
(in the parent both are equal)
Here's my question:
How can I match the ID contained in the std:thread struct with the
numbers returned by the python methods?
I can see that the ptid members are obtained in both cases (python API
and gdb) by the same functions (file ptid.c):
ptid_get_pid (ptid_t ptid);
ptid_get_lwp (ptid_t ptid);
ptid_get_tid (ptid_t ptid);
But I can't see why the numbers returned by ptid_get_pid(ptid_t ptid)
are different for each case.
Thanks for your answer.
BR,
--
______________________________
Gonzalo SÃnchez
Software Engineer
Taller Technologies Argentina
San Lorenzo 47, 3rd Floor, Office 5
CÃrdoba, Argentina
Phone: +54-351-4217888 / 4218211