1 #include <chrono> 2 #include <cstdio> 3 #include <fstream> 4 #include <string> 5 #include <thread> 6 7 volatile bool wait_for_attach = true; 8 handle_attach(char * sync_file_path)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(sync_file_path); 16 } 17 18 while (wait_for_attach) 19 std::this_thread::sleep_for(std::chrono::milliseconds(10)); 20 } 21 main(int argc,char ** args)22int main(int argc, char **args) { 23 if (argc == 2) 24 handle_attach(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(std::string(args[0]) + ".side_effect"); 32 return 0; 33 } 34