From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2205) id 96C533858D1E; Thu, 22 Feb 2024 10:35:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 96C533858D1E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1708598133; bh=cahGkekShG+ukljYHcnj26h8DZzaVfvZvJ4dnhtvNLA=; h=From:To:Subject:Date:From; b=mWr74QMAMctsp8a4JkV8Ui1XGKrFJwc10e5WRp6iGO7nwQC9tlkr41gibVe1b4pQ5 +wc62mU6GEQ3QcXo72Q4LBVq6b7U0lxY2uUp/FjqX1cgUv0Q/JBgOUNULlbXpoT+cZ DeO4jIbWeP5z/G7oPjJvi+zo/MIkSuEkvZQkBiIo= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom de Vries To: gdb-cvs@sourceware.org Subject: [binutils-gdb] [gdb/dap] Factor out thread_log X-Act-Checkin: binutils-gdb X-Git-Author: Tom de Vries X-Git-Refname: refs/heads/master X-Git-Oldrev: 852784a93664e59be090a518e6d83464bcc0cf00 X-Git-Newrev: 67cf0bd885e3862fb77de0039208d39cc89dba91 Message-Id: <20240222103533.96C533858D1E@sourceware.org> Date: Thu, 22 Feb 2024 10:35:33 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D67cf0bd885e3= 862fb77de0039208d39cc89dba91 commit 67cf0bd885e3862fb77de0039208d39cc89dba91 Author: Tom de Vries Date: Thu Feb 22 11:35:26 2024 +0100 [gdb/dap] Factor out thread_log =20 In thread_wrapper I used a style where a message is prefixed with the t= hread name. =20 Factor this out into a new function thread_log. =20 Also treat the GDB main thread special, because it's usual name is Main= Thread: ... MainThread: ... which is the default name assigned by python, so instead use the more explicit: ... GDB main: ... =20 Tested on aarch64-linux. =20 Approved-By: Tom Tromey Diff: --- 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/sta= rtup.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=3D()): correctly blocked.""" =20 def thread_wrapper(*args): - thread_name =3D threading.current_thread().name # Catch any exception, and log it. If we let it escape here, it'l= l 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=3D()): target(*args) except Exception as err: err_string =3D "%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") =20 result =3D gdb.Thread(name=3Dname, target=3Dthread_wrapper, args=3Darg= s, daemon=3DTrue) result.start() @@ -178,6 +177,16 @@ def log(something, level=3DLogLevel.DEFAULT): dap_log.log_file.flush() =20 =20 +def thread_log(something, level=3DLogLevel.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 =3D "GDB main" + else: + thread_name =3D threading.current_thread().name + log(thread_name + ": " + something, level) + + def log_stack(level=3DLogLevel.DEFAULT): """Log a stack trace to the log file, if logging is enabled.""" with dap_log.lock: