[Bug 27800] New: LLDB step-in misses internal breakpoint and continues execution

Bug ID 27800
Summary LLDB step-in misses internal breakpoint and continues execution
Product lldb
Version unspecified
Hardware PC
OS All
Status NEW
Severity normal
Priority P
Component All Bugs
Assignee lldb-dev@lists.llvm.org
Reporter progers7@gatech.edu
CC llvm-bugs@lists.llvm.org
Classification Unclassified

Created attachment 16383 [details]
Reproduction test files

lldb-340.4.70
llvm 7.0.0 (clang-700.0.72) (also occurs at trunk@r268813)

Reproduction steps:
1. Compile
  g++ -O1 -gdwarf-4 -c TestClass.cpp
  g++ -gdwarf-4 lldbBug.cpp TestClass.o -o lldbBug -lm

2. Launch lldb and break at TestSubclass::reproStepBug()
  lldb lldbBug
  breakpoint set --name TestSubclass::reproStepBug
  run

3. Once the breakpoint is hit, try stepping
  thread step-in
  [bug!!]

The bug is that lldb's internal step breakpoint is skipped over due to
optimizations. Because the optimized code is linked in, there is no warning
about stepping with optimizations.

In multithreaded programs, this bug results in the current thread continuing
out from underneath lldb. From the user's perspective, the thread just becomes
invalid:
Process 37950 stopped ...
(lldb) thread step-in
(lldb) thread step-in
error: invalid thread
(lldb) thread step-in
error: invalid thread

--------------TestClass.cpp--------------
#include "TestClass.h"

__attribute__ ((optnone)) static bool getMember(const TestClass* testObject) {
    return testObject->member;
}

void TestClass::callMember() const
{
    if (getMember(this))
        member->callMember();
}

---------------TestClass.h---------------
class TestClass {
public:
    explicit TestClass(TestClass* m) : member(m) { }
    void callMember() const;
    TestClass* member;
};

class TestSubclass : public TestClass {
public:
    explicit TestSubclass() : TestClass(0) { }

    // To repro, break at this function and then step through the two calls.
    void reproStepBug() {
        callMember();
        callMember();
    }
};

--------------lldbBug.cpp--------------
#include "TestClass.h"

int main(int argc, char *argv[]) {
    TestSubclass object;
    object.reproStepBug();
    return 0;
}