1#include <chrono>
2#include <cstdio>
3#include <fstream>
4#include <string>
5#include <thread>
6
7volatile bool wait_for_attach = true;
8
9void handle_attach(char *sync_file_path) {
10 lldb_enable_attach();
11
12 {
13 // Create a file to signal that this process has started up.
14 std::ofstream sync_file;
15 sync_file.open(s: sync_file_path);
16 }
17
18 while (wait_for_attach)
19 std::this_thread::sleep_for(rtime: std::chrono::milliseconds(10));
20}
21
22int main(int argc, char **args) {
23 if (argc == 2)
24 handle_attach(sync_file_path: args[1]);
25
26 // We let the binary live a little bit to see if it executed after detaching
27 // from // breakpoint
28
29 // Create a file to signal that this process has started up.
30 std::ofstream out_file; // breakpoint
31 out_file.open(s: std::string(args[0]) + ".side_effect");
32 return 0;
33}
34

source code of lldb/test/API/tools/lldb-dap/disconnect/main.cpp