From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id 2032E3858CD1; Tue, 19 Mar 2024 17:53:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2032E3858CD1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1710870839; bh=aND0fi2y+AIhq5iyfZSRpf9UisGfurnguLA+mfbeXcw=; h=From:To:Subject:Date:From; b=kXag8ldwTWazsCLzbX7BiLqsaGFmNzaEeHqYzNrOmExgpQsrFBl1f0jF9v0iZ9V4x 7Vz4TC9cd1Zy9o45PHA7T5DX/y2vx7KNP0PKIry9PzjQJHIZn/2kTbmwI4X/wlD02Q Wm7skOnVExUE0dtNH/0mCXZBtHEEN+nHzz06/IqY= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom Tromey To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Speed up lookup of "type_specific_data" X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: 12d5d5bfd0201711ac3b14d8cd92589919a82b7a X-Git-Newrev: 1ab9eefe3cea741aba17e11ff28ed48ac3a8293a Message-Id: <20240319175359.2032E3858CD1@sourceware.org> Date: Tue, 19 Mar 2024 17:53:59 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D1ab9eefe3cea= 741aba17e11ff28ed48ac3a8293a commit 1ab9eefe3cea741aba17e11ff28ed48ac3a8293a Author: Tom Tromey Date: Wed Feb 14 09:48:34 2024 -0700 Speed up lookup of "type_specific_data" =20 I noticed that "info locals" on a certain large Ada program was very slow. I tracked this down to ada_get_tsd_type expanding nearly every CU in the program. =20 This patch fixes the problem by changing this code to use the more efficient lookup_transparent_type which, unlike the Ada-specific lookup functions, does not try to find all matching instances. =20 Note that I first tried fixing this by changing ada_find_any_type, but this did not work -- I may revisit this approach at some later date. =20 Also note that the copyright dates on the test files are set that way because I copied them from another test. =20 New in v2: the new test failed on the Linaro regression tester. Looking at the logs, it seems that gdb was picking up a 'value' from libgnat: =20 $1 =3D {} 0xf7e227a4 =20 This version renames the local variable in an attempt to work around this. =20 v3: In v2, while trying to reproduce the problem locally, I accidentally forgot to commit one of the changes. Diff: --- gdb/ada-lang.c | 4 +- gdb/c-lang.c | 6 ++- gdb/cp-namespace.c | 4 +- gdb/cp-support.h | 3 +- gdb/language.h | 5 ++- gdb/symtab.c | 22 +++++----- gdb/symtab.h | 6 ++- gdb/testsuite/gdb.ada/tagged-lookup.exp | 61 ++++++++++++++++++++++++= ++++ gdb/testsuite/gdb.ada/tagged-lookup/foo.adb | 23 +++++++++++ gdb/testsuite/gdb.ada/tagged-lookup/pck.adb | 22 ++++++++++ gdb/testsuite/gdb.ada/tagged-lookup/pck.ads | 21 ++++++++++ gdb/testsuite/gdb.ada/tagged-lookup/pck2.adb | 21 ++++++++++ gdb/testsuite/gdb.ada/tagged-lookup/pck2.ads | 22 ++++++++++ 13 files changed, 200 insertions(+), 20 deletions(-) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 62fc6680ed9..2a904950241 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -6469,7 +6469,9 @@ ada_get_tsd_type (struct inferior *inf) struct ada_inferior_data *data =3D get_ada_inferior_data (inf); =20 if (data->tsd_type =3D=3D 0) - data->tsd_type =3D ada_find_any_type ("ada__tags__type_specific_data"); + data->tsd_type + =3D lookup_transparent_type ("", + SEARCH_TYPE_DOMAIN); return data->tsd_type; } =20 diff --git a/gdb/c-lang.c b/gdb/c-lang.c index ce711c4b4f6..cc33aad088e 100644 --- a/gdb/c-lang.c +++ b/gdb/c-lang.c @@ -935,9 +935,11 @@ public: } =20 /* See language.h. */ - struct type *lookup_transparent_type (const char *name) const override + struct type *lookup_transparent_type (const char *name, + domain_search_flags flags) + const override { - return cp_lookup_transparent_type (name); + return cp_lookup_transparent_type (name, flags); } =20 /* See language.h. */ diff --git a/gdb/cp-namespace.c b/gdb/cp-namespace.c index 41ab52de54a..fb9fcf8ed6e 100644 --- a/gdb/cp-namespace.c +++ b/gdb/cp-namespace.c @@ -1024,10 +1024,10 @@ cp_lookup_nested_symbol (struct type *parent_type, released version of GCC with such information.) */ =20 struct type * -cp_lookup_transparent_type (const char *name) +cp_lookup_transparent_type (const char *name, domain_search_flags flags) { /* First, try the honest way of looking up the definition. */ - struct type *t =3D basic_lookup_transparent_type (name); + struct type *t =3D basic_lookup_transparent_type (name, flags); const char *scope; =20 if (t !=3D NULL) diff --git a/gdb/cp-support.h b/gdb/cp-support.h index f95b6f0f0e2..4015126154b 100644 --- a/gdb/cp-support.h +++ b/gdb/cp-support.h @@ -161,7 +161,8 @@ extern struct block_symbol const struct block *block, const domain_search_flags domain); =20 -struct type *cp_lookup_transparent_type (const char *name); +struct type *cp_lookup_transparent_type (const char *name, + domain_search_flags flags); =20 /* See description in cp-namespace.c. */ =20 diff --git a/gdb/language.h b/gdb/language.h index c2eae4f7434..e67150d7596 100644 --- a/gdb/language.h +++ b/gdb/language.h @@ -349,9 +349,10 @@ struct language_defn =20 /* Find the definition of the type with the given name. */ =20 - virtual struct type *lookup_transparent_type (const char *name) const + virtual struct type *lookup_transparent_type (const char *name, + domain_search_flags flags) const { - return basic_lookup_transparent_type (name); + return basic_lookup_transparent_type (name, flags); } =20 /* Find all symbols in the current program space matching NAME in diff --git a/gdb/symtab.c b/gdb/symtab.c index cd2bc8f2e21..33b664f9478 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -2694,9 +2694,9 @@ symbol::matches (domain_search_flags flags) const /* See symtab.h. */ =20 struct type * -lookup_transparent_type (const char *name) +lookup_transparent_type (const char *name, domain_search_flags flags) { - return current_language->lookup_transparent_type (name); + return current_language->lookup_transparent_type (name, flags); } =20 /* A helper for basic_lookup_transparent_type that interfaces with the @@ -2705,6 +2705,7 @@ lookup_transparent_type (const char *name) static struct type * basic_lookup_transparent_type_quick (struct objfile *objfile, enum block_enum block_index, + domain_search_flags flags, const lookup_name_info &name) { struct compunit_symtab *cust; @@ -2712,14 +2713,14 @@ basic_lookup_transparent_type_quick (struct objfile= *objfile, const struct block *block; struct symbol *sym; =20 - cust =3D objfile->lookup_symbol (block_index, name, SEARCH_STRUCT_DOMAIN= ); + cust =3D objfile->lookup_symbol (block_index, name, flags); if (cust =3D=3D NULL) return NULL; =20 bv =3D cust->blockvector (); block =3D bv->block (block_index); =20 - sym =3D block_find_symbol (block, name, SEARCH_STRUCT_DOMAIN, nullptr); + sym =3D block_find_symbol (block, name, flags, nullptr); if (sym =3D=3D nullptr) error_in_psymtab_expansion (block_index, name.c_str (), cust); gdb_assert (!TYPE_IS_OPAQUE (sym->type ())); @@ -2733,6 +2734,7 @@ basic_lookup_transparent_type_quick (struct objfile *= objfile, static struct type * basic_lookup_transparent_type_1 (struct objfile *objfile, enum block_enum block_index, + domain_search_flags flags, const lookup_name_info &name) { const struct blockvector *bv; @@ -2743,7 +2745,7 @@ basic_lookup_transparent_type_1 (struct objfile *objf= ile, { bv =3D cust->blockvector (); block =3D bv->block (block_index); - sym =3D block_find_symbol (block, name, SEARCH_STRUCT_DOMAIN, nullpt= r); + sym =3D block_find_symbol (block, name, flags, nullptr); if (sym !=3D nullptr) { gdb_assert (!TYPE_IS_OPAQUE (sym->type ())); @@ -2761,7 +2763,7 @@ basic_lookup_transparent_type_1 (struct objfile *objf= ile, global blocks. */ =20 struct type * -basic_lookup_transparent_type (const char *name) +basic_lookup_transparent_type (const char *name, domain_search_flags flags) { struct type *t; =20 @@ -2775,7 +2777,7 @@ basic_lookup_transparent_type (const char *name) for (objfile *objfile : current_program_space->objfiles ()) { t =3D basic_lookup_transparent_type_1 (objfile, GLOBAL_BLOCK, - lookup_name); + flags, lookup_name); if (t) return t; } @@ -2783,7 +2785,7 @@ basic_lookup_transparent_type (const char *name) for (objfile *objfile : current_program_space->objfiles ()) { t =3D basic_lookup_transparent_type_quick (objfile, GLOBAL_BLOCK, - lookup_name); + flags, lookup_name); if (t) return t; } @@ -2798,7 +2800,7 @@ basic_lookup_transparent_type (const char *name) for (objfile *objfile : current_program_space->objfiles ()) { t =3D basic_lookup_transparent_type_1 (objfile, STATIC_BLOCK, - lookup_name); + flags, lookup_name); if (t) return t; } @@ -2806,7 +2808,7 @@ basic_lookup_transparent_type (const char *name) for (objfile *objfile : current_program_space->objfiles ()) { t =3D basic_lookup_transparent_type_quick (objfile, STATIC_BLOCK, - lookup_name); + flags, lookup_name); if (t) return t; } diff --git a/gdb/symtab.h b/gdb/symtab.h index 5bd63979132..e23eaed43ec 100644 --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -2307,9 +2307,11 @@ extern void reread_symbols (int from_tty); The type returned must not be opaque -- i.e., must have at least one fi= eld defined. */ =20 -extern struct type *lookup_transparent_type (const char *); +extern struct type *lookup_transparent_type + (const char *name, domain_search_flags flags =3D SEARCH_STRUCT_DOMAIN); =20 -extern struct type *basic_lookup_transparent_type (const char *); +extern struct type *basic_lookup_transparent_type + (const char *name, domain_search_flags flags =3D SEARCH_STRUCT_DOMAIN= ); =20 /* Macro for name of symbol to indicate a file compiled with gcc. */ #ifndef GCC_COMPILED_FLAG_SYMBOL diff --git a/gdb/testsuite/gdb.ada/tagged-lookup.exp b/gdb/testsuite/gdb.ad= a/tagged-lookup.exp new file mode 100644 index 00000000000..4bc088ba8d5 --- /dev/null +++ b/gdb/testsuite/gdb.ada/tagged-lookup.exp @@ -0,0 +1,61 @@ +# Copyright 2024 Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Check that we can print values of parameters of type 'pointer +# (access) to tagged type'. See PR gdb/22670. + +load_lib "ada.exp" + +require allow_ada_tests + +standard_ada_testfile foo + +if {[gdb_compile_ada "${srcfile}" "${binfile}" executable {debug}] !=3D ""= } { + return -1 +} + +clean_restart ${testfile} + +set bp_location [gdb_get_line_number "STOP" ${testdir}/foo.adb] +if {![runto "foo.adb:$bp_location"]} { + return +} + +gdb_test_no_output "set debug symtab-create 1" + +# The idea here is that just a single CU should be expanded while +# searching for the tsd type. +set found_pck 0 +set found_pck2 0 +gdb_test_multiple "print *the_local_var" "only one CU expanded" -lbl { + -re ".symtab-create. start_subfile: name =3D \[^,\]*pck\\.adb, name_fo= r_id =3D \[^\r\n\]*\r\n" { + set found_pck 1 + exp_continue + } + -re ".symtab-create. start_subfile: name =3D \[^,\]*pck2\\.adb, name_f= or_id =3D \[^\r\n\]*\r\n" { + set found_pck2 1 + exp_continue + } + -re ".symtab-create. start_subfile: name =3D \[^,\]*, name_for_id =3D = \[^\r\n\]*\r\n" { + exp_continue + } + -re -wrap ".* =3D \\\(n =3D> $decimal\\\)" { + if {$found_pck + $found_pck2 =3D=3D 1} { + pass $gdb_test_name + } else { + fail $gdb_test_name + } + } +} diff --git a/gdb/testsuite/gdb.ada/tagged-lookup/foo.adb b/gdb/testsuite/gd= b.ada/tagged-lookup/foo.adb new file mode 100644 index 00000000000..35e1aa3a12a --- /dev/null +++ b/gdb/testsuite/gdb.ada/tagged-lookup/foo.adb @@ -0,0 +1,23 @@ +-- Copyright 2017-2024 Free Software Foundation, Inc. +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see . + +with Pck; use Pck; +with Pck2; use Pck2; +procedure Foo is + The_Local_Var : access Top_T2 :=3D new Top_T2'(N =3D> 2); +begin + Inspect (new Top_T'(N =3D> 2)); -- STOP + Inspect2 (The_Local_Var); +end Foo; diff --git a/gdb/testsuite/gdb.ada/tagged-lookup/pck.adb b/gdb/testsuite/gd= b.ada/tagged-lookup/pck.adb new file mode 100644 index 00000000000..d5f843a0a29 --- /dev/null +++ b/gdb/testsuite/gdb.ada/tagged-lookup/pck.adb @@ -0,0 +1,22 @@ +-- Copyright 2017-2024 Free Software Foundation, Inc. +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see . + +with Pck2; use Pck2; +package body Pck is + procedure Inspect (Obj: access Top_T'Class) is + begin + null; + end Inspect; +end Pck; diff --git a/gdb/testsuite/gdb.ada/tagged-lookup/pck.ads b/gdb/testsuite/gd= b.ada/tagged-lookup/pck.ads new file mode 100644 index 00000000000..7731fe29886 --- /dev/null +++ b/gdb/testsuite/gdb.ada/tagged-lookup/pck.ads @@ -0,0 +1,21 @@ +-- Copyright 2017-2024 Free Software Foundation, Inc. +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see . + +package Pck is + type Top_T is tagged record + N : Integer :=3D 1; + end record; + procedure Inspect (Obj: access Top_T'Class); +end Pck; diff --git a/gdb/testsuite/gdb.ada/tagged-lookup/pck2.adb b/gdb/testsuite/g= db.ada/tagged-lookup/pck2.adb new file mode 100644 index 00000000000..87f77e503da --- /dev/null +++ b/gdb/testsuite/gdb.ada/tagged-lookup/pck2.adb @@ -0,0 +1,21 @@ +-- Copyright 2017-2024 Free Software Foundation, Inc. +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see . + +package body Pck2 is + procedure Inspect2 (Obj: access Top_T2'Class) is + begin + null; + end Inspect2; +end Pck2; diff --git a/gdb/testsuite/gdb.ada/tagged-lookup/pck2.ads b/gdb/testsuite/g= db.ada/tagged-lookup/pck2.ads new file mode 100644 index 00000000000..c45962b3c5c --- /dev/null +++ b/gdb/testsuite/gdb.ada/tagged-lookup/pck2.ads @@ -0,0 +1,22 @@ +-- Copyright 2017-2024 Free Software Foundation, Inc. +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see . + +with Pck; use Pck; +package Pck2 is + type Top_T2 is tagged record + N : Integer :=3D 1; + end record; + procedure Inspect2 (Obj: access Top_T2'Class); +end Pck2;