From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1676298189; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5GwB/n7qnePVFUHoO4M0qRsXUm0LHfZhRkShe+CVfAk=; b=XGHfqsivqCDycvQvCuvq0mvngBH2cu0Ix31cEZgjMPuQ8w8rombx3RFY2GezqLWtxKeCLL 7Qn4qdS7hMV493iVVvFqqBsNuz6X0yF9ge9CQfFB7f4CNF/prvymGlOdKn0d6f5FUr0+8M 7KpT/yphPUepRc43X3FYzugIrL1OSpg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1676298189; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5GwB/n7qnePVFUHoO4M0qRsXUm0LHfZhRkShe+CVfAk=; b=skI6VBdpLPZIixgaYzRPPf8Omoky20B1W/PyEZFt9cvXyL7dA3UGdNvHiifikd1TQgYih2 MsSkBOrOUmKHVjAw== 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 From: Tom de Vries 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 Content-Transfer-Encoding: 8bit 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 List-Id: 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. */ -- 2.35.3