From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by sourceware.org (Postfix) with ESMTPS id 8C541385843F for ; Fri, 11 Oct 2024 14:35:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8C541385843F 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 8C541385843F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728657345; cv=none; b=c/x+jhZFmbojBb3n6h9XUHJYv/hjP9vXDDR8SIYMk/H5g3a6N0FcFr+x1peAkIRMug4NgbCg5K6E5ospdOaoTzlYWue+Wx/2MVbqpseetRLNjgmQlX8rFoj39DfnE6H9PMZ0qQ8qNhadwIkNrSkk3VGu3MHIzeyaO9fDHT7ni1Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728657345; c=relaxed/simple; bh=OXmf0pVn9xg0HECF476uM5CVXmNR+Tsss0xGbIeTw0w=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-Id:MIME-Version; b=duVyLqwA8Jzu85khRpgJ/KBcymYqv+5lIAds92LYvsE+LlKo8RIlRIvrOI/xsEkqqtdlWYWPAKm6VpcMLKFXUZ7N8zxO7JgxQ9GwxVSCmUf36y4y03MzbJ3JJE+YzFagn+rFFRNHHF5YYIDiOT6oKHVAyXgng6VD6ev2nhwXU8M= 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 7978F22027 for ; Fri, 11 Oct 2024 14:35:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1728657342; 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=wP/WWZ9J6t6UGhISCumAqmtXKdyRnasNEf1q9A9wGkk=; b=AoEt5pqOidBp2OGmfa0nVdo+wSo0ypYnogF9vTNOOFMiptIHQETLiLtPW0C1P4fQ6jEPZM astjAsjimvGV8FfXYUORhVzqL0BVMfdVSAzU9yilibetUkL5jrS05oPItaQo3m6T3tluaJ a2DLbJYhklFb6gvb7q/NfZkIL6exxwc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1728657342; 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=wP/WWZ9J6t6UGhISCumAqmtXKdyRnasNEf1q9A9wGkk=; b=DkKKbQaxzU+1qgmTyK62wkYNHqREuQGNuxUZHZ5R+nQvebPIHBoCEopSo05M8jUMRlTzqB iOP0eiUiizDFGdDA== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=AoEt5pqO; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=DkKKbQax DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1728657342; 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=wP/WWZ9J6t6UGhISCumAqmtXKdyRnasNEf1q9A9wGkk=; b=AoEt5pqOidBp2OGmfa0nVdo+wSo0ypYnogF9vTNOOFMiptIHQETLiLtPW0C1P4fQ6jEPZM astjAsjimvGV8FfXYUORhVzqL0BVMfdVSAzU9yilibetUkL5jrS05oPItaQo3m6T3tluaJ a2DLbJYhklFb6gvb7q/NfZkIL6exxwc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1728657342; 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=wP/WWZ9J6t6UGhISCumAqmtXKdyRnasNEf1q9A9wGkk=; b=DkKKbQaxzU+1qgmTyK62wkYNHqREuQGNuxUZHZ5R+nQvebPIHBoCEopSo05M8jUMRlTzqB iOP0eiUiizDFGdDA== 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 62D5113AB0 for ; Fri, 11 Oct 2024 14:35:42 +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 cGzQFr43CWfYFwAAD6G6ig (envelope-from ) for ; Fri, 11 Oct 2024 14:35:42 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH v2 4/5] [gdb] Handle bad alloc in gdb_rl_callback_read_char_wrapper_noexcept Date: Fri, 11 Oct 2024 16:35:43 +0200 Message-Id: <20241011143544.15400-4-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20241011143544.15400-1-tdevries@suse.de> References: <20241011143544.15400-1-tdevries@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 7978F22027 X-Spam-Level: X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[99.99%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; MIME_TRACE(0.00)[0:+]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RCPT_COUNT_ONE(0.00)[1]; ARC_NA(0.00)[]; RCVD_TLS_ALL(0.00)[]; DKIM_TRACE(0.00)[suse.de:+]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; TO_DN_NONE(0.00)[]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; PREVIOUSLY_DELIVERED(0.00)[gdb-patches@sourceware.org]; RCVD_VIA_SMTP_AUTH(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns,suse.de:dkim,suse.de:mid] 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,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: Say we simulate a bad alloc in exceptions_state_mc_init: ... jmp_buf * exceptions_state_mc_init () { + { + static bool throw_bad_alloc = true; + if (throw_bad_alloc) + { + throw_bad_alloc = false; + + va_list dummy; + throw gdb_quit_bad_alloc (gdb_exception_quit ("bad alloc", dummy)); + } + } catchers.emplace_front (); return &catchers.front ().buf; } ... After starting gdb and typing "q", gdb terminates: ... $ gdb -q (gdb) terminate called after throwing an instance of 'gdb_quit_bad_alloc' what(): std::bad_alloc ... because the bad alloc (thrown in TRY_SJLJ) is caught by the noexcept on gdb_rl_callback_read_char_wrapper_noexcept: ... static struct gdb_exception gdb_rl_callback_read_char_wrapper_noexcept () noexcept { struct gdb_exception gdb_expt; /* C++ exceptions can't normally be thrown across readline (unless it is built with -fexceptions, but it won't by default on many ABIs). So we instead wrap the readline call with a sjlj-based TRY/CATCH, and rethrow the GDB exception once back in GDB. */ TRY_SJLJ ... Fix this by renaming gdb_rl_callback_read_char_wrapper_noexcept to gdb_rl_callback_read_char_wrapper_sjlj and calling it from a wrapper function that catches the bad alloc expection: ... static struct gdb_exception gdb_rl_callback_read_char_wrapper_noexcept () noexcept { try { return gdb_rl_callback_read_char_wrapper_sjlj (); } catch (gdb_exception &ex) { return std::move (ex); } } ... getting us instead: ... $ gdb -q (gdb) bad alloc (gdb) q ... Tested on aarch64-linux. --- gdb/event-top.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/gdb/event-top.c b/gdb/event-top.c index cdc7874b7fa..d3cf144958a 100644 --- a/gdb/event-top.c +++ b/gdb/event-top.c @@ -184,7 +184,7 @@ extern "C" void _rl_signal_handler (int); (sjlj-based) C++ exceptions. */ static struct gdb_exception -gdb_rl_callback_read_char_wrapper_noexcept () noexcept +gdb_rl_callback_read_char_wrapper_sjlj () { struct gdb_exception gdb_expt; @@ -229,6 +229,22 @@ gdb_rl_callback_read_char_wrapper_noexcept () noexcept return gdb_expt; } +/* Wrapper around gdb_rl_callback_read_char_wrapper_sjlj to ensure + noexcept. */ + +static struct gdb_exception +gdb_rl_callback_read_char_wrapper_noexcept () noexcept +{ + try + { + return gdb_rl_callback_read_char_wrapper_sjlj (); + } + catch (gdb_exception &ex) + { + return std::move (ex); + } +} + static void gdb_rl_callback_read_char_wrapper (gdb_client_data client_data) { -- 2.35.3