Is there a way "This expression has side effects and will not be evaluated"?

In Visual Studio 2017, I created a .natvis debug visualization rule that calls a C ++ function.

The debugger shows:

This expression has side effects and will not be evaluated.

In addition, it shows a small blue arrow that you can click to make it evaluate, and then it actually calls the function. (I think this may be a recent feature, because I seem to remember trying to do this in VS2013 and I don't remember that it had a workaround)

My question is: is there a way that I can bypass this security check for a long time so that it always immediately evaluates my function and does not require me to click on the arrow?

I considered a very similar question: "This expression causes side effects and will not be evaluated." How to suppress? where the accepted answer is only valid for C # (adding, ac at the end of the C # expression causes the debugger to automatically overestimate it)

I assume that if such a thing existed, it would be one of the following mechanisms:

  • A registry setting or other global settings that disable security checks all the time.
  • A way to annotate a code or .natvis rule so that the compiler somehow knows that it is a safe and clean function without side effects.

: uint32 , , , . u32 , , node. , , , .natvis .

+5
2

, Visual Studio, , , int MyTestFunction() { return 56; }, " .

, , , ( , ), , XML- .natvis CustomListItems.

, , - , , catch-all , - . <CustomListItems> , , , :

  • <Variable> ,
  • <Loop> ,
  • <Break Condition="myCondition"> ,
  • <Exec> , , <Variable>,
  • <If Condition="myCondition">
  • <Item Name="name">value</Item>, .

, CustomListItems ( <Expand> <Variable> , , )

++, (, &gt; &lt; > <, XML).

, , ,

  • .natvis Visual Studio, , .natvis . (: , , VS2017 .natvis )
  • <Item> , " ". .natvis , <Item> . , , . .

CustomListItems.

https://msdn.microsoft.com/en-us/library/jj620914.aspx

+3

, .

: Intrinsic XML, This expression has side effects....

:

, :

namespace rkstl
{
    namespace strings
    {
        //null-terminated string object consisting of 'char' elements
        class string 
        {
         public:    
             //... c'tors, copy c'tor and d'tor come here

             length(); //returns the length of null-terminated string: _mSize
             capacity(); //returns the length of the actual buffer: _mCap
             clear();

             //... other member functions

         private:
             char* _pStr; //the actual buffer
             size_t _mSize; //length of the string
             size_t _mCap; //length of the actual buffer
        };

        //null-terminated wide string object consisting of 'wchar_t' elements
        class wstring
        {
         //...
        };

    }
}

, length() capacity() . , .XML, This expression has side effects..., ( ), , :

<Type Name="rkstl::strings::string">
<DisplayString>{_pStr,na}</DisplayString>
<StringView>_pStr,na</StringView>
<Expand>
  <Item Name="[string length]" ExcludeView="simple">length()</Item>
  <Item Name="[buffer capacity]" ExcludeView="simple">capacity()</Item>
  <ArrayItems>
    <Size>_pEnd - _pBegin</Size>
    <ValuePointer>_pStr</ValuePointer>
  </ArrayItems>
</Expand>

, , . .natvis XML. .natvis rkstl::strings::string:

<Type Name="rkstl::strings::string">
<Intrinsic Name="length_dbg" Expression="(_mSize)"/>
<Intrinsic Name="capacity_dbg" Expression="(_mCap)"/>
<DisplayString>{_pStr,na}</DisplayString>
<StringView>_pStr,na</StringView>
<Expand>
  <Item Name="[length of the string]" ExcludeView="simple">length_dbg()</Item>
  <Item Name="[capacity of the buffer]" ExcludeView="simple">capacity_dbg()</Item>
  <ArrayItems>
    <Size>_pEnd - _pBegin</Size>
    <ValuePointer>_pStr</ValuePointer>
  </ArrayItems>
</Expand>

, length_dbg() capacity_dbg() . , , . :

enter image description here

0

Source: https://habr.com/ru/post/1688473/


All Articles