From patchwork Fri Nov 18 16:43:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 60847 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 41772384F4A6 for ; Fri, 18 Nov 2022 16:47:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 41772384F4A6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1668790028; bh=oRz0VvXR4rjGFxZ+XV/pBiq0pW9ElHBhlUbJW9CQFAc=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=b8i7lCQO8C0rN6EJ0WfyTole8ADUa7eY+BmJ8uo8030dZGJ0nKDIuFitabe6pw5n3 ozmxn35wnv+Imp8FilvQx0bBFE+IdGCNW9ZtbPGWESNNdr+VuVFzdehQcDXLD1nSue yOIMw25JtACxeP5IQeNPLB1ALKEITFAKT9k1QBCA= 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 B3439384F491 for ; Fri, 18 Nov 2022 16:43:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B3439384F491 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 DC36C1FD77; Fri, 18 Nov 2022 16:43:23 +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 B9FF51345B; Fri, 18 Nov 2022 16:43:23 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 09pLLCu2d2P0DgAAMHmgww (envelope-from ); Fri, 18 Nov 2022 16:43:23 +0000 To: gdb-patches@sourceware.org Cc: Ulrich Weigand , Carl Love Subject: [PATCH] Fix gdb.cp/gdb2495.exp on powerpc64le Date: Fri, 18 Nov 2022 17:43:23 +0100 Message-Id: <20221118164323.10089-1-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 X-Spam-Status: No, score=-12.6 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" From: Tom de Vries On powerpc64le-linux I ran into this FAIL: ... (gdb) p exceptions.throw_function()^M terminate called after throwing an instance of 'int'^M ^M Program received signal SIGABRT, Aborted.^M 0x00007ffff7979838 in raise () from /lib64/libc.so.6^M The program being debugged was signaled while in a function called from GDB.^M GDB remains in the frame where the signal was received.^M To change this behavior use "set unwindonsignal on".^M Evaluation of the expression containing the function^M (SimpleException::throw_function()) will be abandoned.^M When the function is done executing, GDB will silently stop.^M (gdb) FAIL: gdb.cp/gdb2495.exp: call a function that raises an exception \ without a handler. ... The following happens: - we start an inferior call - an internal breakpoint is set on the global entry point of std::terminate - the inferior call uses the local entry point - the breakpoint is not triggered - we run into std::terminate We can fix this by simply adding the missing gdbarch_skip_entrypoint call in create_std_terminate_master_breakpoint, but we try to do this a bit more generic, by: - adding a variant of function create_internal_breakpoint which takes a minimal symbol instead of an address as argument - in the new function: - using both gdbarch_convert_from_func_ptr_addr and gdbarch_skip_entrypoint - documenting why we don't need to use gdbarch_addr_bits_remove - adding a note about possibly needing gdbarch_deprecated_function_start_offset. - using the new function in: - create_std_terminate_master_breakpoint - create_exception_master_breakpoint_hook, which currently uses only gdbarch_convert_from_func_ptr_addr. Note: we could use the new function in more locations in breakpoint.c, but as we're not aware of any related failures, we declare this out of scope for this patch. Tested on x86_64-linux, powerpc64le-linux. Co-Authored-By: Ulrich Weigand PR tdep/29793 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29793 --- gdb/breakpoint.c | 42 +++++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) base-commit: f9f88aede3bb84efd088a59a5f6bccb3a6bb6516 diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 490708938ec..578d45b15af 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -3283,6 +3283,8 @@ set_breakpoint_number (int internal, struct breakpoint *b) } } +/* Create a TYPE breakpoint on ADDRESS from an object file with GDBARCH. */ + static struct breakpoint * create_internal_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address, enum bptype type) @@ -3295,6 +3297,33 @@ create_internal_breakpoint (struct gdbarch *gdbarch, return add_to_breakpoint_chain (std::move (b)); } +/* Create a TYPE breakpoint on minimal symbol MSYM from an object file with + GDBARCH. */ + +static struct breakpoint * +create_internal_breakpoint (struct gdbarch *gdbarch, + struct bound_minimal_symbol &msym, enum bptype type) +{ + CORE_ADDR address; + + address = msym.value_address (); + + address = gdbarch_convert_from_func_ptr_addr + (gdbarch, address, current_inferior ()->top_target ()); + + /* Note that we're not using gdbarch_addr_bits_remove here, because that's + related to addresses in $pc. We're getting the address from the + minimal symbol table. */ + + /* Is gdbarch_deprecated_function_start_offset needed here? Or is that dealt + with elsewhere? Needs testing on vax. */ + + if (gdbarch_skip_entrypoint_p (gdbarch)) + address = gdbarch_skip_entrypoint (gdbarch, address); + + return create_internal_breakpoint (gdbarch, address, type); +} + static const char *const longjmp_names[] = { "longjmp", "_longjmp", "siglongjmp", "_siglongjmp" @@ -3544,8 +3573,6 @@ create_std_terminate_master_breakpoint (void) for (struct program_space *pspace : program_spaces) { - CORE_ADDR addr; - set_current_program_space (pspace); for (objfile *objfile : current_program_space->objfiles ()) @@ -3573,8 +3600,8 @@ create_std_terminate_master_breakpoint (void) bp_objfile_data->terminate_msym = m; } - addr = bp_objfile_data->terminate_msym.value_address (); - b = create_internal_breakpoint (objfile->arch (), addr, + b = create_internal_breakpoint (objfile->arch (), + bp_objfile_data->terminate_msym, bp_std_terminate_master); b->locspec = new_explicit_location_spec_function (func_name); b->enable_state = bp_disabled; @@ -3643,7 +3670,6 @@ create_exception_master_breakpoint_hook (objfile *objfile) struct breakpoint *b; struct gdbarch *gdbarch; struct breakpoint_objfile_data *bp_objfile_data; - CORE_ADDR addr; bp_objfile_data = get_breakpoint_objfile_data (objfile); @@ -3666,10 +3692,8 @@ create_exception_master_breakpoint_hook (objfile *objfile) bp_objfile_data->exception_msym = debug_hook; } - addr = bp_objfile_data->exception_msym.value_address (); - addr = gdbarch_convert_from_func_ptr_addr - (gdbarch, addr, current_inferior ()->top_target ()); - b = create_internal_breakpoint (gdbarch, addr, bp_exception_master); + b = create_internal_breakpoint (gdbarch, bp_objfile_data->exception_msym, + bp_exception_master); b->locspec = new_explicit_location_spec_function (func_name); b->enable_state = bp_disabled;