Files
qt-creator/src/plugins/debugger/debuggerplugin.cpp

3214 lines
115 KiB
C++
Raw Normal View History

/**************************************************************************
2008-12-02 12:01:29 +01:00
**
** This file is part of Qt Creator
**
2010-03-05 11:25:49 +01:00
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
2008-12-02 12:01:29 +01:00
**
** Contact: Nokia Corporation (qt-info@nokia.com)
2008-12-02 12:01:29 +01:00
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** 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.
**
** If you are unsure which license is appropriate for your use, please
2009-08-14 09:30:56 +02:00
** contact the sales department at http://qt.nokia.com/contact.
2008-12-02 12:01:29 +01:00
**
**************************************************************************/
2008-12-02 15:08:31 +01:00
2008-12-02 12:01:29 +01:00
#include "debuggerplugin.h"
#include "debuggeractions.h"
#include "debuggeragents.h"
2008-12-02 12:01:29 +01:00
#include "debuggerconstants.h"
#include "debuggerdialogs.h"
#include "debuggerengine.h"
#include "debuggermainwindow.h"
2008-12-02 12:01:29 +01:00
#include "debuggerrunner.h"
#include "debuggerstringutils.h"
#include "debuggertooltip.h"
#include "debuggeruiswitcher.h"
#include "breakpoint.h"
#include "breakhandler.h"
#include "breakwindow.h"
#include "consolewindow.h"
#include "logwindow.h"
#include "moduleswindow.h"
#include "registerwindow.h"
#include "snapshotwindow.h"
#include "stackhandler.h"
#include "stackwindow.h"
#include "sourcefileswindow.h"
#include "threadswindow.h"
2010-11-04 18:11:09 +01:00
#include "watchhandler.h"
#include "watchwindow.h"
#include "watchutils.h"
#include "snapshothandler.h"
#include "threadshandler.h"
2008-12-02 12:01:29 +01:00
#include "ui_commonoptionspage.h"
2009-03-23 12:28:02 +01:00
#include "ui_dumperoptionpage.h"
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/actionmanager/command.h>
#include <coreplugin/uniqueidmanager.h>
2009-01-13 18:15:24 +01:00
#include <coreplugin/basemode.h>
2008-12-02 12:01:29 +01:00
#include <coreplugin/coreconstants.h>
#include <coreplugin/dialogs/ioptionspage.h>
2008-12-02 12:01:29 +01:00
#include <coreplugin/editormanager/editormanager.h>
2009-01-13 18:15:24 +01:00
#include <coreplugin/findplaceholder.h>
#include <coreplugin/icontext.h>
2008-12-02 12:01:29 +01:00
#include <coreplugin/icore.h>
#include <coreplugin/imode.h>
#include <coreplugin/icorelistener.h>
#include <coreplugin/manhattanstyle.h>
2009-01-13 18:15:24 +01:00
#include <coreplugin/minisplitter.h>
2008-12-02 12:01:29 +01:00
#include <coreplugin/modemanager.h>
2008-12-09 16:18:28 +01:00
2008-12-02 12:01:29 +01:00
#include <cppeditor/cppeditorconstants.h>
#include <cpptools/cppmodelmanagerinterface.h>
2008-12-09 16:18:28 +01:00
#include <extensionsystem/pluginmanager.h>
#include <projectexplorer/project.h>
#include <projectexplorer/projectexplorer.h>
2008-12-02 12:01:29 +01:00
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/session.h>
#include <projectexplorer/target.h>
#include <projectexplorer/toolchaintype.h>
2008-12-09 16:18:28 +01:00
#include <qt4projectmanager/qt4projectmanagerconstants.h>
2008-12-09 16:18:28 +01:00
#include <texteditor/basetexteditor.h>
2008-12-02 12:01:29 +01:00
#include <texteditor/basetextmark.h>
#include <texteditor/fontsettings.h>
#include <texteditor/texteditorsettings.h>
2008-12-09 16:18:28 +01:00
#include <utils/qtcassert.h>
#include <utils/savedaction.h>
#include <utils/styledbar.h>
2008-12-02 12:01:29 +01:00
#include <qml/scriptconsole.h>
#include <QtCore/QTimer>
#include <QtCore/QtPlugin>
#include <QtGui/QComboBox>
#include <QtGui/QDockWidget>
#include <QtGui/QFileDialog>
#include <QtGui/QMenu>
#include <QtGui/QMessageBox>
#include <QtGui/QPushButton>
#include <QtGui/QTextBlock>
#include <QtGui/QTextCursor>
#include <QtGui/QToolButton>
2008-12-02 12:01:29 +01:00
#include <climits>
#define DEBUG_STATE 1
#ifdef DEBUG_STATE
//# define STATE_DEBUG(s)
// do { QString msg; QTextStream ts(&msg); ts << s;
// showMessage(msg, LogDebug); } while (0)
# define STATE_DEBUG(s) do { qDebug() << s; } while(0)
#else
# define STATE_DEBUG(s)
#endif
// Note: the Debugger process itself and any helper processes like
// gdbserver, the trk client etc are referred to as 'Engine',
// whereas the debugged process is referred to as 'Inferior'.
//
// Transitions marked by '---' are done in the individual engines.
// Transitions marked by '+-+' are done in the base DebuggerEngine.
// Transitions marked by '*' are done asynchronously.
2010-07-08 18:10:50 +02:00
// The GdbEngine->setupEngine() function is described in more detail below.
//
// The engines are responsible for local roll-back to the last
// acknowledged state before calling notify*Failed. I.e. before calling
// notifyEngineSetupFailed() any process started during setupEngine()
// so far must be terminated.
//
//
//
// DebuggerNotReady
// +
// EngineSetupRequested
// +
// (calls *Engine->setupEngine())
// | |
2010-07-12 18:03:50 +02:00
// | |
// {notify- {notify-
// Engine- Engine-
// SetupOk} SetupFailed}
2010-07-12 18:03:50 +02:00
// + +
// + `+-+-+> EngineSetupFailed
// + +
// + [calls RunControl->startFailed]
// + +
// + DebuggerFinished
// v
// EngineSetupOk
// +
// [calls RunControl->StartSuccessful]
// +
// InferiorSetupRequested
// +
// (calls *Engine->setupInferior())
// | |
// | |
// {notify- {notify-
// Inferior- Inferior-
// SetupOk} SetupFailed}
// + +
// + ` +-+-> InferiorSetupFailed +-+-+-+-+-+->.
// + +
// + +
// EngineRunRequested +
// + +
// (calls *Engine->runEngine()) +
// / | | \ +
// / | | \ +
// | (core) | (attach) | | +
// | | | | +
// {notify- {notifyER&- {notifyER&- {notify- +
// Inferior- Inferior- Inferior- RunEngine- +
// Unrunnable} StopOk} RunOk} Failed} +
// + + + + +
// InferiorUnrunnable + InferiorRunOk + +
// + + +
// InferiorStopOk EngineRunFailed +
// + v
// `-+-+-+-+-+-+-+-+-+-+-+>-+
// +
2010-07-15 09:41:11 +02:00
// +
// #Interrupt@InferiorRunOk# +
// + +
2010-07-15 09:41:11 +02:00
// InferiorStopRequested +
// #SpontaneousStop + +
// @InferiorRunOk# (calls *Engine-> +
// + interruptInferior()) +
// {notify- | | +
// Spontaneous- {notify- {notify- +
// Inferior- Inferior- Inferior- +
// StopOk} StopOk} StopFailed} +
// + + + +
// + + + +
// InferiorStopOk + +
// + + +
// + + +
// + + +
// #Stop@InferiorUnrunnable# + +
// #Creator Close Event# + +
// + + +
// InferiorShutdownRequested +
// + +
// (calls *Engine->shutdownInferior()) +
// | | +
// {notify- {notify- +
// Inferior- Inferior- +
// ShutdownOk} ShutdownFailed} +
// + + +
// + + +
// #Inferior exited# + + +
// | + + +
// {notifyInferior- + + +
// Exited} + + +
// + + + +
// + + + +
// + + + +
// InferiorShutdownOk InferiorShutdownFailed +
// * * +
// EngineShutdownRequested +
// + +
// (calls *Engine->shutdownEngine()) <+-+-+-+-+-+-+-+-+-+-+-+-+-+'
// | |
// | |
// {notify- {notify-
// Engine- Engine-
// ShutdownOk} ShutdownFailed}
// + +
// EngineShutdownOk EngineShutdownFailed
// * *
// DebuggerFinished
//
/* Here is a matching graph as a GraphViz graph. View it using
* \code
grep "^sg1:" debuggerplugin.cpp | cut -c5- | dot -osg1.ps -Tps && gv sg1.ps
sg1: digraph DebuggerStates {
sg1: DebuggerNotReady -> EngineSetupRequested
sg1: EngineSetupRequested -> EngineSetupOk [ label="notifyEngineSetupOk", style="dashed" ];
sg1: EngineSetupRequested -> EngineSetupFailed [ label= "notifyEngineSetupFailed", style="dashed"];
sg1: EngineSetupFailed -> DebuggerFinished [ label= "RunControl::StartFailed" ];
sg1: EngineSetupOk -> InferiorSetupRequested [ label= "RunControl::StartSuccessful" ];
sg1: InferiorSetupRequested -> InferiorSetupFailed [ label="notifyInferiorFailed", style="dashed" ];
sg1: InferiorSetupRequested -> EngineRunRequested [ label="notifyInferiorSetupOk", style="dashed" ];
sg1: InferiorSetupFailed -> EngineShutdownRequested
sg1: EngineRunRequested -> InferiorUnrunnable [ label="notifyInferiorUnrunnable", style="dashed" ];
sg1: EngineRunRequested -> InferiorStopOk [ label="notifyEngineRunAndInferiorStopOk", style="dashed" ];
sg1: EngineRunRequested -> InferiorRunOk [ label="notifyEngineRunAndInferiorRunOk", style="dashed" ];
sg1: EngineRunRequested -> EngineRunFailed [ label="notifyEngineRunFailed", style="dashed" ];
sg1: EngineRunFailed -> EngineShutdownRequested
sg1: InferiorRunOk -> InferiorStopOk [ label="SpontaneousStop\nnotifyInferiorSpontaneousStop", style="dashed" ];
sg1: InferiorRunOk -> InferiorStopRequested [ label="User stop\nEngine::interruptInferior", style="dashed"];
sg1: InferiorStopRequested -> InferiorStopOk [ label="notifyInferiorStopOk", style="dashed" ];
sg1: InferiorStopRequested -> InferiorShutdownRequested [ label="notifyInferiorStopFailed", style="dashed" ];
sg1: InferiorStopOk -> InferiorRunRequested [ label="User\nEngine::continueInferior" ];
sg1: InferiorRunRequested -> InferiorRunOk [ label="notifyInferiorRunOk", style="dashed"];
sg1: InferiorRunRequested -> InferiorRunFailed [ label="notifyInferiorRunFailed", style="dashed"];
sg1: InferiorRunFailed -> InferiorStopOk
sg1: InferiorShutdownRequested -> InferiorShutdownOk [ label= "Engine::shutdownInferior\nnotifyInferiorShutdownOk", style="dashed" ];
sg1: InferiorShutdownRequested -> InferiorShutdownFailed [ label="Engine::shutdownInferior\nnotifyInferiorShutdownFailed", style="dashed" ];
sg1: InferiorExited -> InferiorShutdownOk [ label="notifyInferiorExited", style="dashed"];
sg1: InferiorShutdownOk -> EngineShutdownRequested
sg1: InferiorShutdownFailed -> EngineShutdownRequested
sg1: EngineShutdownRequested -> EngineShutdownOk [ label="Engine::shutdownEngine\nnotifyEngineShutdownOk", style="dashed" ];
sg1: EngineShutdownRequested -> EngineShutdownFailed [ label="Engine::shutdownEngine\nnotifyEngineShutdownFailed", style="dashed" ];
sg1: EngineShutdownOk -> DebuggerFinished [ style = "dotted" ];
sg1: EngineShutdownFailed -> DebuggerFinished [ style = "dotted" ];
sg1: }
* \endcode */
2010-07-15 09:41:11 +02:00
// Additional signalling: {notifyInferiorIll} {notifyEngineIll}
// GdbEngine specific startup. All happens in EngineSetupRequested state
//
// Transitions marked by '---' are done in the individual adapters.
// Transitions marked by '+-+' are done in the GdbEngine.
//
2010-07-08 18:10:50 +02:00
// GdbEngine::setupEngine()
// +
// (calls *Adapter->startAdapter())
// | |
// | `---> handleAdapterStartFailed()
// | +
// | {notifyEngineSetupFailed}
// |
// handleAdapterStarted()
// +
// {notifyEngineSetupOk}
//
//
//
// GdbEngine::setupInferior()
// +
// (calls *Adapter->prepareInferior())
// | |
// | `---> handlePrepareInferiorFailed()
// | +
// | {notifyInferiorSetupFailed}
// |
// handleInferiorPrepared()
// +
// {notifyInferiorSetupOk}
2008-12-02 12:01:29 +01:00
using namespace Core;
2009-01-13 18:15:24 +01:00
using namespace Debugger::Constants;
using namespace Debugger::Internal;
2008-12-02 12:01:29 +01:00
using namespace ProjectExplorer;
2009-01-13 18:15:24 +01:00
using namespace TextEditor;
2008-12-02 12:01:29 +01:00
2010-03-11 12:22:24 +01:00
namespace CC = Core::Constants;
namespace PE = ProjectExplorer::Constants;
2008-12-02 12:01:29 +01:00
namespace Debugger {
namespace Constants {
const char * const M_DEBUG_START_DEBUGGING = "QtCreator.Menu.Debug.StartDebugging";
2008-12-02 12:01:29 +01:00
const char * const STARTEXTERNAL = "Debugger.StartExternal";
const char * const ATTACHEXTERNAL = "Debugger.AttachExternal";
const char * const ATTACHCORE = "Debugger.AttachCore";
const char * const ATTACHTCF = "Debugger.AttachTcf";
const char * const ATTACHREMOTE = "Debugger.AttachRemote";
const char * const DETACH = "Debugger.Detach";
2008-12-02 12:01:29 +01:00
const char * const RUN_TO_LINE1 = "Debugger.RunToLine1";
const char * const RUN_TO_LINE2 = "Debugger.RunToLine2";
2008-12-02 12:01:29 +01:00
const char * const RUN_TO_FUNCTION = "Debugger.RunToFunction";
const char * const JUMP_TO_LINE1 = "Debugger.JumpToLine1";
const char * const JUMP_TO_LINE2 = "Debugger.JumpToLine2";
const char * const RETURN_FROM_FUNCTION = "Debugger.ReturnFromFunction";
const char * const SNAPSHOT = "Debugger.Snapshot";
2008-12-02 12:01:29 +01:00
const char * const TOGGLE_BREAK = "Debugger.ToggleBreak";
const char * const BREAK_BY_FUNCTION = "Debugger.BreakByFunction";
const char * const BREAK_AT_MAIN = "Debugger.BreakAtMain";
const char * const ADD_TO_WATCH1 = "Debugger.AddToWatch1";
const char * const ADD_TO_WATCH2 = "Debugger.AddToWatch2";
const char * const OPERATE_BY_INSTRUCTION = "Debugger.OperateByInstruction";
const char * const FRAME_UP = "Debugger.FrameUp";
const char * const FRAME_DOWN = "Debugger.FrameDown";
2008-12-02 12:01:29 +01:00
#ifdef Q_WS_MAC
const char * const STOP_KEY = "Shift+Ctrl+Y";
2008-12-02 12:01:29 +01:00
const char * const RESET_KEY = "Ctrl+Shift+F5";
const char * const STEP_KEY = "Ctrl+Shift+I";
const char * const STEPOUT_KEY = "Ctrl+Shift+T";
const char * const NEXT_KEY = "Ctrl+Shift+O";
const char * const REVERSE_KEY = "";
2008-12-02 12:01:29 +01:00
const char * const RUN_TO_LINE_KEY = "Shift+F8";
const char * const RUN_TO_FUNCTION_KEY = "Ctrl+F6";
const char * const JUMP_TO_LINE_KEY = "Ctrl+D,Ctrl+L";
2008-12-02 12:01:29 +01:00
const char * const TOGGLE_BREAK_KEY = "F8";
const char * const BREAK_BY_FUNCTION_KEY = "Ctrl+D,Ctrl+F";
const char * const BREAK_AT_MAIN_KEY = "Ctrl+D,Ctrl+M";
const char * const ADD_TO_WATCH_KEY = "Ctrl+D,Ctrl+W";
const char * const SNAPSHOT_KEY = "Ctrl+D,Ctrl+S";
2008-12-02 12:01:29 +01:00
#else
const char * const STOP_KEY = "Shift+F5";
2008-12-02 12:01:29 +01:00
const char * const RESET_KEY = "Ctrl+Shift+F5";
const char * const STEP_KEY = "F11";
const char * const STEPOUT_KEY = "Shift+F11";
const char * const NEXT_KEY = "F10";
const char * const REVERSE_KEY = "F12";
2008-12-02 12:01:29 +01:00
const char * const RUN_TO_LINE_KEY = "";
const char * const RUN_TO_FUNCTION_KEY = "";
const char * const JUMP_TO_LINE_KEY = "";
const char * const TOGGLE_BREAK_KEY = "F9";
const char * const BREAK_BY_FUNCTION_KEY = "";
const char * const BREAK_AT_MAIN_KEY = "";
const char * const ADD_TO_WATCH_KEY = "Ctrl+Alt+Q";
const char * const SNAPSHOT_KEY = "Ctrl+D,Ctrl+S";
2008-12-02 12:01:29 +01:00
#endif
} // namespace Constants
} // namespace Debugger
2010-08-31 13:07:33 +02:00
static SessionManager *sessionManager()
{
2010-08-31 13:07:33 +02:00
return ProjectExplorerPlugin::instance()->session();
}
static QSettings *settings()
{
return ICore::instance()->settings();
}
static QToolButton *toolButton(QAction *action)
{
QToolButton *button = new QToolButton;
button->setDefaultAction(action);
return button;
}
// Retrieve file name and line and optionally address
// from the data set on the text editor context menu action.
static bool positionFromContextActionData(const QObject *sender,
QString *fileName,
int *lineNumber,
quint64 *address = 0)
{
if (const QAction *action = qobject_cast<const QAction *>(sender)) {
const QVariantList data = action->data().toList();
if (data.size() >= (address ? 3 : 2)) {
*fileName = data.front().toString();
*lineNumber = data.at(1).toInt();
if (address)
*address = data.at(2).toULongLong();
return true;
}
}
return false;
}
namespace Debugger {
namespace Internal {
// FIXME: Outdated?
// The createCdbEngine function takes a list of options pages it can add to.
// This allows for having a "enabled" toggle on the page independently
// of the engine. That's good for not enabling the related ActiveX control
// unnecessarily.
void addGdbOptionPages(QList<Core::IOptionsPage*> *opts);
void addScriptOptionPages(QList<Core::IOptionsPage*> *opts);
void addTcfOptionPages(QList<Core::IOptionsPage*> *opts);
#ifdef CDB_ENABLED
void addCdbOptionPages(QList<Core::IOptionsPage*> *opts);
#endif
struct AttachRemoteParameters
{
AttachRemoteParameters() : attachPid(0), winCrashEvent(0) {}
void clear();
quint64 attachPid;
QString attachTarget; // core file name or server:port
// Event handle for attaching to crashed Windows processes.
quint64 winCrashEvent;
};
void AttachRemoteParameters::clear()
{
attachPid = winCrashEvent = 0;
attachTarget.clear();
}
///////////////////////////////////////////////////////////////////////
//
// DebugMode
//
///////////////////////////////////////////////////////////////////////
2009-01-13 18:15:24 +01:00
class DebugMode : public Core::BaseMode
{
public:
DebugMode(QObject *parent = 0) : BaseMode(parent)
{
2010-07-08 12:40:38 +02:00
setDisplayName(QCoreApplication::translate("Debugger::Internal::DebugMode", "Debug"));
setType(Core::Constants::MODE_EDIT_TYPE);
setId(MODE_DEBUG);
setIcon(QIcon(__(":/fancyactionbar/images/mode_Debug.png")));
setPriority(P_MODE_DEBUG);
}
2009-01-13 18:15:24 +01:00
~DebugMode()
{
// Make sure the editor manager does not get deleted.
EditorManager::instance()->setParent(0);
}
};
2009-01-13 18:15:24 +01:00
2008-12-02 12:01:29 +01:00
///////////////////////////////////////////////////////////////////////
//
// LocationMark
//
///////////////////////////////////////////////////////////////////////
// Used in "real" editors
class LocationMark : public TextEditor::BaseTextMark
2008-12-02 12:01:29 +01:00
{
public:
LocationMark(const QString &fileName, int linenumber)
: BaseTextMark(fileName, linenumber)
{}
2008-12-02 12:01:29 +01:00
QIcon icon() const { return DebuggerPlugin::instance()->locationMarkIcon(); }
2008-12-02 12:01:29 +01:00
void updateLineNumber(int /*lineNumber*/) {}
void updateBlock(const QTextBlock & /*block*/) {}
void removedFromEditor() {}
2008-12-02 12:01:29 +01:00
};
///////////////////////////////////////////////////////////////////////
//
// CommonOptionsPage
//
///////////////////////////////////////////////////////////////////////
class CommonOptionsPage : public Core::IOptionsPage
{
public:
CommonOptionsPage() {}
// IOptionsPage
QString id() const
2010-03-11 12:22:24 +01:00
{ return _(DEBUGGER_COMMON_SETTINGS_ID); }
QString displayName() const
2010-03-11 12:22:24 +01:00
{ return QCoreApplication::translate("Debugger", DEBUGGER_COMMON_SETTINGS_NAME); }
QString category() const
2010-03-11 12:22:24 +01:00
{ return _(DEBUGGER_SETTINGS_CATEGORY); }
QString displayCategory() const
2010-03-11 12:22:24 +01:00
{ return QCoreApplication::translate("Debugger", DEBUGGER_SETTINGS_TR_CATEGORY); }
QIcon categoryIcon() const
{ return QIcon(QLatin1String(DEBUGGER_COMMON_SETTINGS_CATEGORY_ICON)); }
QWidget *createPage(QWidget *parent);
void apply() { m_group.apply(settings()); }
void finish() { m_group.finish(); }
virtual bool matches(const QString &s) const;
private:
Ui::CommonOptionsPage m_ui;
Utils::SavedActionSet m_group;
QString m_searchKeywords;
};
QWidget *CommonOptionsPage::createPage(QWidget *parent)
{
QWidget *w = new QWidget(parent);
m_ui.setupUi(w);
m_group.clear();
m_group.insert(theDebuggerAction(ListSourceFiles),
m_ui.checkBoxListSourceFiles);
m_group.insert(theDebuggerAction(UseAlternatingRowColors),
m_ui.checkBoxUseAlternatingRowColors);
m_group.insert(theDebuggerAction(UseToolTipsInMainEditor),
m_ui.checkBoxUseToolTipsInMainEditor);
m_group.insert(theDebuggerAction(CloseBuffersOnExit),
m_ui.checkBoxCloseBuffersOnExit);
m_group.insert(theDebuggerAction(SwitchModeOnExit),
m_ui.checkBoxSwitchModeOnExit);
m_group.insert(theDebuggerAction(AutoDerefPointers), 0);
m_group.insert(theDebuggerAction(UseToolTipsInLocalsView), 0);
m_group.insert(theDebuggerAction(UseToolTipsInBreakpointsView), 0);
m_group.insert(theDebuggerAction(UseAddressInBreakpointsView), 0);
m_group.insert(theDebuggerAction(UseAddressInStackView), 0);
m_group.insert(theDebuggerAction(MaximalStackDepth),
m_ui.spinBoxMaximalStackDepth);
m_group.insert(theDebuggerAction(ShowStdNamespace), 0);
m_group.insert(theDebuggerAction(ShowQtNamespace), 0);
m_group.insert(theDebuggerAction(SortStructMembers), 0);
m_group.insert(theDebuggerAction(LogTimeStamps), 0);
m_group.insert(theDebuggerAction(VerboseLog), 0);
m_group.insert(theDebuggerAction(BreakOnThrow), 0);
m_group.insert(theDebuggerAction(BreakOnCatch), 0);
#ifdef Q_OS_WIN
Utils::SavedAction *registerAction = theDebuggerAction(RegisterForPostMortem);
m_group.insert(registerAction,
m_ui.checkBoxRegisterForPostMortem);
connect(registerAction, SIGNAL(toggled(bool)),
m_ui.checkBoxRegisterForPostMortem, SLOT(setChecked(bool)));
#endif
if (m_searchKeywords.isEmpty()) {
QTextStream(&m_searchKeywords) << ' '
<< m_ui.checkBoxListSourceFiles->text()
<< ' ' << m_ui.checkBoxUseAlternatingRowColors->text()
<< ' ' << m_ui.checkBoxUseToolTipsInMainEditor->text()
#ifdef Q_OS_WIN
<< ' ' << m_ui.checkBoxRegisterForPostMortem->text()
#endif
<< ' ' << m_ui.labelMaximalStackDepth->text();
m_searchKeywords.remove(QLatin1Char('&'));
}
#ifndef Q_OS_WIN
m_ui.checkBoxRegisterForPostMortem->setVisible(false);
#endif
return w;
}
bool CommonOptionsPage::matches(const QString &s) const
{
return m_searchKeywords.contains(s, Qt::CaseInsensitive);
}
2009-03-23 12:28:02 +01:00
///////////////////////////////////////////////////////////////////////
//
// DebuggingHelperOptionPage
2009-03-23 12:28:02 +01:00
//
///////////////////////////////////////////////////////////////////////
static inline bool oxygenStyle()
{
if (const ManhattanStyle *ms = qobject_cast<const ManhattanStyle *>(qApp->style()))
return !qstrcmp("OxygenStyle", ms->baseStyle()->metaObject()->className());
return false;
}
class DebuggingHelperOptionPage : public Core::IOptionsPage
2010-07-08 12:40:38 +02:00
{ // Needs tr - context
Q_OBJECT
2009-03-23 12:28:02 +01:00
public:
DebuggingHelperOptionPage() {}
2009-03-23 12:28:02 +01:00
// IOptionsPage
2010-04-06 16:42:24 +02:00
QString id() const { return _("Z.DebuggingHelper"); }
QString displayName() const { return tr("Debugging Helper"); }
2010-03-11 12:22:24 +01:00
QString category() const { return _(DEBUGGER_SETTINGS_CATEGORY); }
QString displayCategory() const
{ return QCoreApplication::translate("Debugger", DEBUGGER_SETTINGS_TR_CATEGORY); }
QIcon categoryIcon() const
{ return QIcon(QLatin1String(DEBUGGER_COMMON_SETTINGS_CATEGORY_ICON)); }
2009-03-23 12:28:02 +01:00
QWidget *createPage(QWidget *parent);
void apply() { m_group.apply(settings()); }
void finish() { m_group.finish(); }
virtual bool matches(const QString &s) const;
2009-03-23 12:28:02 +01:00
private:
Ui::DebuggingHelperOptionPage m_ui;
Utils::SavedActionSet m_group;
QString m_searchKeywords;
2009-03-23 12:28:02 +01:00
};
QWidget *DebuggingHelperOptionPage::createPage(QWidget *parent)
2009-03-23 12:28:02 +01:00
{
QWidget *w = new QWidget(parent);
m_ui.setupUi(w);
m_ui.dumperLocationChooser->setExpectedKind(Utils::PathChooser::Command);
m_ui.dumperLocationChooser->setPromptDialogTitle(tr("Choose DebuggingHelper Location"));
m_ui.dumperLocationChooser->setInitialBrowsePathBackup(
Core::ICore::instance()->resourcePath() + "../../lib");
2009-03-23 12:28:02 +01:00
m_group.clear();
m_group.insert(theDebuggerAction(UseDebuggingHelpers),
m_ui.debuggingHelperGroupBox);
m_group.insert(theDebuggerAction(UseCustomDebuggingHelperLocation),
m_ui.customLocationGroupBox);
2010-03-11 12:22:24 +01:00
// Suppress Oxygen style's giving flat group boxes bold titles.
if (oxygenStyle())
2010-03-11 12:22:24 +01:00
m_ui.customLocationGroupBox->setStyleSheet(_("QGroupBox::title { font: ; }"));
m_group.insert(theDebuggerAction(CustomDebuggingHelperLocation),
m_ui.dumperLocationChooser);
2009-03-23 12:28:02 +01:00
m_group.insert(theDebuggerAction(UseCodeModel),
m_ui.checkBoxUseCodeModel);
#ifdef QT_DEBUG
m_group.insert(theDebuggerAction(DebugDebuggingHelpers),
m_ui.checkBoxDebugDebuggingHelpers);
#else
m_ui.checkBoxDebugDebuggingHelpers->hide();
#endif
2009-03-23 12:28:02 +01:00
#ifndef QT_DEBUG
#if 0
cmd = am->registerAction(m_manager->m_dumpLogAction,
2010-03-11 12:22:24 +01:00
DUMP_LOG, globalcontext);
2009-03-23 12:28:02 +01:00
//cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+D,Ctrl+L")));
cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+F11")));
mdebug->addAction(cmd);
#endif
#endif
if (m_searchKeywords.isEmpty()) {
QTextStream(&m_searchKeywords)
<< ' ' << m_ui.debuggingHelperGroupBox->title()
<< ' ' << m_ui.customLocationGroupBox->title()
<< ' ' << m_ui.dumperLocationLabel->text()
<< ' ' << m_ui.checkBoxUseCodeModel->text()
<< ' ' << m_ui.checkBoxDebugDebuggingHelpers->text();
m_searchKeywords.remove(QLatin1Char('&'));
}
2009-03-23 12:28:02 +01:00
return w;
}
bool DebuggingHelperOptionPage::matches(const QString &s) const
2009-03-27 13:04:23 +01:00
{
return m_searchKeywords.contains(s, Qt::CaseInsensitive);
2009-03-27 13:04:23 +01:00
}
2008-12-02 12:01:29 +01:00
///////////////////////////////////////////////////////////////////////
//
// Argument parsing
2008-12-02 12:01:29 +01:00
//
///////////////////////////////////////////////////////////////////////
static QString msgParameterMissing(const QString &a)
{
return DebuggerPlugin::tr("Option '%1' is missing the parameter.").arg(a);
}
static QString msgInvalidNumericParameter(const QString &a, const QString &number)
{
return DebuggerPlugin::tr("The parameter '%1' of option '%2' is not a number.").arg(number, a);
}
static bool parseArgument(QStringList::const_iterator &it,
const QStringList::const_iterator &cend,
AttachRemoteParameters *attachRemoteParameters,
unsigned *enabledEngines, QString *errorMessage)
{
const QString &option = *it;
// '-debug <pid>'
// '-debug <corefile>'
// '-debug <server:port>'
2010-03-11 12:22:24 +01:00
if (*it == _("-debug")) {
++it;
if (it == cend) {
*errorMessage = msgParameterMissing(*it);
return false;
}
bool ok;
attachRemoteParameters->attachPid = it->toULongLong(&ok);
if (!ok)
attachRemoteParameters->attachTarget = *it;
return true;
}
// -wincrashevent <event-handle>. A handle used for
// a handshake when attaching to a crashed Windows process.
2010-03-11 12:22:24 +01:00
if (*it == _("-wincrashevent")) {
++it;
if (it == cend) {
*errorMessage = msgParameterMissing(*it);
return false;
}
bool ok;
attachRemoteParameters->winCrashEvent = it->toULongLong(&ok);
if (!ok) {
*errorMessage = msgInvalidNumericParameter(option, *it);
return false;
}
return true;
}
// Engine disabling.
2010-03-11 12:22:24 +01:00
if (option == _("-disable-cdb")) {
*enabledEngines &= ~Debugger::CdbEngineType;
return true;
}
2010-03-11 12:22:24 +01:00
if (option == _("-disable-gdb")) {
*enabledEngines &= ~Debugger::GdbEngineType;
return true;
}
if (option == _("-disable-qmldb")) {
*enabledEngines &= ~Debugger::QmlEngineType;
return true;
}
2010-03-11 12:22:24 +01:00
if (option == _("-disable-sdb")) {
*enabledEngines &= ~Debugger::ScriptEngineType;
return true;
}
if (option == _("-disable-tcf")) {
*enabledEngines &= ~TcfEngineType;
return true;
}
*errorMessage = DebuggerPlugin::tr("Invalid debugger option: %1").arg(option);
return false;
}
static bool parseArguments(const QStringList &args,
AttachRemoteParameters *attachRemoteParameters,
unsigned *enabledEngines, QString *errorMessage)
{
attachRemoteParameters->clear();
const QStringList::const_iterator cend = args.constEnd();
for (QStringList::const_iterator it = args.constBegin(); it != cend; ++it)
if (!parseArgument(it, cend, attachRemoteParameters, enabledEngines, errorMessage))
return false;
if (Debugger::Constants::Internal::debug)
qDebug().nospace() << args << "engines=0x"
<< QString::number(*enabledEngines, 16)
<< " pid" << attachRemoteParameters->attachPid
<< " target" << attachRemoteParameters->attachTarget << '\n';
return true;
}
///////////////////////////////////////////////////////////////////////
//
// Misc
//
///////////////////////////////////////////////////////////////////////
static bool isDebuggable(Core::IEditor *editor)
{
// Only blacklist Qml. Whitelisting would fail on C++ code in files
// with strange names, more harm would be done this way.
//Core::IFile *file = editor->file();
//return !(file && file->mimeType() == "application/x-qml");
// Nowadays, even Qml is debuggable.
Q_UNUSED(editor);
return true;
}
2008-12-02 12:01:29 +01:00
///////////////////////////////////////////////////////////////////////
//
// DebuggerPluginPrivate
//
///////////////////////////////////////////////////////////////////////
2008-12-02 12:01:29 +01:00
struct DebuggerActions
{
QAction *continueAction;
QAction *exitAction; // on the application output button if "Stop" is possible
QAction *interruptAction; // on the fat debug button if "Pause" is possible
QAction *undisturbableAction; // on the fat debug button if nothing can be done
QAction *resetAction; // FIXME: Should not be needed in a stable release
QAction *stepAction;
QAction *stepOutAction;
QAction *runToLineAction; // Debug menu
QAction *runToFunctionAction;
QAction *jumpToLineAction; // in the Debug menu
QAction *returnFromFunctionAction;
QAction *nextAction;
//QAction *snapshotAction;
QAction *watchAction1; // in the Debug menu
QAction *watchAction2; // in the text editor context menu
QAction *breakAction;
QAction *sepAction;
QAction *reverseDirectionAction;
QAction *frameUpAction;
QAction *frameDownAction;
};
2008-12-02 12:01:29 +01:00
} // namespace Internal
2008-12-02 12:01:29 +01:00
using namespace Debugger::Internal;
2008-12-02 12:01:29 +01:00
///////////////////////////////////////////////////////////////////////
//
// DebuggerPluginPrivate
//
///////////////////////////////////////////////////////////////////////
2008-12-02 12:01:29 +01:00
class DebuggerPluginPrivate : public QObject
{
Q_OBJECT
public:
explicit DebuggerPluginPrivate(DebuggerPlugin *plugin);
bool initialize(const QStringList &arguments, QString *errorMessage);
void connectEngine(DebuggerEngine *engine, bool notify = true);
2010-11-04 18:11:09 +01:00
void disconnectEngine() { connectEngine(0); }
DebuggerEngine *currentEngine() const { return m_currentEngine; }
public slots:
void selectThread(int index)
{
currentEngine()->selectThread(index);
}
void breakpointSetRemoveMarginActionTriggered()
{
QString fileName;
int lineNumber;
quint64 address;
if (positionFromContextActionData(sender(), &fileName, &lineNumber, &address))
m_breakHandler->toggleBreakpoint(fileName, lineNumber, address);
}
void breakpointEnableDisableMarginActionTriggered()
{
QString fileName;
int lineNumber;
if (positionFromContextActionData(sender(), &fileName, &lineNumber))
m_breakHandler->toggleBreakpointEnabled(fileName, lineNumber);
}
void updateWatchersHeader(int section, int, int newSize)
{
m_watchersWindow->header()->resizeSection(section, newSize);
}
void sourceFilesDockToggled(bool on)
{
if (on)
m_currentEngine->reloadSourceFiles();
}
void modulesDockToggled(bool on)
{
if (on)
m_currentEngine->reloadModules();
}
2010-06-22 12:02:24 +02:00
void registerDockToggled(bool on)
{
if (on)
m_currentEngine->reloadRegisters();
}
void synchronizeBreakpoints()
{
for (int i = 0, n = m_snapshotHandler->size(); i != n; ++i) {
if (DebuggerRunControl *runControl = m_snapshotHandler->at(i)) {
DebuggerEngine *engine = runControl->engine();
engine->attemptBreakpointSynchronization();
}
}
}
2010-11-04 18:11:09 +01:00
void synchronizeWatchers()
{
for (int i = 0, n = m_snapshotHandler->size(); i != n; ++i) {
if (DebuggerRunControl *runControl = m_snapshotHandler->at(i)) {
DebuggerEngine *engine = runControl->engine();
engine->watchHandler()->synchronizeWatchers();
}
}
}
void setSimpleDockWidgetArrangement(Debugger::DebuggerLanguages activeLanguages);
void editorOpened(Core::IEditor *editor);
void editorAboutToClose(Core::IEditor *editor);
void setBusyCursor(bool busy);
void requestMark(TextEditor::ITextEditor *editor, int lineNumber);
void showToolTip(TextEditor::ITextEditor *editor, const QPoint &pnt, int pos);
void requestContextMenu(TextEditor::ITextEditor *editor,
int lineNumber, QMenu *menu);
void activatePreviousMode();
void activateDebugMode();
void toggleBreakpoint();
void toggleBreakpoint(const QString &fileName, int lineNumber);
void onModeChanged(Core::IMode *mode);
void showSettingsDialog();
void startExternalApplication();
void startRemoteApplication();
void attachExternalApplication();
void attachExternalApplication
(qint64 pid, const QString &binary, const QString &crashParameter);
bool attachCmdLine();
void attachCore();
void attachCore(const QString &core, const QString &exeFileName);
void attachRemote(const QString &spec);
void attachRemoteTcf();
void enableReverseDebuggingTriggered(const QVariant &value);
void languagesChanged(const Debugger::DebuggerLanguages &languages);
void showStatusMessage(const QString &msg, int timeout = -1);
void openMemoryEditor();
DebuggerMainWindow *mainWindow()
{ return qobject_cast<DebuggerMainWindow*>
(DebuggerUISwitcher::instance()->mainWindow()); }
inline void setConfigValue(const QString &name, const QVariant &value);
inline QVariant configValue(const QString &name) const;
DebuggerRunControl *createDebugger(const DebuggerStartParameters &sp,
2010-08-31 13:07:33 +02:00
RunConfiguration *rc = 0);
void startDebugger(RunControl *runControl);
void displayDebugger(DebuggerEngine *engine, bool updateEngine = true);
void dumpLog();
void cleanupViews();
void setInitialState();
void fontSettingsChanged(const TextEditor::FontSettings &settings);
DebuggerState state() const { return m_state; }
void updateState(DebuggerEngine *engine);
void onCurrentProjectChanged(ProjectExplorer::Project *project);
void gotoLocation(const QString &file, int line, bool setMarker);
void clearStatusMessage();
void sessionLoaded();
void aboutToUnloadSession();
void aboutToSaveSession();
void executeDebuggerCommand();
2010-08-31 13:07:33 +02:00
void scriptExpressionEntered(const QString &expression);
void coreShutdown();
public slots:
void handleExecDetach() { currentEngine()->detachDebugger(); }
void handleExecContinue() { currentEngine()->continueInferior(); }
void handleExecInterrupt() { currentEngine()->requestInterruptInferior(); }
void handleExecReset() { currentEngine()->notifyEngineIll(); } // FIXME: Check.
void handleExecStep()
{
resetLocation();
if (theDebuggerBoolSetting(OperateByInstruction))
currentEngine()->executeStepI();
else
currentEngine()->executeStep();
}
void handleExecNext()
{
resetLocation();
if (theDebuggerBoolSetting(OperateByInstruction))
currentEngine()->executeNextI();
else
currentEngine()->executeNext();
}
void handleExecStepOut()
{
resetLocation();
currentEngine()->executeStepOut();
}
void handleExecReturn()
{
resetLocation();
currentEngine()->executeReturn();
}
void handleExecJumpToLine()
{
//removeTooltip();
resetLocation();
QString fileName;
int lineNumber;
if (currentTextEditorPosition(&fileName, &lineNumber))
currentEngine()->executeJumpToLine(fileName, lineNumber);
}
void handleExecRunToLine()
{
//removeTooltip();
resetLocation();
QString fileName;
int lineNumber;
if (currentTextEditorPosition(&fileName, &lineNumber))
currentEngine()->executeRunToLine(fileName, lineNumber);
}
void handleExecRunToFunction()
{
resetLocation();
ITextEditor *textEditor = currentTextEditor();
QTC_ASSERT(textEditor, return);
QPlainTextEdit *ed = qobject_cast<QPlainTextEdit*>(textEditor->widget());
if (!ed)
return;
QTextCursor cursor = ed->textCursor();
QString functionName = cursor.selectedText();
if (functionName.isEmpty()) {
const QTextBlock block = cursor.block();
const QString line = block.text();
foreach (const QString &str, line.trimmed().split('(')) {
QString a;
for (int i = str.size(); --i >= 0; ) {
if (!str.at(i).isLetterOrNumber())
break;
a = str.at(i) + a;
}
if (!a.isEmpty()) {
functionName = a;
break;
}
}
}
if (!functionName.isEmpty())
currentEngine()->executeRunToFunction(functionName);
}
void slotEditBreakpoint()
{
const QAction *act = qobject_cast<QAction *>(sender());
QTC_ASSERT(act, return);
const QVariant data = act->data();
QTC_ASSERT(qVariantCanConvert<BreakpointData *>(data), return);
BreakpointData *breakPointData = qvariant_cast<BreakpointData *>(data);
BreakWindow::editBreakpoint(breakPointData, ICore::instance()->mainWindow());
}
void slotRunToLine()
{
// Run to line, file name and line number set as list.
QString fileName;
int lineNumber;
if (positionFromContextActionData(sender(), &fileName, &lineNumber))
handleExecRunToLine();
}
void slotJumpToLine()
{
QString fileName;
int lineNumber;
if (positionFromContextActionData(sender(), &fileName, &lineNumber))
currentEngine()->executeJumpToLine(fileName, lineNumber);
}
void handleAddToWatchWindow()
{
// Requires a selection, but that's the only case we want anyway.
EditorManager *editorManager = EditorManager::instance();
if (!editorManager)
return;
IEditor *editor = editorManager->currentEditor();
if (!editor)
return;
ITextEditor *textEditor = qobject_cast<ITextEditor*>(editor);
if (!textEditor)
return;
QTextCursor tc;
QPlainTextEdit *ptEdit = qobject_cast<QPlainTextEdit*>(editor->widget());
if (ptEdit)
tc = ptEdit->textCursor();
QString exp;
if (tc.hasSelection()) {
exp = tc.selectedText();
} else {
int line, column;
exp = cppExpressionAt(textEditor, tc.position(), &line, &column);
}
if (exp.isEmpty())
return;
currentEngine()->watchHandler()->watchExpression(exp);
}
void handleExecExit()
{
currentEngine()->exitDebugger();
}
void handleFrameDown()
{
currentEngine()->frameDown();
}
void handleFrameUp()
{
currentEngine()->frameUp();
}
void handleOperateByInstructionTriggered()
{
currentEngine()->gotoLocation(
currentEngine()->stackHandler()->currentFrame(), true);
}
void resetLocation()
{
// FIXME: code should be moved here.
currentEngine()->resetLocation();
//d->m_disassemblerViewAgent.resetLocation();
//d->m_stackHandler.setCurrentIndex(-1);
//plugin()->resetLocation();
}
public:
DebuggerState m_state;
DebuggerUISwitcher *m_uiSwitcher;
DebuggerPlugin *m_manager;
DebugMode *m_debugMode;
DebuggerRunControlFactory *m_debuggerRunControlFactory;
QString m_previousMode;
QScopedPointer<TextEditor::BaseTextMark> m_locationMark;
Core::Context m_continuableContext;
Core::Context m_interruptibleContext;
Core::Context m_undisturbableContext;
Core::Context m_finishedContext;
Core::Context m_anyContext;
AttachRemoteParameters m_attachRemoteParameters;
QAction *m_startExternalAction;
QAction *m_startRemoteAction;
QAction *m_attachExternalAction;
QAction *m_attachCoreAction;
QAction *m_attachTcfAction;
QAction *m_detachAction;
QComboBox *m_langBox;
QToolButton *m_reverseToolButton;
QIcon m_startIcon;
QIcon m_exitIcon;
QIcon m_continueIcon;
QIcon m_interruptIcon;
QIcon m_locationMarkIcon;
QLabel *m_statusLabel;
QComboBox *m_threadBox;
QDockWidget *m_breakDock;
//QDockWidget *m_consoleDock;
QDockWidget *m_modulesDock;
QDockWidget *m_outputDock;
QDockWidget *m_registerDock;
QDockWidget *m_snapshotDock;
QDockWidget *m_sourceFilesDock;
QDockWidget *m_stackDock;
QDockWidget *m_threadsDock;
QDockWidget *m_watchDock;
QDockWidget* m_scriptConsoleDock;
DebuggerActions m_actions;
BreakWindow *m_breakWindow;
BreakHandler *m_breakHandler;
//ConsoleWindow *m_consoleWindow;
QTreeView *m_returnWindow;
QTreeView *m_localsWindow;
QTreeView *m_watchersWindow;
QAbstractItemView *m_registerWindow;
QAbstractItemView *m_modulesWindow;
QAbstractItemView *m_snapshotWindow;
SourceFilesWindow *m_sourceFilesWindow;
QAbstractItemView *m_stackWindow;
QAbstractItemView *m_threadsWindow;
LogWindow *m_logWindow;
ScriptConsole *m_scriptConsoleWindow;
bool m_busy;
QTimer m_statusTimer;
QString m_lastPermanentStatusMessage;
CPlusPlus::Snapshot m_codeModelSnapshot;
DebuggerPlugin *m_plugin;
SnapshotHandler *m_snapshotHandler;
bool m_shuttingDown;
2010-11-04 18:11:09 +01:00
DebuggerEngine *m_currentEngine;
};
2010-11-04 18:11:09 +01:00
DebuggerPluginPrivate::DebuggerPluginPrivate(DebuggerPlugin *plugin)
{
m_plugin = plugin;
2010-11-04 18:11:09 +01:00
m_shuttingDown = false;
m_statusLabel = 0;
m_threadBox = 0;
m_breakDock = 0;
//m_consoleDock = 0;
m_modulesDock = 0;
m_outputDock = 0;
m_registerDock = 0;
m_snapshotDock = 0;
m_sourceFilesDock = 0;
m_stackDock = 0;
m_threadsDock = 0;
m_watchDock = 0;
m_breakWindow = 0;
m_breakHandler = 0;
m_returnWindow = 0;
m_localsWindow = 0;
m_watchersWindow = 0;
m_registerWindow = 0;
m_modulesWindow = 0;
m_snapshotWindow = 0;
m_sourceFilesWindow = 0;
m_stackWindow = 0;
m_threadsWindow = 0;
m_logWindow = 0;
m_scriptConsoleWindow = 0;
m_debugMode = 0;
m_continuableContext = Core::Context(0);
m_interruptibleContext = Core::Context(0);
m_undisturbableContext = Core::Context(0);
m_finishedContext = Core::Context(0);
m_anyContext = Core::Context(0);
m_debugMode = 0;
m_uiSwitcher = 0;
2010-06-22 14:23:22 +02:00
m_state = DebuggerNotReady;
m_snapshotHandler = 0;
2010-11-04 18:11:09 +01:00
m_currentEngine = 0;
}
bool DebuggerPluginPrivate::initialize(const QStringList &arguments, QString *errorMessage)
{
m_continuableContext = Core::Context("Gdb.Continuable");
m_interruptibleContext = Core::Context("Gdb.Interruptible");
m_undisturbableContext = Core::Context("Gdb.Undisturbable");
m_finishedContext = Core::Context("Gdb.Finished");
m_anyContext.add(m_continuableContext);
m_anyContext.add(m_interruptibleContext);
m_anyContext.add(m_undisturbableContext);
m_anyContext.add(m_finishedContext);
// FIXME: Move part of this to extensionsInitialized()?
ICore *core = ICore::instance();
QTC_ASSERT(core, return false);
connect(core, SIGNAL(coreAboutToClose()), this, SLOT(coreShutdown()));
Core::ActionManager *am = core->actionManager();
QTC_ASSERT(am, return false);
const Core::Context globalcontext(CC::C_GLOBAL);
const Core::Context cppDebuggercontext(C_CPPDEBUGGER);
const Core::Context qmlDebuggerContext(C_QMLDEBUGGER);
const Core::Context cppeditorcontext(CppEditor::Constants::C_CPPEDITOR);
m_startIcon = QIcon(_(":/debugger/images/debugger_start_small.png"));
m_startIcon.addFile(__(":/debugger/images/debugger_start.png"));
m_exitIcon = QIcon(_(":/debugger/images/debugger_stop_small.png"));
m_exitIcon.addFile(__(":/debugger/images/debugger_stop.png"));
m_continueIcon = QIcon(__(":/debugger/images/debugger_continue_small.png"));
m_continueIcon.addFile(__(":/debugger/images/debugger_continue.png"));
m_interruptIcon = QIcon(_(":/debugger/images/debugger_interrupt_small.png"));
m_interruptIcon.addFile(__(":/debugger/images/debugger_interrupt.png"));
m_locationMarkIcon = QIcon(_(":/debugger/images/location_16.png"));
m_busy = false;
m_statusLabel = new QLabel;
m_statusLabel->setMinimumSize(QSize(30, 10));
m_breakHandler = new BreakHandler;
connect(m_breakHandler, SIGNAL(breakpointSynchronizationRequested()),
SLOT(synchronizeBreakpoints()));
m_breakWindow = new BreakWindow;
m_breakWindow->setObjectName(QLatin1String("CppDebugBreakpoints"));
2010-11-04 18:11:09 +01:00
m_breakWindow->setModel(m_breakHandler->model());
//m_consoleWindow = new ConsoleWindow;
//m_consoleWindow->setObjectName(QLatin1String("CppDebugConsole"));
m_modulesWindow = new ModulesWindow;
m_modulesWindow->setObjectName(QLatin1String("CppDebugModules"));
m_logWindow = new LogWindow;
m_logWindow->setObjectName(QLatin1String("CppDebugOutput"));
m_registerWindow = new RegisterWindow;
m_registerWindow->setObjectName(QLatin1String("CppDebugRegisters"));
m_stackWindow = new StackWindow;
m_stackWindow->setObjectName(QLatin1String("CppDebugStack"));
m_sourceFilesWindow = new SourceFilesWindow;
m_sourceFilesWindow->setObjectName(QLatin1String("CppDebugSources"));
m_threadsWindow = new ThreadsWindow;
m_threadsWindow->setObjectName(QLatin1String("CppDebugThreads"));
m_returnWindow = new WatchWindow(WatchWindow::ReturnType);
m_returnWindow->setObjectName(QLatin1String("CppDebugReturn"));
m_localsWindow = new WatchWindow(WatchWindow::LocalsType);
m_localsWindow->setObjectName(QLatin1String("CppDebugLocals"));
m_watchersWindow = new WatchWindow(WatchWindow::WatchersType);
m_watchersWindow->setObjectName(QLatin1String("CppDebugWatchers"));
m_scriptConsoleWindow = new ScriptConsole;
m_scriptConsoleWindow->setWindowTitle(tr("QML Script Console"));
2010-09-22 14:07:35 +02:00
m_scriptConsoleWindow->setObjectName(QLatin1String("QMLScriptConsole"));
2010-08-31 13:07:33 +02:00
connect(m_scriptConsoleWindow, SIGNAL(expressionEntered(QString)),
SLOT(scriptExpressionEntered(QString)));
// Snapshot
m_snapshotHandler = new SnapshotHandler;
m_snapshotWindow = new SnapshotWindow(m_snapshotHandler);
m_snapshotWindow->setObjectName(QLatin1String("CppDebugSnapshots"));
m_snapshotWindow->setModel(m_snapshotHandler->model());
// Debug mode setup
m_debugMode = new DebugMode(this);
// Watchers
connect(m_localsWindow->header(), SIGNAL(sectionResized(int,int,int)),
SLOT(updateWatchersHeader(int,int,int)), Qt::QueuedConnection);
QAction *act = 0;
act = m_actions.continueAction = new QAction(tr("Continue"), this);
act->setIcon(m_continueIcon);
connect(act, SIGNAL(triggered()), SLOT(handleExecContinue()));
act = m_actions.exitAction = new QAction(tr("Exit Debugger"), this);
act->setIcon(m_exitIcon);
connect(act, SIGNAL(triggered()), SLOT(handleExecExit()));
act = m_actions.interruptAction = new QAction(tr("Interrupt"), this);
act->setIcon(m_interruptIcon);
connect(act, SIGNAL(triggered()), SLOT(handleExecInterrupt()));
// A "disabled pause" seems to be a good choice.
act = m_actions.undisturbableAction = new QAction(tr("Debugger is Busy"), this);
act->setIcon(m_interruptIcon);
act->setEnabled(false);
act = m_actions.resetAction = new QAction(tr("Abort Debugging"), this);
act->setToolTip(tr("Aborts debugging and "
"resets the debugger to the initial state."));
connect(act, SIGNAL(triggered()), SLOT(handleExecReset()));
act = m_actions.nextAction = new QAction(tr("Step Over"), this);
act->setIcon(QIcon(__(":/debugger/images/debugger_stepover_small.png")));
connect(act, SIGNAL(triggered()), SLOT(handleExecNext()));
act = m_actions.stepAction = new QAction(tr("Step Into"), this);
act->setIcon(QIcon(__(":/debugger/images/debugger_stepinto_small.png")));
connect(act, SIGNAL(triggered()), SLOT(handleExecStep()));
act = m_actions.stepOutAction = new QAction(tr("Step Out"), this);
act->setIcon(QIcon(__(":/debugger/images/debugger_stepout_small.png")));
connect(act, SIGNAL(triggered()), SLOT(handleExecStepOut()));
act = m_actions.runToLineAction = new QAction(tr("Run to Line"), this);
connect(act, SIGNAL(triggered()), SLOT(handleExecRunToLine()));
act = m_actions.runToFunctionAction =
new QAction(tr("Run to Outermost Function"), this);
connect(act, SIGNAL(triggered()), SLOT(handleExecRunToFunction()));
act = m_actions.returnFromFunctionAction =
new QAction(tr("Immediately Return From Inner Function"), this);
connect(act, SIGNAL(triggered()), SLOT(handleExecReturn()));
act = m_actions.jumpToLineAction = new QAction(tr("Jump to Line"), this);
connect(act, SIGNAL(triggered()), SLOT(handleExecJumpToLine()));
act = m_actions.breakAction = new QAction(tr("Toggle Breakpoint"), this);
act = m_actions.watchAction1 = new QAction(tr("Add to Watch Window"), this);
connect(act, SIGNAL(triggered()), SLOT(handleAddToWatchWindow()));
act = m_actions.watchAction2 = new QAction(tr("Add to Watch Window"), this);
connect(act, SIGNAL(triggered()), SLOT(handleAddToWatchWindow()));
//m_actions.snapshotAction = new QAction(tr("Create Snapshot"), this);
//m_actions.snapshotAction->setProperty(Role, RequestCreateSnapshotRole);
//m_actions.snapshotAction->setIcon(
// QIcon(__(":/debugger/images/debugger_snapshot_small.png")));
act = m_actions.reverseDirectionAction =
new QAction(tr("Reverse Direction"), this);
act->setCheckable(true);
act->setChecked(false);
act->setCheckable(false);
act->setIcon(QIcon(__(":/debugger/images/debugger_reversemode_16.png")));
act->setIconVisibleInMenu(false);
act = m_actions.frameDownAction = new QAction(tr("Move to Called Frame"), this);
connect(act, SIGNAL(triggered()), SLOT(handleFrameDown()));
act = m_actions.frameUpAction = new QAction(tr("Move to Calling Frame"), this);
connect(act, SIGNAL(triggered()), SLOT(handleFrameUp()));
connect(theDebuggerAction(OperateByInstruction), SIGNAL(triggered()),
SLOT(handleOperateByInstructionTriggered()));
connect(&m_statusTimer, SIGNAL(timeout()), SLOT(clearStatusMessage()));
connect(theDebuggerAction(ExecuteCommand), SIGNAL(triggered()),
2010-06-22 11:42:28 +02:00
SLOT(executeDebuggerCommand()));
m_plugin->readSettings();
// Cpp/Qml ui setup
m_uiSwitcher = new DebuggerUISwitcher(m_debugMode, this);
ExtensionSystem::PluginManager::instance()->addObject(m_uiSwitcher);
m_uiSwitcher->addLanguage(CppLanguage, cppDebuggercontext);
m_uiSwitcher->addLanguage(QmlLanguage, qmlDebuggerContext);
// Dock widgets
m_breakDock = m_uiSwitcher->createDockWidget(CppLanguage, m_breakWindow);
m_breakDock->setObjectName(QString(DOCKWIDGET_BREAK));
//m_consoleDock = m_uiSwitcher->createDockWidget(CppLanguage, m_consoleWindow,
// Qt::TopDockWidgetArea);
//m_consoleDock->setObjectName(QString(DOCKWIDGET_OUTPUT));
m_modulesDock = m_uiSwitcher->createDockWidget(CppLanguage, m_modulesWindow,
Qt::TopDockWidgetArea);
m_modulesDock->setObjectName(QString(DOCKWIDGET_MODULES));
connect(m_modulesDock->toggleViewAction(), SIGNAL(toggled(bool)),
2010-06-22 12:02:24 +02:00
SLOT(modulesDockToggled(bool)), Qt::QueuedConnection);
m_registerDock = m_uiSwitcher->createDockWidget(CppLanguage, m_registerWindow,
Qt::TopDockWidgetArea);
m_registerDock->setObjectName(QString(DOCKWIDGET_REGISTER));
connect(m_registerDock->toggleViewAction(), SIGNAL(toggled(bool)),
2010-06-22 12:02:24 +02:00
SLOT(registerDockToggled(bool)), Qt::QueuedConnection);
m_outputDock = m_uiSwitcher->createDockWidget(AnyLanguage, m_logWindow,
Qt::TopDockWidgetArea);
m_outputDock->setObjectName(QString(DOCKWIDGET_OUTPUT));
m_snapshotDock = m_uiSwitcher->createDockWidget(CppLanguage, m_snapshotWindow);
m_snapshotDock->setObjectName(QString(DOCKWIDGET_SNAPSHOTS));
m_stackDock = m_uiSwitcher->createDockWidget(CppLanguage, m_stackWindow);
m_stackDock->setObjectName(QString(DOCKWIDGET_STACK));
2010-06-22 12:02:24 +02:00
m_sourceFilesDock = m_uiSwitcher->createDockWidget(CppLanguage,
m_sourceFilesWindow, Qt::TopDockWidgetArea);
m_sourceFilesDock->setObjectName(QString(DOCKWIDGET_SOURCE_FILES));
connect(m_sourceFilesDock->toggleViewAction(), SIGNAL(toggled(bool)),
2010-06-22 12:02:24 +02:00
SLOT(sourceFilesDockToggled(bool)), Qt::QueuedConnection);
m_threadsDock = m_uiSwitcher->createDockWidget(CppLanguage, m_threadsWindow);
m_threadsDock->setObjectName(QString(DOCKWIDGET_THREADS));
QSplitter *localsAndWatchers = new Core::MiniSplitter(Qt::Vertical);
localsAndWatchers->setObjectName(QLatin1String("CppDebugLocalsAndWatchers"));
localsAndWatchers->setWindowTitle(m_localsWindow->windowTitle());
localsAndWatchers->addWidget(m_localsWindow);
localsAndWatchers->addWidget(m_returnWindow);
localsAndWatchers->addWidget(m_watchersWindow);
localsAndWatchers->setStretchFactor(0, 3);
localsAndWatchers->setStretchFactor(1, 1);
localsAndWatchers->setStretchFactor(2, 1);
m_watchDock = m_uiSwitcher->createDockWidget(CppLanguage, localsAndWatchers);
m_watchDock->setObjectName(QString(DOCKWIDGET_WATCHERS));
2010-08-31 13:07:33 +02:00
m_scriptConsoleDock =
m_uiSwitcher->createDockWidget(QmlLanguage, m_scriptConsoleWindow);
m_scriptConsoleDock->setObjectName(QString(DOCKWIDGET_QML_SCRIPTCONSOLE));
2010-11-08 16:29:00 +01:00
// Do not fail to load the whole plugin if something goes wrong here.
uint cmdLineEnabledEngines = AllEngineTypes;
if (!parseArguments(arguments, &m_attachRemoteParameters,
&cmdLineEnabledEngines, errorMessage)) {
*errorMessage = tr("Error evaluating command line arguments: %1")
.arg(*errorMessage);
qWarning("%s\n", qPrintable(*errorMessage));
errorMessage->clear();
}
// Register factory of DebuggerRunControl.
m_debuggerRunControlFactory = new DebuggerRunControlFactory
(m_plugin, DebuggerEngineType(cmdLineEnabledEngines));
m_plugin->addAutoReleasedObject(m_debuggerRunControlFactory);
m_debugMode->setContext(
Core::Context(CC::C_EDITORMANAGER, C_DEBUGMODE, CC::C_NAVIGATION_PANE));
m_reverseToolButton = 0;
// Handling of external applications.
2010-11-09 10:23:10 +01:00
act = m_startExternalAction = new QAction(this);
act->setText(tr("Start and Debug External Application..."));
connect(act, SIGNAL(triggered()), SLOT(startExternalApplication()));
act = m_attachExternalAction = new QAction(this);
act->setText(tr("Attach to Running External Application..."));
connect(act, SIGNAL(triggered()), SLOT(attachExternalApplication()));
act = m_attachCoreAction = new QAction(this);
act->setText(tr("Attach to Core..."));
connect(act, SIGNAL(triggered()), SLOT(attachCore()));
act = m_attachTcfAction = new QAction(this);
act->setText(tr("Attach to Running Tcf Agent..."));
act->setToolTip(tr("This attaches to a running "
"'Target Communication Framework' agent."));
2010-11-09 10:23:10 +01:00
connect(act, SIGNAL(triggered()), SLOT(attachRemoteTcf()));
2010-11-09 10:23:10 +01:00
act = m_startRemoteAction = new QAction(this);
act->setText(tr("Start and Attach to Remote Application..."));
connect(act, SIGNAL(triggered()), SLOT(startRemoteApplication()));
2010-11-09 10:23:10 +01:00
act = m_detachAction = new QAction(this);
act->setText(tr("Detach Debugger"));
connect(act, SIGNAL(triggered()), SLOT(handleExecDetach()));
Core::Command *cmd = 0;
Core::ActionContainer *mstart =
am->actionContainer(PE::M_DEBUG_STARTDEBUGGING);
cmd = am->registerAction(m_actions.continueAction,
PE::DEBUG, m_continuableContext);
2010-03-11 12:22:24 +01:00
mstart->addAction(cmd, CC::G_DEFAULT_ONE);
cmd = am->registerAction(m_startExternalAction,
2008-12-02 12:01:29 +01:00
Constants::STARTEXTERNAL, globalcontext);
cmd->setAttribute(Command::CA_Hide);
2010-03-11 12:22:24 +01:00
mstart->addAction(cmd, CC::G_DEFAULT_ONE);
2008-12-02 12:01:29 +01:00
cmd = am->registerAction(m_attachExternalAction,
2008-12-02 12:01:29 +01:00
Constants::ATTACHEXTERNAL, globalcontext);
cmd->setAttribute(Command::CA_Hide);
2010-03-11 12:22:24 +01:00
mstart->addAction(cmd, CC::G_DEFAULT_ONE);
cmd = am->registerAction(m_attachCoreAction,
Constants::ATTACHCORE, globalcontext);
cmd->setAttribute(Command::CA_Hide);
2010-03-11 12:22:24 +01:00
mstart->addAction(cmd, CC::G_DEFAULT_ONE);
cmd = am->registerAction(m_attachTcfAction,
Constants::ATTACHTCF, globalcontext);
mstart->addAction(cmd, Core::Constants::G_DEFAULT_ONE);
cmd = am->registerAction(m_startRemoteAction,
Constants::ATTACHREMOTE, globalcontext);
cmd->setAttribute(Command::CA_Hide);
2010-03-11 12:22:24 +01:00
mstart->addAction(cmd, CC::G_DEFAULT_ONE);
cmd = am->registerAction(m_detachAction,
Constants::DETACH, globalcontext);
cmd->setAttribute(Command::CA_Hide);
m_uiSwitcher->addMenuAction(cmd, AnyLanguage, CC::G_DEFAULT_ONE);
2008-12-02 12:01:29 +01:00
cmd = am->registerAction(m_actions.exitAction,
Constants::STOP, globalcontext);
//cmd->setDefaultKeySequence(QKeySequence(Constants::STOP_KEY));
cmd->setDefaultText(tr("Stop Debugger"));
m_uiSwitcher->addMenuAction(cmd, AnyLanguage, CC::G_DEFAULT_ONE);
2008-12-02 12:01:29 +01:00
cmd = am->registerAction(m_actions.interruptAction,
PE::DEBUG, m_interruptibleContext);
cmd->setDefaultText(tr("Interrupt Debugger"));
cmd = am->registerAction(m_actions.undisturbableAction,
PE::DEBUG, m_undisturbableContext);
cmd->setDefaultText(tr("Debugger is Busy"));
cmd = am->registerAction(m_actions.resetAction,
2008-12-02 12:01:29 +01:00
Constants::RESET, globalcontext);
//cmd->setDefaultKeySequence(QKeySequence(Constants::RESET_KEY));
2008-12-02 12:01:29 +01:00
cmd->setDefaultText(tr("Reset Debugger"));
m_uiSwitcher->addMenuAction(cmd, AnyLanguage, CC::G_DEFAULT_ONE);
2008-12-02 12:01:29 +01:00
QAction *sep = new QAction(this);
sep->setSeparator(true);
2010-03-11 12:22:24 +01:00
cmd = am->registerAction(sep, _("Debugger.Sep.Step"), globalcontext);
m_uiSwitcher->addMenuAction(cmd, CppLanguage);
2008-12-02 12:01:29 +01:00
cmd = am->registerAction(m_actions.nextAction,
Constants::NEXT, cppDebuggercontext);
2008-12-02 12:01:29 +01:00
cmd->setDefaultKeySequence(QKeySequence(Constants::NEXT_KEY));
cmd->setAttribute(Command::CA_Hide);
m_uiSwitcher->addMenuAction(cmd, CppLanguage);
2008-12-02 12:01:29 +01:00
cmd = am->registerAction(m_actions.stepAction,
Constants::STEP, cppDebuggercontext);
2008-12-02 12:01:29 +01:00
cmd->setDefaultKeySequence(QKeySequence(Constants::STEP_KEY));
cmd->setAttribute(Command::CA_Hide);
m_uiSwitcher->addMenuAction(cmd, CppLanguage);
2008-12-02 12:01:29 +01:00
cmd = am->registerAction(m_actions.stepOutAction,
Constants::STEPOUT, cppDebuggercontext);
2008-12-02 12:01:29 +01:00
cmd->setDefaultKeySequence(QKeySequence(Constants::STEPOUT_KEY));
cmd->setAttribute(Command::CA_Hide);
m_uiSwitcher->addMenuAction(cmd, CppLanguage);
2008-12-02 12:01:29 +01:00
cmd = am->registerAction(m_actions.runToLineAction,
Constants::RUN_TO_LINE1, cppDebuggercontext);
2008-12-02 12:01:29 +01:00
cmd->setDefaultKeySequence(QKeySequence(Constants::RUN_TO_LINE_KEY));
cmd->setAttribute(Command::CA_Hide);
m_uiSwitcher->addMenuAction(cmd, CppLanguage);
2008-12-02 12:01:29 +01:00
cmd = am->registerAction(m_actions.runToFunctionAction,
Constants::RUN_TO_FUNCTION, cppDebuggercontext);
2008-12-02 12:01:29 +01:00
cmd->setDefaultKeySequence(QKeySequence(Constants::RUN_TO_FUNCTION_KEY));
cmd->setAttribute(Command::CA_Hide);
m_uiSwitcher->addMenuAction(cmd, CppLanguage);
2008-12-02 12:01:29 +01:00
cmd = am->registerAction(m_actions.jumpToLineAction,
Constants::JUMP_TO_LINE1, cppDebuggercontext);
cmd->setAttribute(Command::CA_Hide);
m_uiSwitcher->addMenuAction(cmd, CppLanguage);
2008-12-02 12:01:29 +01:00
cmd = am->registerAction(m_actions.returnFromFunctionAction,
Constants::RETURN_FROM_FUNCTION, cppDebuggercontext);
cmd->setAttribute(Command::CA_Hide);
m_uiSwitcher->addMenuAction(cmd, CppLanguage);
cmd = am->registerAction(m_actions.reverseDirectionAction,
Constants::REVERSE, cppDebuggercontext);
cmd->setDefaultKeySequence(QKeySequence(Constants::REVERSE_KEY));
cmd->setAttribute(Command::CA_Hide);
m_uiSwitcher->addMenuAction(cmd, CppLanguage);
2008-12-02 12:01:29 +01:00
sep = new QAction(this);
sep->setSeparator(true);
2010-03-11 12:22:24 +01:00
cmd = am->registerAction(sep, _("Debugger.Sep.Break"), globalcontext);
m_uiSwitcher->addMenuAction(cmd, CppLanguage);
2008-12-02 12:01:29 +01:00
//cmd = am->registerAction(m_actions.snapshotAction,
// Constants::SNAPSHOT, cppDebuggercontext);
//cmd->setDefaultKeySequence(QKeySequence(Constants::SNAPSHOT_KEY));
//cmd->setAttribute(Command::CA_Hide);
//m_uiSwitcher->addMenuAction(cmd, CppLanguage);
cmd = am->registerAction(m_actions.frameDownAction,
Constants::FRAME_DOWN, cppDebuggercontext);
cmd = am->registerAction(m_actions.frameUpAction,
Constants::FRAME_UP, cppDebuggercontext);
cmd = am->registerAction(theDebuggerAction(OperateByInstruction),
Constants::OPERATE_BY_INSTRUCTION, cppDebuggercontext);
cmd->setAttribute(Command::CA_Hide);
m_uiSwitcher->addMenuAction(cmd, CppLanguage);
cmd = am->registerAction(m_actions.breakAction,
Constants::TOGGLE_BREAK, globalcontext);
2008-12-02 12:01:29 +01:00
cmd->setDefaultKeySequence(QKeySequence(Constants::TOGGLE_BREAK_KEY));
m_uiSwitcher->addMenuAction(cmd, CppLanguage);
connect(m_actions.breakAction, SIGNAL(triggered()),
2010-10-27 14:10:44 +02:00
SLOT(toggleBreakpoint()));
2008-12-02 12:01:29 +01:00
//mcppcontext->addAction(cmd);
sep = new QAction(this);
sep->setSeparator(true);
2010-03-11 12:22:24 +01:00
cmd = am->registerAction(sep, _("Debugger.Sep.Watch"), globalcontext);
m_uiSwitcher->addMenuAction(cmd, CppLanguage);
2008-12-02 12:01:29 +01:00
cmd = am->registerAction(m_actions.watchAction1,
Constants::ADD_TO_WATCH1, cppeditorcontext);
cmd->action()->setEnabled(true);
//cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+D,Ctrl+W")));
m_uiSwitcher->addMenuAction(cmd, CppLanguage);
// Editor context menu
ActionContainer *editorContextMenu =
am->actionContainer(CppEditor::Constants::M_CONTEXT);
2010-03-11 12:22:24 +01:00
cmd = am->registerAction(sep, _("Debugger.Sep.Views"),
cppDebuggercontext);
editorContextMenu->addAction(cmd);
cmd->setAttribute(Command::CA_Hide);
cmd = am->registerAction(m_actions.watchAction2,
Constants::ADD_TO_WATCH2, cppDebuggercontext);
cmd->action()->setEnabled(true);
editorContextMenu->addAction(cmd);
cmd->setAttribute(Command::CA_Hide);
m_plugin->addAutoReleasedObject(new CommonOptionsPage);
QList<Core::IOptionsPage *> engineOptionPages;
if (cmdLineEnabledEngines & GdbEngineType)
addGdbOptionPages(&engineOptionPages);
#ifdef CDB_ENABLED
if (cmdLineEnabledEngines & CdbEngineType)
addCdbOptionPages(&engineOptionPages);
#endif
//if (cmdLineEnabledEngines & ScriptEngineType)
// addScriptOptionPages(&engineOptionPages);
//if (cmdLineEnabledEngines & TcfEngineType)
// addTcfOptionPages(&engineOptionPages);
2010-04-06 16:42:24 +02:00
foreach (Core::IOptionsPage *op, engineOptionPages)
m_plugin->addAutoReleasedObject(op);
m_plugin->addAutoReleasedObject(new DebuggingHelperOptionPage);
2010-04-06 16:42:24 +02:00
//setSimpleDockWidgetArrangement(Lang_Cpp);
2009-01-13 18:15:24 +01:00
connect(ModeManager::instance(), SIGNAL(currentModeChanged(Core::IMode*)),
2010-10-27 14:10:44 +02:00
SLOT(onModeChanged(Core::IMode*)));
2009-01-13 18:15:24 +01:00
m_debugMode->widget()->setFocusProxy(EditorManager::instance());
m_plugin->addObject(m_debugMode);
2009-01-13 18:15:24 +01:00
//
// Connections
//
// TextEditor
connect(TextEditorSettings::instance(),
SIGNAL(fontSettingsChanged(TextEditor::FontSettings)),
2010-08-31 13:07:33 +02:00
SLOT(fontSettingsChanged(TextEditor::FontSettings)));
2008-12-02 12:01:29 +01:00
// ProjectExplorer
connect(sessionManager(), SIGNAL(sessionLoaded()),
2010-08-31 13:07:33 +02:00
SLOT(sessionLoaded()));
connect(sessionManager(), SIGNAL(aboutToSaveSession()),
2010-08-31 13:07:33 +02:00
SLOT(aboutToSaveSession()));
connect(sessionManager(), SIGNAL(aboutToUnloadSession()),
2010-08-31 13:07:33 +02:00
SLOT(aboutToUnloadSession()));
2008-12-02 12:01:29 +01:00
// EditorManager
QObject *editorManager = core->editorManager();
connect(editorManager, SIGNAL(editorAboutToClose(Core::IEditor*)),
2010-08-31 13:07:33 +02:00
SLOT(editorAboutToClose(Core::IEditor*)));
2008-12-02 12:01:29 +01:00
connect(editorManager, SIGNAL(editorOpened(Core::IEditor*)),
2010-08-31 13:07:33 +02:00
SLOT(editorOpened(Core::IEditor*)));
2008-12-02 12:01:29 +01:00
// Application interaction
connect(theDebuggerAction(SettingsDialog), SIGNAL(triggered()),
2010-08-31 13:07:33 +02:00
SLOT(showSettingsDialog()));
// Toolbar
QWidget *toolbarContainer = new QWidget;
QHBoxLayout *hbox = new QHBoxLayout(toolbarContainer);
hbox->setMargin(0);
hbox->setSpacing(0);
2010-03-11 12:22:24 +01:00
hbox->addWidget(toolButton(am->command(PE::DEBUG)->action()));
hbox->addWidget(toolButton(am->command(STOP)->action()));
2010-03-11 12:22:24 +01:00
hbox->addWidget(toolButton(am->command(NEXT)->action()));
hbox->addWidget(toolButton(am->command(STEP)->action()));
hbox->addWidget(toolButton(am->command(STEPOUT)->action()));
hbox->addWidget(toolButton(am->command(OPERATE_BY_INSTRUCTION)->action()));
//hbox->addWidget(new Utils::StyledSeparator);
2010-03-11 12:22:24 +01:00
m_reverseToolButton = toolButton(am->command(REVERSE)->action());
hbox->addWidget(m_reverseToolButton);
//m_reverseToolButton->hide();
hbox->addWidget(new Utils::StyledSeparator);
hbox->addWidget(new QLabel(tr("Threads:")));
m_threadBox = new QComboBox;
connect(m_threadBox, SIGNAL(activated(int)), SLOT(selectThread(int)));
hbox->addWidget(m_threadBox);
hbox->addSpacerItem(new QSpacerItem(4, 0));
hbox->addWidget(m_statusLabel, 10);
m_uiSwitcher->setToolbar(CppLanguage, toolbarContainer);
2010-08-31 13:07:33 +02:00
connect(m_uiSwitcher,
SIGNAL(dockResetRequested(Debugger::DebuggerLanguages)),
SLOT(setSimpleDockWidgetArrangement(Debugger::DebuggerLanguages)));
2010-08-31 13:07:33 +02:00
connect(theDebuggerAction(EnableReverseDebugging),
SIGNAL(valueChanged(QVariant)),
SLOT(enableReverseDebuggingTriggered(QVariant)));
// UI Switcher
2010-08-31 13:07:33 +02:00
connect(m_uiSwitcher,
SIGNAL(activeLanguagesChanged(Debugger::DebuggerLanguages)),
SLOT(languagesChanged(Debugger::DebuggerLanguages)));
setInitialState();
2010-11-04 18:11:09 +01:00
connectEngine(0, false);
connect(sessionManager(),
2010-08-31 13:07:33 +02:00
SIGNAL(startupProjectChanged(ProjectExplorer::Project*)),
SLOT(onCurrentProjectChanged(ProjectExplorer::Project*)));
return true;
}
void DebuggerPluginPrivate::setConfigValue(const QString &name, const QVariant &value)
{
settings()->setValue(_("DebugMode/") + name, value);
}
QVariant DebuggerPluginPrivate::configValue(const QString &name) const
{
const QVariant value = settings()->value(_("DebugMode/") + name);
if (value.isValid())
return value;
// Legacy (pre-2.1): Check old un-namespaced-settings.
return settings()->value(name);
}
2010-08-31 13:07:33 +02:00
void DebuggerPluginPrivate::onCurrentProjectChanged(Project *project)
{
2010-08-31 13:07:33 +02:00
RunConfiguration *activeRc = 0;
if (project) {
2010-08-31 13:07:33 +02:00
Target *target = project->activeTarget();
QTC_ASSERT(target, return);
activeRc = target->activeRunConfiguration();
QTC_ASSERT(activeRc, /**/);
}
for (int i = 0, n = m_snapshotHandler->size(); i != n; ++i) {
2010-08-18 11:08:50 +02:00
// Run controls might be deleted during exit.
if (DebuggerRunControl *runControl = m_snapshotHandler->at(i)) {
RunConfiguration *rc = runControl->runConfiguration();
if (rc == activeRc) {
m_snapshotHandler->setCurrentIndex(i);
DebuggerEngine *engine = runControl->engine();
updateState(engine);
return;
}
}
}
// No corresponding debugger found. So we are ready to start one.
ICore *core = ICore::instance();
core->updateAdditionalContexts(m_anyContext, Context());
}
2010-08-31 13:07:33 +02:00
void DebuggerPluginPrivate::languagesChanged(const DebuggerLanguages &languages)
{
const bool debuggerIsCPP = (languages & CppLanguage);
//qDebug() << "DEBUGGER IS CPP: " << debuggerIsCPP;
m_startExternalAction->setVisible(debuggerIsCPP);
m_attachExternalAction->setVisible(debuggerIsCPP);
m_attachCoreAction->setVisible(debuggerIsCPP);
m_startRemoteAction->setVisible(debuggerIsCPP);
m_detachAction->setVisible(debuggerIsCPP);
2008-12-02 12:01:29 +01:00
}
void DebuggerPluginPrivate::startExternalApplication()
2008-12-02 12:01:29 +01:00
{
DebuggerStartParameters sp;
StartExternalDialog dlg(mainWindow());
dlg.setExecutableFile(
configValue(_("LastExternalExecutableFile")).toString());
dlg.setExecutableArguments(
configValue(_("LastExternalExecutableArguments")).toString());
dlg.setWorkingDirectory(
configValue(_("LastExternalWorkingDirectory")).toString());
if (dlg.exec() != QDialog::Accepted)
return;
2008-12-02 12:01:29 +01:00
setConfigValue(_("LastExternalExecutableFile"),
dlg.executableFile());
setConfigValue(_("LastExternalExecutableArguments"),
dlg.executableArguments());
setConfigValue(_("LastExternalWorkingDirectory"),
dlg.workingDirectory());
sp.executable = dlg.executableFile();
sp.startMode = StartExternal;
sp.workingDirectory = dlg.workingDirectory();
sp.breakAtMain = dlg.breakAtMain();
if (!dlg.executableArguments().isEmpty())
sp.processArgs = dlg.executableArguments().split(QLatin1Char(' '));
// Fixme: 1 of 3 testing hacks.
if (!sp.processArgs.isEmpty()
&& (sp.processArgs.front() == _("@tcf@") || sp.processArgs.front() == _("@sym@")))
sp.toolChainType = ProjectExplorer::ToolChain_RVCT_ARMV5;
if (RunControl *rc = m_debuggerRunControlFactory->create(sp))
startDebugger(rc);
2008-12-02 12:01:29 +01:00
}
void DebuggerPluginPrivate::attachExternalApplication()
{
AttachExternalDialog dlg(mainWindow());
if (dlg.exec() == QDialog::Accepted)
attachExternalApplication(dlg.attachPID(), dlg.executable(), QString());
}
void DebuggerPluginPrivate::attachExternalApplication
(qint64 pid, const QString &binary, const QString &crashParameter)
2008-12-02 12:01:29 +01:00
{
if (pid == 0) {
QMessageBox::warning(mainWindow(), tr("Warning"),
tr("Cannot attach to PID 0"));
return;
}
DebuggerStartParameters sp;
sp.attachPID = pid;
sp.displayName = tr("Process %1").arg(pid);
sp.executable = binary;
sp.crashParameter = crashParameter;
2010-09-06 11:33:07 +02:00
sp.startMode = crashParameter.isEmpty() ? AttachExternal : AttachCrashedExternal;
if (DebuggerRunControl *rc = createDebugger(sp))
startDebugger(rc);
2008-12-02 12:01:29 +01:00
}
void DebuggerPluginPrivate::attachCore()
2008-12-02 12:01:29 +01:00
{
AttachCoreDialog dlg(mainWindow());
dlg.setExecutableFile(configValue(_("LastExternalExecutableFile")).toString());
dlg.setCoreFile(configValue(_("LastExternalCoreFile")).toString());
if (dlg.exec() != QDialog::Accepted)
return;
setConfigValue(_("LastExternalExecutableFile"), dlg.executableFile());
setConfigValue(_("LastExternalCoreFile"), dlg.coreFile());
attachCore(dlg.coreFile(), dlg.executableFile());
2008-12-02 12:01:29 +01:00
}
void DebuggerPluginPrivate::attachCore(const QString &core, const QString &exe)
2008-12-02 12:01:29 +01:00
{
DebuggerStartParameters sp;
sp.executable = exe;
sp.coreFile = core;
sp.displayName = tr("Core file \"%1\"").arg(core);
sp.startMode = AttachCore;
if (DebuggerRunControl *rc = createDebugger(sp))
startDebugger(rc);
}
void DebuggerPluginPrivate::attachRemote(const QString &spec)
{
// spec is: executable@server:port@architecture
DebuggerStartParameters sp;
sp.executable = spec.section('@', 0, 0);
sp.remoteChannel = spec.section('@', 1, 1);
sp.remoteArchitecture = spec.section('@', 2, 2);
sp.displayName = tr("Remote: \"%1\"").arg(sp.remoteChannel);
sp.startMode = AttachToRemote;
if (DebuggerRunControl *rc = createDebugger(sp))
startDebugger(rc);
2008-12-02 12:01:29 +01:00
}
void DebuggerPluginPrivate::startRemoteApplication()
{
DebuggerStartParameters sp;
StartRemoteDialog dlg(mainWindow());
QStringList arches;
arches.append(_("i386:x86-64:intel"));
arches.append(_("i386"));
arches.append(_("arm"));
QString lastUsed = configValue(_("LastRemoteArchitecture")).toString();
if (!arches.contains(lastUsed))
arches.prepend(lastUsed);
dlg.setRemoteArchitectures(arches);
QStringList gnuTargets;
gnuTargets.append(_("auto"));
gnuTargets.append(_("i686-linux-gnu"));
gnuTargets.append(_("x86_64-linux-gnu"));
gnuTargets.append(_("arm-none-linux-gnueabi"));
const QString lastUsedGnuTarget
= configValue(_("LastGnuTarget")).toString();
if (!gnuTargets.contains(lastUsedGnuTarget))
gnuTargets.prepend(lastUsedGnuTarget);
dlg.setGnuTargets(gnuTargets);
dlg.setRemoteChannel(
configValue(_("LastRemoteChannel")).toString());
dlg.setLocalExecutable(
configValue(_("LastLocalExecutable")).toString());
dlg.setDebugger(configValue(_("LastDebugger")).toString());
dlg.setRemoteArchitecture(lastUsed);
dlg.setGnuTarget(lastUsedGnuTarget);
dlg.setServerStartScript(
configValue(_("LastServerStartScript")).toString());
dlg.setUseServerStartScript(
configValue(_("LastUseServerStartScript")).toBool());
dlg.setSysRoot(configValue(_("LastSysroot")).toString());
if (dlg.exec() != QDialog::Accepted)
return;
setConfigValue(_("LastRemoteChannel"), dlg.remoteChannel());
setConfigValue(_("LastLocalExecutable"), dlg.localExecutable());
setConfigValue(_("LastDebugger"), dlg.debugger());
setConfigValue(_("LastRemoteArchitecture"), dlg.remoteArchitecture());
setConfigValue(_("LastGnuTarget"), dlg.gnuTarget());
setConfigValue(_("LastServerStartScript"), dlg.serverStartScript());
setConfigValue(_("LastUseServerStartScript"), dlg.useServerStartScript());
setConfigValue(_("LastSysroot"), dlg.sysRoot());
sp.remoteChannel = dlg.remoteChannel();
sp.remoteArchitecture = dlg.remoteArchitecture();
sp.gnuTarget = dlg.gnuTarget();
sp.executable = dlg.localExecutable();
sp.displayName = dlg.localExecutable();
sp.debuggerCommand = dlg.debugger(); // Override toolchain-detection.
if (!sp.debuggerCommand.isEmpty())
sp.toolChainType = ProjectExplorer::ToolChain_INVALID;
sp.startMode = AttachToRemote;
2010-09-06 11:33:07 +02:00
sp.useServerStartScript = dlg.useServerStartScript();
sp.serverStartScript = dlg.serverStartScript();
sp.sysRoot = dlg.sysRoot();
if (RunControl *rc = createDebugger(sp))
startDebugger(rc);
}
void DebuggerPluginPrivate::enableReverseDebuggingTriggered(const QVariant &value)
{
QTC_ASSERT(m_reverseToolButton, return);
m_reverseToolButton->setVisible(value.toBool());
m_actions.reverseDirectionAction->setChecked(false);
m_actions.reverseDirectionAction->setEnabled(value.toBool());
}
void DebuggerPluginPrivate::attachRemoteTcf()
{
DebuggerStartParameters sp;
AttachTcfDialog dlg(mainWindow());
QStringList arches;
arches.append(_("i386:x86-64:intel"));
dlg.setRemoteArchitectures(arches);
dlg.setRemoteChannel(
configValue(_("LastTcfRemoteChannel")).toString());
dlg.setRemoteArchitecture(
configValue(_("LastTcfRemoteArchitecture")).toString());
dlg.setServerStartScript(
configValue(_("LastTcfServerStartScript")).toString());
dlg.setUseServerStartScript(
configValue(_("LastTcfUseServerStartScript")).toBool());
if (dlg.exec() != QDialog::Accepted)
return;
setConfigValue(_("LastTcfRemoteChannel"), dlg.remoteChannel());
setConfigValue(_("LastTcfRemoteArchitecture"), dlg.remoteArchitecture());
setConfigValue(_("LastTcfServerStartScript"), dlg.serverStartScript());
setConfigValue(_("LastTcfUseServerStartScript"), dlg.useServerStartScript());
sp.remoteChannel = dlg.remoteChannel();
sp.remoteArchitecture = dlg.remoteArchitecture();
sp.serverStartScript = dlg.serverStartScript();
sp.startMode = AttachTcf;
if (dlg.useServerStartScript())
sp.serverStartScript = dlg.serverStartScript();
if (RunControl *rc = createDebugger(sp))
startDebugger(rc);
}
bool DebuggerPluginPrivate::attachCmdLine()
{
if (m_attachRemoteParameters.attachPid) {
showStatusMessage(tr("Attaching to PID %1.")
.arg(m_attachRemoteParameters.attachPid));
const QString crashParameter = m_attachRemoteParameters.winCrashEvent
? QString::number(m_attachRemoteParameters.winCrashEvent) : QString();
attachExternalApplication(m_attachRemoteParameters.attachPid,
QString(), crashParameter);
return true;
}
const QString target = m_attachRemoteParameters.attachTarget;
if (!target.isEmpty()) {
if (target.indexOf(':') > 0) {
showStatusMessage(tr("Attaching to remote server %1.").arg(target));
attachRemote(target);
} else {
showStatusMessage(tr("Attaching to core %1.").arg(target));
attachCore(target, QString());
}
return true;
}
return false;
}
void DebuggerPluginPrivate::editorOpened(Core::IEditor *editor)
{
if (!isDebuggable(editor))
return;
ITextEditor *textEditor = qobject_cast<ITextEditor *>(editor);
if (!textEditor)
return;
connect(textEditor, SIGNAL(markRequested(TextEditor::ITextEditor*,int)),
2010-10-27 14:10:44 +02:00
SLOT(requestMark(TextEditor::ITextEditor*,int)));
connect(editor, SIGNAL(tooltipRequested(TextEditor::ITextEditor*,QPoint,int)),
2010-10-27 14:10:44 +02:00
SLOT(showToolTip(TextEditor::ITextEditor*,QPoint,int)));
connect(textEditor,
SIGNAL(markContextMenuRequested(TextEditor::ITextEditor*,int,QMenu*)),
2010-10-27 14:10:44 +02:00
SLOT(requestContextMenu(TextEditor::ITextEditor*,int,QMenu*)));
}
void DebuggerPluginPrivate::editorAboutToClose(Core::IEditor *editor)
{
if (!isDebuggable(editor))
return;
ITextEditor *textEditor = qobject_cast<ITextEditor *>(editor);
if (!textEditor)
return;
disconnect(textEditor, SIGNAL(markRequested(TextEditor::ITextEditor*,int)),
this, SLOT(requestMark(TextEditor::ITextEditor*,int)));
disconnect(editor, SIGNAL(tooltipRequested(TextEditor::ITextEditor*,QPoint,int)),
this, SLOT(showToolTip(TextEditor::ITextEditor*,QPoint,int)));
disconnect(textEditor, SIGNAL(markContextMenuRequested(TextEditor::ITextEditor*,int,QMenu*)),
this, SLOT(requestContextMenu(TextEditor::ITextEditor*,int,QMenu*)));
}
void DebuggerPluginPrivate::requestContextMenu(TextEditor::ITextEditor *editor,
int lineNumber, QMenu *menu)
{
if (!isDebuggable(editor))
return;
BreakpointData *data = 0;
QString fileName;
quint64 address = 0;
if (editor->property("DisassemblerView").toBool()) {
fileName = editor->file()->fileName();
QString line = editor->contents()
.section('\n', lineNumber - 1, lineNumber - 1);
BreakpointData needle;
address = DisassemblerViewAgent::addressFromDisassemblyLine(line);
needle.address = address;
needle.bpLineNumber = -1;
data = m_breakHandler->findSimilarBreakpoint(&needle);
} else {
fileName = editor->file()->fileName();
data = m_breakHandler->findBreakpoint(fileName, lineNumber);
}
QList<QVariant> args;
args.append(fileName);
args.append(lineNumber);
args.append(address);
if (data) {
// existing breakpoint
const QString number = QString::fromAscii(data->bpNumber);
QAction *act;
if (number.isEmpty())
act = new QAction(tr("Remove Breakpoint"), menu);
else
act = new QAction(tr("Remove Breakpoint %1").arg(number), menu);
act->setData(args);
connect(act, SIGNAL(triggered()),
SLOT(breakpointSetRemoveMarginActionTriggered()));
menu->addAction(act);
QAction *act2;
if (data->enabled)
if (number.isEmpty())
act2 = new QAction(tr("Disable Breakpoint"), menu);
else
act2 = new QAction(tr("Disable Breakpoint %1").arg(number), menu);
else
if (number.isEmpty())
act2 = new QAction(tr("Enable Breakpoint"), menu);
else
act2 = new QAction(tr("Enable Breakpoint %1").arg(number), menu);
act2->setData(args);
connect(act2, SIGNAL(triggered()),
this, SLOT(breakpointEnableDisableMarginActionTriggered()));
menu->addAction(act2);
QAction *editAction;
if (number.isEmpty())
editAction = new QAction(tr("Edit Breakpoint..."), menu);
else
editAction = new QAction(tr("Edit Breakpoint %1...").arg(number), menu);
connect(editAction, SIGNAL(triggered()), SLOT(slotEditBreakpoint()));
editAction->setData(qVariantFromValue(data));
menu->addAction(editAction);
} else {
// non-existing
const QString text = address ?
tr("Set Breakpoint at 0x%1").arg(address, 0, 16) :
tr("Set Breakpoint at line %1").arg(lineNumber);
QAction *act = new QAction(text, menu);
act->setData(args);
connect(act, SIGNAL(triggered()),
SLOT(breakpointSetRemoveMarginActionTriggered()));
menu->addAction(act);
}
// Run to, jump to line below in stopped state.
if (state() == InferiorStopOk) {
menu->addSeparator();
const QString runText =
DebuggerEngine::tr("Run to Line %1").arg(lineNumber);
QAction *runToLineAction = new QAction(runText, menu);
runToLineAction->setData(args);
connect(runToLineAction, SIGNAL(triggered()), SLOT(slotRunToLine()));
menu->addAction(runToLineAction);
if (currentEngine()->debuggerCapabilities() & JumpToLineCapability) {
const QString jumpText =
DebuggerEngine::tr("Jump to Line %1").arg(lineNumber);
QAction *jumpToLineAction = new QAction(jumpText, menu);
menu->addAction(runToLineAction);
jumpToLineAction->setData(args);
connect(jumpToLineAction, SIGNAL(triggered()), SLOT(slotJumpToLine()));
menu->addAction(jumpToLineAction);
}
}
}
void DebuggerPluginPrivate::toggleBreakpoint()
2010-06-11 12:38:54 +02:00
{
ITextEditor *textEditor = currentTextEditor();
QTC_ASSERT(textEditor, return);
int lineNumber = textEditor->currentLine();
if (lineNumber >= 0)
toggleBreakpoint(textEditor->file()->fileName(), lineNumber);
}
void DebuggerPluginPrivate::toggleBreakpoint(const QString &fileName, int lineNumber)
2010-06-11 12:38:54 +02:00
{
m_breakHandler->toggleBreakpoint(fileName, lineNumber);
m_breakHandler->synchronizeBreakpoints();
2010-06-11 12:38:54 +02:00
}
void DebuggerPluginPrivate::requestMark(ITextEditor *editor, int lineNumber)
2008-12-02 12:01:29 +01:00
{
if (isDebuggable(editor) && editor && editor->file())
toggleBreakpoint(editor->file()->fileName(), lineNumber);
2008-12-02 12:01:29 +01:00
}
void DebuggerPluginPrivate::showToolTip(ITextEditor *editor,
const QPoint &point, int pos)
2008-12-02 12:01:29 +01:00
{
if (!isDebuggable(editor))
return;
if (!theDebuggerBoolSetting(UseToolTipsInMainEditor))
return;
if (state() != InferiorStopOk)
return;
currentEngine()->setToolTipExpression(point, editor, pos);
2008-12-02 12:01:29 +01:00
}
DebuggerRunControl *DebuggerPluginPrivate::createDebugger
(const DebuggerStartParameters &sp, RunConfiguration *rc)
2008-12-02 12:01:29 +01:00
{
return m_debuggerRunControlFactory->create(sp, rc);
2008-12-02 12:01:29 +01:00
}
void DebuggerPluginPrivate::displayDebugger(DebuggerEngine *engine, bool updateEngine)
{
QTC_ASSERT(engine, return);
disconnectEngine();
connectEngine(engine);
if (updateEngine)
engine->updateAll();
updateState(engine);
}
2010-08-31 13:07:33 +02:00
void DebuggerPluginPrivate::startDebugger(RunControl *rc)
2008-12-02 12:01:29 +01:00
{
QTC_ASSERT(rc, return);
ProjectExplorerPlugin::instance()->startRunControl(rc, PE::DEBUGMODE);
2008-12-02 12:01:29 +01:00
}
class DummyEngine : public DebuggerEngine
{
Q_OBJECT
public:
DummyEngine() : DebuggerEngine(DebuggerStartParameters()) {}
virtual ~DummyEngine() {}
virtual void setupEngine() {}
virtual void setupInferior() {}
virtual void runEngine() {}
virtual void shutdownEngine() {}
virtual void shutdownInferior() {}
virtual void executeDebuggerCommand(const QString &) {}
virtual unsigned debuggerCapabilities() const { return 0; }
};
void DebuggerPluginPrivate::connectEngine(DebuggerEngine *engine, bool notify)
2008-12-02 12:01:29 +01:00
{
static Debugger::DummyEngine dummyEngine;
if (!engine)
engine = &dummyEngine;
2010-11-04 18:11:09 +01:00
if (m_currentEngine == engine)
return;
m_currentEngine = engine;
if (notify)
engine->setActive(false);
m_localsWindow->setModel(engine->localsModel());
m_modulesWindow->setModel(engine->modulesModel());
m_registerWindow->setModel(engine->registerModel());
m_returnWindow->setModel(engine->returnModel());
m_sourceFilesWindow->setModel(engine->sourceFilesModel());
m_stackWindow->setModel(engine->stackModel());
m_threadsWindow->setModel(engine->threadsModel());
m_threadBox->setModel(engine->threadsModel());
m_threadBox->setModelColumn(ThreadData::NameColumn);
m_watchersWindow->setModel(engine->watchersModel());
if (notify)
engine->setActive(true);
2008-12-02 12:01:29 +01:00
}
static void changeFontSize(QWidget *widget, qreal size)
{
QFont font = widget->font();
font.setPointSizeF(size);
widget->setFont(font);
}
void DebuggerPluginPrivate::fontSettingsChanged
(const TextEditor::FontSettings &settings)
2008-12-02 12:01:29 +01:00
{
qreal size = settings.fontZoom() * settings.fontSize() / 100.;
changeFontSize(m_breakWindow, size);
changeFontSize(m_logWindow, size);
changeFontSize(m_localsWindow, size);
changeFontSize(m_modulesWindow, size);
//changeFontSize(m_consoleWindow, size);
changeFontSize(m_registerWindow, size);
changeFontSize(m_returnWindow, size);
changeFontSize(m_sourceFilesWindow, size);
changeFontSize(m_stackWindow, size);
changeFontSize(m_threadsWindow, size);
changeFontSize(m_watchersWindow, size);
2008-12-02 12:01:29 +01:00
}
void DebuggerPluginPrivate::cleanupViews()
2008-12-02 12:01:29 +01:00
{
m_plugin->resetLocation();
m_actions.reverseDirectionAction->setChecked(false);
m_actions.reverseDirectionAction->setEnabled(false);
hideDebuggerToolTip();
// FIXME ABC: Delete run control / engine?
//if (d->m_engine)
// d->m_engine->cleanup();
if (theDebuggerBoolSetting(CloseBuffersOnExit)) {
if (EditorManager *editorManager = EditorManager::instance()) {
QList<IEditor *> toClose;
foreach (IEditor *editor, editorManager->openedEditors()) {
if (editor->property(Debugger::Constants::OPENED_BY_DEBUGGER).toBool()) {
// close disassembly views. close other opened files if they are not modified and not current editor
if (editor->property(Debugger::Constants::OPENED_WITH_DISASSEMBLY).toBool()
|| (!editor->file()->isModified() && editor != editorManager->currentEditor())) {
toClose.append(editor);
} else {
editor->setProperty(Debugger::Constants::OPENED_BY_DEBUGGER, false);
}
}
}
editorManager->closeEditors(toClose);
}
2008-12-02 12:01:29 +01:00
}
}
void DebuggerPluginPrivate::setBusyCursor(bool busy)
{
//STATE_DEBUG("BUSY FROM: " << m_busy << " TO: " << busy);
if (busy == m_busy)
return;
m_busy = busy;
QCursor cursor(busy ? Qt::BusyCursor : Qt::ArrowCursor);
m_breakWindow->setCursor(cursor);
//m_consoleWindow->setCursor(cursor);
m_localsWindow->setCursor(cursor);
m_modulesWindow->setCursor(cursor);
m_logWindow->setCursor(cursor);
m_registerWindow->setCursor(cursor);
m_returnWindow->setCursor(cursor);
m_sourceFilesWindow->setCursor(cursor);
m_stackWindow->setCursor(cursor);
m_threadsWindow->setCursor(cursor);
m_watchersWindow->setCursor(cursor);
m_snapshotWindow->setCursor(cursor);
m_scriptConsoleWindow->setCursor(cursor);
}
2010-08-31 13:07:33 +02:00
void DebuggerPluginPrivate::setSimpleDockWidgetArrangement
(Debugger::DebuggerLanguages activeLanguages)
2008-12-02 12:01:29 +01:00
{
Debugger::DebuggerUISwitcher *uiSwitcher = DebuggerUISwitcher::instance();
DebuggerMainWindow *mw = mainWindow();
mw->setTrackingEnabled(false);
QList<QDockWidget *> dockWidgets = mw->dockWidgets();
foreach (QDockWidget *dockWidget, dockWidgets) {
dockWidget->setFloating(false);
mw->removeDockWidget(dockWidget);
}
foreach (QDockWidget *dockWidget, dockWidgets) {
if (dockWidget == m_outputDock /*|| dockWidget == m_consoleDock*/) {
mw->addDockWidget(Qt::TopDockWidgetArea, dockWidget);
} else {
mw->addDockWidget(Qt::BottomDockWidgetArea, dockWidget);
}
dockWidget->hide();
}
2010-08-31 13:07:33 +02:00
if ((activeLanguages.testFlag(CppLanguage)
&& !activeLanguages.testFlag(QmlLanguage))
|| activeLanguages == AnyLanguage) {
m_stackDock->show();
m_breakDock->show();
m_watchDock->show();
m_threadsDock->show();
m_snapshotDock->show();
} else {
m_stackDock->show();
m_breakDock->show();
m_watchDock->show();
m_scriptConsoleDock->show();
if (uiSwitcher->qmlInspectorWindow())
uiSwitcher->qmlInspectorWindow()->show();
}
mw->splitDockWidget(mw->toolBarDockWidget(), m_stackDock, Qt::Vertical);
mw->splitDockWidget(m_stackDock, m_watchDock, Qt::Horizontal);
mw->tabifyDockWidget(m_watchDock, m_breakDock);
mw->tabifyDockWidget(m_watchDock, m_modulesDock);
mw->tabifyDockWidget(m_watchDock, m_registerDock);
mw->tabifyDockWidget(m_watchDock, m_threadsDock);
mw->tabifyDockWidget(m_watchDock, m_sourceFilesDock);
mw->tabifyDockWidget(m_watchDock, m_snapshotDock);
mw->tabifyDockWidget(m_watchDock, m_scriptConsoleDock);
if (uiSwitcher->qmlInspectorWindow())
mw->tabifyDockWidget(m_watchDock, uiSwitcher->qmlInspectorWindow());
mw->setTrackingEnabled(true);
}
void DebuggerPluginPrivate::setInitialState()
{
m_watchersWindow->setVisible(false);
m_returnWindow->setVisible(false);
setBusyCursor(false);
m_actions.reverseDirectionAction->setChecked(false);
m_actions.reverseDirectionAction->setEnabled(false);
hideDebuggerToolTip();
m_startExternalAction->setEnabled(true);
m_attachExternalAction->setEnabled(true);
#ifdef Q_OS_WIN
m_attachCoreAction->setEnabled(false);
#else
m_attachCoreAction->setEnabled(true);
#endif
m_startRemoteAction->setEnabled(true);
m_detachAction->setEnabled(false);
m_actions.watchAction1->setEnabled(true);
m_actions.watchAction2->setEnabled(true);
m_actions.breakAction->setEnabled(true);
//m_actions.snapshotAction->setEnabled(false);
theDebuggerAction(OperateByInstruction)->setEnabled(false);
m_actions.exitAction->setEnabled(false);
m_actions.resetAction->setEnabled(false);
m_actions.stepAction->setEnabled(false);
m_actions.stepOutAction->setEnabled(false);
m_actions.runToLineAction->setEnabled(false);
m_actions.runToFunctionAction->setEnabled(false);
m_actions.returnFromFunctionAction->setEnabled(false);
m_actions.jumpToLineAction->setEnabled(false);
m_actions.nextAction->setEnabled(false);
theDebuggerAction(AutoDerefPointers)->setEnabled(true);
theDebuggerAction(ExpandStack)->setEnabled(false);
theDebuggerAction(ExecuteCommand)->setEnabled(m_state == InferiorStopOk);
m_scriptConsoleWindow->setEnabled(false);
//emit m_plugin->stateChanged(m_state);
}
void DebuggerPluginPrivate::updateState(DebuggerEngine *engine)
{
2010-10-28 08:55:50 +02:00
QTC_ASSERT(engine, return);
QTC_ASSERT(m_watchersWindow->model(), return);
QTC_ASSERT(m_returnWindow->model(), return);
QTC_ASSERT(!engine->isSlaveEngine(), return);
m_threadBox->setCurrentIndex(engine->threadsHandler()->currentThread());
m_watchersWindow->setVisible(
m_watchersWindow->model()->rowCount(QModelIndex()) > 0);
m_returnWindow->setVisible(
m_returnWindow->model()->rowCount(QModelIndex()) > 0);
2010-10-28 08:55:50 +02:00
//m_plugin->showMessage(QString("PLUGIN SET STATE: ")
// + DebuggerEngine::stateName(engine->state()), LogStatus);
//qDebug() << "PLUGIN SET STATE: " << engine->state();
if (m_state == engine->state())
return;
m_state = engine->state();
bool actionsEnabled = DebuggerEngine::debuggerActionsEnabled(m_state);
ICore *core = ICore::instance();
ActionManager *am = core->actionManager();
if (m_state == DebuggerNotReady) {
QTC_ASSERT(false, /* We use the Core m_debugAction here */);
// F5 starts debugging. It is "startable".
m_actions.interruptAction->setEnabled(false);
m_actions.continueAction->setEnabled(false);
m_actions.exitAction->setEnabled(false);
am->command(Constants::STOP)->setKeySequence(QKeySequence());
2010-10-27 14:10:44 +02:00
am->command(PE::DEBUG)->setKeySequence(QKeySequence(PE::DEBUG_KEY));
core->updateAdditionalContexts(m_anyContext, Context());
} else if (m_state == InferiorStopOk) {
// F5 continues, Shift-F5 kills. It is "continuable".
m_actions.interruptAction->setEnabled(false);
m_actions.continueAction->setEnabled(true);
m_actions.exitAction->setEnabled(true);
am->command(Constants::STOP)->setKeySequence(QKeySequence(STOP_KEY));
2010-10-27 14:10:44 +02:00
am->command(PE::DEBUG)->setKeySequence(QKeySequence(PE::DEBUG_KEY));
core->updateAdditionalContexts(m_anyContext, m_continuableContext);
} else if (m_state == InferiorRunOk) {
// Shift-F5 interrupts. It is also "interruptible".
m_actions.interruptAction->setEnabled(true);
m_actions.continueAction->setEnabled(false);
m_actions.exitAction->setEnabled(false);
am->command(Constants::STOP)->setKeySequence(QKeySequence());
am->command(PE::DEBUG)->setKeySequence(QKeySequence(STOP_KEY));
core->updateAdditionalContexts(m_anyContext, m_interruptibleContext);
} else if (m_state == DebuggerFinished) {
// We don't want to do anything anymore.
m_actions.interruptAction->setEnabled(false);
m_actions.continueAction->setEnabled(false);
m_actions.exitAction->setEnabled(false);
am->command(Constants::STOP)->setKeySequence(QKeySequence());
2010-10-27 14:10:44 +02:00
am->command(PE::DEBUG)->setKeySequence(QKeySequence(PE::DEBUG_KEY));
//core->updateAdditionalContexts(m_anyContext, m_finishedContext);
m_codeModelSnapshot = CPlusPlus::Snapshot();
core->updateAdditionalContexts(m_anyContext, Context());
setBusyCursor(false);
cleanupViews();
} else if (m_state == InferiorUnrunnable) {
// We don't want to do anything anymore.
m_actions.interruptAction->setEnabled(false);
m_actions.continueAction->setEnabled(false);
m_actions.exitAction->setEnabled(true);
am->command(Constants::STOP)->setKeySequence(QKeySequence(STOP_KEY));
am->command(PE::DEBUG)->setKeySequence(QKeySequence(STOP_KEY));
core->updateAdditionalContexts(m_anyContext, m_finishedContext);
} else {
// Everything else is "undisturbable".
m_actions.interruptAction->setEnabled(false);
m_actions.continueAction->setEnabled(false);
m_actions.exitAction->setEnabled(false);
am->command(Constants::STOP)->setKeySequence(QKeySequence());
am->command(PE::DEBUG)->setKeySequence(QKeySequence());
core->updateAdditionalContexts(m_anyContext, m_undisturbableContext);
}
m_startExternalAction->setEnabled(true);
m_attachExternalAction->setEnabled(true);
#ifdef Q_OS_WIN
m_attachCoreAction->setEnabled(false);
#else
m_attachCoreAction->setEnabled(true);
#endif
m_startRemoteAction->setEnabled(true);
const bool stopped = m_state == InferiorStopOk;
const bool detachable = stopped
&& engine->startParameters().startMode != AttachCore;
2009-09-30 13:07:14 +02:00
m_detachAction->setEnabled(detachable);
2008-12-02 12:01:29 +01:00
if (stopped)
QApplication::alert(mainWindow(), 3000);
const uint caps = engine->debuggerCapabilities();
const bool canReverse = (caps & ReverseSteppingCapability)
&& theDebuggerBoolSetting(EnableReverseDebugging);
m_actions.reverseDirectionAction->setEnabled(canReverse);
m_actions.watchAction1->setEnabled(true);
m_actions.watchAction2->setEnabled(true);
m_actions.breakAction->setEnabled(true);
//m_actions.snapshotAction->setEnabled(stopped && (caps & SnapshotCapability));
theDebuggerAction(OperateByInstruction)->setEnabled(stopped);
m_actions.resetAction->setEnabled(m_state != DebuggerNotReady
&& m_state != DebuggerFinished);
m_actions.stepAction->setEnabled(stopped);
m_actions.stepOutAction->setEnabled(stopped);
m_actions.runToLineAction->setEnabled(stopped);
m_actions.runToFunctionAction->setEnabled(stopped);
m_actions.returnFromFunctionAction->
setEnabled(stopped && (caps & ReturnFromFunctionCapability));
const bool canJump = stopped && (caps & JumpToLineCapability);
m_actions.jumpToLineAction->setEnabled(canJump);
m_actions.nextAction->setEnabled(stopped);
const bool canDeref = actionsEnabled && (caps & AutoDerefPointersCapability);
theDebuggerAction(AutoDerefPointers)->setEnabled(canDeref);
theDebuggerAction(AutoDerefPointers)->setEnabled(true);
theDebuggerAction(ExpandStack)->setEnabled(actionsEnabled);
theDebuggerAction(ExecuteCommand)->setEnabled(m_state == InferiorStopOk);
const bool notbusy = m_state == InferiorStopOk
|| m_state == DebuggerNotReady
|| m_state == DebuggerFinished
|| m_state == InferiorUnrunnable;
setBusyCursor(!notbusy);
m_scriptConsoleWindow->setEnabled(stopped);
2009-01-13 18:15:24 +01:00
}
void DebuggerPluginPrivate::gotoLocation(const QString &file, int line, bool setMarker)
{
// CDB might hit on breakpoints while shutting down.
if (m_shuttingDown)
return;
bool newEditor = false;
ITextEditor *editor =
BaseTextEditor::openEditorAt(file, line, 0, QString(),
EditorManager::IgnoreNavigationHistory, &newEditor);
if (!editor)
return;
if (newEditor)
editor->setProperty(Debugger::Constants::OPENED_BY_DEBUGGER, true);
if (setMarker)
m_locationMark.reset(new LocationMark(file, line));
}
void DebuggerPluginPrivate::onModeChanged(IMode *mode)
2009-01-13 18:15:24 +01:00
{
// FIXME: This one gets always called, even if switching between modes
// different then the debugger mode. E.g. Welcome and Help mode and
// also on shutdown.
2010-08-30 17:08:29 +02:00
m_uiSwitcher->onModeChanged(mode);
if (mode != m_debugMode)
2009-01-13 18:15:24 +01:00
return;
EditorManager *editorManager = EditorManager::instance();
if (editorManager->currentEditor())
2009-01-13 18:15:24 +01:00
editorManager->currentEditor()->widget()->setFocus();
}
void DebuggerPluginPrivate::showSettingsDialog()
{
Core::ICore::instance()->showOptionsDialog(
2010-03-11 12:22:24 +01:00
_(DEBUGGER_SETTINGS_CATEGORY),
_(DEBUGGER_COMMON_SETTINGS_ID));
}
void DebuggerPluginPrivate::dumpLog()
{
QString fileName = QFileDialog::getSaveFileName(mainWindow(),
tr("Save Debugger Log"), QDir::tempPath());
if (fileName.isEmpty())
return;
QFile file(fileName);
if (!file.open(QIODevice::WriteOnly))
return;
QTextStream ts(&file);
ts << m_logWindow->inputContents();
ts << "\n\n=======================================\n\n";
ts << m_logWindow->combinedContents();
}
void DebuggerPluginPrivate::clearStatusMessage()
{
m_statusLabel->setText(m_lastPermanentStatusMessage);
}
/*! Activates the previous mode when the current mode is the debug mode. */
void DebuggerPluginPrivate::activatePreviousMode()
{
Core::ModeManager *modeManager = ICore::instance()->modeManager();
if (modeManager->currentMode() == modeManager->mode(MODE_DEBUG)
&& !m_previousMode.isEmpty()) {
modeManager->activateMode(m_previousMode);
m_previousMode.clear();
}
}
void DebuggerPluginPrivate::activateDebugMode()
{
m_actions.reverseDirectionAction->setChecked(false);
m_actions.reverseDirectionAction->setEnabled(false);
ModeManager *modeManager = ModeManager::instance();
m_previousMode = modeManager->currentMode()->id();
modeManager->activateMode(_(MODE_DEBUG));
}
void DebuggerPluginPrivate::sessionLoaded()
{
2010-11-04 18:11:09 +01:00
m_breakHandler->loadSessionData();
WatchHandler::loadSessionData();
synchronizeWatchers();
}
void DebuggerPluginPrivate::aboutToUnloadSession()
{
// Stop debugging the active project when switching sessions.
// Note that at startup, session switches may occur, which interfere
// with command-line debugging startup.
// FIXME ABC: Still wanted? Iterate?
//if (d->m_engine && state() != DebuggerNotReady
// && runControl()->sp().startMode == StartInternal)
// d->m_engine->shutdown();
}
void DebuggerPluginPrivate::aboutToSaveSession()
{
2010-11-04 18:11:09 +01:00
WatchHandler::saveSessionData();
m_breakHandler->saveSessionData();
}
void DebuggerPluginPrivate::executeDebuggerCommand()
{
if (QAction *action = qobject_cast<QAction *>(sender()))
currentEngine()->executeDebuggerCommand(action->data().toString());
}
void DebuggerPluginPrivate::showStatusMessage(const QString &msg0, int timeout)
{
m_plugin->showMessage(msg0, LogStatus);
QString msg = msg0;
msg.replace(QLatin1Char('\n'), QString());
m_statusLabel->setText(msg);
if (timeout > 0) {
m_statusTimer.setSingleShot(true);
m_statusTimer.start(timeout);
} else {
m_lastPermanentStatusMessage = msg;
m_statusTimer.stop();
}
}
2010-08-31 13:07:33 +02:00
void DebuggerPluginPrivate::scriptExpressionEntered(const QString &expression)
{
currentEngine()->executeDebuggerCommand(expression);
}
void DebuggerPluginPrivate::openMemoryEditor()
{
AddressDialog dialog;
if (dialog.exec() == QDialog::Accepted)
(void) new MemoryViewAgent(currentEngine(), dialog.address());
}
void DebuggerPluginPrivate::coreShutdown()
{
m_shuttingDown = true;
}
///////////////////////////////////////////////////////////////////////
//
// DebuggerPlugin
//
///////////////////////////////////////////////////////////////////////
DebuggerPlugin *theInstance = 0;
DebuggerPlugin *DebuggerPlugin::instance()
{
return theInstance;
}
DebuggerPlugin::DebuggerPlugin()
{
d = new DebuggerPluginPrivate(this);
theInstance = this;
}
DebuggerPlugin::~DebuggerPlugin()
{
theInstance = 0;
delete DebuggerSettings::instance();
removeObject(d->m_debugMode);
delete d->m_debugMode;
d->m_debugMode = 0;
removeObject(d->m_uiSwitcher);
delete d->m_uiSwitcher;
d->m_uiSwitcher = 0;
delete d->m_snapshotHandler;
d->m_snapshotHandler = 0;
delete d;
}
bool DebuggerPlugin::initialize(const QStringList &arguments, QString *errorMessage)
{
return d->initialize(arguments, errorMessage);
}
void DebuggerPlugin::setSessionValue(const QString &name, const QVariant &value)
{
QTC_ASSERT(sessionManager(), return);
sessionManager()->setValue(name, value);
//qDebug() << "SET SESSION VALUE: " << name;
}
QVariant DebuggerPlugin::sessionValue(const QString &name)
{
QTC_ASSERT(sessionManager(), return QVariant());
//qDebug() << "GET SESSION VALUE: " << name;
return sessionManager()->value(name);
}
void DebuggerPlugin::setConfigValue(const QString &name, const QVariant &value)
{
QTC_ASSERT(d->m_debugMode, return);
settings()->setValue(name, value);
}
QVariant DebuggerPlugin::configValue(const QString &name) const
{
QTC_ASSERT(d->m_debugMode, return QVariant());
return settings()->value(name);
}
void DebuggerPlugin::resetLocation()
{
d->m_locationMark.reset();
}
void DebuggerPlugin::gotoLocation(const QString &file, int line, bool setMarker)
{
d->gotoLocation(file, line, setMarker);
}
void DebuggerPlugin::openTextEditor(const QString &titlePattern0,
const QString &contents)
{
if (d->m_shuttingDown)
return;
QString titlePattern = titlePattern0;
EditorManager *editorManager = EditorManager::instance();
QTC_ASSERT(editorManager, return);
2010-09-08 09:13:59 +02:00
IEditor *editor = editorManager->openEditorWithContents(
Core::Constants::K_DEFAULT_TEXT_EDITOR_ID, &titlePattern, contents);
QTC_ASSERT(editor, return);
editorManager->activateEditor(editor, EditorManager::IgnoreNavigationHistory);
}
void DebuggerPlugin::writeSettings() const
{
QSettings *s = settings();
DebuggerSettings::instance()->writeSettings(s);
}
void DebuggerPlugin::readSettings()
{
//qDebug() << "PLUGIN READ SETTINGS";
QSettings *s = settings();
DebuggerSettings::instance()->readSettings(s);
}
const CPlusPlus::Snapshot &DebuggerPlugin::cppCodeModelSnapshot() const
{
if (d->m_codeModelSnapshot.isEmpty() && theDebuggerAction(UseCodeModel)->isChecked())
d->m_codeModelSnapshot = CppTools::CppModelManagerInterface::instance()->snapshot();
return d->m_codeModelSnapshot;
}
void DebuggerPlugin::clearCppCodeModelSnapshot()
{
d->m_codeModelSnapshot = CPlusPlus::Snapshot();
}
ExtensionSystem::IPlugin::ShutdownFlag DebuggerPlugin::aboutToShutdown()
{
2010-08-31 13:07:33 +02:00
disconnect(sessionManager(),
SIGNAL(startupProjectChanged(ProjectExplorer::Project*)), d, 0);
writeSettings();
if (d->m_uiSwitcher)
d->m_uiSwitcher->aboutToShutdown();
return SynchronousShutdown;
}
void DebuggerPlugin::showMessage(const QString &msg, int channel, int timeout)
{
//qDebug() << "PLUGIN OUTPUT: " << channel << msg;
LogWindow *ow = d->m_logWindow;
//ConsoleWindow *cw = d->m_consoleWindow;
QTC_ASSERT(ow, return);
switch (channel) {
case StatusBar:
// This will append to ow's output pane, too.
d->showStatusMessage(msg, timeout);
break;
case LogMiscInput:
ow->showInput(LogMisc, msg);
ow->showOutput(LogMisc, msg);
break;
case LogInput:
ow->showInput(LogInput, msg);
ow->showOutput(LogInput, msg);
break;
case ScriptConsoleOutput:
d->m_scriptConsoleWindow->appendResult(msg);
break;
default:
ow->showOutput(channel, msg);
if (channel == LogError)
ensureLogVisible();
break;
}
}
//////////////////////////////////////////////////////////////////////
//
// Register specific stuff
//
//////////////////////////////////////////////////////////////////////
bool DebuggerPlugin::isReverseDebugging() const
{
return d->m_actions.reverseDirectionAction->isChecked();
}
QMessageBox *DebuggerPlugin::showMessageBox(int icon, const QString &title,
const QString &text, int buttons)
{
QMessageBox *mb = new QMessageBox(QMessageBox::Icon(icon),
title, text, QMessageBox::StandardButtons(buttons), mainWindow());
mb->setAttribute(Qt::WA_DeleteOnClose);
mb->show();
return mb;
}
void DebuggerPlugin::ensureLogVisible()
{
QAction *action = d->m_outputDock->toggleViewAction();
if (!action->isChecked())
action->trigger();
}
QIcon DebuggerPlugin::locationMarkIcon() const
{
return d->m_locationMarkIcon;
}
void DebuggerPlugin::extensionsInitialized()
{
d->m_uiSwitcher->initialize();
d->m_watchersWindow->setVisible(false);
d->m_returnWindow->setVisible(false);
connect(d->m_uiSwitcher, SIGNAL(memoryEditorRequested()),
d, SLOT(openMemoryEditor()));
// time gdb -i mi -ex 'debuggerplugin.cpp:800' -ex r -ex q bin/qtcreator.bin
const QByteArray env = qgetenv("QTC_DEBUGGER_TEST");
//qDebug() << "EXTENSIONS INITIALIZED:" << env;
// if (!env.isEmpty())
// m_plugin->runTest(QString::fromLocal8Bit(env));
if (d->m_attachRemoteParameters.attachPid
|| !d->m_attachRemoteParameters.attachTarget.isEmpty())
QTimer::singleShot(0, d, SLOT(attachCmdLine()));
}
QWidget *DebuggerPlugin::mainWindow() const
{
return d->m_uiSwitcher->mainWindow();
}
DebuggerRunControl *DebuggerPlugin::createDebugger
(const DebuggerStartParameters &sp, RunConfiguration *rc)
{
return instance()->d->createDebugger(sp, rc);
}
2010-08-31 13:07:33 +02:00
void DebuggerPlugin::startDebugger(RunControl *runControl)
{
instance()->d->startDebugger(runControl);
}
2010-08-31 13:07:33 +02:00
void DebuggerPlugin::displayDebugger(RunControl *runControl)
{
DebuggerRunControl *rc = qobject_cast<DebuggerRunControl *>(runControl);
QTC_ASSERT(rc, return);
instance()->d->displayDebugger(rc->engine());
}
// if updateEngine is set, the engine will update its threads/modules and so forth.
void DebuggerPlugin::displayDebugger(DebuggerEngine *engine, bool updateEngine)
{
instance()->d->displayDebugger(engine, updateEngine);
}
void DebuggerPlugin::updateState(DebuggerEngine *engine)
{
d->updateState(engine);
}
void DebuggerPlugin::activateDebugMode()
{
d->activateDebugMode();
}
void DebuggerPlugin::createNewDock(QWidget *widget)
{
QDockWidget *dockWidget =
DebuggerUISwitcher::instance()->createDockWidget(CppLanguage, widget);
dockWidget->setWindowTitle(widget->windowTitle());
dockWidget->setObjectName(widget->windowTitle());
dockWidget->setFeatures(QDockWidget::DockWidgetClosable);
//dockWidget->setWidget(widget);
//mainWindow()->addDockWidget(Qt::TopDockWidgetArea, dockWidget);
dockWidget->show();
}
void DebuggerPlugin::runControlStarted(DebuggerRunControl *runControl)
{
d->connectEngine(runControl->engine());
d->m_snapshotHandler->appendSnapshot(runControl);
}
void DebuggerPlugin::runControlFinished(DebuggerRunControl *runControl)
{
Q_UNUSED(runControl);
d->m_snapshotHandler->removeSnapshot(runControl);
d->disconnectEngine();
if (theDebuggerBoolSetting(SwitchModeOnExit))
if (d->m_snapshotHandler->size() == 0)
d->activatePreviousMode();
}
DebuggerLanguages DebuggerPlugin::activeLanguages() const
{
return DebuggerUISwitcher::instance()->activeDebugLanguages();
}
bool DebuggerPlugin::isRegisterViewVisible() const
{
return d->m_registerDock->toggleViewAction()->isChecked();
}
bool DebuggerPlugin::hasSnapshots() const
{
return d->m_snapshotHandler->size();
}
Internal::BreakHandler *DebuggerPlugin::breakHandler() const
{
return d->m_breakHandler;
}
Internal::SnapshotHandler *DebuggerPlugin::snapshotHandler() const
{
return d->m_snapshotHandler;
}
DebuggerEngine *DebuggerPlugin::currentEngine() const
{
return d->m_currentEngine;
}
void DebuggerPlugin::remoteCommand(const QStringList &options, const QStringList &)
{
if (options.isEmpty())
return;
unsigned enabledEngines = 0;
QString errorMessage;
2010-11-08 16:29:00 +01:00
if (!parseArguments(options,
&d->m_attachRemoteParameters, &enabledEngines, &errorMessage)) {
qWarning("%s", qPrintable(errorMessage));
2010-11-08 16:29:00 +01:00
return;
}
if (!d->attachCmdLine())
qWarning("%s", qPrintable(
_("Incomplete remote attach command received: %1").
arg(options.join(QString(QLatin1Char(' '))))));
}
void DebuggerPlugin::showQtDumperLibraryWarning(const QString &details)
{
QMessageBox dialog(mainWindow());
QPushButton *qtPref = dialog.addButton(tr("Open Qt4 Options"),
QMessageBox::ActionRole);
QPushButton *helperOff = dialog.addButton(tr("Turn off Helper Usage"),
QMessageBox::ActionRole);
QPushButton *justContinue = dialog.addButton(tr("Continue Anyway"),
QMessageBox::AcceptRole);
dialog.setDefaultButton(justContinue);
dialog.setWindowTitle(tr("Debugging Helper Missing"));
dialog.setText(tr("The debugger could not load the debugging helper library."));
dialog.setInformativeText(tr(
"The debugging helper is used to nicely format the values of some Qt "
"and Standard Library data types. "
"It must be compiled for each used Qt version separately. "
"On the Qt4 options page, select a Qt installation "
"and click Rebuild."));
if (!details.isEmpty())
dialog.setDetailedText(details);
dialog.exec();
if (dialog.clickedButton() == qtPref) {
Core::ICore::instance()->showOptionsDialog(
_(Qt4ProjectManager::Constants::QT_SETTINGS_CATEGORY),
_(Qt4ProjectManager::Constants::QTVERSION_SETTINGS_PAGE_ID));
} else if (dialog.clickedButton() == helperOff) {
theDebuggerAction(UseDebuggingHelpers)
->setValue(qVariantFromValue(false), false);
}
}
//////////////////////////////////////////////////////////////////////
//
// Testing
//
//////////////////////////////////////////////////////////////////////
/*
void DebuggerPlugin::runTest(const QString &fileName)
{
DebuggerStartParameters sp;
sp.executable = fileName;
sp.processArgs = QStringList() << "--run-debuggee";
sp.workingDirectory.clear();
startDebugger(m_debuggerRunControlFactory->create(sp));
}
*/
} // namespace Debugger
2008-12-02 12:01:29 +01:00
#include "debuggerplugin.moc"
2010-08-31 13:07:33 +02:00
Q_EXPORT_PLUGIN(Debugger::DebuggerPlugin)