27_gdb_thread = threading.current_thread()
35 """Start a new thread, invoking TARGET with *ARGS there.
36 This is a helper function that ensures that any GDB signals are
38 result =
gdb.Thread(name=name, target=target, args=args, daemon=
True)
43 """Start the DAP thread and invoke TARGET there."""
44 exec_and_log(
"set breakpoint pending on")
48 def really_start_dap():
50 _dap_thread = threading.current_thread()
53 start_thread(
"DAP", really_start_dap)
57 """A decorator that asserts that FUNC must be run in the GDB thread."""
59 @functools.wraps(func)
60 def ensure_gdb_thread(*args, **kwargs):
61 assert threading.current_thread()
is _gdb_thread
62 return func(*args, **kwargs)
64 return ensure_gdb_thread
68 """A decorator that asserts that FUNC must be run in the DAP thread."""
70 @functools.wraps(func)
71 def ensure_dap_thread(*args, **kwargs):
72 assert threading.current_thread()
is _dap_thread
73 return func(*args, **kwargs)
75 return ensure_dap_thread
79 """Whether DAP logging is enabled."""
81 set_doc =
"Set the DAP logging status."
82 show_doc =
"Show the DAP logging status."
88 "debug dap-log-file", gdb.COMMAND_MAINTENANCE, gdb.PARAM_OPTIONAL_FILENAME
97 if self.
value is not None:
106 """Log SOMETHING to the log file, if logging is enabled."""
107 if dap_log.log_file
is not None:
108 print(something, file=dap_log.log_file)
109 dap_log.log_file.flush()
113 """Log a stack trace to the log file, if logging is enabled."""
114 if dap_log.log_file
is not None:
115 traceback.print_exc(file=dap_log.log_file)
120 """Execute the gdb command CMD.
121 If logging is enabled, log the command and its output."""
124 output = gdb.execute(cmd, from_tty=
True, to_string=
True)
132 """A simple class that can invoke a gdb command."""
140 exec_and_log(self.
cmd)
144 """Send CMD to the gdb thread.
145 CMD can be either a function or a string.
146 If it is a string, it is passed to gdb.execute."""
147 if isinstance(cmd, str):
153 """Send FN to the gdb thread and return its result.
154 If FN is a string, it is passed to gdb.execute and None is
155 returned as the result.
156 If FN throws an exception, this function will throw the
157 same exception in the calling thread.
159 if isinstance(fn, str):
161 if sys.version_info[0] == 3
and sys.version_info[1] <= 6:
162 result_q = queue.Queue()
164 result_q = queue.SimpleQueue()
170 except Exception
as e:
175 if isinstance(val, Exception):
send_gdb_with_response(fn)
start_thread(name, target, args=())
void(* func)(remote_target *remote, char *)