Skip to content

Commit

Permalink
gdb: Correctly support multiprocessing for reporting threads.
Browse files Browse the repository at this point in the history
Fixes ida not displaying any threads.
  • Loading branch information
galli-leo committed Apr 29, 2019
1 parent 4361515 commit e6fde68
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -3,3 +3,4 @@ build/
/.vs
/twib/.vs
/twib/CMakeSettings.json
.vscode
26 changes: 20 additions & 6 deletions twib/tool/GdbStub.cpp
Expand Up @@ -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);
Expand Down Expand Up @@ -565,6 +571,10 @@ void GdbStub::QueryGetSupported(util::Buffer &packet) {
} else {
is_first = false;
}

if (feature == "multiprocess+") {
multi_process = true;
}

response.Write(feature);
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions twib/tool/GdbStub.hpp
Expand Up @@ -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();

Expand Down

0 comments on commit e6fde68

Please sign in to comment.