From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 6UKjLPcRemo8SBsAWB0awg (envelope-from ) for ; Mon, 10 Aug 2026 14:01:27 -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=ZnHb7m/c; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id B1A9E1E166; Mon, 10 Aug 2026 14:01:27 -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 9EECB1E09B for ; Mon, 10 Aug 2026 14:01:25 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7AD564B99F56 for ; Mon, 10 Aug 2026 18:01:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7AD564B99F56 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=ZnHb7m/c Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [IPv6:2a00:1450:4864:20::134]) by sourceware.org (Postfix) with ESMTPS id 49B234BA2E37 for ; Mon, 10 Aug 2026 18:00:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 49B234BA2E37 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 49B234BA2E37 Authentication-Results: sourceware.org; arc=pass smtp.remote-ip=2a00:1450:4864:20::134 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1786384858; cv=pass; b=njZaGXAf5/jUTVMMoBIkSWRjs+PFVRE9fYEz9kvIG050cjsNLi5d4ucSGcJ8trrwniK2IN8ZFQKgBiSLHDTgGLb+anOoZadiX4HVq+W1E+S22gprKgKShUFb7FBGeeVqLUn9JouJwWXE6P8S2+CpXXh8bo6asBfR3jfpy0eXCfg= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1786384858; c=relaxed/simple; bh=LTIzHuArA77zKkWJDo5kYdJBgS+b78oqezUpEma+2+E=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=UDSu8GxdbaZ8mBoCRn/5RaduhXGIomjRDeHqqvs0jM+5gG3qqFjUFzNY48QPJNpn5V8VyWwFUjIoSn3mDah44naHPdZ3xJH6K4x2n7ntCl13oho6wh6TFfu1YYKjqR/Ws8UnFE+6NkQTOe+Rq3JdmnDutYhk7RMtUXoWOOC3Wxc= 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=ZnHb7m/c DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 49B234BA2E37 Received: by mail-lf1-x134.google.com with SMTP id 2adb3069b0e04-5b2a22c52c1so2071321e87.3 for ; Mon, 10 Aug 2026 11:00:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1786384857; cv=none; d=google.com; s=arc-20260327; b=REWXa0Up5yQ7X3/ZJ+TyXHtg4gpJ7mItYC21POLaP517i9mmslkT4a/BAzf4i4mcTF R/J25ds7XMTB4Us5V1wWv/pOmQTABLNHOLYTxOj/YiD+v3yjpcimeHKGfdQhS8vaoAHB QOHmyV4tsEZsBfWCfmQT/DI7IFhiCq9O7/GEMhODspzJfLGetMliIZ7lAiNDoW4kT8EU IXg+HwvtAyK+CwgGRItjlyRj9d7HiAXCsUkgzNKdgaZukprDoXDrhTf4NK9rQWzM5BKm TyPlogtl2tQr/OaCuoGBFQkmU1YXIHgGN91fTdTolySvBVNNatrhE5d3uJIH45QcmjLK +vhg== 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=6NaEt8tmMDsjUkt+rGp6XzyITzGsRVOWQ1xEXaQtBRw=; fh=72kqq0iQhigvR9Vv/oqX5ebs3Yyyw7XhzWxOOEPdupI=; b=VNNJwdX8i6hlc+KloEkE3YrRUbmi496UHWB9jxOsyp4lwgmDbtKewYYPhZ4SISOnr3 lpQCO0d/Co38t1U23uOD1NvPvG1qjgzDmnBFebpjRtzby5O6IDeJ6CYoKCfAOaPPlHut IpG7k0TNQs5ZHdFC4fKa4uVTvVtyjeq2o5iqsey33SFcqKkAy6qFDW0TArMshfPPayv6 zaqf6HmOI9CTYC2VRSO/ZmnkJJOD38+8A0dF6EcgcSfxeB4n3NUxD1VyLvzzPg6NKGqm uFeb+A3RBnQ8/McrAi9Sy+0wySoWbs+o2FhjS2nzuK73RHpffmpk0Wsq2dy7033hRQIQ +y0g==; 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=1786384857; x=1786989657; 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=6NaEt8tmMDsjUkt+rGp6XzyITzGsRVOWQ1xEXaQtBRw=; b=ZnHb7m/c2MmFRkgxJ2UP9SDBeMQO1ZOUKgqTo5gnfEKdC+cf1Fms18WsBbmO4kTvwW citUuBrC1CjOyxdHn390+YTXN+fJDTS15/fcU1hvqJU0RHKYkxs0zBjyDdFGYtp1fjdz Ea+3xRZZBYBil07mMiCvLAaF+a/9WMq9UGQOt8sC7wjalJsp56wgr0f+WW2hoe5eHj0h Ao01509OrG2H58uk20VUXV2D1t8T1b4d01oEgO5HkQhHboTOT0vBG++w00eFHGg/gmnQ k+KEpdumaQEHCRvcrYTJp6WB4eVXZf1riTM3xPbFqUTgQDUNd0GYn6Isd4O+hUzyRLQ2 1M1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786384857; x=1786989657; 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=6NaEt8tmMDsjUkt+rGp6XzyITzGsRVOWQ1xEXaQtBRw=; b=Fx6xLI57UrHepLMmNHOR095gEKSMJWKrMFhWPOcslZcHw+DIYnlMK1iMUV3wrFh6eI c0n07oU77ff+xBnkJdoyZM2axeKQxZMK6pGgv6kzBs7w0DVzpjzpABp4lJnUjbd25iWw wXuvx33GnpQU7nYPfjIEPIZyeW+DwT1YzyPLBNdMCtGIQax7YAgm55Fex3Ui+x4AIMVc 1AhI2HvgfOk4O+iGlzxxJFxaraHWuw3+e7TLbJYdxuQRCa6jmcI8dLyHgwlvn2lUXE0M uEmN0apiHrDLSMEsx03dk5tMGjY5YW6bg1gwEIPjngs7a8eRBaWRUlCWLNHVlVwjQ8rQ THYg== X-Gm-Message-State: AOJu0YyqbL0WvybCWyXFd0s+e2Wb5ouFuGMYXB2PMKYU/xUsgBZMwj62 czwxBwJsCxloTHnsZUdhu+lPdGa4tUniqWKPV7UPXjnIkJXASWS49WGzXh+gM8Z8ssHJXgYZ+Hs bZZCW/4jGtqmtaqjfuXB/S7TJ1eBiUYuu+Q== X-Gm-Gg: AR+sD128RqTn9QNaaoF+hJ3NSH8fMXYUPS4r6F5blzwNt9AdbIyEQvDjSYkm40sNVY7 cI49DQcfOr0IBjPW7JSSkJs7f0tOdGYWzpwTznzT+P5uz36Tp/PY8mZlP1HQ89uThQGJk5nRmWM G2IXS9g8Odwy/8DbR65tDPGVkPj1TYbLRqse0NP3iZ6jEzYGkBNb/sNsFbAjJyVbhkNi5kAeNXl aNr2S+i8qFSkrJvSvmp6Cpkx2wfcydDhp55qIDgcp/xhQjNqcmrYnLGgswY6ljIrqFoZwdQfnSo mgshxVuOkbRb4QVajuwuKlA9LAXrELJqgLUc/qBZAVGh+3DPtokzBvHzoAq/UmBAGHxW3vtBPcB J X-Received: by 2002:a05:6512:3e1f:b0:5ae:b130:1e1 with SMTP id 2adb3069b0e04-5b3181c124fmr543970e87.28.1786384856759; Mon, 10 Aug 2026 11:00:56 -0700 (PDT) MIME-Version: 1.0 References: <20260809171936.645-2-oleg.tolmatcev@gmail.com> In-Reply-To: <20260809171936.645-2-oleg.tolmatcev@gmail.com> From: Oleg Tolmatcev Date: Mon, 10 Aug 2026 20:00:43 +0200 X-Gm-Features: AUfX_mzSVBas7gUEYU6TGi7ppxQnVFymZT07o_pQiTvOayCHGjYpbPRbnGTI_gs Message-ID: Subject: Re: [PATCH v4] 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=B2=D1=81, 9 =D0=B0=D0=B2=D0=B3. 2026=E2=80=AF=D0=B3. =D0=B2 19:19, 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 | 10 ++++ > 3 files changed, 67 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..4cecd552d3c 100644 > --- a/gdb/testsuite/gdb.base/completion.exp > +++ b/gdb/testsuite/gdb.base/completion.exp > @@ -87,6 +87,16 @@ 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" > + > +# Leave the helper frame before continuing with the readline-based > +# completion checks below. > +gdb_test "finish" ".*" "return from local completion helper" > + > # Test that completion of commands 'target FOO' works well. > set targets [list "core" "tfile" "exec"] > > -- > 2.55.0.windows.3 > Still two regressions on ARM. Oleg