开发者

Mapping thread id from top to gdb

I am using top to see the thread wise cpu usage using

  top -H -p `pgrep app.out`

It is showing some pid for each thread like

4015
4016

I had attached gdb to the application using gdb attach command. Now I want to switch to thread 4015 which is showing inside top o/p.

How can I do that ?

If I fire thread 4015 it is showing no thread开发者_如何学Go . as I need to give thread id in gdb.

So how can I map top thread id to gdb thread id ?


You should be able to match the LWP displayed in GDB with the top information:

according to my quick tests with Firefox, you can see that in your top -H -p:

PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
6492 kevin     20   0 1242m 386m  31m S  0.3  4.9   0:09.00 firefox
6470 kevin     20   0 1242m 386m  31m S  5.7  4.9   5:04.89 firefox

and that in GDB info threads:

 22   Thread 0x7fe3d2393700 (LWP 6492) "firefox" pthread_cond_timedwait...
...
* 1   Thread 0x7fe3dd868740 (LWP 6470) "firefox" __GI___poll ()...

EDIT: just for you in exclusivity, here is a brand new commands for gdb: lwp_to_id <lwp>:

import gdb
class lwp_to_id (gdb.Command):
    def __init__(self):
        gdb.Command.__init__(self, "lwp_to_id", gdb.COMMAND_OBSCURE)

    def invoke(self, args, from_tty):
        lwp = int(args)
        for thr in gdb.selected_inferior().threads():
            if thr.ptid[1] == lwp:
                print "LWP %s maps to thread #%d" % (lwp, thr.num)
                return
        else:
            print "LWP %s doesn't match any threads in the current inferior." % lwp
lwp_to_id()

(working at least on the trunk version of GDB, not sure about the official releases !


Do a

ps xjf 

This will give you a tree of all processes with their pid and parent pid.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜