OSDN Git Service

d928b593d2e48c64b693aaed45cde8324165aad4
[qt-creator-jp/qt-creator-jp.git] / src / plugins / debugger / gdb / attachgdbadapter.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 "attachgdbadapter.h"
35 #include "gdbmi.h"
36 #include "debuggerstartparameters.h"
37
38 #include "gdbengine.h"
39 #include "procinterrupt.h"
40 #include "debuggerstringutils.h"
41
42 #include <utils/qtcassert.h>
43
44
45 namespace Debugger {
46 namespace Internal {
47
48 #define CB(callback) \
49     static_cast<GdbEngine::AdapterCallback>(&AttachGdbAdapter::callback), \
50     STRINGIFY(callback)
51
52 ///////////////////////////////////////////////////////////////////////
53 //
54 // AttachGdbAdapter
55 //
56 ///////////////////////////////////////////////////////////////////////
57
58 AttachGdbAdapter::AttachGdbAdapter(GdbEngine *engine, QObject *parent)
59     : AbstractGdbAdapter(engine, parent)
60 {
61 }
62
63 void AttachGdbAdapter::startAdapter()
64 {
65     QTC_ASSERT(state() == EngineSetupRequested, qDebug() << state());
66     showMessage(_("TRYING TO START ADAPTER"));
67
68     if (!m_engine->startGdb())
69         return;
70
71     m_engine->handleAdapterStarted();
72 }
73
74 void AttachGdbAdapter::setupInferior()
75 {
76     QTC_ASSERT(state() == InferiorSetupRequested, qDebug() << state());
77     const qint64 pid = startParameters().attachPID;
78     m_engine->postCommand("attach " + QByteArray::number(pid), CB(handleAttach));
79     // Task 254674 does not want to remove them
80     //qq->breakHandler()->removeAllBreakpoints();
81 }
82
83 void AttachGdbAdapter::runEngine()
84 {
85     QTC_ASSERT(state() == EngineRunRequested, qDebug() << state());
86     m_engine->showStatusMessage(tr("Attached to process %1.")
87         .arg(m_engine->inferiorPid()));
88     m_engine->notifyEngineRunAndInferiorStopOk();
89     GdbMi data;
90     m_engine->handleStop0(data);
91 }
92
93 void AttachGdbAdapter::handleAttach(const GdbResponse &response)
94 {
95     QTC_ASSERT(state() == InferiorSetupRequested, qDebug() << state());
96     if (response.resultClass == GdbResultDone || response.resultClass == GdbResultRunning) {
97         showMessage(_("INFERIOR ATTACHED"));
98         showMessage(msgAttachedToStoppedInferior(), StatusBar);
99         m_engine->handleInferiorPrepared();
100         //m_engine->updateAll();
101     } else {
102         QString msg = QString::fromLocal8Bit(response.data.findChild("msg").data());
103         m_engine->notifyInferiorSetupFailed(msg);
104     }
105 }
106
107 void AttachGdbAdapter::interruptInferior()
108 {
109     QTC_ASSERT(state() == InferiorStopRequested, qDebug() << state(); return);
110     const qint64 pid = startParameters().attachPID;
111     QTC_ASSERT(pid > 0, return);
112     if (!interruptProcess(pid)) {
113         showMessage(_("CANNOT INTERRUPT %1").arg(pid));
114         m_engine->notifyInferiorStopFailed();
115     }
116 }
117
118 void AttachGdbAdapter::shutdownInferior()
119 {
120     m_engine->defaultInferiorShutdown("detach");
121 }
122
123 void AttachGdbAdapter::shutdownAdapter()
124 {
125     m_engine->notifyAdapterShutdownOk();
126 }
127
128 } // namespace Internal
129 } // namespace Debugger