Files
llvm-project/lldb/test/API/api/multithreaded/test_breakpoint_location_callback.cpp.template
Alex Langford 54840055b8 [lldb] Fix TestMultithreaded.py when libc++ symbols are present (#174664)
There are a few test cases in TestMultithreaded.py. Most of them set a
breakpoint by name on "next". There's no problem with doing that, but
one of the tests cases in particular relies on being able to grab a
specific breakpoint location corresponding to the test inferior.

If you have libc++ symbols, this test will also have breakpoint
locations for symbols named `next` in libc++. I could have changed the
test to find the correct `next` breakpoint location, but it seems easier
to give it a more uncommon name instead.
2026-01-09 13:50:56 -08:00

59 lines
1.7 KiB
Plaintext

// LLDB C++ API Test: verify that the function registered with
// SBBreakpoint.SetCallback() is invoked when a breakpoint is hit.
#include <mutex>
#include <iostream>
#include <vector>
#include <string>
%include_SB_APIs%
#include "common.h"
using namespace std;
using namespace lldb;
mutex g_mutex;
condition_variable g_condition;
int g_breakpoint_hit_count = 0;
bool BPCallback (void *baton,
SBProcess &process,
SBThread &thread,
SBBreakpointLocation &location) {
lock_guard<mutex> lock(g_mutex);
g_breakpoint_hit_count += 1;
g_condition.notify_all();
return true;
}
void test(SBDebugger &dbg, vector<string> args) {
dbg.SetAsync(false);
SBTarget target = dbg.CreateTarget(args.at(0).c_str());
if (!target.IsValid()) throw Exception("invalid target");
// Only look for the breakpoint in the main module.
SBFileSpec main_module(args.at(0).c_str(), /*resolve=*/true);
SBFileSpecList module_list;
module_list.Append(main_module);
SBBreakpoint breakpoint = target.BreakpointCreateByName(
"next", eFunctionNameTypeFull, module_list, SBFileSpecList());
if (!breakpoint.IsValid()) throw Exception("invalid breakpoint");
if(breakpoint.GetNumLocations() != 1) throw Exception("unexpected amount of breakpoint locations");
SBBreakpointLocation breakpoint_location = breakpoint.GetLocationAtIndex(0);
breakpoint_location.SetCallback(BPCallback, 0);
std::unique_ptr<char> working_dir(get_working_dir());
SBProcess process = target.LaunchSimple (0, 0, working_dir.get());
{
unique_lock<mutex> lock(g_mutex);
g_condition.wait_for(lock, chrono::seconds(5));
if (g_breakpoint_hit_count != 1)
throw Exception("Breakpoint hit count expected to be 1");
}
}