OSDN Git Service

It's 2011 now.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / debugger / gdb / remoteplaingdbadapter.cpp
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** No Commercial Usage
10 **
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 **
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file.  Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights.  These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33
34 #include "remoteplaingdbadapter.h"
35 #include "gdbengine.h"
36 #include "debuggerstartparameters.h"
37
38 #include <debugger/debuggeractions.h>
39 #include <debugger/debuggerstringutils.h>
40 #include <utils/qtcassert.h>
41
42 namespace Debugger {
43 namespace Internal {
44
45 RemotePlainGdbAdapter::RemotePlainGdbAdapter(GdbEngine *engine, QObject *parent)
46     : AbstractPlainGdbAdapter(engine, parent),
47       m_gdbProc(engine->startParameters().connParams, this)
48 {
49     connect(&m_gdbProc, SIGNAL(started()), this, SLOT(handleGdbStarted()));
50     connect(&m_gdbProc, SIGNAL(startFailed()), this,
51         SLOT(handleGdbStartFailed()));
52 }
53
54 void RemotePlainGdbAdapter::startAdapter()
55 {
56     QTC_ASSERT(state() == EngineSetupRequested, qDebug() << state());
57     showMessage(QLatin1String("TRYING TO START ADAPTER"));
58     m_engine->requestRemoteSetup();
59 }
60
61 void RemotePlainGdbAdapter::setupInferior()
62 {
63     AbstractPlainGdbAdapter::setupInferior();
64     m_engine->postCommand("directory "
65         + m_engine->startParameters().remoteSourcesDir);
66 }
67
68 void RemotePlainGdbAdapter::interruptInferior()
69 {
70     m_gdbProc.interruptInferior();
71 }
72
73 QByteArray RemotePlainGdbAdapter::execFilePath() const
74 {
75     return startParameters().executable.toUtf8();
76 }
77
78 bool RemotePlainGdbAdapter::infoTargetNecessary() const
79 {
80     return true;
81 }
82
83 QByteArray RemotePlainGdbAdapter::toLocalEncoding(const QString &s) const
84 {
85     return s.toUtf8();
86 }
87
88 QString RemotePlainGdbAdapter::fromLocalEncoding(const QByteArray &b) const
89 {
90     return QString::fromUtf8(b);
91 }
92
93 void RemotePlainGdbAdapter::handleApplicationOutput(const QByteArray &output)
94 {
95     showMessage(QString::fromUtf8(output), AppOutput);
96 }
97
98 void RemotePlainGdbAdapter::shutdownInferior()
99 {
100     m_engine->defaultInferiorShutdown("kill");
101 }
102
103 void RemotePlainGdbAdapter::shutdownAdapter()
104 {
105     m_engine->notifyAdapterShutdownOk();
106 }
107
108 void RemotePlainGdbAdapter::handleRemoteSetupDone(int gdbServerPort, int qmlPort)
109 {
110     Q_UNUSED(gdbServerPort);
111     QTC_ASSERT(state() == EngineSetupRequested, qDebug() << state());
112
113     if (qmlPort != -1)
114         startParameters().qmlServerPort = qmlPort;
115     if (!startParameters().workingDirectory.isEmpty())
116         m_gdbProc.setWorkingDirectory(startParameters().workingDirectory);
117     if (startParameters().environment.size())
118         m_gdbProc.setEnvironment(startParameters().environment.toStringList());
119     m_gdbProc.realStart(m_engine->startParameters().debuggerCommand,
120         QStringList() << QLatin1String("-i") << QLatin1String("mi"),
121         m_engine->startParameters().executable);
122 }
123
124 void RemotePlainGdbAdapter::handleGdbStarted()
125 {
126     if (m_engine->startGdb(QStringList(),
127             m_engine->startParameters().debuggerCommand))
128         m_engine->handleAdapterStarted();
129 }
130
131 void RemotePlainGdbAdapter::handleGdbStartFailed()
132 {
133     m_engine->handleAdapterStartFailed(m_gdbProc.errorString());
134 }
135
136 void RemotePlainGdbAdapter::handleRemoteSetupFailed(const QString &reason)
137 {
138     QTC_ASSERT(state() == EngineSetupRequested, qDebug() << state());
139
140     m_engine->handleAdapterStartFailed(reason);
141 }
142
143 } // namespace Internal
144 } // namespace Debugger