binutils-gdb.git
2 years agoAutomatic date update in version.in
GDB Administrator [Thu, 28 Apr 2022 00:00:21 +0000 (00:00 +0000)]
Automatic date update in version.in

2 years agox86: Disable 2 tests with large memory requirement
H.J. Lu [Wed, 27 Apr 2022 18:26:44 +0000 (11:26 -0700)]
x86: Disable 2 tests with large memory requirement

gas/

* testsuite/gas/i386/i386.exp: Disable rept.

ld/

* testsuite/ld-x86-64/x86-64.exp: Disable pr17618.

2 years agoMake gdb.base/parse_number.exp test all architectures
Pedro Alves [Wed, 27 Apr 2022 10:08:03 +0000 (11:08 +0100)]
Make gdb.base/parse_number.exp test all architectures

There are some subtle differences between architectures, like the size
of a "long" type, and this isn't currently accounted for in
gdb.base/parse_number.exp.

For example, on aarch64 a long type is 8 bytes, whereas a long type is
4 bytes for x86_64.  This causes the following FAIL's:

 FAIL: gdb.base/parse_number.exp: lang=asm: ptype 0xffffffffffffffff
 FAIL: gdb.base/parse_number.exp: lang=auto: ptype 0xffffffffffffffff
 FAIL: gdb.base/parse_number.exp: lang=c: ptype 0xffffffffffffffff
 FAIL: gdb.base/parse_number.exp: lang=c++: ptype 0xffffffffffffffff
 FAIL: gdb.base/parse_number.exp: lang=fortran: p/x 0xffffffffffffffff
 FAIL: gdb.base/parse_number.exp: lang=fortran: ptype 0xffffffffffffffff
 FAIL: gdb.base/parse_number.exp: lang=go: ptype 0xffffffffffffffff
 FAIL: gdb.base/parse_number.exp: lang=local: ptype 0xffffffffffffffff
 FAIL: gdb.base/parse_number.exp: lang=minimal: ptype 0xffffffffffffffff
 FAIL: gdb.base/parse_number.exp: lang=objective-c: ptype 0xffffffffffffffff
 FAIL: gdb.base/parse_number.exp: lang=opencl: ptype 0xffffffffffffffff
 FAIL: gdb.base/parse_number.exp: lang=pascal: ptype 0xffffffffffffffff

There are some fortran-specific divergences as well, where 32-bit
architectures show "unsigned int" for both 32-bit and 64-bit integers
and 64-bit architectures show "unsigned int" and "unsigned long" for
32-bit and 64-bit integers.

There might be a bug that 32-bit fortran truncates 64-bit values to
32-bit, given "p/x 0xffffffffffffffff" returns "0xffffffff".

Here's what we get for aarch64:

 (gdb) ptype 0xffffffff
 type = unsigned int
 (gdb) ptype 0xffffffffffffffff
 type = unsigned long
 (gdb) p sizeof (0xffffffff)
 $1 = 4
 (gdb) p sizeof (0xffffffffffffffff)
 quit
 $2 = 8
 (gdb) ptype 0xffffffff
 type = unsigned int
 (gdb) ptype 0xffffffffffffffff
 type = unsigned long

And for arm:

 (gdb) ptype 0xffffffff
 type = unsigned int
 (gdb) ptype 0xffffffffffffffff
 quit
 type = unsigned long long
 (gdb) p sizeof (0xffffffff)
 quit
 $1 = 4
 (gdb) p sizeof (0xffffffffffffffff)
 quit
 $2 = 8
 (gdb) ptype 0xffffffff
 type = unsigned int
 (gdb) ptype 0xffffffffffffffff
 type = unsigned long

This patch...

* Makes the testcase iterate over all architectures, thus covering all
  the different combinations of types/sizes every time.

* Adjusts the expected values and types based on the sizes of long
  long, long and int.

A particularly curious architecture is s12z, which has 32-bit long
long, and thus no way to represent 64-bit integers in C-like
languages.

Co-Authored-By: Luis Machado <luis.machado@arm.com>
Change-Id: Ifc0ccd33e7fd3c7585112ff6bebe7d266136768b

2 years agoFix gdbserver build for x86-64 Windows
Tom Tromey [Wed, 27 Apr 2022 16:14:01 +0000 (10:14 -0600)]
Fix gdbserver build for x86-64 Windows

I broke the gdbserver build on x86-64 Windows a little while back.
Previously, I could not build this configuration, but today I found
out that if I configure with:

    --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32

using the Fedora 34 tools, it will in fact build.  I'm not certain,
but maybe the gnulib update helped with this.

This patch fixes the build.  I'm checking it in.

2 years agoCreate pseudo sections for NT_ARM_TLS notes on FreeBSD.
John Baldwin [Wed, 27 Apr 2022 15:06:39 +0000 (08:06 -0700)]
Create pseudo sections for NT_ARM_TLS notes on FreeBSD.

bfd/ChangeLog:

* elf.c (elfcore_grok_freebsd_note): Handle NT_ARM_TLS notes.

2 years agogdb/arm: Extend arm_m_addr_is_magic to support FNC_RETURN, add unwind-secure-frames...
Christophe Lyon [Fri, 1 Apr 2022 09:22:28 +0000 (10:22 +0100)]
gdb/arm: Extend arm_m_addr_is_magic to support FNC_RETURN, add unwind-secure-frames command

This patch makes use of the support for several stack pointers
introduced by the previous patch to switch between them as needed
during unwinding.

It introduces a new 'unwind-secure-frames' arm command to enable/disable
mode switching during unwinding. It is enabled by default.

It has been tested using an STM32L5 board (with cortex-m33) and the
sample applications shipped with the STM32Cube development
environment: GTZC_TZSC_MPCBB_TrustZone in
STM32CubeL5/Projects/NUCLEO-L552ZE-Q/Examples/GTZC.

The test consisted in setting breakpoints in various places and check
that the backtrace is correct: SecureFault_Callback (Non-secure mode),
__gnu_cmse_nonsecure_call (before and after the vpush instruction),
SecureFault_Handler (Secure mode).

This implies that we tested only some parts of this patch (only MSP*
were used), but remaining parts seem reasonable.

Signed-off-by: Torbjörn Svensson <torbjorn.svensson@st.com>
Signed-off-by: Christophe Lyon <christophe.lyon@foss.st.com>
Signed-off-by: Christophe Lyon <christophe.lyon@arm.com>
2 years agogdb/arm: Add support for multiple stack pointers on Cortex-M
Christophe Lyon [Fri, 1 Apr 2022 09:22:16 +0000 (10:22 +0100)]
gdb/arm: Add support for multiple stack pointers on Cortex-M

Armv8-M architecture with Security extension features four stack pointers
to handle Secure and Non-secure modes.

This patch adds support to switch between them as needed during
unwinding, and replaces all updates of cache->prev_sp with calls to
arm_cache_set_prev_sp.

Signed-off-by: Torbjörn Svensson <torbjorn.svensson@st.com>
Signed-off-by: Christophe Lyon <christophe.lyon@foss.st.com>
Signed-off-by: Christophe Lyon <christophe.lyon@arm.com>
2 years agogdb/arm: Introduce arm_cache_init
Christophe Lyon [Fri, 1 Apr 2022 09:22:12 +0000 (10:22 +0100)]
gdb/arm: Introduce arm_cache_init

This patch is a preparation for the rest of the series and adds two
arm_cache_init helper functions. It updates every place that updates
cache->saved_regs to call the helper instead.

Signed-off-by: Torbjörn Svensson <torbjorn.svensson@st.com>
Signed-off-by: Christophe Lyon <christophe.lyon@foss.st.com>
Signed-off-by: Christophe Lyon <christophe.lyon@arm.com>
2 years agogdb/arm: Define MSP and PSP registers for M-Profile
Christophe Lyon [Fri, 1 Apr 2022 09:22:08 +0000 (10:22 +0100)]
gdb/arm: Define MSP and PSP registers for M-Profile

This patch removes the hardcoded access to PSP in
arm_m_exception_cache() and relies on the definition with the XML
descriptions.

Signed-off-by: Christophe Lyon <christophe.lyon@foss.st.com>
Signed-off-by: Christophe Lyon <christophe.lyon@arm.com>
2 years agogdb/arm: Fix prologue analysis to support vpush
Christophe Lyon [Fri, 1 Apr 2022 09:21:58 +0000 (10:21 +0100)]
gdb/arm: Fix prologue analysis to support vpush

While working on adding support for Non-secure/Secure modes unwinding,
I noticed that the prologue analysis lacked support for vpush, which
is used for instance in the CMSE stub routine.

This patch updates thumb_analyze_prologue accordingly, adding support
for vpush of D-registers.

Signed-off-by: Christophe Lyon <christophe.lyon@foss.st.com>
Signed-off-by: Christophe Lyon <christophe.lyon@arm.com>
2 years agogdb/testsuite: fix FAIL in gdb.base/clear_non_user_bp.exp
Enze Li [Wed, 27 Apr 2022 13:12:27 +0000 (21:12 +0800)]
gdb/testsuite: fix FAIL in gdb.base/clear_non_user_bp.exp

Tom and Simon feedback that there is a test failing in this commit:

  commit a5c69b1e49bae4d0dcb20f324cebb310c63495c6
  Date:   Sun Apr 17 15:09:46 2022 +0800

    gdb: fix using clear command to delete non-user breakpoints(PR cli/7161)

Then, I reproduced the same fail with Ubuntu 20.04 as Simon said, and I
fixed the nit in this patch.  The root of the problem is not correctly
matching the presentation of internal breakpoints.

In addition, as Pedro pointed out, the original testcase is not portable
in some methods, so this patch fixes this issue and some other
improvements.

Tested on x86_64 ubuntu 20.04.4 and openSUSE Tumbleweed(VERSION_ID="20220425").

2 years agox86: VFPCLASSSH is Evex.LLIG
Jan Beulich [Wed, 27 Apr 2022 09:08:57 +0000 (11:08 +0200)]
x86: VFPCLASSSH is Evex.LLIG

This also was mistakenly flagged as Evex.128.

2 years agoFix potential buffer overruns when creating DLLs.
Nick Clifton [Wed, 27 Apr 2022 07:35:18 +0000 (08:35 +0100)]
Fix potential buffer overruns when creating DLLs.

PR 29006
* pe-dll.c (make_head): Use asprintf to allocate and populate a
buffer containing the temporary name.
(make_tail, make_one, make_singleton_name_thunk): Likewise.
(make_import_fixup_mark, make_import_fixup_entry): Likewise.
(make_runtime_pseudo_reloc): Likewise.
(pe_create_runtime_relocator_reference): Likewise.

2 years agoRevert pr29072 lto test changes
Alan Modra [Tue, 26 Apr 2022 23:39:41 +0000 (09:09 +0930)]
Revert pr29072 lto test changes

Revert commit 65daf5bed6 testsuite changes in ld-plugin/.  -z isn't
supported for non-ELF targets, and isn't needed since we now prune the
exec stack warning (commit 333cd559ba).

PR 29072

2 years agogdb/testsuite: use with_cwd where possible
Simon Marchi [Fri, 22 Apr 2022 13:16:59 +0000 (09:16 -0400)]
gdb/testsuite: use with_cwd where possible

I learned about with_cwd today.  I spotted a few spots that could use
it, to make the code more robust.

Change-Id: Ia23664cb827f25e79d31948e0c006a8dc61c33e1

2 years agoAutomatic date update in version.in
GDB Administrator [Wed, 27 Apr 2022 00:00:16 +0000 (00:00 +0000)]
Automatic date update in version.in

2 years agoGDB PowerPC record test cases for ISA 2.06 and ISA 3.1
Carl Love [Tue, 26 Apr 2022 19:23:49 +0000 (19:23 +0000)]
GDB PowerPC record test cases for ISA 2.06 and ISA 3.1

This patch adds PowerPC specific tests to verify recording of various
instructions.  The first test case checks the ISA 2.06 lxvd2x instruction.
The second test case tests several of the ISA 3.01 instructions.  Specifically,
it checks the word and prefixed instructions and some of the Matrix
Multiply Assist (MMA) instructions.

The patch has been run on both Power 10 and Power 9 to verify the ISA
2.06 test case runs on both platforms without errors.  The ISA 3.1 test
runs without errors on Power 10 and is skipped as expected on Power 9.

2 years agoAdd recording support for the ISA 3.1 PowerPC instructions.
Carl Love [Tue, 26 Apr 2022 19:23:17 +0000 (19:23 +0000)]
Add recording support for the ISA 3.1 PowerPC instructions.

This patch adds support for the PowerPC ISA 3.1 instructions to the PowerPC
gdb instruction recording routines.  Case statement entries are added to a
number of the existing routines for recording the 32-bit word instructions.
A few new functions were added to handle the new word instructions.  The 64-bit
prefix instructions are all handled by a set of new routines.  The function
ppc_process_prefix_instruction() is the primary function to handle the
prefixed instructions. It calls additional functions to handle specific
sets of prefixed instructions.  These new functions are:
  ppc_process_record_prefix_vsx_d_form(),
  ppc_process_record_prefix_store_vsx_ds_form(),
  ppc_process_record_prefix_op34(),
  ppc_process_record_prefix_op33(),
  ppc_process_record_prefix_op32(),
  ppc_process_record_prefix_store(),
  ppc_process_record_prefix_op59_XX3(),
  ppc_process_record_prefix_op42().

2 years agoHandle encoding failures in Windows thread names
Tom Tromey [Tue, 19 Apr 2022 17:21:35 +0000 (11:21 -0600)]
Handle encoding failures in Windows thread names

Internally at AdaCore, we noticed that the new Windows thread name
code could fail.  First, it might return a zero-length string, but in
gdb conventions it should return nullptr instead.  Second, an encoding
failure could wind up showing replacement characters to the user; this
is confusing and not useful; it's better to recognize such errors and
simply discard the name.  This patch makes both of these changes.

2 years agoi386: Pass -z noexecstack to linker tests
H.J. Lu [Tue, 26 Apr 2022 16:26:36 +0000 (09:26 -0700)]
i386: Pass -z noexecstack to linker tests

PR ld/29072
* testsuite/ld-i386/i386.exp: Pass -z noexecstack to gotpc1
and property-6.

2 years agobsd-kvm: Fix build after recent changes to path handling functions.
John Baldwin [Tue, 26 Apr 2022 16:13:12 +0000 (09:13 -0700)]
bsd-kvm: Fix build after recent changes to path handling functions.

Convert bsd_kvm_corefile and the local filename in bsd_kvm_open to
std::string rather than simple char * pointers freed by xfree.

2 years agogdb: make some random Python files Python 3-compatible
Simon Marchi [Tue, 26 Apr 2022 15:37:46 +0000 (11:37 -0400)]
gdb: make some random Python files Python 3-compatible

I noticed that these files failed to format with Black, because they use
print without parenthesis (which isn't Python 3 compatible).

I don't know if these files are still relevant, but the change is
trivial, so here it is.

Change-Id: I116445c2b463486016f824d32effffc915b60766

2 years agoPowerPC: Update expected floating point output for gdb.arch/altivec-regs.exp and...
Carl Love [Tue, 26 Apr 2022 15:00:19 +0000 (15:00 +0000)]
PowerPC: Update expected floating point output for gdb.arch/altivec-regs.exp and gdb.arch/vsx-regs.exp

The format for printing the floating point values was changed by commit:

   commit 56262a931b7ca8ee3ec9104bc7e9e0b40cf3d64e
   Author: Tom Tromey <tromey@adacore.com>
   Date:   Thu Feb 17 13:43:59 2022 -0700

       Change how "print/x" displays floating-point value

       Currently, "print/x" will display a floating-point value by first
       casting it to an integer type.  This yields weird results like:

           (gdb) print/x 1.5
           $1 = 0x1
        ...
        Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=16242

The above change results in 417 regression test failures since the expected
Power vector register output no longer match.

This patch updates the expected Altivec floating point register prints to
the hexadecimal format for both big endian and little endian systems.  The
patch also fixes a formatting isue with the decimal_vector expected value
assign statements.

The expected VSX vector_register1, vector_register1_vr, vector_register2,
vector_register2_vr variables are updated to include the new float128 entry.
Additionally, the comment in the vsx expect file about the initialization
of the vs registers is updated.

The patch has been tested on Power 10, Power 8 LE and Power 8 BE.

2 years agogdbsupport/pathstuff.h: #include <array> explicitly for std::array<>
John Baldwin [Tue, 26 Apr 2022 00:06:09 +0000 (17:06 -0700)]
gdbsupport/pathstuff.h: #include <array> explicitly for std::array<>

This fixes build breakage using clang with libc++ on FreeBSD where
std::array<> is not yet declared when used by the path_join variadic
function template.

2 years agoAutomatic date update in version.in
GDB Administrator [Tue, 26 Apr 2022 00:00:13 +0000 (00:00 +0000)]
Automatic date update in version.in

2 years agoDo not put linkage names into .gdb_index
Tom Tromey [Fri, 22 Apr 2022 17:44:59 +0000 (11:44 -0600)]
Do not put linkage names into .gdb_index

This changes the .gdb_index writer to skip linkage names.  This was
always done historically (though somewhat implicitly).

2 years agoEmit a note warning the user that creating an executable stack because of a missing...
Nick Clifton [Mon, 25 Apr 2022 11:51:31 +0000 (12:51 +0100)]
Emit a note warning the user that creating an executable stack because of a missing .note.GNU-stack section is deprecated.

PR 29072
bfd * elflink.c (bfd_elf_size_dynamic_sections): Display a note to the
user that the current ehaviour of creating an executable stack
because of a missing .note.GNU-stack section is deprecated and
will be changed in a future release.

binutils* testsuite/lib/binutils-common.exp (prune_warnings_extra): Filter
out notes about the executable stacjk behaviour beign deprecated.

ld * testsuite/ld-elf/pr29072.b.warn: Update to include the note
about the linker's behaviour being depreccated.

2 years agogdb/fortran: Support for assumed rank zero
rupothar [Fri, 8 Apr 2022 10:35:41 +0000 (16:05 +0530)]
gdb/fortran: Support for assumed rank zero

If a variable is passed to function in FORTRAN as an argument the
variable is treated as an array with rank zero.  GDB currently does
not support the case for assumed rank 0.  This patch provides support
for assumed rank 0 and updates the testcase as well.

Without patch:
Breakpoint 1, arank::sub1 (a=<error reading variable:
  failed to resolve dynamic array rank>) at assumedrank.f90:11
11       PRINT *, RANK(a)
(gdb) p a
failed to resolve dynamic array rank
(gdb) p rank(a)
failed to resolve dynamic array rank

With patch:
Breakpoint 1, arank::sub1 (a=0) at assumedrank.f90:11
11       PRINT *, RANK(a)
(gdb) p a
$1 = 0
(gdb) p rank(a)
$2 = 0

2 years agogdb/infrun: assert !step_over_info_valid_p in restart_threads
Lancelot SIX [Tue, 19 Apr 2022 22:13:29 +0000 (23:13 +0100)]
gdb/infrun: assert !step_over_info_valid_p in restart_threads

While working in gdb/infrun.c:restart_threads, I was wondering what are
the preconditions to call the function.  It seems to me that
!step_over_info_valid_p should be a precondition (i.e. if we are doing
an inline step over breakpoint, we do not want to resume non stepping
threads as one of them might miss the breakpoint which is temporally
disabled).

To convince myself that this is true, I have added an assertion to
enforce this, and got one regression in the testsuite:

    FAIL: gdb.base/step-over-syscall.exp: vfork: displaced=off: single step over vfork (GDB internal error)

This call to restart_threads originates from handle_vfork_done which
does not check if a step over is active when restarting other threads:

    if (target_is_non_stop_p ())
      {
        scoped_restore_current_thread restore_thread;

        insert_breakpoints ();
        restart_threads (event_thread, event_thread->inf);
        start_step_over ();
      }

In this patch, I propose to:
- Call start_step_over before restart_threads.  If a step over is already
  in progress (as it is the case in the failing testcase),
  start_step_over return immediately, and there is no point in restarting
  all threads just to stop them right away for a step over breakpoint.
- Only call restart_threads if no step over is in progress at this
  point.

In this patch, I also propose to keep the assertion in restart_threads
to help enforce this precondition, and state it explicitly.

I have also checked all other places which call restart_threads, and
they all seem to check that there is no step over currently active
before doing the call.

As for infrun-related things, I am never completely sure I did not miss
something.  So as usual, all feedback and thoughts are very welcome.

Tested on x86_64-linux-gnu.

Change-Id: If5f5f98ec4cf9aaeaabb5e3aa88ae6ffd70d4f37

2 years agoAutomatic date update in version.in
GDB Administrator [Mon, 25 Apr 2022 00:00:15 +0000 (00:00 +0000)]
Automatic date update in version.in

2 years agogdb: move setbuf calls out of gdb_readline_no_editing_callback
Andrew Burgess [Sun, 24 Apr 2022 15:39:19 +0000 (08:39 -0700)]
gdb: move setbuf calls out of gdb_readline_no_editing_callback

After this commit:

  commit d08cbc5d3203118da5583296e49273cf82378042
  Date:   Wed Dec 22 12:57:44 2021 +0000

      gdb: unbuffer all input streams when not using readline

Issues were reported with some MS-Windows hosts, see the thread
starting here:

  https://sourceware.org/pipermail/gdb-patches/2022-March/187004.html

Filed in bugzilla as: PR mi/29002

The problem seems to be that calling setbuf on terminal file handles
is not always acceptable, see this mail for more details:

  https://sourceware.org/pipermail/gdb-patches/2022-April/187310.html

This commit does two things, first moving the setbuf calls out of
gdb_readline_no_editing_callback so that we don't end up calling
setbuf so often.

Then, for MS-Windows hosts, we don't call setbuf for terminals, this
appears to resolve the issues that have been reported.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29002

2 years agoAutomatic date update in version.in
GDB Administrator [Sun, 24 Apr 2022 00:00:10 +0000 (00:00 +0000)]
Automatic date update in version.in

2 years agoAutomatic date update in version.in
GDB Administrator [Sat, 23 Apr 2022 00:00:17 +0000 (00:00 +0000)]
Automatic date update in version.in

2 years agogdb: handle_no_resumed: only update thread list of event target
Simon Marchi [Tue, 12 Apr 2022 02:11:03 +0000 (22:11 -0400)]
gdb: handle_no_resumed: only update thread list of event target

When running:

    $ make check TESTS="gdb.multi/multi-re-run.exp" RUNTESTFLAGS="--target_board=native-gdbserver"

I get:

    target remote localhost:2347^M
    Remote debugging using localhost:2347^M
    Reading symbols from /lib64/ld-linux-x86-64.so.2...^M
    Reading symbols from /usr/lib/debug//lib/x86_64-linux-gnu/ld-2.31.so...^M
    0x00007ffff7fd0100 in _start () from /lib64/ld-linux-x86-64.so.2^M
    (gdb) continue^M
    Continuing.^M
    Cannot execute this command while the target is running.^M
    Use the "interrupt" command to stop the target^M
    and then try again.^M
    (gdb) FAIL: gdb.multi/multi-re-run.exp: re_run_inf=1: iter=1: runto: run to all_started

The test does:

 - Connect to a remote target with inferior 2, continue and stop on the
   all_started function
 - Connect to a separate remote target / GDBserver instance with inferior 1,
   continue and (expect to) stop on the all_started function

The failure seen above happens when trying to continue inferior 1.

What happens is:

 - GDB tells inferior 1's remote target to continue
 - We go into fetch_inferior_event, try to get an event at random from
   the targets
 - do_target_wait happens to pick inferior 2's target
 - That target return TARGET_WAITKIND_NO_RESUMED, which makes sense:
   inferior 2 is stopped, that target has no resumed thread
 - handle_no_resumed tries to update the thread list of all targets:

   for (auto *target : all_non_exited_process_targets ())
     {
       switch_to_target_no_thread (target);
       update_thread_list ();
     }

 - When trying to update the thread list of inferior 1's target, it hits
   the "Cannot execute this command while the target is running" error.
   This target is working in "remote all-stop" mode, and it is currently
   waiting for a stop reply, so it can't send packets to update the
   thread list at this time.

To handle the problem described in the comment in handle_no_resumed, I
don't think it is necessary to update the thread list of all targets,
but only the event target.  That comment describes a kind of race
condition where some target reports a breakpoint hit for a thread and
then its last remaining resumed thread exits, so sends a "no resumed"
event.  If we ended up resuming the thread that hit a breakpoint, we
want to ignore the "no resumed" and carry on.

But I don't really see why we need to update the thread list on the
other targets.  I can't really articulate this, it's more a gut feeling,
maybe I just fail to imagine the situation where this is needed.  But
here is the patch anyway, so we can discuss it.  The patch changes
handle_no_resumed to only update the thread list of the event target.
This fixes the test run shown above.

The way I originally tried to fix this was to make
remote_target::update_thread_list return early if the target is
currently awaiting a stop reply, since there's no way it can update the
thread list at that time.  But that felt more like papering over the
problem.  I then thought that we probably shouldn't be asking the target
to update the thread list unnecessarily.

Change-Id: Ide3df22b4f556478e155ad1c67ad4b4fe7c26a58

2 years agogdbserver/linux: free process_info_private and arch_process_info when failing to...
Simon Marchi [Fri, 22 Apr 2022 15:34:54 +0000 (11:34 -0400)]
gdbserver/linux: free process_info_private and arch_process_info when failing to attach

Running

  $ ../gdbserver/gdbserver --once --attach :1234 539436

with ASan while /proc/sys/kernel/yama/ptrace_scope is set to 1 (prevents
attaching) shows that we fail to free some platform-specific objects
tied to the process_info (process_info_private and arch_process_info):

    Direct leak of 32 byte(s) in 1 object(s) allocated from:
        #0 0x7f6b558b3fb9 in __interceptor_calloc /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:154
        #1 0x562eaf15d04a in xcalloc /home/simark/src/binutils-gdb/gdbserver/../gdb/alloc.c:100
        #2 0x562eaf251548 in xcnew<process_info_private> /home/simark/src/binutils-gdb/gdbserver/../gdbsupport/poison.h:122
        #3 0x562eaf22810c in linux_process_target::add_linux_process_no_mem_file(int, int) /home/simark/src/binutils-gdb/gdbserver/linux-low.cc:426
        #4 0x562eaf22d33f in linux_process_target::attach(unsigned long) /home/simark/src/binutils-gdb/gdbserver/linux-low.cc:1132
        #5 0x562eaf1a7222 in attach_inferior /home/simark/src/binutils-gdb/gdbserver/server.cc:308
        #6 0x562eaf1c1016 in captured_main /home/simark/src/binutils-gdb/gdbserver/server.cc:3949
        #7 0x562eaf1c1d60 in main /home/simark/src/binutils-gdb/gdbserver/server.cc:4084
        #8 0x7f6b552f630f in __libc_start_call_main (/usr/lib/libc.so.6+0x2d30f)

    Indirect leak of 56 byte(s) in 1 object(s) allocated from:
        #0 0x7f6b558b3fb9 in __interceptor_calloc /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:154
        #1 0x562eaf15d04a in xcalloc /home/simark/src/binutils-gdb/gdbserver/../gdb/alloc.c:100
        #2 0x562eaf2a0d79 in xcnew<arch_process_info> /home/simark/src/binutils-gdb/gdbserver/../gdbsupport/poison.h:122
        #3 0x562eaf295e2c in x86_target::low_new_process() /home/simark/src/binutils-gdb/gdbserver/linux-x86-low.cc:723
        #4 0x562eaf22819b in linux_process_target::add_linux_process_no_mem_file(int, int) /home/simark/src/binutils-gdb/gdbserver/linux-low.cc:428
        #5 0x562eaf22d33f in linux_process_target::attach(unsigned long) /home/simark/src/binutils-gdb/gdbserver/linux-low.cc:1132
        #6 0x562eaf1a7222 in attach_inferior /home/simark/src/binutils-gdb/gdbserver/server.cc:308
        #7 0x562eaf1c1016 in captured_main /home/simark/src/binutils-gdb/gdbserver/server.cc:3949
        #8 0x562eaf1c1d60 in main /home/simark/src/binutils-gdb/gdbserver/server.cc:4084
        #9 0x7f6b552f630f in __libc_start_call_main (/usr/lib/libc.so.6+0x2d30f)

Those objects are deleted by linux_process_target::mourn, but that is
not called if we fail to attach, we only call remove_process.  I
initially fixed this by making linux_process_target::attach call
linux_process_target::mourn on failure (before calling error).  But this
isn't done anywhere else (including in GDB) so it would just be
confusing to do things differently here.

Instead, add a linux_process_target::remove_linux_process helper method
(which calls remove_process), and call that instead of remove_process in
the Linux target.  Move the free-ing of the extra data from the mourn
method to that new method.

Change-Id: I277059a69d5f08087a7f3ef0b8f1792a1fcf7a85

2 years agogdb: handle bracketed-paste-mode and EOF correctly
Andrew Burgess [Tue, 15 Feb 2022 17:28:03 +0000 (17:28 +0000)]
gdb: handle bracketed-paste-mode and EOF correctly

This commit replaces an earlier commit that worked around the issues
reported in bug PR gdb/28833.

The previous commit just implemented a work around in order to avoid
the worst results of the bug, but was not a complete solution.  The
full solution was considered too risky to merge close to branching GDB
12.  This improved fix has been applied after GDB 12 branched.  See
this thread for more details:

  https://sourceware.org/pipermail/gdb-patches/2022-March/186391.html

This commit replaces this earlier commit:

  commit 74a159a420d4b466cc81061c16d444568e36740c
  Date:   Fri Mar 11 14:44:03 2022 +0000

      gdb: work around prompt corruption caused by bracketed-paste-mode

Please read that commit for a full description of the bug, and why is
occurs.

In this commit I extend GDB to use readline's rl_deprep_term_function
hook to call a new function gdb_rl_deprep_term_function.  From this
new function we can now print the 'quit' message, this replaces the
old printing of 'quit' in command_line_handler.  Of course, we only
print 'quit' in gdb_rl_deprep_term_function when we are handling EOF,
but thanks to the previous commit (to readline) we now know when this
is.

There are two aspects of this commit that are worth further
discussion, the first is in the new gdb_rl_deprep_term_function
function.  In here I have used a scoped_restore_tmpl to disable the
readline global variable rl_eof_found.

The reason for this is that, in rl_deprep_terminal, readline will
print an extra '\n' character before printing the escape sequence to
leave bracketed paste mode.  You might then think that in the
gdb_rl_deprep_term_function function, we could simply print "quit" and
rely on rl_deprep_terminal to print the trailing '\n'.  However,
rl_deprep_terminal only prints the '\n' when bracketed paste mode is
on.  If the user has turned this feature off, no '\n' is printed.
This means that in gdb_rl_deprep_term_function we need to print
"quit" when bracketed paste mode is on, and "quit\n" when bracketed
paste mode is off.

We could absolutely do that, no problem, but given we know how
rl_deprep_terminal is implemented, it's easier (I think) to just
temporarily clear rl_eof_found, this prevents the '\n' being printed
from rl_deprep_terminal, and so in gdb_rl_deprep_term_function, we can
now always print "quit\n" and this works for all cases.

The second issue that should be discussed is backwards compatibility
with older versions of readline.  GDB can be built against the system
readline, which might be older than the version contained within GDB's
tree.  If this is the case then the system readline might not contain
the fixes needed to support correctly printing the 'quit' string.

To handle this situation I have retained the existing code in
command_line_handler for printing 'quit', however, this code is only
used now if the version of readline we are using doesn't not include
the required fixes.  And so, if a user is using an older version of
readline, and they have bracketed paste mode on, then they will see
the 'quit' sting printed on the line below the prompt, like this:

  (gdb)
  quit

I think this is the best we can do when someone builds GDB against an
older version of readline.

Using a newer version of readline, or the patched version of readline
that is in-tree, will now give a result like this in all cases:

  (gdb) quit

Which is what we want.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28833

2 years agoreadline: back-port changes needed to properly detect EOF
Andrew Burgess [Mon, 7 Mar 2022 13:49:21 +0000 (13:49 +0000)]
readline: back-port changes needed to properly detect EOF

This commit is a partial back-port of this upstream readline commit:

  commit 002d31aa5f5929eb32d0e0e2e8b8d35d99e59961
  Author: Chet Ramey <chet.ramey@case.edu>
  Date:   Thu Mar 3 11:11:47 2022 -0500

      add rl_eof_found to public API; fix pointer aliasing problems  \
            with history-search-backward; fix a display problem with \
            runs of invisible characters at the end of a physical    \
            screen line

I have only pulled in the parts of this commit that relate to the new
rl_eof_found global, and the RL_STATE_EOF state flag.  These changes
are needed in order to fix PR cli/28833, and are discussed in this
thread to the bug-readline mailing list:

  https://lists.gnu.org/archive/html/bug-readline/2022-02/msg00021.html

The above commit is not yet in any official readline release, but my
hope is that now it has been merged into the readline tree it should
be safe enough to back port this fix to GDB's tree.

At some point in the future we will inevitably want to roll forward
the version of readline that we maintain in the binutils-gdb
repository.  When that day comes the changes in this commit can be
replaced with the latest upstream readline code, as I have not changed
the meaning of this code at all from what is in upstream readline.

This commit alone does not fix the PR cli/28833 issue, for that see
the next commit, which changes GDB itself.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28833

2 years agogdb: improved EOF handling when using readline 7
Andrew Burgess [Tue, 29 Mar 2022 14:07:04 +0000 (15:07 +0100)]
gdb: improved EOF handling when using readline 7

In this commit:

  commit a6b413d24ccc5d76179bab866834e11fd6fec294
  Date:   Fri Mar 11 14:44:03 2022 +0000

      gdb: work around prompt corruption caused by bracketed-paste-mode

a change was made to GDB to work around bug PR gdb/28833.  The
consequence of this work around is that, when bracketed paste mode is
enabled in readline, and GDB is quit by sending EOF, then the output
will look like this:

  (gdb)
  quit

The ideal output, which is what we get when bracketed paste mode is
off, is this:

  (gdb) quit

The reason we need to make this change is explained in the original
commit referenced above.  What isn't mentioned in the above commit, is
that the change that motivated this work around was only added in
readline 8, older versions of readline don't require the change.

In later commits in this series I will add a fix to GDB's in-tree copy
of readline (this fix is back-ported from upstream readline), and then
I will change GDB so that, when using the (patched) in-tree readline,
we can have the ideal output in all cases.

However, GDB can be built against the system readline.  When this is
done, and the system readline is version 8, then we will still have to
use the work around (two line) style output.

But, if GDB is built against the system readline, and the system
readline is an older version 7 readline, then there's no reason why we
can't have the ideal output, after all, readline 7 doesn't include the
change that we need to work around.

This commit changes GDB so that, when using readline 7 we get the
ideal output in all cases.  This change is trivial (a simple check
against the readline version number) so I think this should be fine to
include.

For testing this commit, you need to configure GDB including the
'--with-system-readline' flag, and build GDB on a system that uses
readline 7, for example 'Ubuntu 18.04'.  Then run the test
'gdb.base/eof-exit.exp', you should expect everything to PASS.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28833

2 years agogdb: prune inferiors at end of fetch_inferior_event, fix intermittent failure of...
Simon Marchi [Fri, 22 Apr 2022 17:40:57 +0000 (13:40 -0400)]
gdb: prune inferiors at end of fetch_inferior_event, fix intermittent failure of gdb.threads/fork-plus-threads.exp

This test sometimes fail like this:

    info threads^M
      Id   Target Id         Frame ^M
      11.12 process 2270719   Couldn't get registers: No such process.^M
    (gdb) FAIL: gdb.threads/fork-plus-threads.exp: detach-on-fork=off: no threads left
    [Inferior 11 (process 2270719) exited normally]^M
    info inferiors^M
      Num  Description       Connection           Executable        ^M
    * 1    <null>                                 /home/smarchi/build/binutils-gdb/gdb/testsuite/outputs/gdb.threads/fork-plus-threads/fork-plus-threads ^M
      11   <null>                                 /home/smarchi/build/binutils-gdb/gdb/testsuite/outputs/gdb.threads/fork-plus-threads/fork-plus-threads ^M
    (gdb) FAIL: gdb.threads/fork-plus-threads.exp: detach-on-fork=off: only inferior 1 left (the program exited)

I can get it to fail quite reliably by pinning it to a core:

  $ taskset -c 5 make check TESTS="gdb.threads/fork-plus-threads.exp"

The previous attempt at fixing this was:

  https://sourceware.org/pipermail/gdb-patches/2021-October/182846.html

What we see is part due to a possible unfortunate ordering of events
given by the kernel, and what could be considered a bug in GDB.

The test program makes a number of forks, waits them all, then exits.
Most of the time, GDB will get and process the exit event for inferior 1
after the exit events of all the children.  But this is not guaranteed.
After the last child exits and is waited by the parent, the parent can
exit quickly, such that GDB collects from the kernel the exit events for
the parent and that child at the same time.  It then chooses one event
at random, which can be the event for the parent.  This will result in
the parent appearing to exit before its child.  There's not much we can
do about it, so I think we have to adjust the test to cope.

After expect has seen the "exited normally" notification for inferior 1,
it immediately does an "info thread" that it expects to come back empty.
But at this point, GDB might not have processed inferior 11's (the last
child) exit event, so it will look like there is still a thread.  Of
course that thread is dead, we just don't know it yet.  But that makes
the "no thread" test fail.  If the test waited just a bit more for the
"exited normally" notification for inferior 11, then the list of threads
would be empty.

So, first change, make the test collect all the "exited normally"
notifications for all inferiors before proceeding, that should ensure we
see an empty thread list.  That would fix the first FAIL above.

However, we would still have the second FAIL, as we expect inferior 11
to not be there, it should have been deleted automatically.  Inferior 11
is normally deleted when prune_inferiors is called.  That is called by
normal_stop, which is only called by fetch_inferior_event only if the
event thread completed an execution command FSM (thread_fsm).  But the
FSM for the continue command completed when inferior 1 exited.  At that
point inferior 11 was not prunable, as it still had a thread.  When
inferior 11 exits, prune_inferiors is not called.

I think that can be considered a GDB bug.  From the user point of view,
there's no reason why in one case inferior 11 would be deleted and not
in the other case.

This patch makes the somewhat naive change to call prune_inferiors in
fetch_inferior_event, so that it is called in this case.  It is placed
at this particular point in the function so that it is called after the
user inferior / thread selection is restored.  If it was called before
that, inferior 11 wouldn't be pruned, because it would still be the
current inferior.

Change-Id: I48a15d118f30b1c72c528a9f805ed4974170484a
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=26272

2 years agoUn-break the coff-pe-read.c build
Tom Tromey [Fri, 22 Apr 2022 15:28:10 +0000 (09:28 -0600)]
Un-break the coff-pe-read.c build

This fixes a build breakage in my recent coff-pe-read.c change.

I'm sorry about this.  I don't understand how it happened, because I
definitely built and tested the series on Windows, and I didn't change
it before pushing.  Something must have gone wrong on the Windows
build, but I don't know what.  I'll investigate and and re-test to be
sure.

2 years agoMore const use and alloca avoidance in coff-pe-read.c
Tom Tromey [Tue, 19 Apr 2022 13:41:44 +0000 (07:41 -0600)]
More const use and alloca avoidance in coff-pe-read.c

This changes another function in coff-pe-read.c to use 'const' more,
and to avoid the use of alloca by instead using std::string.

2 years agoUse std::string in coff-pe-read.c
Tom Tromey [Tue, 19 Apr 2022 13:33:09 +0000 (07:33 -0600)]
Use std::string in coff-pe-read.c

coff-pe-read.c uses xsnprintf and alloca, but using std::string is
better, and just as easy.  In general I think alloca is something to
be avoided, and unbounded uses especially so.

2 years agoRemove a const-removing cast from coff-pe-read.c
Tom Tromey [Tue, 19 Apr 2022 13:30:08 +0000 (07:30 -0600)]
Remove a const-removing cast from coff-pe-read.c

coff-pe-read.c casts away const at one spot, but this is easily
replaced by calling bfd_get_filename directly in a couple of debugging
prints.

2 years agoSimplify BFD section iteration in coff-pe-read.c
Tom Tromey [Tue, 19 Apr 2022 13:27:48 +0000 (07:27 -0600)]
Simplify BFD section iteration in coff-pe-read.c

coff-pe-read.c iterates over BFD sections using bfd_map_over_sections,
but it's much simpler to use a for-each loop.  This allows for the
removal of helper functions and types.

2 years agoFix method naming bug in new DWARF indexer
Tom Tromey [Thu, 21 Apr 2022 15:37:24 +0000 (09:37 -0600)]
Fix method naming bug in new DWARF indexer

Pedro pointed out that gdb-add-index is much slower with the new DWARF
indexer.  He also noticed that, in some cases, the generated
.gdb_index would have the wrong fully-qualified name for a method.

I tracked this down to a bug in the indexer.  If a type could have
methods but was marked as a declaration, the indexer was ignoring it.
However, this meant that the internal map to find the qualified name
was not updated for this container.

2 years agoRISC-V: Add missing DECLARE_INSNs for Zicbo{m,p,z}
Christoph Muellner [Thu, 21 Apr 2022 22:31:27 +0000 (00:31 +0200)]
RISC-V: Add missing DECLARE_INSNs for Zicbo{m,p,z}

The recently added support for the Zicbo{m,p,z} extensions did not
include DECLARE_INSN() declarations for the instructions.
These declarations are needed by GDB's instruction detection code.
This patch adds them.

Signed-off-by: Christoph Muellner <cmuellner@gcc.gnu.org>
2 years agoAutomatic date update in version.in
GDB Administrator [Fri, 22 Apr 2022 00:00:20 +0000 (00:00 +0000)]
Automatic date update in version.in

2 years agoFix for gdb.base/solib-search.exp test.
Carl Love [Tue, 22 Mar 2022 20:23:44 +0000 (15:23 -0500)]
Fix for gdb.base/solib-search.exp test.

The variable right_lib_flags is not being set correctly to define RIGHT.
The value RIGHT is needed to force the address of the library functions
lib1_func3 and lib2_func4 to occur at different address in the wrong and
right libraries.

With RIGHT defined correctly, functions lib1_func3 and lib2_func4 occur
at different addresses the test runs correctly on Powerpc.

The test needs the lib2 addresses to be different in the right and
wrong cases.  That is the point of introducing function lib2_spacer
with the ifdef RIGHT compiler directive.

On Intel, the ARRAY_SIZE of 1 versus 8192 is sufficient to get the
dynamic linker to move the addresses of the library.  You can also get
the same effect on PowerPC but you must use a value much larger than
8192.

The key thing is that the test was not properly setting RIGHT to
defined to get the lib2_spacer function on Intel and Powerpc.

Without the patch, we have the Intel backtrace for the bad libraries:

backtrace
#0  break_here () at /home/ ... /gdb/testsuite/gdb.base/solib-search.c:30
#1  0x00007ffff7fae156 in ?? ()
#2  0x00007fffffffc150 in ?? ()
#3  0x00007ffff7fbb156 in ?? ()
#4  0x00007fffffffc160 in ?? ()
#5  0x00007ffff7fae146 in ?? ()
#6  0x00007fffffffc170 in ?? ()
#7  0x00007ffff7fbb146 in ?? ()
#8  0x00007fffffffc180 in ?? ()
#9  0x0000555555555156 in main () at /home/ ... /binutils-gdb/gdb/testsuite/gdb.base/solib-search.c:23
Backtrace stopped: previous frame inner to this frame (corrupt stack?)
(gdb) PASS: gdb.base/solib-search.exp: backtrace (with wrong libs) (data collection)

The backtrace on Intel with the good libraries is:

backtrace
#0  break_here () at /.../binutils-gdb/gdb/testsuite/gdb.base/solib-search.c:30
#1  0x00007ffff7fae156 in lib2_func4 () at /.../binutils-gdb/gdb/testsuite/gdb.base/solib-search-lib2.c:49
#2  0x00007ffff7fbb156 in lib1_func3 () at /.../gdb.base/solib-search-lib1.c:49
#3  0x00007ffff7fae146 in lib2_func2 () at /.../testsuite/gdb.base/solib-search-lib2.c:30
#4  0x00007ffff7fbb146 in lib1_func1 () at /.../gdb.base/solib-search-lib1.c:30
#5  0x0000555555555156 in main () at /...solib-search.c:23
(gdb) PASS: gdb.base/solib-search.exp: backtrace (with right libs) (data collection)
PASS: gdb.base/solib-search.exp: backtrace (with right libs)

In one case the backtrace is correct and the other it
is wrong on Intel.  This is due to the fact that the ARRAY_SIZE caused
the dynamic linker to move the library function addresses around.  I
believe it has to do with the default size of the data and code
sections used by the dynamic linker.

So without the patch the backtrace on PowerPC looks like:

 backtrace
#0  break_here () at /.../solib-search.c:30
#1  0x00007ffff7f007f4 in lib2_func4 () at /.../solib-search-lib2.c:49
#2  0x00007ffff7f307f4 in lib1_func3 () at /.../solib-search-lib1.c:49
#3  0x00007ffff7f007ac in lib2_func2 () at /.../solib-search-lib2.c:30
#4  0x00007ffff7f307ac in lib1_func1 () at /.../solib-search-lib1.c:30
#5  0x000000001000074c in main () at /.../solib-search.c:23

for both the good and bad libraries.

The patch fixes defining RIGHT in solib-search-lib1.c and solib-search-
lib2.c.  Note, without the patch the lib1_spacer and lib2_spacer
functions do not show up in the object dump of the Intel or Powerpc
libraries as it should.  The patch fixes that by making sure RIGHT gets
defined.

Now with the patch the backtrace for the bad library on PowerPC looks
like:

backtrace
#0  break_here () at /.../solib-search.c:30
#1  0x00007ffff7f0083c in __glink_PLTresolve () from /.../solib-search-lib2.so
Backtrace stopped: frame did not save the PC

And the backtrace for the good libraries on PowerPC looks like:

backtrace
#0  break_here () at /.../solib-search.c:30
#1  0x00007ffff7f0083c in lib2_func4 () at /.../solib-search-lib2.c:49
#2  0x00007ffff7f3083c in lib1_func3 () at /.../solib-search-lib1.c:49
#3  0x00007ffff7f007cc in lib2_func2 () at /.../solib-search-lib2.c:30
#4  0x00007ffff7f307cc in lib1_func1 () at /.../solib-search-lib1.c:30
#5  0x000000001000074c in main () at /.../solib-search.c:23
(gdb) PASS: gdb.base/solib-search.exp: backtrace (with right libs) (data collection)
PASS: gdb.base/solib-search.exp: backtrace (with right libs)

The issue then is on Power where the ARRAY_SIZE of 1 versus 8192 is not
sufficient to cause the dymanic linker to allocate the libraries at
different addresses.  I don't claim to understand the specifics of how
the dynamic linker works and what the default size is for the data and
code sections are.  My guess is by default PowerPC allocates a larger
data size by default, which is large enough to hold array[8192].  The
default size of the data section allocated by the dynamic linker on
Intel is not large enough to hold array[8192] thus causing the code
section on Intel to have to move when the large array is defined.

Note on PowerPC, if you make ARRAY_SIZE big enough, then you will cause
the library addresses to occur at different addresses as the larger
data section forces the code section to a different address.  That was
actually my original fix for the program until I spoke with Doug Evans
who originally wrote the test.  Doug noticed that RIGHT was not getting
defined as he originally intended in the test.

With the patch to fix the definition of RIGHT, PowerPC has a bad and a
good backtrace because the address of lib1_func3 and lib2_func4 both
move because lib1_spacer and lib2_spacer are now defined
before lib1_func3 and lib2_func4.

Without the patch, the lib1_spacer and lib2_spacer function doesn't show
up in the binary for the correct or incorrect library on Intel or PowerPC.
With the patch, RIGHT gets defined as originally intended for the test on
both architectures and lib1_spacer and lib2_spacer function show up in the
binaries on both architectures changing the other function addresses as
intended thus causing the test work as intended on PowerPC.

2 years agogdb/dwarf: remove line_header::header_length field
Simon Marchi [Tue, 12 Apr 2022 19:36:16 +0000 (15:36 -0400)]
gdb/dwarf: remove line_header::header_length field

This can be a local in dwarf_decode_line_header.

Change-Id: I2ecf4616d1a3197bd1e81ded9f999a2da9a685af

2 years agogdb/dwarf: remove line_header::total_length field
Simon Marchi [Tue, 12 Apr 2022 19:31:24 +0000 (15:31 -0400)]
gdb/dwarf: remove line_header::total_length field

This doesn' have to be a field, it can simply be a local variable in
dwarf_decode_line_header.  Name the local variable "unit_length", since
that's what the field in called in DWARF 4 and 5.  It's always easier to
follow the code with the standard on the side when we use the same
terminology.

Change-Id: I3ad1022afd9410b193ea11b9b5437686c1e4e633

2 years agogdb/testsuite: fix "set temporary breakpoint" DUPLICATEs
Simon Marchi [Thu, 21 Apr 2022 19:05:32 +0000 (15:05 -0400)]
gdb/testsuite: fix "set temporary breakpoint" DUPLICATEs

Commit c67f4e538 ("gdb/testsuite: make gdb.ada/mi_prot.exp stop at
expected location") introduced some DUPLICATEs in MI tests using
mi_continue_to_line, for example:

    DUPLICATE: gdb.ada/mi_ref_changeable.exp: mi_continue_to_line: set temporary breakpoint

These test names were previously differentiated by the location passed
to mi_continue_to_line.  Since the location can contain a path, that
commit removed the location from the test name, in favor of a hardcoded
string "set temporary breakpoint", hence removing the differentiator.

mi_continue_to_line receives a "test" parameter, containing a test
name.  Add a "with_test_prefix" with that name, so that all tests
recorded during mi_continue_to_line have this in their name.

mi_continue_to_line passes that "test" string to mi_get_stop_line, that
is a bit superfluous.  mi_get_stop_line only uses that string in case of
failures (it doesn't record a pass if everything goes fine).  Since it's
not crucial, just remove it, and adjust all callers.

Adjust three gdb.mi/mi-var-*.exp tests to use prefixes to differentiate
the multiple calls to mi_run_inline_test (which calls
mi_continue_to_line).

Change-Id: I511c6caa70499f8657b1cde37d71068d74d56a74

2 years agoAlways use dwarf2_initialize_objfile
Tom Tromey [Tue, 19 Apr 2022 17:32:04 +0000 (11:32 -0600)]
Always use dwarf2_initialize_objfile

Internally we noticed that some tests would fail like so on Windows:

warning: Section .debug_aranges in [...] has duplicate debug_info_offset 0x0, ignoring .debug_aranges.

Debugging showed that, in fact, a second CU was being created at this
offset.  We tracked this down to the fact that, while the ELF reader
is careful to re-use the per-BFD data, other readers are not, and
could re-read the DWARF data multiple times.

However, since the change to allow an objfile to have multiple "quick
symbol" implementations, there's no reason for this approach -- it's
safe and easy for all symbol readers to reuse the per-BFD data when
reading DWARF.

This patch implements this idea, simplifying dwarf2_build_psymtabs and
making it private, and then switching to dwarf2_initialize_objfile as
the sole way to start the DWARF reader.

Note that, while I think the call to dwarf2_build_frame_info in
machoread.c is also obsolete, I haven't attempted to remove it here.

2 years agogdb: fix 'remote show FOO-packet' aliases
Andrew Burgess [Thu, 21 Apr 2022 10:16:18 +0000 (11:16 +0100)]
gdb: fix 'remote show FOO-packet' aliases

The following behaviour was observed in GDB:

  (gdb) show remote X-packet
  Support for the `p' packet is auto-detected, currently unknown.

Note the message mentions the 'p' packet.  This is a regression since
this commit:

  commit 8579fd136a614985bd27f20539c7bb7c5a51287d
  Date:   Mon Nov 8 14:58:46 2021 +0000

      gdb/gdbsupport: make xstrprintf and xstrvprintf return a unique_ptr

Before this commit the behaviour was:

  (gdb) show remote X-packet
  Support for the `X' packet is auto-detected, currently unknown.

The problem was caused by a failed attempt to ensure that some
allocated strings were deleted when GDB exits.  The code in the above
commit attempted to make use of 'static' to solve this problem,
however, the solution was just wrong.

In this new commit I instead allocate a static vector into which all
the allocated strings are stored, this ensures the strings are
released when GDB exits (which makes output from tools like valgrind
cleaner), but each string within the vector can be unique, which fixes
the regression.

2 years agogdbsupport: add path_join function
Simon Marchi [Wed, 20 Apr 2022 21:03:25 +0000 (17:03 -0400)]
gdbsupport: add path_join function

In this review [1], Eli pointed out that we should be careful when
concatenating file names to avoid duplicated slashes.  On Windows, a
double slash at the beginning of a file path has a special meaning.  So
naively concatenating "/"  and "foo/bar" would give "//foo/bar", which
would not give the desired results.  We already have a few spots doing:

  if (first_path ends with a slash)
    path = first_path + second_path
  else
    path = first_path + slash + second_path

In general, I think it's nice to avoid superfluous slashes in file
paths, since they might end up visible to the user and look a bit
unprofessional.

Introduce the path_join function that can be used to join multiple path
components together (along with unit tests).

I initially wanted to make it possible to join two absolute paths, to
support the use case of prepending a sysroot path to a target file path,
or the prepending the debug-file-directory to a target file path.  But
the code in solib_find_1 shows that it is more complex than this anyway
(for example, when the right hand side is a Windows path with a drive
letter).  So I don't think we need to support that case in path_join.
That also keeps the implementation simpler.

Change a few spots to use path_join to show how it can be used.  I
believe that all the spots I changed are guarded by some checks that
ensure the right hand side operand is not an absolute path.

Regression-tested on Ubuntu 18.04.  Built-tested on Windows, and I also
ran the new unit-test there.

[1] https://sourceware.org/pipermail/gdb-patches/2022-April/187559.html

Change-Id: I0df889f7e3f644e045f42ff429277b732eb6c752

2 years agogdb_spawn_attach_cmdline: use unsupported instead of untested
Lancelot SIX [Thu, 21 Apr 2022 08:28:21 +0000 (09:28 +0100)]
gdb_spawn_attach_cmdline: use unsupported instead of untested

In a previous commit (b750766ac96: gdb/testsuite: Introduce and use
gdb_spawn_attach_cmdline), if gdb_spawn_attach_cmdline cannot have GDB
attach to the process because of ptrace restrictions (operation not
permitted), the proc issues UNTESTED.  This should really be
UNSUPPORTED, as it is done in gdb_attach.

This patch fixes this oversight.

Change-Id: Ib87e33b9230f3fa7a85e06220ef4c63814b71f7d

2 years agogdb/testsuite: add binary testcases to py-format-string.exp
Enze Li [Sat, 16 Apr 2022 07:36:29 +0000 (15:36 +0800)]
gdb/testsuite: add binary testcases to py-format-string.exp

We currently only test decimal and hexadecimal for the
gdb.Value.format_string() interface, this patch adds testcases for
binary format.

Tested on x86_64 openSUSE Tumbleweed(VERSION_ID="20220413").

2 years agogdb.debuginfod/fetch_src_and_symbols.exp: Fix "notice empty URL" test
Pedro Alves [Thu, 21 Apr 2022 12:35:09 +0000 (13:35 +0100)]
gdb.debuginfod/fetch_src_and_symbols.exp: Fix "notice empty URL" test

The gdb_test_multiple pattern for the "notice empty URL" test in
gdb.debuginfod/fetch_src_and_symbols.exp misses expecting the prompt.
Fix it by using -re -wrap.

Also, by using "confirm off", the message GDB prints if Debuginfod
downloading is available doesn't contain "Enable debuginfod" any
longer.  E.g.:

~~~
  (gdb) file testsuite/outputs/gdb.debuginfod/fetch_src_and_symbols/fetch_src_and_symbols
  Reading symbols from testsuite/outputs/gdb.debuginfod/fetch_src_and_symbols/fetch_src_and_symbols...

  This GDB supports auto-downloading debuginfo from the following URLs:
    <http://localhost:123>
  Enable debuginfod for this session? (y or [n])
~~~

~~~
  (gdb) with confirm off -- file testsuite/outputs/gdb.debuginfod/fetch_src_and_symbols/fetch_src_and_symbols
  Reading symbols from testsuite/outputs/gdb.debuginfod/fetch_src_and_symbols/fetch_src_and_symbols...

  This GDB supports auto-downloading debuginfo from the following URLs:
    <http://127.0.0.1:8000>
    <127.0.0.1:8000>
  Debuginfod has been disabled.
  To make this setting permanent, add 'set debuginfod enabled off' to .gdbinit.
  (No debugging symbols found in testsuite/outputs/gdb.debuginfod/fetch_src_and_symbols/fetch_src_and_symbols)
  (gdb)
~~~

I handled that correctly in the other tests that use test_urls, but
had forgotten to update the "notice empty URL" one.

Change-Id: I00040c83466e1494b3875574eb009c571a1504bf

2 years agoprune .note.GNU-stack warning from testsuite
Alan Modra [Wed, 20 Apr 2022 23:19:30 +0000 (08:49 +0930)]
prune .note.GNU-stack warning from testsuite

binutils/
* testsuite/lib/binutils-common.exp (prune_warnings_extra): Remove
.note.GNU-stack warning.
(run_dump_test): Call prune_warnings for ld and objcopy output.
ld/
* testsuite/ld-elf/elf.exp: Disable prune_warnings_extra temporarily
around test for absent .note.GNU-stack
* testsuite/ld-cris/globsymw2.s,
* testsuite/ld-cris/warn3.d: Modify "is not implemented" message
to avoid dejagnu prune_warnings.

2 years agold testsuite xcoff XPASS
Alan Modra [Wed, 20 Apr 2022 23:20:02 +0000 (08:50 +0930)]
ld testsuite xcoff XPASS

* testsuite/ld-scripts/defined5.d: Don't xfail xcoff targets.

2 years agoDelete unused COFF gas macro
Alan Modra [Fri, 15 Apr 2022 23:15:42 +0000 (08:45 +0930)]
Delete unused COFF gas macro

* config/obj-coff.h (sy_obj): Don't define.
(OBJ_SYMFIELD_TYPE): Revise comments.

2 years agoAutomatic date update in version.in
GDB Administrator [Thu, 21 Apr 2022 00:00:13 +0000 (00:00 +0000)]
Automatic date update in version.in

2 years agogdb/debuginfod: Prevent out_of_range exception
Aaron Merey [Fri, 8 Apr 2022 22:50:56 +0000 (18:50 -0400)]
gdb/debuginfod: Prevent out_of_range exception

Trailing whitespace in the string of debuginfod URLs causes an
out_of_range exception during the printing of URLs for the first
use notice.

To fix this, stop printing URLs when the substring to be printed
consists only of whitespace.

Also add first use notice testcases.

Co-Authored-By: Pedro Alves <pedro@palves.net>
2 years agogdb/testsuite: Introduce and use gdb_spawn_attach_cmdline
Lancelot SIX [Thu, 14 Apr 2022 09:41:48 +0000 (10:41 +0100)]
gdb/testsuite: Introduce and use gdb_spawn_attach_cmdline

Following a7e6a19e87f3d719ea23c65b580a6d9bca4ccab3 "gdb: testsuite: add
new gdb_attach to check "attach" command", this commit proposes to
introduce the gdb_spawn_attach_cmdline helper and use it in
gdb.base/attach.exp.

This helper starts GDB and adds the "--pid=$PID" argument.

Also note that both the original and new implementation use
gdb_spawn_with_cmdline_opts, which in the end uses default_gdb_spawn.
This makes sure that we use $INTERNAL_GDBFLAGS, which by default already
contain "-iex \"set height 0\" -iex \"set width 0\"".  To avoid
repetition of those arguments, gdb_spawn_attach_cmdline does not repeat
those arguments.

To maintain a behavior similat to what gdb.base/attach.exp used to do,
gdb_spawn_attach_cmdline keeps the -quiet flag.

Tested on x86_64-gnu-linux

Change-Id: I1fdcdb71c86d9c5d34bb28fc86fac68bcec37358

2 years agoReplace symbol_symtab with symbol::symtab
Tom Tromey [Mon, 18 Apr 2022 02:00:59 +0000 (20:00 -0600)]
Replace symbol_symtab with symbol::symtab

This turns symbol_symtab into a method on symbol.  It also replaces
symbol_set_symtab with a method.

2 years agoReplace symbol_arch with symbol::arch
Tom Tromey [Mon, 18 Apr 2022 01:47:22 +0000 (19:47 -0600)]
Replace symbol_arch with symbol::arch

This turns symbol_arch into a method on symbol.

2 years agoReplace symbol_objfile with symbol::objfile
Tom Tromey [Mon, 18 Apr 2022 01:44:20 +0000 (19:44 -0600)]
Replace symbol_objfile with symbol::objfile

This turns symbol_objfile into a method on symbol.

2 years agoRemove symbol::aclass_index
Tom Tromey [Sat, 16 Apr 2022 18:49:50 +0000 (12:49 -0600)]
Remove symbol::aclass_index

Symbols have an aclass_index method, but this isn't needed, because
the aclass index isn't useful outside of the symbol implementation.

2 years agoUse array_view for symbol_impls
Tom Tromey [Sat, 16 Apr 2022 18:36:47 +0000 (12:36 -0600)]
Use array_view for symbol_impls

It seemed to me that using array_view for symbol_impls would give a
bit more error checking, at least when gdb is built in libstdc++ debug
mode.

2 years agoAdd accessors for symbol's artificial field
Tom Tromey [Sat, 16 Apr 2022 18:33:56 +0000 (12:33 -0600)]
Add accessors for symbol's artificial field

For a series I'm experimenting with, it was handy to hide a symbol's
"artificial" field behind accessors.  This patch is the result.

2 years agoUnify the DWARF index holders
Tom Tromey [Tue, 23 Nov 2021 00:05:55 +0000 (17:05 -0700)]
Unify the DWARF index holders

The dwarf2_per_bfd object has a separate field for each possible kind
of index.  Until an earlier patch in this series, two of these were
even derived from a common base class, but still had separate slots.
This patch unifies all the index fields using the common base class
that was introduced earlier in this series.  This makes it more
obvious that only a single index can be active at a time, and also
removes some code from dwarf2_initialize_objfile.

2 years agoAdd an ad hoc version check to dwarf_scanner_base
Tom Tromey [Mon, 22 Nov 2021 23:53:34 +0000 (16:53 -0700)]
Add an ad hoc version check to dwarf_scanner_base

Some generic code in the DWARF reader has a special case for older
versions of .gdb_index.  This patch adds an ad hoc version check
method so that these spots can work without specific knowledge of
which index is in use.

2 years agoSimplify version check in dw2_symtab_iter_next
Tom Tromey [Mon, 22 Nov 2021 23:50:46 +0000 (16:50 -0700)]
Simplify version check in dw2_symtab_iter_next

This simplifies the index versio check in dw2_symtab_iter_next, by
passing a reference to the index object to this function.  This avoids
an indirection via the per_bfd object.

2 years agoIntroduce and use dwarf_scanner_base
Tom Tromey [Mon, 22 Nov 2021 23:43:47 +0000 (16:43 -0700)]
Introduce and use dwarf_scanner_base

This introduces dwarf_scanner_base, a base class for all the index
readers in the DWARF code.  Then, it changes both mapped_index_base
and cooked_index_vector to derive from this new base class.

2 years agoIntroduce readnow_functions
Tom Tromey [Tue, 30 Mar 2021 02:14:30 +0000 (20:14 -0600)]
Introduce readnow_functions

This introduces readnow_functions, a new subclass of
dwarf2_base_index_functions, and changes the DWARF reader to use it.
This lets us drop the "index is NULL" hack from the gdb index code.

2 years agoRemove some "OBJF_READNOW" code from dwarf2_debug_names_index
Tom Tromey [Tue, 30 Mar 2021 00:31:31 +0000 (18:31 -0600)]
Remove some "OBJF_READNOW" code from dwarf2_debug_names_index

The dwarf2_debug_names_index code treats a NULL debug_names_table as
if it were from OBJF_READNOW.  However, this trick is only done for
gdb_index, never for debug_names -- see dwarf2_initialize_objfile.

2 years agoLet mapped index classes create the quick_symbol_functions object
Tom Tromey [Mon, 29 Mar 2021 23:58:21 +0000 (17:58 -0600)]
Let mapped index classes create the quick_symbol_functions object

This changes the mapped index classes to create the
quick_symbol_functions objects.  This is a step toward having a more
abstract interface to mapped indices.

2 years agoGive mapped_index_base a virtual destructor
Tom Tromey [Mon, 29 Mar 2021 23:44:57 +0000 (17:44 -0600)]
Give mapped_index_base a virtual destructor

This changes mapped_index_base to have a virtual destructor, so it can
be destroyed via its base class.

2 years agoMove mapped_index_base to new header file
Tom Tromey [Mon, 29 Mar 2021 23:42:36 +0000 (17:42 -0600)]
Move mapped_index_base to new header file

This moves mapped_index_base and the helper struct name_component to a
new header file in gdb/dwarf2/.

2 years agox86: reject all invalid SAE variants
Jan Beulich [Wed, 20 Apr 2022 14:56:05 +0000 (16:56 +0200)]
x86: reject all invalid SAE variants

So far an SAE-only specifier was accepted for static-rounding insns,
while SAE-only insns didn't accept static rounding specifiers. If
anything it would make sense the other way around, allowing SAE-only
insns to have the (ignored) rounding mode specified individually rather
than globally via -mevexrcig=. But for now make things match the SDM.

2 years agoRe: xcoff: implement linker relaxation
Alan Modra [Wed, 20 Apr 2022 14:26:08 +0000 (23:56 +0930)]
Re: xcoff: implement linker relaxation

* xcofflink.c (xcoff_stub_csect_name): Increase buffer size.
(xcoff_stub_get_csect_in_range, xcoff_build_one_stub): Whitespace.
(bfd_xcoff_size_stubs): Cast PRIx64 arg to required type.
Don't use freed stub_name.

2 years agoRevert "as: Reject unknown -gXXX option" testsuite
Alan Modra [Wed, 20 Apr 2022 13:54:46 +0000 (23:24 +0930)]
Revert "as: Reject unknown -gXXX option" testsuite

This reverts the test committed as part of 6ea673e2d6.

2 years agoxcoff: implement linker relaxation
Cl?ment Chigot [Wed, 20 Apr 2022 14:11:47 +0000 (15:11 +0100)]
xcoff: implement linker relaxation

bfd/ChangeLog:

* coff-rs6000.c (xcoff_reloc_type_noop): Add info argument.
(xcoff_reloc_type_fail): Likewise.
(xcoff_reloc_type_pos): Likewise.
(xcoff_reloc_type_neg): Likewise.
(xcoff_reloc_type_rel): Likewise.
(xcoff_reloc_type_toc): Likewise.
(xcoff_reloc_type_ba): Likewise.
(xcoff_reloc_type_crel): Likewise.
(xcoff_reloc_type_tls): Likewise.
(xcoff_reloc_type_br): Add stub handler.
(xcoff_ppc_relocate_section): Add info to
xcoff_calculate_relocation.
(xcoff_stub_indirect_call_code): New constant.
(xcoff_stub_shared_call_code): Likewise.
(bfd_xcoff_backend_data): Add stub code fields.
(bfd_pmac_xcoff_backend_data): Likewise.
* coff64-rs6000.c (xcoff64_reloc_type_br): Add stub handler.
(xcoff64_ppc_relocate_section): Add info to
xcoff64_calculate_relocation.
(xcoff64_stub_indirect_call_code): New constant.
(xcoff64_stub_shared_call_code): Likewise.
(bfd_xcoff_backend_data): Add stub code fields.
(bfd_xcoff_aix5_backend_data): Likewise.
* libxcoff.h (struct xcoff_backend_data_rec): Add stub fields.
(bfd_xcoff_stub_indirect_call_code): New define.
(bfd_xcoff_stub_indirect_call_size): New define.
(bfd_xcoff_stub_shared_call_code): New define.
(bfd_xcoff_stub_shared_call_size): New define.
(xcoff_reloc_function): Add info argument.
(enum xcoff_stub_type): New enum.
(struct xcoff_stub_hash_entry): New structure.
* xcofflink.c (struct xcoff_link_hash_table): Add stub hash
table and params fields.
(xcoff_stub_hash_entry): New define.
(xcoff_stub_hash_lookup): New define.
(stub_hash_newfunc): New function.
(_bfd_xcoff_bfd_link_hash_table_free): Free the new stub hash
table.
(_bfd_xcoff_bfd_link_hash_table_create): Create the new stub
hash table.
(xcoff_link_add_symbols): Save rawsize for XTY_SD.
(bfd_xcoff_link_init): New function.
(xcoff_stub_csect_name): New function.
(xcoff_stub_get_csect_in_range): New function.
(xcoff_stub_name): New function.
(bfd_xcoff_get_stub_entry): New function.
(bfd_xcoff_type_of_stub): New function.
(xcoff_add_stub): New function.
(xcoff_build_one_stub): New function.
(bfd_xcoff_size_stubs): New function.
(bfd_xcoff_build_stubs): New function.
(xcoff_stub_create_relocations): New function.
(xcoff_link_input_bfd): Adapt relocations to stub.
(xcoff_write_global_symbol): Adapt to new TOC entries generated
for stubs.
(_bfd_xcoff_bfd_final_link): Handle stub file.
* xcofflink.h (struct bfd_xcoff_link_params): New structure.

ld/ChangeLog:

* emultempl/aix.em (params): New variable.
(stub_file): New variable.
(xcoff_add_stub_section): New function.
(xcoff_layout_sections_again): New function
(hook_in_stub): New function.
(_after_allocation): Add stub creation.
(_create_output_section_statements): Allocate stub file and
pass params to backend.

2 years agoStubs (added in a later patch) will generate new .loader symbols, once the allocation...
Cl?ment Chigot [Wed, 20 Apr 2022 14:07:50 +0000 (15:07 +0100)]
Stubs (added in a later patch) will generate new .loader symbols, once the allocations have been done. Thus, the .loader section cannot be layout before that.

bfd/ChangeLog:

* coff-rs6000.c (_bfd_xcoff_put_ldsymbol_name): Write len in
  ldinfo->strings instead of directly in the output_bfd.
* coff64-rs6000.c (_bfd_xcoff64_put_ldsymbol_name): Likewise.
* xcofflink.c (struct xcoff_link_hash_table): Remove ldrel_count
  field. Add ldinfo field.
(xcoff_mark_symbol): Adjust to new ldinfo field.
(xcoff_mark): Likewise.
(bfd_xcoff_link_count_reloc): Likewise.
(xcoff_build_loader_section): Split into two functions: one that
build the loader section (this function) and one that only size
it...
(xcoff_size_loader_section): ... (this function).
(bfd_xcoff_size_dynamic_sections): Adapt to new ldinfo field.
Move the part where the dynamic sections are build to ...
(bfd_xcoff_build_dynamic_sections): ... this function.
* xcofflink.h: Add bfd_xcoff_build_dynamic_sections prototype.

include/ChangeLog:

* coff/xcoff.h (struct xcoff_loader_info): Add ldrel_count and
libpath fields.

ld/ChangeLog:

* emultempl/aix.em (_after_allocation): New function.

2 years agoUse symbol_symtab accessor in compile-object-load.c
Tom Tromey [Sat, 16 Apr 2022 20:19:18 +0000 (14:19 -0600)]
Use symbol_symtab accessor in compile-object-load.c

I noticed that compile-object-load.c directly references owner.symtab
of a symbol.  However, I think it's better for all users to call
symbol_symtab.  This patch makes this change.

2 years agoAdd linker warning for when it creates an executable stack.
Nick Clifton [Wed, 20 Apr 2022 12:37:51 +0000 (13:37 +0100)]
Add linker warning for when it creates an executable stack.

   PR 29072

2 years agoMicro-optimize cooked_index_entry::full_name
Tom Tromey [Wed, 20 Apr 2022 05:44:50 +0000 (23:44 -0600)]
Micro-optimize cooked_index_entry::full_name

I noticed that cooked_index_entry::full_name can return the canonical
string when there is no parent entry.

Regression tested on x86-64 Fedora 34.

2 years agogdb: LoongArch: Implement loongarch_scan_prologue()
Tiezhu Yang [Wed, 20 Apr 2022 09:48:53 +0000 (17:48 +0800)]
gdb: LoongArch: Implement loongarch_scan_prologue()

If can't determine prologue from the symbol table, need to examine
instructions. Implement loongarch_scan_prologue() to analyze the
function prologue from START_PC to LIMIT_PC, return the address of
the first instruction past the prologue.

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
2 years agoAutomatic date update in version.in
GDB Administrator [Wed, 20 Apr 2022 00:00:11 +0000 (00:00 +0000)]
Automatic date update in version.in

2 years agoas: Reject unknown -gXXX option
H.J. Lu [Sat, 16 Apr 2022 17:46:05 +0000 (10:46 -0700)]
as: Reject unknown -gXXX option

* as.c (parse_args): Reject unknown -gXXX option.
* testsuite/gas/all/empty.s: New file.
* testsuite/gas/all/pr29067.d: Likewise.
* testsuite/gas/all/pr29067.err: Likewise.
* testsuite/gas/all/gas.exp: Run pr29067.

2 years agogdb/selftest-arch: Make register_test_foreach_arch generate arch tests lazily
Lancelot SIX [Tue, 22 Mar 2022 14:02:54 +0000 (10:02 -0400)]
gdb/selftest-arch: Make register_test_foreach_arch generate arch tests lazily

The register_test_foreach_arch is used to instantiate a given selftest
for all architectures supported by GDB.  It is used in many _initialize_*
functions (under initialize_all_files, called by gdb_init).

Because the call is done during GDB's initialization, and because there
is no guaranty about the order in which all the _initialize_* functions
are executed, when register_test_foreach_arch is called, GDB is not
fully initialized.  Specifically, when a particular initialize function
is executed, only the architectures registered at that point are listed
by gdbarch_printable_names.

As a consequence, the list of selftest effectively executed depends on
the order the _initialize_* functions are called.  This can be observed
with the following:

    $ ./gdb/gdb \
        -data-directory ./gdb/data-directory \
        -quiet -batch -ex "maint selftest" 2>&1 \
        | grep -E "Ran [0-9]+ unit tests"
    Ran 145 unit tests, 0 failed
    $ GDB_REVERSE_INIT_FUNCTIONS=1 ./gdb/gdb \
        -data-directory ./gdb/data-directory \
        -quiet -batch -ex "maint selftest" 2>&1 \
        | grep -E "Ran [0-9]+ unit tests"
    Ran 82 unit tests, 0 failed

To fix this, make register_test_foreach_arch register a lazy selftest
generator.  This way when the test generator is eventually executed, all
architectures are registered and we do not have a dependency on the
order the initialize functions are executed in.

Tested on x86_64-linux

Change-Id: I88eefebf7d372ad672f42d3a103e89354bc8a925

2 years agogdbsupport/selftest: Allow lazy registration
Lancelot SIX [Tue, 22 Mar 2022 12:09:40 +0000 (08:09 -0400)]
gdbsupport/selftest: Allow lazy registration

This patch adds a way to delay the registration of tests until the
latest possible moment.  This is intended for situations where GDB needs
to be fully initialized in order to decide if a particular selftest can
be executed or not.

This mechanism will be used in the next patch.

Change-Id: I7f6b061f4c0a6832226c7080ab4e3a2523e1b0b0

2 years agogdbsupport/selftest: Replace for_each_selftest with an iterator_range
Lancelot SIX [Wed, 23 Mar 2022 15:29:53 +0000 (15:29 +0000)]
gdbsupport/selftest: Replace for_each_selftest with an iterator_range

Remove the callback-based selftests::for_each_selftest function and use
an iterator_range instead.

Also use this iterator range in run_tests so all iterations over the
selftests are done in a consistent way.  This will become useful in a
later commit.

Change-Id: I0b3a5349a7987fbcb0071f11c394e353df986583

2 years agox86: don't mistake ordinary immediates for SAE / rounding control
Jan Beulich [Tue, 19 Apr 2022 07:26:17 +0000 (09:26 +0200)]
x86: don't mistake ordinary immediates for SAE / rounding control

The way SAE templates are constructed was always puzzling me (including
the need for separate templates in the first place), and expressing the
extzra attribute via Imm8 actually has a bad effect: Ordinary immediates
would also be accepted, leading to an extra byte being added after the
instruction (i.e. generating bad code). Before re-working this (in
particular to accept proper Intel syntax there), fix the immediate issue
by adding the so far missing check.

2 years agox86: VCMPSH is Evex.LLIG
Jan Beulich [Tue, 19 Apr 2022 07:25:25 +0000 (09:25 +0200)]
x86: VCMPSH is Evex.LLIG

These were mistakenly flagged as Evex.128. Getting the LLIG status right
for insns allowing for SAE is a prereq for planned further work.

2 years agox86: drop stray CheckRegSize from VFPCLASSPH
Jan Beulich [Tue, 19 Apr 2022 07:24:53 +0000 (09:24 +0200)]
x86: drop stray CheckRegSize from VFPCLASSPH

Like VFPCLASSP{S,D} it has only a single operand allowing multiple
sizes, hence there are no pairs of operands to check for consistent
size.

2 years agox86/Intel: test non-legacy VCVT{,U}SI2SH insn forms
Jan Beulich [Tue, 19 Apr 2022 07:24:24 +0000 (09:24 +0200)]
x86/Intel: test non-legacy VCVT{,U}SI2SH insn forms

For an unclear reason corresponding AVX512F tests were apparently not
cloned or used as reference here, and instead the bogus legacy forms of
the insns (with the embedded rounding specifier not last) were used.

2 years agox86: correct and simplify NOP disassembly
Jan Beulich [Tue, 19 Apr 2022 07:23:49 +0000 (09:23 +0200)]
x86: correct and simplify NOP disassembly

It's not just REX.W which is ignored with opcode 0x90. The same goes for
REX.R and REX.X as well as empty REX. None of these are forms of
"xchg %eax,%eax" (which would mean zero-extending %eax to %rax), so they
also shouldn't be disassembled this way.

While there simplify things: A single hook function suffices, thus
making it unnecessary to keep two expressions in sync. And checking
ins->address_mode for mode_64bit also is unnecessary, as "rex" can be
non-zero only in that case anyway.

2 years agoAutomatic date update in version.in
GDB Administrator [Tue, 19 Apr 2022 00:00:19 +0000 (00:00 +0000)]
Automatic date update in version.in

2 years agogdb/testsuite/dwarf: don't automatically add directory and file entry for DWARF 5
Simon Marchi [Thu, 7 Apr 2022 01:51:56 +0000 (21:51 -0400)]
gdb/testsuite/dwarf: don't automatically add directory and file entry for DWARF 5

To support DWARF 5 in the DWARF assembler line tables, we currently copy
the first user-provided directory and the first user-provided files and
make them elements at indices 0 in the directory and file name tables.
That was a sufficient behavior at the time (see commit 44fda089397a
("[gdb/testsuite] Support .debug_line v5 in dwarf assembler")), but in
the following patches, I would need to have finer grained control on
what is generated exactly.  For example, I'd like to generate a DWARF 5 line
table with just a single file and a single directory.

Get rid of this behavior, and implement what is suggested in
44fda089397a: make include_dir return the directory index that can be
used to refer to that directory entry (based on the DWARF version), and
use it afterwards.

Adjust dw2-lines.exp and dw2-prologue-end.exp accordingly.  Their produced
DWARF5 binaries will change a bit, in that they will now have a single
directory and file, where they had two before.  But it doesn't change
the expected GDB behavior.

Change-Id: I5459b16ac9b7f28c34c9693c35c9afd2ebb3aa3b

2 years agogdb: use gdb_tilde_expand instead of gdb_tilde_expand_up in source_script_with_search
Simon Marchi [Thu, 14 Apr 2022 00:12:37 +0000 (20:12 -0400)]
gdb: use gdb_tilde_expand instead of gdb_tilde_expand_up in source_script_with_search

Since this is the latest use of gdb_tilde_expand_up, remove it.

Change-Id: I964c812ce55fe087876abf91e7a3577ad79c0425