IDE Debug Helpers: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
 
mNo edit summary
(17 intermediate revisions by 8 users not shown)
Line 1: Line 1:
=<span class="caps">IDE</span> debug helpers=
[[Category:Tools::QtCreator]]
[[Category:Developing_Qt]]


==Qt Creator==
== Qt Creator ==


Qt Creator directly supports introspection of all Qt Containers and QObject derived classes for Qt 4 and Qt 5.<br /> 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.
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/creator-debugging-helpers.html the Qt Creator documentation] for details.


==MS visual studio QString &amp; QByteArray expansions==
== LLDB ==


The new layout of QString in Qt 5 is hard to inspect using the debugger.<br /> The following code can be added to autoexp.dat (c:\program files(x86)\microsoft visual studio 9.0\common7\packages\debugger\autoexp.dat)<br /> You should add it to the &lt;nowiki&gt;[Visualizer]&lt;/nowiki&gt; section, before the <span class="caps">STL</span>/ATL containers.
There is an effort to introspect Qt types using LLDB at https://bitbucket.org/lukeworth/lldb-qt-formatters.


Unfortunately, sizeof() cannot be used. That is why there is a constant 2 or 4 for the offset pointer.<br /> For an x64 build, the sizes most likely need to be doubled.
KDevelop ships formatter scripts in its LLDB plugin for Qt types that can be used directly in plain LLDB. https://unlimitedcodeworks.xyz/blog/2016/08/20/gsoc-kdevelop-lldb-final-report/#using-data-formatter-scripts-outside-kdevelop


==MS Visual Studio 2012==
== MS visual studio QString & QByteArray expansions ==


There is a new way to visualize native type, see<br />http://code.msdn.microsoft.com/Writing-type-visualizers-2eae77a2 ''[code.msdn.microsoft.com]'' for details.
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:\program 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.


Ready-made .natvis files are included in the [[QtVSAddin|Visual Studio add-in]] ''[qt.io]'', and can be grabbed directly from [https://qt.gitorious.org/qt-labs/vstools/source/tools/Qt4EEAddin/qt5.natvis gitorious] ''[qt.gitorious.org]''.
<pre>
; Qt types
QStringData{
preview ([(unsigned short*)$e.d + $e.offset,su])
stringview ([(unsigned short*)$e.d + $e.offset,sub])
}
QString{
preview ([$e.d])
}
QByteArrayData{
preview ([(unsigned char*)$e.d + $e.offset,s])
stringview ([(unsigned char*)$e.d + $e.offset,sb])
}
QByteArray{
preview ([$e.d])
}
</pre>


So we can visualize QString and some other types using .natvis file<br /> (save to file: <span class="caps">USERPROFILE</span>\My Documents\Visual Studio 2012\Visualizers\Qt5.natvis)<br />
If all else fails you can always just add a watcher for
  (char*)str.d + str.d->offset,su
in the debugger, to see the contents of str.


==MS Visual Studio 2013==
== MS Visual Studio 2012 ==


The “.natvis” files introduced in MSVS2012 received some additional attention in MSVS2013:
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.


http://blogs.msdn.com/b/vcblog/archive/2013/06/28/using-visual-studio-2013-to-write-maintainable-native-visualizations-natvis.aspx
Ready-made .natvis files are included in the [http://wiki.qt.io/QtVSAddin Visual Studio add-in].
 
So we can visualize QString and some other types using [http://code.qt.io/cgit/qt-labs/vstools.git/plain/tools/Qt4EEAddin/qt5.natvis qt5.natvis] file
(save to file: %USERPROFILE%\Documents\Visual Studio 2012\Visualizers\qt5.natvis)
<pre>
<?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<int>">
<DisplayString>{_q_value}</DisplayString>
</Type>
 
<Type Name="QTypedArrayData<'''>">
<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>
</pre>
 
== MS Visual Studio 2013 ==


===Categories:===
The ".natvis" files introduced in MSVS2012 received some additional attention in MSVS2013:


* [[:Category:Developing Qt|Developing_Qt]]
http://blogs.msdn.com/b/vcblog/archive/2013/06/28/using-visual-studio-2013-to-write-maintainable-native-visualizations-natvis.aspx
* [[:Category:Tools|Tools]]
** [[:Category:Tools::QtCreator|QtCreator]]

Revision as of 07:56, 15 May 2017


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.

LLDB

There is an effort to introspect Qt types using LLDB at https://bitbucket.org/lukeworth/lldb-qt-formatters.

KDevelop ships formatter scripts in its LLDB plugin for Qt types that can be used directly in plain LLDB. https://unlimitedcodeworks.xyz/blog/2016/08/20/gsoc-kdevelop-lldb-final-report/#using-data-formatter-scripts-outside-kdevelop

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:\program 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 + $e.offset,su])
 stringview ([(unsigned short*)$e.d + $e.offset,sub])
}
QString{
 preview ([$e.d])
}
QByteArrayData{
 preview ([(unsigned char*)$e.d + $e.offset,s])
 stringview ([(unsigned char*)$e.d + $e.offset,sb])
}
QByteArray{
 preview ([$e.d])
}

If all else fails you can always just add a watcher for

  (char*)str.d + str.d->offset,su

in the debugger, to see the contents of str.

MS Visual Studio 2012

There is a new way to visualize native type, see http://code.msdn.microsoft.com/Writing-type-visualizers-2eae77a2 for details.

Ready-made .natvis files are included in the Visual Studio add-in.

So we can visualize QString and some other types using qt5.natvis file (save to file: %USERPROFILE%\Documents\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<int>">
 <DisplayString>{_q_value}</DisplayString>
 </Type>

<Type Name="QTypedArrayData<'''>">
 <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:

http://blogs.msdn.com/b/vcblog/archive/2013/06/28/using-visual-studio-2013-to-write-maintainable-native-visualizations-natvis.aspx