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