Trouble with python API when read std::thread members

Gonzalo Sanchez <[email protected]>
Newsgroups gmane.comp.gdb.devel
Message-ID <CAD7hSgC-qA1BdtEyu8W1cXsaeXi2O4BM+KtYR38oa=HEz_SyDw@mail.gmail.com>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.