From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10560 invoked by alias); 3 Mar 2007 22:00:35 -0000 Received: (qmail 10536 invoked by uid 22791); 3 Mar 2007 22:00:30 -0000 X-Spam-Check-By: sourceware.org Received: from rwcrmhc11.comcast.net (HELO rwcrmhc11.comcast.net) (204.127.192.81) by sourceware.org (qpsmtpd/0.31) with ESMTP; Sat, 03 Mar 2007 22:00:28 +0000 Received: from hippogriff.homeunix.org ([75.71.67.96]) by comcast.net (rwcrmhc11) with ESMTP id <20070303220026m11009o9jbe>; Sat, 3 Mar 2007 22:00:26 +0000 Received: by hippogriff.homeunix.org (Postfix, from userid 1000) id 9A2C857680; Sat, 3 Mar 2007 15:00:34 -0700 (MST) Date: Sat, 03 Mar 2007 22:00:00 -0000 From: Patrick Alken To: gdb@sourceware.org Subject: fortran arrays in gdb Message-ID: <20070303220033.GA17346@hippogriff.physics.drexel.edu> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="45Z9DzgjV8m4Oswq" Content-Disposition: inline User-Agent: Mutt/1.4.2.2i Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org X-SW-Source: 2007-03/txt/msg00045.txt.bz2 --45Z9DzgjV8m4Oswq Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 1722 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 --45Z9DzgjV8m4Oswq Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="mat.c" Content-length: 288 #include 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; } --45Z9DzgjV8m4Oswq Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="testmat.f" Content-length: 234 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 --45Z9DzgjV8m4Oswq--