diff options
author | Andrew Burgess <andrew.burgess@embecosm.com> | 2020-07-14 10:10:07 +0100 |
---|---|---|
committer | Andrew Burgess <andrew.burgess@embecosm.com> | 2020-07-15 08:56:25 +0100 |
commit | 3dcc261cf8dfbf60075cc4617cec0b1aaab8896f (patch) | |
tree | 2214ba625e4a73450af5963507ead0f391187a37 /gdb/f-typeprint.c | |
parent | f0e8d0bae403e33b8a3e8de5817d8f920e063f84 (diff) | |
download | binutils-gdb-3dcc261cf8dfbf60075cc4617cec0b1aaab8896f.tar.gz |
gdb/fortran: Handle dynamic string types when printing types
After commit:
commit 8c2e4e0689ea244d0ed979171a3d09c9176b8175
Date: Sun Jul 12 22:58:51 2020 -0400
gdb: add accessors to struct dynamic_prop
An existing bug was exposed in the Fortran type printing code. When
GDB is asked to print the type of a function that takes a dynamic
string argument GDB will try to read the upper bound of the string.
The read of the upper bound is written as:
if (type->bounds ()->high.kind () == PROP_UNDEFINED)
// Treat the upper bound as unknown.
else
// Treat the upper bound as known and constant.
However, this is not good enough. When printing a function type the
dynamic argument types will not have been resolved. As a result the
dynamic property is not PROP_UNDEFINED, but nor is it constant.
By rewriting this code to specifically check for the PROP_CONST case,
and treating all other cases as the upper bound being unknown we avoid
incorrectly treating the dynamic property as being constant.
gdb/ChangeLog:
* f-typeprint.c (f_type_print_base): Allow for dynamic types not
being resolved.
gdb/testsuite/ChangeLog:
* gdb.fortran/ptype-on-functions.exp: Add more tests.
* gdb.fortran/ptype-on-functions.f90: Likewise.
Diffstat (limited to 'gdb/f-typeprint.c')
-rw-r--r-- | gdb/f-typeprint.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/gdb/f-typeprint.c b/gdb/f-typeprint.c index 80dbfe11167..65ec93af9f4 100644 --- a/gdb/f-typeprint.c +++ b/gdb/f-typeprint.c @@ -406,16 +406,20 @@ f_type_print_base (struct type *type, struct ui_file *stream, int show, break; case TYPE_CODE_STRING: - /* Strings may have dynamic upperbounds (lengths) like arrays. */ + /* Strings may have dynamic upperbounds (lengths) like arrays. We + check specifically for the PROP_CONST case to indicate that the + dynamic type has been resolved. If we arrive here having been + asked to print the type of a value with a dynamic type then the + bounds will not have been resolved. */ - if (type->bounds ()->high.kind () == PROP_UNDEFINED) - fprintfi_filtered (level, stream, "character*(*)"); - else + if (type->bounds ()->high.kind () == PROP_CONST) { LONGEST upper_bound = f77_get_upperbound (type); fprintf_filtered (stream, "character*%s", pulongest (upper_bound)); } + else + fprintfi_filtered (level, stream, "character*(*)"); break; case TYPE_CODE_STRUCT: |