[gdb] Fix printing of unresolved dynamic type

When debugging gdb in batch mode with executable mixed-lang-stack and doing a
backtrace at breakpt:
...
$ gdb --args gdb \
  -batch \
  outputs/gdb.fortran/mixed-lang-stack/mixed-lang-stack \
  -ex "b breakpt" \
  -ex r \
  -ex bt
...
and stopping at resolve_dynamic_type to print the type:
...
(gdb) b resolve_dynamic_type
Breakpoint 1 at 0x6b020c: file gdbtypes.c, line 2633.
(gdb) commands
Type commands for breakpoint(s) 1, one per line.
End with a line saying just "end".
>call recursive_dump_type (type, 0)
>continue
>end
(gdb) run
...
we eventually run into an assert for the dynamic type of "str":
...
Thread 1 "gdb" hit Breakpoint 1, resolve_dynamic_type (type=0x22204f0, \
  valaddr=..., addr=4199408) at gdbtypes.c:2633
2633        = {check_typedef (type), valaddr, addr, NULL};
type node 0x22204f0
name '<NULL>' (0x0)
code 0xd (TYPE_CODE_STRING)
length 0
  ...
    nfields 0 0x22204b0
gdbtypes.h:526: internal-error: LONGEST dynamic_prop::const_val() const: \
  Assertion `m_kind == PROP_CONST' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
...
when trying to print the high bound of a TYPE_CODE_RANGE, which has m_kind
PROP_LOCEXPR, while the code in resolve_dynamic_type assumes PROP_CONST.

Fix this by extending the printing of TYPE_CODE_RANGE to allow
PROP_LOCEXPR/PROP_LOCLIST as well, such that we have instead:
...
    nfields 0 0x1fbc020
    low 1  high (dynamic)
...

Tested on x86_64-linux.

gdb/ChangeLog:

2020-08-17  Tom de Vries  <tdevries@suse.de>

	PR gdb/26393
	* gdbtypes.c (dump_dynamic_prop): New function.
	(recursive_dump_type): Use dump_dynamic_prop for TYPE_CODE_RANGE.
This commit is contained in:
Tom de Vries
2020-08-17 09:54:37 +02:00
parent d3267445af
commit 53d5a2a5c1
2 changed files with 34 additions and 7 deletions

View File

@ -4856,6 +4856,29 @@ print_gnat_stuff (struct type *type, int spaces)
static struct obstack dont_print_type_obstack;
/* Print the dynamic_prop PROP. */
static void
dump_dynamic_prop (dynamic_prop const& prop)
{
switch (prop.kind ())
{
case PROP_CONST:
printf_filtered ("%s", plongest (prop.const_val ()));
break;
case PROP_UNDEFINED:
printf_filtered ("(undefined)");
break;
case PROP_LOCEXPR:
case PROP_LOCLIST:
printf_filtered ("(dynamic)");
break;
default:
gdb_assert_not_reached ("unhandled prop kind");
break;
}
}
void
recursive_dump_type (struct type *type, int spaces)
{
@ -5115,13 +5138,11 @@ recursive_dump_type (struct type *type, int spaces)
}
if (type->code () == TYPE_CODE_RANGE)
{
printfi_filtered (spaces, "low %s%s high %s%s\n",
plongest (type->bounds ()->low.const_val ()),
(type->bounds ()->low.kind () == PROP_UNDEFINED
? " (undefined)" : ""),
plongest (type->bounds ()->high.const_val ()),
(type->bounds ()->high.kind () == PROP_UNDEFINED
? " (undefined)" : ""));
printfi_filtered (spaces, "low ");
dump_dynamic_prop (type->bounds ()->low);
printf_filtered (" high ");
dump_dynamic_prop (type->bounds ()->high);
printf_filtered ("\n");
}
switch (TYPE_SPECIFIC_FIELD (type))