19from .server
import send_event
20from .startup
import exec_and_log, in_gdb_thread, log
21from .modules
import is_module, make_module
28inferior_running =
False
33 global inferior_running
34 inferior_running =
False
36 if hasattr(event,
"exit_code"):
37 code = event.exit_code
44 send_event(
"terminated")
48def thread_event(event, reason):
53 "threadId": event.inferior_thread.global_num,
59def _new_thread(event):
60 global inferior_running
61 inferior_running =
True
62 thread_event(event,
"started")
66def _thread_exited(event):
67 thread_event(event,
"exited")
71def _new_objfile(event):
72 if is_module(event.new_objfile):
77 "module": make_module(event.new_objfile),
83def _objfile_removed(event):
84 if is_module(event.objfile):
89 "module": make_module(event.objfile),
99 global inferior_running
100 inferior_running =
True
101 global _suppress_cont
103 log(
"_suppress_cont case")
104 _suppress_cont =
False
109 "threadId": gdb.selected_thread().global_num,
110 "allThreadsContinued":
True,
115class StopKinds(enum.Enum):
118 BREAKPOINT =
"breakpoint"
120 EXCEPTION =
"exception"
127def exec_and_expect_stop(cmd, reason):
128 """Indicate that a stop is expected, then execute CMD"""
129 global _expected_stop
130 _expected_stop = reason
131 if reason != StopKinds.PAUSE:
132 global _suppress_cont
133 _suppress_cont =
True
140 global inferior_running
141 inferior_running =
False
142 log(
"entering _on_stop: " + repr(event))
143 global _expected_stop
145 "threadId": gdb.selected_thread().global_num,
146 "allThreadsStopped":
True,
148 if isinstance(event, gdb.BreakpointEvent):
150 _expected_stop = StopKinds.BREAKPOINT
151 obj[
"hitBreakpointIds"] = [x.number
for x
in event.breakpoints]
152 elif _expected_stop
is None:
154 _expected_stop = StopKinds.EXCEPTION
155 obj[
"reason"] = _expected_stop.value
156 _expected_stop =
None
157 send_event(
"stopped", obj)
165_infcall_was_running =
False
169def _on_inferior_call(event):
170 global _infcall_was_running
171 if isinstance(event, gdb.InferiorCallPreEvent):
172 _infcall_was_running = inferior_running
173 if not _infcall_was_running:
176 if not _infcall_was_running:
180gdb.events.stop.connect(_on_stop)
181gdb.events.exited.connect(_on_exit)
182gdb.events.new_thread.connect(_new_thread)
183gdb.events.thread_exited.connect(_thread_exited)
184gdb.events.cont.connect(_cont)
185gdb.events.new_objfile.connect(_new_objfile)
186gdb.events.free_objfile.connect(_objfile_removed)
187gdb.events.inferior_call.connect(_on_inferior_call)