From 059cb43018edd1e2ae1c4391fc0c0b80d2c0e4ff Mon Sep 17 00:00:00 2001 From: Igor Kulaychuk Date: Sun, 16 Jul 2017 05:31:15 +0300 Subject: [PATCH] Add target-attach and target-detach commands --- src/debug/netcoredbg/commands.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/debug/netcoredbg/commands.cpp b/src/debug/netcoredbg/commands.cpp index ec06334..a9eb4c0 100644 --- a/src/debug/netcoredbg/commands.cpp +++ b/src/debug/netcoredbg/commands.cpp @@ -26,7 +26,9 @@ HRESULT PrintBreakpoint(ULONG32 id, std::string &output); // Frames HRESULT GetFrameAt(ICorDebugThread *pThread, int level, ICorDebugFrame **ppFrame); +HRESULT AttachToProcess(int pid); void TerminateProcess(); +HRESULT DetachProcess(); void _out_printf(const char *fmt, ...) __attribute__((format (printf, 1, 2))); @@ -215,6 +217,24 @@ static std::unordered_map commands { { "exec-step", std::bind(StepCommand, _1, _2, _3, STEP_IN) }, { "exec-next", std::bind(StepCommand, _1, _2, _3, STEP_OVER) }, { "exec-finish", std::bind(StepCommand, _1, _2, _3, STEP_OUT) }, + { "target-attach", [](ICorDebugProcess *, const std::vector &args, std::string &output) -> HRESULT { + HRESULT Status; + if (args.size() != 1) + { + output = "Command requires an argument"; + return E_INVALIDARG; + } + bool ok; + int pid = ParseInt(args.at(0), ok); + if (!ok) return E_INVALIDARG; + IfFailRet(AttachToProcess(pid)); + // TODO: print succeessful result + return S_OK; + }}, + { "target-detach", [](ICorDebugProcess *, const std::vector &, std::string &output) -> HRESULT { + DetachProcess(); + return S_OK; + }}, { "stack-list-frames", [](ICorDebugProcess *pProcess, const std::vector &args, std::string &output) -> HRESULT { if (!pProcess) return E_FAIL; HRESULT Status; -- 2.7.4