Commit Graph

1191 Commits

Author SHA1 Message Date
Tom Tromey
df73a19dd8 Handle Ada extended access thick pointers
In Ada, sometimes an array is represented as a "thick" pointer -- a
structure that holds a pointer to the array data and another pointer
to the bounds structure.

A new "extended access" feature is being added to GNAT which changes
the shape of these objects.  With the new feature, the bounds are
inlined into the thick pointer.

This patch changes gdb to understand this new feature.  A test case is
provided; it is written in C to avoid requiring a newer GNAT just for
this test.

Approved-By: Andrew Burgess <aburgess@redhat.com>
2025-09-19 09:41:03 -06:00
Tom Tromey
6c82831fe6 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.
2025-09-11 11:59:58 -06:00
Tom Tromey
e68dd763a1 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.
2025-09-11 11:59:58 -06:00
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
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
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
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
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
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
Tom Tromey
118245e166 Remove ada_ternop_slice
ada_ternop_slice can be merged with its sole caller.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2025-09-09 09:28:22 -06:00
Tom Tromey
b1618ec21a Remove ada_equal_binop
ada_equal_binop can be merged with its sole caller.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2025-09-09 09:27:28 -06:00
Tom Tromey
cfd104b66c Remove ada_unop_in_range
ada_unop_in_range can be merged with its sole caller.  This change
points out that one of the arguments was not needed.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2025-09-09 09:27:04 -06:00
Simon Marchi
fbb487b451 gdb: make iterate_over_objfiles_in_search_order methods of program_space and solib_ops
Change the "iterate over objfiles in search order" operation from a
gdbarch method to methods on both program_space and solib_ops.

The first motivation for this is that I want to encapsulate solib-svr4's
data into svr4_solib_ops (in a subsequent series), instead of it being
in a separate structure (svr4_info).  It is awkward to do so as long as
there are entry points that aren't the public solib_ops interface.

The second motivation is my project of making it able to have multiple
solib_ops per program space (which should be the subject of said
subsequent series), to better support heterogenousa systems (like ROCm,
with CPU and GPU in the same inferior).  When we have this, when stopped
in GPU code, it won't make sense to ask the host's architecture to do
the iteration, as the logic could be different for the GPU architecture.
Instead, program_space::iterate_over_objfiles_in_search_order will be
responsible to delegate to the various solib_ops using a logic that is
yet to be determined.

I included this patch in this series (rather than the following one)
so that svr4_solib_ops::iterate_over_objfiles_in_search_order can access
svr4_solib_ops::default_debug_base, introduced in a later patch in this
series.

default_iterate_over_objfiles_in_search_order becomes the default
implementation of solib_ops::iterate_over_objfiles_in_search_order.

As far as I know, all architectures using
svr4_iterate_over_objfiles_in_search_order also use solib_ops_svr4, so I
don't expect this patch to cause behavior changes.

Change-Id: I71f8a800b8ce782ab973af2f2eb5fcfe4e06ec76
Reviewed-By: Guinevere Larsen <guinevere@redhat.com>
2025-08-22 10:45:47 -04:00
Simon Marchi
4260abb7a7 gdb: rename address_class -> location_class
The enum address_class and related fields and methods seem misnamed to
me.  Generalize it to "location_class".  The enumerators in
address_class are already prefixed with LOC, so the new name seems
logical to me.  Rename related fields and methods as well.

Plus, address_class could easily be mistaken for other unrelated things
named "address class" in GDB or DWARF.

Tested by rebuilding.

Change-Id: I0dca3738df412b350715286c608041b08e9b4d82
Approved-by: Kevin Buettner <kevinb@redhat.com>
2025-08-19 09:49:46 -04:00
Tom Tromey
89495c3326 Change type::fields to return an array_view
This patch changes type::fields to return an array_view of the fields,
then fixes up the fallout.

More cleanups would be possible here (in particular in the field
initialization code) but I haven't done so.

The main motivation for this patch was to make it simpler to iterate
over the fields of a type.

Regression tested on x86-64 Fedora 41.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2025-08-12 08:30:37 -06:00
Tom Tromey
5fe70629ce Change file initialization to use INIT_GDB_FILE macro
This patch introduces a new macro, INIT_GDB_FILE.  This is used to
replace the current "_initialize_" idiom when introducing a per-file
initialization function.  That is, rather than write:

    void _initialize_something ();
    void
    _initialize_something ()
    {
       ...
    }

... now you would write:

    INIT_GDB_FILE (something)
    {
       ...
    }

The macro handles both the declaration and definition of the function.

The point of this approach is that it makes it harder to accidentally
cause an initializer to be omitted; see commit 2711e475 ("Ensure
cooked_index_entry self-tests are run").  Specifically, the regexp now
used by make-init-c seems harder to trick.

New in v2: un-did some erroneous changes made by the script.

The bulk of this patch was written by script.
Regression tested on x86-64 Fedora 41.
2025-06-26 06:15:59 -06:00
Tom Tromey
762d4b9862 Use gdb::unordered_set for Ada symbol cache
This changes the Ada symbol cache to use gdb::unordered_set rather
than an htab.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2025-04-15 17:30:48 -06:00
Tom Tromey
82595d9e39 Use gdb::string_set for decoded_names_store
This patch changes decoded_names_store to use a gdb::string_set rather
than an htab.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2025-04-15 16:55:12 -06:00
Tom de Vries
7bef406490 [gdb/ada] Fix gdb.ada/overloads.exp on s390x
On s390x-linux, with test-case gdb.ada/overloads.exp and gcc 7.5.0 I run into:
...
(gdb) print Oload(CA)^M
Could not find a match for oload^M
(gdb) FAIL: $exp: print Oload(CA)
...

The mismatch happens here in ada_type_match:
...
      return ftype->code () == atype->code ();
...
with:
...
(gdb) p ftype->code ()
$3 = TYPE_CODE_TYPEDEF
(gdb) p atype->code ()
$4 = TYPE_CODE_ARRAY
...

At the start of ada_type_match, typedefs are skipped:
...
  ftype = ada_check_typedef (ftype);
  atype = ada_check_typedef (atype);
...
but immediately after this, refs are skipped:
...
  if (ftype->code () == TYPE_CODE_REF)
    ftype = ftype->target_type ();
  if (atype->code () == TYPE_CODE_REF)
    atype = atype->target_type ();
...
which in this case makes ftype a typedef.

Fix this by using ada_check_typedef after skipping the refs as well.

Tested on x86_64-linux and s390x-linux.

Approved-By: Tom Tromey <tom@tromey.com>

PR ada/32409
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32409
2025-04-15 16:59:32 +02:00
Tom Tromey
d01e823438 Update copyright dates to include 2025
This updates the copyright headers to include 2025.  I did this by
running gdb/copyright.py and then manually modifying a few files as
noted by the script.

Approved-By: Eli Zaretskii <eliz@gnu.org>
2025-04-08 10:54:39 -06:00
Tom Tromey
973c575967 Many minor typo fixes
I ran codespell on gdb/*.[chyl] and fixed a bunch of simple typos.
Most of what remains is trickier, i.e., spots where a somewhat natural
name of something in the code is flagged as a typo.

Reviewed-By: Tom de Vries <tdevries@suse.de>
2025-04-03 10:56:32 -06:00
Tom Tromey
f83d71e9c7 Update ada_add_block_renamings for compiler changes
With the hierarchical name patches to GNAT, ada_add_block_renamings
must now be updated as well -- the comment there about the supported
forms of DW_TAG_imported_declaration is no longer correct, and now
full names must sometimes be constructed during the lookup process.
2025-03-06 14:17:18 -07:00
Tom Tromey
7eccd2e407 Compare unqualified names in ada_identical_enum_types_p
With the coming changes to GNAT, gdb must compare the unqualified
names of two enum types.

Currently, GNAT will fully-qualify enumeration constant names, so for
instance one might see "enum_with_gap__lit4" as the name.

GNAT also may emit a copy of an enumeration type when a newtype is
involved.  E.g., in the arr_acc_idx_w_gap.exp test case, this can
occur for the base type of this subtype:

   type Enum_Subrange is new Enum_With_Gaps range Lit1 .. Lit3;

(Note that the base type of this subrange is anonymous.)

With some forthcoming changes to GNAT, these names will no longer be
qualified -- and because the newtype is anonymous, they can't be
identically qualified.  But, in gdb we still want "lit4" to resolve
without ambiguity in this scenario.

The fix is to change ada_identical_enum_types_p to compare unqualified
enum names.  This will work correctly with both variants of the
compiler, and with -fgnat-encodings=all as well.
2025-03-06 14:17:17 -07:00
Tom Tromey
a855184971 Use ada_identical_enum_types_p in ada_atr_enum_rep
With the coming changes to GNAT, we may see two distinct but
equivalent enum types in the DWARF.  In this case, it's better to use
ada_identical_enum_types_p rather than types_equal when comparing
these types... something that matters when using 'Enum_Rep.
2025-03-06 14:17:17 -07:00
Tom Tromey
56ddbf7284 Fix latent crash in ada_variant_discrim_name
ada_variant_discrim_name does this:

  for (discrim_end = name + strlen (name) - 6; discrim_end != name;

If NAME is too short, this will construct an invalid pointer, perhaps
causing a crash.

This patch arranges to check the length first.
2025-03-06 14:17:17 -07:00
Tom Tromey
29faeceaa8 Allow for anonymous Ada enumeration types
With some forthcoming changes to GNAT, gdb might see a nameless enum
in ada_resolve_enum, causing a crash.  This patch allows an anonymous
enum type to be considered identical to a named type when the contents
are identical.
2025-03-06 14:17:17 -07:00
Tom Tromey
5393cfd07a Avoid double-decoding in ada_add_global_exceptions
I noticed that ada_add_global_exceptions calls ada_decode on
'search_name' -- and then passes this to name_matches_regex, which
also calls ada_decode.

name_matches_regex is also used later, where the result of
'natural_name ()' is passed to it -- but natural_name also calls
ada_decode.

So, I think the call to ada_decode in name_matches_regex is redundant.
This patch removes it, and turns name_matches_regex into an inner
function to avoid propagating its use.

Note that, right now, the DWARF implementation of
expand_symtabs_matching does not in fact pass an encoded name to this
callback.  So, this code remains slightly (but currently harmlessly)
wrong.  expand_symtabs_matching is fixed by another pending series of
mine.
2025-03-06 07:08:14 -07:00
Tom Tromey
fbfadf9659 Avoid crash with 'length
While testing gnat-llvm, I found a gdb crash when applying 'length to
a non-array type.  This patch fixes the crash.
2025-01-22 08:08:25 -07:00
Tom Tromey
66834f8da9 Use block::is_static_block in ada-lang.c
This changes one spot in ada-lang.c to use block::is_static_block
rather than a hand-rolled implementation.  Note this also fixes the
call -- what is currently written there is wrong.

Approved-By: Tom de Vries <tdevries@suse.de>
2024-12-20 10:07:03 -07:00
Tom Tromey
f6dcf290ce Use generic_printstr from ada_language::printstr
Currently, if you create a lazy string while in Ada language mode, the
string will be rendered strangely, like:

    "["d0"]["9f"]["d1"]["80"]["d0"]["b8"]...

This happens because ada_printstr does not really handle UTF-8
decoding.

This patch changes ada_language::printstr to use generic_printstr when
UTF-8 is used.

Note that this code could probably be improved some more -- the
current patch only addresses the narrow case of the Python API.  I've
filed a follow-up bug (PR ada/32413) for the remaining changes.

Approved-By: Andrew Burgess <aburgess@redhat.com>
2024-12-12 07:41:12 -07:00
Tom Tromey
b6f3ac06ee Improve choice sorting in ada-lang.c
ada-lang.c has a "sort_choices" function that claims to sort the
symbol choices, but which does not really implement sorting.  This
patch changes this code to really sort the result vector, sorting
first by filename, then line number, and finally by the symbol name.

The filename sorting is done first by comparing basenames.  It turns
out that gnatmake and gprbuild invoke the compiler a bit differently,
so depending on which one you use, the results of a naive sort might
be different (due to the use of absolute or relative paths).
2024-11-20 13:18:40 -07:00
Tom Tromey
b6829c3c91 Use an iterator range for 'using' directives
This patch changes block::get_using to return an iterator range.  This
seemed cleaner to me than the current approach of returning a pointer
to the first using directive; all the callers actually use this to
iterate.
2024-11-11 07:51:05 -07:00
Tom Tromey
fc55e99ad7 Wrap help strings at 80 columns
This patch ensures that all ordinary help strings are wrapped at 80
columns.  For the most part this consists of changing code like this
(note the embedded \n and the trailing backslash without a newline):

-Manage the space-separated list of debuginfod server URLs that GDB will query \
-when missing debuginfo, executables or source files.\nThe default value is \
-copied from the DEBUGINFOD_URLS environment variable."),

... to end each line with \n\, like:

+Manage the space-separated list of debuginfod server URLs that GDB will\n\
+query when missing debuginfo, executables or source files.\n\
+The default value is copied from the DEBUGINFOD_URLS environment variable."),

Approved-By: Eli Zaretskii <eliz@gnu.org>
2024-11-11 07:44:27 -07:00
Tom Tromey
04ce6b03d9 Implement 'Object_Size
This patch started as an attempt to allow the 'Size attribute to be
applied to types, and not just objects.

However, that turns out to be difficult due to the Ada semantcs of
'Size.  In particular, Ada requires 'Size to denote the size of the
representation of the value, so for example Boolean'Size must be 1.
Implementing this properly requires information not readily available
to gdb... and while we could synthesize this information in many
cases, it also seemed to me that this wasn't strictly very useful when
debugging.

So instead, this patch adds support for the 'Object_Size attribute,
which is somewhat closer to 'sizeof'.

Note also that while 'Object_Size is defined for some dynamic types, I
chose not to implement this here, as again this information is not
readily available -- and I think it's preferable to error than to
print something that might be incorrect.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
2024-10-22 12:04:06 -06:00
Tom de Vries
8f6606b6e3 [gdb] Fix common misspellings
Fix the following common misspellings:
...
accidently -> accidentally
additonal -> additional
addresing -> addressing
adress -> address
agaisnt -> against
albiet -> albeit
arbitary -> arbitrary
artifical -> artificial
auxillary -> auxiliary
auxilliary -> auxiliary
bcak -> back
begining -> beginning
cannonical -> canonical
compatiblity -> compatibility
completetion -> completion
diferent -> different
emited -> emitted
emiting -> emitting
emmitted -> emitted
everytime -> every time
excercise -> exercise
existance -> existence
fucntion -> function
funtion -> function
guarentee -> guarantee
htis -> this
immediatly -> immediately
layed -> laid
noone -> no one
occurances -> occurrences
occured -> occurred
originaly -> originally
preceeded -> preceded
preceeds -> precedes
propogate -> propagate
publically -> publicly
refering -> referring
substract -> subtract
substracting -> subtracting
substraction -> subtraction
taht -> that
targetting -> targeting
teh -> the
thier -> their
thru -> through
transfered -> transferred
transfering -> transferring
upto -> up to
vincinity -> vicinity
whcih -> which
whereever -> wherever
wierd -> weird
withing -> within
writen -> written
wtih -> with
doesnt -> doesn't
...

Tested on x86_64-linux.
2024-10-06 07:59:48 +02:00
Andrew Burgess
bcb92f7ba7 gdb: more file name styling
While looking at the recent line number styling commit I noticed a few
places where we could add more file name styling.  So lets do that.

Approved-By: Tom Tromey <tom@tromey.com>
2024-10-02 10:10:20 +01:00
Tom Tromey
1ce2312391 Introduce and use operation::type_p
There's currently code in gdb that checks if an expression evaluates
to a type.  In some spots this is done by comparing the opcode against
OP_TYPE, but other spots more correctly also compare with OP_TYPEOF
and OP_DECLTYPE.

This patch cleans up this area, replacing opcode-checking with a new
method on 'operation'.

Generally, checking the opcode should be considered deprecated,
although it's unfortunately difficult to get rid of opcodes entirely.

I also took advantage of this change to turn eval_op_type into a
method, removing a bit of indirection.

Reviewed-by: Keith Seitz <keiths@redhat.com>
2024-10-01 13:25:25 -06:00
Tom de Vries
00105aa1c4 [gdb/symtab] Don't expand non-Ada CUs for info exceptions
I noticed when running test-case gdb.ada/info_exc.exp with glibc debug info
installed, that the "info exceptions" command that lists all Ada exceptions
also expands non-Ada CUs, which includes CUs in
/lib64/ld-linux-x86-64.so.2 and /lib64/libc.so.6.

Fix this by:
- adding a new lang_matcher parameter to the expand_symtabs_matching
  function, and
- using that new parameter in the expand_symtabs_matching call in
  ada_add_global_exceptions.

The new parameter is a hint, meaning implementations are free to ignore it and
expand CUs with any language.  This is the case for partial symtabs, I'm not
sure whether it makes sense to implement support for this there.

Conversely, when processing a CU with language C and name "<artificial>"
(as produced by GCC LTO), the CU may not really have a single language and we
should ignore the lang_matcher.  See also commit d2f6771173
("Fix 'catch exception' with -flto").

Now that we have lang_matcher available, also use it to limit name splitting
styles and symbol matchers to those applicable to the matched languages.

Without this patch we have (with a gdb build with -O0):
...
$ time gdb -q -batch -x outputs/gdb.ada/info_exc/gdb.in.1 > /dev/null
real	0m1.866s
user	0m2.089s
sys	0m0.120s
...
and with this patch we have:
...
$ time gdb -q -batch -x outputs/gdb.ada/info_exc/gdb.in.1 > /dev/null
real	0m0.469s
user	0m0.777s
sys	0m0.051s
...

Or, to put it in terms of number of CUs, we have 1853 CUs:
...
$ gdb -q -batch -readnow outputs/gdb.ada/info_exc/foo \
    -ex start \
    -ex "maint info symtabs" \
    | grep -c " name "
1853
...

Without this patch, we have:
...
$ gdb -q -batch outputs/gdb.ada/info_exc/foo \
    -ex start \
    -ex "info exceptions" \
    -ex "maint info symtabs" \
    | grep -c " name "
1393
...
so ~75% of the CUs is expanded, and with this patch we have:
...
$ gdb <same-as-above>
20
...
so ~1% of the CUs is expanded.

Tested on x86_64-linux.

Approved-By: Tom Tromey <tom@tromey.com>

PR symtab/32182
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32182
2024-09-24 10:24:22 +02:00
Tom Tromey
2bf0419eea Move enum size check into ada_identical_enum_types_p
Currently, the callers of ada_identical_enum_types_p must check that
both enum types have the same number of members.  In another series
I'm working on, it was convenient to move this check into the callee
instead; and I broke this patch out to make that series a little
simpler.

Approved-By: Tom de Vries <tdevries@suse.de>
2024-09-09 11:47:17 -06:00
Tom Tromey
511c6575b2 Minor cleanup to ada_identical_enum_types_p
This moves the declaration of 'i' into the 'for' loops in
ada_identical_enum_types_p.  This is just a trivial cleanup.

Approved-By: Tom de Vries <tdevries@suse.de>
2024-09-09 11:47:17 -06:00
Tom Tromey
6b82623187 Boolify ada_identical_enum_types_p
This changes ada_identical_enum_types_p to return bool rather than
int.

Approved-By: Tom de Vries <tdevries@suse.de>
2024-09-09 11:47:17 -06:00
Andrew Burgess
6cce025114 gdb: only insert thread-specific breakpoints in the relevant inferior
This commit updates GDB so that thread or inferior specific
breakpoints are only inserted into the program space in which the
specific thread or inferior is running.

In terms of implementation, getting this basically working is easy
enough, now that a breakpoint's thread or inferior field is setup
prior to GDB looking for locations, we can easily use this information
to find a suitable program_space and pass this to as a filter when
creating the sals.

Or we could if breakpoint_ops::create_sals_from_location_spec allowed
us to pass in a filter program_space.

So, this commit extends breakpoint_ops::create_sals_from_location_spec
to take a program_space argument, and uses this to filter the set of
returned sals.  This accounts for about half the change in this patch.

The second set of changes starts from breakpoint_set_thread and
breakpoint_set_inferior, this is called when the thread or inferior
for a breakpoint changes, e.g. from the Python API.

Previously this call would never result in the locations of a
breakpoint changing, after all, locations were inserted in every
program space, and we just use the thread or inferior variable to
decide when we should stop.  Now though, changing a breakpoint's
thread or inferior can mean we need to figure out a new set of
breakpoint locations.

To support this I've added a new breakpoint_re_set_one function, which
is like breakpoint_re_set, but takes a single breakpoint, and just
updates the locations for that one breakpoint.  We only need to call
this function if the program_space in which a breakpoint's thread (or
inferior) is running actually changes.  If the program_space does
change then we call the new breakpoint_re_set_one function passing in
the program_space which should be used to filter the new locations (or
nullptr to indicate we should set locations in all program spaces).
This filter program_space needs to propagate down to all the re_set
methods, this accounts for the remaining half of the changes in this
patch.

There were a couple of existing tests that created thread or inferior
specific breakpoints and then checked the 'info breakpoints' output,
these needed updating.  These were:

  gdb.mi/user-selected-context-sync.exp
  gdb.multi/bp-thread-specific.exp
  gdb.multi/multi-target-continue.exp
  gdb.multi/multi-target-ping-pong-next.exp
  gdb.multi/tids.exp
  gdb.mi/new-ui-bp-deleted.exp
  gdb.multi/inferior-specific-bp.exp
  gdb.multi/pending-bp-del-inferior.exp

I've also added some additional tests to:

  gdb.multi/pending-bp.exp

I've updated the documentation and added a NEWS entry.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
2024-09-07 21:48:35 +01:00
Tom Tromey
d2f6771173 Fix 'catch exception' with -flto
A user noticed that when an Ada program (including the runtime) is
compiled with -flto, then "catch exception" does not work -- even
though setting the equivalent breakpoint by hand does work.

Looking into this, it turns out that GCC puts the exception functions
from the Ada runtime into a CU that uses the C language, not Ada.
Then, when trying to look up the relevant symbol,
lookup_name_info::search_name_hash uses the "verbatim" form of the
symbol name (like "<__gnat_debug_raise_exception>") rather than the
"<>"-less form, causing the symbol not to be found.

This patch fixes the problem in two steps.

First, lookup_name_info::search_name_hash is changed to use the same
hack that language_defn::get_symbol_name_matcher uses.  That is, when
the current language is Ada, verbatim-mode lookups are special-cased.
(This is a bit unfortunate; perhaps a better long term approach would
be to promote verbatim mode to a fundamental mode of
lookup_name_info.)

Second, although the above fixes the problem in the Ada language mode,
the code still fails in other languages.  However, due to the way
these lookups are coded in ada-lang.c, I think it makes sense to
temporarily set the current language to Ada in
create_ada_exception_catchpoint.

Tested on x86-64 Fedora 38.

A new test case that mimics the -flto scenario is included.

Reviewed-By: Alexandra Petlanova Hajkova <ahajkova@redhat.com>
2024-09-06 12:31:50 -06:00
Tom Tromey
6a4eb277b7 Clear Ada symbol cache
This patch changes "maint flush symbol-cache" to also flush the
Ada-specific symbol cache.  This can be helpful when working on the
Ada code.

Approved-By: Tom de Vries <tdevries@suse.de>
2024-09-06 11:08:41 -06:00
Tom de Vries
bbc8c5a1d1 [gdb] Fix typos
Fix a few typos.

unconditionaly -> unconditionally
gratuitiously -> gratuitously
configureable -> configurable
represention -> representation
distiguished -> distinguished
breakpointer -> breakpoint
asssignments -> assignments
architectual -> architectural
compatibity -> compatibility
adjustement -> adjustment
unexcepted -> unexpected
propogated -> propagated
consistant -> consistent
succeding -> succeeding
higlight -> highlight
detachs -> detach

Tested by rebuilding on x86_64-linux.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2024-09-03 17:30:37 +02:00
Tom Tromey
16ffddc6b9 Simplify ada_identical_enum_types_p
This patch changes ada_identical_enum_types_p to reuse the field names
that are computed earlier in the loop.  This is a simple cleanup, but
also is useful for a larger change that I'm working on.

Tested on x86-64 Fedora 38.
2024-08-26 13:29:04 -06:00
Tom Tromey
a55790e992 Use SEARCH_FUNCTION_DOMAIN when looking for Ada exception symbols
While working on another bug, I noticed that the Ada code to find
exception symbols uses SEARCH_VFT.  This will find variables and types
-- but only functions are needed here.  This patch changes the code to
use SEARCH_FUNCTION_DOMAIN.

Tested on x86-64 Fedora 38, using a version of GNAT with the debuginfo
installed, to ensure the exception-related tests work.

Reviewed-by: Keith Seitz <keiths@redhat.com>
2024-08-20 07:58:06 -06:00
Simon Marchi
4144d36a68 gdb: add program_space parameter to lookup_minimal_symbol
>From what I can see, lookup_minimal_symbol doesn't have any dependencies
on the global current state other than the single reference to
current_program_space.  Add a program_space parameter and make that
current_program_space reference bubble up one level.

Change-Id: I759415e2f9c74c9627a2fe05bd44eb4147eee6fe
Reviewed-by: Keith Seitz <keiths@redhat.com>
Approved-By: Andrew Burgess <aburgess@redhat.com>
2024-08-12 10:31:09 -04:00