Skip to content

Commit

Permalink
Remove code related to the live view from the debugger
Browse files Browse the repository at this point in the history
  • Loading branch information
xusheng6 committed Jun 19, 2024
1 parent f5389dd commit 7a47a1a
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 82 deletions.
1 change: 0 additions & 1 deletion api/debuggerapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,6 @@ namespace BinaryNinjaDebuggerAPI {
static DbgRef<DebuggerController> GetController(Ref<BinaryNinja::FileMetadata> file);
static bool ControllerExists(Ref<BinaryNinja::FileMetadata> file);
void Destroy();
Ref<BinaryView> GetLiveView();
Ref<BinaryView> GetData();
void SetData(const Ref<BinaryView>& data);
Ref<Architecture> GetRemoteArchitecture();
Expand Down
9 changes: 0 additions & 9 deletions api/debuggercontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,6 @@ void DebuggerController::Destroy()
}


Ref<BinaryView> DebuggerController::GetLiveView()
{
BNBinaryView* view = BNDebuggerGetLiveView(m_object);
if (!view)
return nullptr;
return new BinaryView(view);
}


Ref<BinaryView> DebuggerController::GetData()
{
BNBinaryView* view = BNDebuggerGetData(m_object);
Expand Down
1 change: 0 additions & 1 deletion api/ffi.h
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,6 @@ extern "C"
DEBUGGER_FFI_API bool BNDebuggerControllerExists(BNBinaryView* data);
DEBUGGER_FFI_API BNDebuggerController* BNGetDebuggerControllerFromFile(BNFileMetadata* file);
DEBUGGER_FFI_API bool BNDebuggerControllerExistsFromFile(BNFileMetadata* file);
DEBUGGER_FFI_API BNBinaryView* BNDebuggerGetLiveView(BNDebuggerController* controller);
DEBUGGER_FFI_API BNBinaryView* BNDebuggerGetData(BNDebuggerController* controller);
DEBUGGER_FFI_API void BNDebuggerSetData(BNDebuggerController* controller, BNBinaryView* data);
DEBUGGER_FFI_API BNArchitecture* BNDebuggerGetRemoteArchitecture(BNDebuggerController* controller);
Expand Down
21 changes: 8 additions & 13 deletions api/python/debuggercontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,10 +515,10 @@ class DebuggerController:
target breaks. In the future, we will switch to an asyunchrounous communication model where these functions return
before the operation is performed.
For each insteance of DebuggerController, there are two BinaryViews associated with it. The first one is the
original BinaryView that gets rebased to the proper offset according to the target's actual base. The second is a
"live" BinaryView that represents the entire memory space of the target process. They can be accessed by ``data``
and ``live_view``, respectively.
Starting from 4.1.5542-dev (0ad6b08b), the debugger no longer involves two binary views during debugging. Instead,
it always uses the incoming binary view that is used to create the controller, and memory regions that are not
present in the original binary view are represented using the new MemoryRegion API. The binary view can be accessed
by the ``data`` property.
"""
def __init__(self, bv: binaryninja.BinaryView):
Expand Down Expand Up @@ -547,15 +547,10 @@ def data(self) -> binaryninja.BinaryView:
return binaryninja.BinaryView(handle=result)

@property
@binaryninja.deprecation.deprecated(deprecated_in="4.1.5542", details='Debugger no longer uses the live view, Use :py:attr:`data` instead')
def live_view(self) -> binaryninja.BinaryView:
"""Get the live BinaryView of the debugger"""
result = dbgcore.BNDebuggerGetLiveView(self.handle)
if result is None:
return None
result = ctypes.cast(result, ctypes.POINTER(binaryninja.core.BNBinaryView))
if result is None:
return None
return binaryninja.BinaryView(handle=result)
return self.data

@property
def remote_arch(self) -> binaryninja.Architecture:
Expand Down Expand Up @@ -589,7 +584,7 @@ def read_memory(self, address: int, size: int) -> binaryninja.DataBuffer:
"""
Read memory from the target.
One can also get the ``live_view`` BinaryView of the DebuggerController, and use ordinary read methods to read
One can also get the ``data`` BinaryView of the DebuggerController, and use ordinary read methods to read
its content.
:param address: address to read from
Expand All @@ -608,7 +603,7 @@ def write_memory(self, address: int, buffer) -> bool:
"""
Write memory of the target.
One can also get the ``live_view`` BinaryView of the DebuggerController, and use ordinary write methods to write
One can also get the ``data`` BinaryView of the DebuggerController, and use ordinary write methods to write
its content.
:param address: address to write to
Expand Down
4 changes: 1 addition & 3 deletions core/debuggercontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1426,7 +1426,7 @@ void DebuggerController::DeleteController(BinaryViewRef data)
if (!controller)
continue;

if ((controller->GetData() == data) || (controller->GetLiveView() == data))
if (controller->GetData() == data)
{
g_debuggerControllers[i] = nullptr;
}
Expand All @@ -1443,8 +1443,6 @@ bool DebuggerController::ControllerExists(BinaryViewRef data)
continue;
if (controller->GetData() == data)
return true;
if (controller->GetLiveView() == data)
return true;
}

return false;
Expand Down
1 change: 0 additions & 1 deletion core/debuggercontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@ namespace BinaryNinjaDebugger {
BinaryViewRef GetData() { return m_data; }
FileMetadataRef GetFile() { return m_file; }
void SetData(BinaryViewRef view) {}
BinaryViewRef GetLiveView() const { return m_data; }
DebuggerFileAccessor* GetMemoryAccessor() const { return m_accessor; }

uint32_t GetExitCode();
Expand Down
9 changes: 0 additions & 9 deletions core/ffi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,6 @@ bool BNDebuggerControllerExistsFromFile(BNFileMetadata* file)
}


BNBinaryView* BNDebuggerGetLiveView(BNDebuggerController* controller)
{
BinaryViewRef result = controller->object->GetLiveView();
if (result)
return BNNewViewReference(result->GetObject());
return nullptr;
}


BNBinaryView* BNDebuggerGetData(BNDebuggerController* controller)
{
BinaryViewRef result = controller->object->GetData();
Expand Down
4 changes: 2 additions & 2 deletions ui/breakpointswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,8 @@ void DebugBreakpointsWidget::jump()
BreakpointItem bp = m_model->getRow(sel[0].row());
UIContext* context = UIContext::contextForWidget(this);
ViewFrame* frame = context->getCurrentViewFrame();
if (m_controller->GetLiveView())
frame->navigate(m_controller->GetLiveView(), bp.address(), true, true);
if (m_controller->GetData())
frame->navigate(m_controller->GetData(), bp.address(), true, true);
}


Expand Down
12 changes: 3 additions & 9 deletions ui/moduleswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,9 +423,7 @@ void DebugModulesWidget::jumpToStart()
if (!frame)
return;

if (m_controller->GetLiveView())
frame->navigate(m_controller->GetLiveView(), address, true, true);
else
if (m_controller->GetData())
frame->navigate(m_controller->GetData(), address, true, true);
}

Expand All @@ -451,9 +449,7 @@ void DebugModulesWidget::jumpToEnd()
if (!frame)
return;

if (m_controller->GetLiveView())
frame->navigate(m_controller->GetLiveView(), address, true, true);
else
if (m_controller->GetData())
frame->navigate(m_controller->GetData(), address, true, true);
}

Expand Down Expand Up @@ -537,9 +533,7 @@ void DebugModulesWidget::onDoubleClicked()
if (!frame)
return;

if (m_controller->GetLiveView())
frame->navigate(m_controller->GetLiveView(), address, true, true);
else
if (m_controller->GetData())
frame->navigate(m_controller->GetData(), address, true, true);
};

Expand Down
18 changes: 8 additions & 10 deletions ui/registerswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,15 @@ QVariant DebugRegistersListModel::headerData(int column, Qt::Orientation orienta
std::set<std::string> DebugRegistersListModel::getUsedRegisterNames()
{
std::set<std::string> usedRegisterNames;
if (!m_controller->GetLiveView())
if (!m_controller->GetData())
return usedRegisterNames;

auto pc = m_controller->IP();
auto arch = m_controller->GetLiveView()->GetDefaultArchitecture();
auto arch = m_controller->GetData()->GetDefaultArchitecture();
if (!arch)
return usedRegisterNames;

auto functions = m_controller->GetLiveView()->GetAnalysisFunctionsContainingAddress(pc);
auto functions = m_controller->GetData()->GetAnalysisFunctionsContainingAddress(pc);
if (functions.empty() || (!functions[0]))
return usedRegisterNames;

Expand Down Expand Up @@ -304,7 +304,7 @@ bool DebugRegistersListModel::setData(const QModelIndex& index, const QVariant&
uint64_t newValue = 0;
std::string errorString;
if (!BinaryView::ParseExpression(
m_controller->GetLiveView(), valueStr.toStdString(), newValue, currentValue, errorString))
m_controller->GetData(), valueStr.toStdString(), newValue, currentValue, errorString))
return false;

if (newValue == currentValue)
Expand Down Expand Up @@ -575,9 +575,7 @@ void DebugRegistersWidget::jump()
if (!frame)
return;

if (m_controller->GetLiveView())
frame->navigate(m_controller->GetLiveView(), value, true, true);
else
if (m_controller->GetData())
frame->navigate(m_controller->GetData(), value, true, true);
}

Expand Down Expand Up @@ -649,7 +647,7 @@ void DebugRegistersWidget::paste()
uint64_t newValue = 0;
std::string errorString;
if (!BinaryView::ParseExpression(
m_controller->GetLiveView(), text.toStdString(), newValue, reg.value(), errorString))
m_controller->GetData(), text.toStdString(), newValue, reg.value(), errorString))
return;

if (newValue == reg.value())
Expand Down Expand Up @@ -715,7 +713,7 @@ void DebugRegistersWidget::jumpInNewPaneInternal(const QModelIndex &index)
if (newViewFrame)
{
newViewFrame->disableSync();
newViewFrame->navigate(m_controller->GetLiveView(), value);
newViewFrame->navigate(m_controller->GetData(), value);
}
}
}
Expand Down Expand Up @@ -764,7 +762,7 @@ void DebugRegistersWidget::hoverTimerEvent()
auto reg = m_model->getRow(sourceIndex.row());
uint64_t addr = reg.value();

auto liveView = m_controller->GetLiveView();
auto liveView = m_controller->GetData();
if (!liveView)
return;

Expand Down
6 changes: 3 additions & 3 deletions ui/stackwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ bool DebugStackListModel::setData(const QModelIndex& index, const QVariant& valu
return false;

size_t addressSize = m_controller->GetRemoteArchitecture()->GetAddressSize();
BinaryWriter* writer = new BinaryWriter(m_controller->GetLiveView());
BinaryWriter* writer = new BinaryWriter(m_controller->GetData());
ok = false;
writer->Seek(item->address());
switch (addressSize)
Expand Down Expand Up @@ -432,11 +432,11 @@ void DebugStackWidget::updateContent()
if (!m_controller->IsConnected())
return;

if (!m_controller->GetLiveView())
if (!m_controller->GetData())
return;

std::vector<DebugStackItem> stackItems;
BinaryReader* reader = new BinaryReader(m_controller->GetLiveView());
BinaryReader* reader = new BinaryReader(m_controller->GetData());
uint64_t stackPointer = m_controller->StackPointer();
size_t addressSize = m_controller->GetRemoteArchitecture()->GetAddressSize();
for (ptrdiff_t i = -8; i < 60 + 1; i++)
Expand Down
4 changes: 1 addition & 3 deletions ui/threadframes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -738,9 +738,7 @@ void ThreadFramesWidget::onDoubleClicked()
if (!frame)
return;

if (m_debugger->GetLiveView())
frame->navigate(m_debugger->GetLiveView(), addrToJump, true, true);
else
if (m_debugger->GetData())
frame->navigate(m_debugger->GetData(), addrToJump, true, true);
}

Expand Down
34 changes: 16 additions & 18 deletions ui/ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,7 @@ static void JumpToIPCallback(BinaryView* view, UIContext* context)
if (!frame)
return;

if (controller->GetLiveView())
frame->navigate(controller->GetLiveView(), controller->IP(), true, true);
else
if (controller->GetData())
frame->navigate(controller->GetData(), controller->IP(), true, true);
}

Expand Down Expand Up @@ -986,7 +984,7 @@ void DebuggerUI::navigateDebugger(uint64_t address)
if (function)
{
// If the user is viewing a function in the current View, then navigate the current frame.
frame->navigate(m_controller->GetLiveView(), address, true, true);
frame->navigate(m_controller->GetData(), address, true, true);
}
else
{
Expand All @@ -1003,10 +1001,10 @@ void DebuggerUI::navigateDebugger(uint64_t address)
{
View* groupView = i->getCurrentViewInterface();
auto data = groupView->getData();
bool dataMatch = (data && (data == m_controller->GetLiveView() || data == m_controller->GetData()));
bool dataMatch = data && (data == m_controller->GetData());
if (dataMatch && groupView->getCurrentFunction())
{
navigated |= i->navigate(m_controller->GetLiveView(), address, true, true);
navigated |= i->navigate(m_controller->GetData(), address, true, true);
if (navigated)
break;
}
Expand All @@ -1015,7 +1013,7 @@ void DebuggerUI::navigateDebugger(uint64_t address)
}

if (!navigated)
frame->navigate(m_controller->GetLiveView(), address, true, true);
frame->navigate(m_controller->GetData(), address, true, true);
}

openDebuggerSideBar(frame);
Expand Down Expand Up @@ -1043,7 +1041,7 @@ void DebuggerUI::removeOldIPHighlight()
if (address == lastIP)
return;

BinaryViewRef data = m_controller->GetLiveView();
BinaryViewRef data = m_controller->GetData();
if (!data)
return;

Expand Down Expand Up @@ -1081,7 +1079,7 @@ void DebuggerUI::updateIPHighlight()
if (address == lastIP)
return;

BinaryViewRef data = m_controller->GetLiveView();
BinaryViewRef data = m_controller->GetData();
if (!data)
return;

Expand Down Expand Up @@ -1116,14 +1114,14 @@ void DebuggerUI::navigateToCurrentIP()
if (address == lastIp)
return;

BinaryViewRef liveView = m_controller->GetLiveView();
BinaryViewRef liveView = m_controller->GetData();
if (!liveView)
return;

auto functions = liveView->GetAnalysisFunctionsContainingAddress(address);
if (functions.empty())
{
auto data = m_controller->GetLiveView();
auto data = m_controller->GetData();
auto id = data->BeginUndoActions();
liveView->CreateUserFunction(data->GetDefaultPlatform(), address);
data->ForgetUndoActions(id);
Expand Down Expand Up @@ -1178,7 +1176,7 @@ void DebuggerUI::updateUI(const DebuggerEvent& event)
{
// If there is no function at the current address, define one. This might be a little aggressive,
// but given that we are lacking the ability to "show as code", this feels like an OK workaround.
BinaryViewRef liveView = m_controller->GetLiveView();
BinaryViewRef liveView = m_controller->GetData();
if (!liveView)
break;

Expand Down Expand Up @@ -1230,8 +1228,8 @@ void DebuggerUI::updateUI(const DebuggerEvent& event)
uint64_t address = m_controller->RelativeAddressToAbsolute(event.data.relativeAddress);

std::vector<std::pair<BinaryViewRef, uint64_t>> dataAndAddress;
if (m_controller->GetLiveView())
dataAndAddress.emplace_back(m_controller->GetLiveView(), address);
if (m_controller->GetData())
dataAndAddress.emplace_back(m_controller->GetData(), address);

if (DebugModule::IsSameBaseModule(event.data.relativeAddress.module, m_controller->GetInputFile()))
{
Expand Down Expand Up @@ -1268,7 +1266,7 @@ void DebuggerUI::updateUI(const DebuggerEvent& event)
uint64_t address = event.data.absoluteAddress;

std::vector<std::pair<BinaryViewRef, uint64_t>> dataAndAddress;
BinaryViewRef data = m_controller->GetLiveView();
BinaryViewRef data = m_controller->GetData();
if (data)
dataAndAddress.emplace_back(data, address);

Expand Down Expand Up @@ -1308,8 +1306,8 @@ void DebuggerUI::updateUI(const DebuggerEvent& event)
uint64_t address = m_controller->RelativeAddressToAbsolute(event.data.relativeAddress);

std::vector<std::pair<BinaryViewRef, uint64_t>> dataAndAddress;
if (m_controller->GetLiveView())
dataAndAddress.emplace_back(m_controller->GetLiveView(), address);
if (m_controller->GetData())
dataAndAddress.emplace_back(m_controller->GetData(), address);

if (DebugModule::IsSameBaseModule(event.data.relativeAddress.module, m_controller->GetInputFile()))
{
Expand Down Expand Up @@ -1339,7 +1337,7 @@ void DebuggerUI::updateUI(const DebuggerEvent& event)
uint64_t address = event.data.absoluteAddress;

std::vector<std::pair<BinaryViewRef, uint64_t>> dataAndAddress;
BinaryViewRef data = m_controller->GetLiveView();
BinaryViewRef data = m_controller->GetData();
if (data)
dataAndAddress.emplace_back(data, address);

Expand Down

0 comments on commit 7a47a1a

Please sign in to comment.