llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.63k stars 11.83k forks source link

LLDB hangs when using C++ API on Windows #52769

Open mika256 opened 2 years ago

mika256 commented 2 years ago

Architecture: x86 OS: Windows 10 LLVM Version: 13.0.0

It happens if the breakpoint is hit too often. Here is the minimal source code for reproduction. Let the program being debugged be named TestApp.exe and the file Main.cpp:

#include <iostream>

int main() {
  while (true) {
    std::cout << ".";  // Here you need to set a breakpoint
  }
  return 0;
}

Code for starting the debugger, setting a breakpoint, and debugging run loop:

#include <lldb/API/LLDB.h>
#include <windows.h>
#include <iostream>

using namespace lldb;

int main() {
  SBDebugger::Initialize();
  auto debugger = SBDebugger::Create(true);
  debugger.SetAsync(false);

  auto const appPath = R"(TestApp.exe)";  // Path to the program being debugged
  auto target = debugger.CreateTarget(appPath);

  auto breakpoint = target.BreakpointCreateByLocation("Main.cpp", 5);  // Breakpoint location in the program being debugged

  auto process = target.LaunchSimple(nullptr, nullptr, nullptr);

  while (true) {
    process.Continue();
    auto const count = breakpoint.GetHitCount();
    if (count % 100 == 0) {
      std::cout << count << " ";  // We just print the number of times the breakpoint was hit every 100 times
    }
  }

  SBDebugger::Terminate();
  return 0;
}

If you run the second program, then after a while, from a few seconds to a couple of minutes, both programs hang. This is a very important case for a debugger I am developing, in which a large number of breakpoint hits need to be skipped according to certain rules. And this error blocks further work.

llvmbot commented 2 years ago

@llvm/issue-subscribers-lldb