50420 Commits

Author SHA1 Message Date
5aca7eaa2b [gdb/tdep] Add amd64/i386 epilogue override unwinders
For amd64 the current frame-unwinders are:
...
$ gdb -q -batch -ex "set arch i386:x86-64" -ex "maint info frame-unwinders"
The target architecture is set to "i386:x86-64".
dummy                   DUMMY_FRAME
dwarf2 tailcall         TAILCALL_FRAME
inline                  INLINE_FRAME
python                  NORMAL_FRAME
amd64 epilogue          NORMAL_FRAME
dwarf2                  NORMAL_FRAME
dwarf2 signal           SIGTRAMP_FRAME
amd64 sigtramp          SIGTRAMP_FRAME
amd64 prologue          NORMAL_FRAME
...

For a -g0 -fasynchronous-unwind-tables exec (without .debug_info but with
.eh_frame section), we'd like to start using the dwarf2 unwinder instead of
the "amd64 epilogue" unwinder, by returning true in
compunit_epilogue_unwind_valid for cust == nullptr.

But we'd run into the following problem for a -g0
-fno-asynchronous-unwind-tables (without .debug_info and .eh_frame section)
exec:
- the "amd64 epilogue" unwinder would not run
  (because compunit_epilogue_unwind_valid () == true)
- the dwarf2 unwinder would also not run
  (because there's no .eh_frame info).

Fix this by:
- renaming the "amd64 epilogue" unwinder to "amd64 epilogue override", and
- adding a fallback "amd64 epilogue" after the dwarf unwinders,
while making sure that only one of the two is active.  Likewise for i386.  NFC.

For amd64, this results in this change:
...
 $ gdb -q -batch -ex "set arch i386:x86-64" -ex "maint info frame-unwinders"
 The target architecture is set to "i386:x86-64".
 dummy                   DUMMY_FRAME
 dwarf2 tailcall         TAILCALL_FRAME
 inline                  INLINE_FRAME
 python                  NORMAL_FRAME
-amd64 epilogue          NORMAL_FRAME
+amd64 epilogue override NORMAL_FRAME
 dwarf2                  NORMAL_FRAME
 dwarf2 signal           SIGTRAMP_FRAME
+amd64 epilogue          NORMAL_FRAME
 amd64 sigtramp          SIGTRAMP_FRAME
 amd64 prologue          NORMAL_FRAME
...

And for i386:
...
 $ gdb -q -batch -ex "set arch i386" -ex "maint info frame-unwinders"
 The target architecture is set to "i386".
 dummy                   DUMMY_FRAME
 dwarf2 tailcall         TAILCALL_FRAME
 iline                  INLINE_FRAME
-i386 epilogue           NORMAL_FRAME
+i386 epilogue override  NORMAL_FRAME
 dwarf2                  NORMAL_FRAME
 dwarf2 signal           SIGTRAMP_FRAME
+i386 epilogue           NORMAL_FRAME
 i386 stack tramp        NORMAL_FRAME
 i386 sigtramp           SIGTRAMP_FRAME
 i386 prologue           NORMAL_FRAME
...
2023-02-20 12:20:14 +01:00
2f9f989c2b [gdb/tdep] Fix amd64/i386_stack_frame_destroyed_p
The use of compunit_epilogue_unwind_valid in both amd64_stack_frame_destroyed_p
and i386_stack_frame_destroyed_p is problematic, in the sense that the
functions no longer match their documented behaviour.

Fix this by moving the use of compunit_epilogue_unwind_valid to
amd64_epilogue_frame_sniffer and i386_epilogue_frame_sniffer.  No functional
changes.
2023-02-20 12:20:14 +01:00
cb911672fb [gdb/symtab] Factor out compunit_epilogue_unwind_valid
Factor out compunit_epilogue_unwind_valid from both
amd64_stack_frame_destroyed_p and i386_stack_frame_destroyed_p.  No functional
changes.

Also add a comment in the new function about the assumption that in absence of
producer information, epilogue unwind info is invalid.

Approved-By: Tom Tromey <tom@tromey.com>
2023-02-20 12:20:14 +01:00
1bcaeecb7f [gdb/testsuite] Add xfail case in gdb.python/py-record-btrace.exp
I came across:
...
gdb) PASS: gdb.python/py-record-btrace.exp: prepare record: stepi 100
python insn = r.instruction_history^M
warning: Non-contiguous trace at instruction 1 (offset = 0x3e10).^M
(gdb) FAIL: gdb.python/py-record-btrace.exp: prepare record: python insn = r.i\
nstruction_history
...

I'm assuming it's the same root cause as for the already present XFAIL.

Fix this by recognizing above warning in the xfail regexp.

Tested on x86_64-linux, although sofar I was not able to trigger the warning
again.

Approved-By: Markus T. Metzger <markus.t.metzger@intel.com>
2023-02-20 11:16:02 +01:00
13d4a4bd5a [gdb/testsuite] Fix gdb.threads/schedlock.exp for gcc 4.8.5
Since commit 9af467b8240 ("[gdb/testsuite] Fix gdb.threads/schedlock.exp on
fast cpu"), the test-case fails for gcc 4.8.5.

The problem is that for gcc 4.8.5, the commit turned a two-line loop:
...
(gdb) next
78          while (*myp > 0)
(gdb) next
81              MAYBE_CALL_SOME_FUNCTION(); (*myp) ++;
(gdb) next
78          while (*myp > 0)
...
into a three-line loop:
...
(gdb) next
83              MAYBE_CALL_SOME_FUNCTION(); (*myp) ++;
(gdb) next
84              cnt++;
(gdb) next
85            }
(gdb) next
83              MAYBE_CALL_SOME_FUNCTION(); (*myp) ++;
(gdb)
...
and the test-case doesn't expect this.

Fix this by reverting back to the original loop shape as much as possible by:
- removing the cnt++ line
- replacing "while (1)" with "while (one)", where one is a volatile variable
  set to 1.

Tested on x86_64-linux, using compilers:
- gcc 4.8.5, 7.5.0, 12.2.1
- clang 4.0.1, 13.0.1
2023-02-20 11:16:02 +01:00
0d1912950e Convert contained_in to method
This converts contained_in to be a method of block.
2023-02-19 12:51:06 -07:00
b32797e8b9 Make block members 'private'
This changes block to make the data members 'private'.
2023-02-19 12:51:06 -07:00
522553837b Remove allocate_block and allocate_global_block
This removes allocate_block and allocate_global_block in favor of
simply calling 'new'.
2023-02-19 12:51:06 -07:00
56c0cd6158 Have global_block inherit from block
This changes global_block to inherit from block, which is what was
always intended.
2023-02-19 12:51:06 -07:00
44bb9f9e7a Use 'new' for block and global_block
This changes block and global_block to add initializers, and then to
use 'new' for allocation.
2023-02-19 12:51:06 -07:00
69fb3874a7 Fix memory leak in mdebugread.c
mdebugread.c allocates blocks on the heap.  However, this is a memory
leak if the corresponding objfile is ever destroyed.

This patch changes this code to use allocate_block instead, fixing a
FIXME from 2003.

I don't know how to test this patch.
2023-02-19 12:51:06 -07:00
548a89df23 Remove ALL_BLOCK_SYMBOLS
This removes ALL_BLOCK_SYMBOLS in favor of foreach.
2023-02-19 12:51:06 -07:00
a1b294260f Remove ALL_BLOCK_SYMBOLS_WITH_NAME
This removes ALL_BLOCK_SYMBOLS_WITH_NAME in favor of foreach.
2023-02-19 12:51:06 -07:00
1c49bb455c Convert explicit iterator uses to foreach
This converts most existing explicit uses of block_iterator to use
foreach with the range iterator instead.
2023-02-19 12:51:06 -07:00
0f50815c89 Introduce a block iterator wrapper
This introduces a C++-style iterator that wraps the existing
block_iterator.  It also adds a range adapter.  These will be used in
a later patch.
2023-02-19 12:51:06 -07:00
81326ac076 Combine both styles of block iterator
This merges the two styles of block iterator, having the
initialization API decide which to use based on an optional parameter.
2023-02-19 12:51:06 -07:00
0688bf443c Store 'name' in block_iterator
This changes the block_iterator to store the 'name' that is used by
block_iter_match_next.  This avoids any problem where the name could
be passed inconsistently, and also makes the subsequent patches easier
to understand.
2023-02-19 12:51:06 -07:00
7bf30a4447 Convert block_static_link to method
This converts block_static_link to be a method.  This was mostly
written by script.
2023-02-19 12:51:06 -07:00
cade9c8a45 Convert set_block_compunit_symtab to method
This converts set_block_compunit_symtab to be a method.  This was
mostly written by script.
2023-02-19 12:51:06 -07:00
d24e14a0c6 Convert block_static_block and block_global_block to methods
This converts block_static_block and block_global_block to be methods.
This was mostly written by script.  It was simpler to convert them at
the same time because they're often used near each other.
2023-02-19 12:51:06 -07:00
99f3dfd0f9 Convert block_containing_function to method
This converts block_containing_function to be a method.  This was
mostly written by script.
2023-02-19 12:51:06 -07:00
3c9d050626 Convert block_linkage_function to method
This converts block_linkage_function to be a method.  This was mostly
written by script.
2023-02-19 12:51:05 -07:00
3c45e9f915 Convert more block functions to methods
This converts block_scope, block_set_scope, block_using, and
block_set_using to be methods.  These are all done at once to make it
easier to also convert block_initialize_namespace at the same time.
This was mostly written by script.
2023-02-19 12:51:05 -07:00
a4dfe74756 Convert block_inlined_p to method
This converts block_inlined_p to be a method.  This was mostly written
by script.
2023-02-19 12:51:05 -07:00
7f5937df01 Convert block_gdbarch to method
This converts block_gdbarch to be a method.  This was mostly written
by script.
2023-02-19 12:51:05 -07:00
46baa3c6cf Convert block_objfile to method
This converts block_objfile to be a method.  This was mostly written
by script.
2023-02-19 12:51:05 -07:00
8f14fd1120 Don't allow NULL as an argument to block_global_block
block_global_block has special behavior when the block is NULL.
Remove this and patch up the callers instead.
2023-02-19 12:51:05 -07:00
7800409613 Don't allow NULL as an argument to block_static_block
block_static_block has special behavior when the block is NULL.
Remove this and patch up the callers instead.
2023-02-19 12:51:05 -07:00
392c1cbd74 Don't allow NULL as an argument to block_using
block_using has special behavior when the block is NULL.
Remove this.  No caller seems to be affected.
2023-02-19 12:51:05 -07:00
683aecac8c Don't allow NULL as an argument to block_scope
block_scope has special behavior when the block is NULL.
Remove this and patch up the callers instead.
2023-02-19 12:51:05 -07:00
f52688890e Avoid extra allocations in block
block_set_scope and block_set_using unconditionally allocate the block
namespace object.  However, this isn't truly needed, so arrange to
only allocate when it is.
2023-02-19 12:51:05 -07:00
4aabc41664 Rearrange block.c to avoid a forward declaration
Moving block_initialize_namespace before its callers lets us avoid a
forward declaration.
2023-02-19 12:51:05 -07:00
47fe57c928 Fix "start" for D, Rust, etc
The new DWARF indexer broke "start" for some languages.

For D, it is broken because, while the code in cooked_index_shard::add
specifically excludes Ada, it fails to exclude D.  This means that the
C "main" will be detected as "main" here -- whereas what is intended
is for the code in find_main_name to use d_main_name to find the name.

The Rust compiler, on the other hand, uses DW_AT_main_subprogram.
However, the code in dwarf2_build_psymtabs_hard fails to create a
fully-qualified name, so the name always ends up as plain "main".

For D and Ada, a very simple approach suffices: remove the check
against "main" from cooked_index_shard::add.  This also has the
benefit of slightly speeding up DWARF indexing.  I assume this
approach will work for Pascal and Modula-2 as well, but I don't have a
way to test those at present.

For Rust, though, this is not sufficient.  And, computing the
fully-qualified name in dwarf2_build_psymtabs_hard will crash, because
cooked_index_entry::full_name uses the canonical name -- and that is
not computed until after canonicalization.

However, we don't want to wait for canonicalization to be done before
computing the main name.  That would remove any benefit from doing
canonicalization is the background.

This patch solves this dilemma by noticing that languages using
DW_AT_main_subprogram are, currently, disjoint from languages
requiring canonicalization.  Because of this, we can add a parameter
to full_name to let us avoid crashes, slowdowns, and races here.

This is kind of tricky and ugly, so I've tried to comment it
sufficiently.

While doing this, I had to change gdb.dwarf2/main-subprogram.exp.  A
different possibility here would be to ignore the canonicalization
needs of C in this situation, because those only affect certain types.
However, I chose this approach because the test case is artificial
anyhow.

A long time ago, in an earlier threading attempt, I changed the global
current_language to be a function (hidden behind a macro) to let us
attempt lazily computing the current language.  Perhaps this approach
could still be made to work.  However, that also seemed rather tricky,
more so than this patch.

Reviewed-By: Andrew Burgess <aburgess@redhat.com>
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30116
2023-02-18 15:41:38 -07:00
e8eca7a6b6 Fix crash in go_symbol_package_name
go_symbol_package_name package name asserts that it is only passed a
Go symbol, but this is not enforced by one caller.  It seems simplest
to just check and return early in this case.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=17876
Reviewed-By: Andrew Burgess <aburgess@redhat.com>
2023-02-17 19:05:04 -05:00
be643e074f Avoid manual memory management in go-lang.c
I noticed a couple of spots in go-lang.c that could be improved by
using unique_ptr.

Reviewed-By: Andrew Burgess <aburgess@redhat.com>
2023-02-17 19:05:04 -05:00
733da2ced8 gdb: fix regression in gdb.xml/maint_print_struct.exp
A regression in gdb.xml/maint_print_struct.exp was introduced with
commit:

  commit 81b86eced24f905545b58aa6c27478104c364976
  Date:   Fri Jan 6 09:30:40 2023 -0700

      Do not record a rejected target description

The test relied on an invalid target description being stored within
the tdesc_info of the current inferior, the above commit stopped this
behaviour.

Update the test to check that the invalid architecture is NOT stored,
and then check printing the target description directly from the
file.

Approved-By: Tom Tromey <tromey@adacore.com>
2023-02-17 22:29:09 +00:00
7a2a5ff865 Fix multi-threaded debugging under AIX
Multi-threaded debugging using the libpthdebug debug interface
is currently broken due to multiple issues.

When debugging a single inferior, we were getting assertion
failures in get_aix_thread_info as no tp->priv structure was
allocated for the main thread.

We fixed this by switching the main
thread from a (pid, 0, 0) ptid_t to a (pid, 0, tid) ptid_t and
allocaing the tp->priv structure in sync_threadlists.

As a result, the switch_to_thread call in pdc_read_data could
now fail since the main thread no longer uses (pid, 0, 0).

So we replaced the call by only switching inferior_ptid, the current
inferior, and the current address space (like proc-service.c).
Add similar switching to pdc_write_data where it was missing
completely.

When debugging multiple inferiors, an additional set of
problems prevented correct multi-threaded debugging:

First of all, aix-thread.c used to have a number of global
variables holding per-inferior information.

We switched hese
to a per-inferior data structure instead.

Also, sync_threadlists was getting confused as we were
comparing the list of threads returned by libpthdebug
for *one* process with GDB's list of threads for *all*
processes. Now we only use he GDB threads of the current
inferior instead.

We also skip calling pd_activate
from pd_enable if that in_initial_library_scan flag is
true for the current inferior.

Finally, the presence of the thread library in any but
the first inferior was not correctly detected due to a
bug in solib-aix.c, where the BFD file name for shared
library members was changed when the library was loaded
for the first time, which caused the library to no longer
be recognized by name when loaded a second time.
2023-02-17 20:12:06 +01:00
fe0431855a Remove two unnecessary returns in ada-lang.c
I found a couple of spots in ada-lang.c where a return follows a call
to error.  These are unnecessary because error never returns.
2023-02-17 10:24:16 -07:00
ab3fdfe6e4 [gdb/testsuite] Simplify gdb.arch/amd64-disp-step-avx.exp
On SLE-11, with glibc 2.11.3, I run into:
...
(gdb) PASS: gdb.arch/amd64-disp-step-avx.exp: vex3: \
  var128 has expected value after
continue^M
Continuing.^M
^M
Program received signal SIGSEGV, Segmentation fault.^M
0x0000000000400283 in _exit (status=0) at \
  ../sysdeps/unix/sysv/linux/_exit.c:33^M
33      ../sysdeps/unix/sysv/linux/_exit.c: No such file or directory.^M
(gdb) FAIL: gdb.arch/amd64-disp-step-avx.exp: \
  continue until exit at amd64-disp-step-avx
...

This is not related to gdb, we get the same result by just running the exec.

The problem is that the test-case:
- calls glibc's _exit, and
- uses -nostartfiles -static, putting the burden for any necessary
  initialization for calling glibc's _exit on the test-case itself.

So, when we get to the second insn in _exit:
...
000000000040acb0 <_exit>:
  40acb0:       48 63 d7                movslq %edi,%rdx
  40acb3:       64 4c 8b 14 25 00 00    mov    %fs:0x0,%r10
...
no glibc-related initialization is done, and we run into the segfault.

Adding this (borrowed from __libc_start_main) in _start in the .S file is
sufficient to fix it:
...
         .rept 200
         nop
+        call __pthread_initialize_minimal
         .endr
...
But that already doesn't compile with say glibc 2.31, and regardless I think
this sort of fix is too fragile.

We could of course fix this by simply not running to exit.  But ideally we'd
have an exec that doesn't segfault when you just run it.

Alternatively, we could hand-code an _exit syscall and bypass glibc
all together.  But I'd rather fix this in a way that simplifies the test-case.

Taking a step back, the -nostartfiles -static was added to address that the
xmm registers were not zero at main (which AFAICT is a valid thing to happen).

[ The change itself silently broke the test-case, needing further fixing by
commit 40310f30a51 ("gdb: make gdb.arch/amd64-disp-step-avx.exp actually test
displaced stepping"). ]

Instead, simplify things by reverting to the original situation:
- no -nostartfiles -static compilation flags,
- no _start in the .S file,
- use exit instead of _exit in the .S file,
and fix the original problem by setting the xmm registers to zero rather than
checking that they're zero.

Now that we're no longer forcing -static, add nopie to the flags to prevent
compilation failure with target board unix/-fPIE/-pie.

Tested on x86_64-linux.

PR testsuite/30132
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30132
2023-02-17 15:33:18 +01:00
12d67b37cd Rename parameter of create_ada_exception_catchpoint
create_ada_exception_catchpoint has a parameter named "disabled", but
both its callers and callees use it to mean "enabled".  This is
confusing, so this patch renames the parameter.
2023-02-16 10:29:11 -07:00
16b84b6599 Update the 'g' packet documentation
The 'g' packet documentation references a macro that no longer exists,
and it also claims that the 'x' response for an unavailable register
is limited to trace frames.  This patch updates the documentation to
reflect what I think is currently correct.

Co-Authored-By: Pedro Alves <pedro@palves.net>
Approved-By: Eli Zaretskii <eliz@gnu.org>
Change-Id: I863baa3b9293059cfd4aa3d534602cbcb693ba87
2023-02-16 17:08:48 +00:00
6f63b61dd1 Constify ada_main_name
Unlike the other *_main_name functions, ada_main_name returns a
non-const "char *".  This is strange, though, because the caller
should not in fact modify or free this pointer.  This patch changes
this function to constify its return type.
2023-02-16 08:10:59 -07:00
1e159729d9 Remove unused declaration from ada-lang.h
I stumbled across this declaration in ada-lang.h.  I don't know what
function did, but it no longer exists, so remove the declaration.
Tested by rebuilding.
2023-02-16 08:08:31 -07:00
42af03dafe gdb/doc: document MI -remove-inferior command
Back in 2010 the -remove-inferior command was added in commit
a79b8f6ea8c2, unfortunately this command was never added to the
documentation.

This commit addresses that oversight.

Approved-By: Eli Zaretskii <eliz@gnu.org>
2023-02-16 08:42:48 +00:00
b59ff01d87 Return bool from more value methods
There are several more value methods that currently return 'int' but
that should return 'bool'.  This patch updates these.

Reviewed-By: Bruno Larsen <blarsen@redhat.com>
2023-02-15 15:07:08 -07:00
19124154b9 Have value::bits_synthetic_pointer return bool
This changes value::bits_synthetic_pointer to return bool and fixes up
some fallout from this.

Reviewed-By: Bruno Larsen <blarsen@redhat.com>
2023-02-15 15:07:07 -07:00
42c13555ff Change value::m_stack to bool
This changes value::m_stack to be a bool and updates the various uses.

Reviewed-By: Bruno Larsen <blarsen@redhat.com>
2023-02-15 15:07:07 -07:00
a7c27481a0 Change value::m_initialized to bool
This changes value::m_initialized to be a bool and updates the various
uses.

Reviewed-By: Bruno Larsen <blarsen@redhat.com>
2023-02-15 15:07:07 -07:00
a5b210cb69 Change value::m_lazy to bool
This changes value::m_lazy to be a bool and updates the various uses.

Reviewed-By: Bruno Larsen <blarsen@redhat.com>
2023-02-15 15:07:07 -07:00
b2227e67b4 Change value::m_modifiable to bool
This changes value::m_modifiable to be a bool and updates the various
uses.

Reviewed-By: Bruno Larsen <blarsen@redhat.com>
2023-02-15 15:07:07 -07:00