From patchwork Fri May 19 21:27:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 69704 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1185E3857700 for ; Fri, 19 May 2023 21:28:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1185E3857700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1684531714; bh=R+iy5mNNZZkZucsmQFfkH5akVPK7D//Q0DpSnHOKdbU=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=a8T3gmKpU4N+tvGv9RECzRTNf8HXPyyI81K2XKZ+EBjT8yjuZPneen28+M8zSh5OU GKtXdIoMMmrYQXoSyvKmZeNDYS4I9Cer9vnu4uz9TDJKknsk2mx1jDz9ZKuzJPRZnH FoaKGQysCaS95X20/lU1TBFYV/yYBxy1vWQBjB7c= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 218083858C52 for ; Fri, 19 May 2023 21:28:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 218083858C52 Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-653-AZvy9YtZOcKbQiUcu3f4Kw-1; Fri, 19 May 2023 17:28:07 -0400 X-MC-Unique: AZvy9YtZOcKbQiUcu3f4Kw-1 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-3093b0cf714so1442084f8f.2 for ; Fri, 19 May 2023 14:28:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684531685; x=1687123685; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=R+iy5mNNZZkZucsmQFfkH5akVPK7D//Q0DpSnHOKdbU=; b=IBeeVCAo0Ec8ec5RtPJY/lG0YCg+sk4GWJAIIjtmSNU3WElgL73E+Zx/o1s2MD6GF0 lxw24zmHeRPf3lYCFtn1qvnCrNWxS2FNDRiSfPkNGnGk05mLTUm3bCr49OVYCwRzm6fB zWQT3YzAeAcYJj5/iO3TxWXUseUsdbtkq6BRtGmfUoAGABJ+ipTafaOn9BNuG1TzagSp cKkcbkUZ9YV3hvXeq9XcM/MyY2Xp93ylsdsO7epPfVTapHu0MxHCqYmsCc83QGtVIbF1 hcwx9A3qxj3/060IDN4Z96Eh8yheMzraO+3LxoQMF5x4Odkc9cErNT72GOeZl1HZ0nyI YsbQ== X-Gm-Message-State: AC+VfDzwIvMUDxR3oi/pC/JY5wfzcBZsu7iOaSRb0XxcOBB/WKFu5vx0 Sr5Jddhi+ibBOP2QCmB47JshXf1J8PJBiH/sKbzKWWm7XewC5dEsd4/vSx9PngaWAsDQmx4WYm4 3TAISE4JNUeWtfBNKzMJKnN+uaLIq46QTTaWrsoeEGBkc+piIypmBI5CqGNItNmbmIFYlg1WUoc g+YW3elw== X-Received: by 2002:adf:e401:0:b0:309:4176:702 with SMTP id g1-20020adfe401000000b0030941760702mr2564760wrm.37.1684531685451; Fri, 19 May 2023 14:28:05 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6Yl0sn0uzzKFfg34/Xfh6rh7ryeOw3xE7Nbq0TcZA0cB5A6MXpmCa8iFchEX8JCGSDqu5ngA== X-Received: by 2002:adf:e401:0:b0:309:4176:702 with SMTP id g1-20020adfe401000000b0030941760702mr2564754wrm.37.1684531685105; Fri, 19 May 2023 14:28:05 -0700 (PDT) Received: from localhost (11.72.115.87.dyn.plus.net. [87.115.72.11]) by smtp.gmail.com with ESMTPSA id b15-20020a5d4b8f000000b00306344eaebfsm73752wrt.28.2023.05.19.14.28.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 May 2023 14:28:04 -0700 (PDT) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv3 1/2] gdb: have mdict_size always return a symbol count Date: Fri, 19 May 2023 22:27:57 +0100 Message-Id: X-Mailer: git-send-email 2.25.4 In-Reply-To: References: <20230518033357.77174-1-dark.ryu.550@gmail.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" In the next commit we would like to have mdict_size return the number of symbols in the dictionary, currently mdict_size is just a heuristic, sometimes it returns the number of symbols, and sometimes the number of buckets in a hashing dictionary (see size_hashed in dictionary.c). Currently this vague notion of size is good enough, the only place mdict_size is used is in a maintenance command in order to print a message containing the size of the dictionary ... so we don't really care that the value isn't correct. However, in the next commit we do want the size returned to be the number of symbols in the dictionary, so this commit makes mdict_size return the symbol count in all cases. The new use is still not on a hot path -- it's going to be a Python __repr__ method, so all I do in this commit is have size_hashed walk the dictionary and count the entries, obviously this could be slow if we have a large number of symbols, but for now I'm not worrying about that case. We could always store the symbol count if we wanted, but that would increase the size of every dictionary for a use case that isn't going to be hit that often. I've updated the text in 'maint print symbols' so that we don't talk about the size being 'syms/buckets', but just 'symbols' now. --- gdb/dictionary.c | 13 ++++++++++++- gdb/dictionary.h | 3 +-- gdb/symmisc.c | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/gdb/dictionary.c b/gdb/dictionary.c index 4f8df240a3e..f3dfe092830 100644 --- a/gdb/dictionary.c +++ b/gdb/dictionary.c @@ -650,7 +650,18 @@ insert_symbol_hashed (struct dictionary *dict, static int size_hashed (const struct dictionary *dict) { - return DICT_HASHED_NBUCKETS (dict); + int nbuckets = DICT_HASHED_NBUCKETS (dict); + int total = 0; + + for (int i = 0; i < nbuckets; ++i) + { + for (struct symbol *sym = DICT_HASHED_BUCKET (dict, i); + sym != nullptr; + sym = sym->hash_next) + total++; + } + + return total; } /* Functions only for DICT_HASHED_EXPANDABLE. */ diff --git a/gdb/dictionary.h b/gdb/dictionary.h index d982396cb31..44bd075fcf2 100644 --- a/gdb/dictionary.h +++ b/gdb/dictionary.h @@ -159,8 +159,7 @@ extern struct symbol * extern struct symbol *mdict_iter_match_next (const lookup_name_info &name, struct mdict_iterator *miterator); -/* Return some notion of the size of the multidictionary: the number of - symbols if we have that, the number of hash buckets otherwise. */ +/* Return the number of symbols in multidictionary MDICT. */ extern int mdict_size (const struct multidictionary *mdict); diff --git a/gdb/symmisc.c b/gdb/symmisc.c index ff7f31f885f..e414dea7bf6 100644 --- a/gdb/symmisc.c +++ b/gdb/symmisc.c @@ -286,7 +286,7 @@ dump_symtab_1 (struct symtab *symtab, struct ui_file *outfile) /* drow/2002-07-10: We could save the total symbols count even if we're using a hashtable, but nothing else but this message wants it. */ - gdb_printf (outfile, ", %d syms/buckets in ", + gdb_printf (outfile, ", %d symbols in ", mdict_size (b->multidict ())); gdb_puts (paddress (gdbarch, b->start ()), outfile); gdb_printf (outfile, "..");