Skip to content

Commit 54c27b6

Browse files
committed
Fix bugs
1 parent 5ab45ed commit 54c27b6

1 file changed

Lines changed: 49 additions & 28 deletions

File tree

tools/cbextension.py

Lines changed: 49 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@
1111
cb_notify_url = 'http://localhost:20829/api/v1/event/gdb/'
1212

1313

14-
def cb_post_event(runner):
15-
if not cb_lock.acquire(timeout=1.0):
16-
return None
17-
runner()
18-
cb_lock.release()
14+
def cb_post_event(runner, pk=None):
15+
if cb_lock.acquire(timeout=1.0):
16+
runner()
17+
cb_lock.release()
18+
elif pk is not None:
19+
cb_notify_event({
20+
'pk': pk,
21+
'error': 'Timeout'
22+
})
1923

2024

2125
def cb_execmd(*cmdlist):
@@ -67,13 +71,13 @@ def _runner():
6771
cb_post_event(_runner)
6872

6973

70-
def cb_prog_cmd_async(pk, cmd, arg='', thread='$_thread'):
74+
def cb_prog_cmd_async(pk, cmd, arg='', thread=None):
7175
# run / step / stepi / next / nexti / continue / until / finish &
72-
cmdstr = 'thread apply %s -s %s %s &' % (thread, cmd, arg)
76+
cmdlist = [] if thread is None else ['thread apply', thread, '-s']
77+
cmdlist.extend([cmd, arg, '&'])
7378

7479
def _runner():
75-
result = gdb.execute(cmdstr, False, True)
76-
gdb.flush()
80+
result = gdb.execute(' '.join(cmdlist), False, True)
7781
cb_notify_event({
7882
'pk': pk,
7983
'result': result
@@ -82,7 +86,7 @@ def _runner():
8286
cb_post_event(_runner)
8387

8488

85-
def cb_prog_cmd(pk, cmd, arg='', thread='$_gthread', frame='0'):
89+
def cb_prog_cmd(pk, cmd, arg='', thread=None, frame=None):
8690
# -stack-list-variables --thread 1 --frame 0 --all-values
8791
# ^done,variables=[{name="x",value="11"},{name="s",value="{a = 1, b = 2}"}]
8892

@@ -139,13 +143,15 @@ def cb_prog_cmd(pk, cmd, arg='', thread='$_gthread', frame='0'):
139143
# -break-enable
140144
# -break-watch
141145

142-
cmdstr = ' '.join(['interpreter-exec mi', '"', cmd,
143-
'--thread', thread, '--frame', frame, arg,
144-
'"']
146+
cmdlist = ['interpreter-exec mi', '"', cmd]
147+
if thread is not None:
148+
cmdlist.extend(['--thread', thread])
149+
if frame is not None:
150+
cmdlist.extend(['--frame', frame])
151+
cmdlist.extend([arg, '"'])
145152

146153
def _runner():
147-
result = gdb.execute(cmdstr, False, True)
148-
gdb.flush()
154+
result = gdb.execute(' '.join(cmdlist), False, True)
149155
cb_notify_event({
150156
'pk': pk,
151157
'result': result
@@ -175,30 +181,45 @@ def cb_exited_handler(event):
175181

176182
def cb_new_thread_handler(event):
177183
thread = event.inferior_thread
178-
cb_notify_event({
179-
'inferior': thread.inferior.num,
180-
'thread': thread.num,
181-
'gthread': thread.global_num,
182-
'state': 'new',
183-
})
184+
if isinstance(thread, gdb.Inferior):
185+
cb_notify_event({
186+
'inferior': thread.num,
187+
'state': 'new',
188+
})
189+
else:
190+
cb_notify_event({
191+
'inferior': thread.inferior.num,
192+
'thread': thread.num,
193+
'gthread': thread.global_num,
194+
'state': 'new',
195+
})
184196

185197

186198
def cb_stop_handler(event):
187199
thread = event.inferior_thread
200+
gdb.write('stop_handler: %s' % type(thread))
188201
if hasattr(event, 'breakpoints'):
189202
reason = [(bp.thread, bp.number, bp.type, bp.location)
190203
for bp in event.breakpoints]
191204
elif hasattr(event, 'stop_signal'):
192205
reason = event.stop_signal
193206
else:
194207
reason = ''
195-
cb_notify_event({
196-
'inferior': thread.inferior.num,
197-
'thread': thread.num,
198-
'gthread': thread.global_num,
199-
'state': 'exited' if thread.is_exited() else 'stopped',
200-
'reason': reason
201-
})
208+
209+
if isinstance(thread, gdb.Inferior):
210+
cb_notify_event({
211+
'inferior': thread.num,
212+
'state': 'exited' if thread.is_exited() else 'stopped',
213+
'reason': reason
214+
})
215+
else:
216+
cb_notify_event({
217+
'inferior': thread.inferior.num,
218+
'thread': thread.num,
219+
'gthread': thread.global_num,
220+
'state': 'exited' if thread.is_exited() else 'stopped',
221+
'reason': reason
222+
})
202223

203224

204225
def cb_cont_handler(event):

0 commit comments

Comments
 (0)