This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC 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]

[Bug c++/14444] New: g++ 3.2.1 not generating proper debugging information


I have a small program for which g++ 3.2.1 doesn't seem to generate the right 
debugging information. Although this problem was seen in a vendor supplied 
cross compiler, I confirmed that it exists in 3.x.y native compilers on RedHat 
and Solaris.

The magic combination to trigger this problems seems to be a string/int pair 
straddling a while/switch code block:

#include <string>
#include <stdio.h>
int main(int argc, char *argv[]) {
    std::string a = "foo";
    int c = 0;
    while (c != -1) {
	switch (c = getchar()) {
	    default:
		printf ("read %d, %s\n", c, a.c_str());
		c = -1; // break the loop
		break;
	}
    }
    std::string b = "bar";
    int k = 10;
    printf("%s %s %d\n", a.c_str(), b.c_str(), k);
}

When I compile this with -g and default optimization and load it in gdb, I 
can't see all the local variables via 'info locals'.

Here are my observations about the program:
- This is the exact combination that causes the problem; if I delete one of the 
string variables, switch the order of variable definitions, or delete the 
while/switch blocks, the problem goes away.
- To begin with, only the variable 'k' is visible. Even inside the while loop, 
I can't see 'c' or 'a'.
- All variables become visible once I exit the while loop.
- It doesn't matter if I actually use the variables or not - they are invisible 
until I exit the while loop.
- If I switch to g++ 2.95.3, all is well. Problem begins with g++ 3.2.1.

(Cross) Compiler is:

/opt/hardhat3.0/hardhat/devkit/x86/586/bin/586-g++ -v
Reading specs from /opt/hardhat3.0/hardhat/devkit/x86/586/bin/../lib/gcc-
lib/i586-hardhat-linux/3.2.1/specs
Configured with: ../configure --host=i686-pc-linux-gnu
--target=i586-hardhat-linux --prefix=/opt/hardhat/devkit/x86/586
--exec-prefix=/opt/hardhat/devkit/x86/586
--bindir=/opt/hardhat/devkit/x86/586/bin
--sbindir=/opt/hardhat/devkit/x86/586/sbin
--sysconfdir=/opt/hardhat/devkit/x86/586/etc
--datadir=/opt/hardhat/devkit/x86/586/share
--includedir=/opt/hardhat/devkit/x86/586/include
--libdir=/opt/hardhat/devkit/x86/586/lib
--libexecdir=/opt/hardhat/devkit/x86/586/libexec
--localstatedir=/opt/hardhat/devkit/x86/586/var
--sharedstatedir=/opt/hardhat/devkit/x86/586/share
--mandir=/opt/hardhat/devkit/x86/586/man
--infodir=/opt/hardhat/devkit/x86/586/info
--program-transform-name=s,^,586-, --enable-cross
--with-gxx-include-dir=${prefix}/i586-hardhat-linux/include/g++-v3
--enable-shared --enable-languages=c,c++ --enable-threads=posix
--enable-__cxa_atexit --disable-multilib --with-cpu=i586
Thread model: posix
gcc version 3.2.1 20020930 (MontaVista)

Debugger is:
swtest38:~-15> gdb --version
GNU gdb 5.2.1
Copyright 2002 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are 
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i586-hardhat-linux".

Target system is:
swtest38:~-18> uname -a
Linux swtest38 2.4.18 #1 Wed Feb 11 00:31:23 CST 2004 i586 unknown

Sorry for not including the preprocessed output; I thought that
since string and stdio.h are standard header files, a source file is
sufficient.

Jim Wilson has already taken a look at this problem and offered the following 
diagnosis:

The locals are there, but they have been put into a lexical block, which  is 
not correct.  The current development sources seem to handle this  correctly.  
a, b, and c are visible in the entire function except the prologue/epilogue, 
and k is visible only after the loop.

info locals still didn't work for me though.  It fails to print the value of a, 
and then bails out.

This is for an x86-linux target that uses dwarf2 debug info.  I didn't check a 
stabs target like solaris.

<snipped>
-- 
Jim Wilson, GNU Tools Support, http://www.SpecifixInc.com

Thanks for your time and help.
Sriram

-- 
           Summary: g++ 3.2.1 not generating proper debugging information
           Product: gcc
           Version: 3.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: mailsb04-posts at yahoo dot com
                CC: gcc-bugs at gcc dot gnu dot org,mailsb04-posts at yahoo
                    dot com
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i586-hardhat-linux


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14444


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