From patchwork Fri Oct 11 14:35: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: 98740 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 E23B43857003 for ; Fri, 11 Oct 2024 14:37:11 +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 42BAC3858D26 for ; Fri, 11 Oct 2024 14:35:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 42BAC3858D26 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 42BAC3858D26 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=1728657346; cv=none; b=DMjM22n2b3in8/PalX48ikCXXawmTnQ6B4embw8y7f8snBZ9U27SC5h8f2Oy9Q2SrlbBYx96PHLPOCIFqvcpwUr1eM7icu6FmRHXTxaPGRGSMJLlspYKoOrN8w1GRq9iYIDRLsqBQoeWFMfUlShnJKVZGrL4gJizxwiSuqZvY1I= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728657346; c=relaxed/simple; bh=SJks7EL4f+Q5crL4E31aWKe2ngYqVBNwYdMJrPrPepY=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-Id:MIME-Version; b=nrlSCpcDSzB65NVDIOaM8Z0Uu7SfbH28CoDsvsBIE03vUhEjBD1eD1GGpcRkvf0bNrrIVeeG2rxlArI7dc+bWHWXAkZFBMIaqkxbkdQJu4h3TmyVYdZDpjqby3F6dzcUcLtWZcippXgSXXz57Qx/p/es8k9AOcmLRd26iC+x4uk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from imap1.dmz-prg2.suse.org (unknown [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 26C2A22026 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; bh=fr9yscAWYS3Qk1dODytC8yrg+pBq7yalKJmnok+3O+U=; b=m6z531JaetFDZIB1dNmTDNWcArn2TfDp1evXh+qYU0bdxZc0qEHIi2RxFTQIUbpS9zOqS6 ZwwH6r8XITH/YGPyZeJno82+kJGzY0zK9Hs7tAAh5Mtlc93W6D/YYYe+djPV1wzO6mn9L/ UyiJsPBvc8BBHQRWavrKwPwoSvhpBRo= 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; bh=fr9yscAWYS3Qk1dODytC8yrg+pBq7yalKJmnok+3O+U=; b=iaRFSB2OmbK8UtoFFLbx27ex/xrZ1uymiXw75SlXj+mR/IHXw84K2muGfTpKG4F70qAnZE rJ688KMQ4zSjhICQ== Authentication-Results: smtp-out1.suse.de; none 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; bh=fr9yscAWYS3Qk1dODytC8yrg+pBq7yalKJmnok+3O+U=; b=m6z531JaetFDZIB1dNmTDNWcArn2TfDp1evXh+qYU0bdxZc0qEHIi2RxFTQIUbpS9zOqS6 ZwwH6r8XITH/YGPyZeJno82+kJGzY0zK9Hs7tAAh5Mtlc93W6D/YYYe+djPV1wzO6mn9L/ UyiJsPBvc8BBHQRWavrKwPwoSvhpBRo= 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; bh=fr9yscAWYS3Qk1dODytC8yrg+pBq7yalKJmnok+3O+U=; b=iaRFSB2OmbK8UtoFFLbx27ex/xrZ1uymiXw75SlXj+mR/IHXw84K2muGfTpKG4F70qAnZE rJ688KMQ4zSjhICQ== 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 0BEE2136E0 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 NfpcAb43CWfYFwAAD6G6ig (envelope-from ) for ; Fri, 11 Oct 2024 14:35:42 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH v2 1/5] [gdb] Don't create registry keys in destructor Date: Fri, 11 Oct 2024 16:35:40 +0200 Message-Id: <20241011143544.15400-1-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 X-Spam-Score: -2.80 X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; ARC_NA(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,suse.de:mid]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TO_DN_NONE(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[gdb-patches@sourceware.org]; RCVD_TLS_ALL(0.00)[] X-Spam-Level: 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.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 Creating a registry key using emplace calls new: ... DATA *result = new DATA (std::forward (args)...); ... which can throw a bad alloc, which will terminate gdb if called from a destructor. Fix this in a few places. Tested on aarch64-linux. --- gdb/ada-tasks.c | 33 +++++++++++++++++++++++---------- gdb/objfiles.c | 21 +++++++++++++++------ gdb/solib-svr4.c | 17 ++++++++++++----- gdb/source.c | 23 +++++++++++++++-------- gdb/source.h | 3 ++- gdb/symtab.c | 18 ++++++++++++------ 6 files changed, 79 insertions(+), 36 deletions(-) base-commit: 5bc1b13676bc5eeefc50d25379991f5f9255eb80 diff --git a/gdb/ada-tasks.c b/gdb/ada-tasks.c index d050b269815..6d925e8e86e 100644 --- a/gdb/ada-tasks.c +++ b/gdb/ada-tasks.c @@ -287,18 +287,21 @@ task_to_str (int taskno, const ada_task_info *task_info) } /* Return the ada-tasks module's data for the given program space (PSPACE). - If none is found, add a zero'ed one now. - - This function always returns a valid object. */ + If none is found, add a zero'ed one now, unless !CREATE. */ static struct ada_tasks_pspace_data * -get_ada_tasks_pspace_data (struct program_space *pspace) +get_ada_tasks_pspace_data (struct program_space *pspace, bool create = true) { struct ada_tasks_pspace_data *data; data = ada_tasks_pspace_data_handle.get (pspace); if (data == NULL) - data = ada_tasks_pspace_data_handle.emplace (pspace); + { + if (!create) + return nullptr; + + data = ada_tasks_pspace_data_handle.emplace (pspace); + } return data; } @@ -316,13 +319,18 @@ get_ada_tasks_pspace_data (struct program_space *pspace) not use tasking. */ static struct ada_tasks_inferior_data * -get_ada_tasks_inferior_data (struct inferior *inf) +get_ada_tasks_inferior_data (struct inferior *inf, bool create = true) { struct ada_tasks_inferior_data *data; data = ada_tasks_inferior_data_handle.get (inf); if (data == NULL) - data = ada_tasks_inferior_data_handle.emplace (inf); + { + if (!create) + return nullptr; + + data = ada_tasks_inferior_data_handle.emplace (inf); + } return data; } @@ -1447,7 +1455,10 @@ ada_task_list_changed (struct inferior *inf) static void ada_tasks_invalidate_pspace_data (struct program_space *pspace) { - get_ada_tasks_pspace_data (pspace)->initialized_p = 0; + auto data = get_ada_tasks_pspace_data (pspace, false); + if (data == nullptr) + return; + data->initialized_p = 0; } /* Invalidate the per-inferior data. */ @@ -1455,8 +1466,10 @@ ada_tasks_invalidate_pspace_data (struct program_space *pspace) static void ada_tasks_invalidate_inferior_data (struct inferior *inf) { - struct ada_tasks_inferior_data *data = get_ada_tasks_inferior_data (inf); - + struct ada_tasks_inferior_data *data + = get_ada_tasks_inferior_data (inf, false); + if (data == nullptr) + return; data->known_tasks_kind = ADA_TASKS_UNKNOWN; data->task_list_valid_p = false; } diff --git a/gdb/objfiles.c b/gdb/objfiles.c index 0e076fe36be..d25d34cef6a 100644 --- a/gdb/objfiles.c +++ b/gdb/objfiles.c @@ -82,17 +82,22 @@ objfile_pspace_info::~objfile_pspace_info () xfree (sections); } -/* Get the current svr4 data. If none is found yet, add it now. This - function always returns a valid object. */ +/* Get the current svr4 data. If none is found yet, add it now, unless + !CREATE. */ static struct objfile_pspace_info * -get_objfile_pspace_data (struct program_space *pspace) +get_objfile_pspace_data (struct program_space *pspace, bool create = true) { struct objfile_pspace_info *info; info = objfiles_pspace_data.get (pspace); if (info == NULL) - info = objfiles_pspace_data.emplace (pspace); + { + if (!create) + return nullptr; + + info = objfiles_pspace_data.emplace (pspace); + } return info; } @@ -563,14 +568,18 @@ objfile::~objfile () { symtab_and_line cursal - = get_current_source_symtab_and_line (this->pspace ()); + = get_current_source_symtab_and_line (this->pspace (), false); if (cursal.symtab && cursal.symtab->compunit ()->objfile () == this) clear_current_source_symtab_and_line (this->pspace ()); } /* Rebuild section map next time we need it. */ - get_objfile_pspace_data (m_pspace)->section_map_dirty = 1; + { + auto info = get_objfile_pspace_data (m_pspace, false); + if (info != nullptr) + info->section_map_dirty = 1; + } } diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c index 7999a8e6c7e..f61af431b35 100644 --- a/gdb/solib-svr4.c +++ b/gdb/solib-svr4.c @@ -426,16 +426,21 @@ free_probes_table (struct svr4_info *info) info->probes_table.reset (nullptr); } -/* Get the svr4 data for program space PSPACE. If none is found yet, add it now. - This function always returns a valid object. */ +/* Get the svr4 data for program space PSPACE. If none is found yet, add it + now, unless !CREATE. */ static struct svr4_info * -get_svr4_info (program_space *pspace) +get_svr4_info (program_space *pspace, bool create = true) { struct svr4_info *info = solib_svr4_pspace_data.get (pspace); if (info == NULL) - info = solib_svr4_pspace_data.emplace (pspace); + { + if (!create) + return nullptr; + + info = solib_svr4_pspace_data.emplace (pspace); + } return info; } @@ -1631,7 +1636,9 @@ probes_table_htab_remove_objfile_probes (void **slot, void *info) static void probes_table_remove_objfile_probes (struct objfile *objfile) { - svr4_info *info = get_svr4_info (objfile->pspace ()); + svr4_info *info = get_svr4_info (objfile->pspace (), false); + if (info == nullptr) + return; if (info->probes_table != nullptr) htab_traverse_noresize (info->probes_table.get (), probes_table_htab_remove_objfile_probes, objfile); diff --git a/gdb/source.c b/gdb/source.c index 292d2bf71c5..8476e94bdce 100644 --- a/gdb/source.c +++ b/gdb/source.c @@ -219,29 +219,34 @@ get_lines_to_list (void) } /* A helper to return the current source location object for PSPACE, - creating it if it does not exist. */ + creating it if it does not exist, unless !CREATE. */ static current_source_location * -get_source_location (program_space *pspace) +get_source_location (program_space *pspace, bool create = true) { current_source_location *loc = current_source_key.get (pspace); if (loc == nullptr) - loc = current_source_key.emplace (pspace); + { + if (!create) + return nullptr; + + loc = current_source_key.emplace (pspace); + } return loc; } /* See source.h. */ symtab_and_line -get_current_source_symtab_and_line (program_space *pspace) +get_current_source_symtab_and_line (program_space *pspace, bool create) { symtab_and_line cursal; - current_source_location *loc = get_source_location (pspace); + current_source_location *loc = get_source_location (pspace, create); cursal.pspace = pspace; - cursal.symtab = loc->symtab (); - cursal.line = loc->line (); + cursal.symtab = loc == nullptr ? nullptr : loc->symtab (); + cursal.line = loc == nullptr ? 0 : loc->line (); cursal.pc = 0; cursal.end = 0; @@ -300,7 +305,9 @@ set_current_source_symtab_and_line (const symtab_and_line &sal) void clear_current_source_symtab_and_line (program_space *pspace) { - current_source_location *loc = get_source_location (pspace); + current_source_location *loc = current_source_key.get (pspace); + if (loc == nullptr) + return; loc->set (nullptr, 0); } diff --git a/gdb/source.h b/gdb/source.h index 541ee3b7a12..fc5cb8bad5b 100644 --- a/gdb/source.h +++ b/gdb/source.h @@ -108,9 +108,10 @@ extern int get_first_line_listed (void); extern int get_lines_to_list (void); /* Return the current source file for listing and next line to list. + Don't create a current source location object, unless CREATE. NOTE: The returned sal pc and end fields are not valid. */ extern symtab_and_line get_current_source_symtab_and_line - (program_space *pspace); + (program_space *pspace, bool create = true); /* If the current source file for listing is not set, try and get a default. Usually called before get_current_source_symtab_and_line() is called. diff --git a/gdb/symtab.c b/gdb/symtab.c index a479e920c60..6c6f4da966e 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -102,7 +102,7 @@ static struct block_symbol const domain_search_flags domain); static void set_main_name (program_space *pspace, const char *name, - language lang); + language lang, bool create = true); /* Type of the data stored on the program space. */ @@ -1756,7 +1756,7 @@ symtab_all_objfiles_removed (program_space *pspace) symbol_cache_flush (pspace); /* Forget everything we know about the main function. */ - set_main_name (pspace, nullptr, language_unknown); + set_main_name (pspace, nullptr, language_unknown, false); } /* This module's 'free_objfile' observer. */ @@ -6445,15 +6445,18 @@ make_source_files_completion_list (const char *text, const char *word) /* Return the "main_info" object for the current program space. If the object has not yet been created, create it and fill in some - default values. */ + default values, unless !CREATE. */ static main_info * -get_main_info (program_space *pspace) +get_main_info (program_space *pspace, bool create = true) { main_info *info = main_progspace_key.get (pspace); if (info == NULL) { + if (!create) + return nullptr; + /* It may seem strange to store the main name in the progspace and also in whatever objfile happens to see a main name in its debug info. The reason for this is mainly historical: @@ -6467,9 +6470,12 @@ get_main_info (program_space *pspace) } static void -set_main_name (program_space *pspace, const char *name, enum language lang) +set_main_name (program_space *pspace, const char *name, enum language lang, + bool create) { - main_info *info = get_main_info (pspace); + main_info *info = get_main_info (pspace, create); + if (info == nullptr) + return; if (!info->name_of_main.empty ()) { From patchwork Fri Oct 11 14:35:41 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: 98736 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 33AC8385AC2F for ; Fri, 11 Oct 2024 14:36:16 +0000 (GMT) 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.223.131]) by sourceware.org (Postfix) with ESMTPS id 7E1583858C2B for ; Fri, 11 Oct 2024 14:35:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7E1583858C2B 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 7E1583858C2B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728657345; cv=none; b=ObgAFCGTn0HblFrF+hMsltQLUfavAzAv8I9RoOqyLe3Uwvzy3ZtnCd/smQhDtTiCObmmfQLPVbS0BDp3OKbd8wvzNst8+eXB2RwOKnEvc5EZX1GEmh99WtBeoMowFK/66THFc3tqSjAW+GfKq3M8Vq41NxVpoEYDNMosHmQWpsE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728657345; c=relaxed/simple; bh=bWYS6VJaHbrwpQ2B+f3RoRVpfvDDNs9XH6hkh8P61ZI=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-Id:MIME-Version; b=M88JIKkzSrCGsxfMZwj9c0uZnKqHvfisWGIa6Q9C5rnSU7IztrIaIqJWiQBm93IdmYTGe3ng18Iefb6uEiTPpx7Qn/7sujwVdBQNbtp35Q4Ufs0f1cixa5k6qNsXZR+irsCvuU0mhz1nbCL7QEqPE4cC2OdL/DsAnvAeQ72qqHc= 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-out2.suse.de (Postfix) with ESMTPS id 4DE131FC06 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=tuONMGQ/o9i5NpGAbaLlFpTSCGrIJhUso/cfRyp+feI=; b=0k1tEkv1i5Dw+ZDr9mUzs3Om4Rdr6UsNiQ75s5Mq8h6qxC526hfWmgM1lZ0GvPAvi1oi5m qGD9+EF32PNuG38BvJ2gXJopj07aF6OQgygTC2GtucpwaFFzLsXeM0+eWTlUGj+SoGgeWX rMiKCy4dSeOLu3/yZ0HxCymJD7D+x/8= 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=tuONMGQ/o9i5NpGAbaLlFpTSCGrIJhUso/cfRyp+feI=; b=IJPcuLcecBIm+lx9P+N25J4kRLBpoCqvvv1FUXIL1ODx5wGpSSpKFOGN9QBxuE7GOw1kwh 6g0gC/K3KZRkEwBg== Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=0k1tEkv1; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=IJPcuLce 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=tuONMGQ/o9i5NpGAbaLlFpTSCGrIJhUso/cfRyp+feI=; b=0k1tEkv1i5Dw+ZDr9mUzs3Om4Rdr6UsNiQ75s5Mq8h6qxC526hfWmgM1lZ0GvPAvi1oi5m qGD9+EF32PNuG38BvJ2gXJopj07aF6OQgygTC2GtucpwaFFzLsXeM0+eWTlUGj+SoGgeWX rMiKCy4dSeOLu3/yZ0HxCymJD7D+x/8= 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=tuONMGQ/o9i5NpGAbaLlFpTSCGrIJhUso/cfRyp+feI=; b=IJPcuLcecBIm+lx9P+N25J4kRLBpoCqvvv1FUXIL1ODx5wGpSSpKFOGN9QBxuE7GOw1kwh 6g0gC/K3KZRkEwBg== 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 2988A13AAF 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 cGnmCL43CWfYFwAAD6G6ig (envelope-from ) for ; Fri, 11 Oct 2024 14:35:42 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH v2 2/5] [gdb] Handle bad alloc handling in gdb_bfd_open Date: Fri, 11 Oct 2024 16:35:41 +0200 Message-Id: <20241011143544.15400-2-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 X-Rspamd-Queue-Id: 4DE131FC06 X-Spam-Score: -3.01 X-Rspamd-Action: no action 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:rdns, imap1.dmz-prg2.suse.org:helo, suse.de:mid, suse.de:dkim] X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Spam-Level: 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.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 Say we simulate a bad alloc in gdb_bfd_init_data: ... + { + 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)); + } + } gdata = new gdb_bfd_data (abfd, st); ... That works out fine for doing "file a.out" once: ... $ gdb -q -batch -ex "file a.out" bad alloc $ ... but doing so twice get us: ... $ gdb -q -batch -ex "file a.out" -ex "file a.out" bad alloc Fatal signal: Segmentation fault ----- Backtrace ----- 0x5183f7 gdb_internal_backtrace_1 /home/vries/gdb/src/gdb/bt-utils.c:121 0x5183f7 _Z22gdb_internal_backtracev /home/vries/gdb/src/gdb/bt-utils.c:167 0x62329b handle_fatal_signal /home/vries/gdb/src/gdb/event-top.c:917 0x6233ef handle_sigsegv /home/vries/gdb/src/gdb/event-top.c:990 0xfffeffba483f ??? 0x65554c eq_bfd /home/vries/gdb/src/gdb/gdb_bfd.c:231 0xeaca77 htab_find_with_hash /home/vries/gdb/src/libiberty/hashtab.c:597 0x657487 _Z12gdb_bfd_openPKcS0_ib /home/vries/gdb/src/gdb/gdb_bfd.c:580 0x6272d7 _Z16exec_file_attachPKci /home/vries/gdb/src/gdb/exec.c:451 0x627e67 exec_file_command /home/vries/gdb/src/gdb/exec.c:550 0x627f23 file_command /home/vries/gdb/src/gdb/exec.c:565 Segmentation fault (core dumped) $ ... The problem is in gdb_bfd_open, where we insert abfd into gdb_bfd_cache: ... if (bfd_sharing) { slot = htab_find_slot_with_hash (gdb_bfd_cache, &search, hash, INSERT); gdb_assert (!*slot); *slot = abfd; } gdb_bfd_init_data (abfd, &st); ... while the bad alloc means that gdb_bfd_init_data is interrupted and abfd is not properly initialized. Fix this by reversing the order, inserting abfd into gdb_bfd_cache only after a successful call to gdb_bfd_init_data, such that we get: ... $ gdb -q -batch -ex "file a.out" -ex "file a.out" bad alloc $ ... Tested on aarch64-linux. --- gdb/gdb_bfd.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/gdb/gdb_bfd.c b/gdb/gdb_bfd.c index 0854d571ecf..b142f985dcd 100644 --- a/gdb/gdb_bfd.c +++ b/gdb/gdb_bfd.c @@ -587,6 +587,14 @@ gdb_bfd_open (const char *name, const char *target, int fd, host_address_to_string (abfd), bfd_get_filename (abfd)); + /* It's important to pass the already-computed stat info here, + rather than, say, calling gdb_bfd_ref_ptr::new_reference. BFD by + default will "stat" the file each time bfd_get_mtime is called -- + and since we will enter it into the hash table using this + mtime, if the file changed at the wrong moment, the race would + lead to a hash table corruption. */ + gdb_bfd_init_data (abfd, &st); + if (bfd_sharing) { slot = htab_find_slot_with_hash (gdb_bfd_cache, &search, hash, INSERT); @@ -594,13 +602,6 @@ gdb_bfd_open (const char *name, const char *target, int fd, *slot = abfd; } - /* It's important to pass the already-computed stat info here, - rather than, say, calling gdb_bfd_ref_ptr::new_reference. BFD by - default will "stat" the file each time bfd_get_mtime is called -- - and since we already entered it into the hash table using this - mtime, if the file changed at the wrong moment, the race would - lead to a hash table corruption. */ - gdb_bfd_init_data (abfd, &st); return gdb_bfd_ref_ptr (abfd); } From patchwork Fri Oct 11 14:35:42 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: 98739 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 619BE385843F for ; Fri, 11 Oct 2024 14:36:47 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2a07:de40:b251:101:10:150:64:2]) by sourceware.org (Postfix) with ESMTPS id 611863857C5F for ; Fri, 11 Oct 2024 14:35:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 611863857C5F 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 611863857C5F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a07:de40:b251:101:10:150:64:2 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728657346; cv=none; b=auS1xcp3VwLgLLJm7g8Wl0Vyf4Dsk9K4fFElRWKjftgLU5TO8SH63/oq4/GUlD4U82bsbGDzpEedQoUW1z/hR+kswsCrR/4GJ3n8sCW3aKjE6JLl5ImWKOeTqTO+fbJOkvuJwAjE/eT1I7NWD2G00izAqq2+pngzpnpQJCj99vA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728657346; c=relaxed/simple; bh=y/7Tkq0oaVfo5p5APfqS4aq6FbsNAFHqBGTyLO8hJ4U=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-Id:MIME-Version; b=khm7dDVo5W/+C42mNlr4hKVK3Dl7oiTylrHgWJETDNm0gKFuaT4lDdl839iN+fLFYo6ukJXZ4ZfV5C/n/TnzMWQ2yBdufgUWYNgYtYDyej4+z8JUbeqvM5XYq8BUqflSh+DfZy4PViqWKIGe73H2ECI76rSZwnkrWfaNH/djwR8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from imap1.dmz-prg2.suse.org (unknown [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-out2.suse.de (Postfix) with ESMTPS id 5E6471FF09 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=PyIOADEJVE4smIib5GfdbTAvrJjB5uNDHLmsDqrjZ+Y=; b=uo7+53TmL0AOd6dZ1PYPnTqMHyKzfcxI5HMg35gb0knYuT35f2owFlJOsUzZhBfJ1RsTk/ +mAr+NmO2ua8c0LW8ILjoWs7IpRd9uucy9HF+dCz0ziXpn5HhTLkX9PKkwnaYZ39zbcmhG m2GzHeLAu2w2EMe0asbSVMjRqwHmNL8= 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=PyIOADEJVE4smIib5GfdbTAvrJjB5uNDHLmsDqrjZ+Y=; b=UEv2mYRDGIS3EFMna03lorBAf/9111GYsI+Muft4w1MhP1hr3VrMetclg1Vurx/I1/xq0r ORwDUWKxohIg7NCA== Authentication-Results: smtp-out2.suse.de; none 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=PyIOADEJVE4smIib5GfdbTAvrJjB5uNDHLmsDqrjZ+Y=; b=uo7+53TmL0AOd6dZ1PYPnTqMHyKzfcxI5HMg35gb0knYuT35f2owFlJOsUzZhBfJ1RsTk/ +mAr+NmO2ua8c0LW8ILjoWs7IpRd9uucy9HF+dCz0ziXpn5HhTLkX9PKkwnaYZ39zbcmhG m2GzHeLAu2w2EMe0asbSVMjRqwHmNL8= 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=PyIOADEJVE4smIib5GfdbTAvrJjB5uNDHLmsDqrjZ+Y=; b=UEv2mYRDGIS3EFMna03lorBAf/9111GYsI+Muft4w1MhP1hr3VrMetclg1Vurx/I1/xq0r ORwDUWKxohIg7NCA== 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 45A65136E0 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 UJK9D743CWfYFwAAD6G6ig (envelope-from ) for ; Fri, 11 Oct 2024 14:35:42 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH v2 3/5] [gdb] Handle bad alloc in cooked_index_debug_info::do_reading Date: Fri, 11 Oct 2024 16:35:42 +0200 Message-Id: <20241011143544.15400-3-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 X-Spam-Level: X-Spamd-Result: default: False [-2.80 / 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)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; ARC_NA(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:mid,imap1.dmz-prg2.suse.org:helo]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TO_DN_NONE(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[gdb-patches@sourceware.org]; RCVD_TLS_ALL(0.00)[] X-Spam-Score: -2.80 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.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 Say we simulate done_reading throwing a bad alloc in cooked_index_debug_info::do_reading: ... gdb::task_group workers ([this] () { + { + 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)); + } + } this->done_reading (); }); ... This gets gdb to terminate: ... $ gdb -q -batch -ex "file a.out" terminate called after throwing an instance of 'gdb_quit_bad_alloc' ... because the gdb::task_group finalizer is called from the destructor gdb::~task_group. Fix this by catching the exception and storing it in m_failed, as done in cooked_index_worker::start, such that we get: ... $ gdb -q -batch -ex "file a.out" bad alloc $ ... Tested on aarch64-linux. --- gdb/dwarf2/read.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index ea31d8dd851..771be5bfdfe 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -5012,7 +5012,15 @@ cooked_index_debug_info::do_reading () /* Work is done in a task group. */ gdb::task_group workers ([this] () { - this->done_reading (); + try + { + this->done_reading (); + } + catch (gdb_exception &exc) + { + this->m_failed = std::move (exc); + this->set (cooked_state::CACHE_DONE); + } }); auto end = per_bfd->all_units.end (); From patchwork Fri Oct 11 14:35:43 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: 98738 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 A8A363857358 for ; Fri, 11 Oct 2024 14:36:24 +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 [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 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 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 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) { From patchwork Fri Oct 11 14:35:44 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: 98737 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 608D7385AC36 for ; Fri, 11 Oct 2024 14:36:16 +0000 (GMT) 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.223.131]) by sourceware.org (Postfix) with ESMTPS id 7E3873858433 for ; Fri, 11 Oct 2024 14:35:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7E3873858433 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 7E3873858433 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728657345; cv=none; b=H82Drjt7ymQ/o1jbrJbAL7aywyUPNsxlqIK7aTq4cXvtwiajDwRic0Km6nocqx9ZaeGQqfvVlHSdnNoIBh5EywgLyqnC+OSTDUFghNkNpAxU25t/mOH75NJNvxk9izlcsTVArfbhmUWa49LIpDUbQ9ijgcpS7KXZmmitYXsFFwI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728657345; c=relaxed/simple; bh=QApNl3w2RmQ69BBlUuZ92ZTBfGKNKOQRyLl7IK2fKW0=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-Id:MIME-Version; b=oaeCHe8dfKXm9A5ES0n5W2ylRDV8c+s/BEljT+5CdenKxKuGmg9QD7c44rKb9UsNM4RvgtfN/na2Fc1/E5RyrqrgBhz4zXxC87x4sue8SC6Y/n8GlgfWzI1pw9QjyuCuY4e/NW4N1g+JDN0bXzS2KSnzXkCwbO7gtI0oC3Skb8o= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from imap1.dmz-prg2.suse.org (unknown [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-out2.suse.de (Postfix) with ESMTPS id 9631A1FF0C 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=p0R16gg8DITio604nNfuG9oY9QF+gFSEJTr1f4hLcow=; b=1wPidTDDV7zDTYtOScEOO14wEdA7qhZirCpv1BMFAPPy934b8PD6oqCUF7F+uHhklT3Gax 6MbjJfrneFKiXAD0FQyT/q0EjxLzUvAoI0sw2BFdEVwBjVuvAc8D20TqfABkKAjLIrcxBp OhbcrNfVFbYqp+xvomuk8gUAqvuID0M= 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=p0R16gg8DITio604nNfuG9oY9QF+gFSEJTr1f4hLcow=; b=P2hwrjOfwGbOW/vFmpFinEKwCWDlW6Frj6UAnKHt39vJ5XT87hBZJyzns2l23xcDseO9T4 EWeCmgxeXdoTNFAQ== Authentication-Results: smtp-out2.suse.de; none 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=p0R16gg8DITio604nNfuG9oY9QF+gFSEJTr1f4hLcow=; b=1wPidTDDV7zDTYtOScEOO14wEdA7qhZirCpv1BMFAPPy934b8PD6oqCUF7F+uHhklT3Gax 6MbjJfrneFKiXAD0FQyT/q0EjxLzUvAoI0sw2BFdEVwBjVuvAc8D20TqfABkKAjLIrcxBp OhbcrNfVFbYqp+xvomuk8gUAqvuID0M= 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=p0R16gg8DITio604nNfuG9oY9QF+gFSEJTr1f4hLcow=; b=P2hwrjOfwGbOW/vFmpFinEKwCWDlW6Frj6UAnKHt39vJ5XT87hBZJyzns2l23xcDseO9T4 EWeCmgxeXdoTNFAQ== 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 7F546136E0 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 EG7SHb43CWfYFwAAD6G6ig (envelope-from ) for ; Fri, 11 Oct 2024 14:35:42 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH v2 5/5] [gdb] Handle bad alloc in cooked_index_worker::start Date: Fri, 11 Oct 2024 16:35:44 +0200 Message-Id: <20241011143544.15400-5-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 X-Spam-Score: -2.80 X-Spamd-Result: default: False [-2.80 / 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)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; ARC_NA(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:mid,imap1.dmz-prg2.suse.org:helo]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TO_DN_NONE(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[gdb-patches@sourceware.org]; RCVD_TLS_ALL(0.00)[] X-Spam-Level: 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.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 Say we simulate a bad alloc in post_task in cooked_index_worker::start: ... void cooked_index_worker::start () { + { + 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)); + } + } gdb::thread_pool::g_thread_pool->post_task ([=] () ... That makes gdb hang: ... $ gdb -q -batch a.out bad alloc ... because we're waiting for the cooked index to transfer into cooked_state::CACHE_DONE. Fix that by catching the bad alloc in cooked_index_worker::start, and setting the cooked index to cooked_state::CACHE_DONE, as done in the posted task, getting us instead: ... $ gdb -q -batch a.out bad alloc $ ... Tested on aarch64-linux. --- gdb/dwarf2/cooked-index.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/gdb/dwarf2/cooked-index.c b/gdb/dwarf2/cooked-index.c index 4073c924890..51e24b74239 100644 --- a/gdb/dwarf2/cooked-index.c +++ b/gdb/dwarf2/cooked-index.c @@ -465,20 +465,28 @@ cooked_index_shard::find (const std::string &name, bool completing) const void cooked_index_worker::start () { - gdb::thread_pool::g_thread_pool->post_task ([=] () - { - try - { - do_reading (); - } - catch (const gdb_exception &exc) + try + { + gdb::thread_pool::g_thread_pool->post_task ([=] () { - m_failed = exc; - set (cooked_state::CACHE_DONE); - } + try + { + do_reading (); + } + catch (const gdb_exception &exc) + { + m_failed = exc; + set (cooked_state::CACHE_DONE); + } - bfd_thread_cleanup (); - }); + bfd_thread_cleanup (); + }); + } + catch (const gdb_exception &exc) + { + m_failed = exc; + set (cooked_state::CACHE_DONE); + } } /* See cooked-index.h. */