bthread_frame , select bthread frame by id
| 115 | print(res) |
| 116 | |
| 117 | class BthreadFrameCmd(gdb.Command): |
| 118 | """bthread_frame <id>, select bthread frame by id""" |
| 119 | def __init__(self): |
| 120 | gdb.Command.__init__(self, "bthread_frame", gdb.COMMAND_STACK, gdb.COMPLETE_NONE) |
| 121 | |
| 122 | def invoke(self, arg, tty): |
| 123 | global status |
| 124 | global bthreads |
| 125 | if not status: |
| 126 | print("Not in bthread debug mode") |
| 127 | return |
| 128 | if not arg: |
| 129 | print("bthread_frame <id>, see 'bthread_list'") |
| 130 | return |
| 131 | bthread_id = int(arg) |
| 132 | if bthread_id >= len(bthreads): |
| 133 | print("id {} exceeds max bthread nums {}".format(bthread_id, len(bthreads))) |
| 134 | return |
| 135 | stack = bthreads[bthread_id]["stack"] |
| 136 | if str(stack) == "0x0": |
| 137 | print("this bthread has no stack") |
| 138 | return |
| 139 | context = gdb.parse_and_eval("(*(('bthread::ContextualStack' *){})).context".format(stack)) |
| 140 | rip = gdb.parse_and_eval("*(uint64_t*)({}+7*8)".format(context)) |
| 141 | rbp = gdb.parse_and_eval("*(uint64_t*)({}+6*8)".format(context)) |
| 142 | rsp = gdb.parse_and_eval("{}+8*8".format(context)) |
| 143 | gdb.parse_and_eval("$rip = {}".format(rip)) |
| 144 | gdb.parse_and_eval("$rsp = {}".format(rsp)) |
| 145 | gdb.parse_and_eval("$rbp = {}".format(rbp)) |
| 146 | |
| 147 | class BthreadAllCmd(gdb.Command): |
| 148 | """print all bthread frames""" |