From patchwork Mon Feb 13 14:23:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 64895 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 564033888C58 for ; Mon, 13 Feb 2023 14:23:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 564033888C58 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1676298217; bh=uLfuX9ww1k6b4T7dJYAnKWYs506MjJRcTSWIrgpU3Vg=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=dgEhKLa2/zRmUomWDz07AwboNxY5dmEWhvoKKK5lBVdGdek8t9KIzAV423mLl2hkc SnckN/6jFNG+fBDg/igkAJrUlQHJT1ICd2n04KyMDye5VEygQ8oMmQ1VBhwe87PEQ4 AW8eMHlLYYLzB2hC6ps/KDczR+pgmwqsapJ7sFtg= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id 0984A38493CA for ; Mon, 13 Feb 2023 14:23:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0984A38493CA Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 44F7D21866; Mon, 13 Feb 2023 14:23:09 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 2E720138E6; Mon, 13 Feb 2023 14:23:09 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 6C06Cs1H6mOwfgAAMHmgww (envelope-from ); Mon, 13 Feb 2023 14:23:09 +0000 To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH v2 1/5] [gdb/symtab] Factor out compunit_epilogue_unwind_valid Date: Mon, 13 Feb 2023 15:23:05 +0100 Message-Id: <20230213142309.24366-2-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230213142309.24366-1-tdevries@suse.de> References: <20230213142309.24366-1-tdevries@suse.de> MIME-Version: 1.0 X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, DKIM_INVALID, DKIM_SIGNED, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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-Patchwork-Original-From: Tom de Vries via Gdb-patches From: Tom de Vries Reply-To: Tom de Vries Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" Factor out compunit_epilogue_unwind_valid from both amd64_stack_frame_destroyed_p and i386_stack_frame_destroyed_p. NFC. Also add a comment in the new function about the assumption that in absence of producer information, epilogue unwind info is invalid. --- gdb/amd64-tdep.c | 4 +--- gdb/i386-tdep.c | 4 +--- gdb/symtab.h | 13 +++++++++++++ 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/gdb/amd64-tdep.c b/gdb/amd64-tdep.c index 328e001f5bb..d2e683b6fa8 100644 --- a/gdb/amd64-tdep.c +++ b/gdb/amd64-tdep.c @@ -2902,10 +2902,8 @@ static int amd64_stack_frame_destroyed_p (struct gdbarch *gdbarch, CORE_ADDR pc) { gdb_byte insn; - struct compunit_symtab *cust; - cust = find_pc_compunit_symtab (pc); - if (cust != NULL && cust->epilogue_unwind_valid ()) + if (compunit_epilogue_unwind_valid (find_pc_compunit_symtab (pc))) return 0; if (target_read_memory (pc, &insn, 1)) diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c index 8dccae633f7..3fe548d8c68 100644 --- a/gdb/i386-tdep.c +++ b/gdb/i386-tdep.c @@ -2219,10 +2219,8 @@ static int i386_stack_frame_destroyed_p (struct gdbarch *gdbarch, CORE_ADDR pc) { gdb_byte insn; - struct compunit_symtab *cust; - cust = find_pc_compunit_symtab (pc); - if (cust != NULL && cust->epilogue_unwind_valid ()) + if (compunit_epilogue_unwind_valid (find_pc_compunit_symtab (pc))) return 0; if (target_read_memory (pc, &insn, 1)) diff --git a/gdb/symtab.h b/gdb/symtab.h index 11ff875c6b8..cd6b5f722fd 100644 --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -1917,6 +1917,19 @@ is_main_symtab_of_compunit_symtab (struct symtab *symtab) { return symtab == symtab->compunit ()->primary_filetab (); } + +/* Return true if epilogue unwind info of CUST is valid. */ + +static inline bool +compunit_epilogue_unwind_valid (struct compunit_symtab *cust) +{ + /* In absence of producer information, assume epilogue unwind info is + invalid. */ + if (cust == nullptr) + return false; + + return cust->epilogue_unwind_valid (); +} /* The virtual function table is now an array of structures which have the From patchwork Mon Feb 13 14:23:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 64896 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B4BC73886C43 for ; Mon, 13 Feb 2023 14:23:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B4BC73886C43 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1676298217; bh=Ykc3BzkngoFAOfC7F+BbefprU8uz+vksTy8xNPsfz6s=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=I0D+qVR3oAO2uUYK/77K50+/OTaCsyn56Y/C+0sUoRRHRwWIMKOvLq/9RTlwld948 SOYUIj3AJJGPEPGnXRFuGM17mSfmXZB7cTPU9NFBBpwTTxft8iTDbVBe/99K4dN27f sxGmh+T/QUSWVcaw5glKxiV9pKYNvHzRQcu79ETQ= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by sourceware.org (Postfix) with ESMTPS id 26E9438493EA for ; Mon, 13 Feb 2023 14:23:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 26E9438493EA Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 5F63E1F381; Mon, 13 Feb 2023 14:23:09 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 49893138E6; Mon, 13 Feb 2023 14:23:09 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id YLD3EM1H6mOwfgAAMHmgww (envelope-from ); Mon, 13 Feb 2023 14:23:09 +0000 To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH v2 2/5] [gdb/tdep] Fix amd64/i386_stack_frame_destroyed_p Date: Mon, 13 Feb 2023 15:23:06 +0100 Message-Id: <20230213142309.24366-3-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230213142309.24366-1-tdevries@suse.de> References: <20230213142309.24366-1-tdevries@suse.de> MIME-Version: 1.0 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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-Patchwork-Original-From: Tom de Vries via Gdb-patches From: Tom de Vries Reply-To: Tom de Vries Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" The use of compunit_epilogue_unwind_valid in both amd64_stack_frame_destroyed_p and i386_stack_frame_destroyed_p is problematic, in the sense that the functions no longer match their documented behaviour. Fix this by moving the use of compunit_epilogue_unwind_valid to amd64_epilogue_frame_sniffer and i386_epilogue_frame_sniffer. NFC. --- gdb/amd64-tdep.c | 19 ++++++++++++------- gdb/i386-tdep.c | 20 ++++++++++++-------- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/gdb/amd64-tdep.c b/gdb/amd64-tdep.c index d2e683b6fa8..0ec9b23922d 100644 --- a/gdb/amd64-tdep.c +++ b/gdb/amd64-tdep.c @@ -2903,9 +2903,6 @@ amd64_stack_frame_destroyed_p (struct gdbarch *gdbarch, CORE_ADDR pc) { gdb_byte insn; - if (compunit_epilogue_unwind_valid (find_pc_compunit_symtab (pc))) - return 0; - if (target_read_memory (pc, &insn, 1)) return 0; /* Can't read memory at pc. */ @@ -2920,11 +2917,19 @@ amd64_epilogue_frame_sniffer (const struct frame_unwind *self, frame_info_ptr this_frame, void **this_prologue_cache) { - if (frame_relative_level (this_frame) == 0) - return amd64_stack_frame_destroyed_p (get_frame_arch (this_frame), - get_frame_pc (this_frame)); - else + struct gdbarch *gdbarch = get_frame_arch (this_frame); + CORE_ADDR pc = get_frame_pc (this_frame); + + if (frame_relative_level (this_frame) != 0) + /* We're not in the inner frame, so assume we're not in an epilogue. */ return 0; + + if (compunit_epilogue_unwind_valid (find_pc_compunit_symtab (pc))) + /* Don't override the symtab unwinders. */ + return 0; + + /* Check whether we're in an epilogue. */ + return amd64_stack_frame_destroyed_p (gdbarch, pc); } static struct amd64_frame_cache * diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c index 3fe548d8c68..5e797d098e8 100644 --- a/gdb/i386-tdep.c +++ b/gdb/i386-tdep.c @@ -2219,10 +2219,6 @@ static int i386_stack_frame_destroyed_p (struct gdbarch *gdbarch, CORE_ADDR pc) { gdb_byte insn; - - if (compunit_epilogue_unwind_valid (find_pc_compunit_symtab (pc))) - return 0; - if (target_read_memory (pc, &insn, 1)) return 0; /* Can't read memory at pc. */ @@ -2237,11 +2233,19 @@ i386_epilogue_frame_sniffer (const struct frame_unwind *self, frame_info_ptr this_frame, void **this_prologue_cache) { - if (frame_relative_level (this_frame) == 0) - return i386_stack_frame_destroyed_p (get_frame_arch (this_frame), - get_frame_pc (this_frame)); - else + struct gdbarch *gdbarch = get_frame_arch (this_frame); + CORE_ADDR pc = get_frame_pc (this_frame); + + if (frame_relative_level (this_frame) != 0) + /* We're not in the inner frame, so assume we're not in an epilogue. */ + return 0; + + if (compunit_epilogue_unwind_valid (find_pc_compunit_symtab (pc))) + /* Don't override the symtab unwinders. */ return 0; + + /* Check whether we're in an epilogue. */ + return i386_stack_frame_destroyed_p (gdbarch, pc); } static struct i386_frame_cache * From patchwork Mon Feb 13 14:23:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 64897 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3C1533889E1B for ; Mon, 13 Feb 2023 14:24:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3C1533889E1B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1676298246; bh=5GwB/n7qnePVFUHoO4M0qRsXUm0LHfZhRkShe+CVfAk=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=RY/zsjZBnSImjJ/u1o7d8Qcz92ZGhN0+LiPMtdwKL0Ktms54q1uhq9cxalRS1mjoF TYMrhsC8hCS0GGukZQlKyyv7byPCbw4qkcDc/0UgHARC47bl/EqK/DnqKnSX1r/134 BJCdblaKE4f3TVlBDOWaGjJslZMUNYf/oJXuN4Yw= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id 4B299383FBAE for ; Mon, 13 Feb 2023 14:23:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4B299383FBAE Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 7CCC71F390; Mon, 13 Feb 2023 14:23:09 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 651C7138E6; Mon, 13 Feb 2023 14:23:09 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id CHOpF81H6mOwfgAAMHmgww (envelope-from ); Mon, 13 Feb 2023 14:23:09 +0000 To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH v2 3/5] [gdb/tdep] Add amd64/i386 epilogue override unwinders Date: Mon, 13 Feb 2023 15:23:07 +0100 Message-Id: <20230213142309.24366-4-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230213142309.24366-1-tdevries@suse.de> References: <20230213142309.24366-1-tdevries@suse.de> MIME-Version: 1.0 X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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-Patchwork-Original-From: Tom de Vries via Gdb-patches From: Tom de Vries Reply-To: Tom de Vries Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" For amd64 the current frame-unwinders are: ... $ gdb -q -batch -ex "set arch i386:x86-64" -ex "maint info frame-unwinders" The target architecture is set to "i386:x86-64". dummy DUMMY_FRAME dwarf2 tailcall TAILCALL_FRAME inline INLINE_FRAME python NORMAL_FRAME amd64 epilogue NORMAL_FRAME dwarf2 NORMAL_FRAME dwarf2 signal SIGTRAMP_FRAME amd64 sigtramp SIGTRAMP_FRAME amd64 prologue NORMAL_FRAME ... For a -g0 -fasynchronous-unwind-tables exec (without .debug_info but with .eh_frame section), we'd like to start using the dwarf2 unwinder instead of the "amd64 epilogue" unwinder, by returning true in compunit_epilogue_unwind_valid for cust == nullptr. But we'd run into the following problem for a -g0 -fno-asynchronous-unwind-tables (without .debug_info and .eh_frame section) exec: - the "amd64 epilogue" unwinder would not run (because compunit_epilogue_unwind_valid () == true) - the dwarf2 unwinder would also not run (because there's no .eh_frame info). Fix this by: - renaming the "amd64 epilogue" unwinder to "amd64 epilogue override", and - adding a fallback "amd64 epilogue" after the dwarf unwinders, while making sure that only one of the two is active. Likewise for i386. NFC. For amd64, this results in this change: ... $ gdb -q -batch -ex "set arch i386:x86-64" -ex "maint info frame-unwinders" The target architecture is set to "i386:x86-64". dummy DUMMY_FRAME dwarf2 tailcall TAILCALL_FRAME inline INLINE_FRAME python NORMAL_FRAME -amd64 epilogue NORMAL_FRAME +amd64 epilogue override NORMAL_FRAME dwarf2 NORMAL_FRAME dwarf2 signal SIGTRAMP_FRAME +amd64 epilogue NORMAL_FRAME amd64 sigtramp SIGTRAMP_FRAME amd64 prologue NORMAL_FRAME ... And for i386: ... $ gdb -q -batch -ex "set arch i386" -ex "maint info frame-unwinders" The target architecture is set to "i386". dummy DUMMY_FRAME dwarf2 tailcall TAILCALL_FRAME iline INLINE_FRAME -i386 epilogue NORMAL_FRAME +i386 epilogue override NORMAL_FRAME dwarf2 NORMAL_FRAME dwarf2 signal SIGTRAMP_FRAME +i386 epilogue NORMAL_FRAME i386 stack tramp NORMAL_FRAME i386 sigtramp SIGTRAMP_FRAME i386 prologue NORMAL_FRAME ... --- gdb/amd64-tdep.c | 58 +++++++++++++++++++++++++++++++++++++++++------ gdb/i386-tdep.c | 59 ++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 103 insertions(+), 14 deletions(-) diff --git a/gdb/amd64-tdep.c b/gdb/amd64-tdep.c index 0ec9b23922d..c0c62bdd696 100644 --- a/gdb/amd64-tdep.c +++ b/gdb/amd64-tdep.c @@ -2913,9 +2913,9 @@ amd64_stack_frame_destroyed_p (struct gdbarch *gdbarch, CORE_ADDR pc) } static int -amd64_epilogue_frame_sniffer (const struct frame_unwind *self, - frame_info_ptr this_frame, - void **this_prologue_cache) +amd64_epilogue_frame_sniffer_1 (const struct frame_unwind *self, + frame_info_ptr this_frame, + void **this_prologue_cache, bool override_p) { struct gdbarch *gdbarch = get_frame_arch (this_frame); CORE_ADDR pc = get_frame_pc (this_frame); @@ -2924,14 +2924,45 @@ amd64_epilogue_frame_sniffer (const struct frame_unwind *self, /* We're not in the inner frame, so assume we're not in an epilogue. */ return 0; - if (compunit_epilogue_unwind_valid (find_pc_compunit_symtab (pc))) - /* Don't override the symtab unwinders. */ - return 0; + bool unwind_valid_p + = compunit_epilogue_unwind_valid (find_pc_compunit_symtab (pc)); + if (override_p) + { + if (unwind_valid_p) + /* Don't override the symtab unwinders, skip + "amd64 epilogue override". */ + return 0; + } + else + { + if (!unwind_valid_p) + /* "amd64 epilogue override" unwinder already ran, skip + "amd64 epilogue". */ + return 0; + } /* Check whether we're in an epilogue. */ return amd64_stack_frame_destroyed_p (gdbarch, pc); } +static int +amd64_epilogue_override_frame_sniffer (const struct frame_unwind *self, + frame_info_ptr this_frame, + void **this_prologue_cache) +{ + return amd64_epilogue_frame_sniffer_1 (self, this_frame, this_prologue_cache, + true); +} + +static int +amd64_epilogue_frame_sniffer (const struct frame_unwind *self, + frame_info_ptr this_frame, + void **this_prologue_cache) +{ + return amd64_epilogue_frame_sniffer_1 (self, this_frame, this_prologue_cache, + false); +} + static struct amd64_frame_cache * amd64_epilogue_frame_cache (frame_info_ptr this_frame, void **this_cache) { @@ -3000,6 +3031,17 @@ amd64_epilogue_frame_this_id (frame_info_ptr this_frame, (*this_id) = frame_id_build (cache->base + 16, cache->pc); } +static const struct frame_unwind amd64_epilogue_override_frame_unwind = +{ + "amd64 epilogue override", + NORMAL_FRAME, + amd64_epilogue_frame_unwind_stop_reason, + amd64_epilogue_frame_this_id, + amd64_frame_prev_register, + NULL, + amd64_epilogue_override_frame_sniffer +}; + static const struct frame_unwind amd64_epilogue_frame_unwind = { "amd64 epilogue", @@ -3257,7 +3299,9 @@ amd64_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch, /* Hook the function epilogue frame unwinder. This unwinder is appended to the list first, so that it supercedes the other unwinders in function epilogues. */ - frame_unwind_prepend_unwinder (gdbarch, &amd64_epilogue_frame_unwind); + frame_unwind_prepend_unwinder (gdbarch, &amd64_epilogue_override_frame_unwind); + + frame_unwind_append_unwinder (gdbarch, &amd64_epilogue_frame_unwind); /* Hook the prologue-based frame unwinders. */ frame_unwind_append_unwinder (gdbarch, &amd64_sigtramp_frame_unwind); diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c index 5e797d098e8..d765c1e95d7 100644 --- a/gdb/i386-tdep.c +++ b/gdb/i386-tdep.c @@ -2229,9 +2229,9 @@ i386_stack_frame_destroyed_p (struct gdbarch *gdbarch, CORE_ADDR pc) } static int -i386_epilogue_frame_sniffer (const struct frame_unwind *self, - frame_info_ptr this_frame, - void **this_prologue_cache) +i386_epilogue_frame_sniffer_1 (const struct frame_unwind *self, + frame_info_ptr this_frame, + void **this_prologue_cache, bool override_p) { struct gdbarch *gdbarch = get_frame_arch (this_frame); CORE_ADDR pc = get_frame_pc (this_frame); @@ -2240,14 +2240,45 @@ i386_epilogue_frame_sniffer (const struct frame_unwind *self, /* We're not in the inner frame, so assume we're not in an epilogue. */ return 0; - if (compunit_epilogue_unwind_valid (find_pc_compunit_symtab (pc))) - /* Don't override the symtab unwinders. */ - return 0; + bool unwind_valid_p + = compunit_epilogue_unwind_valid (find_pc_compunit_symtab (pc)); + if (override_p) + { + if (unwind_valid_p) + /* Don't override the symtab unwinders, skip + "i386 epilogue override". */ + return 0; + } + else + { + if (!unwind_valid_p) + /* "i386 epilogue override" unwinder already ran, skip + "i386 epilogue". */ + return 0; + } /* Check whether we're in an epilogue. */ return i386_stack_frame_destroyed_p (gdbarch, pc); } +static int +i386_epilogue_override_frame_sniffer (const struct frame_unwind *self, + frame_info_ptr this_frame, + void **this_prologue_cache) +{ + return i386_epilogue_frame_sniffer_1 (self, this_frame, this_prologue_cache, + true); +} + +static int +i386_epilogue_frame_sniffer (const struct frame_unwind *self, + frame_info_ptr this_frame, + void **this_prologue_cache) +{ + return i386_epilogue_frame_sniffer_1 (self, this_frame, this_prologue_cache, + false); +} + static struct i386_frame_cache * i386_epilogue_frame_cache (frame_info_ptr this_frame, void **this_cache) { @@ -2320,6 +2351,17 @@ i386_epilogue_frame_prev_register (frame_info_ptr this_frame, return i386_frame_prev_register (this_frame, this_cache, regnum); } +static const struct frame_unwind i386_epilogue_override_frame_unwind = +{ + "i386 epilogue override", + NORMAL_FRAME, + i386_epilogue_frame_unwind_stop_reason, + i386_epilogue_frame_this_id, + i386_epilogue_frame_prev_register, + NULL, + i386_epilogue_override_frame_sniffer +}; + static const struct frame_unwind i386_epilogue_frame_unwind = { "i386 epilogue", @@ -8616,13 +8658,16 @@ i386_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) unwinder in function epilogues (where the DWARF unwinder currently fails). */ if (info.bfd_arch_info->bits_per_word == 32) - frame_unwind_append_unwinder (gdbarch, &i386_epilogue_frame_unwind); + frame_unwind_append_unwinder (gdbarch, &i386_epilogue_override_frame_unwind); /* Hook in the DWARF CFI frame unwinder. This unwinder is appended to the list before the prologue-based unwinders, so that DWARF CFI info will be used if it is available. */ dwarf2_append_unwinders (gdbarch); + if (info.bfd_arch_info->bits_per_word == 32) + frame_unwind_append_unwinder (gdbarch, &i386_epilogue_frame_unwind); + frame_base_set_default (gdbarch, &i386_frame_base); /* Pseudo registers may be changed by amd64_init_abi. */ From patchwork Mon Feb 13 14:23:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 64898 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4D0683887F69 for ; Mon, 13 Feb 2023 14:24:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4D0683887F69 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1676298273; bh=qEViwaooTCO4apycXhLldyEb2jYQaEejAU6TpPXq5EM=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=YG9SmnaiBDSaFZIN2hJGxr8KR1CT5IHOSsn7uw1iWJCYEYkqacu3XquXF5HUp1O8H OTVFjx4iLlfsrQSri78UE+HSflbPId9wScgRS0im2BPSSvmVrZI3YGBnIxf3RPfUyq Q0oTVobz0Yhx97EPIhmHNI9/oP4oKEy5/0UtXZXM= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id 650063839DF6 for ; Mon, 13 Feb 2023 14:23:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 650063839DF6 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 9887F1F45A; Mon, 13 Feb 2023 14:23:09 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 822B0138E6; Mon, 13 Feb 2023 14:23:09 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id GAmsHs1H6mOwfgAAMHmgww (envelope-from ); Mon, 13 Feb 2023 14:23:09 +0000 To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH v2 4/5] [gdb/symtab] Trust epilogue unwind info for unknown producer (-g0 case) Date: Mon, 13 Feb 2023 15:23:08 +0100 Message-Id: <20230213142309.24366-5-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230213142309.24366-1-tdevries@suse.de> References: <20230213142309.24366-1-tdevries@suse.de> MIME-Version: 1.0 X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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-Patchwork-Original-From: Tom de Vries via Gdb-patches From: Tom de Vries Reply-To: Tom de Vries Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" For a -g0 -fasynchronous-unwind-tables exec (without .debug_info but with .eh_frame section), start using the dwarf2 unwinder instead of the "amd64 epilogue override" unwinder, by returning true in compunit_epilogue_unwind_valid for cust == nullptr. This has effect both on the amd64 and i386 targets, but only add amd64 test-case gdb.base/unwind-on-each-insn-amd64-2.exp. --- gdb/symtab.h | 4 +- .../gdb.base/unwind-on-each-insn-amd64-2.exp | 52 ++++++++++++++++++ .../gdb.base/unwind-on-each-insn-amd64-2.s | 54 +++++++++++++++++++ 3 files changed, 108 insertions(+), 2 deletions(-) create mode 100644 gdb/testsuite/gdb.base/unwind-on-each-insn-amd64-2.exp create mode 100644 gdb/testsuite/gdb.base/unwind-on-each-insn-amd64-2.s diff --git a/gdb/symtab.h b/gdb/symtab.h index cd6b5f722fd..17d2746fd48 100644 --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -1924,9 +1924,9 @@ static inline bool compunit_epilogue_unwind_valid (struct compunit_symtab *cust) { /* In absence of producer information, assume epilogue unwind info is - invalid. */ + valid. */ if (cust == nullptr) - return false; + return true; return cust->epilogue_unwind_valid (); } diff --git a/gdb/testsuite/gdb.base/unwind-on-each-insn-amd64-2.exp b/gdb/testsuite/gdb.base/unwind-on-each-insn-amd64-2.exp new file mode 100644 index 00000000000..c8a94ccef4f --- /dev/null +++ b/gdb/testsuite/gdb.base/unwind-on-each-insn-amd64-2.exp @@ -0,0 +1,52 @@ +# Copyright 2023 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . */ + +# Check that epilogue unwind info is used, even if no debug info is available. + +require is_x86_64_m64_target + +set srcfile_flags {debug} +set srcfile2_flags {nodebug} + +if [info exists COMPILE] { + # Make sure that we use .eh_frame info, by generating it + # using -fasynchronous-unwind-tables. + if { [gdb_can_simple_compile fasynchronous-unwind-tables \ + { void foo () { } } object -fasynchronous-unwind-tables] } { + lappend srcfile2_flags additional_flags=-fasynchronous-unwind-tables + } else { + unsupported "required: .eh_frame" + return + } + standard_testfile unwind-on-each-insn.c unwind-on-each-insn-foo.c + # When updating the .s file, use these flags to generate the file: + #lappend srcfile2_flags additional_flags=-save-temps + #lappend srcfile2_flags additional_flags=-dA + # and do the following: + # - copy it in place, run the test-case and verify that all tests pass. + # - confuse the amd64 epilogue unwinder by inserting the following + # in foo: + # nop + # + pushq $.L1 + # + ret + # + .L1: + # + nop + # popq %rbp + # - verify that the test-case passes. +} else { + standard_testfile unwind-on-each-insn.c .s +} + +source $srcdir/$subdir/unwind-on-each-insn.exp.tcl diff --git a/gdb/testsuite/gdb.base/unwind-on-each-insn-amd64-2.s b/gdb/testsuite/gdb.base/unwind-on-each-insn-amd64-2.s new file mode 100644 index 00000000000..c141f71817c --- /dev/null +++ b/gdb/testsuite/gdb.base/unwind-on-each-insn-amd64-2.s @@ -0,0 +1,54 @@ + .file "unwind-on-each-insn-foo.c" + .text + .globl foo + .type foo, @function +foo: +.LFB0: + .cfi_startproc +# BLOCK 2 seq:0 +# PRED: ENTRY (FALLTHRU) + pushq %rbp + .cfi_def_cfa_offset 16 + .cfi_offset 6, -16 + movq %rsp, %rbp + .cfi_def_cfa_register 6 + movq %rdi, -8(%rbp) + nop + pushq $.L1 + ret +.L1: + nop + popq %rbp + .cfi_def_cfa 7, 8 +# SUCC: EXIT [100.0%] + ret + .cfi_endproc +.LFE0: + .size foo, .-foo + .globl bar + .type bar, @function +bar: +.LFB1: + .cfi_startproc +# BLOCK 2 seq:0 +# PRED: ENTRY (FALLTHRU) + pushq %rbp + .cfi_def_cfa_offset 16 + .cfi_offset 6, -16 + movq %rsp, %rbp + .cfi_def_cfa_register 6 + subq $8, %rsp + movq %rdi, -8(%rbp) + movq -8(%rbp), %rax + movq %rax, %rdi + call foo + nop + leave + .cfi_def_cfa 7, 8 +# SUCC: EXIT [100.0%] + ret + .cfi_endproc +.LFE1: + .size bar, .-bar + .ident "GCC: (SUSE Linux) 7.5.0" + .section .note.GNU-stack,"",@progbits From patchwork Mon Feb 13 14:23:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 64899 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A93C43887F7E for ; Mon, 13 Feb 2023 14:24:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A93C43887F7E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1676298273; bh=hXOOBq1WC7B7eMQhGkzGHmdbdYluyCatwdq4v8kOzJw=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=ly31Hqkzm0arV2PfIOAIF39FbxRH4PCEgPFCdbCZdodxOg1EhkzqdUGmW5GVU/IZm H7cLE7nh2DCFbOKUAbzemm3HCZFkJLfbXw7/186yX13TsrbdhHfzT84tD81UhubVFt RvFi/TDnL70+wZp9H0KwHOZ+TQ2VNETy6OEgDTPQ= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id 820EF3881D1D for ; Mon, 13 Feb 2023 14:23:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 820EF3881D1D Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id B4F3E1F45E; Mon, 13 Feb 2023 14:23:09 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 9E2C0138E6; Mon, 13 Feb 2023 14:23:09 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id YNKdJc1H6mOwfgAAMHmgww (envelope-from ); Mon, 13 Feb 2023 14:23:09 +0000 To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH v2 5/5] [gdb/symtab] Trust epilogue unwind info for unknown or non-gcc producer Date: Mon, 13 Feb 2023 15:23:09 +0100 Message-Id: <20230213142309.24366-6-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230213142309.24366-1-tdevries@suse.de> References: <20230213142309.24366-1-tdevries@suse.de> MIME-Version: 1.0 X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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-Patchwork-Original-From: Tom de Vries via Gdb-patches From: Tom de Vries Reply-To: Tom de Vries Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" Currently we only trust epilogue unwind info only for gcc >= 4.5.0. This has the effect that we don't trust epilogue unwind info for: - unknown producers (CU without DW_AT_producer attribute) - non-gcc producers (say, clang). Instead, only distrust epilogue unwind info only for gcc < 4.5.0. --- gdb/dwarf2/read.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index ce6c01ac771..46792bd9162 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -8451,7 +8451,13 @@ process_full_comp_unit (dwarf2_cu *cu, enum language pretend_language) if (cu->has_loclist && gcc_4_minor >= 5) cust->set_locations_valid (true); - if (gcc_4_minor >= 5) + int major, minor; + if (cu->producer != nullptr + && producer_is_gcc (cu->producer, &major, &minor) + && (major < 4 || (major == 4 && minor < 5))) + /* Don't trust gcc < 4.5.x. */ + cust->set_epilogue_unwind_valid (false); + else cust->set_epilogue_unwind_valid (true); cust->set_call_site_htab (cu->call_site_htab);