Commit Graph

1041 Commits

Author SHA1 Message Date
Tom Tromey
86d6495bd4 Ignore DW_TAG_padding in tag_is_type
DW_TAG_padding isn't a real tag -- it doesn't appear in the DWARF
standard, only in include/dwarf2.def as a placeholder.  So, remove it
from dwarf2/tag.h:tag_is_type.

Reviewed-By: Tom de Vries <tdevries@suse.de>
2024-09-09 11:32:40 -06:00
Andrew Burgess
e454ae416a gdb: allow quoted filenames for commands that have custom completion
This commit changes how GDB processes command arguments for the
following commands:

  compile file
  maint print c-tdesc
  save gdb-index

After this commit these commands will now expect their single filename
argument to be (optionally) quoted if it contains any special
characters (e.g. whit space or quotes).

If the filename does not contain any special characters then nothing
changes.  As an example:

   (gdb) save gdb-index /path/to/some/directory/

will work before and after this patch.  However, if the directory
name contains a white space then before this patch a user would write:

  (gdb) save gdb-index /path/to some/directory/

But this will now fail as GDB will consider this as two arguments,
'/path/to' and 'some/directory/'.  To pass this single directory name
a user must now do one of these:

  (gdb) save gdb-index "/path/to some/directory/"
  (gdb) save gdb-index '/path/to some/directory/'
  (gdb) save gdb-index /path/to\ some/directory/

This brings these commands into line with commands like 'file' and
'symbol-file', which have supported quoted filenames for a while.

The motivation for this change is to make handling of filename
arguments consistent throughout GDB.  We can't move to all commands
taking non-quoted filenames as the non-quoted style only allows for a
single argument.  Additionally, the non-quoted style doesn't allow for
filenames that end in white space (though this is probably pretty
rare).  So, if we want to have consistency the only choice is to move
towards supporting quote filenames.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
2024-09-07 20:28:59 +01:00
Andrew Burgess
dc22ab49e9 gdb: deprecated filename_completer and associated functions
Following on from the previous commit, this commit marks the old
unquoted filename completion related functions as deprecated.

The aim of doing this is to make it more obvious to someone adding a
new command that they should not be using the older unquoted style
filename argument handling.

I split this change from the previous to make for an easier review.
This commit touches more files, but is _just_ function renaming.
Check out gdb/completer.{c,h} for what has been renamed.  All the
other files have just been updated to use the new names.

There should be no user visible changes after this commit.
2024-09-07 20:28:58 +01:00
Tom Tromey
82d6a9e5b4 Improve comments in dwarf2/parent-map.h
I noticed that the comments for class parent_map aren't very clear.
This patch attempts to fix this, and also clarifies a point on
parent_map_map::add_map.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2024-09-04 12:05:45 -06:00
Simon Marchi
e5afccc7e4 gdb/dwarf2: cleanup includes
Cleanup includes in dwarf2/*.

 1. Add the necessary includes so that clangd reports no errors when
    opening header files.  This ensures that header files include what
    they use.

 2. Remove all includes reported as unused by clangd (except
    gdb-safe-ctype.h, which I think does some magic that affects what
    follows).

Built-tested --enable-threading at "yes" and "no", since there are some
portions of code gated by `#ifdef CXX_STD_THREAD`.

Change-Id: I21debffcd7c2caf90f08e1e0fbba3ce30422d042
Approved-By: Tom Tromey <tom@tromey.com>
2024-08-30 13:57:11 -04:00
Tom Tromey
5a06416ebf Don't check dwarf2_name in process_enumeration_scope
I noticed that process_enumeration_scope checks the result of
dwarf2_name.  However, this isn't needed, because new_symbol does the
same check.  This patch removes the unnecessary code.

Reviewed-by: Keith Seitz <keiths@redhat.com>
2024-08-28 14:14:43 -06:00
Tom de Vries
b5070480d7 [gdb/symtab] Change DWARF_ERROR from Dwarf Error to DWARF Error
It was suggested here [1] that the canonical prefix for dwarf errors
should not be "Dwarf Error: ", given that the canonical spelling is DWARF
instead of Dwarf.

Fix this by using "DWARF Error: " instead.

Given the use of DWARF_ERROR_PREFIX, that needs to be changed only in a single
location.

Tested on x86_64-linux.

Suggested-By: Tom Tromey <tom@tromey.com>
Approved-By: Tom Tromey <tom@tromey.com>

[1] https://sourceware.org/pipermail/gdb-patches/2024-August/211258.html
2024-08-27 09:08:41 +02:00
Tom de Vries
408dac3f45 [gdb/symtab] Use DWARF_ERROR_PREFIX
Result of:
...
$ sed -i 's/"Dwarf Error: /DWARF_ERROR_PREFIX\n"/' gdb/dwarf2/*
...
and manually fixing indentation.

No functional changes.

Tested on x86_64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
2024-08-27 09:08:41 +02:00
Tom de Vries
25cd029a62 [gdb/symtab] Add gdb/dwarf2/error.h
Add a new header file gdb/dwarf2/error.h, containing macros:
- DWARF_ERROR, and
- DWARF_ERROR_PREFIX.

The DWARF_ERROR_PREFIX is to be used in dwarf errors in a follow-up patch.

No functional changes.

Tested on x86_64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
2024-08-27 09:08:41 +02:00
Tom de Vries
f6f07a0b92 [gdb/symtab] Use [in module %s] notation more consistently in dwarf errors
In gdb/dwarf2/read.c, I found a few strings "in module %s":
...
$ grep "in module %s" gdb/dwarf2/read.c | fgrep -v '['
		     "DIE at %s in module %s"),
      error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
    error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
	error (_("Dwarf Error: DIE at %s referenced in module %s "
      error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
    error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
...
that are not using the commonly used "[in module %s]" notation.  Fix these.

In one case, the string was also used in the middle rather than at the end of
the message, so fix that as well.

Tested on x86_64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
2024-08-27 09:08:41 +02:00
Dmitry Neverov
e814012b2b Recognize -2 as a tombstone value in .debug_line
Commit a8caed5d7f handled the tombstone
value -1 used by lld (https://reviews.llvm.org/D81784).  The
referenced lld commit also uses the tombstone value -2 for
pre-DWARF-v5
(e618ccbf43).

If not handled, -2 breaks the pc step range calculation and triggers
the assertion:

  gdb/infrun.c:2794: internal-error: resume_1: Assertion
  `pc_in_thread_step_range (pc, tp)' failed.

This commit adds -2 tombstone value and handles it in the same way as -1.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31727
Approved-By: Tom Tromey <tom@tromey.com>
2024-08-25 10:43:05 +02:00
Aaron Merey
aa35682ce5 gdb/dwarf2: Check for null abbrev_info ptr
A corrupt debuginfo file can result in a null abbrev_info pointer
being passed to cooked_indexer::scan_attributes.  This pointer
is set to nullptr by peek_die_abbrev when an abbrev of 0 is found.

There is no check for whether the abbrev pointer is null and
SIGSEGV occurs when attempting to dereference the pointer.

An abbrev of 0 normally indicates that the corresponding DIE is a
null entry, but scan_attributes expects a non-null DIE.

Fix this by throwing an error in cooked_indexer::scan_attributes
when peek_die_abbrev returns a nullptr in order to avoid
scan_attributes calling itself with a null abbrev.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31478
Co-authored-by: Tom de Vries <tdevries@suse.de>
Approved-By: Tom Tromey <tom@tromey.com>
2024-08-23 16:10:36 -04:00
Tom de Vries
573d8bb08b [gdb/symtab] Return correct reader for top-level CU in cooked_indexer::ensure_cu_exists
With the test-case included in this patch, we run into:
...
$ gdb -q -batch $exec
Dwarf Error: Could not find abbrev number 3 in CU at offset 0xdb \
  [in module $exec]
...

The debug info consists of two CUs:
...
  Compilation Unit @ offset 0xb2:
   Length:        0x25 (32-bit)
   Version:       4
   Abbrev Offset: 0x6c
   Pointer Size:  8
 <0><bd>: Abbrev Number: 1 (DW_TAG_compile_unit)
    <be>   DW_AT_language    : 2	(non-ANSI C)
 <1><bf>: Abbrev Number: 2 (DW_TAG_subprogram)
    <c0>   DW_AT_low_pc      : 0x4004a7
    <c8>   DW_AT_high_pc     : 0x4004b2
    <d0>   DW_AT_specification: <0xe8>
 <1><d4>: Abbrev Number: 3 (DW_TAG_subprogram)
    <d5>   DW_AT_name        : main
 <1><da>: Abbrev Number: 0
  Compilation Unit @ offset 0xdb:
   Length:        0xf (32-bit)
   Version:       4
   Abbrev Offset: 0x86
   Pointer Size:  8
 <0><e6>: Abbrev Number: 1 (DW_TAG_compile_unit)
    <e7>   DW_AT_language    : 2	(non-ANSI C)
 <1><e8>: Abbrev Number: 2 (DW_TAG_subprogram)
    <e9>   DW_AT_specification: <0xd4>
 <1><ed>: Abbrev Number: 0
...
where:
- DIE 0xbf in CU@0xb2 contains an inter-CU reference to
- DIE 0xe8 in CU@0xdb, which contains an inter-CU reference to
- DIE 0xd4 back in CU@0xb2.

The dwarf error is caused by this bit of code in
cooked_indexer::ensure_cu_exists:
...
  if (per_cu == m_per_cu)
    return reader;
...

The dwarf error happens as follows:
- a cutu_reader A is created for CU@0xb2
- using cutu_reader A, the cooked index reader starts indexing dies, with
  m_per_cu set to CU@0xb2
- while indexing it scans the attributes of DIE 0xbf and encounters the
  inter-CU reference to DIE 0xe8
- it calls cooked_indexer::ensure_cu_exists, which creates a cutu_reader B for
  CU@0xdb and returns it
- using cutu_reader B, it continues scanning attributes of DIE 0xe8 and
  encounters the inter-CU reference to DIE 0xd4
- it calls cooked_indexer::ensure_cu_exists, the problematic bit is triggered
  and cutu_reader B is returned
- using cutu_reader B, it continues scanning attributes of DIE 0xd4
- this goes wrong because:
  - the attributes of the DIE are encoded using the abbreviation table at
    offset 0x6c, while
  - the decoding is done using cutu_reader B which uses the abbreviation table
    at offset 0x86.

Fix this by removing the problematic if clause.

Since cutu_reader A is not preserved in m_index_storage,
cooked_indexer::ensure_cu_exists cannot find it there and creates a duplicate
cutu_reader C for CU@0xb2.  Fix this in process_psymtab_comp_unit by preserving
the cutu_reader A as well in m_index_storage.

Tested on x86_64-linux and aarch64-linux.

PR symtab/32081
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32081

Approved-By: Tom Tromey <tom@tromey.com>
Reported-By: Andreas Schwab <schwab@linux-m68k.org>
2024-08-22 10:00:27 +02:00
Tom Tromey
5d683ae3da Do not assume ELF in dwarf2/read.c
dwarf2/read.c has this code:

  else if (elf_section_data (sectp)->this_hdr.sh_size
	   > bfd_get_file_size (abfd))

This assumes that the BFD is an ELF, which is an invalid assumption.
A user noticed that this can sometimes cause a crash.

This patch fixes the problem by changing this code to use
bfd_section_size_insane.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32104
Reviewed-By: Tom de Vries <tdevries@suse.de>
Reviewed-by: Keith Seitz <keiths@redhat.com>
2024-08-21 10:33:46 -06:00
Tom Tromey
219036b4fa Simplify typename_concat
This patch simplifies typename_concat, changing the return type and
removing the obstack allocation code.  The latter is possible because
the only caller using this mode uses the name when creating a new
type, and 'new_type' copies the string to the appropriate obstack
anyway.  It also changes typename_concat to use 'concat'.  This change
lets us remove a mildly fragile macro as well.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2024-08-12 12:16:15 -06:00
Simon Marchi
2e7c4d0fe5 gdb: add program_space parameter to lookup_minimal_symbol_linkage
Make the current_program_space reference bubble up one level.

Change-Id: Ic349dc96b7d375ad7c66022d84657136f0de8c87
Reviewed-by: Keith Seitz <keiths@redhat.com>
Approved-By: Andrew Burgess <aburgess@redhat.com>
2024-08-12 10:38:29 -04:00
Simon Marchi
4144d36a68 gdb: add program_space parameter to lookup_minimal_symbol
>From what I can see, lookup_minimal_symbol doesn't have any dependencies
on the global current state other than the single reference to
current_program_space.  Add a program_space parameter and make that
current_program_space reference bubble up one level.

Change-Id: I759415e2f9c74c9627a2fe05bd44eb4147eee6fe
Reviewed-by: Keith Seitz <keiths@redhat.com>
Approved-By: Andrew Burgess <aburgess@redhat.com>
2024-08-12 10:31:09 -04:00
Simon Marchi
c8979ae4fb gdb: make lookup_minimal_symbol objf and sfile parameters optional
Most calls to lookup_minimal_symbol don't pass a value for sfile and
objf.  Make these parameters optional (have a default value of
nullptr).  And since passing a value to `objf` is much more common than
passing a value to `sfile`, swap the order so `objf` comes first, to
avoid having to pass a nullptr value to `sfile` when wanting to pass a
value to `objf`.

Change-Id: I8e9cc6b942e593bec640f9dfd30f62786b0f5a27
Reviewed-by: Keith Seitz <keiths@redhat.com>
Approved-By: Andrew Burgess <aburgess@redhat.com>
2024-08-12 10:31:09 -04:00
Simon Marchi
03b40f6f55 gdb: drop struct keyword when using bound_minimal_symbol
This is a simple find / replace from "struct bound_minimal_symbol" to
"bound_minimal_symbol", to make things shorter and more consisten
througout.  In some cases, move variable declarations where first used.

Change-Id: Ica4af11c4ac528aa842bfa49a7afe8fe77a66849
Reviewed-by: Keith Seitz <keiths@redhat.com>
Approved-By: Andrew Burgess <aburgess@redhat.com>
2024-08-12 10:31:09 -04:00
Tom de Vries
4e7b18de44 [gdb/symtab] Emit malformed macro definition complaint once
Add a test-case gdb.dwarf2/macro-complaints.exp, that checks complaints for the
.debug_macro section.

For one malformed macro definition, I get two identical complaints:
...
During symbol reading: macro debug info contains a malformed macro definition:^M
`M1_11_MALFORMED(ARG'^M
During symbol reading: macro debug info contains a malformed macro definition:^M
`M1_11_MALFORMED(ARG'^M
...

Fix this by bailing out after the first one.

Tested on aarch64-linux.

Reviewed-By: Alexandra Petlanova Hajkova <ahajkova@redhat.com>
2024-07-30 16:56:31 +02:00
Simon Marchi
1cb8a69ec2 gdb: use std::string vector for macro definition
Use std::vector<std::string> when defining macros, to avoid the manual
memory management.

With the use of std::vector, the separate `int argc` parameter is no
longer needed, we can use the size of the vector instead.  However, for
some functions, this parameter had a dual function.  For object-like
macros, it was interpreted as a `macro_special_kind` enum.  For these
functions, remove `argc`, but add a new `special_kind` parameter.

Change-Id: Ice76a6863dfe598335e3b8d5d077513e50975cc5
Approved-By: Tom de Vries <tdevries@suse.de>
2024-07-30 08:52:57 -04:00
Simon Marchi
d9deb60b2e gdb, gdbserver, gdbsupport: use [[noreturn]] instead of ATTRIBUTE_NORETURN
C++ 11 has a built-in attribute for this, no need to use a compat macro.

Change-Id: I90e4220d26e8f3949d91761f8a13cd9c37da3875
Reviewed-by: Lancelot Six <lancelot.six@amd.com>
2024-07-16 18:30:45 -04:00
Andrew Burgess
88aad97c21 gdb: add overloads of gdb_abspath
Add two overloads of gdb_abspath, one which takes std::string and one
which takes gdb::unique_xmalloc_ptr<char>, then make use of these
overloads throughout GDB and gdbserver.

There should be no user visible changes after this commit.

Approved-By: Tom Tromey <tom@tromey.com>
2024-06-27 15:15:25 +01:00
Schimpe, Christina
2a56698523 gdb: use alternative for demangled name for non-demangeable linkage names
In case a DIE contains a linkage name which cannot be demangled and
a source language name (DW_AT_NAME) exists then we want to display this name
instead of the non-demangeable linkage name.

dwarf2_physname returns the linkage name in case the linkage name
cannot be demangled.  Before this patch we always set the returned physname
as demangled name.  This patch changes this by comparing the value
of physname with the linkage name.  Now after this change in case it is equals
to the linkage name and if DW_AT_NAME exists then this is set as the demangled
name otherwise like before still linkage name is used.

For the reproducer, using the test source file added in this change:
"gdb/testsuite/gdb.dwarf2/dw2-wrong-mangled-name.c"

Here is an example of the DWARF where wrong linkage name is emitted by the
compiler for the "func_demangled_test" function:

subprogram {
    {MACRO_AT_range {func_demangled_test}}
    {linkage_name "_FUNC_WRONG_MANGLED__"}
    {name "func_demangled_test"}
    {external 1 flag}
}
subprogram {
    {MACRO_AT_range {main}}
    {external 1 flag}
    {name main}
    {main_subprogram 1 flag}
}

Before this change for a function having both DIEs DW_AT_name and
DW_AT_LINKAGENAME but with the wrong linkage name info, the backtrace
command shows following:

(gdb) b func_demangled_test
(gdb) r
Breakpoint 1, 0x0000555555555131 in _FUNC_WRONG_MANGLED__ ()
(gdb) backtrace
\#0  0x0000555555555131 in  _FUNC_WRONG_MANGLED__ ()
\#1  0x000055555555514a in main ()

After the change now GDB shows the name emitted by DW_AT_NAME:

(gdb) b func_demangled_test
(gdb) r
Breakpoint 1, 0x0000555555555131 in func_demangled_test ()
(gdb) backtrace
\#0  0x0000555555555131 in func_demangled_test ()
\#1  0x000055555555514a in main ()

A new test is added to verify this change.

Approved-By: Tom Tromey <tom@tromey.com>
2024-06-25 12:42:29 +02:00
Tom de Vries
bd54c881cd [gdb/symtab] Remove dead code in parse_macro_definition
In parse_macro_definition, there's a loop:
...
  for (p = body; *p; p++)
    if (*p == ' ' || *p == '(')
      break;
...
whose post-condition is:
...
  gdb_assert (*p == ' ' || *p == '(' || *p == '\0');
...

Consequently, in the following:
...
  if (*p == ' ' || *p == '\0')
    <BODY1>
  else if (*p == '(')
    <BODY2>
  else
    <BODY3>
...
BODY3 is dead code.

Remove it, and get rid of unnecessary indentation by using an early-exit:
....
  if (*p == ' ' || *p == '\0')
    {
      <BODY1>
      return;
    }

  gdb_assert (*p == '(');
  <BODY2>
...

Tested on aarch64-linux.

Reviewed-By: Alexandra Petlanova Hajkova <ahajkova@redhat.com>
Approved-By: Tom Tromey <tom@tromey.com>
2024-06-25 07:59:13 +02:00
Tom Tromey
979114a1b3 Prefer htab_traverse_noresize
A few spots in gdb were using htab_traverse.  IMO this is almost never
useful and htab_traverse_noresize should be preferred.
2024-06-24 09:11:30 -06:00
Tom Tromey
4122e647d5 Don't obstack-allocate the call site hash table
The call site hash table is the last hash table using obstack
allocation.  In one large (non-public) test case, these hash tables
take a substiantial amount of memory.  Some of this memory is wasted
-- whenever the hash table is resized, the old table is not freed.

This patch fixes the problem by changing this hash table to be
heap-allocated.  This means that resizing will no longer "leak"
memory.
2024-06-24 09:11:30 -06:00
Tom Tromey
5e6ab40868 Don't obstack-allocate the CU dependency hash table
The CU dependency hash table is obstack-allocated, but there's no need
to do this.
2024-06-24 09:11:29 -06:00
Tom Tromey
7682ef5a19 Don't obstack-allocate the DIE hash
The DIE hash table is currently allocated on an obstack.  There's no
need to do this, and I think it's better to simply heap-allocate the
hash table.

This patch implements this.  I also removed store_in_ref_table as
well, inlining it into its sole caller, as I think this is clearer.
2024-06-24 09:11:29 -06:00
Tom de Vries
b49c3a37b1 [gdb/symtab] Fix target type of complex long double on arm
When running test-case gdb.base/complex-parts.exp on arm-linux, I get:
...
(gdb) p $_cimag (z3)^M
$6 = 6.5^M
(gdb) PASS: gdb.base/complex-parts.exp: long double imaginary: p $_cimag (z3)
ptype $^M
type = double^M
(gdb) FAIL: gdb.base/complex-parts.exp: long double imaginary: ptype $
...

Given that z3 is a complex long double, the test-case expects the type of the
imaginary part of z3 to be long double, but it's double instead.

This is due to the fact that the dwarf info doesn't specify an explicit target
type:
...
    <5b>   DW_AT_name        : z3
    <60>   DW_AT_type        : <0xa4>
  ...
 <1><a4>: Abbrev Number: 2 (DW_TAG_base_type)
    <a5>   DW_AT_byte_size   : 16
    <a6>   DW_AT_encoding    : 3        (complex float)
    <a7>   DW_AT_name        : complex long double
...
and consequently we're guessing in dwarf2_init_complex_target_type based on
the size:
...
	case 64:
	  tt = builtin_type (gdbarch)->builtin_double;
	  break;
	case 96: /* The x86-32 ABI specifies 96-bit long double.  */
	case 128:
	  tt = builtin_type (gdbarch)->builtin_long_double;
	  break;
...

For arm-linux, complex long double is 16 bytes, so the target type is assumed
to be 8 bytes, which is handled by the "case 64", which gets us double
instead of long double.

Fix this by searching for "long" in the name_hint parameter, and using long
double instead.

Note that base types in dwarf are not allowed to contain references to other
types, and the complex types are base types, so the missing explicit target
type is standard-conformant.

A gcc PR was filed to add this as a dwarf extension (
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115272 ).

Tested on arm-linux.
2024-06-19 17:32:55 +02:00
Tom Tromey
2e3b7a3893 Move dwarf2_per_bfd::index_addrmap to mapped_gdb_index
dwarf2_per_bfd::index_addrmap is only used by the .gdb_index reader,
so this field can be moved to mapped_gdb_index instead.  Then,
cooked_index_functions::find_per_cu can be removed in favor of a
method on the index object.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31821
Approved-By: Simon Marchi <simon.marchi@efficios.com>
2024-05-31 08:26:05 -06:00
Simon Marchi
05d9d66d92 gdb: remove unused includes in utils.h
Remove some includes reported as unused by clangd.  Add some includes in
other files that were previously relying on the transitive include.

Change-Id: Ibdd0a998b04d21362a20d0ca8e5267e21e2e133e
2024-05-30 22:43:52 -04:00
Tom Tromey
b013bd1663 Default dwarf_synchronous to true
Unfortunately the background DWARF reading series introduced a number
of races, as repored by thread sanitizer.  This patch changes gdb to
disable this feature for the time being -- in particular for the gdb
15 release.

I've filed a bug and linked all the known races to it.  Once those are
fixed we can re-enable this feature by default.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31751
2024-05-22 10:14:06 -06:00
Dmitry Neverov
1f8243f039 gdb/symtab: use symbol name matcher for all segments in a qualified name 2024-05-17 08:02:30 -06:00
Dmitry Neverov
1cd542c8e9 gdb/symtab: compute match_type outside the loop
It will be used for all segments in a qualified name,
not only the last one.

Approved-By: Tom Tromey <tom@tromey.com>
2024-05-17 08:02:30 -06:00
Dmitry Neverov
5d0e164203 gdb/symtab: reuse last segment lookup name info by creating it outside the loop 2024-05-17 08:02:29 -06:00
Dmitry.Neverov
3a0fae3129 gdb/symtab: check name matches before expanding a CU
The added check fixes the case when an unqualified lookup
name without template arguments causes expansion of many CUs
which contain the name with template arguments.

This is similar to what dw2_expand_symtabs_matching_symbol does
before expanding the CU.

In the referenced issue the lookup name was wxObjectDataPtr and many
CUs had names like wxObjectDataPtr<wxBitmapBundleImpl>. This caused
their expansion and the lookup took around a minute. The added check
helps to avoid the expansion and makes the symbol lookup to return in
a second or so.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30520
2024-05-17 08:02:29 -06:00
Hannes Domani
5140d8e013 Fix heap-use-after-free in index-cached with --disable-threading
If threads are disabled, either by --disable-threading explicitely, or by
missing std::thread support, you get the following ASAN error when
loading symbols:

==7310==ERROR: AddressSanitizer: heap-use-after-free on address 0x614000002128 at pc 0x00000098794a bp 0x7ffe37e6af70 sp 0x7ffe37e6af68
READ of size 1 at 0x614000002128 thread T0
    #0 0x987949 in index_cache_store_context::store() const ../../gdb/dwarf2/index-cache.c:163
    #1 0x943467 in cooked_index_worker::write_to_cache(cooked_index const*, deferred_warnings*) const ../../gdb/dwarf2/cooked-index.c:601
    #2 0x1705e39 in std::function<void ()>::operator()() const /gcc/9/include/c++/9.2.0/bits/std_function.h:690
    #3 0x1705e39 in gdb::task_group::impl::~impl() ../../gdbsupport/task-group.cc:38

0x614000002128 is located 232 bytes inside of 408-byte region [0x614000002040,0x6140000021d8)
freed by thread T0 here:
    #0 0x7fd75ccf8ea5 in operator delete(void*, unsigned long) ../../.././libsanitizer/asan/asan_new_delete.cc:177
    #1 0x9462e5 in cooked_index::index_for_writing() ../../gdb/dwarf2/cooked-index.h:689
    #2 0x9462e5 in operator() ../../gdb/dwarf2/cooked-index.c:657
    #3 0x9462e5 in _M_invoke /gcc/9/include/c++/9.2.0/bits/std_function.h:300

It's happening because cooked_index_worker::wait always returns true in
this case, which tells cooked_index::wait it can delete the m_state
cooked_index_worker member, but cooked_index_worker::write_to_cache tries
to access it immediately afterwards.

Fixed by making cooked_index_worker::wait only return true if desired_state
is CACHE_DONE, same as if threading was enabled, so m_state will not be
prematurely deleted.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31694
Approved-By: Tom Tromey <tom@tromey.com>
2024-05-04 18:55:20 +02:00
Tom Tromey
b42d685452 Remove dwarf2_per_objfile::adjust
All the calls to dwarf2_per_objfile::adjust have been removed, so we
can remove this function entirely.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31261
2024-05-04 09:30:31 -06:00
Tom Tromey
12fddc10c3 Remove call to dwarf2_per_objfile::adjust from read_attribute_value
Currently, read_attribute_value calls dwarf2_per_objfile::adjust on
any address.  This seems wrong, because the address may not even be in
the text section.

Luckily, this call is also not needed, because read_func_scope calls
'relocate', which does the same work.
2024-05-04 09:30:30 -06:00
Tom Tromey
6142f7cd83 Remove call to dwarf2_per_objfile::adjust from read_call_site_scope
read_call_site_scope does not need to call 'adjust', because in
general the call site is not a symbol address, but rather just the
address of some particular call.
2024-05-04 09:30:30 -06:00
Tom Tromey
a5a4010189 Remove more calls to dwarf2_per_objfile::adjust
As with the previous patch, this patch removes some calls to
dwarf2_per_objfile::adjust.  These calls are not needed by the cooked
indexer, as it does not create symbols or look up symbols by address.

The call in dwarf2_ranges_read is similarly not needed, as it is only
used to update an addrmap; and in any case I believe this particular
call is only reached by the indexer.
2024-05-04 09:30:30 -06:00
Tom Tromey
91fc201ed4 Remove call to dwarf2_per_objfile::adjust from ranges readers
dwarf2_per_objfile::adjust applies gdbarch_adjust_dwarf2_addr to an
address, leaving the result unrelocated.  However, this adjustment is
only needed for text-section symbols -- it isn't needed for any sort
of address mapping.  Therefore, these calls can be removed from
read_addrmap_from_aranges and create_addrmap_from_gdb_index.

Approved-By: Andrew Burgess <aburgess@redhat.com>
2024-05-04 09:30:30 -06:00
Tom de Vries
5ce0e02478 [gdb/symtab] Work around PR gas/29517, dwarf2 case
In commit 1d45d90934 ("[gdb/symtab] Work around PR gas/29517") we added a
workaround for PR gas/29517.

The problem is present in gas version 2.39, and fixed in 2.40, so the
workaround is only active for gas version == 2.39.

However, the problem in gas is only fixed for dwarf version >= 3, which
supports DW_TAG_unspecified_type.

Fix this by also activating the workaround for dwarf version == 2.

Tested on x86_64-linux.

Approved-by: Kevin Buettner <kevinb@redhat.com>

PR symtab/31689
https://sourceware.org/bugzilla/show_bug.cgi?id=31689
2024-05-02 09:34:46 +02:00
Simon Marchi
5b9707eb87 gdb: remove gdbcmd.h
Most files including gdbcmd.h currently rely on it to access things
actually declared in cli/cli-cmds.h (setlist, showlist, etc).  To make
things easy, replace all includes of gdbcmd.h with includes of
cli/cli-cmds.h.  This might lead to some unused includes of
cli/cli-cmds.h, but it's harmless, and much faster than going through
the 170 or so files by hand.

Change-Id: I11f884d4d616c12c05f395c98bbc2892950fb00f
Approved-By: Tom Tromey <tom@tromey.com>
2024-04-25 12:59:02 -04:00
Simon Marchi
e5dc0d5d04 gdb: move a bunch of quit-related things to event-top.{c,h}
Move some declarations related to the "quit" machinery from defs.h to
event-top.h.  Most of the definitions associated to these declarations
are in event-top.c.  The exceptions are `quit()` and `maybe_quit()`,
that are defined in utils.c.  For consistency, move these two
definitions to event-top.c.

Include "event-top.h" in many files that use these things.

Change-Id: I6594f6df9047a9a480e7b9934275d186afb14378
Approved-By: Tom Tromey <tom@tromey.com>
2024-04-23 11:26:14 -04:00
Simon Marchi
ff191ddf80 gdb/dwarf2/read.c: remove pessimizing std::move
When building with this clang:

    $ c++ --version
    FreeBSD clang version 16.0.6 (https://github.com/llvm/llvm-project.git llvmorg-16.0.6-0-g7cbf1a259152)

I see:

    $ gmake
      CXX    dwarf2/read.o
    /home/smarchi/src/binutils-gdb/gdb/dwarf2/read.c:4890:6: error: moving a temporary object prevents copy elision [-Werror,-Wpessimizing-move]
                                            std::move (thread_storage.release_parent_map ()));
                                            ^
    /home/smarchi/src/binutils-gdb/gdb/dwarf2/read.c:4890:6: note: remove std::move call here
                                            std::move (thread_storage.release_parent_map ()));
                                            ^~~~~~~~~~~                                    ~

The compiler seems right, there is not need to std::move the result of
`release_parent_map ()`, it's already going to be an rvalue.  Remove the
std::move.

The issue isn't FreeBSD-specific, I see it on Linux as well when
building hwith clang, I just noticed it on a FreeBSD build first.

Change-Id: I7aa20a4db56c799f20d838ad08099a01653bba19
Approved-By: Tom Tromey <tom@tromey.com>
2024-04-23 10:40:12 -04:00
Simon Marchi
740ccea39e gdb: don't include hashtab.h in defs.h
Nothing in defs.h actually uses this.

Add some includes for some spots using things from hashtab.h.  Note that
if the GDB build doesn't use libxxhash, hashtab.h is included by
gdbsupport/common-utils.h, so all files still see hashtab.h.  It puzzled
me for some time why I didn't see build failures in my build (which
didn't use libxxhash) but the buildbot gave build failures (it uses
libxxhash).

Change-Id: I8efd68decdaf579f048941c7537cd689885caa2a
Approved-By: John Baldwin <jhb@FreeBSD.org>
2024-04-22 21:34:19 -04:00
Simon Marchi
ec45252592 gdb: move store/extract integer functions to extract-store-integer.{c,h}
Move the declarations out of defs.h, and the implementations out of
findvar.c.

I opted for a new file, because this functionality of converting
integers to bytes and vice-versa seems a bit to generic to live in
findvar.c.

Change-Id: I524858fca33901ee2150c582bac16042148d2251
Approved-By: John Baldwin <jhb@FreeBSD.org>
2024-04-22 21:34:19 -04:00
Simon Marchi
523e454fab gdbsupport: constify some return values in print-utils.{h,cc}
There is no reason the callers of these functions need to change the
returned string, so change the `char *` return types to `const char *`.

Update a few callers to also use `const char *`.

Change-Id: I94adff574d5e1b326e8cc688cf1817a15b408b96
Approved-By: Tom Tromey <tom@tromey.com>
2024-04-18 10:31:54 -04:00