Tom Tromey [Wed, 27 Aug 2025 19:30:46 +0000 (13:30 -0600)]
Add Ada test case with long array indices
This patch adds a test case to test that the previous two patches did
their job.
With the current gdb, this test fails:
(gdb) print some_regular_access.all
Value out of range.
The bug here is that the array has an index type that is wider than
'int', which is perfectly acceptable in Ada.
Note that this series doesn't quite go far enough: in Ada the index
could be a 128-bit integer. This change would be more invasive; and
in practice this doesn't really seem to come up much -- so I've
deferred it.
Tom Tromey [Wed, 27 Aug 2025 19:08:13 +0000 (13:08 -0600)]
Use LONGEST rather than int for array slices
This patch started by removing the remaining calls to longest_to_int
from ada-lang.c, then chasing down the callees to make sure they were
also using LONGEST. This ended up with a small change to value_slice
as well.
Tom Tromey [Wed, 27 Aug 2025 18:56:02 +0000 (12:56 -0600)]
Remove some uses of longest_to_int from ada-lang.c
A few spots in ada-lang.c use longest_to_int -- but in a context where
the value is immediately passed to a function accepting LONGEST. This
patch removes the offending calls. It turned out to be easy to change
find_struct_field as well, so I've included that in this patch.
Tom de Vries [Thu, 11 Sep 2025 16:31:37 +0000 (18:31 +0200)]
[gdb/testsuite, tclint] Drop lreverse
When running tclint with lib/future.exp, I get:
...
$ tclint lib/future.exp
$exp:756:5: redefinition of built-in command 'lreverse' [redefined-builtin]
...
The code was added to handle pre-7.5 tcl versions without lreverse.
Since we now require Tcl 8.6.2 (as per PR testsuite/33205), drop this.
Tested by rerunning tclint.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
PR testsuite/33403
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33403
Tom de Vries [Thu, 11 Sep 2025 16:31:37 +0000 (18:31 +0200)]
[gdb/testsuite, tclint] Fix syntax error in gdb.base/dtrace-probe.exp
When running tclint with gdb.base/dtrace-probe.exp I get:
...
$ tclint gdb.base/dtrace-probe.exp
$exp:67:45: syntax error: expected newline or semicolon, got ]
...
due to these lines:
...
67 runto "-probe-dtrace test:two-locations"]
68 runto "-probe-dtrace test:two-locations"]
...
Fix this by dropping the trailing ']'.
Tested by rerunning tclint.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
PR testsuite/33403
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33403
Copy non_got_ref_without_indirect_extern_access when copying indirect
symbol for weak alias so that _bfd_x86_elf_adjust_dynamic_symbol will
properly handle GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS.
testsuite: RISC-V: Add '.option norvc' to ensure consistent results.
Add `.option norvc` to several RISC-V tests to avoid compressed
instruction generation. This ensures consistent disassembly and
alignment behavior regardless of assembler default options.
Kevin Buettner [Fri, 11 Jul 2025 23:18:13 +0000 (16:18 -0700)]
Fix unwinding when restoring a register from one of a greater size
When debugging functions where a callee-saved register is moved to a
register of a larger size (e.g., a 64-bit general-purpose register to
a 128-bit vector register), GDB would crash when the user issued the
"return" command. For example:
ldgr %f0, %r11 ; Move 64-bit general-purpose register (r11)
; to 128-bit vector register (f0)
.cfi_register r11, f0 ; DW_CFA_register: r11 is stored in f0
...
lgdr %r11, %f0 ; Restore r11 from f0
.cfi_restore r11 ; DW_CFA_restore: r11 is restored to its original
; register
(This example uses instructions and registers for the S390x architecture,
where this bug was originally found.)
If GDB is stopped in the "..." section and the user issues the
"return" command, GDB crashes due to a buffer size mismatch during
unwinding. Specifically, in frame_register_unwind in frame.c, a
buffer the size of the original register (the 64-bit r11 in this
example) has been allocated and GDB would like to use memcpy to copy
the contents of the register where the original register was saved
(the 128-bit f0) to the buffer for the original register. But,
fortunately, GDB has an assertion which prevents this from happening:
This patch ensures that GDB uses the original register's type (e.g.,
r11's type) when unwinding, even if it was marked as saved to a differently
typed/sized register (e.g., f0) via .cfi_register (DW_CFA_register).
The fix adds a 'struct type *' parameter to value_of_register_lazy() to
explicitly track the original register's type. The function
frame_unwind_got_register is updated to pass the correct type for the
original register.
The call chain from frame_register_unwind to frame_unwind_got_register
is shown by this backtrace:
#0 frame_unwind_got_register (frame=..., regnum=13, new_regnum=128)
at gdb/frame-unwind.c:300
#1 0x000000000135d894 in dwarf2_frame_prev_register (this_frame=...,
this_cache=0x2204528, regnum=13)
at gdb/dwarf2/frame.c:1187
#2 0x00000000014d9186 in frame_unwind_legacy::prev_register (
this=0x211f428 <dwarf2_frame_unwind>, this_frame=...,
this_prologue_cache=0x2204528, regnum=13) at gdb/frame-unwind.c:401
#3 0x00000000014e1d12 in frame_unwind_register_value (next_frame=...,
regnum=13) at gdb/frame.c:1263
#4 0x00000000014e16b8 in frame_register_unwind (next_frame=..., regnum=13,
optimizedp=0x3ffffff813c, unavailablep=0x3ffffff8138,
lvalp=0x3ffffff8134, addrp=0x3ffffff8128, realnump=0x3ffffff8124,
buffer=...) at gdb/frame.c:1189
The register numbers shown above are for s390x. On s390x,
S390_R11_REGNUM has value 13. Vector registers (like f0) are numbered
differently from floating-point registers of the same name, leading to
regnum 128 for f0 despite S390_F0_REGNUM being assigned a different
value in s390-tdep.h.
New test cases for aarch64 and x86_64 check for this on more popular
architectures and also without dependency on a particular compiler to
generate an unusual prologue in which a general purpose register is
being moved to a vector register. In both cases, the test simulates
the bug found on s390x where a 64-bit frame pointer was being moved to
a much wider vector register. These test cases will cause an internal
error on their respective architecture, but will pass with this fix in
place.
When tested on s390x linux (native), this change fixes 59 GDB internal
errors and around 200 failures overall. This is the list of internal
errors that no longer occur on s390x:
I have tested this commit on Fedora Linux, with architectures s390x,
x86_64, x86_64/-m32, aarch64, ppc64le, and riscv64, with no
regressions found.
This v2 version makes some changes suggested by Andrew Burgess: It
adds an assert to frame_unwind_got_register() and always passes the
type of REGNUM to value_of_register_lazy(). It also updates value.h's
comment describing value_of_register_lazy().
In his approval message, Andrew requested some changes to the tests.
Those have been made exactly as requested.
Tom Tromey [Thu, 24 Apr 2025 21:24:52 +0000 (15:24 -0600)]
Rename expand_symtabs_matching
After this series, expand_symtabs_matching is now misnamed. This
patch renames it, renames some associated types, and also fixes up
some comments that I previously missed.
Acked-By: Simon Marchi <simon.marchi@efficios.com>
Tom Tromey [Tue, 11 Feb 2025 20:39:16 +0000 (13:39 -0700)]
Remove enter_symbol_lookup
The "enter_symbol_lookup" class was introduced to work around the lack
of reentrancy in symbol lookup. There were two problems here:
1. The DWARF reader kept a mark bit on the dwarf2_per_cu_data object.
This bit is gone now, replaced with a local mark vector.
2. Some spots in gdb first examined the expanded symbol tables, and
then on failure expanded some symtabs and searched the newly
expanded ones (skipping previousy-expanded ones). Fixing this has
been the main point of this series.
Now that both of these barriers are gone, I think enter_symbol_lookup
can be removed.
One proof of this idea is that, without the first fix mentioned above,
py-symbol.exp regressed because gdbpy_lookup_static_symbols did not
first ensure that the current language was set -- i.e., there was a
latent bug in the enter_symbol_lookup patch anyway.
Acked-By: Simon Marchi <simon.marchi@efficios.com>
Tom Tromey [Thu, 2 Jan 2025 22:28:18 +0000 (15:28 -0700)]
Convert lookup_symbol_in_objfile
This converts lookup_symbol_in_objfile to the callback approach by
removing the call to lookup_symbol_in_objfile_symtabs. (The latter is
not removed as there are still other callers.)
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=16994
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=16998 Acked-By: Simon Marchi <simon.marchi@efficios.com>
Tom Tromey [Tue, 31 Dec 2024 20:30:18 +0000 (13:30 -0700)]
Convert lookup_symbol_via_quick_fns
This converts lookup_symbol_via_quick_fns to the callback approach,
merging the search loop and the call to expand_symtabs_matching.
Note that this changes lookup_symbol_via_quick_fns to use a
best_symbol_tracker. Before this patch there was a discrepancy here
between the two search functions.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=16994
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=16998 Acked-By: Simon Marchi <simon.marchi@efficios.com>
Tom Tromey [Thu, 2 Jan 2025 22:21:46 +0000 (15:21 -0700)]
Add best_symbol_tracker
This adds a new best_symbol_tracker struct. This is used to implement
the "best symbol" logic that is used sometimes in symtab.c. This
approach makes it simpler and more efficient to track the "best"
symbol when searching across multiple blocks.
Acked-By: Simon Marchi <simon.marchi@efficios.com>
Tom Tromey [Thu, 2 Jan 2025 22:17:25 +0000 (15:17 -0700)]
Simplify block_lookup_symbol
One loop in block_lookup_symbol is identical to the code in
block_lookup_symbol_primary. This patch simplifies the former by
having it call the latter.
This removes an assert. However, note that the assert is not needed
-- it does not check any invariant that must be maintained.
Acked-By: Simon Marchi <simon.marchi@efficios.com>
Tom Tromey [Thu, 2 Jan 2025 22:15:32 +0000 (15:15 -0700)]
Pass lookup_name_info to block_lookup_symbol_primary
This changes block_lookup_symbol_primary to accept a lookup_name_info.
This follows the general trend of hoisting these objects to the
outermost layer where they make sense -- somewhat reducing the cost of
using them.
Acked-By: Simon Marchi <simon.marchi@efficios.com>
Tom Tromey [Tue, 31 Dec 2024 20:11:50 +0000 (13:11 -0700)]
Remove objfile::expand_symtabs_for_function
objfile::expand_symtabs_for_function only has a single caller now, so
it can be removed. This also allows us to merge the expansion and
searching phases, as done in other patches in this series.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=16994
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=16998 Acked-By: Simon Marchi <simon.marchi@efficios.com>
Tom Tromey [Tue, 31 Dec 2024 17:30:15 +0000 (10:30 -0700)]
Simplify basic_lookup_transparent_type
This patch changes basic_lookup_transparent_type to always work via
the "quick" API -- that is, no separate search of the already-expanded
symtabs is needed.
This is more efficient when many CUs have already been expanded. It
also makes the lookup more consistent, as the result is no longer
dependent on the order in which CUs were previously expanded.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=16994
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=16998 Acked-By: Simon Marchi <simon.marchi@efficios.com>
This converts ada_language_defn::collect_symbol_completion_matches to
the callback approach, merging the search loop and the call to
expand_symtabs_matching.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=16994
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=16998 Acked-By: Simon Marchi <simon.marchi@efficios.com>
This converts default_collect_symbol_completion_matches_break_on to
the callback approach, merging the search loop and the call to
expand_symtabs_matching.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=16994
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=16998 Acked-By: Simon Marchi <simon.marchi@efficios.com>
Tom Tromey [Fri, 7 Mar 2025 01:00:37 +0000 (18:00 -0700)]
Rewrite the .gdb_index reader
This patch rewrites the .gdb_index reader to create the same data
structures that are created by the cooked indexer and the .debug_names
reader.
This is done in support of this series; but also because, from what I
can tell, the "templates.exp" change didn't really work properly with
this reader.
In addition to fixing that problem, this patch removes a lot of code.
Implementing this required a couple of hacks, as .gdb_index does not
contain all the information that's used by the cooked index
implementation.
* The index-searching code likes to differentiate between the various
DWARF tags when matching, but .gdb_index lumps many things into a
single "other" category. To handle this, we introduce a phony tag
that's used so that the match method can match on multiple domains.
* Similarly, .gdb_index doesn't distinguish between the type and
struct domains, so another phony tag is used for this.
* The reader must attempt to guess the language of various symbols.
This is somewhat finicky. "Plain" (unqualified) symbols are marked
as language_unknown and then a couple of hacks are used to handle
these -- one in expand_symtabs_matching and another when recognizing
"main".
For what it's worth, I consider .gdb_index to be near the end of its
life. While .debug_names is not perfect -- we found a number of bugs
in the standard while implementing it -- it is better than .gdb_index
and also better documented.
After this patch, we could conceivably remove dwarf_scanner_base.
However, I have not done this.
Finally, this patch also changes this reader to dump the content of
the index, as the other DWARF readers do. This can be handy when
debugging gdb.
Acked-By: Simon Marchi <simon.marchi@efficios.com>
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33316
Tom Tromey [Sat, 7 Dec 2024 23:26:06 +0000 (16:26 -0700)]
Have expand_symtabs_matching work for already-expanded CUs
Currently, gdb will search the already-expanded symtabs in one loop,
and then also expand matching symtabs in another loop. However, this
is somewhat inefficient -- when searching the already-expanded
symtabs, all such symtabs are examined. However, the various "quick"
implementations already know which subset of symtabs might have a
match.
This changes the contract of expand_symtabs_matching to also call the
callback for an already-expanded symtab. With this change, and some
subsequent enabling changes, the number of searched symtabs should
sometimes be reduced. This also cuts down on the amount of redundant
code.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=16994
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=16998
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30736 Acked-By: Simon Marchi <simon.marchi@efficios.com>
Tom Tromey [Sat, 7 Dec 2024 22:51:24 +0000 (15:51 -0700)]
Remove dwarf2_per_cu_data::mark
This removes dwarf2_per_cu_data::mark, replacing it with a
locally-allocated boolean vector. It also inverts the sense of the
flag -- now, the flag is true when a CU should be skipped, and false
when the CU should be further examined. Also, the validity of the
flag is no longer dependent on 'file_matcher != NULL'.
This patch makes the subsequent patch to searching a bit simpler, so
I've separated it out.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=16994
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=16998 Acked-By: Simon Marchi <simon.marchi@efficios.com>
Tom Tromey [Sun, 19 Jan 2025 01:15:21 +0000 (18:15 -0700)]
Entries from anon-struct.exp not in cooked index
g++ will sometimes use a typedef to give a name to an otherwise
anonymous type for linkage purposes. gdb tries to handle this odd
scenario, which is enforced by anon-struct.exp.
It's difficult to detect this problem in the current tree, but the
cooked index does not include an entry for these DIEs.
This patch changes gdb to add these to the index. This is needed by
subsequent changes in this series.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32519 Acked-By: Simon Marchi <simon.marchi@efficios.com>
Tom Tromey [Fri, 24 Jan 2025 01:56:51 +0000 (18:56 -0700)]
Restore "ingestion" of .debug_str when writing .debug_names
When I rewrote the .debug_names writer (commit 91a42a61), I changed
the writer to not import .debug_str into the debug_str_lookup object.
However, a later patch in this series needed this again. The issue
here was that if a name occurs in the DWARF, and is also allocated,
then there is a race, where the created index depends on which DIE is
read first. This can cause index-file.exp failures.
This patch restores the old approach, avoiding this problem. I also
applied a couple of small cleanups to the class. And, I removed the
old complaint from the "ingestion" function, as this was not
necessary.
Acked-By: Simon Marchi <simon.marchi@efficios.com>
Tom Tromey [Mon, 20 Jan 2025 18:06:21 +0000 (11:06 -0700)]
Put all CTF symbols in global scope
The new approach to searching (solely via the quick API) is more
sensitive to discrepancies between the partial and full readers. In
CTF, there is some disagreement about which scope to use. CTF doesn't
seem to really distinguish between the file and global scope, so this
patch takes the simple approach of putting all CTF symbols into the
global scope.
This changes one test as well. It seems to me that the behavior here
is arbitrary and the test is making unwarranted assumptions.
Acked-By: Simon Marchi <simon.marchi@efficios.com>
Tom Tromey [Sun, 19 Jan 2025 23:53:33 +0000 (16:53 -0700)]
Fix index's handling of DW_TAG_imported_declaration
Currently the full symbol reader puts DW_TAG_imported_declaration in
TYPE_DOMAIN, in the global scope. This patch changes the cooked
indexer to follow.
Without this patch, a later patch in the series would cause
nsalias.exp to regress.
This also updates read-gdb-index.c to do something similar.
Acked-By: Simon Marchi <simon.marchi@efficios.com>
Tom Tromey [Thu, 2 Jan 2025 20:40:27 +0000 (13:40 -0700)]
Ada import functions not in index
The cooked index does not currently contain entries for Ada import
functions. This means that whether or not these are visible to
"break" depends on which CUs were previously expanded -- clearly a
bug.
This patch fixes the issue. I think the comments in the patch explain
the fix reasonably well.
Perhaps one to-do item here is to change GNAT to use
DW_TAG_imported_declaration for these imports. This may eventually
let us remove some of the current hacks.
This version includes a fix from Simon to initialize the new member.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32511 Acked-By: Simon Marchi <simon.marchi@efficios.com>
Tom Tromey [Tue, 11 Feb 2025 18:48:09 +0000 (11:48 -0700)]
Emit some type declarations in .gdb_index
If you run struct-decl.exp with the .gdb_index board, you will see
that "the_type" is not emitted in the index. This would cause a
failure in this series. The fix is to ensure that certain necessary
type declarations are emitted.
However, a naive fix here will regress stub-array-size.exp, where a
type declaration and a type definition are both seen -- but the
declaration is seen first and causes a failure. This is handled by
adding some code (including a mild hack) to filter out type
declarations when a corresponding type definition is seen.
Acked-By: Simon Marchi <simon.marchi@efficios.com>
Tom Tromey [Sat, 22 Feb 2025 21:07:57 +0000 (14:07 -0700)]
Change ada_decode to preserve upper-case in some situations
This patch is needed to avoid regressions later in the series.
The issue here is that ada_decode, when called with wide=false, would
act as though the input needed verbatim quoting. That would happen
because the 'W' character would be passed through; and then a later
loop would reject the result due to that character.
Similarly, with operators=false the upper-case-checking loop would be
skipped, but then some names that did need verbatim quoting would pass
through.
Furthermore I noticed that there isn't a need to distinguish between
the "wide" and "operators" cases -- all callers pass identical values
to both.
This patch cleans up the above, consolidating the parameters and
changing how upper-case detection is handled, so that both the
operator and wide cases pass-through without issue. I've added new
unit tests for this.
Acked-By: Simon Marchi <simon.marchi@efficios.com>
Tom Tromey [Mon, 10 Mar 2025 21:52:17 +0000 (15:52 -0600)]
Add another minor hack to cooked_index_entry::full_name
This patch adds another minor hack to cooked_index_entry::full_name.
In particular, if GNAT emits non-hierarchical names (still the default
as the hierarchical series is blocked on one tricky problem), then a
request to compute the "linkage-style" name will now just return the
'name' field.
Without this tweak, this series would regress ada-cold-name.exp,
because the search would look for "name.cold" but the index would
return "name[cold]" as the "linkage" name (which would be wrong).
This area is a bit difficult to unravel. The best plan here, IMO, is
to change Ada to work like the other languages in gdb: store the
natural name and do searches with that name. I think this is
achievable, but I didn't want to try it here.
I've updated the relevant bug (tagged below) to reflect this.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32766 Acked-By: Simon Marchi <simon.marchi@efficios.com>
Tom Tromey [Sat, 26 Jul 2025 21:28:34 +0000 (15:28 -0600)]
Skip some tests with "readnow" board
This series pointed out a few tests that check that a particular index
is in use. It seems to me that this does not really make sense when
the "readnow" board is in use, as this actually skips index creation.
The tests do pass today, but by accident. This patch adds the
appropriate "require" line to the tests in question.
Approved-By: Simon Marchi <simon.marchi@efficios.com> Acked-By: Simon Marchi <simon.marchi@efficios.com>
gas: sframe: skip DW_CFA_GNU_args_size when safe to ignore
Currently, gas warns and skips generating SFrame FDE when it sees:
.cfi_escape 0x2e,XX
From the documentation of DW_CFA_GNU_args_size:
"The DW_CFA_GNU_args_size instruction takes an unsigned LEB128 operand
representing an argument size. This instruction specifies the total of
the size of the arguments which have been pushed onto the stack."
With origins seemingly for VAX architecture, the usage of
DW_CFA_GNU_args_size seems to have evolved. The purpose of
DW_CFA_GNU_args_size is to adjust SP when performing stack unwinding for
exception handling.
For the purpose of stack tracing using SFrame, DW_CFA_GNU_args_size is
safe to skip, especially when the CFA restoration is known to be FP
based. A previous summary of the reasoning and intent was indicated
here [1].
R_X86_64_TPOFF32 relocation of local-exec TLS model can only be used in
executable, not in a shared library, even if the source code is compiled
with -fPIC. Change the linker error message from
relocation R_X86_64_TPOFF32 against symbol `foo' can not be used when making a shared object; recompile with -fPIC
to
relocation R_X86_64_TPOFF32 against symbol `foo' can not be used when making a shared object; replace local-exec with initial-exec TLS model
bfd/
PR ld/33408
* elf64-x86-64.c (elf_x86_64_need_pic): Suggest "replace
local-exec with initial-exec TLS model" for R_X86_64_TPOFF32.
(elf_x86_64_scan_relocs): Drop ABI_64_P check for
R_X86_64_TPOFF32.
Matthieu Longo [Thu, 4 Sep 2025 14:25:21 +0000 (15:25 +0100)]
ld: fix segfault when linker script is not found
ld previously crashed with a segmentation fault if the specified linker
script could not be found. The issue seems to have been introduced
recently by d048eee2910 [1].
This patch adds a check to ensure that a filename was found after
searching the possible prefixes. If no filename was found, the function
returns NULL, and ldfile_open_command_file_1() emits a proper fatal
error message.
This change prevents the crash and provides a clear diagnostic.
A new generic test was also added to cover this error case.
Tom Tromey [Sat, 23 Aug 2025 17:51:03 +0000 (11:51 -0600)]
Change type_stack::insert to take gdbarch
This changes type_stack::insert to take a gdbarch rather than an
expr_builder. This is simpler and means that type_stack doesn't have
to know anything about expression building; the parser-defs.h include
can be removed.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
Tom Tromey [Sat, 23 Aug 2025 17:46:48 +0000 (11:46 -0600)]
Make type_stack popping a bit safer
This changes type_stack so that an element that has an argument can't
be popped in isolation. The idea is to make type stack use a little
safer, making it so that the stack can't end up in an invalid state.
This also fixes up a few related comments.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
Tom Tromey [Sat, 23 Aug 2025 17:39:35 +0000 (11:39 -0600)]
Make type_stack pushing a bit safer
This changes type_stack to make pushing elements a bit safer: if an
element requires an argument, these are now always pushed at the same
time, rather than separately.
This patch also adds a few comments to help document a bit better.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
Alan Modra [Tue, 9 Sep 2025 10:45:44 +0000 (20:15 +0930)]
readelf: tidy dump_relr_relocations
A comment in display_relocations said "RELRS has been freed by
dump_relr_relocations". Except that hadn't happened on all return
paths. Tidy that by freeing relrs allocated in dump_relr_relocations
in that function, and relrs allocated in display_relocation in that
function.
* readelf.c (dump_relr_relocations): Only free relrs allocated
in this function.
(display_relocations): Free relrs here, on error return paths
too.
Tom Tromey [Mon, 4 Aug 2025 16:39:02 +0000 (10:39 -0600)]
Use gnulib c-ctype module in gdb
PR ada/33217 points out that gdb incorrectly calls the <ctype.h>
functions. In particular, gdb feels free to pass a 'char' like:
char *str = ...;
... isdigit (*str)
This is incorrect as isdigit only accepts EOF and values that can be
represented as 'unsigned char' -- that is, a cast is needed here to
avoid undefined behavior when 'char' is signed and a character in the
string might be sign-extended. (As an aside, I think this API seems
obviously bad, but unfortunately this is what the standard says, and
some systems check this.)
Rather than adding casts everywhere, this changes all the code in gdb
that uses any <ctype.h> API to instead call the corresponding c-ctype
function.
Now, c-ctype has some limitations compared to <ctype.h>. It works as
if the C locale is in effect, so in theory some non-ASCII characters
may be misclassified. This would only affect a subset of character
sets, though, and in most places I think ASCII is sufficient -- for
example the many places in gdb that check for whitespace.
Furthermore, in practice most users are using UTF-8-based locales,
where these functions aren't really informative for non-ASCII
characters anyway; see the existing workarounds in gdb/c-support.h.
Note that safe-ctype.h cannot be used because it causes conflicts with
readline.h. And, we canot poison the <ctype.h> identifiers as this
provokes errors from some libstdc++ headers.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33217 Approved-By: Simon Marchi <simon.marchi@efficios.com>
The upstream build of GDB can fail on fedora rawhide, since the self
check in regcache.c uses an unitialized variable to be compared, which
now generates the following warning:
binutils-gdb/gdb/regcache.c:1847:42: error: variable
'buf' is uninitialized when passed as a const pointer argument here
[-Werror,-Wuninitialized-const-pointer]
1847 | SELF_CHECK (regcache->raw_compare (0, &buf, register_size (inf.arch (), 0)));
This commit fixes that by initializing the variable to 0.
Since the comment above that line would be changed, it was also
reformatted so that it doesn't go beyond 80 columns.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
nm: fix treating an ifunc symbol as a stab if '--ifunc-chars=--' is given
If an ifunc symbol is processed in print_symbol(), a 'type' field of a
'syminfo' structure is set to any character specified by a user with an
'--ifunc-chars' option. But afterwards the 'type' field is used to
check whether a symbol is a stab in print_symbol_info_{bsd,sysv}()
functions in order to print additional stab related data. If the 'type'
field equals '-', a symbol is treated as a stab. If '--ifunc-chars=--'
is given, all ifunc symbols will be treated as stab symbols and
uninitialized stab related fields of the 'syminfo' structure will be
printed which can lead to segmentation fault.
To fix this, check if a symbol is a stab before override the 'type'
field. Also, add a test case for this fix.
PR binutils/32556
* nm.c (extended_symbol_info): Add is_stab.
(print_symbol): Check if a symbol is a stab.
(print_symbol_info_bsd): Use info->is_stab.
(print_symbol_info_sysv): Use info->is_stab.
* testsuite/binutils-all/nm.exp: Test nm --ifunc-chars=--.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32556 Fixes: e6f6aa8d184 ("Add option to nm to change the characters displayed for ifunc symbols") Signed-off-by: Dmitry Klochkov <dmitry.klochkov@bell-sw.com>
Nick Clifton [Tue, 9 Sep 2025 07:57:38 +0000 (08:57 +0100)]
objcopy: when an invalid bfd target string is used as a target option, print an error message that references the target string, not the file being copied
Tom Tromey [Sat, 6 Sep 2025 19:17:18 +0000 (13:17 -0600)]
Add m_builder member to lnp_state_machine
I noticed that several spots in lnp_state_machine fetch the CU's
builder. Since this can't change over the lifetime of the object, it
seemed nicer to simply cache it.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
Tom Tromey [Sat, 6 Sep 2025 18:16:26 +0000 (12:16 -0600)]
Move compute_include_file_name earlier
I noticed that the compute_include_file_name intro comment was
slightly wrong, and while looking at this, I also noticed that it has
a single caller. This patch hoists it slightly so that a forward
declaration isn't needed.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
Tom Tromey [Sat, 6 Sep 2025 17:56:40 +0000 (11:56 -0600)]
Move lnp_state_machine to new file
This patch moves lnp_state_machine and some supporting code to a new
file, dwarf2/line-program.c. The main benefit of this is shrinking
dwarf2/read.c a bit.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
Tom Tromey [Sun, 17 Aug 2025 17:38:15 +0000 (11:38 -0600)]
Use type-specific lookups in cp-support.c
cp-support.c has code to substitute types for typedef names when
canonicalizing a C++ name. I believe this code can use type-specific
search domains; and doing this greatly speeds up some cases.
Tom Tromey [Sat, 16 Aug 2025 18:21:15 +0000 (12:21 -0600)]
Avoid symbol lookup for field names in C parser
Currently, the C parser looks up any name it finds -- at lex time.
However, in an expression like "obj->field", looking up the field name
is wasteful, and can sometimes even yield pathological symtab
expansion behavior.
This patch arranges to avoid the name lookup in this case. (It would
be nice to really clean up this area, but I'm not convinced it can
readily be done in a yacc parser.)
Some special code is required for the C++ construct where a qualified
name is used, like "obj->type1::type2::field".
Tom Tromey [Tue, 5 Aug 2025 23:32:55 +0000 (17:32 -0600)]
Change how C parser looks up type tag names
In an earlier version of this series, Simon noticed that something
like "ptype struct type" was much slower.
The deep problem here is the hack in best_symbol -- in this particular
case the C parser is including SEARCH_VAR_DOMAIN, which means that a
type is not "best".
Fixing best_symbol would be good to do, but it's difficult and I
already had many struggles getting this series to this point. So,
rather than fix that, I elected to modify the parser.
The key insight here is that the name lookup in classify_name is
useless when a tag name is expected. This patch adds a flag so that
this lookup is not done. (Incidentally, this kind of thing is much
more straightforward in a recursive descent parser, something like
classify_name would only be applied post-lexing where appropriate.)
This change speeds up the lookup by avoiding the best_symbol hack,
instead searching only for a type.
Acked-By: Simon Marchi <simon.marchi@efficios.com> Reviewed-By: Guinevere Larsen <guinevere@redhat.com>
gdb: Add svr4-tls-tdep.o to list of objects of i*86 targets
GDB currently fails to build from source on i386 if compiled with
--enable-64-bit-bfd. This is happening because svr4-tls-tdep.o is
missing from the gdb_target_obs variable, while amd64-linux-tdep.o is
obviously there.
Fix the problem by adding svr4-tls-tdep.o to the object list, but only
when --enable-64-bit-bfd is provided.
Tom Tromey [Mon, 28 Jul 2025 16:06:00 +0000 (10:06 -0600)]
Require Tcl 8.6.2
This changes the gdb test suite to require Tcl 8.6.2. This allows the
removal of some more compatibility code.
I wrote this as a separate patch so make it simpler to drop if some
platform only provides Tcl 8.5. According to research in the bug,
though, it seems like this isn't likely.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33205 Approved-By: Simon Marchi <simon.marchi@efficios.com>
Alan Modra [Sun, 7 Sep 2025 23:07:13 +0000 (08:37 +0930)]
vms-alpha: ehdr checks
I noticed that _bfd_vms_slurp_ehdr wrongly used buf_size (rather than
rec_size) when sanity checking.
* vms-alpha.c (_bfd_vms_slurp_ehdr): Don't allow access to
uninitialised buffer memory. Tidy code generally, using
remaining record length for sanity checks.
Alan Modra [Sun, 7 Sep 2025 22:33:14 +0000 (08:03 +0930)]
PR 33385 vms archives
Commit 5c4ce239a3ab "Tidy bfdio to consistenly use containing archive"
broke vms archive handling, which has some horrible hacks involving
use of a special iovec for archive elements. Modify the generic
archive handling code to not use the archive iovec when it differs
from the element iovec.
Also, various commits involving seek optimisation broke the vms
archive handling, which needs to see a rewind on an archive element.
* bfdio.c (bfd_read, bfd_write, bfd_tell, bfd_flush),
(bfd_stat, bfd_seek, bfd_mmap): Do not use the archive
bfd for IO when the archive and element iovec differ.
* plugin.c (bfd_plugin_open_input),
(bfd_plugin_close_file_descriptor): Likewise.
* vms-lib.c (vms_lib_bopen): Force bfd_seek to call iovec seek.
Alan Modra [Sun, 7 Sep 2025 23:00:56 +0000 (08:30 +0930)]
PR 33385 unsupported relocs
Commit 96d3b80f5498 changed a couple of reloc functions to return
false, and propagated the error. They previously did nothing, so
revert to that sad state.
Alan Modra [Sun, 7 Sep 2025 22:56:43 +0000 (08:26 +0930)]
PR 33385 DST handling
Commit 816995444667, a fix for a fuzzer testcase resulting in a buffer
overflow, broke reading of DST. DST is a special case where a first
pass over the section just sizes it.
Commit a3c0896d80d2, another buffer overflow fix, wrongly removed a
line incrementing DST record length.
* vms-alpha.c (image_write): Don't do bounds check for
sections in memory without contents.
(evax_bfd_print_dst): Add one to length.
Alan Modra [Sun, 7 Sep 2025 22:46:21 +0000 (08:16 +0930)]
PR 33385, Extended Image Header
This modifies some of the PR 21813 fixes, allowing for smaller EIHD.
Not knowing any better, I chose to use EIHD__C_LENGTH as the minimum
length.
include/
* vms/eihd.h (EIHD__C_LENGTH): Comment.
bfd/
* vms-alpha.c (_bfd_vms_slurp_eihd): Remove size check
duplicating that done by the caller of this function.
(alpha_vms_object_p): Allow smaller EIHD.
(evax_bfd_print_image): Likewise. Don't print fields past
the record size.
gdb, amd64: extend the amd64 prologue analyzer to skip register pushes
A gdb_test_multiple exits early when processing the results of a
'disassemble' command, without waiting for the prompt to be seen.
This can leave unhandled output in expect's input buffer, which will
then throw off the next test.
Update the gdb_test_multiple to wait for the prompt before declaring
the test passed.
After this I'm no longer seeing the above failure.
There should be no change in what is tested after this commit.
Jan Beulich [Mon, 8 Sep 2025 09:11:51 +0000 (11:11 +0200)]
x86: constrain and fix use of the "nojumps" .arch modifier
As said by the paragraph of the description that isn't modified here (a
few lines up), this was only ever supposed to be used with 16-bit
architectures. Actually enforcing this allows code in
md_estimate_size_before_relax() to move to a less frequently used code
path. (For backwards compatibility, keep accepting "jumps" also with 32-
or 64-bit architectures.)
Repeat the constraint also in the 2nd paragraph of the doc on this
subject. And while there also insert a missing insn in the related
i386-Jumps section.
Furthermore checking a global variable during late processing is wrong. We
need to record the state in the fragment, and use that rather than the
state of the variable at the end of parsing all input.
Seeing that there's no testing of the functionality at all, add a testcase
as well.