This changes lookup_symbol and associated APIs to accept
domain_search_flags rather than a domain_enum.
Note that this introduces some new constants to Python and Guile. I
chose to break out the documentation patch for this, because the
internals here do not change until a later patch, and it seemed
simpler to patch the docs just once, rather than twice.
This changes quick_symbol_functions::lookup_global_symbol_language to
accept domain_search_flags rather than just a domain_enum, and fixes
up the fallout.
To avoid introducing any regressions, any code passing VAR_DOMAIN now
uses SEARCH_VFT.
That is, no visible changes should result from this patch. However,
it sets the stage to refine some searches later on.
The Python and Guile code exposed the internal domain constants both
as attributes of symbols and as values to pass to lookup functions.
Now, perfect backward compatibility here can't be achieved: some
symbols are going to have domain changes by the end of this series.
However, it seemed to me that we can preserve lookups using the basic
domain values.
This patch implements this by exporting the "or"-able search constants
with an extra bit set. Then it introduces some functions to convert
such constants to domain_search_flags. This will be used by the
Python and Guile code, so that both old- and new-style lookups will
work properly; and while preserving the idea that the domain constants
can be compared to a symbol's domain.
completion_list_add_symbol checks that the returned symbol has
VAR_DOMAIN, but also checks that its address class is LOC_BLOCK. The
domain check is redundant -- only functions can possibly be LOC_BLOCK
-- and leaving this in place will cause a regression when combined
with a later patch in this series. This patch preemptively removes
the redundant check.
This adds a new flag enum type, domain_search_flags, which is the flag
version of domain_enum. Nothing uses this yet, but the goal here is
to have all symbol searches and lookups use these flags. The new
names are chosen to exactly parallel domain_enum.
This adds two new symbol domain constants, TYPE_DOMAIN and
FUNCTION_DOMAIN.
Historically, gdb was a C debugger, and the symbol tables continue to
reflect this. In particular, symbol domains match the C language,
with VAR_DOMAIN including variables, functions, and types.
However, other languages have other approaches to namespacing. And,
in any case, it is often useful for other parts of gdb to be able to
distinguish between some domains at lookup time, without resorting to
examining a symbol's location -- in some situations, this sort of
filtering happens too late.
Nothing uses these new domains yet, but the idea behind the patch is
to separate symbols into more domains and then let the
language-specific parts of gdb implement their semantics in terms of
these categories.
Future patches will change and reuse the names from domain_enum. This
patch makes this less error-prone by having a single point to define
these names, using the typical gdb ".def" file.
global_symbol_searcher::add_matching_symbols in symtab.c has a
gigantic 'if' statement -- 33 lines of conditional expression. This
patch splits it up into a series of separate 'if's.
NR_DOMAINS is only used for a static assert, but we no longer need it
now. If we add too many constants to this enum, GCC will warn about
the bitfield overflow:
error: ‘symbol::m_domain’ is too small to hold all values of ‘enum domain_enum’
A patch later in this series will change check_typedef to also look in
the type domain. This change by itself caused a regression, but one
that revealed some peculiar behavior.
The regression is in nullptr_t.exp, where examining a std::nullptr_t
will change from the correct:
typedef decltype(nullptr) std::nullptr_t;
to
typedef void std::nullptr_t;
Right now, the DWARF reader marks all unspecified types as stub types.
However, this interacts weirdly with check_typedef, which currently
does not try to resolve types -- only struct-domain objects.
My first attempt here was to fix this by changing void types not to be
stub types, as I didn't see what value that provided. However, this
caused another regression, because call_function_by_hand_dummy checks
for stub-ness:
if (values_type == NULL || values_type->is_stub ())
values_type = default_return_type;
I'm not really sure why it does this rather than check for
TYPE_CODE_VOID.
While looking into this, I found another oddity: the DWARF reader
correctly creates a type named 'decltype(nullptr)' when it seems a
DW_TAG_unspecified_type -- but it creates a symbol named "void"
instead.
This patch changes the DWARF reader to give the symbol the correct
name. This avoids the regression.
nsalias.exp tries to detect a complaint that is issued when expanding
a CU. However, the test is a bit funny in that, while gdb does
currently expand the CU and issue the complaint, it also emits this
error:
No symbol "N100" in current context.
This series will change gdb such that this CU is not expanded -- which
makes sense, the symbol in question doesn't actually match the lookups
that are done.
So, to make the test more robust, a direct request to expand symtabs
is done instead.
A DW_TAG_entry_point symbol inherits its extern/static property from
the enclosing subroutine. This is encoded in new_symbol -- but the
cooked indexer does not agree.
I noticed a couple of spots in dwarf/read.c:new_symbol that call
add_symbol_to_list. However, this function is generally written to
set list_to_add, and then have a single call to add_symbol_to_list at
the end. This patch cleans up this discrepancy.
Note that new_symbol is overlong and should probably be split up.
Testing this entire series pointed out that the cooked index scanner
disagrees with new_symbol about certain symbols. In particular,
new_symbol has this comment:
Ada and Fortran subprograms, whether marked external or
not, are always stored as a global symbol, because we want
This patch updates the scanner to match.
I don't know why the current code does not cause failures.
It's maybe worth noting that incremental CU expansion -- creating
symtabs directly from the index -- would eliminate this sort of bug.
PR gas/31284
Currently, if an indirect jump is seen, GCFG (a CFG of ginsns) cannot be
created, and the SCFI machinery bails out with a warning:
"Warning: Untraceable control flow for func 'foo'; Skipping SCFI"
It is, however, better suited if this is a hard error. Change it to a
hard error. Also change the message to skip mentioning "SCFI", because
the error itself may also useful when ginsns are used for other passes
(distinct from SCFI) involving GCFG, like a pass to detect if there is
unreachable code. Hence, simply say:
"Error: untraceable control flow for func 'foo'"
gas/
PR gas/31284
* ginsn.c (ginsn_data_end): Use as_bad instead of as_warn.
gas/testsuite/
PR gas/31284
* gas/scfi/x86_64/ginsn-cofi-1.l: Adjust to the expected output
in case of errors.
* gas/scfi/x86_64/scfi-unsupported-cfg-1.l: Error not Warning.
The testcase for change of flow instructions in its current shape is not
doing much: it checks that SCFI issues an appropriate warning. The same
warning is covered by another testcase (scfi-unsupported-cfg-1); It is
better to test the ginsn translation instead, for these 'change of flow
instructions'.
gas/testsuite/
* gas/scfi/x86_64/scfi-cofi-1.s: Moved to...
* gas/scfi/x86_64/ginsn-cofi-1.s: ...here.
* gas/scfi/x86_64/scfi-x86-64.exp: Adjust tests.
* gas/scfi/x86_64/scfi-cofi-1.d: Removed.
* gas/scfi/x86_64/scfi-cofi-1.l: Removed.
* gas/scfi/x86_64/ginsn-cofi-1.l: New test.
SHA512 instructions were added to the architecture at the same time as SHA3
instructions, but later than the SHA1 and SHA256 instructions. Furthermore,
implementations must support either both or neither of the SHA512 and SHA3
instruction sets. However, SHA512 instructions were originally (and
incorrectly) added to Binutils under the +sha2 flag.
This patch moves SHA512 instructions under the +sha3 flag, which matches the
architecture constraints and existing GCC and LLVM behaviour.
Re-using the entire VEX decode hierarchy for the respective major opcode
has led to those two also being decoded as-if valid. Follow the earlier
USE_X86_64_EVEX_{PFX,W}_TABLE approach to avoid this happening.
As suggested during review already, all such entries have their first
slot as Bad_Opcode, so by adding two more enumerators we can avoid doing
that decode step altogether.
Adjustments made for the directive (by set_intel_syntax()) need also
making for the command line option. Break out respective code into a new
helper function, to also be invoked during command line processing.
Further also set register_prefix when processing -mnaked-reg.
With identical source and destination it can be covered by the NDD-to-
legacy conversion logic as well, even if in this case the original insn
doesn't use an NDD encoding. The size savings are even better here, for
the replacement (BSWAP) not having a ModR/M byte.
dwarf.c can hit "Assertion '(start) <= (end)' failed" on truncated
sections, due to get_encoded_eh_value wrongly returning a full count
for truncated words.
* dwarf.c (get_encoded_eh_value): Return zero for truncated words.
PR ld/31289 tests failed for fr30-elf, frv-elf, ft32-elf, iq2000-elf,
mn10200-elf, ms1-elf and msp430-elf targets:
FAIL: ld-elf/fatal-warnings-2a
FAIL: ld-elf/fatal-warnings-2b
FAIL: ld-elf/fatal-warnings-3a
FAIL: ld-elf/fatal-warnings-3b
FAIL: ld-elf/fatal-warnings-4a
FAIL: ld-elf/fatal-warnings-4b
even though PR ld/31289 targets xfail for [is_generic] targets. These
targets not only don't use the generic_link_hash_table linker, but also
don't use the standard ELF emulation. Add is_standard_elf for ELF
targets which use the standard ELF emulation and replace [is_generic]
with ![is_standard_elf] in PR ld/31289 tests.
binutils/
PR ld/31289
* testsuite/lib/binutils-common.exp (is_standard_elf): New.
ld/
PR ld/31289
* testsuite/lib/binutils-common.exp (is_generic): Return 1 for
fr30-*-*, frv-*-elf, ft32-*-*, iq2000-*-*, mn10200-*-*,
moxie-*-moxiebox*, msp430-*-* and mt-*-*.
* testsuite/ld-elf/fatal-warnings-2a.d: Replace [is_generic]
with ![is_standard_elf].
* testsuite/ld-elf/fatal-warnings-2b.d: Likewise.
* testsuite/ld-elf/fatal-warnings-3a.d: Likewise.
* testsuite/ld-elf/fatal-warnings-3b.d: Likewise.
* testsuite/ld-elf/fatal-warnings-4a.d: Likewise.
* testsuite/ld-elf/fatal-warnings-4b.d: Likewise.
Call output_unknown_cmdline_warning if there are no input files so that
$ ld -z bad-option
reports
ld: warning: -z bad-option ignored
ld: no input files
instead of
ld: no input files
PR ld/31289
* ldmain.c (main): Call output_unknown_cmdline_warning if there
are no input files.
On Fedora 39 aarch64 I run into:
...
(gdb) target remote | vgdb --wait=2 --max-invoke-ms=2500 --pid=2114437^M
Remote debugging using | vgdb --wait=2 --max-invoke-ms=2500 --pid=2114437^M
relaying data between gdb and process 2114437^M
warning: remote target does not support file transfer, \
attempting to access files from local filesystem.^M
Reading symbols from /lib/ld-linux-aarch64.so.1...^M
_start () at ../sysdeps/aarch64/dl-start.S:22^M
warning: 22 ../sysdeps/aarch64/dl-start.S: No such file or directory^M
(gdb) FAIL: gdb.base/valgrind-infcall.exp: target remote for vgdb
...
For contrast, on openSUSE Leap 15.4 x86_64 I have:
...
(gdb) target remote | vgdb --wait=2 --max-invoke-ms=2500 --pid=18797^M
Remote debugging using | vgdb --wait=2 --max-invoke-ms=2500 --pid=18797^M
relaying data between gdb and process 18797^M
warning: remote target does not support file transfer, \
attempting to access files from local filesystem.^M
Reading symbols from /lib64/ld-linux-x86-64.so.2...^M
(No debugging symbols found in /lib64/ld-linux-x86-64.so.2)^M
0x0000000004002550 in _start () from /lib64/ld-linux-x86-64.so.2^M
(gdb) PASS: gdb.base/valgrind-infcall.exp: target remote for vgdb
...
The fail happens in vgdb_start because the regexp only matches the
"in _start ()" variant, not the "_start () at":
...
gdb_test "$vgdbcmd" " in \\.?_start .*" "target remote for vgdb"
...
Which variant you get is determined by presence of debug info.
Fix this by also matching the "_start () at" variant.
Tested aarch64-linux and x86_64-linux.
Approved-By: Tom Tromey <tom@tromey.com>
Since gcc commit d3f48f68227 ("c++: non-dependent .* operand folding
[PR112427]"), with gdb we run into PR gcc/113599 [1], a wrong-code bug, as
reported in PR build/31281.
Work around this by flipping inherit order:
...
-class thread_info : public refcounted_object,
- public intrusive_list_node<thread_info>
+class thread_info : public intrusive_list_node<thread_info>,
+ public refcounted_object
...
An argument could be made that this isn't necessary, because this occurred in
an unreleased gcc version.
However, I think it could be useful when bisecting gcc for other problems in
building gdb. Having this workaround means the bisect won't reintroduce the
problem. Furthermore, the workaround is harmless.
Tested on Fedora rawhide x86_64.
Approved-By: Tom Tromey <tom@tromey.com>
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31281
[1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113599
On Fedora rawhide aarch64, I run into:
...
(gdb) PASS: gdb.base/eh_return.exp: set breakpoint on address
run ^M
Starting program: eh_return ^M
[Thread debugging using libthread_db enabled]^M
Using host libthread_db library "/lib64/libthread_db.so.1".^M
[Inferior 1 (process 1113051) exited normally]^M
(gdb) FAIL: gdb.base/eh_return.exp: hit breakpoint (the program exited)
...
This happens as follows: the test-case sets a breakpoint on the last
instruction of function eh2:
...
(gdb) break *0x00000000004103ec^M
...
and expects to hit the breakpoint, but instead the "br x6" is taken:
...
0x00000000004103e0 <+176>: cbz x4, 0x4103ec <eh2+188>^M
0x00000000004103e4 <+180>: add sp, sp, x5^M
0x00000000004103e8 <+184>: br x6^M
0x00000000004103ec <+188>: ret^M
...
In contrast, with fedora f39 we have:
...
0x00000000004103bc <+156>: ldp x2, x3, [sp, #48]^M
0x00000000004103c0 <+160>: ldp x29, x30, [sp, #16]^M
0x00000000004103c4 <+164>: add sp, sp, #0x50^M
0x00000000004103c8 <+168>: add sp, sp, x4^M
0x00000000004103cc <+172>: ret^M
...
and the breakpoint is reached.
Fix this by detecting that the breakpoint is not hit, and declaring the test
unsupported.
Tested on aarch64-linux.
Approved-By: Tom Tromey <tom@tromey.com>
PR testsuite/31291
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31291
Currently, in AIX attach-twice.exp testcase is untested due to the below error.
gdb/testsuite/gdb.base/attach-twice.c:43:7: error: too few arguments to function 'ptrace'
This is because in AIX ptrace has five arguments. This patch is a fix for the same such that
this test case runs in AIX and other targets as well.
There are 2 problems with --fatal-warnings for unknown command-line
options:
1. --fatal-warnings doesn't trigger an error for an unknown command-line
option when --fatal-warnings is the last command-line option.
2. When --fatal-warnings triggers an error for an unknown command-line
option, the message says that the unknown command-line option is ignored.
This patch queues unknown command-line option warnings and outputs queued
command-line option warnings after all command-line options have been
processed so that --fatal-warnings can work for unknown command-line
options regardless of the order of --fatal-warnings.
When --fatal-warnings is used, the linker message is changed from
ld: warning: -z bad-option ignored
to
ld: error: unsupported option: -z bad-option
The above also applies to "-z dynamic-undefined-weak" when the known
"-z dynamic-undefined-weak" option is ignored.
PR ld/31289
* ldelf.c (ldelf_after_parse): Use queue_unknown_cmdline_warning
to warn the ignored -z dynamic-undefined-weak option.
* ldmain.c (main): Call output_unknown_cmdline_warnings after
calling ldemul_after_parse.
* ldmisc.c (CMDLINE_WARNING_SIZE): New.
(cmdline_warning_list): Likewise.
(cmdline_warning_head): Likewise.
(cmdline_warning_tail): Likewise.
(queue_unknown_cmdline_warning): Likewise.
(output_unknown_cmdline_warnings): Likewise.
* ldmisc.h (queue_unknown_cmdline_warning): Likewise.
(output_unknown_cmdline_warnings): Likewise.
* emultempl/elf.em (gld${EMULATION_NAME}_handle_option): Use
queue_unknown_cmdline_warning to warn unknown -z option.
* testsuite/ld-elf/fatal-warnings-1a.d: New file.
* testsuite/ld-elf/fatal-warnings-1b.d: Likewise.
* testsuite/ld-elf/fatal-warnings-2a.d: Likewise.
* testsuite/ld-elf/fatal-warnings-2b.d: Likewise.
* testsuite/ld-elf/fatal-warnings-3a.d: Likewise.
* testsuite/ld-elf/fatal-warnings-3b.d: Likewise.
* testsuite/ld-elf/fatal-warnings-4a.d: Likewise.
* testsuite/ld-elf/fatal-warnings-4b.d: Likewise.
Without this patch the r_offset field of struct external_reloc is
uninitialised when using objcopy.
* coff/riscv64.h (SWAP_IN_RELOC_OFFSET): Define.
(SWAP_OUT_RELOC_OFFSET): Define.
In an earlier patch, I wrote:
... It also adds some machinery so that attach stops can be
suppressed, which I think is the right thing to do.
However, after some discussions here at AdaCore, I now believe this to
be incorrect -- while DAP says that expected "continue" events should
be suppressed, there is no corresponding language for expected "stop"
events, and indeed "stop" events explicitly mention cases like "step".
This patch arranges for the stop event to be emitted again.
A user found that gdb would not correctly print a field from an Ada
record using the scalar storage order feature. We tracked this down
to a combination of problems.
First, GCC did not emit DW_AT_endianity on the enumeration type.
DWARF does not specify this, but it is an obvious and harmless
extension. This was fixed in GCC recently:
https://gcc.gnu.org/pipermail/gcc-patches/2024-January/642347.htmlhttps://gcc.gnu.org/git/?p=gcc.git;a=commit;h=5d8b60effc7268448a94fbbbad923ab6871252cd
Second, GDB did not handle this attribute on enumeration types. This
patch makes this change and adds a test case that will pass with the
patched GCC.
So far, the GCC patch isn't on the gcc-13 branch; but if it ever goes
in, the test case in this patch can be updated to reflect that.
Reviewed-By: Keith Seitz <keiths@redhat.com>
arm_epilogue_frame_this_id has a comment saying that it fall backs to using
the current PC if the function start address can't be identified, but it
actually uses only the PC to make the frame id.
This patch makes the code match the comment. Another hint that it's what
is intended is that arm_prologue_this_id, a function almost identical to
it, does that.
The problem was found by code inspection. It fixes the following testsuite
failures:
FAIL: gdb.base/unwind-on-each-insn.exp: foo: instruction 9: check frame-id matches
FAIL: gdb.reverse/solib-reverse.exp: reverse-next third shr1
FAIL: gdb.reverse/solib-reverse.exp: reverse-next second shr1
FAIL: gdb.reverse/solib-reverse.exp: reverse-next first shr1
FAIL: gdb.reverse/solib-reverse.exp: reverse-next generic
FAIL: gdb.reverse/solib-reverse.exp: reverse-step into solib function one
FAIL: gdb.reverse/solib-reverse.exp: reverse-step within solib function one
FAIL: gdb.reverse/solib-reverse.exp: reverse-step into solib function two
FAIL: gdb.reverse/solib-reverse.exp: reverse-step within solib function two
Tested on arm-linux-gnueabi-hf.
This patch is based on an out-of-tree patch that fedora has been
carrying for a while. It tests if GDB is able to properly unwind a
threaded program in the following situations:
* regular threads
* in a signal handler
* in a signal handler executing on an alternate stack
And the final frame can either be in a syscall or in an infinite loop.
The test works by running the inferior until a crash to generate a
corefile, or until right before the crash. Then applies a backtrace to
all threads to see if any frame can't be identified, and the order of
the threads in GDB. Finally, it goes thread by thread and tries to
collect a large part of the backtrace, to confirm that everything is
being unwound correctly.
Co-Authored-By: Andrew Burgess <aburgess@redhat.com>
Reviewed-By: Luis Machado <luis.machado@arm.com>
Approved-By: Luis Machado <luis.machado@arm.com>