From 53d5a2a5c146f98dd525eda2f33d7781666463bf Mon Sep 17 00:00:00 2001 From: Tom de Vries Date: Mon, 17 Aug 2020 09:54:37 +0200 Subject: [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 '' (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 PR gdb/26393 * gdbtypes.c (dump_dynamic_prop): New function. (recursive_dump_type): Use dump_dynamic_prop for TYPE_CODE_RANGE. --- gdb/ChangeLog | 6 ++++++ gdb/gdbtypes.c | 35 ++++++++++++++++++++++++++++------- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 9cc7e44..3e733a7 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2020-08-17 Tom de Vries + + PR gdb/26393 + * gdbtypes.c (dump_dynamic_prop): New function. + (recursive_dump_type): Use dump_dynamic_prop for TYPE_CODE_RANGE. + 2020-08-15 Tom de Vries PR backtrace/26390 diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index da1c58c..c1eb03d 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -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)) -- cgit v1.1