| 1 | // SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. |
| 2 | // |
| 3 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 4 | |
| 5 | #include "cmakedebug.h" |
| 6 | |
| 7 | #include "services/option/optionmanager.h" |
| 8 | |
| 9 | #include <QDBusMessage> |
| 10 | #include <QDBusConnection> |
| 11 | #include <QUuid> |
| 12 | |
| 13 | class CMakeDebugPrivate |
| 14 | { |
| 15 | friend class CMakeDebug; |
| 16 | }; |
| 17 | |
| 18 | CMakeDebug::CMakeDebug(QObject *parent) |
| 19 | : QObject(parent) |
| 20 | , d(new CMakeDebugPrivate()) |
| 21 | { |
| 22 | |
| 23 | } |
| 24 | |
| 25 | CMakeDebug::~CMakeDebug() |
| 26 | { |
| 27 | if (d) |
| 28 | delete d; |
| 29 | } |
| 30 | |
| 31 | bool CMakeDebug::prepareDebug(QString &retMsg) |
| 32 | { |
| 33 | QString debuggerTool = OptionManager::getInstance()->getCxxDebuggerToolPath(); |
| 34 | if (!debuggerTool.contains("gdb" )) { |
| 35 | retMsg = tr("The gdb is required, please install it in console with \"sudo apt install gdb\", " |
| 36 | "and then restart the tool, reselect the CMake Debugger in Options Dialog..." ); |
| 37 | return false; |
| 38 | } |
| 39 | |
| 40 | return true; |
| 41 | } |
| 42 | |
| 43 | bool CMakeDebug::requestDAPPort(const QString &uuid, const QString &kit, |
| 44 | const QString &targetPath, const QStringList &arguments, |
| 45 | QString &retMsg) |
| 46 | { |
| 47 | QDBusMessage msg = QDBusMessage::createSignal("/path" , |
| 48 | "com.deepin.unioncode.interface" , |
| 49 | "getDebugPort" ); |
| 50 | |
| 51 | msg << uuid |
| 52 | << kit |
| 53 | << targetPath |
| 54 | << arguments; |
| 55 | bool ret = QDBusConnection::sessionBus().send(msg); |
| 56 | if (!ret) { |
| 57 | retMsg = tr("Request cxx dap port failed, please retry." ); |
| 58 | return false; |
| 59 | } |
| 60 | |
| 61 | return true; |
| 62 | } |
| 63 | |
| 64 | bool CMakeDebug::isLaunchNotAttach() |
| 65 | { |
| 66 | return false; |
| 67 | } |
| 68 | |
| 69 | dap::LaunchRequest CMakeDebug::launchDAP(const QString &targetPath, const QStringList &argments) |
| 70 | { |
| 71 | dap::LaunchRequest request; |
| 72 | request.name = "(gdb) Launch" ; |
| 73 | request.type = "cppdbg" ; |
| 74 | request.request = "launch" ; |
| 75 | request.program = targetPath.toStdString(); |
| 76 | request.stopAtEntry = false; |
| 77 | dap::array<dap::string> arrayArg; |
| 78 | foreach (QString arg, argments) { |
| 79 | arrayArg.push_back(arg.toStdString()); |
| 80 | } |
| 81 | request.args = arrayArg; |
| 82 | request.externalConsole = false; |
| 83 | request.MIMode = "gdb" ; |
| 84 | request.__sessionId = QUuid::createUuid().toString().toStdString(); |
| 85 | |
| 86 | return request; |
| 87 | } |
| 88 | |
| 89 | |