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