debugger: make output format of non-printable characters customizable

This commit is contained in:
hjk
2011-02-17 19:00:33 +01:00
parent 8c3e61e083
commit 98c4b82c2d
4 changed files with 66 additions and 10 deletions

View File

@@ -79,6 +79,7 @@ static int generationCounter = 0;
QHash<QByteArray, int> WatchHandler::m_watcherNames; QHash<QByteArray, int> WatchHandler::m_watcherNames;
QHash<QByteArray, int> WatchHandler::m_typeFormats; QHash<QByteArray, int> WatchHandler::m_typeFormats;
int WatchHandler::m_unprintableBase = 0;
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// //
@@ -627,21 +628,41 @@ QVariant WatchModel::data(const QModelIndex &idx, int role) const
case Qt::DisplayRole: { case Qt::DisplayRole: {
const QByteArray ns = engine()->qtNamespace(); const QByteArray ns = engine()->qtNamespace();
QString result;
switch (idx.column()) { switch (idx.column()) {
case 0: case 0:
if (data.name.isEmpty()) if (data.name.isEmpty())
return tr("<Edit>"); result = tr("<Edit>");
if (data.name == QLatin1String("*") && item->parent) else if (data.name == QLatin1String("*") && item->parent)
return QVariant(QLatin1Char('*') + item->parent->name); result = QLatin1Char('*') + item->parent->name;
return removeInitialNamespace(data.name, ns); else
result = removeInitialNamespace(data.name, ns);
break;
case 1: case 1:
return removeInitialNamespace(truncateValue( result = removeInitialNamespace(truncateValue(
formattedValue(data, itemFormat(data))), ns); formattedValue(data, itemFormat(data))), ns);
break;
case 2: case 2:
return removeNamespaces(displayType(data), ns); result = removeNamespaces(displayType(data), ns);
break;
default: default:
break; break;
} }
if (WatchHandler::m_unprintableBase == 0)
return result;
QString encoded;
foreach (const QChar c, result) {
if (c.isPrint()) {
encoded += c;
} else if (WatchHandler::m_unprintableBase == 8) {
encoded += QString("\\%1")
.arg(c.unicode(), 3, 8, QLatin1Char('0'));
} else {
encoded += QString("\\u%1")
.arg(c.unicode(), 4, 16, QLatin1Char('0'));
}
}
return encoded;
} }
case Qt::ToolTipRole: case Qt::ToolTipRole:
@@ -1092,11 +1113,11 @@ WatchHandler::WatchHandler(DebuggerEngine *engine)
m_tooltips = new WatchModel(this, TooltipsWatch); m_tooltips = new WatchModel(this, TooltipsWatch);
connect(debuggerCore()->action(ShowStdNamespace), connect(debuggerCore()->action(ShowStdNamespace),
SIGNAL(triggered()), this, SLOT(emitAllChanged())); SIGNAL(triggered()), SLOT(emitAllChanged()));
connect(debuggerCore()->action(ShowQtNamespace), connect(debuggerCore()->action(ShowQtNamespace),
SIGNAL(triggered()), this, SLOT(emitAllChanged())); SIGNAL(triggered()), SLOT(emitAllChanged()));
connect(debuggerCore()->action(SortStructMembers), connect(debuggerCore()->action(SortStructMembers),
SIGNAL(triggered()), this, SLOT(emitAllChanged())); SIGNAL(triggered()), SLOT(emitAllChanged()));
} }
void WatchHandler::beginCycle(bool fullCycle) void WatchHandler::beginCycle(bool fullCycle)

View File

@@ -180,6 +180,9 @@ public:
void addTypeFormats(const QByteArray &type, const QStringList &formats); void addTypeFormats(const QByteArray &type, const QStringList &formats);
void setUnprintableBase(int base) { m_unprintableBase = base; }
int unprintableBase() const { return m_unprintableBase; }
QByteArray watcherName(const QByteArray &exp); QByteArray watcherName(const QByteArray &exp);
void synchronizeWatchers(); void synchronizeWatchers();
QString editorContents(); QString editorContents();
@@ -214,6 +217,7 @@ private:
WatchModel *m_watchers; WatchModel *m_watchers;
WatchModel *m_tooltips; WatchModel *m_tooltips;
DebuggerEngine *m_engine; DebuggerEngine *m_engine;
static int m_unprintableBase;
}; };
} // namespace Internal } // namespace Internal

View File

@@ -286,14 +286,31 @@ void WatchWindow::contextMenuEvent(QContextMenuEvent *ev)
mi0.data(LocalsIndividualFormatRole).toInt(); mi0.data(LocalsIndividualFormatRole).toInt();
const int effectiveIndividualFormat = const int effectiveIndividualFormat =
individualFormat == -1 ? typeFormat : individualFormat; individualFormat == -1 ? typeFormat : individualFormat;
const int unprintableBase = handler->unprintableBase();
QMenu formatMenu; QMenu formatMenu;
QList<QAction *> typeFormatActions; QList<QAction *> typeFormatActions;
QList<QAction *> individualFormatActions; QList<QAction *> individualFormatActions;
QAction *clearTypeFormatAction = 0; QAction *clearTypeFormatAction = 0;
QAction *clearIndividualFormatAction = 0; QAction *clearIndividualFormatAction = 0;
QAction *showUnprintableUnicode = 0;
QAction *showUnprintableOctal = 0;
QAction *showUnprintableHexadecimal = 0;
formatMenu.setTitle(tr("Change Display Format...")); formatMenu.setTitle(tr("Change Display Format..."));
if (idx.isValid() && !alternativeFormats.isEmpty()) { if (true /*idx.isValid() && !alternativeFormats.isEmpty() */) {
showUnprintableUnicode =
formatMenu.addAction(tr("Treat All Characters as Printable"));
showUnprintableUnicode->setCheckable(true);
showUnprintableUnicode->setChecked(unprintableBase == 0);
showUnprintableOctal =
formatMenu.addAction(tr("Show Unprintable Characters as Octal"));
showUnprintableOctal->setCheckable(true);
showUnprintableOctal->setChecked(unprintableBase == 8);
showUnprintableHexadecimal =
formatMenu.addAction(tr("Show Unprintable Characters as Hexadecimal"));
showUnprintableHexadecimal->setCheckable(true);
showUnprintableHexadecimal->setChecked(unprintableBase == 16);
formatMenu.addSeparator();
QAction *dummy = formatMenu.addAction( QAction *dummy = formatMenu.addAction(
tr("Change Display for Type \"%1\"").arg(type)); tr("Change Display for Type \"%1\"").arg(type));
dummy->setEnabled(false); dummy->setEnabled(false);
@@ -515,6 +532,12 @@ void WatchWindow::contextMenuEvent(QContextMenuEvent *ev)
} else if (act == actShowInEditor) { } else if (act == actShowInEditor) {
QString contents = handler->editorContents(); QString contents = handler->editorContents();
debuggerCore()->openTextEditor(tr("Locals & Watchers"), contents); debuggerCore()->openTextEditor(tr("Locals & Watchers"), contents);
} else if (act == showUnprintableUnicode) {
handler->setUnprintableBase(0);
} else if (act == showUnprintableOctal) {
handler->setUnprintableBase(8);
} else if (act == showUnprintableHexadecimal) {
handler->setUnprintableBase(16);
} else { } else {
for (int i = 0; i != typeFormatActions.size(); ++i) { for (int i = 0; i != typeFormatActions.size(); ++i) {
if (act == typeFormatActions.at(i)) if (act == typeFormatActions.at(i))

View File

@@ -2060,6 +2060,14 @@ struct Ty
}; };
void testStuff() void testStuff()
{
char *x = "0\032\0333";
char *y = "0\032\0333";
char *z = "0\032\0333";
int i = 1;
}
void testStuff5()
{ {
using namespace std; using namespace std;
typedef map<string, list<string> > map_t; typedef map<string, list<string> > map_t;