From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id KWPXCyyV12pzDTsAWB0awg (envelope-from ) for ; Tue, 20 Oct 2026 12:22:04 -0400 Received: by simark.ca (Postfix, from userid 112) id 2D6051E050; Tue, 20 Oct 2026 12:22:04 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.3 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 91B291E04D for ; Tue, 20 Oct 2026 12:22:03 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3CF1C4A9C025 for ; Tue, 20 Oct 2026 16:22:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3CF1C4A9C025 Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 55D444BC057A for ; Tue, 20 Oct 2026 16:20:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 55D444BC057A Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=efficios.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=efficios.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 55D444BC057A Authentication-Results: sourceware.org; arc=none smtp.remote-ip=158.69.221.121 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1792513259; cv=none; b=s4v+Yeo5m2UosRli1DxEcIDjxybyYzGpPE4QHasbXdgHAgZ3/KxdmilsADeSXy+99y1l8kqSpktv1Jjr9bKkzU1iOip9m9eSXwa+zyJ7Ou+A5vimFiZ7onZUY528HZ5QiGqQvsvsWAvYpC6+wM+kraSnBPB3CMEJdJi79hvrMhA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1792513259; c=relaxed/simple; bh=dov2BpCtVK6V3hOXmX2SIqlIE/1H6FBX5LJCjH8PWQc=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=M0vVmFmFsUXCTV80NhHZUmTyKWBwSj8v/SCW2b6Y+KNjZJ1BiFYSRc1QZGupZPYbm+hqSEX/Zb0lUie2ia5lAT7op4Ni79GWe4OKTj1hZJae++Ytb8JeIgR6fwaeH8jIQGcvHgwq5/+A8r6U/V2Uo/YJGk4bTjyPZMtZ6fjfxiQ= ARC-Authentication-Results: i=1; sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 55D444BC057A Received: by simark.ca (Postfix) id 3EFB61E06B; Tue, 20 Oct 2026 12:20:58 -0400 (EDT) From: Simon Marchi To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 03/13] gdb: modernize mangled_name_to_comp and cp_class_name_from_physname Date: Tue, 20 Oct 2026 12:17:25 -0400 Message-ID: <20261020162054.2140671-4-simon.marchi@efficios.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261020162054.2140671-1-simon.marchi@efficios.com> References: <20261020162054.2140671-1-simon.marchi@efficios.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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~public-inbox=simark.ca@sourceware.org - Move gdb_cplus_demangle_v3_components above mangled_name_to_comp, removing the need for a forward declaration. - Use nullptr instead of NULL, and fix the indentation of a return statement in mangled_name_to_comp. - In cp_class_name_from_physname, declare variables where they are initialized, use bool instead of int for the loop flag, use for loops instead of while loops to reduce the scope of the loop variables, and return early when no class name is found. Change-Id: I35be6a6907b15e353a5042e77f4fc6d168039c92 --- gdb/cp-support.c | 95 +++++++++++++++++++++--------------------------- 1 file changed, 42 insertions(+), 53 deletions(-) diff --git a/gdb/cp-support.c b/gdb/cp-support.c index 80f3f14c4086..3ddbc4083745 100644 --- a/gdb/cp-support.c +++ b/gdb/cp-support.c @@ -75,9 +75,6 @@ static void canonicalization_ftype *finder, void *data); -static demangle_parse_info_up gdb_cplus_demangle_v3_components - (const char *mangled, int options); - /* A convenience function to copy STRING into OBSTACK, returning a pointer to the newly allocated string and saving the number of bytes saved in LEN. @@ -664,6 +661,25 @@ cp_canonicalize_string (const char *string) return us; } +/* A wrapper for cplus_demangle_v3_components that forces + DMGL_VERBOSE. */ + +static demangle_parse_info_up +gdb_cplus_demangle_v3_components (const char *mangled, int options) +{ + void *storage; + demangle_component *tree + = cplus_demangle_v3_components (mangled, options | DMGL_VERBOSE, + &storage); + if (tree == nullptr) + return nullptr; + + auto info = std::make_unique (); + info->tree = tree; + info->demangler_storage.reset (storage); + return info; +} + /* Convert a mangled name to a demangle_component tree. OPTIONS is passed to the demangler. @@ -685,18 +701,17 @@ mangled_name_to_comp (const char *mangled_name, int options) /* If it doesn't, or if that failed, then try to demangle the name. */ - gdb::unique_xmalloc_ptr demangled_name = gdb_demangle (mangled_name, - options); - if (demangled_name == NULL) - return NULL; + gdb::unique_xmalloc_ptr demangled_name + = gdb_demangle (mangled_name, options); + if (demangled_name == nullptr) + return nullptr; /* If we could demangle the name, parse it to build the component tree. */ demangle_parse_info_up info = cp_demangled_name_to_comp (demangled_name.get ()); - - if (info == NULL) - return NULL; + if (info == nullptr) + return nullptr; info->demangled_name = std::move (demangled_name); return info; @@ -707,20 +722,15 @@ mangled_name_to_comp (const char *mangled_name, int options) gdb::unique_xmalloc_ptr cp_class_name_from_physname (const char *physname) { - gdb::unique_xmalloc_ptr ret; - struct demangle_component *ret_comp, *prev_comp, *cur_comp; demangle_parse_info_up info = mangled_name_to_comp (physname, DMGL_ANSI); - int done; - if (info == nullptr) return nullptr; - done = 0; - ret_comp = info->tree; + demangle_component *ret_comp = info->tree; /* First strip off any qualifiers, if we have a function or method. */ - while (!done) + for (bool done = false; !done;) switch (ret_comp->type) { case DEMANGLE_COMPONENT_CONST: @@ -733,7 +743,7 @@ cp_class_name_from_physname (const char *physname) ret_comp = d_left (ret_comp); break; default: - done = 1; + done = true; break; } @@ -749,10 +759,9 @@ cp_class_name_from_physname (const char *physname) /* What we have now should be a name, possibly qualified. Additional qualifiers could live in the left subtree or the right subtree. Find the last piece. */ - done = 0; - prev_comp = NULL; - cur_comp = ret_comp; - while (!done) + demangle_component *prev_comp = nullptr; + demangle_component *cur_comp = ret_comp; + for (bool done = false; !done;) switch (cur_comp->type) { case DEMANGLE_COMPONENT_QUAL_NAME: @@ -766,24 +775,23 @@ cp_class_name_from_physname (const char *physname) case DEMANGLE_COMPONENT_DTOR: case DEMANGLE_COMPONENT_OPERATOR: case DEMANGLE_COMPONENT_EXTENDED_OPERATOR: - done = 1; + done = true; break; default: - done = 1; - cur_comp = NULL; + done = true; + cur_comp = nullptr; break; } - if (cur_comp != NULL && prev_comp != NULL) - { - /* We want to discard the rightmost child of PREV_COMP. */ - *prev_comp = *d_left (prev_comp); - /* The ten is completely arbitrary; we don't have a good - estimate. */ - ret = cp_comp_to_string (ret_comp, 10); - } + if (cur_comp == nullptr || prev_comp == nullptr) + return nullptr; - return ret; + /* We want to discard the rightmost child of PREV_COMP. */ + *prev_comp = *d_left (prev_comp); + + /* The ten is completely arbitrary; we don't have a good + estimate. */ + return cp_comp_to_string (ret_comp, 10); } /* Return the child of COMP which is the basename of a method, @@ -1650,25 +1658,6 @@ gdb_cplus_demangle_print (int options, estimated_length, &allocated_size)); } -/* A wrapper for cplus_demangle_v3_components that forces - DMGL_VERBOSE. */ - -static demangle_parse_info_up -gdb_cplus_demangle_v3_components (const char *mangled, int options) -{ - void *storage; - demangle_component *tree - = cplus_demangle_v3_components (mangled, options | DMGL_VERBOSE, - &storage); - if (tree == nullptr) - return nullptr; - - auto info = std::make_unique (); - info->tree = tree; - info->demangler_storage.reset (storage); - return info; -} - /* See cp-support.h. */ unsigned int -- 2.56.0