public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/26870] New: [fortran] Printing dynamic array fails
@ 2020-11-12 12:50 vries at gcc dot gnu.org
  2020-11-12 12:56 ` [Bug fortran/26870] " vries at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: vries at gcc dot gnu.org @ 2020-11-12 12:50 UTC (permalink / raw)
  To: gdb-prs

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

            Bug ID: 26870
           Summary: [fortran] Printing dynamic array 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.fortran/dynamic.exp, as added in fedora patch
https://src.fedoraproject.org/rpms/gdb/blob/master/f/gdb-archer-vla-tests.patch
.

When building current trunk gdb with CFLAGS/CXXFLAGS as in the openSUSE Leap
15.2 gdb package:
...
CFLAGS="-fmessage-length=0 -grecord-gcc-switches -O2 -Wall -D_FORTIFY_SOURCE=2
-fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables
-fstack-clash-protection -g"
CXXFLAGS="$CFLAGS -Wno-error=odr"
...
we run into:
...
(gdb) PASS: gdb.fortran/dynamic.exp: ptype vart
p varz^M
$26 = (warning: array or string index out of range^M
<error reading variable>^M
(gdb) FAIL: gdb.fortran/dynamic.exp: p varz
...

This can be reproduced on the command line:
...
$ gdb -batch dynamic \
    -ex "b 68" \
    -ex r \
    -ex "p varz" 
Breakpoint 1 at 0x400aac: file dynamic.f90, line 68.

Breakpoint 1, bar (varz=..., vart=...) at dynamic.f90:68
68        varz(2) = 5                                   ! varz-almostfilled^M
$1 = (warning: array or string index out of range
<error reading variable>
...

The problem is here, in f77_print_array_1.  Before calling get_discrete_bounds,
upperbound is uninitialized, and randomly set to a large value:
...
120       get_discrete_bounds (range_type, &lowerbound, &upperbound);
(gdb) p lowerbound
$1 = 0
(gdb) p upperbound
$2 = 31290496
...

Stepping into get_discrete_bounds, we can see that it returns -1:
...
(gdb) s
get_discrete_bounds ()
    at gdbtypes.c:1045
1045    {
(gdb) fin
Run till exit from #0  get_discrete_bounds ()
    at gdbtypes.c:1045
f77_print_array_1 ()
    at f-valprint.c:122
122       if (nss != ndimensions)
Value returned is $3 = -1
...
and the bounds are unchanged:
...
(gdb) p lowerbound
$4 = 0
(gdb) p upperbound
$5 = 31290496
...
which causes the warning and error.

And get_discrete_bounds returns -1 because:
...
(gdb) p type.main_type.flds_bnds.bounds.low
$18 = {m_kind = PROP_CONST, m_data = {const_val = 1, baton = 0x1, variant_parts
= 0x1, 
    original_type = 0x1}}
(gdb) p type.main_type.flds_bnds.bounds.high
$19 = {m_kind = PROP_UNDEFINED, m_data = {const_val = 6003792, 
    baton = 0x5b9c50 <check_typedef(type*)+464>, 
    variant_parts = 0x5b9c50 <check_typedef(type*)+464>, 
    original_type = 0x5b9c50 <check_typedef(type*)+464>}}
...

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

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

* [Bug fortran/26870] [fortran] Printing dynamic array fails
  2020-11-12 12:50 [Bug fortran/26870] New: [fortran] Printing dynamic array fails vries at gcc dot gnu.org
@ 2020-11-12 12:56 ` vries at gcc dot gnu.org
  2021-10-13 12:22 ` vries at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: vries at gcc dot gnu.org @ 2020-11-12 12:56 UTC (permalink / raw)
  To: gdb-prs

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

--- Comment #1 from Tom de Vries <vries at gcc dot gnu.org> ---
Tentative patch:
...
diff --git a/gdb/f-valprint.c b/gdb/f-valprint.c
index 33ac761f85d..737d7bd0f6e 100644
--- a/gdb/f-valprint.c
+++ b/gdb/f-valprint.c
@@ -117,7 +117,8 @@ f77_print_array_1 (int nss, int ndimensions, struct type
*type,
   LONGEST lowerbound, upperbound;
   LONGEST i;

-  get_discrete_bounds (range_type, &lowerbound, &upperbound);
+  if (get_discrete_bounds (range_type, &lowerbound, &upperbound) < 0)
+    lowerbound = 0, upperbound = -1;

   if (nss != ndimensions)
     {
...

With the patch, we have instead the expected:
...
Breakpoint 1, bar (varz=..., vart=...) at dynamic.f90:68
68        varz(2) = 5                                   ! varz-almostfilled^M
$1 = ()
...

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

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

* [Bug fortran/26870] [fortran] Printing dynamic array fails
  2020-11-12 12:50 [Bug fortran/26870] New: [fortran] Printing dynamic array fails vries at gcc dot gnu.org
  2020-11-12 12:56 ` [Bug fortran/26870] " vries at gcc dot gnu.org
@ 2021-10-13 12:22 ` vries at gcc dot gnu.org
  2021-10-13 14:06 ` [Bug symtab/26870] " vries at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: vries at gcc dot gnu.org @ 2021-10-13 12:22 UTC (permalink / raw)
  To: gdb-prs

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

--- Comment #2 from Tom de Vries <vries at gcc dot gnu.org> ---
With gdb-11.1 we have:
...
(gdb) PASS: gdb.fortran/dynamic.exp: ptype vart
p varz^M
$26 = <error reading variable>^M
(gdb) FAIL: gdb.fortran/dynamic.exp: p varz
p vart^M
$27 = <error reading variable>^M
(gdb) FAIL: gdb.fortran/dynamic.exp: p vart
...
which means we no longer get the "warning: array or string index out of range"
which is good.

The error message is a bit uninformative, and could be improved using:
...
diff --git a/gdb/valprint.c b/gdb/valprint.c
index 324055da93f..05740c838ad 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -1050,7 +1050,7 @@ do_val_print (struct value *value, struct ui_file
*stream, int recurs
e,
   catch (const gdb_exception_error &except)
     {
       fprintf_styled (stream, metadata_style.style (),
-                     _("<error reading variable>"));
+                     _("<error reading variable: %s>"), except.what ());
     }
 }

...
to:
...
(gdb) PASS: gdb.fortran/dynamic.exp: ptype vart
p varz^M
$26 = <error reading variable: failed to get range bounds>^M
(gdb) FAIL: gdb.fortran/dynamic.exp: p varz
...

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

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

* [Bug symtab/26870] [fortran] Printing dynamic array fails
  2020-11-12 12:50 [Bug fortran/26870] New: [fortran] Printing dynamic array fails vries at gcc dot gnu.org
  2020-11-12 12:56 ` [Bug fortran/26870] " vries at gcc dot gnu.org
  2021-10-13 12:22 ` vries at gcc dot gnu.org
@ 2021-10-13 14:06 ` vries at gcc dot gnu.org
  2021-10-13 14:07 ` vries at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: vries at gcc dot gnu.org @ 2021-10-13 14:06 UTC (permalink / raw)
  To: gdb-prs

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

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

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

--- Comment #3 from Tom de Vries <vries at gcc dot gnu.org> ---
(In reply to Tom de Vries from comment #1)
> Tentative patch:
> ...
> diff --git a/gdb/f-valprint.c b/gdb/f-valprint.c
> index 33ac761f85d..737d7bd0f6e 100644
> --- a/gdb/f-valprint.c
> +++ b/gdb/f-valprint.c
> @@ -117,7 +117,8 @@ f77_print_array_1 (int nss, int ndimensions, struct type
> *type,
>    LONGEST lowerbound, upperbound;
>    LONGEST i;
>  
> -  get_discrete_bounds (range_type, &lowerbound, &upperbound);
> +  if (get_discrete_bounds (range_type, &lowerbound, &upperbound) < 0)
> +    lowerbound = 0, upperbound = -1;
>  
>    if (nss != ndimensions)
>      {
> ...
> 
> With the patch, we have instead the expected:
> ...
> Breakpoint 1, bar (varz=..., vart=...) at dynamic.f90:68
> 68        varz(2) = 5                                   ! varz-almostfilled^M
> $1 = ()
> ...

Reading this back, I don't think this is the right solution.  This suggests
that the dimension is 0, and the error may give the idea of using an explicit
dimension for printing the variable.

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

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

* [Bug symtab/26870] [fortran] Printing dynamic array fails
  2020-11-12 12:50 [Bug fortran/26870] New: [fortran] Printing dynamic array fails vries at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2021-10-13 14:06 ` [Bug symtab/26870] " vries at gcc dot gnu.org
@ 2021-10-13 14:07 ` vries at gcc dot gnu.org
  2021-10-13 14:07 ` vries at gcc dot gnu.org
  2021-10-13 14:08 ` vries at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: vries at gcc dot gnu.org @ 2021-10-13 14:07 UTC (permalink / raw)
  To: gdb-prs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |11.1

--- Comment #4 from Tom de Vries <vries at gcc dot gnu.org> ---
Marking this as fixed in 11.2, where we now do:
...
(gdb) PASS: gdb.fortran/dynamic.exp: ptype vart
p varz^M
$26 = <error reading variable>^M
...

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

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

* [Bug symtab/26870] [fortran] Printing dynamic array fails
  2020-11-12 12:50 [Bug fortran/26870] New: [fortran] Printing dynamic array fails vries at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2021-10-13 14:07 ` vries at gcc dot gnu.org
@ 2021-10-13 14:07 ` vries at gcc dot gnu.org
  2021-10-13 14:08 ` vries at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: vries at gcc dot gnu.org @ 2021-10-13 14:07 UTC (permalink / raw)
  To: gdb-prs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #5 from Tom de Vries <vries at gcc dot gnu.org> ---
(In reply to Tom de Vries from comment #4)
> Marking this as fixed in 11.2, where we now do:
> ...
> (gdb) PASS: gdb.fortran/dynamic.exp: ptype vart
> p varz^M
> $26 = <error reading variable>^M
> ...

Now really mark this fixed.

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

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

* [Bug symtab/26870] [fortran] Printing dynamic array fails
  2020-11-12 12:50 [Bug fortran/26870] New: [fortran] Printing dynamic array fails vries at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2021-10-13 14:07 ` vries at gcc dot gnu.org
@ 2021-10-13 14:08 ` vries at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: vries at gcc dot gnu.org @ 2021-10-13 14:08 UTC (permalink / raw)
  To: gdb-prs

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

--- Comment #6 from Tom de Vries <vries at gcc dot gnu.org> ---
(In reply to Tom de Vries from comment #2)
> The error message is a bit uninformative, and could be improved using:
> ...
> diff --git a/gdb/valprint.c b/gdb/valprint.c
> index 324055da93f..05740c838ad 100644
> --- a/gdb/valprint.c
> +++ b/gdb/valprint.c
> @@ -1050,7 +1050,7 @@ do_val_print (struct value *value, struct ui_file
> *stream, int recurs
> e,
>    catch (const gdb_exception_error &except)
>      {
>        fprintf_styled (stream, metadata_style.style (),
> -                     _("<error reading variable>"));
> +                     _("<error reading variable: %s>"), except.what ());
>      }
>  }
>  
> ...
> to:
> ...
> (gdb) PASS: gdb.fortran/dynamic.exp: ptype vart
> p varz^M
> $26 = <error reading variable: failed to get range bounds>^M
> (gdb) FAIL: gdb.fortran/dynamic.exp: p varz
> ...

Submitted for trunk here (
https://sourceware.org/pipermail/gdb-patches/2021-October/182521.html ).

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

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

end of thread, other threads:[~2021-10-13 14:08 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-12 12:50 [Bug fortran/26870] New: [fortran] Printing dynamic array fails vries at gcc dot gnu.org
2020-11-12 12:56 ` [Bug fortran/26870] " vries at gcc dot gnu.org
2021-10-13 12:22 ` vries at gcc dot gnu.org
2021-10-13 14:06 ` [Bug symtab/26870] " vries at gcc dot gnu.org
2021-10-13 14:07 ` vries at gcc dot gnu.org
2021-10-13 14:07 ` vries at gcc dot gnu.org
2021-10-13 14:08 ` 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).