public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* GDB problems with Fortran common blocks and shared libraries
@ 2005-01-05 19:34 Jeff Webb
  0 siblings, 0 replies; only message in thread
From: Jeff Webb @ 2005-01-05 19:34 UTC (permalink / raw)
  To: gdb

[-- Attachment #1: Type: text/plain, Size: 2158 bytes --]

Hello,

I haven't been able to get gdb to work properly when debugging fortran code that uses common blocks when the code is loaded as a shared library.  I've attached a very simple example that illustrates the problem.

The main program establishes a common block /cb/ that contains three integer variables (i,j,k).  The main program then calls two subroutines (sub1 and sub2), which print out the values of the variables in the common block.  The only difference between sub1 and sub2 is that sub1 is located in the top-level source file called "main.f", and sub2 is located in a separate source file called "sub.f".

If I create a statically linked program, the program executes correctly, and gdb displays the correct values for the common block variables found in sub1 and sub2.

If I create a dynamically linked program, the program executes correctly, but gdb has some problems when the common block is examined from sub2.  The first problem is that the "cb_" symbol for the common block only gets mapped to the "cb_" symbol in main if I run gdb with '--readnow', or if I put a breakpoint in sub1 first, and then examine the common block from sub2.  I can work around this problem with the '--readnow' flag.

The second problem is causing me more trouble.  Although the '--readnow' flag causes the common block 'cb_' to get resolved properly, the members of the common block (i,j,k) are not.  They still point to an address in the memory associated with the shared library, and not the main program, where the 'real' common block is located.

I have been tinkering with gdb's source code, trying to track down the problem, but understanding how everything works is a little daunting.  It appears that 'cb_' gets fixed up because it is a global variable, but the i, j, k seem to be locals and don't get relocated when gdb fixes up 'cb_'.

I was hoping someone who understands the code better might see the root of the problem, and point me in the direction of a fix.  Not being able to debug these common block variables is a major show stopper for a project I am working on, so I am anxious to find a fix, even if it has to be a hack.

Thanks,

-Jeff

[-- Attachment #2: main.f --]
[-- Type: text/x-fortran, Size: 259 bytes --]

      program main
      common /cb/ i, j, k
      integer i, j, k
      i = 1
      j = 2
      k = 3
      call sub1
      call sub2
      end

      subroutine sub1
      common /cb/ i, j, k
      integer i, j, k
      print *,i,j,k
      return
      end

[-- Attachment #3: sub.f --]
[-- Type: text/x-fortran, Size: 113 bytes --]

      subroutine sub2
      common /cb/ i, j, k
      integer i, j, k
      print *,i,j,k
      return
      end

[-- Attachment #4: Makefile --]
[-- Type: text/plain, Size: 236 bytes --]

all: libsub.so main main_static

main_static: main.f sub.f
	g77 -g main.f sub.f -o main_static

main: main.f
	g77 -g main.f -o main -L./ -lsub

libsub.so: sub.f
	g77 -g sub.f -o libsub.so -shared

clean:
	rm -f *~ *.so main main_static

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2005-01-05 19:34 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-01-05 19:34 GDB problems with Fortran common blocks and shared libraries Jeff Webb

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).