binutils-gdb.git
3 years agoRevert "[gdb/symtab] Fix infinite recursion in dwarf2_cu::get_builder()"
Tom de Vries [Wed, 12 May 2021 14:03:02 +0000 (16:03 +0200)]
Revert "[gdb/symtab] Fix infinite recursion in dwarf2_cu::get_builder()"

This reverts commit 4cf88725da1cb503be04d3237354105ec170bc86.

It causes the following regression:
...
$ cat shadow.cc
namespace A {}

int
main()
{
  using namespace A;
  return 0;
}
$ g++-10 -g shadow.cc -flto -o shadow
$ ./gdb -q -batch ./shadow  -ex "b main"
Aborted (core dumped)
...

3 years agoEnsure data pointer kept within bounds
Alan Modra [Wed, 12 May 2021 07:57:34 +0000 (17:27 +0930)]
Ensure data pointer kept within bounds

* dwarf.c (process_extended_line_op): Don't bump data pointer past
end when strnlen doesn't find string terminator.
(decode_location_expression): Remove dead code.
(skip_attr_bytes): Remove const from end param.  Ensure data
pointer doesn't pass end.
(get_type_signedness): Remove const from end param.
(read_and_display_attr_value): Ensure data pointer doesn't pass end.
(display_debug_lines_raw, display_debug_lines_decoded): Likewise.
(display_debug_pubnames_worker): Likewise.
(display_debug_pubnames_worker): Use SAFE_BYTE_GET_AND INC rather
than blindly incrementing data pointer.
(display_debug_addr, display_debug_str_offsets): Likewise.  Don't
compare pointers, compare lengths.

3 years agoSAFE_BYTE_GET
Alan Modra [Wed, 12 May 2021 03:21:52 +0000 (12:51 +0930)]
SAFE_BYTE_GET

This rearranges SAFE_BYTE_GET* macros, eliminating some duplication,
and making sure that the _INC variants never increment their PTR arg
past END.  I've added an assertion that should show us places where we
use them improperly with user derived PTR args, which I'm sure the
fuzzers will find for us.

* dwarf.c (SAFE_BYTE_GET_INTERNAL): Define.
(SAFE_BYTE_GET, SAFE_BYTE_GET_AND_INC): Define using the above.
(SAFE_SIGNED_BYTE_GET, SAFE_SIGNED_BYTE_GET_AND_INC): Likewise.
(display_discr_list): Use SAFE_BYTE_GET_AND_INC rather than
SAFE_BYTE_GET followed by increment.
(process_debug_info): Likewise, and test bytes remaining before
incrementing section_begin rather than using pointer comparison.
(display_debug_names): Pass lvalue as SAFE_BYTE_GET PTR.
(process_cu_tu_index): Likewise for SAFE_BYTE_GET_AND_INC.

3 years agoSAFE_BYTE_GET64
Alan Modra [Wed, 12 May 2021 08:18:13 +0000 (17:48 +0930)]
SAFE_BYTE_GET64

Functions dealing with lack of a 64-bit integer type can disappear now
that we require C99.  Printing using dwarf_vmatoa is better too.

binutils/
* dwarf.c (dwarf_vmatoa64, SAFE_BYTE_GET64, add64): Delete.
(skip_attr_bytes): Replace use of SAFE_BYTE_GET64 with
SAFE_BYTE_GET_AND_INC.
(read_and_display_attr_value): Likewise.  Print using dwarf_vmatoa.
(process_debug_info, process_cu_tu_index): Likewise.
* elfcomm.c (byte_put, byte_put_little_endian, byte_put_big_endian),
(byte_get, byte_get_little_endian, byte_get_big_endian),
(byte_get_signed): Make size param unsigned.  Remove code dealing
with 4-byte elf_vma.
(byte_get_64): Delete.
* elfcomm.h  (byte_put, byte_put_little_endian, byte_put_big_endian),
(byte_get, byte_get_little_endian, byte_get_big_endian),
(byte_get_signed): Update prototypes.
(byte_get_64): Delete.
gas/
* testsuite/gas/elf/dwarf-5-file0.d: Update.
* testsuite/gas/i386/dwarf5-line-1.d: Update.

3 years agoPR27836, readelf -w pointer comparison UB
Alan Modra [Tue, 11 May 2021 08:27:04 +0000 (17:57 +0930)]
PR27836, readelf -w pointer comparison UB

PR 27836
* dwarf.c (display_debug_frames): Don't compare pointers derived
from user input.  Test offset against bounds instead.

3 years agoGuile: add value-const-value
George Barrett [Wed, 28 Apr 2021 17:32:56 +0000 (03:32 +1000)]
Guile: add value-const-value

The Guile API doesn't currently have an equivalent to the Python API's
gdb.Value.const_value(). This commit adds a procedure with equivalent
semantics to the Guile API.

gdb/ChangeLog:

* NEWS (Guile API): Note the addition of the new procedure.
* guile/scm-value.c (gdbscm_value_const_value): Add
implementation of value-const-value procedure.
(value_functions): Add value-const-value procedure.

gdb/doc/ChangeLog:

* guile.texi (Values From Inferior In Guile): Add documentation
for value-const-value.

gdb/testsuite/ChangeLog:

* gdb.guile/scm-value.exp (test_value_in_inferior): Add test for
value-const-value.

3 years agoGuile: add value-{rvalue-,}reference-value
George Barrett [Wed, 28 Apr 2021 17:32:47 +0000 (03:32 +1000)]
Guile: add value-{rvalue-,}reference-value

The Guile API doesn't currently have an equivalent to the Python API's
Value.reference_value() or Value.rvalue_reference_value(). This commit
adds a procedure with equivalent semantics to the Guile API.

gdb/ChangeLog:

* NEWS (Guile API): Note the addition of new procedures.
* guile/scm-value.c (gdbscm_reference_value): Add helper function
for reference value creation.
(gdbscm_value_reference_value): Add implementation of
value-reference-value procedure.
(gdbscm_value_rvalue_reference_value): Add implementation of
value-rvalue-reference-value procedure.
(value_functions): Add value-reference-value procedure.  Add
value-rvalue-reference-value procedure.

gdb/doc/ChangeLog:

* guile.texi (Values From Inferior In Guile): Add documentation
for value-reference-value.  Add documentation for
value-rvalue-reference-value.

gdb/testsuite/ChangeLog:

* gdb.guile/scm-value.exp (test_value_in_inferior): Add test for
value-reference-value.  Add test for value-rvalue-reference-value.

3 years agoGuile: improved rvalue reference support
George Barrett [Wed, 28 Apr 2021 17:32:37 +0000 (03:32 +1000)]
Guile: improved rvalue reference support

Adds a couple of missing bits to the Guile API to make C++11 rvalue
reference values and types usable from Guile scripts.

gdb/ChangeLog:

* guile/scm-type.c (type_integer_constants): Add binding for
TYPE_CODE_RVALUE_REF.
* guile/scm-value.c (gdbscm_value_referenced_value): Handle
dereferencing of rvalue references.
* NEWS (Guile API): Note improvements in rvalue reference support.

gdb/doc/ChangeLog:

* guile.texi (Types In Guile): Add documentation for
TYPE_CODE_RVALUE_REF.

3 years agoarm: fix fallout from recent thumb2 detection patch
Richard Earnshaw [Wed, 12 May 2021 10:43:59 +0000 (11:43 +0100)]
arm: fix fallout from recent thumb2 detection patch

The recent change to correct the detection of thumb2 object files
resulted in a ld test for veneering starting to fail.  The problem was
the test itself, which was incorrectly expecting thumb1 type far-call
veneers instead of the thumb2 flavour.  We already have a dump file of
the expected form, so the fix is to change the expected output
accordingly.

ld/

* testsuite/ld-arm/arm-elf.exp (farcall test for v8-m.mainline):
Correct expected output.

3 years agogdb: generate the prefix name for prefix commands on demand
Marco Barisione [Wed, 12 May 2021 10:19:22 +0000 (11:19 +0100)]
gdb: generate the prefix name for prefix commands on demand

Previously, the prefixname field of struct cmd_list_element was manually
set for prefix commands.  This seems verbose and error prone as it
required every single call to functions adding prefix commands to
specify the prefix name while the same information can be easily
generated.

Historically, this was not possible as the prefix field was null for
many commands, but this was fixed in commit
3f4d92ebdf7f848b5ccc9e8d8e8514c64fde1183 by Philippe Waroquiers, so
we can rely on the prefix field being set when generating the prefix
name.

This commit also fixes a use after free in this scenario:
* A command gets created via Python (using the gdb.Command class).
  The prefix name member is dynamically allocated.
* An alias to the new command is created. The alias's prefixname is set
  to point to the prefixname for the original command with a direct
  assignment.
* A new command with the same name as the Python command is created.
* The object for the original Python command gets freed and its
  prefixname gets freed as well.
* The alias is updated to point to the new command, but its prefixname
  is not updated so it keeps pointing to the freed one.

gdb/ChangeLog:

* command.h (add_prefix_cmd): Remove the prefixname argument as
it can now be generated automatically.  Update all callers.
(add_basic_prefix_cmd): Ditto.
(add_show_prefix_cmd): Ditto.
(add_prefix_cmd_suppress_notification): Ditto.
(add_abbrev_prefix_cmd): Ditto.
* cli/cli-decode.c (add_prefix_cmd): Ditto.
(add_basic_prefix_cmd): Ditto.
(add_show_prefix_cmd): Ditto.
(add_prefix_cmd_suppress_notification): Ditto.
(add_prefix_cmd_suppress_notification): Ditto.
(add_abbrev_prefix_cmd): Ditto.
* cli/cli-decode.h (struct cmd_list_element): Replace the
prefixname member variable with a method which generates the
prefix name at runtime.  Update all code reading the prefix
name to use the method, and remove all code setting it.
* python/py-cmd.c (cmdpy_destroyer): Remove code to free the
prefixname member as it's now a method.
(cmdpy_function): Determine if the command is a prefix by
looking at prefixlist, not prefixname.

3 years agoAdd MTE register set support for core files
Luis Machado [Wed, 12 May 2021 10:03:17 +0000 (11:03 +0100)]
Add MTE register set support for core files

* elf-bfd.h (elfcore_write_aarch_mte): New prototype.
* elf.c (elfcore_grok_aarch_mte, elfcore_write_aarch_mte): New
functions.
(elfcore_grok_note): Handle notes of type NT_ARM_TAGGED_ADDR_CTRL.
(elfcore_write_register_note): Handle MTE notes.

3 years agogdb, btrace, pt: ignore status update enable events
Markus Metzger [Fri, 30 Apr 2021 15:09:47 +0000 (17:09 +0200)]
gdb, btrace, pt: ignore status update enable events

Future versions of libipt report enable/disable status updates on PSB+.
Ignore them.

3 years agoPR27853, Infinite loop in dwarf.c
Alan Modra [Wed, 12 May 2021 05:41:43 +0000 (15:11 +0930)]
PR27853, Infinite loop in dwarf.c

Not quite infinite but much longer than it need be.  The problem is
triggered by read_and_display_attr_value incrementing "data" past
"end".  read_and_display_attr_value shouldn't do that, but be
defensive.

PR 27853
* dwarf.c (display_formatted_table): Test for data >= end rather
than data == end.
(process_extended_line_op): Likewise.
(display_debug_lines_raw): Likewise.
(display_debug_lines_decoded): Likewise.

3 years agoPR27849, heap-buffer-overflow on readelf -w
Alan Modra [Tue, 11 May 2021 23:21:22 +0000 (08:51 +0930)]
PR27849, heap-buffer-overflow on readelf -w

PR 27849
* dwarf.c (fetch_indexed_string): Correct length sanity checks.
Sanity check section size for version and padding too.  Correct
index sanity check.  Handle multiple tables in .debug_str_offsets.

3 years agosim: clean up explicit environment build calls
Mike Frysinger [Wed, 12 May 2021 04:46:19 +0000 (00:46 -0400)]
sim: clean up explicit environment build calls

This was enabled by default for all targets, but a few ports still
include an explicit call.  Clean that up, and update the docs.

3 years agoFix build failure in d10v sim
Luis Machado [Mon, 10 May 2021 19:06:50 +0000 (16:06 -0300)]
Fix build failure in d10v sim

While building all targets on Ubuntu 20.04/aarch64, I ran into the following
build error:

In file included from /usr/include/string.h:495,
                 from ../../bfd/bfd.h:48,
                 from ../../../../repos/binutils-gdb/sim/d10v/interp.c:4:
In function memset,
    inlined from sim_create_inferior at ../../../../repos/binutils-gdb/sim/d10v/interp.c:1146:3:
/usr/include/aarch64-linux-gnu/bits/string_fortified.h:71:10: error: __builtin_memset offset [33, 616] from the object at State is out of the bounds of referenced subobject regs with type reg_t[16] {aka short unsigned int[16]} at offset 0 [-Werror=array-bounds]
   71 |   return __builtin___memset_chk (__dest, __ch, __len, __bos0 (__dest));
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
make[3]: *** [Makefile:558: interp.o] Error 1

The following patch fixes this.

sim/ChangeLog:

2021-05-12  Luis Machado  <luis.machado@linaro.org>

* d10v/interp.c (sim_create_inferior): Fix memset call.

3 years agox86-64/ELF: Fix "clear src_mask for all reloc types" test case
Roland McGrath [Wed, 12 May 2021 00:00:30 +0000 (17:00 -0700)]
x86-64/ELF: Fix "clear src_mask for all reloc types" test case

ld/
* testsuite/ld-x86-64/rela.d: Fix regexp not to presume a specific
address layout, so it works for e.g. --target=x86-64-elf.

3 years agoAutomatic date update in version.in
GDB Administrator [Wed, 12 May 2021 00:00:36 +0000 (00:00 +0000)]
Automatic date update in version.in

3 years agogdb: fix indentation in arm_record_data_proc_misc_ld_str
Simon Marchi [Tue, 11 May 2021 21:32:28 +0000 (17:32 -0400)]
gdb: fix indentation in arm_record_data_proc_misc_ld_str

The scopes under this "if" are over-indented, fix that.

gdb/ChangeLog:

* arm-tdep.c (arm_record_data_proc_misc_ld_str): Fix
indentation.

Change-Id: I84a551793207ca95d0bc4f122e336555c8179c0e

3 years agogdb: fix indentation of cmd_list_element
Simon Marchi [Tue, 11 May 2021 20:08:16 +0000 (16:08 -0400)]
gdb: fix indentation of cmd_list_element

This structure declaration is over-indented, fix that.

gdb/ChangeLog:

* cli/cli-decode.h (struct cmd_list_element): Fix indentation.

Change-Id: I17c9cd739a233239b3add72f4fce7947c20907cd

3 years agoarm: correctly decode Tag_THUMB_ISA_use=3 for thumb2 features
Richard Earnshaw [Tue, 11 May 2021 15:18:25 +0000 (16:18 +0100)]
arm: correctly decode Tag_THUMB_ISA_use=3 for thumb2 features

This was detected when a user accidentally tried to build a shared
library using armv8-m.main objects.  The resulting error was "warning:
thumb-1 mode PLT generation not currently supported".  Something was
clearly wrong because v8-m.main is a thumb-2 variant.

It turns out that the code to detect thumb-2 in object files hadn't
been updated for the extended definition of Tag_THUMB_ISA_use to
support the value 3, meaning 'work it out for yourself from the
architecture tag'; something that is now necessary given that the line
between thumb-1 and thumb-2 has become blurred over time.

Another problem with the function doing this calculation was that the
absence of this tag (implying a default value 0) should mean use of
thumb code was NOT permitted.  However, the code went on to look at
the architecture flags and decide that it could ignore this if the
architecture flags said that thumb2 features were available, thus
completely ignoring the intended meaning.

bfd/

* elf32-arm.c (using_thumb2): Correctly handle Tag_THUMB_ISA_use
values 0 and 3.

3 years agodwarf.c (process_abbrev_set): Properly parenthesize, fix fallout
Hans-Peter Nilsson [Tue, 11 May 2021 14:12:24 +0000 (16:12 +0200)]
dwarf.c (process_abbrev_set): Properly parenthesize, fix fallout

Building as ILP32 shows:

 gcc -m32 -DHAVE_CONFIG_H -I. -I/checkout/binutils  -I. -I/checkout/binutils -I../bfd -I/checkout/binutils/../bfd -I/checkout/binutils/../include -DLOCALEDIR="\"/usr/local/share/locale\"" -Dbin_dummy_emulation=bin_vanilla_emulation  -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Wshadow -Wstack-usage=262144 -Werror -I/checkout/binutils/../zlib -g -O2   -MT dwarf.o -MD -MP -MF $depbase.Tpo -c -o dwarf.o /checkout/binutils/dwarf.c &&\
 mv -f $depbase.Tpo $depbase.Po
 In file included from /checkout/binutils/sysdep.h:101:0,
                  from /checkout/binutils/dwarf.c:21:
 /checkout/binutils/dwarf.c: In function 'process_abbrev_set':
 /checkout/binutils/dwarf.c:1072:15: error: format '%lx' expects argument of type 'long unsigned int', but argument 2 has type 'dwarf_vma {aka long long unsigned int}' [-Werror=format=]
        warn (_("Debug info is corrupted, abbrev size (%lx) is larger than "
                ^
 /checkout/binutils/dwarf.c:1072:13: note: in expansion of macro '_'
        warn (_("Debug info is corrupted, abbrev size (%lx) is larger than "
              ^
 cc1: all warnings being treated as errors
 Makefile:1101: recipe for target 'dwarf.o' failed

The recent commit, casting one of the terms, has an obvious
typo.  To wit, the (non-cast) term abbrev_size is a
dwarf_vma and causes the whole expression to (still) be 64
bits.

binutils:
* dwarf.c (process_abbrev_set): Properly parenthesize before
casting to unsigned long.

3 years ago[gdb/testsuite] Update infrun regexp in gdb.base/watch_thread_num.exp
Tom de Vries [Tue, 11 May 2021 12:22:11 +0000 (14:22 +0200)]
[gdb/testsuite] Update infrun regexp in gdb.base/watch_thread_num.exp

The test-case gdb.base/watch_thread_num.exp contains an infrun regexp:
...
       -re "infrun:" {
...
which doesn't trigger because:
- the test-case doesn't contain "set debug infrun 1", and
- if we hack the test-case to add this, the regexp doesn't match
  because "[infrun] " is printed instead.

Make the test pass with "set debug infrun 1" and add the setting commented
out.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2021-05-11  Tom de Vries  <tdevries@suse.de>

* gdb.base/watch_thread_num.exp: Fix "set debug infrun 1" FAILs.
Add "set debug infrun 1" commented out.

3 years ago[gdb/testsuite] Fix read1 timeout in gdb.base/gdb-sigterm.exp
Tom de Vries [Tue, 11 May 2021 12:22:11 +0000 (14:22 +0200)]
[gdb/testsuite] Fix read1 timeout in gdb.base/gdb-sigterm.exp

When running check-read1, I run into a timeout in test-case
gdb.base/gdb-sigterm.exp:
...
  [infrun] handle_inferior_event: status->kind = stopped, \
    signal = GDB_SIGNAL_TRAP^M
  [infrun] start_step_over: enter^M
    [infrun] start_step_overFAIL: gdb.base/gdb-sigterm.exp: \
      expect eof #0 (timeout)
gdb.base/gdb-sigterm.exp: expect eof #0: stepped 0 times
FAIL: gdb.base/gdb-sigterm.exp: 50 SIGTERM passes
...

The corresponding gdb_test_multiple has an exp_continue clause, but it doesn't
trigger because the regexp greps for 'infrun: ' instead of '[infrun] '.

Fix the timeout by fixing the infrun regexp.

Tested on x86_64-linux, with check and check-read1.

gdb/testsuite/ChangeLog:

2021-05-11  Tom de Vries  <tdevries@suse.de>

* gdb.base/gdb-sigterm.exp: Fix exp_continue regexp.

3 years agogdb/fortran: Breakpoint location is modified.
Bhuvanendra Kumar N [Tue, 11 May 2021 11:56:46 +0000 (17:26 +0530)]
gdb/fortran: Breakpoint location is modified.

Breakpoint location is modified to "return" statement which is
outside the DO loop. Because the label 100 of DO loop should get
executed for each iteration as shared in this external link:
http://www-pnp.physics.ox.ac.uk/~gronbech/intfor/node18.html.
flang compiler is following this fortran standard, whereas gfortran
compiler is not following, hence the test case is passing with
gfortran and failing with flang. but to correct this gfortran
behavior, bug has been filed in bugzilla
(https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99816). As reported in
the bug, with gfortran, label 100 of DO loop is reached only after
the completion of the entire DO loop. Hence at label 100, all the
array elements are set and printing of array element a(2) succeeds.
whereas with flang, when we are at label 100 for first time, array
element a(2) is not yet set, only a(1) is set, hence moving the
breakpoint location to outside the DO loop, so that once we are
outside the DO loop, we can print any of the array elements. This
change in test case is done irrespective of any fortran compiler.

gdb/testsuite/ChangeLog:
        * gdb.fortran/array-element.exp: Breakpoint location is modified.

3 years agoPR27844, Unstable symbol name in objdump outputs
Alan Modra [Tue, 11 May 2021 12:00:14 +0000 (21:30 +0930)]
PR27844, Unstable symbol name in objdump outputs

Special care for fuzzers.

PR 27844
* pdp11.c (aout_get_external_symbols): Clear first four bytes of
strings array, not just the first byte.
* aoutx.h (aout_get_external_symbols): Likewise.

3 years agoFix an illegal memory access when attempting to disassemble a corrupt TIC30 binary.
Nick Clifton [Tue, 11 May 2021 10:29:58 +0000 (11:29 +0100)]
Fix an illegal memory access when attempting to disassemble a corrupt TIC30 binary.

PR 27840
* tic30-dis.c (print_insn_tic30): Prevent attempts to read beyond
the end of the code buffer.

3 years agoPrevent libdel.dll.a from being installed on Windows based systems.
Nick Clifton [Tue, 11 May 2021 10:06:53 +0000 (11:06 +0100)]
Prevent libdel.dll.a from being installed on Windows based systems.

PR 27113
* Makefile.am (install-data-local): Also delete libdep.dll.a if it
is present.
* Makefile.in: Regenerate.

3 years agoReport illegal Z80 load instructions.
Sergey Belyashov [Tue, 11 May 2021 09:57:04 +0000 (10:57 +0100)]
Report illegal Z80 load instructions.

PR 27823
* config/tc-z80.c (emit_ld_r_m): Report an illegal load
instruction.
* testsuite/gas/z80/ill_ops.s: New test source file.
* testsuite/gas/z80/ill_ops.d: New test driver.
* testsuite/gas/z80/ill_ops.l: New test error output.

3 years agoPR27845, readelf heap-buffer-overflow
Alan Modra [Tue, 11 May 2021 08:27:59 +0000 (17:57 +0930)]
PR27845, readelf heap-buffer-overflow

PR 27845
* dwarf.c (process_abbrev_set): Replace start and end parameters
with section, abbrev_base, abbrev_size, abbrev_offset.  Update
all callers.  Sanity check parameters correctly and emit warnings
here rather than..
(process_debug_info): ..here.

3 years agoAutomatic date update in version.in
GDB Administrator [Tue, 11 May 2021 00:00:36 +0000 (00:00 +0000)]
Automatic date update in version.in

3 years ago[PR gdb/27614] gdb-add-index fails on symlinks.
Lancelot SIX [Wed, 24 Mar 2021 23:55:25 +0000 (23:55 +0000)]
[PR gdb/27614] gdb-add-index fails on symlinks.

PR 27614 shows that gdb-add-index fails to generate the index when its
argument is a symlink.

The following one liner illustrates the reported problem:

        $ echo 'int main(){}'|gcc -g -x c -;ln -s a.out symlink;gdb-add-index symlink
        gdb-add-index: No index was created for symlink
        gdb-add-index: [Was there no debuginfo? Was there already an index?]
        $ ls -l
        -rwxr-xr-x 1 25712 Mar 19 23:05 a.out*
        -rw------- 1  8277 Mar 19 23:05 a.out.gdb-index
        lrwxrwxrwx 1     5 Mar 19 23:05 symlink -> a.out*

GDB generates the .gdb-index file with a name that matches the name of
the actual program (a.out.gdb-index here), not the symlink that
references it.  The remaining of the script is looking for a file named
after the provided argument (would be 'symlink.gdb-index' in our
example).

gdb/ChangeLog:

PR gdb/27614
* contrib/gdb-add-index.sh: Fix when called with a symlink as an
argument.

gdb/testsuite/ChangeLog:

PR gdb/27614
* gdb.dwarf2/gdb-add-index-symlink.exp: New test.

3 years agoRemove strayed fprintf in commit 23182ac0d83
H.J. Lu [Mon, 10 May 2021 19:50:22 +0000 (12:50 -0700)]
Remove strayed fprintf in commit 23182ac0d83

PR binutils/27839
* simple.c (bfd_simple_get_relocated_section_contents): Remove
strayed fprintf.

3 years agogdb/testsuite: don't use source tree as temporary HOME directory
Andrew Burgess [Mon, 10 May 2021 15:49:56 +0000 (16:49 +0100)]
gdb/testsuite: don't use source tree as temporary HOME directory

In this commit:

  commit 1845e254645efbc02248345ccdb557d265dd8ae1
  Date:   Wed May 5 16:50:17 2021 +0100

      gdb/guile: perform tilde expansion when sourcing guile scripts

A test was added that tries to source a guile script from the users
HOME directory.  In order to achieve this the test (temporarily)
modifies $HOME to point into the binutils-gdb source tree.

The problem with this is that sourcing a guile script can cause the
guile script to be byte compiled and written into a .cache/ directory,
which is stored .... in the $HOME directory.

The result was that the test added in the above commit would cause a
.cache/ directory to be added into the binutils-gdb source tree.

In this commit the test is updated to create a new directory in the
build tree, the file we want to source is copied over, and $HOME is
set to point at the location in the build tree.  Now when the test is
run the .cache/ directory is created in the build tree, leaving the
source tree untouched.

gdb/testsuite/ChangeLog:

* gdb.guile/guile.exp: Don't use the source directory as a
temporary HOME directory.

3 years agogdb/testsuite: use proc parameters in gdb.arch/amd64-osabi.exp
Simon Marchi [Mon, 10 May 2021 16:43:06 +0000 (12:43 -0400)]
gdb/testsuite: use proc parameters in gdb.arch/amd64-osabi.exp

This test has a little oversight: the test procedure doesn't actually
use its parameters, the commands and expected patterns are hard-coded,
so we always test with i386:x86-64, instead of with the three arches.
Fix that.

gdb/testsuite/ChangeLog:

* gdb.arch/amd64-osabi.exp (test_osabi_none): Use the
parameters.

Change-Id: Iee2c32963d09e502ae791d5df2b6c04a1f49a57a

3 years agogdb, gdbserver: make status_to_str display the signal name
Simon Marchi [Mon, 10 May 2021 16:13:36 +0000 (12:13 -0400)]
gdb, gdbserver: make status_to_str display the signal name

I was looking at some "set debug lin-lwp" logs, and saw that a thread
received the "Child exited" signal.  It took me a moment to realize that
this was SIGCHLD.  I then thought that it would be nice for
status_to_str to show the signal name (SIGCHLD) in addition to the
description "Child exited", since people are much more used to referring
to signals using their names.

Fortunately, libiberty contains a handy function to get the signal name
from the signal number, strsigno, use that.

The output of "set debug lin-lwp" now looks like:

    [linux-nat] linux_nat_wait_1: waitpid 1209631 received SIGTRAP - Trace/breakpoint trap (stopped)

gdb/ChangeLog:

* nat/linux-waitpid.c (status_to_str): Show signal name.

Change-Id: I8ad9b1e744dd64461fd87b08d5c29f9ef97c4691

3 years agoFix an indirection via uninitialised memory when parsing a corrupt input file.
Nick Clifton [Mon, 10 May 2021 13:44:31 +0000 (14:44 +0100)]
Fix an indirection via uninitialised memory when parsing a corrupt input file.

PR 27839
* simple.c (simple_dummy_add_to_set): New function.
(simple_dummy_constructor): New function.
(simple_dummy_multiple_common): New function.
(bfd_simple_get_relocated_section_contents): Zero out the
callbacks structure, and then set the add_to_set, constructor and
multiple_common fields.

3 years agoEnable linker garbage collection for the PRU target.
Dimitar Dimitrov [Mon, 10 May 2021 13:00:00 +0000 (14:00 +0100)]
Enable linker garbage collection for the PRU target.

bfd * elf32-pru.c (elf_backend_can_gc_sections): Define as 1.

ld * testsuite/ld-elf/group8a.d: Remove pru from XFAIL list.
* testsuite/ld-elf/group8b.d: Ditto.
* testsuite/ld-elf/group9a.d: Ditto.
* testsuite/ld-elf/group9b.d: Ditto.
* testsuite/ld-elf/pr12851.d: Ditto.
* testsuite/ld-elf/pr22677.d: Ditto.
* testsuite/lib/ld-lib.exp (check_gc_sections_available): Remove
pru from list.

3 years agoPRU: Add alignment for resource table, and allow sizes of memory regions to be set...
Dimitar Dimitrov [Mon, 10 May 2021 12:58:17 +0000 (13:58 +0100)]
PRU: Add alignment for resource table, and allow sizes of memory regions to be set from the command line.

ld * scripttempl/pru.sc (.resource_table): Add ALIGN directive.
Use symbols for memory sizes.

3 years agoAdd support for 8-bit and 24-bit shifts in the z80 assembler.
Sergey Belyashov [Mon, 10 May 2021 12:36:08 +0000 (13:36 +0100)]
Add support for 8-bit and 24-bit shifts in the z80 assembler.

PR 27415
* config/tc-z80.c (emit_data_val): Add support for 8-bit and
24-bit shifts.
* testsuite/gas/z80/z80_reloc.a: Update tests.
* testsuite/gas/z80/z80_reloc.d: Update expected disassembly.

3 years agoRestore old behaviour of windres so that options containing spaces are not enclosed...
Thomas Wolff [Mon, 10 May 2021 10:28:15 +0000 (11:28 +0100)]
Restore old behaviour of windres so that options containing spaces are not enclosed in double quotes.

PR 4356
PR 26865
PR 27594
* windres.c (quot): Revert previous delta.  Do not use double
quotes when spaces are detected in options.
* doc/binutils.texi (windres): Remove suggestion that the
--preprocessor option can take arguments.

3 years agogdb/doc: reword a sentence
Andrew Burgess [Sun, 9 May 2021 16:26:53 +0000 (17:26 +0100)]
gdb/doc: reword a sentence

Change this:

  The available watchpoint types represented by constants are defined
  in the gdb module:

to this:

  The available watchpoint types are represented by constants defined
  in the gdb module:

The new version matches a similar line a few lines up the document
which reads:

  The available types are represented by constants defined in the gdb
  module:

gdb/doc/ChangeLog:

* guile.texinfo (Breakpoints In Guile): Reword sentence.
* python.texinfo (Breakpoints In Python): Reword sentence.

3 years agoAvoid possible pointer wrap
Alan Modra [Mon, 10 May 2021 00:26:43 +0000 (09:56 +0930)]
Avoid possible pointer wrap

PTR supplied to these macros can be read from user input, END is an
end of buffer pointer.  It's safer to do arithmetic on END than on PTR.

* dwarf.c (SAFE_BYTE_GET): Check bounds by subtracting amount from
END rather than adding amount to PTR.
(SAFE_SIGNED_BYTE_GET, SAFE_BYTE_GET64): Likewise.

3 years agoAutomatic date update in version.in
GDB Administrator [Mon, 10 May 2021 00:00:37 +0000 (00:00 +0000)]
Automatic date update in version.in

3 years agogdb/doc: document 'set debug py-unwind'
Andrew Burgess [Sat, 8 May 2021 17:02:36 +0000 (18:02 +0100)]
gdb/doc: document 'set debug py-unwind'

When the 'set debug py-unwind' flag was added, it was never documented
in the manual.  This commit adds some text for this command to the
manual.

gdb/doc/ChangeLog:

* python.texinfo (Python Commands): Document 'set debug
py-unwind' and 'show debug py-unwind'.

3 years agogdb/py: add some debugging to py-breakpoint.c
Andrew Burgess [Wed, 5 May 2021 12:46:36 +0000 (13:46 +0100)]
gdb/py: add some debugging to py-breakpoint.c

Adds some new debugging to python/py-breakpoint.c.

gdb/ChangeLog:

* python/py-breakpoint.c (pybp_debug): New static global.
(show_pybp_debug): New function.
(pybp_debug_printf): Define.
(PYBP_SCOPED_DEBUG_ENTER_EXIT): Define.
(gdbpy_breakpoint_created): Add some debugging.
(gdbpy_breakpoint_deleted): Likewise.
(gdbpy_breakpoint_modified): Likewise.
(_initialize_py_breakpoint): New function.

gdb/doc/ChangeLog:

* python.texinfo (Python Commands): Document 'set debug
py-breakpoint' and 'show debug py-breakpoint'.

3 years agogdb/py: convert debug logging in py-unwind to use new scheme
Andrew Burgess [Sat, 8 May 2021 15:28:41 +0000 (16:28 +0100)]
gdb/py: convert debug logging in py-unwind to use new scheme

Converts the debug print out in python/py-unwind.c to use the new
debug printing scheme.  I have also modified what is printed in a few
places, for example, rather than printing frame pointers, I now print
the frame level, this matches what we do in the general 'set debug
frame' tracing, and is usually more helpful (I think).

I also added a couple of ENTER/EXIT scope printers.

gdb/ChangeLog:

* python/py-unwind.c (pyuw_debug): Convert to bool.
(show_pyuw_debug): New function.
(pyuw_debug_printf): Define.
(PYUW_SCOPED_DEBUG_ENTER_EXIT): Define.
(pyuw_this_id): Convert to new debug print macros.
(pyuw_prev_register): Likewise.
(pyuw_sniffer): Likewise.
(pyuw_dealloc_cache): Likewise.
(_initialize_py_unwind): Update now pyuw_debug is a bool, and add
show function when registering.

3 years agogdb: replace fprint_frame_id
Andrew Burgess [Sat, 8 May 2021 14:43:56 +0000 (15:43 +0100)]
gdb: replace fprint_frame_id

Replace fprint_frame_id with a member function frame_id::to_string
that returns a std::string.  Convert all of the previous users of
fprint_frame_id to use the new member function.  This means that
instead of writing things like this:

  fprintf_unfiltered (file, " id=");
  fprint_frame_id (file, s->id.id);

We can write this:

  fprintf_unfiltered (file, " id=%s", s->id.id.to_string ().c_str ());

There should be no user visible changes after this commit.

gdb/ChangeLog:

* dummy-frame.c (fprint_dummy_frames): Convert use of
fprint_frame_id to use frame_id::to_string.
* frame.c (fprint_field): Delete.
(fprint_frame_id): Moved to...
(frame_id::to_string): ...this, rewritten to return a string.
(fprint_frame): Convert use of fprint_frame_id to use
frame_id::to_string.
(compute_frame_id): Likewise.
(frame_id_p): Likewise.
(frame_id_eq): Likewise.
(frame_id_inner): Likewise.
* frame.h (struct frame_id) <to_string>: New member function.
(fprint_frame_id): Delete declaration.
* guile/scm-frame.c (frscm_print_frame_smob): Convert use of
fprint_frame_id to use frame_id::to_string.
* python/py-frame.c (frame_object_to_frame_info): Likewise.
* python/py-unwind.c (unwind_infopy_str): Likewise.
(pyuw_this_id): Likewise.

3 years agoUse htab_eq_string in libctf
Alan Modra [Sun, 9 May 2021 02:58:32 +0000 (12:28 +0930)]
Use htab_eq_string in libctf

* ctf-impl.h (ctf_dynset_eq_string): Don't declare.
* ctf-hash.c (ctf_dynset_eq_string): Delete function.
* ctf-dedup.c (make_set_element): Use htab_eq_string.
(ctf_dedup_atoms_init, ADD_CITER, ctf_dedup_init): Likewise.
(ctf_dedup_conflictify_unshared): Likewise.
(ctf_dedup_walk_output_mapping): Likewise.

3 years agoUse htab_eq_string in binutils
Alan Modra [Sun, 9 May 2021 02:58:18 +0000 (12:28 +0930)]
Use htab_eq_string in binutils

A quick check says this is the only place in all of bfd, opcodes,
binutils, gas, ld, gprof that duplicates the new libiberty
htab_eq_string.

* objcopy.c (eq_string): Delete.
(create_symbol_htab): Use htab_eq_string.

3 years agogdbsupport: re-generate configure & friends
Simon Marchi [Sun, 9 May 2021 01:27:49 +0000 (21:27 -0400)]
gdbsupport: re-generate configure & friends

I get these changes when re-generating the autoconf stuff in gdbsupport,
fallouts from 4655f8509fd4 ("Don't run personality syscall at configure
time; don't check it at all").

gdbsupport/ChangeLog:

* Makefile.in: Re-generate.
* config.in: Re-generate.
* configure: Re-generate.

Change-Id: Ie1876ee58d6f4f1cf25fa14900eecf4c85a744c1

3 years agogdb, gdbserver: make status_to_str return std::string
Simon Marchi [Sun, 9 May 2021 01:06:41 +0000 (21:06 -0400)]
gdb, gdbserver: make status_to_str return std::string

Instead of using a static buffer.  This is safer, and we don't really
mind about any extra dynamic allocation here, since it's only used for
debug purposes.

gdb/ChangeLog:

* nat/linux-waitpid.c (status_to_str): Return std::string.
* nat/linux-waitpid.h (status_to_str): Likewise.
* linux-nat.c (linux_nat_post_attach_wait): Adjust.
(linux_nat_target::attach): Adjust.
(linux_handle_extended_wait): Adjust.
(wait_lwp): Adjust.
(stop_wait_callback): Adjust.
(linux_nat_filter_event): Adjust.
(linux_nat_wait_1): Adjust.
* nat/linux-waitpid.c (status_to_str): Adjust.
* nat/linux-waitpid.h (status_to_str): Adjust.

gdbserver/ChangeLog:

* linux-low.cc (linux_process_target::wait_for_event_filtered):
Adjust to status_to_str returning std::string.

Change-Id: Ia8aead70270438a5690f243e6faafff6c38ff757

3 years agogdb: add missing space in infrun_debug_printf
Simon Marchi [Sun, 9 May 2021 00:37:27 +0000 (20:37 -0400)]
gdb: add missing space in infrun_debug_printf

gdb/ChangeLog:

* infrun.h (infrun_debug_printf): Add missing space.

Change-Id: I476096a098451ff2019ab38caa41ebfef0e04a1c

3 years agoAutomatic date update in version.in
GDB Administrator [Sun, 9 May 2021 00:00:37 +0000 (00:00 +0000)]
Automatic date update in version.in

3 years agosim: h8300: clean up various warnings
Mike Frysinger [Sat, 8 May 2021 16:41:04 +0000 (12:41 -0400)]
sim: h8300: clean up various warnings

A random grab bag of minor fixes to enable -Werror for this port.

Disable h8_set_macS for now as it's unused.
Initialize trace & intMask before using them.
Mark local set_h8300h function static.

3 years agosim: touch modules target
Mike Frysinger [Sat, 8 May 2021 16:34:03 +0000 (12:34 -0400)]
sim: touch modules target

If there are no updates to the file, touch the result so we don't
keep trying to regenerate it.

3 years agosim: cgen: tweak trace format
Mike Frysinger [Sun, 2 May 2021 02:29:50 +0000 (22:29 -0400)]
sim: cgen: tweak trace format

Fixes build warnings when the address size isn't an integer.

3 years agosim: cgen: namespace mode_names a bit
Mike Frysinger [Sun, 2 May 2021 02:11:41 +0000 (22:11 -0400)]
sim: cgen: namespace mode_names a bit

These are exported in the library linkage, so add a cgen_ prefix.

3 years agosim: cgen: tweak cgen_rtx_error to fix warnings
Mike Frysinger [Sun, 2 May 2021 02:05:25 +0000 (22:05 -0400)]
sim: cgen: tweak cgen_rtx_error to fix warnings

The function was missing a prototype, and passing a constant string
as the format string instead of going through a %s format.

3 years agosim: cgen: tweak initializers to avoid warnings
Mike Frysinger [Sun, 2 May 2021 02:03:05 +0000 (22:03 -0400)]
sim: cgen: tweak initializers to avoid warnings

Use {} instead of {0} to avoid warnings:

common/cgen-utils.c:59:1: warning: missing braces around initializer [-Wmissing-braces]
   59 | {
      | ^
   60 |   {
   61 |     VIRTUAL_INSN_X_INVALID, "--invalid--", NULL, 0, { V, { 0 } }
      |                                                            {{}}

Generated code should be the same.

3 years agobinutils: update release docs process
Mike Frysinger [Sun, 2 May 2021 16:58:11 +0000 (12:58 -0400)]
binutils: update release docs process

Now that we generate multiple html & pdf forms, update the release
process to show how they get updated.

3 years agosupport generating multi-html pages in parallel
Mike Frysinger [Sun, 2 May 2021 16:50:39 +0000 (12:50 -0400)]
support generating multi-html pages in parallel

Use the pattern from other projects where we generate the html pages
in a dir named the same as the project.  So now we have:
gas/doc/gas.html - single html page
gas/doc/gas/ - multiple html pages

This works for projects that have a doc/ subdir already, but gprof &
ld require a little tweaking since they generate their docs in their
respective toplevels.

3 years agogenerate single html manual page by default
Mike Frysinger [Sun, 2 May 2021 16:09:00 +0000 (12:09 -0400)]
generate single html manual page by default

This better matches other GNU projects like autoconf/automake where
the html manual is the single page form.  We'll support the multi-page
form in a follow up change.

3 years agosim: add html & pdf stubs
Mike Frysinger [Sat, 8 May 2021 15:53:37 +0000 (11:53 -0400)]
sim: add html & pdf stubs

We stub out the info targets already since we don't provide any.

3 years agosim: use htab_eq_string
Tom Tromey [Sat, 8 May 2021 13:50:47 +0000 (07:50 -0600)]
sim: use htab_eq_string

This changes the sim to use htab_eq_string from libiberty.

sim/common/ChangeLog
2021-05-08  Tom Tromey  <tom@tromey.com>

* sim-options.c (compare_strings): Remove.
(dup_arg_p): Use htab_eq_string.

3 years agoDon't run personality syscall at configure time; don't check it at all
Pedro Alves [Wed, 28 Apr 2021 22:05:15 +0000 (23:05 +0100)]
Don't run personality syscall at configure time; don't check it at all

Currently, in order to tell whether support for disabling address
space randomization on Linux is available, GDB checks if the
personality syscall works, at configure time.  I.e., it does a run
test, instead of a compile/link test:

  AC_RUN_IFELSE([PERSONALITY_TEST],
[have_personality=true],
[have_personality=false],

This is a bit bogus, because the machine the build is done on may not
(and is when you consider distro gdbs) be the machine that eventually
runs gdb.  It would be better if this were a compile/link test
instead, and then at runtime, GDB coped with the personality syscall
failing.  Actually, GDB already copes.

One environment where this is problematic is building GDB in a Docker
container -- by default, Docker runs the container with seccomp, with
a profile that disables the personality syscall.  You can tell Docker
to use a less restricted seccomp profile, but I think we should just
fix it in GDB.

"man 2 personality" says:

       This system call first appeared in Linux 1.1.20 (and thus first
       in a stable kernel release with Linux 1.2.0); library support
       was added in glibc 2.3.

...

       ADDR_NO_RANDOMIZE (since Linux 2.6.12)
              With this flag set, disable address-space-layout randomization.

glibc 2.3 was released in 2002.
Linux 2.6.12 was released in 2005.

The original patch that added the configure checks was submitted in
2008.  The first version of the patch that was submitted to the list
called personality from common code:

 https://sourceware.org/pipermail/gdb-patches/2008-June/058204.html

and then was moved to Linux-specific code:

 https://sourceware.org/pipermail/gdb-patches/2008-June/058209.html

Since HAVE_PERSONALITY is only checked in Linux code, and
ADDR_NO_RANDOMIZE exists for over 15 years, I propose just completely
removing the configure checks.

If for some odd reason, some remotely modern system still needs a
configure check, then we can revert this commit but drop the
AC_RUN_IFELSE in favor of always doing the AC_LINK_IFELSE
cross-compile fallback.

gdb/ChangeLog:

* linux-nat.c (linux_nat_target::supports_disable_randomization):
Remove references to HAVE_PERSONALITY.
* nat/linux-personality.c: Remove references to HAVE_PERSONALITY.
(maybe_disable_address_space_randomization)
(~maybe_disable_address_space_randomizatio): Remove references to
HAVE_PERSONALITY.
* config.in, configure: Regenerate.

gdbserver/ChangeLog:

* linux-low.cc:
(linux_process_target::supports_disable_randomization): Remove
reference to HAVE_PERSONALITY.
* config.in, configure: Regenerate.

gdbsupport/ChangeLog:

* common.m4 (personality test): Remove.

3 years agoDon't include sys/personality.h in linux-low.cc anymore
Pedro Alves [Sat, 8 May 2021 11:54:43 +0000 (12:54 +0100)]
Don't include sys/personality.h in linux-low.cc anymore

Lancelot pointed out that since the refactor at:

  https://sourceware.org/pipermail/gdb-patches/2015-January/120503.html

the sys/personality.h include is not needed in linux-low.cc anymore,
as it does not call personality directly itself anymore.

gdbserver/ChangeLog:

* linux-low.cc: Don't include sys/personality.h or define
ADDR_NO_RANDOMIZE.

3 years agosim: m68hc11: fix up cycle buffer printing
Mike Frysinger [Sat, 8 May 2021 01:53:25 +0000 (21:53 -0400)]
sim: m68hc11: fix up cycle buffer printing

Make sure the local static buffer is large enough, and simplify the
sprintf for merging the fields all into one.  This fixes compiler
warnings from buf possibly being overflowed.

3 years agoAutomatic date update in version.in
GDB Administrator [Sat, 8 May 2021 00:00:38 +0000 (00:00 +0000)]
Automatic date update in version.in

3 years agogdb/guile: perform tilde expansion when sourcing guile scripts
Andrew Burgess [Wed, 5 May 2021 15:50:17 +0000 (16:50 +0100)]
gdb/guile: perform tilde expansion when sourcing guile scripts

Before this patch:

  (gdb) source ~/script.scm
  ERROR: In procedure apply-smob/1:
  ERROR: In procedure primitive-load-path: Unable to find file "~/script.scm" in load path
  Error while executing Scheme code.
  (gdb)

This is because the path is not tilde expanded.  In contrast, when
sourcing a .py or .gdb script the path is tilde expanded.

This commit fixes this oversight, and allows the above source command
to work as expected.

The tilde expansion is done in the generic GDB code before we call the
sourcer function for any particular extension language.

gdb/ChangeLog:

* cli/cli-cmds.c: Add 'gdbsupport/gdb_tilde_expand.h'
include.
(source_script_with_search): Perform tilde expansion.

gdb/testsuite/ChangeLog:

* gdb.guile/guile.exp: Add an extra test.

3 years agogdb/testsuite: use gdb_test_no_output instead of send_gdb
Andrew Burgess [Fri, 7 May 2021 21:14:27 +0000 (22:14 +0100)]
gdb/testsuite: use gdb_test_no_output instead of send_gdb

I noticed gdb.base/ptype-offsets.exp failing occasionally, this was
due to lines like this in the test script:

  send_gdb "set print type hex on\n"

As this does not match the '(gdb)' prompt that is produced, the prompt
would sometimes be matched against the next test, causing the next
test to think its output was missing and fail.

Fix this by switching to:

  gdb_test_no_output "set print type hex on"

gdb/testsuite/ChangeLog:

* gdb.base/ptype-offsets.exp: Replace use of send_gdb with
gdb_test_no_output.

3 years agogdb: make target_desc_info::filename an std::string
Simon Marchi [Fri, 7 May 2021 20:28:56 +0000 (16:28 -0400)]
gdb: make target_desc_info::filename an std::string

To make the management of memory automatic.

As to why I chose to make this an std::string and not an
std::unique_xmalloc_ptr<char>: some parts of the code consider both a
NULL value and an empty string value to mean "no filename".
target_desc_info_from_user_p, however, doesn't check for a non-NULL but
empty string value.  So it seems like having two ways of denoting "no
filename" can lead to these kinds of inconsistencies.  Using
std::string, "no filename" is only represented by an empty value.

As a bonus, using an std::string lets us copy target_desc_info objects
using the default assignment operator.

gdb/ChangeLog:

* target-descriptions.c (struct target_desc_info) <filename>:
Make std::string.
(copy_inferior_target_desc_info): Adjust.
(target_desc_info_free): Adjust.
(target_find_description): Adjust.
(set_tdesc_filename_cmd): Adjust.
(show_tdesc_filename_cmd): Adjust.
(unset_tdesc_filename_cmd): Adjust.
(maint_print_c_tdesc_cmd): Adjust.

Change-Id: I4e3a6ad8ccda2b88c202471d4f54249753cad127

3 years agogdb: (de-)allocate target_desc_info with new/delete
Simon Marchi [Fri, 7 May 2021 20:28:56 +0000 (16:28 -0400)]
gdb: (de-)allocate target_desc_info with new/delete

In preparation for using non-POD types in the struct.

gdb/ChangeLog:

* target-descriptions.c (struct target_desc_info): Initialize
fields.
(get_tdesc_info): Use new.
(target_desc_info_free): Use delete.

Change-Id: I10fdaeeae7cdbd7930ae7adeeb13f7f363c67c7a

3 years agogdb: change target_desc_info::fetched to bool
Simon Marchi [Fri, 7 May 2021 20:28:56 +0000 (16:28 -0400)]
gdb: change target_desc_info::fetched to bool

gdb/ChangeLog:

* target-descriptions.c (struct target_desc_info) <fetched>:
bool.
(target_find_description): Adjust.
(target_clear_description): Adjust.

Change-Id: Ib69e097b38cf270e674f1249105d535a312954e1

3 years agogdb: remove target description macros
Simon Marchi [Fri, 7 May 2021 20:28:56 +0000 (16:28 -0400)]
gdb: remove target description macros

In my opinion, the target_desc_fetched, current_target_desc and
target_description_filename macros in target-descriptions.c are not very
useful.  I don't think it's useful to hide that they operate on the
current inferior, as everything currently works under the assumption
that the various tdesc commands operate on the current inferior, and I
don't see that changing in the foreseeable future.

This change also avoids having multiple unnecessary calls to
current_inferior and get_tdesc_info per function.

gdb/ChangeLog:

* target-descriptions.c (struct target_desc_info) <tdesc>:
Adjust doc.
(target_desc_fetched): Remove.
(current_target_desc): Remove.
(target_description_filename): Remove.
(target_find_description): Adjust.
(target_clear_description): Adjust.
(target_current_description): Adjust.
(set_tdesc_filename_cmd): Adjust.
(show_tdesc_filename_cmd): Adjust.
(unset_tdesc_filename_cmd): Adjust.
(maint_print_c_tdesc_cmd): Adjust.
(maint_print_xml_tdesc_cmd): Adjust.

Change-Id: Ibfb581490e949c16d59924e2cac633ede5c26c5b

3 years agosim: Add bfd include path for common testsuite tools
Dimitar Dimitrov [Mon, 5 Apr 2021 16:21:35 +0000 (19:21 +0300)]
sim: Add bfd include path for common testsuite tools

On a host without installed libbfd, this patch fixes the following
"make check-sim" errors for both pru cross target, and native x86_64:

In file included from ../../../binutils/sim/common/sim-basics.h:131,
                 from testsuite/common/bits32m0.c:13:../../../binutils/sim/../include/gdb/callback.h:55:10: fatal error: bfd.h: No such file or directory
   55 | #include "bfd.h"
      |          ^~~~~~~

Signed-off-by: Dimitar Dimitrov <dimitar@dinux.eu>
3 years agoAdd a generic .bss directive for ELF based targets.
Nick Clifton [Fri, 7 May 2021 16:07:41 +0000 (17:07 +0100)]
Add a generic .bss directive for ELF based targets.

PR 3136
* config/obj-elf.c (elf_pseudo_table): Add entry for .bss.
(obj_elf_bss): New function.  Change to the .bss section.
Support an optional subsection number.
(obj_elf_change_section): Call obj_elf_section_change_hook.
(obj_elf_section): Likewise.
(obj_elf_data): Likewise.
(obj_elf_text): Likewise.
(obj_elf_struct): Likewise.
(obj_elf_subsection): Likewise.
(obj_elf_previous): Likewise.
* config/obj-elf.h (obj_elf_bss): Prototype.
* doc/as.texi (Bss): New node.

3 years agogdb: some int to bool conversion
Andrew Burgess [Fri, 7 May 2021 15:49:24 +0000 (16:49 +0100)]
gdb: some int to bool conversion

Change int parameter to bool in remote_notice_new_inferior (remote.c)
and notice_new_inferior (infcmd.c), and update the callers.

There should be no user visible changes after this commit.

gdb/ChangeLog:

* infcmd.c (notice_new_inferior): Change parameter type.
* inferior.h (notice_new_inferior): Change parameter type.
* remote.c (remote_notice_new_inferior): Change parameter type to
bool.  Also update type of local variable to bool.
(remote_target::update_thread_list): Change type of local variable
to bool.
(remote_target::process_stop_reply): Pass bool instead of int to
remote_notice_new_inferior.

3 years agogdb: remove reference to current inferior in target_stack::unpush
Simon Marchi [Fri, 7 May 2021 15:52:51 +0000 (11:52 -0400)]
gdb: remove reference to current inferior in target_stack::unpush

target_stack::unpush needs to get the target beneath the target being
unpushed to update the m_top field (which keeps the stratum of the
top-most target).  It currently does so using target_ops::beneath, which
uses the target stack of the current inferior.  The target stack of the
current inferior is the same as the `this` in the unpush method.

Avoid this detour and remove this reference to the current inferior by
calling target_ops::find_beneath and passing `this` to find the target
beneath `t` in the target stack that is `this`.

gdb/ChangeLog:

* target.c (target_stack::unpush): Call target_ops::find_beneath
to get the target beneath `t`.

Change-Id: If9d9661567c5c16f655d270bd2ec9f1b3aa6dadc

3 years agogdb: make target_close check that the target isn't pushed in all inferiors
Simon Marchi [Fri, 7 May 2021 15:51:19 +0000 (11:51 -0400)]
gdb: make target_close check that the target isn't pushed in all inferiors

The target_close function currently checks that the target to be closed
isn't pushed in the current inferior:

    gdb_assert (!current_inferior ()->target_is_pushed (targ));

Normally, a target is closed when its refcount has dropped to 0, due to
not being used in any inferior anymore.  I think it would make sense to
change that assert to not only check in the current inferior, but to
check in all inferiors.  It would be quite bad (and a bug) to close a
target while it's still pushed in one of the non-current inferiors.

gdb/ChangeLog:

* target.c (target_close): Check in all inferiors that the
target is not pushed.

Change-Id: I6e37fc3f3476a0593da1e476604642b2de90f1d5

3 years agodebuginfod-support.c: Use long-lived debuginfod_client
Aaron Merey [Fri, 7 May 2021 15:37:16 +0000 (11:37 -0400)]
debuginfod-support.c: Use long-lived debuginfod_client

Instead of initializing a new debuginfod_client for each query, store
the first initialized client for the remainder of the GDB session and
use it for every debuginfod query.

In conjunction with upcoming changes to libdebuginfod, using one client
for all queries will avoid latency caused by unneccesarily setting up
TCP connections multiple times.

Tested on Fedora 33 x86_64.

gdb/ChangeLog:

* debuginfod-support.c (debuginfod_init): Remove.
(get_debuginfod_client): New function.

3 years agoRemove streq_hash in favor of htab_eq_string
Tom Tromey [Fri, 7 May 2021 15:18:18 +0000 (09:18 -0600)]
Remove streq_hash in favor of htab_eq_string

Now that libiberty includes htab_eq_string, we can remove the
identical function from gdb.

gdb/ChangeLog
2021-05-07  Tom Tromey  <tom@tromey.com>

* breakpoint.c (ambiguous_names_p): Use htab_eq_string.
* utils.c (streq_hash): Remove.
* utils.h (streq_hash): Don't declare.
* completer.c (completion_tracker::discard_completions): Update
comment.
* ada-lang.c (_initialize_ada_language): Use htab_eq_string.

3 years agogdb: re-format Python files using black 21.4b0
Simon Marchi [Fri, 7 May 2021 14:56:20 +0000 (10:56 -0400)]
gdb: re-format Python files using black 21.4b0

Re-format all Python files using black [1] version 21.4b0.  The goal is
that from now on, we keep all Python files formatted using black.  And
that we never have to discuss formatting during review (for these files
at least) ever again.

One change is needed in gdb.python/py-prettyprint.exp, because it
matches the string representation of an exception, which shows source
code.  So the change in formatting must be replicated in the expected
regexp.

To document our usage of black I plan on adding this to the "GDB Python
Coding Standards" wiki page [2]:

--8<--

All Python source files under the `gdb/` directory must be formatted
using black version 21.4b0.

This specific version can be installed using:

    $ pip3 install 'black == 21.4b0'

All you need to do to re-format files is run `black <file/directory>`,
and black will re-format any Python file it finds in there.  It runs
quite fast, so the simplest is to do:

    $ black gdb/

from the top-level.

If you notice that black produces changes unrelated to your patch, it's
probably because someone forgot to run it before you.  In this case,
don't include unrelated hunks in your patch.  Push an obvious patch
fixing the formatting and rebase your work on top of that.

-->8--

Once this is merged, I plan on setting a up an `ignoreRevsFile`
config so that git-blame ignores this commit, as described here:

  https://github.com/psf/black#migrating-your-code-style-without-ruining-git-blame

I also plan on working on a git commit hook (checked in the repo) to
automatically check the formatting of the Python files on commit.

[1] https://pypi.org/project/black/
[2] https://sourceware.org/gdb/wiki/Internals%20GDB-Python-Coding-Standards

gdb/ChangeLog:

* Re-format all Python files using black.

gdb/testsuite/ChangeLog:

* Re-format all Python files using black.
* gdb.python/py-prettyprint.exp (run_lang_tests): Adjust.

Change-Id: I28588a22c2406afd6bc2703774ddfff47cd61919

3 years agogdb: add lookup_cmd_exact to simplify a common pattern
Marco Barisione [Fri, 7 May 2021 14:43:30 +0000 (15:43 +0100)]
gdb: add lookup_cmd_exact to simplify a common pattern

In code dealing with commands, there's a pattern repeated a few times of
calling lookup_cmd with some speficic arguments and then using strcmp
on the returned command to check for an exact match.
As a later patch would add a few more similar lines of code, this patch
adds a new lookup_cmd_exact function which simplify this use case.

gdb/ChangeLog:

* cli/cli-decode.c (lookup_cmd_exact): Add.
* cli/cli-script.c (do_define_command): Use lookup_cmd_exact.
(define_prefix_command): Ditto.
* command.h: Add lookup_cmd_exact.

3 years agoFix .dwsect generation for XCOFF. Handle .function generated with DWARF on XCOFF.
Cl?ment Chigot [Fri, 7 May 2021 14:29:49 +0000 (15:29 +0100)]
Fix .dwsect generation for XCOFF.  Handle .function generated with DWARF on XCOFF.

gas * config/tc-ppc.c (ppc_function): Update comment for
fifth argument.
(ppc_frob_symbol): Remove ppc_last_function check.
Make sure coff_last_function is reset.
Correctly set fsize when not provided in .function.
* testsuite/gas/ppc/aix.exp: New tests.
* testsuite/gas/ppc/xcoff-function-1-32.d: New test.
* testsuite/gas/ppc/xcoff-function-1-64.d: New test.
* testsuite/gas/ppc/xcoff-function-1.s: New test.

bfd * coff-rs6000.c (xcoff_dwsect_names): Add new DWARF
sections.
* coffgen.c (coff_pointerize_aux): Handle C_DWARF.
(coff_print_symbol): Likewise.
* libxcoff.h (XCOFF_DWSECT_NBR_NAMES): Update.

gas * config/obj-coff.c (coff_frob_symbol): Don't skip C_DWARF.
(coff_adjust_section_syms): Use corrext auxent for C_DWARF.
(coff_frob_section): Likewise.
* config/obj-coff.h (SA_GET_SECT_SCNLEN,
SA_GET_SECT_NRELOC, SA_SET_SECT_SCNLEN,
SA_SET_SECT_NRELOC) New defines.
(SET_SECTION_RELOCS): Adjust for C_DWARF.
* config/tc-ppc.c (ppc_frob_symbol): Don't skip C_DWARF.
(ppc_adjust_symtab): Reorder C_DWARF symbols.
* testsuite/gas/ppc/aix.exp: New tests.
* testsuite/gas/ppc/xcoff-dwsect-2-32.d: New test.
* testsuite/gas/ppc/xcoff-dwsect-2-64.d: New test.
* testsuite/gas/ppc/xcoff-dwsect-2.s: New test.

include * coff/internal.h (C_DWARF): New define.
* coff/xcoff.h (SSUBTYP_DWLOC, SSUBTYP_DWFRAME,
SSUBTYP_DWMAC): New defines.

3 years agoSrop readelf's unwind decoder from complaining about x86 binaries.
Nick Clifton [Fri, 7 May 2021 14:24:14 +0000 (15:24 +0100)]
Srop readelf's unwind decoder from complaining about x86 binaries.

* readelf.c (no_processor_specific_unwind): New function.
(process_unwind): Use no_processor_specific_unwind for X86
targets.

3 years agolibiberty: add htab_eq_string
Tom Tromey [Thu, 29 Apr 2021 00:44:48 +0000 (18:44 -0600)]
libiberty: add htab_eq_string

The libiberty hash table includes a helper function for strings, but
no equality function.  Consequently, this equality function has been
reimplemented a number of times in both the gcc and binutils-gdb
source trees.  This patch adds the function to the libiberty hash
table, as a step toward the goal of removing all the copies.

One change to gcc is included here.  Normally I would have put this in
the next patch, but gensupport.c used the most natural name for its
reimplementation of this function, and this can't coexist with the
extern function in libiberty.

include

* hashtab.h (htab_eq_string): Declare.

libiberty

* hashtab.c (htab_eq_string): New function.

3 years ago[gdb/symtab] Fix infinite recursion in dwarf2_cu::get_builder()
Tom de Vries [Fri, 7 May 2021 10:13:05 +0000 (12:13 +0200)]
[gdb/symtab] Fix infinite recursion in dwarf2_cu::get_builder()

With the test-case attached in PR26327, gdb aborts:
...
$ gdb -q -batch 447.dealII -ex "b main"
Aborted (core dumped)
...
when running out of stack due to infinite recursion:
...
 #8  0x00000000006aaba6 in dwarf2_cu::get_builder (this=0x35e4b40)
     at src/gdb/dwarf2/read.c:700
 #9  0x00000000006aaba6 in dwarf2_cu::get_builder (this=0x22ee2c0)
     at src/gdb/dwarf2/read.c:700
 #10 0x00000000006aaba6 in dwarf2_cu::get_builder (this=0x35e4b40)
     at src/gdb/dwarf2/read.c:700
 #11 0x00000000006aaba6 in dwarf2_cu::get_builder (this=0x22ee2c0)
     at src/gdb/dwarf2/read.c:700
...

We're recursing in this code in dwarf2_cu::get_builder():
...
     /* Otherwise, search ancestors for a valid builder.  */
     if (ancestor != nullptr)
       return ancestor->get_builder ();
...
due to the fact that the ancestor chain is a cycle.

Higher up in the call stack, we find some code that is responsible for
triggering this, in new_symbol:
...
       case DW_TAG_formal_parameter:
         {
           /* If we are inside a function, mark this as an argument.  If
              not, we might be looking at an argument to an inlined function
              when we do not have enough information to show inlined frames;
              pretend it's a local variable in that case so that the user can
              still see it.  */
           struct context_stack *curr
             = cu->get_builder ()->get_current_context_stack ();
           if (curr != nullptr && curr->name != nullptr)
             SYMBOL_IS_ARGUMENT (sym) = 1;
...

This is code that was added to support pre-4.1 gcc, to be able to show
arguments of inlined functions as locals, in the absense of sufficiently
correct debug information.

Removing this code (that is, doing SYMBOL_IS_ARGUMENT (sym) = 1
unconditially), fixes the crash.  The ancestor variable also seems to have
been added specifically to deal with fallout from this code, so remove that as
well.

Tested on x86_64-linux:
- openSUSE Leap 15.2 with gcc 7.5.0, and
- openSUSE Tumbleweed with gcc 10.3.0.

gdb/ChangeLog:

2021-05-07  Tom de Vries  <tdevries@suse.de>

PR symtab/26327
* dwarf2/read.c (struct dwarf2_cu): Remove ancestor.
(dwarf2_cu::get_builder): Remove ancestor-related code.
(new_symbol): Remove code supporting pre-4.1 gcc that show arguments
of inlined functions as locals.
(follow_die_offset, follow_die_sig_1): Remove setting of ancestor.

gdb/doc/ChangeLog:

2021-05-07  Tom de Vries  <tdevries@suse.de>

PR symtab/26327
* gdb.texinfo (Inline Functions): Update.

3 years agox86-64/ELF: clear src_mask for all reloc types
Jan Beulich [Fri, 7 May 2021 10:05:12 +0000 (12:05 +0200)]
x86-64/ELF: clear src_mask for all reloc types

x86-64 uses rela relocations. The comment next to the field's declaration
says "Non-zero values for ELF USE_RELA targets should be viewed with
suspicion ..." And indeed the fields being non-zero causes section
contents to be accumulated into the final relocated values in addition to
the relocations' addends, which is contrary to the ELF spec.

3 years agox86: don't mix disp and imm processing
Jan Beulich [Fri, 7 May 2021 10:03:12 +0000 (12:03 +0200)]
x86: don't mix disp and imm processing

Surely disp processing should access the disp operand, not an imm one.
This is not an active issue only because imms and disps are, at the
moment, overlapping fields of the same union.

3 years agox86: move register check in immediate operand parsing
Jan Beulich [Fri, 7 May 2021 10:02:40 +0000 (12:02 +0200)]
x86: move register check in immediate operand parsing

i386_finalize_immediate() is used for both AT&T and Intel immediate
operand handling. Move an AT&T-only check to i386_immediate(), which at
the same time allows it to cover other cases as well, giving an overall
better / more consistent diagnostic.

3 years agox86: minor improvements to optimize_imm()
Jan Beulich [Fri, 7 May 2021 10:02:07 +0000 (12:02 +0200)]
x86: minor improvements to optimize_imm()

- Drop a pointless & where just before it was checked that the
  respective bits are clear already anyway.
- Avoid a not really necessary operand_type_set() and a redundant
  operand_type_or() / operand_type_and() pair.

3 years agoWhen computing section link order for a relocateable link, ignore section sizes.
Nick Clifton [Fri, 7 May 2021 09:57:47 +0000 (10:57 +0100)]
When computing section link order for a relocateable link, ignore section sizes.

* ldelfgen.c (compare_link_order): Ignore section size when
performing a relocateable link.

3 years agogdb/guile: Have gdbscm_safe_source_script return a unique_ptr
Andrew Burgess [Wed, 5 May 2021 20:39:06 +0000 (21:39 +0100)]
gdb/guile: Have gdbscm_safe_source_script return a unique_ptr

Change gdbscm_safe_source_script to return a
gdb::unique_xmalloc_ptr<char> instead of a raw char*.  Update the
users of this function.

There should be no user visible change after this commit.

gdb/ChangeLog:

* guile/guile-internal.h (gdbscm_safe_source_script): Change
function return type.
* guile/guile.c (gdbscm_source_script): Update to handle change in
gdbscm_safe_source_script.
* guile/scm-objfile.c (gdbscm_source_objfile_script): Likewise.
* guile/scm-safe-call.c (gdbscm_safe_source_script): Change return
type.

3 years agodwarf: Don't omit second operand of '?' operator
Michael Forney [Sat, 1 May 2021 07:55:16 +0000 (00:55 -0700)]
dwarf: Don't omit second operand of '?' operator

This is a GNU C extension and is not valid in ISO C.

* dwarf.c: Don't omit second operand of '?' operator.

3 years agomultiple definition warnings from script symbols
Alan Modra [Fri, 7 May 2021 01:54:10 +0000 (11:24 +0930)]
multiple definition warnings from script symbols

In commit 89753bbf81 I enabled a warning for scripts redefining
symbols.  The idea was to not warn for symbols defined by shared
libraries (the h->u.def.section->output_section != NULL test), but the
test failed to take into account absolute symbols.  Absolute symbols
defined in shared libraries are currently indistinguishable from
absolute symbols defined in relocatable objects, at least when only
looking at struct bfd_link_hash_entry.  So, don't warn for any
absolute symbols.

* ldexp.c (update_definedness): Don't return false for absolute
symbols.
* ldmain.c (multiple_definition): Print "warning: " in message
when not a hard error.

3 years agosim: m32c: clean up various warnings
Mike Frysinger [Fri, 7 May 2021 04:31:05 +0000 (00:31 -0400)]
sim: m32c: clean up various warnings

A random grab bag of minor fixes to enable -Werror for this port.

Check the return values of read & write calls and issue warnings when
they fail.
Fixup funky pointer math as the compiler doesn't like ++ on void*.
Handle short reads with fread().

3 years agosim: m32c: fix warnings about mixing code & decls
Mike Frysinger [Fri, 7 May 2021 04:26:36 +0000 (00:26 -0400)]
sim: m32c: fix warnings about mixing code & decls

Add scope braces to a bunch of the generated sections to avoid compiler
warnings about mixing code & variable declarations.

3 years agosim: m32c: switch from custom fgets to getline
Mike Frysinger [Fri, 7 May 2021 04:08:43 +0000 (00:08 -0400)]
sim: m32c: switch from custom fgets to getline

No need to implement this ourselves when POSIX has a nice API.

3 years agosim: m68hc11: fix up last warnings
Mike Frysinger [Fri, 7 May 2021 03:52:05 +0000 (23:52 -0400)]
sim: m68hc11: fix up last warnings

Change the printf formats a little to fix the last build warnings in
here, and then turn on -Werror by default for the arch port.