Skip to content

Commit

Permalink
feat: [debug] support debugging linglong project
Browse files Browse the repository at this point in the history
add connect to gdbserver

Log: as title
  • Loading branch information
LiHua000 committed Nov 26, 2024
1 parent e67b6cf commit f21534d
Show file tree
Hide file tree
Showing 23 changed files with 473 additions and 34 deletions.
9 changes: 8 additions & 1 deletion src/plugins/cxx/cmake/cmakegenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,14 @@ QMap<QString, QVariant> CMakeGenerator::getDebugArguments(const dpfservice::Proj
QMap<QString, QVariant> param;
param.insert("workspace", projectInfo.runWorkspaceDir());
param.insert("targetPath", projectInfo.runProgram());
param.insert("arguments", projectInfo.runCustomArgs());
QStringList debugArgs;
if (!projectInfo.runCustomArgs().isEmpty()) {
debugArgs.append("--args");
debugArgs.append(projectInfo.runProgram()); // gdb -i --args program arg
debugArgs.append(projectInfo.runCustomArgs());
}

param.insert("arguments", debugArgs);

return param;
}
Expand Down
28 changes: 28 additions & 0 deletions src/plugins/debugger/dap/dapdebugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,34 @@ void DAPDebugger::startDebugRemote(const RemoteInfo &info)
updateRunState(kPreparing);
}

void DAPDebugger::connectToGdbServer(const GdbserverInfo &info)
{
d->isRemote = false; // local dapDebugger -> gdbserver
d->currentSession = d->localSession;

QMap<QString, QVariant> param;
param.insert("workspace", "");
param.insert("targetPath", info.executablePath);
QStringList commands;
if (!info.executablePath.isEmpty())
commands.append(QString("--se=%1").arg(info.executablePath));
commands.append(QString("--ex=target remote %1:%2").arg(info.ip, QString::number(info.port)));
for (auto command : info.initCommands) {
if (!command.isEmpty())
commands.append(QString("--iex=%1").arg(command));
}
if (!info.debugInfo.isEmpty())
commands.append(QString("--iex=set debug-file-directory %1").arg(info.debugInfo));
if (!info.arg.isEmpty()) {
commands.append("--args");
commands.append(info.arg);
}
param.insert("arguments", commands);

requestDebugPort(param, "cmake", false);
updateRunState(kPreparing);
}

void DAPDebugger::attachDebug(const QString &processId)
{
if (d->runState != kNoRun) {
Expand Down
1 change: 1 addition & 0 deletions src/plugins/debugger/dap/dapdebugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class DAPDebugger : public AbstractDebugger

void startDebug() override;
void startDebugRemote(const RemoteInfo &info) override;
void connectToGdbServer(const GdbserverInfo &info);
void startRerverseDebug(const QString &target);
void attachDebug(const QString &processId) override;
void detachDebug() override;
Expand Down
3 changes: 3 additions & 0 deletions src/plugins/debugger/debuggerglobals.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#ifndef DEBUGGERGLOBALS_H
#define DEBUGGERGLOBALS_H

#include "services/debugger/debuggerservice.h"

#include <common/util/singleton.h>
#include <QColor>
#include <QtConcurrent>
Expand All @@ -13,6 +15,7 @@
* define AppOutPutPane`s toolbar name
*/
const QString debugToolBarName = "debugTool";
typedef dpfservice::GDBServerPreParam GdbserverInfo;

/*
* Redefine global instance
Expand Down
20 changes: 19 additions & 1 deletion src/plugins/debugger/debugmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "interface/menumanager.h"
#include "interface/attachinfodialog.h"
#include "reversedebug/reversedebugger.h"
#include "remotedebug/connecttoserverdlg.h"

#include "services/debugger/debuggerservice.h"
#include "services/window/windowservice.h"
Expand Down Expand Up @@ -54,6 +55,15 @@ bool DebugManager::initialize(dpfservice::WindowService *windowService,
debuggerService->getDebugState = std::bind(&DebugManager::getRunState, this);
}

if (!debuggerService->requestConnectToGdbServer) {
debuggerService->requestConnectToGdbServer = std::bind([=](const GDBServerPreParam &param){
auto dialog = new ConnectToServerDlg();
dialog->setAttribute(Qt::WA_DeleteOnClose);
dialog->setParam(param);
dialog->exec();
}, _1);
}

return true;
}

Expand Down Expand Up @@ -129,7 +139,7 @@ void DebugManager::run()
}
}

void DebugManager::remoteDebug(RemoteInfo info)
void DebugManager::remoteDebug(const RemoteInfo &info)
{
if (!currentDebugger) {
LanguageService *service = dpfGetService(LanguageService);
Expand All @@ -149,6 +159,14 @@ void DebugManager::remoteDebug(RemoteInfo info)
AsynInvokeWithParam(currentDebugger->startDebugRemote, info);
}

void DebugManager::connectToGdbServer(const GdbserverInfo &info)
{
// only support gdb.
auto dapDebuger = qobject_cast<DAPDebugger *>(currentDebugger);
QtConcurrent::run([dapDebuger, &info]() {
dapDebuger->connectToGdbServer(info);
});}

void DebugManager::attachDebug()
{
AttachInfoDialog dialog;
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/debugger/debugmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public slots:
/**
* UI triggered.
*/
void remoteDebug(RemoteInfo info);
void remoteDebug(const RemoteInfo &info);
void connectToGdbServer(const GdbserverInfo &info);
void run();
void attachDebug();
void detachDebug();
Expand Down
12 changes: 12 additions & 0 deletions src/plugins/debugger/interface/menumanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "common/widget/appoutputpane.h"
#include "services/window/windowservice.h"
#include "remotedebug/remotedebugdlg.h"
#include "remotedebug/connecttoserverdlg.h"

#include <QMenu>

Expand Down Expand Up @@ -147,6 +148,17 @@ void MenuManager::initialize(WindowService *windowService)
"debugger_remotedebug");
mDebug->addAction(actionImpl);

conenctToServerDebug.reset(new QAction(MWMDA_SERVER_DEBUG));
connect(conenctToServerDebug.get(), &QAction::triggered, debugManager, [=]() {
auto dialog = new ConnectToServerDlg();
dialog->setAttribute(Qt::WA_DeleteOnClose);
dialog->exec();
});
actionImpl = initAction(conenctToServerDebug.get(), "Debug.Server.Debug",
MWMDA_SERVER_DEBUG, QKeySequence(),
"debugger_connecttoserver");
mDebug->addAction(actionImpl);

attachDebugging.reset(new QAction(MWMDA_ATTACH_DEBUG));
connect(attachDebugging.get(), &QAction::triggered, debugManager, &DebugManager::attachDebug);
actionImpl = initAction(attachDebugging.get(), "Debug.Attach.Debugging",
Expand Down
1 change: 1 addition & 0 deletions src/plugins/debugger/interface/menumanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public slots:
QSharedPointer<QAction> stepOut;
QSharedPointer<QAction> stepBack;
QSharedPointer<QAction> remoteDebug;
QSharedPointer<QAction> conenctToServerDebug;
};

#endif // MENUMANAGER_H
2 changes: 1 addition & 1 deletion src/plugins/debugger/interface/stackframemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ void StackFrameModel::removeAll()

StackFrameData StackFrameModel::currentFrame() const
{
if (currentIndex == -1 || stackFrames.size() == 0)
if (currentIndex == -1 || stackFrames.size() == 0 || (stackFrames.size() < currentIndex))
return StackFrameData();

return stackFrames.at(currentIndex);
Expand Down
177 changes: 177 additions & 0 deletions src/plugins/debugger/remotedebug/connecttoserverdlg.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#include "connecttoserverdlg.h"
#include "debugmanager.h"

#include <DDialog>
#include <DLabel>
#include <DPushButton>
#include <DFileDialog>

#include <QGridLayout>
#include <QHBoxLayout>
#include <QSpacerItem>
#include <QVBoxLayout>

DWIDGET_USE_NAMESPACE
ConnectToServerDlg::ConnectToServerDlg(QWidget *parent)
: DDialog(parent)
{
setupUi();

connect(selDebugEE, &DSuggestButton::clicked, this, [=]() { setFileByFileDialog(leDebugee); });
connect(selProject, &DSuggestButton::clicked, this, [=]() { setDirByFileDialog(leProjectPath); });
connect(selDebugInfo, &DSuggestButton::clicked, this, [=]() { setDirByFileDialog(leDebugInfo); });
}

void ConnectToServerDlg::on_pbtnOK_clicked()

Check warning on line 29 in src/plugins/debugger/remotedebug/connecttoserverdlg.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

The function 'on_pbtnOK_clicked' is never used.

Check warning on line 29 in src/plugins/debugger/remotedebug/connecttoserverdlg.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'on_pbtnOK_clicked' is never used.
{
GdbserverInfo info;

info.executablePath = leDebugee->text();
info.initCommands = leCommands->toPlainText().split('\n');
info.ip = leIP->text();
bool ok;
info.port = lePort->text().toInt(&ok);
info.projectPath = leProjectPath->text();
info.arg = leParam->text();
info.debugInfo = leDebugInfo->text();
if (!ok) {
lePort->clear();
lePort->setPlaceholderText(tr("Port must be number"));
return;
}

debugManager->connectToGdbServer(info);
accept();
}

void ConnectToServerDlg::on_pbtnCancel_clicked()

Check warning on line 51 in src/plugins/debugger/remotedebug/connecttoserverdlg.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

The function 'on_pbtnCancel_clicked' is never used.

Check warning on line 51 in src/plugins/debugger/remotedebug/connecttoserverdlg.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'on_pbtnCancel_clicked' is never used.
{
reject();
}

void ConnectToServerDlg::setupUi()
{
setWindowTitle(tr("Connect To GdbServer"));
setIcon(QIcon::fromTheme("ide"));
auto verticalLayout = static_cast<QVBoxLayout *>(this->layout());
verticalLayout->setContentsMargins(20, 11, 20, 11);
auto gridLayout = new QGridLayout();
gridLayout->setSpacing(6);
gridLayout->setContentsMargins(0, 0, 10, 0);

auto lbIP = new DLabel(this);
lbIP->setText(tr("IP:"));
leIP = new DLineEdit(this);
gridLayout->addWidget(lbIP, 1, 0);
gridLayout->addWidget(leIP, 1, 1, 1, 2);

lePort = new DLineEdit(this);
auto lbPort = new DLabel(this);
lbPort->setText(tr("Port:"));
gridLayout->addWidget(lbPort, 2, 0);
gridLayout->addWidget(lePort, 2, 1, 1, 2);

auto lbDebuggee = new DLabel(this);
lbDebuggee->setText(tr("Debuggee:"));
leDebugee = new DLineEdit(this);
selDebugEE = new DSuggestButton(this);
selDebugEE->setIcon(DStyle::standardIcon(style(), DStyle::SP_SelectElement));
gridLayout->addWidget(lbDebuggee, 3, 0);
gridLayout->addWidget(leDebugee, 3, 1);
gridLayout->addWidget(selDebugEE, 3, 2);

auto lbParam = new DLabel(this);
lbParam->setText(tr("Param:"));
leParam = new DLineEdit(this);
gridLayout->addWidget(lbParam, 4, 0);
gridLayout->addWidget(leParam, 4, 1, 1, 2);

leCommands = new DTextEdit(this);
auto lbCommands = new DLabel(this);
lbCommands->setText(tr("Init Commands:"));
gridLayout->addWidget(lbCommands, 5, 0);
gridLayout->addWidget(leCommands, 5, 1, 1, 2);

leProjectPath = new DLineEdit(this);
auto lbProjectPath = new DLabel(this);
lbProjectPath->setText(tr("Local Project Path:"));
selProject = new DSuggestButton(this);
selProject->setIcon(DStyle::standardIcon(style(), DStyle::SP_SelectElement));
gridLayout->addWidget(lbProjectPath, 6, 0);
gridLayout->addWidget(leProjectPath, 6, 1);
gridLayout->addWidget(selProject, 6, 2);

leDebugInfo = new DLineEdit(this);
auto lbDebugInfo = new DLabel(this);
lbDebugInfo->setText(tr("Debug Info:"));
selDebugInfo = new DSuggestButton(this);
selDebugInfo->setIcon(DStyle::standardIcon(style(), DStyle::SP_SelectElement));
gridLayout->addWidget(lbDebugInfo, 7, 0);
gridLayout->addWidget(leDebugInfo, 7, 1);
gridLayout->addWidget(selDebugInfo, 7, 2);

verticalLayout->addLayout(gridLayout);

auto horizontalLayout = new QHBoxLayout();
horizontalLayout->setSpacing(6);
auto pbtnCancel = new DPushButton(this);
pbtnCancel->setFixedWidth(173);
pbtnCancel->setText("Cancel");
pbtnCancel->setObjectName(QStringLiteral("pbtnCancel"));
horizontalLayout->addWidget(pbtnCancel);

DVerticalLine *vLine = new DVerticalLine;
vLine->setObjectName("VLine");
vLine->setFixedHeight(30);
horizontalLayout->addWidget(vLine);

auto pbtnOK = new DSuggestButton(this);
pbtnOK->setFixedWidth(173);
pbtnOK->setText(tr("OK"));
pbtnOK->setObjectName(QStringLiteral("pbtnOK"));
horizontalLayout->addWidget(pbtnOK);

verticalLayout->addLayout(horizontalLayout);
QMetaObject::connectSlotsByName(this);
}

void ConnectToServerDlg::setParam(const GdbserverInfo &info)
{
leIP->setText(info.ip);
lePort->setText(QString::number(info.port));
leDebugee->setText(info.executablePath);
leParam->setText(info.arg);
leCommands->setText(info.initCommands.join('\n'));
leProjectPath->setText(info.projectPath);
leDebugInfo->setText(info.debugInfo);
}

void ConnectToServerDlg::setDirByFileDialog(DLineEdit *edit)
{
if (!edit)
return;

QString dir = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
QString filePath = DFileDialog::getExistingDirectory(this, "", dir);
if (filePath.isEmpty() && !QFileInfo(filePath).exists())
return;

edit->setText(filePath);
}

void ConnectToServerDlg::setFileByFileDialog(DLineEdit *edit)
{
if (!edit)
return;

QString dir = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
QString filePath = DFileDialog::getOpenFileName(this, "", dir);
if (filePath.isEmpty() && !QFileInfo(filePath).exists())
return;

edit->setText(filePath);
}
Loading

0 comments on commit f21534d

Please sign in to comment.