public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [PATCH 2/8] [gdb/dap] Factor out thread_log
Date: Mon, 19 Feb 2024 09:23:35 +0100	[thread overview]
Message-ID: <20240219082341.21313-2-tdevries@suse.de> (raw)
In-Reply-To: <20240219082341.21313-1-tdevries@suse.de>

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 | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/gdb/python/lib/gdb/dap/startup.py b/gdb/python/lib/gdb/dap/startup.py
index daaeb28e997..e68c5ba344e 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()
@@ -174,6 +173,14 @@ def log(something, level=LogLevel.DEFAULT):
         dap_log.log_file.flush()
 
 
+def thread_log(something, level=LogLevel.DEFAULT):
+    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."""
     if dap_log.log_file is not None and level <= _log_level.value:
-- 
2.35.3


  reply	other threads:[~2024-02-19  8:23 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-19  8:23 [PATCH 1/8] [gdb/testsuite] Set up dap log file in gdb.dap/type_checker.exp Tom de Vries
2024-02-19  8:23 ` Tom de Vries [this message]
2024-02-20 15:30   ` [PATCH 2/8] [gdb/dap] Factor out thread_log Tom Tromey
2024-02-21 13:30     ` Tom de Vries
2024-02-19  8:23 ` [PATCH 3/8] [gdb/dap] Flush after printing in log_stack Tom de Vries
2024-02-20 15:30   ` Tom Tromey
2024-02-19  8:23 ` [PATCH 4/8] [gdb/dap] Make dap log printing thread-safe Tom de Vries
2024-02-20 15:32   ` Tom Tromey
2024-02-21 13:31     ` Tom de Vries
2024-02-19  8:23 ` [PATCH 5/8] [gdb/dap] Fix race between dap startup and dap log file Tom de Vries
2024-02-20 15:38   ` Tom Tromey
2024-02-19  8:23 ` [PATCH 6/8] [gdb/dap] Don't let dap log string grow indefinitely Tom de Vries
2024-02-20 15:41   ` Tom Tromey
2024-02-21 13:34     ` Tom de Vries
2024-02-19  8:23 ` [PATCH 7/8] [gdb/dap] Join JSON reader and writer threads with DAP thread Tom de Vries
2024-02-20 15:47   ` Tom Tromey
2024-02-20 20:01   ` Tom Tromey
2024-02-21 13:35     ` Tom de Vries
2024-02-19  8:23 ` [PATCH 8/8] [gdb/dap] Fix race between dap exit and gdb exit Tom de Vries
2024-02-20 15:51   ` Tom Tromey
2024-02-21 13:39     ` Tom de Vries
2024-02-20 15:29 ` [PATCH 1/8] [gdb/testsuite] Set up dap log file in gdb.dap/type_checker.exp Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240219082341.21313-2-tdevries@suse.de \
    --to=tdevries@suse.de \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).