| 1 | // SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. |
| 2 | // |
| 3 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 4 | |
| 5 | #include "debugservice.h" |
| 6 | #include "debugmodel.h" |
| 7 | #include "debugsession.h" |
| 8 | |
| 9 | namespace DEBUG_NAMESPACE { |
| 10 | |
| 11 | |
| 12 | DebugService::DebugService(QObject *parent) |
| 13 | : QObject(parent) |
| 14 | { |
| 15 | model.reset(new DebugModel(undefined, this)); |
| 16 | } |
| 17 | |
| 18 | void DebugService::sendAllBreakpoints(DebugSession *session) |
| 19 | { |
| 20 | #if 0 // breakpoint type not supported now. |
| 21 | sendBreakpoints(undefined, session, false); |
| 22 | sendFunctionBreakpoints(session); |
| 23 | sendDataBreakpoints(session); |
| 24 | sendInstructionBreakpoints(session); |
| 25 | // send exception breakpoints at the end since some debug adapters rely on the order |
| 26 | sendExceptionBreakpoints(session); |
| 27 | #endif |
| 28 | |
| 29 | // remove all previous breakpoints. |
| 30 | sendBreakpoints({}, session); |
| 31 | |
| 32 | auto breakpoints = model->getAllBreakpoints(); |
| 33 | for (auto it = breakpoints.begin(); it != breakpoints.end(); ++it) { |
| 34 | sendBreakpoints(it.key(), session); |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | dap::array<IBreakpoint> DebugService::addBreakpoints( |
| 39 | QUrl uri, dap::array<IBreakpointData> rawBreakpoints, dap::optional<DebugSession *> session) |
| 40 | { |
| 41 | auto breakpoints = model->addBreakpoints(uri, rawBreakpoints); |
| 42 | if (session) |
| 43 | sendBreakpoints(uri, session.value()); |
| 44 | |
| 45 | return breakpoints; |
| 46 | } |
| 47 | |
| 48 | dap::array<IBreakpoint> DebugService::removeBreakpoints( |
| 49 | const QString &filePath, int lineNumber, dap::optional<DebugSession *> session) |
| 50 | { |
| 51 | auto breakpoints = model->removeBreakpoint(filePath, lineNumber); |
| 52 | if (session) |
| 53 | sendBreakpoints(QUrl(filePath), session.value()); |
| 54 | |
| 55 | return breakpoints; |
| 56 | } |
| 57 | |
| 58 | DebugModel *DebugService::getModel() const |
| 59 | { |
| 60 | return model.get(); |
| 61 | } |
| 62 | |
| 63 | void DebugService::sendBreakpoints(dap::optional<QUrl> uri, DebugSession *session, bool sourceModified) |
| 64 | { |
| 65 | Q_UNUSED(sourceModified) |
| 66 | if (!uri.has_value()) { |
| 67 | dap::array<IBreakpoint> empty; |
| 68 | session->sendBreakpoints({}, empty); |
| 69 | } else { |
| 70 | auto breakpointsToSend = model->getBreakpoints(uri, undefined, undefined, true); |
| 71 | session->sendBreakpoints(uri->path(), breakpointsToSend); |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | void DebugService::sendFunctionBreakpoints(DebugSession *session) |
| 76 | { |
| 77 | Q_UNUSED(session) |
| 78 | // TODO(mozart) |
| 79 | } |
| 80 | |
| 81 | void DebugService::sendDataBreakpoints(DebugSession *session) |
| 82 | { |
| 83 | Q_UNUSED(session) |
| 84 | // TODO(mozart) |
| 85 | } |
| 86 | |
| 87 | void DebugService::sendInstructionBreakpoints(DebugSession *session) |
| 88 | { |
| 89 | Q_UNUSED(session) |
| 90 | // TODO(mozart) |
| 91 | } |
| 92 | |
| 93 | void DebugService::sendExceptionBreakpoints(DebugSession *session) |
| 94 | { |
| 95 | Q_UNUSED(session) |
| 96 | // TODO(mozart) |
| 97 | } |
| 98 | } // end namespace. |
| 99 | |