From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id mfiBASHBvWryTCEAWB0awg (envelope-from ) for ; Wed, 30 Sep 2026 22:10:41 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=polymtl.ca header.i=@polymtl.ca header.a=rsa-sha256 header.s=oct2025 header.b=cmaWeqnz; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 0188D1E051; Wed, 30 Sep 2026 22:10:40 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [IPv6:2620:52:6:3111::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 788E21E033 for ; Wed, 30 Sep 2026 22:10:40 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DD3184BB590D for ; Thu, 1 Oct 2026 02:10:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DD3184BB590D Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=polymtl.ca header.i=@polymtl.ca header.a=rsa-sha256 header.s=oct2025 header.b=cmaWeqnz Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id 01D8E4BB58B6 for ; Thu, 1 Oct 2026 02:10:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 01D8E4BB58B6 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=polymtl.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=polymtl.ca ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 01D8E4BB58B6 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=132.207.4.11 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1790820602; cv=none; b=tI9ILjiGLh++sV+fjsrXIBXtt2nNxwsA6H34u2qER3UxBp2zLzG++ZiqPwsUB6Z9SuOOW7676+VJ+q0j21Gqv1CBNJSyybSFLXdgwR0aTZa2nblSW6/Cx6xPeSdLk+Ji0ZSkLXRYNffAoji+r1RuytXHJCHWpH7IYgLPZXsTvCY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1790820602; c=relaxed/simple; bh=dsA7ma/jiIOhrZl0I+Zevu2o/7aRV6hLgAlRJGv1LTg=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=p2mK6ZNNehJP2LQpr7H5RRm8aYTzVvTqhgqalZyWHqc2IaFkIvTj7NepS+fa+8IRiWZT5iA6wtEVM4j/l3kI5ujrQer/PO0nFWk6HrJGuTWmPJHUbmtH/iccFVQc0RjBDxwNp2qkj62GsNIGPwuvvjI+O1dsKr58wOAIxt1NCoE= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=polymtl.ca header.i=@polymtl.ca header.a=rsa-sha256 header.s=oct2025 header.b=cmaWeqnz DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 01D8E4BB58B6 Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 69129tOL167686 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 30 Sep 2026 22:10:00 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 69129tOL167686 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=polymtl.ca; s=oct2025; t=1790820600; bh=Hz0wLsEPX+LtaIlNWDV5TvzQHtvOSI5NjYMjk99T04o=; h=From:To:Cc:Subject:Date:In-Reply-To:From; b=cmaWeqnzXL3hd1+Hx/ezRLkbEQCqFSM6S+59v1itQ4jh94d/ZGrHsZkWzlaNWC0wN 72JPBqbDI6i9YXk82gUDYFiUCzuIE3aw0UGWwOs7FhthngjaUHldjyP6+Gyr8sgIF9 J5v75vCGuutobfllg+raNad/dcWU/GS9jinjQkPYVNN5QylcB8obP/A1HGlSkmwMBv gqlhqc7c9EpGWngOjM4X8lU0R2JY5I4Lza+EE656BjuXoz6qJPSKHgq4Us26KGiDi+ USRkw82yHcjK1m0jZW0jELVnm3QY9OWsJRf+BHA3WPTfu+i73V2veyxk3yTF3n0avn 5z4NZPo14kIPQ== Received: by simark.ca (Postfix) id 67CAB1E090; Wed, 30 Sep 2026 22:09:54 -0400 (EDT) From: simon.marchi@polymtl.ca To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH v2 03/11] gdb: factor out regexp compilation from global_symbol_searcher::search Date: Wed, 30 Sep 2026 22:09:20 -0400 Message-ID: <20261001020952.698419-4-simon.marchi@polymtl.ca> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260929194119.155169-1-simon.marchi@efficios.com> References: <20260929194119.155169-1-simon.marchi@efficios.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Thu, 1 Oct 2026 02:09:55 +0000 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 From: Simon Marchi Factor out the scopes that compile the regexps, in order to make global_symbol_searcher::search itself simpler to read. Factor out a helper to compile a symbol search regex as well. Change-Id: Ie4485b2eb593967069ac635c933df817bc5304e6 --- gdb/symtab.c | 118 ++++++++++++++++++++++++++++++--------------------- gdb/symtab.h | 9 ++++ 2 files changed, 78 insertions(+), 49 deletions(-) diff --git a/gdb/symtab.c b/gdb/symtab.c index aae82218b5cf..49e8719f4ec0 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -4938,66 +4938,86 @@ global_symbol_searcher::add_matching_msymbols return true; } -/* See symtab.h. */ +/* Compile REGEXP, a symbol name or symbol type regexp. -std::vector -global_symbol_searcher::search () const + If REGEXP is nullptr, return an empty optional. */ + +static std::optional +compile_symbol_search_regex (const char *regexp) { - std::optional name_regex; - std::optional type_regex; + if (regexp == nullptr) + return {}; - if (m_symbol_name_regexp != NULL) - { - const char *symbol_name_regexp = m_symbol_name_regexp; - std::string symbol_name_regexp_holder; + int cflags + = REG_NOSUB | (case_sensitivity == case_sensitive_off ? REG_ICASE : 0); - /* Make sure spacing is right for C++ operators. - This is just a courtesy to make the matching less sensitive - to how many spaces the user leaves between 'operator' - and or . */ - const char *op_end; - const char *opname = operator_chars (symbol_name_regexp, &op_end); + return std::make_optional (regexp, cflags, + _("Invalid regexp")); +} - if (*opname) - { - int fix = -1; /* -1 means ok; otherwise number of - spaces needed. */ +/* See symtab.h. */ - if (c_isalpha (*opname) || *opname == '_' || *opname == '$') - { - /* There should 1 space between 'operator' and 'TYPENAME'. */ - if (opname[-1] != ' ' || opname[-2] == ' ') - fix = 1; - } - else - { - /* There should 0 spaces between 'operator' and 'OPERATOR'. */ - if (opname[-1] == ' ') - fix = 0; - } - /* If wrong number of spaces, fix it. */ - if (fix >= 0) - { - symbol_name_regexp_holder - = string_printf ("operator%.*s%s", fix, " ", opname); - symbol_name_regexp = symbol_name_regexp_holder.c_str (); - } - } +std::optional +global_symbol_searcher::compile_name_regex () const +{ + if (m_symbol_name_regexp == nullptr) + return {}; - int cflags = REG_NOSUB | (case_sensitivity == case_sensitive_off - ? REG_ICASE : 0); - name_regex.emplace (symbol_name_regexp, cflags, - _("Invalid regexp")); - } + const char *symbol_name_regexp = m_symbol_name_regexp; + std::string symbol_name_regexp_holder; + + /* Make sure spacing is right for C++ operators. + This is just a courtesy to make the matching less sensitive + to how many spaces the user leaves between 'operator' + and or . */ + const char *op_end; + const char *opname = operator_chars (symbol_name_regexp, &op_end); - if (m_symbol_type_regexp != NULL) + if (*opname) { - int cflags = REG_NOSUB | (case_sensitivity == case_sensitive_off - ? REG_ICASE : 0); - type_regex.emplace (m_symbol_type_regexp, cflags, - _("Invalid regexp")); + /* -1 means ok; otherwise number of spaces needed. */ + int fix = -1; + + if (c_isalpha (*opname) || *opname == '_' || *opname == '$') + { + /* There should 1 space between 'operator' and 'TYPENAME'. */ + if (opname[-1] != ' ' || opname[-2] == ' ') + fix = 1; + } + else + { + /* There should 0 spaces between 'operator' and 'OPERATOR'. */ + if (opname[-1] == ' ') + fix = 0; + } + /* If wrong number of spaces, fix it. */ + if (fix >= 0) + { + symbol_name_regexp_holder + = string_printf ("operator%.*s%s", fix, " ", opname); + symbol_name_regexp = symbol_name_regexp_holder.c_str (); + } } + return compile_symbol_search_regex (symbol_name_regexp); +} + +/* See symtab.h. */ + +std::optional +global_symbol_searcher::compile_type_regex () const +{ + return compile_symbol_search_regex (m_symbol_type_regexp); +} + +/* See symtab.h. */ + +std::vector +global_symbol_searcher::search () const +{ + std::optional name_regex = compile_name_regex (); + std::optional type_regex = compile_type_regex (); + bool found_func_msymbol_without_debug_info = false; std::set result_set; for (objfile &objfile : current_program_space->objfiles ()) diff --git a/gdb/symtab.h b/gdb/symtab.h index e4cfa31e25e7..e60b32230239 100644 --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -2670,6 +2670,15 @@ class global_symbol_searcher of SIZE_MAX, there is no "unlimited". */ size_t m_max_search_results = SIZE_MAX; + /* Compile M_SYMBOL_NAME_REGEXP, if set. + + This function normalizes the spacing when it detects a C++ operator in the + regexp. */ + std::optional compile_name_regex () const; + + /* Compile M_SYMBOL_TYPE_REGEXP, if set. */ + std::optional compile_type_regex () const; + /* Expand symtabs in OBJFILE that match NAME_REGEX, are of type M_KIND. Return true if any msymbols were seen that we should later consider adding to the results list. */ -- 2.55.0