1
votes

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.

1
Did you try using step instead of next. - panickal
Despite your precautions to avoid optimization I would disassemble the function (you can use disas in gdb or use objdump -d from the command line) and see what the compiler really did with that loop. You appear to have passed list by value so your whole function is a no-op and the compiler may have figured that out. - Ben Jackson
I've had gdb do bizarre or impossible things many times before; having talked to other developers about it, I get the feeling that it just doesn't work well for some people. - Cannoliopsida
Sorry I've changed the example to pass by reference. I checked the disassembly and tried stepping by instructions. The disassembly looks correct, but stepping by instructions is yielding even more bizarre behavior. I will stop over a mov instruction, for example, then end up in some other subroutine. Instruction stepping doesn't seem to stop on the correct break points like source level stepping does either... I have gotten some errors from gdb that I'll edit in the description. Thanks for the suggestion. - John
step seems to work correctly, but not next. - John

1 Answers

0
votes

I solved my problem by upgrading to the newest version of gdb (7.4). I was using version 7.1-ubuntu.