Commit Graph

957 Commits

Author SHA1 Message Date
Tom Tromey
d66beefaf6 Simplify Ada catchpoints
All the Ada catchpoints use the same breakpoint_ops contents, because
the catchpoint itself records its kind.  This patch simplifies the
code by removing the redundant ops structures.
2022-01-18 10:34:05 -07:00
Tom Tromey
d322d6d69d Move gdb_regex to gdbsupport
This moves the gdb_regex convenience class to gdbsupport.
2022-01-18 10:14:43 -07:00
Tom Tromey
bf31fd38f0 Move gdb obstack code to gdbsupport
This moves the gdb-specific obstack code -- both extensions like
obconcat and obstack_strdup, and things like auto_obstack -- to
gdbsupport.
2022-01-18 10:14:42 -07:00
Joel Brobecker
4a94e36819 Automatic Copyright Year update after running gdb/copyright.py
This commit brings all the changes made by running gdb/copyright.py
as per GDB's Start of New Year Procedure.

For the avoidance of doubt, all changes in this commits were
performed by the script.
2022-01-01 19:13:23 +04:00
Tom Tromey
696d6f4d5c Use for-each more in gdb
There are some loops in gdb that use ARRAY_SIZE (or a wordier
equivalent) to loop over a static array.  This patch changes some of
these to use foreach instead.

Regression tested on x86-64 Fedora 34.
2021-12-08 13:20:30 -07:00
Tom de Vries
af5300fe24 [gdb/ada] Fix assert in ada_is_unconstrained_packed_array_type
On openSUSE Leap 42.3, with system compiler gcc 4.8.5 I run into:
...
(gdb) print u_one_two_three^M
src/gdb/gdbtypes.h:1050: internal-error: field: \
 Assertion `idx >= 0 && idx < num_fields ()' failed.^M
...

We run into trouble while doing this in
ada_is_unconstrained_packed_array_type:
...
1953          return TYPE_FIELD_BITSIZE (type, 0) > 0;
...
which tries to get field 0 from a type without fields:
...
(gdb) p type->num_fields ()
$6 = 0
...
which is the case because the type is a typedef:
...
(gdb) p type->code ()
$7 = TYPE_CODE_TYPEDEF
...

Fix this by using the type referenced by the typedef instead.

Tested on x86_64-linux.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28323
2021-12-07 07:35:10 +01:00
Simon Marchi
fb2a515fd0 gdb: revert one array_view copy change in ada-lang.c
Commit 4bce7cdaf4 ("gdbsupport: add array_view copy function") caused
an internal error when running gdb.ada/packed_array_assign.exp:

    print pra(1) := pr^M
    /home/smarchi/src/binutils-gdb/gdb/../gdbsupport/array-view.h:217: internal-error: copy: Assertion `dest.size () == src.size ()' failed.^M

I am not sure what's the root cause of this, whether it is a GDB bug
exposed by using the array_view copy function or not.  Back out the
change that triggers the internal error for now, while we investigate
it.

Change-Id: I055ab14143e4cfd3ca7ce8f4855c6c3c05db52a7
2021-12-03 20:43:19 -05:00
Simon Marchi
4bce7cdaf4 gdbsupport: add array_view copy function
An assertion was recently added to array_view::operator[] to ensure we
don't do out of bounds accesses.  However, when the array_view is copied
to or from using memcpy, it bypasses that safety.

To address this, add a `copy` free function that copies data from an
array view to another, ensuring that the destination and source array
views have the same size.  When copying to or from parts of an
array_view, we are expected to use gdb::array_view::slice, which does
its own bounds check.  With all that, any copy operation that goes out
of bounds should be caught by an assertion at runtime.

copy is implemented using std::copy and std::copy_backward, which, at
least on libstdc++, appears to pick memmove when copying trivial data.
So in the end there shouldn't be much difference vs using a bare memcpy,
as we do right now.  When copying non-trivial data, std::copy and
std::copy_backward assigns each element in a loop.

To properly support overlapping ranges, we must use std::copy or
std::copy_backward, depending on whether the destination is before the
source or vice-versa.  std::copy and std::copy_backward don't support
copying exactly overlapping ranges (where the source range is equal to
the destination range).  But in this case, no copy is needed anyway, so
we do nothing.

The order of parameters of the new copy function is based on std::copy
and std::copy_backward, where the source comes before the destination.

Change a few randomly selected spots to use the new function, to show
how it can be used.

Add a test for the new function, testing both with arrays of a trivial
type (int) and of a non-trivial type (foo).  Test non-overlapping
ranges as well as three kinds of overlapping ranges: source before dest,
dest before source, and dest == source.

Change-Id: Ibeaca04e0028410fd44ce82f72e60058d6230a03
2021-12-03 16:37:36 -05:00
Andrew Burgess
8579fd136a gdb/gdbsupport: make xstrprintf and xstrvprintf return a unique_ptr
The motivation is to reduce the number of places where unmanaged
pointers are returned from allocation type routines.  All of the
callers are updated.

There should be no user visible changes after this commit.
2021-11-16 17:45:45 +00:00
Simon Marchi
313f3b21cb gdb: remove bpstat typedef, rename bpstats to bpstat
I don't find that the bpstat typedef, which hides a pointer, is
particularly useful.  In fact, it confused me many times, and I just see
it as something to remember that adds cognitive load.  Also, with C++,
we might want to be able to pass bpstats objects by const-reference, not
necessarily by pointer.

So, remove the bpstat typedef and rename struct bpstats to bpstat (since
it represents one bpstat, it makes sense that it is singular).

Change-Id: I52e763b6e54ee666a9e045785f686d37b4f5f849
2021-11-08 16:39:14 -05:00
Simon Marchi
970db51860 gdb: remove TYPE_FIELD_ENUMVAL
Remove TYPE_FIELD_ENUMVAL, replace with type::field +
field::loc_enumval.

Change-Id: I2ada73e4635aad3363ce2eb22c1dc52698ee2072
2021-10-29 16:44:45 -04:00
Simon Marchi
b610c04548 gdb: remove TYPE_FIELD_BITPOS
Remove TYPE_FIELD_BITPOS, replace its uses with type::field +
field::loc_bitpos.

Change-Id: Iccd8d5a77e5352843a837babaa6bd284162e0320
2021-10-29 16:44:44 -04:00
Simon Marchi
f54bdb6d27 gdb: add add_setshow_prefix_cmd
There's a common pattern to call add_basic_prefix_cmd and
add_show_prefix_cmd to add matching set and show commands.  Add the
add_setshow_prefix_cmd function to factor that out and use it at a few
places.

Change-Id: I6e9e90a30e9efb7b255bf839cac27b85d7069cfd
2021-10-28 10:44:18 -04:00
Simon Marchi
50888e42dc gdb: change functions returning value contents to use gdb::array_view
The bug fixed by this [1] patch was caused by an out-of-bounds access to
a value's content.  The code gets the value's content (just a pointer)
and then indexes it with a non-sensical index.

This made me think of changing functions that return value contents to
return array_views instead of a plain pointer.  This has the advantage
that when GDB is built with _GLIBCXX_DEBUG, accesses to the array_view
are checked, making bugs more apparent / easier to find.

This patch changes the return types of these functions, and updates
callers to call .data() on the result, meaning it's not changing
anything in practice.  Additional work will be needed (which can be done
little by little) to make callers propagate the use of array_view and
reap the benefits.

[1] https://sourceware.org/pipermail/gdb-patches/2021-September/182306.html

Change-Id: I5151f888f169e1c36abe2cbc57620110673816f3
2021-10-25 14:51:44 -04:00
Tom Tromey
4d1795ac4d Fix latent Ada bug when accessing field offsets
The "add accessors for field (and call site) location" patch caused a
gdb crash when running the internal AdaCore testsuite.  This turned
out to be a latent bug in ada-lang.c.

The immediate cause of the bug is that find_struct_field
unconditionally uses TYPE_FIELD_BITPOS.  This causes an assert for a
dynamic type.

This patch fixes the problem by doing two things.  First, it changes
find_struct_field to use a dummy value for the field offset in the
situation where the offset is not actually needed by the caller.  This
works because the offset isn't used in any other way -- only as a
result.

Second, this patch assures that calls to find_struct_field use a
resolved type when the offset is needed.  For
value_tag_from_contents_and_address, this is done by resolving the
type explicitly.  In ada_value_struct_elt, this is done by passing
nullptr for the out parameters when they are not needed (the second
call in this function already uses a resolved type).

Note that, while we believe the parent field probably can't occur at a
variable offset, the patch still updates this code path, just in case.

I've updated an existing test case to reproduce the crash.
I'm checking this in.
2021-10-21 08:24:40 -06:00
Tom Tromey
5a8edb756a Check index in type::field
This changes gdb to check the index that is passed to type::field.
This caught one bug in the Ada code when running the test suite
(actually I found the bug first, then realized that the check would
have helped), so this patch fixes that as well.

Regression tested on x86-64 Fedora 34.
2021-10-19 13:30:59 -06:00
Simon Marchi
cd3f655cc7 gdb: add accessors for field (and call site) location
Add accessors for the various location values in struct field.  This
lets us assert that when we get a location value of a certain kind (say,
bitpos), the field's location indeed contains a value of that kind.

Remove the SET_FIELD_* macros, instead use the new setters directly.
Update the FIELD_* macros used to access field locations to go through
the getters.  They will be removed in a subsequent patch.

There are places where the FIELD_* macros are used on call_site_target
structures, because it contains members of the same name (loc_kind and
loc).  For now, I have replicated the getters/setters in
call_site_target.  But we could perhaps eventually factor them in a
"location" structure that can be used at both places.

Note that the field structure, being zero-initialized, defaults to a
bitpos location with value 0.  While writing this patch, I tried to make
it default to an "unset" location, to catch places where we would miss
setting a field's location.  However, I found that some places relied on
the default being "bitpos 0", so I left it as-is.  This change could
always be done as follow-up work, making these places explicitly set the
"bitpos 0" location.

I found two issues to fix:

 - I got some failures in the gdb.base/infcall-nested-structs-c++.exp
   test.  They were caused by two functions in amd64-tdep.c using
   TYPE_FIELD_BITPOS before checking if the location is of the bitpos
   kind, which they do indirectly through `field_is_static`.  Simply
   move getting the bitpos below the field_is_static call.

 - I got a failure in gdb.xml/tdesc-regs.exp.  It turns out that in
   make_gdb_type_enum, we set enum field values using SET_FIELD_BITPOS,
   and later access them through FIELD_ENUMVAL.  Fix that by using
   set_loc_enumval to set the value.

Change-Id: I53d3734916c46457576ba11dd77df4049d2fc1e8
2021-10-07 11:03:54 -04:00
Tom Tromey
acbf4a58ef Remove 'varsize-limit'
This makes the Ada-specific "varsize-limit" a synonym for
"max-value-size", and removes the Ada-specific checks of the limit.

I am not certain of the history here, but it seems to me that this
code is fully obsolete now.  And, removing this makes it possible to
index large Ada arrays without triggering an error.  A new test case
is included to demonstrate this.
2021-10-05 12:35:24 -06:00
Tom Tromey
3456e70c9d Use unique_xmalloc_ptr<char> when demangling
I noticed that some methods in language_defn could use
unique_xmalloc_ptr<char> rather than a plain 'char *'.  This patch
implements this change, fixing up the fallout and changing
gdb_demangle to also return this type.  In one spot, std::string is
used to simplify some related code, and in another, an auto_obstack is
used to avoid manual management.

Regression tested on x86-64 Fedora 34.
2021-10-04 13:45:38 -06:00
Simon Marchi
33d16dd987 gdb: remove TYPE_FIELD_NAME and FIELD_NAME macros
Remove the `TYPE_FIELD_NAME` and `FIELD_NAME` macros, changing all the
call sites to use field::name directly.

Change-Id: I6900ae4e1ffab1396e24fb3298e94bf123826ca6
2021-09-30 22:05:57 -04:00
Simon Marchi
d3fd12dfc5 gdb: add field::name / field::set_name
Add the `name` and `set_name` methods on `struct field`, in order to
remove `FIELD_NAME` and `TYPE_FIELD_NAME` macros.  In this patch, the
macros are changed to use `field::name`, so all the call sites that are
used to set the field's name are changed to use `field::set_name`.
The next patch will remove the macros completely.

Note that because of the name clash between the existing field named
`name` and the new method, I renamed the field `m_name`.  It is not
private per-se, because we can't make `struct field` a non-POD yet, but
it should be considered private anyway (not accessed outside `struct
field`).

Change-Id: If16ddbca4e0c39d0ff9da420bb5cdebe5b9b0896
2021-09-30 22:05:46 -04:00
Tom Tromey
7ebaa5f782 Move value_true to value.h
I noticed that value_true is declared in language.h and defined in
language.c.  However, as part of the value API, I think it would be
better in one of those files.  And, because it is very short, I
changed it to be an inline function in value.h.  I've also removed a
comment from the implementation, on the basis that it seems obsolete
-- if the change it suggests was needed, it probably would have been
done by now; and if it is needed in the future, odds are it would be
done differently anyway.

Finally, this patch also changes value_true and value_logical_not to
return a bool, and updates some uses.
2021-09-24 11:58:04 -06:00
Tom de Vries
2c71f639a0 [gdb/ada] Handle artificial local symbols
With current master and gcc 7.5.0/8.5.0, we have this timeout:
...
(gdb) print s^M
Multiple matches for s^M
[0] cancel^M
[1] s at src/gdb/testsuite/gdb.ada/interface/foo.adb:20^M
[2] s at src/gdb/testsuite/gdb.ada/interface/foo.adb:?^M
> FAIL: gdb.ada/interface.exp: print s (timeout)
...

[ The FAIL doesn't reproduce with gcc 9.3.1.  This difference in
behaviour bisects to gcc commit d70ba0c10de.

The FAIL with earlier gcc bisects to gdb commit ba8694b650. ]

The FAIL is caused by gcc generating this debug info describing a named
artificial variable:
...
 <2><1204>: Abbrev Number: 31 (DW_TAG_variable)
    <1205>   DW_AT_name        : s.14
    <1209>   DW_AT_type        : <0x1213>
    <120d>   DW_AT_artificial  : 1
    <120d>   DW_AT_location    : 5 byte block: 91 e0 7d 23 18   \
      (DW_OP_fbreg: -288; DW_OP_plus_uconst: 24)
...

An easy way to fix this would be to simply not put named artificial variables
into the symbol table.  However, that causes regressions for Ada.  It relies
on being able to get the value from such variables, using a named reference.

Fix this instead by marking the symbol as artificial, and:
- ignoring such symbols in ada_resolve_variable, which fixes the FAIL
- ignoring such ada symbols in do_print_variable_and_value, which prevents
  them from showing up in "info locals"

Note that a fix for the latter was submitted here (
https://sourceware.org/pipermail/gdb-patches/2008-January/054994.html ), and
this patch borrows from it.

Tested on x86_64-linux.

Co-Authored-By: Joel Brobecker  <brobecker@adacore.com>

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28180
2021-09-18 09:25:49 +02:00
Tom Tromey
965bc1df87 Handle compiler-generated suffixes in Ada names
The compiler may add a suffix to a mangled name.  A typical example
would be splitting a function and creating a ".cold" variant.

This patch changes Ada decoding (aka demangling) to handle these
suffixes.  It also changes the encoding process to handle them as
well.

A symbol like "function.cold" will now be displayed to the user as
"function[cold]".  The "." is not simply preserved because that is
already used in Ada.
2021-08-02 10:48:30 -06:00
Tom Tromey
ba8694b650 Handle type qualifier for enumeration name
Pierre-Marie noticed that the Ada expression "TYPE'(NAME)" resolved
incorrectly when "TYPE" was an enumeration type.  Here, "NAME" should
be unambiguous.

This patch fixes this problem.  Note that the patch is not perfect --
it does not give an error if TYPE is an enumeration type but NAME is
not an enumerator but does have some other meaning in scope.  Fixing
this proved difficult, and so I've left it out.
2021-08-02 10:11:23 -06:00
Tom Tromey
03adb248d6 Defer Ada character literal resolution
In Ada, an enumeration type can use a character literal as one of the
enumerators.  The Ada expression parser handles the appropriate
conversion.

It turns out, though, that this conversion was handled incorrectly.
For an expression like TYPE'(EXP), the conversion would be done for
any such literal appearing in EXP -- but only the outermost such
expression should really be affected.

This patch defers the conversion until the resolution phase, fixing
the bug.
2021-08-02 10:11:22 -06:00
Tom Tromey
8b12db26d1 Refactor Ada resolution
In a subsequent patch, it will be convenient if an Ada expression
operation can supply its own replacement object.  This patch refactors
Ada expression resolution to make this possible.
2021-08-02 10:11:22 -06:00
Tom Tromey
cd4583499f Remove add_symbols_from_enclosing_procs
I noticed that add_symbols_from_enclosing_procs is empty, and can be
removed.  The one caller, ada_add_local_symbols, can also be
simplified, removing some code that, I think, was an incorrect attempt
to handle nested functions.
2021-08-02 10:11:22 -06:00
Simon Marchi
0f8e203412 gdb: add context getter/setter to cmd_list_element
Straightforward replacement of get_cmd_context / set_cmd_context with
cmd_list_element methods.

gdb/ChangeLog:

	* cli/cli-decode.h (struct cmd_list_element) <set_context,
	context>: New.
	<context>: Rename to...
	<m_context>: ... this.
	* cli/cli-decode.c (set_cmd_context, get_cmd_context): Remove.
	* command.h (set_cmd_context, get_cmd_context): Remove, use
	cmd_list_element::set_context and cmd_list_element::context
	everywhere instead.

Change-Id: I5016b0079014e3f17d1aa449ada7954473bf2b5d
2021-06-25 21:35:40 -04:00
Andrew Burgess
158cc4feb7 gdb: use gdb::optional instead of passing a pointer to gdb::array_view
Following on from the previous commit, this commit changes the API of
value_struct_elt to take gdb::optional<gdb::array_view<value *>>
instead of a pointer to the gdb::array_view.

This makes the optional nature of the array_view parameter explicit.

This commit is purely a refactoring commit, there should be no user
visible change after this commit.

I have deliberately kept this refactor separate from the previous two
commits as this is a more extensive change, and I'm not 100% sure that
using gdb::optional for the parameter type, instead of a pointer, is
going to be to everyone's taste.  If there's push back on this patch
then this one can be dropped from the series.

gdb/ChangeLog:

	* ada-lang.c (desc_bounds): Use '{}' instead of NULL to indicate
	an empty gdb::optional when calling value_struct_elt.
	(desc_data): Likewise.
	(desc_one_bound): Likewise.
	* eval.c (structop_base_operation::evaluate_funcall): Pass
	gdb::array_view, not a gdb::array_view* to value_struct_elt.
	(eval_op_structop_struct): Use '{}' instead of NULL to indicate
	an empty gdb::optional when calling value_struct_elt.
	(eval_op_structop_ptr): Likewise.
	* f-lang.c (fortran_structop_operation::evaluate): Likewise.
	* guile/scm-value.c (gdbscm_value_field): Likewise.
	* m2-lang.c (eval_op_m2_high): Likewise.
	(eval_op_m2_subscript): Likewise.
	* opencl-lang.c (opencl_structop_operation::evaluate): Likewise.
	* python/py-value.c (valpy_getitem): Likewise.
	* rust-lang.c (rust_val_print_str): Likewise.
	(rust_range): Likewise.
	(rust_subscript): Likewise.
	(eval_op_rust_structop): Likewise.
	(rust_aggregate_operation::evaluate): Likewise.
	* valarith.c (value_user_defined_op): Likewise.
	* valops.c (search_struct_method): Change parameter type, update
	function body accordingly, and update header comment.
	(value_struct_elt): Change parameter type, update function body
	accordingly.
	* value.h (value_struct_elt): Update declaration.
2021-06-25 20:43:06 +01:00
Tom Tromey
8a3df5acae Add non-wrapping mode to ada_decode
When ada_decode encounters a name that it cannot decode, it simply
wraps it in <...>, which is used elsewhere in the Ada code to indicate
that a verbatim match should be done.

A subequent patch needed the ability to suppress this wrapping, so
this patch adds a new mode to ada_decode.

2021-06-25  Tom Tromey  <tromey@adacore.com>

	* ada-lang.c (ada_decode): Add wrap parameter.
	* ada-lang.h (ada_decode): Add wrap parameter.
2021-06-25 08:07:21 -06:00
Simon Marchi
24b21115f5 gdb: fix tab after space indentation issues
I spotted some indentation issues where we had some spaces followed by
tabs at beginning of line, that I wanted to fix.  So while at it, I did
a quick grep to find and fix all I could find.

gdb/ChangeLog:

	* Fix tab after space indentation issues throughout.

Change-Id: I1acb414dd9c593b474ae2b8667496584df4316fd
2021-05-27 15:18:49 -04:00
Simon Marchi
40cb8ca539 gdb: add breakpoint::locations method
Add the breakpoint::locations method, which returns a range that can be
used to iterate over a breakpoint's locations.  This shortens

  for (bp_location *loc = b->loc; loc != nullptr; loc = loc->next)

into

  for (bp_location *loc : b->locations ())

Change all the places that I found that could use it.

gdb/ChangeLog:

	* breakpoint.h (bp_locations_range): New.
	(struct breakpoint) <locations>: New.  Use where possible.

Change-Id: I1ba2f7d93d57e544e1f8609124587dcf2e1da037
2021-05-27 14:58:37 -04:00
Marco Barisione
4915bfdcfb gdb: Add an overloaded ui_out::text accepting a const std::string &
gdb/ChangeLog:

	* ui-out.h (class ui_out): Add ui_out::text accepting a constant
	reference to a std::string.  Fix all callers using
	std::string::c_str.
	* ui-out.c (ui_out::text): Ditto.
2021-05-19 13:58:40 +01:00
Marco Barisione
2f822da535 gdb: generate the prefix name for prefix commands on demand
Previously, the prefixname field of struct cmd_list_element was manually
set for prefix commands.  This seems verbose and error prone as it
required every single call to functions adding prefix commands to
specify the prefix name while the same information can be easily
generated.

Historically, this was not possible as the prefix field was null for
many commands, but this was fixed in commit
3f4d92ebdf by Philippe Waroquiers, so
we can rely on the prefix field being set when generating the prefix
name.

This commit also fixes a use after free in this scenario:
* A command gets created via Python (using the gdb.Command class).
  The prefix name member is dynamically allocated.
* An alias to the new command is created. The alias's prefixname is set
  to point to the prefixname for the original command with a direct
  assignment.
* A new command with the same name as the Python command is created.
* The object for the original Python command gets freed and its
  prefixname gets freed as well.
* The alias is updated to point to the new command, but its prefixname
  is not updated so it keeps pointing to the freed one.

gdb/ChangeLog:

	* command.h (add_prefix_cmd): Remove the prefixname argument as
	it can now be generated automatically.  Update all callers.
	(add_basic_prefix_cmd): Ditto.
	(add_show_prefix_cmd): Ditto.
	(add_prefix_cmd_suppress_notification): Ditto.
	(add_abbrev_prefix_cmd): Ditto.
	* cli/cli-decode.c (add_prefix_cmd): Ditto.
	(add_basic_prefix_cmd): Ditto.
	(add_show_prefix_cmd): Ditto.
	(add_prefix_cmd_suppress_notification): Ditto.
	(add_prefix_cmd_suppress_notification): Ditto.
	(add_abbrev_prefix_cmd): Ditto.
	* cli/cli-decode.h (struct cmd_list_element): Replace the
	prefixname member variable with a method which generates the
	prefix name at runtime.  Update all code reading the prefix
	name to use the method, and remove all code setting it.
	* python/py-cmd.c (cmdpy_destroyer): Remove code to free the
	prefixname member as it's now a method.
	(cmdpy_function): Determine if the command is a prefix by
	looking at prefixlist, not prefixname.
2021-05-12 11:19:22 +01:00
Tom Tromey
2698f5ead6 Remove streq_hash in favor of htab_eq_string
Now that libiberty includes htab_eq_string, we can remove the
identical function from gdb.

gdb/ChangeLog
2021-05-07  Tom Tromey  <tom@tromey.com>

	* breakpoint.c (ambiguous_names_p): Use htab_eq_string.
	* utils.c (streq_hash): Remove.
	* utils.h (streq_hash): Don't declare.
	* completer.c (completion_tracker::discard_completions): Update
	comment.
	* ada-lang.c (_initialize_ada_language): Use htab_eq_string.
2021-05-07 09:18:18 -06:00
Tom Tromey
2869ac4b59 Fix crash with GNAT minimal encodings
Running the AdaCore internal test suite with -fgnat-encodings=minimal
found a gdb crash.  The bug is that GDB ends up with a typedef in
ada_index_type, resulting in a NULL dereference.

This crash can be reproduced using GCC 11 with the included test case.

Tested on x86-64 Fedora 32.  Because this is Ada-specific, and was
already reviewed by Joel, I am going to check it in.

2021-04-30  Tom Tromey  <tromey@adacore.com>

	* ada-lang.c (ada_index_type): Use ada_check_typedef.

gdb/testsuite/ChangeLog
2021-04-30  Tom Tromey  <tromey@adacore.com>

	* gdb.ada/enum_idx_packed/pck.ads (My_Enum, My_Array_Type)
	(Confused_Array): New types.
	* gdb.ada/enum_idx_packed/foo.adb (Confused_Array): New variable.
	* gdb.ada/enum_idx_packed.exp: Add new tests.
2021-04-30 07:33:01 -06:00
Tom Tromey
db2534b704 Fix Ada overloading with 'null'
Currently, the Ada expression parser treats 'null' as an integer 0.
However, this causes overloading to fail in certain cases.

This patch changes the Ada expression parser to use a special type for
'null'.  I chose pointer-to-int0, because I think that's not likely to
be needed for any other Ada expression.  Note this works because a
"mod 1" type has an underlying non-zero byte size; the test includes a
check for this.

The output is changed so that "print null", by default, shows "null".
And, ada_type_match is changed both to recognize the special null type
and to remove a bit of weird code related to how pointers are treated
for overload type matching.

Tested on x86-64 Fedora 32.  Because this only touches Ada, and Joel
already approved it internally at AdaCore, I am checking it in.

gdb/ChangeLog
2021-04-28  Tom Tromey  <tromey@adacore.com>

	* ada-exp.y (primary): Use new type for null pointer.
	* ada-lang.c (ada_type_match): Remove "may_deref"
	parameter.  Handle null pointer.
	(ada_args_match): Update.
	* ada-valprint.c (ada_value_print_ptr, ada_value_print):
	Handle null pointer.

gdb/testsuite/ChangeLog
2021-04-28  Tom Tromey  <tromey@adacore.com>

	* gdb.ada/null_overload.exp: New file.
	* gdb.ada/null_overload/foo.adb: New file.
2021-04-28 10:19:57 -06:00
Simon Marchi
c90e7d6352 gdbsupport, gdb: give names to observers
Give a name to each observer, this will help produce more meaningful
debug message.

gdbsupport/ChangeLog:

	* observable.h (class observable) <struct observer> <observer>:
	Add name parameter.
	<name>: New field.
	<attach>: Add name parameter, update all callers.

Change-Id: Ie0cc4664925215b8d2b09e026011b7803549fba0
2021-04-24 19:26:41 -04:00
Tom Tromey
0b7b2c2adf Simplify quick_symbol_functions::map_matching_symbols
quick_symbol_functions::map_matching_symbols is only used by the Ada
code.  Currently, it both expands certain psymtabs and then walks over
the full symtabs -- including any already-expanded ones -- calling a
callback.

It appears to work lazily as well, in that if the callback returns
false, iteration stops.  However, only the psymtab implementation does
this; the DWARF index implementations are not lazy.  It turns out,
though, that the only callback that is ever passed here never returns
false.

This patch simplifies this method by removing the callback.  The
method is also renamed.  In the new scheme, the caller is responsible
for walking the full symtabs, which removes some redundancy as well.

gdb/ChangeLog
2021-04-17  Tom Tromey  <tom@tromey.com>

	* psymtab.c (psymbol_functions::expand_matching_symbols): Rename
	from map_matching_symbols.  Change parameters.
	* psympriv.h (struct psymbol_functions) <expand_matching_symbols>:
	Rename from map_matching_symbols.  Change parameters.
	* dwarf2/read.c (struct dwarf2_gdb_index)
	<expand_matching_symbols>: Rename from map_matching_symbols.
	Change parameters.
	(struct dwarf2_debug_names_index) <expand_matching_symbols>:
	Rename from map_matching_symbols.  Change parameters.
	(dwarf2_gdb_index::expand_matching_symbols): Rename from
	dw2_map_matching_symbols.  Change parameters.
	(dwarf2_gdb_index::expand_matching_symbols): Remove old
	implementation.
	(dwarf2_debug_names_index::expand_matching_symbols): Rename from
	map_matching_symbols.  Change parameters.
	* objfiles.h (struct objfile) <expand_matching_symbols>: Rename
	from map_matching_symbols.  Change parameters.
	* symfile-debug.c (objfile::expand_matching_symbols): Rename from
	map_matching_symbols.  Change parameters.
	* ada-lang.c (map_matching_symbols): New function.
	(add_nonlocal_symbols): Update.
2021-04-17 09:35:06 -06:00
Tom Tromey
03a8ea51c3 Add search_flags to expand_symtabs_matching
This adds a block search flags parameter to expand_symtabs_matching.
All callers are updated to search both the static and global blocks,
as that was the implied behavior before this patch.

This is a step toward replacing lookup_symbol with
expand_symtabs_matching.

gdb/ChangeLog
2021-04-17  Tom Tromey  <tom@tromey.com>

	* symtab.c (global_symbol_searcher::expand_symtabs)
	(default_collect_symbol_completion_matches_break_on): Update.
	* symmisc.c (maintenance_expand_symtabs): Update.
	* symfile.h (expand_symtabs_matching): Add search_flags
	parameter.
	* symfile.c (expand_symtabs_matching): Add search_flags
	parameter.
	* symfile-debug.c (objfile::expand_symtabs_matching): Add
	search_flags parameter.
	* quick-symbol.h (struct quick_symbol_functions)
	<expand_symtabs_matching>: Add search_flags parameter.
	* python/py-symbol.c (gdbpy_lookup_static_symbols): Update.
	* psymtab.c (recursively_search_psymtabs)
	(psymbol_functions::expand_symtabs_matching): Add search_flags
	parameter.
	* psympriv.h (struct psymbol_functions) <expand_symtabs_matching>:
	Add search_flags parameter.
	* objfiles.h (struct objfile) <expand_symtabs_matching>: Add
	search_flags parameter.
	* linespec.c (iterate_over_all_matching_symtabs): Update.
	* dwarf2/read.c (struct dwarf2_gdb_index)
	<expand_symtabs_matching>: Add search_flags parameter.
	(struct dwarf2_debug_names_index) <expand_symtabs_matching>: Add
	search_flags parameter.
	(dw2_map_matching_symbols): Update.
	(dw2_expand_marked_cus, dw2_expand_symtabs_matching)
	(dwarf2_gdb_index::expand_symtabs_matching): Add search_flags
	parameter.
	(dw2_debug_names_iterator): Change block_index to search flags.
	<m_block_index>: Likewise.
	(dw2_debug_names_iterator::next)
	(dwarf2_debug_names_index::lookup_symbol)
	(dwarf2_debug_names_index::expand_symtabs_for_function)
	(dwarf2_debug_names_index::map_matching_symbols)
	(dwarf2_debug_names_index::map_matching_symbols): Update.
	(dwarf2_debug_names_index::expand_symtabs_matching): Add
	search_flags parameter.
	* ada-lang.c (ada_add_global_exceptions)
	(collect_symbol_completion_matches): Update.
2021-04-17 09:35:05 -06:00
Tom Tromey
9e5e03df52 Use block_symbol in var_value_operation
I noticed that var_value_operation takes a block and a symbol, and
most callers destructure a block_symbol to pass in.  It seems better
for this class to simply hold a block_symbol instead.

Tested on x86-64 Fedora 32.

gdb/ChangeLog
2021-04-15  Tom Tromey  <tromey@adacore.com>

	* rust-exp.y (rust_parser::convert_ast_to_expression): Update.
	* parse.c (parser_state::push_symbol, parser_state::push_dollar):
	Update.
	* p-exp.y (variable): Update.
	* m2-exp.y (variable): Update.
	* go-exp.y (variable): Update.
	* expprint.c (dump_for_expression): New overload.
	* expop.h (check_objfile): New overload.
	(check_constant): New overload.
	(class var_value_operation): Use block_symbol.
	<get_symbol>: Rewrite.
	* eval.c (var_value_operation::evaluate)
	(var_value_operation::evaluate_funcall)
	(var_value_operation::evaluate_for_address)
	(var_value_operation::evaluate_for_address)
	(var_value_operation::evaluate_with_coercion)
	(var_value_operation::evaluate_for_sizeof)
	(var_value_operation::evaluate_for_cast): Update.
	* d-exp.y (PrimaryExpression): Update.
	* c-exp.y (variable): Update.
	* ax-gdb.c (var_value_operation::do_generate_ax): Update.
	* ada-lang.c (ada_var_value_operation::evaluate_for_cast)
	(ada_var_value_operation::evaluate)
	(ada_var_value_operation::resolve)
	(ada_funcall_operation::resolve): Update.
	* ada-exp.y (write_var_from_sym, write_object_renaming)
	(write_ambiguous_var, write_var_or_type, write_name_assoc)
	(maybe_overload): Update.
	* ada-exp.h (class ada_var_value_operation) <get_block>: Rewrite.
2021-04-15 10:05:00 -06:00
Tom Tromey
2315bb2d57 Simplify use of map_matching_symbols in ada-lang.c
I noticed that ada-lang.c creates a lambda to call
aux_add_nonlocal_symbols.  However, this code can be simplified a bit
by changing match_data to implement operator(), and then simply
passing the object as the callback.  That is what this patch
implements.

gdb/ChangeLog
2021-03-26  Tom Tromey  <tom@tromey.com>

	* ada-lang.c (struct match_data): Add operator().
	(match_data::operator()): Rename from aux_add_nonlocal_symbols.
	(callback): Remove 'callback'.
2021-03-26 13:44:24 -06:00
Tom Tromey
4d080b4687 Introduce method wrappers for quick_symbol_functions
This introduces wrappers for each function in quick_symbol_functions.
The wrappers are methods on objfile, and are defined in
symfile-debug.c, so that they can use the symfile_debug variable.
Places that call the quick functions are all updated to call these new
wrapper methods.

gdb/ChangeLog
2021-03-20  Tom Tromey  <tom@tromey.com>

	* symtab.c (iterate_over_symtabs, expand_symtab_containing_pc)
	(lookup_symbol_via_quick_fns, find_quick_global_symbol_language)
	(basic_lookup_transparent_type_quick)
	(find_pc_sect_compunit_symtab, find_symbol_at_address)
	(find_line_symtab, global_symbol_searcher::expand_symtabs):
	Update.
	* symmisc.c (print_objfile_statistics, dump_objfile)
	(maintenance_expand_symtabs): Update.
	* symfile.c (symbol_file_add_with_addrs)
	(expand_symtabs_matching, map_symbol_filenames): Update.
	* symfile-debug.c (objfile::has_partial_symbols)
	(objfile::find_last_source_symtab)
	(objfile::forget_cached_source_info)
	(objfile::map_symtabs_matching_filename, objfile::lookup_symbol)
	(objfile::print_stats, objfile::dump)
	(objfile::expand_symtabs_for_function)
	(objfile::expand_all_symtabs)
	(objfile::expand_symtabs_with_fullname)
	(objfile::map_matching_symbols)
	(objfile::expand_symtabs_matching)
	(objfile::find_pc_sect_compunit_symtab)
	(objfile::map_symbol_filenames)
	(objfile::find_compunit_symtab_by_address)
	(objfile::lookup_global_symbol_language): New methods.
	(debug_sym_quick_functions): Remove.
	(debug_sym_fns, install_symfile_debug_logging): Update.
	* source.c (forget_cached_source_info_for_objfile)
	(select_source_symtab): Update.
	* objfiles.h (struct objfile): Add methods corresponding to
	quick_symbol_functions.
	* objfiles.c (objfile::has_partial_symbols): Move to
	symfile-debug.c.
	* linespec.c (iterate_over_all_matching_symtabs): Update.
	* cp-support.c (add_symbol_overload_list_qualified): Update.
	* ada-lang.c (add_nonlocal_symbols): Update.
2021-03-20 17:23:41 -06:00
Tom Tromey
3b5c4de0cf Call ada_ensure_varsize_limit in indirection
Internal testing revealed yet another Ada regression from the
expression rewrite.  In this case, indirection did not use the Ada
varsize limit.  The old code relied on the expression resolution
process to evaluate this subexpression with EVAL_AVOID_SIDE_EFFECTS in
order to get this error.  However, this isn't always done in the new
approach; so this patch introduces another call to
ada_ensure_varsize_limit in the appropriate spot.

As with the earlier patches, this path was not tested in-tree, so this
patch also updates a test.

gdb/ChangeLog
2021-03-15  Tom Tromey  <tromey@adacore.com>

	* ada-lang.c (ada_unop_ind_operation::evaluate): Call
	ada_ensure_varsize_limit.

gdb/testsuite/ChangeLog
2021-03-15  Tom Tromey  <tromey@adacore.com>

	* gdb.ada/varsize_limit.exp: Add new test.
	* gdb.ada/varsize_limit/vsizelim.adb: Update.
2021-03-15 06:23:13 -06:00
Tom Tromey
c04da66c26 Implement Ada operator overloading
In the expression rewrite, I neglected to carry over support for Ada
operator overloading.  It turns out that there were no tests for this
in-tree.

This patch adds support for operator overloading, and adds the missing
test.

gdb/ChangeLog
2021-03-15  Tom Tromey  <tromey@adacore.com>

	* ada-lang.c (numeric_type_p, integer_type_p): Return true for
	fixed-point.
	* ada-exp.y (maybe_overload): New function.
	(ada_wrap_overload): New function.
	(ada_un_wrap2, ada_wrap2, ada_wrap_op): Use maybe_overload.
	(exp1, simple_exp, relation, and_exp, and_then_exp, or_exp)
	(or_else_exp, xor_exp, primary): Update.

gdb/testsuite/ChangeLog
2021-03-15  Tom Tromey  <tromey@adacore.com>

	* gdb.ada/operator_call/twovecs.ads: New file.
	* gdb.ada/operator_call/twovecs.adb: New file.
	* gdb.ada/operator_call/opcall.adb: New file.
	* gdb.ada/operator_call.exp: New file.
2021-03-15 06:23:13 -06:00
Tom Tromey
9863c3b5fc Fix regression in Ada ptype
This fixes PR ada/27545, which points out that a test in
gdb.ada/tagged.exp started failing due to the expression rewrite.  I
didn't notice this failure because my system gcc-gnat debuginfo was
out of date, and so the test was already failing in the baseline.

Previously, the OP_VAR_VALUE case in ada_evaluate_subexp ended up
doing a recursive call:

    arg1 = evaluate_subexp (nullptr, exp, pos, EVAL_NORMAL);

However, during the rewrite I missed this fact and had the new code
call the superclass implementation.

This patch fixes the bug by changing this code to use a recursive call
instead.

gdb/ChangeLog
2021-03-15  Tom Tromey  <tromey@adacore.com>

	PR ada/27545:
	* ada-lang.c (ada_var_value_operation::evaluate): Use recursive
	call for tagged type.
2021-03-15 06:23:13 -06:00
Tom Tromey
207582c075 Fix bug in Ada aggregate assignment
The expression rewrite caused a regression in the internal AdaCore
test suite.  The bug was that I had dropped a bit of code from
aggregate assignment -- assign_aggregate used to return the container,
which I thought was redundant, but which can actually change during
the call.  There was no test for this case in the tree, so I've added
one.

gdb/ChangeLog
2021-03-15  Tom Tromey  <tromey@adacore.com>

	* ada-lang.c (ada_aggregate_operation::assign_aggregate): Return
	container.
	(ada_assign_operation::evaluate): Update.
	* ada-exp.h (class ada_aggregate_operation) <assign_aggregate>:
	Change return type.

gdb/testsuite/ChangeLog
2021-03-15  Tom Tromey  <tromey@adacore.com>

	* gdb.ada/assign_arr/target_wrapper.ads (IArray, Put, Do_Nothing):
	Declare.
	* gdb.ada/assign_arr/target_wrapper.adb: New file.
	* gdb.ada/assign_arr/main_p324_051.adb (IValue): New variable.
	Call Put.
	* gdb.ada/assign_arr.exp: Update.
2021-03-15 06:23:12 -06:00
Tom Tromey
7056f312d0 Use bool for "parse_completion"
Some spots in GDB already use bool for "parse_completion", but a few
were still using int.  This patch updates these to bool.

I'm checking this in.

gdb/ChangeLog
2021-03-10  Tom Tromey  <tromey@adacore.com>

	* parser-defs.h (parser_state): Change completion to bool.
	<parse_completion>: Likewise.
	* ada-lang.h (ada_find_operator_symbol, ada_resolve_funcall)
	(ada_resolve_variable, ada_resolve_function): Update.
	* ada-lang.c (ada_find_operator_symbol): Change
	parse_completion to bool.
	(ada_resolve_funcall, ada_resolve_variable)
	(ada_resolve_function): Likewise.
2021-03-10 11:50:09 -07:00
Tom Tromey
9c79936b3d Use bound_minimal_symbol in var_msym_value_operation
This changes var_msym_value_operation to use a bound_minimal_symbol
rather than separate minsym and objfile parameters.  The main benefit
of this is removing the possibly-confusing check_objfile overload for
a plain minimal symbol.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

	* parse.c (parser_state::push_symbol, parser_state::push_dollar):
	Update.
	* p-exp.y (variable): Update.
	* go-exp.y (variable): Update.
	* expprint.c (dump_for_expression): Use bound_minimal_symbol.
	Remove overload for objfile.
	* expop.h (eval_op_var_msym_value): Use bound_minimal_symbol
	parameter.
	(check_objfile): Likewise.
	(dump_for_expression): Likewise.  Remove overload for objfile.
	(class var_msym_value_operation): Use bound_minimal_symbol.
	* eval.c (eval_op_var_msym_value): Use bound_minimal_symbol
	parameter.
	(var_msym_value_operation::evaluate_for_address)
	(var_msym_value_operation::evaluate_for_sizeof)
	(var_msym_value_operation::evaluate_for_cast): Update.
	* d-exp.y (PrimaryExpression): Update.
	* c-exp.y (variable): Update.
	* ax-gdb.c (var_msym_value_operation::do_generate_ax): Update.
	* ada-lang.c (ada_var_msym_value_operation::evaluate_for_cast):
	Update.
	* ada-exp.y (write_var_or_type): Update.
2021-03-08 07:28:44 -07:00