From patchwork Wed Mar 20 20:23:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 87426 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 14CCB3858C60 for ; Wed, 20 Mar 2024 20:24:36 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-il1-x12a.google.com (mail-il1-x12a.google.com [IPv6:2607:f8b0:4864:20::12a]) by sourceware.org (Postfix) with ESMTPS id 6368F3858D1E for ; Wed, 20 Mar 2024 20:24:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6368F3858D1E Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6368F3858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::12a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710966243; cv=none; b=UNW/9+Jpprqfc+OgVV0mboQs0PbkJFou7ENF46IwUXsLlgwlqDhHYq5siBIOLFcqHfkGPf3EtAWYWlN8mEGKh8u8agAh7wpTA94kmNCZvDlWMdsPwkj2v4dkWHUwYXWhqo2cBuzZWOJjebn+tSNEiLLLuj6dcl5H8BHRo1mjxqk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710966243; c=relaxed/simple; bh=aS1/qGo3Aew215lGPwek98UBh8L+CSVzq53rxyTOyJM=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=T6v0DiWT3LdsTJ5HsGRI9Z+c7XWbm4iAgbEWr+ewi2DvSnWPOcxNFCmmbXZ7L9NxnsWB8T6Lusgk0r1WRngX8e3dqday1RBOhxOqi7y7I5xma24ypDxNDgi1ZM7ZUrTZ+x/dTzgh8bmWqWBkWKE0A4osQtG3LkKqIAQt5MQylPY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-il1-x12a.google.com with SMTP id e9e14a558f8ab-3685f40712aso1152655ab.0 for ; Wed, 20 Mar 2024 13:24:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1710966240; x=1711571040; darn=sourceware.org; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=wy0xk7IxLpGpZi91uVw7bWDYvO4xd/6WeA7653F8kM4=; b=fNM5uWnxUydkpkl/7+VEkv1359S4V03tkW1eOr3swx+41QyqjVQsruqT7b/K5dOVDg aWyh1tc3vXwpY3V3bsXiqauBqZQpBr7LHHFzKzM3eIUrZImsh0QC6WAVrBGlRH7vimHG /6oSsjtQ9K3w5inYtt/I0iHiFvR57o1kYfEq2W68c6elZ5zrqDXfvKueb8f/juZNIap7 lx1TU7h5wiJUE896wjwg7drYyuWqeoQ7kQzbMm+K4a50aD5JIVnCsJoQ4KGLWIAOrieT F47Ye0QC3s7wTBXLTgFotl9cI04JY26tRAZgoo26O4bgE4LwhYS8dct+SYWuTfyiRYPA s7Sw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710966240; x=1711571040; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wy0xk7IxLpGpZi91uVw7bWDYvO4xd/6WeA7653F8kM4=; b=cn2oOEKV2omRwM8f/HqRkRpovacg6ntjPak++kpzZOWl/o1XPp78ObCKUVsRF3W+wK sQAKOEfY1tzndsDfr3B+FsLE5Z41j45RTQMZZNqodzJd6TbZEJhQbsfrRp2MrIbThVd+ StjE2ZU1LCmzd67qszj9qTl8O6Rq/2cdVD+pt1c+gsPAqbo5sb1gm+F2sIlhmp1clf4W WIxtJczF+XuSy6vCOQPukDUvwfP/xFVIflIjP0v/hL23y+ZdL9vzaosKbAdHrb/s9Lg6 A2MbM9P/iSpCyjYa6rSQQ3gw9AirFSSztpQW6Sh/sDIfVhD/1IYJ48z1Un1tjYktHrlQ f5aA== X-Gm-Message-State: AOJu0YxJmRPuJa7HonUOK9U2DIIVK57GyST1vvHbwIlI9RAQ524HenJa goNhdWWmZmNDSwqKxLxRhzPzDqIP3fCpbflX5EhzHL7xZK3CatRhQ7e2Xgk1i0lBf6eaNEgvjNQ = X-Google-Smtp-Source: AGHT+IEmZ+lnJz9I2XAb9h8KlwAW8ABPQLAXhucgm9xLsbNBfzBVN9J8drhcTTR4NFy0rzTEYpEz2Q== X-Received: by 2002:a05:6e02:c93:b0:365:c6ae:c40e with SMTP id b19-20020a056e020c9300b00365c6aec40emr93224ile.0.1710966240519; Wed, 20 Mar 2024 13:24:00 -0700 (PDT) Received: from localhost.localdomain (97-122-82-115.hlrn.qwest.net. [97.122.82.115]) by smtp.gmail.com with ESMTPSA id eq4-20020a0566384e2400b00474f719b8c3sm3708441jab.33.2024.03.20.13.24.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Mar 2024 13:24:00 -0700 (PDT) From: Tom Tromey Date: Wed, 20 Mar 2024 14:23:58 -0600 Subject: [PATCH 1/3] Some constification in psymtab MIME-Version: 1.0 Message-Id: <20240320-bcache-type-v1-1-fe616105e9ae@adacore.com> References: <20240320-bcache-type-v1-0-fe616105e9ae@adacore.com> In-Reply-To: <20240320-bcache-type-v1-0-fe616105e9ae@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.4 X-Spam-Status: No, score=-11.1 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, T_SCC_BODY_TEXT_LINE 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 This patch changes some spots in psymtab.[ch] to use 'const'. This is just preparation for a subsequent patch. Note that psymbols are conceptually const, and since they were changed to be objfile-indepdendent, they are truly never modified -- which is what makes this patch reasonably short. --- gdb/psymtab.c | 59 ++++++++++++++++++++++++++++------------------------------- gdb/psymtab.h | 4 ++-- 2 files changed, 30 insertions(+), 33 deletions(-) diff --git a/gdb/psymtab.c b/gdb/psymtab.c index a831e5eec40..f1aabd5b10b 100644 --- a/gdb/psymtab.c +++ b/gdb/psymtab.c @@ -37,18 +37,15 @@ #include #include "gdbsupport/buildargv.h" -static struct partial_symbol *lookup_partial_symbol (struct objfile *, - struct partial_symtab *, - const lookup_name_info &, - int, - domain_search_flags); +static const struct partial_symbol *lookup_partial_symbol + (struct objfile *, struct partial_symtab *, const lookup_name_info &, + int, domain_search_flags); static const char *psymtab_to_fullname (struct partial_symtab *ps); -static struct partial_symbol *find_pc_sect_psymbol (struct objfile *, - struct partial_symtab *, - CORE_ADDR, - struct obj_section *); +static const struct partial_symbol *find_pc_sect_psymbol + (struct objfile *, struct partial_symtab *, CORE_ADDR, + struct obj_section *); static struct compunit_symtab *psymtab_to_symtab (struct objfile *objfile, struct partial_symtab *pst); @@ -117,7 +114,7 @@ find_pc_sect_psymtab_closer (struct objfile *objfile, { if (pc >= tpst->text_low (objfile) && pc < tpst->text_high (objfile)) { - struct partial_symbol *p; + const struct partial_symbol *p; CORE_ADDR this_addr; /* NOTE: This assumes that every psymbol has a @@ -212,12 +209,12 @@ psymbol_functions::find_pc_sect_compunit_symtab /* Find which partial symbol within a psymtab matches PC and SECTION. Return NULL if none. */ -static struct partial_symbol * +static const struct partial_symbol * find_pc_sect_psymbol (struct objfile *objfile, struct partial_symtab *psymtab, CORE_ADDR pc, struct obj_section *section) { - struct partial_symbol *best = NULL; + const struct partial_symbol *best = NULL; CORE_ADDR best_pc; const CORE_ADDR textlow = psymtab->text_low (objfile); @@ -229,7 +226,7 @@ find_pc_sect_psymbol (struct objfile *objfile, /* Search the global symbols as well as the static symbols, so that find_pc_partial_function doesn't use a minimal symbol and thus cache a bad endaddr. */ - for (partial_symbol *p : psymtab->global_psymbols) + for (const partial_symbol *p : psymtab->global_psymbols) { if (p->domain == VAR_DOMAIN && p->aclass == LOC_BLOCK @@ -249,7 +246,7 @@ find_pc_sect_psymbol (struct objfile *objfile, } } - for (partial_symbol *p : psymtab->static_psymbols) + for (const partial_symbol *p : psymtab->static_psymbols) { if (p->domain == VAR_DOMAIN && p->aclass == LOC_BLOCK @@ -289,7 +286,7 @@ psymbol_functions::lookup_global_symbol_language (struct objfile *objfile, for (partial_symtab *ps : partial_symbols (objfile)) { - struct partial_symbol *psym; + const struct partial_symbol *psym; if (ps->readin_p (objfile)) continue; @@ -307,7 +304,7 @@ psymbol_functions::lookup_global_symbol_language (struct objfile *objfile, /* Returns true if PSYM matches LOOKUP_NAME. */ static bool -psymbol_name_matches (partial_symbol *psym, +psymbol_name_matches (const partial_symbol *psym, const lookup_name_info &lookup_name) { const language_defn *lang = language_def (psym->ginfo.language ()); @@ -320,14 +317,14 @@ psymbol_name_matches (partial_symbol *psym, LOOKUP_NAME. Check the global symbols if GLOBAL, the static symbols if not. */ -static struct partial_symbol * +static const struct partial_symbol * lookup_partial_symbol (struct objfile *objfile, struct partial_symtab *pst, const lookup_name_info &lookup_name, int global, domain_search_flags domain) { - struct partial_symbol **start, **psym; - struct partial_symbol **top, **real_top, **bottom, **center; + const struct partial_symbol **start, **psym; + const struct partial_symbol **top, **real_top, **bottom, **center; int length = (global ? pst->global_psymbols.size () : pst->static_psymbols.size ()); @@ -497,11 +494,11 @@ psymbol_functions::forget_cached_source_info (struct objfile *objfile) static void print_partial_symbols (struct gdbarch *gdbarch, struct objfile *objfile, - const std::vector &symbols, + const std::vector &symbols, const char *what, struct ui_file *outfile) { gdb_printf (outfile, " %s partial symbols:\n", what); - for (partial_symbol *p : symbols) + for (const partial_symbol *p : symbols) { QUIT; gdb_printf (outfile, " `%s'", p->ginfo.linkage_name ()); @@ -830,15 +827,15 @@ recursively_search_psymtabs } } - partial_symbol **gbound = (ps->global_psymbols.data () - + ps->global_psymbols.size ()); - partial_symbol **sbound = (ps->static_psymbols.data () - + ps->static_psymbols.size ()); - partial_symbol **bound = gbound; + const partial_symbol **gbound = (ps->global_psymbols.data () + + ps->global_psymbols.size ()); + const partial_symbol **sbound = (ps->static_psymbols.data () + + ps->static_psymbols.size ()); + const partial_symbol **bound = gbound; /* Go through all of the symbols stored in a partial symtab in one loop. */ - partial_symbol **psym = ps->global_psymbols.data (); + const partial_symbol **psym = ps->global_psymbols.data (); if ((search_flags & SEARCH_GLOBAL_BLOCK) == 0) { @@ -1006,7 +1003,7 @@ partial_symtab::end () /* Sort the global list; don't sort the static list. */ std::sort (global_psymbols.begin (), global_psymbols.end (), - [] (partial_symbol *s1, partial_symbol *s2) + [] (const partial_symbol *s1, const partial_symbol *s2) { return strcmp_iw_ordered (s1->ginfo.search_name (), s2->ginfo.search_name ()) < 0; @@ -1075,7 +1072,7 @@ partial_symtab::add_psymbol (const partial_symbol &psymbol, return; /* Save pointer to partial symbol in psymtab, growing symtab if needed. */ - std::vector &list + std::vector &list = (where == psymbol_placement::STATIC ? static_psymbols : global_psymbols); @@ -1496,7 +1493,7 @@ maintenance_check_psymtabs (const char *ignore, int from_tty) continue; bv = cust->blockvector (); b = bv->static_block (); - for (partial_symbol *psym : ps->static_psymbols) + for (const partial_symbol *psym : ps->static_psymbols) { /* Skip symbols for inlined functions without address. These may or may not have a match in the full symtab. */ @@ -1518,7 +1515,7 @@ maintenance_check_psymtabs (const char *ignore, int from_tty) } } b = bv->global_block (); - for (partial_symbol *psym : ps->global_psymbols) + for (const partial_symbol *psym : ps->global_psymbols) { lookup_name_info lookup_name (psym->ginfo.search_name (), symbol_name_match_type::SEARCH_NAME); diff --git a/gdb/psymtab.h b/gdb/psymtab.h index 557a7cf4c08..f41f2418639 100644 --- a/gdb/psymtab.h +++ b/gdb/psymtab.h @@ -444,7 +444,7 @@ struct partial_symtab improve access. Binary search will be the usual method of finding a symbol within it. */ - std::vector global_psymbols; + std::vector global_psymbols; /* Static symbol list. This list will *not* be sorted after readin; to find a symbol in it, exhaustive search must be used. This is @@ -453,7 +453,7 @@ struct partial_symtab to take a *lot* of time; check) or an error (and we don't care how long errors take). */ - std::vector static_psymbols; + std::vector static_psymbols; /* True if the name of this partial symtab is not a source file name. */