How do I set persistent and conditional watchpoints on locally scoped variables?

后端 未结 4 1738
执笔经年
执笔经年 2020-12-13 12:57
  1. If I set a watchpoint for a variable local to the current scope, it will be auto deleted when going out of the scope. Is there any way to set it once and keep it au

4条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-13 13:36

    1. I'm not sure which language us are using, so the exact answer will vary, but could you change the variable to either be static, global, or dynamically allocated (and don't free it when the function returns?). This way it's raw address won't change, and gdb will be able breakpoint on it.

    2. Instead of watching the value whe it equals a specific value; you should set a conditional break point on the line where you want to check the value of var1. This should effectively have the same effect

    e.g.

    (gdb) break main.c:123 if (var1 == 0)
    

提交回复
热议问题