Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lldb / test / API / api / multithreaded / test_breakpoint_location_callback.cpp.template
blob0b0dc5652e850131cdeb3c424120d9aea3dd01b8
2 // LLDB C++ API Test: verify that the function registered with
3 // SBBreakpoint.SetCallback() is invoked when a breakpoint is hit.
5 #include <mutex>
6 #include <iostream>
7 #include <vector>
8 #include <string>
10 %include_SB_APIs%
12 #include "common.h"
14 using namespace std;
15 using namespace lldb;
17 mutex g_mutex;
18 condition_variable g_condition;
19 int g_breakpoint_hit_count = 0;
21 bool BPCallback (void *baton,
22                  SBProcess &process,
23                  SBThread &thread,
24                  SBBreakpointLocation &location) {
25   lock_guard<mutex> lock(g_mutex);
26   g_breakpoint_hit_count += 1;
27   g_condition.notify_all();
28   return true;
31 void test(SBDebugger &dbg, vector<string> args) {
32   dbg.SetAsync(false);
33   SBTarget target = dbg.CreateTarget(args.at(0).c_str());
34   if (!target.IsValid()) throw Exception("invalid target");
36   SBBreakpoint breakpoint = target.BreakpointCreateByName("next");
37   if (!breakpoint.IsValid()) throw Exception("invalid breakpoint");
39   if(breakpoint.GetNumLocations() != 1) throw Exception("unexpected amount of breakpoint locations");
40   SBBreakpointLocation breakpoint_location = breakpoint.GetLocationAtIndex(0);
41   breakpoint_location.SetCallback(BPCallback, 0);
43   std::unique_ptr<char> working_dir(get_working_dir());
44   SBProcess process = target.LaunchSimple (0, 0, working_dir.get());
46   {
47     unique_lock<mutex> lock(g_mutex);
48     g_condition.wait_for(lock, chrono::seconds(5));
49     if (g_breakpoint_hit_count != 1)
50       throw Exception("Breakpoint hit count expected to be 1");
51   }