* NEWS: Document the new option.
* as.c (flag_compress_debug): Set default algorithm based
on the configure option.
* configure.ac: Add --enable-default-compressed-debug-sections-algorithm.
* configure: Regenerate.
* config.in: Likewise.
ld/ChangeLog:
* NEWS: Document the new option.
* configure.ac: Add --enable-default-compressed-debug-sections-algorithm.
* configure: Regenerate.
* config.in: Likewise.
* ldmain.c: Set default algorithm based
on the configure option.
some instructions in the RISC-V simulator stopped working as a new
instruction class 'INSN_CLASS_ZMMUL' was added, and some existing
instructions were moved into this class.
The simulator doesn't currently handle this instruction class, and so
the instructions will now cause an illegal instruction trap.
This commit adds support for INSN_CLASS_ZMMUL, and adds a test that
ensures the affected instructions can be executed by the simulator.
Reviewed-by: Palmer Dabbelt <palmer@rivosinc.com> Reviewed-by: Andrew Burgess <aburgess@redhat.com>
Tsukasa OI [Sun, 9 Oct 2022 03:57:12 +0000 (03:57 +0000)]
sim/moxie: add custom directory stamp rule
Because sim/moxie/moxie-gdb.dtb is neither a program nor a library, automake
does not generate dirstamp file ($builddir/sim/moxie/.dirstamp) for it.
When maintainer mode is enabled, it tries to rebuild sim/moxie/moxie-gdb.dtb
but fails because there's no rules for automake-generated dirstamp file
which moxie-gdb.dtb depends.
This commit adds its own rule for the directory stamp (modified copy of the
automake output) and adds the directory stamp file to DISTCLEANFILES to
mimic automake-generated behavior (although "make distclean" does not work
when maintainer mode is enabled).
Bruno Larsen [Tue, 11 Oct 2022 09:22:37 +0000 (11:22 +0200)]
gdb/testsuite: Fix formatting of python script
The python black formatter was complaining about formatting on the
script gdb.python/pretty-print-call-by-hand.py. This commit changed
the offending lines to make the formatter happy.
Tom de Vries [Tue, 11 Oct 2022 08:14:38 +0000 (10:14 +0200)]
[gdb/testsuite] Fix prompt parsing in capture_command_output
I noticed in capture_command_output that the output of a single command is
matched using two gdb_test_multiples:
- the first one matching the echoed command and skipping an optional prefix,
- the second one matching the output and the prompt.
This is error-prone, because the first gdb_test_multiple has implicit
clauses which may consume the prompt.
The problem is easy to spot with an example. First consider:
...
set output [capture_command_output "print 1" "\\\$1 = "]
gdb_assert { [string equal $output "1"] }
...
for which we get:
...
PASS: [string equal $output "1"]
...
If we change the prefix string to a no-match, say "1 = ", and update the
output string match accordingly, we get instead:
...
FAIL: capture_command_output for print 1
FAIL: [string equal $output "\$1 = 1"]
...
The first FAIL is produced by the first gdb_test_multiple, consuming the prompt.
The second gdb_test_multiple then silently times out waiting for another prompt,
after which the second FAIL is produced. Note that the timeout is silent
because the gdb_test_multiple is called with an empty message argument.
The second FAIL is because capture_command_output returns "", given that all
the command output was consumed by the first gdb_test_multiple.
Fix this by rewriting capture_command_output to use only a single
gdb_test_multiple.
gprofng/ChangeLog
2022-10-10 Vladimir Mezentsev <vladimir.mezentsev@oracle.com>
PR gprofng/29107
* testsuite/config/default.exp: Set up environment to run gprofng tests
without installation.
* testsuite/lib/Makefile.skel: Likewise.
* testsuite/lib/display-lib.exp: Likewise.
+ sleep 2
set result 0
set code [catch {gdb_expect $code} string]
"recent enough" means a system where libpthread.so was merged with
libc.so, so at least glibc 2.34.
The problem is that the `run &` command prints some things after the
prompt:
(gdb) [Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/../lib/libthread_db.so.1".
If expect is quick enough, it will consume only up to the prompt. But
if it is slow enough, it will consume those messages at the same time as
the prompt, in which case the gdb_test used for "run &" won't match. By
default, the prompt used by gdb_test uses a `$` to anchor the match at
the end of the buffer. If there's anything following the prompt, it
won't match.
The diff above adds a delay between sending the command and consuming
the output, giving GDB more time to output the messages, giving a good
chance that expect consumes them at the same time as the prompt.
This is normally handled by using gdb_test_multiple and specifying a
pattern that ends with "$gdb_prompt", but not a trailing $. I think
this is common enough that it deserves its own gdb_test option.
Therefore, add the -no-anchor-prompt option to gdb_test, and
gdb_test_no_output for completeness. Use it in
gdb.base/async-shell.exp.
Change-Id: I9051d8800d1c10a2e95db1a575991f7723492f1b Approved-By: Tom de Vries <tdevries@suse.de>
Tom Tromey [Sun, 13 Feb 2022 01:41:34 +0000 (18:41 -0700)]
Fix a latent bug in print_wchar
print_wchar keeps track of when escape sequences are emitted, to force
an escape sequence if needed by a subsequent character. For example
for the string concatenation "\0" "1", gdb will print "\000\061" --
because printing "\0001" might be confusing.
However, this code has two errors. First, this logic is not needed
for octal escapes, because there is a length limit of 3 for octal
escapes, and gdb always prints these with "%.3o". Second, though,
this *is* needed for hex escapes, because those do not have a length
limit.
This patch fixes these problems and adds the appropriate tests.
Tom Tromey [Sat, 12 Feb 2022 01:24:23 +0000 (18:24 -0700)]
Don't use wchar_printable in print_wchar
print_wchar uses wchar_printable, but this isn't needed -- all the
relevant cases are already handled by the 'switch'. This changes the
code to use gdb_iswprint, and removes a somewhat confusing comment
related to this code.
Tom Tromey [Thu, 27 Jan 2022 01:07:18 +0000 (18:07 -0700)]
Fix latent quote char bug in generic_printstr
generic_printstr prints an empty string like:
fputs_filtered ("\"\"", stream);
However, this seems wrong to me if the quote character is something
other than double quote. This patch fixes this latent bug. Thanks to
Andrew for the test case.
Co-authored-by: Andrew Burgess <aburgess@redhat.com>
Tom Tromey [Mon, 10 Oct 2022 13:47:32 +0000 (07:47 -0600)]
Fix the guile build
The frame_info_ptr patches broke the build with Guile. This patch
fixes the problem. In mos cases I chose to preserve the use of
frame_info_ptr, at least where I could be sure that the object
lifetime did not interact with Guile's longjmp-based exception scheme.
Tom de Vries [Mon, 10 Oct 2022 12:44:40 +0000 (14:44 +0200)]
[gdb/testsuite] Fix error message for cmd with trailing newline
I noticed that the error message in gdb_test_multiple about trailing newline
in a command does not mention the offending command, nor the word command:
...
if [string match "*\[\r\n\]" $command] {
error "Invalid trailing newline in \"$message\" test"
}
...
Fix this by using instead:
...
error "Invalid trailing newline in \"$command\" command"
...
Also add a test-case to trigger this: gdb.testsuite/gdb-test.exp.
Andrew Burgess [Wed, 5 Oct 2022 14:26:11 +0000 (15:26 +0100)]
gdb: include the base address in in-memory bfd filenames
The struct target_buffer (in gdb_bfd.c) is used to hold information
about an in-memory BFD object created by GDB. For now this mechanism
is used by GDB when loading information about JIT symfiles.
This commit updates target_buffer (in gdb_bfd.c) to be more C++ like,
and, at the same time, adds the base address of the symfile into the
BFD filename.
Right now, every in-memory BFD is given the filename "<in-memory>".
This filename is visible in things like 'maint info symtabs' and
'maint info line-table'. If there are multiple in-memory BFD objects
then it can be hard to match keep track if which BFD is which. This
commit changes the name to be "<in-memory@ADDRESS>" where ADDRESS is
replaced with the base address for where the in-memory symbol file was
read from.
As an example of how this is useful, here's the output of 'maint info
jit' showing a single loaded JIT symfile:
I've added a new test that checks the new in-memory file names are
generated correctly, and also checks that the in-memory JIT files can
be dumped back out using 'dump binary memory'.
Andrew Burgess [Wed, 5 Oct 2022 14:25:59 +0000 (15:25 +0100)]
gdb: remove filename arg from gdb_bfd_open_from_target_memory
The filename argument to gdb_bfd_open_from_target_memory was never
used; this argument had a default value of nullptr, and the only call
to this function, in jit.c, relied on the default value.
In the next commit I'm going to make some changes to the
gdb_bfd_open_from_target_memory function, and, though I could take
account of a filename parameter, it seems pointless to maintain an
unused argument.
This commit removes the filename argument.
There should be no user visible changes after this commit.
Andrew Burgess [Tue, 10 May 2022 14:16:46 +0000 (15:16 +0100)]
gdb: add infcall specific debugging
Add two new commands:
set debug infcall on|off
show debug infcall
These enable some new debugging related to when GDB makes inferior
function calls. I've added some basic debugging for what I think are
the major steps in the inferior function call process, but I'm sure we
might want to add more later.
Andrew Burgess [Tue, 10 May 2022 14:15:44 +0000 (15:15 +0100)]
gdb: improve infrun_debug_show_threads output
This commit switches to use INFRUN_SCOPED_DEBUG_START_END in the
infrun_debug_show_threads function, which means the output will get an
extra level of indentation, this looks a little nicer I think.
Nick Clifton [Mon, 10 Oct 2022 10:28:45 +0000 (11:28 +0100)]
Add ability to create reproducible source tarballs.
* src-release.sh: Add "-r <date>" option to create reproducible
tarballs based upon a fixed timestamp of <date>.
* binutils/README-how-to-make-a-release: Add a line showing how to
use -r <date> when creating a binutils release.
Bruno Larsen [Mon, 25 Jul 2022 17:06:37 +0000 (14:06 -0300)]
gdb/frame: Add reinflation method for frame_info_ptr
Currently, despite having a smart pointer for frame_infos, GDB may
attempt to use an invalidated frame_info_ptr, which would cause internal
errors to happen. One such example has been documented as PR
python/28856, that happened when printing frame arguments calls an
inferior function.
To avoid failures, the smart wrapper was changed to also cache the frame
id, so the pointer can be reinflated later. For this to work, the
frame-id stuff had to be moved to their own .h file, which is included
by frame-info.h.
Frame_id caching is done explicitly using the prepare_reinflate method.
Caching is done manually so that only the pointers that need to be saved
will be, and reinflating has to be done manually using the reinflate
method because the get method and the -> operator must not change
the internals of the class. Finally, attempting to reinflate when the
pointer is being invalidated causes the following assertion errors:
As for performance concerns, my personal testing with `time make
chec-perf GDB_PERFTEST_MODE=run` showed an actual reduction of around
10% of time running.
This commit also adds a testcase that exercises the python/28856 bug with
7 different triggers, run, continue, step, backtrace, finish, up and down.
Some of them can seem to be testing the same thing twice, but since this
test relies on stale pointers, there is always a chance that GDB got lucky
when testing, so better to test extra.
Regression tested on x86_64, using both gcc and clang.
Tom Tromey [Mon, 25 Jul 2022 17:06:35 +0000 (14:06 -0300)]
Change GDB to use frame_info_ptr
This changes GDB to use frame_info_ptr instead of frame_info *
The substitution was done with multiple sequential `sed` commands:
sed 's/^struct frame_info;/class frame_info_ptr;/'
sed 's/struct frame_info \*/frame_info_ptr /g' - which left some
issues in a few files, that were manually fixed.
sed 's/\<frame_info \*/frame_info_ptr /g'
sed 's/frame_info_ptr $/frame_info_ptr/g' - used to remove whitespace
problems.
The changed files were then manually checked and some 'sed' changes
undone, some constructors and some gets were added, according to what
made sense, and what Tromey originally did
Co-Authored-By: Bruno Larsen <blarsen@redhat.com> Approved-by: Tom Tomey <tom@tromey.com>
Tom Tromey [Mon, 25 Jul 2022 17:06:34 +0000 (14:06 -0300)]
Introduce frame_info_ptr smart pointer class
This adds frame_info_ptr, a smart pointer class. Every instance of
the class is kept on an intrusive list. When reinit_frame_cache is
called, the list is traversed and all the pointers are invalidated.
This should help catch the typical GDB bug of keeping a frame_info
pointer alive where a frame ID was needed instead.
Co-Authored-By: Bruno Larsen <blarsen@redhat.com> Approved-by: Tom Tomey <tom@tromey.com>
Tom Tromey [Mon, 25 Jul 2022 17:06:33 +0000 (14:06 -0300)]
Remove frame_id_eq
This replaces frame_id_eq with operator== and operator!=. I wrote
this for a version of this series that I later abandoned; but since it
simplifies the code, I left this patch in.
Andrew Burgess [Sat, 8 Oct 2022 15:58:00 +0000 (16:58 +0100)]
gdb/testsuite: use 'end' at the end of python blocks
Within the testsuite, use the keyword 'end' to terminate blocks of
Python code being sent to GDB, rather than sending \004. I could only
find three instances of this, all in tests that I originally wrote. I
have no memory of there being any special reason why I used \004
instead of 'end' - I assume I copied this from somewhere else that has
since changed.
Non of the tests being changed here are specifically about whether
\004 can be used to terminate a Python block, so I think switching to
the more standard 'end' keyword is the right choice.
Alan Modra [Mon, 10 Oct 2022 00:38:40 +0000 (11:08 +1030)]
Merge configure.ac from gcc project
To merge with gcc's copy of configure.ac we need to revert changes to
configure.ac in the following gcc commits: dc832fb39fc0 2022-08-25 fc259b522c0f 2022-06-25
Then reapply configure.ac changes in binutils from these binutils
commits: 50ad1254d503 2021-01-09 bb368aad297f 2022-03-11 e5f2f7d901ee 2022-07-26 2cac01e3ffff 2022-09-26
Plus copy over gcc's config/ax_cxx_compile_stdcxx.m4, then regenerate
configure.
Tom Tromey [Fri, 23 Sep 2022 22:23:41 +0000 (16:23 -0600)]
Merge both implementations of debug_names::insert
The class debug_names has two 'insert' overloads, but only one of them
is ever called externally, and it simply forwards to the other
implementation. It seems cleaner to me to have a single method, so
this patch merges the two.
Tom de Vries [Sat, 8 Oct 2022 08:47:47 +0000 (10:47 +0200)]
[gdb/testsuite] Fix silent fail in gdb.server/connect-with-no-symbol-file.exp
With native and target boards native-gdbserver, remote-gdbserver-on-localhost and
remote-stdio-gdbserver I have for gdb.server/connect-with-no-symbol-file.exp:
...
# of expected passes 8
...
but with native-extended-gdbserver I have instead:
...
# of expected passes 8
# of unexpected failures 4
...
The extra FAILs are of the form:
...
(gdb) detach^M
Detaching from pid process 28985^M
[Inferior 1 (process 28985) detached]^M
(gdb) FAIL: gdb.server/connect-with-no-symbol-file.exp: sysroot=: \
action=permission: connection to GDBserver succeeded
...
and are due to the fact that the actual gdb output doesn't match the regexp:
...
gdb_test "detach" \
".*Detaching from program: , process.*Ending remote debugging.*" \
"connection to GDBserver succeeded"
...
With native, the actual gdb output is:
...
(gdb) detach^M
Detaching from pid process 29657^M
Ending remote debugging.^M
[Inferior 1 (process 29657) detached]^M
(gdb) Remote debugging from host ::1, port 51028^M
...
and because the regexp doesn't match, it triggers an implicit clause for
"Ending remote debugging" in gdb_test_multiple, which has the consequence
that the FAIL is silent.
Fix:
- the regexp by making it less strict
- the silent fail by rewriting into a gdb_test_multiple, and adding an
explicit fail clause.
Tested on x86_64-linux, using native and aforementioned target boards.
Lancelot SIX [Fri, 7 Oct 2022 13:44:40 +0000 (14:44 +0100)]
gdb/testsuite: fix gdb.threads/linux-dp.exp regex
On ubuntu 22.04 with the libc6-dbg package installed, I have the
following failure:
where
#0 print_philosopher (n=3, left=33 '!', right=33 '!') at .../gdb/testsuite/gdb.threads/linux-dp.c:105
#1 0x000055555555576a in philosopher (data=0x55555555937c) at .../gdb/testsuite/gdb.threads/linux-dp.c:148
#2 0x00007ffff7e11b43 in start_thread (arg=<optimized out>) at ./nptl/pthread_create.c:442
#3 0x00007ffff7ea3a00 in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:81
(gdb) FAIL: gdb.threads/linux-dp.exp: first thread-specific breakpoint hit
The regex for this test accounts for different situations (with /
without debug symbol) but assumes that if debug info is present the
backtrace shows execution under pthread_create. However, for the
implementation under test, we are under start_thread.
Update the regex to accept start_thread.
Tested on Ubuntu-22.04 x86_64 with and without libc6-dbg debug symbols
available.
Tom de Vries [Fri, 7 Oct 2022 16:08:00 +0000 (18:08 +0200)]
[gdb/testsuite] Handle host cleanfiles
When running test-case gdb.server/abspath.exp with host board
local-remote-host-notty, I get:
...
$ git sti
...
deleted: gdb/testsuite/gdb.xml/trivial.xml
...
This happens as follows. The test-case calls skip_gdbserver_test, which calls
gdb_skip_xml_test, which does:
...
set xml_file [gdb_remote_download host "${srcdir}/gdb.xml/trivial.xml"]
...
Then proc gdb_remote_download appends $xml_file (which for this particular
host board happens to be ${srcdir}/gdb.xml/trivial.xml) to cleanfiles, which
ends up being handled in gdb_finish by:
...
eval remote_file target delete $cleanfiles
...
The problem is that a host file is deleted using target delete.
Fix this by splitting cleanfiles up in cleanfiles_target and cleanfiles_host.
Tom de Vries [Fri, 7 Oct 2022 14:17:35 +0000 (16:17 +0200)]
[gdb/testsuite] Remove unnecessary warning in gdb.base/default.exp
When running test-case gdb.base/default.exp with target board
native-gdbserver, we get:
...
WARNING: Skipping backtrace and break tests because of GDB stub.
...
There's no need for such a warning, so remove it.
Tested on x86_64-linux with native and target board native-gdbserver.
Tom de Vries [Fri, 7 Oct 2022 14:17:35 +0000 (16:17 +0200)]
[gdb/testsuite] Fix have_mpx with remote-gdbserver-on-localhost
With target board remote-gdbserver-on-localhost and gdb.arch/i386-mpx-call.exp
I run into:
...
FAIL: gdb.arch/i386-mpx-call.exp: upper_bnd0: continue to a bnd violation
...
This is due to the have_mpx test which should return 0, but instead returns 1
because the captured output:
...
No MPX support
No MPX support
...
does not match the used regexp:
...
set status [expr ($status == 0) \
&& ![regexp "^No MPX support\r\n" $output]]
...
which does match the captured output with native:
...
No MPX support^M
No MPX support^M
...
Fix this by making the \r in the regexp optional.
Tested on x86_64-linux, with native and target board
remote-gdbserver-on-localhost.
Tom de Vries [Fri, 7 Oct 2022 14:17:34 +0000 (16:17 +0200)]
[gdb/testsuite] Fix path in test name in gdb_load_shlib
When running test-case gdb.server/solib-list.exp with target board
remote-gdbserver-on-localhost, I run into:
...
(gdb) set solib-search-path $outputs/gdb.server/solib-list^M
(gdb) PASS: gdb.server/solib-list.exp: non-stop 0: \
set solib-search-path $outputs/gdb.server/solib-list
PATH: gdb.server/solib-list.exp: non-stop 0: \
set solib-search-path $outputs/gdb.server/solib-list
...
This is due to this code in gdb_load_shlib:
...
gdb_test "set solib-search-path [file dirname $file]" "" ""
...
Fix this by setting an explicit test name.
Tested on x86_64-linux, with native and target boards
remote-gdbserver-on-localhost, native-gdbserver and native-extended-gdbserver.
Alan Modra [Thu, 6 Oct 2022 23:53:05 +0000 (10:23 +1030)]
PR29653, objcopy/strip: fuzzed small input file induces large output file
_bfd_check_format functions should not print errors or warnings if
they return NULL. A NULL return means the particular target under
test does not match, so there isn't any reason to make a complaint
about the target. In fact there isn't a good reason to warn even if
the target matches, except via the _bfd_per_xvec_warn mechanism; Some
other target might be a better match.
This patch tidies pe_bfd_object_p with the above in mind, and
restricts the PE optional header SectionAlignment and FileAlignment
fields somewhat. I chose to warn on nonsense values rather than
refusing to match. Refusing to match would be OK too.
PR 29653
* peXXigen.c (_bfd_XXi_swap_aouthdr_in): Don't emit error about
invalid NumberOfRvaAndSizes here. Limit loop copying data
directory to IMAGE_NUMBEROF_DIRECTORY_ENTRIES.
* peicode.h (pe_bfd_object_p): Don't clear and test bfd_error
around bfd_coff_swap_aouthdr_in. Warn on invalid SectionAlignment,
FileAlignment and NumberOfRvaAndSizes. Don't return NULL on
invalid NumberOfRvaAndSizes.
Read LSPEN, ASPEN and LSPACT bits from FPCCR and use them together
with FPCAR to identify if lazy FPU state preservation is active for
the current frame. See "Lazy context save of FP state", in B1.5.7,
also ARM AN298, supported by Cortex-M4F architecture for details on
lazy FPU register stacking. The same conditions are valid for other
Cortex-M cores with FPU.
This patch has been verified on a STM32F4-Discovery board by:
a) writing a non-zero value (lets use 0x1122334455667788 as an
example) to all the D-registers in the main function
b) configured the SysTick to fire
c) in the SysTick_Handler, write some other value (lets use
0x0022446688aaccee as an example) to one of the D-registers (D0 as
an example) and then do "SVC #0"
d) in the SVC_Handler, write some other value (lets use
0x0099aabbccddeeff) to one of the D-registers (D0 as an example)
In GDB, suspend the execution in the SVC_Handler function and compare
the value of the D-registers for the SVC_handler frame and the
SysTick_Handler frame. With the patch, the value of the modified
D-register (D0) should be the new value (0x009..eff) on the
SVC_Handler frame, and the intermediate value (0x002..cee) for the
SysTick_Handler frame. Now compare the D-register value for the
SysTick_Handler frame and the main frame. The main frame should
have the initial value (0x112..788).
Tom de Vries [Thu, 6 Oct 2022 12:53:07 +0000 (14:53 +0200)]
[gdb/symtab] Factor out have_complaint
After committing 8ba677d3560 ("[gdb/symtab] Don't complain about function
decls") I noticed that quite a bit of code in read_func_scope is used to decide
whether to issue the "cannot get low and high bounds for subprogram DIE at
$hex" complaint, which executes unnecessarily if we have the default
"set complaints 0".
Fix this by (NFC):
- factoring out new static function have_complaint from macro complaint, and
- using it to wrap the relevant code in read_func_scope.
Andrew Burgess [Tue, 4 Oct 2022 12:51:46 +0000 (13:51 +0100)]
gdb: more infrun debug from breakpoint.c
This commit adds additional infrun debug from the breakpoint.c file.
The new debug output all relates to breakpoint condition evaluation.
There is already some infrun debug emitted from the breakpoint.c file,
so hopefully, adding more will not be contentious. I think the
functions being instrumented make sense as part of the infrun process,
the inferior stops, evaluates the condition, and then either stops or
continues. This new debug gives more insight into that process.
I had to make the bp_location* argument to find_loc_num_by_location
const, and add a declaration for find_loc_num_by_location.
There should be no user visible changes unless they turn on debug
output.
Tsukasa OI [Mon, 26 Sep 2022 11:13:51 +0000 (11:13 +0000)]
RISC-V: Fix T-Head immediate types on printing
This commit fixes two minor typing-related issues for
T-Head immediate operands.
1. A signed type must be specified when printing with %i.
2. unsigned/signed int is not portable enough for max 32-bit immediates.
Instead, we should use unsigned/signed long.
The format string is changed accordingly.
opcodes/ChangeLog:
* riscv-dis.c (print_insn_args): Fix T-Head immediate types on
printing.
Tsukasa OI [Tue, 2 Aug 2022 08:51:44 +0000 (17:51 +0900)]
RISC-V: Print comma and tabs as the "text" style
On the RISC-V disassembler, some separators have non-text style when
printed with another word with another style.
This commit splits those, making sure that those comma and tabs are printed
with the "text" style.
opcodes/ChangeLog:
* riscv-dis.c (print_insn_args): Split and print the comma as
text. (riscv_disassemble_insn): Split and print tabs as text.
(riscv_disassemble_data): Likewise.
Tsukasa OI [Tue, 2 Aug 2022 08:18:33 +0000 (17:18 +0900)]
RISC-V: Optimize riscv_disassemble_data printf
This commit makes types of printf arguments on riscv_disassemble_data
as small as possible (as long as we can preserve the portability) to reduce
the cost of printf (especially on 32-bit host).
opcodes/ChangeLog:
* riscv-dis.c (riscv_disassemble_data): Use smallest possible type
to printing data.
Alan Modra [Wed, 5 Oct 2022 23:15:56 +0000 (09:45 +1030)]
Re: bfd BLD-POTFILES.in dependencies
Removing $BLD_POTFILES from BFD-POTFILES.in was correct, but left a
hole in dependencies.
make[4]: Entering directory '/home/alan/build/gas/all/bfd/po'
make[4]: *** No rule to make target '../elf32-aarch64.c', needed by '/home/alan/src/binutils-gdb/bfd/po/bfd.pot'. Stop.
Jan Beulich [Wed, 5 Oct 2022 07:16:24 +0000 (09:16 +0200)]
x86/gas: support quoted address scale factor in AT&T syntax
An earlier attempt (e68c3d59acd0 ["x86: better respect quotes in
parse_operands()"]) needed undoing (cc0f96357e0b ["x86: permit
parenthesized expressions again as addressing scale factor"]) as far its
effect here went. As indicated back then, the issue is the backwards
scanning of the operand string to find the matching opening parenthesis.
Switch to forward scanning, finding the last outermost unquoted opening
parenthesis (which is the one matching the trailing closing one).
Tom de Vries [Tue, 4 Oct 2022 14:51:03 +0000 (16:51 +0200)]
[gdb/symtab] Don't complain about function decls
[ Requires "[gdb/symtab] Don't complain about inlined functions" as
submitted here (
https://sourceware.org/pipermail/gdb-patches/2022-September/191762.html ). ]
With the test-case included in this patch, we get:
...
(gdb) ptype main^M
During symbol reading: cannot get low and high bounds for subprogram DIE \
at 0xc1^M
type = int (void)^M
(gdb) FAIL: gdb.dwarf2/anon-ns-fn.exp: ptype main without complaints
...
The DIE causing the complaint is a function declaration:
...
<2><c1>: Abbrev Number: 3 (DW_TAG_subprogram)
<c2> DW_AT_name : foo
<c8> DW_AT_declaration : 1
...
which is referred to from the DIE representing the function definition:
...
<1><f4>: Abbrev Number: 7 (DW_TAG_subprogram)
<f5> DW_AT_specification: <0xc1>
<f9> DW_AT_low_pc : 0x4004c7
<101> DW_AT_high_pc : 0x7
...
which does contain the low and high bounds.
Fix this by not complaining about function declarations.
Tom de Vries [Tue, 4 Oct 2022 14:51:03 +0000 (16:51 +0200)]
[gdb/symtab] Don't complain about inlined functions
With the test-case included in this patch, we get:
...
(gdb) ptype main^M
During symbol reading: cannot get low and high bounds for subprogram DIE \
at 0x113^M
During symbol reading: cannot get low and high bounds for subprogram DIE \
at 0x11f^M
type = int (void)^M
(gdb) FAIL: gdb.dwarf2/inline.exp: ptype main
...
The complaints are about foo, with DW_AT_inline == DW_INL_inlined:
...
<1><11f>: Abbrev Number: 6 (DW_TAG_subprogram)
<120> DW_AT_name : foo
<126> DW_AT_prototyped : 1
<126> DW_AT_type : <0x10c>
<12a> DW_AT_inline : 1 (inlined)
...
and foo2, with DW_AT_inline == DW_INL_declared_inlined:
...
<1><113>: Abbrev Number: 5 (DW_TAG_subprogram)
<114> DW_AT_name : foo2
<11a> DW_AT_prototyped : 1
<11a> DW_AT_type : <0x10c>
<11e> DW_AT_inline : 3 (declared as inline and inlined)
...
Fix this by not complaining about inlined functions.
Tsukasa OI [Tue, 4 Oct 2022 08:42:35 +0000 (08:42 +0000)]
gdb/riscv: Partial support for instructions up to 176-bit
Because riscv_insn_length started to support instructions up to 176-bit,
we need to increase buf size to 176-bit in size.
Also, that would break an assumption in riscv_insn::decode so this commit
fixes it, noting that instructions longer than 64-bit are not fully
supported yet.
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.
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.*.
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:
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.
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).
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.
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.
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):
* 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.
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.
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
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.