[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

C++: a gdb problem when debugging multiple files source program.



For some reason the behavior of gdb when I split a C++ program into
multiple files is not the same as when there is only one source file.
In particular, in the multiple file case gdb does not recognize local
variables and does not honor breakpoints that are set by line numbers.
What am I missing?

The details are:

(gdb) b demo::demo()
Breakpoint 1 at 0x804d69c: file demo.cc, line 4.
(gdb) r
Starting program: /tmp/multipleFiles

Breakpoint 1, 0x0804d69c in demo (this=0x804cb64) at demo.cc:4
4       {
(gdb) l
1       #include "demo.h"
2
3       demo::demo()
4       {
5           ifstream input("mainMultiple.cc");
6           istream_iterator<string> iter(input);
7           while (input) cout << *iter++ << "  ";
8           cout << "\n";
9       };
10
(gdb) n
5           ifstream input("mainMultiple.cc");
(gdb) n
6           istream_iterator<string> iter(input);
(gdb) p input
No symbol "input" in current context.
(gdb) b 8
Breakpoint 2 at 0x804d5f0: file demo.cc, line 8.
(gdb) c
Continuing.
#include  "demo.h"  int  main()  {}

Program exited normally.
(gdb) q
[02:49:37 tmp]$

gdb version is 5.1.

[02:50:20 tmp]$ g++-3.0 -v
Reading specs from /usr/lib/gcc-lib/i386-linux/3.0.2/specs
Configured with: ../src/configure -v --enable-languages=c,c++,java,f77,p
roto,objc --prefix=/usr --infodir=/share/info --mandir=/share/man
--enable-shared --with-gnu-as --with-gnu-ld --with-system-zlib
--enable-long-long --enable-nls --without-included-gettext
--disable-checking --enable-threads=posix --enable-java-gc=boehm
--with-cpp-install-dir=bin --enable-objc-gc i386-linux
Thread model: posix
gcc version 3.0.2 (Debian)
[02:50:27 tmp]$

The build line from the Makefile is:

multipleFiles: demo.cc  demo.h  mainMultiple.cc
        $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ demo.cc mainMultiple.cc


Follows the sources for the multiple and single versions of the program
and the Makefile:

            ========================================

::::::::::::::
demo.h
::::::::::::::
#include <fstream>
#include <iostream>
#include <iterator>

using namespace std;

class demo {
    public:
        demo();
};

extern demo testing;

::::::::::::::
demo.cc
::::::::::::::
#include "demo.h"

demo::demo()
{
    ifstream input("mainMultiple.cc");
    istream_iterator<string> iter(input);
    while (input) cout << *iter++ << "  ";
    cout << "\n";
};

demo testing;

::::::::::::::
mainMultiple.cc
::::::::::::::
#include "demo.h"

int main() {}

::::::::::::::
mainSingle.cc
::::::::::::::
#include <fstream>
#include <iostream>
#include <iterator>

using namespace std;

class demo
{
    public:
        demo() {
            ifstream input("mainSingle.cc");
            istream_iterator<string> iter(input);
            while (input) cout << *iter++ << "  ";
            cout << "\n";
        }
};

demo testing;

int main() {}

::::::::::::::
Makefile
::::::::::::::
CXX      = g++-3.0
CXXFLAGS = -Wall -ggdb
LDFLAGS  = -ggdb

all: multipleFiles  singleFile

multipleFiles: demo.cc  demo.h  mainMultiple.cc
        $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ demo.cc mainMultiple.cc

singleFile: mainSingle.cc
        $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $<

clean:
        $(RM) -v *.o

.PHONY: all clean

-- 

    Shaul Karl
    email: shaulka(at-no-spam)bezeqint.net 
           Please replace (at-no-spam) with an at - @ - character.
           (at-no-spam) is meant for unsolicitate mail senders only.




Reply to: