From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@adacore.com>
Subject: [PATCH 6/9] Share handle_ms_vc_exception with gdbserver
Date: Wed, 13 Apr 2022 13:17:53 -0600 [thread overview]
Message-ID: <20220413191756.1146768-7-tromey@adacore.com> (raw)
In-Reply-To: <20220413191756.1146768-1-tromey@adacore.com>
Currently, gdb's native Windows target implements the exception-based
approach for setting thread names, but gdbserver does not. This patch
moves handle_ms_vc_exception to the shared nat/windows-nat.c code, as
preparation for adding this support to gdbserver.
---
gdb/nat/windows-nat.c | 40 ++++++++++++++++++++++++++++++++++++++++
gdb/nat/windows-nat.h | 20 +++++++++-----------
gdb/windows-nat.c | 40 ----------------------------------------
gdbserver/win32-low.cc | 9 ---------
4 files changed, 49 insertions(+), 60 deletions(-)
diff --git a/gdb/nat/windows-nat.c b/gdb/nat/windows-nat.c
index e6d73485c24..9defbd71d14 100644
--- a/gdb/nat/windows-nat.c
+++ b/gdb/nat/windows-nat.c
@@ -19,6 +19,7 @@
#include "gdbsupport/common-defs.h"
#include "nat/windows-nat.h"
#include "gdbsupport/common-debug.h"
+#include "target/target.h"
#ifdef __CYGWIN__
#define __USEWIDE
@@ -162,6 +163,45 @@ get_image_name (HANDLE h, void *address, int unicode)
return buf;
}
+/* See nat/windows-nat.h. */
+
+bool
+windows_process_info::handle_ms_vc_exception (const EXCEPTION_RECORD *rec)
+{
+ if (rec->NumberParameters >= 3
+ && (rec->ExceptionInformation[0] & 0xffffffff) == 0x1000)
+ {
+ DWORD named_thread_id;
+ windows_thread_info *named_thread;
+ CORE_ADDR thread_name_target;
+
+ thread_name_target = rec->ExceptionInformation[1];
+ named_thread_id = (DWORD) (0xffffffff & rec->ExceptionInformation[2]);
+
+ if (named_thread_id == (DWORD) -1)
+ named_thread_id = current_event.dwThreadId;
+
+ named_thread = thread_rec (ptid_t (current_event.dwProcessId,
+ named_thread_id, 0),
+ DONT_INVALIDATE_CONTEXT);
+ if (named_thread != NULL)
+ {
+ int thread_name_len;
+ gdb::unique_xmalloc_ptr<char> thread_name
+ = target_read_string (thread_name_target, 1025, &thread_name_len);
+ if (thread_name_len > 0)
+ {
+ thread_name.get ()[thread_name_len - 1] = '\0';
+ named_thread->name = std::move (thread_name);
+ }
+ }
+
+ return true;
+ }
+
+ return false;
+}
+
/* The exception thrown by a program to tell the debugger the name of
a thread. The exception record contains an ID of a thread and a
name to give it. This exception has no documented name, but MSDN
diff --git a/gdb/nat/windows-nat.h b/gdb/nat/windows-nat.h
index 7f76ba0e58f..522e267176d 100644
--- a/gdb/nat/windows-nat.h
+++ b/gdb/nat/windows-nat.h
@@ -92,7 +92,7 @@ struct windows_thread_info
adjustments if the registers are read multiple times. */
bool pc_adjusted = false;
- /* The name of the thread, allocated by xmalloc. */
+ /* The name of the thread. */
gdb::unique_xmalloc_ptr<char> name;
};
@@ -213,16 +213,6 @@ struct windows_process_info
void handle_unload_dll ();
- /* Handle MS_VC_EXCEPTION when processing a stop. MS_VC_EXCEPTION is
- somewhat undocumented but is used to tell the debugger the name of
- a thread.
-
- Return true if the exception was handled; return false otherwise.
-
- This function must be supplied by the embedding application. */
-
- bool handle_ms_vc_exception (const EXCEPTION_RECORD *rec);
-
/* When EXCEPTION_ACCESS_VIOLATION is processed, we give the embedding
application a chance to change it to be considered "unhandled".
This function must be supplied by the embedding application. If it
@@ -256,6 +246,14 @@ struct windows_process_info
private:
+ /* Handle MS_VC_EXCEPTION when processing a stop. MS_VC_EXCEPTION is
+ somewhat undocumented but is used to tell the debugger the name of
+ a thread.
+
+ Return true if the exception was handled; return false otherwise. */
+
+ bool handle_ms_vc_exception (const EXCEPTION_RECORD *rec);
+
/* Iterate over all DLLs currently mapped by our inferior, looking for
a DLL which is loaded at LOAD_ADDR. If found, add the DLL to our
list of solibs; otherwise do nothing. LOAD_ADDR NULL means add all
diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index 646ddda7328..581eb47e7ba 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -1054,46 +1054,6 @@ display_selectors (const char * args, int from_tty)
/* See nat/windows-nat.h. */
-bool
-windows_nat::windows_process_info::handle_ms_vc_exception
- (const EXCEPTION_RECORD *rec)
-{
- if (rec->NumberParameters >= 3
- && (rec->ExceptionInformation[0] & 0xffffffff) == 0x1000)
- {
- DWORD named_thread_id;
- windows_thread_info *named_thread;
- CORE_ADDR thread_name_target;
-
- thread_name_target = rec->ExceptionInformation[1];
- named_thread_id = (DWORD) (0xffffffff & rec->ExceptionInformation[2]);
-
- if (named_thread_id == (DWORD) -1)
- named_thread_id = current_event.dwThreadId;
-
- named_thread = thread_rec (ptid_t (current_event.dwProcessId,
- named_thread_id, 0),
- DONT_INVALIDATE_CONTEXT);
- if (named_thread != NULL)
- {
- int thread_name_len;
- gdb::unique_xmalloc_ptr<char> thread_name
- = target_read_string (thread_name_target, 1025, &thread_name_len);
- if (thread_name_len > 0)
- {
- thread_name.get ()[thread_name_len - 1] = '\0';
- named_thread->name = std::move (thread_name);
- }
- }
-
- return true;
- }
-
- return false;
-}
-
-/* See nat/windows-nat.h. */
-
bool
windows_nat::windows_process_info::handle_access_violation
(const EXCEPTION_RECORD *rec)
diff --git a/gdbserver/win32-low.cc b/gdbserver/win32-low.cc
index 8437c69e1cc..8fde3e95b2d 100644
--- a/gdbserver/win32-low.cc
+++ b/gdbserver/win32-low.cc
@@ -1041,15 +1041,6 @@ fake_breakpoint_event (void)
/* See nat/windows-nat.h. */
-bool
-windows_nat::windows_process_info::handle_ms_vc_exception
- (const EXCEPTION_RECORD *rec)
-{
- return false;
-}
-
-/* See nat/windows-nat.h. */
-
bool
windows_nat::windows_process_info::handle_access_violation
(const EXCEPTION_RECORD *rec)
--
2.34.1
next prev parent reply other threads:[~2022-04-13 19:18 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-13 19:17 [PATCH 0/9] Windows thread names Tom Tromey
2022-04-13 19:17 ` [PATCH 1/9] Fix possible Cygwin build problem Tom Tromey
2022-05-21 11:18 ` Jon Turney
2022-05-21 12:31 ` Eli Zaretskii
2022-05-26 17:00 ` Tom Tromey
2022-05-26 19:04 ` Eli Zaretskii
2022-06-02 14:12 ` Jon Turney
2022-06-02 16:04 ` Eli Zaretskii
2022-04-13 19:17 ` [PATCH 2/9] Don't call QUIT in read_string Tom Tromey
2022-04-13 19:17 ` [PATCH 3/9] Rename read_string Tom Tromey
2022-04-13 19:17 ` [PATCH 4/9] Remove the byte order parameter to target_read_string Tom Tromey
2022-04-13 19:17 ` [PATCH 5/9] Move target_read_string to target/target.c Tom Tromey
2022-04-13 19:17 ` Tom Tromey [this message]
2022-04-13 19:17 ` [PATCH 7/9] Implement thread_name for gdbserver Tom Tromey
2022-04-13 19:17 ` [PATCH 8/9] Set the worker thread name on Windows Tom Tromey
2022-04-13 19:17 ` [PATCH 9/9] Use GetThreadDescription " Tom Tromey
2022-04-13 19:33 ` Eli Zaretskii
2022-04-14 5:26 ` Eli Zaretskii
2022-04-14 13:17 ` Tom Tromey
2022-04-14 13:51 ` Eli Zaretskii
2022-04-14 18:20 ` Tom Tromey
2022-04-14 18:18 ` Tom Tromey
2022-04-14 13:58 ` [PATCH 0/9] Windows thread names Pedro Alves
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=20220413191756.1146768-7-tromey@adacore.com \
--to=tromey@adacore.com \
--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).