binutils-gdb.git
2 years agoPR29171, invalid read causing SIGSEGV
Alan Modra [Tue, 24 May 2022 01:17:35 +0000 (10:47 +0930)]
PR29171, invalid read causing SIGSEGV

The fix here is to pass "section" down to read_and_display_attr_value.
The test in read_and_display_attr_value is a little bit of hardening.

PR 29171
* dwarf.c (display_debug_macro, display_debug_names): Pass section
to read_and_display_attr_value2.
(read_and_display_attr_value): Don't attempt to check for .dwo
section name when section is NULL.

2 years agoPR29170, divide by zero displaying fuzzed .debug_names
Alan Modra [Tue, 24 May 2022 00:52:50 +0000 (10:22 +0930)]
PR29170, divide by zero displaying fuzzed .debug_names

PR 29170
* dwarf.c (display_debug_names): Don't attempt to display bucket
clashes when bucket count is zero.

2 years agoPR29169, invalid read displaying fuzzed .gdb_index
Alan Modra [Tue, 24 May 2022 00:02:14 +0000 (09:32 +0930)]
PR29169, invalid read displaying fuzzed .gdb_index

PR 29169
* dwarf.c (display_gdb_index): Combine sanity checks.  Calculate
element counts, not word counts.

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

2 years agoTweak the std::hash<> specialization for aarch64_features.
John Baldwin [Mon, 23 May 2022 18:02:55 +0000 (11:02 -0700)]
Tweak the std::hash<> specialization for aarch64_features.

Move the specialization into an explicit std namespace to workaround a
bug in older compilers.  GCC 6.4.1 at least fails to compile the previous
version with the following error:

gdb/arch/aarch64.h:48:13: error: specialization of 'template<class _Tp> struct std::hash' in different namespace [-fpermissive]

  struct std::hash<aarch64_features>

2 years agoFix loongarch_iterate_over_regset_sections for non-native targets.
John Baldwin [Mon, 23 May 2022 17:59:13 +0000 (10:59 -0700)]
Fix loongarch_iterate_over_regset_sections for non-native targets.

Define a constant for the number of registers stored in a register set
and use this with register_size to compute the size of the
general-purpose register set in core dumps.

This also fixes the build on hosts such as FreeBSD that do not define
an elf_gregset_t type.

2 years agogdb: LoongArch: Implement the iterate_over_regset_sections gdbarch method
Tiezhu Yang [Mon, 23 May 2022 07:53:06 +0000 (15:53 +0800)]
gdb: LoongArch: Implement the iterate_over_regset_sections gdbarch method

When execute the following command on LoongArch:

  make check-gdb TESTS="gdb.base/auxv.exp"

there exist the following unsupported and failed testcases:

  UNSUPPORTED: gdb.base/auxv.exp: gcore
  FAIL: gdb.base/auxv.exp: load core file for info auxv on native core dump
  FAIL: gdb.base/auxv.exp: info auxv on native core dump
  FAIL: gdb.base/auxv.exp: matching auxv data from live and core
  UNSUPPORTED: gdb.base/auxv.exp: info auxv on gcore-created dump
  UNSUPPORTED: gdb.base/auxv.exp: matching auxv data from live and gcore

we can see the following messages in gdb/testsuite/gdb.log:

  gcore /home/loongson/build.git/gdb/testsuite/outputs/gdb.base/auxv/auxv.gcore
  Target does not support core file generation.
  (gdb) UNSUPPORTED: gdb.base/auxv.exp: gcore

In order to fix the above issues, implement the iterate_over_regset_sections
gdbarch method to iterate over core file register note sections on LoongArch.

By the way, with this patch, the failed testcases in gdb.base/corefile.exp
and gdb.base/gcore.exp can also be fixed.

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
2 years ago[gdb/testsuite] Fix -prompt handling in gdb_test
Tom de Vries [Mon, 23 May 2022 12:50:02 +0000 (14:50 +0200)]
[gdb/testsuite] Fix -prompt handling in gdb_test

With check-read1 I run into:
...
   [infrun] maybe_set_commit_resumed_all_targets: not requesting
commit-resumed for target native, no resumed threads^M
(gdb) FAIL: gdb.base/ui-redirect.exp: debugging: continue
[infrun] fetch_inferior_event: exit^M
...

The problem is that proc gdb_test doesn't pass down the -prompt option to proc
gdb_test_multiple, due to a typo making this lappend without effect:
...
    set opts {}
    lappend "-prompt $prompt"
...

Fix this by actually appending to opts.

Tested on x86_64-linux.

2 years ago[gdbsupport] Fix UB in print-utils.cc:int_string
Tom de Vries [Mon, 23 May 2022 12:50:02 +0000 (14:50 +0200)]
[gdbsupport] Fix UB in print-utils.cc:int_string

When building gdb with -fsanitize=undefined, I run into:
...
(gdb) PASS: gdb.ada/access_to_packed_array.exp: set logging enabled on
maint print symbols^M
print-utils.cc:281:29:runtime error: negation of -9223372036854775808 cannot \
  be represented in type 'long int'; cast to an unsigned type to negate this \
  value to itself
(gdb) FAIL: gdb.ada/access_to_packed_array.exp: maint print symbols
...

By running in a debug session, we find that this happens during printing of:
...
   typedef system.storage_elements.storage_offset: \
     range -9223372036854775808 .. 9223372036854775807;
...
Possibly, an ada test-case could be created that exercises this in isolation.

The problem is here in int_string, where we negate a val with type LONGEST:
...
         return decimal2str ("-", -val, width);
...

Fix this by, as recommend, using "-(ULONGEST)val" instead.

Tested on x86_64-linux.

2 years ago[gdb/exp] Fix UB in scalar_binop
Tom de Vries [Mon, 23 May 2022 12:50:02 +0000 (14:50 +0200)]
[gdb/exp] Fix UB in scalar_binop

When building gdb with -fsanitize=undefined, I run into:
...
$ gdb -q -batch -ex "p -(-0x7fffffffffffffff - 1)"
src/gdb/valarith.c:1385:10: runtime error: signed integer overflow: \
  0 - -9223372036854775808 cannot be represented in type 'long int'
$1 = -9223372036854775808
...

Fix this by performing the substraction in scalar_binop using unsigned types.

Tested on x86_64-linux.

2 years ago[gdb/ada] Fix gdb.ada/dynamic-iface.exp with gcc 7
Tom de Vries [Mon, 23 May 2022 12:50:02 +0000 (14:50 +0200)]
[gdb/ada] Fix gdb.ada/dynamic-iface.exp with gcc 7

This test in test-case gdb.ada/dynamic-iface.exp passes with gcc 8:
...
(gdb) print obj^M
$1 = (n => 3, a => "ABC", value => 93)^M
(gdb) PASS: gdb.ada/dynamic-iface.exp: print local as interface
...
but fails with gcc 7:
...
(gdb) print obj^M
$1 = ()^M
(gdb) FAIL: gdb.ada/dynamic-iface.exp: print local as interface
...

More concretely, we have trouble finding the type of obj.  With gcc 8:
...
$ gdb -q -batch main -ex "b concrete.adb:20" -ex run -ex "ptype obj"
  ...
type = <ref> new concrete.intermediate with record
    value: integer;
end record
...
and with gcc 7:
...
type = <ref> tagged record null; end record
...

The translation from tagged type to "full view" type happens in
ada_tag_value_at_base_address, where we hit this code:
...
  /* Storage_Offset'Last is used to indicate that a dynamic offset to
     top is used.  In this situation the offset is stored just after
     the tag, in the object itself.  */
  if (offset_to_top == last)
    {
      struct value *tem = value_addr (tag);
      tem = value_ptradd (tem, 1);
      tem = value_cast (ptr_type, tem);
      offset_to_top = value_as_long (value_ind (tem));
    }
...
resulting in an offset_to_top for gcc 8:
...
(gdb) p offset_to_top
$1 = -16
...
and for gcc 7:
...
(gdb) p offset_to_top
$1 = 16
...

The difference is expected, it bisects to gcc commit d0567dc0dbf ("[multiple
changes]") which mentions this change.

There's some code right after the code quoted above that deals with this
change:
...
  else if (offset_to_top > 0)
    {
      /* OFFSET_TO_TOP used to be a positive value to be subtracted
 from the base address.  This was however incompatible with
 C++ dispatch table: C++ uses a *negative* value to *add*
 to the base address.  Ada's convention has therefore been
 changed in GNAT 19.0w 20171023: since then, C++ and Ada
 use the same convention.  Here, we support both cases by
 checking the sign of OFFSET_TO_TOP.  */
      offset_to_top = -offset_to_top;
    }
...
but it's not activated because of the 'else'.

Fix this by removing the 'else'.

Tested on x86_64-linux, with gcc 7.5.0.

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

2 years agold: use definitions in generate_reloc rather than raw literals
Mark Harmstone [Mon, 23 May 2022 11:04:26 +0000 (12:04 +0100)]
ld: use definitions in generate_reloc rather than raw literals

2 years ago[gdb/testsuite] Skip language auto in gdb.base/parse_number.exp
Tom de Vries [Mon, 23 May 2022 06:55:46 +0000 (08:55 +0200)]
[gdb/testsuite] Skip language auto in gdb.base/parse_number.exp

In test-case gdb.base/parse_number.exp, we skip architecture auto in the
$supported_archs loop, to prevent duplicate testing.

Likewise, skip language auto and its alias local in the $::all_languages
loop.  This reduces the number of tests from 17744 to 15572.

Tested on x86_64-linux, with a build with --enable-targets=all.

2 years agoAutomatic date update in version.in
GDB Administrator [Mon, 23 May 2022 00:00:07 +0000 (00:00 +0000)]
Automatic date update in version.in

2 years agoAccept functions with DW_AT_linkage_name present
Alok Kumar Sharma [Sun, 22 May 2022 16:16:06 +0000 (21:46 +0530)]
Accept functions with DW_AT_linkage_name present

Currently GDB is not able to debug (Binary generated with Clang) variables
present in shared/private clause of OpenMP Task construct. Please note that
LLVM debugger LLDB is able to debug.

In case of OpenMP, compilers generate artificial functions which are not
present in actual program. This is done to apply parallelism to block of
code.

For non-artifical functions, DW_AT_name attribute should contains the name
exactly as present in actual program.
(Ref# http://wiki.dwarfstd.org/index.php?title=Best_Practices)
Since artificial functions are not present in actual program they not having
DW_AT_name and having DW_AT_linkage_name instead should be fine.

Currently GDB is invalidating any function not havnig DW_AT_name which is why
it is not able to debug OpenMP (Clang).

It should be fair to fallback to check DW_AT_linkage_name in case DW_AT_name
is absent.

2 years agoAutomatic date update in version.in
GDB Administrator [Sun, 22 May 2022 00:00:06 +0000 (00:00 +0000)]
Automatic date update in version.in

2 years agoAutomatic date update in version.in
GDB Administrator [Sat, 21 May 2022 00:00:39 +0000 (00:00 +0000)]
Automatic date update in version.in

2 years agoRename base_breakpoint -> code_breakpoint
Pedro Alves [Mon, 16 May 2022 16:30:06 +0000 (17:30 +0100)]
Rename base_breakpoint -> code_breakpoint

Even after the previous patches reworking the inheritance of several
breakpoint types, the present breakpoint hierarchy looks a bit
surprising, as we have "breakpoint" as the superclass, and then
"base_breakpoint" inherits from "breakpoint".  Like so, simplified:

   breakpoint
       base_breakpoint
          ordinary_breakpoint
  internal_breakpoint
  momentary_breakpoint
  ada_catchpoint
  exception_catchpoint
       tracepoint
       watchpoint
       catchpoint
  exec_catchpoint
  ...

The surprising part to me is having "base_breakpoint" being a subclass
of "breakpoint".  I'm just refering to naming here -- I mean, you'd
expect that it would be the top level baseclass that would be called
"base".

Just flipping the names of breakpoint and base_breakpoint around
wouldn't be super great for us, IMO, given we think of every type of
*point as a breakpoint at the user visible level.  E.g., "info
breakpoints" shows watchpoints, tracepoints, etc.  So it makes to call
the top level class breakpoint.

Instead, I propose renaming base_breakpoint to code_breakpoint.  The
previous patches made sure that all code breakpoints inherit from
base_breakpoint, so it's fitting.  Also, "code breakpoint" contrasts
nicely with a watchpoint also being typically known as a "data
breakpoint".

After this commit, the resulting hierarchy looks like:

   breakpoint
       code_breakpoint
          ordinary_breakpoint
  internal_breakpoint
  momentary_breakpoint
  ada_catchpoint
  exception_catchpoint
       tracepoint
       watchpoint
       catchpoint
  exec_catchpoint
  ...

... which makes a lot more sense to me.

I've left this patch as last in the series in case people want to
bikeshed on the naming.

"code" has a nice property that it's exactly as many letters as
"base", so this patch didn't require any reindentation.  :-)

Change-Id: Id8dc06683a69fad80d88e674f65e826d6a4e3f66

2 years agoTest "set multiple-symbols on" creating multiple breakpoints
Pedro Alves [Mon, 16 May 2022 11:48:51 +0000 (12:48 +0100)]
Test "set multiple-symbols on" creating multiple breakpoints

To look for code paths that lead to create_breakpoints_sal creating
multiple breakpoints, I ran the whole testsuite with this hack:

  --- a/gdb/breakpoint.c
  +++ b/gdb/breakpoint.c
  @@ -8377,8 +8377,7 @@ create_breakpoints_sal (struct gdbarch *gdbarch,
  int from_tty,
  int enabled, int internal, unsigned flags)
   {
  -  if (canonical->pre_expanded)
  -    gdb_assert (canonical->lsals.size () == 1);
  +  gdb_assert (canonical->lsals.size () == 1);

surprisingly, the assert never failed...

The way to get to create_breakpoints_sal with multiple lsals is to use
"set multiple-symbols ask" and then select multiple options from the
menu, like so:

 (gdb) set multiple-symbols ask
 (gdb) b overload1arg
 [0] cancel
 [1] all
 [2] /home/pedro/gdb/binutils-gdb/src/gdb/testsuite/gdb.cp/ovldbreak.cc:foo::overload1arg()
 [3] /home/pedro/gdb/binutils-gdb/src/gdb/testsuite/gdb.cp/ovldbreak.cc:foo::overload1arg(char)
 [4] /home/pedro/gdb/binutils-gdb/src/gdb/testsuite/gdb.cp/ovldbreak.cc:foo::overload1arg(double)
 [5] /home/pedro/gdb/binutils-gdb/src/gdb/testsuite/gdb.cp/ovldbreak.cc:foo::overload1arg(float)
 [6] /home/pedro/gdb/binutils-gdb/src/gdb/testsuite/gdb.cp/ovldbreak.cc:foo::overload1arg(int)
 [7] /home/pedro/gdb/binutils-gdb/src/gdb/testsuite/gdb.cp/ovldbreak.cc:foo::overload1arg(long)
 [8] /home/pedro/gdb/binutils-gdb/src/gdb/testsuite/gdb.cp/ovldbreak.cc:foo::overload1arg(short)
 [9] /home/pedro/gdb/binutils-gdb/src/gdb/testsuite/gdb.cp/ovldbreak.cc:foo::overload1arg(signed char)
 [10] /home/pedro/gdb/binutils-gdb/src/gdb/testsuite/gdb.cp/ovldbreak.cc:foo::overload1arg(unsigned char)
 [11] /home/pedro/gdb/binutils-gdb/src/gdb/testsuite/gdb.cp/ovldbreak.cc:foo::overload1arg(unsigned int)
 [12] /home/pedro/gdb/binutils-gdb/src/gdb/testsuite/gdb.cp/ovldbreak.cc:foo::overload1arg(unsigned long)
 [13] /home/pedro/gdb/binutils-gdb/src/gdb/testsuite/gdb.cp/ovldbreak.cc:foo::overload1arg(unsigned short)
 > 2-3
 Breakpoint 2 at 0x1532: file /home/pedro/gdb/binutils-gdb/src/gdb/testsuite/gdb.cp/ovldbreak.cc, line 107.
 Breakpoint 3 at 0x154b: file /home/pedro/gdb/binutils-gdb/src/gdb/testsuite/gdb.cp/ovldbreak.cc, line 110.
 warning: Multiple breakpoints were set.
 Use the "delete" command to delete unwanted breakpoints.

... which would trigger the assert.

This commit makes gdb.cp/ovldbreak.exp test this scenario.  It does
that by making set_bp_overloaded take a list of expected created
breakpoints rather than just one breakpoint.  It converts the
procedure to use gdb_test_multiple instead of send_gdb/gdb_expect
along the way.

Change-Id: Id87d1e08feb6670440d926f5344e5081f5e37c8e

2 years agoMake sure momentary breakpoints are always thread-specific
Pedro Alves [Thu, 12 May 2022 19:20:03 +0000 (20:20 +0100)]
Make sure momentary breakpoints are always thread-specific

This adds a new ctor to momentary_breakpoints with a few parameters
that are always necessary for momentary breakpoints.

In particular, I noticed that set_std_terminate_breakpoint doesn't
make the breakpoint be thread specific, which looks like a bug to me.

The point of that breakpoint is to intercept std::terminate calls that
happen as result of the called thread throwing an exception that won't
be caught by the dummy frame.  If some other thread calls
std::terminate, IMO, it's no different from some other thread calling
exit/_exit, for example.

Change-Id: Ifc5ff4a6d6e58b8c4854d00b86725382d38a1a02

2 years agoMomentary breakpoints should have no breakpoint number
Pedro Alves [Thu, 12 May 2022 20:04:42 +0000 (21:04 +0100)]
Momentary breakpoints should have no breakpoint number

Momentary breakpoints have no breakpoint number, their breakpoint
number should be always 0, to avoid constantly incrementing (or
decrementing) the internal breakpoint count.

Indeed, set_momentary_breakpoint installs the created breakpoint
without a number.

However, momentary_breakpoint_from_master incorrectly gives an
internal breakpoint number to the new breakpoint.  This commit fixes
that.

Change-Id: Iedcae5432cdf232db9e9a6e1a646d358abd34f95

2 years agoAdd/tweak intro comments of struct breakpoint and several subclasses
Pedro Alves [Mon, 16 May 2022 14:24:41 +0000 (15:24 +0100)]
Add/tweak intro comments of struct breakpoint and several subclasses

This tweaks the intro comments of the following classes:

 internal_breakpoint
 momentary_breakpoint
 breakpoint
 base_breakpoint
 watchpoint
 catchpoint

Change-Id: If6b31f51ebbb81705fbe5b8435f60ab2c88a98c8

2 years agoMove add_location(sal) to base_breakpoint
Pedro Alves [Thu, 12 May 2022 17:58:38 +0000 (18:58 +0100)]
Move add_location(sal) to base_breakpoint

After the previous patches, only base_breakpoint subclasses use
add_location(sal), so we can move it to base_breakpoint (a.k.a. base
class for code breakpoints).

This requires a few casts here and there, but always at spots where
you can see from context what the breakpoint's type actually is.

I inlined new_single_step_breakpoint into its only caller exactly for
this reason.

I did try to propagate more use of base_breakpoint to avoid casts, but
that turned out unwieldy for this patch.

Change-Id: I49d959322b0fdce5a88a216bb44730fc5dd7c6f8

2 years agoMove common bits of catchpoint/exception_catchpoint to breakpoint's ctor
Pedro Alves [Sat, 7 May 2022 00:29:34 +0000 (01:29 +0100)]
Move common bits of catchpoint/exception_catchpoint to breakpoint's ctor

Move common bits of catchpoint and exception_catchpoint to
breakpoint's ctor, to avoid duplicating code.

Change-Id: I3a115180f4d496426522f1d89a3875026aea3cf2

2 years agoMake catchpoint inherit breakpoint, eliminate init_raw_breakpoint
Pedro Alves [Sat, 7 May 2022 00:23:03 +0000 (01:23 +0100)]
Make catchpoint inherit breakpoint, eliminate init_raw_breakpoint

struct catchpoint's ctor currently calls init_raw_breakpoint, which is
a bit weird, as that ctor-like function takes a sal argument, but
catchpoints don't have code locations.

Instead, make struct catchpoint's ctor add the catchpoint's dummy
location using add_dummy_location.

init_raw_breakpoint uses add_location under the hood, and with a dummy
sal it would ultimately use the breakpoint's gdbarch for the
location's gdbarch, so replace the references to loc->gdbarch (which
is now NULL) in syscall_catchpoint to references to the catchpoint's
gdbarch.

struct catchpoint's ctor was the last user of init_raw_breakpoint, so
this commit eliminates the latter.

Since catchpoint locations aren't code locations, make struct
catchpoint inherit struct breakpoint instead of base_breakpoint.  This
let's us delete the tracepoint::re_set override too.

Change-Id: Ib428bf71efb09fdaf399c56e4372b0f41d9c5869

2 years agoMake breakpoint_address_bits look at the location kind
Pedro Alves [Thu, 12 May 2022 18:43:53 +0000 (19:43 +0100)]
Make breakpoint_address_bits look at the location kind

Software watchpoints allocate a special dummy location using
software_watchpoint_add_no_memory_location, and then
breakpoint_address_bits checks whether the location is that special
location to decide whether the location has a meaninful address to
print.

Introduce a new bp_loc_software_watchpoint location kind, and make
breakpoint_address_bits use bl_address_is_meaningful instead, which
returns false for bp_loc_other, which is in accordance with we
document for bp_location::address:

  /* (... snip ...)  Valid for all types except
     bp_loc_other.  */
  CORE_ADDR address = 0;

Rename software_watchpoint_add_no_memory_location to
add_dummy_location, and simplify it.  This will be used by catchpoints
too in a following patch.

Note that neither "info breakpoints" nor "maint info breakpoints"
actually prints the addresses of watchpoints, but I think it would be
useful to do so in "maint info breakpoints".  This approach let's us
implement that in the future.

Change-Id: I50e398f66ef618c31ffa662da755eaba6295aed7

2 years agoMake exception_catchpoint inherit base_breakpoint instead of catchpoint
Pedro Alves [Sat, 7 May 2022 00:18:34 +0000 (01:18 +0100)]
Make exception_catchpoint inherit base_breakpoint instead of catchpoint

exception_catchpoint is really a code breakpoint, with locations set
by sals, re-set like other code breakpoints, etc., so make it inherit
base_breakpoint.

This adds a bit of duplicated code to exception_catchpoint's ctor
(copied from struct catchpoint's ctor), but it will be eliminated in a
following patch.

Change-Id: I9fbb2927491120e9744a4f5e5cb5e6870ca07009

2 years agoRefactor momentary breakpoints, eliminate set_raw_breakpoint{,_without_location}
Pedro Alves [Fri, 6 May 2022 23:34:33 +0000 (00:34 +0100)]
Refactor momentary breakpoints, eliminate set_raw_breakpoint{,_without_location}

This commit makes set_momentary_breakpoint allocate the breakpoint
type without relying on set_raw_breakpoint, and similarly,
momentary_breakpoint_from_master not rely on
set_raw_breakpoint_without_location.  This will let us convert
init_raw_breakpoint to a ctor in a following patch.

The comment about set_raw_breakpoint being used in gdbtk sources is
stale.  gdbtk no longer uses it.

Change-Id: Ibbf77731e4b22e18ccebc1b5799bbec0aff28c8a

2 years agoRefactor set_internal_breakpoint / internal_breakpoint ctor
Pedro Alves [Fri, 6 May 2022 23:50:24 +0000 (00:50 +0100)]
Refactor set_internal_breakpoint / internal_breakpoint ctor

This moves initialization of internal_breakpoint's breakpoint fields
to internal_breakpoint's ctor, and stops using
new_breakpoint_from_type for internal_breakpoint breakpoints.

Change-Id: I898ed0565f47cb00e4429f1c6446e6f9a385a78d

2 years agoConvert init_ada_exception_catchpoint to a ctor
Pedro Alves [Fri, 6 May 2022 23:23:08 +0000 (00:23 +0100)]
Convert init_ada_exception_catchpoint to a ctor

Currently, init_ada_exception_catchpoint is defined in breakpoint.c, I
presume so it can call the static describe_other_breakpoints function.
I think this is a dependency inversion.
init_ada_exception_catchpoint, being code specific to Ada catchpoints,
should be in ada-lang.c, and describe_other_breakpoints, a core
function, should be exported.

And then, we can convert init_ada_exception_catchpoint to an
ada_catchpoint ctor.

Change-Id: I07695572dabc5a75d3d3740fd9b95db1529406a1

2 years agoMake ada_catchpoint_location's owner ctor parameter be ada_catchpoint
Pedro Alves [Fri, 6 May 2022 23:16:52 +0000 (00:16 +0100)]
Make ada_catchpoint_location's owner ctor parameter be ada_catchpoint

This commit changes ada_catchpoint_location's ctor from:

  ada_catchpoint_location (breakpoint *owner)

to:

  ada_catchpoint_location (ada_catchpoint *owner)

just to make the code better document intention.

To do this, we need to move the ada_catchpoint_location type's
definition to after ada_catchpoint is defined, otherwise the compiler
doesn't know that ada_catchpoint is convertible to struct breakpoint.

Change-Id: Id908b2e38bde30b262381e00c5637adb9bf0129d

2 years agoinit_breakpoint_sal -> base_breakpoint::base_breakpoint
Pedro Alves [Fri, 6 May 2022 22:18:57 +0000 (23:18 +0100)]
init_breakpoint_sal -> base_breakpoint::base_breakpoint

This converts init_breakpoint_sal to a base_breakpoint constructor.

It removes a use of init_raw_breakpoint.

To avoid manually adding a bunch of parameters to
new_breakpoint_from_type, and manually passing them down to the
constructors of a number of different base_breakpoint subclasses, make
new_breakpoint_from_type a variable template function.

Change-Id: I4cc24133ac4c292f547289ec782fc78e5bbe2510

2 years agoRemove "internal" parameter from a couple functions
Pedro Alves [Fri, 6 May 2022 23:07:44 +0000 (00:07 +0100)]
Remove "internal" parameter from a couple functions

None of init_breakpoint_sal, create_breakpoint_sal, and
strace_marker_create_breakpoints_sal make use of their "internal"
parameter, so remove it.

Change-Id: I943f3bb44717ade7a7b7547edf8f3ff3c37da435

2 years agoMore breakpoint_ops parameter elimination
Pedro Alves [Fri, 6 May 2022 22:39:47 +0000 (23:39 +0100)]
More breakpoint_ops parameter elimination

Remove breakpoint_ops parameters from a few functions that don't need
it.

Change-Id: Ifcf5e1cc688184acbf5e19b8ea60138ebe63cf28

2 years agoMake a few functions work with base_breakpoint instead of breakpoint
Pedro Alves [Fri, 6 May 2022 22:11:34 +0000 (23:11 +0100)]
Make a few functions work with base_breakpoint instead of breakpoint

This makes tracepoints inherit from base_breakpoint, since their
locations are code locations.  If we do that, then we can eliminate
tracepoint::re_set and tracepoint::decode_location, as they are doing
the same as the base_breakpoint implementations.

With this, all breakpoint types created by new_breakpoint_from_type
are code breakpoints, i.e., base_breakpoint subclasses, and thus we
can make it return a base_breakpoint pointer.

Finally, init_breakpoint_sal can take a base_breakpoint pointer as
"self" pointer too.  This will let us convert this function to a
base_breakpoint ctor in a following patch.

Change-Id: I3a4073ff1a4c865f525588095c18dc42b744cb54

2 years agoranged_breakpoint: move initialization to ctor
Pedro Alves [Fri, 6 May 2022 21:48:11 +0000 (22:48 +0100)]
ranged_breakpoint: move initialization to ctor

Move initialization of ranged_breakpoint's fields to its ctor.

Change-Id: If7b842861f3cc6a429ea329d45598b5852283ba3

2 years agoranged_breakpoint: use install_breakpoint
Pedro Alves [Fri, 6 May 2022 21:45:21 +0000 (22:45 +0100)]
ranged_breakpoint: use install_breakpoint

This commit replaces a chunk of code in break_range_command by an
equivalent call to install_breakpoint.

Change-Id: I31c06cabd36f5be91740aab029265f678aa78e35

2 years agoranged_breakpoint: don't use init_raw_breakpoint
Pedro Alves [Fri, 6 May 2022 21:21:36 +0000 (22:21 +0100)]
ranged_breakpoint: don't use init_raw_breakpoint

ranged_breakpoint's ctor already sets the breakpoint's type to
bp_hardware_breakpoint.

Since this is a "regular" breakpoint, b->pspace should remain NULL.

Thus, the only thing init_raw_breakpoint is needed for, is to add the
breakpoint's location.  Do that directly.

Change-Id: I1505de94c3919881c2b300437e2c0da9b05f76bd

2 years agoMake structs breakpoint/base_breakpoint/catchpoint be abstract
Pedro Alves [Fri, 6 May 2022 19:09:04 +0000 (20:09 +0100)]
Make structs breakpoint/base_breakpoint/catchpoint be abstract

You should never instanciate these types directly.

Change-Id: I8086c74c415eadbd44924bb0ef20f34b5b97ee6f

2 years agoadd_location_to_breakpoint -> breakpoint::add_location
Pedro Alves [Fri, 6 May 2022 18:18:48 +0000 (19:18 +0100)]
add_location_to_breakpoint -> breakpoint::add_location

Make add_location_to_breakpoint be a method of struct breakpoint.

A patch later in the series will move this to base_breakpoint, but for
now, it needs to be here.

Change-Id: I5bdc2ec1a7c2d66f26f51bf6f6adc8384a90b129

2 years agoPowerPC: Make test gdb.arch/powerpc-power10.exp Endian independent.
Carl Love [Fri, 20 May 2022 17:07:03 +0000 (17:07 +0000)]
PowerPC: Make test gdb.arch/powerpc-power10.exp Endian independent.

The .quad statement stores the 64-bit hex value in Endian order.  When used
to store a 64-bit prefix instructions on Big Endian (BE) systems, the .quad
statement stores the 32-bit suffix followed by the 32-bit prefix rather
than the expected order of prefix word followed by the suffix word.  GDB
fetches 32-bits at a time when disassembling instructions.  The disassembly
on BE gets messed up since GDB fetches the suffix first and interprets it
as a word instruction not a prefixed instruction.  When gdb fetches the
prefix part of the instruction, following the initial suffix word, gdb
associates the prefix word incorrectly with the following 32-bits as the
suffix for the instruction when in fact it is the following instruction.

For example on BE we have two prefixed instructions stored using the
.quad statement as follows:

 addr    word                GDB action
---------------------------------------------
  1      suffix inst A   <- GDB interprets as a word instruction
  2      prefix inst A   <- GDB uses this prefix with

  3      suffix inst B   <- this suffix rather than the suffix at addr 1.
  4      prefix inst B

This patch changes the .quad statement into two .longs to explicitly store
the prefix followed by the suffix of the instruction.

The patch rearranges the instructions to put all of the word instructions
together followed by the prefix instructions for clarity.

The patch has been tested on Power 10 and Power 7 BE and LE to verify
the change works as expected.

2 years agoRemove obsolete text from documentation
Tom Tromey [Thu, 19 May 2022 14:38:21 +0000 (08:38 -0600)]
Remove obsolete text from documentation

The documentation says that -enable-pretty-printing is experimental in
7.0 and may change -- that's long enough ago that I think we can say
that this text is no longer correct or useful.

2 years agoStop readekf and objdump from aggressively following links.
Nick Clifton [Fri, 20 May 2022 15:55:36 +0000 (16:55 +0100)]
Stop readekf and objdump from aggressively following links.

* dwarf.c (dwarf_select_sections_by_names): Return zero if no
sections were selected.
(dwarf_select_sections_by_letters): Likewise.
* dwarf.h: (dwarf_select_sections_by_names): Update prototype.
(dwarf_select_sections_by_letters): Update prototype.
* objdump.c (might_need_separate_debug_info): New function.
(dump_bfd): Call new function before attempting to load separate
debug info files.
(main): Do not enable dwarf section dumping for -WK or -WN.
* readelf.c (parse_args): Do not enable dwarf section dumping for
-wK or -wN.
(might_need_separate_debug_info): New function.
(process_object): Call new function before attempting to load
separate debug info files.
* testsuite/binutils-all/debuginfo.exp: Expect -WE and -wE
debuginfod tests to pass.
* testsuite/binutils-all/objdump.Wk: Add extra regexps.
* testsuite/binutils-all/readelf.k: Add extra regexps.

2 years agoRISC-V: Update zfinx implement with zicsr.
Jia-Wei Chen [Fri, 20 May 2022 10:09:34 +0000 (18:09 +0800)]
RISC-V: Update zfinx implement with zicsr.

Update zfinx implement with zicsr, fix missing fcsr use by zfinx.
add zicsr imply by zfinx.

bfd/ChangeLog:

        * elfxx-riscv.c: New imply.

gas/ChangeLog:

        * testsuite/gas/riscv/csr-insns-pseudo-zfinx.d: New test.

opcodes/ChangeLog:

        * riscv-opc.c: Update insn class.

2 years agoRISC-V: Remove RV128-only fmv instructions
Tsukasa OI [Fri, 20 May 2022 11:51:49 +0000 (20:51 +0900)]
RISC-V: Remove RV128-only fmv instructions

As fmv.x.q and fmv.q.x instructions are RV128-only (not RV64-only),
it should be removed until RV128 support for GNU Binutils is required
again.

gas/ChangeLog:

* testsuite/gas/riscv/fmv.x.q-rv64-fail.d: New failure test.
* testsuite/gas/riscv/fmv.x.q-rv64-fail.l: Likewise.
* testsuite/gas/riscv/fmv.x.q-rv64-fail.s: Likewise.

include/ChangeLog:

* opcode/riscv-opc.h (MATCH_FMV_X_Q, MASK_FMV_X_Q,
MATCH_FMV_Q_X, MASK_FMV_Q_X): Remove RV128-only instructions.

opcodes/ChangeLog:

* riscv-opc.c (riscv_opcodes): Remove RV128-only instructions.

2 years agoFix non-pointer type compilation error in aix-thread.c
Aditya Vidyadhar Kamath [Fri, 20 May 2022 14:16:34 +0000 (07:16 -0700)]
Fix non-pointer type compilation error in aix-thread.c

In aix-thread.c we use ms->value_address () to get the symbol address.
This triggers the following compiler error...

     base operand of '->'  has non-pointer type 'bound_minimal_symbol'

... because ms is not a pointer.

This commit fixes this error by using ms.value_address () instead.

2 years agoadd a trie to map quickly from address range to compilation unit
Steinar H. Gunderson [Fri, 20 May 2022 14:10:34 +0000 (16:10 +0200)]
add a trie to map quickly from address range to compilation unit

When using perf to profile large binaries, _bfd_dwarf2_find_nearest_line()
becomes a hotspot, as perf wants to get line number information
(for inline-detection purposes) for each and every sample. In Chromium
in particular (the content_shell binary), this entails going through
475k address ranges, which takes a long time when done repeatedly.

Add a radix-256 trie over the address space to quickly map address to
compilation unit spaces; for content_shell, which is 1.6 GB when some
(but not full) debug information turned is on, we go from 6 ms to
0.006 ms (6 Âµs) for each lookup from address to compilation unit, a 1000x
speedup.

There is a modest RAM increase of 180 MB in this binary (the existing
linked list over ranges uses about 10 MB, and the entire perf job uses
between 2–3 GB for a medium-size profile); for smaller binaries with few
ranges, there should be hardly any extra RAM usage at all.

2 years agoTidy warn-execstack handling
Alan Modra [Fri, 20 May 2022 05:29:05 +0000 (14:59 +0930)]
Tidy warn-execstack handling

Make ld and bfd values consistent by swapping values 0 and 2 in
link_info.warn_execstack.  This has the benefit of making the value an
"extended" boolean, with 0 meaning no warning, 1 meaning warn, other
values a conditional warning.

Yes, this patch introduces fails on arm/aarch64.  Not a problem with
this patch but an arm/aarch64 before_parse problem.

bfd/
* elflink.c (bfd_elf_size_dynamic_sections): Adjust
warn_execstack test.
include/
* bfdlink.h (warn_execstack): Swap 0 and 2 meaning.
ld/
* configure.ac (DEFAULT_LD_WARN_EXECSTACK): Use values of 0,
1, 2 consistent with link_info.warn_execstack.
* ld.texi: Typo fixes.
* lexsup.c (parse_args): Adjust setting of link_info.warn_execstack.
(elf_static_list_options): Adjust help message conditions.
* configure: Regenerate.

2 years agoAutomatic date update in version.in
GDB Administrator [Fri, 20 May 2022 00:00:45 +0000 (00:00 +0000)]
Automatic date update in version.in

2 years agoarm: Fix system register fpcxt_ns and fpcxt_s naming convention.
Srinath Parvathaneni [Thu, 19 May 2022 15:51:10 +0000 (16:51 +0100)]
arm: Fix system register fpcxt_ns and fpcxt_s naming convention.

The current assembler accepts system registers FPCXTNS and FPCXTS for Armv8.1-M
Mainline Instructions VSTR, VLDR, VMRS and VMSR.
Assembler should be also allowing FPCXT_NS, fpcxt_ns, fpcxtns, FPCXT_S, fpcxt_s
and fpcxts. This patch fixes the issue.

2 years agogdb/doc: use @value{GDBP} in 'info pretty-printer' example
Andrew Burgess [Thu, 19 May 2022 14:20:11 +0000 (15:20 +0100)]
gdb/doc: use @value{GDBP} in 'info pretty-printer' example

Update the 'info pretty-printer' example in the manual to make use of
@value{GDBP} instead of hard-coding '(gdb)'.

2 years agogdb/doc: make use of group/end group in 'info pretty-printers' example
Andrew Burgess [Thu, 19 May 2022 14:13:22 +0000 (15:13 +0100)]
gdb/doc: make use of group/end group in 'info pretty-printers' example

The 'info pretty-printers' example is pretty long and consists of many
commands and their output.

Currently, when the pdf manual is generated this example spans a
page-break, with the page-break falling part way through some example
output from GDB.

This commit breaks up the example using @group .... @end group, within
each group is a single GDB command and all its output.

Now, when the pdf manual is created, the page-break is placed after
the output of one GDB command, and before the subsequent command, this
looks much nicer.

2 years agogdb/doc: fix inconsistent info pretty-printer example
Nikolaos Chatzikonstantinou [Thu, 19 May 2022 14:06:53 +0000 (15:06 +0100)]
gdb/doc: fix inconsistent info pretty-printer example

The example for 'info pretty-printer' in the manual passes an
object-regexp in some cases, but presents output as though no
object-regexp was passed.

This commit fixes the two mistakes, in one case, fixing the output to
filter based on object-regexp, and in the other, to remove the
object-regexp from the command and leave all the output.

2 years agoFix potentially uninitialised variables in the Windows tools
Nick Clifton [Thu, 19 May 2022 14:05:12 +0000 (15:05 +0100)]
Fix potentially uninitialised variables in the Windows tools

2 years agogdb: testsuite: Support displaced stepping on LoongArch
Tiezhu Yang [Tue, 10 May 2022 12:44:04 +0000 (20:44 +0800)]
gdb: testsuite: Support displaced stepping on LoongArch

When execute the following command on LoongArch:

  make check-gdb TESTS="gdb.base/async-shell.exp"

we can see the following message in gdb/testsuite/gdb.sum:

  UNSUPPORTED: gdb.base/async-shell.exp: displaced stepping

modify support_displaced_stepping to support displaced stepping
on LoongArch.

With this patch:

  PASS: gdb.base/async-shell.exp: run &
  PASS: gdb.base/async-shell.exp: shell echo foo
  PASS: gdb.base/async-shell.exp: interrupt
  PASS: gdb.base/async-shell.exp: process stopped

I did the following tests that use support_displaced_stepping
with this patch on LoongArch, there is no failed testcases.

loongson@linux:~/gdb.git$ grep -r support_displaced_stepping gdb/testsuite/gdb.*
gdb/testsuite/gdb.arch/disp-step-insn-reloc.exp:if { ![support_displaced_stepping] } {
gdb/testsuite/gdb.base/step-over-no-symbols.exp:    if { $displaced != "off" && ![support_displaced_stepping] } {
gdb/testsuite/gdb.base/moribund-step.exp:if { ![support_displaced_stepping] } {
gdb/testsuite/gdb.base/async-shell.exp:if { ![support_displaced_stepping] } {
gdb/testsuite/gdb.base/inferior-died.exp:if { ![support_displaced_stepping] } {
gdb/testsuite/gdb.base/step-over-syscall.exp:        if {$displaced == "on" && ![support_displaced_stepping]} {
gdb/testsuite/gdb.mi/mi-watch-nonstop.exp:if { ![support_displaced_stepping] } {
gdb/testsuite/gdb.mi/mi-ns-stale-regcache.exp:if { ![support_displaced_stepping] } {
gdb/testsuite/gdb.mi/mi-nonstop.exp:if { ![support_displaced_stepping] } {
gdb/testsuite/gdb.mi/mi-nsmoribund.exp:if { ![support_displaced_stepping] } {
gdb/testsuite/gdb.mi/mi-nsintrall.exp:if { ![support_displaced_stepping] } {
gdb/testsuite/gdb.mi/mi-nsthrexec.exp:if { ![support_displaced_stepping] } {
gdb/testsuite/gdb.mi/mi-nonstop-exit.exp:if { ![support_displaced_stepping] } {
gdb/testsuite/gdb.multi/watchpoint-multi.exp:if [support_displaced_stepping] {
gdb/testsuite/gdb.python/py-evthreads.exp:if { ![support_displaced_stepping] } {
gdb/testsuite/gdb.threads/step-over-lands-on-breakpoint.exp:    if { $displaced != "off" && ![support_displaced_stepping] } {
gdb/testsuite/gdb.threads/interrupt-while-step-over.exp:    if { ${displaced-stepping} != "off" && ![support_displaced_stepping] } {
gdb/testsuite/gdb.threads/step-over-trips-on-watchpoint.exp:    if { $displaced != "off" && ![support_displaced_stepping] } {

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
2 years agogdbsupport: fix path_join crash with -std=c++17 and -D_GLIBCXX_DEBUG
Simon Marchi [Wed, 4 May 2022 14:10:25 +0000 (10:10 -0400)]
gdbsupport: fix path_join crash with -std=c++17 and -D_GLIBCXX_DEBUG

When building GDB with -std=c++17 and -D_GLIBCXX_DEBUG=1, I get:

  $ ./gdb -nx --data-directory=data-directory -q -ex "maint selftest path_join"
  /usr/include/c++/11.2.0/string_view:233: constexpr const value_type& std::basic_string_view<_CharT, _Traits>::operator[](std::basic_string_view<_CharT, _Traits>::size_type) const [with _CharT = char; _Traits = std::char_traits<char>; std::basic_string_view<_CharT, _Traits>::const_reference = const char&; std::basic_string_view<_CharT, _Traits>::size_type = long unsigned int]: Assertion  '__pos < this->_M_len' failed.

The problem is that we're passing an empty string_view to
IS_ABSOLUTE_PATH.  IS_ABSOLUTE_PATH accesses [0] on that string_view,
which is out-of-bounds.

The reason this is not seen with -std less than c++17 is that our local
copy of string_view (used with C++ < 17) does not have the assert in
operator[], as that wouldn't work in a constexpr method:

  https://gitlab.com/gnutools/binutils-gdb/-/blob/5890af36e5112bcbb8d7555e63570f68466e6944/gdbsupport/gdb_string_view.h#L180

IS_ABSOLUTE_PATH is normally used with null-terminated string.  It's
fine to pass an empty null-terminated string to IS_ABSOLUTE_PATH,
because index 0 in such a string is valid.  But not with an empty
string_view.

Fix that by avoiding the "call" to IS_ABSOLUTE_PATH if the string_view
is empty.

Change-Id: Idf4df961b63f513b3389235e93814c02b89ea32e

2 years agoArm64: force emission of ILP32-dependent relocs
Jan Beulich [Thu, 19 May 2022 10:46:21 +0000 (12:46 +0200)]
Arm64: force emission of ILP32-dependent relocs

Like the placeholder types added in 04dfe7aa5217 ("Arm64: follow-on to
PR gas/27217 fix"), these are also placeholders which are subsequently
resolved (albeit later, hence this being a separate issue). As for the
resolved types 1 is returned, these pseudo-relocs should also have 1
returned to force retaining of the [eventual] relocations. This is also
spelled out individually for each of them in md_apply_fix().

2 years agoCOFF: use hash for string table also when copying / stripping
Jan Beulich [Thu, 19 May 2022 10:45:55 +0000 (12:45 +0200)]
COFF: use hash for string table also when copying / stripping

Otherwise the string table may grow and hence e.g. change a final binary
(observed with PE/COFF ones) even if really there's no change. Doing so
in fact reduces the overall amount of code, and in particular the number
of places which need to remain in sync.

Afaics there's no real equivalent to the "traditional_format" field used
when linking, so hashing is always enabled when copying / stripping.

2 years agoCOFF/PE: keep linker version during objcopy / strip
Jan Beulich [Thu, 19 May 2022 10:44:56 +0000 (12:44 +0200)]
COFF/PE: keep linker version during objcopy / strip

Neither of the tools is really a linker, so whatever was originally
recorded should be retained rather than being overwritten by these
tools' versions.

2 years agoCOFF/PE: don't leave zero timestamp after objcopy / strip
Jan Beulich [Thu, 19 May 2022 10:44:32 +0000 (12:44 +0200)]
COFF/PE: don't leave zero timestamp after objcopy / strip

Fill the timestamp field suitably for _bfd_XXi_only_swap_filehdr_out().
Instead of re-arranging the present if(), fold this logic with that of
copying the optional header.

2 years agoCOFF: make objcopy / strip honor --keep-file-symbols
Jan Beulich [Thu, 19 May 2022 10:44:08 +0000 (12:44 +0200)]
COFF: make objcopy / strip honor --keep-file-symbols

So far this option had no effect when used together with e.g.
--strip-debug. Set BSF_FILE on these symbols to change that.

While altering this also join two adjacent blocks of case labeled
statements with identical code.

2 years agodon't over-align file positions of PE executable sections
Jan Beulich [Thu, 19 May 2022 10:43:10 +0000 (12:43 +0200)]
don't over-align file positions of PE executable sections

When a sufficiently small alignment was specified via --file-alignment,
individual section alignment shouldn't affect placement within the file.
This involves first of all clearing D_PAGED for images when section and
file alignment together don't permit paging of the image. The involved
comparison against COFF_PAGE_SIZE in turn helped point out (through a
compiler warning) that 'page_size' should be of unsigned type (as in
particular FileAlignment is). This yet in turn pointed out a dubious
error condition (which is being deleted).

For the D_PAGED case I think the enforced file alignment may still be
too high, but I'm wary of changing that logic without knowing of
possible corner cases.

Furthermore file positions in PE should be independent of the alignment
recorded in section headers anyway. Otherwise there are e.g. anomalies
following commit 6f8f6017a0c4 ("PR27567, Linking PE files adds alignment
section flags to executables") in that linking would use information a
subsequent processing step (e.g. stripping) wouldn't have available
anymore, and hence a binary could change in that 2nd step for no actual
reason. (Similarly stripping a binary linked with a linker pre-dating
that commit would change the binary again when stripping it a 2nd time.)

2 years ago _bfd_real_fopen should not use ccs parameter on Windows
Yvan Roux [Thu, 19 May 2022 09:58:13 +0000 (10:58 +0100)]
 _bfd_real_fopen should not use ccs parameter on Windows

PR 25713
* bfdio.c (_bfd_real_fopen): Delete ccs string.

2 years agoRISC-V: Fix canonical extension order (K and J)
Tsukasa OI [Mon, 28 Mar 2022 13:12:01 +0000 (22:12 +0900)]
RISC-V: Fix canonical extension order (K and J)

This commit fixes canonical extension order to follow the RISC-V ISA
Manual draft-20210402-1271737 or later.

bfd/ChangeLog:

* elfxx-riscv.c (riscv_recognized_prefixed_ext): Fix "K" extension
prefix to be placed before "J".

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

2 years agoUse aarch64_features to describe register features in target descriptions.
John Baldwin [Wed, 18 May 2022 20:32:04 +0000 (13:32 -0700)]
Use aarch64_features to describe register features in target descriptions.

Replace the sve bool member of aarch64_features with a vq member that
holds the vector quotient.  It is zero if SVE is not present.

Add std::hash<> specialization and operator== so that aarch64_features
can be used as a key with std::unordered_map<>.

Change the various functions that create or lookup aarch64 target
descriptions to accept a const aarch64_features object rather than a
growing number of arguments.

Replace the multi-dimension tdesc_aarch64_list arrays used to cache
target descriptions with unordered_maps indexed by aarch64_feature.

2 years agoArm64: follow-on to PR gas/27217 fix
Jan Beulich [Wed, 18 May 2022 15:55:55 +0000 (17:55 +0200)]
Arm64: follow-on to PR gas/27217 fix

PR gas/27217

Prior to trying to address PR gas/28888 I noticed anomalies in how
certain insns would / wouldn't be affected in similar ways.

Commit eac4eb8ecb26 ("Fix a problem assembling AArch64 sources when a
relocation is generated against a symbol that has a defined value") had
two copy-and-paste mistakes, passing the wrong type to
aarch64_force_reloc().

It further failed to add placeholder relocation types to that function's
block of case labels leading to a return of 1. While not of interest for
aarch64_force_relocation() (these placeholders are resolved right in
parse_operands()), calls to aarch64_force_reloc() happen before that
resolution would take place.

2 years agoFix compile time warning building gold with Clang-14.
Nick Clifton [Wed, 18 May 2022 15:29:57 +0000 (16:29 +0100)]
Fix compile time warning building gold with Clang-14.

* int_encoding.cc (get_length_as_unsigned_LEB_128): Remove
current_length variable.

2 years agooops - forgot changelog entry for the previous delta.
Victor Do Nascimento [Wed, 18 May 2022 15:26:21 +0000 (16:26 +0100)]
oops - forgot changelog entry for the previous delta.

2 years agoarm: Add unwind support for mixed register lists
Victor Do Nascimento [Wed, 18 May 2022 15:25:12 +0000 (16:25 +0100)]
arm: Add unwind support for mixed register lists

* config/tc-arm.c (parse_reg_list): Add handling of mixed register
types.
(reg_names): Enumerate pseudoregister according to mapped physical
register number.
(s_arm_unwind_save_pseudo): Modify function signature.
(s_arm_unwind_save_core): Likewise.
(s_arm_unwind_save_mixed): New function.
(s_arm_unwind_save): Generate register list mask to pass to nested
functions.
* testsuite/gas/arm/unwind-pacbti-m.s: Expand test for mixed
  register type lists.
  * testsuite/gas/arm/unwind-pacbti-m.d: Likewise.
* testsuite/gas/arm/unwind-pacbti-m-readelf.d: Likewise.

2 years agoPowerPC: bp-permanent.exp, kill-after-signal fix
Carl Love [Fri, 6 May 2022 21:49:22 +0000 (21:49 +0000)]
PowerPC: bp-permanent.exp, kill-after-signal fix

Fix changes that didn't make it into commit:
dd9cd55e990bcc9f8448cac38d242d53974b3604.

Fix missing -wrap on gdb_test_multiple in gdb.base/kill-after-signal.exp
that is causing regression test on x86_64-linux with taskset -c 0.

2 years ago[AArch64] Return the regnum for PC (32) on aarch64
Yichao Yu [Wed, 18 May 2022 14:00:00 +0000 (15:00 +0100)]
[AArch64] Return the regnum for PC (32) on aarch64

This will allow the unwind info to explicitly specify a different value
for the return address from the link register.
Such usage, although uncommon, is valid and useful for signal frames.
It is also supported by aadwarf64 from ARM (Note 9 in [1]).

Ref https://sourceware.org/pipermail/gdb/2022-May/050091.html

[1] https://github.com/ARM-software/abi-aa/blob/2022Q1/aadwarf64/aadwarf64.rst#dwarf-register-names

Signed-off-by: Luis Machado <luis.machado@arm.com>
2 years agox86: shrink op_riprel
Jan Beulich [Wed, 18 May 2022 12:39:58 +0000 (14:39 +0200)]
x86: shrink op_riprel

It is only ever initialized from a boolean, so it as well as related
variables' types can simply be bool and there's no masking to 32 bits
needed in set_op().

2 years agoAdd a --no-weak option to nm.
Nick Clifton [Wed, 18 May 2022 12:15:22 +0000 (13:15 +0100)]
Add a --no-weak option to nm.

PR 29135
* nm.c (non_weak): New variable.
(filter_symbols): When non-weak is true, ignore weak symbols.
(long_options): Add --no-weak.
(usage): Mention --no-weak.
(main): Handle -W/--no-weak.
* doc/binutils.texi: Document new feature.
* NEWS: Mention the new feature.
* testsuite/binutils-all/nm.exp: Add test of new feature.
* testsuite/binutils-all/no-weak.s: New test source file.

2 years agoSupport -prompt and -lbl in gdb_test
Pedro Alves [Tue, 17 May 2022 10:16:01 +0000 (11:16 +0100)]
Support -prompt and -lbl in gdb_test

This teaches gdb_test to forward the -prompt and -lbl options to
gdb_test_multiple.

The option parsing is done with parse_args.

As a cleanup, instead of using llength and lindex to get at the
positional arguments, use lassign, and check whether the corresponding
variable is empty.

Convert gdb.base/ui-redirect.exp and gdb.xml/tdesc-reload.exp to use
gdb_test -prompt/-lbl instead of gdb_test_multiple as examples.

Change-Id: I243e1296d32c05a421ccef30b63d43a89eaeb4a0

2 years agoRemove unused DWARF PAUTH registers
Luis Machado [Fri, 6 May 2022 14:30:41 +0000 (15:30 +0100)]
Remove unused DWARF PAUTH registers

The AARCH64_DWARF_PAUTH_DMASK and AARCH64_DWARF_PAUTH_CMASK DWARF registers
never made their way into the aadwarf64. The following patch removes these
constants and their use.

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

2 years agoRename PAUTH_RA_STATE to RA_SIGN_STATE
Luis Machado [Fri, 6 May 2022 14:25:59 +0000 (15:25 +0100)]
Rename PAUTH_RA_STATE to RA_SIGN_STATE

The aadwarf64 [1] names this register RA_SIGN_STATE, so update the code to use
the same name.

[1] https://github.com/ARM-software/abi-aa/blob/main/aadwarf64/aadwarf64.rst

2 years ago[gdb/testsuite] Simplify unknown lang testing in gdb.base/parse_number.exp
Tom de Vries [Wed, 18 May 2022 10:12:29 +0000 (12:12 +0200)]
[gdb/testsuite] Simplify unknown lang testing in gdb.base/parse_number.exp

Move testing of language unknown out of the $supported_archs loop in
gdb.base/parse_number.exp.  This reduces total amount of tests from 18466 to
17744.

Tested on x86_64-linux.

2 years ago[gdb/testsuite] Use hex_for_lang in gdb.base/parse_number.exp
Tom de Vries [Wed, 18 May 2022 10:12:29 +0000 (12:12 +0200)]
[gdb/testsuite] Use hex_for_lang in gdb.base/parse_number.exp

In gdb.base/parse_number.exp, add a new proc hex_for_lang that formats a hex
number appropriately for a given language.

Tested on x86_64-linux.

2 years ago[gdb/tdep] Add gdb/syscalls/update-linux-from-src.sh
Tom de Vries [Wed, 18 May 2022 09:56:32 +0000 (11:56 +0200)]
[gdb/tdep] Add gdb/syscalls/update-linux-from-src.sh

Add a new script gdb/syscalls/update-linux-from-src.sh, that can be used to
generate *-linux.xml.in files from linux kernel sources, like so:
...
$ ./update-linux-from-src.sh ~/upstream/linux-stable.git
Skipping aarch64-linux.xml.in, no syscall.tbl
Generating amd64-linux.xml.in
Skipping arm-linux.xml.in, use arm-linux.py instead
Skipping bfin-linux.xml.in, no longer supported
Generating i386-linux.xml.in
Generating mips-n32-linux.xml.in
Generating mips-n64-linux.xml.in
Generating mips-o32-linux.xml.in
Generating ppc64-linux.xml.in
Generating ppc-linux.xml.in
Generating s390-linux.xml.in
Generating s390x-linux.xml.in
Generating sparc64-linux.xml.in
Generating sparc-linux.xml.in
...

Update *-linux.xml.in and *-linux.xml using linux kernel tag v5.18-rc6.

2 years agoAArch64: Enable FP16 by default for Armv9-A.
Tamar Christina [Wed, 18 May 2022 09:37:10 +0000 (10:37 +0100)]
AArch64: Enable FP16 by default for Armv9-A.

In Armv9-A SVE is mandatory, and for SVE FP16 is mandatory.  This fixes a disconnect
between GCC and binutils where GCC has FP16 on by default and gas doesn't.

include/ChangeLog:

2022-05-16  Tamar Christina  <tamar.christina@arm.com>

* opcode/aarch64.h (AARCH64_ARCH_V9_FEATURES): Add AARCH64_FEATURE_F16.

2 years agogas: avoid octal numbers being accepted when processing .linefile
Jan Beulich [Wed, 18 May 2022 07:38:40 +0000 (09:38 +0200)]
gas: avoid octal numbers being accepted when processing .linefile

Compilers would put decimal numbers there, so I think we should treat
finding octal numbers the same as finding bignums - ignore them as
actually being comments of some very specific form.

2 years agogas: avoid bignum related errors when processing .linefile
Jan Beulich [Wed, 18 May 2022 07:38:18 +0000 (09:38 +0200)]
gas: avoid bignum related errors when processing .linefile

Any construct which to the scrubber looks like a C preprocessor
line/file "directive" is converted to .linefile, but the amount of
checking the scrubber does is minimal (albeit it does let through only
decimal digits for the line part of the contruct). Since the scrubber
conversion is further tied to # being a line comment character, anything
which upon closer inspection turns out not to be a line/file "directive"
is supposed to be treated as a comment, i.e. ignored. Therefore we
cannot use get_absolute_expression(), as this may raise errors. Open-
code the function instead, treating everything not resulting in
O_constant as a comment as well.

Furthermore also bounds-check the parsed value. This bounds check tries
to avoid implementation defined behavior (which may be the raising of an
implementation defined signal), but for now makes the assumption that
int has less than 64 bits. The way bfd_signed_vma (which is what offsetT
aliases) is defined in bfd.h for the BFD64 case I cannot really see a
clean way of avoiding this assumption. Omitting the #ifdef, otoh, would
risk "condition is always false" warnings by compilers.

Convert get_linefile_number() to return bool at this occasion as well.

2 years agogas: fold do_repeat{,_with_expander}()
Jan Beulich [Wed, 18 May 2022 07:37:34 +0000 (09:37 +0200)]
gas: fold do_repeat{,_with_expander}()

do_repeat_with_expander() already deals with the "no expander" case
quite fine, so there's really little point having two functions. What it
lacks compared with do_repeat() is a call to sb_build(), which can
simply be moved (and the then redundant sb_new() be avoided). Along with
this moving also flip if the main if()'s condition such that the "no
expander" case is handled first.

2 years agogas: don't ignore .linefile inside false conditionals
Jan Beulich [Wed, 18 May 2022 07:37:00 +0000 (09:37 +0200)]
gas: don't ignore .linefile inside false conditionals

When assembling code previously pre-processed by a C compiler, long
enough comments may have been collapsed into "# <line> <file>"
constructs. If we skip these, line numbers (and possibly even file
names) will be off / wrong in both diagnostics and debug info.

2 years agogas: simplify ignore_input()
Jan Beulich [Wed, 18 May 2022 07:36:00 +0000 (09:36 +0200)]
gas: simplify ignore_input()

First of all convert to switch(), in preparation of adding another
directive here which may not be ignored. While doing so drop dead code:
A string the first two characters of which do not match "if" also wont
match "ifdef" or "ifndef".

2 years agogas: tweak .irp and alike file/line handling for M68K/MRI
Jan Beulich [Wed, 18 May 2022 07:35:29 +0000 (09:35 +0200)]
gas: tweak .irp and alike file/line handling for M68K/MRI

In commit 2ee1792bec22 ("gas: further adjust file/line handling for .irp
and alike") I neglected the need to omit the leading . in M68K/MRI mode.

2 years agogold: don't invoke IA32 syscall in x86_64 assembly testcase
Xi Ruoyao [Wed, 18 May 2022 07:34:31 +0000 (09:34 +0200)]
gold: don't invoke IA32 syscall in x86_64 assembly testcase

pr17704a_test.s is a x86_64 assembly file, but it invokes IA32 exit
syscall with "int 0x80".  This causes a segfault on kernels with
CONFIG_IA32_EMULATION disabled.

gold/

* testsuite/pr17704a_test.s (_start): Invoke x86_64 exit syscall
instead of its IA32 counterpart.

2 years agoAutomatic date update in version.in
GDB Administrator [Wed, 18 May 2022 00:00:31 +0000 (00:00 +0000)]
Automatic date update in version.in

2 years agoFix typo in info page
Nikolaos Chatzikonstantinou [Sun, 15 May 2022 12:39:42 +0000 (21:39 +0900)]
Fix typo in info page

2 years agoFix gdb.python/py-connection.exp with remote targets
Pedro Alves [Tue, 17 May 2022 11:53:32 +0000 (12:53 +0100)]
Fix gdb.python/py-connection.exp with remote targets

After the patch to make gdb_test's question non-optional when
specified, gdb.python/py-connection.exp started failing like so:

  $ make check TESTS="gdb.python/py-connection.exp" RUNTESTFLAGS="--target_board=native-gdbserver"
  (gdb) PASS: gdb.python/py-connection.exp: info connections while the connection is still around
  disconnect^M
  Ending remote debugging.^M
  (gdb) FAIL: gdb.python/py-connection.exp: kill the inferior

The problem is that "disconnect" when debugging with the native target
asks the user whether to kill the program, while with remote targets,
it doesn't.

Fix it by explicitly killing before disconnecting.

Tested with --target_board unix, native-gdbserver, and native-extended-gdbserver.

Change-Id: Icd85015c76deb84b71894715d43853c1087eba0b

2 years agogdb, btrace: Throw an error for empty recordings when replaying starts.
Felix Willgerodt [Mon, 9 May 2022 08:12:39 +0000 (10:12 +0200)]
gdb, btrace: Throw an error for empty recordings when replaying starts.

This makes record_btrace_start_replaying() more consistent, as it already
errors out e.g. on a recording with only gaps.

2 years agoMake gdb_test's question non-optional if specified
Pedro Alves [Wed, 30 Mar 2022 13:31:56 +0000 (14:31 +0100)]
Make gdb_test's question non-optional if specified

gdb_test supports handling scenarios where GDB asks a question before
finishing handling some command.  The full prototype of gdb_test is:

  # gdb_test COMMAND PATTERN MESSAGE QUESTION RESPONSE

However, QUESTION is a question that GDB _may_ ask, not one that GDB
_must_ ask:

 # QUESTION is a question GDB may ask in response to COMMAND, like
 #   "are you sure?"
 # RESPONSE is the response to send if QUESTION appears.

If GDB doesn't raise the question, the test still passes.

I think that this is a misfeature.  If GDB regresses and stops asking
a question, the testsuite won't notice.  So I think that if a QUESTION
is specified, gdb_test should ensure it comes out of GDB.

Running the testsuite exposed a number of tests that pass
QUESTION/RESPONSE to GDB, but no question comes out.  The previous
commits fixed them all, so this commit changes gdb_test's behavior.

A related issue is that gdb_test doesn't enforce that if you specify
QUESTION, that you also specify RESPONSE.  I.e., you should pass 1, 2,
3, or 5 arguments to gdb_test, but never 4, or more than 5.  Making
gdb_test detect bogus arguments actually regressed some testcases,
also all fixed in previous commits.

Change-Id: I47c39c9034e6a6841129312037a5ca4c5811f0db

2 years agogdb.base/skip.exp: Don't abuse gdb_test's question support
Pedro Alves [Tue, 17 May 2022 09:25:12 +0000 (10:25 +0100)]
gdb.base/skip.exp: Don't abuse gdb_test's question support

gdb.base/skip.exp abuses gdb_test's support for answering a GDB
question to do this:

    # With gcc 9.2.0 we jump once back to main before entering foo here.
    # If that happens try to step a second time.
    gdb_test "step" "foo \\(\\) at.*" "step 3" \
"main \\(\\) at .*\r\n$gdb_prompt " "step"

After a patch later in this series, gdb_test will FAIL if GDB does NOT
issue the question, so this test would start failing on older GCCs.

Switch to using gdb_test_multiple instead.  There are three spots in
the file that have the same pattern, and they're actually in a
sequence of commands that is repeated those 3 times.  Factor all that
out to a procedure.

I don't have gcc 9.2 handy, but I do have gcc 6.5, and that one is
affected as well, so update the comment.

Change-Id: If0a7e3cdf5191b4eec95ce0c8845c3a4d801c39e

2 years agoAvoid having to unload file in gdb.server/connect-with-no-symbol-file.exp
Pedro Alves [Wed, 30 Mar 2022 13:31:56 +0000 (14:31 +0100)]
Avoid having to unload file in gdb.server/connect-with-no-symbol-file.exp

gdb.server/connect-with-no-symbol-file.exp's connect_no_symbol_file
does:

gdb_test "file" ".*" "discard symbol table" \
    {Discard symbol table from `.*'\? \(y or n\) } "y"

A following patch will make gdb_test expect the question out of GDB if
one is passed down as argument to gdb_test.  With that, this test
starts failing.  This is because connect_no_symbol_file is called in a
loop, and the first time around, there's a loaded file, so "file" asks
the "Discard symbol table ... ?" question, while in the following
iterations there's no file, so there's no question.

Fix this by not loading a file into GDB in the first place.

Change-Id: I810c036b57842c4c5b47faf340466b0d446d1abc

2 years agoFix bogus gdb_test invocations
Pedro Alves [Wed, 30 Mar 2022 13:31:56 +0000 (14:31 +0100)]
Fix bogus gdb_test invocations

A following patch will make gdb_test error out if bogus arguments are
passed, which exposed bugs in a few testcases:

 - gdb.python/py-parameter.exp, passing a spurious "1" as extra
   parameter, resulting in:

   ERROR: Unexpected arguments: {set test-file-param bar.txt} {The name of the file has been changed to bar.txt} {set new file parameter} 1

 - gdb.python/py-xmethods.exp, a missing test message, resulting in
   the next gdb_test being interpreted as message, question and
   response!  With the enforcing patch, this was caught with:

   ERROR: Unexpected arguments: {p g.mul<char>('a')} {From Python G<>::mul.*} gdb_test {p g_ptr->mul<char>('a')} {From Python G<>::mul.*} {after: g_ptr->mul<char>('a')}

 - gdb.base/pointers.exp, missing a quote.

Change-Id: I66f2db4412025a64121db7347dfb0b48240d46d4

2 years agogdb.base/scope.exp: Remove bogus gdb_test questions
Pedro Alves [Wed, 30 Mar 2022 13:31:56 +0000 (14:31 +0100)]
gdb.base/scope.exp: Remove bogus gdb_test questions

This test is abusing the QUESTION/RESPONSE feature to send an
alternative command to GDB if the first command fails.  Like so:

   gdb_test "print 'scope0.c'::filelocal" \
    "\\\$$decimal = 1" "print 'scope0.c'::filelocal at main" \
    "No symbol \"scope0.c\" in current context.*" \
    "print '$srcdir/$subdir/scope0.c'::filelocal"

So if 'scope0.c' doesn't work, we try again with
'$srcdir/$subdir/scope0.c'.  I strongly suspect this is really an
obsolete test.  I think that if '$srcdir/$subdir/scope0.c' works, then
'scope0.c' should have worked too, thus I'd think that if we pass due
to the question path, then it's a bug.  So just remove the question
part passed to gdb_test.

Change-Id: I2acc99285f1d519284051b49693b5441fbdfe3cd

2 years agoRemove gdb_test questions that GDB doesn't ask
Pedro Alves [Wed, 30 Mar 2022 13:31:56 +0000 (14:31 +0100)]
Remove gdb_test questions that GDB doesn't ask

Change-Id: Ib2616dc883e9dc9ee100f6c86d83a921a0113c16

2 years agoRISC-V: Added half-precision floating-point v1.0 instructions.
Nelson Chu [Thu, 26 Mar 2020 10:38:27 +0000 (18:38 +0800)]
RISC-V: Added half-precision floating-point v1.0 instructions.

bfd/
* elfxx-riscv.c (riscv_implicit_subsets): Added implicit f
and zicsr for zfh.
(riscv_supported_std_z_ext): Added default v1.0 version for zfh.
(riscv_multi_subset_supports): Handle INSN_CLASS_ZFH,
INSN_CLASS_D_AND_ZFH and INSN_CLASS_Q_AND_ZFH.
gas/
* config/tc-riscv.c (FLT_CHARS): Added "hH".
(macro): Expand Pseudo M_FLH and M_FSH.
(riscv_pseudo_table): Added .float16 directive.
* testsuite/gas/riscv/float16-be.d: New testcase for .float16.
* testsuite/gas/riscv/float16-le.d: Likewise.
* testsuite/gas/riscv/float16.s: Likewise.
* testsuite/gas/riscv/fp-zfh-insns.d: New testcase for zfh.
* testsuite/gas/riscv/fp-zfh-insns.s: Likewise.
include/
* opcode/riscv-opc.h: Added MASK and MATCH encodings for zfh.
* opcode/riscv.h: Added INSN_CLASS and pseudo macros for zfh.
opcodes/
* riscv-opc.c (riscv_opcodes): Added zfh instructions.

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