From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26481 invoked by alias); 5 Jan 2005 19:34:02 -0000 Mailing-List: contact gdb-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sources.redhat.com Received: (qmail 26122 invoked from network); 5 Jan 2005 19:33:51 -0000 Received: from unknown (HELO mrdec-owa.ds.amrdec.army.mil) (199.209.144.25) by sourceware.org with SMTP; 5 Jan 2005 19:33:51 -0000 Received: from [10.0.144.54] (10.0.144.54 [10.0.144.54]) by mrdec-owa.ds.amrdec.army.mil with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2657.72) id CHK2LM7D; Wed, 5 Jan 2005 13:32:33 -0600 Message-ID: <41DC40C2.9060308@nta-inc.net> Date: Wed, 05 Jan 2005 19:34:00 -0000 From: Jeff Webb User-Agent: Mozilla Thunderbird 0.6 (X11/20040519) MIME-Version: 1.0 To: gdb@sources.redhat.com Subject: GDB problems with Fortran common blocks and shared libraries Content-Type: multipart/mixed; boundary="------------090106080308090405040209" X-SW-Source: 2005-01/txt/msg00042.txt.bz2 This is a multi-part message in MIME format. --------------090106080308090405040209 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Content-length: 2158 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 --------------090106080308090405040209 Content-Type: text/x-fortran; name="main.f" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="main.f" Content-length: 259 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 --------------090106080308090405040209 Content-Type: text/x-fortran; name="sub.f" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="sub.f" Content-length: 113 subroutine sub2 common /cb/ i, j, k integer i, j, k print *,i,j,k return end --------------090106080308090405040209 Content-Type: text/plain; name="Makefile" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="Makefile" Content-length: 236 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 --------------090106080308090405040209--