From patchwork Mon Oct 28 12:40:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 99703 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 770E6385840B for ; Mon, 28 Oct 2024 12:41:30 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2a07:de40:b251:101:10:150:64:1]) by sourceware.org (Postfix) with ESMTPS id 0C84E3858D20 for ; Mon, 28 Oct 2024 12:40:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0C84E3858D20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 0C84E3858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a07:de40:b251:101:10:150:64:1 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730119268; cv=none; b=eZdv97YCyPUqVK7K/859qpqg61ZT958MRBNMclYGUnF2OzY1e/8M79t5P+EbRwZyDUDPSENFNfAaBAht30CYaPExf0zgXc/g8/63tox1etWpRGR9I0QnjWVVur80wIdDbZijM1LoiE463pz0MT2a6qgjW3THcpOiB3goUAmI19s= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730119268; c=relaxed/simple; bh=yItWft0QMaWVJx/GRdAh46EH3DVRmplEcJStinq8cB8=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-Id:MIME-Version; b=mt/yu6+fut2XCAaIHyVmx3UiQzyJiaQ6T3YOvDbXB/0kJXNUPrZaKky/e0OuYEB1KUQnp9EEjrRLh3ZbZuX257+i1391Vxwe2vejogYNt4S2YN77xE5IPwmkF/ZZxNy5VDrmgbJWsKwJm8B5ZI1FPB33vtiXJC+WBMkgyfGbAKg= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 08F9821DF8 for ; Mon, 28 Oct 2024 12:40:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1730119256; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sBb6iBZShPaFiHqIhNqtY6+zAmvx0TUo178Y0OxnndA=; b=cSJMdig6sunzPwxPHvSW+m4pQjttKyDw6c+i7V6+9HiKTaXyhbiAP6Y6JSFuTBwgBMNG9Z AdjZC3WetZadRuavPCI+URh78qVh0vQBcIFn8du60U3FZIBTK00wEHqW5Ec0nxoDWoNa0A Giz9YmlYIHqArdhpoZeWgKHOl7RqZMw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1730119256; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sBb6iBZShPaFiHqIhNqtY6+zAmvx0TUo178Y0OxnndA=; b=4LAPqqAA+4NvwVte8z/QnRoc40SQAO17IBpofFTMgZRUKmBeFSMTLrX37y/6oj8LExicLY bipP8FCLgya/6OAg== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=cSJMdig6; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=4LAPqqAA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1730119256; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sBb6iBZShPaFiHqIhNqtY6+zAmvx0TUo178Y0OxnndA=; b=cSJMdig6sunzPwxPHvSW+m4pQjttKyDw6c+i7V6+9HiKTaXyhbiAP6Y6JSFuTBwgBMNG9Z AdjZC3WetZadRuavPCI+URh78qVh0vQBcIFn8du60U3FZIBTK00wEHqW5Ec0nxoDWoNa0A Giz9YmlYIHqArdhpoZeWgKHOl7RqZMw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1730119256; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sBb6iBZShPaFiHqIhNqtY6+zAmvx0TUo178Y0OxnndA=; b=4LAPqqAA+4NvwVte8z/QnRoc40SQAO17IBpofFTMgZRUKmBeFSMTLrX37y/6oj8LExicLY bipP8FCLgya/6OAg== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id E315D13866 for ; Mon, 28 Oct 2024 12:40:55 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id AIUINleGH2cjYAAAD6G6ig (envelope-from ) for ; Mon, 28 Oct 2024 12:40:55 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH 2/2] [gdb] Handle exception when getting result of inferior call Date: Mon, 28 Oct 2024 13:40:40 +0100 Message-Id: <20241028124040.19601-2-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20241028124040.19601-1-tdevries@suse.de> References: <20241028124040.19601-1-tdevries@suse.de> MIME-Version: 1.0 X-Rspamd-Queue-Id: 08F9821DF8 X-Spam-Level: X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[99.99%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; ASN(0.00)[asn:25478, ipnet:::/0, country:RU]; MIME_TRACE(0.00)[0:+]; FROM_HAS_DN(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[gdb-patches@sourceware.org]; RCVD_TLS_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:dkim,suse.de:mid]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; TO_DN_NONE(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; RCPT_COUNT_ONE(0.00)[1]; DKIM_TRACE(0.00)[suse.de:+] X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Rspamd-Action: no action X-Spam-Score: -3.01 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, RCVD_IN_DNSWL_NONE, 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.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~patchwork=sourceware.org@sourceware.org When running test-case gdb.ada/finish-var-size.exp with target board fission, we first run into PR32315 with the finish command (as reported in that PR), and then again with an inferior call: ... (gdb) print pck.get(True) gdb/dwarf2/read.c:5567: internal-error: load_full_comp_unit: \ Assertion `! this_cu->is_debug_types' failed. ... After the assert for the inferior call, we do: ... Quit this debugging session? (y or n) n ... Create a core file of GDB? (y or n) n ... and run into: ... gdb/infcall.c:1613: internal-error: call_function_by_hand_dummy: \ Assertion `retval != NULL' failed. ... So what happened? Instead of aborting for the first assertion, some error is thrown in call_thread_fsm::should_stop during the call to get_call_return_value, at which point the fsm is already set to finished: ... if (stop_stack_dummy == STOP_STACK_DUMMY) { /* Done. */ set_finished (); /* Stash the return value before the dummy frame is popped and registers are restored to what they were before the call.. */ return_value = get_call_return_value (&return_meta_info); } ... The error is caught by run_inferior_call, and returned to call_function_by_hand_dummy. Then in call_function_by_hand_dummy, we do: ... if (call_thread->state != THREAD_EXITED) { /* The FSM should still be the same. */ gdb_assert (call_thread->thread_fsm () == sm); if (call_thread->thread_fsm ()->finished_p ()) { struct value *retval; infcall_debug_printf ("call completed"); ... and end up in the "call completed" branch, asserting that call_thread->thread_fsm ()->return_value != NULL. Indeed the call completed successfully, but we ran into an exception fetching the return value of the call, so it's not there. Fix this by handling the case that an exception was returned by run_inferior_call in the "call completed" branch, getting us instead: ... (gdb) print pck.get(True) gdb/dwarf2/read.c:5567: internal-error: load_full_comp_unit: \ Assertion `! this_cu->is_debug_types' failed. ... Quit this debugging session? (y or n) n ... Create a core file of GDB? (y or n) n Command aborted. (gdb) ... Tested on aarch64-linux. PR gdb/32316 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32316 --- gdb/infcall.c | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/gdb/infcall.c b/gdb/infcall.c index 02e3b385bd7..4998b933520 100644 --- a/gdb/infcall.c +++ b/gdb/infcall.c @@ -1610,25 +1610,29 @@ call_function_by_hand_dummy (struct value *function, maybe_remove_breakpoints (); - gdb_assert (retval != NULL); - /* Destruct the pass-by-ref argument clones. */ call_destructors (dtors_to_invoke, default_return_type); - return retval; + if (e.reason >= 0) + { + gdb_assert (retval != NULL); + return retval; + } } else - infcall_debug_printf ("call did not complete"); + { + infcall_debug_printf ("call did not complete"); - /* Didn't complete. Clean up / destroy the call FSM, and restore the - previous state machine, and handle the error. */ - { - std::unique_ptr finalizing - = call_thread->release_thread_fsm (); - call_thread->set_thread_fsm (std::move (saved_sm)); + /* Didn't complete. Clean up / destroy the call FSM, and restore + the previous state machine, and handle the error. */ + { + std::unique_ptr finalizing + = call_thread->release_thread_fsm (); + call_thread->set_thread_fsm (std::move (saved_sm)); - finalizing->clean_up (call_thread.get ()); - } + finalizing->clean_up (call_thread.get ()); + } + } } } @@ -1638,8 +1642,8 @@ call_function_by_hand_dummy (struct value *function, { const char *name = get_function_name (funaddr, name_buf, sizeof (name_buf)); - - discard_infcall_control_state (inf_status.release ()); + if (inf_status != nullptr) + discard_infcall_control_state (inf_status.release ()); /* We could discard the dummy frame here if the program exited, but it will get garbage collected the next time the program is