From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id 623163858C2C; Thu, 14 Apr 2022 18:21:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 623163858C2C Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom Tromey To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Share handle_ms_vc_exception with gdbserver X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: b17c7ab3808f5b781537514b28695dafaa29cb28 X-Git-Newrev: 44ac251ad202da57e134f160b6831a56a82a8cf0 Message-Id: <20220414182141.623163858C2C@sourceware.org> Date: Thu, 14 Apr 2022 18:21:41 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Apr 2022 18:21:41 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D44ac251ad202= da57e134f160b6831a56a82a8cf0 commit 44ac251ad202da57e134f160b6831a56a82a8cf0 Author: Tom Tromey Date: Tue Apr 12 14:25:44 2022 -0600 Share handle_ms_vc_exception with gdbserver =20 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. Diff: --- 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 a82aa89b085..9fdef463760 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" =20 #ifdef __CYGWIN__ #define __USEWIDE @@ -162,6 +163,45 @@ get_image_name (HANDLE h, void *address, int unicode) return buf; } =20 +/* See nat/windows-nat.h. */ + +bool +windows_process_info::handle_ms_vc_exception (const EXCEPTION_RECORD *rec) +{ + if (rec->NumberParameters >=3D 3 + && (rec->ExceptionInformation[0] & 0xffffffff) =3D=3D 0x1000) + { + DWORD named_thread_id; + windows_thread_info *named_thread; + CORE_ADDR thread_name_target; + + thread_name_target =3D rec->ExceptionInformation[1]; + named_thread_id =3D (DWORD) (0xffffffff & rec->ExceptionInformation[= 2]); + + if (named_thread_id =3D=3D (DWORD) -1) + named_thread_id =3D current_event.dwThreadId; + + named_thread =3D thread_rec (ptid_t (current_event.dwProcessId, + named_thread_id, 0), + DONT_INVALIDATE_CONTEXT); + if (named_thread !=3D NULL) + { + int thread_name_len; + gdb::unique_xmalloc_ptr thread_name + =3D target_read_string (thread_name_target, 1025, &thread_name_len); + if (thread_name_len > 0) + { + thread_name.get ()[thread_name_len - 1] =3D '\0'; + named_thread->name =3D 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 =3D false; =20 - /* The name of the thread, allocated by xmalloc. */ + /* The name of the thread. */ gdb::unique_xmalloc_ptr name; }; =20 @@ -213,16 +213,6 @@ struct windows_process_info =20 void handle_unload_dll (); =20 - /* 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 =20 private: =20 + /* 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) =20 /* See nat/windows-nat.h. */ =20 -bool -windows_nat::windows_process_info::handle_ms_vc_exception - (const EXCEPTION_RECORD *rec) -{ - if (rec->NumberParameters >=3D 3 - && (rec->ExceptionInformation[0] & 0xffffffff) =3D=3D 0x1000) - { - DWORD named_thread_id; - windows_thread_info *named_thread; - CORE_ADDR thread_name_target; - - thread_name_target =3D rec->ExceptionInformation[1]; - named_thread_id =3D (DWORD) (0xffffffff & rec->ExceptionInformation[= 2]); - - if (named_thread_id =3D=3D (DWORD) -1) - named_thread_id =3D current_event.dwThreadId; - - named_thread =3D thread_rec (ptid_t (current_event.dwProcessId, - named_thread_id, 0), - DONT_INVALIDATE_CONTEXT); - if (named_thread !=3D NULL) - { - int thread_name_len; - gdb::unique_xmalloc_ptr thread_name - =3D target_read_string (thread_name_target, 1025, &thread_name_len); - if (thread_name_len > 0) - { - thread_name.get ()[thread_name_len - 1] =3D '\0'; - named_thread->name =3D 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) =20 /* See nat/windows-nat.h. */ =20 -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)