Summary: | [fortran] Printing dynamic string with DW_AT_string_length of class loclistpr fails | ||
---|---|---|---|
Product: | gdb | Reporter: | Tom de Vries <vries> |
Component: | symtab | Assignee: | Not yet assigned to anyone <unassigned> |
Status: | RESOLVED FIXED | ||
Severity: | normal | ||
Priority: | P2 | ||
Version: | HEAD | ||
Target Milestone: | 12.1 | ||
Host: | Target: | ||
Build: | Last reconfirmed: |
Description
Tom de Vries
2020-11-17 13:37:06 UTC
The parameter s in function f: ... <2><1ed>: Abbrev Number: 13 (DW_TAG_formal_parameter) <1ee> DW_AT_name : s <1f2> DW_AT_type : <0x25a> ... has type: ... <1><25a>: Abbrev Number: 17 (DW_TAG_string_type) <25b> DW_AT_string_length: 0xbf (location list) <25f> DW_AT_byte_size : 4 <260> DW_AT_sibling : <0x26e> ... matching with location list: ... 000000bf 0000000000400730 0000000000400764 (DW_OP_reg4 (rsi)) 000000d2 0000000000400764 0000000000400783 (DW_OP_reg6 (rbp)) 000000e5 0000000000400783 0000000000400784 (DW_OP_GNU_entry_value: (DW_OP_reg4 (rsi)); DW_OP_stack_value) ... Doing a print of pc at the breakpoint: ... 4 print *, s (gdb) info registers pc pc 0x400734 0x400734 <f+4> ... tells us that the string length can be found in register rsi, which contains: ... (gdb) info registers rsi rsi 0x3 3 ... So, the information seems to be there. Why doesn't gdb use it? We find the answer by stepping through read_tag_string_type. We hit: ... (gdb) 17837 if (!attr_to_dynamic_prop (attr, die, cu, &prop, prop_type)) (gdb) 17838 length = 1; ... and that's the reason why the length is one. So, why don't we manage to convert the attribute to a dynamic prop? Stepping through attr_to_dynamic_prop shows why: ... (gdb) 18590 if (attr->form_is_block ()) (gdb) 18613 else if (attr->form_is_ref ()) (gdb) 18676 else if (attr->form_is_constant ()) (gdb) 18680 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr->form), (gdb) 18682 return 0; ... The actual form is: ... (gdb) p attr.form $2 = DW_FORM_sec_offset ... and that's not handled in attr_to_dynamic_prop. Tentative patch: ... diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 3c598262913..151ba1faae2 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -18675,14 +18675,30 @@ attr_to_dynamic_prop (const struct attribute *attr, struct die_in fo *die, } else if (attr->form_is_constant ()) prop->set_const_val (attr->constant_value (0)); - else + else if (attr->form_is_section_offset ()) { - dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr->form), - dwarf2_name (die, cu)); - return 0; + switch (attr->name) + { + case DW_AT_string_length: + baton = XOBNEW (obstack, struct dwarf2_property_baton); + baton->property_type = default_type; + fill_in_loclist_baton (cu, &baton->loclist, attr); + prop->set_loclist (baton); + gdb_assert (prop->baton () != NULL); + break; + default: + goto invalid; + } } + else + goto invalid; return 1; + + invalid: + dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr->form), + dwarf2_name (die, cu)); + return 0; } /* See read.h. */ ... and we have: ... $ gdb -batch ./outputs/gdb.opt/fortran-string/fortran-string \ -ex "b 4" \ -ex r \ -ex "ptype s" Breakpoint 1 at 0x400734: file fortran-string.f90, line 4. Breakpoint 1, f (s=..., _s=_s@entry=3) at fortran-string.f90:4 4 print *, s type = character (3) ... |