From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id BMRRONyQAGtS4SQAWB0awg (envelope-from ) for ; Fri, 20 Nov 2026 13:26:36 -0500 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=c6RWrv19; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id D5ACD1E023; Fri, 20 Nov 2026 13:26:36 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,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 099021E023 for ; Fri, 20 Nov 2026 13:26:36 -0500 (EST) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8DF5940B3AE4 for ; Fri, 20 Nov 2026 18:26:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8DF5940B3AE4 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=c6RWrv19 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 6A07840B3B51 for ; Fri, 20 Nov 2026 18:26:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6A07840B3B51 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6A07840B3B51 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1795199168; cv=none; b=ANAJ/TMtkGiqUxugb1d1ln03ZUgS2UgK5ji1lpQWk1bQdQqrFDzccHUFlYA2DyorxYLVy6/VW/G6wCbKHCySiUfipZoG7Y1eJJHI+C8BX722Ex+jXVJDh3jS64H8gAczGquoKY8q50nMggV7ULcdu1YJSUYQcVwIllBkMZGkPAg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1795199168; c=relaxed/simple; bh=/A0ZYYL5XWp4aXFAryvjXhCVmEjdfP4ZIwU5fqJ5pNY=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=E4CUkz4zR7bLNcSsYn/zdBxFlKilDzK8qcsFQvi9R6EWVseRNeb8+tEqxWi2eOKCchOey66k4GUF9jLg15ZkeiIw+6OH0Ucly9Q3f7hy/efxqaXvBS28aXy49LMdZJ9X44SCiPiENLtK4uGW/GM/SfQz3vFgfhIwgMrpTvJyVE8= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=c6RWrv19 DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6A07840B3B51 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1795199168; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=cpsil/v7a5TeMHPXA/FBs7LUVUo+vVKma+aYUf1S5hE=; b=c6RWrv19S6KgAnkSTmN0F1w7N7Mu6XU5N9fhWqv7BmcF3wNqvyEyiaeFbVxv18tk/FiTkt uzCCnC3bqnNScemo8wghDKDqMG5Z6IU5a3fd7MxmWvDrHAX5CU/3XLIDCyoVmUlIcVAkYN KTmhSDMOL7/UL595xOJ6N1mi5zDhJWk= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-616-ndymptRHNt-HYDcKnZ2GPA-1; Fri, 20 Nov 2026 18:26:05 +0000 X-MC-Unique: ndymptRHNt-HYDcKnZ2GPA-1 X-Mimecast-MFC-AGG-ID: ndymptRHNt-HYDcKnZ2GPA_1795199164 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-4923b9fdd43so776031f8f.3 for ; Fri, 20 Nov 2026 10:26:05 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795199164; x=1795803964; h=content-type:mime-version:message-id:date:references:in-reply-to :subject:cc:to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to:content-type; bh=cpsil/v7a5TeMHPXA/FBs7LUVUo+vVKma+aYUf1S5hE=; b=UaZMAbjU8fd3N4crJwUFkCjstfuht56sVvGLUROWr4ZPSbSOY453BAeEqChFy9PrGe 5+SbAeFcr0qAore6lozos8rx3VO/RSZo1O3NOTt3Cp7v8qwKCQQYGAq9XVV0k+diqI4o 6lNnDhuD3ckDSlO/+ctoBhJOxPsV+Bsyv4QKhY4kEAGnafvQZ+YIJXybAG4txv9FOSlS sPUP0h14AL+6y9hkhLN6Qyug7zqfMei154ZRCdoEmk+0MHpk5C3AIqjVWMWKeCnggHMu gLtRJqaHF0mOCYV4S+htX+nIs7SA+bkm8bou1Pa1aVvBx6aNxvloNtQ/2g3dYXYJZf1h DmAg== X-Forwarded-Encrypted: i=1; AL+hErGlMM88ytp3IVpZlWECpfhc2iVcmXKuuVjDwL4crQysLxt58Ih1Axdk1V8S8hM9Nd1tVG7krvTvCpTa9Q==@sourceware.org X-Gm-Message-State: APuU4Z/xRH1+R604n5EVKsz3+CSdzkbwJ0HKnuApvQneJTiXsr/ucLZ5 /UVQn8X8BcBWjgtIU+bl1tEGaDgoxG0K8yz9zyjX7/uxkZuflxvMQ60ASjfocvvIIBr0vga1I+c dSiuZfAJ3NmOD9PgDehGWG3emrTNoxlQwevzB/NmFJmL/o5IpRMPkjJIeu7aIR7pOXPXy45s= X-Gm-Gg: AYBFou1nShgOacC5jBP3+AV8BTKhqbmVvfGRg/ClrRrGMx/ZHm9CNvCFasPDUpnnQqs s/CEtOqweIloEY+ALNmLpbSFIPygLtVXblphM4NBwONVbyqaNkIahWua+4SRCH+lIpCnUYjmbXI WCsaD/FiB4XVX5jYscSkToALZa6dM+SPkP+zg8bQjgsZq2K4lD4gTvBLEWNScesvJEY40Amr7zQ bsEpLlUjutB/jvXMsVCfKITNfDCRNWbuGS10VDzWycYp1orKurzpREXuZ2cpxWsoPJI34MPDZk+ LieHVzBo/nmzkw4pmg2h0lbyATqluzGyB67z+EjDyHHKoDpDo1QFBhYzSI5FSTMY38bjpim0B6M LvkGfqNZeYuku6D7q8bLT6TY85Q4HN9kIAqJLCIrfhVZ0GQ== X-Received: by 2002:a05:600c:154c:b0:4a2:1364:252a with SMTP id 5b1f17b1804b1-4bb887c28a8mr93538255e9.3.1795199164164; Fri, 20 Nov 2026 10:26:04 -0800 (PST) X-Received: by 2002:a05:600c:154c:b0:4a2:1364:252a with SMTP id 5b1f17b1804b1-4bb887c28a8mr93537615e9.3.1795199163660; Fri, 20 Nov 2026 10:26:03 -0800 (PST) Received: from localhost ([83.216.138.189]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb884b8429sm162722885e9.14.2026.11.20.10.26.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Nov 2026 10:26:03 -0800 (PST) From: Andrew Burgess To: Sendao Yan , gdb-patches@sourceware.org Cc: tom@tromey.com, yansendao@126.com Subject: Re: [PATCH] [gdb/symtab] Fall back to symtabs when the quick lookup misses In-Reply-To: <20261120091803.89033-1-yansendao@126.com> References: <20261120091803.89033-1-yansendao@126.com> Date: Fri, 20 Nov 2026 18:26:01 +0000 Message-ID: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: IcGO5xBMz6_TxUSB4X02ej6VKt-zZIGsGsIV5YZzqe4_1795199164 X-Mimecast-Originator: redhat.com Content-Type: text/plain 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 Sendao Yan writes: > lookup_symbol_in_objfile has only searched the cooked index since commit > 86ac8c546235 ("Convert lookup_symbol_in_objfile"). The index stores the > DWARF spelling of a name, so a DWARF5 static constexpr member of a > template instantiation can be missed when the C++ expression evaluator > looks it up using canonicalised template arguments: GCC records > std::ratio<1, 1> but the lookup uses std::ratio<1l, 1l>. > > This makes libstdc++'s chrono pretty-printer fail with > "gdb.error: value has been optimized out" when printing > std::chrono::hh_mm_ss (PR symtab/33533, GCC PR 128817). > > Walk the expanded symtabs as a fallback when the quick lookup returns > nothing, restoring the behaviour that existed before 86ac8c546235 while > keeping the quick lookup as the fast path. > > Add gdb.cp/static-const-template.exp, which prints a static constexpr > member of a class template with a long non-type template parameter. With > the unpatched gdb it fails with ; with the fix it passes. > > Verified with the GCC testcase libstdc++-prettyprinters/chrono.cc > (print hms/hms_nano, also with -flto), the new test, and the existing > gdb.dwarf2/static-const-member.exp, gdb.cp/m-static.exp, > gdb.cp/namespace.exp and gdb.base/condbreak-multi-context.exp. > > Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33533 > --- > gdb/symtab.c | 20 +++++++++- > gdb/testsuite/gdb.cp/static-const-template.cc | 33 +++++++++++++++ > .../gdb.cp/static-const-template.exp | 40 +++++++++++++++++++ > 3 files changed, 91 insertions(+), 2 deletions(-) > create mode 100644 gdb/testsuite/gdb.cp/static-const-template.cc > create mode 100644 gdb/testsuite/gdb.cp/static-const-template.exp > > diff --git a/gdb/symtab.c b/gdb/symtab.c > index dc40fbfadf6..13a275c3fcc 100644 > --- a/gdb/symtab.c > +++ b/gdb/symtab.c > @@ -2501,8 +2501,9 @@ lookup_symbol_in_static_block (const char *name, > } > > /* Perform the standard symbol lookup of NAME in OBJFILE: > - 1) First search expanded symtabs, and if not found > - 2) Search the "quick" symtabs (partial or .gdb_index). > + 1) First search the "quick" symtabs (partial or .gdb_index), and if not > + found > + 2) Search the expanded symtabs. > BLOCK_INDEX is one of GLOBAL_BLOCK or STATIC_BLOCK. */ > > static struct block_symbol > @@ -2521,6 +2522,21 @@ lookup_symbol_in_objfile (struct objfile *objfile, enum block_enum block_index, > > result = lookup_symbol_via_quick_fns (objfile, block_index, > name, domain); > + if (result.symbol == NULL) GDB uses 'nullptr' not NULL for new code. > + { > + /* The cooked index does not necessarily contain every symbol that > + the expanded symtabs do. In particular, GCC emits a DWARF5 > + DW_TAG_variable for a static constexpr member using the DWARF > + spelling of the enclosing template arguments (e.g. > + std::ratio<1, 1>), while the C++ expression evaluator looks the > + member up using the canonical spelling (std::ratio<1l, 1l>), so > + the quick lookup misses it. Fall back to walking the symtabs, > + which was the behaviour before commit 86ac8c546235. > + > + PR symtab/33533. */ > + result = lookup_symbol_in_objfile_symtabs (objfile, block_index, > + name, domain); > + } > symbol_lookup_debug_printf ("lookup_symbol_in_objfile (...) = %s", > result.symbol != NULL > ? host_address_to_string (result.symbol) > diff --git a/gdb/testsuite/gdb.cp/static-const-template.cc b/gdb/testsuite/gdb.cp/static-const-template.cc > new file mode 100644 > index 00000000000..036e6b3b593 > --- /dev/null > +++ b/gdb/testsuite/gdb.cp/static-const-template.cc > @@ -0,0 +1,33 @@ > +/* Copyright 2026 Free Software Foundation, Inc. > + > + This program is free software; you can redistribute it and/or modify > + it under the terms of the GNU General Public License as published by > + the Free Software Foundation; either version 3 of the License, or > + (at your option) any later version. > + > + This program is distributed in the hope that it will be useful, > + but WITHOUT ANY WARRANTY; without even the implied warranty of > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > + GNU General Public License for more details. > + > + You should have received a copy of the GNU General Public License > + along with this program. If not, see . */ > + > +/* A static constexpr member of a class template with a non-type template > + parameter. The reference from the member typedef forces GCC to emit the > + declaration DIE (DW_TAG_variable with DW_AT_const_value) in DWARF5. */ > + > +template > +struct S > +{ > + static constexpr unsigned v = N; > + using P = int[v]; > +}; > + > +S<1> s; > + > +int > +main () > +{ > + return 0; > +} > diff --git a/gdb/testsuite/gdb.cp/static-const-template.exp b/gdb/testsuite/gdb.cp/static-const-template.exp > new file mode 100644 > index 00000000000..af8477dba4e > --- /dev/null > +++ b/gdb/testsuite/gdb.cp/static-const-template.exp > @@ -0,0 +1,40 @@ > +# Copyright 2026 Free Software Foundation, Inc. > +# This program is free software; you can redistribute it and/or modify > +# it under the terms of the GNU General Public License as published by > +# the Free Software Foundation; either version 3 of the License, or > +# (at your option) any later version. > +# > +# This program is distributed in the hope that it will be useful, > +# but WITHOUT ANY WARRANTY; without even the implied warranty of > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > +# GNU General Public License for more details. > +# > +# You should have received a copy of the GNU General Public License > +# along with this program. If not, see . > + > +# Test printing a static constexpr member of a class template with a > +# non-type template parameter. > +# > +# In DWARF5, GCC spells the enclosing type S<1> while the C++ expression > +# evaluator looks the member up using the canonical spelling S<1l>. The > +# cooked index stores the DWARF spelling, so before the fix for PR > +# symtab/33533 the lookup missed and gdb printed . > + > +standard_testfile .cc > + > +set opts {debug c++ dwarf5} > +lappend opts additional_flags=-std=c++11 > + > +if {[prepare_for_testing "failed to prepare" $testfile $srcfile $opts]} { > + return -1 > +} > + > +if {![runto_main]} { > + return -1 > +} The -1 on both these returns is unnecessary. Please remove. > + > +gdb_test "print s.v" "= 1" \ > + "print static constexpr member of a template" > + > +gdb_test "print 'S<1l>::v'" "= 1" \ > + "print static constexpr member with canonical template arguments" What happens if you remove the 'print s.v' line test? Does this second test still pass? My concern here is that if you *rely* on finding symbols in the expanded symtabs, then the lookup only works if something else first expands the symtab. This means we have random bugs where things don't work, then they'll suddenly start working (once the symtab has expanded). Can you talk more about why this bug cannot be fixed in the quick syms lookup path. At the very least, if we are baking in a known limitation (reliance on expanded symtabs), then this should be documented in both the commit message and code comments. Thanks, Andrew