From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from rock.gnat.com (rock.gnat.com [205.232.38.15]) by sourceware.org (Postfix) with ESMTP id 81883385DC1B for ; Wed, 15 Apr 2020 19:13:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 81883385DC1B Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey@adacore.com Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 5807256047; Wed, 15 Apr 2020 15:13:17 -0400 (EDT) X-Virus-Scanned: Debian amavisd-new at gnat.com Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id L6tfXbLLHv8G; Wed, 15 Apr 2020 15:13:17 -0400 (EDT) Received: from murgatroyd (174-16-110-145.hlrn.qwest.net [174.16.110.145]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by rock.gnat.com (Postfix) with ESMTPSA id EB75A56043; Wed, 15 Apr 2020 15:13:16 -0400 (EDT) From: Tom Tromey To: Simon Marchi Cc: Tom Tromey , gdb-patches@sourceware.org Subject: Re: [PATCH v3 21/29] Share handle_exception References: <20200313190855.28662-1-tromey@adacore.com> <20200313190855.28662-22-tromey@adacore.com> <33cddd77-b9c5-dfaa-78cb-2812016b07fd@simark.ca> <87tv1kadv4.fsf@tromey.com> <214bbace-933a-a99e-1fcd-0956b6b4a5bd@simark.ca> X-Attribution: Tom Date: Wed, 15 Apr 2020 13:13:16 -0600 In-Reply-To: <214bbace-933a-a99e-1fcd-0956b6b4a5bd@simark.ca> (Simon Marchi's message of "Wed, 15 Apr 2020 13:54:19 -0400") Message-ID: <87zhbc8svn.fsf@tromey.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-25.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 15 Apr 2020 19:13:19 -0000 >>>>> "Simon" =3D=3D Simon Marchi writes: Simon> It helps, but there's still: Simon> CXX nat/windows-nat.o Simon> /home/smarchi/src/binutils-gdb/gdbserver/../gdb/nat/windows-nat.c: I= n function =E2=80=98windows_nat::handle_exception_result windows_nat::handl= e_exception(target_waitstatus*, bool)=E2=80=99: Simon> /home/smarchi/src/binutils-gdb/gdbserver/../gdb/nat/windows-nat.c:21= 4:10: error: =E2=80=98find_pc_partial_function=E2=80=99 was not declared in= this scope Simon> 214 | || (find_pc_partial_function (addr, &fn, NULL, NULL) Simon> | ^~~~~~~~~~~~~~~~~~~~~~~~ Yeah, I realized this quite a while after sending it. Simon> If we look at gdbserver's version of the function before this change= , it didn't have that part, Simon> so perhaps it should be factored out into a callback, which will res= ide in gdb/windows-nat.c. Yep, please try this. Tom commit 3cb8f05b1e897a617e499edc54c9fc5cf456634c Author: Tom Tromey Date: Wed Apr 15 13:11:23 2020 -0600 Fix Cygwin gdb build =20=20=20=20 Simon pointed out that the windows-nat sharing series broke the Cygwin build. This patch fixes the problem, by moving the Cygwin-specific code to a new handler function. This approach is taken because this code calls find_pc_partial_function, which isn't available in gdbserver. =20=20=20=20 gdb/ChangeLog 2020-04-15 Tom Tromey =20=20=20=20 * windows-nat.c (windows_nat::handle_access_violation): New function. * nat/windows-nat.h (handle_access_violation): Declare. * nat/windows-nat.c (handle_exception): Move Cygwin code to windows-nat.c. Call handle_access_violation. =20=20=20=20 gdbserver/ChangeLog 2020-04-15 Tom Tromey =20=20=20=20 * win32-low.cc (windows_nat::handle_access_violation): New function. diff --git a/gdb/ChangeLog b/gdb/ChangeLog index b0a535a624f..f6a15d1482c 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,11 @@ +2020-04-15 Tom Tromey + + * windows-nat.c (windows_nat::handle_access_violation): New + function. + * nat/windows-nat.h (handle_access_violation): Declare. + * nat/windows-nat.c (handle_exception): Move Cygwin code to + windows-nat.c. Call handle_access_violation. + 2020-04-15 Tom Tromey =20 * windows-nat.c (DEBUG_EXEC, DEBUG_EVENTS, DEBUG_MEM) diff --git a/gdb/nat/windows-nat.c b/gdb/nat/windows-nat.c index cd7c1d177c6..8c2092a51d7 100644 --- a/gdb/nat/windows-nat.c +++ b/gdb/nat/windows-nat.c @@ -184,26 +184,8 @@ handle_exception (struct target_waitstatus *ourstatus,= bool debug_exceptions) case EXCEPTION_ACCESS_VIOLATION: DEBUG_EXCEPTION_SIMPLE ("EXCEPTION_ACCESS_VIOLATION"); ourstatus->value.sig =3D GDB_SIGNAL_SEGV; -#ifdef __CYGWIN__ - { - /* See if the access violation happened within the cygwin DLL - itself. Cygwin uses a kind of exception handling to deal - with passed-in invalid addresses. gdb should not treat - these as real SEGVs since they will be silently handled by - cygwin. A real SEGV will (theoretically) be caught by - cygwin later in the process and will be sent as a - cygwin-specific-signal. So, ignore SEGVs if they show up - within the text segment of the DLL itself. */ - const char *fn; - CORE_ADDR addr =3D (CORE_ADDR) (uintptr_t) rec->ExceptionAddress; - - if ((!cygwin_exceptions && (addr >=3D cygwin_load_start - && addr < cygwin_load_end)) - || (find_pc_partial_function (addr, &fn, NULL, NULL) - && startswith (fn, "KERNEL32!IsBad"))) - return HANDLE_EXCEPTION_UNHANDLED; - } -#endif + if (handle_access_violation (rec)) + return HANDLE_EXCEPTION_UNHANDLED; break; case STATUS_STACK_OVERFLOW: DEBUG_EXCEPTION_SIMPLE ("STATUS_STACK_OVERFLOW"); diff --git a/gdb/nat/windows-nat.h b/gdb/nat/windows-nat.h index aea1519672d..8d0fa9bd216 100644 --- a/gdb/nat/windows-nat.h +++ b/gdb/nat/windows-nat.h @@ -157,6 +157,13 @@ extern void handle_unload_dll (); =20 extern bool handle_ms_vc_exception (const EXCEPTION_RECORD *rec); =20 +/* 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 + returns true, then the exception is "unhandled". */ + +extern bool handle_access_violation (const EXCEPTION_RECORD *rec); + =20 /* Currently executing process */ extern HANDLE current_process_handle; diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index e82e58ec1f2..b857f82eb89 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -1230,6 +1230,31 @@ windows_nat::handle_ms_vc_exception (const EXCEPTION= _RECORD *rec) return false; } =20 +/* See nat/windows-nat.h. */ + +bool +windows_nat::handle_access_violation (const EXCEPTION_RECORD *rec) +{ +#ifdef __CYGWIN__ + /* See if the access violation happened within the cygwin DLL + itself. Cygwin uses a kind of exception handling to deal with + passed-in invalid addresses. gdb should not treat these as real + SEGVs since they will be silently handled by cygwin. A real SEGV + will (theoretically) be caught by cygwin later in the process and + will be sent as a cygwin-specific-signal. So, ignore SEGVs if + they show up within the text segment of the DLL itself. */ + const char *fn; + CORE_ADDR addr =3D (CORE_ADDR) (uintptr_t) rec->ExceptionAddress; + + if ((!cygwin_exceptions && (addr >=3D cygwin_load_start + && addr < cygwin_load_end)) + || (find_pc_partial_function (addr, &fn, NULL, NULL) + && startswith (fn, "KERNEL32!IsBad"))) + return true; +#endif + return false; +} + /* Resume thread specified by ID, or all artificially suspended threads, if we are continuing execution. KILLED non-zero means we have killed the inferior, so we should ignore weird errors due to diff --git a/gdbserver/ChangeLog b/gdbserver/ChangeLog index 2b381455ed7..d22b6b2daef 100644 --- a/gdbserver/ChangeLog +++ b/gdbserver/ChangeLog @@ -1,3 +1,8 @@ +2020-04-15 Tom Tromey + + * win32-low.cc (windows_nat::handle_access_violation): New + function. + 2020-04-13 Tom Tromey =20 * server.h (gdb_fildes_t): Remove typedef. diff --git a/gdbserver/win32-low.cc b/gdbserver/win32-low.cc index e1226b4b0db..41348dd77d4 100644 --- a/gdbserver/win32-low.cc +++ b/gdbserver/win32-low.cc @@ -1198,6 +1198,14 @@ windows_nat::handle_ms_vc_exception (const EXCEPTION= _RECORD *rec) return false; } =20 +/* See nat/windows-nat.h. */ + +bool +windows_nat::handle_access_violation (const EXCEPTION_RECORD *rec) +{ + return false; +} + /* A helper function that will, if needed, set 'stopped_at_software_breakpoint' on the thread and adjust the PC. */