IDE Debug Helpers: Difference between revisions
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
[[Category:Tools::QtCreator]] | [[Category:Tools::QtCreator]] | ||
[[Category:Developing_Qt]] | |||
= IDE debug helpers = | = IDE debug helpers = | ||
Line 5: | Line 6: | ||
== Qt Creator == | == Qt Creator == | ||
Qt Creator directly supports introspection of all Qt Containers and QObject derived classes for Qt 4 and Qt 5. | Qt Creator directly supports introspection of all Qt Containers and QObject derived classes for Qt 4 and Qt 5. | ||
User defined types can be supported in addition, see [http://doc.qt.io/qtcreator-2.8/creator-debugging-helpers.html the Qt Creator documentation] for details. | |||
== MS visual studio QString & QByteArray expansions == | == MS visual studio QString & QByteArray expansions == | ||
The new layout of QString in Qt 5 is hard to inspect using the debugger. | The new layout of QString in Qt 5 is hard to inspect using the debugger. | ||
The following code can be added to autoexp.dat (c:files(x86)visual studio 9.0\common7\packages\debugger\autoexp.dat) | |||
You should add it to the <nowiki>[Visualizer]</nowiki> section, before the STL/ATL containers. | |||
<code> | <code> | ||
; Qt types | |||
QStringData{ | |||
preview ([(unsigned short*)$e.d + 2 + $e.offset,su]) | |||
stringview ([(unsigned short*)$e.d + 2 + $e.offset,sub]) | |||
} | |||
QString{ | |||
preview ([$e.d]) | |||
} | |||
QByteArrayData{ | |||
preview ([(unsigned char*)$e.d + 4 + $e.offset,s]) | |||
stringview ([(unsigned char*)$e.d + 4 + $e.offset,sb]) | |||
} | |||
QByteArray{ | |||
preview ([$e.d]) | |||
} | |||
</code> | |||
Unfortunately, sizeof() cannot be used. That is why there is a constant 2 or 4 for the offset pointer. | Unfortunately, sizeof() cannot be used. That is why there is a constant 2 or 4 for the offset pointer. | ||
For an x64 build, the sizes most likely need to be doubled. | |||
== MS Visual Studio 2012 == | == MS Visual Studio 2012 == | ||
There is a new way to visualize native type, see | There is a new way to visualize native type, see | ||
"http://code.msdn.microsoft.com/Writing-type-visualizers-2eae77a2":http://code.msdn.microsoft.com/Writing-type-visualizers-2eae77a2 for details. | |||
Ready-made .natvis files are included in the | Ready-made .natvis files are included in the "Visual Studio add-in":http://wiki.qt.io/QtVSAddin, and can be grabbed directly from "gitorious":https://qt.gitorious.org/qt-labs/vstools/source/tools/Qt4EEAddin/qt5.natvis. | ||
So we can visualize QString and some other types using .natvis file | So we can visualize QString and some other types using .natvis file | ||
(save to file: USERPROFILEDocuments\Visual Studio 2012\Visualizers\Qt5.natvis) | |||
<code> | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<AutoVisualizer > | |||
<Type Name="QString"> | |||
<DisplayString>{(char*)d + d->offset,su}</DisplayString> | |||
</Type> | |||
<Type Name="QtPrivate::RefCount"> | |||
<DisplayString>{atomic}</DisplayString> | |||
</Type> | |||
<Type Name="QBasicAtomicInteger&amp;amp;lt;int&amp;amp;gt;"> | |||
<DisplayString>{_q_value}</DisplayString> | |||
</Type> | |||
<Type Name="QTypedArrayData&amp;amp;lt;'''&amp;gt;"> | |||
<DisplayString>{{Count = {size}}}</DisplayString> | |||
<Expand> | |||
<Item Name="[size]">size</Item> | |||
<ArrayItems> | |||
<Size>size</Size> | |||
<ValuePointer>(iterator) ((char''')this + offset)</ValuePointer> | |||
</ArrayItems> | |||
</Expand> | |||
</Type> | |||
<Type Name="QByteArray"> | |||
<DisplayString>{*d}</DisplayString> | |||
</Type> | |||
<!— More Qt5 types… —> | |||
</AutoVisualizer> | |||
</code> | |||
== MS Visual Studio 2013 == | == MS Visual Studio 2013 == | ||
The | The ".natvis" files introduced in MSVS2012 received some additional attention in MSVS2013: | ||
http://blogs.msdn.com/b/vcblog/archive/2013/06/28/using-visual-studio-2013-to-write-maintainable-native-visualizations-natvis.aspx | http://blogs.msdn.com/b/vcblog/archive/2013/06/28/using-visual-studio-2013-to-write-maintainable-native-visualizations-natvis.aspx |
Revision as of 08:54, 25 February 2015
IDE debug helpers
Qt Creator
Qt Creator directly supports introspection of all Qt Containers and QObject derived classes for Qt 4 and Qt 5. User defined types can be supported in addition, see the Qt Creator documentation for details.
MS visual studio QString & QByteArray expansions
The new layout of QString in Qt 5 is hard to inspect using the debugger. The following code can be added to autoexp.dat (c:files(x86)visual studio 9.0\common7\packages\debugger\autoexp.dat) You should add it to the [Visualizer] section, before the STL/ATL containers.
; Qt types
QStringData{
preview ([(unsigned short*)$e.d + 2 + $e.offset,su])
stringview ([(unsigned short*)$e.d + 2 + $e.offset,sub])
}
QString{
preview ([$e.d])
}
QByteArrayData{
preview ([(unsigned char*)$e.d + 4 + $e.offset,s])
stringview ([(unsigned char*)$e.d + 4 + $e.offset,sb])
}
QByteArray{
preview ([$e.d])
}
Unfortunately, sizeof() cannot be used. That is why there is a constant 2 or 4 for the offset pointer. For an x64 build, the sizes most likely need to be doubled.
MS Visual Studio 2012
There is a new way to visualize native type, see "http://code.msdn.microsoft.com/Writing-type-visualizers-2eae77a2":http://code.msdn.microsoft.com/Writing-type-visualizers-2eae77a2 for details.
Ready-made .natvis files are included in the "Visual Studio add-in":http://wiki.qt.io/QtVSAddin, and can be grabbed directly from "gitorious":https://qt.gitorious.org/qt-labs/vstools/source/tools/Qt4EEAddin/qt5.natvis.
So we can visualize QString and some other types using .natvis file (save to file: USERPROFILEDocuments\Visual Studio 2012\Visualizers\Qt5.natvis)
<?xml version="1.0" encoding="utf-8"?>
<AutoVisualizer >
<Type Name="QString">
<DisplayString>{(char*)d + d->offset,su}</DisplayString>
</Type>
<Type Name="QtPrivate::RefCount">
<DisplayString>{atomic}</DisplayString>
</Type>
<Type Name="QBasicAtomicInteger&amp;amp;lt;int&amp;amp;gt;">
<DisplayString>{_q_value}</DisplayString>
</Type>
<Type Name="QTypedArrayData&amp;amp;lt;'''&amp;gt;">
<DisplayString>{{Count = {size}}}</DisplayString>
<Expand>
<Item Name="[size]">size</Item>
<ArrayItems>
<Size>size</Size>
<ValuePointer>(iterator) ((char''')this + offset)</ValuePointer>
</ArrayItems>
</Expand>
</Type>
<Type Name="QByteArray">
<DisplayString>{*d}</DisplayString>
</Type>
<!— More Qt5 types… —>
</AutoVisualizer>
MS Visual Studio 2013
The ".natvis" files introduced in MSVS2012 received some additional attention in MSVS2013: