Commit graph

50665 commits

Author SHA1 Message Date
Tom Tromey
145674b325 Remove mi_version function
The mi_version function is unused, and I think it's better overall if
it is never used.  This patch removes it.  Tested by rebuilding.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2023-03-20 13:13:12 -06:00
Tom Tromey
505ca0bfa5 Update python-helper.exp for type allocation changes
The type allocation changes introduced a failure in python-helper.exp
that I did not notice.  The bug is that, with these patches,
arch-allocated integer types have a TYPE_SPECIFIC_INT object attached.
This patch updates the test to allow this.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30253
2023-03-20 11:40:36 -06:00
Tom de Vries
80d6c79866 [gdb/testsuite] Handle remotedir in remote_upload
Dejagnu's remotedir implementation has support in remote_exec and
remote_download, but not remote_upload.

Consider the following scenario:
- downloading an executable to target,
- running it,
- uploading a file produced by the executable
while assuming remote target user remote-target with homedir
/home/remote-target and remotedir set to /home/remote-target/tmp.

Concretely, it looks like this:
...
 # binfile == "$outputs/gdb.abc/a.out"
 set target_binfile [remote_download target $binfile]
 # target_binfile == "/home/remote-target/tmp/a.out"
 remote_exec target $target_binfile
 # Running $target_binfile produced /home/remote-target/tmp/result.txt.
 set result [remote_upload target /home/remote-target/tmp/result.txt \
                 $outputs/gdb.abc/result.txt]
 # result == $outputs/gdb.abc/result.txt.
...

Add a remote_upload implementation that also handles remotedir in lib/gdb.exp,
overriding dejagnu's remote_upload, such that we can simplify the
remote_upload call to:
...
 set result [remote_upload target result.txt $outputs/gdb.abc/result.txt]
...

Tested on x86_64-linux.

PR testsuite/30250
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30250
2023-03-20 17:06:49 +01:00
Andrew Burgess
454f8b67a8 gdb: fix crash during command completion
In some cases GDB will fail when attempting to complete a command that
involves a rust symbol, the failure can manifest as a crash.

The problem is caused by the completion_match_for_lcd object being
left containing invalid data during calls to cp_symbol_name_matches_1.

The first question to address is why we are calling a C++ support
function when handling a rust symbol.  That's due to GDB's auto
language detection for msymbols, in some cases GDB can't tell if a
symbol is a rust symbol, or a C++ symbol.

The test application contains symbols for functions which are
statically linked in from various rust support libraries.  There's no
DWARF for these symbols, so all GDB has is the msymbols built from the
ELF symbol table.

Here's the problematic symbol that leads to our crash:

    mangled: _ZN4core3str21_$LT$impl$u20$str$GT$5parse17h5111d2d6a50d22bdE
  demangled: core::str::<impl str>::parse

As an msymbol this is initially created with language auto, then GDB
eventually calls symbol_find_demangled_name, which loops over all
languages calling language_defn::sniff_from_mangled_name, the first
language that can demangle the symbol gets assigned as the language
for that symbol.

Unfortunately, there's overlap in the mangled symbol names,
some (legacy) rust symbols can be demangled as both rust and C++, see
cplus_demangle in libiberty/cplus-dem.c where this is mentioned.

And so, because we check the C++ language before we check for rust,
then the msymbol is (incorrectly) given the C++ language.

Now it's true that is some cases we might be able to figure out that a
demangled symbol is not actually a valid C++ symbol, for example, in
our case, the construct '::<impl str>::' is not, I believe, valid in a
C++ symbol, we could look for ':<' and '>:' and refuse to accept this
as a C++ symbol.

However, I'm not sure it is always possible to tell that a demangled
symbol is rust or C++, so, I think, we have to accept that some times
we will get this language detection wrong.

If we accept that we can't fix the symbol language detection 100% of
the time, then we should make sure that GDB doesn't crash when it gets
the language wrong, that is what this commit addresses.

In our test case the user tries to complete a symbol name like this:

  (gdb) complete break pars

This results in GDB trying to find all symbols that match 'pars',
eventually we consider our problematic symbol, and we end up with a
call stack that looks like this:

  #0  0x0000000000f3c6bd in strncmp_iw_with_mode
  #1  0x0000000000706d8d in cp_symbol_name_matches_1
  #2  0x0000000000706fa4 in cp_symbol_name_matches
  #3  0x0000000000df3c45 in compare_symbol_name
  #4  0x0000000000df3c91 in completion_list_add_name
  #5  0x0000000000df3f1d in completion_list_add_msymbol
  #6  0x0000000000df4c94 in default_collect_symbol_completion_matches_break_on
  #7  0x0000000000658c08 in language_defn::collect_symbol_completion_matches
  #8  0x0000000000df54c9 in collect_symbol_completion_matches
  #9  0x00000000009d98fb in linespec_complete_function
  #10 0x00000000009d99f0 in complete_linespec_component
  #11 0x00000000009da200 in linespec_complete
  #12 0x00000000006e4132 in complete_address_and_linespec_locations
  #13 0x00000000006e4ac3 in location_completer

In cp_symbol_name_matches_1 we enter a loop, this loop repeatedly
tries to match the demangled problematic symbol name against the user
supplied text ('pars').  Each time around the loop another component
of the symbol name is stripped off, thus, we check 'pars' against
these options:

  core::str::<impl str>::parse
  str::<impl str>::parse
  <impl str>::parse
  parse

As soon as we get a match the cp_symbol_name_matches_1 exits its loop
and returns.  In our case, when we're looking for 'pars', the match
occurs on the last iteration of the loop, when we are comparing to
'parse'.

Now the problem here is that cp_symbol_name_matches_1 uses the
strncmp_iw_with_mode, and inside strncmp_iw_with_mode we allow for
skipping over template parameters.  This allows GDB to match the
symbol name 'foo<int>(int,int)' if the user supplies 'foo(int,'.
Inside strncmp_iw_with_mode GDB will record any template arguments
that it has skipped over inside the completion_match_for_lcd object
that is passed in as an argument.

And so, when GDB tries to match against '<impl str>::parse', the first
thing it sees is '<impl str>', GDB assumes this is a template argument
and records this as a skipped region within the
completion_match_for_lcd object.  After '<impl str>' GDB sees a ':'
character, which doesn't match with the 'pars' the user supplied, so
strncmp_iw_with_mode returns a value indicating a non-match.  GDB then
removes the '<impl str>' component from the symbol name and tries
again, this time comparing to 'parse', which does match.

Having found a match, then in cp_symbol_name_matches_1 we record the
match string, and the full symbol name within the
completion_match_result object, and return.

The problem here is that the skipped region, the '<impl str>' that we
recorded in the penultimate loop iteration was never discarded, its
still there in our returned result.

If we look at what the pointers held in the completion_match_result
that cp_symbol_name_matches_1 returns, this is what we see:

  core::str::<impl str>::parse
  |          \________/  |
  |               |      '--- completion match string
  |               '---skip range
  '--- full symbol name

When GDB calls completion_match_for_lcd::finish, GDB tries to create a
string using the completion match string (parse), but excluding the
skip range, as the stored skip range is before the start of the
completion match string, then GDB tries to do some weird string
creation, which will cause GDB to crash.

The reason we don't often see this problem in C++ is that for C++
symbols there is always some non-template text before the template
argument.  This non-template text means GDB is likely to either match
the symbol, or reject the symbol without storing a skip range.

However, notice, I did say, we don't often see this problem.  Once I
understood the issue, I was able to reproduce the crash using a pure
C++ example:

  template<typename S>
  struct foo
  {
    template<typename T>
    foo (int p1, T a)
    {
      s = 0;
    }

    S s;
  };

  int
  main ()
  {
    foo<int> obj (2.3, 0);
    return 0;
  }

Then in GDB:

  (gdb) complete break foo(int

The problem here is that the C++ symbol for the constructor looks like
this:

  foo<int>::foo<double>(int, double)

When GDB enters cp_symbol_name_matches_1 the symbols it examines are:

  foo<int>::foo<double>(int, double)
  foo<double>(int, double)

The first iteration of the loop will match the 'foo', then add the
'<int>' template argument will be added as a skip range.  When GDB
find the ':' after the '<int>' the first iteration of the loop fails
to match, GDB removes the 'foo<int>::' component, and starts the
second iteration of the loop.

Again, GDB matches the 'foo', and now adds '<double>' as a skip
region.  After that the '(int' successfully matches, and so the second
iteration of the loop succeeds, but, once again we left the '<int>' in
place as a skip region, even though this occurs before the start of
our match string, and this will cause GDB to crash.

This problem was reported to the mailing list, and a solution
discussed in this thread:

  https://sourceware.org/pipermail/gdb-patches/2023-January/195166.html

The solution proposed here is similar to one proposed by the original
bug reported, but implemented in a different location within GDB.
Instead of placing the fix in strncmp_iw_with_mode, I place the fix in
cp_symbol_name_matches_1.  I believe this is a better location as it
is this function that implements the loop, and it is this loop, which
repeatedly calls strncmp_iw_with_mode, that should be resetting the
result object state (I believe).

What I have done is add an assert to strncmp_iw_with_mode that the
incoming result object is empty.

I've also added some other asserts in related code, in
completion_match_for_lcd::mark_ignored_range, I make some basic
assertions about the incoming range pointers, and in
completion_match_for_lcd::finish I also make some assertions about how
the skip ranges relate to the match pointer.

There's two new tests.  The original rust example that was used in the
initial bug report, and a C++ test.  The rust example depends on which
symbols are pulled in from the rust libraries, so it is possible that,
at some future date, the problematic symbol will disappear from this
test program.  The C++ test should be more reliable, as this only
depends on symbols from within the C++ source code.

Since I originally posted this patch to the mailing list, the
following patch has been merged:

  commit 6e7eef7216
  Date:   Sun Mar 19 09:13:10 2023 -0600

      Use rust_demangle to fix a crash

This solves the problem of a rust symbol ending up in the C++ specific
code by changing the order languages are sorted.  However, this new
commit doesn't address the issue in the C++ code which was fixed with
this commit.

Given that the C++ issue is real, and has a reproducer, I'm still
going to merge this fix.  I've left the discussion of rust in this
commit message as I originally wrote it, but it should be read within
the context of GDB prior to commit 6e7eef7216.

Co-Authored-By:  Zheng Zhan <zzlossdev@163.com>
2023-03-20 16:05:20 +00:00
Tom Tromey
6e7eef7216 Use rust_demangle to fix a crash
PR rust/30211 points out a crash caused by a particular completion.
This turns out to happen because a Rust minsym winds up in a
C++-specific path in strncmp_iw_with_mode, which ultimately causes the
completer to pass invalid arguments to string::append.

This patch fixes the bug by reordering the language constants so that
Rust comes before C++, and then using rust_demangle.  This ensures
that minsyms are correctly marked as "Rust", avoiding this code and
thus the crash.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=20367
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30211
Reviewed-By: Andrew Burgess <aburgess@redhat.com>
2023-03-20 07:47:15 -06:00
Tom Tromey
0fea10f327 Make ui_out::do_progress_end 'private'
I noticed that ui_out::do_progress_end is public, just to support one
use in debuginfod-support.c.  This patch makes it private, updates
progress_info to call it from its destructor, and finally changes
debuginfod-support.c to follow.
2023-03-20 07:21:03 -06:00
Andrew Burgess
442716d400 gdb: don't use the global thread-id in the saved breakpoints file
I noticed that breakpoint::print_recreate_thread was printing the
global thread-id.  This function is used to implement the 'save
breakpoints' command, and should be writing out suitable CLI commands
for recreating the current breakpoints.  The CLI does not use global
thread-ids, but instead uses the inferior specific thread-ids,
e.g. "2.1".

After some discussion on the mailing list it was suggested that the
most consistent solution would be for the saved breakpoints file to
always contain the inferior-qualified thread-id, so the file would
include "thread 1.1" instead of just "thread 1", even when there is
only a single inferior.

So, this commit adds print_full_thread_id, which is just like the
existing print_thread_id, only it always prints the inferior-qualified
thread-id.

I then update the existing print_thread_id to make use of this new
function, and finally, I update  breakpoint::print_recreate_thread to
also use this new function.

There's a multi-inferior test that confirms the saved breakpoints file
correctly includes the fully-qualified thread-id, and I've also
updated the single inferior test gdb.base/save-bp.exp to have it
validate that the saved breakpoints file includes the
inferior-qualified thread-id, even for this single inferior case.
2023-03-20 10:37:15 +00:00
Tom Tromey
f6eefc3765 Don't declare psymbol_functions::fill_psymbol_map
psymbol_functions::fill_psymbol_map was removed, but I forgot to
remove the declaration.  This patch removes it.  Tested by rebuilding.
2023-03-19 16:50:27 -06:00
Tom Tromey
2d1bc55233 Remove objfile_type
This removes objfile_type, in favor of always using the per-arch
builtins.

Reviewed-By: Simon Marchi <simon.marchi@efficios.com>
2023-03-18 11:12:38 -06:00
Tom Tromey
a9a775da56 Add some types to struct builtin_type
This adds some types to struct builtin_type, ensuring it contains all
the types currently used by objfile_type.

Reviewed-By: Simon Marchi <simon.marchi@efficios.com>
2023-03-18 11:12:38 -06:00
Tom Tromey
a8ed3dde83 Rename objfile_type to builtin_type
This renames objfile_type to be an overload of builtin_type, in
preparation for their unification.

Reviewed-By: Simon Marchi <simon.marchi@efficios.com>
2023-03-18 11:12:38 -06:00
Tom Tromey
426e5b66a7 Use builtin type when appropriate
There are a few spots that check whether a type is objfile-owned, and
then choose either the objfile- or arch-specific builtin type.  I
don't think there is a need to do this any more (if there ever was),
because it is ok for an objfile-allocated type to refer to an
arch-allocated type.

Reviewed-By: Simon Marchi <simon.marchi@efficios.com>
2023-03-18 11:12:38 -06:00
Tom Tromey
526648585c Use type allocator for set types
This changes the set type creation function to accept a type
allocator, and updates all the callers.  Note that symbol readers
should generally allocate on the relevant objfile, regardless of the
underlying type of the set, which is what this patch implements.

Reviewed-By: Simon Marchi <simon.marchi@efficios.com>
2023-03-18 11:12:38 -06:00
Tom Tromey
9e76b17aa5 Use type allocator for array types
This changes the array type creation functions to accept a type
allocator, and updates all the callers.  Note that symbol readers
should generally allocate on the relevant objfile, regardless of the
placement of the index type of the array, which is what this patch
implements.

Reviewed-By: Simon Marchi <simon.marchi@efficios.com>
2023-03-18 11:12:38 -06:00
Tom Tromey
e727c536c6 Use type allocator for range types
This changes the range type creation functions to accept a type
allocator, and updates all the callers.  Note that symbol readers
should generally allocate on the relevant objfile, regardless of the
underlying type of the range, which is what this patch implements.

Reviewed-By: Simon Marchi <simon.marchi@efficios.com>
2023-03-18 11:12:38 -06:00
Tom Tromey
9c794d2d46 Unify arch_pointer_type and init_pointer_type
This unifies arch_pointer_type and init_pointer_type by using a type
allocator.

Reviewed-By: Simon Marchi <simon.marchi@efficios.com>
2023-03-18 11:12:38 -06:00
Tom Tromey
0776344a33 Unify arch_decfloat_type and init_decfloat_type
This unifies arch_decfloat_type and init_decfloat_type by using a type
allocator.

Reviewed-By: Simon Marchi <simon.marchi@efficios.com>
2023-03-18 11:12:38 -06:00
Tom Tromey
77c5f49648 Unify arch_float_type and init_float_type
This unifies arch_float_type and init_float_type by using a type
allocator.

Reviewed-By: Simon Marchi <simon.marchi@efficios.com>
2023-03-18 11:12:38 -06:00
Tom Tromey
46c04ea32f Unify arch_boolean_type and init_boolean_type
This unifies arch_boolean_type and init_boolean_type by using a type
allocator.

Reviewed-By: Simon Marchi <simon.marchi@efficios.com>
2023-03-18 11:12:38 -06:00
Tom Tromey
f50b437c3d Unify arch_character_type and init_character_type
This unifies arch_character_type and init_character_type by using a
type allocator.

Reviewed-By: Simon Marchi <simon.marchi@efficios.com>
2023-03-18 11:12:37 -06:00
Tom Tromey
2d39ccd3d1 Unify arch_integer_type and init_integer_type
This unifies arch_integer_type and init_integer_type by using a type
allocator.

Reviewed-By: Simon Marchi <simon.marchi@efficios.com>
2023-03-18 11:12:37 -06:00
Tom Tromey
333859402c Remove init_type
This removes init_type, replacing all uses with the new type
allocator.

Reviewed-By: Simon Marchi <simon.marchi@efficios.com>
2023-03-18 11:12:37 -06:00
Tom Tromey
cc495054ad Remove arch_type
This removes arch_type, replacing all uses with the new type
allocator.

Reviewed-By: Simon Marchi <simon.marchi@efficios.com>
2023-03-18 11:12:37 -06:00
Tom Tromey
95751990e4 Reuse existing builtin types
This changes a few spots to reuse the existing builting "void" type,
rather than construct a new one.

Reviewed-By: Simon Marchi <simon.marchi@efficios.com>
2023-03-18 11:12:37 -06:00
Tom Tromey
8a17bdd9cc Remove alloc_type
This removes alloc_type, replacing all uses with the new type
allocator.

Reviewed-By: Simon Marchi <simon.marchi@efficios.com>
2023-03-18 11:12:37 -06:00
Tom Tromey
9fa83a7ade Remove alloc_type_copy
This removes alloc_type_copy, replacing all uses with the new type
allocator.

Reviewed-By: Simon Marchi <simon.marchi@efficios.com>
2023-03-18 11:12:37 -06:00
Tom Tromey
c9eb9f1854 Remove alloc_type_arch
This removes alloc_type_arch, replacing all uses with the new type
allocator.

Reviewed-By: Simon Marchi <simon.marchi@efficios.com>
2023-03-18 11:12:37 -06:00
Tom Tromey
6a4d297c62 Introduce type_allocator
This introduces a new type_allocator class.  This class will be used
to abstract out the placement of new types, so that type-creation code
can be simplified and shared.

Reviewed-By: Simon Marchi <simon.marchi@efficios.com>
2023-03-18 11:12:37 -06:00
Tom de Vries
d1de9f5c6c [gdb/testsuite] Handle unbuffer_output.c for remote host
Handle $srcdir/lib/unbuffer_output.c using lappend_include_file.

Tested on x86_64-linux.
2023-03-18 17:50:56 +01:00
Tom de Vries
424500e9a2 [gdb/testsuite] Handle my-syscalls.h for remote host
Handle $srcdir/lib/my-syscalls.h using lappend_include_dir.

Tested on x86_64-linux.
2023-03-18 10:30:16 +01:00
Tom de Vries
f2259ae756 [gdb/testsuite] Handle attributes.h for remote host
Handle $srcdir/lib/attributes.h using lappend_include_dir.

Tested on x86_64-linux.
2023-03-18 10:16:30 +01:00
Tom Tromey
48e0f38c30 Fix line table regression
Simon pointed out a line table regression, and after a couple of false
starts, I was able to reproduce it by hand using his instructions.

The bug is that most of the code in do_mixed_source_and_assembly uses
unrelocated addresses, but one spot does:

  pc = low;

... after the text offset has been removed.

This patch fixes the problem by introducing a new type to represent
unrelocated addresses in the line table.  This prevents this sort of
bug to some degree (it's still possible to manipulate a CORE_ADDR in a
bad way, this is unavoidable).

However, this did let the compiler flag a few spots in that function,
and now it's not possible to compare an unrelocated address from a
line table with an ordinary CORE_ADDR.

Regression tested on x86-64 Fedora 36, though note this setup never
reproduced the bug in the first place.  I also tested it by hand on
the disasm-optim test program.
2023-03-17 16:17:43 -06:00
Frederic Cambus
152d9c48a2 Update the NetBSD system call table to add eventfd(2) and timerfd(2).
Generated from sys/sys/syscall.h revision 1.321.
2023-03-17 13:53:33 -07:00
Simon Marchi
0b63c811ef gdb: introduce bp_loc_tracepoint
Since commit cb1e4e32c2 ("catch catch/throw/rethrow", breakpoint ->
catchpoint), this simple tracing scenario does not work:

    $ gdb/gdb -nx -q --data-directory=gdb/data-directory ./test
    Reading symbols from ./test...
    (gdb) tar rem :1234
    Remote debugging using :1234
    Reading symbols from /lib64/ld-linux-x86-64.so.2...
    (No debugging symbols found in /lib64/ld-linux-x86-64.so.2)
    0x00007ffff7fe5730 in ?? () from /lib64/ld-linux-x86-64.so.2
    (gdb) trace do_something
    Tracepoint 1 at 0x555555555144: file test.c, line 5.
    (gdb) tstart
    (gdb) continue
    Continuing.
    Target returns error code '01'.

The root cause is that the bp_location::nserted flag does not transfer
anymore from an old bp_location to the new matching one.  When a shared
library gets loaded, GDB computes new breakpoint locations for each
breakpoint in update_breakpoint_locations.  The new locations are in the
breakpoint::loc chain, while the old locations are still in the
bp_locations global vector.  Later, update_global_location_list is
called.  It tries to map old locations to new locations, and if
necessary transfer some properties, like the inserted flag.

Since commit cb1e4e32c2, the inserted flag isn't transferred for
locations of tracepoints.  This is because bl_address_is_meaningful used
to be implemented like this:

    static int
    breakpoint_address_is_meaningful (struct breakpoint *bpt)
    {
      enum bptype type = bpt->type;

      return (type != bp_watchpoint && type != bp_catchpoint);
    }

and was changed to this:

    static bool
    bl_address_is_meaningful (bp_location *loc)
    {
      return loc->loc_type != bp_loc_other;
    }

Because locations for tracepoints have the bp_loc_other type,
bl_address_is_meaningful started to return false for them, where it
returned true before.  This made update_global_location_list skip the
part where it calls swap_insertion.

I think this can be solved by introduced a new bp_loc_tracepoint
bp_loc_type.

I don't know if it's accurate, but my understanding is that bp_loc_type
describes roughly "how do we ask the target to insert that location".
bp_loc_software_breakpoint are inserted using
target_ops::insert_breakpoint_location.  bp_loc_hardware_breakpoint are
inserted using target_ops::insert_hw_breakpoint.
bp_loc_software_watchpoint and bp_loc_hardware_watchpoint are inserted
using target_ops::insert_watchpoint.  For all these, the address is
meaningful, as we ask the target to insert the point at a specific
address.  bp_loc_other is a catch-all for "the rest", in practice for
catchpoints that don't have a specific address (hence why
bl_address_is_meaningful returns false for them).  For instance,
inserting a signal catchpoint is done by asking the target to report
that specific signal.  GDB doesn't associate an address to that.

But tracepoints do have a meaningful address to thems, so they can't be
bp_loc_other, with that logic.  They also can't be
bp_loc_software_breakpoint, because we don't want GDB to insert
breakpoints for them (even though they might be implemented using
software breakpoints by the remote side).  So, the new bp_loc_tracepoint
type describes that the way to insert these locations is with
target_ops::download_tracepoint.  It makes bl_address_is_meaningful
return true for them.  And they'll be ignored by insert_bp_location and
GDB won't try to insert a memory breakpoint for them.

With this, I see a few instances of 'Target returns error code: 01'
disappearing from gdb.log, and the results of gdb.trace/*.exp improve a
little bit:

    -# of expected passes       3765
    +# of expected passes       3781
    -# of unexpected failures   518
    +# of unexpected failures   498

Things remain quite broken in that area though.

Change-Id: Ic40935c450410f4bfaba397c9ebc7faf97320dd3
2023-03-17 16:34:25 -04:00
Carl Love
2a8339b71f PowerPC: fix for gdb.reverse/finish-precsave.exp and gdb.reverse/finish-reverse.exp
PPC64 multiple entry points, a normal entry point and an alternate entry
point.  The alternate entry point is to setup the Table of Contents (TOC)
register before continuing at the normal entry point.  When the TOC is
already valid, the normal entry point is used, this is typically the case.
The alternate entry point is typically referred to as the global entry
point (GEP) in IBM.  The normal entry point is typically referred to as
the local entry point (LEP).

When GDB is executing the finish command in reverse, the function
finish_backward currently sets the break point at the alternate entry point.
This issue is if the function, when executing in the forward direction,
entered the function via the normal entry point, execution in the reverse
direction will never sees the break point at the alternate entry point.  In
this case, the reverse execution continues until the next break point is
encountered thus stopping at the wrong place.

This patch adds a new address to struct execution_control_state to hold the
address of the alternate entry point (GEP).  The finish_backwards function
is updated, if the stopping point is between the normal entry point (LEP)
and the end of the function, a breakpoint is set at the normal entry point.
If the stopping point is between the entry points, a breakpoint is set at
the alternate entry point.  This ensures that GDB will always stop at the
normal entry point.  If the function did enter via the alternate entry
point, GDB will detect that and continue to execute backwards in the
function until the alternate entry point is reached.

The patch fixes the behavior of the reverse-finish command on PowerPC to
match the behavior of the command on other platforms, specifically X86.
The patch does not change the behavior of the command on X86.

A new test is added to verify the reverse-finish command on PowerPC
correctly stops at the instruction where the function call is made.

The patch fixes 11 regression errors in test gdb.reverse/finish-precsave.exp
and 11 regression errors in test gdb.reverse/finish-reverse.exp.

The patch has been tested on Power 10 and X86 processor with no new
regression failures.
2023-03-17 16:02:57 -04:00
Carl Love
334d405c2a Move step_until procedure
Procedure step_until from test gdb.reverse/step-indirect-call-thunk.exp
is moved to lib/gdb.exp and renamed repeat_cmd_until.  The existing procedure
gdb_step_until in lib/gdb.exp is simpler variant of the new repeat_cmd_until
procedure.  The existing procedure gdb_step_until is changed to just call
the new repeat_cmd_until procedure with the command set to "step" and an
optional CURRENT string.  The default CURRENT string is set to "\}" to work
with the existing uses of procedure gdb_step_until.
2023-03-17 16:02:48 -04:00
Tom de Vries
1b046c8eb9 [gdb/testsuite] Fix regexp in gdb.arch/ftrace-insn-reloc.exp
With test-case gdb.arch/ftrace-insn-reloc.exp and host board
local-remote-host-notty and target board native-gdbserver I run into:
...
(gdb) info sharedlibrary^M
From To    Syms Read   Shared Object Library^M
$hex $hex  Yes         /lib64/ld-linux-x86-64.so.2^M
$hex $hex  Yes         /home/remote-host/libinproctrace.so^M
$hex $hex  Yes         /lib64/libm.so.6^M
$hex $hex  Yes         /lib64/libc.so.6^M
$hex $hex  Yes         /lib64/libdl.so.2^M
$hex $hex  Yes (*)     /usr/lib64/libstdc++.so.6^M
$hex $hex  Yes (*)     /lib64/libgcc_s.so.1^M
$hex $hex  Yes         /lib64/libpthread.so.0^M
(*): Shared library is missing debugging information.^M
(gdb) FAIL: gdb.arch/ftrace-insn-reloc.exp: IPA loaded
...
due to trying to match libinproctrace.so using the target path, while the
command lists it using the host path.

Fix this by making the regexp less strict.

Tested on x86_64-linux.
2023-03-17 19:25:18 +01:00
Tom de Vries
1850ef87c6 [gdb/testsuite] Handle remote host in gdb_load_shlib
With test-case gdb.arch/ftrace-insn-reloc.exp and host board
local-remote-host-notty and target board native-gdbserver I run into:
...
(gdb) tstart^M
Target returns error code '.In-process agent library not loaded in process.  \
  Fast and static trace points unavailable.'.^M
(gdb) FAIL: gdb.arch/ftrace-insn-reloc.exp: start trace experiment
...

Fix this by:
- handling remote host in gdb_load_shlib, and
- moving the gdb_load_shlib to after the clean_restart, such that the
  set solib-search-path can take effect.

Tested on x86_64-linux.
2023-03-17 19:25:18 +01:00
Tom de Vries
68f2478faa [gdb/testsuite] Fix gdb.arch/i386-biarch-core.exp for remote host
Fix test-case gdb.arch/i386-biarch-core.exp using gdb_download_remote host.

Tested on x86_64-linux.
2023-03-17 19:25:18 +01:00
Tom de Vries
2a7d1e5ebb [gdb/testsuite] Handle REMOTE_HOST_USERNAME in local-remote-host
Handle REMOTE_HOST_USERNAME in local-remote-host, similar to how that's done for
REMOTE_TARGET_USERNAME in remote-gdbserver-on-localhost.

This helps to keep the home dir clean.

Since the setup makes $build/gdb/testsuite on build unreadable for the remote
host, we run into permission problems for GDB and the data-directory, so fix
this (as was done for gdbserver in gdbserver-base.exp) using file normalize.

Tested on x86_64-linux.
2023-03-17 19:25:18 +01:00
Tom de Vries
3741934fdb [gdb/testsuite] Set remotedir by default in some boards
When doing a gdb_simple_compile, and downloading the resulting exec $obj
to target the result $target_obj may be a relative file path, which may give
problems when trying to do:
...
remote_exec target $target_obj
...

Fix/workaround this on some target boards by setting remotedir by default, and
add a corresponding test in gdb.testsuite/board-sanity.exp.

This doesn't work for host/target board local-remote-host-native, so xfail this.

Tested on x86_64-linux.
2023-03-17 16:06:39 +01:00
Tom de Vries
0eb0e08287 [gdb/testsuite] Fix have_avx for remote target
In proc have_avx we compile some source into an exec, resulting in a file $obj
on build, and then attempt to execute it on target:
...
    set result [remote_exec target $obj]
...

Fix this by using gdb_remote_download target.

Likewise in a few other procs that use "remote_exec target".

Tested on x86_64-linux.
2023-03-17 16:06:39 +01:00
Tom de Vries
4581f89b8d [gdb/testsuite] Handle precise-aligned-alloc.c for remote host
With test-case gdb.arch/i386-sse.exp (and likewise gdb.arch/i386-avx.exp) and
host board local-remote-host-notty and target board native-gdbserver I run
into:
...
gdb compile failed, i386-sse.c:68:10: fatal error: \
  ../lib/precise-aligned-alloc.c: No such file or directory
 #include "../lib/precise-aligned-alloc.c"
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...

Fix this using '#include "precise-aligned-alloc.c"' and making that work with
non-remote and remote host.

Tested on x86_64-linux.
2023-03-17 16:06:39 +01:00
Tom de Vries
a14e3d11b2 [gdb/testsuite] Handle remote host in escape_for_host
With test-case gdb.arch/ftrace-insn-reloc.exp and host board
local-remote-host-notty and target board native-gdbserver, I run into:
...
FAIL: gdb.arch/ftrace-insn-reloc.exp: IPA loaded
...
due to having:
...
$ readelf -d ftrace-insn-reloc | grep RUNPATH
 0x000000000000001d (RUNPATH)            Library runpath: []
...
instead of:
...
$ readelf -d ftrace-insn-reloc | grep RUNPATH
 0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN]
...

Handle this in escape_for_host.

Tested on x86_64-linux.
2023-03-17 13:29:13 +01:00
Tom de Vries
ff000c4dbb [gdb/testsuite] Add escape_for_host
In gdb_compile we have:
...
           lappend new_options "ldflags=-Wl,-rpath,\\\$ORIGIN"
...
and we could improve readability by using {} rather than "":
...
           lappend new_options {ldflags=-Wl,-rpath,\$ORIGIN}
...

But rather than manually adding escapes in a string, add a new proc
escape_for_host that care of this for us, allowing us to write:
...
           lappend new_options [escape_for_host {ldflags=-Wl,-rpath,$ORIGIN}]
...

Tested on x86_64-linux.
2023-03-17 13:29:13 +01:00
Tom de Vries
bf8d2f9235 [gdb/testsuite] Declare ada unsupported for remote host
Currently gdb_ada_compile doesn't support remote host.

Make this explicit in allow_ada_tests.

Tested on x86_64-linux.
2023-03-17 10:34:18 +01:00
Tom de Vries
14317f7f05 [gdb/testsuite] Fix filename in gdb.debuginfod/crc_mismatch.exp
After running test-case gdb.debuginfod/crc_mismatch.exp, I find a dir called '$':
...
$ ls $build/gdb/testsuite/
$      config.log     gdb.log  lib       outputs   site.exp
cache  config.status  gdb.sum  Makefile  site.bak  temp
...

Fix this by removing the stray '$' here:
...
set debugfile "$[standard_output_file ${testfile}.debug]"
...

Tested on x86_64-linux.
2023-03-17 10:01:07 +01:00
Andrew Burgess
eef174f6a9 gdb/doc: extended documentation for inferior function calls
I noticed that the documentation for inferior function calls doesn't
say much about what happens if/when an inferior function call is
interrupted, i.e. it doesn't describe what the dummy frame looks like
on the stack, or how GDB behaves when the inferior is continued and
reaches the dummy frame.

This commit aims to add some of this missing information.
2023-03-16 17:14:21 +00:00
Tom Tromey
5a9affd7b8 Fix build breakage in rs6000-aix-tdep.c
A recent change to rs6000-aix-tdep.c broke the build.  This patch
fixes it by declaring a few target descriptions in ppc-tdep.h and then
not including the various features .c files in rs6000-aix-tdep.c.
2023-03-16 09:50:06 -06:00
Hui Li
74975df62c gdb/testsuite: Add support for LoongArch in gdb.base/float.exp
The test results on LoongArch as follows:

Without this patch:

```
$ make check-gdb TESTS="gdb.base/float.exp"
=== gdb Summary ===

 # of expected passes		2
 # of unexpected failures	1

```
With this patch:

```
$ make check-gdb TESTS="gdb.base/float.exp"
=== gdb Summary ===

 # of expected passes		3

```

Signed-off-by: Hui Li <lihui@loongson.cn>
Reviewed-By: Tom Tromey <tom@tromey.com>
Approved-By: Simon Marchi <simon.marchi@efficios.com>
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
2023-03-16 22:59:34 +08:00