Skip to content

Commit

Permalink
+ Remote debugging for Filesystem workspace (#3549)
Browse files Browse the repository at this point in the history
Co-authored-by: Andrey Bezborodov <[email protected]>
  • Loading branch information
iHardRock and Andrey Bezborodov authored Dec 20, 2024
1 parent 651f51a commit c144dc8
Show file tree
Hide file tree
Showing 10 changed files with 1,731 additions and 851 deletions.
14 changes: 12 additions & 2 deletions Interfaces/debugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -371,13 +371,18 @@ class IDebugger
bool m_isSSHDebugging = false;
wxString m_debuggeeProjectName;
wxString m_sshAccount;

//! Command to execute right after connect to the remote target
wxString m_debuggerPostRemoteConnectCommands;

public:
IDebugger()
: m_observer(NULL)
, m_env(NULL)
, m_isRemoteDebugging(false)
, m_isRemoteExtended(false){};
, m_isRemoteExtended(false)
{}

virtual ~IDebugger(){};
void SetProjectName(const wxString& project) { m_debuggeeProjectName = project; }
void SetName(const wxString& name) { m_name = name; }
Expand All @@ -395,9 +400,14 @@ class IDebugger
DebuggerInformation GetDebuggerInformation() { return m_info; }

void SetIsRemoteDebugging(bool isRemoteDebugging) { this->m_isRemoteDebugging = isRemoteDebugging; }
bool GetIsRemoteDebugging() const { return m_isRemoteDebugging; }
void SetIsRemoteExtended(bool isRemoteExtended) { this->m_isRemoteExtended = isRemoteExtended; }
void SetPostRemoteConnectCommands(const wxString& commands) { this->m_debuggerPostRemoteConnectCommands = commands; }


bool GetIsRemoteDebugging() const { return m_isRemoteDebugging; }
bool GetIsRemoteExtended() const { return m_isRemoteExtended; }
const wxString& GetPostRemoteConnectCommands() const { return this->m_debuggerPostRemoteConnectCommands; }

void SetIsSSHDebugging(bool isSSHDebugging) { this->m_isSSHDebugging = isSSHDebugging; }
bool IsSSHDebugging() const { return m_isSSHDebugging; }
void SetSshAccount(const wxString& sshAccount) { this->m_sshAccount = sshAccount; }
Expand Down
49 changes: 29 additions & 20 deletions LiteEditor/manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2071,22 +2071,19 @@ void Manager::DbgStart(long attachPid)
DebugMessage(_("Debug session started successfully!\n"));

if (dbgr->GetIsRemoteDebugging()) {

// debugging remote target
wxString comm;
wxString port = bldConf->GetDbgHostPort();
wxString host = bldConf->GetDbgHostName();
wxString port = bldConf->GetDbgHostPort();

comm << host;

host = host.Trim().Trim(false);
port = port.Trim().Trim(false);
// Trim whitespaces
host = host.Trim(false).Trim();
port = port.Trim(false).Trim();

if (port.IsEmpty() == false) {
comm << wxT(":") << port;
if (!port.IsEmpty()) {
host << wxT(":") << port;
}

dbgr->Run(args, comm);
dbgr->Run(args, host);

} else if (attachPid == wxNOT_FOUND) {

Expand Down Expand Up @@ -2502,19 +2499,31 @@ void Manager::UpdateAsciiViewer(const wxString& expression, const wxString& tip)
void Manager::UpdateRemoteTargetConnected(const wxString& line)
{
IDebugger* dbgr = DebuggerMgr::Get().GetActiveDebugger();
if (dbgr && dbgr->IsRunning() && IsWorkspaceOpen()) {
// we currently do not support this feature when debugging using 'Quick debug'
wxString errMsg;
ProjectPtr proj = clCxxWorkspaceST::Get()->FindProjectByName(GetActiveProjectName(), errMsg);
BuildConfigPtr bldConf = clCxxWorkspaceST::Get()->GetProjBuildConf(proj->GetName(), wxEmptyString);
if (bldConf) {
wxArrayString dbg_cmds =
wxStringTokenize(bldConf->GetDebuggerPostRemoteConnectCmds(), wxT("\n"), wxTOKEN_STRTOK);
for (size_t i = 0; i < dbg_cmds.GetCount(); i++) {
dbgr->ExecuteCmd(dbg_cmds.Item(i));

if (dbgr && dbgr->IsRunning()) {
wxString commands;
// An old behavior for legacy workspace
if (IsWorkspaceOpen()) {
// we currently do not support this feature when debugging using 'Quick debug'
wxString errMsg;
ProjectPtr proj = clCxxWorkspaceST::Get()->FindProjectByName(GetActiveProjectName(), errMsg);
BuildConfigPtr bldConf = clCxxWorkspaceST::Get()->GetProjBuildConf(proj->GetName(), wxEmptyString);
if (bldConf) {
commands = bldConf->GetDebuggerPostRemoteConnectCmds();
}

// Filesystem workspace and so on
} else if (!dbgr->GetPostRemoteConnectCommands().empty()) {
commands = dbgr->GetPostRemoteConnectCommands();
}

// - Execute commands
wxArrayString dbg_cmds = wxStringTokenize(commands, wxT("\n"), wxTOKEN_STRTOK);
for (size_t i = 0; i < dbg_cmds.GetCount(); i++) {
dbgr->ExecuteCmd(dbg_cmds.Item(i));
}
}

// log the line
UpdateAddLine(line);
}
Expand Down
17 changes: 16 additions & 1 deletion Plugin/FileSystemWorkspace/FSConfigPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ FSConfigPage::FSConfigPage(wxWindow* parent, clFileSystemWorkspaceConfig::Ptr_t
lexer->Apply(m_stcCCFlags);
lexer->Apply(m_stcEnv);
lexer->Apply(m_stcCommands);
lexer->Apply(m_stcRemoteCommands);
}

m_dvListCtrlTargets->SetSortFunction([](clRowEntry* a, clRowEntry* b) {
Expand Down Expand Up @@ -79,9 +80,16 @@ FSConfigPage::FSConfigPage(wxWindow* parent, clFileSystemWorkspaceConfig::Ptr_t
m_textCtrlExcludeFiles->ChangeValue(config->GetExcludeFilesPattern());
m_textCtrlExcludePaths->ChangeValue(config->GetExecludePaths());
m_textCtrlWD->ChangeValue(config->GetWorkingDirectory());

m_textCtrlDebugger->ChangeValue(config->GetDebuggerPath());
m_stcCommands->SetText(config->GetDebuggerCommands());

m_checkRemoteEnabled->SetValue(config->GetDebuggerRemoteEnabled());
m_checkRemoteExtended->SetValue(config->GetDebuggerRemoteExtended());
m_textRemoteTargetHost->SetValue(config->GetDebuggerRemoteHost());
m_textRemoteTargetPort->SetValue(config->GetDebuggerRemotePort());
m_stcRemoteCommands->SetText(config->GetDebuggerRemoteCommands());

if (!m_enableRemotePage) {
m_checkBoxEnableRemote->Disable();
m_checkBoxRemoteBuild->Disable();
Expand Down Expand Up @@ -156,7 +164,7 @@ void FSConfigPage::Save()
last_executables.swap(small_arr);
}

m_config->SetExecutable(m_comboBoxExecutable->GetStringSelection());
m_config->SetExecutable(m_comboBoxExecutable->GetValue());
m_config->SetLastExecutables(last_executables);
m_config->SetEnvironment(m_stcEnv->GetText());
m_config->SetArgs(m_textCtrlArgs->GetValue());
Expand All @@ -169,8 +177,15 @@ void FSConfigPage::Save()
m_config->SetExcludeFilesPattern(m_textCtrlExcludeFiles->GetValue());
m_config->SetExcludePaths(m_textCtrlExcludePaths->GetValue());
m_config->SetWorkingDirectory(m_textCtrlWD->GetValue());

m_config->SetDebuggerPath(m_textCtrlDebugger->GetValue());
m_config->SetDebuggerCommands(m_stcCommands->GetText());

m_config->SetDebuggerRemoteEnabled(m_checkRemoteEnabled->IsChecked());
m_config->SetDebuggerRemoteExtended(m_checkRemoteExtended->IsChecked());
m_config->SetDebuggerRemoteHost(m_textRemoteTargetHost->GetValue());
m_config->SetDebuggerRemotePort(m_textRemoteTargetPort->GetValue());
m_config->SetDebuggerRemoteCommands(m_stcRemoteCommands->GetText());
}

void FSConfigPage::OnTargetActivated(wxDataViewEvent& event)
Expand Down
35 changes: 31 additions & 4 deletions Plugin/FileSystemWorkspace/clFileSystemWorkspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -940,10 +940,15 @@ void clFileSystemWorkspace::OnDebug(clDebugEvent& event)
dinfo.breakAtWinMain = false;
dinfo.consoleCommand = EditorConfigST::Get()->GetOptions()->GetProgramConsoleCommand();
dbgr->SetDebuggerInformation(dinfo);
dbgr->SetIsRemoteDebugging(false);

// Setup the debug session
// Setup remote debugging
if (GetConfig()->GetDebuggerRemoteEnabled()) {
dbgr->SetIsRemoteDebugging(GetConfig()->GetDebuggerRemoteEnabled());
dbgr->SetIsRemoteExtended(GetConfig()->GetDebuggerRemoteExtended());
dbgr->SetPostRemoteConnectCommands(GetConfig()->GetDebuggerRemoteCommands());
}

// Setup the debug session
wxString exe, args, wd;
GetExecutable(exe, args, wd);

Expand All @@ -955,6 +960,7 @@ void clFileSystemWorkspace::OnDebug(clDebugEvent& event)
session_info.exeName = exe;
session_info.cwd = wd;
session_info.init_file_content = GetConfig()->GetDebuggerCommands();

clGetManager()->GetBreakpoints(bpList);
session_info.bpList = bpList;

Expand Down Expand Up @@ -999,8 +1005,29 @@ void clFileSystemWorkspace::OnDebug(clDebugEvent& event)
clDebugEvent eventStarted(wxEVT_DEBUG_STARTED);
eventStarted.SetClientData(&session_info);
EventNotifier::Get()->ProcessEvent(eventStarted);
// Now run the debuggee
dbgr->Run(args, "");

if (dbgr->GetIsRemoteDebugging()) {
// debugging remote target
wxString host = GetConfig()->GetDebuggerRemoteHost();
wxString port = GetConfig()->GetDebuggerRemotePort();

// Trim whitespaces
host = host.Trim(false).Trim();
port = port.Trim(false).Trim();

// Add port
if (!port.IsEmpty()) {
host << wxT(":") << port;
}

// Now run the debuggee (remote)
dbgr->Run(args, host);

} else {
// Now run the debuggee (local)
dbgr->Run(args, "");

}
}

void clFileSystemWorkspace::GetExecutable(wxString& exe, wxString& args, wxString& wd)
Expand Down
18 changes: 16 additions & 2 deletions Plugin/FileSystemWorkspace/clFileSystemWorkspaceConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ std::pair<JSONItem, JSONItem> clFileSystemWorkspaceConfig::ToJSON() const
local.addProperty("workingDirectory", m_workingDirectory);
local.addProperty("debuggerPath", m_debuggerPath);
local.addProperty("debuggerCommands", m_debuggerCommands);

local.addProperty("debuggerRemoteEnabled", m_debuggerRemoteEnabled);
local.addProperty("debuggerRemoteExtended", m_debuggerRemoteExtended);
local.addProperty("debuggerRemoteHost", m_debuggerRemoteHost);
local.addProperty("debuggerRemotePort", m_debuggerRemotePort);
local.addProperty("debuggerRemoteCommands", m_debuggerRemoteCommands);

local.addProperty("last_executables", m_lastExecutables);
return { shared, local };
}
Expand Down Expand Up @@ -115,8 +122,15 @@ void clFileSystemWorkspaceConfig::FromLocalJSON(const JSONItem& json)
m_remoteFolder = json["remoteFolder"].toString();
m_remoteAccount = json["remoteAccount"].toString();
m_workingDirectory = json["workingDirectory"].toString();
m_debuggerPath = json["debuggerPath"].toString();
m_debuggerCommands = json["debuggerCommands"].toString();

m_debuggerPath = json["debuggerPath"].toString();
m_debuggerCommands = json["debuggerCommands"].toString();

m_debuggerRemoteEnabled = json["debuggerRemoteEnabled"].toBool();
m_debuggerRemoteExtended = json["debuggerRemoteExtended"].toBool(true);
m_debuggerRemoteHost = json["debuggerRemoteHost"].toString();
m_debuggerRemotePort = json["debuggerRemotePort"].toString();
m_debuggerRemoteCommands = json["debuggerRemoteCommands"].toString();
}

wxString clFileSystemWorkspaceConfig::GetCompileFlagsAsString() const
Expand Down
26 changes: 24 additions & 2 deletions Plugin/FileSystemWorkspace/clFileSystemWorkspaceConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ class WXDLLIMPEXP_SDK clFileSystemWorkspaceConfig
wxString m_excludePaths;
wxString m_debuggerPath;
wxString m_debuggerCommands;

bool m_debuggerRemoteEnabled = false;
bool m_debuggerRemoteExtended = true;
wxString m_debuggerRemoteCommands;
wxString m_debuggerRemoteHost = "localhost";
wxString m_debuggerRemotePort = "2345";

wxArrayString m_lastExecutables;

public:
Expand Down Expand Up @@ -110,10 +117,25 @@ class WXDLLIMPEXP_SDK clFileSystemWorkspaceConfig
wxArrayString ExpandUserCompletionFlags(const wxString& workingDirectory, clBacktickCache::ptr_t backticks,
bool withPrefix = false) const;
wxArrayString GetCompilerOptions(clBacktickCache::ptr_t backticks) const;
void SetDebuggerCommands(const wxString& debuggerCommands) { this->m_debuggerCommands = debuggerCommands; }

void SetDebuggerPath(const wxString& debuggerPath) { this->m_debuggerPath = debuggerPath; }
const wxString& GetDebuggerCommands() const { return m_debuggerCommands; }
void SetDebuggerCommands(const wxString& debuggerCommands) { this->m_debuggerCommands = debuggerCommands; }

void SetDebuggerRemoteEnabled(bool enabled) { this->m_debuggerRemoteEnabled = enabled; }
void SetDebuggerRemoteExtended(bool extended) { this->m_debuggerRemoteExtended = extended; }
void SetDebuggerRemoteHost(const wxString& host) { this->m_debuggerRemoteHost = host; }
void SetDebuggerRemotePort(const wxString& port) { this->m_debuggerRemotePort = port; }
void SetDebuggerRemoteCommands(const wxString& debuggerRemoteCommands) { this->m_debuggerRemoteCommands = debuggerRemoteCommands; }

const wxString& GetDebuggerPath() const { return m_debuggerPath; }
const wxString& GetDebuggerCommands() const { return m_debuggerCommands; }

bool GetDebuggerRemoteEnabled() const { return m_debuggerRemoteEnabled; }
bool GetDebuggerRemoteExtended() const { return m_debuggerRemoteExtended; }
const wxString& GetDebuggerRemoteHost() const { return m_debuggerRemoteHost; }
const wxString& GetDebuggerRemotePort() const { return m_debuggerRemotePort; }
const wxString& GetDebuggerRemoteCommands() const { return m_debuggerRemoteCommands; }

void SetLastExecutables(const wxArrayString& lastExecutables);
const wxArrayString& GetLastExecutables() const;
};
Expand Down
Loading

0 comments on commit c144dc8

Please sign in to comment.