Bug 11104 - gdb 7.0 does not print two dimensional Fortran arrays correctly.
Summary: gdb 7.0 does not print two dimensional Fortran arrays correctly.
Status: REOPENED
Alias: None
Product: gdb
Classification: Unclassified
Component: fortran (show other bugs)
Version: HEAD
: P2 normal
Target Milestone: 7.3
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-12-17 18:42 UTC by Fred Krogh
Modified: 2011-04-21 11:25 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
Proposed patch (1.26 KB, patch)
2010-09-12 14:43 UTC, Andrew Burgess
Details | Diff
Test for this issue. (1.27 KB, application/octet-stream)
2010-09-12 14:53 UTC, Andrew Burgess
Details
Updated patch (1.35 KB, patch)
2010-09-16 08:03 UTC, Andrew Burgess
Details | Diff
Updated testcase (1.42 KB, application/octet-stream)
2010-09-16 08:45 UTC, Andrew Burgess
Details
Support for multi-dimensional fortran arrays (1.02 KB, patch)
2010-10-19 08:30 UTC, Andrew Burgess
Details | Diff
New test in patch format (1.33 KB, patch)
2010-10-19 15:10 UTC, Andrew Burgess
Details | Diff
Support for multi-dimensional fortran arrays (1.22 KB, patch)
2010-10-19 15:12 UTC, Andrew Burgess
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Fred Krogh 2009-12-17 18:42:47 UTC
I was not able to find how to find the triplets requested when running on a
Gentoo Linux system.  Running uname -a gives
Linux mon 2.6.32-gentoo #1 SMP Thu Dec 3 13:59:59 PST 2009 x86_64 AMD
Opteron(tm) Processor 242 AuthenticAMD GNU/Linux

Try this Fortran code
====
      program test
c   Testing gdb for printing arrays
      double precision C(4,4)
      do J = 1, 4
        do I = 1, 4
          C(I,J) = dble(I+J)
        end do
      end do
      print '(''C(1,1), C(4,4):'', 1P, 2E12.5)', C(1,1), C(4,4)
      stop
      end
======
gfortran -ggdb -o test test.f
gdb test
b 9
r
p c(1,2)

And I get

no such vector element
Comment 1 Fred Krogh 2010-01-26 16:09:14 UTC
Just tried gdb-7.0.1 on my gentoo system, and it has the same problem, this time 
noticed for a one-dimensional array.  The error message is the same.  Version 6.8 
works.
Comment 2 Alexander Varnin 2010-05-31 09:49:38 UTC
Confirming on version 7.1
Comment 3 Andrew Burgess 2010-09-12 14:43:57 UTC
Created attachment 4976 [details]
Proposed patch

Fortran multi-dimensional arrays are of type:
   ARRAY of ( ARRAY of ( BASETYPE ) )
Nested to the required depth.
The code used to fetch a single element out of an array could previously only
handle (ARRAY of BASETYPE), and so before calling this we would modify the type
of the array. However, this was leading to other problems when we try to bounds
check the array access.

This patch changes the array access code so that is can peel off all the layers
of ARRAY of ARRAY of ... to get to the BASETYPE.
Comment 4 Andrew Burgess 2010-09-12 14:53:34 UTC
Created attachment 4977 [details]
Test for this issue.

The multi-dim.tar.bz2 contains a new test that should cover this issue. It
would need adding to gdb/testsuite/gdb.fortran. The only thing is, I've not
been able to run any of the Fortran tests myself as I'm struggling to get them
to compile, I don't know if this is just my setup or a general issue.
I'm working with gdb-7.2 & gcc 4.4.3.

I've checked that this new test works using a dirty hack :) but someone who can
actually get the Fortran tests running should check this works correctly before
it's committed into the tree.
Comment 5 Andrew Burgess 2010-09-16 08:03:44 UTC
Created attachment 4986 [details]
Updated patch

This should apply to the current CVS head.
Comment 6 Andrew Burgess 2010-09-16 08:45:30 UTC
Created attachment 4987 [details]
Updated testcase

Finally got the Fortran tests running, slight update to the test case.
Comment 7 Andrew Burgess 2010-10-19 08:30:41 UTC
Created attachment 5068 [details]
Support for multi-dimensional fortran arrays

Minor updates to patch to meeting coding standards. Changelog message removed from patch file:

2010-10-19 Andrew Burgess <aburgess@broadcom.com>

  	* valarith.c (value_subscripted_rvalue) Walk through
  	multi-dimensional arrays to find the element type for the
  	array. Allows the upper bound check to work with multi-dimensional
  	arrays. Fix PR gdb/11104.
  	* eval.c (evaluate_subexp_standard) Remove hack from
  	multi_f77_subscript case now that multi-dimensional arrays are
  	supported.  Fix PR gdb/11104.
Comment 8 Andrew Burgess 2010-10-19 15:10:24 UTC
Created attachment 5069 [details]
New test in patch format

Test for this issue in patch format. ChangeLog message included before patch.
Comment 9 Andrew Burgess 2010-10-19 15:12:08 UTC
Created attachment 5070 [details]
Support for multi-dimensional fortran arrays

Updated to include the ChangeLog entry as text before the patch content.
Comment 10 Sourceware Commits 2011-01-12 16:16:33 UTC
CVSROOT:	/cvs/src
Module name:	src
Changes by:	jkratoch@sourceware.org	2011-01-12 16:16:25

Modified files:
	gdb            : ChangeLog dwarf2read.c eval.c 
	gdb/testsuite  : ChangeLog 
Added files:
	gdb/testsuite/gdb.fortran: multi-dim.exp multi-dim.f90 

Log message:
	gdb/
	PR fortran/11104 and DWARF unbound arrays detection.
	* dwarf2read.c (read_subrange_type): Set zero length on unspecified
	upper bound.  Set TYPE_HIGH_BOUND_UNDEFINED if not language_ada on
	unspecified upper bound.
	* eval.c (evaluate_subexp_standard) <multi_f77_subscript>: Remove
	variables array_size_array, tmp_type and offset_item.  New variable
	array.  Remove call to f77_get_upperbound.  New variables array_type
	and index.  Call value_subscripted_rvalue for each dimenasion.  Remove
	the final call to deprecated_set_value_type.
	
	gdb/testsuite/
	PR fortran/11104 and DWARF unbound arrays detection.
	* gdb.fortran/multi-dim.exp: New file.
	* gdb.fortran/multi-dim.f90: New file.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/ChangeLog.diff?cvsroot=src&r1=1.12463&r2=1.12464
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/dwarf2read.c.diff?cvsroot=src&r1=1.494&r2=1.495
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/eval.c.diff?cvsroot=src&r1=1.145&r2=1.146
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/testsuite/ChangeLog.diff?cvsroot=src&r1=1.2549&r2=1.2550
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/testsuite/gdb.fortran/multi-dim.exp.diff?cvsroot=src&r1=NONE&r2=1.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/testsuite/gdb.fortran/multi-dim.f90.diff?cvsroot=src&r1=NONE&r2=1.1
Comment 11 Jan Kratochvil 2011-01-12 16:22:02 UTC
Fixed by the commit based on Andrew Burgess's patch.
Comment 12 Saha Smirnovsky 2011-04-05 14:42:59 UTC
gdb gives wrong results in case when one-dimensional array is passed as argument to subroutine and is treated as multidimensional array with dimensions which were passed as arguments.

Please see this Fortran code:

test.f90
===
  program test_array
  integer foo(4)

  do I=1,4
    foo(I)=I
  enddo
  call test(foo,2)
  end


  subroutine test(M,N)
  integer  N
  integer  M(N,N)

  do J=1,N
  do I=1,N
    write(*,*) "I,J,M = ",I,J,M(I,J)
  enddo
  enddo
  end
===

This is output:

$ gfortran -ggdb -o test test.f90
$ ./test
 I,J,M =            1           1           1
 I,J,M =            2           1           2
 I,J,M =            1           2           3
 I,J,M =            2           2           4

This is debugging:
$ gdb test
...
(gdb) break test
Breakpoint 1 at 0x804863e: file test.f90, line 11.
(gdb) run
Starting program: /home/????/test 

Breakpoint 1, test (m=..., n=2) at test.f90:11
11	subroutine test(M,N)
(gdb) print M(2,2)
$1 = 2

I use gdb 7.3.50.20110405
Comment 13 Saha Smirnovsky 2011-04-21 11:25:08 UTC
This bug is temporary fixed in archer-jankratochvil-vla branch