Skip to content

Commit 475707b

Browse files
committed
Add an API to explicitly create the debug adapter object
1 parent fffe21d commit 475707b

File tree

9 files changed

+49
-1
lines changed

9 files changed

+49
-1
lines changed

api/debuggerapi.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,8 @@ namespace BinaryNinjaDebuggerAPI
337337

338338
BinaryNinja::Ref<Metadata> GetAdapterProperty(const std::string& name);
339339
bool SetAdapterProperty(const std::string& name, const BinaryNinja::Ref<Metadata>& value);
340+
341+
bool ActivateDebugAdapter();
340342
};
341343

342344

api/debuggercontroller.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,3 +680,9 @@ bool DebuggerController::SetAdapterProperty(const std::string& name, const Binar
680680
{
681681
return BNDebuggerSetAdapterProperty(m_object, name.c_str(), value->m_object);
682682
}
683+
684+
685+
bool DebuggerController::ActivateDebugAdapter()
686+
{
687+
return BNDebuggerActivateDebugAdapter(m_object);
688+
}

api/ffi.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,8 @@ extern "C"
383383
DEBUGGER_FFI_API char* BNDebuggerGetStopReasonString(BNDebugStopReason reason);
384384
DEBUGGER_FFI_API BNDebugStopReason BNDebuggerGetStopReason(BNDebuggerController* controller);
385385

386+
DEBUGGER_FFI_API bool BNDebuggerActivateDebugAdapter(BNDebuggerController* controller);
387+
386388
// DebugAdapterType
387389
DEBUGGER_FFI_API BNDebugAdapterType* BNGetDebugAdapterTypeByName(const char* name);
388390
DEBUGGER_FFI_API bool BNDebugAdapterTypeCanExecute(BNDebugAdapterType* adapter, BNBinaryView* data);

core/adapters/lldbadapter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1149,7 +1149,7 @@ Ref<Metadata> LldbAdapter::GetProperty(const std::string &name)
11491149
if (name == "current_platform")
11501150
{
11511151
auto platform = m_debugger.GetSelectedPlatform();
1152-
return new Metadata(platform.GetName());
1152+
return new Metadata(std::string(platform.GetName()));
11531153
}
11541154
else if (name == "platforms")
11551155
{

core/debuggercontroller.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1492,3 +1492,9 @@ bool DebuggerController::SetAdapterProperty(const std::string& name, const Binar
14921492
{
14931493
return true;
14941494
}
1495+
1496+
1497+
bool DebuggerController::ActivateDebugAdapter()
1498+
{
1499+
return CreateDebugAdapter();
1500+
}

core/debuggercontroller.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,5 +229,7 @@ namespace BinaryNinjaDebugger
229229

230230
BinaryNinja::Ref<BinaryNinja::Metadata> GetAdapterProperty(const std::string& name);
231231
bool SetAdapterProperty(const std::string& name, const BinaryNinja::Ref<BinaryNinja::Metadata>& value);
232+
233+
bool ActivateDebugAdapter();
232234
};
233235
};

core/ffi.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,3 +832,9 @@ DEBUGGER_FFI_API bool BNDebuggerSetAdapterProperty(BNDebuggerController* control
832832
{
833833
return controller->object->SetAdapterProperty(name, new Metadata(BNNewMetadataReference(value)));
834834
}
835+
836+
837+
bool BNDebuggerActivateDebugAdapter(BNDebuggerController* controller)
838+
{
839+
return controller->object->ActivateDebugAdapter();
840+
}

ui/debugserversetting.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ DebugServerSettingsDialog::DebugServerSettingsDialog(QWidget* parent, DebuggerCo
3636
titleLayout->setContentsMargins(0, 0, 0, 0);
3737

3838
m_platformEntry = new QComboBox(this);
39+
// workaround for the missing Metadata API
40+
m_platformEntry->setEditable(true);
41+
3942
// auto platformsMetaData = m_controller->GetAdapterProperty("platforms");
4043
// if (platformsMetaData->IsStringList())
4144
// {

ui/ui.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,27 @@ void GlobalDebuggerUI::SetupMenu(UIContext* context)
444444
}, connectedToDebugServer));
445445
debuggerMenu->addAction("Disconnect from Debug Server", "Launch");
446446

447+
UIAction::registerAction("Activate Debug Adapter");
448+
context->globalActions()->bindAction("Activate Debug Adapter", UIAction([=](const UIActionContext& ctxt) {
449+
if (!ctxt.binaryView)
450+
return;
451+
auto controller = DebuggerController::GetController(ctxt.binaryView);
452+
if (!controller)
453+
return;
454+
455+
if (controller->ActivateDebugAdapter())
456+
{
457+
QMessageBox::information(context->mainWindow(), "Successfully activated",
458+
"Successfully activated the debug adapter. Now you can run backend commands directly.");
459+
}
460+
else
461+
{
462+
QMessageBox::information(context->mainWindow(), "Failed to activate",
463+
"Cannot activate to the debug adapter.");
464+
}
465+
}));
466+
debuggerMenu->addAction("Activate Debug Adapter", "Launch");
467+
447468
#ifdef WIN32
448469
UIAction::registerAction("Reinstall DbgEng Redistributable");
449470
context->globalActions()->bindAction("Reinstall DbgEng Redistributable", UIAction([=](const UIActionContext& ctxt) {

0 commit comments

Comments
 (0)