xref: /llvm-project/lldb/test/API/functionalities/load_after_attach/main.cpp (revision 11a09692ad960a8e547f05f070fe8b24664a4e24)
1 #include "dylib.h"
2 #include <cassert>
3 #include <cstdio>
4 #include <thread>
5 #include <chrono>
6 #include <fstream>
7 
main(int argc,char * argv[])8 int main(int argc, char* argv[]) {
9   lldb_enable_attach();
10   std::ofstream(argv[1]).close();
11 
12   // Wait until debugger is attached.
13   int main_thread_continue = 0;
14   int i = 0;
15   int timeout = 10;
16   for (i = 0; i < timeout; i++) {
17     std::this_thread::sleep_for(std::chrono::seconds(1));  // break here
18     if (main_thread_continue) {
19       break;
20     }
21   }
22   assert(i != timeout && "timed out waiting for debugger");
23 
24   // dlopen the 'liblib_b.so' shared library.
25   void* dylib_handle = dylib_open("lib_b");
26   assert(dylib_handle && "dlopen failed");
27 
28   return i; // break after dlopen
29 }
30