static std::deque<std::string> opt_iex, opt_ex;
static std::optional<std::string> opt_exec, opt_core;
+static std::optional<lldb::pid_t> opt_pid;
static std::vector<std::string> opt_args;
std::string string_quote(std::string &&str) {
}
return cmd;
}
+ if (opt_pid) {
+ std::string retval = (boost::format("attach %1%") % *opt_pid).str();
+ opt_pid.reset();
+ return retval;
+ }
if (!opt_ex.empty()) {
std::string retval = opt_ex.front();
opt_ex.pop_front();
for (int argi = 1; argi < argc; ++argi) {
std::string arg = argv[argi];
+ auto str_to_pid = [](const std::string &str){
+ lldb::pid_t pid_test = atoi(str.c_str());
+ return (boost::format("%1%") % pid_test).str() != str || pid_test <= 0 ? 0 : pid_test;
+ };
if (arg == "-iex") {
const char *cmd = argv[++argi];
assert(cmd);
arg = argv[argi];
opt_args.push_back(std::move(arg));
}
+ } else if (arg == "-p" || arg == "--pid") {
+ opt_pid = str_to_pid(argv[++argi]);
+ if (opt_pid == 0)
+ error(1,0,"Invalid PID: %s",argv[argi]);
} else if (!opt_exec)
opt_exec=std::move(arg);
+ else if (!opt_pid && str_to_pid(arg) > 0)
+ opt_pid = str_to_pid(arg);
else if (!opt_core)
opt_core=std::move(arg);
else