开发者

Breakpoint in a particular case

开发者 https://www.devze.com 2023-02-22 04:26 出处:网络
Recently I coded up a function that wasn\'t working properly. I managed to find out what was wrong and fix it in a roundabout manner but I was wondering if there was an easier way. The function (strip

Recently I coded up a function that wasn't working properly. I managed to find out what was wrong and fix it in a roundabout manner but I was wondering if there was an easier way. The function (stripped down) is something like this:

int func(int param)
{
  if(param == 0) return SOMETHING;
  //...
  for(int i = 0;i < 4;i++) {
    // Point A
    func(param - 1);
  }
  //...
}

I wanted to set开发者_运维问答 a breakpoint at Point A so I could see what happens for param = 10 (for example) and i = 0, 1, 2, 3 but the problem is, the function is recursive so it calls itself with (in this case) param = 9, 8,... I was wondering if there was a way to set the breakpoint for only a certain case. I used MS Visual C++ Express 2008 in this case but if there's a way to do it with another compiler (g++/gdb perhaps) then that would be helpful too.


In Visual Studio, you can right-click the breakpoint and modify it in all kinds of ways.
Under Condition... you can specifiy your condition, like param == 10. You can even use simple C library functions for string comparision strcmp(mystr,"hi") == 0!


The Visual Studio debugger supports conditional breakpoints. After you put a breakpoint in the editor, right click it and select "Condition..."


In Visual Studio you can set conditional breakpoints (not sure about other environments). If you want to do this in any C++ environment ASSERT is always an option.

ASSERT(param != 10);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号