Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions IDE/src/Commands.bf
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ namespace IDE
Add("Zoom Out", new => gApp.Cmd_ZoomOut);
Add("Zoom Reset", new => gApp.Cmd_ZoomReset);
Add("Attach to Process", new => gApp.[Friend]DoAttach);
Add("Connect Remote Debugger", new => gApp.[Friend]DoConnectRemote);
Add("Move Last Selection to Next Find Match", new => gApp.Cmd_MoveLastSelectionToNextFindMatch);

Add("Test Enable Console", new => gApp.Cmd_TestEnableConsole);
Expand Down
15 changes: 15 additions & 0 deletions IDE/src/Debugger/DebugManager.bf
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ namespace IDE.Debugger
[CallingConvention(.Stdcall),CLink]
static extern bool Debugger_Attach(int32 processId, AttachFlags attachFlags);

[CallingConvention(.Stdcall),CLink]
static extern bool Debugger_ConnectRemote(char8* host, int32 port, char8* elfPath);

[CallingConvention(.Stdcall),CLink]
public static extern bool Debugger_SupportsRemoteConnect();

[CallingConvention(.Stdcall),CLink]
public static extern void Debugger_GetStdHandles(Platform.BfpFile** outStdIn, Platform.BfpFile** outStdOut, Platform.BfpFile** outStdErr);

Expand Down Expand Up @@ -1206,6 +1212,15 @@ namespace IDE.Debugger
return Debugger_Attach(process.Id, attachFlags);
}

public bool ConnectRemote(String host, int32 port, String elfPath)
{
mIsRunningCompiled = false;
mIsComptimeDebug = false;
mIsRunningWithHotSwap = false;
mIsRunning = Debugger_ConnectRemote(host, port, elfPath);
return mIsRunning;
}

public void GetStdHandles(Platform.BfpFile** outStdIn, Platform.BfpFile** outStdOut, Platform.BfpFile** outStdErr)
{
Debugger_GetStdHandles(outStdIn, outStdOut, outStdErr);
Expand Down
43 changes: 43 additions & 0 deletions IDE/src/IDEApp.bf
Original file line number Diff line number Diff line change
Expand Up @@ -5778,6 +5778,45 @@ namespace IDE
}
}

[IDECommand]
void DoConnectRemote()
{
var widgetWindow = GetCurrentWindow();
if (widgetWindow != null)
{
var dialog = new RemoteDebugDialog();
dialog.PopupWindow(mMainWindow);
}
}

public void ConnectRemoteDebugger(String host, int32 port, String elfPath)
{
if (mDebugger.mIsRunning)
{
Fail("Already debugging a target");
return;
}

mExecutionPaused = false;
// Remote targets are already halted at connect time; treating the first
// stop as the "init break" would trigger auto-continue into ROM hardware
// breakpoints. Mark it handled so the IDE goes straight to Paused.
mTargetDidInitBreak = true;
mTargetHadFirstBreak = false;

if (!mDebugger.ConnectRemote(host, port, elfPath))
{
Fail("Failed to initiate remote connection");
return;
}

OutputLine("Connecting to remote target at {0}:{1} (ELF: {2})", host, port, elfPath);
CheckDebugVisualizers();
mDebugger.IncrementSessionIdx();
mDebugger.RehupBreakpoints(true);
mIsAttachPendingSourceShow = true;
}

[IDECommand]
void DoLaunch()
{
Expand Down Expand Up @@ -6321,6 +6360,10 @@ namespace IDE
AddMenuItem(subMenu, "Start With&out Compiling", "Start Without Compiling", new => UpdateMenuItem_DebugStopped_HasWorkspace);
AddMenuItem(subMenu, "&Launch Process...", "Launch Process", new => UpdateMenuItem_DebugStopped);
AddMenuItem(subMenu, "&Attach to Process...", "Attach to Process", new => UpdateMenuItem_DebugStopped);
AddMenuItem(subMenu, "Connect to &Remote Target...", "Connect Remote Debugger", new (item) =>
{
item.SetDisabled(mDebugger.mIsRunning || !DebugManager.Debugger_SupportsRemoteConnect());
});
AddMenuItem(subMenu, "&Stop Debugging", "Stop Debugging", new => UpdateMenuItem_DebugOrTestRunning);
AddMenuItem(subMenu, "Break All", "Break All", new => UpdateMenuItem_DebugNotPaused);
AddMenuItem(subMenu, "Remove All Breakpoints", "Remove All Breakpoints");
Expand Down
96 changes: 96 additions & 0 deletions IDE/src/ui/RemoteDebugDialog.bf
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
using System;
using Beefy.events;
using Beefy.widgets;
using Beefy.theme.dark;
using Beefy.gfx;
using Beefy;

namespace IDE.ui
{
class RemoteDebugDialog : DarkDialog
{
public static String sLastHost = new String("localhost") ~ delete _;
public static int32 sLastPort = 1234;
public static String sLastElf = new String("") ~ delete _;

EditWidget mHostEdit;
EditWidget mPortEdit;
PathEditWidget mElfEdit;

public this()
{
mWindowFlags = BFWindow.Flags.ClientSized | .TopMost | .Caption |
.Border | .SysMenu | .PopupPosition;

AddOkCancelButtons(new (evt) => { Connect(); }, null, 0, 1);
Title = "Connect to Remote Target";

mHostEdit = AddEdit(sLastHost);
var portStr = scope String();
sLastPort.ToString(portStr);
mPortEdit = AddEdit(portStr);

mElfEdit = new PathEditWidget(.File);
mElfEdit.SetText(sLastElf);
AddWidget(mElfEdit);
}

void Connect()
{
var host = scope String();
mHostEdit.GetText(host);
host.Trim();

var portStr = scope String();
mPortEdit.GetText(portStr);
portStr.Trim();

int32 port = sLastPort;
if (int32.Parse(portStr) case .Ok(let p))
port = p;

var elfPath = scope String();
mElfEdit.GetText(elfPath);
elfPath.Trim();

sLastHost.Set(host);
sLastPort = port;
sLastElf.Set(elfPath);

IDEApp.sApp.ConnectRemoteDebugger(host, port, elfPath);
}

public override void Draw(Graphics g)
{
base.Draw(g);
using (g.PushColor(DarkTheme.COLOR_TEXT))
{
g.SetFont(DarkTheme.sDarkTheme.mSmallFont);
g.DrawString("Host:", mHostEdit.mX, mHostEdit.mY - 18);
g.DrawString("Port:", mPortEdit.mX, mPortEdit.mY - 18);
g.DrawString("ELF Binary:", mElfEdit.mX, mElfEdit.mY - 18);
}
}

public override void ResizeComponents()
{
base.ResizeComponents();
float editW = mWidth - 12;
mHostEdit.Resize(6, 40, editW, 20);
mPortEdit.Resize(6, 100, editW, 20);
mElfEdit.Resize(6, 160, editW, 20);
}

public override void CalcSize()
{
mWidth = 320;
mHeight = 240;
}

public override void Resize(float x, float y, float width, float height)
{
base.Resize(x, y, width, height);
ResizeComponents();
}
}
}
18 changes: 18 additions & 0 deletions IDEHelper/DebugManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,24 @@ BF_EXPORT bool BF_CALLTYPE Debugger_Attach(int processId, BfDbgAttachFlags attac
return false;
}

BF_EXPORT bool BF_CALLTYPE Debugger_ConnectRemote(const char* host, int32 port, const char* elfPath)
{
BF_ASSERT(gDebugger == NULL);

if (gDebugManager->mDebugger64->ConnectRemote(host, port, elfPath != NULL ? elfPath : ""))
{
gDebugger = gDebugManager->mDebugger64;
return true;
}

return false;
}

BF_EXPORT bool BF_CALLTYPE Debugger_SupportsRemoteConnect()
{
return gDebugManager->mDebugger64->SupportsRemoteConnect();
}

BF_EXPORT void Debugger_GetStdHandles(BfpFile** outStdIn, BfpFile** outStdOut, BfpFile** outStdErr)
{
if (gDebugger != NULL)
Expand Down
2 changes: 2 additions & 0 deletions IDEHelper/Debugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ class Debugger
virtual bool CanOpen(const StringImpl& fileName, DebuggerResult* outResult) = 0;
virtual void OpenFile(const StringImpl& launchPath, const StringImpl& targetPath, const StringImpl& args, const StringImpl& workingDir, const Array<uint8>& envBlock, bool hotSwapEnabled, DbgOpenFileFlags openFileFlags) = 0;
virtual bool Attach(int processId, BfDbgAttachFlags attachFlags) = 0;
virtual bool ConnectRemote(const StringImpl& host, int port, const StringImpl& elfPath) { return false; }
virtual bool SupportsRemoteConnect() { return false; }
virtual void GetStdHandles(BfpFile** outStdIn, BfpFile** outStdOut, BfpFile** outStdErr) = 0;
virtual void Run() = 0;
virtual bool HasLoadedTargetBinary() { return true; }
Expand Down
Loading
Loading