public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/26910] New: [fortran] Printing dynamic string with DW_AT_string_length of class loclistpr fails
@ 2020-11-17 13:37 vries at gcc dot gnu.org
  2020-11-17 13:40 ` [Bug fortran/26910] " vries at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: vries at gcc dot gnu.org @ 2020-11-17 13:37 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=26910

            Bug ID: 26910
           Summary: [fortran] Printing dynamic string with
                    DW_AT_string_length of class loclistpr fails
           Product: gdb
           Version: HEAD
            Status: NEW
          Severity: normal
          Priority: P2
         Component: fortran
          Assignee: unassigned at sourceware dot org
          Reporter: vries at gcc dot gnu.org
  Target Milestone: ---

Consider test-case gdb.opt/fortran-string.f90, as found here (
https://src.fedoraproject.org/rpms/gdb/blob/master/f/gdb-archer-vla-tests.patch
), but with a print line added to prevent inlining of f:
...
     1    subroutine f(s)
     2    character*(*) s
     3    s = s
     4    print *, s
     5    end
     6
     7    program main
     8    call f ('foo')
     9    end
...

When printing the type of s at line 4:
...
$ gdb.sh -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*1
...
we get "character*1", while we'd like to see string length 3 there.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug fortran/26910] [fortran] Printing dynamic string with DW_AT_string_length of class loclistpr fails
  2020-11-17 13:37 [Bug fortran/26910] New: [fortran] Printing dynamic string with DW_AT_string_length of class loclistpr fails vries at gcc dot gnu.org
@ 2020-11-17 13:40 ` vries at gcc dot gnu.org
  2020-11-17 13:43 ` vries at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: vries at gcc dot gnu.org @ 2020-11-17 13:40 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=26910

--- Comment #1 from Tom de Vries <vries at gcc dot gnu.org> ---
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.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug fortran/26910] [fortran] Printing dynamic string with DW_AT_string_length of class loclistpr fails
  2020-11-17 13:37 [Bug fortran/26910] New: [fortran] Printing dynamic string with DW_AT_string_length of class loclistpr fails vries at gcc dot gnu.org
  2020-11-17 13:40 ` [Bug fortran/26910] " vries at gcc dot gnu.org
@ 2020-11-17 13:43 ` vries at gcc dot gnu.org
  2021-10-14 19:59 ` vries at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: vries at gcc dot gnu.org @ 2020-11-17 13:43 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=26910

--- Comment #2 from Tom de Vries <vries at gcc dot gnu.org> ---
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)
...

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug fortran/26910] [fortran] Printing dynamic string with DW_AT_string_length of class loclistpr fails
  2020-11-17 13:37 [Bug fortran/26910] New: [fortran] Printing dynamic string with DW_AT_string_length of class loclistpr fails vries at gcc dot gnu.org
  2020-11-17 13:40 ` [Bug fortran/26910] " vries at gcc dot gnu.org
  2020-11-17 13:43 ` vries at gcc dot gnu.org
@ 2021-10-14 19:59 ` vries at gcc dot gnu.org
  2021-10-15  5:23 ` [Bug symtab/26910] " vries at gcc dot gnu.org
  2021-10-28  8:54 ` vries at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: vries at gcc dot gnu.org @ 2021-10-14 19:59 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=26910

--- Comment #3 from Tom de Vries <vries at gcc dot gnu.org> ---
https://sourceware.org/pipermail/gdb-patches/2021-October/182572.html

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug symtab/26910] [fortran] Printing dynamic string with DW_AT_string_length of class loclistpr fails
  2020-11-17 13:37 [Bug fortran/26910] New: [fortran] Printing dynamic string with DW_AT_string_length of class loclistpr fails vries at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2021-10-14 19:59 ` vries at gcc dot gnu.org
@ 2021-10-15  5:23 ` vries at gcc dot gnu.org
  2021-10-28  8:54 ` vries at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: vries at gcc dot gnu.org @ 2021-10-15  5:23 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=26910

Tom de Vries <vries at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|fortran                     |symtab

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug symtab/26910] [fortran] Printing dynamic string with DW_AT_string_length of class loclistpr fails
  2020-11-17 13:37 [Bug fortran/26910] New: [fortran] Printing dynamic string with DW_AT_string_length of class loclistpr fails vries at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2021-10-15  5:23 ` [Bug symtab/26910] " vries at gcc dot gnu.org
@ 2021-10-28  8:54 ` vries at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: vries at gcc dot gnu.org @ 2021-10-28  8:54 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=26910

Tom de Vries <vries at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |12.1
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #4 from Tom de Vries <vries at gcc dot gnu.org> ---
https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=5b151607e1faf27238e9dce6d3124741779dcc3a

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-10-28  8:54 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-17 13:37 [Bug fortran/26910] New: [fortran] Printing dynamic string with DW_AT_string_length of class loclistpr fails vries at gcc dot gnu.org
2020-11-17 13:40 ` [Bug fortran/26910] " vries at gcc dot gnu.org
2020-11-17 13:43 ` vries at gcc dot gnu.org
2021-10-14 19:59 ` vries at gcc dot gnu.org
2021-10-15  5:23 ` [Bug symtab/26910] " vries at gcc dot gnu.org
2021-10-28  8:54 ` vries at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).