* fortran arrays in gdb
@ 2007-03-03 22:00 Patrick Alken
2007-03-03 22:23 ` Patrick Alken
2007-03-05 12:33 ` Daniel Jacobowitz
0 siblings, 2 replies; 6+ messages in thread
From: Patrick Alken @ 2007-03-03 22:00 UTC (permalink / raw)
To: gdb
[-- Attachment #1: Type: text/plain, Size: 1722 bytes --]
Hello,
I am trying to call fortran subroutines from C and then step
through the fortran code with gdb. Unfortunately, gdb (version 6.5)
cannot properly display the contents of 2D arrays passed to the fortran
routine. I have created 2 simple files:
mat.c - a C program which calls the fortran routine with a 4x4 matrix
testmat.f - a fortran77 subroutine which prints out the matrix
These were compiled with:
g77 -g -Wall -c testmat.f
gcc -g -Wall -o mat mat.c testmat.o -lg2c
Here is the output of the program (which is correct):
> ./mat
a( 1, 1) = 1.
a( 1, 2) = 5.
a( 1, 3) = 9.
a( 1, 4) = 13.
a( 2, 1) = 2.
a( 2, 2) = 6.
a( 2, 3) = 10.
a( 2, 4) = 14.
a( 3, 1) = 3.
a( 3, 2) = 7.
a( 3, 3) = 11.
a( 3, 4) = 15.
a( 4, 1) = 4.
a( 4, 2) = 8.
a( 4, 3) = 12.
a( 4, 4) = 16.
Now here is the problem: when I step through the fortran subroutine
with gdb and try to print out individual array values, it gives
incorrect results:
> gdb mat
...
(gdb) break testmat_
Breakpoint 1 at 0x8048592: file testmat.f, line 1.
(gdb) r
Starting program: /home/cosine/C/mat
Breakpoint 1, testmat_ (n=0xbfa83ecc, a=0xbfa83ed0) at testmat.f:1
1 subroutine testmat(n,a)
Current language: auto; currently fortran
(gdb) n
6 do 10 i = 1, n
(gdb) p a(2,2)
$1 = 3
(gdb) p a(4,3)
$2 = 6
(gdb) p a(3,4)
$3 = 6
(gdb)
By comparing this with the correct output from calling the program,
we know that a(2,2) should in fact be 6, not 3. a(4,3) should be 12,
not 6, and a(3,4) should be 15, not 6.
Can someone please tell me if there is a way to correct this problem.
I really need to be able to step through fortran code and be able
to rely on the gdb output. Please help!
Patrick Alken
[-- Attachment #2: mat.c --]
[-- Type: text/plain, Size: 288 bytes --]
#include <stdio.h>
void testmat_(int *n, double *A);
int main()
{
double data[] = { 1.0, 2.0, 3.0, 4.0,
5.0, 6.0, 7.0, 8.0,
9.0, 10.0, 11.0, 12.0,
13.0, 14.0, 15.0, 16.0 };
int n = 4;
testmat_(&n, data);
return 0;
}
[-- Attachment #3: testmat.f --]
[-- Type: text/plain, Size: 234 bytes --]
subroutine testmat(n,a)
c
integer n, i, j
double precision a(n,n)
do 10 i = 1, n
do 20 j = 1, n
print *, 'a(', i, ',', j, ') =', a(i,j)
20 continue
10 continue
return
end
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: fortran arrays in gdb
2007-03-03 22:00 fortran arrays in gdb Patrick Alken
@ 2007-03-03 22:23 ` Patrick Alken
2007-03-05 12:33 ` Daniel Jacobowitz
1 sibling, 0 replies; 6+ messages in thread
From: Patrick Alken @ 2007-03-03 22:23 UTC (permalink / raw)
To: gdb
Hi again,
Interestingly, I can get correct results using the following method:
(gdb) p a
$76 = (PTR TO -> ( real*8 (1,1))) 0xbfa83ed0
(gdb) p *((double*)0xbfa83ed0 + 1 + 1*4)
$78 = 6
where I just printed out a(2,2), so in other words, I can use
(gdb) p *((double*)0xbfa83ed0 + r + c*4)
where 'r' is the row I want and 'c' is the column I want. So
why won't the a(r,c) syntax work?
On Sat, Mar 03, 2007 at 03:00:33PM -0700, Patrick Alken wrote:
> Hello,
>
> I am trying to call fortran subroutines from C and then step
> through the fortran code with gdb. Unfortunately, gdb (version 6.5)
> cannot properly display the contents of 2D arrays passed to the fortran
> routine. I have created 2 simple files:
>
> mat.c - a C program which calls the fortran routine with a 4x4 matrix
> testmat.f - a fortran77 subroutine which prints out the matrix
>
> These were compiled with:
>
> g77 -g -Wall -c testmat.f
> gcc -g -Wall -o mat mat.c testmat.o -lg2c
>
> Here is the output of the program (which is correct):
>
> > ./mat
> a( 1, 1) = 1.
> a( 1, 2) = 5.
> a( 1, 3) = 9.
> a( 1, 4) = 13.
> a( 2, 1) = 2.
> a( 2, 2) = 6.
> a( 2, 3) = 10.
> a( 2, 4) = 14.
> a( 3, 1) = 3.
> a( 3, 2) = 7.
> a( 3, 3) = 11.
> a( 3, 4) = 15.
> a( 4, 1) = 4.
> a( 4, 2) = 8.
> a( 4, 3) = 12.
> a( 4, 4) = 16.
>
> Now here is the problem: when I step through the fortran subroutine
> with gdb and try to print out individual array values, it gives
> incorrect results:
>
> > gdb mat
> ...
> (gdb) break testmat_
> Breakpoint 1 at 0x8048592: file testmat.f, line 1.
> (gdb) r
> Starting program: /home/cosine/C/mat
>
> Breakpoint 1, testmat_ (n=0xbfa83ecc, a=0xbfa83ed0) at testmat.f:1
> 1 subroutine testmat(n,a)
> Current language: auto; currently fortran
> (gdb) n
> 6 do 10 i = 1, n
> (gdb) p a(2,2)
> $1 = 3
> (gdb) p a(4,3)
> $2 = 6
> (gdb) p a(3,4)
> $3 = 6
> (gdb)
>
> By comparing this with the correct output from calling the program,
> we know that a(2,2) should in fact be 6, not 3. a(4,3) should be 12,
> not 6, and a(3,4) should be 15, not 6.
>
> Can someone please tell me if there is a way to correct this problem.
> I really need to be able to step through fortran code and be able
> to rely on the gdb output. Please help!
>
> Patrick Alken
>
> #include <stdio.h>
>
> void testmat_(int *n, double *A);
>
> int main()
> {
> double data[] = { 1.0, 2.0, 3.0, 4.0,
> 5.0, 6.0, 7.0, 8.0,
> 9.0, 10.0, 11.0, 12.0,
> 13.0, 14.0, 15.0, 16.0 };
> int n = 4;
>
> testmat_(&n, data);
>
> return 0;
> }
> subroutine testmat(n,a)
> c
> integer n, i, j
> double precision a(n,n)
>
> do 10 i = 1, n
> do 20 j = 1, n
> print *, 'a(', i, ',', j, ') =', a(i,j)
> 20 continue
> 10 continue
> return
> end
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: fortran arrays in gdb
2007-03-03 22:00 fortran arrays in gdb Patrick Alken
2007-03-03 22:23 ` Patrick Alken
@ 2007-03-05 12:33 ` Daniel Jacobowitz
2007-03-05 17:01 ` Patrick Alken
1 sibling, 1 reply; 6+ messages in thread
From: Daniel Jacobowitz @ 2007-03-05 12:33 UTC (permalink / raw)
To: Patrick Alken; +Cc: gdb
On Sat, Mar 03, 2007 at 03:00:33PM -0700, Patrick Alken wrote:
> Hello,
>
> I am trying to call fortran subroutines from C and then step
> through the fortran code with gdb. Unfortunately, gdb (version 6.5)
> cannot properly display the contents of 2D arrays passed to the fortran
> routine. I have created 2 simple files:
Could you try 6.6, or better yet, a current CVS snapshot? Some work
was done on Fortran array support.
--
Daniel Jacobowitz
CodeSourcery
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: fortran arrays in gdb
2007-03-05 12:33 ` Daniel Jacobowitz
@ 2007-03-05 17:01 ` Patrick Alken
2007-03-05 17:09 ` Daniel Jacobowitz
0 siblings, 1 reply; 6+ messages in thread
From: Patrick Alken @ 2007-03-05 17:01 UTC (permalink / raw)
To: gdb
Hi,
I have tried the latest snapshot: GNU gdb 6.6.50.20070305
but it has the same behavior has 6.5:
(gdb) p a
$5 = (PTR TO -> ( real*8 (1,1))) 0xbf85dbd0
Since the matrix "a" has a dynamically specified size:
double precision a(n,n) where n is an input parameter, maybe
gdb cannot determine how big it is, since the "print a" command
is telling me its a 1-by-1 matrix. Is there a way to "tell" gdb
what the leading dimension of the array is, so that a(x,y) will
work correctly?
Patrick Alken
On Mon, Mar 05, 2007 at 07:33:09AM -0500, Daniel Jacobowitz wrote:
> On Sat, Mar 03, 2007 at 03:00:33PM -0700, Patrick Alken wrote:
> > Hello,
> >
> > I am trying to call fortran subroutines from C and then step
> > through the fortran code with gdb. Unfortunately, gdb (version 6.5)
> > cannot properly display the contents of 2D arrays passed to the fortran
> > routine. I have created 2 simple files:
>
> Could you try 6.6, or better yet, a current CVS snapshot? Some work
> was done on Fortran array support.
>
> --
> Daniel Jacobowitz
> CodeSourcery
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: fortran arrays in gdb
2007-03-05 17:01 ` Patrick Alken
@ 2007-03-05 17:09 ` Daniel Jacobowitz
2007-03-05 18:59 ` Patrick Alken
0 siblings, 1 reply; 6+ messages in thread
From: Daniel Jacobowitz @ 2007-03-05 17:09 UTC (permalink / raw)
To: Patrick Alken; +Cc: gdb
On Mon, Mar 05, 2007 at 10:01:10AM -0700, Patrick Alken wrote:
> Hi,
>
> I have tried the latest snapshot: GNU gdb 6.6.50.20070305
> but it has the same behavior has 6.5:
>
> (gdb) p a
> $5 = (PTR TO -> ( real*8 (1,1))) 0xbf85dbd0
>
> Since the matrix "a" has a dynamically specified size:
>
> double precision a(n,n) where n is an input parameter, maybe
> gdb cannot determine how big it is, since the "print a" command
> is telling me its a 1-by-1 matrix. Is there a way to "tell" gdb
> what the leading dimension of the array is, so that a(x,y) will
> work correctly?
No, but it's supposed to be able to figure this out automatically. I
guess there must be a bug somewhere :-(
--
Daniel Jacobowitz
CodeSourcery
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: fortran arrays in gdb
2007-03-05 17:09 ` Daniel Jacobowitz
@ 2007-03-05 18:59 ` Patrick Alken
0 siblings, 0 replies; 6+ messages in thread
From: Patrick Alken @ 2007-03-05 18:59 UTC (permalink / raw)
To: gdb
> No, but it's supposed to be able to figure this out automatically. I
> guess there must be a bug somewhere :-(
Ok, well in the mean time, p *(a + x + y*(*n)) works well enough to
compute a(x,y). Thanks.
Patrick Alken
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2007-03-05 18:59 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-03-03 22:00 fortran arrays in gdb Patrick Alken
2007-03-03 22:23 ` Patrick Alken
2007-03-05 12:33 ` Daniel Jacobowitz
2007-03-05 17:01 ` Patrick Alken
2007-03-05 17:09 ` Daniel Jacobowitz
2007-03-05 18:59 ` Patrick Alken
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox