1 | // SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. |
2 | // |
3 | // SPDX-License-Identifier: GPL-3.0-or-later |
4 | |
5 | #include "debuggerplugin.h" |
6 | #include "debuggerglobals.h" |
7 | #include "debugmanager.h" |
8 | |
9 | #include "services/window/windowservice.h" |
10 | #include "services/debugger/debuggerservice.h" |
11 | |
12 | #include "base/abstractnav.h" |
13 | #include "base/abstractaction.h" |
14 | #include "base/abstractmenu.h" |
15 | #include "base/abstractmainwindow.h" |
16 | #include "base/abstractwidget.h" |
17 | |
18 | #include <QMenu> |
19 | |
20 | using namespace dpfservice; |
21 | |
22 | void DebuggerPlugin::initialize() |
23 | { |
24 | QString errStr; |
25 | auto &ctx = dpfInstance.serviceContext(); |
26 | if (!ctx.load(dpfservice::DebuggerService::name(), &errStr)) { |
27 | qCritical() << errStr; |
28 | abort(); |
29 | } |
30 | } |
31 | |
32 | bool DebuggerPlugin::start() |
33 | { |
34 | auto &ctx = dpfInstance.serviceContext(); |
35 | windowService = ctx.service<WindowService>(WindowService::name()); |
36 | if (!windowService) { |
37 | qCritical() << "Failed, can't found window service" ; |
38 | abort(); |
39 | } |
40 | |
41 | DebuggerService *debuggerService = ctx.service<DebuggerService>(DebuggerService::name()); |
42 | if (!debuggerService) { |
43 | qCritical() << "Failed, can't found debugger service" ; |
44 | abort(); |
45 | } |
46 | |
47 | debugManager->initialize(windowService, debuggerService); |
48 | |
49 | // instert output pane to window. |
50 | windowService->addContextWidget(tr("Stac&kFrame" ), new AbstractWidget(debugManager->getStackPane()), "Application" ); |
51 | windowService->setWidgetWatch(new AbstractWidget(debugManager->getLocalsPane())); |
52 | windowService->addContextWidget(tr("Break&points" ), new AbstractWidget(debugManager->getBreakpointPane()), "Application" ); |
53 | |
54 | connect(debugManager, &DebugManager::debugStarted, this, &DebuggerPlugin::slotDebugStarted); |
55 | |
56 | return true; |
57 | } |
58 | |
59 | dpf::Plugin::ShutdownFlag DebuggerPlugin::stop() |
60 | { |
61 | QProcess::execute("killall -9 debugadapter" ); |
62 | return Sync; |
63 | } |
64 | |
65 | void DebuggerPlugin::slotDebugStarted() |
66 | { |
67 | editor.switchContext(tr("&Application Output" )); |
68 | } |
69 | |