GDB 7.12.1: Strange "stepping" behavior

Richard Szibele richard@szibele.com
Sat Apr 22 23:06:00 GMT 2017


Hello everyone,

I am experiencing strange stepping behavior with GDB 7.12.1 and a 
program compiled with g++ (GCC) 5.4.0 which I can demonstrate with a 
simple example:


#include <memory>
#include <iostream>

int main()
{
     auto ptr = std::shared_ptr<int>(new int);
     *ptr = 100;
     std::cout << *ptr << std::endl;
     return 0;
}


I've compiled the above with the following g++ flags:

g++ -std=c++14 -g -O0 main.cpp

and then run gdb on the resulting executable.

When I step over using "next" I end up jumping back and forth, rather 
than a simple linear top-down progression in the source code. I've read 
that this is due to compiler optimizations, but as I've supplied the 
flags -g and -O0, I do not believe this should happen.

Is this a bug or am I doing something wrong?

Best Regards,
Richard Szibele



More information about the Gdb mailing list