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 "abstractplaingdbadapter.h"
36 #include "gdbengine.h"
37 #include "debuggerstartparameters.h"
38 #include "debuggeractions.h"
39 #include "debuggercore.h"
40 #include "debuggerstringutils.h"
42 #include <utils/qtcassert.h>
47 #define CB(callback) \
48 static_cast<GdbEngine::AdapterCallback>(&AbstractPlainGdbAdapter::callback), \
51 AbstractPlainGdbAdapter::AbstractPlainGdbAdapter(GdbEngine *engine,
53 : AbstractGdbAdapter(engine, parent)
57 void AbstractPlainGdbAdapter::setupInferior()
59 QTC_ASSERT(state() == InferiorSetupRequested, qDebug() << state());
60 if (!startParameters().processArgs.isEmpty()) {
61 QString args = startParameters().processArgs;
62 m_engine->postCommand("-exec-arguments " + toLocalEncoding(args));
64 m_engine->postCommand("-file-exec-and-symbols \"" + execFilePath() + '"',
65 CB(handleFileExecAndSymbols));
68 void AbstractPlainGdbAdapter::handleFileExecAndSymbols(const GdbResponse &response)
70 QTC_ASSERT(state() == InferiorSetupRequested, qDebug() << state());
71 if (response.resultClass == GdbResultDone) {
72 if (infoTargetNecessary()) {
73 // Old gdbs do not announce the PID for programs without pthreads.
74 // Note that successfully preloading the debugging helpers will
75 // automatically load pthreads, so this will be unnecessary.
76 if (m_engine->m_gdbVersion < 70000)
77 m_engine->postCommand("info target", CB(handleInfoTarget));
79 m_engine->handleInferiorPrepared();
81 QByteArray ba = response.data.findChild("msg").data();
82 QString msg = fromLocalEncoding(ba);
83 // Extend the message a bit in unknown cases.
84 if (!ba.endsWith("File format not recognized"))
85 msg = tr("Starting executable failed:\n") + msg;
86 m_engine->notifyInferiorSetupFailed(msg);
90 void AbstractPlainGdbAdapter::runEngine()
92 QTC_ASSERT(state() == EngineRunRequested, qDebug() << state());
93 m_engine->postCommand("-exec-run", GdbEngine::RunRequest, CB(handleExecRun));
96 void AbstractPlainGdbAdapter::handleExecRun(const GdbResponse &response)
98 QTC_ASSERT(state() == EngineRunRequested, qDebug() << state());
99 if (response.resultClass == GdbResultRunning) {
100 m_engine->notifyEngineRunAndInferiorRunOk();
101 //showStatusMessage(tr("Running..."));
102 showMessage(_("INFERIOR STARTED"));
103 showMessage(msgInferiorSetupOk(), StatusBar);
104 // FIXME: That's the wrong place for it.
105 if (debuggerCore()->boolSetting(EnableReverseDebugging))
106 m_engine->postCommand("target record");
108 QString msg = fromLocalEncoding(response.data.findChild("msg").data());
109 //QTC_ASSERT(status() == InferiorRunOk, /**/);
110 //interruptInferior();
112 m_engine->notifyEngineRunFailed();
116 void AbstractPlainGdbAdapter::handleInfoTarget(const GdbResponse &response)
118 if (response.resultClass == GdbResultDone) {
119 // [some leading stdout here]
120 // >&" Entry point: 0x80831f0 0x08048134 - 0x08048147 is .interp\n"
121 // [some trailing stdout here]
122 QString msg = _(response.data.findChild("consolestreamoutput").data());
123 QRegExp needle(_("\\bEntry point: 0x([0-9a-f]+)\\b"));
124 if (needle.indexIn(msg) != -1) {
125 m_engine->m_entryPoint =
126 "0x" + needle.cap(1).toLatin1().rightJustified(sizeof(void *) * 2, '0');
127 m_engine->postCommand("tbreak *0x" + needle.cap(1).toAscii());
128 // Do nothing here - inferiorPrepared handles the sequencing.
130 m_engine->notifyInferiorSetupFailed(_("Parsing start address failed"));
132 } else if (response.resultClass == GdbResultError) {
133 m_engine->notifyInferiorSetupFailed(_("Fetching start address failed"));
137 } // namespace Debugger
138 } // namespace Internal