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 "localplaingdbadapter.h"
36 #include "gdbengine.h"
37 #include "debuggerstartparameters.h"
38 #include "procinterrupt.h"
39 #include "debuggercore.h"
40 #include "debuggerstringutils.h"
42 #include <utils/qtcassert.h>
44 #include <QtCore/QFileInfo>
45 #include <QtCore/QProcess>
46 #include <QtGui/QMessageBox>
51 ///////////////////////////////////////////////////////////////////////
55 ///////////////////////////////////////////////////////////////////////
57 LocalPlainGdbAdapter::LocalPlainGdbAdapter(GdbEngine *engine, QObject *parent)
58 : AbstractPlainGdbAdapter(engine, parent)
61 connect(&m_outputCollector, SIGNAL(byteDelivery(QByteArray)),
62 engine, SLOT(readDebugeeOutput(QByteArray)));
65 AbstractGdbAdapter::DumperHandling LocalPlainGdbAdapter::dumperHandling() const
67 // LD_PRELOAD fails for System-Qt on Mac.
68 #if defined(Q_OS_WIN) || defined(Q_OS_MAC)
69 return DumperLoadedByGdb;
71 return DumperLoadedByGdbPreload;
75 void LocalPlainGdbAdapter::startAdapter()
77 QTC_ASSERT(state() == EngineSetupRequested, qDebug() << state());
78 showMessage(_("TRYING TO START ADAPTER"));
81 if (!prepareWinCommand())
87 if (!m_outputCollector.listen()) {
88 m_engine->handleAdapterStartFailed(tr("Cannot set up communication with child process: %1")
89 .arg(m_outputCollector.errorString()), QString());
92 gdbArgs.append(_("--tty=") + m_outputCollector.serverName());
94 if (!startParameters().workingDirectory.isEmpty())
95 m_gdbProc.setWorkingDirectory(startParameters().workingDirectory);
96 if (startParameters().environment.size())
97 m_gdbProc.setEnvironment(startParameters().environment.toStringList());
99 if (!m_engine->startGdb(gdbArgs)) {
100 m_outputCollector.shutdown();
104 checkForReleaseBuild();
105 m_engine->handleAdapterStarted();
108 void LocalPlainGdbAdapter::setupInferior()
110 AbstractPlainGdbAdapter::setupInferior();
113 void LocalPlainGdbAdapter::runEngine()
115 AbstractPlainGdbAdapter::runEngine();
118 void LocalPlainGdbAdapter::shutdownInferior()
120 m_engine->defaultInferiorShutdown("kill");
123 void LocalPlainGdbAdapter::shutdownAdapter()
125 showMessage(_("PLAIN ADAPTER SHUTDOWN %1").arg(state()));
126 m_outputCollector.shutdown();
127 m_engine->notifyAdapterShutdownOk();
130 void LocalPlainGdbAdapter::checkForReleaseBuild()
132 // Quick check for a "release" build
135 args.append(_("-h"));
136 args.append(_("-j"));
137 args.append(_(".debug_info"));
138 args.append(startParameters().executable);
139 proc.start(_("objdump"), args);
140 proc.closeWriteChannel();
141 if (!proc.waitForStarted()) {
142 showMessage(_("OBJDUMP PROCESS COULD NOT BE STARTED. "
143 "RELEASE BUILD CHECK WILL FAIL"));
146 proc.waitForFinished();
147 QByteArray ba = proc.readAllStandardOutput();
148 // This should yield something like
149 // "debuggertest: file format elf32-i386\n\n"
150 // "Sections:\nIdx Name Size VMA LMA File off Algn\n"
151 // "30 .debug_info 00087d36 00000000 00000000 0006bbd5 2**0\n"
152 // " CONTENTS, READONLY, DEBUGGING"
153 if (ba.contains("Sections:") && !ba.contains(".debug_info")) {
154 showMessageBox(QMessageBox::Information, "Warning",
155 tr("This does not seem to be a \"Debug\" build.\n"
156 "Setting breakpoints by file name and line number may fail."));
160 void LocalPlainGdbAdapter::interruptInferior()
162 const qint64 attachedPID = m_engine->inferiorPid();
163 if (attachedPID <= 0) {
164 showMessage(_("TRYING TO INTERRUPT INFERIOR BEFORE PID WAS OBTAINED"));
168 if (interruptProcess(attachedPID)) {
169 showMessage(_("INTERRUPTED %1").arg(attachedPID));
171 showMessage(_("CANNOT INTERRUPT %1").arg(attachedPID));
172 m_engine->notifyInferiorStopFailed();
176 QByteArray LocalPlainGdbAdapter::execFilePath() const
178 return QFileInfo(startParameters().executable)
179 .absoluteFilePath().toLocal8Bit();
182 bool LocalPlainGdbAdapter::infoTargetNecessary() const
191 QByteArray LocalPlainGdbAdapter::toLocalEncoding(const QString &s) const
193 return s.toLocal8Bit();
196 QString LocalPlainGdbAdapter::fromLocalEncoding(const QByteArray &b) const
198 return QString::fromLocal8Bit(b);
201 } // namespace Internal
202 } // namespace Debugger