aboutsummaryrefslogtreecommitdiff
path: root/gdb/f-valprint.c
diff options
context:
space:
mode:
authorBhuvanendra Kumar N <Bhuvanendra.KumarN@amd.com>2022-02-02 17:52:27 +0000
committerAndrew Burgess <aburgess@redhat.com>2022-02-11 15:26:25 +0000
commite951225303b7d0565c985e2d562d3787983ff06f (patch)
treebb924f8f2e8cccb6afb95c0446ff42aa91a2f3e1 /gdb/f-valprint.c
parent9ab50efc463ff723b8e9102f1f68a6983d320517 (diff)
downloadgdb-e951225303b7d0565c985e2d562d3787983ff06f.zip
gdb-e951225303b7d0565c985e2d562d3787983ff06f.tar.gz
gdb-e951225303b7d0565c985e2d562d3787983ff06f.tar.bz2
gdb/fortran: support ptype and print commands for namelist variables
Gfortran supports namelists (a Fortran feature); it emits DW_TAG_namelist and DW_TAG_namelist_item dies. But gdb does not process these dies and does not support 'print' or 'ptype' commands on namelist variables. An attempt to print namelist variables results in gdb bailing out with the error message as shown below. (gdb) print nml No symbol "nml" in current context. This commit is to make the print and ptype commands work for namelist variables and its items. Sample output of these commands is shared below, with fixed gdb. (gdb) ptype nml type = Type nml integer(kind=4) :: a integer(kind=4) :: b End Type nml (gdb) print nml $1 = ( a = 10, b = 20 )
Diffstat (limited to 'gdb/f-valprint.c')
-rw-r--r--gdb/f-valprint.c26
1 files changed, 20 insertions, 6 deletions
diff --git a/gdb/f-valprint.c b/gdb/f-valprint.c
index e8d8627..6a199f1 100644
--- a/gdb/f-valprint.c
+++ b/gdb/f-valprint.c
@@ -512,24 +512,38 @@ f_language::value_print_inner (struct value *val, struct ui_file *stream,
case TYPE_CODE_STRUCT:
case TYPE_CODE_UNION:
+ case TYPE_CODE_NAMELIST:
/* Starting from the Fortran 90 standard, Fortran supports derived
types. */
fprintf_filtered (stream, "( ");
for (index = 0; index < type->num_fields (); index++)
{
- struct value *field = value_field (val, index);
-
- struct type *field_type = check_typedef (type->field (index).type ());
-
+ struct type *field_type
+ = check_typedef (type->field (index).type ());
if (field_type->code () != TYPE_CODE_FUNC)
{
- const char *field_name;
+ const char *field_name = type->field (index).name ();
+ struct value *field;
+
+ if (type->code () == TYPE_CODE_NAMELIST)
+ {
+ /* While printing namelist items, fetch the appropriate
+ value field before printing its value. */
+ struct block_symbol sym
+ = lookup_symbol (field_name, get_selected_block (nullptr),
+ VAR_DOMAIN, nullptr);
+ if (sym.symbol == nullptr)
+ error (_("failed to find symbol for name list component %s"),
+ field_name);
+ field = value_of_variable (sym.symbol, sym.block);
+ }
+ else
+ field = value_field (val, index);
if (printed_field > 0)
fputs_filtered (", ", stream);
- field_name = type->field (index).name ();
if (field_name != NULL)
{
fputs_styled (field_name, variable_name_style.style (),