1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
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
16 ** GNU Lesser General Public License Usage
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.
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.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
34 #include "attachgdbadapter.h"
36 #include "debuggerstartparameters.h"
38 #include "gdbengine.h"
39 #include "procinterrupt.h"
40 #include "debuggerstringutils.h"
42 #include <utils/qtcassert.h>
48 #define CB(callback) \
49 static_cast<GdbEngine::AdapterCallback>(&AttachGdbAdapter::callback), \
52 ///////////////////////////////////////////////////////////////////////
56 ///////////////////////////////////////////////////////////////////////
58 AttachGdbAdapter::AttachGdbAdapter(GdbEngine *engine, QObject *parent)
59 : AbstractGdbAdapter(engine, parent)
63 void AttachGdbAdapter::startAdapter()
65 QTC_ASSERT(state() == EngineSetupRequested, qDebug() << state());
66 showMessage(_("TRYING TO START ADAPTER"));
68 if (!m_engine->startGdb())
71 m_engine->handleAdapterStarted();
74 void AttachGdbAdapter::setupInferior()
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();
83 void AttachGdbAdapter::runEngine()
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();
90 m_engine->handleStop0(data);
93 void AttachGdbAdapter::handleAttach(const GdbResponse &response)
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();
102 QString msg = QString::fromLocal8Bit(response.data.findChild("msg").data());
103 m_engine->notifyInferiorSetupFailed(msg);
107 void AttachGdbAdapter::interruptInferior()
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();
118 void AttachGdbAdapter::shutdownInferior()
120 m_engine->defaultInferiorShutdown("detach");
123 void AttachGdbAdapter::shutdownAdapter()
125 m_engine->notifyAdapterShutdownOk();
128 } // namespace Internal
129 } // namespace Debugger