From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id W1zKJKV1cGq3LAIAWB0awg (envelope-from ) for ; Mon, 03 Aug 2026 07:04:05 -0400 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=FPoAbq55; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 654861E09E; Mon, 03 Aug 2026 07:04:05 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-6.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 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 243011E099 for ; Mon, 03 Aug 2026 07:04:04 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4D04C4BA2E37 for ; Mon, 3 Aug 2026 11:04:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4D04C4BA2E37 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=FPoAbq55 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id 90C164BA540B for ; Mon, 3 Aug 2026 11:03:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 90C164BA540B 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 90C164BA540B Authentication-Results: sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1785755018; cv=none; b=fnYFjHX30xg56LznsoP6FOX8ELZ1WsUeRV1JiNcg9HNppx5fs3YUwSxLtgNIoPVm33n0KXwpEZlYVpnlZ5Ef9jNkIswDy5QtsiFu/i5RR14bY7UQ5eb6DKbxZGkZSmgdnhmXHzkKiUkOIqcIuVPeopqeOCwAMFqls7/qe8GTkzE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1785755018; c=relaxed/simple; bh=DUlCHnNJMUpyMpQbZ1Spjk0pJdkz8NXer+NRGYAOHAs=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=HpmDXHnrf9I86PwN1TxR/j8rFygla4fKCxWp5LZPwrHLaUAqV8A25ulq5wsMQzqYQ4buF/FaY91K2kqmrZnCk09hrY0w/+RgZ8UvRuIJBgxy9tzv7bN5FKuvaxqDN9e8LikyIZWO3/LTBPU9xBwLp7jLnEctQw+ORXMkIBkLBsY= 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=FPoAbq55 DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 90C164BA540B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1785755018; 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=WDkRRHk1o7F1l47qlISjfZZMBk/AEn9IGKHI82RFB5U=; b=FPoAbq550atdRQy/HdCYLg71j2zfxPTr/xzh2fqh8NiDGBP4Og3/NzPj9fDrTT2SvRiZTM nTaHvcZ2yCzRJ8a+zRVmFmMJ+qieTpeZ+9Q+G21GwaTQD+RlzT2X37wgh6m05wdamTIGKu WYNobD9AEPMAH68+yjtpe2UPWxhYtOQ= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-483-rm6PzgMyO3WSsCik4g7o7g-1; Mon, 03 Aug 2026 07:03:37 -0400 X-MC-Unique: rm6PzgMyO3WSsCik4g7o7g-1 X-Mimecast-MFC-AGG-ID: rm6PzgMyO3WSsCik4g7o7g_1785755016 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-490a767b782so13129925e9.2 for ; Mon, 03 Aug 2026 04:03:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785755016; x=1786359816; 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=WDkRRHk1o7F1l47qlISjfZZMBk/AEn9IGKHI82RFB5U=; b=LNAs1fqWfDE65VpBNEqLhTNINvMGIElfHtQiYYnO3g3KPmwuz5cM3zrNt2vQRf7T7V Zi7kbANh0QC1kt8ZlCGnSnsV/3kZet9wovSTB8JBeGdoRHNQ5zT3M2LFCVQnhk+IU2sO dvNCW6/zmOSeUzpZvfdDrlEreOTTrbhZGfh4bVHZw5peYYfZiekhD1SHBv5WXp4FMkUW dgK6w3mI4pfUN0WTS61ujkjozg5DIZIO/rt55PXYXbB26P/ysRkDvFg47QSKenlI4iU9 uf9Cre4hiBjYYIAipcVWJEeZtjgYs+Bqn+IfgdiglbpDJ7+HFpPvhz1AnF9YpRbBsXAS hqIw== X-Forwarded-Encrypted: i=1; AHgh+RpRzjhs8vlwtLYlovz832jUbk6Hg5guI9kEIo/9pqkM1d9R25VLnLNy/bjAI7/sibcL5DMIsQu87n1mVA==@sourceware.org X-Gm-Message-State: AOJu0YwW5ZgMmy1NQ14ngNZOgOl+7Cr3el1waOCBn/mADQCDIgp/oFxx AoHawUsHTRDV2/3qAHgJC6RngRtT4G1lOwhf97cHbPUSuje2Qalsx4svM16DdqYdty88+op2YxL nICvxlHwwn3p95p53E/7J85P5K2NqE3XIPtEbeoXojU8dS8lwYlpZbRp2iBhYMvDZZb+8jbk= X-Gm-Gg: AR+sD101G3iXY9gjIhVqtyZ12R6naWBR5c1JQiTDHdyS/hTKFMntowoC4NUvakpRyQP SdZNVb/O+Up+bkVNzqfEc9Fkuak9dlD0U5QkQGedurjSeud3FmPIZFARnBt+l2cBuuQlBE2iWe3 OLa3/1OI44ds3ka85LXNMUghCxh9gzR5iTW1IpRhlB/U+F4tnWk0woNxu+HoY2EMHG4R4nwNXcg vwQwldTSxhPfTdsj2pJWHzVVIQKwG8e0f0SLiVoO2OoC1Iha7bZG2uH1+f3MMhFJFLNU8H8m/Lz e2nkccjeu55t+39C/SbXKyvDgODjPsvMs8+B3Hocvhy0aFkxeuVaL0aGPBRpkc1mTE50PH5In1+ 2TWZ+9rSEcPS6lS2v X-Received: by 2002:a05:600c:6989:b0:495:4811:7998 with SMTP id 5b1f17b1804b1-4980c664d83mr249644925e9.17.1785755015592; Mon, 03 Aug 2026 04:03:35 -0700 (PDT) X-Received: by 2002:a05:600c:6989:b0:495:4811:7998 with SMTP id 5b1f17b1804b1-4980c664d83mr249643375e9.17.1785755014902; Mon, 03 Aug 2026 04:03:34 -0700 (PDT) Received: from localhost (92.6.93.209.dyn.plus.net. [209.93.6.92]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49807b85be7sm270358525e9.2.2026.08.03.04.03.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Aug 2026 04:03:34 -0700 (PDT) From: Andrew Burgess To: Oleg Tolmatcev , gdb-patches@sourceware.org Cc: Oleg Tolmatcev Subject: Re: [PATCH] gdb: search local symbols before global symbols in completion In-Reply-To: <20260801160146.1318-2-oleg.tolmatcev@gmail.com> References: <20260801160146.1318-2-oleg.tolmatcev@gmail.com> Date: Mon, 03 Aug 2026 12:03:33 +0100 Message-ID: <87cxvzmpoa.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: X3YksYxDVYgHq6ZUybelcmupi7CTP2g4KaGbNtUC4cw_1785755016 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 Oleg Tolmatcev writes: > 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. > --- > gdb/symtab.c | 72 ++++++++++++++++++++++++++-------------------------- It feels like this really needs a test in the gdb.dap/ directory. Thanks, Andrew > 1 file changed, 36 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 = get_selected_block (); > + surrounding_static_block = b == nullptr ? nullptr : b->static_block (); > + surrounding_global_block = b == nullptr ? nullptr : b->global_block (); > + if (surrounding_static_block != NULL) > + while (b != surrounding_static_block) > + { > + QUIT; > + > + for (struct symbol *sym : block_iterator_range (b)) > + { > + if (code == 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 () == STRUCT_DOMAIN > + && sym->type ()->code () == 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 () != NULL && b->inlined_p ()) > + break; > + b = 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 = get_selected_block (); > - surrounding_static_block = b == nullptr ? nullptr : b->static_block (); > - surrounding_global_block = b == nullptr ? nullptr : b->global_block (); > - if (surrounding_static_block != NULL) > - while (b != surrounding_static_block) > - { > - QUIT; > - > - for (struct symbol *sym : block_iterator_range (b)) > - { > - if (code == 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 () == STRUCT_DOMAIN > - && sym->type ()->code () == 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 () != NULL && b->inlined_p ()) > - break; > - b = b->superblock (); > - } > - > /* Add fields from the file's types; symbols will be added below. */ > > if (code == TYPE_CODE_UNDEF) > -- > 2.55.0.windows.1