lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]




Le mer. 24 nov. 2021 à 23:21, Simon Lambert <simon.lambert.4@gmail.com> a écrit :
Looking for a Visual Studio .natvis file for Lua 5.3 to help debugging the stack.


--
Benoit.
<?xml version="1.0" encoding="utf-8"?>
<!--
    Add a link to this file in %USER%\Documents\Visual Studio 2015\Visualizers\ with mklink command line tool.
    Or add this file to the vcproj you are debugging.
    You can then watch a Lua State with {,,lua53.dll}*(lua_State*)pointer
-->
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010";>
    <Type Name="lua_State">
        <DisplayString>stack top = {top-(ci->func+1),d}</DisplayString>
        <Expand>
            <CustomListItems>
                <Variable Name="count" InitialValue="top-(ci->func+1)"/>
                <Variable Name="index" InitialValue="0"/>
                <Loop>
                    <Break Condition="index == count"/>
                    <Item Name="[{-1-index,d}]">ci->func[count-index]</Item>
                    <Exec>++ index</Exec>
                </Loop>
            </CustomListItems>
            <Item Name="[registry]">l_G->l_registry</Item>
        </Expand>
    </Type>
    <Type Name="lua_TValue">
        <DisplayString Condition="this == &amp;luaO_nilobject_">                                 NIL                                   </DisplayString>
        <DisplayString Condition="((tt_ &amp; 0xf) == 0)">                                       nil                                   </DisplayString>
        <DisplayString Condition="((tt_ &amp; 0xf) == 1)">                                       &lt;BOOL&gt; {value_.b,d}             </DisplayString>
        <DisplayString Condition="((tt_ &amp; 0xf) == 2)">                                       &lt;LDAT&gt; {value_.p}               </DisplayString>
        <DisplayString Condition="((tt_ &amp; 0xf) == 3) &amp;&amp; ((tt_ &amp; 0x30) == 0x00)"> &lt;FNUM&gt; {value_.n}               </DisplayString>
        <DisplayString Condition="((tt_ &amp; 0xf) == 3) &amp;&amp; ((tt_ &amp; 0x30) == 0x10)"> &lt;INUM&gt; {value_.i}               </DisplayString>
        <DisplayString Condition="((tt_ &amp; 0xf) == 4) &amp;&amp; ((tt_ &amp; 0x30) == 0x00)"> &lt;SSTR&gt; {*(TString*)value_.gc}   </DisplayString>
        <DisplayString Condition="((tt_ &amp; 0xf) == 4) &amp;&amp; ((tt_ &amp; 0x30) == 0x10)"> &lt;LSTR&gt; {*(TString*)value_.gc}   </DisplayString>
        <DisplayString Condition="((tt_ &amp; 0xf) == 5)">                                       &lt;TABL&gt; {*(Table*)value_.gc}     </DisplayString>
        <DisplayString Condition="((tt_ &amp; 0xf) == 6) &amp;&amp; ((tt_ &amp; 0x30) == 0x00)"> &lt;LCLO&gt; {*(LClosure*)value_.gc}  </DisplayString>
        <DisplayString Condition="((tt_ &amp; 0xf) == 6) &amp;&amp; ((tt_ &amp; 0x30) == 0x10)"> &lt;FPTR&gt; {value_.f}               </DisplayString>
        <DisplayString Condition="((tt_ &amp; 0xf) == 6) &amp;&amp; ((tt_ &amp; 0x30) == 0x20)"> &lt;CCLO&gt; {*(CClosure*)value_.gc}  </DisplayString>
        <DisplayString Condition="((tt_ &amp; 0xf) == 7)">                                       &lt;UDAT&gt; {*((Udata*)value_.gc)}   </DisplayString>
        <DisplayString Condition="((tt_ &amp; 0xf) == 8)">                                       &lt;THRD&gt; {*(lua_State*)value_.gc} </DisplayString>
        <DisplayString>                                                                          unknown ({tt_})                       </DisplayString>
        <Expand>
            <Item Condition="((tt_ &amp; 0xf) == 5)"                                       Name="[contents]">*(Table*)value_.gc</Item>
            <Item Condition="((tt_ &amp; 0xf) == 6) &amp;&amp; ((tt_ &amp; 0x30) == 0x00)" Name="[Lua closure]">*(LClosure*)value_.gc</Item>
            <Item Condition="((tt_ &amp; 0xf) == 6) &amp;&amp; ((tt_ &amp; 0x30) == 0x20)" Name="[C Closure]">*(CClosure*)value_.gc</Item>
            <Item Condition="((tt_ &amp; 0xf) == 7)"                                       Name="[full userdata]">*(Udata*)value_.gc</Item>
            <Item Condition="((tt_ &amp; 0xf) == 8)"                                       Name="[thread]">*(lua_State*)value_.gc</Item>
        </Expand>
    </Type>
    <Type Name="Udata">
        <DisplayString>{(void*)(this+1)}</DisplayString>
        <Expand>
            <Item Name="[metatable]"                 Condition="metatable!=nullptr">                                               *metatable            </Item>
            <Item Name="[uservalue: nil]"            Condition="((ttuv_ &amp; 0xf) == 0)">                                         "nil",sb              </Item>
            <Item Name="[uservalue: boolean]"        Condition="((ttuv_ &amp; 0xf) == 1)">                                         user_.b,d             </Item>
            <Item Name="[uservalue: light userdata]" Condition="((ttuv_ &amp; 0xf) == 2)">                                         user_.p               </Item>
            <Item Name="[uservalue: integer]"        Condition="((ttuv_ &amp; 0xf) == 3) &amp;&amp; ((ttuv_ &amp; 0x30) == 0x00)"> user_.n               </Item>
            <Item Name="[uservalue: number]"         Condition="((ttuv_ &amp; 0xf) == 3) &amp;&amp; ((ttuv_ &amp; 0x30) == 0x10)"> user_.i               </Item>
            <Item Name="[uservalue: short string]"   Condition="((ttuv_ &amp; 0xf) == 4) &amp;&amp; ((ttuv_ &amp; 0x30) == 0x00)"> *(TString*)user_.gc   </Item>
            <Item Name="[uservalue: long string]"    Condition="((ttuv_ &amp; 0xf) == 4) &amp;&amp; ((ttuv_ &amp; 0x30) == 0x10)"> *(TString*)user_.gc   </Item>
            <Item Name="[uservalue: table]"          Condition="((ttuv_ &amp; 0xf) == 5)">                                         *(Table*)user_.gc     </Item>
            <Item Name="[uservalue: full userdata]"  Condition="((ttuv_ &amp; 0xf) == 7)">                                         *(Udata*)user_.gc     </Item>
            <Item Name="[uservalue: thread]"         Condition="((ttuv_ &amp; 0xf) == 8)">                                         *(lua_State*)user_.gc </Item>
            <Item Name="[uservalue: unknown]"        Condition="((ttuv_ &amp; 0xf) &gt; 8)">                                       user_                 </Item>
        </Expand>
    </Type>
    <Type Name="TString">
        <DisplayString>{(char*)(this+1),s}</DisplayString>
    </Type>

    <Type Name="Table">
        <DisplayString>sizearray={sizearray,d} sizenode={1&lt;&lt;lsizenode,d}</DisplayString>
        <Expand>
            <Item Name="metatable" Condition="metatable!=nullptr">metatable</Item>
            <Item Name="[array size]">sizearray,d</Item>
            <CustomListItems MaxItemsPerView="100">
                <Variable Name="node" InitialValue="(TValue*)0"/>
                <Variable Name="inode" InitialValue="0"/>
                <Loop>
                    <Break Condition="inode>=sizearray"/>
                    <Item>array[inode]</Item>
                    <Exec>++ inode</Exec>
                </Loop>
            </CustomListItems>
            <Item Name="[node size]">1&lt;&lt;lsizenode,d</Item>
            <CustomListItems MaxItemsPerView="100">
                <Variable Name="mynode" InitialValue="node"/>
                <Variable Name="lastnode" InitialValue="node+(1&lt;&lt;lsizenode)"/>
                <Loop>
                    <Break Condition="mynode>=lastnode"/>
                    <Item>*mynode</Item>
                    <Exec>++ mynode</Exec>
                </Loop>
            </CustomListItems>
        </Expand>
    </Type>

    <Type Name="Node">
        <DisplayString>[{i_key}] = {i_val}</DisplayString>
        <!--
        <Expand>
            <Item Name="[key]">i_key.tvk</Item>
            <Item Name="[val]">i_val</Item>
        </Expand>
        -->
    </Type>
    <Type Name="TKey">
        <DisplayString>{tvk}</DisplayString>
    </Type>
    <Type Name="LClosure">
        <DisplayString>Lua function defined at {p->source}:{p->linedefined,d}-&gt;{p->lastlinedefined,d}</DisplayString>
    </Type>
    <!--
    <Type Name="CClosure">
        <DisplayString>{f}</DisplayString>
    </Type>
    <Type Name="Closure">
        <DisplayString>{c}</DisplayString>
    </Type>
-->
</AutoVisualizer>