From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id SwnsJsnscmpw+QgAWB0awg (envelope-from ) for ; Wed, 05 Aug 2026 03:56:57 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=lLLqSsLO; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 8DBC81E033; Wed, 05 Aug 2026 03:56:57 -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,FREEMAIL_FROM,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 05E731E033 for ; Wed, 05 Aug 2026 03:56:56 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 81C9A4B9DB71 for ; Wed, 5 Aug 2026 07:56:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 81C9A4B9DB71 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=lLLqSsLO Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [IPv6:2a00:1450:4864:20::135]) by sourceware.org (Postfix) with ESMTPS id 554134BAE7DA for ; Wed, 5 Aug 2026 07:56:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 554134BAE7DA Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 554134BAE7DA Authentication-Results: sourceware.org; arc=pass smtp.remote-ip=2a00:1450:4864:20::135 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1785916583; cv=pass; b=XUCyVUTBuiHyTuE+Nuy3t7PZrHJvN6CweDeL1wWZZr3MK7V539D0D2RRsGgrHZvx8dRUt6/cB3nMFyyxhLay2gAthiTq3vP8aPg5rK+EiujYkI2XtM/xemN1SWDHdlmRH3Vn/UTvOehGx8X1mBDvNG/Nyr87A0DyxrfULbpQ9RM= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1785916583; c=relaxed/simple; bh=BTWE+LcM+rJ3lfC5v14UJUXZyiD0q8OC5JbJewCtVVw=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=nJ5TwT3mCsf/Ys+FLb2wmdSHSshcqvER3p5YuzZZ6kd5fHdB6cZVsi0lEo54nlPdtS1ypaWHH3sDnC5sjBSnByNryd9IOeRtllCWCmZnu0CPncTNWnbv+ABCzYONJ8VtKrVxQ8oQIHRHxz1yqx7yxEA9DoK0HlAuwPn2jSEf6vI= ARC-Authentication-Results: i=2; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=lLLqSsLO DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 554134BAE7DA Received: by mail-lf1-x135.google.com with SMTP id 2adb3069b0e04-5aeb2bc82ccso977248e87.2 for ; Wed, 05 Aug 2026 00:56:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1785916582; cv=none; d=google.com; s=arc-20260327; b=sEmVB6OQaEY6oplUPlFHhSJCnA42jvcIdoV+2IV8pJrG753PDb9BZpdFgSGAecHqS6 lLdSXGCbMFkVDrxdOhta1ek6lI7/ZZoRWzVASrP3V8qbeSnKliKAY7LmUvUh26WA1U85 O9t+Kff7z1CI4hrHKcZeKnbXhP6WrRTghXIDHU7JRc6AQG6hCehrp4ATlCBAbieN/S3d MX2avb6OrexPDa6DDS/bqRxcCAHQaPG24duSHIB4qBYKjmN3iKqy3JN7BXQjqRov9rY5 oUveg+V+kIODBi4fg2QOoeGe1vq0/dqM1W3JGc6c44Sn571/O7MKVI5n7sPNdI1XJnWB SQtg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=K1DPk8CITzreNSEhkm8fDRe9RGNmRjWjDkXTkrwnxe0=; fh=72kqq0iQhigvR9Vv/oqX5ebs3Yyyw7XhzWxOOEPdupI=; b=HpR54bhpxis9/RfBi0GHfBdVCWcoCkxz4wcavIpTOr0DhbcYV9hYLCdYqp5uezPXcB peeM41s32reFeivq2XhCMhCxiDkcvHTm54fA2XSPQsNmqD0q0pMTaASxqu7IMmWomTrU TeOmhzcnm2JrmaX31uJF5b6F60CVMumvLGrKjsBHaNOwFGsdUx1ZR2kdPWjN0YR0UZvZ PE191ebO+0fzWdJCjrdUUOH4pDkSDJZnzULTydFfpuw1oEI/9hajWhIk1WcZLcVVGRXB E50CCL8YiI5gs6ILMAAaPcBUP1x+VTOBbV8j3VnS4SDq1s8GJoT1NMqFPdKNCy10Rs/i hBsA==; darn=sourceware.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785916582; x=1786521382; darn=sourceware.org; h=content-transfer-encoding:content-type:to:subject:message-id:date :from:in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to:content-type; bh=K1DPk8CITzreNSEhkm8fDRe9RGNmRjWjDkXTkrwnxe0=; b=lLLqSsLOQSYz9tzzwPF+P5vfWxDiU0bC7UjUCcpFJSAqBJDoeryEiCAkVI/TvOYbZl FFU2FbyaFhnkMH2hMPttJy9Cuf+KuwIVRZwsJtxvRo3BACdHvl+35ekBc1wGQEFn5Y8p 1Y6S9SXRUZtFbdjUAWMMiBi3plPCzfxU970FrrRmkDa7iII4LBdZ2UCR1fPtKVsRxxDH N5UeK9HruLJmjxFm5opvlikBn9VH9ZW1Qf5Kv3NBWIgsEVPI9+BgHXpP4mBPMyPUfIAD PO7IZ/BzRts9+42HTxmrX1k80Tpn5LrJH+6GkGUYCLcvAL0HWB+nAchauA9CU3ZqPuIB Ls3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785916582; x=1786521382; h=content-transfer-encoding:content-type:to:subject:message-id:date :from:in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to:content-type; bh=K1DPk8CITzreNSEhkm8fDRe9RGNmRjWjDkXTkrwnxe0=; b=Ca2qRvOZ9LtuqYwttO8tTHNeQVH09f+NmujVuMgcNzx9lliBXWdVPY0wR3KDnGOtpy 33pHDkoeIqEADWQFcfXpfDRYhvHKNqoTLL1dnfbuPeyblGgNQLFXpQtW4we3ThoQDYdX gkqS5VLvL2E23On26dIcvSwmfWY2q095uPDTBxVI2rIl/EEmdkWVCCAffT70AxHJD29n AloBppoivo+FHTqY3doPgEXSy7Mn77e6gNdgLyWWSljwfxaKmGiLFoA+h5JDBoBkUDHV 21y+NHFHs7W0vWzNfC3y2zcczP1eWPOJ13WpgTbyQ3ZP3/FvEjx+x1++l/1zadPZklJx HrXQ== X-Gm-Message-State: AOJu0YyZlQEkOZ88HAG/BaPcvpF9+j8MFI7zIpThdIYuDarO7n0yuJ2z oyOn+tukq7c1/CMPqVI1BjODGN+DwNCzsp9a+kwuRIcpaSPbuCI/EXX0fi0ROUAEMf3L3YNv+kx MfPFmijxy06hrG443XzmsoSIHpaP17peJEg== X-Gm-Gg: AR+sD13soCJee7n4dZ2JJI7Bass7bONIzCa+gYH8wswffWhelajhTD4Li9pyur/yi19 GFBNFWyiIlQgQYfJbIsH7fmWMfCunk/QwAiMNDXBfPNFf95rSnldGUUABL6QgcTHBqGzZiZY3Hb G0hPOCu//QolQ3sTjL0x0t/LQczAiC8GbJxAI7MUkLCPAkJq3MDYW7QTxR2dFiZhe6VWh37QrBH USxJ7dumcO6cABXrIsvcNSTdKZw604szsTiVdxixe4WvbPyP4/w2067MDesU2Lo5tfvAPH67cWZ eUGbV2L1DJIj9XGJiihlvlh9dc/ApC+j7kNIXCzgNEIGf975sdEj/CTlPZeCN/lJNtUoS40NY6I = X-Received: by 2002:a05:6512:1083:b0:5b0:12cf:ae42 with SMTP id 2adb3069b0e04-5b2f4cc9345mr602882e87.35.1785916581352; Wed, 05 Aug 2026 00:56:21 -0700 (PDT) MIME-Version: 1.0 References: <20260803202529.506-2-oleg.tolmatcev@gmail.com> In-Reply-To: <20260803202529.506-2-oleg.tolmatcev@gmail.com> From: Oleg Tolmatcev Date: Wed, 5 Aug 2026 09:56:11 +0200 X-Gm-Features: AUfX_mxHKK0bccteoBdz_xlTtFC8T8QMzbpGxAVGh9yM5PY8bYNyeOpMCiSmAx8 Message-ID: Subject: Re: [PATCH v2] gdb: search local symbols before global symbols in completion To: gdb-patches@sourceware.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 =D0=BF=D0=BD, 3 =D0=B0=D0=B2=D0=B3. 2026=E2=80=AF=D0=B3. =D0=B2 22:26, Oleg= Tolmatcev : > > When symbol completion is performed from a selected frame, search the > local blocks before scanning minimal symbols and global/static symbols. > This makes completion prefer names that are visible in the current > context, including local variables. > > Add a regression test that checks completion prefers a local symbol over > a global symbol with the same name. > --- > gdb/symtab.c | 72 +++++++++++++-------------- > gdb/testsuite/gdb.base/break.c | 21 ++++++++ > gdb/testsuite/gdb.base/completion.exp | 6 +++ > 3 files changed, 63 insertions(+), 36 deletions(-) > > diff --git a/gdb/symtab.c b/gdb/symtab.c > index 5d5076f2e77..85665bebdf4 100644 > --- a/gdb/symtab.c > +++ b/gdb/symtab.c > @@ -5931,6 +5931,42 @@ default_collect_symbol_completion_matches_break_on > > lookup_name_info lookup_name (sym_text, name_match_type, true); > > + /* Search upwards from currently selected frame (so that we can > + complete on local vars). Also catch fields of types defined in > + this places which match our text string. Only complete on types > + visible from current context. */ > + > + b =3D get_selected_block (); > + surrounding_static_block =3D b =3D=3D nullptr ? nullptr : b->static_bl= ock (); > + surrounding_global_block =3D b =3D=3D nullptr ? nullptr : b->global_bl= ock (); > + if (surrounding_static_block !=3D NULL) > + while (b !=3D surrounding_static_block) > + { > + QUIT; > + > + for (struct symbol *sym : block_iterator_range (b)) > + { > + if (code =3D=3D TYPE_CODE_UNDEF) > + { > + completion_list_add_symbol (tracker, sym, lookup_name, > + sym_text, word); > + completion_list_add_fields (tracker, sym, lookup_name, > + sym_text, word); > + } > + else if (sym->domain () =3D=3D STRUCT_DOMAIN > + && sym->type ()->code () =3D=3D code) > + completion_list_add_symbol (tracker, sym, lookup_name, > + sym_text, word); > + } > + > + /* Stop when we encounter an enclosing function. Do not stop for > + non-inlined functions - the locals of the enclosing function > + are in scope for a nested function. */ > + if (b->function () !=3D NULL && b->inlined_p ()) > + break; > + b =3D b->superblock (); > + } > + > /* At this point scan through the misc symbol vectors and add each > symbol you find to the list. Eventually we want to ignore > anything that isn't a text symbol (everything else will be > @@ -5974,42 +6010,6 @@ default_collect_symbol_completion_matches_break_on > SEARCH_ALL_DOMAINS); > } > > - /* Search upwards from currently selected frame (so that we can > - complete on local vars). Also catch fields of types defined in > - this places which match our text string. Only complete on types > - visible from current context. */ > - > - b =3D get_selected_block (); > - surrounding_static_block =3D b =3D=3D nullptr ? nullptr : b->static_bl= ock (); > - surrounding_global_block =3D b =3D=3D nullptr ? nullptr : b->global_bl= ock (); > - if (surrounding_static_block !=3D NULL) > - while (b !=3D surrounding_static_block) > - { > - QUIT; > - > - for (struct symbol *sym : block_iterator_range (b)) > - { > - if (code =3D=3D TYPE_CODE_UNDEF) > - { > - completion_list_add_symbol (tracker, sym, lookup_name, > - sym_text, word); > - completion_list_add_fields (tracker, sym, lookup_name, > - sym_text, word); > - } > - else if (sym->domain () =3D=3D STRUCT_DOMAIN > - && sym->type ()->code () =3D=3D code) > - completion_list_add_symbol (tracker, sym, lookup_name, > - sym_text, word); > - } > - > - /* Stop when we encounter an enclosing function. Do not stop for > - non-inlined functions - the locals of the enclosing function > - are in scope for a nested function. */ > - if (b->function () !=3D NULL && b->inlined_p ()) > - break; > - b =3D b->superblock (); > - } > - > /* Add fields from the file's types; symbols will be added below. */ > > if (code =3D=3D TYPE_CODE_UNDEF) > diff --git a/gdb/testsuite/gdb.base/break.c b/gdb/testsuite/gdb.base/brea= k.c > index 26085d40ca2..c9b74c6a567 100644 > --- a/gdb/testsuite/gdb.base/break.c > +++ b/gdb/testsuite/gdb.base/break.c > @@ -23,6 +23,26 @@ extern int marker2 (int a); > extern void marker3 (char *a, char *b); > extern void marker4 (long d); > > +struct completion_global_struct > +{ > + int global_field; > +}; > + > +struct completion_local_struct > +{ > + int local_field; > +}; > + > +struct completion_global_struct completion_var; > + > +static void > +completion_local_over_global (void) > +{ > + struct completion_local_struct completion_var =3D { 23 }; > + > + completion_var.local_field++; /* local-completion-breakpoint */ > +} > + > /* We're used by a test that requires malloc, so make sure it is in > the executable. */ > void *need_malloc () > @@ -50,6 +70,7 @@ main (int argc, char **argv, char **envp) > marker2 (43); /* set breakpoint 20 here */ > marker3 ("stack", "trace"); /* set breakpoint 21 here */ > marker4 (177601976L); > + completion_local_over_global (); > /* We're used by a test that requires malloc, so make sure it is > in the executable. */ > (void)malloc (1); > diff --git a/gdb/testsuite/gdb.base/completion.exp b/gdb/testsuite/gdb.ba= se/completion.exp > index 44cf649d5b6..9848f21d951 100644 > --- a/gdb/testsuite/gdb.base/completion.exp > +++ b/gdb/testsuite/gdb.base/completion.exp > @@ -87,6 +87,12 @@ gdb_test "complete set gnutarget aut" "set gnutarget a= uto" > > gdb_test "complete set cp-abi aut" "set cp-abi auto" > > +# Check that symbol completion in a selected frame prefers a local > +# symbol over a global symbol with the same name. > +gdb_breakpoint [gdb_get_line_number "local-completion-breakpoint"] > +gdb_continue_to_breakpoint "local-completion-breakpoint" > +gdb_test "complete p completion_var.l" "p completion_var.local_field" > + > # Test that completion of commands 'target FOO' works well. > set targets [list "core" "tfile" "exec"] > > -- > 2.55.0.windows.1 > For some reason this patch caused regressions on Arm. I need to investigate= . The previous one, without the test didn't cause regressions. Oleg