]> git.ipfire.org Git - thirdparty/binutils-gdb.git/log
thirdparty/binutils-gdb.git
19 months agoNote that at least dejagnu version 1.5.3 is required in order to be ale to run the...
Nick Clifton [Tue, 4 Oct 2022 09:53:16 +0000 (10:53 +0100)] 
Note that at least dejagnu version 1.5.3 is required in order to be ale to run the testsuites.

* README-maintainer-mode: Add a minimum version of dejagnu
requirement.

19 months agoopcodes/riscv: style csr names as registers
Andrew Burgess [Mon, 3 Oct 2022 09:59:57 +0000 (10:59 +0100)] 
opcodes/riscv: style csr names as registers

While reviewing another patch I noticed that RISC-V CSR names are
given the text style, not the register style.  This patch fixes this
mistake.

19 months ago[AArch64] Update FPSR/FPCR fields for FPU and SVE
Luis Machado [Thu, 22 Sep 2022 11:53:33 +0000 (12:53 +0100)] 
[AArch64] Update FPSR/FPCR fields for FPU and SVE

I noticed some missing flags/fields from FPSR and FPCR registers in
both the FPU and SVE target descriptions.

This patch adds those and makes the SVE versions of FPSR and FPCR
use the proper flags/bitfields types.

19 months agoSupport objcopy changing compression to or from zstd
Alan Modra [Tue, 4 Oct 2022 02:44:05 +0000 (13:14 +1030)] 
Support objcopy changing compression to or from zstd

Commit 2cac01e3ffff lacked support for objcopy changing compression
style.  Add that support, which meant a rewrite of
bfd_compress_section_contents.  In the process I've fixed some memory
leaks.

* compress.c (bfd_is_section_compressed_info): Rename from
bfd_is_section_compressed_with_header and add ch_type param
to return compression header ch_type field.
Update all callers.
(decompress_section_contents): Remove buffer and size params.
Rewrite.  Update callers.
(bfd_init_section_compress_status): Free contents on failure.
(bfd_compress_section): Likewise.
* elf.c (_bfd_elf_make_section_from_shdr): Support objcopy
changing between any of the three compression schemes.  Report
"unable to compress/decompress" rather than "unable to
initialize compress/decompress status" on compress/decompress
failures.
* bfd-in2.h: Regenerate.

19 months agoRe: compress .gnu.debuglto_.debug_* sections if requested
Alan Modra [Tue, 4 Oct 2022 02:39:36 +0000 (13:09 +1030)] 
Re: compress .gnu.debuglto_.debug_* sections if requested

Enable zlib-gnu compression for .gnu.debuglto_.debug_*.  This differs
from zlib-gnu for .debug_* where the name is changed to .zdebug_*.
The name change isn't really needed.

bfd/
* elf.c (elf_fake_sections): Replace "." with ".z" in debug
section names only when name was ".d*", ie. ".debug_*".
(_bfd_elf_assign_file_positions_for_non_load): Likewise.
gas/
* write.c (compress_debug): Compress .gnu.debuglto_.debug_*
for zlib-gnu too.  Compress .gnu.linkonce.wi.*.

19 months agocompress .gnu.debuglto_.debug_* sections if requested
Martin Liska [Thu, 29 Sep 2022 12:10:30 +0000 (14:10 +0200)] 
compress .gnu.debuglto_.debug_* sections if requested

Right now, when using LTO, the intermediate object files do contain
debug info in sections starting with .gnu.debuglto_ prefix and are
not compressed when --compress-debug-sections is used.

It's a mistake and we can save quite some disk space. The following
example comes from tramp3d when the corresponding LTO sections
are compressed with zlib:

$ bloaty tramp3d-v4-v2.o -- tramp3d-v4.o
    FILE SIZE        VM SIZE
 --------------  --------------
   +83%     +10  [ = ]       0    [Unmapped]
 -68.0%    -441  [ = ]       0    .gnu.debuglto_.debug_line
 -52.3%    -759  [ = ]       0    .gnu.debuglto_.debug_line_str
 -62.4% -3.24Ki  [ = ]       0    .gnu.debuglto_.debug_abbrev
 -64.8% -1.12Mi  [ = ]       0    .gnu.debuglto_.debug_info
 -88.8% -4.58Mi  [ = ]       0    .gnu.debuglto_.debug_str
 -27.7% -5.70Mi  [ = ]       0    TOTAL

bfd/ChangeLog:

* elf.c (_bfd_elf_make_section_from_shdr): Compress all debug
  info sections.

gas/ChangeLog:

* write.c (compress_debug): Compress also ".gnu.debuglto_.debug_"
if the compression algorithm is different from zlib-gnu.

19 months agoRISC-V/gas: allow generating up to 176-bit instructions with .insn
Jan Beulich [Tue, 4 Oct 2022 07:46:11 +0000 (09:46 +0200)] 
RISC-V/gas: allow generating up to 176-bit instructions with .insn

For the time being simply utilize O_big to avoid widening other fields,
bypassing append_insn() etc.

19 months agoRISC-V/gas: don't open-code insn_length()
Jan Beulich [Tue, 4 Oct 2022 07:45:31 +0000 (09:45 +0200)] 
RISC-V/gas: don't open-code insn_length()

Use the helper when it can be used.

19 months agoRISC-V/gas: drop stray call to install_insn()
Jan Beulich [Tue, 4 Oct 2022 07:45:08 +0000 (09:45 +0200)] 
RISC-V/gas: drop stray call to install_insn()

add_fixed_insn(), by calling move_insn(), already invokes install_insn().

19 months agoRISC-V/gas: drop riscv_subsets static variable
Jan Beulich [Tue, 4 Oct 2022 07:44:44 +0000 (09:44 +0200)] 
RISC-V/gas: drop riscv_subsets static variable

It's fully redundant with the subset_list member of riscv_rps_as.

19 months agoRISC-V: don't cast expressions' X_add_number to long in diagnostics
Jan Beulich [Tue, 4 Oct 2022 07:40:55 +0000 (09:40 +0200)] 
RISC-V: don't cast expressions' X_add_number to long in diagnostics

There's no need for such workarounds anymore now that we use C99
uniformly. This addresses several testsuite failures encountered when
(cross-)building on a 32-bit host.

19 months agoignore DWARF debug information for -gsplit-dwarf with dwarf-5
Potharla, Rupesh [Tue, 4 Oct 2022 07:39:53 +0000 (09:39 +0200)] 
ignore DWARF debug information for -gsplit-dwarf with dwarf-5

Skip dwo_id for split dwarf.

* dwarf2.c (parse_comp_unit): Skip DWO_id for DW_UT_skeleton.

19 months agoAutomatic date update in version.in
GDB Administrator [Tue, 4 Oct 2022 00:00:14 +0000 (00:00 +0000)] 
Automatic date update in version.in

19 months agoFix self-move warning check for GCC 13+
Jan-Benedict Glaw [Mon, 3 Oct 2022 14:56:24 +0000 (16:56 +0200)] 
Fix self-move warning check for GCC 13+

GCC 13 got the self-move warning (0abb78dda084a14b3d955757c6431fff71c263f3),
but that warning is only checked for clang, resulting in:

/usr/lib/gcc-snapshot/bin/g++ -x c++    -I. -I. -I./config -DLOCALEDIR="\"/tmp/gdb-m68k-linux/share/locale\"" -DHAVE_CONFIG_H -I./../include/opcode -I./../readline/readline/.. -I./../zlib  -I../bfd -I./../bfd -I./../include -I../libdecnumber -I./../libdecnumber  -I./../gnulib/import -I../gnulib/import -I./.. -I.. -I./../libbacktrace/ -I../libbacktrace/  -DTUI=1    -I./.. -pthread  -Wall -Wpointer-arith -Wno-unused -Wunused-value -Wunused-variable -Wunused-function -Wno-switch -Wno-char-subscripts -Wempty-body -Wunused-but-set-parameter -Wunused-but-set-variable -Wno-sign-compare -Wno-error=maybe-uninitialized -Wno-mismatched-tags -Wsuggest-override -Wimplicit-fallthrough=3 -Wduplicated-cond -Wshadow=local -Wdeprecated-copy -Wdeprecated-copy-dtor -Wredundant-move -Wmissing-declarations -Wstrict-null-sentinel -Wformat -Wformat-nonliteral -Werror -g -O2   -c -o unittests/environ-selftests.o -MT unittests/environ-selftests.o -MMD -MP -MF unittests/.deps/environ-selftests.Tpo unittests/environ-selftests.c
unittests/environ-selftests.c: In function 'void selftests::gdb_environ_tests::test_self_move()':
unittests/environ-selftests.c:228:7: error: moving 'env' of type 'gdb_environ' to itself [-Werror=self-move]
  228 |   env = std::move (env);
      |   ~~~~^~~~~~~~~~~~~~~~~
unittests/environ-selftests.c:228:7: note: remove 'std::move' call
cc1plus: all warnings being treated as errors
make[1]: *** [Makefile:1896: unittests/environ-selftests.o] Error 1
make[1]: Leaving directory '/var/lib/laminar/run/gdb-m68k-linux/3/binutils-gdb/gdb'
make: *** [Makefile:13193: all-gdb] Error 2

19 months agogdb: constify inferior::target_is_pushed
Simon Marchi [Fri, 30 Sep 2022 00:14:41 +0000 (20:14 -0400)] 
gdb: constify inferior::target_is_pushed

Change-Id: Ia4143b9c63cb76e2c824ba773c66f5c5cd94b2aa

19 months ago[AArch64] Handle W registers as pseudo-registers instead of aliases of X registers
Luis Machado [Thu, 15 Sep 2022 14:57:01 +0000 (15:57 +0100)] 
[AArch64] Handle W registers as pseudo-registers instead of aliases of X registers

The aarch64 port handles W registers as aliases of X registers. This is
incorrect because X registers are 64-bit and W registers are 32-bit.

This patch teaches GDB how to handle W registers as pseudo-registers of
32-bit, the bottom half of the X registers.

Testcase included.

19 months ago[AArch64] Fix pseudo-register numbering in the presence of unexpected additional...
Luis Machado [Fri, 9 Sep 2022 09:30:53 +0000 (10:30 +0100)] 
[AArch64] Fix pseudo-register numbering in the presence of unexpected additional registers

When using AArch64 GDB with the QEMU debugging stub (in user mode), we get
additional system registers that GDB doesn't particularly care about, so
it doesn't number those explicitly.

But given the pseudo-register numbers are above the number of real registers,
we need to setup/account for the real registers first before going ahead and
numbering the pseudo-registers.  This has to happen at the end of
aarch64_gdbarch_init, after the call to tdesc_use_registers, as that
updates the total number of real registers.

This is in preparation to supporting pointer authentication for bare metal
aarch64 (QEMU).

19 months agoreadelf: DO not load section headers from file offset zero
Nick Clifton [Mon, 3 Oct 2022 12:19:21 +0000 (13:19 +0100)] 
readelf: DO not load section headers from file offset zero

* readelf.c (get_32bit_section_headers): Return false if the
e_shoff field is zero.
(get_64bit_section_headers): Likewise.

19 months agoRISC-V: Move supervisor instructions after all unprivileged ones
Tsukasa OI [Wed, 28 Sep 2022 12:41:38 +0000 (12:41 +0000)] 
RISC-V: Move supervisor instructions after all unprivileged ones

This location of supervisor instructions is out of place (because many other
privileged instructions are located at the tail but after the supervisor
instructions, we have many unprivileged instructions including bit
manipulation / crypto / vector instructions).

Not only that, this is harmful to implement pseudoinstructions in the latest
'P'-extension proposal (CLROV and RDOV).  This commit moves supervisor
instructions after all unprivileged instructions.

opcodes/ChangeLog:

* riscv-opc.c (riscv_opcodes): Adjust indents.  Move supervisor
instructions after all unprivileged instructions.

19 months agoImprove GDB's baseclass detection with typedefs
Bruno Larsen [Fri, 23 Sep 2022 09:36:02 +0000 (11:36 +0200)] 
Improve GDB's baseclass detection with typedefs

When a class inherits from a typedef'd baseclass, GDB may be unable to
find the baseclass if the user is not using the typedef'd name, as is
tested on gdb.cp/virtbase2.exp; the reason that test case is working
under gcc is that the dwarf generated by gcc links the class to the
original definition of the baseclass, not to the typedef.  If the
inheritance is linked to the typedef, such as how clang does it,
gdb.cp/virtbase2.exp starts failing.

This can also be seen in gdb.cp/impl-this.exp, when attempting to print
D::Bint::i, and GDB not being able to find the baseclass Bint.

This happens because searching for baseclasses only uses the macro
TYPE_BASECLASS_NAME, which returns the typedef'd name. However, we can't
switch that macro to checking for typedefs, otherwise we wouldn't be
able to find the typedef'd name anymore. This is fixed by searching for
members or baseclasses by name, we check both the saved name and the
name after checking for typedefs.

This also fixes said long-standing bug in gdb.cp/impl-this.exp when the
compiler adds information about typedefs in the debuginfo.

19 months agoRISC-V: Assign DWARF numbers to vector registers
Tsukasa OI [Thu, 11 Aug 2022 21:16:51 +0000 (06:16 +0900)] 
RISC-V: Assign DWARF numbers to vector registers

This commit assigns DWARF register numbers to vector registers (v0-v31:
96..127) to implement RISC-V DWARF Specification version 1.0-rc4
(now in the frozen state):

https://github.com/riscv-non-isa/riscv-elf-psabi-doc/releases/tag/v1.0-rc4

binutils/ChangeLog:

* dwarf.c (dwarf_regnames_riscv): Assign DWARF register numbers
96..127 to vector registers v0-v31.

gas/ChangeLog:

* config/tc-riscv.c (tc_riscv_regname_to_dw2regnum): Support
vector registers.
* testsuite/gas/riscv/dw-regnums.s: Add vector registers to the
DWARF register number test.
* testsuite/gas/riscv/dw-regnums.d: Likewise.

19 months agoRISC-V: Add testcase for DWARF register numbers
Tsukasa OI [Thu, 11 Aug 2022 21:20:03 +0000 (06:20 +0900)] 
RISC-V: Add testcase for DWARF register numbers

Although it had csr-dw-regnums.d (for CSRs), it didn't have DWARF register
number test for GPRs/FPRs.

This commit adds dw-regnums.{s,d} to test such registers.

gas/ChangeLog:

* testsuite/gas/riscv/dw-regnums.s: New DWARF register number test
for GPRs/FPRs.
* testsuite/gas/riscv/dw-regnums.d: Likewise.

19 months agoAutomatic date update in version.in
GDB Administrator [Mon, 3 Oct 2022 00:00:11 +0000 (00:00 +0000)] 
Automatic date update in version.in

19 months ago[gdb/testsuite] Fix waitpid testing in next-fork-other-thread.c
Tom de Vries [Sun, 2 Oct 2022 18:18:00 +0000 (20:18 +0200)] 
[gdb/testsuite] Fix waitpid testing in next-fork-other-thread.c

In next-fork-other-thread.c, there's this loop:
...
      do
        {
          ret = waitpid (pid, &stat, 0);
        } while (ret == EINTR);
...

The loop condition tests for "ret == EINTR" but waitpid signals EINTR by
returning -1 and setting errno to EINTR.

Fix this by changing the loop condition to "ret == -1 && errno == EINTR".

Tested on x86_64-linux.

19 months agogdb/testsuite: handle invalid .exp names passed in TESTS
Andrew Burgess [Sat, 10 Sep 2022 10:10:25 +0000 (11:10 +0100)] 
gdb/testsuite: handle invalid .exp names passed in TESTS

I ran some tests like:

  $ make check-gdb TESTS="gdb.base/break.exp"

then, then I went to rerun the tests later, I managed to corrupt the
command line, like this:

  $ make check-gdb TESTS="gdb.base/breakff.exp"

the make command did exit with an error, but DejaGnu appeared to
report that every test passed!  The tail end of the output looks like
this:

  Illegal Argument "no-matching-tests-found"
  try "runtest --help" for option list
   === gdb Summary ===

  # of expected passes 115
  /tmp/build/gdb/gdb version  13.0.50.20220831-git -nw -nx -iex "set height 0" -iex "set width 0" -data-directory /tmp/build/gdb/testsuite/../data-directory

  make[3]: *** [Makefile:212: check-single] Error 1
  make[3]: Leaving directory '/tmp/build/gdb/testsuite'
  make[2]: *** [Makefile:161: check] Error 2
  make[2]: Leaving directory '/tmp/build/gdb/testsuite'
  make[1]: *** [Makefile:1916: check] Error 2
  make[1]: Leaving directory '/tmp/build/gdb'
  make: *** [Makefile:13565: check-gdb] Error 2

For a while, I didn't spot that DejaGnu had failed at all, I saw the
115 passes, and thought everything had run correctly - though I was
puzzled that make was reporting an error.

What happens is that in gdb/testsuite/Makefile, in the check-single
rule, we first run DejaGnu, then run the dg-add-core-file-count.sh
script, and finally, we use sed to extract the results from the
gdb.sum file.

In my case, with the invalid test name, DejaGnu fails, but the
following steps are still run, the final result, the 115 passes, is
then extracted from the pre-existing gdb.sum file.

If I use 'make -jN' then the 'check-parallel' rule, rather than the
'check-single' rule is used.  In this case the behaviour is slightly
different, the tail end of the output now looks like this:

  No matching tests found.

  make[4]: Leaving directory '/tmp/build/gdb/testsuite'
  find: ‘outputs’: No such file or directory
  Usage: ../../../src/gdb/testsuite/../../contrib/dg-extract-results.py [-t tool] [-l variant-list] [-L] log-or-sum-file ...

      tool           The tool (e.g. g++, libffi) for which to create a
                     new test summary file.  If not specified then output
                     is created for all tools.
      variant-list   One or more test variant names.  If the list is
                     not specified then one is constructed from all
                     variants in the files for <tool>.
      sum-file       A test summary file with the format of those
                     created by runtest from DejaGnu.
      If -L is used, merge *.log files instead of *.sum.  In this
      mode the exact order of lines may not be preserved, just different
      Running *.exp chunks should be in correct order.
  find: ‘outputs’: No such file or directory
  Usage: ../../../src/gdb/testsuite/../../contrib/dg-extract-results.py [-t tool] [-l variant-list] [-L] log-or-sum-file ...

      tool           The tool (e.g. g++, libffi) for which to create a
                     new test summary file.  If not specified then output
                     is created for all tools.
      variant-list   One or more test variant names.  If the list is
                     not specified then one is constructed from all
                     variants in the files for <tool>.
      sum-file       A test summary file with the format of those
                     created by runtest from DejaGnu.
      If -L is used, merge *.log files instead of *.sum.  In this
      mode the exact order of lines may not be preserved, just different
      Running *.exp chunks should be in correct order.
  make[3]: Leaving directory '/tmp/build/gdb/testsuite'
  make[2]: Leaving directory '/tmp/build/gdb/testsuite'
  make[1]: Leaving directory '/tmp/build/gdb'

Rather than DejaGnu failing, we now get a nice 'No matching tests
found' message, followed by some other noise.  This other noise is
first `find` failing, followed by the dg-extract-results.py script
failing.

What happens here is that, in the check-parallel rule, the outputs
directory is deleted before DejaGnu is invoked.  Then we try to run
all the tests, and finally we use find and dg-extract-results.py to
combine all the separate .sun and .log files together.  However, if
there are no tests run then the outputs/ directory is never created,
so the find command and consequently the dg-extract-results.py script,
fail.

This commit aims to fix the following issues:

 (1) For check-single and check-parallel rules, don't run any of the
 post-processing steps if DejaGnu failed to run.  This will avoid all
 the noise after the initial failure of DejaGnu,

 (2) For check-single ensure that we don't accidentally report
 previous results, this is related to the above, but is worth calling
 out as a separate point, and

 (3) For check-single, print the 'No matching tests found' message
 just like we do for a parallel test run.  This makes the parallel and
 non-parallel testing behaviour more similar, and I think is clearer
 than the current 'Illegal Argument' error message.

Points (1) and (2) will be handled by moving the post processing steps
inside an if block within the recipe.  For check-single I propose
deleting the gdb.sum and gdb.log files before running DejaGnu, this is
similar (I think) to how we delete the outputs/ directory in the
check-parallel rule.

For point (3) I plan to split the check-single rule in two, the
existing check-single will be renamed do-check-single, then a new
check-single rule will be added.  The new check-single rule can either
depend on the new do-check-single, or will ensure the 'No matching
tests found' message is printed when appropriate.

19 months agogdb/disasm: better intel flavour disassembly styling with Pygments
Andrew Burgess [Sat, 27 Aug 2022 15:15:31 +0000 (16:15 +0100)] 
gdb/disasm: better intel flavour disassembly styling with Pygments

This commit was inspired by this stackoverflow post:

  https://stackoverflow.com/questions/73491793/why-is-there-a-%C2%B1-in-lea-rax-rip-%C2%B1-0xeb3

One of the comments helpfully links to this Python test case:

  from pygments import formatters, lexers, highlight

  def colorize_disasm(content, gdbarch):
      try:
          lexer = lexers.get_lexer_by_name("asm")
          formatter = formatters.TerminalFormatter()
          return highlight(content, lexer, formatter).rstrip().encode()
      except:
          return None

  print(colorize_disasm("lea [rip+0x211]  # COMMENT", None).decode())

Run the test case and you should see that the '+' character is
underlined, and could be confused with a combined +/- symbol.

What's happening is that Pygments is failing to parse the input text,
and the '+' is actually being marked in the error style.  The error
style is red and underlined.

It is worth noting that the assembly instruction being disassembled
here is an x86-64 instruction in the 'intel' disassembly style, rather
than the default att style.  Clearly the Pygments module expects the
att syntax by default.

If we change the test case to this:

  from pygments import formatters, lexers, highlight

  def colorize_disasm(content, gdbarch):
      try:
          lexer = lexers.get_lexer_by_name("asm")
          lexer.add_filter('raiseonerror')
          formatter = formatters.TerminalFormatter()
          return highlight(content, lexer, formatter).rstrip().encode()
      except:
          return None

  res = colorize_disasm("lea rax,[rip+0xeb3] # COMMENT", None)
  if res:
      print(res.decode())
  else:
      print("No result!")

Here I've added the call: lexer.add_filter('raiseonerror'), and I am
now checking to see if the result is None or not.  Running this and
the test now print 'No result!' - instead of styling the '+' in the
error style, we instead give up on the styling attempt.

There are two things we need to fix relating to this disassembly
text.  First, Pygments is expecting att style disassembly, not the
intel style that this example uses.  Fortunately, Pygments also
supports the intel style, all we need to do is use the 'nasm' lexer
instead of the 'asm' lexer.

However, this leads to the second problem; in our disassembler line we
have '# COMMENT'.  The "official" Intel disassembler style uses ';'
for its comment character, however, gas and libopcodes use '#' as the
comment character, as gas uses ';' for an instruction separator.

Unfortunately, Pygments expects ';' as the comment character, and
treats '#' as an error, which means, with the addition of the
'raiseonerror' filter, that any line containing a '#' comment, will
not get styled correctly.

However, as the i386 disassembler never produces a '#' character other
than for comments, we can easily "fix" Pygments parsing of the
disassembly line.  This is done by creating a filter.  This filter
looks for an Error token with the value '#', we then change this into
a comment token.  Every token after this (until the end of the line)
is also converted into a comment.

In this commit I do the following:

  1. Check the 'disassembly-flavor' setting and select between the
  'asm' and 'nasm' lexers based on the setting.  If the setting is not
  available then the 'asm' lexer is used by default,

  2. Use "add_filter('raiseonerror')" to ensure that the formatted
  output will not include any error text, which would be underlined,
  and might be confusing,

  3. If the 'nasm' lexer is selected, then add an additional filter
  that will format '#' and all other text on the line, as a comment,
  and

  4. If Pygments throws an exception, instead of returning None,
  return the original, unmodified content.  This will mean that this
  one instruction is printed without styling, but GDB will continue to
  call into the Python code to style later instructions.

I haven't included a test specifically for the above error case,
though I have manually check that the above case now styles
correctly (with no underline).  The existing style tests check that
the disassembler styling still works though, so I know I've not
generally broken things.

One final thought I have after looking at this issue is that I wonder
now if using Pygments for styling disassembly from every architecture
is actually a good idea?

Clearly, the 'asm' lexer is OK with att style x86-64, but not OK with
intel style x86-64, so who knows how well it will handle other random
architectures?

When I first added this feature I tested it against some random
RISC-V, ARM, and X86-64 (att style) code, and it seemed fine, but I
never tried to make an exhaustive check of all instructions, so its
quite possible that there are corner cases where things are styled
incorrectly.

With the above changes I think that things should be a bit better
now.  If a particular instruction doesn't parse correctly then our
Pygments based styling code will just not style that one instruction.
This is combined with the fact that many architectures are now moving
to libopcodes based styling, which is much more reliable.

So, I think it is fine to keep using Pygments as a fallback mechanism
for styling all architectures, even if we know it might not be perfect
in all cases.

19 months agogdb: improve disassembler styling when Pygments raises an exception
Andrew Burgess [Fri, 26 Aug 2022 20:19:14 +0000 (21:19 +0100)] 
gdb: improve disassembler styling when Pygments raises an exception

While working on another issue relating to GDB's use of the Python
Pygments package for disassembly styling I noticed an issue in the
case where the Pygments package raises an exception.

The intention of the current code is that, should the Pygments package
raise an exception, GDB will disable future attempts to call into the
Pygments code.  This was intended to prevent repeated errors during
disassembly if, for some reason, the Pygments code isn't working.

Since the Pygments based styling was added, GDB now supports
disassembly styling using libopcodes, but this is only available for
some architectures.  For architectures not covered by libopcodes
Pygments is still the only option.

What I observed is that, if I disable the libopcodes styling, then
setup GDB so that the Pygments based styling code will indicate an
error (by returning None), GDB does, as expected, stop using the
Pygments based styling.  However, the libopcodes based styling will
instead be used, despite this feature having been disabled.

The problem is that the disassembler output is produced into a
string_file buffer.  When we are using Pygments, this buffer is
created without styling support.  However, when Pygments fails, we
recreate the buffer with styling support.

The problem is that we should only recreate the buffer with styling
support only if libopcodes styling is enabled.  This was an oversight
in commit:

  commit 4cbe4ca5da5cd7e1e6331ce11f024bf3c07b9744
  Date:   Mon Feb 14 14:40:52 2022 +0000

      gdb: add support for disassembler styling using libopcodes

This commit:

  1. Factors out some of the condition checking logic into two new
  helper functions use_ext_lang_for_styling and
  use_libopcodes_for_styling,

  2. Reorders gdb_disassembler::m_buffer and gdb_disassembler::m_dest,
  this allows these fields to be initialised m_dest first, which means
  that the new condition checking functions can rely on m_dest being
  set, even when called from the gdb_disassembler constructor,

  3. Make use of the new condition checking functions each time
  m_buffer is initialised,

  4. Add a new test that forces the Python disassembler styling
  function to return None, this will cause GDB to disable use of
  Pygments for styling, and

  5. When we reinitialise m_buffer, and re-disassemble the
  instruction, call reset the in-comment flag.  If the instruction
  being disassembler ends in a comment then the first disassembly pass
  will have set the in-comment flag to true.  This shouldn't be a
  problem as we will only be using Pygments, and thus performing a
  re-disassembly pass, if libopcodes is disabled, so the in-comment
  flag will never be checked, even if it is set incorrectly.  However,
  I think that having the flag set correctly is a good thing, even if
  we don't check it (you never know what future uses might come up).

19 months agogdb/testsuite: extend styling test for libopcodes styling
Andrew Burgess [Fri, 26 Aug 2022 20:13:51 +0000 (21:13 +0100)] 
gdb/testsuite: extend styling test for libopcodes styling

This commit extends the gdb.base/style.exp test to cover disassembler
styling using libopcodes (where available).

The test will try to enable libopcode based styling, if this
works (because such styling is available) then some tests are run to
check that the output is styled, and that the styling can be disabled
using 'set style disassembler enabled off'.  If libopcodes styling is
not available on the current architecture then these new tests will be
skipped.

I've moved the Python Pygments module check inside the
test_disable_disassembler_styling function now, so that the test will
be run even when Python Pygments is not available, this allows the new
tests discussed above.

If the Pygments module is not available then the Pygments based tests
will be skipped just as they were before.

19 months agogdb: update now gdbarch_register_name doesn't return nullptr
Andrew Burgess [Wed, 31 Aug 2022 14:42:43 +0000 (15:42 +0100)] 
gdb: update now gdbarch_register_name doesn't return nullptr

After the previous few commit, gdbarch_register_name no longer returns
nullptr.  This commit audits all the calls to gdbarch_register_name
and removes any code that checks the result against nullptr.

There should be no visible change after this commit.

19 months agogdb: final cleanup of various gdbarch_register_name methods
Andrew Burgess [Wed, 31 Aug 2022 12:32:59 +0000 (13:32 +0100)] 
gdb: final cleanup of various gdbarch_register_name methods

Building on the previous commits, this commit goes through the various
gdbarch_register_name methods and removes all the remaining 'return
NULL' cases, I claim that these either couldn't be hit, or should be
returning the empty string.

In all cases the return of NULL was used if the register number being
passed to gdbarch_register_name was "invalid", i.e. negative, or
greater than the total number of declared registers.  I don't believe
either of these cases can occur, and the previous commit asserts that
this is the case.  As a result we can simplify the code by removing
these checks.  In many cases, where the register names are held in an
array, I was able to add a static assert that the array contains the
correct number of strings, after that, a direct access into the array
is fine.

I don't have any means of testing these changes.

19 months agogdb/csky: remove nullptr return from csky_pseudo_register_name
Andrew Burgess [Thu, 1 Sep 2022 14:39:59 +0000 (15:39 +0100)] 
gdb/csky: remove nullptr return from csky_pseudo_register_name

Building on the previous commits, in this commit I remove two
instances of 'return NULL' from csky_pseudo_register_name, and replace
them with a return of the empty string.

These two are particularly interesting, and worth pulling into their
own commit, because these returns of NULL appear to be depended on
within other parts of the csky code.

In csky-linux-tdep.c in the register collect/supply code, GDB checks
for the register name being nullptr in order to decide if a target
supports a particular feature or not.  I've updated the code to check
for the empty string.

I have no way of testing this change.

19 months agogdb: add asserts to gdbarch_register_name
Andrew Burgess [Thu, 1 Sep 2022 13:01:11 +0000 (14:01 +0100)] 
gdb: add asserts to gdbarch_register_name

This commit adds asserts to gdbarch_register_name that validate the
parameters, and the return value.

The interesting thing here is that gdbarch_register_name is generated
by gdbarch.py, and so, to add these asserts, I need to update the
generation script.

I've added two new arguments for Functions and Methods (as declared in
gdbarch-components.py), these arguments are 'param_checks' and
'result_checks'.  Each of these new arguments can be used to list some
expressions that are then used within gdb_assert calls in the
generated code.

The asserts that validate the API as described in the comment I added
to gdbarch_register_name a few commits back; the register number
passed in needs to be a valid cooked register number, and the result
being returned should not be nullptr.

19 months agogdb: check for duplicate register names in selftest
Andrew Burgess [Wed, 31 Aug 2022 10:40:16 +0000 (11:40 +0100)] 
gdb: check for duplicate register names in selftest

Building on the previous commit, this commit extends the register_name
selftest to check for duplicate register names.

If two registers in the cooked register set (real + pseudo registers)
have the same name, then this will show up as duplicate registers in
the 'info all-registers' output, but the user will only be able to
interact with one copy of the register.

In this commit I extend the selftest that I added in the previous
commit to check for duplicate register names, I didn't include this
functionality in the previous commit because one architecture needed
fixing, and I wanted to keep those fixes separate from the fixes in
the previous commit.

The problematic architecture(s) are powerpc:750 and powerpc:604.  In
both of these cases the 'dabr' register appears twice, there's a
definition of dabr in power-oea.xml which is included into both
powerpc-604.xml and powerpc-750.xml.  Both of these later two xml
files also define the dabr register.

I'm hopeful that this change shouldn't break anything, but I don't
have the ability to actually test this change, however:

On the gdbserver side, neither powerpc-604.xml nor powerpc-750.xml are
mentioned in gdbserver/configure.srv, which I think means that
gdbserver will never use these descriptions, and,

Within GDB the problematic descriptions are held in the variables
tdesc_powerpc_604 and tdesc_powerpc_750, which are only mentioned in
the variants array in rs6000-tdep.c, this is used when looking up a
description based on the architecture.

For a native Linux target however, this will not be used as
ppc_linux_nat_target::read_description exists, which calls
ppc_linux_match_description, which I don't believe can return either
of the problematic descriptions.

This leaves the other native targets, FreeBSD, AIX, etc.  These don't
appear to override the ::read_description method, so will potentially
return the problematic descriptions, but, in each case I think the
::fetch_registers and ::store_registers methods will ignore the dabr
register, which will leave the register as <unavailable>.

So, my proposed solution is to just remove the duplicate register from
each of powerpc-604.xml and powerpc-750.xml, then regenerate the
corresponding C++ source file.  With this change made, the selftest
now passes for all architectures.

19 months agogdb: add a gdbarch_register_name self test, and fix some architectures
Andrew Burgess [Tue, 30 Aug 2022 14:21:47 +0000 (15:21 +0100)] 
gdb: add a gdbarch_register_name self test, and fix some architectures

This commit adds a self-test that checks that gdbarch_register_name
never returns nullptr for any valid register number.

Most architectures already met this requirement, there were just 6
that failed the new selftest, and are updated in this commit.

Beyond the self-tests I don't have any facilities to test that the
architectures I've adjusted still work correctly.

If you review all the various gdbarch_register_name implementations
then you will see that there are far more architectures that seem like
they might return nullptr in some situations, e.g. alpha, avr, bpf,
etc.  This commit doesn't attempt to address these cases as non of
them are hit during the selftest.  Many of these cases can never be
hit, for example, in alpha_register_name GDB checks for a register
number less than zero, this case can't happen and could be changed
into an assert.

A later commit in this series will have a general cleanup of all the
various register_name methods, and remove all references to NULL from
their code, however, as that commit will be mostly adjusting code that
is never hit, I want to keep those changes separate.

The selftest has been tested on x86-64, but I don't have access to
suitable systems to fully test any of the *-tdep.c code I've changed
in this commit.

19 months agogdb/gdbarch: add a comment to gdbarch_register_name
Andrew Burgess [Sun, 28 Aug 2022 20:19:50 +0000 (21:19 +0100)] 
gdb/gdbarch: add a comment to gdbarch_register_name

After the previous commit, this commit sets out to formalise the API
for gdbarch_register_name.  Not every architecture is actually in
compliance with the API I set out here, but I believe that most are.

I think architectures that don't comply with the API laid out here
will fail the gdb.base/completion.exp test.

The claims in the comment are I feel, best demonstrated with the
asserts in this code:

  const char *
  gdbarch_register_name (struct gdbarch *gdbarch, int regnr)
  {
    gdb_assert (regnr >= 0);
    gdb_assert (regnr < gdbarch_num_cooked_regs (gdbarch));

    const char *name = gdbarch->register_name (gdbarch, regnr);

    gdb_assert (name != nullptr);

    return name;
  }

Like I said, I don't believe every architecture follows these rules
right now, which is why I'm not actually adding any asserts.  Instead,
this commit adds a comment to gdbarch_register_name, this comment is
where I'd like to get to, rather than where we are right now.

Subsequent commits will fix all targets to be in compliance with this
comment, and will even add the asserts shown above to
gdbarch_register_name.

19 months agogdb/riscv: fix failure in gdb.base/completion.exp
Andrew Burgess [Sun, 28 Aug 2022 19:40:28 +0000 (20:40 +0100)] 
gdb/riscv: fix failure in gdb.base/completion.exp

I noticed a test failure in gdb.base/completion.exp for RISC-V on
a native Linux target, this is the failure:

  (gdb) FAIL: gdb.base/completion.exp: complete 'info registers '

The problem is caused by a mismatch in the output of 'maint print
registers' and the completion list for 'info registers'.  The 'info
registers' completion list contains less registers than
expected. Additionally, the list of registers extracted from the
'maint print registers' list was wrong too, in some cases the test was
grabbing the register number, rather than a register name,

Both of these problems have the same root cause, riscv_register_name
returns nullptr for some registers when it should return an empty
string.

The gdbarch_register_name API is not clearly documented anywhere, and
at first glance it would appear that the function can return either
nullptr, or an empty string to indicate that a register is not
available on the current target.  Indeed, there are plenty of places
in GDB where we compare the output of gdbarch_register_name to both
nullptr and '\0' in order to see if a register is supported or not,
and there are plenty of targets that return empty string in some
cases, and nullptr in others.

However, the 'info registers' completion code (reg_or_group_completer)
clearly depends on user_reg_map_regnum_to_name only returning nullptr
when the passed in regnum is greater than the maximum possible
register number (i.e. after all physical registers, pseudo-registers,
and user-registers), this means that gdbarch_register_name should not
be returning nullptr.

I did consider "fixing" user_reg_map_regnum_to_name, if
gdbarch_register_name returns nullptr, I could convert to an empty
string at this point, but that felt like a real hack, so I discarded
that plan.

The next possibility I considered was "fixing" reg_or_group_completer
to not rely on nullptr to indicate the end marker.  Or rather, I could
have reg_or_group_completer use gdbarch_num_cooked_regs, we know that
we should check at least that many register numbers.  Then, once we're
passed that limit, we keep checking until we hit a nullptr.  This
would absolutely work, and didn't actually feel that bad, but, it
still felt a little weird that gdbarch_register_name could return
nullptr OR the empty string to mean the same thing, so I wondered if
the "right" solution was to have gdbarch_register_name not return
nullptr.  With this in mind I tried an experiment:

I added a self-test that, for each architecture, calls
gdbarch_register_name for every register number up to the
gdbarch_num_cooked_regs limit, and checks that the name is not
nullptr.

Only a handful of architectures failed this test, RISC-V being one of
them.

This seems to suggest that most architectures agree that the correct
API for gdbarch_register_name is to return an empty string for
registers that are not supported on the current target, and that
returning nullptr is really a mistake.

In this commit I will update the RISC-V target so that GDB no longer
returns nullptr from riscv_register_name, instead we return the empty
string.

In subsequent commits I will add the selftest that I mention above,
and will fix the targets that fail the selftest.

With this change the gdb.base/completion.exp test now passes.

19 months agogdb/testsuite: rewrite capture_command_output proc
Andrew Burgess [Sun, 28 Aug 2022 19:21:07 +0000 (20:21 +0100)] 
gdb/testsuite: rewrite capture_command_output proc

I noticed a test failure in gdb.base/completion.exp for RISC-V on a
native Linux target.  Upon investigation I discovered a couple of
reasons for the failure, this commit addresses one of them.  A later
commit will address the other issue.

The completion.exp test makes use of the capture_command_output proc
to collect the output of the 'maint print registers' command.  For
RISC-V this command produces a lot of output.

Currently the capture_command_output proc tries to collect the
complete command output in a single expect buffer, and what I see is
an error caused by the expect buffer becoming full.

This commit rewrites capture_command_output to make use of
gdb_test_multiple to collect the command output line at a time, in
this way we avoid overflowing the expect buffer.

The capture_command_output proc has some logic for skipping a prefix
pattern, which is passed in to the proc as an argument.  In order to
handle this correctly (only matching the prefix at the start of the
command output), I use two gdb_test_multiple calls, the first spots
and discards the echoed command and the (optional) prefix pattern, the
second gdb_test_multiple call then collects the rest of the command
output line at a time until a prompt is seen.

There is one slight oddity with the current implementation, which I
have changed in my rewrite, this does, slightly, change the behaviour
of the proc.

The current implementation uses this pattern:

  -re "[string_to_regexp ${command}]\[\r\n\]+${prefix}(.*)\[\r\n\]+$gdb_prompt $"

Now a typical command output will look like this:

  output here\r\n
  (gdb)

As the TCL regexp matching is greedy, TCL will try to match as much as
possible in one part of the pattern before moving on to the next.
Thus, when this matches against (.*)[\r\n]+, the (.*) will end up
matching against 'output here\r' and the [\r\n]+ will match '\n' only.

In short the previous implementation would leave the '\r' on the end
of the returned text, but not the final trailing '\n'.

Now clearly I could make a new version of capture_command_output that
maintained this behaviour, but I couldn't see any reason to do this.
So, my new implementation drops the final '\r\n' completely, in our
example above we now return 'output here' with no '\r'.

This change doesn't seem to affect any of the existing tests, but I
thought it was worth mentioning.

19 months agogdb/mi: new options for -data-disassemble command
Andrew Burgess [Thu, 23 Jun 2022 13:49:55 +0000 (14:49 +0100)] 
gdb/mi: new options for -data-disassemble command

Now that the disassembler has two different strategies for laying out
the opcode bytes of an instruction (see /r vs /b for the disassemble
command), I wanted to add support for this to the MI disassemble
command.

Currently the -data-disassemble command takes a single 'mode' value,
which currently has 6 different values (0 -> 5), 3 of these modes
relate to opcode display.

So, clearly I should just add an additional 3 modes to handle the new
opcode format, right?

No, I didn't think that was a great idea either.

So, I wonder, could I adjust the -data-disassemble command in a
backward compatible way, that would allow GDB to move away from using
the mode value altogether?

I think we can.

In this commit, I propose adding two new options to -data-disassemble,
these are:

  --opcodes none|bytes|display
  --source

Additionally, I will make the mode optional, and default to mode 0 if
no mode value is given.  Mode 0 is the simplest, no source code, no
opcodes disassembly mode.

The two new options are only valid for mode 0, if they are used with
any other mode then an error is thrown.

The --opcodes option can add opcodes to the result, with 'bytes' being
equivalent to 'disassemble /b' and 'display' being 'disassemble /r'.

The --source option will enable the /s style source code display, this
is equivalent to modes 4 and 5.  There is no way, using the new
command options to get the now deprecated /m style source code
display, that is mode 1 and 3.

My hope is that new users of the MI will not use the mode at all, and
instead will just use the new options to achieve the output they need.
Existing MI users can continue to use the mode, and will not need to
be updated to use the new options.

19 months agogdb/mi: some int to bool conversion
Andrew Burgess [Thu, 23 Jun 2022 14:02:04 +0000 (15:02 +0100)] 
gdb/mi: some int to bool conversion

Just some simple int to bool conversion in mi_cmd_disassemble.  There
should be no user visible changes after this commit.

19 months agogdb/doc: update syntax of -data-disassemble command arguments
Andrew Burgess [Thu, 23 Jun 2022 12:57:57 +0000 (13:57 +0100)] 
gdb/doc: update syntax of -data-disassemble command arguments

The argument documentation for -data-disassemble looks like this:

   -data-disassemble
      [ -s @var{start-addr} -e @var{end-addr} ]
    | [ -a @var{addr} ]
    | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
    -- @var{mode}

However, I believe, according to the 'Notation and Terminology'
section, this means that the there are 3 optional location
specification argument groups for the command, followed by a
non-optional '-- mode'.

However, this is not true, one of the location specifications must be
given, i.e. we can't choose to give NO location specification, which
is what the above implies.

I propose that we change this to instead be:

   -data-disassemble
    ( -s @var{start-addr} -e @var{end-addr}
    | -a @var{addr}
    | -f @var{filename} -l @var{linenum} [ -n @var{lines} ] )
    -- @var{mode}

By placing all the location specifications within '( ... )' we
indication that these are a group, from which one of the options,
separated by '|', must be selected.

However, the 'Notation and Terminology' section only describes two
uses for parenthesis: '( GROUP )*' and '( GROUP )+', in the first case
GROUP is repeated zero or more times, and in the second GROUP is
repeated 1 or more times.

Neither of those exactly describe what I want, which is GROUP must
appear exactly once.  I propose to extend 'Notation and Terminology'
to include '( GROUP )' which means that GROUP should appear exactly
once.

This change is important because, in a later commit, I want to add
additional optional arguments to the -data-disassemble command, and
things start to get confusing with the original syntax.

19 months agogdb: make gdb_disassembly_flag unsigned
Andrew Burgess [Thu, 23 Jun 2022 11:19:52 +0000 (12:19 +0100)] 
gdb: make gdb_disassembly_flag unsigned

In a later commit I want to use operator~ on a gdb_disassembly_flag
flag value.  This is currently not possible as gdb_disassembly_flag
is, by default, signed.

This commit just makes this enum unsigned.

There should be no user visible changes after this commit.

19 months agogdb: disassembler opcode display formatting
Andrew Burgess [Tue, 21 Jun 2022 19:23:35 +0000 (20:23 +0100)] 
gdb: disassembler opcode display formatting

This commit changes the format of 'disassemble /r' to match GNU
objdump.  Specifically, GDB will now display the instruction bytes in
as 'objdump --wide --disassemble' does.

Here is an example for RISC-V before this patch:

  (gdb) disassemble /r 0x0001018e,0x0001019e
  Dump of assembler code from 0x1018e to 0x1019e:
     0x0001018e <call_me+66>:     03 26 84 fe     lw      a2,-24(s0)
     0x00010192 <call_me+70>:     83 25 c4 fe     lw      a1,-20(s0)
     0x00010196 <call_me+74>:     61 65   lui     a0,0x18
     0x00010198 <call_me+76>:     13 05 85 6a     addi    a0,a0,1704
     0x0001019c <call_me+80>:     f1 22   jal     0x10368 <printf>
  End of assembler dump.

And here's an example after this patch:

  (gdb) disassemble /r 0x0001018e,0x0001019e
  Dump of assembler code from 0x1018e to 0x1019e:
     0x0001018e <call_me+66>:     fe842603                lw      a2,-24(s0)
     0x00010192 <call_me+70>:     fec42583                lw      a1,-20(s0)
     0x00010196 <call_me+74>:     6561                    lui     a0,0x18
     0x00010198 <call_me+76>:     6a850513                addi    a0,a0,1704
     0x0001019c <call_me+80>:     22f1                    jal     0x10368 <printf>
  End of assembler dump.

There are two differences here.  First, the instruction bytes after
the patch are grouped based on the size of the instruction, and are
byte-swapped to little-endian order.

Second, after the patch, GDB now uses the bytes-per-line hint from
libopcodes to add whitespace padding after the opcode bytes, this
means that in most cases the instructions are nicely aligned.

It is still possible for a very long instruction to intrude into the
disassembled text space.  The next example is x86-64, before the
patch:

  (gdb) disassemble /r main
  Dump of assembler code for function main:
     0x0000000000401106 <+0>:     55      push   %rbp
     0x0000000000401107 <+1>:     48 89 e5        mov    %rsp,%rbp
     0x000000000040110a <+4>:     c7 87 d8 00 00 00 01 00 00 00   movl   $0x1,0xd8(%rdi)
     0x0000000000401114 <+14>:    b8 00 00 00 00  mov    $0x0,%eax
     0x0000000000401119 <+19>:    5d      pop    %rbp
     0x000000000040111a <+20>:    c3      ret
  End of assembler dump.

And after the patch:

  (gdb) disassemble /r main
  Dump of assembler code for function main:
     0x0000000000401106 <+0>:     55                      push   %rbp
     0x0000000000401107 <+1>:     48 89 e5                mov    %rsp,%rbp
     0x000000000040110a <+4>:     c7 87 d8 00 00 00 01 00 00 00   movl   $0x1,0xd8(%rdi)
     0x0000000000401114 <+14>:    b8 00 00 00 00          mov    $0x0,%eax
     0x0000000000401119 <+19>:    5d                      pop    %rbp
     0x000000000040111a <+20>:    c3                      ret
  End of assembler dump.

Most instructions are aligned, except for the very long instruction.
Notice too that for x86-64 libopcodes doesn't request that GDB group
the instruction bytes.  This matches the behaviour of objdump.

In case the user really wants the old behaviour, I have added a new
modifier 'disassemble /b', this displays the instruction byte at a
time.  For x86-64, which never groups instruction bytes, /b and /r are
equivalent, but for RISC-V, using /b gets the old layout back (except
that the whitespace for alignment is still present).  Consider our
original RISC-V example, this time using /b:

  (gdb) disassemble /b 0x0001018e,0x0001019e
  Dump of assembler code from 0x1018e to 0x1019e:
     0x0001018e <call_me+66>:     03 26 84 fe             lw      a2,-24(s0)
     0x00010192 <call_me+70>:     83 25 c4 fe             lw      a1,-20(s0)
     0x00010196 <call_me+74>:     61 65                   lui     a0,0x18
     0x00010198 <call_me+76>:     13 05 85 6a             addi    a0,a0,1704
     0x0001019c <call_me+80>:     f1 22                   jal     0x10368 <printf>
  End of assembler dump.

Obviously, this patch is a potentially significant change to the
behaviour or /r.  I could have added /b with the new behaviour and
left /r alone.  However, personally, I feel the new behaviour is
significantly better than the old, hence, I made /r be what I consider
the "better" behaviour.

The reason I prefer the new behaviour is that, when I use /r, I almost
always want to manually decode the instruction for some reason, and
having the bytes displayed in "instruction order" rather than memory
order, just makes this easier.

The 'record instruction-history' command also takes a /r modifier, and
has been modified in the same way as disassemble; /r gets the new
behaviour, and /b has been added to retain the old behaviour.

Finally, the MI command -data-disassemble, is unchanged in behaviour,
this command now requests the raw bytes of the instruction, which is
equivalent to the /b modifier.  This means that the MI output will
remain backward compatible.

19 months agogdb/disasm: read opcodes bytes with a single read_code call
Andrew Burgess [Thu, 23 Jun 2022 10:49:08 +0000 (11:49 +0100)] 
gdb/disasm: read opcodes bytes with a single read_code call

This commit reduces the number of times we call read_code when
printing the instruction opcode bytes during disassembly.

I've added a new gdb::byte_vector within the
gdb_pretty_print_disassembler class, in line with all the other
buffers that gdb_pretty_print_disassembler needs.  This byte_vector is
then resized as needed, and filled with a single read_code call for
each instruction.

There should be no user visible changes after this commit.

19 months agogdb/testsuite: new test for -data-disassemble opcodes format
Andrew Burgess [Wed, 22 Jun 2022 11:23:53 +0000 (12:23 +0100)] 
gdb/testsuite: new test for -data-disassemble opcodes format

Add another test for the output of MI command -data-disassemble.  The
new check validates the format of the 'opcodes' field, specifically,
this test checks that the field contains a series of bytes, separated
by a single space.

We also check that the bytes are in the correct order, that is, the
first byte is from the lowest address, and subsequent bytes are from
increasing addresses.

The motivation for this test (besides more tests being generally good)
is that I plan to make changes to how opcode bytes are displayed in
the disassembler output, and I want to ensure that I don't break any
existing MI behaviour.

There should be no user visible changes to GDB after this commit.

19 months agoAutomatic date update in version.in
GDB Administrator [Sun, 2 Oct 2022 00:00:18 +0000 (00:00 +0000)] 
Automatic date update in version.in

19 months agoAutomatic date update in version.in
GDB Administrator [Sat, 1 Oct 2022 00:00:12 +0000 (00:00 +0000)] 
Automatic date update in version.in

19 months agoRISC-V: Relax "fmv.[sdq]" requirements
Tsukasa OI [Tue, 1 Feb 2022 10:00:00 +0000 (19:00 +0900)] 
RISC-V: Relax "fmv.[sdq]" requirements

This commit relaxes requirements to "fmv.s" instructions from 'F' to ('F'
or 'Zfinx').  The same applies to "fmv.d" and "fmv.q".  Note that 'Zhinx'
extension already contains "fmv.h" instruction (as well as 'Zfh').

gas/ChangeLog:

* testsuite/gas/riscv/zfinx.s: Add "fmv.s" instruction.
* testsuite/gas/riscv/zfinx.d: Likewise.
* testsuite/gas/riscv/zdinx.s: Add "fmv.d" instruction.
* testsuite/gas/riscv/zdinx.d: Likewise.
* testsuite/gas/riscv/zqinx.d: Add "fmv.q" instruction.
* testsuite/gas/riscv/zqinx.s: Likewise.

opcodes/ChangeLog:

* riscv-opc.c (riscv_opcodes): Relax requirements to "fmv.[sdq]"
instructions to support those in 'Zfinx'/'Zdinx'/'Zqinx'.

19 months agoRISC-V: Reorganize and enhance 'Zfinx' tests
Tsukasa OI [Fri, 27 May 2022 11:25:53 +0000 (20:25 +0900)] 
RISC-V: Reorganize and enhance 'Zfinx' tests

This commit adds certain test cases for 'Zfinx'/'Zdinx'/'Zqinx' extensions
and reorganizes them, fixing coding style while improving coverage.
This is partially based on jiawei's 'Zhinx' testcases.

gas/ChangeLog:

* testsuite/gas/riscv/zfinx.s: Use different registers for
better encode space testing.  Make indentation consistent.
Add tests for instruction with rounding mode.  Change march
to minimum required extensions.  Remove source line.
* testsuite/gas/riscv/zfinx.d: Likewise.
* testsuite/gas/riscv/zdinx.s: Likewise.
* testsuite/gas/riscv/zdinx.d: Likewise.
* testsuite/gas/riscv/zqinx.s: Likewise.
Also use even-numbered registers to use valid register pairs.
* testsuite/gas/riscv/zqinx.d: Likewise.

Signed-off-by: Tsukasa OI <research_trasio@irq.a4lg.com>
Signed-off-by: jiawei <jiawei@iscas.ac.cn>
19 months agoRISC-V: Eliminate long-casts of X_add_number in diagnostics
Christoph Müllner [Fri, 30 Sep 2022 10:15:14 +0000 (12:15 +0200)] 
RISC-V: Eliminate long-casts of X_add_number in diagnostics

There is no need for casts to (signed/unsigned) long, as we can use
C99's PRId64/PRIu64 format specifiers.

19 months agoRISC-V: fallout from "re-arrange opcode table for consistent alias handling"
Jan Beulich [Fri, 30 Sep 2022 09:44:32 +0000 (11:44 +0200)] 
RISC-V: fallout from "re-arrange opcode table for consistent alias handling"

Several new testcasee have appeared since the submission of said change,
some of which now also need adjustment.

19 months agoRISC-V: fix build after "Add support for arbitrary immediate encoding formats"
Jan Beulich [Fri, 30 Sep 2022 09:43:59 +0000 (11:43 +0200)] 
RISC-V: fix build after "Add support for arbitrary immediate encoding formats"

Pre- and post-increment/decrement are side effects, the behavior of
which is undefined when combined with passing an address of the accessed
variable in the same function invocation. There's no need for the
increments here - simply adding 1 achieves the intended effect without
triggering compiler diagnostics (which are fatal with -Werror).

19 months agoobjcopy: avoid "shadowing" of remove() function name
Jan Beulich [Fri, 30 Sep 2022 08:55:02 +0000 (10:55 +0200)] 
objcopy: avoid "shadowing" of remove() function name

remove() is a standard library function (declared in stdio.h), which
triggers a "shadows a global declaration" warning with some gcc versions.

19 months agoRISC-V: drop stray INSN_ALIAS flags
Jan Beulich [Fri, 30 Sep 2022 08:20:17 +0000 (10:20 +0200)] 
RISC-V: drop stray INSN_ALIAS flags

FENCE.TSO isn't an alias. ZIP and UNZIP in the long run likely are, but
presently they aren't. This fixes disassembly of these insns with
-Mno-aliases.

19 months agoRISC-V: re-arrange opcode table for consistent alias handling
Jan Beulich [Fri, 30 Sep 2022 08:19:00 +0000 (10:19 +0200)] 
RISC-V: re-arrange opcode table for consistent alias handling

For disassembly to pick up aliases in favor of underlying insns (helping
readability in the common case), the aliases need to come ahead of the
"base" insns. Slightly more code movement is needed because of insns
with the same name needing to stay next to each other.

Note that the "rorw" alias entry also has the missing INSN_ALIAS added
here.

Clone a few testcases to exercise -Mno-aliases some more, better
covering the differences between the default and that disassembly mode.

19 months agox86: correct build dependencies in opcodes/
Jan Beulich [Fri, 30 Sep 2022 08:14:58 +0000 (10:14 +0200)] 
x86: correct build dependencies in opcodes/

With the command in the rule merely being "echo", i386-tbl.h won't be
rebuilt if missing, when at the same time i386-init.h is present and
up-to-date. Use a pattern rule instead to express the multiple targets
correctly (the &: rule separator is supported only by GNU make 4.3 and
newer). Note that now, for the opposite case to work (i386-tbl.h is
up-to-date but i386-init.h is missing), i386-init.h also needs
mentioning as a dependency somewhere: Add a fake dependency for
i386-opc.lo ("fake" because i386-opc.c doesn't include that header).

At the same time use $(AM_V_GEN) in the actual rule, replacing the
earlier (open-coded) "echo". And while there also drop a duplicate
dependency of i386-gen.o on i386-opc.h.

19 months agox86: improve match_template()'s diagnostics
Jan Beulich [Fri, 30 Sep 2022 08:13:39 +0000 (10:13 +0200)] 
x86: improve match_template()'s diagnostics

At the example of

extractps $0, %xmm0, %xmm0
insertps $0, %xmm0, %eax

(both having respectively the same mistake of using the wrong kind of
destination register) it is easy to see that current behavior is far
from ideal: The former results in "unsupported instruction" for 32-bit
code simply because the 2nd template we have is a Cpu64 one. Instead we
should aim at emitting the "best" possible error, which will typically
be the one where we passed the largest number of checks. Generalize the
original "specific_error" approach by making it apply to the entire
matching loop, utilizing that line numbers increase as we pass further
checks.

19 months agox86/Intel: restrict suffix derivation
Jan Beulich [Fri, 30 Sep 2022 08:12:45 +0000 (10:12 +0200)] 
x86/Intel: restrict suffix derivation

While in some cases deriving an AT&T-style suffix from an Intel syntax
memory operand size specifier is necessary, in many cases this is not
only pointless, but has led to the introduction of various workarounds:
Excessive use of IgnoreSize and NoRex64 as well as the ToDword and
ToQword attributes. Suppress suffix derivation when we can clearly tell
that the memory operand's size isn't going to be needed to infer the
possible need for the low byte/word opcode bit or an operand size prefix
(0x66 or REX.W).

As a result ToDword and ToQword can be dropped entirely, plus a fair
number of IgnoreSize and NoRex64 can also be got rid of. Note that
IgnoreSize needs to remain on legacy encoded SIMD insns with GPR
operand, to avoid emitting an operand size prefix in 16-bit mode. (Since
16-bit code using SIMD insns isn't well tested, clone an existing
testcase just enough to cover a few insns which are potentially
problematic but are being touched here.)

Note that while folding the VCVT{,T}S{S,D}2SI templates, VCVT{,T}SH2SI
isn't included there. This is to fulfill the request of not allowing L
and Q suffixes there, despite the inconsistency with VCVT{,T}S{S,D}2SI.

19 months agoLoongArch: Update ELF e_flags handling according to specification.
liuzhensong [Thu, 4 Aug 2022 06:30:39 +0000 (14:30 +0800)] 
LoongArch: Update ELF e_flags handling according to specification.

  Update handling of e_flags according to the documentation
  update [1] (discussions [2][3]).

  Object file bitness is now represented in the EI_CLASS byte.
  The e_flags field is now interpreted as follows:

  e_flags[2:0]: Base ABI modifier

  - 0x1: soft-float
  - 0x2: single-precision hard-float
  - 0x3: double-precision hard-float

  e_flags[7:6]: ELF object ABI version

  - 0x0: v0
  - 0x1: v1

  [1]: https://github.com/loongson/LoongArch-Documentation/blob/main/docs/LoongArch-ELF-ABI-EN.adoc#e_flags-identifies-abi-type-and-version
  [2]: https://github.com/loongson/LoongArch-Documentation/pull/61
  [3]: https://github.com/loongson/LoongArch-Documentation/pull/47

19 months agogprofng: fix cppcheck warnings
Vladimir Mezentsev [Thu, 29 Sep 2022 20:30:42 +0000 (13:30 -0700)] 
gprofng: fix cppcheck warnings

gprofng/ChangeLog
2022-09-29  Vladimir Mezentsev  <vladimir.mezentsev@oracle.com>

* common/hwcdrv.c: Fix cppcheck warning.
* src/ABS.h: Likewise.
* src/CompCom.cc: Likewise.

19 months ago[gdb/testsuite] Fix gdb.mi/mi-sym-info.exp on openSUSE Tumbleweed
Tom de Vries [Fri, 30 Sep 2022 04:04:56 +0000 (06:04 +0200)] 
[gdb/testsuite] Fix gdb.mi/mi-sym-info.exp on openSUSE Tumbleweed

On openSUSE Tumbleweed, I run into:
...
FAIL: gdb.mi/mi-sym-info.exp: List all functions from debug information only
...

The problem is in matching this string:
...
{name="_start",type="void (void)",description="void _start(void);"}
...
using regexp fun_re, which requires a line field:
...
set fun_re \
    "\{line=\"$decimal\",name=${qstr},type=${qstr},description=${qstr}\}"
...

Fix this by making the line field optional in fun_re.

Tested on x86_64-linux.

19 months agoRISC-V: Add privileged extensions without instructions/CSRs
Tsukasa OI [Sat, 10 Sep 2022 06:49:43 +0000 (06:49 +0000)] 
RISC-V: Add privileged extensions without instructions/CSRs

Currently, GNU Binutils does not support following privileged extensions:

-   'Smepmp'
-   'Svnapot'
-   'Svpbmt'

as they do not provide new CSRs or new instructions ('Smepmp' extends the
privileged architecture CSRs but does not define the CSR itself).  However,
adding them might be useful as we no longer have to "filter" ISA strings
just for toolchains (if full ISA string is given by a vendor, we can
straightly use it).

And there's a fact that supports this theory: there's already an
(unprivileged) extension which does not provide CSRs or instructions (but
only an architectural guarantee): 'Zkt' (constant timing guarantee for
certain subset of RISC-V instructions).

This simple commit simply adds three privileged extensions listed above.

bfd/ChangeLog:

* elfxx-riscv.c (riscv_supported_std_s_ext): Add 'Smepmp',
'Svnapot' and 'Svpbmt' extensions.

19 months agogdb: Remove unused extra_lines variable
Tsukasa OI [Sat, 24 Sep 2022 09:25:57 +0000 (09:25 +0000)] 
gdb: Remove unused extra_lines variable

Clang generates a warning if there is a variable that is set but not used
otherwise ("-Wunused-but-set-variable").  On the default configuration, it
causes a build failure (unless "--disable-werror" is specified).

The only extra_lines use in arrange_linetable function is removed on the
commit 558802e4d1c5dcbd0df7d2c6ef62a6deac247a2f
("gdb: change subfile::line_vector to an std::vector").  So, this variable
should be removed to prevent a build failure.

19 months ago[gdb/testsuite] Add aranges to gdb.dwarf2/dw2-dir-file-name.exp
Tom de Vries [Fri, 30 Sep 2022 03:58:43 +0000 (05:58 +0200)] 
[gdb/testsuite] Add aranges to gdb.dwarf2/dw2-dir-file-name.exp

Since commit 52b920c5d20 ("[gdb/testsuite] Fix gdb.dwarf2/dw2-dir-file-name.exp
for ppc64le"), the test-case fails with target board cc-with-debug-names, due
to missing .debug_aranges info.

Add the missing .debug_aranges info.

Also add a file_id option to Dwarf::assemble, to make it possible to contribute
to an already open file.

Tested on x86_64-linux.

19 months ago[gdb/c++] Print destructor the same for gcc and clang
Tom de Vries [Fri, 30 Sep 2022 03:47:54 +0000 (05:47 +0200)] 
[gdb/c++] Print destructor the same for gcc and clang

Consider the test-case contained in this patch.

With g++ (7.5.0) we have for "ptype A":
...
type = class A {
  public:
    int a;

    A(void);
    ~A();
}
...
and with clang++ (13.0.1):
...
type = class A {
  public:
    int a;

    A(void);
    ~A(void);
}
...
and we observe that the destructor is printed differently.

There's a difference in debug info between the two cases: in the clang case,
there's one artificial parameter, but in the g++ case, there are two, and
these similar cases are handled differently in cp_type_print_method_args.

This is due to this slightly convoluted bit of code:
...
  i = staticp ? 0 : 1;
  if (nargs > i)
    {
      while (i < nargs)
        ...
    }
  else if (varargs)
    gdb_printf (stream, "...");
  else if (language == language_cplus)
    gdb_printf (stream, "void");
...

The purpose of "i = staticp ? 0 : 1" is to skip the printing of the implicit
this parameter.

In commit 5f4d1085085 ("c++/8218: Destructors w/arguments"), skipping of other
artificial parameters was added, but using a different method: rather than
adjusting the potential loop start, it skips the parameter in the loop.

The observed difference in printing is explained by whether we enter the loop:
- in the clang case, the loop is not entered and we print "void".
- in the gcc case, the loop is entered, and nothing is printed.

Fix this by rewriting the code to:
- always enter the loop
- handle whether arguments need printing in the loop
- keep track of how many arguments are printed, and
  use that after the loop to print void etc.
such that we have the same for both gcc and clang:
...
    A(void);
    ~A(void);
...

Note that I consider the discussion of whether we want to print:
- A(void) / ~A(void), or
- A() / ~A()
out-of-scope for this patch.

Tested on x86_64-linux.

19 months agoPR29626, Segfault when disassembling ARM code
Alan Modra [Fri, 30 Sep 2022 00:56:30 +0000 (10:26 +0930)] 
PR29626, Segfault when disassembling ARM code

PR 29626
* arm-dis.c (mapping_symbol_for_insn): Return false on zero
symtab_size.  Delete later symtab_size test.

19 months agoAutomatic date update in version.in
GDB Administrator [Fri, 30 Sep 2022 00:00:13 +0000 (00:00 +0000)] 
Automatic date update in version.in

19 months agogdb: make target_auxv_parse static and rename
Simon Marchi [Thu, 29 Sep 2022 20:08:24 +0000 (16:08 -0400)] 
gdb: make target_auxv_parse static and rename

It is only used in auxv.c.  Also, given it is not strictly a wrapper
around target_ops::auxv (since 27a48a9223d0 "Add auxv parsing to the
architecture vector."), I think that the name prefixed with target is a
bit misleading.  Rename to just parse_auxv.

Change-Id: I41cca055b92c8ede37c258ba6583746a07d8f77e

19 months agogdb: make fprint_target_auxv static
Simon Marchi [Thu, 29 Sep 2022 19:19:23 +0000 (15:19 -0400)] 
gdb: make fprint_target_auxv static

It's only used in auxv.c.

Change-Id: I4992d9aae37b6631a074ab99bbab2f619725b642

19 months agogdb: constify auxv parse functions
Simon Marchi [Thu, 29 Sep 2022 19:13:09 +0000 (15:13 -0400)] 
gdb: constify auxv parse functions

Constify the input parameters of the various auxv parse functions, they
don't need to modify the raw auxv data.

Change-Id: I13eacd5ab8e925ec2b5c1f7722cbab39c41516ec

19 months agogdb: constify target_stack::is_pushed
Simon Marchi [Thu, 29 Sep 2022 20:39:13 +0000 (16:39 -0400)] 
gdb: constify target_stack::is_pushed

The target_ops parameters here can be made const.

Change-Id: Ibc18b17d6b21d06145251a03e68aca90538117d6

19 months agoConstify target_desc declarations
Keith Seitz [Fri, 9 Sep 2022 15:44:50 +0000 (08:44 -0700)] 
Constify target_desc declarations

This patch changes various global target_desc declarations to const, thereby
correcting a prominent source of ODR violations in PowerPC-related target code.
The majority of files/changes are mechanical const-ifications accomplished by
regenerating the C files in features/.

This also required manually updating mips-linux-tdep.h,  s390-linux-tdep.h,
nios2-tdep.h, s390-tdep.h, arch/ppc-linux-tdesc.h, arch/ppc-linux-common.c,
and rs6000-tdep.c.

Patch tested against the sourceware trybot, and fully regression tested against
our (Red Hat's) internal  test infrastructure on Rawhide aarch64, s390x, x86_64,
and powerpcle.

With this patch, I can finally enable LTO in our GDB package builds. [Tested
with a rawhide scratch build containing this patch.]

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

19 months agocleanup: Add missing feature/ XML files to Makefile
Keith Seitz [Mon, 12 Sep 2022 14:56:58 +0000 (07:56 -0700)] 
cleanup: Add missing feature/ XML files to Makefile

This patch adds some missing .xml files to features/Makefile so that when the
directory's C files are regenerated, all files are appropriately remade.

This has demonstrated that there have been several "misses" in regenerating
files in this directory. Namely, arm-secext.c and sparc{32,64}-solaris.c. For
the former case, there was what essentially amounts to a typo regarding the
create feature function's name. In the later case, this file has missed at least
one important update in July, 2020, when allocate_target_description was
changed to return a unique pointer.

Those corrections are included.

19 months agoAdd -B to the help output from gprof, and add suitable documentation.
Nick Clifton [Thu, 29 Sep 2022 12:12:37 +0000 (13:12 +0100)] 
Add -B to the help output from gprof, and add suitable documentation.

PR 29627
* gprof.c (usage): Add -B.
* gprof.texi (synopsis): Add -B.
(Output Options): Add entry for -B.

19 months agoAutomatic date update in version.in
GDB Administrator [Thu, 29 Sep 2022 00:00:20 +0000 (00:00 +0000)] 
Automatic date update in version.in

19 months agoFix GDB build: ELF support check & -lzstd
Pedro Alves [Wed, 28 Sep 2022 10:33:30 +0000 (11:33 +0100)] 
Fix GDB build: ELF support check & -lzstd

GDB fails to build for me, on Ubuntu 20.04.  I get:

 ...
   CXXLD  gdb
 /usr/bin/ld: linux-tdep.o: in function `linux_corefile_thread(thread_info*, linux_corefile_thread_data*)':
 /home/pedro/gdb/binutils-gdb/src/gdb/linux-tdep.c:1831: undefined reference to `gcore_elf_build_thread_register_notes(gdbarch*, thread_info*, gdb_signal, bfd*, std::unique_ptr<char, gdb::xfree_deleter<char> >*, int*)'
 /usr/bin/ld: linux-tdep.o: in function `linux_make_corefile_notes(gdbarch*, bfd*, int*)':
 /home/pedro/gdb/binutils-gdb/src/gdb/linux-tdep.c:2117: undefined reference to `gcore_elf_make_tdesc_note(bfd*, std::unique_ptr<char, gdb::xfree_deleter<char> >*, int*)'
 collect2: error: ld returned 1 exit status
 make[2]: *** [Makefile:2149: gdb] Error 1
 make[2]: Leaving directory '/home/pedro/gdb/binutils-gdb/build/gdb'
 make[1]: *** [Makefile:11847: all-gdb] Error 2
 make[1]: Leaving directory '/home/pedro/gdb/binutils-gdb/build'
 make: *** [Makefile:1004: all] Error 2

Those undefined functions exist in gdb/gcore-elf.c, which is only
included in the build if GDB's configure thinks that the target you're
configuring for is an ELF target.  GDB's configure thinks my system
isn't ELF, which is incorrect.

For the ELF support check, gdb/config.log shows:

 configure:17387: checking for ELF support in BFD
 configure:17407: gcc -o conftest -I/home/pedro/gdb/binutils-gdb/src/gdb/../include -I../bfd -I/home/pedro/gdb/binutils-gdb/src/gdb/../bfd -g3 -O0      -L../bfd -L../libiberty  -lzstd   conftest.c -lbfd -liberty -lz  -lncursesw -lm -ldl  >&5
 /usr/bin/ld: ../bfd/libbfd.a(compress.o): in function `decompress_contents':
 /home/pedro/gdb/binutils-gdb/src/bfd/compress.c:42: undefined reference to `ZSTD_decompress'
 /usr/bin/ld: /home/pedro/gdb/binutils-gdb/src/bfd/compress.c:44: undefined reference to `ZSTD_isError'
 /usr/bin/ld: ../bfd/libbfd.a(compress.o): in function `bfd_compress_section_contents':
 /home/pedro/gdb/binutils-gdb/src/bfd/compress.c:195: undefined reference to `ZSTD_compress'
 /usr/bin/ld: /home/pedro/gdb/binutils-gdb/src/bfd/compress.c:198: undefined reference to `ZSTD_isError'
 collect2: error: ld returned 1 exit status
 configure:17407: $? = 1
 ...
 configure:17417: result: no

Note how above, in the gcc command line, "-lzstd" appears before
"-lbfd".  That explain the link failure.  It should appear after, like
-lz does.

This commit fixes it, by moving ZSTD_LIBS from LDFLAGS to LIBS, next
to -lz, in GDB_AC_CHECK_BFD, and regenerating gdb/configure.

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

19 months agogdb: remove trailing spaces in README
Simon Marchi [Wed, 28 Sep 2022 13:58:51 +0000 (09:58 -0400)] 
gdb: remove trailing spaces in README

Change-Id: Ic7f8e415acd1bff6194cf08ed646bff45571f165

19 months agoTreat Character as a discrete type in Ada
Tom Tromey [Mon, 26 Sep 2022 14:24:14 +0000 (08:24 -0600)] 
Treat Character as a discrete type in Ada

A user noticed that gdb would assert when printing a certain array
with array-indexes enabled.  This turned out to be caused by the array
having an index type of Character, which is completely valid in Ada.
This patch changes the Ada support to recognize Character as a
discrete type, and adds some tests.

Because this is Ada-specific and was also reviewed internally, I am
checking it in.

19 months agoThe help document of size misses an option.
Nick Clifton [Wed, 28 Sep 2022 14:29:18 +0000 (15:29 +0100)] 
The help document of size misses an option.

PR 29628
* size.c (usage): Add -f.
* doc/binutils.texi (size): Add -f.

19 months agold/testsuite: force warnings when dealing with execstack tests
Clément Chigot [Wed, 14 Sep 2022 11:12:32 +0000 (13:12 +0200)] 
ld/testsuite: force warnings when dealing with execstack tests

Binutils can be configured to avoid printing the execstack or RWD
segment warnings. In this case, the first test of PR ld/29072 will fail.
Fix that by always manually forcing the warnings for it.

ld/ChangeLog:

* testsuite/ld-elf/elf.exp (PR ld/29072): Force execstack and
RWD segment warnings.

19 months agoRe: egrep in binutils
Alan Modra [Wed, 28 Sep 2022 13:26:41 +0000 (22:56 +0930)] 
Re: egrep in binutils

Multi-line patterns for grep are not supported on some old versions
of grep.

binutils/
* embedspu.sh: Replace multi-line grep with sed.
ld/
* testsuite/ld-elfvers/vers.exp: Replace multi-line grep with sed.

19 months agoRenenerate {gdb,gdbserver}/configure
Pedro Alves [Wed, 28 Sep 2022 10:35:06 +0000 (11:35 +0100)] 
Renenerate {gdb,gdbserver}/configure

Pick up config/lib-ld.m4 changes from:

 commit 67d1991b785bdfef1d70cddfa0202b99b43ccce9
 Author:     Alan Modra <amodra@gmail.com>
 AuthorDate: Wed Sep 28 13:37:31 2022 +0930
 Commit:     Alan Modra <amodra@gmail.com>
 CommitDate: Wed Sep 28 13:37:31 2022 +0930

     egrep in binutils

Change-Id: Ifc84d30f1fca015e80bafa80f9a35616b0077220

19 months agoThe help document of as misses some many options
Nick Clifton [Wed, 28 Sep 2022 11:56:04 +0000 (12:56 +0100)] 
The help document of as misses some many options

PR 29623
* as.c (show_usage): Document the --dump-config,
--gdwarf-cie-version, --hash-size, --multibyte-handling,
and --reduce-memory-overheads options.
* config/tc-i386.c (md_show_usage): Document the -O option.
* doc/as.texi: Document the --dump-config, --emulation,
--hash-size, and --reduce-memory-overheads options.

19 months agoegrep in binutils
Alan Modra [Wed, 28 Sep 2022 04:07:31 +0000 (13:37 +0930)] 
egrep in binutils

Apparently some distros have a nagging egrep that helpfully tells you
egrep is deprecated and to use "grep -E".  The nag message causes a ld
testsuite failure.  What's more the advice isn't that good.  The "-E"
flag may not be available with older versions of grep.

This patch fixes bare invocation of egrep within binutils, replacing
it with the autoconf $EGREP or with grep.

config/
* lib-ld.m4 (AC_LIB_PROG_LD_GNU): Require AC_PROG_EGREP and
invoke $EGREP.
(AC_LIB_PROG_LD): Likewise.
binutils/
* configure: Regenerate.
* embedspu.sh: Replace egrep with grep.
gold/
* testsuite/Makefile.am (flagstest_compress_debug_sections.check):
Replace egrep with grep.
* testsuite/Makefile.in: Regenerate.
* testsuite/bnd_ifunc_1.sh: Replace egrep with $EGREP.
* testsuite/bnd_ifunc_2.sh: Likewise.
* testsuite/bnd_plt_1.sh: Likewise.
* testsuite/discard_locals_test.sh: Likewise.
* testsuite/gnu_property_test.sh: Likewise.
* testsuite/no_version_test.sh: Likewise.
* testsuite/pr18689.sh: Likewise.
* testsuite/pr26936.sh: Likewise.
* testsuite/retain.sh: Likewise.
* testsuite/split_i386.sh: Likewise.
* testsuite/split_s390.sh: Likewise.
* testsuite/split_x32.sh: Likewise.
* testsuite/split_x86_64.sh: Likewise.
* testsuite/ver_test_pr16504.sh: Likewise.
intl/
* configure: Regenerate.
ld/
* testsuite/ld-elfvers/vers.exp (test_ar): Replace egrep with grep.

19 months agoregen bfd/configure
Alan Modra [Wed, 28 Sep 2022 00:28:37 +0000 (09:58 +0930)] 
regen bfd/configure

19 months agoasan: _bfd_stab_section_find_nearest_line segv
Alan Modra [Wed, 28 Sep 2022 00:22:22 +0000 (09:52 +0930)] 
asan: _bfd_stab_section_find_nearest_line segv

The segv was on "info->strs[strsize - 1] = 0;" with strsize zero.  OK,
if strsize is zero we don't have any filenames in stabs so no useful
info.

* syms.c (_bfd_stab_section_find_nearest_line): Exit if either
stabsize or strsize is zero.

19 months agoasan: segv in _bfd_archive_close_and_cleanup
Alan Modra [Tue, 27 Sep 2022 23:52:43 +0000 (09:22 +0930)] 
asan: segv in _bfd_archive_close_and_cleanup

Uninitialised arelt_data->parent_cache led to this segv.

* pdb.c (pdb_get_elt_at_index): Clear arelt_data.

19 months agoAutomatic date update in version.in
GDB Administrator [Wed, 28 Sep 2022 00:00:15 +0000 (00:00 +0000)] 
Automatic date update in version.in

19 months agosim: Link ZSTD_LIBS
Fangrui Song [Tue, 27 Sep 2022 18:42:32 +0000 (11:42 -0700)] 
sim: Link ZSTD_LIBS

This fixes linker errors in a `../../configure --enable-targets
--enable-sim; make all-gdb` build.

19 months agogold: Suppress "unused" variable warning on Clang
Tsukasa OI [Mon, 26 Sep 2022 10:35:40 +0000 (10:35 +0000)] 
gold: Suppress "unused" variable warning on Clang

Clang generates a warning if there is a variable that is set but not used
otherwise ("-Wunused-but-set-variable").  On the default configuration, it
causes a build failure (unless "--disable-werror" is specified).

Because the cause of this error is in the Bison-generated code
($(srcdir)/gold/yyscript.y -> $(builddir)/gold/yyscript.c),
this commit suppresses this warning ("-Wunused-but-set-variable") by placing
DIAGNOSTIC_IGNORE_UNUSED_BUT_SET_VARIABLE macro at the end of user
prologue on yyscript.y.

* yyscript.y: Suppress -Wunused-but-set-variable warning on
the Bison-generated code.

19 months agolibctf: Add ZSTD_LIBS to LIBS so that ac_cv_libctf_bfd_elf can be true
Fangrui Song [Tue, 27 Sep 2022 03:41:42 +0000 (20:41 -0700)] 
libctf: Add ZSTD_LIBS to LIBS so that ac_cv_libctf_bfd_elf can be true

19 months agobinutils, gdb: support zstd compressed debug sections
Fangrui Song [Tue, 27 Sep 2022 02:50:13 +0000 (19:50 -0700)] 
binutils, gdb: support zstd compressed debug sections

PR29397 PR29563: Add new configure option --with-zstd which defaults to
auto.  If pkgconfig/libzstd.pc is found, define HAVE_ZSTD and support
zstd compressed debug sections for most tools.

* bfd: for addr2line, objdump --dwarf, gdb, etc
* gas: support --compress-debug-sections=zstd
* ld: support ELFCOMPRESS_ZSTD input and --compress-debug-sections=zstd
* objcopy: support ELFCOMPRESS_ZSTD input for
  --decompress-debug-sections and --compress-debug-sections=zstd
* gdb: support ELFCOMPRESS_ZSTD input.  The bfd change references zstd
  symbols, so gdb has to link against -lzstd in this patch.

If zstd is not supported, ELFCOMPRESS_ZSTD input triggers an error.  We
can avoid HAVE_ZSTD if binutils-gdb imports zstd/ like zlib/, but this
is too heavyweight, so don't do it for now.

```
% ld/ld-new a.o
ld/ld-new: a.o: section .debug_abbrev is compressed with zstd, but BFD is not built with zstd support
...

% ld/ld-new a.o --compress-debug-sections=zstd
ld/ld-new: --compress-debug-sections=zstd: ld is not built with zstd support

% binutils/objcopy --compress-debug-sections=zstd a.o b.o
binutils/objcopy: --compress-debug-sections=zstd: binutils is not built with zstd support

% binutils/objcopy b.o --decompress-debug-sections
binutils/objcopy: zstd.o: section .debug_abbrev is compressed with zstd, but BFD is not built with zstd support
...
```

19 months agoPR29617, ld segfaults when bfd_close fails
Alan Modra [Tue, 27 Sep 2022 00:38:18 +0000 (10:08 +0930)] 
PR29617, ld segfaults when bfd_close fails

PR 29617
* ldmain.c (main): Don't access output_bfd after bfd_close.

19 months agoAutomatic date update in version.in
GDB Administrator [Tue, 27 Sep 2022 00:00:11 +0000 (00:00 +0000)] 
Automatic date update in version.in

19 months agogdb/testsuite: update field names in gdb-gdb.py.in
Simon Marchi [Fri, 23 Sep 2022 13:21:18 +0000 (09:21 -0400)] 
gdb/testsuite: update field names in gdb-gdb.py.in

Patches that renamed the type::length and type::target_type fields
didn't update gdb-gdb.py.in accordingly, do that.

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

19 months agogdb/testsuite: use gdb_test in gdb.gdb/python-helper.exp
Simon Marchi [Fri, 23 Sep 2022 13:29:47 +0000 (09:29 -0400)] 
gdb/testsuite: use gdb_test in gdb.gdb/python-helper.exp

If some command in there gives the wrong answer, we currently have to
wait for a timeout for the test to continue.  For instance, I currently
see:

    print *val->type
    $1 = Python Exception <class 'gdb.error'>: Cannot take address of method length.

    (outer-gdb) FAIL: gdb.gdb/python-helper.exp: pretty print type (timeout)

We can avoid this and modernize the test at the same time by using the
-prompt option of gdb_test.

gdb_test_no_output currently accepts a -prompt_re option (the variable
name passed to parse_args defines the option name), but I think
it's a typo.  It's supposed to be -prompt, like gdb_test.  I can't find
anything using -prompt_re using grep.  Change it to just "prompt".

Change-Id: Icc0a9a0ef482e62460c708bccdd544c11d711eca

19 months agogdb/testsuite: bump duration for the whole test in do_self_tests
Simon Marchi [Fri, 23 Sep 2022 13:45:24 +0000 (09:45 -0400)] 
gdb/testsuite: bump duration for the whole test in do_self_tests

When running gdb.gdb/python-helper.exp, I get some timeouts:

    continue
    Continuing.
    print 1

    FAIL: gdb.gdb/python-helper.exp: hit breakpoint in outer gdb (timeout)

At this time, GDB is actually processing the stop and reading in some
CUs.  selftest_setup does bump the timeout, but it's not for the whole
test.

Since debugging GDB with GDB is (unfortunately) a bit slow, bump the
timeout for the whole duration of the setup and body.  On my optimized
build, the command takes just a bit more than the current timeout of 10
seconds.  But it's much slower if running the test on an unoptimized
build, so I think it's necessary to bump the timeout for that in any
case.

Change-Id: I4d38285870e76c94f9d0bfdb60648a2e7f2cfa5d

19 months agobinutils/testsuite: handle the different install names of c++filt
Clément Chigot [Fri, 23 Sep 2022 09:52:54 +0000 (11:52 +0200)] 
binutils/testsuite: handle the different install names of c++filt

c++filt is always named cxxfilt in a build directory, but in a install
directory it would be named either cxxfilt or c++filt (depending on
the host).  Handle this last case in testsuite.

binutils/ChangeLog:
        *  testsuite/config/default.exp (CXXFILE): if cxxfilt not found,
        try c++filt.

19 months agobinutils/testsuite: skip gentestdlls related tests if missing
Clément Chigot [Fri, 16 Sep 2022 08:50:34 +0000 (10:50 +0200)] 
binutils/testsuite: skip gentestdlls related tests if missing

When launching the testsuite through runtest outside the build tree,
gentestdlls might not be available, this binary being created by make
check.
Simply untested the related tests instead of crashing.

binutils/ChangeLog:

* testsuite/binutils-all/objdump.exp: Skip dotnet tests if
gentestdlls is not available.

19 months ago[gdb/testsuite] Fix gdb.dwarf2/dw2-unspecified-type-foo.c with -m32
Tom de Vries [Mon, 26 Sep 2022 11:43:42 +0000 (13:43 +0200)] 
[gdb/testsuite] Fix gdb.dwarf2/dw2-unspecified-type-foo.c with -m32

When running test-case gdb.dwarf2/dw2-unspecified-type-foo.c with target board
unix/-m32, I run into:
...
(gdb) PASS: gdb.dwarf2/dw2-unspecified-type.exp: ptype foo
p ((int (*) ()) foo) ()^M
$1 = -135698472^M
...

Add the missing "return 0" in foo, which fixes this.

Tested on x86_64-linux.

19 months agoPR29613, use of uninitialized value in objcopy
Alan Modra [Mon, 26 Sep 2022 08:55:24 +0000 (18:25 +0930)] 
PR29613, use of uninitialized value in objcopy

PR 29613
* elf.c (_bfd_elf_write_secondary_reloc_section): Trim sh_size
back to relocs written.  Use better types for vars.