2009-02-25 09:15:00 +01:00
|
|
|
/**************************************************************************
|
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
|
|
|
**
|
2009-06-17 00:01:27 +10:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Commercial Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** 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.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** 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.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** 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
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
**************************************************************************/
|
2008-12-02 15:08:31 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "stackwindow.h"
|
2009-08-14 13:04:05 +02:00
|
|
|
#include "stackframe.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-04-02 15:06:24 +02:00
|
|
|
#include "debuggeractions.h"
|
2009-08-14 13:04:05 +02:00
|
|
|
#include "debuggeragents.h"
|
2010-03-18 10:59:06 +01:00
|
|
|
#include "debuggermanager.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-02-17 11:16:23 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2010-03-18 10:59:06 +01:00
|
|
|
#include <utils/savedaction.h>
|
2009-02-17 11:16:23 +01:00
|
|
|
|
2009-03-03 18:05:23 +01:00
|
|
|
#include <QtCore/QDebug>
|
|
|
|
|
|
|
|
|
|
#include <QtGui/QAction>
|
|
|
|
|
#include <QtGui/QApplication>
|
|
|
|
|
#include <QtGui/QClipboard>
|
|
|
|
|
#include <QtGui/QComboBox>
|
|
|
|
|
#include <QtGui/QHeaderView>
|
|
|
|
|
#include <QtGui/QMenu>
|
|
|
|
|
#include <QtGui/QResizeEvent>
|
|
|
|
|
#include <QtGui/QTreeView>
|
|
|
|
|
#include <QtGui/QVBoxLayout>
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-08-14 13:04:05 +02:00
|
|
|
namespace Debugger {
|
|
|
|
|
namespace Internal {
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-08-14 13:04:05 +02:00
|
|
|
StackWindow::StackWindow(DebuggerManager *manager, QWidget *parent)
|
|
|
|
|
: QTreeView(parent), m_manager(manager), m_alwaysResizeColumnsToContents(false)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-03-16 16:55:56 +01:00
|
|
|
setFrameStyle(QFrame::NoFrame);
|
2009-08-14 13:04:05 +02:00
|
|
|
m_disassemblerAgent = new DisassemblerViewAgent(manager);
|
|
|
|
|
|
2009-05-05 10:14:35 +02:00
|
|
|
QAction *act = theDebuggerAction(UseAlternatingRowColors);
|
2008-12-02 12:01:29 +01:00
|
|
|
setWindowTitle(tr("Stack"));
|
|
|
|
|
|
2009-05-05 10:14:35 +02:00
|
|
|
setAlternatingRowColors(act->isChecked());
|
2008-12-02 12:01:29 +01:00
|
|
|
setRootIsDecorated(false);
|
|
|
|
|
setIconSize(QSize(10, 10));
|
|
|
|
|
|
|
|
|
|
header()->setDefaultAlignment(Qt::AlignLeft);
|
|
|
|
|
|
|
|
|
|
connect(this, SIGNAL(activated(QModelIndex)),
|
|
|
|
|
this, SLOT(rowActivated(QModelIndex)));
|
2009-05-05 10:14:35 +02:00
|
|
|
connect(act, SIGNAL(toggled(bool)),
|
|
|
|
|
this, SLOT(setAlternatingRowColorsHelper(bool)));
|
2009-10-01 11:22:44 +02:00
|
|
|
connect(theDebuggerAction(UseAddressInStackView), SIGNAL(toggled(bool)),
|
|
|
|
|
this, SLOT(showAddressColumn(bool)));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2009-11-04 14:39:21 +01:00
|
|
|
StackWindow::~StackWindow()
|
|
|
|
|
{
|
2009-11-04 19:26:35 +01:00
|
|
|
delete m_disassemblerAgent;
|
2009-11-04 14:39:21 +01:00
|
|
|
}
|
|
|
|
|
|
2009-10-01 11:22:44 +02:00
|
|
|
void StackWindow::showAddressColumn(bool on)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-10-01 11:22:44 +02:00
|
|
|
setColumnHidden(4, !on);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StackWindow::rowActivated(const QModelIndex &index)
|
|
|
|
|
{
|
2009-10-02 12:31:19 +02:00
|
|
|
m_manager->activateFrame(index.row());
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StackWindow::contextMenuEvent(QContextMenuEvent *ev)
|
|
|
|
|
{
|
2009-08-14 13:04:05 +02:00
|
|
|
QModelIndex idx = indexAt(ev->pos());
|
|
|
|
|
StackFrame frame = model()->data(idx, Qt::UserRole).value<StackFrame>();
|
|
|
|
|
QString address = frame.address;
|
2010-01-29 21:33:57 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
QMenu menu;
|
2009-03-03 18:05:23 +01:00
|
|
|
|
2010-02-05 10:23:55 +01:00
|
|
|
const unsigned engineCapabilities = m_manager->debuggerCapabilities();
|
2009-04-06 17:27:15 +02:00
|
|
|
menu.addAction(theDebuggerAction(ExpandStack));
|
2009-08-14 13:04:05 +02:00
|
|
|
|
2010-03-29 18:44:02 +02:00
|
|
|
QAction *actCopyContents = menu.addAction(tr("Copy Contents to Clipboard"));
|
2009-08-14 13:04:05 +02:00
|
|
|
actCopyContents->setEnabled(model() != 0);
|
|
|
|
|
|
2010-04-06 10:49:53 +02:00
|
|
|
if (engineCapabilities & CreateFullBacktraceCapability)
|
|
|
|
|
menu.addAction(theDebuggerAction(CreateFullBacktrace));
|
2010-03-29 18:44:02 +02:00
|
|
|
|
2009-08-14 13:04:05 +02:00
|
|
|
QAction *actShowMemory = menu.addAction(QString());
|
|
|
|
|
if (address.isEmpty()) {
|
2010-03-29 18:44:02 +02:00
|
|
|
actShowMemory->setText(tr("Open Memory Editor"));
|
2009-08-14 13:04:05 +02:00
|
|
|
actShowMemory->setEnabled(false);
|
|
|
|
|
} else {
|
2010-02-12 10:52:09 +01:00
|
|
|
actShowMemory->setText(tr("Open Memory Editor at %1").arg(address));
|
2010-02-05 10:23:55 +01:00
|
|
|
actShowMemory->setEnabled(engineCapabilities & ShowMemoryCapability);
|
2010-01-29 21:33:57 +01:00
|
|
|
}
|
2009-08-14 13:04:05 +02:00
|
|
|
|
|
|
|
|
QAction *actShowDisassembler = menu.addAction(QString());
|
|
|
|
|
if (address.isEmpty()) {
|
2010-02-12 10:52:09 +01:00
|
|
|
actShowDisassembler->setText(tr("Open Disassembler"));
|
2009-08-14 13:04:05 +02:00
|
|
|
actShowDisassembler->setEnabled(false);
|
|
|
|
|
} else {
|
2010-02-12 10:52:09 +01:00
|
|
|
actShowDisassembler->setText(tr("Open Disassembler at %1").arg(address));
|
2010-02-05 10:23:55 +01:00
|
|
|
actShowDisassembler->setEnabled(engineCapabilities & DisassemblerCapability);
|
2009-08-14 13:04:05 +02:00
|
|
|
}
|
|
|
|
|
|
2009-04-02 15:06:24 +02:00
|
|
|
menu.addSeparator();
|
2009-10-07 13:36:48 +02:00
|
|
|
#if 0 // @TODO: not implemented
|
2009-10-02 12:31:19 +02:00
|
|
|
menu.addAction(theDebuggerAction(UseToolTipsInStackView));
|
2009-10-07 13:36:48 +02:00
|
|
|
#endif
|
2009-10-01 11:22:44 +02:00
|
|
|
menu.addAction(theDebuggerAction(UseAddressInStackView));
|
|
|
|
|
|
2010-02-12 10:52:09 +01:00
|
|
|
QAction *actAdjust = menu.addAction(tr("Adjust Column Widths to Contents"));
|
2009-08-18 16:46:33 +02:00
|
|
|
|
|
|
|
|
QAction *actAlwaysAdjust =
|
2010-02-12 10:52:09 +01:00
|
|
|
menu.addAction(tr("Always Adjust Column Widths to Contents"));
|
2009-08-18 16:46:33 +02:00
|
|
|
actAlwaysAdjust->setCheckable(true);
|
|
|
|
|
actAlwaysAdjust->setChecked(m_alwaysResizeColumnsToContents);
|
|
|
|
|
|
|
|
|
|
menu.addSeparator();
|
|
|
|
|
|
2009-04-02 15:06:24 +02:00
|
|
|
menu.addAction(theDebuggerAction(SettingsDialog));
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
QAction *act = menu.exec(ev->globalPos());
|
|
|
|
|
|
2009-08-14 13:04:05 +02:00
|
|
|
if (act == actCopyContents)
|
2009-03-03 18:05:23 +01:00
|
|
|
copyContentsToClipboard();
|
2009-08-14 13:04:05 +02:00
|
|
|
else if (act == actAdjust)
|
2008-12-02 12:01:29 +01:00
|
|
|
resizeColumnsToContents();
|
2009-08-14 13:04:05 +02:00
|
|
|
else if (act == actAlwaysAdjust)
|
2008-12-02 12:01:29 +01:00
|
|
|
setAlwaysResizeColumnsToContents(!m_alwaysResizeColumnsToContents);
|
2009-08-14 13:04:05 +02:00
|
|
|
else if (act == actShowMemory)
|
|
|
|
|
(void) new MemoryViewAgent(m_manager, address);
|
|
|
|
|
else if (act == actShowDisassembler)
|
|
|
|
|
m_disassemblerAgent->setFrame(frame);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2009-03-03 18:05:23 +01:00
|
|
|
void StackWindow::copyContentsToClipboard()
|
|
|
|
|
{
|
|
|
|
|
QString str;
|
|
|
|
|
int n = model()->rowCount();
|
|
|
|
|
int m = model()->columnCount();
|
|
|
|
|
for (int i = 0; i != n; ++i) {
|
|
|
|
|
for (int j = 0; j != m; ++j) {
|
|
|
|
|
QModelIndex index = model()->index(i, j);
|
|
|
|
|
str += model()->data(index).toString();
|
|
|
|
|
str += '\t';
|
|
|
|
|
}
|
|
|
|
|
str += '\n';
|
|
|
|
|
}
|
|
|
|
|
QClipboard *clipboard = QApplication::clipboard();
|
2009-06-03 20:45:49 +02:00
|
|
|
#ifdef Q_WS_X11
|
2009-03-03 18:05:23 +01:00
|
|
|
clipboard->setText(str, QClipboard::Selection);
|
|
|
|
|
#endif
|
|
|
|
|
clipboard->setText(str, QClipboard::Clipboard);
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void StackWindow::resizeColumnsToContents()
|
|
|
|
|
{
|
2009-10-01 11:22:44 +02:00
|
|
|
for (int i = model()->columnCount(); --i >= 0; )
|
|
|
|
|
resizeColumnToContents(i);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StackWindow::setAlwaysResizeColumnsToContents(bool on)
|
|
|
|
|
{
|
|
|
|
|
m_alwaysResizeColumnsToContents = on;
|
2009-03-04 09:45:20 +01:00
|
|
|
QHeaderView::ResizeMode mode =
|
|
|
|
|
on ? QHeaderView::ResizeToContents : QHeaderView::Interactive;
|
2009-10-01 11:22:44 +02:00
|
|
|
for (int i = model()->columnCount(); --i >= 0; )
|
|
|
|
|
header()->setResizeMode(i, mode);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2009-08-14 13:04:05 +02:00
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Debugger
|