binutils-gdb.git
2 years agotestsuite supports_dt_relr
Alan Modra [Thu, 13 Jan 2022 02:21:12 +0000 (12:51 +1030)]
testsuite supports_dt_relr

Tidy, and fix "FAIL: Build dt-relr-glibc-1b.so" on all non-x86
linux targets.

binutils/
* binutils-common.exp (supports_dt_relr): New proc.
ld/
* testsuite/config/default.exp (DT_RELR_LDFLAGS, NO_DT_RELR_LDFLAGS),
(DT_RELR_CC_LDFLAGS, NO_DT_RELR_CC_LDFLAGS): Use supports_dt_relr.
* testsuite/ld-elf/dt-relr.exp: Don't run unless supports_dt_relr.
* testsuite/ld-elf/dt-relr-1a.d: Likewise.
* testsuite/ld-elf/dt-relr-1b.d: Likewise.
* testsuite/ld-elf/dt-relr-1c.d: Likewise.
* testsuite/ld-elf/dt-relr-2a.d: Likewise.
* testsuite/ld-elf/dt-relr-2b.d: Likewise.
* testsuite/ld-elf/dt-relr-2c.d: Likewise.
* testsuite/ld-elf/dt-relr-2d.d: Likewise.
* testsuite/ld-elf/dt-relr-2e.d: Likewise.
* testsuite/ld-elf/dt-relr-2f.d: Likewise.
* testsuite/ld-elf/dt-relr-2g.d: Likewise.
* testsuite/ld-elf/dt-relr-2h.d: Likewise.
* testsuite/ld-elf/dt-relr-3a.d: Likewise.
* testsuite/ld-elf/dt-relr-3b.d: Likewise.

2 years agoDon't use C++ comments in assembly
Alan Modra [Thu, 13 Jan 2022 01:45:45 +0000 (12:15 +1030)]
Don't use C++ comments in assembly

It might seem to work, but only if '/' is a start of comment char.

* testsuite/ld-elf/dt-relr-1.s: Use # for comment.
* testsuite/ld-elf/dt-relr-2.s: Likewise.
* testsuite/ld-elf/dt-relr-3.s: Likewise.

2 years agoMove DT_RELR tag setting to elflink.c
Alan Modra [Thu, 13 Jan 2022 00:29:30 +0000 (10:59 +1030)]
Move DT_RELR tag setting to elflink.c

This makes the code setting DT_RELR tags generally available.  Many
targets will be able to use the defaults.  Those that can't should set
up sh_entsize for .relr.dyn output section before reaching the dynamic
tag code in bfd_elf_final_link.

* elflink.c (bfd_elf_final_link): Set up DT_RELR tags and sh_entsize.
* elfxx-x86.c (_bfd_x86_elf_finish_dynamic_sections): Don't do any
of that here.

2 years agoRe: Set SEC_ELF_REVERSE_COPY earlier
Alan Modra [Wed, 12 Jan 2022 05:11:22 +0000 (15:41 +1030)]
Re: Set SEC_ELF_REVERSE_COPY earlier

Let's not rely on .init/.fini having relocs for the size sanity check.
This is mainly to squash reports of "my fuzzed object made ld hang".

2 years agogdb: testsuite: make string[] type as char in gdb.base/charset.c
Tiezhu Yang [Thu, 13 Jan 2022 03:11:39 +0000 (11:11 +0800)]
gdb: testsuite: make string[] type as char in gdb.base/charset.c

This reverts the commit ff656e2e1cb1 ("gdb: testsuite: fix failed
testcases in gdb.base/charset.exp").

The original test code has no problem. On an architecture where
char is signed, then both 'A' and ebcdic_us_string[7] will yield
-63, which makes the equality true. On an architecture where char
is unsigned, then both 'A' and ebcdic_us_string[7] will yield 193,
which also makes the equality true.

The test cases only failed on LoongArch. The default type of char
is signed char on LoongArch, like x86-64. But when use gdb print
command on LoongArch, the default type of char is unsigned char,
this is wrong, I will look into it later, sorry for that.

On LoongArch:

  $ cat test_char.c
  #include <stdio.h>

  int main()
  {
          char c1 = 193;
          unsigned char c2 = 193;

          printf("%d\n", c1);
          printf("%d\n", c1 == c2);

          return 0;
  }
  $ gcc test_char.c -o test_char
  $ ./test_char
  -63
  0

  (gdb) set target-charset EBCDIC-US
  (gdb) print 'A'
  $1 = 193 'A'
  (gdb) print /c 'A'
  $2 = 193 'A'
  (gdb) print /u 'A'
  $3 = 193
  (gdb) print /d 'A'
  $4 = -63
  (gdb) print /x 'A'
  $5 = 0xc1

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

2 years agogdb Power 9 add test for HW watchpoint support.
Carl Love [Wed, 12 Jan 2022 17:56:58 +0000 (11:56 -0600)]
gdb Power 9 add test for HW watchpoint support.

The Power 9 processor revision 2.2 has HW watchpoint support disabled due
to a HW bug.  The support is fixed in Power 9 processor revision 2.3.  This
patch add a test to lib/gdb.exp for Power to determine if the processor
supports HW watchpoints or not.  If the Power processor doesn't support HW
watchpoints the proceedure skip_hw_watchpoint_tests will return 1 to
disable the various HW watchpoint tests.

The patch has been tested on Power 9, processor revesions 2.2 and 2.3.  The
patch has also been tested on Power 10.  No regression test failures were
found.

2 years agogdb/python: add gdb.host_charset function
Andrew Burgess [Wed, 12 Jan 2022 11:52:19 +0000 (11:52 +0000)]
gdb/python: add gdb.host_charset function

We already have gdb.target_charset and gdb.target_wide_charset.  This
commit adds gdb.host_charset along the same lines.

2 years agogdb/testsuite: fix gdb.python/py-events.exp for finding process id
Tankut Baris Aktemur [Wed, 12 Jan 2022 15:06:10 +0000 (16:06 +0100)]
gdb/testsuite: fix gdb.python/py-events.exp for finding process id

When executed with --target_board=native-extended-gdbserver, the
gdb.python/py-events.exp test errors out with

  ERROR: tcl error sourcing /path/to/gdb/testsuite/gdb.python/py-events.exp.
  ERROR: can't read "process_id": no such variable
      while executing
  "lappend expected "ptid: \\($process_id, $process_id, 0\\)" "address: $addr""
      (file "/path/to/gdb/testsuite/gdb.python/py-events.exp" line 103)
      invoked from within
  "source /path/to/gdb/testsuite/gdb.python/py-events.exp"
      ("uplevel" body line 1)
      invoked from within
  "uplevel #0 source /path/to/gdb/testsuite/gdb.python/py-events.exp"
      invoked from within
  "catch "uplevel #0 source $test_file_name""

There are multiple problems around this:

1. The process_id variable is not initialized to a default value.

2. The test attempts to find the PID of the current thread, but the
   regexp that it uses is not tailored for the output printed by the
   remote target.

3. The test uses "info threads" to find the current thread PID.
   Using the "thread" command instead is simpler.

Fix these problems.

2 years agoDon't mention "serial" in target remote description
Tom Tromey [Tue, 11 Jan 2022 18:52:33 +0000 (11:52 -0700)]
Don't mention "serial" in target remote description

PR remote/9177 points out that "info files" mentions "serial" a couple
of times:

    Remote serial target in gdb-specific protocol:
    Debugging a target over a serial line.

However, often the remote target isn't really a serial connection.

It seems to me that this text could be a bit clearer; and furthermore
since "info files" prints the target's long description,
remote_target::files_info doesn't really add much and can simply be
removed.

Regression tested on x86-64 Fedora 34.

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

2 years agold: Add glibc dependency for DT_RELR
H.J. Lu [Thu, 6 Jan 2022 03:21:45 +0000 (19:21 -0800)]
ld: Add glibc dependency for DT_RELR

When DT_RELR is enabled, to avoid random run-time crash with older glibc
binaries without DT_RELR support, add a GLIBC_ABI_DT_RELR symbol version,
which is provided by glibc with DT_RELR support, dependency on the shared
C library if it provides a GLIBC_2.XX symbol version.

bfd/

* elflink.c (elf_link_add_dt_relr_dependency): New function.
(bfd_elf_size_dynamic_sections): Call
elf_link_add_dt_relr_dependency if DT_RELR is enabled.

ld/

* ld.texi: Mention GLIBC_ABI_DT_RELR in -z pack-relative-relocs
entry.
* testsuite/ld-elf/dt-relr-glibc-1.c: New file.
* testsuite/ld-elf/dt-relr-glibc-1a.rd: Likewise.
* testsuite/ld-elf/dt-relr-glibc-1b.rd: Likewise.
* testsuite/ld-elf/dt-relr.exp: Likewise.

2 years agold: Add simple DT_RELR tests
H.J. Lu [Thu, 6 Jan 2022 00:01:08 +0000 (16:01 -0800)]
ld: Add simple DT_RELR tests

* testsuite/ld-elf/dt-relr-1.s: New file.
* testsuite/ld-elf/dt-relr-1a.d: Likewise.
* testsuite/ld-elf/dt-relr-1b.d: Likewise.
* testsuite/ld-elf/dt-relr-1c.d: Likewise.
* testsuite/ld-elf/dt-relr-2.s: Likewise.
* testsuite/ld-elf/dt-relr-2a.d: Likewise.
* testsuite/ld-elf/dt-relr-2b.d: Likewise.
* testsuite/ld-elf/dt-relr-2c.d: Likewise.
* testsuite/ld-elf/dt-relr-2d.d: Likewise.
* testsuite/ld-elf/dt-relr-2e.d: Likewise.
* testsuite/ld-elf/dt-relr-2f.d: Likewise.
* testsuite/ld-elf/dt-relr-2g.d: Likewise.
* testsuite/ld-elf/dt-relr-2h.d: Likewise.
* testsuite/ld-elf/dt-relr-3.s: Likewise.
* testsuite/ld-elf/dt-relr-3a.d: Likewise.
* testsuite/ld-elf/dt-relr-3b.d: Likewise.
* testsuite/ld-i386/dt-relr-1.s: Likewise.
* testsuite/ld-i386/dt-relr-1a.d: Likewise.
* testsuite/ld-i386/dt-relr-1b.d: Likewise.
* testsuite/ld-x86-64/dt-relr-1a-x32.d: Likewise.
* testsuite/ld-x86-64/dt-relr-1a.d: Likewise.
* testsuite/ld-x86-64/dt-relr-1b-x32.d: Likewise.
* testsuite/ld-x86-64/dt-relr-1b.d: Likewise.
* testsuite/ld-x86-64/dt-relr-1.s: Likewise.
* testsuite/ld-i386/i386.exp: Run dt-relr-1a and dt-relr-1b.
* testsuite/ld-x86-64/x86-64.exp: Run dt-relr-1a, dt-relr-1a-x32
dt-relr-1b and dt-relr-1b-x32.

2 years agox86: Add DT_RELR support
H.J. Lu [Mon, 3 Jan 2022 05:14:46 +0000 (21:14 -0800)]
x86: Add DT_RELR support

DT_RELR is implemented with linker relaxation:

1. During linker relaxation, we scan input relocations with the same
logic in relocate_section to determine if a relative relocation should
be generated and save the relative relocation candidate information for
sizing the DT_RELR section later after all symbols addresses can be
determined.  For these relative relocations which can't be placed in
the DT_RELR section, they will be placed in the rela.dyn/rel.dyn
section.
2. When DT_RELR is enabled, _bfd_elf_map_sections_to_segments calls a
backend function to size the DT_RELR section which will compute the
DT_RELR section size and tell ldelf_map_segments to layout sections
again when the DT_RELR section size has been increased.
3. After regular symbol processing is finished, bfd_elf_final_link calls
a backend function to finish the DT_RELR section.

* elf32-i386.c (elf_i386_relocate_section): Don't generate
relative relocation when DT_RELR is enabled.
(elf_i386_finish_dynamic_symbol): Likewise.
* elf64-x86-64.c (elf_x86_64_relocate_section): Don't generate
relative relocation when DT_RELR is enabled.
(elf_x86_64_finish_dynamic_symbol): Likewise.
* elfxx-x86.c (_bfd_x86_elf_link_hash_table_create): Initialize
relative_r_type, relative_r_name, elf_append_reloc,
elf_write_addend and elf_write_addend_in_got.
(elf_x86_relative_reloc_record_add): New function.
(_bfd_x86_elf_link_relax_section): Likewise.
(elf64_dt_relr_bitmap_add): Likewise.
(elf32_dt_relr_bitmap_add): Likewise.
(_bfd_elf32_write_addend): Likewise.
(_bfd_elf64_write_addend): Likewise.
(elf_x86_size_or_finish_relative_reloc): Likewise.
(elf_x86_compute_dl_relr_bitmap): Likewise.
(elf_x86_write_dl_relr_bitmap): Likewise.
(elf_x86_relative_reloc_compare ): Likewise.
(_bfd_elf_x86_size_relative_relocs): Likewise.
(_bfd_elf_x86_finish_relative_relocs): Likewise.
(_bfd_x86_elf_size_dynamic_sections): Skip the .relr.dyn section.
(_bfd_x86_elf_finish_dynamic_sections): Convert 3 spare dynamic
tags to DT_RELR, DT_RELRSZ and for compact relative relocation.
* elfxx-x86.h (X86_64_GOT_TYPE_P): New.
(I386_GOT_TYPE_P): Likewise.
(X86_GOT_TYPE_P): Likewise.
(X86_64_RELATIVE_RELOC_TYPE_P): Likewise.
(I386_RELATIVE_RELOC_TYPE_P): Likewise.
(X86_RELATIVE_RELOC_TYPE_P): Likewise.
(X86_LOCAL_GOT_RELATIVE_RELOC_P): Likewise.
(I386_PCREL_TYPE_P): Likewise.
(X86_64_PCREL_TYPE_P): Likewise.
(X86_64_NEED_DYNAMIC_RELOC_TYPE_P): Rewrite.
(I386_NEED_DYNAMIC_RELOC_TYPE_P): Likewise.
(GENERATE_DYNAMIC_RELOCATION_P): Also check rel_from_abs.
(elf_x86_link_hash_entry): Add got_relative_reloc_done.
(elf_x86_relative_reloc_record): New.
(elf_x86_relative_reloc_data): Likewise.
(elf_dt_relr_bitmap): Likewise.
(elf_x86_link_hash_table): Add dt_relr_bitmap, relative_reloc,
unaligned_relative_reloc, relative_r_type, relative_r_name,
elf_append_reloc, elf_write_addend, elf_write_addend_in_got and
relative_reloc_done.
(elf_x86_relative_reloc_done): New.
(relative_reloc_packed): Likewise.
(_bfd_x86_elf_link_relax_section): Likewise.
(_bfd_elf_x86_size_relative_relocs): Likewise.
(_bfd_elf_x86_finish_relative_relocs): Likewise.
(_bfd_elf32_write_addend): Likewise.
(_bfd_elf64_write_addend): Likewise.
(bfd_elf32_bfd_relax_section): Likewise.
(bfd_elf64_bfd_relax_section): Likewise.
(elf_backend_size_relative_relocs): Likewise.
(elf_backend_finish_relative_relocs): Likewise.
(elf_x86_allocate_local_got_info): Also allocate
relative_reloc_done.

2 years agoelf: Support DT_RELR in linker tests
H.J. Lu [Wed, 5 Jan 2022 15:12:03 +0000 (07:12 -0800)]
elf: Support DT_RELR in linker tests

Allow eabling and disabling DT_RELR in linker tests.  Disable DT_RELR in
linker tests which don't expect DT_RELR in linker outputs.

binutils/

* testsuite/lib/binutils-common.exp (run_dump_test): Make
DT_RELR_LDFLAGS and NO_DT_RELR_LDFLAGS global.

ld/

* testsuite/config/default.exp (DT_RELR_LDFLAGS): New.
(DT_RELR_CC_LDFLAGS): Likewise.
(NO_DT_RELR_LDFLAGS): Likewise.
(NO_DT_RELR_CC_LDFLAGS): Likewise.
* testsuite/ld-elf/shared.exp: Pass $NO_DT_RELR_LDFLAGS to
linker for some tests.
* testsuite/ld-i386/export-class.exp: Likewise.
* testsuite/ld-i386/i386.exp: Likewise.
* testsuite/ld-i386/ibt-plt-2a.d: Pass $NO_DT_RELR_LDFLAGS to
linker.
* testsuite/ld-i386/ibt-plt-3a.d: Likewise.
* testsuite/ld-i386/ibt-plt-3c.d: Likewise.
* testsuite/ld-i386/pr26869.d: Likewise.
* testsuite/ld-i386/report-reloc-1.d: Likewise.
* testsuite/ld-ifunc/ifunc-2-i386-now.d: Likewise.
* testsuite/ld-ifunc/ifunc-2-local-i386-now.d: Likewise.
* testsuite/ld-ifunc/ifunc-2-local-x86-64-now.d: Likewise.
* testsuite/ld-ifunc/ifunc-2-x86-64-now.d: Likewise.
* testsuite/ld-ifunc/pr17154-x86-64.d: Likewise.
* testsuite/ld-x86-64/bnd-branch-1-now.d: Likewise.
* testsuite/ld-x86-64/bnd-ifunc-1-now.d: Likewise.
* testsuite/ld-x86-64/bnd-ifunc-2-now.d: Likewise.
* testsuite/ld-x86-64/bnd-ifunc-2.d: Likewise.
* testsuite/ld-x86-64/bnd-plt-1-now.d: Likewise.
* testsuite/ld-x86-64/bnd-plt-1.d: Likewise.
* testsuite/ld-x86-64/ibt-plt-2a-x32.d: Likewise.
* testsuite/ld-x86-64/ibt-plt-2a.d: Likewise.
* testsuite/ld-x86-64/ibt-plt-3a-x32.d: Likewise.
* testsuite/ld-x86-64/ibt-plt-3a.d: Likewise.
* testsuite/ld-x86-64/ilp32-4.d: Likewise.
* testsuite/ld-x86-64/load1c.d: Likewise.
* testsuite/ld-x86-64/load1d.d: Likewise.
* testsuite/ld-x86-64/pr13082-2b.d: Likewise.
* testsuite/ld-x86-64/pr14207.d: Likewise.
* testsuite/ld-x86-64/pr18176.d: Likewise.
* testsuite/ld-x86-64/pr19162.d: Likewise.
* testsuite/ld-x86-64/pr19636-2d.d: Likewise.
* testsuite/ld-x86-64/pr19636-2l.d: Likewise.
* testsuite/ld-x86-64/pr20253-1d.d: Likewise.
* testsuite/ld-x86-64/pr20253-1f.d: Likewise.
* testsuite/ld-x86-64/pr20253-1j.d: Likewise.
* testsuite/ld-x86-64/pr20253-1l.d: Likewise.
* testsuite/ld-x86-64/report-reloc-1-x32.d: Likewise.
* testsuite/ld-x86-64/report-reloc-1.d: Likewise.
* testsuite/ld-x86-64/export-class.exp (x86_64_export_class_test):
Pass $NO_DT_RELR_LDFLAGS to linker.
* testsuite/ld-x86-64/x86-64.exp: Pass $NO_DT_RELR_LDFLAGS to
linker for some tests.

2 years agoelf: Add size_relative_relocs and finish_relative_relocs
H.J. Lu [Thu, 6 Jan 2022 17:24:41 +0000 (09:24 -0800)]
elf: Add size_relative_relocs and finish_relative_relocs

On some targets, the DT_RELR section size can be computed only after all
symbols addresses can be determined.  Set the preliminary DT_RELR section
size before mapping sections to segments and set the final DT_RELR section
size after regular symbol processing is done.

* elf-bfd.h (elf_backend_data): Add size_relative_relocs and
finish_relative_relocs.
* elf.c (_bfd_elf_map_sections_to_segments): Call
size_relative_relocs if DT_RELR is enabled.
* elflink.c (bfd_elf_final_link): Call finish_relative_relocs
after regular symbol processing is finished if DT_RELR is enabled.
* elfxx-target.h (elf_backend_size_relative_relocs): New.
(elf_backend_finish_relative_relocs): Likewise.
(elfNN_bed): Add elf_backend_size_relative_relocs and
elf_backend_finish_relative_relocs.

2 years agold: Initial DT_RELR support
H.J. Lu [Mon, 3 Jan 2022 14:50:20 +0000 (06:50 -0800)]
ld: Initial DT_RELR support

Add a -z pack-relative-relocs option to enable DT_RELR and create a
relr.dyn section for DT_RELR.  DT_RELR is implemented with the linker
relaxation infrastructure, but it doesn't require the --relax option
enabled.  -z pack-relative-relocs implies -z combreloc.  -z nocombreloc
implies -z nopack-relative-relocs.

-z pack-relative-relocs is chosen over the similar option in lld,
--pack-dyn-relocs=relr, to implement a glibc binary lockout mechanism
with a special glibc version symbol, to avoid random crashes of DT_RELR
binaries with the existing glibc binaries.

bfd/

* elf-bfd.h (elf_link_hash_table): Add srelrdyn.
* elflink.c (_bfd_elf_link_create_dynamic_sections): Create a
.relr.dyn section for DT_RELR.

include/

* bfdlink.h (bfd_link_info): Add enable_dt_relr.

ld/

* News: Mention -z pack-relative-relocs and
-z nopack-relative-relocs.
* ld.texi: Document -z pack-relative-relocs and
-z nopack-relative-relocs.
* ldelf.c (ldelf_after_parse): Disable DT_RELR if not building
PIE nor shared library.  Add 3 spare dynamic tags for DT_RELR,
DT_RELRSZ and DT_RELRENT.
* ldlang.c (lang_relax_sections): Also enable relaxation if
DT_RELR is enabled.
* emulparams/elf32_x86_64.sh: Source dt-relr.sh.
* emulparams/elf_i386.sh: Likewise.
* emulparams/elf_x86_64.sh: Likewise.
* emulparams/dt-relr.sh: New file.
* scripttempl/elf.sc: Support .relr.dyn.

2 years agoelf: Pass need_layout to _bfd_elf_map_sections_to_segments
H.J. Lu [Thu, 6 Jan 2022 16:45:16 +0000 (08:45 -0800)]
elf: Pass need_layout to _bfd_elf_map_sections_to_segments

On some targets, the DT_RELR section size can be computed only after all
symbols addresses can be determined.  Update ldelf_map_segments to pass
need_layout to _bfd_elf_map_sections_to_segments which will size DT_RELR
section and set need_layout to true if the DT_RELR section size is changed.

bfd/

* elf-bfd.h (_bfd_elf_map_sections_to_segments): Add a bool
pointer argument.
* elf.c (_bfd_elf_map_sections_to_segments): Add a bool pointer
argument to indicate if section layout needs update.
(assign_file_positions_for_load_sections): Pass NULL to
_bfd_elf_map_sections_to_segments.
* elflink.c (_bfd_elf_strip_zero_sized_dynamic_sections): Pass
NULL to _bfd_elf_map_sections_to_segments.

ld/

* ldelfgen.c (ldelf_map_segments): Pass &need_layout to
_bfd_elf_map_sections_to_segments.

2 years agoelf: Add .relr.dyn to special_sections_r
H.J. Lu [Mon, 3 Jan 2022 13:51:05 +0000 (05:51 -0800)]
elf: Add .relr.dyn to special_sections_r

* elf.c (special_sections_r): Add .relr.dyn.

2 years agogdb: add 'maint set/show gnu-source-highlight enabled' command
Andrew Burgess [Fri, 26 Nov 2021 15:13:43 +0000 (15:13 +0000)]
gdb: add 'maint set/show gnu-source-highlight enabled' command

In a later commit I want to address an issue with the Python pygments
based code styling solution.  As this approach is only used when the
GNU Source Highlight library is not available, testing bugs in this
area can be annoying, as it requires GDB to be rebuilt with use of GNU
Source Highlight disabled.

This commit adds a pair of new maintenance commands:

  maintenance set gnu-source-highlight enabled on|off
  maintenance show gnu-source-highlight enabled

these commands can be used to disable use of the GNU Source Highlight
library, allowing me, in a later commit, to easily test bugs that
would otherwise be masked by GNU Source Highlight being used.

I made this a maintenance command, rather than a general purpose
command, as it didn't seem like this was something a general user
would need to adjust.  We can always convert the maintenance command
to a general command later if needed.

There's no test for this here, but this feature will be used in a
later commit.

2 years agogdb: erase items from the source_cache::m_offset_cache
Andrew Burgess [Fri, 26 Nov 2021 14:34:27 +0000 (14:34 +0000)]
gdb: erase items from the source_cache::m_offset_cache

The source_cache class has two member variables m_source_map, which
stores the file contents, and m_offset_cache, which stores offsets
into the file contents.

As source files are read the contents of the file, as well as the
offset data, are stored in the cache using these two member variables.

Whenever GDB needs either the files contents, or the offset data,
source_cache::ensure is called.  This function looks for the file in
m_source_map, and if it's found then this implies the file is also in
m_offset_cache, and we're done.

If the file is not in m_source_map then GDB calls
source_cache::get_plain_source_lines to open the file and read its
contents.  ::get_plain_source_lines also calculates the offset data,
which is then inserted into m_offset_cache.

Back in ::ensure, the file contents are added into m_source_map.  And
finally, if m_source_map contains more than MAX_ENTRIES, an entry is
removed from m_source_map.

The problem is entries are not removed from m_offset_cache at the same
time.

This means that if a program contains enough source files, GDB will
hold at most MAX_ENTRIES cached source file contents, but can contain
offsets data for every source file.

Now, the offsets data is going to be smaller than the cached file
contents, so maybe there's no harm here.  But, when we reload the file
contents we always recalculate the offsets data.  And, when we
::get_line_charpos asking for offset data we still call ::ensure which
will ends up loading and caching the file contents.

So, given the current code does the work of reloading the offset data
anyway, we may as well save memory by capping m_offset_cache to
MAX_ENTRIES just like we do m_source_map.

That's what this commit does.

There should be no user visible changes after this commit, except for
ever so slightly lower memory usage in some cases.

2 years agogdb: new 'maint flush source-cache' command
Andrew Burgess [Fri, 26 Nov 2021 13:51:36 +0000 (13:51 +0000)]
gdb: new 'maint flush source-cache' command

This commit adds a new 'maint flush source-cache' command, this
flushes the cache of source file contents.

After flushing GDB is forced to reread source files the next time any
source lines are to be displayed.

I've added a test for this new feature.  The test is a little weird,
in that it modifies a source file after compilation, and makes use of
the cache flush so that the changes show up when listing the source
file.  I'm not sure when such a situation would ever crop up in real
life, but maybe we can imagine such cases.

In reality, this command is useful for testing the syntax highlighting
within GDB, we can adjust the syntax highlighting settings, flush the
cache, and then get the file contents re-highlighted using the new
settings.

2 years agogdb: rename lin-lwp to linux-nat in set/show debug
Andrew Burgess [Wed, 22 Dec 2021 15:33:38 +0000 (15:33 +0000)]
gdb: rename lin-lwp to linux-nat in set/show debug

Rename 'set debug lin-lwp' to 'set debug linux-nat' and 'show debug
lin-lwp' to 'show debug linux-nat'.

I've updated the documentation and help text to match, as well as
making it clear that the debug that is coming out relates to all
aspects of Linux native inferior support, not just the LWP aspect of
it.

The boundary between general "native" target debug, and the lwp
specific part of that debug was always a little blurry, but the actual
debug variable inside GDB is debug_linux_nat, and the print routine
linux_nat_debug_printf, is used throughout the linux-nat.c file, not
just for lwp related debug, so the new name seems to make more sense.

2 years agold: add hidden and internal visibility support for XCOFF
Clément Chigot [Tue, 23 Nov 2021 14:45:28 +0000 (15:45 +0100)]
ld: add hidden and internal visibility support for XCOFF

This patch adds a primary support for hidden and internal visibility in
GNU linker for XCOFF format.
The protected visibility isn't yet supported.

PR 22085

bfd/ChangeLog:

* xcofflink.c (xcoff_dynamic_definition_p): Add hidden
  and internal visibility support.
(xcoff_link_add_symbols): Likewise.
(xcoff_auto_export_p): Likewise.
(bfd_xcoff_export_symbol): Likewise.
(xcoff_link_input_bfd): Likewise.

ld/ChangeLog:

* testsuite/ld-vsb/main.c: Adapt for XCOFF.
* testsuite/ld-vsb/sh1.c: Likewse.
* testsuite/ld-vsb/vsb.exp: Likewise.
* testsuite/ld-vsb/visibility-1-xcoff-32.d: New test.
* testsuite/ld-vsb/visibility-1-xcoff-64.d: New test.
* testsuite/ld-vsb/visibility-2-xcoff-32.d: New test.
* testsuite/ld-vsb/visibility-2-xcoff-64.d: New test.
* testsuite/ld-vsb/xcoffvsb.dat: New test.

2 years agold/testsuite: prepare ld-elfvsb to support XCOFF
Clément Chigot [Tue, 23 Nov 2021 14:41:35 +0000 (15:41 +0100)]
ld/testsuite: prepare ld-elfvsb to support XCOFF

A following patch will add visibility support in ld for XCOFF. Thus,
ld-elfvsb is renamed ld-vsb and a suffix is added to files targeting only
ELF format.

ld/ChangeLog:

* testsuite/ld-elfvsb: rename as ld-vsb.
* testsuite/ld-elfvsb/hidden0.d: move to ld-vsb and rename with
  suffix -elf.d.
* testsuite/ld-elfvsb/hidden1.d: Likewise.
* testsuite/ld-elfvsb/hidden2.d: Likewise.
* testsuite/ld-elfvsb/internal0.d: Likewise.
* testsuite/ld-elfvsb/internal1.d: Likewise.
* testsuite/ld-elfvsb/protected0.d: Likewise.
* testsuite/ld-elfvsb/protected1.d: Likewise.

2 years agogas: add visibility support using GNU syntax on XCOFF
Clément Chigot [Wed, 17 Nov 2021 15:20:48 +0000 (16:20 +0100)]
gas: add visibility support using GNU syntax on XCOFF

In order to ease port of GNU assembly code and especially ld testsuite,
this patch allows XCOFF to accept the usual GNU syntax for visibility.

PR 22085

gas/ChangeLog:

* config/tc-ppc.c (ppc_GNU_visibility): New function.
* testsuite/gas/ppc/aix.exp: Add new tests.
* testsuite/gas/ppc/xcoff-visibility-2-32.d: New test.
* testsuite/gas/ppc/xcoff-visibility-2-64.d: New test.
* testsuite/gas/ppc/xcoff-visibility-2.s: New test.

2 years agogas: add visibility support for XCOFF
Clément Chigot [Tue, 16 Nov 2021 13:02:16 +0000 (14:02 +0100)]
gas: add visibility support for XCOFF

XCOFF assembly defines the visibility using an additional argument
on several pseudo-ops: .globl, .weak, .extern and .comm.
This implies that .globl and .weak syntax is different than the
usual GNU syntax. But we want to provide compatibility with AIX
assembler, especially because GCC is generating the visibility
using this XCOFF syntax.

PR 22085

bfd/ChangeLog:

        * coffcode.h (coff_write_object_contents): Change XCOFF header
        vstamp field to 2.
        * coffgen.c (coff_print_symbol): Increase the size for n_type.

gas/ChangeLog:

        * config/tc-ppc.c (ppc_xcoff_get_visibility): New function.
        (ppc_globl): New function.
        (ppc_weak): New function.
        (ppc_comm): Add visibility field support.
        (ppc_extern): Likewise.
        * testsuite/gas/all/cofftag.d: Adjust to new n_type size
        providing by objdump.
        * testsuite/gas/ppc/test1xcoff32.d: Likewise.
        * testsuite/gas/ppc/aix.exp: Add new tests.
        * testsuite/gas/ppc/xcoff-visibility-1-32.d: New test.
        * testsuite/gas/ppc/xcoff-visibility-1-64.d: New test.
        * testsuite/gas/ppc/xcoff-visibility-1.s: New test.

include/ChangeLog:

        * coff/internal.h (SYM_V_INTERNAL, SYM_V_HIDDEN,
        SYM_V_PROTECTED, SYM_V_EXPORTED, SYM_V_MASK): New defines.
        * coff/xcoff.h (struct xcoff_link_hash_entry): Add visibility
        field.

ld/ChangeLog:

        * testsuite/ld-pe/pr19803.d: Adjust to new n_type size
        providing by objdump.

2 years agoobjdump, readelf: Emit "CU:" format only when wide output is requested
Hans-Peter Nilsson [Wed, 12 Jan 2022 04:41:09 +0000 (05:41 +0100)]
objdump, readelf: Emit "CU:" format only when wide output is requested

As pre-approved by Alan in
https://sourceware.org/pipermail/binutils/2021-September/118019.html
and I believe people have run into getting testsuite failures for
test-environments with "long" directory names, at least once more
since that time.  Enough.  I grepped the gas, binutils and ld
testsuites for "CU:" to catch target-specific occurrences, but I
noticed none.  I chose to remove "CU:" on the objdump tests instead of
changing options to get the wide format, so as to keep the name of the
test consistent with actual options; but added it to the readelf
options for the gas test as I believe the "CU:" format is preferable.

Tested for cris-elf and native x86_64-pc-linux-gnu.

binutils:
* dwarf.c (display_debug_lines_decoded): Don't check the
string length of the directory, instead emit the "CU: dir/name"
format only if wide output is requested.
* testsuite/binutils-all/dw5.W, testsuite/binutils-all/objdump.WL:
Adjust accordingly.

gas:
* testsuite/gas/elf/dwarf-5-loc0.d: Add -W to readelf options.

2 years agoSet SEC_ELF_REVERSE_COPY earlier
Alan Modra [Wed, 12 Jan 2022 02:07:27 +0000 (12:37 +1030)]
Set SEC_ELF_REVERSE_COPY earlier

For the sake of DT_RELR.

bfd/
* elflink.c (elf_link_input_bfd): Don't set SEC_ELF_REVERSE_COPY
here.  Move sanity checks to reverse copying code.
ld/
* ldlang.c (lang_add_section): Set SEC_ELF_REVERSE_COPY for
.ctors/.dtors in .init_array/.fini_array.

2 years agogdb: testsuite: fix wrong comment in gdb.base/charset.c
Tiezhu Yang [Wed, 12 Jan 2022 00:33:49 +0000 (08:33 +0800)]
gdb: testsuite: fix wrong comment in gdb.base/charset.c

In gdb/testsuite/gdb.base/charset.c, use "IBM1047" instead of "EBCDIC"
to fix the wrong comment.

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
2 years agogdb: testsuite: fix failed testcases in gdb.base/charset.exp
Tiezhu Yang [Wed, 12 Jan 2022 00:31:02 +0000 (08:31 +0800)]
gdb: testsuite: fix failed testcases in gdb.base/charset.exp

In gdb/testsuite/gdb.base/charset.c, the last argument is greater than 127
when call fill_run() in EBCDIC-US and IBM1047, but the type of string[] is
char, this will change the value due to sign extension.

For example, ebcdic_us_string[7] will be -63 instead of the original 193 in
EBCDIC-US.

Make the type of string[] as unsigned char to fix the following six failed
testcases:

  $ grep FAIL gdb/testsuite/gdb.sum
  FAIL: gdb.base/charset.exp: check value of parsed character literal in EBCDIC-US
  FAIL: gdb.base/charset.exp: check value of parsed string literal in EBCDIC-US
  FAIL: gdb.base/charset.exp: check value of escape that doesn't exist in EBCDIC-US
  FAIL: gdb.base/charset.exp: check value of parsed character literal in IBM1047
  FAIL: gdb.base/charset.exp: check value of parsed string literal in IBM1047
  FAIL: gdb.base/charset.exp: check value of escape that doesn't exist in IBM1047

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

2 years agoar: Add --thin for creating thin archives
Fangrui Song [Tue, 11 Jan 2022 16:59:40 +0000 (08:59 -0800)]
ar: Add --thin for creating thin archives

In many ar implementations (FreeBSD, elfutils, etc), -T has the X/Open
System Interface specified semantics. Therefore -T for thin archives is
not recommended for portability. -T is deprecated without diagnostics.

    PR binutils/28759
    * ar.c (long_options): Add --thin.
    (usage) Add --thin. Deprecate -T without diagnostics.
    * doc/binutils.texi: Add doc.
    * NEWS: Mention --thin.
    * binutils/testsuite/binutils-all/ar.exp: Add tests.

2 years agoFix multiple problems with DLL generation.
Martin Storsj [Tue, 11 Jan 2022 15:43:59 +0000 (15:43 +0000)]
Fix multiple problems with DLL generation.

ld * pe-dll.c (make_head): Prefix the symbol name with the dll name.
(make_tail, make_one, make_singleton_name_thunk): Likewise.
(make_import_fixup_entry, make_runtime_pseudo_reloc): Likewise.
(pe_create_runtime_relocator_reference): Likewise.
(pe_dll_generate_implib): Set dll_symname_len.
(pe_process_import_defs): Likewise.

binutils
* dlltool.c (main): If a prefix has not been provided, attempt to
use a deterministic one based upon the dll name.

2 years agogas/doc: mention quoted symbol names
Jan Beulich [Tue, 11 Jan 2022 14:43:34 +0000 (15:43 +0100)]
gas/doc: mention quoted symbol names

2 years agogdbsupport: regenerate Makefile.in
Andrew Burgess [Mon, 10 Jan 2022 17:42:06 +0000 (17:42 +0000)]
gdbsupport: regenerate Makefile.in

I had cause to regenerate gdbsupport/Makefile.in, and noticed some
unexpected changes in the copyright header dates.

I suspect that this was caused by the end of year date range update
process.

The Makefile.in contains two date ranges.  The first range appears to
be the date range for the version of automake being used, that is the
range runs up to 2017 only, when automake 1.15.1 was released.

The second date range in Makefile.in represents the date range for the
generated file, and so, now runs up to 2022.

Anyway, this is the result of running autoreconf (using automake
1.15.1) in the gdbsupport directory.

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

2 years agoXCOFF: add support for TLS relocations on hidden symbols
Clément Chigot [Fri, 17 Dec 2021 13:46:01 +0000 (14:46 +0100)]
XCOFF: add support for TLS relocations on hidden symbols

This patch adds support for TLS relocation targeting C_HIDEXT symbols.
In gas, TLS relocations, except R_TLSM and R_TLMSL, must keep the value
of their target symbol.
In ld, it simply ensures that internal TLS symbols are added to the
linker hash table for xcoff_reloc_type_tls.

It also improves the tests made by both.

bfd/ChangeLog:

* coff-rs6000.c (xcoff_howto_table): Fix name of R_TLSML.
(xcoff_reloc_type_tls): Replace the error when h is NULL by
an assert.
(xcoff_complain_overflow_unsigned_func): Adjust comments.
* coff64-rs6000.c (xcoff64_howto_table): Fix name of R_TLSML.
* xcofflink.c (xcoff_link_add_symbols_to_hash_table): New
function.
(xcoff_link_add_symbols): Add C_HIDEXT TLS symbols to the linker
hash table.

gas/ChangeLog:

* config/tc-ppc.c (md_apply_fix): Enable support for TLS
relocation over internal symbols.
* testsuite/gas/ppc/aix.exp: Replace xcoff-tlms by xcoff-tls.
* testsuite/gas/ppc/xcoff-tlsm-32.d: Removed.
* testsuite/gas/ppc/xcoff-tlsm-64.d: Removed.
* testsuite/gas/ppc/xcoff-tlsm.s: Removed.
* testsuite/gas/ppc/xcoff-tls-32.d: New test.
* testsuite/gas/ppc/xcoff-tls-64.d: New test.
* testsuite/gas/ppc/xcoff-tls.s: New test.

ld/ChangeLog:

* testsuite/ld-powerpc/aix52.exp: Improve aix-tls-reloc test.
* testsuite/ld-powerpc/aix-tls-reloc.s: Likewise.
* testsuite/ld-powerpc/aix-tls-reloc-32.d: Removed.
* testsuite/ld-powerpc/aix-tls-reloc-64.d: Removed.
* testsuite/ld-powerpc/aix-tls-reloc-32.dd: New test.
* testsuite/ld-powerpc/aix-tls-reloc-32.dt: New test.
* testsuite/ld-powerpc/aix-tls-reloc-64.dd: New test.
* testsuite/ld-powerpc/aix-tls-reloc-64.dt: New test.

2 years agogdb: add Tiezhu Yang to MAINTAINERS
Tiezhu Yang [Mon, 10 Jan 2022 06:36:36 +0000 (14:36 +0800)]
gdb: add Tiezhu Yang to MAINTAINERS

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
2 years agoReduce use of unfiltered output in Darwin code
Tom Tromey [Mon, 27 Dec 2021 04:38:34 +0000 (21:38 -0700)]
Reduce use of unfiltered output in Darwin code

The Darwin code uses unfiltered output liberally.  This patch changes
this code to send some output to gdb_stdlog (in some cases via the use
of debug_prefixed_printf_cond_nofunc), or to gdb_stderr, or to simply
switch to filtered output.

Note that I didn't switch inferior_debug to use
debug_prefixed_printf_cond_nofunc, because that would affect the
output by removing the information about the inferior.  I wasn't sure
if this was important or not, so I left it in.

v2 of this patch uses warning rather than prints to gdb_stderr, and
removes some trailing whitespace.

I can't compile this patch, so it's "best effort".

2 years agoAutomatic date update in version.in
GDB Administrator [Mon, 10 Jan 2022 00:00:06 +0000 (00:00 +0000)]
Automatic date update in version.in

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

2 years agogdb/hurd: handle inferiors exiting
Andrew Burgess [Thu, 6 Jan 2022 15:32:55 +0000 (15:32 +0000)]
gdb/hurd: handle inferiors exiting

While testing on GNU/Hurd (i386) I noticed that GDB crashes when an
inferior exits, with this error:

  inferior.c:293: internal-error: inferior* find_inferior_pid(process_stratum_target*, int): Assertion `pid != 0' failed.

The problem appears to be in gnu_nat_target::wait.

We always set inferior_ptid to null_ptid before calling target_wait,
this has been the case since the multi-target changes were made to GDB
in commit:

  commit 5b6d1e4fa4fc6827c7b3f0e99ff120dfa14d65d2
  Date:   Fri Jan 10 20:06:08 2020 +0000

      Multi-target support

With follow up changes in commit:

  commit 24ed6739b699f329c2c45aedee5f8c7d2f54e493
  Date:   Thu Jan 30 14:35:40 2020 +0000

      gdb/remote: Restore support for 'S' stop reply packet

Unfortunately, the GNU/Hurd target is still relying on the value of
inferior_ptid in the case where an inferior exits - we return the
value of inferior_ptid as the pid of the process that exited.  This
was fine in the single target world, where inferior_ptid identified
the one running inferior, but this is no longer good enough.

Instead, we should return a ptid containing the pid of the process
that exited, as obtained from the wait event, and this is what this
commit does.

I've not run the full testsuite on GNU/Hurd as there appear to be lots
of other issues with this target that makes running the full testsuite
very painful, but I think this looks like a small easy improvement.

2 years agoAdd explicit check for nullptr to target_announce_attach
Tom Tromey [Sat, 8 Jan 2022 16:45:27 +0000 (09:45 -0700)]
Add explicit check for nullptr to target_announce_attach

Lancelot pointed out that target_announce_attach was missing an
explicit check against nullptr.  This patch adds it.

2 years agoAdd _sigsys info to siginfo struct
Hannes Domani [Tue, 7 Apr 2020 18:57:07 +0000 (20:57 +0200)]
Add _sigsys info to siginfo struct

This patch adds information about _sigsys structure from newer
kernels, so that $_siginfo decoding can show information about
_sigsys, making it easier for developers to debug seccomp failures.
Requested in PR gdb/24283.

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

2 years agogdb: testsuite: show print array-indexes after set in arrayidx.exp
Tiezhu Yang [Sat, 8 Jan 2022 10:43:00 +0000 (14:43 +0400)]
gdb: testsuite: show print array-indexes after set in arrayidx.exp

Add "show print array-indexes" testcases after set print array-indexes
to off or on.

Without this patch:

    PASS: gdb.base/arrayidx.exp: set print array-indexes to off
    PASS: gdb.base/arrayidx.exp: print array with array-indexes off
    PASS: gdb.base/arrayidx.exp: set print array-indexes to on
    PASS: gdb.base/arrayidx.exp: print array with array-indexes on

With this patch:

    PASS: gdb.base/arrayidx.exp: set print array-indexes to off
    PASS: gdb.base/arrayidx.exp: show print array-indexes is off
    PASS: gdb.base/arrayidx.exp: print array with array-indexes off
    PASS: gdb.base/arrayidx.exp: set print array-indexes to on
    PASS: gdb.base/arrayidx.exp: show print array-indexes is on
    PASS: gdb.base/arrayidx.exp: print array with array-indexes on

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
2 years agold: Extract _bfd_elf_link_iterate_on_relocs
H.J. Lu [Mon, 27 Dec 2021 18:13:06 +0000 (10:13 -0800)]
ld: Extract _bfd_elf_link_iterate_on_relocs

DT_RELR encodes consecutive R_*_RELATIVE relocations in GOT (the global
offset table) and data sections in a compact format:

https://groups.google.com/g/generic-abi/c/bX460iggiKg

On some targets, R_*_RELATIVE relocations are counted and the GOT offsets
are allocated when setting the dynamic section sizes after seeing all
relocations.  R_*_RELATIVE relocations are generated while relocating
sections after section layout has been finalized.

To prepare for DT_RELR implementation on these targets, extract
_bfd_elf_link_iterate_on_relocs from _bfd_elf_link_check_relocs so
that a backend can scan relocations in elf_backend_always_size_sections

For x86 targets, the old check_relocs is renamed to scan_relocs and a
new check_relocs is added to chek input sections and create dynamic
relocation sections so that they will be mapped to output sections.
scan_relocs is now called from elf_backend_always_size_sections.

Since relocations are scanned after __start, __stop, .startof. and
.sizeof. symbols have been finalized on x86, __[start|stop]_SECNAME for
--gc-sections -z start-stop-gc are now zero when all SECNAME sections
been garbage collected.  This is no need for elf_x86_start_stop_gc_p.

bfd/

* elf-bfd.h (_bfd_elf_link_iterate_on_relocs): New.
* elf32-i386.c (elf_i386_convert_load_reloc): Don't call
elf_x86_start_stop_gc_p.
(elf_i386_check_relocs): Renamed to ...
(elf_i386_scan_relocs): This.  Don't call
_bfd_elf_make_dynamic_reloc_section.
(elf_i386_always_size_sections): New.
(elf_backend_check_relocs): Removed.
(elf_backend_always_size_sections): New.
* elf64-x86-64.c (elf_x86_64_convert_load_reloc): Don't call
elf_x86_start_stop_gc_p.
(elf_x86_64_check_relocs): Renamed to ...
(elf_x86_64_scan_relocs): This.  Don't call
_bfd_elf_make_dynamic_reloc_section.
(elf_x86_64_always_size_sections): New.
(elf_backend_check_relocs): Removed.
(elf_backend_always_size_sections): New.
* elflink.c (elf_link_check_or_scan_relocs):
New.  Extracted from _bfd_elf_link_check_relocs.
(_bfd_elf_link_check_relocs): Call elf_link_check_or_scan_relocs.
* elfxx-x86.c (_bfd_x86_elf_check_relocs): New.
* elfxx-x86.h (X86_64_NEED_DYNAMIC_RELOC_TYPE_P): New.
(I386_NEED_DYNAMIC_RELOC_TYPE_P): Likewise.
(X86_NEED_DYNAMIC_RELOC_TYPE_P): Likewise.
(_bfd_x86_elf_check_relocs): Likewise.
(elf_backend_check_relocs): Likewise.
(elf_backend_always_size_sections): Removed.
(elf_x86_start_stop_gc_p): Likewise.

ld/

* testsuite/ld-i386/pr27491-1a.d: Updated.
* testsuite/ld-x86-64/pr27491-1a.d: Likewise.

2 years agoAutomatic date update in version.in
GDB Administrator [Sat, 8 Jan 2022 00:00:09 +0000 (00:00 +0000)]
Automatic date update in version.in

2 years agogdb/testsuite: Remove duplicates from gdb.mi/mi-catch-load.exp
Lancelot SIX [Mon, 22 Nov 2021 22:36:47 +0000 (22:36 +0000)]
gdb/testsuite: Remove duplicates from gdb.mi/mi-catch-load.exp

When I run the testsuite, I have:

    Running .../gdb/testsuite/gdb.mi/mi-catch-load.exp ...
    DUPLICATE: gdb.mi/mi-catch-load.exp: breakpoint at main
    DUPLICATE: gdb.mi/mi-catch-load.exp: mi runto main

Fix by grouping the various phases in with_test_prefix blocks.  Since
the tests now have a prefix, remove the manually written prefixes in
testnames.

Also change some messages with the pattern "(timeout) $testname" into
"$estname (timeout)" since tools will handle this as $testname[1] (which
is what we want in this particular scenario).

Tested on x86_64-linux.

[1] https://sourceware.org/gdb/wiki/GDBTestcaseCookbook#Do_not_use_.22tail_parentheses.22_on_test_messages

2 years agogdb/testsuite: Remove duplicates from gdb.threads/staticthreads.ex
Lancelot SIX [Tue, 23 Nov 2021 16:40:24 +0000 (16:40 +0000)]
gdb/testsuite: Remove duplicates from gdb.threads/staticthreads.ex

When running the testsuite, I have:

    Running .../gdb/testsuite/gdb.threads/staticthreads.exp ...
    DUPLICATE: gdb.threads/staticthreads.exp: couldn't compile staticthreads.c: unrecognized error

Fix by using foreach_with_prefix instead of foreach when preparing the
test case.

Testeed on x86_64-linux both in a setup where the test fails to prepare
and in a setup where the test fails to setup.

2 years agogdb/testsuite: Remove duplicates from gdb.mi/mi-language.exp
Lancelot SIX [Tue, 23 Nov 2021 15:15:57 +0000 (15:15 +0000)]
gdb/testsuite: Remove duplicates from gdb.mi/mi-language.exp

When running the testsuite, I have:

    Running .../gdb/testsuite/gdb.mi/mi-language.exp ...
    DUPLICATE: gdb.mi/mi-language.exp: set lang ada

This is due to an erroneous explicit test name.  This explicit test name
also happens to be useless (at least it would have been if it was
correct) since it only repeats the command, so just remove the explicit
test name and let the command be used as default test name.  Also remove
explicit test name at another location in the file since it also just
repeat the command.

Tested on x86_64-linux.

2 years agogdb/testsuite: Remove duplicates from gdb.mi/mi-nonstop-exit.exp
Lancelot SIX [Tue, 23 Nov 2021 13:42:13 +0000 (13:42 +0000)]
gdb/testsuite: Remove duplicates from gdb.mi/mi-nonstop-exit.exp

When running the testsuite, I have:

    Running .../gdb/testsuite/gdb.mi/mi-nonstop-exit.exp ...
    DUPLICATE: gdb.mi/mi-nonstop-exit.exp: breakpoint at main
    DUPLICATE: gdb.mi/mi-nonstop-exit.exp: mi runto main

This test runs the same sequence of operations twice.  Refactor the code
by running both of those sequences within a foreach_with_prefix block to
ensure that the commands have unique test names.

Tested on x86_64-linux.

2 years agogdb/testsuite: Remove duplicates from gdb.mi/mi-nonstop.exp
Lancelot SIX [Tue, 23 Nov 2021 13:35:47 +0000 (13:35 +0000)]
gdb/testsuite: Remove duplicates from gdb.mi/mi-nonstop.exp

When running the testsuite, I have:

    Running .../gdb/testsuite/gdb.mi/mi-nonstop.exp ...
    DUPLICATE: gdb.mi/mi-nonstop.exp: check varobj, w1, 1
    DUPLICATE: gdb.mi/mi-nonstop.exp: stacktrace of stopped thread

Fix by adjusting the problematic test names.

Tested on x86_64-linux.

2 years agogdb/testsuite: Remove duplicates from gdb.mi/mi-nsthrexec.exp
Lancelot SIX [Mon, 22 Nov 2021 22:03:47 +0000 (22:03 +0000)]
gdb/testsuite: Remove duplicates from gdb.mi/mi-nsthrexec.exp

When running the testsuite, I have:

    Running .../gdb/testsuite/gdb.mi/mi-nsthrexec.exp ...
    DUPLICATE: gdb.mi/mi-nsthrexec.exp: breakpoint at main

Fix by adjusting the duplicated test name.

Tested on x86_64-linux.

2 years agogdb/testsuite: Remove duplicates from gdb.base/watchpoints.exp
Lancelot SIX [Sun, 21 Nov 2021 17:21:40 +0000 (17:21 +0000)]
gdb/testsuite: Remove duplicates from gdb.base/watchpoints.exp

When running the testsuite, I have:

    Running ../gdb/testsuite/gdb.base/watchpoints.exp ...
    DUPLICATE: gdb.base/watchpoints.exp: watchpoint hit, first time

Fix by adjusting the test names where appropriate.

Tested on x86_64-linux.

2 years agogdb/testsuite: Remove duplicates from gdb.base/nested-subp2.exp
Lancelot SIX [Sun, 21 Nov 2021 15:34:09 +0000 (15:34 +0000)]
gdb/testsuite: Remove duplicates from gdb.base/nested-subp2.exp

When running the testsuite, I have:

    Running .../gdb/testsuite/gdb.base/nested-subp2.exp ...
    DUPLICATE: gdb.base/nested-subp2.exp: continue to the STOP marker
    DUPLICATE: gdb.base/nested-subp2.exp: print c
    DUPLICATE: gdb.base/nested-subp2.exp: print count

Fix by using with_test_prefix to differentiate the test that are
performed at different points during the execution of the debuggee.

Tested on x86_64-linux.

2 years agogdb/testsuite: Remove duplicates from gdb.base/call-signal-resume.exp
Lancelot SIX [Sun, 21 Nov 2021 15:22:49 +0000 (15:22 +0000)]
gdb/testsuite: Remove duplicates from gdb.base/call-signal-resume.exp

When running the testsuite, I have:

    Running .../gdb/testsuite/gdb.base/call-signal-resume.exp ...
    DUPLICATE: gdb.base/call-signal-resume.exp: dummy stack frame number
    DUPLICATE: gdb.base/call-signal-resume.exp: set confirm off
    DUPLICATE: gdb.base/call-signal-resume.exp: return

This is due to the fact that a pattern was probably copy/pasted to
re-use the logic while not adjusting the test names to avoid the
duplication.

Fix by removing the redundant tests ('set confirm off' only needs to be
used once) and adjusting the test names where appropriate.

Tested on x86_64-linux.

2 years agogdb/testsuite: Remove duplicates from gdb.base/pointers.exp
Lancelot SIX [Sun, 21 Nov 2021 01:55:43 +0000 (01:55 +0000)]
gdb/testsuite: Remove duplicates from gdb.base/pointers.exp

When I run the testsuite, I have :

    Running .../gdb/testsuite/gdb.base/pointers.exp ...
    DUPLICATE: gdb.base/pointers.exp: pointer assignment

Fix by placing the sections with duplication in with_test_prefix blocks.
This removes the duplication and gives a better organization the file.

Tested on x86_64-linux.
Co-Authored-By: Pedro Alves <pedro@palves.net>
2 years agogdb/testsuite: Remove duplicates from gdb.base/unload.exp
Lancelot SIX [Sun, 21 Nov 2021 01:50:26 +0000 (01:50 +0000)]
gdb/testsuite: Remove duplicates from gdb.base/unload.exp

When running the testsuite, I have:

    Running .../gdb/testsuite/gdb.base/unload.exp ...
    DUPLICATE: gdb.base/unload.exp: continuing to unloaded libfile

Fix by adjusting the test name.

Tested on x86_64-linux.

2 years agogdb/testsuite: Remove duplicates from gdb.base/define-prefix.exp
Lancelot SIX [Sun, 21 Nov 2021 01:45:21 +0000 (01:45 +0000)]
gdb/testsuite: Remove duplicates from gdb.base/define-prefix.exp

When running the testsuite, I have:

    Running .../gdb/testsuite/gdb.base/define-prefix.exp ...
    DUPLICATE: gdb.base/define-prefix.exp: define user command: ghi-prefix-cmd

Fix by adjusting test names.

Tested on x86_64-linux.

2 years agogdb/testsuite: Remove duplicates from gdb.base/funcargs.exp
Lancelot SIX [Sun, 21 Nov 2021 01:38:43 +0000 (01:38 +0000)]
gdb/testsuite: Remove duplicates from gdb.base/funcargs.exp

When running the testsuite, I have:

    Running .../gdb/testsuite/gdb.base/funcargs.exp ...
    DUPLICATE: gdb.base/funcargs.exp: run to call2a

Fix by using proc_with_prefix instead on plain proc to create logical
function blocks.

Tested on x86_64-linux.

2 years agogdb/testsuite: Remove duplicates from gdb.base/shlib-call.exp
Lancelot SIX [Sun, 21 Nov 2021 01:33:13 +0000 (01:33 +0000)]
gdb/testsuite: Remove duplicates from gdb.base/shlib-call.exp

When I run the testsuite, I have:

    Running .../gdb/testsuite/gdb.base/shlib-call.exp ...
    DUPLICATE: gdb.base/shlib-call.exp: print g
    DUPLICATE: gdb.base/shlib-call.exp: set print sevenbit-strings
    DUPLICATE: gdb.base/shlib-call.exp: set print address off
    DUPLICATE: gdb.base/shlib-call.exp: set width 0
    DUPLICATE: gdb.base/shlib-call.exp: continue until exit

Fix by adjusting the test names when required, and by removing
un-necessary commands.

While at it, do some cleanup:
- Replace an explicit GDB restart sequence with a call to clean_restart.
- Remove trailing whitespaces.
- Use $gdb_test_name in gdb_test_multiple.

Tested on x86_64-linux.

2 years agogdb/testsuite: Remove duplicates from gdb.base/set-cfd.exp
Lancelot SIX [Sun, 21 Nov 2021 00:55:01 +0000 (00:55 +0000)]
gdb/testsuite: Remove duplicates from gdb.base/set-cfd.exp

When running the testsuite, I have:

    Running .../gdb/testsuite/gdb.base/set-cwd.exp ...
    DUPLICATE: gdb.base/set-cwd.exp: test_cwd_reset: continue to breakpoint: break-here

Fix by moving the tests after the 'runto_main' within the same
with_test_prefix scope.

While at it, I fix some indentation issues.

Tested on x86_64-linux.

2 years agogdb/testsuite: Remove duplicates from gdb.base/exprs.exp
Lancelot SIX [Sun, 21 Nov 2021 00:44:36 +0000 (00:44 +0000)]
gdb/testsuite: Remove duplicates from gdb.base/exprs.exp

When running the testsuite, I have:

    Running .../gdb/testsuite/gdb.base/exprs.exp ...
    DUPLICATE: gdb.base/exprs.exp: \$[0-9]* = red (setup)

Fix by using with_test_prefix where appropriate.

Tested on x86_64-linux.

2 years agogdb/testsuite: Remove duplicates from gdb.base/readline.exp
Lancelot SIX [Sun, 21 Nov 2021 00:35:01 +0000 (00:35 +0000)]
gdb/testsuite: Remove duplicates from gdb.base/readline.exp

When running the testsuite, I have:

    Running .../gdb/testsuite/gdb.base/readline.exp ...
    DUPLICATE: gdb.base/readline.exp: Simple operate-and-get-next - final prompt

Fix by adjusting the prefix given to the second 'simple' call to
operate_and_get_next.

Tested on x86_64-linux.

2 years agogdb/testsuite: Remove duplicates from gdb.base/pretty-array.exp
Lancelot SIX [Sun, 21 Nov 2021 00:29:01 +0000 (00:29 +0000)]
gdb/testsuite: Remove duplicates from gdb.base/pretty-array.exp

When I run the testsuite, I have:

    Running .../gdb/testsuite/gdb.base/pretty-array.exp ...
    DUPLICATE: gdb.base/pretty-array.exp: print nums
    DUPLICATE: gdb.base/pretty-array.exp: print nums

Fix by giving a name to the test cases.

Tested on x86_64-linux.

2 years agogdb/testsuite: Remove duplicates from gdb.base/ui-redirect.exp
Lancelot SIX [Sun, 21 Nov 2021 00:20:56 +0000 (00:20 +0000)]
gdb/testsuite: Remove duplicates from gdb.base/ui-redirect.exp

When running the testsuite, I have:

    Running .../gdb/testsuite/gdb.base/ui-redirect.exp ...
    DUPLICATE: gdb.base/ui-redirect.exp: redirect while already logging: set logging redirect off

Fix by moving the first 'set logging redirect off' to the end of the
previous [with_test_prefix] test block. The statement's purpose is to
clean the on flag set in this previous block, so moving it there makes
sense and does not change the sequence of commands in the test file.

Tested on x86_64-linux.

2 years agogdb: completion-support.exp: improve leading whitespace support
Lancelot SIX [Sat, 20 Nov 2021 23:20:23 +0000 (23:20 +0000)]
gdb: completion-support.exp: improve leading whitespace support

There is a expect support library in the source tree designed to help
developers test the auto-completion capabilities of GDB.

One of the functions is test_gdb_complete_unique_re.  It is used
(usually indirectly via test_gdb_complete_unique) to test that a given
input line is completed as a given output line.  The test checks for two
ways to do the completion: using tab-completion, or using the
'complete' command.  To do this, calls to two dedicated functions are
performed.  If we omit few details, we can consider that a call to

    test_gdb_complete_unique $input $expected

is equivalent to the two following calls:

    test_gdb_complete_tab_unique $input $expected
    test_gdb_complete_cmd_unique $input $expected

When using the tab-completion, everything works as expected, but some
care must be taken when using the 'complete' command if the given input
has leading whitespaces.  In such situation, the output of the
'complete' command will drop the leading whitespaces.

The current approach is that in such situation, the input and expected
outputs are right trimmed (i.e. all leading whitespaces are removed)
when performing the command completion check.

This means that the following call:

    test_gdb_complete_unique "   $input" "   $expected"

is almost equivalent to (again, omitting few details and arguments):

    test_gdb_complete_tab_unique "   $input" "   $expected"
    test_gdb_complete_cmd_unique "$input" "$expected"

This approach comes with a problem that we encounter when running the
tests in complete-empty.exp.  When doing so, we have:

    Running .../gdb/testsuite/gdb.base/complete-empty.exp ...
    DUPLICATE: gdb.base/complete-empty.exp: empty-input-line: cmd complete ""

This is because the test file does something like:

    test_gdb_complete_unique "" "!" " " 1
    test_gdb_complete_unique "   " "   !" " " 1¬

which, if we do the substitution introduced above is equivalent to:

    test_gdb_complete_tab_unique "" "!"
    test_gdb_complete_cmd_unique "" "!"
    test_gdb_complete_tab_unique "   " "   !"
    test_gdb_complete_cmd_unique "" "!"

We see that the lines 2 and 4 are now the same, and for this reason the
testing framework complains about DUPLICATE test names.

To fix that, this commit proposes that instead of left trimming both
input and expected outputs, only the expected output is trimmed.

Care must be taken in the case the completion gives more possibilities
than allowed by the max-completions setting.  In this case, the input
will be repeated in the output in its left trimmed version.  This commit
also ensures that this is taken care of.

With this commit, the gdb.base/complete-empty.exp still passes all its
tests but does not report the DUPLICATE anymore.

Tested on x86_64-linux.

2 years agogdb/testsuite: Remove duplicates from gdb.base/subst.exp
Lancelot SIX [Sat, 20 Nov 2021 23:07:55 +0000 (23:07 +0000)]
gdb/testsuite: Remove duplicates from gdb.base/subst.exp

When I run the testsuite, I have:

    Running .../gdb/testsuite/gdb.base/subst.ex ...
    DUPLICATE: gdb.base/subst.exp: unset substitute-path from, no rule entered yet

Fix by adjusting the problematic test name.

Tested on x86_64-linux.

2 years agogdb/testsuite: Remove duplicates from gdb.base/dfp-exprs.exp
Pedro Alves [Fri, 10 Dec 2021 22:41:54 +0000 (22:41 +0000)]
gdb/testsuite: Remove duplicates from gdb.base/dfp-exprs.exp

When I run the testsuite, I have:

    Running ../gdb/testsuite/gdb.base/dfp-exprs.exp ...
    DUPLICATE: gdb.base/dfp-exprs.exp: p 1.2dl < 1.3df

Replace hand-written tests checking various comparison operators between
various decimal floating point types with a loop to programmatically
generate all the combinations.  This removes the need to eyeball for all
suffixes, which lead to the original duplication.

Also add a lot more combinations, testing all comparison operators
comprehensively.  The result is 262 unique tests vs 104 before this
patch.

Tested on x86_86-linux.

Change-Id: Id215a3d610aa8e032bf06ee160b5e3aed4a92d1e

2 years agogdb/testsuite: Remove duplicates from gdb.base/ptype.exp
Lancelot SIX [Sat, 20 Nov 2021 22:57:10 +0000 (22:57 +0000)]
gdb/testsuite: Remove duplicates from gdb.base/ptype.exp

When running the testsuite, I have:

    Running .../gdb/testsuite/gdb.base/ptype.exp ...
    DUPLICATE: gdb.base/ptype.exp: ptype the_highest
    DUPLICATE: gdb.base/ptype.exp: list intfoo
    DUPLICATE: gdb.base/ptype.exp: list charfoo

Fix by adjusting the offending test names.

Tested on x86_64-linux.

2 years agogdb/testsuite: Remove duplicates from gdb.base/dfp-test.exp
Lancelot SIX [Sat, 20 Nov 2021 00:10:07 +0000 (00:10 +0000)]
gdb/testsuite: Remove duplicates from gdb.base/dfp-test.exp

When running the testsuite, I have:

    Running .../gdb/testsuite/gdb.base/dfp-test.exp ...
    DUPLICATE: gdb.base/dfp-test.exp: 1.23E is an invalid number
    DUPLICATE: gdb.base/dfp-test.exp: 1.23E45A is an invalid number
    DUPLICATE: gdb.base/dfp-test.exp: 1.23E is an invalid number
    DUPLICATE: gdb.base/dfp-test.exp: 1.23E45A is an invalid number

Fix by using proc_with_prefix where appropriate.

Tested on x86_64-linux.
Co-Authored-By: Andrew Burgess <aburgess@redhat.com>
2 years agogdb/testsuite: Remove duplicates from gdb.base/del.exp
Lancelot SIX [Fri, 19 Nov 2021 23:55:05 +0000 (23:55 +0000)]
gdb/testsuite: Remove duplicates from gdb.base/del.exp

When running the testsuite, I have:

    Running .../gdb/testsuite/gdb.base/del.exp ...
    DUPLICATE: gdb.base/del.exp: info break after removing break on main

Refactor slightly this test to run the various configurations under
foreach_with_prefix so each variant is automatically prefixed, ensuring
that the forgotten custom test name cannot happen.

Tested on x86_64-linux.

2 years agogdb/testsuite: Remove duplicates from gdb.base/solib-display.exp
Lancelot SIX [Fri, 19 Nov 2021 23:34:27 +0000 (23:34 +0000)]
gdb/testsuite: Remove duplicates from gdb.base/solib-display.exp

When running the testsuite, I have:

    Running .../gdb/testsuite/gdb.base/solib-display.exp ...
    DUPLICATE: gdb.base/solib-display.exp: NO: break 25
    DUPLICATE: gdb.base/solib-display.exp: NO: continue
    DUPLICATE: gdb.base/solib-display.exp: IN: break 25
    DUPLICATE: gdb.base/solib-display.exp: IN: continue
    DUPLICATE: gdb.base/solib-display.exp: SEP: break 25
    DUPLICATE: gdb.base/solib-display.exp: SEP: continue

The 'break 25' appears because the test inserts two breakpoints at the
same location.  Fix this by only inserting the breakpoint once.

Fix the 'continue' DUPLICATE by giving a phony name to the second
continue: 'continue two'.

While at it, this commit also removes a trailing space.

Tested on x86_64-linux.

2 years agogdb/testsuite: Remove duplicates from gdb.base/decl-before-def.exp
Lancelot SIX [Fri, 19 Nov 2021 23:27:18 +0000 (23:27 +0000)]
gdb/testsuite: Remove duplicates from gdb.base/decl-before-def.exp

When running the testsuite, I have:

    Running .../gdb/testsuite/gdb.base/decl-before-def.exp ...
    DUPLICATE: gdb.base/decl-before-def.exp: p a

Fix by giving explicit names to the two tests that use the same command.

Tested on x86_64-linux.

2 years agogdb/testsuite: Remove duplicates from gdb.base/pending.exp
Lancelot SIX [Fri, 19 Nov 2021 23:22:53 +0000 (23:22 +0000)]
gdb/testsuite: Remove duplicates from gdb.base/pending.exp

When running the testsuite, I have:

    Running .../gdb/testsuite/gdb.base/pending.exp ...
    DUPLICATE: gdb.base/pending.exp: disable other breakpoints

Fix by adjusting the test names.

Tested on x86_64-linux.

2 years agogdb/testsuite: Remove duplicates from gdb.base/checkpoint.exp
Lancelot SIX [Fri, 19 Nov 2021 23:16:51 +0000 (23:16 +0000)]
gdb/testsuite: Remove duplicates from gdb.base/checkpoint.exp

When running the testsuite, I have:

    Running .../gdb/testsuite/gdb.base/checkpoint.exp ...
    DUPLICATE: gdb.base/checkpoint.exp: verify lines 5 two
    DUPLICATE: gdb.base/checkpoint.exp: restart 0 one

This patch fixes the various erroneous incorrect test names.

While at it, this patch also remove some trailing white spaces across
the file.

Tested on x86_64-linux.

2 years agogdb/testsuite: Remove duplicates from gdb.base/pie-fork.exp
Lancelot SIX [Fri, 19 Nov 2021 23:08:23 +0000 (23:08 +0000)]
gdb/testsuite: Remove duplicates from gdb.base/pie-fork.exp

When running the testsuite, I have:

    Running .../gdb/testsuite/gdb.base/pie-fork.exp ...
    DUPLICATE: gdb.base/pie-fork.exp: test_no_detach_on_fork: continue

Fix by giving explicit names to the 'continue' commands that cause the
duplicate message.

Tested on x86_64-linux.

2 years agogdb/testsuite: Remove duplicates from gdb.base/realname-expand.exp
Lancelot SIX [Fri, 19 Nov 2021 22:48:59 +0000 (22:48 +0000)]
gdb/testsuite: Remove duplicates from gdb.base/realname-expand.exp

When running the testsuite, I have:

    Running .../gdb/testsuite/gdb.base/realname-expand.exp ...
    DUPLICATE: gdb.base/realname-expand.exp: set basenames-may-differ on

This is due to the fact that the test restarts GDB twice and each time
sets the basenames-may-differ setting.  This patch proposes to fix this
by not restarting GDB so the setting is maintained.  It just clears the
breakpoints between the two tests and updates the breakpoints number as
required.

This patch also perform some minor refactorings to improve visibility.

Tested on x86_64-linux.

2 years agogdb/testsuite: Remove duplicates from gdb.base/interp.exp
Lancelot SIX [Fri, 19 Nov 2021 19:55:05 +0000 (19:55 +0000)]
gdb/testsuite: Remove duplicates from gdb.base/interp.exp

When running the testsuite I have:

    Running .../gdb/testsuite/gdb.base/interp.exp ...
    DUPLICATE: gdb.base/interp.exp: interpreter-exec mi "-var-update *"

This is due to the fact that multiple successive instances of
gdb_test_multiple use 'pass $cmd', but one of them forgets to reset $cmd
to a new test name.

Fix by using 'pass $gdb_test_name', given that the gdb_test_name is set
by gdb_test_multiple.

While fixing this, this patch refactors all occurrences of the following
pattern:

    set cmd foo
    gdb_test_multiple $cmd $cmd {
        -re ... {
            pass $cmd
        }
    }

into

    gdb_test_multiple foo "" {
        -re ... {
            pass $gdb_test_name
         }
    }

This makes this test file coherent in its use of $gdb_test_name.

Tested on x86_64-linux.

2 years agogdb/testsuite: Remove duplicates from gdb.base/miscexprs.exp
Lancelot SIX [Fri, 19 Nov 2021 19:05:37 +0000 (19:05 +0000)]
gdb/testsuite: Remove duplicates from gdb.base/miscexprs.exp

When running the testsuite I see:

    Running .../gdb/testsuite/gdb.base/miscexprs.exp ...
    DUPLICATE: gdb.base/miscexprs.exp: print value of !ibig.i[100]
    DUPLICATE: gdb.base/miscexprs.exp: print value of !ibig.i[100]

This is due to an explicit test name repeated across multiple tests.
The actual test explicit names do not add much over the command from
wich default test names are derived.

Fix by removing the explicit test names across the file where they do
not add value.  While at doing some cleaning, also use $gdb_test_name in
the various uses of gdb_test_multiple.

Tested on x86_64-linux.

2 years agogdb/testsuite: Remove duplicates from gdb.base/stack-checking.exp
Lancelot SIX [Fri, 19 Nov 2021 18:58:04 +0000 (18:58 +0000)]
gdb/testsuite: Remove duplicates from gdb.base/stack-checking.exp

When running the testsuite I have:

    Running .../gdb/testsuite/gdb.base/stack-checking.exp ...
    DUPLICATE: gdb.base/stack-checking.exp: bt
    DUPLICATE: gdb.base/stack-checking.exp: bt

Fix by using with_test_prefix.

Tested on x86_64-linux.

2 years agoRISC-V: update docs to reflect privileged spec v1.9 has been dropped
Philipp Tomsich [Wed, 5 Jan 2022 13:57:28 +0000 (14:57 +0100)]
RISC-V: update docs to reflect privileged spec v1.9 has been dropped

After commit d8af286fffa ("RISC-V: Drop the privileged spec v1.9
support.") has removed support for privileged spec v1.9, this removes
it from the documentation.

References: d8af286fffa ("RISC-V: Drop the privileged spec v1.9 support.")

gas/ChangeLog:

* configure: Regenerate.
* configure.ac: Remove reference to priv spec 1.9.
* po/fr.po: Same.
* po/ru.po: Same.
* po/uk.po: Same.

2 years agoRISC-V: update docs for -mpriv-spec/--with-priv-spec for 1.12
Philipp Tomsich [Tue, 4 Jan 2022 17:12:32 +0000 (18:12 +0100)]
RISC-V: update docs for -mpriv-spec/--with-priv-spec for 1.12

While support for the privileged spec was added in a63375ac337
("RISC-V: Hypervisor ext: support Privileged Spec 1.12"), the
documentation has not been updated.  Add 1.12 to the relevant
documentation.

References: a63375ac337 ("RISC-V: Hypervisor ext: support Privileged Spec 1.12")

gas/ChangeLog:

* config/tc-riscv.c: Add 1.12 to the usage message.
* configure: Regenerate.
* configure.ac: Add 1.12 to the help/usage message.
* po/fr.po: Same.
* po/ru.po: Same.
* po/uk.po: Same.

2 years agoDo not use CC_HAS_LONG_LONG
Tom Tromey [Fri, 7 Jan 2022 21:00:33 +0000 (14:00 -0700)]
Do not use CC_HAS_LONG_LONG

ax.cc checks CC_HAS_LONG_LONG, but nothing defines this.  However,
PRINTF_HAS_LONG_LONG is checked in configure.  This patch removes the
former and keeps the latter.  This is PR remote/14976 (filed by me in
2012, lol).

I'm checking this in.

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

2 years agogdb/doc: shorten some source lines, and prevent some line breaks
Andrew Burgess [Wed, 22 Dec 2021 16:47:29 +0000 (16:47 +0000)]
gdb/doc: shorten some source lines, and prevent some line breaks

Building on the previous commit, this makes use of a trailing @ to
split long @deffn lines in the guile.texi source file.  This splitting
doesn't change how the document is laid out by texinfo.

I have also wrapped keyword and argument name pairs in @w{...} to
prevent line breaks appearing between the two.  I've currently only
done this for the longer @deffn lines, where a line break is
possible.  This makes the @deffn lines much nicer to read in the
generated pdf.

2 years agogdb/doc: Remove (...) around guile procedure names in @deffn lines
Andrew Burgess [Wed, 22 Dec 2021 16:04:56 +0000 (16:04 +0000)]
gdb/doc: Remove (...) around guile procedure names in @deffn lines

Most guile procedures in the guile.texi file are defined like:

  @deffn {Scheme Procedure} name arg1 arg2 arg3

But there are two places where we do this:

  @deffn {Scheme Procedure} (name arg1 arg2 arg3)

Notice the added (...).  Though this does represent how a procedure
call is written in scheme, it's not the normal style throughout the
manual.  I also checked the 'info guile' info page to see how they
wrote there declarations, and they use the first style too.

The second style also has the drawback that index entries are added as
'(name', and so they are grouped in the '(' section of the index,
which is not very user friendly.

In this commit I've changed the definitions of make-command and
make-parameter to use the first style.

The procedure declaration lines can get pretty long with all of the
arguments, and this was true for both of the procedures I am changing
in this commit.  I have made use of a trailing '@' to split the deffn
lines, and keep them under 80 characters in the texi source.  This
makes no difference to how the final document looks.

Finally, our current style for keyword arguments, appears to be:

  [#:keyword-name argument-name]

I don't really understand the reason for this, 'info guile' just seems
to use:

  [#:keyword-name]

which seems just as good to me.  But I don't propose to change
that just now.  What I do notice though, is that sometimes, texinfo
will place a line break between the keyword-name and the
argument-name, for example, the pdf of make-command is:

  make-command name [#:invoke invoke] [#:command-class
    command-class] [#:completer-class completer] [#:prefix? prefix] [#:doc
    doc-string]

Notice the line break after '#:command-class' and after '#:doc',
neither of which are ideal.  And so, for the two commands I am
changing in this commit, I have made use of @w{...} to prevent line
breaks between the keyword-name and the argument-name.  Now the pdf
looks like this:

  make-command name [#:invoke invoke]
    [#:command-class command-class] [#:completer-class completer]
    [#:prefix? prefix] [#:doc doc-string]

Which seems much better.  I'll probably update the other deffn lines
at some point.

2 years agoRevert previous delta to debug.c. Replace with patch to reject indirect types that...
Pavel Mayorov [Fri, 7 Jan 2022 12:34:37 +0000 (12:34 +0000)]
Revert previous delta to debug.c.  Replace with patch to reject indirect types that point to indirect types.

PR 28718
* dwarf.c: Revert previous delta.
(debug_get_real_type): Reject indirect types that point to
indirect types.
(debug_get_type_name, debug_get_type_size, debug_write_type):
Likewise.

2 years agoRISC-V: Updated the default ISA spec to 20191213.
Nelson Chu [Thu, 30 Dec 2021 15:23:46 +0000 (23:23 +0800)]
RISC-V: Updated the default ISA spec to 20191213.

Update the default ISA spec from 2.2 to 20191213 will change the default
version of i from 2.0 to 2.1.  Since zicsr and zifencei are separated
from i 2.1, users need to add them in the architecture string if they need
fence.i and csr instructions.  Besides, we also allow old ISA spec can
recognize zicsr and zifencei, but we won't output them since they are
already included in the i extension when i's version is less than 2.1.

bfd/
* elfxx-riscv.c (riscv_parse_add_subset): Allow old ISA spec can
recognize zicsr and zifencei.
gas/
* config/tc-riscv.c (DEFAULT_RISCV_ISA_SPEC): Updated to 20191213.
* testsuite/gas/riscv/csr-version-1p10.d: Added zicsr to -march since
the default version of i is 2.1.
* testsuite/gas/riscv/csr-version-1p11.d: Likewise.
* testsuite/gas/riscv/csr-version-1p12.d: Likewise.
* testsuite/gas/riscv/csr-version-1p9p1.d: Likewise.
* testsuite/gas/riscv/option-arch-03.d: Updated i's version to 2.1.
* testsuite/gas/riscv/option-arch-03.s: Likewise.
ld/
* testsuite/ld-riscv-elf/call-relax.d: Added zicsr to -march since
the default version of i is 2.1.
* testsuite/ld-riscv-elf/attr-merge-arch-01.d: Updated i's version to 2.1.
* testsuite/ld-riscv-elf/attr-merge-arch-01a.s: Likewise.
* testsuite/ld-riscv-elf/attr-merge-arch-01b.: Likewise.
* testsuite/ld-riscv-elf/attr-merge-arch-02.d: Likewise.
* testsuite/ld-riscv-elf/attr-merge-arch-02a.s: Likewise.
* testsuite/ld-riscv-elf/attr-merge-arch-02b.s: Likewise.
* testsuite/ld-riscv-elf/attr-merge-arch-03.d: Likewise.
* testsuite/ld-riscv-elf/attr-merge-arch-03a.s: Likewise.
* testsuite/ld-riscv-elf/attr-merge-arch-03b.s: Likewise.
* testsuite/ld-riscv-elf/attr-merge-arch-failed-02.d: Added zifencei
into Tag_RISCV_arch since it is added implied when i's version is
larger than 2.1.

2 years agoMove elf_backend_always_size_sections earlier
Alan Modra [Fri, 7 Jan 2022 03:13:56 +0000 (13:43 +1030)]
Move elf_backend_always_size_sections earlier

* elflink.c (bfd_elf_size_dynamic_sections): Move plt/got init
earlier and call elf_backend_always_size_sections at the start
of this function.

2 years agoAutomatic date update in version.in
GDB Administrator [Fri, 7 Jan 2022 00:00:18 +0000 (00:00 +0000)]
Automatic date update in version.in

2 years agoldelfgen.c: Add missing newlines when calling einfo
H.J. Lu [Thu, 6 Jan 2022 22:52:11 +0000 (14:52 -0800)]
ldelfgen.c: Add missing newlines when calling einfo

* ldelfgen.c (ldelf_map_segments): Add the missing newline to
einfo.

2 years agoFix a stack exhaustion bug parsing malicious STABS format debug information.
Nick Clifton [Thu, 6 Jan 2022 16:37:26 +0000 (16:37 +0000)]
Fix a stack exhaustion bug parsing malicious STABS format debug information.

PR 28718
* debug.c (debug_write_type): Allow for malicious recursion via
indirect debug types.

2 years agoaarch64: Add support for new SME instructions
Richard Sandiford [Thu, 6 Jan 2022 16:22:54 +0000 (16:22 +0000)]
aarch64: Add support for new SME instructions

This patch adds support for three new SME instructions: ADDSPL,
ADDSVL and RDSVL.  They behave like ADDPL, ADDVL and RDVL, but read
the streaming vector length instead of the current vector length.

opcodes/
* aarch64-tbl.h (aarch64_opcode_table): Add ADDSPL, ADDSVL and RDSVL.
* aarch64-dis-2.c: Regenerate.

gas/
* testsuite/gas/aarch64/sme.s, testsuite/gas/aarch64/sme.d: Add tests
for ADDSPL, ADDSVL and RDSVL.

2 years agoUse target_announce_detach in more targets
Tom Tromey [Mon, 27 Dec 2021 05:03:09 +0000 (22:03 -0700)]
Use target_announce_detach in more targets

target_announce_detach was added in commit 0f48b757 ("Factor out
"Detaching from program" message printing").  There, Pedro wrote:

    (For now, I left the couple targets that print this a bit differently
    alone.  Maybe this could be further pulled out into infcmd.c.  If we
    did that, and those targets want to continue printing differently,
    this new function could be converted to a target method.)

It seems to me that the differences aren't very big, and in some cases
other targets handled the output a bit more nicely.  In particular,
some targets will print a different message when exec_file==NULL,
rather than printing the same output with an empty string as
exec_file.

This patch incorporates the nicer output into target_announce_detach,
then changes the remaining ports to use this function.

2 years agoIntroduce target_announce_attach
Tom Tromey [Mon, 27 Dec 2021 04:49:48 +0000 (21:49 -0700)]
Introduce target_announce_attach

This introduces target_announce_attach, by analog with
target_announce_detach.  Then it converts existing targets to use
this, rather than emitting their own output by hand.

2 years agogdb: make use add_setshow_prefix_cmd in gnu-nat.c
Andrew Burgess [Thu, 6 Jan 2022 12:53:20 +0000 (12:53 +0000)]
gdb: make use add_setshow_prefix_cmd in gnu-nat.c

In gnu-nat.c we currently implement some set/show prefix commands
"manually", that is, we call add_prefix_cmd, and assign a set and show
function to each prefix command.

These set/show functions print an error indicating that the user
didn't type a complete command.

If we instead switch to using add_setshow_prefix_cmd then we can
delete the set/show functions, GDB provides some default functions,
which give a nice help style summary that lists all of the available
sub-commands, along with a one line summary of what each does.

Though this clearly changes the existing behaviour, I think this
change is acceptable as the new behaviour is more inline with other
set/show prefix commands, and the new behaviour is more informative.

This change will conflict with Tom's change here:

  https://sourceware.org/pipermail/gdb-patches/2022-January/184724.html

Where Tom changes the set/show functions that I delete.  My suggestion
is that the set/show functions still be deleted even after Tom's
patch (or instead of Tom's patch).

For testing I've build GDB on GNU/Hurd, and manually tested these
functions.  I did a grep over the testsuite, and don't believe the
existing error messages are being checked for in any tests.

2 years agoUse warning in windows-nat error messages
Tom Tromey [Sun, 26 Dec 2021 21:21:28 +0000 (14:21 -0700)]
Use warning in windows-nat error messages

A warning in windows-nat.c can be converted to use the warning
function.  As a side effect, this arranges for the output to be sent
to gdb_stderr.

2 years agoClean up some dead code in windows-tdep.c
Tom Tromey [Sun, 26 Dec 2021 20:49:22 +0000 (13:49 -0700)]
Clean up some dead code in windows-tdep.c

windows-tdep.c checks the result of xmalloc, which isn't necessary.  I
initially removed this dead check, but then went a bit further and
modified the code so that some "goto"s and explicit memory management
could be removed.  Then, I added a couple of missing bounds checks.

I believe this also fixes a possible bug with a missing 0-termination
of a string.  I am not certain, but that is why I think the existing
code allocates a buffer that is 1 byte too long -- but then it fails
to set this byte to 0.

2 years agoAvoid crash in language_info
Tom Tromey [Wed, 5 Jan 2022 17:42:25 +0000 (10:42 -0700)]
Avoid crash in language_info

language_info calls:

  show_language_command (NULL, 1, NULL, NULL);

... "knowing" that show_language_command does not use its ui_file
parameter.  However, this was changed in commit 7514a661
("Consistently Use ui_file parameter to show callbacks").

This patch changes language_info to pass a ui_file.

It took a while to write the test -- this function is only called when
'verbose' is on and when switching the "expected" language in auto
mode.

2 years agoFix some failures in langs.exp
Tom Tromey [Thu, 6 Jan 2022 14:34:44 +0000 (07:34 -0700)]
Fix some failures in langs.exp

langs.exp currently has some fails for me because the stack trace
includes full paths to the source files.

    FAIL: gdb.base/langs.exp: up to foo in langs.exp
    FAIL: gdb.base/langs.exp: up to cppsub_ in langs.exp
    FAIL: gdb.base/langs.exp: up to fsub in langs.exp

This fixes the failures by making the filename regexps a bit more lax.