Print Ada type name in more cases

In some cases the name of an Ada type cannot be decoded by
decoded_type_name.  For example, the name
"p__complex_variable_record_type__T9s" in the included test case is
rejected due to the "T".  This causes ptype to display the full
contents of a record type -- when in fact the name is available and
ought to be printed.

Fixing this in decoded_type_name isn't possible because the "__T" name
is not the real name of the type -- it is just a compiler-assigned
name of convenience.

This patch fixes the problem by using the resolved type's name when
the original type's name isn't suitable.

gdb/ChangeLog
2020-11-04  Tom Tromey  <tromey@adacore.com>

	* ada-typeprint.c (ada_print_type): Handle __T types.

gdb/testsuite/ChangeLog
2020-11-04  Tom Tromey  <tromey@adacore.com>

	* gdb.ada/rec_ptype.exp: New file.
	* gdb.ada/rec_ptype/main.adb: New file.
	* gdb.ada/rec_ptype/p.ads: New file.
This commit is contained in:
Tom Tromey
2020-11-04 09:17:58 -07:00
parent d8f62e8447
commit 8d9fd3a107
6 changed files with 137 additions and 1 deletions

View File

@@ -955,7 +955,20 @@ ada_print_type (struct type *type0, const char *varstring,
const struct type_print_options *flags)
{
struct type *type = ada_check_typedef (ada_get_base_type (type0));
char *type_name = decoded_type_name (type0);
/* If we can decode the original type name, use it. However, there
are cases where the original type is an internally-generated type
with a name that can't be decoded (and whose encoded name might
not actually bear any relation to the type actually declared in
the sources). In that case, try using the name of the base type
in its place.
Note that we looked at the possibility of always using the name
of the base type. This does not always work, unfortunately, as
there are situations where it's the base type which has an
internally-generated name. */
const char *type_name = decoded_type_name (type0);
if (type_name == nullptr)
type_name = decoded_type_name (type);
int is_var_decl = (varstring != NULL && varstring[0] != '\0');
if (type == NULL)