Skip to content

Commit 8bc88f8

Browse files
authored
Fix multiple bugs: Python FFI mismatches, mutex leak, thread state, double notify, and misc (#1026)
1 parent aaba3d4 commit 8bc88f8

File tree

6 files changed

+27
-17
lines changed

6 files changed

+27
-17
lines changed

api/python/debuggercontroller.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def __ne__(self, other):
8383
return not (self == other)
8484

8585
def __hash__(self):
86-
return hash((self.pid, self.pid))
86+
return hash((self.pid, self.name))
8787

8888
def __setattr__(self, name, value):
8989
try:
@@ -1586,7 +1586,7 @@ def detach(self) -> None:
15861586
"""
15871587
Detach the target, and let it execute on its own.
15881588
"""
1589-
dbgcore.BNDebuggerQuit(self.handle)
1589+
dbgcore.BNDebuggerDetach(self.handle)
15901590

15911591
def pause(self) -> None:
15921592
"""
@@ -2072,12 +2072,12 @@ def pid_attach(self) -> int:
20722072
20732073
``pid_attach`` is only useful for connecting to a running process using PID.
20742074
2075-
:getter: returns the remote port
2076-
:setter: sets the remote port
2075+
:getter: returns the PID to attach to
2076+
:setter: sets the PID to attach to
20772077
"""
20782078
return dbgcore.BNDebuggerGetPIDAttach(self.handle)
20792079

2080-
@remote_port.setter
2080+
@pid_attach.setter
20812081
def pid_attach(self, pid: int) -> None:
20822082
dbgcore.BNDebuggerSetPIDAttach(self.handle, pid)
20832083

@@ -2494,7 +2494,9 @@ def set_adapter_property(self, name: Union[str, bytes], value: binaryninja.metad
24942494
return dbgcore.BNDebuggerSetAdapterProperty(self.handle, name, handle)
24952495

24962496
def get_addr_info(self, addr: int):
2497-
return dbgcore.BNDebuggerGetAddressInformation(self.handle, addr)
2497+
buffer = addr.to_bytes(64, byteorder='little', signed=False)
2498+
c_buffer = (ctypes.c_ubyte * 64)(*buffer)
2499+
return dbgcore.BNDebuggerGetAddressInformation(self.handle, c_buffer)
24982500

24992501
@property
25002502
def is_first_launch(self):

core/adapters/dbgengttdadapter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ bool DbgEngTTDAdapter::Start()
116116

117117
auto handle = GetModuleHandleA("dbgeng.dll");
118118
if (handle == nullptr)
119-
false;
119+
return false;
120120

121121
// HRESULT DebugCreate(
122122
// [in] REFIID InterfaceId,

core/adapters/gdbadapter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1376,7 +1376,7 @@ std::string GdbAdapter::InvokeBackendCommand(const std::string& command)
13761376
if (command.substr(0, 4) == "mon ")
13771377
return RunMonitorCommand(command.substr(4));
13781378
else if (command.substr(0, 8) == "monitor ")
1379-
return RunMonitorCommand(command.substr(4));
1379+
return RunMonitorCommand(command.substr(8));
13801380

13811381
auto reply = this->m_rspConnector->TransmitAndReceive(RspData(command));
13821382
return reply.AsString();

core/debuggercontroller.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,7 +1259,6 @@ DebugStopReason DebuggerController::RunToAndWaitInternal(const std::vector<uint6
12591259
}
12601260
}
12611261

1262-
NotifyStopped(reason);
12631262
return reason;
12641263
}
12651264

@@ -1286,7 +1285,6 @@ DebugStopReason DebuggerController::RunToReverseAndWaitInternal(const std::vecto
12861285
}
12871286
}
12881287

1289-
NotifyStopped(reason);
12901288
return reason;
12911289
}
12921290

@@ -1530,7 +1528,11 @@ void DebuggerController::DetachAndWait()
15301528
locked = true;
15311529

15321530
if (!m_state->IsConnected())
1531+
{
1532+
if (locked)
1533+
m_targetControlMutex.unlock();
15331534
return;
1535+
}
15341536

15351537
// TODO: return whether the operation is successful
15361538
ExecuteAdapterAndWait(DebugAdapterDetach);
@@ -1559,7 +1561,11 @@ void DebuggerController::QuitAndWait()
15591561
locked = true;
15601562

15611563
if (!m_state->IsConnected())
1564+
{
1565+
if (locked)
1566+
m_targetControlMutex.unlock();
15621567
return;
1568+
}
15631569

15641570
if (m_state->IsRunning())
15651571
{

core/debuggerstate.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -330,12 +330,13 @@ bool DebuggerThreads::SuspendThread(std::uint32_t tid)
330330
if (!adapter)
331331
return false;
332332

333-
auto threads = GetAllThreads();
334-
auto thread = std::find_if(threads.begin(), threads.end(), [&](DebugThread const& t) {
333+
std::unique_lock lock(m_threadsMutex);
334+
335+
auto thread = std::find_if(m_threads.begin(), m_threads.end(), [&](DebugThread const& t) {
335336
return t.m_tid == tid;
336337
});
337338

338-
if (thread == threads.end())
339+
if (thread == m_threads.end())
339340
return false;
340341

341342

@@ -360,12 +361,13 @@ bool DebuggerThreads::ResumeThread(std::uint32_t tid)
360361
if (!adapter)
361362
return false;
362363

363-
auto threads = GetAllThreads();
364-
auto thread = std::find_if(threads.begin(), threads.end(), [&](DebugThread const& t) {
364+
std::unique_lock lock(m_threadsMutex);
365+
366+
auto thread = std::find_if(m_threads.begin(), m_threads.end(), [&](DebugThread const& t) {
365367
return t.m_tid == tid;
366368
});
367369

368-
if (thread == threads.end())
370+
if (thread == m_threads.end())
369371
return false;
370372

371373
if (!thread->m_isFrozen)

ui/threadframes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class FrameItem
9999
uint64_t m_fp {};
100100

101101
QList<FrameItem*> m_childItems;
102-
FrameItem* m_parentItem;
102+
FrameItem* m_parentItem {nullptr};
103103
};
104104

105105
Q_DECLARE_METATYPE(FrameItem);

0 commit comments

Comments
 (0)