abstractplaingdbadapter.cpp 5.34 KB
Newer Older
hjk's avatar
hjk committed
1 2 3 4
/**************************************************************************
**
** This file is part of Qt Creator
**
hjk's avatar
hjk committed
5
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
hjk's avatar
hjk committed
6 7 8
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
con's avatar
con committed
9
** No Commercial Usage
hjk's avatar
hjk committed
10
**
con's avatar
con committed
11 12 13 14
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
hjk's avatar
hjk committed
15 16 17 18 19 20 21 22 23 24
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
con's avatar
con committed
25 26 27 28 29 30
** In addition, as a special exception, Nokia gives you certain additional
** rights.  These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
hjk's avatar
hjk committed
31 32 33
**
**************************************************************************/

ck's avatar
ck committed
34
#include "abstractplaingdbadapter.h"
35 36
#include "gdbmi.h"
#include "gdbengine.h"
Friedemann Kleint's avatar
Friedemann Kleint committed
37
#include "debuggerstartparameters.h"
38
#include "debuggeractions.h"
hjk's avatar
hjk committed
39
#include "debuggercore.h"
ck's avatar
ck committed
40
#include "debuggerstringutils.h"
hjk's avatar
hjk committed
41 42 43 44 45 46 47

#include <utils/qtcassert.h>

namespace Debugger {
namespace Internal {

#define CB(callback) \
ck's avatar
ck committed
48
    static_cast<GdbEngine::AdapterCallback>(&AbstractPlainGdbAdapter::callback), \
hjk's avatar
hjk committed
49 50
    STRINGIFY(callback)

ck's avatar
ck committed
51 52
AbstractPlainGdbAdapter::AbstractPlainGdbAdapter(GdbEngine *engine,
                                                 QObject *parent)
hjk's avatar
hjk committed
53 54 55 56
    : AbstractGdbAdapter(engine, parent)
{
}

hjk's avatar
hjk committed
57
void AbstractPlainGdbAdapter::setupInferior()
hjk's avatar
hjk committed
58
{
hjk's avatar
hjk committed
59
    QTC_ASSERT(state() == InferiorSetupRequested, qDebug() << state());
60
    if (!startParameters().processArgs.isEmpty()) {
61
        QString args = startParameters().processArgs;
ck's avatar
ck committed
62
        m_engine->postCommand("-exec-arguments " + toLocalEncoding(args));
63
    }
ck's avatar
ck committed
64
    m_engine->postCommand("-file-exec-and-symbols \"" + execFilePath() + '"',
hjk's avatar
hjk committed
65 66 67
        CB(handleFileExecAndSymbols));
}

ck's avatar
ck committed
68
void AbstractPlainGdbAdapter::handleFileExecAndSymbols(const GdbResponse &response)
hjk's avatar
hjk committed
69
{
hjk's avatar
hjk committed
70
    QTC_ASSERT(state() == InferiorSetupRequested, qDebug() << state());
hjk's avatar
hjk committed
71
    if (response.resultClass == GdbResultDone) {
ck's avatar
ck committed
72 73 74 75 76 77 78
        if (infoTargetNecessary()) {
            // Old gdbs do not announce the PID for programs without pthreads.
            // Note that successfully preloading the debugging helpers will
            // automatically load pthreads, so this will be unnecessary.
            if (m_engine->m_gdbVersion < 70000)
                m_engine->postCommand("info target", CB(handleInfoTarget));
        }
79
        m_engine->handleInferiorPrepared();
80
    } else {
81
        QByteArray ba = response.data.findChild("msg").data();
ck's avatar
ck committed
82
        QString msg = fromLocalEncoding(ba);
83 84 85
        // Extend the message a bit in unknown cases.
        if (!ba.endsWith("File format not recognized"))
            msg = tr("Starting executable failed:\n") + msg;
hjk's avatar
hjk committed
86
        m_engine->notifyInferiorSetupFailed(msg);
hjk's avatar
hjk committed
87 88 89
    }
}

hjk's avatar
hjk committed
90
void AbstractPlainGdbAdapter::runEngine()
91
{
hjk's avatar
hjk committed
92
    QTC_ASSERT(state() == EngineRunRequested, qDebug() << state());
93
    m_engine->postCommand("-exec-run", GdbEngine::RunRequest, CB(handleExecRun));
94 95
}

ck's avatar
ck committed
96
void AbstractPlainGdbAdapter::handleExecRun(const GdbResponse &response)
hjk's avatar
hjk committed
97
{
hjk's avatar
hjk committed
98
    QTC_ASSERT(state() == EngineRunRequested, qDebug() << state());
hjk's avatar
hjk committed
99
    if (response.resultClass == GdbResultRunning) {
hjk's avatar
hjk committed
100 101
        m_engine->notifyEngineRunAndInferiorRunOk();
        //showStatusMessage(tr("Running..."));
102
        showMessage(_("INFERIOR STARTED"));
hjk's avatar
hjk committed
103
        showMessage(msgInferiorSetupOk(), StatusBar);
104
        // FIXME: That's the wrong place for it.
hjk's avatar
hjk committed
105
        if (debuggerCore()->boolSetting(EnableReverseDebugging))
106
            m_engine->postCommand("target record");
hjk's avatar
hjk committed
107
    } else {
ck's avatar
ck committed
108
        QString msg = fromLocalEncoding(response.data.findChild("msg").data());
hjk's avatar
hjk committed
109
        //QTC_ASSERT(status() == InferiorRunOk, /**/);
hjk's avatar
hjk committed
110
        //interruptInferior();
hjk's avatar
hjk committed
111 112
        showMessage(msg);
        m_engine->notifyEngineRunFailed();
hjk's avatar
hjk committed
113 114 115
    }
}

ck's avatar
ck committed
116
void AbstractPlainGdbAdapter::handleInfoTarget(const GdbResponse &response)
hjk's avatar
hjk committed
117
{
ck's avatar
ck committed
118 119 120 121 122 123 124 125 126 127 128 129
    if (response.resultClass == GdbResultDone) {
        // [some leading stdout here]
        // >&"        Entry point: 0x80831f0  0x08048134 - 0x08048147 is .interp\n"
        // [some trailing stdout here]
        QString msg = _(response.data.findChild("consolestreamoutput").data());
        QRegExp needle(_("\\bEntry point: 0x([0-9a-f]+)\\b"));
        if (needle.indexIn(msg) != -1) {
            m_engine->m_entryPoint =
                    "0x" + needle.cap(1).toLatin1().rightJustified(sizeof(void *) * 2, '0');
            m_engine->postCommand("tbreak *0x" + needle.cap(1).toAscii());
            // Do nothing here - inferiorPrepared handles the sequencing.
        } else {
hjk's avatar
hjk committed
130
            m_engine->notifyInferiorSetupFailed(_("Parsing start address failed"));
ck's avatar
ck committed
131 132
        }
    } else if (response.resultClass == GdbResultError) {
hjk's avatar
hjk committed
133
        m_engine->notifyInferiorSetupFailed(_("Fetching start address failed"));
hjk's avatar
hjk committed
134 135 136 137
    }
}

} // namespace Debugger
ck's avatar
ck committed
138
} // namespace Internal