deliverable/binutils-gdb.git
3 years agoRISC-V: Add sext.[bh] and zext.[bhw] pseudo instructions.
Nelson Chu [Wed, 9 Dec 2020 05:53:22 +0000 (13:53 +0800)] 
RISC-V: Add sext.[bh] and zext.[bhw] pseudo instructions.

https://github.com/riscv/riscv-asm-manual/pull/61

We aleady have sext.w, so just add sext.b, sext.h, zext.b, zext.h
and zext.w.  In a certain sense, zext.b is not a pseudo - It is an
alias of andi.  Similarly, sext.b and sext.h are aliases of other
rvb instructions, when we enable b extension; But they are pseudos
when we just enable rvi.  However, this patch does not consider the
rvb cases.  Besides, zext.w is only valid in rv64.

gas/
    * config/tc-riscv.c (riscv_ext): New function.  Use md_assemblef
    to expand the zext and sext pseudos, to give them a chance to be
    expanded into c-ext instructions.
    (macro): Handle M_ZEXTH, M_ZEXTW, M_SEXTB and M_SEXTH.
    * testsuite/gas/riscv/ext.s: New testcase.
    * testsuite/gas/riscv/ext-32.d: Likewise.
    * testsuite/gas/riscv/ext-64.d: Likewise.
include/
    * opcode/riscv.h (M_ZEXTH, M_ZEXTW, M_SEXTB, M_SEXTH.): Added.
opcodes/
    * riscv-opc.c (riscv_opcodes): Add sext.[bh] and zext.[bhw].

3 years agoRISC-V: Dump CSR according to the elf privileged spec attributes.
Nelson Chu [Tue, 8 Dec 2020 06:39:01 +0000 (14:39 +0800)] 
RISC-V: Dump CSR according to the elf privileged spec attributes.

opcodes/
    * disassemble.h (riscv_get_disassembler): Declare.
    * disassemble.c (disassembler): Changed to riscv_get_disassembler.
    * riscv-dis.c (riscv_get_disassembler): Check the elf privileged spec
    attributes before calling print_insn_riscv.
    (parse_riscv_dis_option): Same as the assembler, the priority of elf
    attributes are higher than the options.  If we find the privileged
    attributes, but the -Mpriv-spec= is different, then output error/warning
    and still use the elf attributes set.

3 years agoRISC-V: Control fence.i and csr instructions by zifencei and zicsr.
Nelson Chu [Wed, 2 Dec 2020 09:18:35 +0000 (17:18 +0800)] 
RISC-V: Control fence.i and csr instructions by zifencei and zicsr.

bfd/
    * elfxx-riscv.c (riscv_ext_dont_care_version): New function.  Return
    TRUE if we don't care the versions of the extensions.  These extensions
    are added to the subset list for special purposes, with the explicit
    versions or the RISCV_UNKNOWN_VERSION versions.
    (riscv_parse_add_subset): If we do care the versions of the extension,
    and the versions are unknown, then report errors for the non-implicit
    extensions, and return directly for the implicit one.
    (riscv_arch_str1): Do not output i extension after e, and the extensions
    which versions are unknown.
gas/
    * config/tc-riscv.c (riscv_multi_subset_supports): Handle INSN_CLASS_ZICSR
    and INSN_CLASS_ZIFENCEI.
    * testsuite/gas/riscv/march-imply-i.s: New testcase.
    * testsuite/gas/riscv/march-imply-i2p0-01.d: New testcase.  The version
    of i is less than 2.1, and zi* are supported in the chosen spec, so
    enable the fence.i and csr instructions, also output the implicit zi* to
    the arch string.
    * testsuite/gas/riscv/march-imply-i2p0-02.d: Likewise, but the zi* are
    not supported in the spec 2.2.  Enable the related instructions since
    i's version is less than 2.1, but do not output them.
    * testsuite/gas/riscv/march-imply-i2p1-01.d: New testcase.  The version
    of i is 2.1, so don't add it's implicit zi*, and disable the related
    instructions.
    * testsuite/gas/riscv/march-imply-i2p1-01.l: Likewise.
    * testsuite/gas/riscv/march-imply-i2p1-02.d: Likewise, and set the zi*
    explicitly, so enable the related instructions.
    * testsuite/gas/riscv/march-imply-i2p0.d: Removed.
    * testsuite/gas/riscv/march-imply-i2p1.d: Removed.
include/
    * opcode/riscv.h: Add INSN_CLASS_ZICSR and INSN_CLASS_ZIFENCEI.
opcodes/
    * riscv-opc.c (riscv_opcodes): Control fence.i and csr instructions by
    zifencei and zicsr.

3 years agoAutomatic date update in version.in
GDB Administrator [Thu, 10 Dec 2020 00:00:16 +0000 (00:00 +0000)] 
Automatic date update in version.in

3 years agoUse add_angle_brackets in ada_lookup_encoded_symbol
Tom Tromey [Wed, 9 Dec 2020 21:17:15 +0000 (14:17 -0700)] 
Use add_angle_brackets in ada_lookup_encoded_symbol

Joel recently pointed out add_angle_brackets to me.  This patch
changes one spot in ada-lang.c to use this function rather than doing
it on its own.

gdb/ChangeLog
2020-12-09  Tom Tromey  <tromey@adacore.com>

* ada-lang.c (ada_lookup_encoded_symbol): Use add_angle_brackets.

3 years agoHandle 128-bit constants for fixed point
Tom Tromey [Wed, 9 Dec 2020 21:12:58 +0000 (14:12 -0700)] 
Handle 128-bit constants for fixed point

In some cases, GNAT can emit 128-bit constants for fixed-point types.
This patch changes gdb to handle this scenario, by changing the
low-level rational-reading functions in dwarf2/read.c to work directly
with gdb_mpz values.  (I'm not sure offhand if these 128-bit patches
have gone into upstream GCC yet -- but they will eventually, and
meanwhile I think it should be clear that this patch is otherwise
harmless.)

gdb/ChangeLog
2020-12-09  Tom Tromey  <tromey@adacore.com>

* dwarf2/read.c (get_dwarf2_rational_constant): Change "numerator"
and "denominator" to gdb_mpz.  Handle block forms.
(get_dwarf2_unsigned_rational_constant): Change "numerator" and
"denominator" to gdb_mpz.
(finish_fixed_point_type): Update.
(has_zero_over_zero_small_attribute): Update.

3 years agoUnify all operators into std-operator.def
Tom Tromey [Wed, 9 Dec 2020 20:43:44 +0000 (13:43 -0700)] 
Unify all operators into std-operator.def

This removes ada-operator.def and fortran-operator.def, merging their
contents into std-operator.def.

Note that the comment for OP_EXTENDED0 is a bit wrong.  IMO this
constant could be removed, as it is only used for a single assert that
does not provide much value.  However, I haven't done so here.

gdb/ChangeLog
2020-12-09  Tom Tromey  <tromey@adacore.com>

* expprint.c (op_name): Update.
* expression.h (enum exp_opcode): Update.
* std-operator.def: Add more opcodes.
* ada-operator.def, fortran-operator.def: Remove, moving contents
into std-operator.def.

3 years agogdb: address review comments of previous series
Simon Marchi [Wed, 9 Dec 2020 19:49:02 +0000 (14:49 -0500)] 
gdb: address review comments of previous series

I forgot to include fixes for review comments I got before pushing the
previous commits (or I pushed the wrong commits).  This one fixes it.

 - Return {} instead of false in get_discrete_low_bound and
   get_discrete_high_bound.
 - Compute high bound after confirming low bound is valid in
   get_discrete_bounds.

gdb/ChangeLog:

* gdbtypes.c (get_discrete_low_bound, get_discrete_high_bound):
Return {} instead of false.
(get_discrete_bounds): Compute high bound only if low bound is
valid.

Change-Id: I5f9a66b3672adfac9441068c899ab113ab2c331a

3 years agogdb: fix value_subscript when array upper bound is not known
Simon Marchi [Wed, 9 Dec 2020 18:52:12 +0000 (13:52 -0500)] 
gdb: fix value_subscript when array upper bound is not known

Since commit 7c6f27129631 ("gdb: make get_discrete_bounds check for
non-constant range bounds"), subscripting  flexible array member fails:

    struct no_size
    {
      int n;
      int items[];
    };

    (gdb) p *ns
    $1 = {n = 3, items = 0x5555555592a4}
    (gdb) p ns->items[0]
    Cannot access memory at address 0xfffe555b733a0164
    (gdb) p *((int *) 0x5555555592a4)
    $2 = 101  <--- we would expect that
    (gdb) p &ns->items[0]
    $3 = (int *) 0xfffe5559ee829a24  <--- wrong address

Since the flexible array member (items) has an unspecified size, the array type
created for it in the DWARF doesn't have dimensions (this is with gcc 9.3.0,
Ubuntu 20.04):

    0x000000a4:   DW_TAG_array_type
                    DW_AT_type [DW_FORM_ref4]       (0x00000038 "int")
                    DW_AT_sibling [DW_FORM_ref4]    (0x000000b3)

    0x000000ad:     DW_TAG_subrange_type
                      DW_AT_type [DW_FORM_ref4]     (0x00000031 "long unsigned int")

This causes GDB to create a range type (TYPE_CODE_RANGE) with a defined
constant low bound (dynamic_prop with kind PROP_CONST) and an undefined
high bound (dynamic_prop with kind PROP_UNDEFINED).

value_subscript gets both bounds of that range using
get_discrete_bounds.  Before commit 7c6f27129631, get_discrete_bounds
didn't check the kind of the dynamic_props and would just blindly read
them as if they were PROP_CONST.  It would return 0 for the high bound,
because we zero-initialize the range_bounds structure.  And it didn't
really matter in this case, because the returned high bound wasn't used
in the end.

Commit 7c6f27129631 changed get_discrete_bounds to return a failure if
either the low or high bound is not a constant, to make sure we don't
read a dynamic prop that isn't a PROP_CONST as a PROP_CONST.  This
change made get_discrete_bounds start to return a failure for that
range, and as a result would not set *lowp and *highp.  And since
value_subscript doesn't check get_discrete_bounds' return value, it just
carries on an uses an uninitialized value for the low bound.  If
value_subscript did check the return value of get_discrete_bounds, we
would get an error message instead of a bogus value.  But it would still
be a bug, as we wouldn't be able to print the flexible array member's
elements.

Looking at value_subscript, we see that the low bound is always needed,
but the high bound is only needed if !c_style.  So, change
value_subscript to use get_discrete_low_bound and
get_discrete_high_bound separately.  This fixes the case described
above, where the low bound is known but the high bound isn't (and is not
needed).  This restores the original behavior without accessing a
dynamic_prop in a wrong way.

A test is added.  In addition to the case described above, a case with
an array member of size 0 is added, which is a GNU C extension that
existed before flexible array members were introduced.  That case
currently fails when compiled with gcc <= 8.  gcc <= 8 produces DWARF
similar to the one shown above, while gcc 9 adds a DW_AT_count of 0 in
there, which makes the high bound known.  A case where an array member
of size 0 is the only member of the struct is also added, as that was
how PR 28675 was originally reported, and it's an interesting corner
case that I think could trigger other funny bugs.

Question about the implementation: in value_subscript, I made it such
that if the low or high bound is unknown, we fall back to zero.  That
effectively makes it the same as it was before 7c6f27129631.  But should
we instead error() out?

gdb/ChangeLog:

PR 26875, PR 26901
* gdbtypes.c (get_discrete_low_bound): Make non-static.
(get_discrete_high_bound): Make non-static.
* gdbtypes.h (get_discrete_low_bound): New declaration.
(get_discrete_high_bound): New declaration.
* valarith.c (value_subscript): Only fetch high bound if
necessary.

gdb/testsuite/ChangeLog:

PR 26875, PR 26901
* gdb.base/flexible-array-member.c: New test.
* gdb.base/flexible-array-member.exp: New test.

Change-Id: I832056f80e6c56f621f398b4780d55a3a1e299d7

3 years agogdb: split get_discrete_bounds in two
Simon Marchi [Wed, 9 Dec 2020 18:52:03 +0000 (13:52 -0500)] 
gdb: split get_discrete_bounds in two

get_discrete_bounds is not flexible for ranges (TYPE_CODE_RANGE), in the
sense that it returns true (success) only if both bounds are present and
constant values.

This is a problem for code that only needs to know the low bound and
fails unnecessarily if the high bound is unknown.

Split the function in two, get_discrete_low_bound and
get_discrete_high_bound, that both return an optional.  Provide a new
implementation of get_discrete_bounds based on the two others, so the
callers don't have to be changed.

gdb/ChangeLog:

* gdbtypes.c (get_discrete_bounds): Implement with
get_discrete_low_bound and get_discrete_high_bound.
(get_discrete_low_bound): New.
(get_discrete_high_bound): New.

Change-Id: I986b5e9c0dd969800e3fb9546af9c827d52e80d0

3 years agogdb: make get_discrete_bounds return bool
Simon Marchi [Wed, 9 Dec 2020 18:51:57 +0000 (13:51 -0500)] 
gdb: make get_discrete_bounds return bool

get_discrete_bounds currently has three possible return values (see its
current doc for details).  It appears that for all callers, it would be
sufficient to have a boolean "worked" / "didn't work" return value.

Change the return type of get_discrete_bounds to bool and adjust all
callers.  Doing so simplifies the following patch.

gdb/ChangeLog:

* gdbtypes.h (get_discrete_bounds): Return bool, adjust all
callers.
* gdbtypes.c (get_discrete_bounds): Return bool.

Change-Id: Ie51feee23c75f0cd7939742604282d745db59172

3 years agogdb: make discrete_position return optional
Simon Marchi [Wed, 9 Dec 2020 18:51:45 +0000 (13:51 -0500)] 
gdb: make discrete_position return optional

Instead of returning a boolean status and returning the value through a
pointer, return an optional that does both jobs.  This helps in the
following patches, and I think it is an improvement in general.

gdb/ChangeLog:

* ada-lang.c (ada_value_slice_from_ptr): Adjust.
(ada_value_slice): Adjust.
(pos_atr): Adjust.
* gdbtypes.c (get_discrete_bounds): Adjust.
(discrete_position): Return optional.
* gdbtypes.h (discrete_position): Return optional.

Change-Id: I758dbd8858b296ee472ed39ec35db1dbd624a5ae

3 years agogas: Generate a new section for SHF_GNU_RETAIN
H.J. Lu [Wed, 9 Dec 2020 00:41:22 +0000 (16:41 -0800)] 
gas: Generate a new section for SHF_GNU_RETAIN

For
.globl foo2
.section .data.foo,"aR"
.align 4
.type foo2, @object
.size foo2, 4
foo2:
.long 2
.globl foo1
.section .data.foo
.align 4
.type foo1, @object
.size foo1, 4
foo1:
.long 1

generate a new section if the SHF_GNU_RETAIN bit doesn't match.

* config/obj-elf.c (SEC_ASSEMBLER_SHF_MASK): New.
(get_section_by_match): Also check if SEC_ASSEMBLER_SHF_MASK of
sh_flags matches.  Rename info to sh_info.
(obj_elf_change_section): Don't check previous SHF_GNU_RETAIN.
Rename info to sh_info.
(obj_elf_section): Rename info to sh_info.  Set sh_flags for
SHF_GNU_RETAIN.
* config/obj-elf.h (elf_section_match): Rename info to sh_info.
Add sh_flags.
* testsuite/gas/elf/elf.exp: Run section27.
* testsuite/gas/elf/section24b.d: Updated.
* testsuite/gas/elf/section27.d: New file.
* testsuite/gas/elf/section27.s: Likewise.

3 years agoAutomatic date update in version.in
GDB Administrator [Wed, 9 Dec 2020 00:00:17 +0000 (00:00 +0000)] 
Automatic date update in version.in

3 years agogdbsupport: Use LOCALAPPDATA to determine cache dir
Alexander Fedotov [Tue, 8 Dec 2020 10:07:23 +0000 (13:07 +0300)] 
gdbsupport: Use LOCALAPPDATA to determine cache dir

Use the LOCALAPPDATA environment variable to determine the cache dir
when running on Windows with native command line, otherwise nasty
warning "Couldn't determine a path for index cached directory" appears.

Change-Id: I77903f9f0cb4743555866b8aea892cef55132589

3 years ago[gdb/testsuite] Simplify gdb.arch/amd64-gs_base.exp
Tom de Vries [Tue, 8 Dec 2020 08:29:40 +0000 (09:29 +0100)] 
[gdb/testsuite] Simplify gdb.arch/amd64-gs_base.exp

Redo fix committed in commit 67748e0f66 "[gdb/testsuite] Make
gdb.arch/amd64-gs_base.exp unsupported for i386" using is_amd64_regs_target.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-12-08  Tom de Vries  <tdevries@suse.de>

* gdb.arch/amd64-gs_base.exp: Undo commit 67748e0f66, reimplement
using is_amd64_regs_target.

3 years ago[gdb/testsuite] Fix gdb.ada/mi_task_arg.exp for -m32
Tom de Vries [Tue, 8 Dec 2020 08:29:40 +0000 (09:29 +0100)] 
[gdb/testsuite] Fix gdb.ada/mi_task_arg.exp for -m32

When running test-case gdb.ada/mi_task_arg.exp with target board unix/-m32, I
run into:
...
(gdb) ^M
Expecting: ^(-stack-list-arguments 1[^M
]+)?(\^done,stack-args=\[ \
  frame={level="0",args=\[\]}, \
  frame={level="1",args=\[{name="<_task>",value="0x[0-9A-Fa-f]+"}\]}, \
  frame={level="2",args=\[({name="self_id",value="0x[0-9A-Fa-f]+"})?\]},.*[^M
]+[(]gdb[)] ^M
[ ]*)
-stack-list-arguments 1^M
^done,stack-args=[ \
  frame={level="0",args=[]}, \
  frame={level="1",args=[{name="<_task>",value="0x808abf0"}]}, \
  frame={level="2",args=[{name="self_id",value="<optimized out>"}]}, \
  frame={level="3",args=[]},frame={level="4",args=[]}]^M
(gdb) ^M
FAIL: gdb.ada/mi_task_arg.exp: -stack-list-arguments 1 (unexpected output)
...

The problem is that we're expecting a $hex for the value of self_id, but
instead get <optimized out>.

Looking at the debug info for self_id:
...
 <1><12a1f>: Abbrev Number: 84 (DW_TAG_subprogram)
    <12a20>   DW_AT_name        : system__tasking__stages__task_wrapper
    ...
 <2><12a35>: Abbrev Number: 61 (DW_TAG_formal_parameter)
    <12a36>   DW_AT_name        : self_id
    <12a40>   DW_AT_location    : 0x459e (location list)
...
it refers to location information here:
...
    0000459e 08053060 080531ac (DW_OP_fbreg: 0)
    000045aa 0805327c 080532a5 (DW_OP_fbreg: 0)
    000045b6 08053320 08053324 (DW_OP_fbreg: 0)
...
while the pc used to retrieve the location information is 0x080531c5:
...
 $ gdb -batch outputs/gdb.ada/mi_task_arg/task_switch \
   -ex "break 57" -ex run -ex bt
   ...
 #0  task_switch.break_me () at task_switch.adb:57
 #1  0x0804aaae in task_switch.caller (<_task>=0x808abf0) \
                     at task_switch.adb:51
 #2  0x080531c5 in system.tasking.stages.task_wrapper \
                     (self_id=<optimized out>) at s-tassta.adb:1295
...
which indeed falls outside of the ranges listed in the location info.

Fix this by accepting <optimized out> as valid value of self_id.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-12-08  Tom de Vries  <tdevries@suse.de>

* gdb.ada/mi_task_arg.exp: Accept <optimized out> as valid value of
self_id.

3 years agoAutomatic date update in version.in
GDB Administrator [Tue, 8 Dec 2020 00:00:18 +0000 (00:00 +0000)] 
Automatic date update in version.in

3 years agogdb.base/break-on-linker-gcd-function.exp: Remove unused variable
Pedro Alves [Mon, 7 Dec 2020 18:55:08 +0000 (18:55 +0000)] 
gdb.base/break-on-linker-gcd-function.exp: Remove unused variable

Commit:

 commit 4d142eaa28c64565b58fcdb5a83377ec9b778cb1
 Author:     Jan Kratochvil <jan.kratochvil@redhat.com>
 AuthorDate: Tue Jul 2 20:06:12 2013 +0000

     gdb/testsuite/
     * gdb.base/break-on-linker-gcd-function.exp: Replace
     prepare_for_testing by build_executable_from_specs and clean_restart.
 ...

did:

 set additional_flags {-ffunction-sections -Wl,--gc-sections}
 -if {[prepare_for_testing $testfile.exp $testfile $srcfile \
 -        [list debug c++ additional_flags=$additional_flags]]} {
 +if {[build_executable_from_specs $testfile.exp $testfile \
 +       {c++ additional_flags=-Wl,--gc-sections} \
 +       $srcfile {debug c++ additional_flags=-ffunction-sections}]} {

and that left the additional_flags variable behind.  Remove it.

gdb/testsuite/ChangeLog:

* gdb.base/break-on-linker-gcd-function.exp: Remove unused
'additional_flags' variable.

3 years agoRemove references to the unofficial SHF_GNU_BUILD_NOTE section flag.
Nick Clifton [Mon, 7 Dec 2020 16:17:40 +0000 (16:17 +0000)] 
Remove references to the unofficial SHF_GNU_BUILD_NOTE section flag.

binutils * objcopy.c (is_mergeable_note_section): Remove reference to
SHF_GNU_BUILD_NOTE.

include * elf/common.h (SHF_GNU_BUILD_NOTE): Delete.

3 years agobinutils: Make smart_rename safe too
Siddhesh Poyarekar [Mon, 7 Dec 2020 15:18:33 +0000 (20:48 +0530)] 
binutils: Make smart_rename safe too

smart_rename is capable of handling symlinks by copying and it also
tries to preserve ownership and permissions of files when they're
overwritten during the rename.  This is useful in objcopy where the
file properties need to be preserved.

However because smart_rename does this using file names, it leaves a
race window between renames and permission fixes.  This change removes
this race window by using file descriptors from the original BFDs that
were used to manipulate these files wherever possible.

The file that is to be renamed is also passed as a file descriptor so
that we use fchown/fchmod on the file descriptor, thus making sure
that we only modify the file we have opened to write.  Further, in
case the file is to be overwritten (as is the case in ar or objcopy),
the permissions that need to be restored are taken from the file
descriptor that was opened for input so that integrity of the file
status is maintained all the way through to the rename.

binutils/

* rename.c
* ar.c
(write_archive) [!defined (_WIN32) || defined (__CYGWIN32__)]:
Initialize TARGET_STAT and OFD to pass to SMART_RENAME.
* arsup.c
(ar_save) [defined (_WIN32) || defined (__CYGWIN32__)]:
Likewise.
* bucomm.h (smart_rename): Add new arguments to declaration.
* objcopy.c
(strip_main)[defined (_WIN32) || defined (__CYGWIN32__)]:
Initialize COPYFD and pass to SMART_RENAME.
(copy_main) [defined (_WIN32) || defined (__CYGWIN32__)]:
Likewise.
* rename.c (try_preserve_permissions): New function.
(smart_rename): Use it and add new arguments.

3 years agoobjcopy: Get input file stat after BFD open
Siddhesh Poyarekar [Mon, 7 Dec 2020 15:18:28 +0000 (20:48 +0530)] 
objcopy: Get input file stat after BFD open

Get file state from the descriptor opened by copy_file for the input
BFD.  This ensures continuity in the view of the input file through
the descriptor.  At the moment it is only to preserve timestamps
recorded at the point that we opened the file for input but in the
next patch this state will also be used to preserve ownership and
permissions wherever applicable.

binutils/

* objcopy.c (copy_file): New argument IN_STAT.  Return stat of
ibfd through it.
(strip_main): Remove redundant stat calls.  adjust copy_file
calls.
(copy_main): Likewise.

3 years agobinutils: Use file descriptors from make_tempname
Siddhesh Poyarekar [Mon, 7 Dec 2020 15:18:23 +0000 (20:48 +0530)] 
binutils: Use file descriptors from make_tempname

The purpose of creating a temporary file securely using mkstemp is
defeated if it is closed in make_tempname and reopened later for use;
it is as good as using mktemp.  Get the file descriptor instead and
then use it to create the BFD object.

bfd/

* opncls.c (bfd_fdopenw): New function.
* bfd-in2.h: Regenerate.

binutils/

* bucomm.c (make_tempname): Add argument to return file
descriptor.
* bucomm.h (make_tempname): Likewise.
* ar.c: Include libbfd.h.
(write_archive): Adjust for change in make_tempname.  Call
bfd_fdopenw instead of bfd_openw.
* objcopy.c: Include libbfd.h.
(copy_file): New argument OFD.  Use bfd_fdopenw instead of
bfd_openw.
(strip_main): Adjust for change in make_tempname and
copy_file.
(copy_main): Likewise.

3 years agoUse expression completer for "maint print type"
Tom Tromey [Mon, 7 Dec 2020 14:33:46 +0000 (07:33 -0700)] 
Use expression completer for "maint print type"

I happened to notice that expression completion did not work correctly
for "maint print type".  This patch adds the appropriate completer
there.

gdb/ChangeLog
2020-12-07  Tom Tromey  <tromey@adacore.com>

* maint.c (_initialize_maint_cmds): Use expression command
completer for "maint print type".

3 years ago[GOLD] gcc-11 stringop-overflow warning
Alan Modra [Mon, 7 Dec 2020 06:46:46 +0000 (17:16 +1030)] 
[GOLD] gcc-11 stringop-overflow warning

I'm unsure why this is deserving of a warning.  Not writing the most
efficient code surely can't be a real problem, but that is what
https://gcc.gnu.org/bugzilla//show_bug.cgi?id=88059#c1 seems to say.

plugin.cc:528:10: error: 'char* strncpy(char*, const char*, size_t)' specified bound depends on the length of the source argument [-Werror=stringop-overflow=]
  528 |   strncpy(tempdir, dir_template, len);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
plugin.cc:526:22: note: length computed here
  526 |   size_t len = strlen(dir_template) + 1;
      |                ~~~~~~^~~~~~~~~~~~~~

* plugin.cc (Plugin_recorder::init): Replace strncpy with memcpy.

3 years agoelf32-csky.c:3932:19: error: comparison is always false
Alan Modra [Mon, 7 Dec 2020 03:33:47 +0000 (14:03 +1030)] 
elf32-csky.c:3932:19: error: comparison is always false

It looks like csky missed out on an edit for 706704c8834.  Not that it
matters very much.  There doesn't appear to be any csky reloc howto
that sets the negate bit.

Similarly for ns32k and nds32.

* elf32-csky.c (csky_relocate_contents): Correct negate test.
* cpu-ns32k.c (_bfd_do_ns32k_reloc_contents): Likewise.
* elf32-nds32.c (nds32_relocate_contents): Likewise.

3 years agoREADME-how-to-make-a-release (point releases): Add a note to update the milestone...
Nick Clifton [Mon, 7 Dec 2020 11:08:34 +0000 (11:08 +0000)] 
README-how-to-make-a-release (point releases): Add a note to update the milestone list on sourceware's bugzilla.

3 years agogdb/completer: improve tab completion to consider the '-force-condition' flag
Tankut Baris Aktemur [Mon, 7 Dec 2020 08:28:33 +0000 (09:28 +0100)] 
gdb/completer: improve tab completion to consider the '-force-condition' flag

The commit

  commit 733d554a4625db4ffb89b7a20e1cf27ab071ef4d
  Author: Tankut Baris Aktemur <tankut.baris.aktemur@intel.com>
  Date:   Tue Oct 27 10:56:03 2020 +0100

  gdb/breakpoint: add flags to 'condition' and 'break' commands to force condition

introduced the '-force-condition' flag to the 'break' command.  This
flag was defined as a keyword like 'thread', 'task', and 'if'.
However, it starts with '-'.  This difference caused an uncovered case
when tab-completing a seemingly complete linespec.

Below, we see "-force-condition" in the completion list, where both
the options and the keywords are listed:

  (gdb) break -function main <TAB>
  -force-condition  -function  -label  -line  -qualified
  -source           if         task    thread

But tab-completing '-' lists only options:

  (gdb) break -function main -<TAB>
  -function   -label      -line       -qualified  -source

This patch fixes the problem by adding keywords to the completion
list, so that we see:

  (gdb) break -function main -<TAB>
  -force-condition  -function  -label  -line  -qualified  -source

gdb/ChangeLog:
2020-12-07  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

* completer.c (complete_explicit_location): Also add keywords
that start with '-' to the completion list.

gdb/testsuite/ChangeLog:
2020-12-07  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

* gdb.linespec/explicit.exp: Extend with a test to check completing
'-' after seemingly complete options.

3 years agogdb/linespec: relax the position of the '-force-condition' flag
Tankut Baris Aktemur [Mon, 7 Dec 2020 08:20:31 +0000 (09:20 +0100)] 
gdb/linespec: relax the position of the '-force-condition' flag

The break command's "-force-condition" flag is currently required to
be followed by the "if" keyword.  This prevents flexibility when using
other keywords, e.g. "thread":

  (gdb) break main -force-condition thread 1 if foo
  Function "main -force-condition" not defined.
  Make breakpoint pending on future shared library load? (y or [n]) n

Remove the requirement that "-force-condition" is always followed by
an "if", so that more flexibility is obtained when positioning
keywords.

gdb/ChangeLog:
2020-12-07  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

* linespec.c (linespec_lexer_lex_keyword): The "-force-condition"
keyword may be followed by any keyword.
* breakpoint.c (find_condition_and_thread): Advance 'tok' by
'toklen' in the case for "-force-condition".

gdb/testsuite/ChangeLog:
2020-12-07  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

* gdb.linespec/keywords.exp: Add tests to check positional
flexibility of "-force-condition".

3 years agogdb/main: execute breakpoint commands for '-iex' and '-ex' commands
Tankut Baris Aktemur [Mon, 7 Dec 2020 08:03:24 +0000 (09:03 +0100)] 
gdb/main: execute breakpoint commands for '-iex' and '-ex' commands

Suppose we have the script file below:

  break main
  commands
    print 123
  end
  run

If started with this script file, GDB executes the breakpoint command:

  $ gdb -q -x myscript --args ./test
  Reading symbols from ./test...
  Breakpoint 1 at 0x114e: file test.c, line 2.

  Breakpoint 1, main () at test.c:2
  2         return 0;
  $1 = 123
  (gdb)

However, if we remove the "run" line from the script and pass it with
the '-ex' option instead, the command is not executed:

  $ gdb -q -x myscript_no_run --args ./test
  Reading symbols from ./test...
  Breakpoint 1 at 0x114e: file test.c, line 2.
  Starting program: /path/to/test

  Breakpoint 1, main () at test.c:2
  2         return 0;
  (gdb)

If the user enters a command at this point, the breakpoint command
is executed, yielding weird output:

  $ gdb -q -x myscript_no_run --args ./test
  Reading symbols from ./test...
  Breakpoint 1 at 0x114e: file test.c, line 2.
  Starting program: /path/to/test

  Breakpoint 1, main () at test.c:2
  2         return 0;
  (gdb) print "a"
  $1 = "a"
  $2 = 123

When consuming script files, GDB runs bp actions after executing a
command.  See `command_handler` in event-top.c:

  if (c[0] != '#')
    {
      execute_command (command, ui->instream == ui->stdin_stream);

      /* Do any commands attached to breakpoint we stopped at.  */
      bpstat_do_actions ();
    }

However, for '-ex' commands, `bpstat_do_actions` is not invoked.
Hence, the misaligned output explained above occurs.  To fix the
problem, add a call to `bpstat_do_actions` after executing a command.

gdb/ChangeLog:
2020-12-07  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

* main.c (catch_command_errors): Add a flag parameter; invoke
`bpstat_do_actions` if the flag is set.
(execute_cmdargs): Update a call to `catch_command_errors`.

gdb/testsuite/ChangeLog:
2020-12-07  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

* gdb.base/bp-cmds-run-with-ex.c: New file.
* gdb.base/bp-cmds-run-with-ex.exp: New file.
* gdb.base/bp-cmds-run-with-ex.gdb: New file.
* gdb.gdb/python-interrupts.exp: Update the call to
'catch_command_errors' with the new argument.
* gdb.gdb/python-selftest.exp: Ditto.

3 years ago[gdb/ada] Handle shrink resize in replace_operator_with_call
Tom de Vries [Mon, 7 Dec 2020 08:07:32 +0000 (09:07 +0100)] 
[gdb/ada] Handle shrink resize in replace_operator_with_call

In replace_operator_with_call, we resize the elts array like this:
...
  exp->nelts = exp->nelts + 7 - oplen;
  exp->resize (exp->nelts);
...

Although all the current callers ensure that the new size is bigger, it could
also be smaller, in which case the following memmove possibly reads out of
bounds:
...
   memmove (exp->elts + pc + 7, exp->elts + pc + oplen,
           EXP_ELEM_TO_BYTES (save_nelts - pc - oplen));
...

Fix this by doing the resize after the memmove in case the new size is
smaller.

Tested on x86_64-linux.

gdb/ChangeLog:

2020-12-07  Tom de Vries  <tdevries@suse.de>

* ada-lang.c (replace_operator_with_call): Handle shrink resize.

3 years agoFix struct expression regression
Tom Tromey [Mon, 7 Dec 2020 04:34:25 +0000 (21:34 -0700)] 
Fix struct expression regression

The patch to change struct expression to use new introduced a
regression -- there is a spot that reallocates expressions that I
failed to update.

This patch rewrites this code to follow the new approach.  Now the
rewriting is done in place.

gdb/ChangeLog
2020-12-06  Tom Tromey  <tom@tromey.com>

PR ada/26999
* ada-lang.c (replace_operator_with_call): Rewrite.

3 years agoAutomatic date update in version.in
GDB Administrator [Mon, 7 Dec 2020 00:00:16 +0000 (00:00 +0000)] 
Automatic date update in version.in

3 years agos390: Fix BC instruction breakpoint handling
Giancarlo Frix [Sun, 6 Dec 2020 10:27:52 +0000 (14:27 +0400)] 
s390: Fix BC instruction breakpoint handling

This fixes a long-lived bug in the s390 port.

When trying to step over a breakpoint set on a BC (branch on condition)
instruction with displaced stepping on IBM Z, gdb would incorrectly
adjust the pc regardless of whether or not the branch was taken. Since
the branch target is an absolute address, this would cause the inferior
to jump around wildly whenever the branch was taken, either crashing it
or causing it to behave unpredictably.

It turns out that the logic to handle BC instructions correctly was in
the code, but that the enum value representing its opcode has always
been incorrect.

This patch corrects the enum value to the actual opcode, fixing the
stepping problem. The enum value is also used in the prologue analysis
code, so this also fixes a minor bug where more of the prologue would
be read than was necessary.

gdb/ChangeLog:

        PR breakpoints/27009
        * s390-tdep.h (op_bc): Correct BC opcode value.

3 years agogmp-utils: protect gdb_mpz exports against out-of-range values
Joel Brobecker [Sun, 6 Dec 2020 04:56:59 +0000 (23:56 -0500)] 
gmp-utils: protect gdb_mpz exports against out-of-range values

The gdb_mpz class currently provides a couple of methods which
essentially export an mpz_t value into either a buffer, or an integral
type. The export is based on using the mpz_export function which
we discovered can be a bit treacherous if used without caution.

In particular, the initial motivation for this patch was to catch
situations where the mpz_t value was so large that it would not fit
in the destination area. mpz_export does not know the size of
the buffer, and therefore can happily write past the end of our buffer.

While designing a solution to the above problem, I also discovered
that we also needed to be careful when exporting signed numbers.
In particular, numbers which are larger than the maximum value
for a given signed type size, but no so large as to fit in the
*unsigned* version with the same size, would end up being exported
incorrectly. This is related to the fact that mpz_export ignores
the sign of the value being exportd, and assumes an unsigned export.
Thus, for such large values, the appears as if mpz_export is able
to fit our value into our buffer, but in fact, it does not.

Also, I noticed that gdb_mpz::write wasn't taking its unsigned_p
parameter, which was a hole.

For all these reasons, a new low-level private method called
"safe_export" has been added to class gdb_mpz, whose goal is
to perform all necessary checks and manipulations for a safe
and correct export. As a bonus, this method allows us to factorize
the handling of negative value exports.

The gdb_mpz::as_integer and gdb_mpz::write methods are then simplified
to take advantage of this new safe_export method.

gdb/ChangeLog:

        * gmp-utils.h (gdb_mpz::safe_export): New private method.
        (gdb_mpz::as_integer): Reimplement using gdb_mpz::safe_export.
        * gmp-utils.c (gdb_mpz::write): Rewrite using gdb_mpz::safe_export.
        (gdb_mpz::safe_export): New method.
        * unittests/gmp-utils-selftests .c (gdb_mpz_as_integer):
        Update function description.
        (check_as_integer_raises_out_of_range_error): New function.
        (gdb_mpz_as_integer_out_of_range): New function.
        (_initialize_gmp_utils_selftests): Register
        gdb_mpz_as_integer_out_of_range as a selftest.

3 years agoAutomatic date update in version.in
GDB Administrator [Sun, 6 Dec 2020 00:00:14 +0000 (00:00 +0000)] 
Automatic date update in version.in

3 years agoVAX/BFD: Do not warn about GOT addend mismatches if no GOT entry is made
Maciej W. Rozycki [Sat, 5 Dec 2020 11:18:14 +0000 (11:18 +0000)] 
VAX/BFD: Do not warn about GOT addend mismatches if no GOT entry is made

Match the condition used in `elf_vax_instantiate_got_entries' for the
creation of GOT entries in the processing of R_VAX_GOT32 relocations in
`elf_vax_check_relocs', removing incorrect warnings about a GOT addend
mismatch like:

./ld-new: tmpdir/got-local-ref-off-r.o: warning: GOT addend of 1 to `bar_hidden' does not match previous GOT addend of 0
./ld-new: tmpdir/got-local-ref-off-r.o: warning: GOT addend of 2 to `bar_hidden' does not match previous GOT addend of 0

and corresponding failures with the test cases newly added here:

FAIL: GOT test (executable hidden reference with offset)
FAIL: GOT test (executable visible reference with offset)

for symbols that are considered local for reasons other than having been
forced local with a version script, which is usually the ELF visibility.
Correct code is produced regardless, but the warning breaks `-Werror'
compilation and may upset people regardless.

Interestingly this shows with executable links only, because in shared
library links code from `elf_link_add_object_symbols' triggers:

    /* If the symbol already has a dynamic index, but
       visibility says it should not be visible, turn it into
       a local symbol.  */
    switch (ELF_ST_VISIBILITY (h->other))
      {
      case STV_INTERNAL:
      case STV_HIDDEN:
(*bed->elf_backend_hide_symbol) (info, h, TRUE);
dynsym = FALSE;
break;
      }

that sets `h->forced_local' like with a version script.

Add suitable test cases including disassembly to verify correct code has
been produced where no warnings have been issued, and that warnings do
get issued where necessary.  Do not verify (broken) code produced in the
latter case; we should probably make the warning an error, or preferably
actually start supporting GOT references with different addends as they
appear feasible with explicitly relocated GOT that we use.

bfd/
* elf32-vax.c (elf_vax_check_relocs) <R_VAX_GOT32>: Use
SYMBOL_REFERENCES_LOCAL rather than `h->forced_local' to check
whether the symbol referred is local or not.

ld/
* testsuite/ld-vax-elf/got-local-exe-off-hidden.dd: New test
dump.
* testsuite/ld-vax-elf/got-local-exe-off-visible.dd: New test
dump.
* testsuite/ld-vax-elf/got-local-lib-off-hidden.dd: New test
dump.
* testsuite/ld-vax-elf/got-local-lib-off-visible.ed: New test
dump.
* testsuite/ld-vax-elf/got-local-off-external.ed: New test dump.
* testsuite/ld-vax-elf/got-local-exe-off.xd: New test dump.
* testsuite/ld-vax-elf/got-local-lib-off.xd: New test dump.
* testsuite/ld-vax-elf/got-local.ld: New test linker script.
* testsuite/ld-vax-elf/got-local-aux-off.s: New test source.
* testsuite/ld-vax-elf/got-local-def-off.s: New test source.
* testsuite/ld-vax-elf/got-local-ref-off-external.s: New test
source.
* testsuite/ld-vax-elf/got-local-ref-off-hidden.s: New test
source.
* testsuite/ld-vax-elf/got-local-ref-off-visible.s: New test
source.
* testsuite/ld-vax-elf/vax-elf.exp: Run the new tests.

3 years agoFix TARGET_CHAR_BIT/HOST_CHAR_BIT confusion in gmp-utils.c
Joel Brobecker [Sat, 5 Dec 2020 08:03:48 +0000 (03:03 -0500)] 
Fix TARGET_CHAR_BIT/HOST_CHAR_BIT confusion in gmp-utils.c

In a couple of gdb_mpz methods, we are computing the number of
bits in a gdb::array_view of gdb_byte. Since gdb_byte is defined
using a host-side type (see common-types.h), the number of bits
in a gdb_byte should be HOST_CHAR_BIT, not TARGET_CHAR_BIT.

gdb/ChangeLog:

        * gmp-utils.c (gdb_mpz::read): Use HOST_CHAR_BIT instead of
        TARGET_CHAR_BIT.
        (gdb_mpz::write): Likewise.

3 years agox86-64: Convert load to mov only for GOTPCRELX relocations
H.J. Lu [Sat, 5 Dec 2020 02:54:47 +0000 (18:54 -0800)] 
x86-64: Convert load to mov only for GOTPCRELX relocations

Since converting load to mov needs to rewrite the REX byte and we don't
know if there is a REX byte with GOTPCREL relocation, do it only for
GOTPCRELX relocations.

bfd/

PR ld/27016
* elf64-x86-64.c (elf_x86_64_convert_load_reloc): Convert load
to mov only for GOTPCRELX relocations.

ld/

PR ld/27016
* testsuite/ld-x86-64/x86-64.exp: Run pr27016a and pr27016b.
* testsuite/ld-x86-64/pr27016a.d: New file.
* testsuite/ld-x86-64/pr27016a.s: Likewise.
* testsuite/ld-x86-64/pr27016b.d: Likewise.
* testsuite/ld-x86-64/pr27016b.s: Likewise.

3 years agoAutomatic date update in version.in
GDB Administrator [Sat, 5 Dec 2020 00:00:11 +0000 (00:00 +0000)] 
Automatic date update in version.in

3 years agogdb: use two displaced step buffers on amd64/Linux
Simon Marchi [Fri, 4 Dec 2020 21:44:55 +0000 (16:44 -0500)] 
gdb: use two displaced step buffers on amd64/Linux

As observed on a binary compiled on AMD64 Ubuntu 20.04, against glibc
2.31 (I think it's the libc that provides this startup code, right?),
there are enough bytes at the executable's entry point to hold more than
one displaced step buffer.  gdbarch_max_insn_length is 16, and the
code at _start looks like:

0000000000001040 <_start>:
    1040:       f3 0f 1e fa             endbr64
    1044:       31 ed                   xor    %ebp,%ebp
    1046:       49 89 d1                mov    %rdx,%r9
    1049:       5e                      pop    %rsi
    104a:       48 89 e2                mov    %rsp,%rdx
    104d:       48 83 e4 f0             and    $0xfffffffffffffff0,%rsp
    1051:       50                      push   %rax
    1052:       54                      push   %rsp
    1053:       4c 8d 05 56 01 00 00    lea    0x156(%rip),%r8        # 11b0 <__libc_csu_fini>
    105a:       48 8d 0d df 00 00 00    lea    0xdf(%rip),%rcx        # 1140 <__libc_csu_init>
    1061:       48 8d 3d c1 00 00 00    lea    0xc1(%rip),%rdi        # 1129 <main>
    1068:       ff 15 72 2f 00 00       callq  *0x2f72(%rip)        # 3fe0 <__libc_start_main@GLIBC_2.2.5>
    106e:       f4                      hlt
    106f:       90                      nop

The two buffers would occupy [0x1040, 0x1060).

I checked on Alpine, which uses the musl C library, the startup code
looks like:

0000000000001048 <_start>:
    1048:       48 31 ed                xor    %rbp,%rbp
    104b:       48 89 e7                mov    %rsp,%rdi
    104e:       48 8d 35 e3 2d 00 00    lea    0x2de3(%rip),%rsi        # 3e38 <_DYNAMIC>
    1055:       48 83 e4 f0             and    $0xfffffffffffffff0,%rsp
    1059:       e8 00 00 00 00          callq  105e <_start_c>

000000000000105e <_start_c>:
    105e:       48 8b 37                mov    (%rdi),%rsi
    1061:       48 8d 57 08             lea    0x8(%rdi),%rdx
    1065:       45 31 c9                xor    %r9d,%r9d
    1068:       4c 8d 05 47 01 00 00    lea    0x147(%rip),%r8        # 11b6 <_fini>
    106f:       48 8d 0d 8a ff ff ff    lea    -0x76(%rip),%rcx        # 1000 <_init>
    1076:       48 8d 3d 0c 01 00 00    lea    0x10c(%rip),%rdi        # 1189 <main>
    107d:       e9 9e ff ff ff          jmpq   1020 <__libc_start_main@plt>

Even though there's a _start_c symbol, it all appears to be code that
runs once at the very beginning of the program, so it looks fine if the
two buffers occupy [0x1048, 0x1068).

One important thing I discovered while doing this is that when debugging
a dynamically-linked executable, breakpoints in the shared library
loader are hit before executing the _start code, and these breakpoints
may be displaced-stepped.  So it's very important that the buffer bytes
are restored properly after doing the displaced steps, otherwise the
_start code will be corrupted once we try to execute it.

Another thing that made me think about is that library constructors (as
in `__attribute__((constructor))`) run before _start.  And they are free
to spawn threads.  What if one of these threads executes a displaced
step, therefore changing the bytes at _start, while the main thread
executes _start?  That doesn't sound good and I don't know how we could
prevent it.  But this is a problem that predates the current patch.

Even when stress-testing the implementation, by making many threads do
displaced steps over and over, I didn't see a significant performance (I
confirmed that the two buffers were used by checking the "set debug
displaced" logs though).  However, this patch mostly helps make the
feature testable by anybody with an AMD64/Linux machine, so I think it's
useful.

gdb/ChangeLog:

* amd64-linux-tdep.c (amd64_linux_init_abi): Pass 2 as the
number of displaced step buffers.

Change-Id: Ia0c96ea0fcda893f4726df6fdac7be5214620112

3 years agogdb: make displaced stepping implementation capable of managing multiple buffers
Simon Marchi [Fri, 4 Dec 2020 21:43:56 +0000 (16:43 -0500)] 
gdb: make displaced stepping implementation capable of managing multiple buffers

The displaced_step_buffer class, introduced in the previous patch,
manages access to a single displaced step buffer.  Change it into
displaced_step_buffers (note the plural), which manages access to
multiple displaced step buffers.

When preparing a displaced step for a thread, it looks for an unused
buffer.

For now, all users still pass a single displaced step buffer, so no real
behavior change is expected here.  The following patch makes a user pass
more than one buffer, so the functionality introduced by this patch is
going to be useful in the next one.

gdb/ChangeLog:

* displaced-stepping.h (struct displaced_step_buffer): Rename
to...
(struct displaced_step_buffers): ... this.
<m_addr, m_current_thread, m_copy_insn_closure>: Remove.
<struct displaced_step_buffer>: New inner class.
<m_buffers>: New.
* displaced-stepping.c (displaced_step_buffer::prepare): Rename
to...
(displaced_step_buffers::prepare): ... this, adjust for multiple
buffers.
(displaced_step_buffer::finish):  Rename to...
(displaced_step_buffers::finish): ... this, adjust for multiple
buffers.
(displaced_step_buffer::copy_insn_closure_by_addr): Rename to...
(displaced_step_buffers::copy_insn_closure_by_addr): ... this,
adjust for multiple buffers.
(displaced_step_buffer::restore_in_ptid): Rename to...
(displaced_step_buffers::restore_in_ptid): ... this, adjust for
multiple buffers.
* linux-tdep.h (linux_init_abi): Change supports_displaced_step
for num_disp_step_buffers.
* linux-tdep.c (struct linux_gdbarch_data)
<num_disp_step_buffers>: New field.
(struct linux_info) <disp_step_buf>: Rename to...
<disp_step_bufs>: ... this, change type to
displaced_step_buffers.
(linux_displaced_step_prepare): Use
linux_gdbarch_data::num_disp_step_buffers to create that number
of buffers.
(linux_displaced_step_finish): Adjust.
(linux_displaced_step_copy_insn_closure_by_addr): Adjust.
(linux_displaced_step_restore_all_in_ptid): Adjust.
(linux_init_abi): Change supports_displaced_step parameter for
num_disp_step_buffers, save it in linux_gdbarch_data.
* aarch64-linux-tdep.c (aarch64_linux_init_abi): Adjust.
* alpha-linux-tdep.c (alpha_linux_init_abi): Adjust.
* amd64-linux-tdep.c (amd64_linux_init_abi_common): Change
supports_displaced_step parameter for num_disp_step_buffers.
(amd64_linux_init_abi): Adjust.
(amd64_x32_linux_init_abi): Adjust.
* arc-linux-tdep.c (arc_linux_init_osabi): Adjust.
* arm-linux-tdep.c (arm_linux_init_abi): Adjust.
* bfin-linux-tdep.c (bfin_linux_init_abi): Adjust.
* cris-linux-tdep.c (cris_linux_init_abi): Adjust.
* csky-linux-tdep.c (csky_linux_init_abi): Adjust.
* frv-linux-tdep.c (frv_linux_init_abi): Adjust.
* hppa-linux-tdep.c (hppa_linux_init_abi): Adjust.
* i386-linux-tdep.c (i386_linux_init_abi): Adjust.
* ia64-linux-tdep.c (ia64_linux_init_abi): Adjust.
* m32r-linux-tdep.c (m32r_linux_init_abi): Adjust.
* m68k-linux-tdep.c (m68k_linux_init_abi):
* microblaze-linux-tdep.c (microblaze_linux_init_abi):
* mips-linux-tdep.c (mips_linux_init_abi): Adjust.
* mn10300-linux-tdep.c (am33_linux_init_osabi): Adjust.
* nios2-linux-tdep.c (nios2_linux_init_abi): Adjust.
* or1k-linux-tdep.c (or1k_linux_init_abi): Adjust.
* ppc-linux-tdep.c (ppc_linux_init_abi): Adjust.
* riscv-linux-tdep.c (riscv_linux_init_abi): Adjust.
* rs6000-tdep.c (struct ppc_inferior_data) <disp_step_buf>:
Change type to displaced_step_buffers.
* s390-linux-tdep.c (s390_linux_init_abi_any): Adjust.
* sh-linux-tdep.c (sh_linux_init_abi): Adjust.
* sparc-linux-tdep.c (sparc32_linux_init_abi): Adjust.
* sparc64-linux-tdep.c (sparc64_linux_init_abi): Adjust.
* tic6x-linux-tdep.c (tic6x_uclinux_init_abi): Adjust.
* tilegx-linux-tdep.c (tilegx_linux_init_abi): Adjust.
* xtensa-linux-tdep.c (xtensa_linux_init_abi): Adjust.

Change-Id: Ia9c02f207da2c9e1d9188020139619122392bb70

3 years agogdb: change linux gdbarch data from post to pre-init
Simon Marchi [Fri, 4 Dec 2020 21:43:56 +0000 (16:43 -0500)] 
gdb: change linux gdbarch data from post to pre-init

The following patch will need to fill a field in linux_gdbarch_data
while the gdbarch is being built.  linux_gdbarch_data is currently
allocated as a post-init gdbarch data, meaning it's not possible to fill
it before the gdbarch is completely initialized.  Change it to a
pre-init gdbarch data to allow this.

The init_linux_gdbarch_data function doesn't use the created gdbarch,
it only allocates the linux_gdbarch_data structure on the gdbarch's
obstack, so the change is trivial.

gdb/ChangeLog:

* linux-tdep.c (init_linux_gdbarch_data): Change parameter to
obkstack.
(_initialize_linux_tdep): Register pre-init gdb data instead of
post-init.

Change-Id: If35ce91b6bb5435680d43b9268d811d95661644f

3 years agogdb: move displaced stepping logic to gdbarch, allow starting concurrent displaced...
Simon Marchi [Fri, 4 Dec 2020 21:43:55 +0000 (16:43 -0500)] 
gdb: move displaced stepping logic to gdbarch, allow starting concurrent displaced steps

Today, GDB only allows a single displaced stepping operation to happen
per inferior at a time.  There is a single displaced stepping buffer per
inferior, whose address is fixed (obtained with
gdbarch_displaced_step_location), managed by infrun.c.

In the case of the AMD ROCm target [1] (in the context of which this
work has been done), it is typical to have thousands of threads (or
waves, in SMT terminology) executing the same code, hitting the same
breakpoint (possibly conditional) and needing to to displaced step it at
the same time.  The limitation of only one displaced step executing at a
any given time becomes a real bottleneck.

To fix this bottleneck, we want to make it possible for threads of a
same inferior to execute multiple displaced steps in parallel.  This
patch builds the foundation for that.

In essence, this patch moves the task of preparing a displaced step and
cleaning up after to gdbarch functions.  This allows using different
schemes for allocating and managing displaced stepping buffers for
different platforms.  The gdbarch decides how to assign a buffer to a
thread that needs to execute a displaced step.

On the ROCm target, we are able to allocate one displaced stepping
buffer per thread, so a thread will never have to wait to execute a
displaced step.

On Linux, the entry point of the executable if used as the displaced
stepping buffer, since we assume that this code won't get used after
startup.  From what I saw (I checked with a binary generated against
glibc and musl), on AMD64 we have enough space there to fit two
displaced stepping buffers.  A subsequent patch makes AMD64/Linux use
two buffers.

In addition to having multiple displaced stepping buffers, there is also
the idea of sharing displaced stepping buffers between threads.  Two
threads doing displaced steps for the same PC could use the same buffer
at the same time.  Two threads stepping over the same instruction (same
opcode) at two different PCs may also be able to share a displaced
stepping buffer.  This is an idea for future patches, but the
architecture built by this patch is made to allow this.

Now, the implementation details.  The main part of this patch is moving
the responsibility of preparing and finishing a displaced step to the
gdbarch.  Before this patch, preparing a displaced step is driven by the
displaced_step_prepare_throw function.  It does some calls to the
gdbarch to do some low-level operations, but the high-level logic is
there.  The steps are roughly:

- Ask the gdbarch for the displaced step buffer location
- Save the existing bytes in the displaced step buffer
- Ask the gdbarch to copy the instruction into the displaced step buffer
- Set the pc of the thread to the beginning of the displaced step buffer

Similarly, the "fixup" phase, executed after the instruction was
successfully single-stepped, is driven by the infrun code (function
displaced_step_finish).  The steps are roughly:

- Restore the original bytes in the displaced stepping buffer
- Ask the gdbarch to fixup the instruction result (adjust the target's
  registers or memory to do as if the instruction had been executed in
  its original location)

The displaced_step_inferior_state::step_thread field indicates which
thread (if any) is currently using the displaced stepping buffer, so it
is used by displaced_step_prepare_throw to check if the displaced
stepping buffer is free to use or not.

This patch defers the whole task of preparing and cleaning up after a
displaced step to the gdbarch.  Two new main gdbarch methods are added,
with the following semantics:

  - gdbarch_displaced_step_prepare: Prepare for the given thread to
    execute a displaced step of the instruction located at its current PC.
    Upon return, everything should be ready for GDB to resume the thread
    (with either a single step or continue, as indicated by
    gdbarch_displaced_step_hw_singlestep) to make it displaced step the
    instruction.

  - gdbarch_displaced_step_finish: Called when the thread stopped after
    having started a displaced step.  Verify if the instruction was
    executed, if so apply any fixup required to compensate for the fact
    that the instruction was executed at a different place than its
    original pc.  Release any resources that were allocated for this
    displaced step.  Upon return, everything should be ready for GDB to
    resume the thread in its "normal" code path.

The displaced_step_prepare_throw function now pretty much just offloads
to gdbarch_displaced_step_prepare and the displaced_step_finish function
offloads to gdbarch_displaced_step_finish.

The gdbarch_displaced_step_location method is now unnecessary, so is
removed.  Indeed, the core of GDB doesn't know how many displaced step
buffers there are nor where they are.

To keep the existing behavior for existing architectures, the logic that
was previously implemented in infrun.c for preparing and finishing a
displaced step is moved to displaced-stepping.c, to the
displaced_step_buffer class.  Architectures are modified to implement
the new gdbarch methods using this class.  The behavior is not expected
to change.

The other important change (which arises from the above) is that the
core of GDB no longer prevents concurrent displaced steps.  Before this
patch, start_step_over walks the global step over chain and tries to
initiate a step over (whether it is in-line or displaced).  It follows
these rules:

  - if an in-line step is in progress (in any inferior), don't start any
    other step over
  - if a displaced step is in progress for an inferior, don't start
    another displaced step for that inferior

After starting a displaced step for a given inferior, it won't start
another displaced step for that inferior.

In the new code, start_step_over simply tries to initiate step overs for
all the threads in the list.  But because threads may be added back to
the global list as it iterates the global list, trying to initiate step
overs, start_step_over now starts by stealing the global queue into a
local queue and iterates on the local queue.  In the typical case, each
thread will either:

  - have initiated a displaced step and be resumed
  - have been added back by the global step over queue by
    displaced_step_prepare_throw, because the gdbarch will have returned
    that there aren't enough resources (i.e. buffers) to initiate a
    displaced step for that thread

Lastly, if start_step_over initiates an in-line step, it stops
iterating, and moves back whatever remaining threads it had in its local
step over queue to the global step over queue.

Two other gdbarch methods are added, to handle some slightly annoying
corner cases.  They feel awkwardly specific to these cases, but I don't
see any way around them:

  - gdbarch_displaced_step_copy_insn_closure_by_addr: in
    arm_pc_is_thumb, arm-tdep.c wants to get the closure for a given
    buffer address.

  - gdbarch_displaced_step_restore_all_in_ptid: when a process forks
    (at least on Linux), the address space is copied.  If some displaced
    step buffers were in use at the time of the fork, we need to restore
    the original bytes in the child's address space.

These two adjustments are also made in infrun.c:

  - prepare_for_detach: there may be multiple threads doing displaced
    steps when we detach, so wait until all of them are done

  - handle_inferior_event: when we handle a fork event for a given
    thread, it's possible that other threads are doing a displaced step at
    the same time.  Make sure to restore the displaced step buffer
    contents in the child for them.

[1] https://github.com/ROCm-Developer-Tools/ROCgdb

gdb/ChangeLog:

* displaced-stepping.h (struct
displaced_step_copy_insn_closure): Adjust comments.
(struct displaced_step_inferior_state) <step_thread,
step_gdbarch, step_closure, step_original, step_copy,
step_saved_copy>: Remove fields.
(struct displaced_step_thread_state): New.
(struct displaced_step_buffer): New.
* displaced-stepping.c (displaced_step_buffer::prepare): New.
(write_memory_ptid): Move from infrun.c.
(displaced_step_instruction_executed_successfully): New,
factored out of displaced_step_finish.
(displaced_step_buffer::finish): New.
(displaced_step_buffer::copy_insn_closure_by_addr): New.
(displaced_step_buffer::restore_in_ptid): New.
* gdbarch.sh (displaced_step_location): Remove.
(displaced_step_prepare, displaced_step_finish,
displaced_step_copy_insn_closure_by_addr,
displaced_step_restore_all_in_ptid): New.
* gdbarch.c: Re-generate.
* gdbarch.h: Re-generate.
* gdbthread.h (class thread_info) <displaced_step_state>: New
field.
(thread_step_over_chain_remove): New declaration.
(thread_step_over_chain_next): New declaration.
(thread_step_over_chain_length): New declaration.
* thread.c (thread_step_over_chain_remove): Make non-static.
(thread_step_over_chain_next): New.
(global_thread_step_over_chain_next): Use
thread_step_over_chain_next.
(thread_step_over_chain_length): New.
(global_thread_step_over_chain_enqueue): Add debug print.
(global_thread_step_over_chain_remove): Add debug print.
* infrun.h (get_displaced_step_copy_insn_closure_by_addr):
Remove.
* infrun.c (get_displaced_stepping_state): New.
(displaced_step_in_progress_any_inferior): Remove.
(displaced_step_in_progress_thread): Adjust.
(displaced_step_in_progress): Adjust.
(displaced_step_in_progress_any_thread): New.
(get_displaced_step_copy_insn_closure_by_addr): Remove.
(gdbarch_supports_displaced_stepping): Use
gdbarch_displaced_step_prepare_p.
(displaced_step_reset): Change parameter from inferior to
thread.
(displaced_step_prepare_throw): Implement using
gdbarch_displaced_step_prepare.
(write_memory_ptid): Move to displaced-step.c.
(displaced_step_restore): Remove.
(displaced_step_finish): Implement using
gdbarch_displaced_step_finish.
(start_step_over): Allow starting more than one displaced step.
(prepare_for_detach): Handle possibly multiple threads doing
displaced steps.
(handle_inferior_event): Handle possibility that fork event
happens while another thread displaced steps.
* linux-tdep.h (linux_displaced_step_prepare): New.
(linux_displaced_step_finish): New.
(linux_displaced_step_copy_insn_closure_by_addr): New.
(linux_displaced_step_restore_all_in_ptid): New.
(linux_init_abi): Add supports_displaced_step parameter.
* linux-tdep.c (struct linux_info) <disp_step_buf>: New field.
(linux_displaced_step_prepare): New.
(linux_displaced_step_finish): New.
(linux_displaced_step_copy_insn_closure_by_addr): New.
(linux_displaced_step_restore_all_in_ptid): New.
(linux_init_abi): Add supports_displaced_step parameter,
register displaced step methods if true.
(_initialize_linux_tdep): Register inferior_execd observer.
* amd64-linux-tdep.c (amd64_linux_init_abi_common): Add
supports_displaced_step parameter, adjust call to
linux_init_abi.  Remove call to
set_gdbarch_displaced_step_location.
(amd64_linux_init_abi): Adjust call to
amd64_linux_init_abi_common.
(amd64_x32_linux_init_abi): Likewise.
* aarch64-linux-tdep.c (aarch64_linux_init_abi): Adjust call to
linux_init_abi.  Remove call to
set_gdbarch_displaced_step_location.
* arm-linux-tdep.c (arm_linux_init_abi): Likewise.
* i386-linux-tdep.c (i386_linux_init_abi): Likewise.
* alpha-linux-tdep.c (alpha_linux_init_abi): Adjust call to
linux_init_abi.
* arc-linux-tdep.c (arc_linux_init_osabi): Likewise.
* bfin-linux-tdep.c (bfin_linux_init_abi): Likewise.
* cris-linux-tdep.c (cris_linux_init_abi): Likewise.
* csky-linux-tdep.c (csky_linux_init_abi): Likewise.
* frv-linux-tdep.c (frv_linux_init_abi): Likewise.
* hppa-linux-tdep.c (hppa_linux_init_abi): Likewise.
* ia64-linux-tdep.c (ia64_linux_init_abi): Likewise.
* m32r-linux-tdep.c (m32r_linux_init_abi): Likewise.
* m68k-linux-tdep.c (m68k_linux_init_abi): Likewise.
* microblaze-linux-tdep.c (microblaze_linux_init_abi): Likewise.
* mips-linux-tdep.c (mips_linux_init_abi): Likewise.
* mn10300-linux-tdep.c (am33_linux_init_osabi): Likewise.
* nios2-linux-tdep.c (nios2_linux_init_abi): Likewise.
* or1k-linux-tdep.c (or1k_linux_init_abi): Likewise.
* riscv-linux-tdep.c (riscv_linux_init_abi): Likewise.
* s390-linux-tdep.c (s390_linux_init_abi_any): Likewise.
* sh-linux-tdep.c (sh_linux_init_abi): Likewise.
* sparc-linux-tdep.c (sparc32_linux_init_abi): Likewise.
* sparc64-linux-tdep.c (sparc64_linux_init_abi): Likewise.
* tic6x-linux-tdep.c (tic6x_uclinux_init_abi): Likewise.
* tilegx-linux-tdep.c (tilegx_linux_init_abi): Likewise.
* xtensa-linux-tdep.c (xtensa_linux_init_abi): Likewise.
* ppc-linux-tdep.c (ppc_linux_init_abi): Adjust call to
linux_init_abi.  Remove call to
set_gdbarch_displaced_step_location.
* arm-tdep.c (arm_pc_is_thumb): Call
gdbarch_displaced_step_copy_insn_closure_by_addr instead of
get_displaced_step_copy_insn_closure_by_addr.
* rs6000-aix-tdep.c (rs6000_aix_init_osabi): Adjust calls to
clear gdbarch methods.
* rs6000-tdep.c (struct ppc_inferior_data): New structure.
(get_ppc_per_inferior): New function.
(ppc_displaced_step_prepare): New function.
(ppc_displaced_step_finish): New function.
(ppc_displaced_step_restore_all_in_ptid): New function.
(rs6000_gdbarch_init): Register new gdbarch methods.
* s390-tdep.c (s390_gdbarch_init): Don't call
set_gdbarch_displaced_step_location, set new gdbarch methods.

gdb/testsuite/ChangeLog:

* gdb.arch/amd64-disp-step-avx.exp: Adjust pattern.
* gdb.threads/forking-threads-plus-breakpoint.exp: Likewise.
* gdb.threads/non-stop-fair-events.exp: Likewise.

Change-Id: I387cd235a442d0620ec43608fd3dc0097fcbf8c8

3 years agogdb: move displaced stepping types to displaced-stepping.{h,c}
Simon Marchi [Fri, 4 Dec 2020 21:43:55 +0000 (16:43 -0500)] 
gdb: move displaced stepping types to displaced-stepping.{h,c}

Move displaced-stepping related stuff unchanged to displaced-stepping.h
and displaced-stepping.c.  This helps make the following patch a bit
smaller and easier to read.

gdb/ChangeLog:

* Makefile.in (COMMON_SFILES): Add displaced-stepping.c.
* aarch64-tdep.h: Include displaced-stepping.h.
* displaced-stepping.h (struct displaced_step_copy_insn_closure):
Move here.
(displaced_step_copy_insn_closure_up): Move here.
(struct buf_displaced_step_copy_insn_closure): Move here.
(struct displaced_step_inferior_state): Move here.
(debug_displaced): Move here.
(displaced_debug_printf_1): Move here.
(displaced_debug_printf): Move here.
* displaced-stepping.c: New file.
* gdbarch.sh: Include displaced-stepping.h in gdbarch.h.
* gdbarch.h: Re-generate.
* inferior.h: Include displaced-stepping.h.
* infrun.h (debug_displaced): Move to displaced-stepping.h.
(displaced_debug_printf_1): Likewise.
(displaced_debug_printf): Likewise.
(struct displaced_step_copy_insn_closure): Likewise.
(displaced_step_copy_insn_closure_up): Likewise.
(struct buf_displaced_step_copy_insn_closure): Likewise.
(struct displaced_step_inferior_state): Likewise.
* infrun.c (show_debug_displaced): Move to displaced-stepping.c.
(displaced_debug_printf_1): Likewise.
(displaced_step_copy_insn_closure::~displaced_step_copy_insn_closure):
Likewise.
(_initialize_infrun): Don't register "set/show debug displaced".

Change-Id: I29935f5959b80425370630a45148fc06cd4227ca

3 years agogdb: pass inferior to get_linux_inferior_data
Simon Marchi [Fri, 4 Dec 2020 21:43:54 +0000 (16:43 -0500)] 
gdb: pass inferior to get_linux_inferior_data

Pass to get_linux_inferior_data the inferior for which we want to obtain
the linux-specific data, rather than assuming the current inferior.
This helps slightly reduce the diff in the upcoming main patch.

Update the sole caller to pass the current inferior.

gdb/ChangeLog:

* linux-tdep.c (get_linux_inferior_data): Add inferior
parameter.
(linux_vsyscall_range): Pass current inferior.

Change-Id: Ie4b61190e4a2e89b5b55a140cfecd4de66d92393

3 years agogdb: introduce status enum for displaced step prepare/finish
Simon Marchi [Fri, 4 Dec 2020 21:43:54 +0000 (16:43 -0500)] 
gdb: introduce status enum for displaced step prepare/finish

This is a preparatory patch to reduce the size of the diff of the
upcoming main patch.  It introduces enum types for the return values of
displaced step "prepare" and "finish" operations.  I find that this
expresses better the intention of the code, rather than returning
arbitrary integer values (-1, 0 and 1) which are difficult to remember.
That makes the code easier to read.

I put the new enum types in a new displaced-stepping.h file, because I
introduce that file in a later patch anyway.  Putting it there avoids
having to move it later.

There is one change in behavior for displaced_step_finish: it currently
returns 0 if the thread wasn't doing a displaced step and 1 if the
thread was doing a displaced step which was executed successfully.  It
turns out that this distinction is not needed by any caller, so I've
merged these two cases into "_OK", rather than adding an extra
enumerator.

gdb/ChangeLog:

* infrun.c (displaced_step_prepare_throw): Change return type to
displaced_step_prepare_status.
(displaced_step_prepare): Likewise.
(displaced_step_finish): Change return type to
displaced_step_finish_status.
(resume_1): Adjust.
(stop_all_threads): Adjust.
* displaced-stepping.h: New file.

Change-Id: I5c8fe07212cd398d5b486b5936d9d0807acd3788

3 years agogdb: rename displaced_step_fixup to displaced_step_finish
Simon Marchi [Fri, 4 Dec 2020 21:43:54 +0000 (16:43 -0500)] 
gdb: rename displaced_step_fixup to displaced_step_finish

This is a preparatory patch to reduce a little bit the diff size of the
main patch later in this series.  It renames the displaced_step_fixup
function in infrun.c to displaced_step_finish.

The rationale is to better differentiate the low and high level
operations.

We first have the low level operation of writing an instruction to a
displaced buffer, called "copy_insn".  The mirror low level operation to
fix up the state after having executed the instruction is "fixup".  The
high level operation of preparing a thread for a displaced step (which
includes doing the "copy_insn" and some more bookkeeping) is called
"prepare" (as in displaced_step_prepare).  The mirror high level
operation to cleaning up after a displaced step (which includes doing
the "fixup" and some more bookkeeping) is currently also called "fixup"
(as in displaced_step_fixup), just like the low level operation.

I think that choosing a different name for the low and high level
cleanup operation makes it clearer, hence "finish".

gdb/ChangeLog:

* infrun.c (displaced_step_fixup): Rename to...
(displaced_step_finish): ... this, update all callers.

Change-Id: Id32f48c1e2091d09854c77fcedcc14d2519957a2

3 years agogdb: rename displaced_step_closure to displaced_step_copy_insn_closure
Simon Marchi [Fri, 4 Dec 2020 21:43:53 +0000 (16:43 -0500)] 
gdb: rename displaced_step_closure to displaced_step_copy_insn_closure

Since we're going to introduce other "displaced step" functions and
another kind of displaced step closure, make it clear that this is the
return type of the gdbarch_displaced_step_copy_insn function.

gdb/ChangeLog:

* infrun.h (get_displaced_step_closure_by_addr): Rename to...
(get_displaced_step_copy_insn_closure_by_addr): ... this.
Update all users.
(displaced_step_closure): Rename to...
(displaced_step_copy_insn_closure): ... this.  Update all users.
(displaced_step_closure_up): Rename to...
(displaced_step_copy_insn_closure_up). ... this.  Update all
users.
(buf_displaced_step_closure): Rename to...
(buf_displaced_step_copy_insn_closure): ... this.  Update all
users.
* infrun.c (get_displaced_step_closure_by_addr): Rename to...
(get_displaced_step_copy_insn_closure_by_addr): ... this.
Update all users.
* aarch64-tdep.c (aarch64_displaced_step_closure): Rename to...
(aarch64_displaced_step_copy_insn_closure): ... this.  Update
all users.
* amd64-tdep.c (amd64_displaced_step_closure): Rename to...
(amd64_displaced_step_copy_insn_closure): ... this.  Update all
users.
* arm-tdep.h (arm_displaced_step_closure): Rename to...
(arm_displaced_step_copy_insn_closure): ... this.  Update all
users.
* i386-tdep.h (i386_displaced_step_closure): Rename to...
(i386_displaced_step_copy_insn_closure): ... this.  Update all
users.
* rs6000-tdep.c (ppc_displaced_step_closure): Rename to...
(ppc_displaced_step_copy_insn_closure): ... this.  Update all
users.
* s390-tdep.c (s390_displaced_step_closure): Rename to...
(s390_displaced_step_copy_insn_closure): ... this.  Update all
users.
* gdbarch.h: Re-generate.
* gdbarch.c: Re-generate.

Change-Id: I11f56dbcd4c3532fb195a08ba93bccf1d12a03c8

3 years agogdb: rename things related to step over chains
Simon Marchi [Fri, 4 Dec 2020 21:43:53 +0000 (16:43 -0500)] 
gdb: rename things related to step over chains

Rename step_over_queue_head to global_thread_step_over_chain_head, to
make it more obvious when reading code that we are touching the global
queue.  Rename all functions that operate on it to have "global" in
their name, to make it clear on which chain they operate on.  Also, in a
subsequent patch, we'll need both global and non-global versions of
these functions, so it will be easier to do the distinction if they are
named properly.

Normalize the naming to use "chain" everywhere instead of sometimes
"queue", sometimes "chain".

I also reworded a few comments in gdbthread.h.  They implied that the
step over chain is per-inferior, when in reality there is only one
global chain, not one per inferior, as far as I understand.

gdb/ChangeLog:

* gdbthread.h (thread_step_over_chain_enqueue): Rename to...
(global_thread_step_over_chain_enqueue): ... this.  Update all
users.
(thread_step_over_chain_remove): Rename to...
(global_thread_step_over_chain_remove): ... this.  Update all
users.
(thread_step_over_chain_next): Rename to...
(global_thread_step_over_chain_next): ... this.  Update all
users.
* infrun.h (step_over_queue_head): Rename to...
(global_thread_step_over_chain_head): ... this.  Update all
users.
* infrun.c (step_over_queue_head): Rename to...
(global_thread_step_over_chain_head): ... this.  Update all
users.
* thread.c (step_over_chain_remove): Rename to...
(thread_step_over_chain_remove): ... this.  Update all users.
(thread_step_over_chain_next): Rename to...
(global_thread_step_over_chain_next): ... this.  Update all
users.
(thread_step_over_chain_enqueue): Rename to...
(global_thread_step_over_chain_enqueue): ... this.  Update all
users.
(thread_step_over_chain_remove): Rename to...
(global_thread_step_over_chain_remove): ... this.  Update all
users.

Change-Id: Iabbf57d83c01321ca199d83fadb57f5b04e4d6d9

3 years agogdb: get rid of get_displaced_stepping_state
Simon Marchi [Fri, 4 Dec 2020 21:43:53 +0000 (16:43 -0500)] 
gdb: get rid of get_displaced_stepping_state

Remove function get_displaced_stepping_state.  When it was introduced,
inferiors' displaced stepping state was kept in a linked list in
infrun.c, so it was handy.  Nowadays, the state is kept inside struct
inferior directly, so we can just access it directly instead.

gdb/ChangeLog:

* infrun.c (get_displaced_stepping_state): Remove, change
callers to access the field directly.

Change-Id: I9a733e32e29c7ebf856ab0befe1076bbb8c7af69

3 years agogdb: restore displaced step buffer bytes when another thread forks
Simon Marchi [Fri, 4 Dec 2020 21:43:52 +0000 (16:43 -0500)] 
gdb: restore displaced step buffer bytes when another thread forks

In handle_inferior_event, where we handle forks, we make sure to restore
the bytes of the displaced stepping buffer in the child's address
space.  However, we only do it when the forking thread was the one
doing a displaced step.  It could happen that a thread forks while
another one is doing a displaced step.  In this case, we also need to
restore the bytes in the child.

Move the byte-restoring code outside of the condition that checks
whether the event thread was displaced stepping.

gdb/ChangeLog:

* infrun.c (handle_inferior_event): Restore displaced step
buffer bytes in child process when handling fork, even if fork
happened in another thread than the displaced-stepping one.

Change-Id: Ibb0daaeb123aba03f4fb4b4d820754eb2436bc69

3 years agogdb: clear inferior displaced stepping state and in-line step-over info on exec
Simon Marchi [Fri, 4 Dec 2020 21:43:52 +0000 (16:43 -0500)] 
gdb: clear inferior displaced stepping state and in-line step-over info on exec

When a process does an exec, all its program space is replaced with the
newly loaded executable.  All non-main threads disappear and the main
thread starts executing at the entry point of the new executable.

Things can go wrong if a displaced step operation is in progress while
we process the exec event.

If the main thread is the one executing the displaced step: when that
thread (now executing in the new executable) stops somewhere (say, at a
breakpoint), displaced_step_fixup will run and clear up the state.  We
will execute the "fixup" phase for the instruction we single-stepped in
the old program space.  We are now in a completely different context,
so doing the fixup may corrupt the state.

If it is a non-main thread that is doing the displaced step: while
handling the exec event, GDB deletes the thread_info representing that
thread (since the thread doesn't exist in the inferior after the exec).
But inferior::displaced_step_state::step_thread will still point to it.
When handling events later, this condition, in displaced_step_fixup,
will likely never be true:

    /* Was this event for the thread we displaced?  */
    if (displaced->step_thread != event_thread)
      return 0;

... since displaced->step_thread points to a deleted thread (unless that
storage gets re-used for a new thread_info, but that wouldn't be good
either).  This effectively makes the displaced stepping buffer occupied
for ever.  When a thread in the new program space will want to do a
displaced step, it will wait for ever.

I think we simply need to reset the displaced stepping state of the
inferior on exec.  Everything execution-related that existed before the
exec is now gone.

Similarly, if a thread does an in-line step over an exec syscall
instruction, nothing clears the in-line step over info when the event is
handled.  So it the in-line step over info stays there indefinitely, and
things hang because we can never start another step over.  To fix this,
I added a call to clear_step_over_info in infrun_inferior_execd.

Add a test with a program with two threads that does an exec.  The test
includes the following axes:

- whether it's the leader thread or the other thread that does the exec.

- whether the exec'r and exec'd program have different text segment
  addresses.  This is to hopefully catch cases where the displaced
  stepping info doesn't get reset, and GDB later tries to restore bytes
  of the old address space in the new address space.  If the mapped
  addresses are different, we should get some memory error.   This
  happens without the patch applied:

  $ ./gdb -q -nx --data-directory=data-directory testsuite/outputs/gdb.threads/step-over-exec/step-over-exec-execr-thread-leader-diff-text-segs-true -ex "b main" -ex r -ex "b my_execve_syscall if 0"  -ex "set displaced-stepping on"
  ...
  Breakpoint 1, main (argc=1, argv=0x7fffffffde38) at /home/simark/src/binutils-gdb/gdb/testsuite/gdb.threads/step-over-exec.c:69
  69        argv0 = argv[0];
  Breakpoint 2 at 0x60133a: file /home/simark/src/binutils-gdb/gdb/testsuite/lib/my-syscalls.S, line 34.
  (gdb) c
  Continuing.
  [New Thread 0x7ffff7c62640 (LWP 1455423)]
  Leader going in exec.
  Exec-ing /home/simark/build/binutils-gdb/gdb/testsuite/outputs/gdb.threads/step-over-exec/step-over-exec-execr-thread-leader-diff-text-segs-true-execd
  [Thread 0x7ffff7c62640 (LWP 1455423) exited]
  process 1455418 is executing new program: /home/simark/build/binutils-gdb/gdb/testsuite/outputs/gdb.threads/step-over-exec/step-over-exec-execr-thread-leader-diff-text-segs-true-execd
  Error in re-setting breakpoint 2: Function "my_execve_syscall" not defined.
  No unwaited-for children left.
  (gdb) n
  Single stepping until exit from function _start,
  which has no line number information.
  Cannot access memory at address 0x6010d2
  (gdb)

- Whether displaced stepping is allowed or not, so that we end up
  testing both displaced stepping and in-line stepping on arches that do
  support displaced stepping (otherwise, it just tests in-line stepping
  twice I suppose)

To be able to precisely put a breakpoint on the syscall instruction, I
added a small assembly file (lib/my-syscalls.S) that contains minimal
Linux syscall wrappers.  I prefer that to the strategy used in
gdb.base/step-over-syscall.exp, which is to stepi into the glibc wrapper
until we find something that looks like a syscall instruction, I find
that more predictable.

gdb/ChangeLog:

* infrun.c (infrun_inferior_execd): New function.
(_initialize_infrun): Attach inferior_execd observer.

gdb/testsuite/ChangeLog:

* gdb.threads/step-over-exec.exp: New.
* gdb.threads/step-over-exec.c: New.
* gdb.threads/step-over-exec-execd.c: New.
* lib/my-syscalls.S: New.
* lib/my-syscalls.h: New.

Change-Id: I1bbc8538e683f53af5b980091849086f4fec5ff9

3 years agogdb: add inferior_execd observable
Simon Marchi [Fri, 4 Dec 2020 21:43:51 +0000 (16:43 -0500)] 
gdb: add inferior_execd observable

I want to add another action (clearing displaced stepping state) that
happens when an inferior execs.  I think it would be cleaner to have an
observer for this event, rather than have infrun know about each other
sub-component.

Replace the calls to solib_create_inferior_hook and
jit_inferior_created_hook in follow_exec by observers.

gdb/ChangeLog:

* observable.h (inferior_execd): Declare new observable.
* observable.c (inferior_execd): Declare new observable.
* infrun.c (follow_exec): Notify inferior_execd observer.
* jit.c (jit_inferior_created_hook): Make static.
(_initialize_jit): Register inferior_execd observer.
* jit.h (jit_inferior_created_hook): Remove declaration.
* solib.c (_initialize_solib): Register inferior_execd observer.

Change-Id: I000cce00094e23baa67df693d912646b6ae38e44

3 years ago[gdb] Fix heap-buffer-overflow in completion_tracker::build_completion_result
Tom de Vries [Fri, 4 Dec 2020 21:35:07 +0000 (22:35 +0100)] 
[gdb] Fix heap-buffer-overflow in completion_tracker::build_completion_result

When building gdb with address sanitizer and running test-case
gdb.base/completion.exp, we run into:
...
==5743==ERROR: AddressSanitizer: heap-buffer-overflow on address \
  0x60200025c02f at pc 0x000000cd9d64 bp 0x7fff3297da30 sp 0x7fff3297da28
READ of size 1 at 0x60200025c02f thread T0
    #0 0xcd9d63 in completion_tracker::build_completion_result(char const*, \
                     int, int) gdb/completer.c:2258
  ...
0x60200025c02f is located 1 bytes to the left of 1-byte region \
  [0x60200025c030,0x60200025c031)
...

This can be reproduced using just:
...
$ gdb
(gdb) p/d[TAB]
...

The problem is in this code in completion_tracker::build_completion_result:
...
      bool completion_suppress_append
        = (suppress_append_ws ()
           || match_list[0][strlen (match_list[0]) - 1] == ' ');
...
If strlen (match_list[0]) == 0, then we access match_list[0][-1].

Fix this by testing if the memory access is in bounds before doing the memory
access.

Tested on x86_64-linux.

gdb/ChangeLog:

2020-12-04  Tom de Vries  <tdevries@suse.de>

PR gdb/27003
* completer.c (completion_tracker::build_completion_result): Don't
access match_list[0][-1].

3 years agoRemove redundant typedefs
Tom Tromey [Fri, 4 Dec 2020 20:09:43 +0000 (13:09 -0700)] 
Remove redundant typedefs

I was inspired by this patch of Simon's:

https://sourceware.org/pipermail/gdb-patches/2020-November/173522.html

... to remove other typedefs that are no longer necessary now that gdb
uses C++.

I didn't remove absolutely every one -- I didn't touch the tdep files.
However, I removed many of them.  In some cases, I removed an existing
different struct tag.

2020-12-04  Tom Tromey  <tromey@adacore.com>

* linespec.c (struct linespec_token): Rename; remove typedef.
* guile/scm-block.c (struct block_smob): Remove typedef.
(struct block_syms_progress_smob): Likewise.
* guile/scm-symbol.c (struct symbol_smob): Remove typedef.
* guile/scm-symtab.c (symtab_smob): Remove typedef.
(struct sal_smob): Remove typedef.
* guile/scm-param.c (struct param_smob): Remove typedef.
* guile/scm-progspace.c (struct pspace_smob): Rename.
* guile/scm-objfile.c (struct objfile_smob): Rename.
* guile/scm-iterator.c (struct iterator_smob): Rename.
* guile/scm-frame.c (struct frame_smob): Rename.
* guile/scm-arch.c (struct arch_smob): Rename.
* guile/scm-type.c (struct field_smob): Remove typedef.
(struct type_smob): Rename.
* guile/scm-cmd.c (struct command_smob): Remove typedef.
* guile/scm-ports.c (struct ioscm_memory_port): Remove typedef.
* guile/scm-value.c (struct value_smob): Remove typedef.
* guile/scm-lazy-string.c (lazy_string_smob): Remove typedef.
* guile/guile-internal.h (struct scheme_variable)
(struct scheme_function, struct scheme_integer_constant)
(struct gdb_smob, struct chained_gdb_smob)
(struct eqable_gdb_smob, arch_smob, frame_smob, iterator_smob)
(objfile_smob, pspace_smob, type_smob): Remove typedef.
* guile/scm-pretty-print.c (pretty_printer_smob): Remove typedef.
(struct pretty_printer_worker_smob): Remove typedef.
* guile/scm-exception.c (struct exception_smob): Remove typedef.
* python/py-block.c (struct block_object): Remove typedef.
(block_syms_iterator_object): Update.
(set_block): Update.
(block_syms_iterator_object): Remove typedef.
* python/py-inferior.c (struct membuf_object): Remove typedef.
* python/py-symtab.c (struct symtab_object): Remove typedef.
(set_symtab): Update.
(sal_object): Remove typedef.
(set_sal): Update.
* python/py-frame.c (frame_object): Remove typedef.
* python/py-record-btrace.c (struct btpy_list_object): Remove
typedef.
* python/py-arch.c (struct arch_object): Remove typedef.
* python/py-linetable.c (struct linetable_entry_object)
(linetable_object, struct ltpy_iterator_object): Remove typedef.
* python/py-events.h (eventregistry_object): Remove typedef.
(struct events_object): Remove typedef.
* python/python-internal.h (gdbpy_breakpoint_object): Remove
typedef.
(thread_object): Remove typedef.
* python/py-progspace.c (pspace_object): Remove typedef.
* python/py-value.c (struct value_object): Remove typedef.
* python/py-record.h (recpy_record_object): Remove typedef.
(struct recpy_element_object): Remove typedef.
* python/py-lazy-string.c (lazy_string_object): Remove typedef.
* python/py-objfile.c (objfile_object): Remove typedef.
* python/py-cmd.c (struct cmdpy_object): Remove typedef.
* python/py-type.c (type_object): Remove typedef.
(typy_iterator_object): Update.
(set_type): Update.
(field_object): Remove typedef.
(typy_iterator_object): Remove typedef.
* python/py-registers.c (register_descriptor_iterator_object):
Remove typedef.
(struct register_descriptor_object)
(struct reggroup_iterator_object, struct reggroup_object): Remove
typedef.
* python/py-record.c (recpy_gap_object): Remove typedef.
* python/py-symbol.c (symbol_object): Remove typedef.
(set_symbol): Update.
* python/py-event.h (event_object): Remove typedef.
* python/py-param.c (parmpy_object): Remove typedef.
* python/py-instruction.c (struct py_insn_obj): Remove typedef.
* python/py-unwind.c (struct pending_frame_object): Remove typedef.
(unwind_info_object, struct cached_frame_info): Likewise.

3 years agogdb/testsuite: make declare_labels use better default label names
Simon Marchi [Fri, 4 Dec 2020 20:08:54 +0000 (15:08 -0500)] 
gdb/testsuite: make declare_labels use better default label names

When using the single-element form of argument to declare_labels, the
generated label (in the assembly file) is of the format ".LlabelN",
where N is a number.

I propose making it use the name of the label by default.  Calling:

    declare_labels foo

will generate the ".LfooN" in the assembly file (again, where N is a
number).  When debugging the output of the DWARF assembler, it makes it
easier to map labels to the source.  Also, when defining the same label
twice by mistake in the Tcl code (like I d id), it's easier to track the
error from the message to the root cause:

    -/home/smarchi/build/binutils-gdb/gdb/testsuite/outputs/gdb.dwarf2/implptrpiece/implptrpiece-dw.S:62: Error: symbol `.Llabel5' is already defined
    +/home/smarchi/build/binutils-gdb/gdb/testsuite/outputs/gdb.dwarf2/implptrpiece/implptrpiece-dw.S:62: Error: symbol `.Lvar_label5' is already defined

This doesn't change anything for the test cases, it just makes the
assembly output a bit nicer.

gdb/testsuite/ChangeLog:

* lib/dwarf.exp (declare_labels): Use name as text if text is
not provided.

Change-Id: I63856c1fa6390498fd5b9d66f471f817ff0a465c

3 years agoFix building gdb release from tar file without makeinfo
Bernd Edlinger [Wed, 25 Nov 2020 17:52:49 +0000 (18:52 +0100)] 
Fix building gdb release from tar file without makeinfo

Add GDBvn.texi and version.subst to the release tar file,
so the gdb.info does not need makeinfo.

This avoids the need for makeinfo to be available.

2020-12-04  Bernd Edlinger  <bernd.edlinger@hotmail.de>

* Makefile.in: Delete GDBvn.texi and version.subst only in
the maintainer-clean target.

3 years agoUpdate gdb/ChangeLog to reflect the PR for a bug fix
Shahab Vahedi [Fri, 4 Dec 2020 15:21:39 +0000 (16:21 +0100)] 
Update gdb/ChangeLog to reflect the PR for a bug fix

This is just an update in the gdb/ChangeLog to reflect a newly
created PR [27015] for a bugfix commit:

10c19fad  arc: Write correct "eret" value during register collection

3 years agoConstify value_internal_function_name
Tom Tromey [Fri, 4 Dec 2020 15:15:14 +0000 (08:15 -0700)] 
Constify value_internal_function_name

I noticed that value_internal_function_name should have a const return
type.  This patch makes this change.

gdb/ChangeLog
2020-12-04  Tom Tromey  <tromey@adacore.com>

* value.c (value_internal_function_name): Make return type const.
* value.h (value_internal_function_name): Make return type const.

3 years agoFix shifting of negative value
Luis Machado [Wed, 2 Dec 2020 14:29:30 +0000 (11:29 -0300)] 
Fix shifting of negative value

When UBSan is enabled, I noticed runtime errors complaining of shifting
of negative numbers.

This patch fixes this by reusing existing macros from the ARM port.

It also removes unused macros from AArch64's port.

gdb/ChangeLog:

2020-12-04  Luis Machado  <luis.machado@linaro.org>

* aarch64-tdep.c (submask, bit, bits): Remove.
* arch/aarch64-insn.c (extract_signed_bitfield): Remove.
(aarch64_decode_adr, aarch64_decode_b aarch64_decode_bcond)
(aarch64_decode_cb, aarch64_decode_tb)
(aarch64_decode_ldr_literal): Use sbits to extract a signed
immediate.
* arch/aarch64-insn.h (submask, bits, bit, sbits): New macros.

3 years ago[gdb/testsuite] Make gdb.arch/amd64-gs_base.exp unsupported for i386
Tom de Vries [Fri, 4 Dec 2020 12:36:48 +0000 (13:36 +0100)] 
[gdb/testsuite] Make gdb.arch/amd64-gs_base.exp unsupported for i386

With target board unix/-m32 I run into:
...
(gdb) print /x $fs_base^M
$1 = void^M
(gdb) FAIL: gdb.arch/amd64-gs_base.exp: print fs_base
...

The problem is that the fs_base register is not supported for i386.

Fix this by making the test unsupported if fs_base/gs_base don't show up in
info register sys output.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-12-04  Tom de Vries  <tdevries@suse.de>

PR testsuite/26990
* gdb.arch/amd64-gs_base.exp: Handle -m32 where fs_base and gs_base
are unsupported.

3 years ago[gdb/tdep] Handle static field in i386_16_byte_align_p
Tom de Vries [Fri, 4 Dec 2020 12:36:48 +0000 (13:36 +0100)] 
[gdb/tdep] Handle static field in i386_16_byte_align_p

When running test-case on gdb.cp/many-args.exp with target board unix/-m32, I
run into:
...
(gdb) p check_val (ref_val, ref_val, ... , ref_val, ref_val)^M
$1 = false^M
(gdb) FAIL: gdb.cp/many-args.exp: check passing many structures
...

The test source contains struct ss:
...
typedef int v4si __attribute__ ((vector_size (16)));

struct ss
{
  static v4si static_field;
  unsigned char aa;
};
...
and i386_16_byte_align_p returns true for this type.

Fix this by skipping static fields in i386_16_byte_align_p.

Tested on x86_64-linux.

gdb/ChangeLog:

2020-12-04  Tom de Vries  <tdevries@suse.de>

PR tdep/27007
* i386-tdep.c (i386_16_byte_align_p): Skip static fields.

3 years ago[gdb/testsuite] Fix control-flow in gdb.reverse/insn-reverse.exp
Tom de Vries [Fri, 4 Dec 2020 12:36:48 +0000 (13:36 +0100)] 
[gdb/testsuite] Fix control-flow in gdb.reverse/insn-reverse.exp

In gdb.reverse/insn-reverse.exp, we have loop containing a call to
gdb_test_multiple, which itself contains a break:
...
  for {} {$count < 500} {incr count} {
    ...
    gdb_test_multiple "x/i \$pc" "" {
      ...
      break
    }
...

On SLE-11 with:
...
$ runtest --version
Expect version is       5.44.1.11
Tcl version is          8.5
Framework version is    1.4.4
...
the break doesn't seem to have the effect of breaking out of the loop.

The break does have the effect of terminating evaluation of the expect clause,
which means we don't set insn_array, after which we run into:
...
ERROR: tcl error sourcing src/gdb/testsuite/gdb.reverse/insn-reverse.exp.
ERROR: can't read "insn_array(5)": no such element in array
...

gdb/testsuite/ChangeLog:

2020-12-04  Tom de Vries  <tdevries@suse.de>

* gdb.reverse/insn-reverse.exp: Don't break inside gdb_test_multiple
clause.

3 years ago[gdb/testsuite] Fix count usage in gdb.reverse/insn-reverse.exp
Tom de Vries [Fri, 4 Dec 2020 12:36:47 +0000 (13:36 +0100)] 
[gdb/testsuite] Fix count usage in gdb.reverse/insn-reverse.exp

Consider the test-case gdb.reverse/insn-reverse.exp.

After the loop setting count, the valid entries in various arrays range from 0
to $count - 1 inclusive.

Then $count is decremented:
...
       incr count -1
...
after which the valid entries range from 0 to $count inclusive.

The first subsequent loop handles that properly:
...
       for {set i $count} {$i >= 0} {incr i -1} {
...
but the following loop does not, because it treats $count as exclusive bound:
...
for {set i 0} {$i < $count} {incr i} {
...

Fix this by removing the incr, and using $count - 1 as starting value in the
first loop.

gdb/testsuite/ChangeLog:

2020-12-04  Tom de Vries  <tdevries@suse.de>

* gdb.reverse/insn-reverse.exp: Fix count handling.

3 years ago[gdb/testsuite] Fix gdb.reverse/insn-reverse-x86.c for -m32
Tom de Vries [Fri, 4 Dec 2020 12:36:47 +0000 (13:36 +0100)] 
[gdb/testsuite] Fix gdb.reverse/insn-reverse-x86.c for -m32

When running test-case gdb.reverse/insn-reverse.exp with target board
unix/-m32, we get:
...
spawn -ignore SIGHUP gcc -fno-stack-protector -fdiagnostics-color=never \
  -c -g -m32 -o insn-reverse0.o insn-reverse.c^M
insn-reverse-x86.c: Assembler messages:^M
insn-reverse-x86.c:88: Error: bad register name `%r8w'^M
....

Fix this by guarding x86_64 assembly in insn-reverse-x86.c with #ifdef
__x86_64__.

Tested on x86_64-linux, with native and unix/-m32.

gdb/testsuite/ChangeLog:

2020-12-04  Tom de Vries  <tdevries@suse.de>

* gdb.reverse/insn-reverse-x86.c: Guard x86_64 assembly with #ifdef
__x86_64__.

3 years ago[gdb/testsuite] Handle SIGILL in gdb.reverse/insn-reverse.exp
Tom de Vries [Fri, 4 Dec 2020 12:36:47 +0000 (13:36 +0100)] 
[gdb/testsuite] Handle SIGILL in gdb.reverse/insn-reverse.exp

Consider test-case gdb.reverse/insn-reverse.exp.

It runs a number of subtests, dependent on the architecture, f.i. for
x86_64 it runs subtests rdrand and rdseed.

For each subtest, it checks whether the subtest is supported and otherwise
bails out of that subtest.

However, there may be a problem with the support test or the information it
relies on, and if it states that a subtest is supported while it is actually
not, we may run into a SIGILL, as f.i. described in PR21166, which results in
tcl errors like this:
...
ERROR: tcl error sourcing src/gdb/testsuite/gdb.reverse/insn-reverse.exp.
ERROR: can't read "insn_array(5)": no such element in array
...

We can emulate this by inserting a sigfpe in function rdrand in
insn-reverse-x86.c, like this:
...
  volatile int a = 0; volatile int b = 1; volatile int c = b / a;
...

The problem is that the loop in the test-case attempts to stepi over of all
insn in rdrand, but because of the signal it will never get to the last insn.

Handle this by detecting that the stepi made no progress, and bailing out of
the loop.

Furthermore, make running of the subtests independent, such that a SIGILL in
subtest rdrand does not affect running of subtest rdseed.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-12-04  Tom de Vries  <tdevries@suse.de>

* gdb.reverse/insn-reverse.c (test_nr): New var.
(usage, parse_args): New function.
(main): Call parse_args.  Only run test for test_nr.
* gdb.reverse/insn-reverse.exp: Detect lack of progress in stepi loop
and bail out.  Run subtests individually, using an inferior arg
specifying the subtest.

3 years agoIBM Z: Add risbgz and risbgnz extended mnemonics
Andreas Krebbel [Fri, 4 Dec 2020 08:00:43 +0000 (09:00 +0100)] 
IBM Z: Add risbgz and risbgnz extended mnemonics

These two extended mnemonics are documented in the Principles of
Operations manual but currently not supported by Binutils. They
provide aliases for already supported instructions with the zero flag
being set.  The flag otherwise is mingled into one of the immediate
operands what makes asm code much harder to read.

opcodes/

* s390-opc.txt: Add risbgz and risbgnz.
* s390-opc.c (U6_26): New operand type.
(INSTR_RIE_RRUUU2, MASK_RIE_RRUUU2): New instruction format and
mask.

gas/

* testsuite/gas/s390/zarch-z10.s: Add tests for risbgz.
* testsuite/gas/s390/zarch-z10.d: Add regexp for risbgz.
* testsuite/gas/s390/zarch-zEC12.s: Add tests for risbgnz.
* testsuite/gas/s390/zarch-zEC12.d: Add regexp for risbgnz.

3 years agoasan: readelf: memory leaks
Alan Modra [Thu, 3 Dec 2020 05:40:37 +0000 (16:10 +1030)] 
asan: readelf: memory leaks

This tidies some code used by readelf, hopefully fixing some
intermittent oss-fuzz bug reports that likely could only be reproduced
by feeding readelf two or more object files on the command line.  The
second and subsequent file may see non-zero state in .bss variables,
and non-initial values in .data variables.  This patch fixes some of
those, and moves some .data variables to .rodata.

* dwarf.c (frame_display_row): Do without static variable "sloc".
(cu_tu_indexes_read): Move to file scope.
(free_debug_memory): Reset it here, along with level_type_signed.
Free and clear a number of other static variables.
* readelf.c (arm_attr_public_tag <table>): Constify, updating..
(arm_attr_tag_*): ..all these uses.
(process_mips_specific): Free "rels" on error path.

3 years agoPR26978, Inconsistency for strong foo@v1 and weak foo@@v1
Alan Modra [Wed, 2 Dec 2020 02:33:23 +0000 (13:03 +1030)] 
PR26978, Inconsistency for strong foo@v1 and weak foo@@v1

Prior to this patch
  ld -shared --version-script=pr26979.ver pr26978a.o pr26978b.o
results in
  ld: pr26978b.o: in function `foo_v1':
  (.text+0x0): multiple definition of `foo@v1'
  ld: pr26978b.o:(*IND*+0x0): multiple definition of `foo'
while
  ld -shared --version-script=pr26979.ver pr26978b.o pr26978a.o
results in no error, but some odd dynamic symbols.
  ... 0 NOTYPE  GLOBAL DEFAULT    7 foo@v1
  ... 0 NOTYPE  WEAK   DEFAULT    7 foo@@v1

When linking an undecorated reference to foo against such a shared
library, ld complains about multiple definitions of foo@v1 while gold
creates a dynamic reference to foo@v1.  That results in foo@v1 being
used at runtime.

While we could error in both cases, it is reasonable to say foo@v1 and
foo@@v1 are in fact the same symbol.  (Same name, same version.  The
only real difference is that foo@@v1 satisfies a reference to plain
foo, while foo@v1 does not.)  Just as merging a weak undecorated sym
with a strong sym results in the strong sym prevailing, so should the
strong foo@v1 prevail.  And since there is a definition that satisfies
plain foo, the foo@@v1 variety of dynamic symbol should be emitted at
the foo@v1 value.  That makes the testcase that currently links
continue to produce a shared library, and that shared library can now
be used by both ld and gold with the same runtime behaviour as when
using gold with the odd dynamic symbol library.

bfd/
PR 26978
* elflink.c (_bfd_elf_add_default_symbol): Handle the case where
a new weak sym@@ver should be overridden by an existing sym@ver.
(elf_link_add_object_symbols): Don't _bfd_elf_add_default_symbol
for a new weak sym@ver when sym@@ver already exists.
* linker.c (link_action): Choose MIND for previous indirect,
current def, rather than MDEF.
(_bfd_generic_link_add_one_symbol <MIND>): Handle redefinition of
weak indirect symbol.
ld/
* testsuite/ld-elf/pr26978a.d,
* testsuite/ld-elf/pr26978a.s,
* testsuite/ld-elf/pr26978b.d,
* testsuite/ld-elf/pr26978b.s: New tests.

3 years agoAutomatic date update in version.in
GDB Administrator [Fri, 4 Dec 2020 00:00:17 +0000 (00:00 +0000)] 
Automatic date update in version.in

3 years agogdb: fix logic of find_comp_unit and set_comp_unit
Simon Marchi [Thu, 3 Dec 2020 20:47:56 +0000 (15:47 -0500)] 
gdb: fix logic of find_comp_unit and set_comp_unit

The logic in find_comp_unit and set_comp_unit is reversed.  When the BFD
requires relocation, we want to put the comp_unit structure in the
map where the comp_unit objects are not shared, that is the one indexed
by objfile.  If the BFD does not require relocation, then, we can share
a single comp_unit structure for all users of that BFD, so we want to
put it in the BFD-indexed map.  The comments on top of
dwarf2_frame_bfd_data and dwarf2_frame_objfile_data make that clear.

Fix it by swapping the two in find_comp_unit and set_comp_unit.

I don't have a test for this, because I don't see how to write one in a
reasonable amount of time.

gdb/ChangeLog:

PR gdb/26876
* dwarf2/frame.c (find_comp_unit, set_comp_unit): Reverse use of
dwarf2_frame_bfd_data and dwarf2_frame_objfile_data.

Change-Id: I80c1ee7ad8425fa4947de65b170973d05f5a52ec

3 years agoIBM Z: Add support for HLASM extended mnemonics
Andreas Krebbel [Thu, 3 Dec 2020 15:31:15 +0000 (16:31 +0100)] 
IBM Z: Add support for HLASM extended mnemonics

Add extended mnemonics used in the HLASM assembler.  All of them are
just aliases for instructions we already support and help when
assembling code which was written for the HLASM assembler.

The HLASM mnemonics are documented here:
https://www.ibm.com/support/knowledgecenter/SSENW6_1.6.0/com.ibm.hlasm.v1r6.asm/asmr1023.pdf

See the 'Branching with extended mnemonic codes' chapter.

objdump will still print the existing mnemonics with the exception of
relative nop branches (i.e. conditional branches with an empty
condition code mask).  Now we have jnop and jgnop which will be used
by objdump when possible.

The same change have been applied to the LLVM assembler:
https://reviews.llvm.org/D92185

opcodes/

* s390-opc.txt: Add extended mnemonics.

gas/

* testsuite/gas/s390/esa-g5.s: Test new extended mnemonics.
* testsuite/gas/s390/esa-g5.d: Likewise.
* testsuite/gas/s390/esa-z900.s: Likewise.
* testsuite/gas/s390/esa-z900.d: Likewise.
* testsuite/gas/s390/zarch-z900.s: Likewise.
* testsuite/gas/s390/zarch-z900.d: Likewise.

ld/

* testsuite/ld-s390/tlsbin_64.dd: The newly added jgnop mnemonic
replaces long relative branches with empty condition code mask.

3 years agoVAX/LD/testsuite: Wrap excessively long lines
Maciej W. Rozycki [Thu, 3 Dec 2020 13:27:45 +0000 (13:27 +0000)] 
VAX/LD/testsuite: Wrap excessively long lines

A couple of lines in the vax-elf.exp test script exceed 80 characters;
wrap them.

ld/
* testsuite/ld-vax-elf/vax-elf.exp: Wrap excessively long lines
throughout.

3 years ago[GOLD] PR26936 test
Alan Modra [Thu, 3 Dec 2020 01:29:42 +0000 (11:59 +1030)] 
[GOLD] PR26936 test

Fails if you configure with --disable-x86-used-note.  Fix that.

* testsuite/Makefile.am (pr26936a.o): Pass -mx86-used-note=yes.
(pr26936b.o, pr26936c.o, pr26936d.o): Likewise.
* testsuite/Makefile.in: Regenerate.

3 years agoAutomatic date update in version.in
GDB Administrator [Thu, 3 Dec 2020 00:00:14 +0000 (00:00 +0000)] 
Automatic date update in version.in

3 years agotestsuite/ld-elf/pr26936.d: Pass -W.
Hans-Peter Nilsson [Wed, 2 Dec 2020 20:53:42 +0000 (21:53 +0100)] 
testsuite/ld-elf/pr26936.d: Pass -W.

Required for the expected "CU:" to be emitted for long
source-paths.  See binutils/dwarf.c:

 if (do_wide || strlen (directory) < 76)
   printf (_("CU: %s/%s:\n"), directory, file_table[0].name);
 else
   printf ("%s:\n", file_table[0].name);

3 years agogdb/riscv: rewrite target description validation, add rv32e support
Andrew Burgess [Mon, 23 Nov 2020 18:03:32 +0000 (18:03 +0000)] 
gdb/riscv: rewrite target description validation, add rv32e support

This commit started as adding rv32e support to gdb.  The rv32e
architecture is a cut-down rv32i, it only has 16 x-registers compared
to the usual 32, and an rv32e target should not have any floating
point registers.

In order to add this I needed to adjust the target description
validation checks that are performed from riscv_gdbarch_init, and I
finally got fed up with the current scheme of doing these checks and
rewrote this code.

Unfortunately the rv32e changes are currently mixed in with the
rewrite of the validation scheme.  I could split these apart if anyone
is really interested in seeing these two ideas as separate patches.

The main idea behind this change is that where previously I tried to
have a purely data driven approach, a set of tables one for each
expected feature, and then a single generic function that would
validate a feature given a table, I have created a new class for each
feature.  Each class has its own check member function which allows
the logic for how to check each feature to be different.  I think the
new scheme is much easier to follow.

There are some other changes that I made to the validation code as
part of this commit.

I've relaxed some of the checks related to the floating point CSRs.
Previously the 3 CSRs fflags, frm, and fcsr all had to be present in
either the fpu feature or the csr feature.  This requirement is now
relaxed, if the CSRs are not present then gdb will not reject the
target description.  My thinking here is that there's no gdb
functionality that specifically requires these registers, and so, if a
target offers a description without these registers nothing else in
gdb should stop working.

And as part of the rv32e support targets now only have to provide the
first 16 x-registers and $pc.  The second half of the x-registers (x16
-> x31) are now optional.

gdb/ChangeLog:

* arch/riscv.c: Include 'rv32e-xregs.c'.
(riscv_create_target_description): Update to handle rv32e.
* arch/riscv.h (struct riscv_gdbarch_features) <embedded>: New
member variable.
<operator==>: Update to account for new field.
<hash>: Likewise.
* features/Makefile (FEATURE_XMLFILES): Add riscv/rv32e-xregs.xml.
* features/riscv/rv32e-xregs.c: Generated.
* features/riscv/rv32e-xregs.xml: New file.
* riscv-tdep.c (riscv_debug_breakpoints): Move from later in the
file.
(riscv_debug_infcall): Likewise.
(riscv_debug_unwinder): Likewise.
(riscv_debug_gdbarch): Likewise.
(enum riscv_register_required_status): Delete.
(struct riscv_register_feature): Add constructor, delete default
constructor, copy, and assign constructors.
(struct riscv_register_feature::register_info) <required>: Delete.
<check>: Update comment and arguments.
(struct riscv_register_feature) <name>: Change to member function.
<prefer_first_name>: Delete.
<tdesc_feature>: New member function.
<registers>: Rename to...
<m_registers>: ...this.
<m_feature_name>: New member variable.
(riscv_register_feature::register_info::check): Update arguments.
(riscv_xreg_feature): Rewrite as class, create a single static
instance of the class.
(riscv_freg_feature): Likewise.
(riscv_virtual_feature): Likewise.
(riscv_csr_feature): Likewise.
(riscv_create_csr_aliases): Has become a member function inside
riscv_csr_feature class.
(riscv_abi_embedded): New function definition.
(riscv_register_name): Adjust to use new feature objects.
(struct riscv_call_info) <riscv_call_info>: Check for rv32e abi,
and adjust available argument registers.
(riscv_features_from_gdbarch_info): Check for EF_RISCV_RVE flag.
(riscv_check_tdesc_feature): Delete.
(riscv_tdesc_unknown_reg): Adjust to use new feature objects.
(riscv_gdbarch_init): Delete target description checking code, and
instead call to the new feature objects to perform the checks.
Reorder handling of no abi information case, allows small code
simplification.
(_initialize_riscv_tdep): Remove call, this is now done in the
riscv_csr_feature constructor.
* riscv-tdep.h (riscv_abi_embedded): Declare.

3 years agogdb/riscv: remove csr aliases created with DECLARE_CSR_ALIAS
Andrew Burgess [Thu, 26 Nov 2020 11:42:03 +0000 (11:42 +0000)] 
gdb/riscv: remove csr aliases created with DECLARE_CSR_ALIAS

In this commit:

  commit 767a879e31ce31179e6135c2f991f670a35709fa
  Date:   Tue Jun 9 17:38:30 2020 +0100

      gdb/riscv: Improved register alias name creation

RISC-V GDB was changed to make use of the DECLARE_CSR_ALIAS macro to
define register aliases for some CSRs.  Actually, only one alias was
created 'dscratch' as an alias for 'dscratch0'.  All of the other
DECLARE_CSR_ALIAS lines (from include/opcode/riscv-opc.h) were
filtered out.

In this commit:

  commit 08ccfccf0ed825be9be2972594d4be4a2207ef13
  Date:   Mon Jun 8 10:54:53 2020 +0800

      RISC-V: Support debug and float CSR as the unprivileged ones.

Changes were made to include/opcode/riscv-opc.h so that GDB no longer
created even the dscratch alias.

This caused a test failure in gdb.arch/riscv-tdesc-regs.exp.

In looking at how to address this failure I think that the best
strategy is, for now at least, to just remove the code that tries to
create aliases with DECLARE_CSR_ALIAS.

My thoughts are that:

  1. At least some of the aliases are for CSRs where the register now
  has a completely different use.  Being able to reference the CSR
  using a completely inappropriate name just seems confusing.  This
  was solved by the filtering added in the first commit referenced
  above.  But we certainly don't want to blindly add all aliases.

  2. Names presented in a target description are always honoured, so
  if a user has a legacy target then they should just start sending a
  target description with their legacy register names in, this problem
  is then solved.

  3. It's easy enough to figure out which CSRs a target has with the
  info registers command, so missing an alias shouldn't be a big
  issue.

  4.  Allowing users to use names for registers that differ from the
  names the target announces doesn't feel like a critical feature.  If
  in the future targets want multiple names for a register then maybe
  we could/should extend target descriptions to allow the target to
  send aliases as well as the primary name.... but that can wait for
  another day.

So in this commit I remove the use of DECLARE_CSR_ALIAS, and remove
the test that was failing.

gdb/ChangeLog:

* riscv-tdep.c (riscv_create_csr_aliases): Remove use of
DECLARE_CSR_ALIAS.

gdb/testsuite/ChangeLog:

* gdb.arch/riscv-tdesc-regs.exp: Remove unwanted test.

3 years agogdb/riscv: place unknown csrs into the correct register groups
Andrew Burgess [Tue, 24 Nov 2020 18:08:25 +0000 (18:08 +0000)] 
gdb/riscv: place unknown csrs into the correct register groups

Unknown riscv CSRs should not be in the 'general' group, but should be
in the system and csr register groups.

To see this in action connect to QEMU, this target advertises two
registers dscratch and mucounteren which are unknown to GDB (these are
legacy CSRs).  Before this commit these registers would show up in the
output of:

  (gdb) info registers
  ....
  dscratch       Could not fetch register "dscratch"; remote failure reply 'E14'
  mucounteren    Could not fetch register "mucounteren"; remote failure reply 'E14'

Ignore the errors, this is just a QEMU annoyance, it advertises these
CSRs, but doesn't actually let GDB read them.  These registers don't
show up in the output of either:

  (gdb) info registers csr
  (gdb) info registers system

After this commit this situation is reveresed, which makes more sense
to me.

gdb/ChangeLog:

* riscv-tdep.c (riscv_is_unknown_csr): New function,
implementation moved from riscv_register_reggroup_p.
(riscv_register_reggroup_p): Update group handling for unknown
CSRs.

gdb/testsuite/ChangeLog:

* gdb.arch/riscv-tdesc-regs.exp (get_expected_result): New proc,
update test to use this.

3 years agoAdd gnu global outputs to .gitignore
Enze Li [Wed, 2 Dec 2020 15:00:13 +0000 (10:00 -0500)] 
Add gnu global outputs to .gitignore

GNU Global outputs can be safely ignored.

ChangeLog:

2020-12-02  Enze Li  <lienze2010@hotmail.com>

* .gitignore: Add gnu global outputs.

Change-Id: I04ce68ab3279426195793adb56f834a34ee72ea2

3 years agoSync .gitignore with gcc
Simon Marchi [Wed, 2 Dec 2020 14:41:56 +0000 (09:41 -0500)] 
Sync .gitignore with gcc

Bring in a few lines that are in gcc's .gitignore but not binutils-gdb's
.gitignore.

ChangeLog:

* .gitignore: Sync with gcc.

Change-Id: I8900ddfbb5ab8cce6236e1905fdbb52fb4c291e2

3 years agoSearch for DWZ files in debug-file-directories as well
Sergio Durigan Junior [Sat, 14 Nov 2020 22:42:46 +0000 (17:42 -0500)] 
Search for DWZ files in debug-file-directories as well

When Debian (and Ubuntu) builds its binaries, it (still) doesn't use
dwz's "--relative" option.  This causes their debuginfo files to
carry a .gnu_debugaltlink section containing a full pathname to the
DWZ alt debug file, like this:

  $ readelf -wk /usr/bin/cat
  Contents of the .gnu_debugaltlink section:

    Separate debug info file: /usr/lib/debug/.dwz/x86_64-linux-gnu/coreutils.debug
    Build-ID (0x14 bytes):
   ee 76 5d 71 97 37 ce 46 99 44 32 bb e8 a9 1a ef 99 96 88 db

  Contents of the .gnu_debuglink section:

    Separate debug info file: 06d3bee37b8c7e67b31cb2689cb351102ae73b.debug
    CRC value: 0x53267655

This usually works OK, because most of the debuginfo files installed
via apt will be present in /usr/lib/debug anyway.  However, imagine
the following scenario:

- You are using /usr/bin/cat, it crashes on you and generates a
  corefile.

- You don't want/need to "apt install" the debuginfo file for
  coreutils from the repositories.  Instead, you already have the
  debuginfo files in a separate directory (e.g., $HOME/dbgsym).

- You start GDB and "set debug-file-directory $HOME/dbgsym/usr/lib/debug".
  You then get the following message:

  $ gdb -ex 'set debug-file-directory ./dbgsym/usr/lib/debug' -ex 'file /bin/cat' -ex 'core-file ./cat.core'
  GNU gdb (Ubuntu 10.1-0ubuntu1) 10.1
  ...
  Reading symbols from /bin/cat...
  Reading symbols from /home/sergio/gdb/dbgsym/usr/lib/debug/.build-id/bc/06d3bee37b8c7e67b31cb2689cb351102ae73b.debug...
  could not find '.gnu_debugaltlink' file for /home/sergio/gdb/dbgsym/usr/lib/debug/.build-id/bc/06d3bee37b8c7e67b31cb2689cb351102ae73b.debug

This error happens because GDB is trying to locate the build-id
link (inside /home/sergio/gdb/dbgsym/usr/lib/debug/.build-id) for the
DWZ alt debug file, which doesn't exist.  Arguably, this is a problem
with how dh_dwz works in Debian, and it's something I'm also planning
to tackle.  But, back at the problem at hand.

Besides not being able to find the build-id link in the directory
mentioned above, GDB also tried to open the DWZ alt file using its
filename.  The problem here is that, since we don't have the distro's
debuginfo installed, it can't find anything under /usr/lib/debug that
satisfies it.

It occurred to me that a good way to workaround this problem is to
actually try to locate the DWZ alt debug file inside the
debug-file-directories (that were likely provided by the user).  So
this is what the proposed patch does.

The idea here is simple: get the filename extracted from the
.gnu_debugaltlink section, and manipulate it in order to replace the
initial part of the path (everything before "/.dwz/") by whatever
debug-file-directories the user might have provided.

I talked with Mark Wielaard and he agrees this is a sensible approach.
In fact, apparently this is something that eu-readelf also does.

I regtested this code, and no regressions were found.

2020-12-01  Sergio Durigan Junior  <sergiodj@sergiodj.net>

* dwarf2/read.c (dwz_search_other_debugdirs): New function.
(dwarf2_get_dwz_file): Convert 'filename' to a
std::string.  Use dwz_search_other_debugdirs to search for DWZ
files in the debug-file-directories provided by the user as well.

3 years agoUse new+delete for struct expression
Tom Tromey [Wed, 2 Dec 2020 00:22:05 +0000 (17:22 -0700)] 
Use new+delete for struct expression

In another series I'm working on, it is necessary to manage
"struct expression" with new and delete.  Because the patch is
straightforward and could be extracted, I've done so here.

gdb/ChangeLog
2020-12-01  Tom Tromey  <tom@tromey.com>

* parse.c (expr_builder::expr_builder): Initialize expout.
(expr_builder::release): Use expression::resize.
(expression::expression, expression::~expression)
(expression::resize): New methods.
(write_exp_elt): Use expression::resize.
(prefixify_expression): Update.
(increase_expout_size): Use expression::resize.
* expression.h (struct expression): Add constructor, destructor.
<resize>: New method.
(expression_up): Change type.

3 years agoAutomatic date update in version.in
GDB Administrator [Wed, 2 Dec 2020 00:00:17 +0000 (00:00 +0000)] 
Automatic date update in version.in

3 years agogdb/testsuite: fix indentation in gdb.threads/non-ldr-exc-1.exp
Simon Marchi [Tue, 1 Dec 2020 21:29:45 +0000 (16:29 -0500)] 
gdb/testsuite: fix indentation in gdb.threads/non-ldr-exc-1.exp

gdb/testsuite/ChangeLog:

* gdb.threads/non-ldr-exc-1.exp: Fix indentation.

Change-Id: I02ba8a518aae9cb67106d09bef92968a7078e91e

3 years agogdb/testsuite: use foreach_with_prefix in gdb.threads/non-ldr-exc-*.exp
Simon Marchi [Tue, 1 Dec 2020 20:07:08 +0000 (15:07 -0500)] 
gdb/testsuite: use foreach_with_prefix in gdb.threads/non-ldr-exc-*.exp

Replace the manual with_test_prefix in the do_test proc with using
foreach_with_prefix at the top-level.  This helps reduce the indentation
level of the code a bit, and makes the test names in sync with the
variable names used in the code.

gdb/testsuite/ChangeLog:

* gdb.threads/non-ldr-exc-1.exp: Use foreach_with_prefix.
(do_test): Don't use with_test_prefix.
* gdb.threads/non-ldr-exc-2.exp: Use foreach_with_prefix.
(do_test): Don't use with_test_prefix.
* gdb.threads/non-ldr-exc-3.exp: Use foreach_with_prefix.
(do_test): Don't use with_test_prefix.
* gdb.threads/non-ldr-exc-4.exp: Use foreach_with_prefix.
(do_test): Don't use with_test_prefix.

Change-Id: I3af1df2eee1a8add427a67b6048bb6dede41cbeb

3 years agoPowerPC remove 512 bytes region limit if 2nd DAWR is avaliable.
Rogerio Alves [Tue, 1 Dec 2020 19:53:38 +0000 (16:53 -0300)] 
PowerPC remove 512 bytes region limit if 2nd DAWR is avaliable.

Power 10 introduces the 2nd DAWR (second watchpoint) and also removed
a restriction that limit the watch region to 512 bytes.

2020-11-08  Rogerio A. Cardoso  <rcardoso@linux.ibm.com>

/gdb

* ppc-linux-nat.c: (PPC_DEBUG_FEATURE_DATA_BP_ARCH_31): New define.
(region_ok_for_hw_watchpoint): Check if 2nd DAWR is avaliable before
set region.

3 years agoAdd missing ChangeLog entry.
Rogerio Alves [Tue, 1 Dec 2020 19:44:31 +0000 (16:44 -0300)] 
Add missing ChangeLog entry.

3 years agogdb/testsuite: fix comment in gdb.threads/non-ldr-exit.exp
Simon Marchi [Tue, 1 Dec 2020 15:31:19 +0000 (10:31 -0500)] 
gdb/testsuite: fix comment in gdb.threads/non-ldr-exit.exp

Maybe there's something I don't understand in that test, but the comment
seems wrong.  It checks what happens when the non-leader thread does an
exit, not the leader.

gdb/testsuite/ChangeLog:

* gdb.threads/non-ldr-exit.exp: Fix comment.

Change-Id: I35c96a70c097fa9529737874f54f3f78036008a4

3 years agoarc: Enable -Ttext-segment
H.J. Lu [Tue, 1 Dec 2020 12:27:28 +0000 (04:27 -0800)] 
arc: Enable -Ttext-segment

Define TEXT_START_ADDR and SHLIB_TEXT_START_ADDR with SEGMENT_START to
enable -Ttext-segment.

PR ld/26970
* scripttempl/elfarc.sc (TEXT_START_ADDR): New.  Add SEGMENT_START.
(SHLIB_TEXT_START_ADDR): Likewise.

3 years agogdbsupport/tdesc: print enum fields using 'evalue' syntax
Andrew Burgess [Tue, 1 Dec 2020 11:07:12 +0000 (11:07 +0000)] 
gdbsupport/tdesc: print enum fields using 'evalue' syntax

Currently when printing an XML description GDB prints enum values like
this:

  <enum id="levels_type" size="4">
    <field name="low" start="0"/>
    <field name="high" start="1"/>
  </enum>

This is incorrect, and is most likely a copy and paste error with the
struct and flags printing code.  The correct syntax is:

  <enum id="levels_type" size="4">
    <evalue name="low" value="0"/>
    <evalue name="high" value="1"/>
  </enum>

A test is included to cover this functionality.

gdb/testsuite/ChangeLog:

* gdb.xml/maint-xml-dump-03.xml: New file.

gdbsupport/ChangeLog:

* tdesc.cc (print_xml_feature::visit): Print enum fields using
'evalue' syntax.

3 years agogdbsupport/tdesc: print enum size attribute
Chungyi Chi [Tue, 1 Dec 2020 11:06:08 +0000 (11:06 +0000)] 
gdbsupport/tdesc: print enum size attribute

According to gdb online docs[1], XML target description enum types
have both name and size attributes.  Currently GDB does not print the
size attribute.  This commit fixes this.  This change will be visible
in the output of the command `maint print xml-tdesc`.

There are other bugs with the print of enum types in XML target
descriptions, the next commit will fix these and include a test that
covers this patch.

[1] https://sourceware.org/gdb/current/onlinedocs/gdb/Enum-Target-Types.html#Enum-Target-Types

gdbsupport/ChangeLog:

* tdesc.cc (print_xml_feature::visit): Print enum size attribute.

3 years agoRISC-V: Fix the order checking for Z* extension.
Nelson Chu [Fri, 20 Nov 2020 15:42:28 +0000 (23:42 +0800)] 
RISC-V: Fix the order checking for Z* extension.

We have to check the first char of the Z* extensions, to make sure that
they follow the order of the standard extensions.  But we can not have
the testcases for this patch, since we only support the zicsr and zifencei
so far, both of them are the sub extensions of i.

bfd/
* elfxx-riscv.c (riscv_parse_prefixed_ext): Use riscv_compare_subsets
to check the Z* extensions' order.

3 years agoRISC-V: Support to add implicit extensions for G.
Nelson Chu [Fri, 20 Nov 2020 14:33:11 +0000 (22:33 +0800)] 
RISC-V: Support to add implicit extensions for G.

G is a special case, consider the ISA spec github issue as follows,
https://github.com/riscv/riscv-isa-manual/issues/575

My understand is that - i, m, a, f and d extensions are not g's implicit
extensions, they are g's expansions.  The zifencei is the implicit extension
of g, and so is zicsr, since it is implicited by f (or i2p1).  However,
we add the g with the RISCV_UNKNOWN_VERSION to the subset list, and it
will not output to the arch string, it is only used to check what implicit
extensions are need to be added.

bfd/
* elfxx-riscv.c (riscv_parse_add_subset): Allow to add g with
RISCV_UNKNOWN_VERSION versions.
(riscv_parse_std_ext): Add g to the subset list, we only use it
to add the implicit extensions, but won't output it to arch string.
(riscv_parse_add_implicit_subsets): Add implicit zicsr and zifencei
for g extension.
(riscv_arch_str1): Do not output g to the arch string.
* elfxx-riscv.h (RISCV_UNKNOWN_VERSION): Moved to include/opcode/riscv.h.

gas/
* testsuite/gas/riscv/attribute-10.d: Updated.
* testsuite/gas/riscv/march-imply-g.d: New testcase for g.
* testsuite/gas/riscv/march-imply-unsupported.d: The zicsr and zifencei
are not supported in the ISA spec v2.2, so don't add and output them.

include/
* opcode/riscv.h (RISCV_UNKNOWN_VERSION): added.

3 years agoRISC-V: Support to add implicit extensions.
Nelson Chu [Fri, 20 Nov 2020 10:05:05 +0000 (18:05 +0800)] 
RISC-V: Support to add implicit extensions.

We have to parse and add all arch string extensions at first, and then
start to add their implicit extensions.  That means we can always add
arch string extensions at the end of the subset list, but we need to
search the right place to add their implicit extensions.  For now we
follow the following rules to add the implicit extensions,

* Add zicsr and zifencei only when the i's version less than 2.1.
* Add d, f and zicsr when q is found.
* Add f and zicsr when d is found.
* Add zicsr when f is found.

Besides, we do not add the implicit extensions if they are already added
in the subset list, or we cannot find their default versions according to
the chosen ISA spec.

bfd/
* elfnn-riscv.c (riscv_merge_std_ext): Updated since
riscv_lookup_subset is changed.
* elfxx-riscv.c (riscv_ext_order): New Array used to compare the
extensions' order quickly.
(riscv_init_ext_order): New function.  Init the riscv_ext_order
according to the riscv_supported_std_ext and parse_config[i].class
automatically.
(riscv_compare_subsets): New function.  Similar to the strcmp, but
compare the subsets with the specific order.
(riscv_lookup_subset): Return TRUE and set `current` to the subset
if it is found.  Otherwise, return FALSE and set `current` to the
place where we should insert the subset.
(riscv_add_implicit_subset): New function.  Search the list first,
and then find the right place to add the implicit_subset.
(riscv_parse_add_subset): Since We have to add all arch string
extensions first, and then start to add their implicit extensions.
We can add arch string extensions in order by the original
riscv_add_subset, and then add the implicit subsets by the
riscv_add_implicit_subset.  Besides, do not add the implicit
extensions if we failed to find their default versions.
(riscv_parse_std_ext): Updated.
(riscv_parse_add_implicit_subsets): New function.  Add all implicit
extensions according to the arch string extensions.
(riscv_parse_subset): Call riscv_init_ext_order and
riscv_parse_add_implicit_subsets, before and after parsing the
arch string.  Remove parts of the ISA conflict checking since
the implicit extensions are added.
* elfxx-riscv.h (riscv_lookup_subset): Updated.

gas/
* config/tc-riscv.c (riscv_subset_supports): Updated.
* testsuite/gas/riscv/march-imply-i2p0.d: New testcase.  Need to
add the implicit zicsr and zifencei when i's version less than 2.1.
* testsuite/gas/riscv/march-imply-i2p1.d: New testcase.
* testsuite/gas/riscv/march-imply-d.d: Likewise.
* testsuite/gas/riscv/march-imply-f.d: Likewise.
* testsuite/gas/riscv/march-imply-q.d: Likewise.
* testsuite/gas/riscv/march-fail-rv32iq.l: Updated.
* testsuite/gas/riscv/march-fail-rv32id.d: Removed.
* testsuite/gas/riscv/march-fail-rv32id.l: Likewise.
* testsuite/gas/riscv/march-fail-rv64iq.d: Likewise.
* testsuite/gas/riscv/march-fail-rv64iq.l: Likewise.

3 years agoRISC-V: Improve the version parsing for arch string.
Nelson Chu [Fri, 20 Nov 2020 09:26:04 +0000 (17:26 +0800)] 
RISC-V: Improve the version parsing for arch string.

Keep the riscv_add_subset to do the same thing, and use a new
function, riscv_parse_add_subset, to cover most of the things
when parsing, including find the default versions for extensions,
and check whether the versions are valid.  The version 0p0 should
be an invalid version, that is the mistake I made before.  This
patch clarify the version rules as follows,

* We accept any version of extensions set by users, except 0p0.
* The non-standard x extensions must be set with versions in arch string.
* If user don't set the versions, or set 0p0 for the extensions, then try
  to find the supported versions according to the chosen ISA spec.
  Otherwise, report errors rather than output 0p0 for them.

Besides, we use as_bad rather than as_fatal to report more errors
for assembler.

bfd/
* elfxx-riscv.c (riscv_lookup_subset): Moved to front.
(riscv_add_subset): Likewise.
(riscv_release_subset_list): Likewise.
(riscv_parse_add_subset): New function.  Find and check the
versions before adding them by riscv_add_subset.
(riscv_parsing_subset_version): Remove use_default_version
and change the version type from unsigned to int.  Set the
versions to RISCV_UNKNOWN_VERSION if we can not find them
in the arch string.
(riscv_parse_std_ext): Updated.
(riscv_parse_prefixed_ext): Updated.  Since we use as_bad
rather than as_fatal to report more errors, return NULL
string if the parsed end_of_version is NULL, too.
(riscv_parse_subset): Use a new boolean, no_conflict, to
report more errors when we have more than one ISA conflicts.

* elfxx-riscv.h (RISCV_DONT_CARE_VERSION): Changed to
RISCV_UNKNOWN_VERSION.
(riscv_lookup_subset_version): Removed.
(riscv_parse_subset_t): Updated.

gas/
* config/tc-riscv.c (riscv_get_default_ext_version):
Change the version type from unsigned to int.
(riscv_set_arch): Use as_bad rather than as_fatal to
report more errors.

* testsuite/gas/riscv/attribute-02.d: Updated since x must be
set with versions.
* testsuite/gas/riscv/attribute-03.d: Likewise.
* testsuite/gas/riscv/march-ok-two-nse.d: Likewise.
* testsuite/gas/riscv/attribute-09.d: zicsr wasn't supported
in the spec 2.2, so choose the newer spec.
* testsuite/gas/riscv/march-fail-base-01.l: Updated since as_bad.
* testsuite/gas/riscv/march-fail-base-02.l: Likewise.
* testsuite/gas/riscv/march-fail-order-std.l: Likewise.
* testsuite/gas/riscv/march-fail-order-x.l: Likewise.
* testsuite/gas/riscv/march-fail-order-z.l: Likewise.
* testsuite/gas/riscv/march-fail-porder.l: Likewise.
* testsuite/gas/riscv/march-fail-rv32ef.l: Likewise.
* testsuite/gas/riscv/march-fail-rv32id.l: Likewise.
* testsuite/gas/riscv/march-fail-rv32iq.l: Likewise.
* testsuite/gas/riscv/march-fail-rv64iq.l: Likewise.
* testsuite/gas/riscv/march-fail-single-char.l: Likewise.
* testsuite/gas/riscv/march-fail-unknown-std.l: Likewise.
* testsuite/gas/riscv/march-fail-unknown.l: Likewise.
* testsuite/gas/riscv/march-fail-uppercase.l: Likewise.
* testsuite/gas/riscv/march-fail-version.l: Likewise.
* testsuite/gas/riscv/march-fail-isa-spec.d: Likewise.
* testsuite/gas/riscv/march-fail-isa-spec.l: Likewise.

include/
* opcode/riscv.h (riscv_ext_version):
Change the version type from unsigned to int.

3 years agoRISC-V: Remove the unimplemented extensions.
Nelson Chu [Fri, 20 Nov 2020 08:52:35 +0000 (16:52 +0800)] 
RISC-V: Remove the unimplemented extensions.

Although spec had defined and ratified p, v and n extensions,
but we don't have any related implementaitons so far, so keep
them in the supported extension table looks weird.  Remove them
until we have the related implementations.

opcodes/
* riscv-opc.c (riscv_ext_version_table): Remove the p, v, n
and their versions.

3 years agoRISC-V: Add zifencei and prefixed h class extensions.
Nelson Chu [Fri, 20 Nov 2020 07:35:17 +0000 (15:35 +0800)] 
RISC-V: Add zifencei and prefixed h class extensions.

bfd/
* elfxx-riscv.c (riscv_parse_std_ext): Stop parsing standard
extensions when parsed h keyword.
(riscv_get_prefix_class): Support prefixed h class.
(riscv_std_h_ext_strtab): Likewise.
(riscv_ext_h_valid_p): Likewise.
(parse_config): Likewise.
(riscv_std_z_ext_strtab): Add zifencei.
* elfxx-riscv.h (riscv_isa_ext_class): Add RV_ISA_CLASS_H.

gas/
* testsuite/gas/riscv/march-fail-order-z.d: New testcase, check
orders of prefixed z extensions.
* testsuite/gas/riscv/march-fail-order-z.l: Likewise.
* testsuite/gas/riscv/march-fail-single-char-h.d: New testcase.
* testsuite/gas/riscv/march-fail-single-char.l: Updated.
* testsuite/gas/riscv/march-fail-unknown-h.d: New testcase.
* testsuite/gas/riscv/march-fail-unknown.l: Updated.

opcodes/
* riscv-opc.c (riscv_ext_version_table): Add zifencei.

3 years agoRISC-V: Don't allow any uppercase letter in the arch string.
Nelson Chu [Sat, 21 Nov 2020 03:19:58 +0000 (11:19 +0800)] 
RISC-V: Don't allow any uppercase letter in the arch string.

Although I cannot find any RISC-V specs said that uppercases are not
allowed in the arhc string, but seems like it is an established fact
both for GNU and LLVM.  Therefore, we shouldn't allow the uppercases
for the non-standard x extensions, too.

bfd/
* elfxx-riscv.c (riscv_parse_subset): ISA string cannot contain
any uppercase letter.

gas/
* testsuite/gas/riscv/march-fail-uppercase-base.d: Updated.
* testsuite/gas/riscv/march-fail-uppercase.l: Updated.
* testsuite/gas/riscv/march-fail-uppercase-x.d: New testcase.

This page took 0.101513 seconds and 4 git commands to generate.