Commit graph

52947 commits

Author SHA1 Message Date
Simon Marchi
c5c3b90970 gdb-gdb.py: strip typedefs in intrusive_list printer assertion
When debugging gdb itself and trying to print a intrusive_list that has
more than one element, I get:

    File "/home/simark/build/binutils-gdb-all-targets/gdb/gdb-gdb.py", line 365, in _children_generator
      node_ptr = self._as_node_ptr(elem_ptr)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/home/simark/build/binutils-gdb-all-targets/gdb/gdb-gdb.py", line 345, in _as_node_ptr
      assert elem_ptr.type.code == gdb.TYPE_CODE_PTR
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    AssertionError

This is because node_ptr is a typedef
(intrusive_list_base_iterator::pointer).  Add a call to strip_typedefs
to get to the real type.

Enhance gdb.gdb/python-helper.exp with a test that would have caught
this bug.

Change-Id: I3eaca8de5ed06d05756ed979332b6a431e15b700
Approved-By: Andrew Burgess <aburgess@redhat.com>
2024-07-19 16:30:52 -04:00
Andrew Burgess
22836ca885 gdb: check for multiple matching build-id files
Within the debug-file-directory GDB looks for the existence of a
.build-id directory.

Within the .build-id directory GDB looks for files with the form:

  .build-id/ff/4b4142d62b399499844924d53e33d4028380db.debug

which contain the debug information for the objfile with the build-id
ff4b4142d62b399499844924d53e33d4028380db.

There appear to be two strategies for populating the .build-id
directory.  Ubuntu takes the approach of placing the actual debug
information in this directory, so
4b4142d62b399499844924d53e33d4028380db.debug is an actual file
containing the debug information.

Fedora, RHEL, and SUSE take a slightly different approach, placing the
debug information elsewhere, and then creating symlinks in the
.build-id directory back to the original debug information file.  The
actual debug information is arranged in a mirror of the filesystem
within the debug directory, as an example, if the debug-file-directory
is /usr/lib/debug, then the debug information for /bin/foo can be
found in /usr/lib/debug/bin/foo.debug.

Where this gets interesting is that in some cases a package will
install a single binary with multiple names, in this case a single
binary will be install with either hard-links, or symlinks providing
the alternative names.

The debug information for these multiple binaries will then be placed
into the /usr/lib/debug/ tree, and again, links are created so a
single file can provide debug information for each of the names that
binary presents as.  An example file system might look like this (the
[link] could be symlinks, but are more likely hard-links):

  /bin/
    foo
    bar -> foo	[ HARD LINK ]
    baz -> foo	[ HARD LINK ]
  /usr/
    lib/
      debug/
        bin/
	  foo.debug
	  bar.debug -> foo.debug	[ HARD LINK ]
	  baz.debug -> foo.debug	[ HARD LINK ]

In the .build-id tree though we have a problem.  Do we have a single
entry that links to one of the .debug files?  This would work; a user
debugging any of the binaries will find the debug information based on
the build-id, and will get the correct information, after all the
.debug files are identical (same file linked together).  But there is
one problem with this approach.

Sometimes, for *reasons* it's possible that one or more the linked
binaries might get removed, along with its associated debug
information.  I'm honestly not 100% certain under what circumstances
this can happen, but what I observe is that sometime a single name for
a binary, and its corresponding .debug entry, can be missing.  If this
happens to be the entry that the .build-id link is pointing at, then
we have a problem.  The user can no longer find the debug information
based on the .build-id link.

The solution that Fedora, RHEL, & SUSE have adopted is to add multiple
entries in the .build-id tree, with each entry pointing to a different
name within the debug/ tree, a sequence number is added to the
build-id to distinguish the multiple entries.  Thus, we might end up
with a layout like this:

  /bin/
    foo
    bar -> foo	[ HARD LINK ]
    baz -> foo	[ HARD LINK ]
  /usr/
    lib/
      debug/
        bin/
	  foo.debug
	  bar.debug -> foo.debug	[ HARD LINK ]
	  baz.debug -> foo.debug	[ HARD LINK ]
      .build-id/
        a3/
          4b4142d62b399499844924d53e33d4028380db.debug -> ../../debug/bin/foo.debug	[ SYMLINK ]
          4b4142d62b399499844924d53e33d4028380db.1.debug -> ../../debug/bin/bar.debug	[ SYMLINK ]
          4b4142d62b399499844924d53e33d4028380db.2.debug -> ../../debug/bin/baz.debug	[ SYMLINK ]

With current master GDB, debug information will only ever be looked up
via the 4b4142d62b399499844924d53e33d4028380db.debug link.  But if
'foo' and its corresponding 'foo.debug' are ever removed, then master
GDB will fail to find the debug information.

Ubuntu seems to have a much better approach for debug information
handling; they place the debug information directly into the .build-id
tree, so there only ever needs to be a single entry for any one
build-id.  I wonder if/how they handle the case where multiple names
might share a single .debug file, if one of those names is then
uninstalled, how do they know the .debug file should be retained or
not ... but I assume that problem either doesn't exist or has been
solved.

Anyway, for a while Fedora has carried a patch that handles the
build-id sequence number logic.  What's presented here is inspired by
the Fedora patch, but has some changes to fix some issues.

I'm aware that this is a patch that applies to only some (probably a
minority) of distros.  However, the logic is contained to only a
single function in build-id.c, and isn't too complex, so I'm hoping
that there wont be too many objections.

For distros that don't have build-id sequence numbers there should be
no impact.  The sequence number approach still leaves the first file
without a sequence number, and this is the first file that GDB (after
this patch) checks for.  The new logic only kicks in if the
non-sequence numbered first file exists, but is a symlink to a non
existent file; in this case GDB checks for the sequence numbered files
instead.

Tests are included.

There is a small fix needed for gdb.base/sysroot-debug-lookup.exp,
after this commit GDB now treats a target: sysroot where the target
file system is local to GDB the same as if the sysroot had no target:
prefix.  The consequence of this is that GDB now resolves a symlink
back to the real filename in the sysroot-debug-lookup.exp test where
it didn't previously.  As this behaviour is inline with the case where
there is no target: prefix I think this is fine.
2024-07-18 13:24:20 +01:00
Andrew Burgess
3055e3d2f1 gdb: add GDB side target_ops::fileio_stat implementation
This commit adds the GDB side of target_ops::fileio_stat.  There's an
implementation for inf_child_target, which just calls 'lstat', and
there's an implementation for remote_target, which sends a new
vFile:stat packet.

The new packet is documented.

There's still no users of target_fileio_stat as I have not yet added
support for vFile::stat to gdbserver.  If these packets are currently
sent to gdbserver then they will be reported as not supported and the
ENOSYS error code will be returned.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
2024-07-18 13:24:20 +01:00
Andrew Burgess
08a115cc1c gdb: add target_fileio_stat, but no implementations yet
In a later commit I want target_fileio_stat, that is a call that
operates on a filename rather than an open file descriptor as
target_fileio_fstat does.

This commit adds the initial framework for target_fileio_stat, I've
added the top level target function and the virtual target_ops methods
in the target_ops base class.

At this point no actual targets override target_ops::fileio_stat, so
any attempts to call this function will return ENOSYS error code.
2024-07-18 13:24:20 +01:00
Tom de Vries
0ed152c5c6 [gdb/testsuite] Fix gdb.arch/arm-pseudo-unwind.exp with unix/mthumb
When running test-case gdb.arch/arm-pseudo-unwind.exp with target board
unix/mthumb, we run into:
...
(gdb) continue^M
Continuing.^M
^M
Program received signal SIGILL, Illegal instruction.^M
0x00400f38 in ?? ()^M
(gdb) FAIL: $exp: continue to breakpoint: continue to callee
...

The test-case attempts to force arm-pseudo-unwind.c to be compiled in arm mode
using additional_flags=-marm, but that's overridden by using target board
unix/mthumb.

This causes function main to be in thumb mode, and consequently function
caller (which is called from main) is is executed as if it's in thumb mode,
while it's actually in arm mode.

Fix this by adding an intermediate function caller_trampoline in
arm-pseudo-unwind.c, and hardcoding it to arm mode using
__attribute__((target("arm"))).

Likewise for test-case gdb.arch/arm-pseudo-unwind-legacy.exp.

Tested on arm-linux.

Approved-By: Luis Machado <luis.machado@arm.com>
2024-07-17 17:04:02 +02: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
Simon Marchi
9153eb8a7f gdb: fix indentation in remote.c
Change-Id: If344acdf703fdd3892f73f75fc891d5473808b79
2024-07-16 14:05:14 -04:00
Simon Marchi
a7a430a68c gdb: add ATTRIBUTE_NORETURN to remote_unpush_target
My IDE (well, clangd) suggested this.  It doesn't hurt to have it.

Change-Id: If6001983c17dbed3dceebac3078c8deb12c04d6b
2024-07-16 14:03:27 -04:00
Tom de Vries
b6a5604da0 [gdb/testsuite] Simplify gdb.base/complex-parts.exp
I noticed a lot of escaping in test-case gdb.base/complex-parts.exp.

Make the test-case more readable by using:
- string_to_regexp, and
- {} instead of "".

Tested on x86_64-linux and aarch64-linux.
2024-07-16 17:22:04 +02:00
Simon Marchi
58a775a606 gdb: pass program space to overlay_invalidate_all
Make the current program space bubble up one level.

Change-Id: I5ac1e3290ad266730465cd60aa3672d45ffa6475
2024-07-15 14:40:14 -04:00
Simon Marchi
8991986e24 gdb: pass program space to objfile::make
Make the current program space reference bubble up one level.

Change-Id: Iee8b11c853c76e539c991c4785737c69e6a1925c
Approved-By: Tom Tromey <tom@tromey.com>
Reviewed-By: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
2024-07-15 14:34:12 -04:00
Simon Marchi
da877546db gdb: pass program space to objfile::objfile
Make the current program space reference bubble up one level.

Change-Id: I81e45e89e0cfd87c308f801d49ae811a941348b7
Approved-By: Tom Tromey <tom@tromey.com>
Reviewed-By: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
2024-07-15 14:34:12 -04:00
Simon Marchi
d1e4438fa1 gdb: pass program space to entry_point_address
Make the current program space reference bubble up one level.

Change-Id: Ifc9b8186abaefb10caf99f79ae09e526fa65c882
Approved-By: Tom Tromey <tom@tromey.com>
Reviewed-By: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
2024-07-15 14:34:12 -04:00
Simon Marchi
b7513ebd18 gdb: pass program space to entry_point_address_query
Make the current program space bubble up one level.

Change-Id: Ic3ad0869ca1afe41854f605a6f7eb092fca29ff8
Approved-By: Tom Tromey <tom@tromey.com>
Reviewed-By: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
2024-07-15 14:34:12 -04:00
Simon Marchi
da2732476d gdb: pass program space to objfiles_changed
Make the current program space reference bubble up one level.

Change-Id: I9b33c9e0d22c171eb1bb59ce480621b02c7b7bf7
Approved-By: Tom Tromey <tom@tromey.com>
Reviewed-By: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
2024-07-15 14:34:12 -04:00
Simon Marchi
3bae94c0fb gdb: pass program space to get_current_source_symtab_and_line
Make the current program space reference bubble up one level.

Change-Id: I6ba6dc4a2cb188720cbb61b84ab5c954aac105c6
Approved-By: Tom Tromey <tom@tromey.com>
Reviewed-By: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
2024-07-15 14:34:12 -04:00
Simon Marchi
9c067e2844 gdb: pass program space to have_{full,partial}_symbols
Make the current program space reference bubble up one level.

Change-Id: I19c4fc2ca955f9c828ef426a077b43983865697b
Approved-By: Tom Tromey <tom@tromey.com>
Reviewed-By: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
2024-07-15 14:34:12 -04:00
Simon Marchi
cc7541ce5e gdb: bool-ify a few functions in objfiles.{c,h}
Change return types to bool, and make a few stylistic adjustments.

Change-Id: I784c3c33af0394a77c25064b06eb3e128e69222f
Approved-By: Tom Tromey <tom@tromey.com>
Reviewed-By: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
2024-07-15 14:34:12 -04:00
Simon Marchi
fbee6a57b2 gdb: pass program space to clear_current_source_symtab_and_line
Make the current program space reference bubble up one level.

Change-Id: I692554474d17e4f4708fd8ad662bf6c0bb964726
Approved-By: Tom Tromey <tom@tromey.com>
Reviewed-By: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
2024-07-15 14:34:12 -04:00
Simon Marchi
4113c737bd gdb: make program_space::free_all_objfiles use this
Use `this` instead of `current_program_space`.  Presumably, the method
wants to check the solibs of "this" program space, not the current
global program space (although they are likely always the same at the
moment).

Change-Id: Iaf0534f36bfd47c04c53ed0657da332bdb8fb906
Approved-By: Tom Tromey <tom@tromey.com>
Reviewed-By: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
2024-07-15 14:34:12 -04:00
Simon Marchi
b8c9d0de90 gdb: pass program space to no_shared_libraries
Make the current program space reference bubble up one level.  Pass
`current_program_space` everywhere, except in some cases where we can
get the pspace another way, and it's relatively obvious that it's the
same as the current program space.

Change-Id: Id86b79f1e44f92a398f49d137d57457174dfa96d
Approved-By: Tom Tromey <tom@tromey.com>
Reviewed-By: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
2024-07-15 14:34:12 -04:00
Simon Marchi
89dc60d957 gdb: split no_shared_libraries, command vs implementation
The `no_shared_libraries` function is currently used to implement the
`nosharedlibrary` command, but it also used internally by other
functions.  This does not make a very good internal API.

Add the `no_shared_libraries_command` function to implement the CLI
command.  Remove the unused parameters from `no_shared_libraries`.

Remove the `from_tty` parameter of `target_pre_inferior`, since it's now
unused.

Change-Id: I4fcba5ee1e0f7d250aab1a7b62b9ea16265fe962
Approved-By: Tom Tromey <tom@tromey.com>
Reviewed-By: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
2024-07-15 14:34:12 -04:00
Simon Marchi
98793b838c gdb: pass program space to objfile_purge_solibs
Make the current program space reference bubble up one level.

Change-Id: I08cfa77a0351c9602131ed2a294eabb1f1f59a6e
Approved-By: Tom Tromey <tom@tromey.com>
Reviewed-By: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
2024-07-15 14:34:12 -04:00
Simon Marchi
93016848f9 gdb: use objfile::pspace in objfile::unlink
I think it would make sense to use objfile::pspace instead of the
current program space here.  It reduces the risks of calling this
method with the wrong current program space set.

Change-Id: Id4f3644719f232640c83a1c7f4aa92eaa6af6c5c
Approved-By: Tom Tromey <tom@tromey.com>
Reviewed-By: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
2024-07-15 14:34:12 -04:00
Simon Marchi
574b77fccb gdb: remove some trivial uses of current_program_space
It is obvious that pspace is the same as current_program_space in these
cases, due to the set_current_program_space call just above.  The rest
of the functions probably care about the current program space though,
so leave the set_cset_current_program_space calls there.

Change-Id: I3c300decbf2c2fe5f25aa7f697ebcb524432394f
2024-07-15 11:07:29 -04:00
Hannes Domani
25c2284095 Fix loading a saved recording
Currently you get this assertion failure if you try to execute the
inferior after loading a saved recording, when no recording was done
earlier in the same gdb session:
```
$ gdb -q c -ex "record restore test.rec"
Reading symbols from c...
[New LWP 26428]
Core was generated by `/tmp/c'.
Restored records from core file /tmp/test.rec.
(gdb) c
Continuing.
../../gdb/inferior.c:293: internal-error: inferior* find_inferior_pid(process_stratum_target*, int): Assertion `pid != 0' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
```

The change in step-precsave.exp triggers this bug, since now the
recording is loaded in a new gdb session, where
record_full_resume_ptid was never set.

The fix is to simply set record_full_resume_ptid when resuming a loaded
recording.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31971
Approved-By: Guinevere Larsen <blarsen@redhat.com>
2024-07-15 16:31:20 +02:00
Simon Marchi
134a0a106c gdb: make objfile::pspace private
Rename to m_pspace, add getter.  An objfile's pspace never changes, so
no setter is necessary.

Change-Id: If4dfb300cb90dc0fb9776ea704ff92baebb8f626
2024-07-15 13:55:00 +00:00
Kévin Le Gouguec
5e07665d4c gdb: add testcase for invalid record display
More of a DWARF-generation non-regression test; fixed on the GCC side
with 2024-06-03 "Implement wrap-around arithmetics in DWARF
expressions" (f3d6d60d2ae).

Approved-By: Tom Tromey <tom@tromey.com>
2024-07-11 11:48:29 +02:00
Tom Tromey
4401c3c098 Accept unnamed array in gdb.ada/limited-length.exp
Some compiler changes I'm working on cause a regression in
gdb.ada/limited-length.exp -- with the changes, the array type is
nameless and so is not mentioned in the max-value-size error message.

Because the array type is nameless in the source code, this seems like
an improvement to me, and so this patch changes the test to accept
either form.
2024-07-02 11:15:31 -06:00
Aditya Vidyadhar Kamath
d59d4e2f3a Use lwp field in ptid for AIX.
Currently in AIX, the private data is used to maintain the kernel thread ID.

This is a patch to trim the need to have another field in the private data of a thread in AIX.

We want to use the lwp field to represent the kernel thread ID to match or
make things similar to the Linux targets.
2024-07-02 17:27:31 +02:00
Andrew Burgess
632c537277 gdb: add overloads of gdb_tilde_expand
Like the previous commit, add two overloads of gdb_tilde_expand, one
takes std::string and other takes gdb::unique_xmalloc_ptr<char>.  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:26 +01: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
Tom de Vries
cbccccfdf1 [gdb/testsuite] Minor cleanup in gdb.base/bg-execution-repeat.exp
Simplify a gdb_test_multiple in test-case gdb.base/bg-execution-repeat.exp
using "gdb_test -no-prompt-anchor".

Suggested-By: Guinevere Larsen <blarsen@redhat.com>

Tested on x86_64-linux.
2024-06-26 09:05:09 +02:00
Tom de Vries
c44008bda2 [gdb/testsuite] Fix timeout in gdb.base/bg-execution-repeat.exp
I ran into the following test failure with test-case
gdb.base/bg-execution-repeat.exp:
...
(gdb) PASS: gdb.base/bg-execution-repeat.exp: c&: repeat bg command
^M
Breakpoint 2, foo () at bg-execution-repeat.c:23^M
23        return 0; /* set break here */^M
print 1^M
$1 = 1^M
(gdb) PASS: gdb.base/bg-execution-repeat.exp: c&: input still accepted
FAIL: gdb.base/bg-execution-repeat.exp: c&: breakpoint hit 2 (timeout)
...

The failure can be easily reproduced by adding a sleep 5 here:
...
+    sleep 5
     gdb_test "print 1" " = 1" "input still accepted"
...

There's a race in the test-case, between:
- the command handled in the foreground: the "print 1" command, and
- the command handled in the background: the continue command.

The current way of dealing with this is by putting the inferior to sleep for 5
seconds:
...
  foo ();
  sleep (5);
  foo ();
...
with the aim that the "print 1" command will win the race.

This method is both slow and unreliable.

Fix this by making the inferior wait till the "print 1" command is done.

This reduces running time from ~11s to ~1s.

I also verified that the test-case still triggers on the original problem by
applying this gdb/infcmd.c patch:
...
-strip_bg_char (const char *args, int *bg_char_p)
+strip_bg_char (const char *_args, int *bg_char_p)
 {
-  const char *p;
+  char *args = const_cast<char *>(_args);
+  char *p;

   if (args == nullptr || *args == '\0')
     {
@@ -210,6 +211,7 @@ strip_bg_char (const char *args, int *bg_char_p)
       p--;
       while (p > args && isspace (p[-1]))
 	p--;
+      *p = '\0';
...

Tested on x86_64-linux, with make-check-all.sh.

PR testsuite/31794
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31794

Reviewed-By: Guinevere Larsen <blarsen@redhat.com>
2024-06-26 08:49:40 +02:00
Flavio Cruz
64e3e92fe0 Hurd port: update interface to match upstream and fix warnings.
We have recently updated the interface for raising exceptions to use
long [1] and updated mach_port_t to be "unsigned int". This patches fixes
those problems and will help us port GDB to Hurd x86_64.

Tested on Hurd i686 and x86_64.

[1] https://git.savannah.gnu.org/cgit/hurd/gnumach.git/tree/include/mach/exc.defs

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2024-06-25 13:05:37 -04:00
Andrew Burgess
98dd5ba2af gdb/doc: the all-doc build target should build .... all docs
I noticed that the 'all-doc' build target doesn't build all the doc
formats, 'man' and 'html' are missing.

This commit updates 'all-doc' so that all formats are built.

This doesn't change the default 'all' target, which is the default
target used when building GDB itself, the 'all' target continues to
just build the 'info' docs.

There should be no difference in the actual generated output after
this commit, I'm just changing what gets built.

Approved-By: Tom Tromey <tom@tromey.com>
2024-06-25 14:36:13 +01:00
Andrew Burgess
9ac999f500 gdb/doc: fix cannot create directory error when building dvi/pdf
After this commit:

  commit 0700386f14 (gdb-tmp-c)
  Date:   Wed May 8 19:12:57 2024 +0100

      gdb/doc: fix parallel build of pdf and dvi files

When building the dvi or pdf targets you'd get errors like this:

  mkdir: cannot create directory ‘texi2dvi_tmpdir/gdb_dvi’: No such file or directory
  mkdir: cannot create directory ‘texi2dvi_tmpdir/gdb_pdf’: No such file or directory

fixed by ensuring the directory is created before calling texi2dvi.
2024-06-25 14:33:56 +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
Hui Li
6ced1278fc gdb: LoongArch: Add support for hardware breakpoint
LoongArch defines hardware watchpoint functions for fetch operations.
After the software configures the watchpoints for fetch, the processor
hardware will monitor the access addresses of the fetch operations and
trigger a watchpoint exception when the watchpoint setting conditions
are met.

Hardware watchpoints for fetch operations is used to implement hardware
breakpoint function on LoongArch. Refer to the following document for
hardware breakpoint.
https://loongson.github.io/LoongArch-Documentation/LoongArch-Vol1-EN.html#control-and-status-registers-related-to-watchpoints

A simple test is as follows:

lihui@bogon:~$ cat test.c
  #include <stdio.h>
  int a = 0;
  int main()
  {
        printf("start test\n");
        a = 1;
        printf("a = %d\n", a);
        printf("end test\n");
        return 0;
  }
lihui@bogon:~$ gcc -g test.c -o test

without this patch:

lihui@bogon:~$ gdb test
...
(gdb) start
...
Temporary breakpoint 1, main () at test.c:5
5               printf("start test\n");
(gdb) hbreak 8
No hardware breakpoint support in the target.

with this patch:

lihui@bogon:~$ gdb test
...
(gdb) start
...

Temporary breakpoint 1, main () at test.c:5
5               printf("start test\n");
(gdb) hbreak 8
Hardware assisted breakpoint 2 at 0x1200006ec: file test.c, line 8.
(gdb) c
Continuing.
start test
a = 1

Breakpoint 2, main () at test.c:8
8               printf("end test\n");
(gdb) c
Continuing.
end test
[Inferior 1 (process 25378) exited normally]

Signed-off-by: Hui Li <lihui@loongson.cn>
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
2024-06-25 05:50:29 +08:00
Hui Li
c1cdee0e2c gdb: LoongArch: Add support for hardware watchpoint
LoongArch defines hardware watchpoint functions for load/store
operations. After the software configures the watchpoints for
load/store, the processor hardware will monitor the access
addresses of the load/store operations and trigger watchpoint
exception when the watchpoint setting conditions are met.

After this patch, watch/rwatch/awatch command are supported. Refer to the
following document for hardware watchpoint.
https://loongson.github.io/LoongArch-Documentation/LoongArch-Vol1-EN.html#control-and-status-registers-related-to-watchpoints

A simple test is as follows:

lihui@bogon:~$ cat test.c
  #include <stdio.h>
  int a = 0;
  int main()
  {
        printf("start test\n");
        a = 1;
        printf("a = %d\n", a);
        printf("end test\n");
        return 0;
  }

lihui@bogon:~$ gcc -g test.c -o test

without this patch:

lihui@bogon:~$ gdb test
...
(gdb) start
...
Temporary breakpoint 1, main () at test.c:5
5               printf("start test\n");
(gdb) awatch a
Target does not support this type of hardware watchpoint.
...

with this patch:

lihui@bogon:~$ gdb test
...
(gdb) start
...
Temporary breakpoint 1, main () at test.c:5
5               printf("start test\n");
(gdb) awatch a
Hardware access (read/write) watchpoint 2: a
(gdb) c
Continuing.
start test

Hardware access (read/write) watchpoint 2: a

Old value = 0
New value = 1
main () at test.c:7
7               printf("a = %d\n", a);
(gdb) c
Continuing.

Hardware access (read/write) watchpoint 2: a

Value = 1
0x00000001200006e0 in main () at test.c:7
7               printf("a = %d\n", a);
(gdb) c
Continuing.
a = 1
end test
[Inferior 1 (process 22250) exited normally]

Signed-off-by: Hui Li <lihui@loongson.cn>
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
2024-06-25 05:50:08 +08:00
Hannes Domani
5ae5974d60 Fix gdb.lookup_type for function-local types
Looking for a type defined locally in a function doesn't work
any more since the introduction of TYPE_DOMAIN:
```
(gdb) python print (gdb.lookup_type ('main()::Local'))
Python Exception <class 'gdb.error'>: No type named main()::Local.
Error occurred in Python: No type named main()::Local.
```

cp_search_static_and_baseclasses was simply missing a check for
SEARCH_TYPE_DOMAIN, now it works again:
```
(gdb) python print (gdb.lookup_type ('main()::Local'))
Local
```

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31922
Approved-By: Tom Tromey <tom@tromey.com>
2024-06-24 18:45:37 +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
f59be2ed39 Add compunit_symtab::forget_cached_source_info
It seemed cleaner to me for compunit_symtab to have a
forget_cached_source_info method, then for the objfile to know how to
do this.
2024-06-24 09:11:30 -06:00
Tom Tromey
4408976055 Make symtab members private
This rearranges symtab so that the private members appear at the end,
and then adds the "private" keyword.
2024-06-24 09:11:30 -06:00
Tom Tromey
e433e995a9 Rename symtab::fullname
This renames symtab::fullname to m_fullname and adds new accessor
methods.
2024-06-24 09:11:29 -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
Martin Simmons
c702f1ad8a Include needed unordered_map header
Compiling on FreeBSD 13.2 with the default clang version 14.0.5 and top level
configure options --with-python=/usr/local/bin/python3.9 gives this error:

  CXX    ada-exp.o
./../binutils-gdb/gdb/ada-exp.y💯8: error: no template named 'unordered_map' in namespace 'std'
  std::unordered_map<std::string, std::vector<ada_index_var_operation *>>
  ~~~~~^
1 error generated.

This change fixes it.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31918
Approved-By: Tom Tromey <tom@tromey.com>
2024-06-24 06:19:58 -06:00