public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v2 1/3] [gdb/dap] Factor out thread_log
@ 2024-02-21 13:20 Tom de Vries
  2024-02-21 13:20 ` [PATCH v2 2/3] [gdb/dap] Fix race between dap startup and dap log file Tom de Vries
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Tom de Vries @ 2024-02-21 13:20 UTC (permalink / raw)
  To: gdb-patches

In thread_wrapper I used a style where a message is prefixed with the thread
name.

Factor this out into a new function thread_log.

Also treat the GDB main thread special, because it's usual name is MainThread:
...
MainThread: <msg>
...
which is the default name assigned by python, so instead use the more
explicit:
...
GDB main: <msg>
...

Tested on aarch64-linux.
---
 gdb/python/lib/gdb/dap/startup.py | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/gdb/python/lib/gdb/dap/startup.py b/gdb/python/lib/gdb/dap/startup.py
index 0a42c91e8f4..29fe78ecd53 100644
--- a/gdb/python/lib/gdb/dap/startup.py
+++ b/gdb/python/lib/gdb/dap/startup.py
@@ -64,7 +64,6 @@ def start_thread(name, target, args=()):
     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.
@@ -72,11 +71,11 @@ def start_thread(name, target, args=()):
             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()
@@ -178,6 +177,16 @@ def log(something, level=LogLevel.DEFAULT):
             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:

base-commit: 7c34de9efdb13fff482ed0c4de0dffee1e1880f3
-- 
2.35.3


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-02-22 10:39 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-21 13:20 [PATCH v2 1/3] [gdb/dap] Factor out thread_log Tom de Vries
2024-02-21 13:20 ` [PATCH v2 2/3] [gdb/dap] Fix race between dap startup and dap log file Tom de Vries
2024-02-21 21:09   ` Tom Tromey
2024-02-21 13:20 ` [PATCH v2 3/3] [gdb/dap] Fix race between dap exit and gdb exit Tom de Vries
2024-02-21 21:10   ` Tom Tromey
2024-02-22 10:39     ` Tom de Vries
2024-02-21 21:07 ` [PATCH v2 1/3] [gdb/dap] Factor out thread_log Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).