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. */ From patchwork Wed Mar 20 20:23:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 87425 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 C039B385829D for ; Wed, 20 Mar 2024 20:24:35 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd2d.google.com (mail-io1-xd2d.google.com [IPv6:2607:f8b0:4864:20::d2d]) by sourceware.org (Postfix) with ESMTPS id BFE8A3858D28 for ; Wed, 20 Mar 2024 20:24:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BFE8A3858D28 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 BFE8A3858D28 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::d2d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710966243; cv=none; b=QT4vJDGlAmlbI713hVjmzAzF6izjZsG0ser2wmkuO5fZ0LPzO4ljyvZz8AV+55nrbyPKflXwWYEZjWP28hhe8EItdewnyflTV4tR4lKXnJFo1P8uq+Dujiv5wS7+BZ6HI/IvOVvCxGvMd3T/ba8g/uTKQst9xzp8aVJZ7uE86os= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710966243; c=relaxed/simple; bh=PCAZQtBdJmgVzUMYStIcnCAnJUQwjMbP9bNujGF4tYE=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=EklSVHcWVigLrpSUvIeaX3gVdMT7l08J89GU2+qDUrNznIMpM14ZaBeBygBlm1kVhZ8XvJ0REvoBgEjh0vAjP9uzOpzcN+NHtvwuO0VSXrvCI1aVz95WtQN/2MJcgUmjM75J9EaDHxy5MwOnOVor4ohUilJEQMtIkn5sXtowMW8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-io1-xd2d.google.com with SMTP id ca18e2360f4ac-7cc77e74b5cso6941539f.2 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=1710966241; x=1711571041; 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=QJvR9ecuRMvVH3ucwkwjYQ/Nhusk9wgGvkSC2APggxA=; b=XaWH0QkDB5Xnby78YuYVCfJRLWHINIv7OAvuZelMlbBcPVyZ/wp9Y8XjDdOZbv8dMF t2B5wJx1/V5i/TvJ7jTG4ygtJPeINeu/2ewADn4R1kacOQOZ/PUQ2BR2dTeGmeqfaXlH 6fr+KehO9O57Dw7twQPGBuPNhvHEUa2jurW7GscQ7wEk3ZMfR92R08x9Y57exV4/X5NG KYaWNgGi65g9H69tP0Ine9PgAP0zwHpQMZrCQ8Z7TBnfMiILdP8OjCWOwTXYuFgt6lz/ oqaF2mtOTkc4nEoeFplDjOy1jepVVHjeDUCVM38MxR8mtw0erXUBigBugs79UcYCHcBj vl/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710966241; x=1711571041; 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=QJvR9ecuRMvVH3ucwkwjYQ/Nhusk9wgGvkSC2APggxA=; b=okQ8qlOQSi+bfKyrrQ+4GJok4Njz5ZY6HIGO6UVUnpkTsAklXsRaUqAICsRiHxWxsF E4ySjG9SQq19Nr2P4S3oZqoA3bYiSg60HMP9s/ac4prh+cyHKx+fAVoHARR62rIwodCa EKVH9QTjU1lcBl3YLt5kyiyvpIZotmS+m2QgYyijgJzLj5XkrJCo33meZI4fnXogVJcb cGU4x6ctoBTFnx+a+zXBBvHjIjAFhS+Mkfz2gse39voU/usJeI2zGF8SUc26q2Caf9lr 6z74XD7E1zudDhj96MhBCAxE4OSw+8w1maEnApbC1GZhbtOD6FizSwHQFpIJA6dS/KyG MyvA== X-Gm-Message-State: AOJu0YxVk3iGbJumruOanFZK97/COmwyqSQ1Es3X6U8m5D59qkPJsNdl ke/YOfw3jFiAZLTdIlFSuxrEy3QBtbz1Uo2R9PX3ZvtTqs3PjjfR1K0mwjAS5cuO1BANNy4VX/Y = X-Google-Smtp-Source: AGHT+IHOyZcWHJ9MGFyA9/jCNZiRpwHuJ4Q+Ab+lFJMAL+r/OnjCDBBx1xkZEywHeV0Trt/obFOrOA== X-Received: by 2002:a6b:c985:0:b0:7cc:25b:55e9 with SMTP id z127-20020a6bc985000000b007cc025b55e9mr16290559iof.13.1710966240972; 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:59 -0600 Subject: [PATCH 2/3] Make bcache more type-safe MIME-Version: 1.0 Message-Id: <20240320-bcache-type-v1-2-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.2 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 The bcache uses memcpy to make copies of the data passed to it. In C++, this is only safe for trivially-copyable types. This patch changes bcache to require this property, and slightly changes the API to make it easier to use when copying a single object. It also makes the new 'insert' template methods return the correct type. --- gdb/bcache.h | 25 ++++++++++++++++++++++++- gdb/gdbtypes.c | 2 +- gdb/macrotab.c | 12 ++++++------ gdb/psymtab.c | 6 ++---- 4 files changed, 33 insertions(+), 12 deletions(-) diff --git a/gdb/bcache.h b/gdb/bcache.h index 17a09880d99..a77cd005ea6 100644 --- a/gdb/bcache.h +++ b/gdb/bcache.h @@ -152,7 +152,26 @@ struct bcache were newly added to the cache, or to false if the bytes were found in the cache. */ - const void *insert (const void *addr, int length, bool *added = nullptr); + template>> + const T *insert (const T *addr, int length, bool *added = nullptr) + { + return (const T *) this->insert ((const void *) addr, length, added); + } + + /* Find a copy of OBJECT in this bcache. If BCACHE has never seen + those bytes before, add a copy of them to BCACHE. In either + case, return a pointer to BCACHE's copy of that string. Since + the cached value is meant to be read-only, return a const buffer. + If ADDED is not NULL, set *ADDED to true if the bytes were newly + added to the cache, or to false if the bytes were found in the + cache. */ + + template>> + const T *insert (const T &object, bool *added = nullptr) + { + return (const T *) this->insert ((const void *) &object, sizeof (object), + added); + } /* Print statistics on this bcache's memory usage and efficacity at eliminating duplication. TYPE should be a string describing the @@ -173,6 +192,10 @@ struct bcache private: + /* Implementation of the templated 'insert' methods. */ + + const void *insert (const void *addr, int length, bool *added); + /* All the bstrings are allocated here. */ struct obstack m_cache {}; diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index 960a7f49e45..4fcfbc587f6 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -4373,7 +4373,7 @@ check_types_worklist (std::vector *worklist, /* If the type pair has already been visited, we know it is ok. */ - cache->insert (&entry, sizeof (entry), &added); + cache->insert (entry, &added); if (!added) continue; diff --git a/gdb/macrotab.c b/gdb/macrotab.c index 5329d2a5a93..a9c425b63c9 100644 --- a/gdb/macrotab.c +++ b/gdb/macrotab.c @@ -110,8 +110,9 @@ macro_free (void *object, struct macro_table *t) /* If the macro table T has a bcache, then cache the LEN bytes at ADDR there, and return the cached copy. Otherwise, just xmalloc a copy of the bytes, and return a pointer to that. */ -static const void * -macro_bcache (struct macro_table *t, const void *addr, int len) +template +static const U * +macro_bcache (struct macro_table *t, const U *addr, int len) { if (t->bcache) return t->bcache->insert (addr, len); @@ -120,7 +121,7 @@ macro_bcache (struct macro_table *t, const void *addr, int len) void *copy = xmalloc (len); memcpy (copy, addr, len); - return copy; + return (const U *) copy; } } @@ -131,7 +132,7 @@ macro_bcache (struct macro_table *t, const void *addr, int len) static const char * macro_bcache_str (struct macro_table *t, const char *s) { - return (const char *) macro_bcache (t, s, strlen (s) + 1); + return macro_bcache (t, s, strlen (s) + 1); } @@ -572,8 +573,7 @@ new_macro_definition (struct macro_table *t, cached_argv[i] = macro_bcache_str (t, argv[i]); /* Now bcache the array of argument pointers itself. */ - d->argv = ((const char * const *) - macro_bcache (t, cached_argv, cached_argv_size)); + d->argv = macro_bcache (t, cached_argv, cached_argv_size); } /* We don't bcache the entire definition structure because it's got diff --git a/gdb/psymtab.c b/gdb/psymtab.c index f1aabd5b10b..ca638515d61 100644 --- a/gdb/psymtab.c +++ b/gdb/psymtab.c @@ -1062,10 +1062,8 @@ partial_symtab::add_psymbol (const partial_symbol &psymbol, bool added; /* Stash the partial symbol away in the cache. */ - partial_symbol *psym - = ((struct partial_symbol *) - partial_symtabs->psymbol_cache.insert - (&psymbol, sizeof (struct partial_symbol), &added)); + const partial_symbol *psym = partial_symtabs->psymbol_cache.insert (psymbol, + &added); /* Do not duplicate global partial symbols. */ if (where == psymbol_placement::GLOBAL && !added) From patchwork Wed Mar 20 20:24:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 87427 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 5B9CB3858426 for ; Wed, 20 Mar 2024 20:24:59 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-il1-x135.google.com (mail-il1-x135.google.com [IPv6:2607:f8b0:4864:20::135]) by sourceware.org (Postfix) with ESMTPS id 25A493858C41 for ; Wed, 20 Mar 2024 20:24:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 25A493858C41 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 25A493858C41 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::135 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710966243; cv=none; b=Ra+Mj0armgY31kbIpxJwWEN31/jFLYxZtiYgqNaEWi3djwPnELoJLPenTG86Ylej6niK3euJ0LuwYH+0EGvH4AR8+bg48eM1WMG8nKusI10SWiLz83CVBDG4fPWv0uNzvckKt4gwj/2/VGupiz4OkNkOmA/EHkzBvm5vts/tfVI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710966243; c=relaxed/simple; bh=gKRx4DJf0LaFqYh+GdZ2wKPSaTcoXYFVDaEyVclsU0c=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=BLnZzIH+2RpI/vz0at3I1cH8r5ZbOBIsd+nWpfbEc+G/L+wNSdBeNNsDuXbhJl87W+V5f6Tg55LCecpCBvH8kLESQ2hNcHUWXxtJJ+rex4bLMwTzzoU0Y4GvyII0HqDg3M+juF2opPxhYFDL1EQ40ZL7sNxGgLXrU4wN0e+TXTU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-il1-x135.google.com with SMTP id e9e14a558f8ab-3684e301716so1245165ab.3 for ; Wed, 20 Mar 2024 13:24:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1710966241; x=1711571041; 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=vFBhddPQT2V5/Cz6Ov3JnRsCEi58xUKVEV3DrVYsMg0=; b=dmgbMiedkwQkGrITp02VOU76TfuIdt8/HONVFXcKBzueQG7OGV+Aae93LYnxz0eG4V lPpjm//P1KzQO/c36almZA/0ahrALCFxxvdXI2jiEHNNDggDzZVyMGq8JxYEdAMMqwtw Fety+gWP186Mf2mFqAfQHEKMWVAZzEBK3ttFUB/GUO45kzxIZ4SZ5NcXnWk/MHljXtAF dxRdtqwJs53upm42jluO3hdcq3/gvxOUyxLgn+kNVx3hKVrQUUkKML+LUS0vmvPzDV6M 6FIJgVMwJjGhYPVd2huAWiav8rocvWFY3WzcLvv9fB9CFuYJJHl81KHyFpaXiSJrJgqW c9Rg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710966241; x=1711571041; 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=vFBhddPQT2V5/Cz6Ov3JnRsCEi58xUKVEV3DrVYsMg0=; b=RV7UGlCryFR+CPRP/nW4e6SwHZG9MPmOPysHaclstSFhHsfv4mj1ofijPxPuSfjXfx LqENqfMFWqWsF3bAEc1R6+bA0Lwrk56WjRPym+eAlmPtybs2wJk1icD0kH8e4guehnYs Bfyt8pLJprly7eGPByyQT828diKqwfxE438NMybhwR8hA+l9RSm4M/dIxF6M7w1iOR+I PTzftqa7a8/DCtSnah+TAO7uq8EJhnItGj/WQSPQ7Fd9jZP4Oov6Zhx4seWBa7rEEXR4 7GPd3Z5ISPcfzn+0HOoAD+sr6HoUaPgO1JwU9t/ech9Qnj4N/pSE1we7CkEElONx07aA K/ow== X-Gm-Message-State: AOJu0YybKKsq8XVo8VsI+Rqz3KsO8HPoWOGBmp4K0+4x7b1eGM36B9/C DY+PbQW2PaHGoloMXd4h6n6YstZ9ZBXZ5IDEERWLwCLce+vGpyuyt1zxjYNKifTvPJ9oBOigHVs = X-Google-Smtp-Source: AGHT+IHjnVwGXjTGtw1RLopyEccU84MmjkycecCQvOivxT5inL+8BpHTTTrVlsaphjh7onwZyJA3Gw== X-Received: by 2002:a05:6e02:1290:b0:368:5c9b:ad4 with SMTP id y16-20020a056e02129000b003685c9b0ad4mr2029874ilq.10.1710966241350; Wed, 20 Mar 2024 13:24:01 -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.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Mar 2024 13:24:01 -0700 (PDT) From: Tom Tromey Date: Wed, 20 Mar 2024 14:24:00 -0600 Subject: [PATCH 3/3] Remove a couple unnecessary casts MIME-Version: 1.0 Message-Id: <20240320-bcache-type-v1-3-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 After the previous bcache change, a couple of casts in objfiles.h are now redundant. --- gdb/objfiles.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gdb/objfiles.h b/gdb/objfiles.h index 8b8b7182e87..ab655906508 100644 --- a/gdb/objfiles.h +++ b/gdb/objfiles.h @@ -234,14 +234,14 @@ struct objfile_per_bfd_storage const char *intern (const char *str) { - return (const char *) string_cache.insert (str, strlen (str) + 1); + return string_cache.insert (str, strlen (str) + 1); } /* Same as the above, but for an std::string. */ const char *intern (const std::string &str) { - return (const char *) string_cache.insert (str.c_str (), str.size () + 1); + return string_cache.insert (str.c_str (), str.size () + 1); } /* Get the BFD this object is associated to. */