baremetalruncontrolfactory.cpp 5.76 KB
Newer Older
Tim Sander's avatar
Tim Sander committed
1
2
/****************************************************************************
**
Eike Ziller's avatar
Eike Ziller committed
3
** Copyright (C) 2015 Tim Sander <tim@krieglstein.org>
4
** Copyright (C) 2015 Denis Shienkov <denis.shienkov@gmail.com>
Eike Ziller's avatar
Eike Ziller committed
5
** Contact: http://www.qt.io/licensing
Tim Sander's avatar
Tim Sander committed
6
7
8
9
10
11
12
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
Eike Ziller's avatar
Eike Ziller committed
13
14
** a written agreement between you and The Qt Company.  For licensing terms and
** conditions see http://www.qt.io/terms-conditions.  For further information
Eike Ziller's avatar
Eike Ziller committed
15
** use the contact form at http://www.qt.io/contact-us.
Tim Sander's avatar
Tim Sander committed
16
17
18
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
Eike Ziller's avatar
Eike Ziller committed
19
20
21
22
23
24
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file.  Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
Tim Sander's avatar
Tim Sander committed
25
**
Eike Ziller's avatar
Eike Ziller committed
26
27
** In addition, as a special exception, The Qt Company gives you certain additional
** rights.  These rights are described in The Qt Company LGPL Exception
Tim Sander's avatar
Tim Sander committed
28
29
30
31
32
33
34
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/

#include "baremetalruncontrolfactory.h"
#include "baremetalgdbcommandsdeploystep.h"
#include "baremetalrunconfiguration.h"
Tim Sander's avatar
Tim Sander committed
35
#include "baremetaldevice.h"
36
37
38
39
#include "baremetaldebugsupport.h"

#include "gdbserverprovider.h"
#include "gdbserverprovidermanager.h"
Tim Sander's avatar
Tim Sander committed
40

41
#include <debugger/debuggerruncontrol.h>
Tim Sander's avatar
Tim Sander committed
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <debugger/debuggerstartparameters.h>
#include <debugger/debuggerkitinformation.h>
#include <projectexplorer/buildsteplist.h>
#include <projectexplorer/toolchain.h>
#include <projectexplorer/project.h>
#include <projectexplorer/buildconfiguration.h>
#include <analyzerbase/analyzerstartparameters.h>
#include <analyzerbase/analyzermanager.h>
#include <analyzerbase/analyzerruncontrol.h>
#include <projectexplorer/kitinformation.h>
#include <projectexplorer/target.h>
#include <utils/portlist.h>
#include <utils/qtcassert.h>

56
57
#include <QApplication>

Tim Sander's avatar
Tim Sander committed
58
59
60
61
62
63
64
65
using namespace Analyzer;
using namespace Debugger;
using namespace ProjectExplorer;

namespace BareMetal {
namespace Internal {

BareMetalRunControlFactory::BareMetalRunControlFactory(QObject *parent) :
66
    IRunControlFactory(parent)
Tim Sander's avatar
Tim Sander committed
67
68
69
70
71
72
73
{
}

BareMetalRunControlFactory::~BareMetalRunControlFactory()
{
}

74
bool BareMetalRunControlFactory::canRun(RunConfiguration *runConfiguration, Core::Id mode) const
Tim Sander's avatar
Tim Sander committed
75
{
76
77
78
    if (mode != ProjectExplorer::Constants::NORMAL_RUN_MODE
            && mode != ProjectExplorer::Constants::DEBUG_RUN_MODE
            && mode != ProjectExplorer::Constants::DEBUG_RUN_MODE_WITH_BREAK_ON_MAIN) {
Tim Sander's avatar
Tim Sander committed
79
        return false;
80
    }
Tim Sander's avatar
Tim Sander committed
81
82
83
84
85

    const QByteArray idStr = runConfiguration->id().name();
    return runConfiguration->isEnabled() && idStr.startsWith(BareMetalRunConfiguration::IdPrefix);
}

86
RunControl *BareMetalRunControlFactory::create(
87
        RunConfiguration *runConfiguration, Core::Id mode, QString *errorMessage)
Tim Sander's avatar
Tim Sander committed
88
89
90
{
    QTC_ASSERT(canRun(runConfiguration, mode), return 0);

91
    const auto rc = qobject_cast<BareMetalRunConfiguration *>(runConfiguration);
Tim Sander's avatar
Tim Sander committed
92
    QTC_ASSERT(rc, return 0);
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110

    const QString bin = rc->localExecutableFilePath();
    if (bin.isEmpty()) {
        *errorMessage = tr("Cannot debug: Local executable is not set.");
        return 0;
    } else if (!QFile::exists(bin)) {
        *errorMessage = tr("Cannot debug: Could not find executable for \"%1\".")
                .arg(bin);
        return 0;
    }

    const Target *target = rc->target();
    QTC_ASSERT(target, return 0);

    const Kit *kit = target->kit();
    QTC_ASSERT(kit, return 0);

    auto dev = qSharedPointerCast<const BareMetalDevice>(DeviceKitInformation::device(kit));
Tim Sander's avatar
Tim Sander committed
111
112
113
114
    if (!dev) {
        *errorMessage = tr("Cannot debug: Kit has no device.");
        return 0;
    }
115
116
117
118
119

    const GdbServerProvider *p = GdbServerProviderManager::instance()->findProvider(
                dev->gdbServerProviderId());
    if (!p) {
        *errorMessage = tr("Cannot debug: Device has no GDB server provider configuration.");
120
121
        return 0;
    }
122
123
124

    DebuggerStartParameters sp;

125
126
127
128
129
130
131
    if (const BuildConfiguration *bc = target->activeBuildConfiguration()) {
        if (const BuildStepList *bsl = bc->stepList(BareMetalGdbCommandsDeployStep::stepId())) {
            foreach (const BuildStep *bs, bsl->steps()) {
                if (auto ds = qobject_cast<const BareMetalGdbCommandsDeployStep *>(bs)) {
                    if (!sp.commandsAfterConnect.endsWith("\n"))
                        sp.commandsAfterConnect.append("\n");
                    sp.commandsAfterConnect.append(ds->gdbCommands().toLatin1());
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
                }
            }
        }
    }

    sp.executable = bin;
    sp.processArgs = rc->arguments();
    sp.startMode = AttachToRemoteServer;
    sp.displayName = rc->displayName();
    sp.commandsAfterConnect = p->initCommands().toLatin1();
    sp.commandsForReset = p->resetCommands().toLatin1();
    sp.remoteChannel = p->channel();
    sp.useContinueInsteadOfRun = true;

    if (p->startupMode() == GdbServerProvider::StartupOnNetwork)
        sp.remoteSetupNeeded = true;

149
    DebuggerRunControl *runControl = createDebuggerRunControl(sp, rc, errorMessage, mode);
150
151
152
153
154
155
    if (runControl && sp.remoteSetupNeeded) {
        const auto debugSupport = new BareMetalDebugSupport(dev, runControl);
        Q_UNUSED(debugSupport);
    }

    return runControl;
Tim Sander's avatar
Tim Sander committed
156
157
158
159
}

} // namespace Internal
} // namespace BareMetal