Commit Graph

123453 Commits

Author SHA1 Message Date
Tom Tromey
ae912a65f9 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>
2025-09-10 16:07:58 -06:00
Tom Tromey
00dd832815 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>
2025-09-10 16:07:58 -06:00
Tom Tromey
8ac273ba2a Make dw_expand_symtabs_matching_file_matcher static
dw_expand_symtabs_matching_file_matcher is no longer needed outside of
read.c, so it can be made static.

Acked-By: Simon Marchi <simon.marchi@efficios.com>
2025-09-10 16:07:58 -06:00
Tom Tromey
86ac8c5462 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>
2025-09-10 16:07:57 -06:00
Tom Tromey
c879f4dc3e 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>
2025-09-10 16:07:57 -06:00
Tom Tromey
2d0e2b2612 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>
2025-09-10 16:07:57 -06:00
Tom Tromey
aa2d853044 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>
2025-09-10 16:07:57 -06:00
Tom Tromey
4a4ebdf9dd 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>
2025-09-10 16:07:57 -06:00
Tom Tromey
afd578774e Simplify block_lookup_symbol_primary
This simplifies block_lookup_symbol_primary by using
block_iterator_range.

Acked-By: Simon Marchi <simon.marchi@efficios.com>
2025-09-10 16:07:57 -06:00
Tom Tromey
5f99f39a39 Convert linespec.c:iterate_over_all_matching_symtabs
This converts linespec.c:iterate_over_all_matching_symtabs 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>
2025-09-10 16:07:57 -06:00
Tom Tromey
4a0b3e62a4 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>
2025-09-10 16:07:57 -06:00
Tom Tromey
ce889924a7 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>
2025-09-10 16:07:57 -06:00
Tom Tromey
0267b7bb32 Remove expand_symtabs_matching
The last caller of the global expand_symtabs_matching function has
been changed, so now we can remove this function.

Acked-By: Simon Marchi <simon.marchi@efficios.com>
2025-09-10 16:07:57 -06:00
Tom Tromey
b7561b2a31 Convert ada-lang.c:map_matching_symbols
This converts ada-lang.c:map_matching_symbols 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>
2025-09-10 16:07:57 -06:00
Tom Tromey
e271cb3281 Convert ada_language_defn::collect_symbol_completion_matches
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>
2025-09-10 16:07:57 -06:00
Tom Tromey
59cc52253e Convert ada_add_global_exceptions
This converts ada_add_global_exceptions 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>
2025-09-10 16:07:49 -06:00
Tom Tromey
1696b45a63 Convert gdbpy_lookup_static_symbols
This changes gdbpy_lookup_static_symbols 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>
2025-09-10 16:05:28 -06:00
Tom Tromey
5b66439bc8 Convert default_collect_symbol_completion_matches_break_on
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>
2025-09-10 16:05:28 -06:00
Tom Tromey
486bc5ac81 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
2025-09-10 16:05:28 -06:00
Tom Tromey
f88f9f42db 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>
2025-09-10 16:05:28 -06:00
Tom Tromey
29fa4279c2 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>
2025-09-10 16:05:28 -06:00
Tom Tromey
e7605fe0c0 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>
2025-09-10 16:05:27 -06:00
Tom Tromey
a6862c3322 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>
2025-09-10 16:05:27 -06:00
Tom Tromey
3c238e032f 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>
2025-09-10 16:05:27 -06:00
Tom Tromey
53e6563141 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>
2025-09-10 16:05:27 -06:00
Tom Tromey
a7343246f5 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>
2025-09-10 16:05:27 -06:00
Tom Tromey
0fa4f62568 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>
2025-09-10 16:05:27 -06:00
Tom Tromey
cfe3a766e6 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>
2025-09-10 16:05:27 -06:00
Tom Tromey
27de7d7bc3 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>
2025-09-10 16:05:27 -06:00
Tom Tromey
4ca244e7db 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>
2025-09-10 16:05:27 -06:00
Tom Tromey
f55320428b Remove support for .gdb_index < 7
This patch removes support for .gdb_index versions less than 7.  See
the patch that rewrites the reader to understand why this is needed.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Acked-By: Simon Marchi <simon.marchi@efficios.com>
2025-09-10 16:05:26 -06:00
Indu Bhagat
84c1e5cec0 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].

[1] https://sourceware.org/pipermail/binutils/2025-August/143829.html

This fixes PR gas/33414 - sframe: handle DW_CFA_GNU_args_size in gas better

gas/
	PR gas/33414
	* gen-sframe.c (sframe_xlate_do_escape_gnu_args_size): New
	definition.
	(sframe_xlate_do_cfi_escape): Handle DW_CFA_GNU_args_size.
gas/testsuite/
	PR gas/33414
	* gas/cfi-sframe/cfi-sframe.exp: New test.
	* gas/cfi-sframe/cfi-sframe-common-12.d: New test.
	* gas/cfi-sframe/cfi-sframe-common-12.s: New test.
	* gas/cfi-sframe/cfi-sframe-x86_64-3.d: New test.
	* gas/cfi-sframe/cfi-sframe-x86_64-3.s: New test.
2025-09-10 11:13:21 -07:00
Tom Tromey
2fe19b88c9 Fix var_arr_typedef.exp to preserve local variable
This patch fixes var_arr_typedef.exp to preserve a local variable a
bit better, protecting it from a gnat-llvm optimization.
2025-09-10 10:15:41 -06:00
H.J. Lu
86aa0d170d x86-64: Fix misleading R_X86_64_TPOFF32 error message
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.

ld/

	PR ld/33408
	* testsuite/ld-x86-64/tls-le-pic-1-x32.d: New file.
	* testsuite/ld-x86-64/tls-le-pic-1.d: Likewise.
	* testsuite/ld-x86-64/tls-le-pic-1.s: Likewise.
	* testsuite/ld-x86-64/tls-le-pic-2-x32.d: Likewise.
	* testsuite/ld-x86-64/tls-le-pic-2.d: Likewise.
	* testsuite/ld-x86-64/tls-le-pic-2.s: Likewise.
	* testsuite/ld-x86-64/tls-le-pic-3-x32.d: Likewise.
	* testsuite/ld-x86-64/tls-le-pic-3.d: Likewise.
	* testsuite/ld-x86-64/tls-le-pic-3.s: Likewise.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-09-10 06:13:43 -07:00
Matthieu Longo
f04c774b7d 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 d048eee291 [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.

[1]: https://inbox.sourceware.org/binutils/20250812143757.3565482-1-hjl
     .tools@gmail.com/
2025-09-10 14:03:35 +01:00
H.J. Lu
45f3ea0bbb Revert "binutils: Require GNU tail for 'objdump -Wi' test"
This reverts commit 897d8d7bba.
2025-09-10 05:15:55 -07:00
H.J. Lu
0a0918901a x86: Correct _bfd_x86_elf_copy_indirect_symbol comments
Since

commit eeb2f20a76
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Fri Sep 1 13:03:40 2017 -0700

    x86: Add _bfd_x86_elf_adjust_dynamic_symbol

replaced elf_i386_adjust_dynamic_symbol with
_bfd_x86_elf_copy_indirect_symbol, correct the comments.

	* elfxx-x86.c (_bfd_x86_elf_copy_indirect_symbol): Replace
	elf_i386_adjust_dynamic_symbol with
	_bfd_x86_elf_copy_indirect_symbol in comments.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-09-10 05:15:11 -07:00
Gopi Kumar Bulusu
c8af46a9cc MicroBlaze: Update gdb/NEWS for GNU/Linux gdbserver target
* gdb/NEWS : Add MicroBlaze gdbserver target

Signed-off-by: David Holsgrove <david.holsgrove@petalogix.com>
Signed-off-by: Nathan Rossi <nathan.rossi@petalogix.com>
Signed-off-by: Mahesh Bodapati <mbodapat@xilinx.com>
Signed-off-by: Gopi Kumar Bulusu <gopi@sankhya.com>
Approved-by: Michael J. Eager <eager@eagercon.com>
2025-09-10 11:07:40 +05:30
Gopi Kumar Bulusu
2dda928eb2 MicroBlaze: Update software breakpoint machine code as per MicroBlaze ISA
This patch updates breakpoint instruction machine code to be inline
with the specification in MicroBlaze ISA [1]

* gdb/microblaze-tdep.h : Update MICROBLAZE_BREAKPOINT

[1] https://docs.amd.com/r/en-US/ug984-vivado-microblaze-ref/brki

Signed-off-by: David Holsgrove <david.holsgrove@petalogix.com>
Signed-off-by: Nathan Rossi <nathan.rossi@petalogix.com>
Signed-off-by: Mahesh Bodapati <mbodapat@xilinx.com>
Signed-off-by: Gopi Kumar Bulusu <gopi@sankhya.com>
2025-09-10 10:46:28 +05:30
Tom Tromey
6038b11258 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>
2025-09-09 18:24:32 -06:00
Tom Tromey
c152f17e36 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>
2025-09-09 18:24:32 -06:00
Tom Tromey
8ea36fc9f3 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>
2025-09-09 18:24:32 -06:00
GDB Administrator
1faabbe632 Automatic date update in version.in 2025-09-10 00:01:15 +00:00
Alan Modra
aa644b6710 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.
2025-09-10 06:51:22 +09:30
Hannes Domani
b7e3459d2c Fix gdb.Value.dynamic_type attribute
gdb currently crashes if you try to get the dynamic_type from a
gdb.Value of a POD struct:

(gdb) py print(gdb.parse_and_eval('pod').dynamic_type)
Fatal signal: Segmentation fault

It happens because value_rtti_type() returns NULL for them, and this is
not handled correctly.

Fixed by using val->type() as a fallback in this case.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2025-09-09 21:11:27 +02:00
Tom Tromey
3719472095 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>
2025-09-09 11:59:04 -06:00
Tom Tromey
15e11aac9c Use c-ctype.h (not safe-ctype.h) in gdb
This changes gdb and related programs to use the gnulib c-ctype code
rather than safe-ctype.h.  The gdb-safe-ctype.h header is removed.

This changes common-defs.h to include the c-ctype header, making it
available everywhere in gdb.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33217
Approved-By: Simon Marchi <simon.marchi@efficios.com>
2025-09-09 11:58:27 -06:00
Tom Tromey
50673a4629 Import the c-ctype module from gnulib
This arranges to import the c-ctype module from gnulib.  c-ctype is
similar ot safe-ctype, but doesn't poison the <ctype.h> APIs.

This patch should not result in any functional changes, as nothing
includes the new header yet.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33217
Approved-By: Simon Marchi <simon.marchi@efficios.com>
2025-09-09 11:58:27 -06:00
Guinevere Larsen
a66526aca6 gdb: fix build with newest clang
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>
2025-09-09 12:38:41 -03:00
Tom Tromey
ea1bd34d53 Remove ada_binop_in_bounds
ada_binop_in_bounds can be merged with its sole caller.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2025-09-09 09:28:40 -06:00