Skip to content

Commit 3229306

Browse files
committed
Fix compilation
1 parent e99b629 commit 3229306

File tree

4 files changed

+54
-56
lines changed

4 files changed

+54
-56
lines changed

core/debuggercontroller.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ bool DebuggerController::SetBreakpointCondition(uint64_t address, const std::str
226226
if (result)
227227
{
228228
DebuggerEvent event;
229-
event.type = AbsoluteBreakpointConditionChangedEvent;
229+
event.type = BreakpointChangedEvent;
230230
event.data.absoluteAddress = address;
231231
PostDebuggerEvent(event);
232232
}
@@ -240,7 +240,7 @@ bool DebuggerController::SetBreakpointCondition(const ModuleNameAndOffset& addre
240240
if (result)
241241
{
242242
DebuggerEvent event;
243-
event.type = RelativeBreakpointConditionChangedEvent;
243+
event.type = BreakpointChangedEvent;
244244
event.data.relativeAddress = address;
245245
PostDebuggerEvent(event);
246246
}

core/debuggerstate.cpp

Lines changed: 38 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -527,15 +527,15 @@ std::vector<BreakpointEntry>::iterator DebuggerBreakpoints::FindBreakpoint(const
527527
const uint64_t targetAbsolute = m_state->GetModules()->RelativeAddressToAbsolute(address);
528528
for (auto it = m_breakpoints.begin(); it != m_breakpoints.end(); ++it)
529529
{
530-
if (m_state->GetModules()->RelativeAddressToAbsolute(it->address) == targetAbsolute)
530+
if (m_state->GetModules()->RelativeAddressToAbsolute(it->location) == targetAbsolute)
531531
return it;
532532
}
533533
}
534534
else
535535
{
536536
for (auto it = m_breakpoints.begin(); it != m_breakpoints.end(); ++it)
537537
{
538-
if (it->address == address)
538+
if (it->location == address)
539539
return it;
540540
}
541541
}
@@ -611,7 +611,7 @@ bool DebuggerBreakpoints::RemoveOffset(const ModuleNameAndOffset& address)
611611
if (it == m_breakpoints.end())
612612
return false;
613613

614-
ModuleNameAndOffset actualAddr = it->address;
614+
ModuleNameAndOffset actualAddr = it->location;
615615
m_breakpoints.erase(it);
616616
SerializeMetadata();
617617

@@ -642,7 +642,7 @@ bool DebuggerBreakpoints::EnableOffset(const ModuleNameAndOffset& address)
642642

643643
if (m_state->GetAdapter() && m_state->IsConnected())
644644
{
645-
uint64_t remoteAddress = m_state->GetModules()->RelativeAddressToAbsolute(it->address);
645+
uint64_t remoteAddress = m_state->GetModules()->RelativeAddressToAbsolute(it->location);
646646
m_state->GetAdapter()->AddBreakpoint(remoteAddress);
647647
}
648648
return true;
@@ -667,7 +667,7 @@ bool DebuggerBreakpoints::DisableOffset(const ModuleNameAndOffset& address)
667667

668668
if (m_state->GetAdapter() && m_state->IsConnected())
669669
{
670-
uint64_t remoteAddress = m_state->GetModules()->RelativeAddressToAbsolute(it->address);
670+
uint64_t remoteAddress = m_state->GetModules()->RelativeAddressToAbsolute(it->location);
671671
m_state->GetAdapter()->RemoveBreakpoint(remoteAddress);
672672
}
673673
return true;
@@ -704,9 +704,8 @@ bool DebuggerBreakpoints::ContainsAbsolute(uint64_t address)
704704

705705
for (const auto& bp : m_breakpoints)
706706
{
707-
if (m_state->GetModules()->RelativeAddressToAbsolute(bp.address) == address)
707+
if (m_state->GetModules()->RelativeAddressToAbsolute(bp.location) == address)
708708
return true;
709-
}
710709
}
711710
return false;
712711
}
@@ -735,7 +734,7 @@ std::string DebuggerBreakpoints::GetConditionAbsolute(const uint64_t address)
735734
{
736735
for (const auto& bp : m_breakpoints)
737736
{
738-
if (m_state->GetModules()->RelativeAddressToAbsolute(bp.address) == address)
737+
if (m_state->GetModules()->RelativeAddressToAbsolute(bp.location) == address)
739738
return bp.condition;
740739
}
741740
return "";
@@ -753,7 +752,7 @@ bool DebuggerBreakpoints::HasConditionAbsolute(const uint64_t address)
753752
{
754753
for (const auto& bp : m_breakpoints)
755754
{
756-
if (m_state->GetModules()->RelativeAddressToAbsolute(bp.address) == address)
755+
if (m_state->GetModules()->RelativeAddressToAbsolute(bp.location) == address)
757756
return !bp.condition.empty();
758757
}
759758
return false;
@@ -793,8 +792,13 @@ bool DebuggerBreakpoints::AddHardwareBreakpoint(uint64_t address, DebugBreakpoin
793792
// Add to internal storage (either adapter succeeded, or no adapter connected yet)
794793
// Convert absolute address to module+offset for ASLR-safe storage (like AddAbsolute does for software breakpoints)
795794
ModuleNameAndOffset info = m_state->GetModules()->AbsoluteAddressToRelative(address);
796-
BreakpointInfo bp(info, type, size);
795+
BreakpointEntry bp;
796+
bp.location = info;
797+
bp.enabled = true;
798+
bp.type = type;
799+
bp.size = size;
797800
bp.address = address;
801+
bp.isRelative = true;
798802
m_breakpoints.push_back(bp);
799803
SerializeMetadata();
800804

@@ -844,7 +848,7 @@ bool DebuggerBreakpoints::ContainsHardwareBreakpoint(uint64_t address, DebugBrea
844848
{
845849
// Similar to ContainsAbsolute, we need to handle both relative and absolute hardware breakpoints
846850
// For relative hardware breakpoints, convert to absolute and compare
847-
for (const BreakpointInfo& breakpoint : m_breakpoints)
851+
for (const BreakpointEntry& breakpoint : m_breakpoints)
848852
{
849853
if (breakpoint.IsHardware() && breakpoint.type == type && breakpoint.size == size)
850854
{
@@ -959,7 +963,12 @@ bool DebuggerBreakpoints::AddHardwareBreakpoint(const ModuleNameAndOffset& locat
959963
}
960964

961965
// Add to internal storage (either adapter succeeded, or no adapter connected yet)
962-
BreakpointInfo bp(location, type, size); // Uses the constructor for module+offset
966+
BreakpointEntry bp;
967+
bp.location = location;
968+
bp.enabled = true;
969+
bp.type = type;
970+
bp.size = size;
971+
bp.isRelative = true;
963972
m_breakpoints.push_back(bp);
964973
SerializeMetadata();
965974

@@ -969,10 +978,10 @@ bool DebuggerBreakpoints::AddHardwareBreakpoint(const ModuleNameAndOffset& locat
969978

970979
bool DebuggerBreakpoints::RemoveHardwareBreakpoint(const ModuleNameAndOffset& location, DebugBreakpointType type, size_t size)
971980
{
972-
BreakpointInfo toFind(location, type, size);
973-
974981
// Remove from our list
975-
auto iter = std::find(m_breakpoints.begin(), m_breakpoints.end(), toFind);
982+
auto iter = std::find_if(m_breakpoints.begin(), m_breakpoints.end(), [&](const BreakpointEntry& bp) {
983+
return bp.IsHardware() && bp.location == location && bp.type == type && bp.size == size;
984+
});
976985
if (iter != m_breakpoints.end())
977986
{
978987
m_breakpoints.erase(iter);
@@ -992,8 +1001,9 @@ bool DebuggerBreakpoints::RemoveHardwareBreakpoint(const ModuleNameAndOffset& lo
9921001

9931002
bool DebuggerBreakpoints::ContainsHardwareBreakpoint(const ModuleNameAndOffset& location, DebugBreakpointType type, size_t size)
9941003
{
995-
BreakpointInfo toFind(location, type, size);
996-
return std::find(m_breakpoints.begin(), m_breakpoints.end(), toFind) != m_breakpoints.end();
1004+
return std::find_if(m_breakpoints.begin(), m_breakpoints.end(), [&](const BreakpointEntry& bp) {
1005+
return bp.IsHardware() && bp.location == location && bp.type == type && bp.size == size;
1006+
}) != m_breakpoints.end();
9971007
}
9981008

9991009

@@ -1003,8 +1013,9 @@ bool DebuggerBreakpoints::EnableHardwareBreakpoint(const ModuleNameAndOffset& lo
10031013
return false;
10041014

10051015
// Find and enable the hardware breakpoint
1006-
BreakpointInfo toFind(location, type, size);
1007-
auto iter = std::find(m_breakpoints.begin(), m_breakpoints.end(), toFind);
1016+
auto iter = std::find_if(m_breakpoints.begin(), m_breakpoints.end(), [&](const BreakpointEntry& bp) {
1017+
return bp.IsHardware() && bp.location == location && bp.type == type && bp.size == size;
1018+
});
10081019
if (iter != m_breakpoints.end())
10091020
{
10101021
iter->enabled = true;
@@ -1027,8 +1038,9 @@ bool DebuggerBreakpoints::DisableHardwareBreakpoint(const ModuleNameAndOffset& l
10271038
return false;
10281039

10291040
// Find and disable the hardware breakpoint
1030-
BreakpointInfo toFind(location, type, size);
1031-
auto iter = std::find(m_breakpoints.begin(), m_breakpoints.end(), toFind);
1041+
auto iter = std::find_if(m_breakpoints.begin(), m_breakpoints.end(), [&](const BreakpointEntry& bp) {
1042+
return bp.IsHardware() && bp.location == location && bp.type == type && bp.size == size;
1043+
});
10321044
if (iter != m_breakpoints.end())
10331045
{
10341046
iter->enabled = false;
@@ -1045,28 +1057,14 @@ bool DebuggerBreakpoints::DisableHardwareBreakpoint(const ModuleNameAndOffset& l
10451057
}
10461058

10471059

1048-
std::vector<ModuleNameAndOffset> DebuggerBreakpoints::GetSoftwareBreakpointList() const
1049-
{
1050-
std::vector<ModuleNameAndOffset> result;
1051-
for (const BreakpointInfo& bp : m_breakpoints)
1052-
{
1053-
if (bp.IsSoftware())
1054-
{
1055-
result.push_back(bp.location);
1056-
}
1057-
}
1058-
return result;
1059-
}
1060-
1061-
10621060
void DebuggerBreakpoints::SerializeMetadata()
10631061
{
10641062
std::vector<Ref<Metadata>> breakpoints;
10651063
for (const auto& bp : m_breakpoints)
10661064
{
10671065
std::map<std::string, Ref<Metadata>> info;
1068-
info["module"] = new Metadata(bp.address.module);
1069-
info["offset"] = new Metadata(bp.address.offset);
1066+
info["module"] = new Metadata(bp.location.module);
1067+
info["offset"] = new Metadata(bp.location.offset);
10701068
info["enabled"] = new Metadata(bp.enabled);
10711069

10721070
if (!bp.condition.empty())
@@ -1099,8 +1097,8 @@ void DebuggerBreakpoints::UnserializedMetadata()
10991097
continue;
11001098

11011099
BreakpointEntry bp;
1102-
bp.address.module = info["module"]->GetString();
1103-
bp.address.offset = info["offset"]->GetUnsignedInteger();
1100+
bp.location.module = info["module"]->GetString();
1101+
bp.location.offset = info["offset"]->GetUnsignedInteger();
11041102
bp.enabled = (info["enabled"] && info["enabled"]->IsBoolean()) ? info["enabled"]->GetBoolean() : true;
11051103
bp.condition = (info["condition"] && info["condition"]->IsString()) ? info["condition"]->GetString() : "";
11061104

@@ -1114,7 +1112,7 @@ void DebuggerBreakpoints::Apply()
11141112
if (!m_state->GetAdapter())
11151113
return;
11161114

1117-
for (const BreakpointInfo& bp : m_breakpoints)
1115+
for (const auto& bp : m_breakpoints)
11181116
{
11191117
if (bp.IsSoftware())
11201118
{

core/debuggerstate.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,14 @@ namespace BinaryNinjaDebugger {
8484
bool enabled = true;
8585
std::string condition;
8686

87-
uint64_t address; // Absolute address (for absolute addressing or resolved relative)
88-
DebugBreakpointType type; // Breakpoint type (Software, HardwareExecute, etc.)
89-
size_t size; // Size for hardware watchpoints
90-
bool isRelative; // True if using module+offset, false if using absolute address
87+
uint64_t address = 0; // Absolute address (for absolute addressing or resolved relative)
88+
DebugBreakpointType type = SoftwareBreakpoint; // Breakpoint type (Software, HardwareExecute, etc.)
89+
size_t size = 1; // Size for hardware watchpoints
90+
bool isRelative = true; // True if using module+offset, false if using absolute address
91+
92+
// Helper methods
93+
bool IsSoftware() const { return type == SoftwareBreakpoint; }
94+
bool IsHardware() const { return type != SoftwareBreakpoint; }
9195
};
9296

9397
class DebuggerBreakpoints
@@ -122,16 +126,7 @@ namespace BinaryNinjaDebugger {
122126
bool HasConditionAbsolute(uint64_t address);
123127
bool HasConditionOffset(const ModuleNameAndOffset& address);
124128

125-
private:
126-
// Find breakpoint by address, handling module name differences via absolute address comparison
127-
std::vector<BreakpointEntry>::iterator FindBreakpoint(const ModuleNameAndOffset& address);
128-
std::vector<BreakpointEntry>::const_iterator FindBreakpoint(const ModuleNameAndOffset& address) const;
129-
130-
// Get only software breakpoints (for backward compatibility)
131-
std::vector<ModuleNameAndOffset> GetSoftwareBreakpointList() const;
132-
133129
// Hardware breakpoint methods
134-
// Hardware breakpoint methods - absolute address
135130
bool AddHardwareBreakpoint(uint64_t address, DebugBreakpointType type, size_t size);
136131
bool RemoveHardwareBreakpoint(uint64_t address, DebugBreakpointType type, size_t size);
137132
bool EnableHardwareBreakpoint(uint64_t address, DebugBreakpointType type, size_t size);
@@ -144,6 +139,11 @@ namespace BinaryNinjaDebugger {
144139
bool EnableHardwareBreakpoint(const ModuleNameAndOffset& location, DebugBreakpointType type, size_t size);
145140
bool DisableHardwareBreakpoint(const ModuleNameAndOffset& location, DebugBreakpointType type, size_t size);
146141
bool ContainsHardwareBreakpoint(const ModuleNameAndOffset& location, DebugBreakpointType type, size_t size);
142+
143+
private:
144+
// Find breakpoint by address, handling module name differences via absolute address comparison
145+
std::vector<BreakpointEntry>::iterator FindBreakpoint(const ModuleNameAndOffset& address);
146+
std::vector<BreakpointEntry>::const_iterator FindBreakpoint(const ModuleNameAndOffset& address) const;
147147
};
148148

149149

core/ffi.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,7 @@ BNDebugBreakpoint* BNDebuggerGetBreakpoints(BNDebuggerController* controller, si
825825
result[i].enabled = breakpoints[i].enabled;
826826
result[i].type = (BNDebugBreakpointType)breakpoints[i].type;
827827
result[i].size = breakpoints[i].size;
828-
result[i].condition = breakpoints[i].condition.empty() ? nullptr : BNDebuggerAllocString(bp.condition.c_str());
828+
result[i].condition = breakpoints[i].condition.empty() ? nullptr : BNDebuggerAllocString(breakpoints[i].condition.c_str());
829829
}
830830
return result;
831831
}

0 commit comments

Comments
 (0)