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