From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id VyPIGSgjdmrOphEAWB0awg (envelope-from ) for ; Fri, 07 Aug 2026 14:25:44 -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=c/OYECDH; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 58C961E09B; Fri, 07 Aug 2026 14:25:44 -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 [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 219FD1E09B for ; Fri, 07 Aug 2026 14:25:43 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 33F7B4BB3BF7 for ; Fri, 7 Aug 2026 18:25:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 33F7B4BB3BF7 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=c/OYECDH Received: from mail-lf1-x130.google.com (mail-lf1-x130.google.com [IPv6:2a00:1450:4864:20::130]) by sourceware.org (Postfix) with ESMTPS id 802544BA799E for ; Fri, 7 Aug 2026 18:25:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 802544BA799E 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 802544BA799E Authentication-Results: sourceware.org; arc=pass smtp.remote-ip=2a00:1450:4864:20::130 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1786127115; cv=pass; b=jOB5RX3V/KbjtqGc9lxwXI+Jvw47RxD2g1AjztlQh8JYdrldFaI7X1P41ba5aOGSfpHZ+2arnJaPTaaqa890VUxpZ7igiI1KQ+vW2jSv3XDUZC+HHyWFhguwyiT7s2WyCeewCM26SCzodLvuKREzB3XFnRRl20jM3AZriMMwgoQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1786127115; c=relaxed/simple; bh=h2z224WK+OIsgrIx1KTDHf0y0RsI/U3fJeYZPFZRWxU=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=T2doZmb8q4uKcfixVUTHpRKpcBo5n9TsBRkLxJOZ+9zfFmUUoBAaG9oNRPiniqEvaxdgNRNafQRo8mVRGh6cIBtNRfgYrtwQW1G8qY3N4wFyvy3MOW66w4/ANozCTpjgmtnrUFGuAwfXzlvpk6HhxSPVxZi5JwL/gfuJ8mQX+aE= 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=c/OYECDH DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 802544BA799E Received: by mail-lf1-x130.google.com with SMTP id 2adb3069b0e04-5b14d1f9315so2992264e87.2 for ; Fri, 07 Aug 2026 11:25:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1786127114; cv=none; d=google.com; s=arc-20260327; b=BCiJ0jTyTFcmFnEm+JIHtkxDgnmnpnBkijb8gItDk3euBQCJtIZkfx9eikPS6UdxeV tgaU7KVbsD5NXUh2OZVhkeMqwKpU5egHACRdPb5Rk+cop04LLTGTbZ/Iys19pS3I93GL Ks16RByrAVQvQ44jFLZddUZUvMsfnhU8vSU7LqwEk1laktkKPq3E+0Q+81S3q7HptjXk lYgQi+Fqexym83cw7SlEwAr6pbyTdiYv8cbPJPji3LvolNcyc+A/xfaE1e0Hr0H9K7lc oDhWNDZ/OLO9U8F1GtDVxrTy64++9TbI0NJj/WpBULa8milDRwZOWyaGu/DZm9jbO0Da RhuQ== 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=fPJF9j0iNifpE3Ze08EHuorEmv2O/F3vgDhDDmj/cY0=; fh=72kqq0iQhigvR9Vv/oqX5ebs3Yyyw7XhzWxOOEPdupI=; b=UullAWnL4t9Z07p5XGfcDp+1EZRYBuL7y4nrVLwNzTpnBJ0coWivRHFi2lZxwhul7C 2TuyUCVUIZcYWpSQJDoZ8cc5u8CmVIOQEf0PcPQLcpjsJcFPGkeEHRbcHLNoI7H8f3Pg /0x6JrMwK6RaoasEr/9W1uwYbpZ5lQsHcTBa+7ppyl+Yy0J54PLpJqm+Km4qNtpcJaJe xfCg7RgQajd+/H5oa7bLK3580TiMDt1mV8v3y4MTUnAFjpiXqTkq5KDFj+1MrReYrjBL +jQKwpE6QY57KFcxWUcsVE3dfDVQsIrgPjgi1WPqAI7tvz9eDQBVVOFIy8S7nikug+Ml Ub7w==; 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=1786127114; x=1786731914; 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=fPJF9j0iNifpE3Ze08EHuorEmv2O/F3vgDhDDmj/cY0=; b=c/OYECDHQdM2UQehyn7RofG8jB1CCoPdtsL0EiAP1MLXuqy1egK0USnKAzxZsHpvQM hBxE9snhNFH1Ccv/3JYV32PB2oOqOgan1BVyclLMSQlZ0K6f0JegMk0akSrHCTLkhFK2 FNW6P7pgZ8TZiKjOAU7l604OI3MIu6xmZK6ruvTPCqacAG/KhhkAZe3TjGY/CgcPBJFi EDmmoc/z4+1MlYLMjS1oVNCeeOPhNaDwxabHhzde86ZzRF5uO+CPfl9Sc11bfrKj/R2R jRQZoyKmOeLNyiNpgZKHb9AXPNLFGwx0w0UVDC7nvk1jL+VdVK4LrnDTrtZztEx3V068 i/1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786127114; x=1786731914; 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=fPJF9j0iNifpE3Ze08EHuorEmv2O/F3vgDhDDmj/cY0=; b=RWKauINLMbPfDoKJ0dvh7T2vaiJYps6aEDuPBkLuwg3JdA0YUyJHNUBRNbgk8YT8WJ fLb+q0xVxKbjUDI9MwhNi1gmtaNt63TNwfNCkcEC+RjZg2at0HJcaH9bG4GyWJXU5/MA 2/EIqUBQF7tfwkyUOgeIzC0rZw/5mhYduWb85OAAixFAngbjLj9HEj+oZTKqOiQDhLB5 8Oo8cOXTEhX8Vr1iDx+SZjWQGIc+44gCewW5Un9CtrnCHoB+KfmY1n/uEBKVeoOqEfDv y38p9bv7N60/olhP/gd16hcp+DAs9vizJH6/RzQ2kiLmZx2Lox6jRSD15Bjo5/R7z8rX OC8g== X-Gm-Message-State: AOJu0Yz3USidRNZPB+kLwybEGdPCIwrq7EUvezOdO0r5I6Nx7Rr91vnp Y5kQva8253h4+37hbqi50as4yB+j5JjaKlawJomDh9jhnEeH35QKReKbUH10BGk0VU6fIskmPb+ KfoQvdp5fZTdErDq6H1b8frx87f4ebcw9yQ== X-Gm-Gg: AR+sD126v9jTmLoYrSWf8dtBv2kNZqo/AFgS8v8G/3YheiG42Msnqn0S6tEau2fWPGT yW1VhzWkBENS0WIIoM4zCaWagvJebBVmmoAd0uXX8TGmbt4iO3sMqFWNSZ/Er6POhDu2bWE/3sc SRMWj/mWAoK3B3EEJUVy4a9UCaMS+ap+26S5y4fqXA4f2FZh1wgp1kSS/3XVx6uZIChAfuEQSs8 8iw6VTJmD9dWhMntdxu8KdUAPp2dOx+h2uK+XhBMe/at6L+eO6ycPH5LPS82tNSvbe5oMEjjzeh L3LCoiahHug/HhNKSwSVgYbVUd1txPubssgcB9Wn1KoKPF6GYeJO6MfcCDoloHOq186gtK5hLC0 X X-Received: by 2002:a05:6512:3b09:b0:5b3:c15:c688 with SMTP id 2adb3069b0e04-5b30c15c797mr58096e87.7.1786127113766; Fri, 07 Aug 2026 11:25:13 -0700 (PDT) MIME-Version: 1.0 References: <20260805154636.1663-2-oleg.tolmatcev@gmail.com> In-Reply-To: <20260805154636.1663-2-oleg.tolmatcev@gmail.com> From: Oleg Tolmatcev Date: Fri, 7 Aug 2026 20:25:00 +0200 X-Gm-Features: AUfX_mxkpNLSPIar5txZ3ND6_Wt5UVsNj28nEvjvxHm6aY1nquyhS5bZ9ncBHvc Message-ID: Subject: Re: [PATCH v3] 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 =D1=81=D1=80, 5 =D0=B0=D0=B2=D0=B3. 2026=E2=80=AF=D0=B3. =D0=B2 17:46, 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 | 7 +++ > 3 files changed, 64 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..78a19780443 100644 > --- a/gdb/testsuite/gdb.base/completion.exp > +++ b/gdb/testsuite/gdb.base/completion.exp > @@ -87,6 +87,13 @@ 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" > +gdb_test_no_output "select-frame 1" > + > # Test that completion of commands 'target FOO' works well. > set targets [list "core" "tfile" "exec"] > > -- > 2.55.0.windows.3 > Still 2 regressions on ARM. Will have to fix the test again. Oleg