Skip to content

Commit 3e3c25e

Browse files
committed
Remove dead code, redundant checks, C++20 feature and fix Python API consistency issues
1 parent d93565f commit 3e3c25e

6 files changed

Lines changed: 8 additions & 32 deletions

File tree

api/python/debuggercontroller.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ def __eq__(self, other):
382382
if not isinstance(other, self.__class__):
383383
return NotImplemented
384384
return self.module == other.module and self.offset == other.offset and self.address == other.address \
385-
and self.enabled == other.enabled and self.condition == other.condition
385+
and self.enabled == other.enabled
386386

387387
def __ne__(self, other):
388388
if not isinstance(other, self.__class__):
@@ -2161,9 +2161,9 @@ def set_breakpoint_condition(self, address, condition: str) -> bool:
21612161
:return: True if successful, False otherwise
21622162
"""
21632163
if isinstance(address, int):
2164-
return dbgcore.BNDebuggerSetBreakpointConditionAbsolute(self.handle, address, condition.encode('utf-8') if condition else None)
2164+
return dbgcore.BNDebuggerSetBreakpointConditionAbsolute(self.handle, address, condition)
21652165
elif isinstance(address, ModuleNameAndOffset):
2166-
return dbgcore.BNDebuggerSetBreakpointConditionRelative(self.handle, address.module.encode('utf-8'), address.offset, condition.encode('utf-8') if condition else None)
2166+
return dbgcore.BNDebuggerSetBreakpointConditionRelative(self.handle, address.module, address.offset, condition)
21672167
else:
21682168
raise NotImplementedError
21692169

@@ -2177,7 +2177,7 @@ def get_breakpoint_condition(self, address) -> str:
21772177
if isinstance(address, int):
21782178
result = dbgcore.BNDebuggerGetBreakpointConditionAbsolute(self.handle, address)
21792179
elif isinstance(address, ModuleNameAndOffset):
2180-
result = dbgcore.BNDebuggerGetBreakpointConditionRelative(self.handle, address.module.encode('utf-8'), address.offset)
2180+
result = dbgcore.BNDebuggerGetBreakpointConditionRelative(self.handle, address.module, address.offset)
21812181
else:
21822182
raise NotImplementedError
21832183

core/debuggercontroller.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2458,9 +2458,6 @@ bool DebuggerController::EvaluateBreakpointCondition(uint64_t address)
24582458
return true; // no condition means always break
24592459

24602460
const std::string condition = breakpoints->GetConditionAbsolute(address);
2461-
if (condition.empty())
2462-
return true;
2463-
24642461
uint64_t result = 0;
24652462
std::string errorString;
24662463

core/debuggercontroller.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ namespace BinaryNinjaDebugger {
8585
// this does not change even if we add the debugger memory region. In the future, this should be provided by
8686
// the binary view -- we will no longer need to track it ourselves
8787
uint64_t m_viewStart;
88-
// Original file base address before any rebasing - used for file address lookups
88+
// Preserves original file base before rebasing - never updated, used for file VA to offset conversion
8989
uint64_t m_originalFileBase;
9090

9191
// inline static std::vector<DbgRef<DebuggerController>> g_debuggerControllers;

core/debuggerstate.cpp

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ limitations under the License.
2727
#include "debugadapter.h"
2828
#include "debuggercontroller.h"
2929

30-
#include <ranges>
31-
3230
using namespace BinaryNinja;
3331
using namespace std;
3432
using namespace BinaryNinjaDebugger;
@@ -747,7 +745,7 @@ std::optional<ModuleNameAndOffset> DebuggerBreakpoints::FindConditionKey(const M
747745
// absolute address comparison (handles module name differences)
748746
// assumes conditions are stored with valid, resolvable module names
749747
const uint64_t targetAbsolute = m_state->GetModules()->RelativeAddressToAbsolute(address);
750-
for (const auto& key : m_conditions | views::keys)
748+
for (const auto& [key, _] : m_conditions)
751749
{
752750
if (const uint64_t conditionAbsolute = m_state->GetModules()->RelativeAddressToAbsolute(key);
753751
conditionAbsolute == targetAbsolute)
@@ -763,7 +761,7 @@ std::optional<ModuleNameAndOffset> DebuggerBreakpoints::FindConditionKey(const M
763761
{
764762
const uint64_t fileOffset = address.offset - originalBase;
765763
const std::string& mainFile = m_state->GetController()->GetData()->GetFile()->GetOriginalFilename();
766-
for (const auto& key : m_conditions | views::keys)
764+
for (const auto& [key, _] : m_conditions)
767765
{
768766
if (key.offset == fileOffset && DebugModule::IsSameBaseModule(mainFile, key.module))
769767
return key;
@@ -805,23 +803,6 @@ bool DebuggerBreakpoints::HasConditionOffset(const ModuleNameAndOffset& address)
805803
}
806804

807805

808-
void DebuggerBreakpoints::ClearConditionAbsolute(const uint64_t address)
809-
{
810-
const ModuleNameAndOffset info = m_state->GetModules()->AbsoluteAddressToRelative(address);
811-
ClearConditionOffset(info);
812-
}
813-
814-
815-
void DebuggerBreakpoints::ClearConditionOffset(const ModuleNameAndOffset& address)
816-
{
817-
if (const auto key = FindConditionKey(address))
818-
{
819-
m_conditions.erase(*key);
820-
SerializeMetadata();
821-
}
822-
}
823-
824-
825806
void DebuggerBreakpoints::SerializeMetadata()
826807
{
827808
// TODO: who should free these Metadata objects?

core/debuggerstate.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@ namespace BinaryNinjaDebugger {
111111
std::string GetConditionOffset(const ModuleNameAndOffset& address);
112112
bool HasConditionAbsolute(uint64_t address);
113113
bool HasConditionOffset(const ModuleNameAndOffset& address);
114-
void ClearConditionAbsolute(uint64_t address);
115-
void ClearConditionOffset(const ModuleNameAndOffset& address);
116114

117115
private:
118116
// Helper to find the actual key in m_conditions matching the given address,

core/ffi.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,7 @@ char* BNDebuggerGetBreakpointConditionRelative(BNDebuggerController* controller,
991991

992992
uint64_t BNDebuggerRelativeAddressToAbsolute(BNDebuggerController* controller, const char* module, uint64_t offset)
993993
{
994-
const DebuggerState* state = controller->object->GetState();
994+
DebuggerState* state = controller->object->GetState();
995995
if (!state)
996996
return 0;
997997

0 commit comments

Comments
 (0)