From 14897d0f998d664660cf7c371518e9f6de6133ba Mon Sep 17 00:00:00 2001 From: Jan Kratochvil Date: Sat, 7 Sep 2019 22:06:22 +0200 Subject: [PATCH] Add command-line parameter -p|--pid. --- src/LLGDBMain.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/LLGDBMain.cpp b/src/LLGDBMain.cpp index 39dac35..506fe50 100644 --- a/src/LLGDBMain.cpp +++ b/src/LLGDBMain.cpp @@ -345,6 +345,7 @@ static char *completion_entry_function(const char *text, int matches) { static std::deque opt_iex, opt_ex; static std::optional opt_exec, opt_core; +static std::optional opt_pid; static std::vector opt_args; std::string string_quote(std::string &&str) { @@ -376,6 +377,11 @@ std::optional next_arg() { } 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(); @@ -391,6 +397,10 @@ int main(int argc, char **argv) { 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); @@ -410,8 +420,14 @@ int main(int argc, char **argv) { 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 -- 1.8.3.1