0

We can change value manually by changing in variable tooltip or local/auto/watch window. But I want to change value of variable automatically to some specific hardcoded value or based on a code snippet. For eg.-

int main()
{
int a=0,b=1,c=2;
//bla bla
for(int i=0; i<100; ++i)
{
executeMe();
}
//bla bla
}

I want to put a breakpoint on line "executeMe()" and change value of 'b' to hardcoded value 3 or based on variable value 'c', so executing instruction 'b=c'. And continues execution without stopping everytime on breakpoint. How to do this in VS?

ShrinivasD
  • 63
  • 7
  • Could you get useful information from Wendy's suggestion? Or you could think about using condition breakpoint: https://blogs.msdn.microsoft.com/devops/2014/10/06/new-breakpoint-configuration-experience-in-visual-studio-2015/. So you could control the breakpoint when it will be hit. – Jack Zhai Oct 10 '17 at 05:10
  • Would you please share the latest information in your side? Is the condition breakpoint or custom code the path for you? – Jack Zhai Oct 13 '17 at 05:29
  • @JackZhai-MSFT https://stackoverflow.com/a/15415763/2328412 This answer by Tom McKeown helped me. – ShrinivasD Oct 18 '17 at 07:17
  • If possible, you could share the solution as an answer, and then mark it after two days, so it could also help other community members who get the same issue. Have a nice day:) – Jack Zhai Oct 18 '17 at 10:27

2 Answers2

1

Use the 'Print a message:' option instead of a macro. Values from code can be printed by placing them inside {}. The key is that VS will also evaluate the content as an expression - so {variable_name=0} should achieve the same as the macro example.

Thanks to Tom McKeown for this solution on stackoverflow.com/a/15415763/2328412

ShrinivasD
  • 63
  • 7
0

You could use #if preprocessor directives, which is similar with below code.

        int a = 0, b = 1, c = 2;
        for (int i = 0; i < 100; ++i)
        {
#if DEBUG
            b=3;
#endif
            executeMe();
        }
Weiwei
  • 3,674
  • 1
  • 10
  • 13