correctly blocked."""
def thread_wrapper(*args):
- thread_name = threading.current_thread().name
# Catch any exception, and log it. If we let it escape here, it'll be
# printed in gdb_stderr, which is not safe to access from anywhere but
# gdb's main thread.
target(*args)
except Exception as err:
err_string = "%s, %s" % (err, type(err))
- log(thread_name + ": caught exception: " + err_string)
+ thread_log("caught exception: " + err_string)
log_stack()
finally:
# Log when a thread terminates.
- log(thread_name + ": terminating")
+ thread_log("terminating")
result = gdb.Thread(name=name, target=thread_wrapper, args=args, daemon=True)
result.start()
dap_log.log_file.flush()
+def thread_log(something, level=LogLevel.DEFAULT):
+ """Log SOMETHING to the log file, if logging is enabled, and prefix
+ the thread name."""
+ if threading.current_thread() is _gdb_thread:
+ thread_name = "GDB main"
+ else:
+ thread_name = threading.current_thread().name
+ log(thread_name + ": " + something, level)
+
+
def log_stack(level=LogLevel.DEFAULT):
"""Log a stack trace to the log file, if logging is enabled."""
with dap_log.lock: