Qt wiki will be updated on October 12th 2023 starting at 11:30 AM (EEST) and the maintenance will last around 2-3 hours. During the maintenance the site will be unavailable.

IDE Debug Helpers: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
 
No edit summary
Line 1: Line 1:
=<span class="caps">IDE</span> debug helpers=
[[Category:Tools::QtCreator]]<br />[[Category:Developing_Qt]]


==Qt Creator==
= IDE debug helpers =


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 ==


==MS visual studio QString &amp; QByteArray expansions==
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.


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.
== MS visual studio QString &amp; QByteArray expansions ==


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.
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:files(x86)visual studio 9.0\common7\packages\debugger\autoexp.dat)<br />You should add it to the &lt;nowiki&amp;gt;[Visualizer]&lt;/nowiki&amp;gt; section, before the STL/ATL containers.


==MS Visual Studio 2012==
<code><br />; Qt types<br />QStringData{<br /> preview ([(unsigned short*)$e.d + 2 + $e.offset,su])<br /> stringview ([(unsigned short*)$e.d + 2 + $e.offset,sub])<br />}<br />QString{<br /> preview ([$e.d])<br />}<br />QByteArrayData{<br /> preview ([(unsigned char*)$e.d + 4 + $e.offset,s])<br /> stringview ([(unsigned char*)$e.d + 4 + $e.offset,sb])<br />}<br />QByteArray{<br /> preview ([$e.d])<br />}<br /></code>


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.
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.


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]''.
== MS Visual Studio 2012 ==


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 />
There is a new way to visualize native type, see<br />&quot;http://code.msdn.microsoft.com/Writing-type-visualizers-2eae77a2&amp;quot;:http://code.msdn.microsoft.com/Writing-type-visualizers-2eae77a2 for details.


==MS Visual Studio 2013==
Ready-made .natvis files are included in the &quot;Visual Studio add-in&amp;quot;:http://wiki.qt.io/QtVSAddin, and can be grabbed directly from &quot;gitorious&amp;quot;:https://qt.gitorious.org/qt-labs/vstools/source/tools/Qt4EEAddin/qt5.natvis.


The “.natvis” files introduced in MSVS2012 received some additional attention in MSVS2013:
So we can visualize QString and some other types using .natvis file<br />&amp;#40;save to file: USERPROFILEDocuments\Visual Studio 2012\Visualizers\Qt5.natvis&amp;amp;#41;<br /><code><br />&amp;lt;?xml version=&quot;1.0&amp;quot; encoding=&quot;utf-8&amp;quot;?&amp;gt;<br />&lt;AutoVisualizer &gt;


http://blogs.msdn.com/b/vcblog/archive/2013/06/28/using-visual-studio-2013-to-write-maintainable-native-visualizations-natvis.aspx
&lt;Type Name=&quot;QString&amp;quot;&gt;<br /> &lt;DisplayString&amp;gt;{(char*)d + d-&amp;gt;offset,su}&lt;/DisplayString&amp;gt;<br /> &lt;/Type&amp;gt;
 
&lt;Type Name=&quot;QtPrivate::RefCount&amp;quot;&gt;<br /> &lt;DisplayString&amp;gt;{atomic}&lt;/DisplayString&amp;gt;<br /> &lt;/Type&amp;gt;
 
&lt;Type Name=&quot;QBasicAtomicInteger&amp;amp;amp;lt;int&amp;amp;amp;gt;&quot;&gt;<br /> &lt;DisplayString&amp;gt;{_q_value}&lt;/DisplayString&amp;gt;<br /> &lt;/Type&amp;gt;
 
&lt;Type Name=&quot;QTypedArrayData&amp;amp;amp;lt;'''&amp;amp;gt;&quot;&gt;<br /> &lt;DisplayString&amp;gt;{{Count = {size}}}&lt;/DisplayString&amp;gt;<br /> &lt;Expand&amp;gt;<br /> &lt;Item Name=&quot;[size]&quot;&gt;size&amp;lt;/Item&amp;gt;<br /> &lt;ArrayItems&amp;gt;<br /> &lt;Size&amp;gt;size&amp;lt;/Size&amp;gt;<br /> &lt;ValuePointer&amp;gt;(iterator) ((char''')this + offset)&lt;/ValuePointer&amp;gt;<br /> &lt;/ArrayItems&amp;gt;<br /> &lt;/Expand&amp;gt;<br /> &lt;/Type&amp;gt;
 
&lt;Type Name=&quot;QByteArray&amp;quot;&gt;<br /> &lt;DisplayString&amp;gt;{*d}&lt;/DisplayString&amp;gt;<br /> &lt;/Type&amp;gt;
 
&amp;lt;!— More Qt5 types… —&amp;gt;
 
&lt;/AutoVisualizer&amp;gt;<br /></code>
 
== MS Visual Studio 2013 ==


===Categories:===
The &quot;.natvis&amp;quot; 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 14:30, 23 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 <nowiki&gt;[Visualizer]</nowiki&gt; section, before the STL/ATL containers.

<br />; Qt types<br />QStringData{<br /> preview ([(unsigned short*)$e.d + 2 + $e.offset,su])<br /> stringview ([(unsigned short*)$e.d + 2 + $e.offset,sub])<br />}<br />QString{<br /> preview ([$e.d])<br />}<br />QByteArrayData{<br /> preview ([(unsigned char*)$e.d + 4 + $e.offset,s])<br /> stringview ([(unsigned char*)$e.d + 4 + $e.offset,sb])<br />}<br />QByteArray{<br /> preview ([$e.d])<br />}<br />

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&quot;:http://code.msdn.microsoft.com/Writing-type-visualizers-2eae77a2 for details.

Ready-made .natvis files are included in the "Visual Studio add-in&quot;:http://wiki.qt.io/QtVSAddin, and can be grabbed directly from "gitorious&quot;:https://qt.gitorious.org/qt-labs/vstools/source/tools/Qt4EEAddin/qt5.natvis.

So we can visualize QString and some other types using .natvis file
&#40;save to file: USERPROFILEDocuments\Visual Studio 2012\Visualizers\Qt5.natvis&amp;#41;

<br />&amp;lt;?xml version=&quot;1.0&amp;quot; encoding=&quot;utf-8&amp;quot;?&amp;gt;<br />&lt;AutoVisualizer &gt;

&lt;Type Name=&quot;QString&amp;quot;&gt;<br /> &lt;DisplayString&amp;gt;{(char*)d + d-&amp;gt;offset,su}&lt;/DisplayString&amp;gt;<br /> &lt;/Type&amp;gt;

&lt;Type Name=&quot;QtPrivate::RefCount&amp;quot;&gt;<br /> &lt;DisplayString&amp;gt;{atomic}&lt;/DisplayString&amp;gt;<br /> &lt;/Type&amp;gt;

&lt;Type Name=&quot;QBasicAtomicInteger&amp;amp;amp;lt;int&amp;amp;amp;gt;&quot;&gt;<br /> &lt;DisplayString&amp;gt;{_q_value}&lt;/DisplayString&amp;gt;<br /> &lt;/Type&amp;gt;

&lt;Type Name=&quot;QTypedArrayData&amp;amp;amp;lt;'''&amp;amp;gt;&quot;&gt;<br /> &lt;DisplayString&amp;gt;{{Count = {size}}}&lt;/DisplayString&amp;gt;<br /> &lt;Expand&amp;gt;<br /> &lt;Item Name=&quot;[size]&quot;&gt;size&amp;lt;/Item&amp;gt;<br /> &lt;ArrayItems&amp;gt;<br /> &lt;Size&amp;gt;size&amp;lt;/Size&amp;gt;<br /> &lt;ValuePointer&amp;gt;(iterator) ((char''')this + offset)&lt;/ValuePointer&amp;gt;<br /> &lt;/ArrayItems&amp;gt;<br /> &lt;/Expand&amp;gt;<br /> &lt;/Type&amp;gt;

&lt;Type Name=&quot;QByteArray&amp;quot;&gt;<br /> &lt;DisplayString&amp;gt;{*d}&lt;/DisplayString&amp;gt;<br /> &lt;/Type&amp;gt;

&amp;lt;! More Qt5 types &amp;gt;

&lt;/AutoVisualizer&amp;gt;<br />

MS Visual Studio 2013

The ".natvis&quot; 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