GDB 7.12.1: Strange "stepping" behavior

Richard Szibele <[email protected]>
Newsgroups gmane.comp.gdb.devel
Message-ID <[email protected]>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.