Skip to content

Commit f33a65a

Browse files
Copilotxusheng6
andcommitted
Add process exit detection and event handling
- Add m_exitCode member to store exit code from GDB - Parse exit-code field from stopped event when process exits - Post TargetExitedEventType event when process exits - Update ExitCode() to return stored exit code - Maintain GetModuleList() implementation for parsing info proc mappings Co-authored-by: xusheng6 <[email protected]>
1 parent 692bfdb commit f33a65a

File tree

3 files changed

+35
-5
lines changed

3 files changed

+35
-5
lines changed

_codeql_detected_source_root

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.

core/adapters/gdbmiadapter.cpp

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,38 @@ void GdbMiAdapter::AsyncRecordHandler(const MiRecord& record)
197197
// Update target state BEFORE posting events
198198
m_targetRunningAtomic.store(false, std::memory_order_release);
199199

200-
// Kick a background refresh so we don’t block the reader
201-
ScheduleStateRefresh();
202-
203-
m_eventCV.notify_all();
200+
// Check if the process has exited
201+
if (m_lastStopReason == ProcessExited)
202+
{
203+
// Parse exit code if available
204+
if (value.Exists("exit-code"))
205+
{
206+
try {
207+
m_exitCode = std::stoull(value["exit-code"].GetString(), nullptr, 0);
208+
} catch(...) {
209+
LogWarn("Failed to parse exit code");
210+
m_exitCode = 0;
211+
}
212+
}
213+
else
214+
{
215+
m_exitCode = 0;
216+
}
217+
218+
// Post target exited event
219+
DebuggerEvent dbgevt;
220+
dbgevt.type = TargetExitedEventType;
221+
dbgevt.data.exitData.exitCode = m_exitCode;
222+
PostDebuggerEvent(dbgevt);
223+
224+
m_eventCV.notify_all();
225+
}
226+
else
227+
{
228+
// Normal stop - kick a background refresh so we don't block the reader
229+
ScheduleStateRefresh();
230+
m_eventCV.notify_all();
231+
}
204232
}
205233
else if (record.command == "running")
206234
{
@@ -987,7 +1015,7 @@ std::string GdbMiAdapter::InvokeBackendCommand(const std::string& command) {
9871015
return (result.command == "done") ? result.payload : result.command;
9881016
}
9891017

990-
uint64_t GdbMiAdapter::ExitCode() { return 0; }
1018+
uint64_t GdbMiAdapter::ExitCode() { return m_exitCode; }
9911019

9921020
DebugStopReason GdbMiAdapter::StopReason() { return m_lastStopReason; }
9931021

core/adapters/gdbmiadapter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class GdbMiAdapter : public BinaryNinjaDebugger::DebugAdapter
1515
std::vector<std::string> m_registerNames; // In GDB's order
1616
BinaryNinjaDebugger::DebugStopReason m_lastStopReason;
1717
std::atomic<bool> m_targetRunningAtomic{false};
18+
uint64_t m_exitCode = 0;
1819

1920
std::mutex m_eventMutex;
2021
std::mutex m_gdbCommandMutex;

0 commit comments

Comments
 (0)