This is the mail archive of the gdb@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

GDB problems with Fortran common blocks and shared libraries


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
      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
      subroutine sub2
      common /cb/ i, j, k
      integer i, j, k
      print *,i,j,k
      return
      end
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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]