diff --git a/.gitignore b/.gitignore index 288f613..4f531e4 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ build/ /.vs /twib/.vs /twib/CMakeSettings.json +.vscode \ No newline at end of file diff --git a/twib/tool/GdbStub.cpp b/twib/tool/GdbStub.cpp index d26bb30..5c1bcca 100644 --- a/twib/tool/GdbStub.cpp +++ b/twib/tool/GdbStub.cpp @@ -402,6 +402,12 @@ void GdbStub::HandleVAttach(util::Buffer &packet) { return; } + if(!multi_process && attached_processes.size() > 0) { + LogMessage(Error, "Already debugging a process! Make sure multiprocessing is enabled!"); + connection.RespondError(1); + return; + } + auto r = attached_processes.emplace(pid, Process(pid, itdi.OpenActiveDebugger(pid))); r.first->second.IngestEvents(*this); @@ -565,6 +571,10 @@ void GdbStub::QueryGetSupported(util::Buffer &packet) { } else { is_first = false; } + + if (feature == "multiprocess+") { + multi_process = true; + } response.Write(feature); } @@ -574,9 +584,11 @@ void GdbStub::QueryGetSupported(util::Buffer &packet) { void GdbStub::QueryGetCurrentThread(util::Buffer &packet) { util::Buffer response; - response.Write('p'); - GdbConnection::Encode(current_thread ? current_thread->process.pid : 0, 0, response); - response.Write('.'); + if (multi_process) { + response.Write('p'); + GdbConnection::Encode(current_thread ? current_thread->process.pid : 0, 0, response); + response.Write('.'); + } GdbConnection::Encode(current_thread ? current_thread->thread_id : 0, 0, response); connection.Respond(response); } @@ -610,9 +622,11 @@ void GdbStub::QueryGetSThreadInfo(util::Buffer &packet) { } else { response.Write('m'); } - response.Write('p'); - GdbConnection::Encode(thread.process.pid, 0, response); - response.Write('.'); + if (multi_process) { + response.Write('p'); + GdbConnection::Encode(thread.process.pid, 0, response); + response.Write('.'); + } GdbConnection::Encode(thread.thread_id, 0, response); has_written = true; } diff --git a/twib/tool/GdbStub.hpp b/twib/tool/GdbStub.hpp index 6abb31f..e53de13 100644 --- a/twib/tool/GdbStub.hpp +++ b/twib/tool/GdbStub.hpp @@ -106,6 +106,7 @@ class GdbStub { std::string stop_reason = "W00"; bool waiting_for_stop = false; bool has_async_wait = false; + bool multi_process = false; void Stop();