jmjatlanta
September 6th, 2011, 08:51 PM
I am having difficulty with GDB and C++ in Ubuntu, and am unsure where to go for answers. Here's the basics:
I have a simple program:
<code>
#include <iostream>
#include <map>
#include <string>
int main(int argc, char* argv[]) {
std::map<std::string, std::string> dict;
dict["Hello"] = "World!";
std::cout << "Map size is " << dict.size() << std::endl;
return 0;
}
</code>
and I compile via:
g++ -O0 -ggdb -o DebugTest DebugTest.cpp
I step through the code, and hit the line
dict["Hello"] = "World";
I enter "n" to get to the next line, and the program runs all the last lines (I get the expected output on STDOUT) and stops in __libc_start_main().
I have attempted to do the same thing in Cygwin on my Windows XP box, and it works as expected, stepping through the remaining lines. But with Ubuntu (Natty), it seems to run all the lines and jump to the end.
If I type "break 7" it works, as it finds the "dict["Hello"] = ..." line. If I type "break 8" gdb says "No line 8 in file "DebugTest.cpp""
Here's the output of my GDB session:
gdb DebugTest
GNU gdb 6.8
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-pc-linux-gnu"...
(gdb) break main
Breakpoint 1 at 0x8048bde: file DebugTest.cpp, line 6.
(gdb) run
Starting program: /home/jmjatlanta/development/cpp/cpplanguage/DebugTest/DebugTest
Breakpoint 1, main (argc=1, argv=0xbf82b8d4) at DebugTest.cpp:6
6 std::map<std::string, std::string> dict;
(gdb) n
7 dict["Hello"] = "Test";
(gdb) n
Number of elements: 1
0x002e1e37 in __libc_start_main () from /lib/i386-linux-gnu/libc.so.6
(gdb) n
Single stepping until exit from function __libc_start_main,
which has no line number information.
Program exited normally.
(gdb)
I have a simple program:
<code>
#include <iostream>
#include <map>
#include <string>
int main(int argc, char* argv[]) {
std::map<std::string, std::string> dict;
dict["Hello"] = "World!";
std::cout << "Map size is " << dict.size() << std::endl;
return 0;
}
</code>
and I compile via:
g++ -O0 -ggdb -o DebugTest DebugTest.cpp
I step through the code, and hit the line
dict["Hello"] = "World";
I enter "n" to get to the next line, and the program runs all the last lines (I get the expected output on STDOUT) and stops in __libc_start_main().
I have attempted to do the same thing in Cygwin on my Windows XP box, and it works as expected, stepping through the remaining lines. But with Ubuntu (Natty), it seems to run all the lines and jump to the end.
If I type "break 7" it works, as it finds the "dict["Hello"] = ..." line. If I type "break 8" gdb says "No line 8 in file "DebugTest.cpp""
Here's the output of my GDB session:
gdb DebugTest
GNU gdb 6.8
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-pc-linux-gnu"...
(gdb) break main
Breakpoint 1 at 0x8048bde: file DebugTest.cpp, line 6.
(gdb) run
Starting program: /home/jmjatlanta/development/cpp/cpplanguage/DebugTest/DebugTest
Breakpoint 1, main (argc=1, argv=0xbf82b8d4) at DebugTest.cpp:6
6 std::map<std::string, std::string> dict;
(gdb) n
7 dict["Hello"] = "Test";
(gdb) n
Number of elements: 1
0x002e1e37 in __libc_start_main () from /lib/i386-linux-gnu/libc.so.6
(gdb) n
Single stepping until exit from function __libc_start_main,
which has no line number information.
Program exited normally.
(gdb)