Is it possible to set a gdb watchpoint programmatically?

后端 未结 5 1746

I want to set a watchpoint (break on hardware write) temporarily in my C++ program to find memory corruption.

I\'ve seen all the ways to do it manually through gdb,

5条回答
  •  不思量自难忘°
    2020-12-04 20:40

    If you happen to be using Xcode, you can achieve the required effect (automatic setting of watchpoints) by using an action on another breakpoint to set your watchpoint:

    1. Set up a breakpoint somewhere where the variable you want to watch will be in scope that will be hit before you need to start watching the variable,
    2. Right-click on the breakpoint and select Edit Breakpoint...,
    3. Click on Add Action and add a Debugger Command with an LLDB command like: watchpoint set variable (or if you're using GDB1, a command like: watch ),
    4. Check the Automatically continue after evaluating actions checkbox.

    enter image description here

    1: GDB is no longer supported in more recent versions of Xcode, but I believe it is still possible to set it up manually.

提交回复
热议问题