I'm doing some development in LLVM and KLEE and I am having some trouble with gdb. I've compiled everything with -O0 and -ggdb args to get rid of optimizations and add the debug symbols. I've used gdb many times for debugging c code, but this is my first time using it on c++.
When I try to debug with gdb everything works correctly, except that the "next" command sometimes "continues" instead of going to the next source line. The debugger always stops on break points, but it seems to decide to skip over many lines than it should with next... For example I might have something like:
int foo::bar(list_class<int> &list, int num){
int i;
num = num + 3;
for(i = 0; i < 5; i++){
list.add(num + i);
}
num = num + 42;
return num;
}
If I break the line:
num = num + 42;
and I "next" from line
num = num + 3;
It will completely skip the for loop and stop at the break point. If I don't set a break on the line the function will return. If I set a break point on line:
list.add(num + i);
the program will always stop on the break point. Does anyone have any suggestions? Thanks in advance.
Edit:
Here are some errors that gdb is throwing me. I'm not sure if they are related to the problem or not.
warning: can't find linker symbol for virtual table for `std::basic_string<char, std::char_traits<char>, std::allocator<char> >' value
warning: can't find linker symbol for virtual table for `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::_Alloc_hider' value
warning: can't find linker symbol for virtual table for `std::_Rb_tree_node_base' value
warning: found `klee::PTree::PTree(klee::ExecutionState* const&)' instead
warning: can't find linker symbol for virtual table for `klee::KInstIterator' value
warning: found `klee::Executor::runFunctionAsMain(llvm::Function*, int, char**, char**)' instead
warning: can't find linker symbol for virtual table for `klee::TreeOStream' value
warning: found `std::string::compare(char const*) const' instead
warning: can't find linker symbol for virtual table for `klee::ImmutableMap<klee::MemoryObject const*, klee::ObjectHolder, klee::MemoryObjectLT>' value
warning: found `bool std::operator==<char, std::char_traits<char>, std::allocator<char> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, char const*)' instead
warning: can't find linker symbol for virtual table for `klee::ImmutableTree<klee::MemoryObject const*, std::pair<klee::MemoryObject const*, klee::ObjectHolder>, klee::_Select1st<std::pair<klee::MemoryObject const*, klee::ObjectHolder>, klee::MemoryObject const*>, klee::MemoryObjectLT>' value
warning: found `bool std::operator==<char, std::char_traits<char>, std::allocator<char> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, char const*)' instead
Edit #2 (Solved)
I solved my problem by upgrading to the newest version of gdb (7.4). I was using version 7.1-ubuntu.
stepinstead ofnext. - panickaldisasingdbor useobjdump -dfrom the command line) and see what the compiler really did with that loop. You appear to have passedlistby value so your whole function is a no-op and the compiler may have figured that out. - Ben Jacksonstepseems to work correctly, but notnext. - John