]> git.ipfire.org Git - thirdparty/binutils-gdb.git/log
thirdparty/binutils-gdb.git
2 years agoAlways use std::function for self-tests
Tom Tromey [Thu, 23 Sep 2021 19:09:48 +0000 (13:09 -0600)] 
Always use std::function for self-tests

Now that there is a register_test variant that accepts std::function,
it seems to me that the 'selftest' struct and accompanying code is
obsolete -- simply always using std::function is simpler.  This patch
implements this idea.

2 years agoFix PR gdb/17917 Lookup build-id in remote binaries
Daniel Black [Mon, 18 Oct 2021 06:06:47 +0000 (17:06 +1100)] 
Fix PR gdb/17917 Lookup build-id in remote binaries

GDB doesn't support loading debug files using build-id from remote
target filesystems.

This is the case when gdbserver attached to a process and a gdb target
remote occurs over tcp.

With this change we make build-id lookups possible:

    (gdb) show debug-file-directory
    The directory where separate debug symbols are searched for is "/usr/local/lib/debug".
    (gdb) set debug-file-directory /usr/lib/debug
    (gdb) show sysroot
    The current system root is "target:".
    (gdb) target extended-remote :46615
    Remote debugging using :46615
    warning: Can not parse XML target description; XML support was disabled at compile time
    Reading /usr/sbin/mariadbd from remote target...
    warning: File transfers from remote targets can be slow. Use "set sysroot" to access files locally instead.
    Reading /usr/sbin/mariadbd from remote target...
    Reading symbols from target:/usr/sbin/mariadbd...
    Reading /usr/lib/debug/.build-id/6e/0a874dca5a7ff831396ddc0785d939a192efe3.debug from remote target...
    Reading /usr/lib/debug/.build-id/6e/0a874dca5a7ff831396ddc0785d939a192efe3.debug from remote target...
    Reading symbols from target:/usr/lib/debug/.build-id/6e/0a874dca5a7ff831396ddc0785d939a192efe3.debug...
    Reading /lib/x86_64-linux-gnu/libpcre2-8.so.0 from remote target...
    ...

Before this change, the lookups would have been (GNU gdb (GDB) Fedora 10.2-3.fc34):

    (gdb) target extended-remote :46615
    Remote debugging using :46615
    Reading /usr/sbin/mariadbd from remote target...
    warning: File transfers from remote targets can be slow. Use "set sysroot" to access files locally instead.
    Reading /usr/sbin/mariadbd from remote target...
    Reading symbols from target:/usr/sbin/mariadbd...
    Reading /usr/sbin/0a874dca5a7ff831396ddc0785d939a192efe3.debug from remote target...
    Reading /usr/sbin/.debug/0a874dca5a7ff831396ddc0785d939a192efe3.debug from remote target...
    Reading /usr/lib/debug//usr/sbin/0a874dca5a7ff831396ddc0785d939a192efe3.debug from remote target...
    Reading /usr/lib/debug/usr/sbin//0a874dca5a7ff831396ddc0785d939a192efe3.debug from remote target...
    Reading target:/usr/lib/debug/usr/sbin//0a874dca5a7ff831396ddc0785d939a192efe3.debug from remote target...
    Missing separate debuginfo for target:/usr/sbin/mariadbd
    Try: dnf --enablerepo='*debug*' install /usr/lib/debug/.build-id/6e/0a874dca5a7ff831396ddc0785d939a192efe3.debug
    (No debugging symbols found in target:/usr/sbin/mariadbd)

Observe it didn't look for
/usr/lib/debug/.build-id/6e/0a874dca5a7ff831396ddc0785d939a192efe3.debug
on the remote target (where it is) and expected them to be installed
locally.

As a minor optimization, this also changes the build-id lookup such that
if sysroot is empty, no second lookup of the same location is performed.

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

2 years agoFix a potential illegal memory access when testing for a special LTO symbol name.
Nick Clifton [Tue, 19 Oct 2021 15:02:49 +0000 (16:02 +0100)] 
Fix a potential illegal memory access when testing for a special LTO symbol name.

bfd * linker.c (_bfd_generic_link_add_one_symbol): Test for a NULL
name before checking to see if the symbol is __gnu_lto_slim.
* archive.c (_bfd_compute_and_write_armap): Likewise.
binutils
* nm.c (filter_symbols): Test for a NULL name before checking to
see if the symbol is __gnu_lto_slim.
* objcopy.c (filter_symbols): Likewise.

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

2 years agoCTF: incorrect underlying type setting for enumeration types
Weimin Pan [Mon, 18 Oct 2021 18:15:21 +0000 (14:15 -0400)] 
CTF: incorrect underlying type setting for enumeration types

A bug was filed against the incorrect underlying type setting for
an enumeration type, which was caused by a copy and paste error.
This patch fixes the problem by setting it by calling objfile_int_type,
which was originally dwarf2_per_objfile::int_type, with ctf_type_size bits.
Also add error checking on ctf_func_type_info call.

2 years agoAutomatic date update in version.in
GDB Administrator [Mon, 18 Oct 2021 00:00:08 +0000 (00:00 +0000)] 
Automatic date update in version.in

2 years agoPR28459, readelf issues bogus warning
Alan Modra [Sun, 17 Oct 2021 07:04:46 +0000 (17:34 +1030)] 
PR28459, readelf issues bogus warning

I'd missed the fact that the .debug_rnglists dump doesn't exactly
display the contents of the section.  Instead readelf rummages through
.debug_info looking for DW_AT_ranges entries, then displays the
entries in .debug_rnglists pointed at, sorted.  A simpler dump of the
actual section contents might be more useful and robust, but it was
likely done that way to detect overlap and holes.

Anyway, the headers in .debug_rnglists besides the first are ignored,
and limiting to the unit length of the first header fails if there is
more than one unit.

PR 28459
* dwarf.c (display_debug_ranges): Don't constrain data to length
in header.

2 years agoAutomatic date update in version.in
GDB Administrator [Sun, 17 Oct 2021 00:00:19 +0000 (00:00 +0000)] 
Automatic date update in version.in

2 years agold: Adjust pr28158.rd for glibc 2.34
H.J. Lu [Sat, 16 Oct 2021 15:12:25 +0000 (08:12 -0700)] 
ld: Adjust pr28158.rd for glibc 2.34

Adjust pr28158.rd for glibc 2.34:

$ readelf -W --dyn-syms tmpdir/pr28158

Symbol table '.dynsym' contains 4 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND
     1: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND __libc_start_main@GLIBC_2.34 (2)
     2: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND __gmon_start__
     3: 000000000040401c     4 OBJECT  GLOBAL DEFAULT   23 foo@VERS_2.0 (3)
$

vs older glibc:

$ readelf -W --dyn-syms tmpdir/pr28158

Symbol table '.dynsym' contains 4 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND
     1: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND __libc_start_main@GLIBC_2.2.5 (3)
     2: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND __gmon_start__
     3: 000000000040401c     4 OBJECT  GLOBAL DEFAULT   23 foo@VERS_2.0 (2)

$

* testsuite/ld-elf/pr28158.rd: Adjusted for glibc 2.34.

2 years agoAutomatic date update in version.in
GDB Administrator [Sat, 16 Oct 2021 00:00:15 +0000 (00:00 +0000)] 
Automatic date update in version.in

2 years agoAutomatic date update in version.in
GDB Administrator [Fri, 15 Oct 2021 00:00:12 +0000 (00:00 +0000)] 
Automatic date update in version.in

2 years agoPowerpc: Add support for openat and fstatat syscalls
Carl Love [Wed, 13 Oct 2021 20:28:48 +0000 (20:28 +0000)] 
Powerpc: Add support for openat and fstatat syscalls

[gdb] update ppc-linux-tdep.c

Add argument to ppc_canonicalize_syscall for the wordsize.
Add syscall entries for the openat and fstatat system calls.

2 years ago[gdb/testsuite] Add .debug_loc support in dwarf assembler
Tom de Vries [Thu, 14 Oct 2021 14:58:21 +0000 (16:58 +0200)] 
[gdb/testsuite] Add .debug_loc support in dwarf assembler

Add .debug_loc support in the dwarf assembler, and use it in new test-case
gdb.dwarf2/loc-sec-offset.exp (which is based on
gdb.dwarf2/loclists-sec-offset.exp).

Tested on x86_64-linux.

2 years ago[GOLD] Re: PowerPC64: Don't pretend to support multi-toc
Alan Modra [Thu, 14 Oct 2021 06:31:06 +0000 (17:01 +1030)] 
[GOLD] Re: PowerPC64: Don't pretend to support multi-toc

We can't get at section->address() until everything is laid out, so
trying to generalise the offset calculation rather than using a value
of 0x8000 (the old object->toc_base_offset()) was bound to fail.
got->g_o_t() is a little better than a hard-coded 0x8000.

* powerpc.cc (Target_powerpc::Scan::local, global): Don't use
toc_pointer() here.

2 years ago[GOLD] Two GOT sections for PowerPC64
Alan Modra [Fri, 8 Oct 2021 23:33:21 +0000 (10:03 +1030)] 
[GOLD] Two GOT sections for PowerPC64

Split .got into two piece, one with the header and entries for small
model got entries, the other with entries for medium/large model got
entries.  The idea is to better support mixed pcrel/non-pcrel code
where non-pcrel small-model .toc entries need to be within 32k of the
toc pointer.

* target.h (Target::tls_offset_for_local): Add got param.
(Target::tls_offset_for_global): Likewise.
(Target::do_tls_offset_for_local, do_tls_offset_for_global): Likewise.
* output.h (Output_data_got::Got_entry::write): Add got param.
* output.cc (Output_data_got::Got_entry::write): Likewise, pass to
tls_offset_for_local/global calls.
(Output_data_got::do_write): Adjust to suit.
* s390.cc (Target_s390::do_tls_offset_for_local): Likewise.
(Target_s390::do_tls_offset_for_global): Likewise.
* powerpc.cc (enum Got_type): Extend with small types, move from
class Target_powerpc.
(Target_powerpc::biggot_): New.
(Traget_powerpc::do_tls_offset_for_local, do_tls_offset_for_global,
got_size, got_section, got_base_offset): Handle biggot_.
(Target_powerpc::do_define_standard_symbols): Adjust.
(Target_powerpc::make_plt_section, do_finalize_sections): Likewise.
(Output_data_got_powerpc::Output_data_got_powerpc): Only make
64-bit header for small got section.
(Output_data_got_powerpc::g_o_t): Only return a result for small
got section.
(Output_data_got_powerpc::write): Only write small got section
header.
(Target_powerpc::Scan::local, global): Select small/big Got_type
and section to suit reloc.
(Target_powerpc::Relocate::relocate): Similarly.
(Sort_toc_sections): Rewrite.

2 years ago[GOLD] PowerPC64: Don't pretend to support multi-toc
Alan Modra [Tue, 12 Oct 2021 09:15:13 +0000 (19:45 +1030)] 
[GOLD] PowerPC64: Don't pretend to support multi-toc

Code in powerpc.cc is pretending to support a per-object toc pointer
value, but powerpc gold has no real support for multi-toc.  This patch
removes the pretense, tidying quite a lot in preparation for a
followup patch.  If multi-toc is ever to be supported, don't revert
this patch but start by adding object parameter to toc_pointer() and
an object to Branch_stub_key.

* powerpc.cc (Powerpc_relobj::toc_base_offset): Delete.
(Target_powerpc::toc_pointer): New function.  Use throughout.
(Target_powerpc::got_base_offset): New function.  Use throughout..
(Output_data_got_powerpc::got_base_offset): ..in place of
this.  Delete.
(Output_data_got_powerpc::Output_data_got_powerpc): Init
header_index_ to -1u for 64-bit, and make header here.
(Output_data_got_powerpc::set_final_data_size, reserve_ent): Don't
make 64-bit header here.
(Output_data_got_powerpc::g_o_t): Return toc pointer offset in
section for 64-bit.  Use throughout.
(Stub_table): Remove toc_base_off_ from Branch_stub_key, and
object param on add_long_branch_entry and find_long_branch_entry.
Adjust all uses.

2 years agoRe: s12z/disassembler: call memory_error_func when appropriate
Alan Modra [Thu, 14 Oct 2021 02:36:16 +0000 (13:06 +1030)] 
Re: s12z/disassembler: call memory_error_func when appropriate

Adjust for commit ba7c18a48457.

* testsuite/gas/s12z/truncated.d: Update expected output.

2 years agoAutomatic date update in version.in
GDB Administrator [Thu, 14 Oct 2021 00:00:12 +0000 (00:00 +0000)] 
Automatic date update in version.in

2 years ago[gdb/exp] Improve <error reading variable> message
Tom de Vries [Wed, 13 Oct 2021 19:35:49 +0000 (21:35 +0200)] 
[gdb/exp] Improve <error reading variable> message

When printing a variable x in a subroutine foo:
...
subroutine foo (x)
  integer(4) :: x (*)
  x(3) = 1
end subroutine foo
...
where x is an array with unknown bounds, we get:
...
$ gdb -q -batch outputs/gdb.fortran/array-no-bounds/array-no-bounds \
  -ex "break foo" \
  -ex run \
  -ex "print x"
Breakpoint 1 at 0x4005cf: file array-no-bounds.f90, line 18.

Breakpoint 1, foo (x=...) at array-no-bounds.f90:18
18        x(3) = 1
$1 = <error reading variable>
...

Improve the error message by printing the details of the error, such that we
have instead:
...
$1 = <error reading variable: failed to get range bounds>
...

This is a change in gdb/valprint.c, and grepping through the sources reveals
that this is a common pattern.

Tested on x86_64-linux.

2 years agoPPC fix for stfiwx instruction (and additional stores with primary opcode of 31)
Carl Love [Fri, 8 Oct 2021 22:54:05 +0000 (22:54 +0000)] 
PPC fix for stfiwx instruction (and additional stores with primary opcode of 31)

[gdb] Fix address being recorded in rs6000-tdep.c, ppc_process_record_op31.

The GDB record function was recording the variable addr that was passed in
rather than the calculated effective address (ea) by the
ppc_process_record_op31 function.

2 years agogdb: improve error reporting from the disassembler
Andrew Burgess [Tue, 5 Oct 2021 14:10:12 +0000 (15:10 +0100)] 
gdb: improve error reporting from the disassembler

If the libopcodes disassembler returns a negative value then this
indicates that the disassembly failed for some reason.  In disas.c, in
the function gdb_disassembler::print_insn we can see how this is
handled; when we get a negative value back, we call the memory_error
function, which throws an exception.

The problem here is that the address used in the memory_error call is
gdb_disassembler::m_err_memaddr, which is set in
gdb_disassembler::dis_asm_memory_error, which is called from within
the libopcodes disassembler through the
disassembler_info::memory_error_func callback.

However, for this to work correctly, every time the libopcodes
disassembler returns a negative value, the libopcodes disassembler
must have first called the memory_error_func callback.

My first plan was to make m_err_memaddr a gdb::optional, and assert
that it always had a value prior to calling memory_error, however, a
quick look in opcodes/*-dis.c shows that there _are_ cases where a
negative value is returned without first calling the memory_error_func
callback, for example in arc-dis.c and cris-dis.c.

Now, I think that a good argument can be made that these disassemblers
must therefore be broken, except for the case where we can't read
memory, we should always be able to disassemble the memory contents to
_something_, even if it's just '.word 0x....'.  However, I certainly
don't plan to go and fix all of the disassemblers.

What I do propose to do then, is make m_err_memaddr a gdb::optional,
but now, instead of always calling memory_error, I add a new path
which just calls error complaining about an unknown error.  This new
path is only used if m_err_memaddr doesn't have a value (indicating
that the memory_error_func callback was not called).

To test this I just augmented one of the disassemblers to always
return -1, before this patch I see this:

  Dump of assembler code for function main:
     0x000101aa <+0>: Cannot access memory at address 0x0

And after this commit I now see:

  Dump of assembler code for function main:
     0x000101aa <+0>: unknown disassembler error (error = -1)

This doesn't really help much, but that's because there's no way to
report non memory errors out of the disasembler, because, it was not
expected that the disassembler would ever report non memory errors.

2 years ago[gdb/testsuite] Fix gdb.fortran/call-no-debug.exp with native-gdbserver
Tom de Vries [Wed, 13 Oct 2021 09:36:02 +0000 (11:36 +0200)] 
[gdb/testsuite] Fix gdb.fortran/call-no-debug.exp with native-gdbserver

When running test-case gdb.fortran/call-no-debug.exp with target board
native-gdbserver, I run into:
...
(gdb) PASS: gdb.fortran/call-no-debug.exp: print string_func_ (&'abcdefg', 3)
call (integer) string_func_ (&'abcdefg', 3)^M
$2 = 0^M
(gdb) FAIL: gdb.fortran/call-no-debug.exp: call (integer) string_func_ (&'abcdefg', 3)
...

The problem is that gdb_test is used to match inferior output.

Fix this by using gdb_test_stdio.

Tested on x86_64-linux.

2 years ago[gdb/testsuite] Require use_gdb_stub == 0 where appropriate
Tom de Vries [Wed, 13 Oct 2021 09:06:36 +0000 (11:06 +0200)] 
[gdb/testsuite] Require use_gdb_stub == 0 where appropriate

When running with target board native-gdbserver, we run into a number of FAILs
due to use of the start command (and similar), which is not supported when
use_gdb_stub == 1.

Fix this by:
- requiring use_gdb_stub == 0 for the entire test-case, or
- guarding some tests in the test-case with use_gdb_stub == 0.

Tested on x86_64-linux.

2 years ago[gdb/testsuite] Fix test name in gdb.python/python.exp
Tom de Vries [Wed, 13 Oct 2021 09:06:36 +0000 (11:06 +0200)] 
[gdb/testsuite] Fix test name in gdb.python/python.exp

When running test-case gdb.python/python.exp, we have:
...
PASS: gdb.python/python.exp: starti via gdb.execute, not from tty
PASS: gdb.python/python.exp: starti via interactive input
...

The two tests are instances of the same test, with different values for
starti command argument from_tty, so it's strange that the test names are so
different.

This is due to using a gdb_test nested in a gdb_test_multiple, with the inner
one using a different test name than the outer one.  [ That could still make
sense if both produced passes, but that's not the case here. ]

Fix this by using $gdb_test_name, such that we have:
...
PASS: gdb.python/python.exp: starti via gdb.execute, not from tty
PASS: gdb.python/python.exp: starti via gdb.execute, from tty
...

Also make this more readable by using variables.

Tested on x86_64-linux.

2 years ago[gdb/testsuite] Fix gdb.base/batch-exit-status.exp with native-gdbserver
Tom de Vries [Wed, 13 Oct 2021 09:06:36 +0000 (11:06 +0200)] 
[gdb/testsuite] Fix gdb.base/batch-exit-status.exp with native-gdbserver

When running test-case gdb.base/batch-exit-status.exp with target board
native-gdbserver, I run into (added missing double quotes for clarity):
...
builtin_spawn $build/gdb/testsuite/../../gdb/gdb -nw -nx \
  -data-directory $build/gdb/testsuite/../data-directory \
  -iex "set height 0" -iex "set width 0" \
  -ex "set auto-connect-native-target off" \
  -iex "set sysroot" -batch ""^M
: No such file or directory.^M
PASS: gdb.base/batch-exit-status.exp: 1x: \
  No such file or directory: [lindex $result 2] == 0
FAIL: gdb.base/batch-exit-status.exp: 1x: \
  No such file or directory: [lindex $result 3] == $expect_status
...

As in commit a02a90c114c "[gdb/testsuite] Set sysroot earlier in
local-board.exp", the problem is the use of -ex for
"set auto-connect-native-target off", which makes that the last command to
be executed, and consequently determines the return status.

Fix this by using -iex instead.

Tested on x86_64-linux.

2 years ago[gdb/testsuite] Remove quit in gdb.arch/i386-mpx.exp
Tom de Vries [Wed, 13 Oct 2021 09:06:36 +0000 (11:06 +0200)] 
[gdb/testsuite] Remove quit in gdb.arch/i386-mpx.exp

When running test-case gdb.arch/i386-mpx.exp with target board
native-gdbserver, I run into:
...
(gdb) PASS: gdb.arch/i386-mpx.exp: verify size for bnd0
Remote debugging from host ::1, port 42328^M
quit^M
A debugging session is active.^M
^M
        Inferior 1 [process 19679] will be killed.^M
^M
Quit anyway? (y or n) monitor exit^M
Please answer y or n.^M
A debugging session is active.^M
^M
        Inferior 1 [process 19679] will be killed.^M
^M
Quit anyway? (y or n) WARNING: Timed out waiting for EOF in server after monitor exit
...

The problem is that the test-case sends a quit at the end (without verifying
the result of this in any way):
...
send_gdb "quit\n"
...

Fix this by removing the quit.

Tested on x86_64-linux.

2 years agoAutomatic date update in version.in
GDB Administrator [Wed, 13 Oct 2021 00:00:06 +0000 (00:00 +0000)] 
Automatic date update in version.in

2 years agoAutomatic date update in version.in
GDB Administrator [Tue, 12 Oct 2021 00:00:15 +0000 (00:00 +0000)] 
Automatic date update in version.in

2 years ago[ARM] Add support for M-profile MVE extension
Srinath Parvathaneni [Wed, 21 Jul 2021 15:33:44 +0000 (12:33 -0300)] 
[ARM] Add support for M-profile MVE extension

This patch adds support for the M-profile MVE extension, which includes the
following:

- New M-profile XML feature m-profile-mve
- MVE vector predication status and control register (VPR)
- p0 pseudo register (contained in the VPR)
- q0 ~ q7 pseudo vector registers
- New feature bits
- Documentation update

Pseudo register p0 is the least significant bits of vpr and can be accessed
as $p0 or displayed through $vpr.  For more information about the register
layout, please refer to [1].

The q0 ~ q7 registers map back to the d0 ~ d15 registers, two d registers
per q register.

The register dump looks like this:

(gdb) info reg all
r0             0x0                 0
r1             0x0                 0
r2             0x0                 0
r3             0x0                 0
r4             0x0                 0
r5             0x0                 0
r6             0x0                 0
r7             0x0                 0
r8             0x0                 0
r9             0x0                 0
r10            0x0                 0
r11            0x0                 0
r12            0x0                 0
sp             0x0                 0x0 <__Vectors>
lr             0xffffffff          -1
pc             0xd0c               0xd0c <Reset_Handler>
xpsr           0x1000000           16777216
d0             0                   (raw 0x0000000000000000)
d1             0                   (raw 0x0000000000000000)
d2             0                   (raw 0x0000000000000000)
d3             0                   (raw 0x0000000000000000)
d4             0                   (raw 0x0000000000000000)
d5             0                   (raw 0x0000000000000000)
d6             0                   (raw 0x0000000000000000)
d7             0                   (raw 0x0000000000000000)
d8             0                   (raw 0x0000000000000000)
d9             0                   (raw 0x0000000000000000)
d10            0                   (raw 0x0000000000000000)
d11            0                   (raw 0x0000000000000000)
d12            0                   (raw 0x0000000000000000)
d13            0                   (raw 0x0000000000000000)
d14            0                   (raw 0x0000000000000000)
d15            0                   (raw 0x0000000000000000)
fpscr          0x0                 0
vpr            0x0                 [ P0=0 MASK01=0 MASK23=0 ]
s0             0                   (raw 0x00000000)
s1             0                   (raw 0x00000000)
s2             0                   (raw 0x00000000)
s3             0                   (raw 0x00000000)
s4             0                   (raw 0x00000000)
s5             0                   (raw 0x00000000)
s6             0                   (raw 0x00000000)
s7             0                   (raw 0x00000000)
s8             0                   (raw 0x00000000)
s9             0                   (raw 0x00000000)
s10            0                   (raw 0x00000000)
s11            0                   (raw 0x00000000)
s12            0                   (raw 0x00000000)
s13            0                   (raw 0x00000000)
s14            0                   (raw 0x00000000)
s15            0                   (raw 0x00000000)
s16            0                   (raw 0x00000000)
s17            0                   (raw 0x00000000)
s18            0                   (raw 0x00000000)
s19            0                   (raw 0x00000000)
s20            0                   (raw 0x00000000)
s21            0                   (raw 0x00000000)
s22            0                   (raw 0x00000000)
s23            0                   (raw 0x00000000)
s24            0                   (raw 0x00000000)
s25            0                   (raw 0x00000000)
s26            0                   (raw 0x00000000)
s27            0                   (raw 0x00000000)
s28            0                   (raw 0x00000000)
s29            0                   (raw 0x00000000)
s30            0                   (raw 0x00000000)
s31            0                   (raw 0x00000000)
q0             {u8 = {0x0 <repeats 16 times>}, u16 = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, u32 = {0x0, 0x0, 0x0, 0x0}, u64 = {0x0, 0x0}, f32 = {0x0, 0x0, 0x0, 0x0}, f64 = {0x0, 0x0}}
q1             {u8 = {0x0 <repeats 16 times>}, u16 = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, u32 = {0x0, 0x0, 0x0, 0x0}, u64 = {0x0, 0x0}, f32 = {0x0, 0x0, 0x0, 0x0}, f64 = {0x0, 0x0}}
q2             {u8 = {0x0 <repeats 16 times>}, u16 = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, u32 = {0x0, 0x0, 0x0, 0x0}, u64 = {0x0, 0x0}, f32 = {0x0, 0x0, 0x0, 0x0}, f64 = {0x0, 0x0}}
q3             {u8 = {0x0 <repeats 16 times>}, u16 = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, u32 = {0x0, 0x0, 0x0, 0x0}, u64 = {0x0, 0x0}, f32 = {0x0, 0x0, 0x0, 0x0}, f64 = {0x0, 0x0}}
q4             {u8 = {0x0 <repeats 16 times>}, u16 = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, u32 = {0x0, 0x0, 0x0, 0x0}, u64 = {0x0, 0x0}, f32 = {0x0, 0x0, 0x0, 0x0}, f64 = {0x0, 0x0}}
q5             {u8 = {0x0 <repeats 16 times>}, u16 = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, u32 = {0x0, 0x0, 0x0, 0x0}, u64 = {0x0, 0x0}, f32 = {0x0, 0x0, 0x0, 0x0}, f64 = {0x0, 0x0}}
q6             {u8 = {0x0 <repeats 16 times>}, u16 = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, u32 = {0x0, 0x0, 0x0, 0x0}, u64 = {0x0, 0x0}, f32 = {0x0, 0x0, 0x0, 0x0}, f64 = {0x0, 0x0}}
q7             {u8 = {0x0 <repeats 16 times>}, u16 = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, u32 = {0x0, 0x0, 0x0, 0x0}, u64 = {0x0, 0x0}, f32 = {0x0, 0x0, 0x0, 0x0}, f64 = {0x0, 0x0}}
p0             0x0                 0

Built and regtested with a simulator.

[1] https://developer.arm.com/documentation/ddi0553/bn

Co-Authored-By: Luis Machado <luis.machado@linaro.org>
2 years ago[ARM] Refactor pseudo register numbering
Luis Machado [Mon, 4 Oct 2021 16:56:43 +0000 (13:56 -0300)] 
[ARM] Refactor pseudo register numbering

The pseudo register handling for ARM uses some hardcoded constants to
determine types and names.  In preparation to the upcoming MVE support
patch (that will add another pseudo register), this patch refactors and
reorganizes things in order to simplify handling of future pseudo registers.

We keep track of the first pseudo register number in a group and the number of
pseudo registers in that group.

Right now we only have the S and Q pseudo registers.

2 years ago[ARM] Small refactoring of arm gdbarch initialization
Luis Machado [Mon, 4 Oct 2021 12:34:50 +0000 (09:34 -0300)] 
[ARM] Small refactoring of arm gdbarch initialization

This is in preparation to MVE support, where we will define another
pseudo register. We need to define the pseudo register numbers *after*
accounting for all the registers in the XML description, so move
the call to tdesc_use_registers up.

If we don't do it, GDB's register count won't consider registers contained
in the XML but ignored by GDB, throwing the register numbering off.

2 years ago[ARM] Refactor some constants
Luis Machado [Tue, 27 Jul 2021 14:36:33 +0000 (11:36 -0300)] 
[ARM] Refactor some constants

In preparation for the MVE extension patch, this one refactors some of
the register-related constants we have for ARM.

Basically I'm separating counting constants from numbering constants.

For example, ARM_A1_REGNUM is a numbering constant, whereas ARM_NUM_ARG_REGS
is a counting constant.

2 years ago[gdb/testsuite] Fix FAIL in gdb.mi/mi-var-child-f.exp
Tom de Vries [Mon, 11 Oct 2021 14:59:56 +0000 (16:59 +0200)] 
[gdb/testsuite] Fix FAIL in gdb.mi/mi-var-child-f.exp

When running test-case gdb.mi/mi-var-child-f.exp on openSUSE Tumbleweed
(with glibc 2.34) I run into:
...
(gdb) ^M
PASS: gdb.mi/mi-var-child-f.exp: mi runto prog_array
Expecting: ^(-var-create array \* array[^M
]+)?(\^done,name="array",numchild="[0-9]+",value=".*",type=.*,has_more="0"[^M
]+[(]gdb[)] ^M
[ ]*)
-var-create array * array^M
&"Attempt to use a type name as an expression.\n"^M
^error,msg="-var-create: unable to create variable object"^M
(gdb) ^M
FAIL: gdb.mi/mi-var-child-f.exp: create local variable array (unexpected output)
...

The problem is that the name array is used both:
- as the name for a local variable
- as the name of a type in glibc, in file malloc/dynarray-skeleton.c, as included
  by nss/nss_files/files-hosts.c.

Fix this by ignoring the shared lib symbols.

Likewise in a couple of other fortran tests.

Tested on x86_64-linux.

2 years agoz80/disassembler: call memory_error_func when appropriate
Andrew Burgess [Thu, 7 Oct 2021 16:50:33 +0000 (17:50 +0100)] 
z80/disassembler: call memory_error_func when appropriate

If a call to the read_memory_func fails then we should call the
memory_error_func to notify the user of the disassembler of the
address that was a problem.

Without this GDB will report all memory errors as being at address
0x0.

opcodes/ChangeLog:

* z80-dis.c (fetch_data): Call memory_error_func if the
read_memory_func call fails.

2 years agos12z/disassembler: call memory_error_func when appropriate
Andrew Burgess [Thu, 7 Oct 2021 16:48:28 +0000 (17:48 +0100)] 
s12z/disassembler: call memory_error_func when appropriate

If a call to the read_memory_func fails then we should call the
memory_error_func to notify the user of the disassembler of the
address that was a problem.

Without this GDB will report all memory errors as being at address
0x0.

opcodes/ChangeLog:

* s12z-disc.c (abstract_read_memory): Call memory_error_func if
the read_memory_func call fails.

2 years ago[gdb/testsuite] Fix double debug info in gdb.dwarf2/dw2-ref-missing-frame.exp
Tom de Vries [Mon, 11 Oct 2021 11:31:54 +0000 (13:31 +0200)] 
[gdb/testsuite] Fix double debug info in gdb.dwarf2/dw2-ref-missing-frame.exp

A mistake slipped in in commit a5ea23036d8 "[gdb/testsuite] Use function_range
in gdb.dwarf2/dw2-ref-missing-frame.exp".

Before the commit the main file was compiled with debug info, and the two
others not:
...
if {[prepare_for_testing_full "failed to prepare" \
        [list $testfile {} $srcfile {} $srcfuncfile {} \
             $srcmainfile debug]]} {
...

After the commit, all were compiled with debug info, and consequently, there
are two versions of debug info for $srcfuncfile.  This shows up as a FAIL when
running the test-case with target boards readnow and cc-with-debug-names.

Fix this by using prepare_for_testing_full, as before.

Tested on x86_64-linux.

Fixes: a5ea23036d8 ("[gdb/testsuite] Use function_range in
       gdb.dwarf2/dw2-ref-missing-frame.exp")

2 years ago[gdb/testsuite] Use require for ensure_gdb_index
Tom de Vries [Mon, 11 Oct 2021 10:21:00 +0000 (12:21 +0200)] 
[gdb/testsuite] Use require for ensure_gdb_index

Replace:
...
if { [ensure_gdb_index $binfile] == -1 } {
    return -1
}
...
with:
...
require {ensure_gdb_index $binfile} != -1
...
and consequently, add a missing UNTESTED message.

Tested on x86_64-linux, both with native and target board readnow.

2 years ago[gdb/testsuite] Handle readnow in ensure_gdb_index
Tom de Vries [Mon, 11 Oct 2021 10:21:00 +0000 (12:21 +0200)] 
[gdb/testsuite] Handle readnow in ensure_gdb_index

When running test-case gdb.base/with-mf.exp with target board readnow, I run
into:
...
FAIL: gdb.base/with-mf.exp: check if index present
...
This is since commit 6010fb0c49e "[gdb/testsuite] Fix full buffer in
gdb.rust/dwindex.exp".

Before that commit, the proc ensure_gdb_index would treat the line:
...
.gdb_index: faked for "readnow"^M
...
as proof that an index is already present (which is incorrect).

Now, instead it generates aforementioned FAIL and continues to generate an
index.

Fix this by explicitly handling the readnow case in proc ensure_gdb_index,
such that we bail out instead.

Tested on x86_64-linux.

2 years ago[gdb/testsuite] Fix gdb.dwarf2/gdb-add-index-symlink.exp
Tom de Vries [Mon, 11 Oct 2021 10:21:00 +0000 (12:21 +0200)] 
[gdb/testsuite] Fix gdb.dwarf2/gdb-add-index-symlink.exp

The test-case gdb.dwarf2/gdb-add-index-symlink.exp interpretes a failure to
add an index as a failure to add an index for a symlink:
...
if { [ensure_gdb_index $symlink] == -1 } {
    fail "Unable to call gdb-add-index with a symlink to a symfile"
    return -1
}
...

However, it's possible that the gdb-add-index also fails with a regular
file.  Add a check for that situation.

Tested on x86_64-linux.

2 years ago[gdb/testsuite] Add proc require in lib/gdb.exp
Tom de Vries [Mon, 11 Oct 2021 10:21:00 +0000 (12:21 +0200)] 
[gdb/testsuite] Add proc require in lib/gdb.exp

Add a new proc require in lib/gdb.exp, and use it to shorten:
...
if { [gdb_skip_xml_test] } {
    # Valgrind gdbserver requires gdb with xml support.
    untested "missing xml support"
    return 0
}
...
into:
...
require gdb_skip_xml_test 0
...

Tested on x86_64-linux, both with and without a trigger patch that forces
gdb_skip_xml_test to return 1.

2 years agobfd: Remove use of void pointer arithmetic
Michael Forney [Wed, 6 Oct 2021 17:33:13 +0000 (10:33 -0700)] 
bfd: Remove use of void pointer arithmetic

This is not valid in ISO C. Instead, use a pointer to bfd_byte.

* peicode.h (pe_bfd_object_p): Remove use of void pointer
arithmetic.

2 years agoAutomatic date update in version.in
GDB Administrator [Mon, 11 Oct 2021 00:00:13 +0000 (00:00 +0000)] 
Automatic date update in version.in

2 years agoAutomatic date update in version.in
GDB Administrator [Sun, 10 Oct 2021 00:00:09 +0000 (00:00 +0000)] 
Automatic date update in version.in

2 years ago[gdb] Make execute_command_to_string return string on throw
Tom de Vries [Sat, 9 Oct 2021 16:58:30 +0000 (18:58 +0200)] 
[gdb] Make execute_command_to_string return string on throw

The pattern for using execute_command_to_string is:
...
  std::string output;
  output = execute_fn_to_string (fn, term_out);
...

This results in a problem when using it in a try/catch:
...
  try
    {
      output = execute_fn_to_string (fn, term_out)
    }
  catch (const gdb_exception &e)
    {
      /* Use output.  */
    }
...

If an expection was thrown during execute_fn_to_string, then the output
remains unassigned, while it could be worthwhile to known what output was
generated by gdb before the expection was thrown.

Fix this by returning the string using a parameter instead:
...
  execute_fn_to_string (output, fn, term_out)
...

Also add a variant without string parameter, to support places where the
function is used while ignoring the result:
...
  execute_fn_to_string (fn, term_out)
...

Tested on x86_64-linux.

2 years ago[gdb/testsuite] Add check-readmore
Tom de Vries [Sat, 9 Oct 2021 16:53:12 +0000 (18:53 +0200)] 
[gdb/testsuite] Add check-readmore

Consider the gdb output:
...
27        return SYSCALL_CANCEL (nanosleep, requested_time, remaining);^M
(gdb) ^M
Thread 2 "run-attach-whil" stopped.^M
...

When trying to match the gdb prompt using gdb_test which uses '$gdb_prompt $',
it may pass or fail.

This sort of thing needs to be fixed (see commit b0e2f96b56b), but there's
currently no way to reliably find this type of FAILs.

We have check-read1, but that one actually make the test pass reliably.

We need something like the opposite of check-read1: something that makes
expect read a bit slower, or more exhaustively.

Add a new test target check-readmore that implements this.

There are two methods of implementing this in read1.c:
- the first method waits a bit before doing a read
- the second method does a read and then decides whether to
  return or to wait a bit and do another read, and so on.

The second method is potentially faster, has less risc of timeout and could
potentially detect more problems.  The first method has a simpler
implementation.

The second method is enabled by default.  The default waiting period is 10
miliseconds.

The first method can be enabled using:
...
$ export READMORE_METHOD=1
...
and the waiting period can be specified in miliseconds using:
...
$ export READMORE_SLEEP=9
...

Also a log file can be specified using:
...
$ export READMORE_LOG=$(pwd -P)/LOG
...

Tested on x86_64-linux.

Testing with check-readmore showed these regressions:
...
FAIL: gdb.base/bp-cmds-continue-ctrl-c.exp: run: stop with control-c (continue)
FAIL: gdb.base/bp-cmds-continue-ctrl-c.exp: attach: stop with control-c (continue)
...

I have not been able to find a problem in the test-case, and I think it's the
nature of both the test-case and readmore that makes it run longer.  Make
these pass by increasing the alarm timeout from 60 to 120 seconds.

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

2 years ago[gdb/testsuite] Fix fortran module tests with stressed cpu
Tom de Vries [Sat, 9 Oct 2021 09:35:43 +0000 (11:35 +0200)] 
[gdb/testsuite] Fix fortran module tests with stressed cpu

When running these test-cases:
- gdb.fortran/info-modules.exp
- gdb.fortran/module.exp
- gdb.mi/mi-fortran-modules.exp
in conjunction with:
...
$ stress -c $(($(cat /proc/cpuinfo | grep -c "^processor") + 1))
...
I run into timeouts.

Fix this by using:
- "set auto-solib-add off" to avoid symbols of shared libs
  (which doesn't work for libc, now that libpthread_name_p has been
  updated to  match libc)
- "nosharedlibrary" to avoid symbols of libc

Tested on x86_64-linux.

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

2 years agoPR28415, invalid read in xtensa_read_table_entries
Guillermo E. Martinez [Thu, 7 Oct 2021 05:49:13 +0000 (16:19 +1030)] 
PR28415, invalid read in xtensa_read_table_entries

PR 28415
PR 28416
* elf32-xtensa.c (xtensa_read_table_entries): Handle error
return from retrieve_contents.

2 years agoAutomatic date update in version.in
GDB Administrator [Sat, 9 Oct 2021 00:00:08 +0000 (00:00 +0000)] 
Automatic date update in version.in

2 years ago[gdb/testsuite] Fix gdb.base/info-types-c++.exp with stressed cpu
Tom de Vries [Fri, 8 Oct 2021 22:40:46 +0000 (00:40 +0200)] 
[gdb/testsuite] Fix gdb.base/info-types-c++.exp with stressed cpu

When running test-case gdb.base/info-types-c++.exp in conjunction with:
...
$ stress -c $(($(cat /proc/cpuinfo | grep -c "^processor") + 1))
...
we get:
...
FAIL: gdb.base/info-types-c++.exp: info types (timeout)
...

Fix this by setting auto-solib-add to off.

Tested on x86_64-linux.

2 years ago[gdb/testsuite] Fix gdb.base/info_sources_2.exp with check-read1
Tom de Vries [Fri, 8 Oct 2021 12:17:09 +0000 (14:17 +0200)] 
[gdb/testsuite] Fix gdb.base/info_sources_2.exp with check-read1

When running test-case gdb.base/info_sources_2.exp with check-read1, I run
into:
...
FAIL: gdb.base/info_sources_2.exp: args: : info sources  (timeout)
...

Fix this by consuming a "$src1, $src2, ..., $srcn: line bit by bit rather than
as one whole line.

Also add the missing handling of "Objfile has no debug information".

Tested on x86_64-linux.

2 years ago[gdb/testsuite] Fix gdb.mi/gdb2549.exp with check-read1
Tom de Vries [Fri, 8 Oct 2021 11:07:52 +0000 (13:07 +0200)] 
[gdb/testsuite] Fix gdb.mi/gdb2549.exp with check-read1

When running test-case gdb.mi/gdb2549.exp with check-read1, I run into:
...
FAIL: gdb.mi/gdb2549.exp: register values x (timeout)
...

Fix this by applying the same fix as for "register values t" in commit
478e490a4df "[gdb/testsuite] Fix gdb.mi/gdb2549.exp with check-read1".

Tested on x86_64-linux.

2 years ago[gdb/testsuite] Fix gdb.base/bt-on-error-and-warning.exp with check-read1
Tom de Vries [Fri, 8 Oct 2021 10:30:35 +0000 (12:30 +0200)] 
[gdb/testsuite] Fix gdb.base/bt-on-error-and-warning.exp with check-read1

When running test-case gdb.base/bt-on-error-and-warning.exp with check-read1,
I run into:
...
(gdb) maint internal-error foobar^M
src/gdb/maint.c:82: internal-error: foobar^M
A problem internal to GDB has been detectedFAIL: \
  gdb.base/bt-on-error-and-warning.exp: problem=internal-error, mode=on: \
  scan for backtrace (GDB internal error)
Resyncing due to internal error.
,^M
...

The corresponding gdb_test_multiple in the test-case contains:
...
           -early -re "^A problem internal to GDB has been detected,\r\n" {
               incr header_lines
               exp_continue
           }
...
but instead this one triggers in gdb_test_multiple:
...
        -re ".*A problem internal to GDB has been detected" {
            fail "$message (GDB internal error)"
            gdb_internal_error_resync
            set result -1
        }
...

Fix this by likewise shortening the regexp to before the comma.

Tested on x86_64-linux.

2 years ago[gdb/testsuite] Add nopie in two test-cases
Tom de Vries [Fri, 8 Oct 2021 09:20:31 +0000 (11:20 +0200)] 
[gdb/testsuite] Add nopie in two test-cases

When running test-case gdb.dwarf2/dw2-restrict.exp on openSUSE Leap 15.2 with
gcc-PIE installed (switching compiler default to -fPIE/-pie), I get:
...
gdb compile failed, ld: outputs/gdb.dwarf2/dw2-restrict/dw2-restrict0.o: \
  warning: relocation in read-only section `.text'
ld: warning: creating DT_TEXTREL in a PIE
UNTESTED: gdb.dwarf2/dw2-restrict.exp: failed to prepare
...

This is due to using a hardcoded .S file that was generated with -fno-PIE.

Fix this by adding the missing nopie.

Likewise in gdb.arch/amd64-tailcall-noret.exp.

Tested on x86_64-linux.

2 years agoAutomatic date update in version.in
GDB Administrator [Fri, 8 Oct 2021 00:00:11 +0000 (00:00 +0000)] 
Automatic date update in version.in

2 years ago[gdb/testsuite] Fix gdb.threads/check-libthread-db.exp with glibc 2.34
Tom de Vries [Thu, 7 Oct 2021 16:00:08 +0000 (18:00 +0200)] 
[gdb/testsuite] Fix gdb.threads/check-libthread-db.exp with glibc 2.34

When running test-case gdb.threads/check-libthread-db.exp on openSUSE
Tumbleweed (with glibc 2.34) I get:
...
(gdb) continue^M
Continuing.^M
[Thread debugging using libthread_db enabled]^M
Using host libthread_db library "/lib64/libthread_db.so.1".^M
Stopped due to shared library event:^M
  Inferior loaded /lib64/libm.so.6^M
    /lib64/libc.so.6^M
(gdb) FAIL: gdb.threads/check-libthread-db.exp: user-initiated check: continue
...

The check expect the inferior to load libpthread, but since glibc 2.34
libpthread has been integrated into glibc, and consequently it's no longer
a dependency:
...
$ ldd outputs/gdb.threads/check-libthread-db/check-libthread-db
        linux-vdso.so.1 (0x00007ffe4cae4000)
        libm.so.6 => /lib64/libm.so.6 (0x00007f167c77c000)
        libc.so.6 => /lib64/libc.so.6 (0x00007f167c572000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f167c86e000)
...

Fix this by updating the regexp to expect libpthread or libc.

Tested on x86_64-linux.

2 years ago[gdb/testsuite] Fix gdb.guile/scm-type.exp with gcc 4.8
Tom de Vries [Thu, 7 Oct 2021 16:00:08 +0000 (18:00 +0200)] 
[gdb/testsuite] Fix gdb.guile/scm-type.exp with gcc 4.8

With gcc 7.5.0, I get:
...
(gdb) guile (print (type-range (field-type (type-field (value-type \
  (value-dereference f)) "items"))))^M
= (0 0)^M
(gdb) PASS: gdb.guile/scm-type.exp: lang_cpp: test_range: \
  on flexible array member: $cmd
...
but with gcc 4.8.5, I get instead:
...
(gdb) guile (print (type-range (field-type (type-field (value-type \
  (value-dereference f)) "items"))))^M
= (0 -1)^M
(gdb) FAIL: gdb.guile/scm-type.exp: lang_cpp: test_range: \
  on flexible array member: $cmd
...

There's a difference in debug info.  With gcc 4.8.5, we have:
...
 <2><224>: Abbrev Number: 15 (DW_TAG_member)
    <225>   DW_AT_name        : items
    <22b>   DW_AT_type        : <0x231>
 <1><231>: Abbrev Number: 4 (DW_TAG_array_type)
    <232>   DW_AT_type        : <0x105>
 <2><23a>: Abbrev Number: 16 (DW_TAG_subrange_type)
    <23b>   DW_AT_type        : <0x11a>
    <23f>   DW_AT_upper_bound : 0xffffffffffffffff
...
and with gcc 7.5.0, we have instead:
...
 <2><89f>: Abbrev Number: 12 (DW_TAG_member)
    <8a0>   DW_AT_name        : items
    <8a6>   DW_AT_type        : <0x8ac>
 <1><8ac>: Abbrev Number: 17 (DW_TAG_array_type)
    <8ad>   DW_AT_type        : <0x29d>
 <2><8b5>: Abbrev Number: 41 (DW_TAG_subrange_type)
 <2><8b6>: Abbrev Number: 0
...

As mentioned in commit 858c8f2c1b9 "gdb/testsuite: adjust
gdb.python/flexible-array-member.exp expected pattern":
...
Ideally, GDB would present a consistent and documented value for an
array member declared with size 0, regardless of how the debug info
looks like.
...

As in gdb.python/flexible-array-member.exp, change the test to accept the two
values.

Tested on x86_64-linux.

2 years agogdb: add accessors for field (and call site) location
Simon Marchi [Fri, 1 Oct 2021 02:38:29 +0000 (22:38 -0400)] 
gdb: add accessors for field (and call site) location

Add accessors for the various location values in struct field.  This
lets us assert that when we get a location value of a certain kind (say,
bitpos), the field's location indeed contains a value of that kind.

Remove the SET_FIELD_* macros, instead use the new setters directly.
Update the FIELD_* macros used to access field locations to go through
the getters.  They will be removed in a subsequent patch.

There are places where the FIELD_* macros are used on call_site_target
structures, because it contains members of the same name (loc_kind and
loc).  For now, I have replicated the getters/setters in
call_site_target.  But we could perhaps eventually factor them in a
"location" structure that can be used at both places.

Note that the field structure, being zero-initialized, defaults to a
bitpos location with value 0.  While writing this patch, I tried to make
it default to an "unset" location, to catch places where we would miss
setting a field's location.  However, I found that some places relied on
the default being "bitpos 0", so I left it as-is.  This change could
always be done as follow-up work, making these places explicitly set the
"bitpos 0" location.

I found two issues to fix:

 - I got some failures in the gdb.base/infcall-nested-structs-c++.exp
   test.  They were caused by two functions in amd64-tdep.c using
   TYPE_FIELD_BITPOS before checking if the location is of the bitpos
   kind, which they do indirectly through `field_is_static`.  Simply
   move getting the bitpos below the field_is_static call.

 - I got a failure in gdb.xml/tdesc-regs.exp.  It turns out that in
   make_gdb_type_enum, we set enum field values using SET_FIELD_BITPOS,
   and later access them through FIELD_ENUMVAL.  Fix that by using
   set_loc_enumval to set the value.

Change-Id: I53d3734916c46457576ba11dd77df4049d2fc1e8

2 years agoRISC-V: Support aliases for Zbs instructions
Philipp Tomsich [Wed, 6 Oct 2021 20:26:47 +0000 (22:26 +0200)] 
RISC-V: Support aliases for Zbs instructions

Add aliases for the non-immediate mnemonics of b{set,clr,inv,ext} to
yencode the respective immediate insn b{set,clr,inv,ext}i when the
second source operand is an immediate.

2021-01-11  Philipp Tomsich  <philipp.tomsich@vrull.eu>

    gas/
* testsuite/gas/riscv/b-ext.d: Add tests.
* testsuite/gas/riscv/b-ext.s: Likewise.
* testsuite/gas/riscv/b-ext-64.d: Likewise.
* testsuite/gas/riscv/b-ext-64.s: Likewise.
    opcodes/
        * riscv-opc.c (riscv_opcodes): Add aliases for Zbs.

Suggested-by: Jan Beulich <jbeulich@suse.com>
Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu>
2 years agoRISC-V: Add support for Zbs instructions
Philipp Tomsich [Wed, 6 Oct 2021 20:26:46 +0000 (22:26 +0200)] 
RISC-V: Add support for Zbs instructions

This change adds the Zbs instructions from the Zbs 1.0.0 specification.
See
  https://github.com/riscv/riscv-bitmanip/releases/tag/1.0.0
for the frozen specification.

2021-01-09  Philipp Tomsich  <philipp.tomsich@vrull.eu>

    bfd/
* elfxx-riscv.c (riscv_supported_std_z_ext): Added zbs.
    gas/
* config/tc-riscv.c (riscv_multi_subset_supports): Handle INSN_CLASS_ZBS.
* testsuite/gas/riscv/b-ext.d: Test Zbs instructions.
* testsuite/gas/riscv/b-ext.s: Likewise.
* testsuite/gas/riscv/b-ext-64.d: Likewise.
* testsuite/gas/riscv/b-ext-64.s: Likewise.
    include/
* opcode/riscv-opc.h: Added MASK/MATCH/DECLARE_INSN for Zbs.
* opcode/riscv.h (riscv_insn_class): Added INSN_CLASS_ZBS.
    opcodes/
* riscv-opc.c (riscv_supported_std_z_ext): Add zbs.

Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu>
2 years agoRISC-V: Update extension version for Zb[abc] to 1.0.0
Philipp Tomsich [Wed, 6 Oct 2021 20:26:45 +0000 (22:26 +0200)] 
RISC-V: Update extension version for Zb[abc] to 1.0.0

2021-10-06  Philipp Tomsich  <philipp.tomsich@vrull.eu>

    bfd/
* elfxx-riscv.c (riscv_supported_std_z_ext): Update the version
number for zba, zbb and zbc to 1.0.0

Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu>
Version-changes: 3
- Updated version numbers for zba, zbb and zbc to 1.0.0

2 years agoRISC-V: Split Zb[abc] into commented sections
Philipp Tomsich [Wed, 6 Oct 2021 20:26:44 +0000 (22:26 +0200)] 
RISC-V: Split Zb[abc] into commented sections

The Zb[abc] opcodes are bundled just below the Privileged opcodes in
riscv_opcodes, possibly giving the appearance that they are part of
the Privileged spec for an uninitiated reader.  This separates them
out and adds comments above each section to clearly identify them as
Zba, Zbb or Zbc opcodes.

2021-10-04  Philipp Tomsich  <philipp.tomsich@vrull.eu>

    opcodes/
* riscv-opc.c: Split of Zb[abc] instructions and add comments.

Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu>
2 years agoPR28423, use-after-free in objdump
Alan Modra [Thu, 7 Oct 2021 00:49:53 +0000 (11:19 +1030)] 
PR28423, use-after-free in objdump

XCOFF archives use a bi-directional linked list for file members.  So
one member points to both the previous member and the next member.
Members may not be sequentially ordered in the file.  This of course
is over-engineered nonsense and an attractive target for fuzzers.
(There is even a free list of members!)  The testcase in PR28423 is an
XCOFF archive with one member pointing to itself, which results in
lots of bad behaviour.  For example, "ar t" never terminates.

The use-after-free with "objdump -r" happens like this:  The first
archive element is opened, its symbols are read and "canonicalized"
for objdump, then relocations are read and printed.  Those relocations
use the canonicalized symbols, and also happen to be cached by the
coff bfd backend support.  objdump frees the symbols.  The next
archive element is then opened.  This must be done before the first
element is closed, because finding the next element uses data held in
the currect element.  Unfortunately the next element happens to be the
original, so we aren't opening, we're reopening a bfd which has cached
data.  When the relocations are printed they use the cached copy
containing references to the freed canonical symbols.

This patch adds a little sanity checking to the XCOFF "open next
archive file" support, so that it rejects archive members pointing at
themselves.  That is sufficient to cure this problem.  Anything more
is overkill.  If someone deliberately fuzzes an XCOFF archive with an
element loop then reports an "ar" bug when it runs forever, they will
find their bug report closed WONTFIX.

PR 28423
* coff-rs6000.c (_bfd_xcoff_read_ar_hdr): Save size occupied
by member name in areltdata.extra_size.
(_bfd_xcoff_openr_next_archived_file): Sanity check nextoff.
* coff64-rs6000.c (xcoff64_openr_next_archived_file): Call
_bfd_xcoff_openr_next_archived_file.

2 years agoPR28422, build_id use-after-free
Alan Modra [Wed, 6 Oct 2021 07:58:47 +0000 (18:28 +1030)] 
PR28422, build_id use-after-free

This fixes a bug in commit 5d9bbb73c1df.  All fields preserved from a
bfd in struct bfd_preserve need to be cleared in bfd_reinit.

PR 28422
* format.c (bfd_reinit): Clear build_id.

2 years agoChange ridiculous section size error
Alan Modra [Thu, 7 Oct 2021 00:44:03 +0000 (11:14 +1030)] 
Change ridiculous section size error

Rather than reporting "memory exhausted", report "file truncated".
You can hit this error on small fuzzed object files, or on files that
are actually truncated.  In either case sizes can be such that an out
of memory error is a little confusing.

* compress.c (bfd_get_full_section_contents): Set
bfd_error_file_truncated rather than bfd_error_no_memory when
section size exceeds file size.

2 years ago[gdb/testsuite] Fix FAIL in gdb.base/annota1.exp
Tom de Vries [Thu, 7 Oct 2021 03:45:32 +0000 (05:45 +0200)] 
[gdb/testsuite] Fix FAIL in gdb.base/annota1.exp

On openSUSE tumbleweed I run into:
...
FAIL: gdb.base/annota1.exp: run until main breakpoint (timeout)
...
due to a message related to libthread_db:
...
^Z^Zstarting^M
[Thread debugging using libthread_db enabled]^M
Using host libthread_db library "/lib64/libthread_db.so.1".^M
^M
^Z^Zframes-invalid^M
...
which is not matched by the regexp.

Fix this by updating the regexp.

Tested on x86_64-linux.

2 years ago[gdb/testsuite] Refactor regexp in gdb.base/annota1.exp
Tom de Vries [Thu, 7 Oct 2021 03:45:32 +0000 (05:45 +0200)] 
[gdb/testsuite] Refactor regexp in gdb.base/annota1.exp

Refactor regexp in gdb.base/annota1.exp to reduce indentation and repetition.

Tested on x86_64-linux.

2 years agoAutomatic date update in version.in
GDB Administrator [Thu, 7 Oct 2021 00:00:09 +0000 (00:00 +0000)] 
Automatic date update in version.in

2 years agogdb/doc: improve 'show print elements' description
Andrew Burgess [Wed, 6 Oct 2021 11:28:08 +0000 (12:28 +0100)] 
gdb/doc: improve 'show print elements' description

The documentation for 'show print elements' contains the line:

  If the number is 0, then the printing is unlimited.

However, this line is now out of date as can be seen by this GDB
session:

  (gdb) set print elements 0
  (gdb) show print elements
  Limit on string chars or array elements to print is unlimited.

The value 0 does indeed mean unlimited, and this is described in the
'set print elements' section, however, for 'show print elements' the
user will never see the value 0, so lets just remove that bit from the
docs.

2 years ago[gdb/testsuite] Fix FAIL in gdb.tui/corefile-run.exp
Tom de Vries [Wed, 6 Oct 2021 09:26:38 +0000 (11:26 +0200)] 
[gdb/testsuite] Fix FAIL in gdb.tui/corefile-run.exp

When running test-case gdb.tui/corefile-run.exp on openSUSE Tumbleweed,
I run into:
...
PASS: gdb.tui/corefile-run.exp: load corefile
FAIL: gdb.tui/corefile-run.exp: run until the end
...

What's going on is easier to see when also doing dump_screen if
check_contents passes, and inspecting state at the preceding PASS:
...
 +-------------------------------------------------------------------------+
 exec No process In:                                           L??   PC: ??
 [New LWP 16629]
 [Thread debugging using libthread_db enabled]
 Using host libthread_db library "/lib64/libthread_db.so.1".
 Core was generated by `/data/gdb_versions/devel/build/gdb/testsuite/output
 s/gdb.tui/corefile-run/corefi'.
 Program terminated with signal SIGTRAP, Trace/breakpoint trap.
 #0  main ()
 --Type <RET> for more, q to quit, c to continue without paging--
...

The problem is that we're getting a pagination prompt, and the subsequent run
command is interpreted as an answer to that prompt.

Fix this by:
- detecting the gdb prompt in response to "load corefile", such that
  we detect the failure earlier, and
- doing a "set pagination off" in Term::clean_restart.

Tested on x86_64-linux.

2 years agoPR28420, ecoff fuzzing failures
Alan Modra [Wed, 6 Oct 2021 07:01:31 +0000 (17:31 +1030)] 
PR28420, ecoff fuzzing failures

PR 28420
* coff-mips.c (mips_adjust_reloc_in): Replace abort with error
message and return.
* ecoff.c (ecoff_slurp_reloc_table): Remove assertion and aborts,
instead handle errors gracefully.

2 years agoPR28402, fail to allocate line number array
Alan Modra [Wed, 6 Oct 2021 03:08:42 +0000 (13:38 +1030)] 
PR28402, fail to allocate line number array

This fixes a situation where the COFF code allocated memory for
internal representaion arrays before reading the external file data.
That meant the allocation didn't have any sanity check against file
size.

PR 28402
* coffcode.h (buy_and_read): Malloc rather than alloc memory.
(coff_slurp_line_table): Read native line number info before
allocating memory for internal line number array.  Adjust error
paths to suit.  Remove now unnecessary line number count check.
(coff_slurp_reloc_table): Adjust to suit buy_and_read change.

2 years agoPR28403, null pointer dereference in disassemble_bytes
Alan Modra [Tue, 5 Oct 2021 23:47:29 +0000 (10:17 +1030)] 
PR28403, null pointer dereference in disassemble_bytes

Indexing of symbol and howto arrays wasn't checked in aout targets.

PR 28403
* aout-ns32k.c (MY (reloc_howto)): Sanity check howto_table index.
Make r_index unsigned.
(MY_swap_std_reloc_in): Make r_index unsigned.
* aoutx.h (MOVE_ADDRESS): Sanity check symbol r_index.
(aout_link_input_section_std): Make r_index unsigned.
(aout_link_input_section_ext): Likewise.
* i386lynx.c (MOVE_ADDRESS): Sanity check symbol r_index.
(swap_ext_reloc_in, swap_std_reloc_in): Make r_index unsigned.
* pdp11.c (MOVE_ADDRESS): Sanity check symbol r_index.

2 years agoPR28401, invalid section name lookup
Alan Modra [Tue, 5 Oct 2021 23:24:56 +0000 (09:54 +1030)] 
PR28401, invalid section name lookup

The PR28401 testcase has a section named "", ie. an empty string.
This results in some silly behaviour in load_debug_section, and
dump_dwarf_section.  Fix that.  Note that this patch doesn't correct
the main complaint in PR28401, "failed to allocate", since malloc
failures on sections having huge bogus sizes are to be expected.  We
can't safely catch all such cases by comparing with file size, for
example, where sections contain compressed data.

PR 28401
* objdump.c (load_debug_section): Don't attempt to retrieve
empty name sections.
(dump_dwarf_section): Likewise.

2 years agoAutomatic date update in version.in
GDB Administrator [Wed, 6 Oct 2021 00:00:10 +0000 (00:00 +0000)] 
Automatic date update in version.in

2 years ago[gdb/testsuite] Make tui testing less verbose
Tom de Vries [Tue, 5 Oct 2021 23:27:58 +0000 (01:27 +0200)] 
[gdb/testsuite] Make tui testing less verbose

Currently, tui testing is rather verbose.  When using these RUNTESTFLAGS to
pick up all tui tests (17 in total):
...
rtf=$(echo $(cd src/gdb/testsuite/; find gdb.* -type f -name *.exp* \
  | xargs grep -l tuiterm_env) )
...
we have:
...
$ wc -l gdb.log
120592 gdb.log
...

Most of the output is related to controlling the tui screen, but that does
not give a top-level sense of how the test-case progresses.

Put differently: a lot of bandwith is used to describe how we arrive at a
certain tui screen state.  But we don't actually always show the state we
arrive at, unless there's a FAIL.

And if there's say, a PASS that should actually be FAILing, it's hard to
detect.

Fix this by:
- dropping the -log on the call to verbose in _log.  We still can get the
  same info back using runtest -v.
- dumping the screen or box that we're checking, also when the test passes.

Brings down verbosity to something more reasonable:
...
$ wc -l gdb.log
3221 gdb.log
...

Tested on x86_64-linux.

2 years ago[gdb/testsuite] Add Term::dump_box in lib/tuiterm.exp
Tom de Vries [Tue, 5 Oct 2021 23:27:58 +0000 (01:27 +0200)] 
[gdb/testsuite] Add Term::dump_box in lib/tuiterm.exp

Factor out new proc Term::get_region and use it to implement a
new proc Term::dump_box, similar to Term::dump_screen.

Tested on x86_64-linux.

2 years agogdb: Remove deprecated assertion in setting::get
Lancelot SIX [Tue, 5 Oct 2021 19:55:19 +0000 (19:55 +0000)] 
gdb: Remove deprecated assertion in setting::get

The commit 702991711a91bd47b209289562843a11e7009396 (gdb: Have setter
and getter callbacks for settings) makes it possible for a setting not
to be backed by a memory buffer but use callback functions instead to
retrieve or set the setting's value.

An assertion was not properly updated to take into account that the
m_var member (which points to a memory buffer, if used) might be nullptr
if the setting uses callback functions.  If the setting is backed by a
memory buffer, the m_var has to be non nullptr, which is already checked
before the pointer is dereferenced.

This commit removes this assertion as it is not valid anymore.

2 years agoRemove 'varsize-limit'
Tom Tromey [Mon, 13 Sep 2021 18:53:05 +0000 (12:53 -0600)] 
Remove 'varsize-limit'

This makes the Ada-specific "varsize-limit" a synonym for
"max-value-size", and removes the Ada-specific checks of the limit.

I am not certain of the history here, but it seems to me that this
code is fully obsolete now.  And, removing this makes it possible to
index large Ada arrays without triggering an error.  A new test case
is included to demonstrate this.

2 years agoAllow lazy 'zero' value
Tom Tromey [Mon, 13 Sep 2021 18:31:20 +0000 (12:31 -0600)] 
Allow lazy 'zero' value

This changes value_zero to create a lazy value.  In many cases,
value_zero is called in expression evaluation to wrap a type in a
non-eval context.  It seems senseless to allocate a buffer in these
cases.

A new 'is_zero' flag is added so we can preserve the existing
assertions in value_fetch_lazy.

A subsequent patch will add a test where creating a zero value would
fail, due to the variable size check.  However, the contents of this
value are never needed, and so creating a lazy value avoids the error
case.

2 years agoAdd lval_funcs::is_optimized_out
Tom Tromey [Fri, 10 Sep 2021 18:40:54 +0000 (12:40 -0600)] 
Add lval_funcs::is_optimized_out

This adds an is_optimized_out function pointer to lval_funcs, and
changes value_optimized_out to call it.  This new function lets gdb
determine if a value is optimized out without necessarily fetching the
value.  This is needed for a subsequent patch, where an attempt to
access a lazy value would fail due to the value size limit -- however,
the access was only needed to determine the optimized-out state.

2 years ago[gdb/testsuite] Fix FAIL in gdb.mi/mi-nsmoribund.exp
Tom de Vries [Tue, 5 Oct 2021 13:52:53 +0000 (15:52 +0200)] 
[gdb/testsuite] Fix FAIL in gdb.mi/mi-nsmoribund.exp

Since commit e36788d1354 "[gdb/testsuite] Fix handling of nr_args < 3 in
mi_gdb_test" we run into:
...
PASS: gdb.mi/mi-nsmoribund.exp: print done = 1
Expecting: ^(.*[^M
]+)?([^
]*^M
\*running,thread-id="[0-9]+"^M
\*running,thread-id="[0-9]+"^M
\*running,thread-id="[0-9]+"^M
\*running,thread-id="[0-9]+"^M
\*running,thread-id="[0-9]+"^M
\*running,thread-id="[0-9]+"^M
\*running,thread-id="[0-9]+"^M
\*running,thread-id="[0-9]+"^M
\*running,thread-id="[0-9]+"^M
\*running,thread-id="[0-9]+"[^M
]+[(]gdb[)] ^M
[ ]*)
103-exec-continue --all^M
=library-loaded,id="/lib64/libgcc_s.so.1",target-name="/lib64/libgcc_s.so.1",\
  host-name="/lib64/libgcc_s.so.1",symbols-loaded="0",thread-group="i1",\
  ranges=[{from="0x00007ffff22a5010",to="0x00007ffff22b6365"}]^M
103^running^M
*running,thread-id="5"^M
(gdb) ^M
FAIL: gdb.mi/mi-nsmoribund.exp: 103-exec-continue --all (unexpected output)
...

The regexp expect running messages for all threads, but we only get one for
thread 5.

The test-case uses non-stop mode, and when the exec-continue --all command is
issued, thread 5 is stopped and all other threads are running.  Consequently,
only thread 5 is resumed, and reported as running.

Fix this by updating the regexp.

Tested on x86_64-linux.

2 years agogdb/python: fix memory leak in python inferior code
Andrew Burgess [Fri, 3 Sep 2021 08:23:35 +0000 (09:23 +0100)] 
gdb/python: fix memory leak in python inferior code

When a user creates a gdb.Inferior object for the first time a new
Python object is created.  This object is then cached within GDB's
inferior object using the registry mechanism (see
inferior_to_inferior_object in py-inferior.c, specifically the calls
to inferior_data and set_inferior_data).

The Python Reference to the gdb.Inferior object held within the real
inferior object ensures that the reference count on the Python
gdb.Inferior object never reaches zero while the GDB inferior object
continues to exist.

At the same time, the gdb.Inferior object maintains a C++ pointer back
to GDB's real inferior object.  We therefore end up with a system that
looks like this:

                   Python Reference
                         |
                         |
    .----------.         |          .--------------.
    |          |------------------->|              |
    | inferior |                    | gdb.Inferior |
    |          |<-------------------|              |
    '----------'         |          '--------------'
                         |
                         |
                    C++ Pointer

When GDB's inferior object is deleted (say the inferior exits) then
py_free_inferior is called (thanks to the registry system), this
function looks up the Python gdb.Inferior object and sets the C++
pointer to nullptr and finally reduces the reference count on the
Python gdb.Inferior object.

If at this point the user still holds a reference to the Python
gdb.Inferior object then nothing happens.  However, the gdb.Inferior
object is now in the non-valid state (see infpy_is_valid in
py-inferior.c), but otherwise, everything is fine.

However, if there are no further references to the Python gdb.Inferior
object, or, once the user has given up all their references to the
gdb.Inferior object, then infpy_dealloc is called.

This function currently checks to see if the inferior pointer within
the gdb.Inferior object is nullptr or not.  If the pointer is nullptr
then infpy_dealloc immediately returns.

Only when the inferior point in the gdb.Inferior is not nullptr do
we (a) set the gdb.Inferior reference inside GDB's inferior to
nullptr, and (b) call the underlying Python tp_free function.

There are a number things wrong here:

  1.  The Python gdb.Inferior reference within GDB's inferior object
  holds a reference count, thus, setting this reference to nullptr
  without first decrementing the reference count would leak a
  reference, however...

  2. As GDB's inferior holds a reference then infpy_dealloc will never
  be called until GDB's inferior object is deleted.  Deleting a GDB
  inferior ohject calls py_free_inferior, and so gives up the
  reference.  At this point there is no longer a need to call
  set_inferior_data to set the field back to NULL, that field must
  have been cleared in order to get the reference count to zero, which
  means...

  3. If we know that py_free_inferior must be called before
  infpy_dealloc, then we know that the inferior pointer in
  gdb.Inferior will always be nullptr when infpy_dealloc is called,
  this means that the call to the underlying tp_free function will
  always be skipped.  Skipping this call will cause Python to leak the
  memory associated with the gdb.Inferior object, which is what we
  currently always do.

Given all of the above, I assert that the C++ pointer within
gdb.Inferior will always be nullptr when infpy_dealloc is called.
That's what this patch does.

I wrote a test for this issue making use of Pythons tracemalloc
module, which allows us to spot this memory leak.

2 years ago[gdb/testsuite] Use function_range in gdb.dwarf2/dw2-ref-missing-frame.exp
Bhuvanendra Kumar N [Tue, 5 Oct 2021 11:10:16 +0000 (13:10 +0200)] 
[gdb/testsuite] Use function_range in gdb.dwarf2/dw2-ref-missing-frame.exp

Following 2 test points are failing with clang compiler

(gdb) FAIL: gdb.dwarf2/dw2-ref-missing-frame.exp: func_nofb print
(gdb) FAIL: gdb.dwarf2/dw2-ref-missing-frame.exp: func_loopfb print

As in commit f677852bbda "[gdb/testsuite] Use function_range in
gdb.dwarf2/dw2-abs-hi-pc.exp", the problem is that the CU and functions
have an empty address range, due to using asm labels in global scope,
which is a known source of problems, as explained in the comment of proc
function_range in gdb/testsuite/lib/dwarf.exp.  Hence fix this also by
using function_range.

Tested on x86_64-linux with gcc and clang.

2 years agogdb/python: add a new gdb_exiting event
Andrew Burgess [Tue, 7 Sep 2021 10:45:55 +0000 (11:45 +0100)] 
gdb/python: add a new gdb_exiting event

Add a new event, gdb.events.gdb_exiting, which is called once GDB
decides it is going to exit.

This event is not triggered in the case that GDB performs a hard
abort, for example, when handling an internal error and the user
decides to quit the debug session, or if GDB hits an unexpected,
fatal, signal.

This event is triggered if the user just types 'quit' at the command
prompt, or if GDB is run with '-batch' and has processed all of the
required commands.

The new event type is gdb.GdbExitingEvent, and it has a single
attribute exit_code, which is the value that GDB is about to exit
with.

The event is triggered before GDB starts dismantling any of its own
internal state, so, my expectation is that most Python calls should
work just fine at this point.

When considering this functionality I wondered about using the
'atexit' Python module.  However, this is triggered when the Python
environment is shut down, which is done from a final cleanup.  At
this point we don't know for sure what other GDB state has already
been cleaned up.

2 years agogdb/python: update events test to handle missing exit_code
Andrew Burgess [Wed, 8 Sep 2021 12:27:38 +0000 (13:27 +0100)] 
gdb/python: update events test to handle missing exit_code

The test gdb.python/py-events.exp sets up a handler for the gdb.exited
event.  Unfortunately the handler is slightly broken, it assumes that
the exit_code attribute will always be present.  This is not always
the case.

In a later commit I am going to add more tests to py-events.exp test
script, and in so doing I expose the bug in our handling of gdb.exited
events.

Just to be clear, GDB itself is fine, it is the test that is not
written correctly according to the Python Events API.

So, in this commit I fix the Python code in the test, and extend the
test case to exercise more paths through the Python code.

Additionally, I noticed that the gdb.exited event is used as an
example in the documentation for how to write an event handler.
Unfortunately the same bug that we had in our test was also present in
the example code in the manual.

So I've fixed that too.

After this commit there is no functional change to GDB.

2 years agoAutomatic date update in version.in
GDB Administrator [Tue, 5 Oct 2021 00:00:10 +0000 (00:00 +0000)] 
Automatic date update in version.in

2 years agoUse unique_xmalloc_ptr<char> when demangling
Tom Tromey [Mon, 4 Oct 2021 14:44:22 +0000 (08:44 -0600)] 
Use unique_xmalloc_ptr<char> when demangling

I noticed that some methods in language_defn could use
unique_xmalloc_ptr<char> rather than a plain 'char *'.  This patch
implements this change, fixing up the fallout and changing
gdb_demangle to also return this type.  In one spot, std::string is
used to simplify some related code, and in another, an auto_obstack is
used to avoid manual management.

Regression tested on x86-64 Fedora 34.

2 years agoMinor boolean fix in windows-nat.c
Tom Tromey [Mon, 4 Oct 2021 19:13:48 +0000 (13:13 -0600)] 
Minor boolean fix in windows-nat.c

I noticed a spot in windows-nat.c that used '1' rather than the more
appropriate 'true'.  This patch fixes it.

2 years ago[gdb/build] Add CXX_DIALECT to CXX
Tom de Vries [Mon, 4 Oct 2021 16:51:09 +0000 (18:51 +0200)] 
[gdb/build] Add CXX_DIALECT to CXX

Say we use a gcc version that (while supporting c++11) does not support c++11
by default, and needs an -std setting to enable it.

If gdb would use the default AX_CXX_COMPILE_STDCXX from autoconf-archive, then
we'd have:
...
CXX="g++ -std=gnu++11"
...

That mechanism however has the following problem (quoting from commit
0bcda685399):
...
the top level Makefile passes CXX down to subdirs, and that overrides whatever
gdb/Makefile may set CXX to.  The result would be that a make invocation from
the build/gdb/ directory would use "g++ -std=gnu++11" as expected, while a
make invocation at the top level would not.
...

Commit 0bcda685399 fixes this by using a custom AX_CXX_COMPILE_STDCXX which
does:
...
CXX=g++
CXX_DIALECT=-std=gnu++11
...

The problem reported in PR28318 is that using the custom instead of the
default AX_CXX_COMPILE_STDCXX makes the configure test for std::thread
support fail.

We could simply add $CXX_DIALECT to the test for std::thread support, but
that would have to be repeated for each added c++ support test.

Instead, fix this by doing:
...
CXX="g++ -std=gnu++11"
CXX_DIALECT=-std=gnu++11
...

This is somewhat awkward, since it results in -std=gnu++11 occuring twice in
some situations:
...
$ touch src/gdb/dwarf2/read.c
$ ( cd build/gdb; make V=1 dwarf2/read.o )
g++-4.8 -std=gnu++11 -x c++ -std=gnu++11 ...
...

However, both settings are needed:
 - the switch in CXX for the std::thread tests (and other tests)
 - the switch in CXX_DIALECT so it can be appended in Makefiles, to
   counteract the fact that the top-level Makefile overrides CXX

The code added in gdb/ax_cxx_compile_stdcxx.m4 is copied from the default
AX_CXX_COMPILE_STDCXX from autoconf-archive.

Tested on x86_64-linux.

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

2 years ago[gdb/symtab] Use unrelocated addresses in call_site
Simon Marchi [Mon, 4 Oct 2021 16:16:40 +0000 (18:16 +0200)] 
[gdb/symtab] Use unrelocated addresses in call_site

Consider test-case gdb.trace/entry-values.exp with target board
unix/-fPIE/-pie.

Using this command we have an abbreviated version, and can see the correct
@entry values for foo:
...
$ gdb -q -batch outputs/gdb.trace/entry-values/entry-values \
  -ex start \
  -ex "break foo" \
  -ex "set print entry-values both" \
  -ex continue
Temporary breakpoint 1 at 0x679

Temporary breakpoint 1, 0x0000555555554679 in main ()
Breakpoint 2 at 0x55555555463e

Breakpoint 2, 0x000055555555463e in foo (i=0, i@entry=2, j=2, j@entry=3)
...

Now, let's try the same again, but run directly to foo rather than stopping at
main:
...
$ gdb -q -batch outputs/gdb.trace/entry-values/entry-values \
  -ex "break foo" \
  -ex "set print entry-values both" \
  -ex run
Breakpoint 1 at 0x63e

Breakpoint 1, 0x000055555555463e in foo (i=0, i@entry=<optimized out>, \
  j=2, j@entry=<optimized out>)
...

So, what explains the difference?  Noteworthy, this is a dwarf assembly
test-case, with debug info for foo and bar, but not for main.

In the first case:
- we run to main
- this does not trigger expanding debug info, because there's none for main
- we set a breakpoint at foo
- this triggers expanding debug info.  Relocated addresses are used in
  call_site info (because the exec is started)
- we continue to foo, and manage to find the call_site info

In the second case:
- we set a breakpoint at foo
- this triggers expanding debug info.  Unrelocated addresses are used in
  call_site info (because the exec is not started)
- we run to foo
- this triggers objfile_relocate1, but it doesn't update the call_site
  info addresses
- we don't manage to find the call_site info

We could fix this by adding the missing call_site relocation in
objfile_relocate1.

This solution however is counter-trend in the sense that we're trying to
work towards the situation where when starting two instances of an executable,
we need only one instance of debug information, implying the use of
unrelocated addresses.

So, fix this instead by using unrelocated addresses in call_site info.

Tested on x86_64-linux.

This fixes all remaining unix/-fno-PIE/-no-pie vs unix/-fPIE/-pie
regressions, like f.i. PR24892.

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

Co-Authored-By: Tom de Vries <tdevries@suse.de>
2 years ago[gdb/symtab] C++-ify call_site
Simon Marchi [Mon, 4 Oct 2021 16:16:40 +0000 (18:16 +0200)] 
[gdb/symtab] C++-ify call_site

- add constructor
- add member function call_site::pc ()

Tested on x86_64-linux.

Co-Authored-By: Tom de Vries <tdevries@suse.de>
2 years ago[gdb/symtab] Add call_site_eq and call_site_hash
Tom de Vries [Mon, 4 Oct 2021 16:16:40 +0000 (18:16 +0200)] 
[gdb/symtab] Add call_site_eq and call_site_hash

In commit b4c919f7525 "[gdb/symtab] Fix htab_find_slot call in
read_call_site_scope" , I removed the comment:
...
It must be the first field as we overload core_addr_hash and core_addr_eq for
it.
...
for field pc of struct call_site.

However, this was not tested, and when indeed moving field pc to the second
location, we run into a testsuite failure in gdb.trace/entry-values.exp.

This is caused by core_addr_eq (the eq_f function for the htab) being
called with a pointer to the pc field (as passed into htab_find_slot) and a
pointer to a hash table element.  Now that pc is no longer the first field,
the pointer to hash table element no longer points to the pc field.

This could be fixed by simply reinstating the comment, but we're trying to
get rid of this kind of tricks that make refactoring more difficult.

Instead, fix this by:
- reverting commit b4c919f7525, apart from the comment removal, such that
  we're passing a pointer to element to htab_find_slot
- updating the htab_find_slot call in compunit_symtab::find_call_site
  in a similar manner
- adding a call_site_eq and call_site_hash, and using these in the hash table
  instead of core_addr_eq and core_addr_hash.

Tested on x86_64-linux, both with and without a trigger patch that moves pc to
the second location in struct call_site.

2 years agoFix remote-sim.c compilation
Tom Tromey [Mon, 4 Oct 2021 15:14:26 +0000 (09:14 -0600)] 
Fix remote-sim.c compilation

The change "make string-like set show commands use std::string
variable" caused remote-sim.c to fail to build.  The issue is that the
code does:

  const std::string &sysroot = gdb_sysroot;
  if (is_target_filename (sysroot))
    sysroot += strlen (TARGET_SYSROOT_PREFIX);

... which isn't valid.

This patch changes this code to use a 'const char *' again, fixing the
build.

2 years ago[gdb/testsuite] update analyze-racy-logs.py to python3
Bruno Larsen [Fri, 1 Oct 2021 18:18:09 +0000 (15:18 -0300)] 
[gdb/testsuite] update analyze-racy-logs.py to python3

Since python 2 is no longer supported on most distributions, update the
script to run under python while while still being runnable under
python2.

2 years agogdbsupport: remove attempt to define TARGET_WORD_SIZE
Andrew Burgess [Thu, 23 Sep 2021 17:20:09 +0000 (18:20 +0100)] 
gdbsupport: remove attempt to define TARGET_WORD_SIZE

In the gdbsupport configure.ac file, there is an attempt to define
TARGET_WORD_SIZE.  This is done by running grep on the file
../bfd/bfd-in3.h.

The problem with this is, the file bfd-in3.h is generated into the bfd
build directory when bfd is configured, and there is no dependency
between the gdbsupport module and the bfd module, so, for example, if
I do:

  $ ../src/configure
  $ make all-gdbsupport

Then bfd will neither be configured, or built.  In this case
TARGET_WORD_SIZE ends up being defined, but with no value because the
grep on bfd-in3.h fails.

However, it turns out that this doesn't matter; we don't actually use
TARGET_WORD_SIZE anywhere.

My proposal in this commit is to just remove the definition of
TARGET_WORD_SIZE, the alternative would be to add a dependency between
configure-gdbsupport and configure-bfd into Makefile.def, but adding a
dependency for something we don't need seems pretty pointless.

2 years agosim: add --info-target for listing supported BFD targets
Mike Frysinger [Mon, 4 Oct 2021 06:11:21 +0000 (02:11 -0400)] 
sim: add --info-target for listing supported BFD targets

It can be difficult to guess the exact bfd name, so add an option to
list all the targets that the current build supports.  This aligns with
other simulator options like --info-architecture.

2 years agoAutomatic date update in version.in
GDB Administrator [Mon, 4 Oct 2021 00:00:10 +0000 (00:00 +0000)] 
Automatic date update in version.in

2 years agogdb: Setting setter return a bool to tell if the value changed
Lancelot SIX [Tue, 14 Sep 2021 22:37:25 +0000 (23:37 +0100)] 
gdb: Setting setter return a bool to tell if the value changed

GDB can notify observers when a parameter is changed.

To do that, do_set_command (in gdb/cli/cli-setshow.c) compares the new
value against the old one before updating it, and based on that notifies
observers.  This looks like something like:

    int valuechanged = 0;
    switch (cmd->var.type ())
    {
    case var_integer:
      {
        LONGEST new_val = parse_and_eval_long (arg)
        if (new_val != cmd->var.get<int> ())
        {
          cmd->var.get<int> (new_val);
          value_changes = 1;
        }
      }
    case var_uinteger:
    case var_zuinteger:
      {
        unsigned int val
          = parse_cli_var_uinteger (c->var->type (), &arg, true);
        if (c->var->get<unsigned int> () != val)
          {
            c->var->set<unsigned int> (val);
            option_changed = true;
          }
      }
    case...
      /* And so on for all possible var_types.  */
    }

This comparison is done for each possible var_type, which leads to
unnecessary logic duplication.

In this patch I propose to move all those checks in one place within the
setting setter method.  This limits the code duplication and simplifies
the do_set_command implementation.

This patch also changes slightly the way a value change is detected.
Instead of comparing the user provided value against the current value
of the setting, we compare the value of the setting before and after the
set operation.  This is meant to handle edge cases where trying to set
an unrecognized value would be equivalent to a noop (the actual value
remains unchanged).  Doing this requires that the original value needs
to be copied before the update, which can be non trivial for
std::string.

There should be no user visible change introduced by this commit.

Tested on x86_64 GNU/Linux.

[1] https://review.lttng.org/c/binutils-gdb/+/5831/41

Change-Id: If064b9cede3eb56275aacd2b286f74eceb1aed11

2 years agogdb: Have setter and getter callbacks for settings
Lancelot SIX [Tue, 14 Sep 2021 22:36:53 +0000 (23:36 +0100)] 
gdb: Have setter and getter callbacks for settings

The main motivation behind this improvement is to help the
implementation of a patch Simon Marchi is preparing to fix a bug when
MI or Python try to access parameters that are inferior dependent (see
PR/28085).

This commit extends the previous ones, which introduces the setting
object to represent a static variable whose value can be set or shown
with the appropriate commands.  This patch proposes that a setting can
either contain a pointer to a static variable holding a setting, or
pointers to a pair of setter and getter callback functions.

The callbacks functions can be used to retrieve or change the value with
custom logic.  This is useful when the source of truth for a given
setting is not contained in the variable pointed to by the setting
instance.

Given that the callback function call is hidden within the setting
abstraction introduced earlier, none of the sites accessing the setting
needs to be updated.  The registered getter or setter is used whatever
the way to access it is (through MI, Python, Guile, the "with" command
and the $_gdb_setting / $_gdb_setting_str convenience functions).

All the add_setshow_*_cmd are given a new overload that will accept the
pair of function pointers (set / get functions) instead of the pointer
to a global variable.

Tested on GNU/Linux x86_64 with no regression observed.

Change-Id: Ieb81fef57550632ff66e6aa85f637372a226be8c
Co-authored-by: Simon Marchi <simon.marchi@polymtl.ca>
2 years agogdb: make string-like set show commands use std::string variable
Simon Marchi [Fri, 10 Sep 2021 21:10:13 +0000 (17:10 -0400)] 
gdb: make string-like set show commands use std::string variable

String-like settings (var_string, var_filename, var_optional_filename,
var_string_noescape) currently take a pointer to a `char *` storage
variable (typically global) that holds the setting's value.  I'd like to
"mordernize" this by changing them to use an std::string for storage.

An obvious reason is that string operations on std::string are often
easier to write than with C strings.  And they avoid having to do any
manual memory management.

Another interesting reason is that, with `char *`, nullptr and an empty
string often both have the same meaning of "no value".  String settings
are initially nullptr (unless initialized otherwise).  But when doing
"set foo" (where `foo` is a string setting), the setting now points to
an empty string.  For example, solib_search_path is nullptr at startup,
but points to an empty string after doing "set solib-search-path".  This
leads to some code that needs to check for both to check for "no value".
Or some code that converts back and forth between NULL and "" when
getting or setting the value.  I find this very error-prone, because it
is very easy to forget one or the other.  With std::string, we at least
know that the variable is not "NULL".  There is only one way of
representing an empty string setting, that is with an empty string.

I was wondering whether the distinction between NULL and "" would be
important for some setting, but it doesn't seem so.  If that ever
happens, it would be more C++-y and self-descriptive to use
optional<string> anyway.

Actually, there's one spot where this distinction mattered, it's in
init_history, for the test gdb.base/gdbinit-history.exp.  init_history
sets the history filename to the default ".gdb_history" if it sees that
the setting was never set - if history_filename is nullptr.  If
history_filename is an empty string, it means the setting was explicitly
cleared, so it leaves it as-is.  With the change to std::string, this
distinction doesn't exist anymore.  This can be fixed by moving the code
that chooses a good default value for history_filename to
_initialize_top.  This is ran before -ex commands are processed, so an
-ex command can then clear that value if needed (what
gdb.base/gdbinit-history.exp tests).

Another small improvement, in my opinion is that we can now easily
give string parameters initial values, by simply initializing the global
variables, instead of xstrdup-ing it in the _initialize function.

In Python and Guile, when registering a string-like parameter, we
allocate (with new) an std::string that is owned by the param_smob (in
Guile) and the parmpy_object (in Python) objects.

This patch started by changing all relevant add_setshow_* commands to
take an `std::string *` instead of a `char **` and fixing everything
that failed to build.  That includes of course all string setting
variable and their uses.

string_option_def now uses an std::string also, because there's a
connection between options and settings (see
add_setshow_cmds_for_options).

The add_path function in source.c is really complex and twisted, I'd
rather not try to change it to work on an std::string right now.
Instead, I added an overload that copies the std:string to a `char *`
and back.  This means more copying, but this is not used in a hot path
at all, so I think it is acceptable.

Change-Id: I92c50a1bdd8307141cdbacb388248e4e4fc08c93
Co-authored-by: Lancelot SIX <lsix@lancelotsix.com>