Commit Graph

1151 Commits

Author SHA1 Message Date
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
Simon Marchi
c8979ae4fb gdb: make lookup_minimal_symbol objf and sfile parameters optional
Most calls to lookup_minimal_symbol don't pass a value for sfile and
objf.  Make these parameters optional (have a default value of
nullptr).  And since passing a value to `objf` is much more common than
passing a value to `sfile`, swap the order so `objf` comes first, to
avoid having to pass a nullptr value to `sfile` when wanting to pass a
value to `objf`.

Change-Id: I8e9cc6b942e593bec640f9dfd30f62786b0f5a27
Reviewed-by: Keith Seitz <keiths@redhat.com>
Approved-By: Andrew Burgess <aburgess@redhat.com>
2024-08-12 10:31:09 -04:00
Simon Marchi
03b40f6f55 gdb: drop struct keyword when using bound_minimal_symbol
This is a simple find / replace from "struct bound_minimal_symbol" to
"bound_minimal_symbol", to make things shorter and more consisten
througout.  In some cases, move variable declarations where first used.

Change-Id: Ica4af11c4ac528aa842bfa49a7afe8fe77a66849
Reviewed-by: Keith Seitz <keiths@redhat.com>
Approved-By: Andrew Burgess <aburgess@redhat.com>
2024-08-12 10:31:09 -04:00
Tom de Vries
de272a5e90 [gdb/exp] Allow internal function to indicate return type
Currently an internal function handler has this prototype:
...
struct value *handler (struct gdbarch *gdbarch,
                       const struct language_defn *language,
                       void *cookie, int argc, struct value **argv);
...

Also allow an internal function with a handler with an additional
"enum noside noside" parameter:
...
struct value *handler (struct gdbarch *gdbarch,
                       const struct language_defn *language, void *cookie,
                       int argc, struct value **argv, enum noside noside);
...

In case such a handler is called with noside == EVAL_AVOID_SIDE_EFFECTS, it's
expected to return some value with the correct return type.

At least, provided it can do so without side effects, otherwise it should
throw an error.

No functional changes.

Tested on x86_64-linux and aarch64-linux.

Reviewed-By: Keith Seitz <keiths@redhat.com>
2024-07-24 16:32:35 +02:00
Simon Marchi
134a0a106c gdb: make objfile::pspace private
Rename to m_pspace, add getter.  An objfile's pspace never changes, so
no setter is necessary.

Change-Id: If4dfb300cb90dc0fb9776ea704ff92baebb8f626
2024-07-15 13:55:00 +00:00
Tom Tromey
3739147957 Simplify ada_lookup_encoded_symbol
This patch simplifies ada_lookup_encoded_symbol by having it return
its result, rather than returning void and having an out parameter.
2024-06-14 11:18:22 -06:00
Simon Marchi
05d9d66d92 gdb: remove unused includes in utils.h
Remove some includes reported as unused by clangd.  Add some includes in
other files that were previously relying on the transitive include.

Change-Id: Ibdd0a998b04d21362a20d0ca8e5267e21e2e133e
2024-05-30 22:43:52 -04:00
Simon Marchi
5b9707eb87 gdb: remove gdbcmd.h
Most files including gdbcmd.h currently rely on it to access things
actually declared in cli/cli-cmds.h (setlist, showlist, etc).  To make
things easy, replace all includes of gdbcmd.h with includes of
cli/cli-cmds.h.  This might lead to some unused includes of
cli/cli-cmds.h, but it's harmless, and much faster than going through
the 170 or so files by hand.

Change-Id: I11f884d4d616c12c05f395c98bbc2892950fb00f
Approved-By: Tom Tromey <tom@tromey.com>
2024-04-25 12:59:02 -04:00
Simon Marchi
e5dc0d5d04 gdb: move a bunch of quit-related things to event-top.{c,h}
Move some declarations related to the "quit" machinery from defs.h to
event-top.h.  Most of the definitions associated to these declarations
are in event-top.c.  The exceptions are `quit()` and `maybe_quit()`,
that are defined in utils.c.  For consistency, move these two
definitions to event-top.c.

Include "event-top.h" in many files that use these things.

Change-Id: I6594f6df9047a9a480e7b9934275d186afb14378
Approved-By: Tom Tromey <tom@tromey.com>
2024-04-23 11:26:14 -04:00
Simon Marchi
ec45252592 gdb: move store/extract integer functions to extract-store-integer.{c,h}
Move the declarations out of defs.h, and the implementations out of
findvar.c.

I opted for a new file, because this functionality of converting
integers to bytes and vice-versa seems a bit to generic to live in
findvar.c.

Change-Id: I524858fca33901ee2150c582bac16042148d2251
Approved-By: John Baldwin <jhb@FreeBSD.org>
2024-04-22 21:34:19 -04:00
Tom Tromey
542ea7fe46 Implement Ada 2022 iterated assignment
Ada 2022 includes iterated assignment for array initialization.  This
patch implements a subset of this for gdb.  In particular, only arrays
with integer index types really work -- currently there's no decent
way to get the index type in EVAL_AVOID_SIDE_EFFECTS mode during
parsing.  Fixing this probably requires the Ada parser to take a
somewhat more sophisticated approach to type resolution; and while
this would help fix another bug in this area, this patch is already
useful without it.
2024-04-02 11:24:27 -06:00
Tom Tromey
d9d782dd8b Introduce and use aggregate_assigner type
This patch is a refactoring to add a new aggregate_assigner type.
This type is passed to Ada aggregate assignment operations in place of
passing a number of separate arguments.  This new approach makes it
simpler to change some aspects of aggregate assignment behavior.
2024-04-02 11:24:26 -06:00
Simon Marchi
18d2988e5d gdb, gdbserver, gdbsupport: remove includes of early headers
Now that defs.h, server.h and common-defs.h are included via the
`-include` option, it is no longer necessary for source files to include
them.  Remove all the inclusions of these files I could find.  Update
the generation scripts where relevant.

Change-Id: Ia026cff269c1b7ae7386dd3619bc9bb6a5332837
Approved-By: Pedro Alves <pedro@palves.net>
2024-03-26 21:13:22 -04:00
Tom Tromey
7e949f0870 Implement Ada 2022 delta aggregates
Ada 2022 includes a "delta aggregates" feature that can sometimes
simplify aggregate creation.  This patch implements this feature for
GDB.
2024-03-21 12:29:49 -06:00
Tom Tromey
1ab9eefe3c Speed up lookup of "type_specific_data"
I noticed that "info locals" on a certain large Ada program was very
slow.  I tracked this down to ada_get_tsd_type expanding nearly every
CU in the program.

This patch fixes the problem by changing this code to use the more
efficient lookup_transparent_type which, unlike the Ada-specific
lookup functions, does not try to find all matching instances.

Note that I first tried fixing this by changing ada_find_any_type, but
this did not work -- I may revisit this approach at some later date.

Also note that the copyright dates on the test files are set that way
because I copied them from another test.

New in v2: the new test failed on the Linaro regression tester.
Looking at the logs, it seems that gdb was picking up a 'value' from
libgnat:

    $1 = {<text variable, no debug info>} 0xf7e227a4 <ada.calendar.formatting.value>

This version renames the local variable in an attempt to work around
this.

v3: In v2, while trying to reproduce the problem locally, I
accidentally forgot to commit one of the changes.
2024-03-19 11:53:21 -06:00
Tom Tromey
1dd09e7f70 Fix Ada 'ptype' of access to array
ptype is a bit funny, in that it accepts both expressions and type
names.  It also evaluates the resulting expression using
EVAL_AVOID_SIDE_EFFECTS -- which both seems sensible (as a user would
you expect ptype to possibly cause inferior execution?), but is also a
historical artifact of how expressions are implemented (there's no
EVAL_FOR_TYPE).

In Ada, calling a function with an array will sometimes result in a
"thick pointer" array descriptor being made.  This is essentially a
structure holding a pointer and bounds information.

Currently, in such a callee, printing the type of the array will yield
funny results:

    (gdb) print str.all
    $1 = "Hello World"
    (gdb) ptype str
    type = array (<>) of character
    (gdb) ptype str.all
    type = array (1 .. 0) of character

That "1 .. 0" is the result of an EVAL_AVOID_SIDE_EFFECTS branch
trying to do "something" with an array descriptor, without doing too
much.

I tried briefly to make this code really dereference the array
descriptor and get the correct runtime type.  However, that proved to
be tricky; it certainly can't be done for all access types, because
that will cause dynamic type resolution and end up printing just the
runtime type -- which with variants may be pretty far from what the
user may expect.

Instead, this patch arranges to just leave such types alone in this
situation.  I don't think this should have an extra effects, because
things like array subscripting still work on thick pointers.

This patch also touches arrayptr.exp, because in that case the access
type is a "thin pointer", and this ensures that the output does not
change in that scenario.
2024-03-18 08:22:37 -06:00
Tom Tromey
4c3b59d5ba Remove two unnecessary casts
I noticed a spot in ada-lang.c where the return value of
value_as_address was cast to CORE_ADDR -- a no-op cast.  I searched
and found another.  This patch fixes both.
2024-02-26 13:50:54 -07:00
Simon Marchi
8480a37e14 gdb: pass frames as const frame_info_ptr &
We currently pass frames to function by value, as `frame_info_ptr`.
This is somewhat expensive:

 - the size of `frame_info_ptr` is 64 bytes, which is a bit big to pass
   by value
 - the constructors and destructor link/unlink the object in the global
   `frame_info_ptr::frame_list` list.  This is an `intrusive_list`, so
   it's not so bad: it's just assigning a few points, there's no memory
   allocation as if it was `std::list`, but still it's useless to do
   that over and over.

As suggested by Tom Tromey, change many function signatures to accept
`const frame_info_ptr &` instead of `frame_info_ptr`.

Some functions reassign their `frame_info_ptr` parameter, like:

  void
  the_func (frame_info_ptr frame)
  {
    for (; frame != nullptr; frame = get_prev_frame (frame))
      {
        ...
      }
  }

I wondered what to do about them, do I leave them as-is or change them
(and need to introduce a separate local variable that can be
re-assigned).  I opted for the later for consistency.  It might not be
clear why some functions take `const frame_info_ptr &` while others take
`frame_info_ptr`.  Also, if a function took a `frame_info_ptr` because
it did re-assign its parameter, I doubt that we would think to change it
to `const frame_info_ptr &` should the implementation change such that
it doesn't need to take `frame_info_ptr` anymore.  It seems better to
have a simple rule and apply it everywhere.

Change-Id: I59d10addef687d157f82ccf4d54f5dde9a963fd0
Approved-By: Andrew Burgess <aburgess@redhat.com>
2024-02-20 10:42:25 -05:00
Tom Tromey
a8b1650962 Handling of arrays with optimized-out bounds
In Ada, sometimes the compiler must emit array bounds by referencing
an artificial variable that's created for this purpose.  However, with
optimization enabled, these variables can be optimized away.

Currently this can result in displays like:

    (gdb) print mumble
    $1 = (warning: unable to get bounds of array, assuming null array
    )

This patch changes this to report that the array is optimized-out,
instead, which is closer to the truth, and more generally useful.  For
example, Python pretty-printers can now recognize this situation.

In order to accomplish this, I introduced a new PROP_OPTIMIZED_OUT
enumerator and changed one place to use it.  Reusing the "unknown"
state wouldn't work properly, because in C it is normal for array
bounds to be unknown.
2024-02-05 07:13:37 -07:00
Tom Tromey
f214edceb8 Rename SEARCH_ALL
The constant SEARCH_ALL conflicts with a define in a Windows header.
This patch renames the constant to SEARCH_ALL_DOMAINS to avoid the
conflict.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31307
2024-02-01 07:10:57 -07:00
Tom Tromey
54d186cf65 Simplify some symbol searches in Ada code
This changes some of the Ada code to simplify symbol searches.  For
example, if a function is being looked for, the search is narrowed to
use SEARCH_FUNCTION_DOMAIN rather than SEARCH_VFT.  In one spot, a
search of the "struct" domain is removed, because Ada does not have a
tag domain.
2024-01-28 10:58:16 -07:00
Tom Tromey
ccf41c2487 Use domain_search_flags in lookup_symbol et al
This changes lookup_symbol and associated APIs to accept
domain_search_flags rather than a domain_enum.

Note that this introduces some new constants to Python and Guile.  I
chose to break out the documentation patch for this, because the
internals here do not change until a later patch, and it seemed
simpler to patch the docs just once, rather than twice.
2024-01-28 10:58:16 -07:00
Tom Tromey
6c01521494 Use domain_search_flags in lookup_global_symbol_language
This changes quick_symbol_functions::lookup_global_symbol_language to
accept domain_search_flags rather than just a domain_enum, and fixes
up the fallout.

To avoid introducing any regressions, any code passing VAR_DOMAIN now
uses SEARCH_VFT.

That is, no visible changes should result from this patch.  However,
it sets the stage to refine some searches later on.
2024-01-28 10:58:16 -07:00
Tom Tromey
c92d4de16a Replace search_domain with domain_search_flags
This patch changes gdb to replace search_domain with
domain_search_flags everywhere.  search_domain is removed.
2024-01-28 10:58:16 -07:00
Andrew Burgess
1d506c26d9 Update copyright year range in header of all files managed by GDB
This commit is the result of the following actions:

  - Running gdb/copyright.py to update all of the copyright headers to
    include 2024,

  - Manually updating a few files the copyright.py script told me to
    update, these files had copyright headers embedded within the
    file,

  - Regenerating gdbsupport/Makefile.in to refresh it's copyright
    date,

  - Using grep to find other files that still mentioned 2023.  If
    these files were updated last year from 2022 to 2023 then I've
    updated them this year to 2024.

I'm sure I've probably missed some dates.  Feel free to fix them up as
you spot them.
2024-01-12 15:49:57 +00:00
Tom Tromey
d56fdf1b97 Refine Ada overload matching
Currently, the overload handling in Ada assumes that any two array
types are compatible.  However, this is obviously untrue, and a user
reported an oddity where comparing two Ada strings resulted in a call
to the "=" function for packed boolean arrays.

This patch improves the situation somewhat, by requiring that the two
arrays have the same arity and compatible base element types.  This is
still over-broad, but it seems safe and is better than the status quo.
2023-12-15 14:03:48 -07:00
Tom Tromey
1414fbf941 Boolify ada_type_match
This changes ada_type_match to return bool.
2023-12-15 14:03:48 -07:00
Tom Tromey
957ce53750 Always use expand_symtabs_matching in ada-lang.c
The previous patch fixed the immediate performance problem with Ada
name matching, by having a subset of matches call
expand_symtabs_matching rather than expand_matching_symbols.  However,
it seemed to me that expand_matching_symbols should not be needed at
all.

To achieve this, this patch changes ada_lookup_name_info::split_name
to use the decoded name, rather than the encoded name.  In order to
make this work correctly, a new decoded form is used: one that does
not decode operators (this is already done) and also does not decode
wide characters.  The latter change is done so that changes to the Ada
source charset don't affect the DWARF index.

With this in place, we can change ada-lang.c to always use
expand_symtabs_matching rather than expand_matching_symbols.
2023-12-06 10:14:24 -07:00
Tom Tromey
47cd8fcf54 Improve performance of Ada name searches
A user reported that certain operations -- like printing a large
structure -- could be slow.  I tracked this down to
ada-lang.c:map_matching_symbols taking an inordinate amount of time.
Specifically, calls like the one to look for a parallel "__XVZ"
variable, in ada_to_fixed_type_1, could result in gdb walking over all
the entries in the cooked index over and over.

Looking into this reveals that
cooked_index_functions::expand_matching_symbols is not written
efficiently -- it ignores its "ordered_compare" parameter.  While
fixing this would be good, it turns out that this entire method isn't
needed; so this series removes it.

However, the deletion is not done in this patch.  This one, instead,
fixes the immediate cause of the slowdown, by using
objfile::expand_symtabs_matching when possible.  This approach is
faster because it is more selective about which index entries to
examine.
2023-12-06 10:07:36 -07:00
Tom Tromey
d182e39881 Use C++17 [[fallthrough]] attribute
This changes gdb to use the C++17 [[fallthrough]] attribute rather
than special comments.

This was mostly done by script, but I neglected a few spellings and so
also fixed it up by hand.

I suspect this fixes the bug mentioned below, by switching to a
standard approach that, presumably, clang supports.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=23159
Approved-By: John Baldwin <jhb@FreeBSD.org>
Approved-By: Luis Machado <luis.machado@arm.com>
Approved-By: Pedro Alves <pedro@palves.net>
2023-11-29 14:29:43 -07:00
Lancelot Six
882b050516 gdb: Remove uses of gdb::to_string (const std::string_view &)
This patch removes all uses of to_string(const std::string_view&) and
use the std::string ctor or implicit conversion from std::string_view to
std::string instead.

A later patch will remove this gdb::to_string while removing
gdbsupport/gdb_string_view.h.

Change-Id: I877cde557a0727be7b0435107e3c7a2aac165895
Approved-By: Tom Tromey <tom@tromey.com>
Approved-By: Pedro Alves <pedro@palves.net>
2023-11-21 11:52:36 +00:00
Lancelot Six
8082468ffe gdb: Use std::string_view instead of gdb::string_view
Given that GDB now requires a C++17, replace all uses of
gdb::string_view with std::string_view.

This change has mostly been done automatically:
- gdb::string_view -> std::string_view
- #include "gdbsupport/gdb_string_view.h" -> #include <string_view>

One things which got brought up during review is that gdb::stging_view
does support being built from "nullptr" while std::sting_view does not.
Two places are manually adjusted to account for this difference:
gdb/tui/tui-io.c:tui_getc_1 and
gdbsupport/format.h:format_piece::format_piece.

The above automatic change transformed
"gdb::to_string (const gdb::string_view &)" into
"gdb::to_string (const std::string_view &)".  The various direct users
of this function are now explicitly including
"gdbsupport/gdb_string_view.h".  A later patch will remove the users of
gdb::to_string.

The implementation and tests of gdb::string_view are unchanged, they will
be removed in a following patch.

Change-Id: Ibb806a7e9c79eb16a55c87c6e41ad396fecf0207
Approved-By: Tom Tromey <tom@tromey.com>
Approved-By: Pedro Alves <pedro@palves.net>
2023-11-21 11:52:36 +00:00
Lancelot Six
6b09f1342c gdb: Replace gdb::optional with std::optional
Since GDB now requires C++17, we don't need the internally maintained
gdb::optional implementation.  This patch does the following replacing:
  - gdb::optional -> std::optional
  - gdb::in_place -> std::in_place
  - #include "gdbsupport/gdb_optional.h" -> #include <optional>

This change has mostly been done automatically.  One exception is
gdbsupport/thread-pool.* which did not use the gdb:: prefix as it
already lives in the gdb namespace.

Change-Id: I19a92fa03e89637bab136c72e34fd351524f65e9
Approved-By: Tom Tromey <tom@tromey.com>
Approved-By: Pedro Alves <pedro@palves.net>
2023-11-21 11:52:35 +00:00
Simon Marchi
99d9c3b92c gdb: remove target_gdbarch
This function is just a wrapper around the current inferior's gdbarch.
I find that having that wrapper just obscures where the arch is coming
from, and that it's often used as "I don't know which arch to use so
I'll use this magical target_gdbarch function that gets me an arch" when
the arch should in fact come from something in the context (a thread,
objfile, symbol, etc).  I think that removing it and inlining
`current_inferior ()->arch ()` everywhere will make it a bit clearer
where that arch comes from and will trigger people into reflecting
whether this is the right place to get the arch or not.

Change-Id: I79f14b4e4934c88f91ca3a3155f5fc3ea2fadf6b
Reviewed-By: John Baldwin <jhb@FreeBSD.org>
Approved-By: Andrew Burgess <aburgess@redhat.com>
2023-10-10 10:44:35 -04:00
Simon Marchi
74daa597e7 gdb: add all_objfiles_removed observer
The new_objfile observer is currently used to indicate both when a new
objfile is added to program space (when passed non-nullptr) and when all
objfiles of a program space were just removed (when passed nullptr).
I think this is confusing (and Andrew apparently thinks so too [1]).
Add a new "all_objfiles_removed" observer to remove the second role from
"new_objfile".

Some existing users of new_objfile do nothing if the passed objfile is
nullptr.  For them, we can simply drop the nullptr check.  For others,
add a new all_objfiles_removed callback, and refactor things a bit to
keep the existing behavior as much as possible.

Some callbacks relied on current_program_space, and following
the refactoring now use either objfile->pspace or the pspace passed to
all_objfiles_removed.  I think this should be relatively safe, and in
general a step in the right direction.

On the notify side, I found only one call site to change from
new_objfile to all_objfiles_removed, in clear_symtab_users.  It is not
entirely clear to me that this is entirely correct.  clear_symtab_users
appears to be called in spots that don't remove all objfiles
(functions finish_new_objfile, remove_symbol_file_command, reread_symbols,
do_module_cleanups).  But I think that this patch at least makes the
current code clearer.

[1] a0a031bce0

Change-Id: Icb648f72862e056267f30f44dd439bd4ec766f13
Approved-By: Tom Tromey <tom@tromey.com>
2023-10-05 13:20:50 -04:00
Simon Marchi
6114d65078 gdb: add program_space parameter to ada_clear_symbol_cache
Make the references to current_program_space bubble up one level.

Change-Id: I82acab5628c30f6535d52aa32ce2c1d0375cbeed
Approved-By: Tom Tromey <tom@tromey.com>
2023-10-05 13:20:50 -04:00
Tom Tromey
26733fc747 Add is_array_like and to_array to language_defn
This adds new is_array_like and to_array methods to language_defn.
This will be used in a subsequent patch that generalizes the new
Python array- and string-handling code.
2023-09-19 13:28:42 -06:00
Tom Tromey
8e032233a0 Use gdb::checked_static_cast for catchpoints
This replaces some casts to various kinds of catchpoint with
checked_static_cast.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2023-09-19 08:14:01 -06:00
Tom de Vries
74c36641b0 [gdb/ada] Extend type equivalence test in ada_resolve_enum
When running test-case gdb.ada/local-enum.exp with target board debug-types, I
run into:
...
(gdb) print v1(three)^M
No name 'three' in enumeration type 'local__e1'^M
(gdb) FAIL: gdb.ada/local-enum.exp: print v1 element
...

The array V1 is of type A1 which is an array with index type E1, containing
"three" as enumerator:
...
  type E1 is (one, two, three);
  type A1 is array (E1) of Integer;
  V1 : A1 := (0, 1, 2);
...

There's also a type E2 that contains three as enumerator:
...
  type E2 is (three, four, five);
...

When doing "print v1(three)", it's the job of ada_resolve_enum to resolve
"three" to type E1 rather than type E2.

When using target board debug-types, the enums E1 and E2 are replicated in the
.debug_types section, and consequently in ada_resolve_enum the type
equivalence check using a pointer comparison fails:
...
  for (int i = 0; i < syms.size (); ++i)
    {
      /* We already know the name matches, so we're just looking for
	 an element of the correct enum type.  */
      if (ada_check_typedef (syms[i].symbol->type ()) == context_type)
 	return i;
    }
...

Fix this by also trying a structural comparison using
ada_identical_enum_types_p.

Tested on x86_64-linux.

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

PR ada/29335
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29335
2023-09-07 21:53:17 +02:00
Tom de Vries
ef136c7fa1 [gdb/ada] Move identical enums handling later
When running test-case gdb.ada/arr_acc_idx_w_gap.exp with target board
cc-with-dwz, I run into:
...
(gdb) print enum_with_gaps'enum_rep(lit3)^M
'Enum_Rep requires argument to have same type as enum^M
(gdb) FAIL: gdb.ada/arr_acc_idx_w_gap.exp: enum_rep
...

With target_board unix, we have instead:
...
(gdb) print enum_with_gaps'enum_rep(lit3)^M
$16 = 13^M
(gdb) PASS: gdb.ada/arr_acc_idx_w_gap.exp: enum_rep
...

Conversely, when I add this test to the test-case:
...
     gdb_test "print enum_with_gaps'enum_rep(lit3)" " = 13" \
 	"enum_rep"
+    gdb_test "print enum_subrange'enum_rep(lit3)" " = 13" \
+	"other enum_rep"
...
the extra test passes with target board cc-with-dwz, but fails with target
board unix.

The problem is here in remove_extra_symbols:
...
  if (symbols_are_identical_enums (syms))
    syms.resize (1);
...
where one of the two identical enums is picked before the enum_rep handling
can resolve lit3 to one of the two.

Fix this by moving the code to ada_resolve_variable.

Tested on x86_64-linux.

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

PR ada/30726
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30726
2023-09-07 21:39:42 +02:00
Tom Tromey
cf1eca3cbb Use ada_value_subscript in valpy_getitem
Ada has a few complexities when it comes to array handling.  Currently
these are all handled in Ada-specific code -- but unfortunately that
means they aren't really accessible to Python.

This patch changes the Python code to defer to Ada when given an Ada
array.  In order to make this work, one spot in ada-lang.c had to be
updated to set the "GNAT-specific" flag on an array type.

The test case for this will come in a later patch.
2023-09-05 11:02:34 -06:00