2

I need to debug a complex GC written in C++ and there is a lot of aliasing for variables inside the code which makes tracking the value of a specific variable quite difficult. Usually I do this using data breakpoints, but obviously the address changes every debug session and I need to add a breakpoint where the variable is created, get its address, remove the old breakpoint, add the new one, etc. If I multiply this process for several variables it becomes annoying and also time consuming.

Is it possible to add a data breakpoint programmatically?

I've found this answer Programmatic data breakpoint in Visual Studio 2010, but it's quite old and I hope there is better support for this.

Zeus
  • 3,703
  • 3
  • 7
  • 20
Mircea Ispas
  • 20,260
  • 32
  • 123
  • 211
  • just an idea but maybe you can make a macro of keyboard shortcuts or use `pyautogui` or something similar – bb1950328 Mar 26 '21 at 12:57
  • Do you specifically need Visual Studio Data breakpoints? For a GC, it might make sense to implement your own watch mechanism using [`GetWriteWatch`](https://learn.microsoft.com/en-us/windows/win32/api/memoryapi/nf-memoryapi-getwritewatch) or [Guard Pages](https://learn.microsoft.com/en-us/windows/win32/memory/creating-guard-pages) – MSalters Mar 26 '21 at 13:04
  • @MSalters the fact that it's a GC is most likely not relevant, probably I shouldn't have added that info in the question. I just need to track the value changes for few specific variables during the debugging session in a complex code base with lots of aliasing. – Mircea Ispas Mar 26 '21 at 13:11
  • The fundamental problem is that Visual Studio needs a [trick](https://stackoverflow.com/a/41179799/15416) to set these data breakpoints; you can't do that from Ring 3 code. And there are only 4 HW breakpoints so it needs guard page tricks if you have more. – MSalters Mar 26 '21 at 13:24
  • 1
    Visual Studio has an SDK which allows it: `EnvDTE.Breakpoints.Add` but that's for Visual Studio extenstions, not for the program to be debugged. – MSalters Mar 26 '21 at 13:33

0 Answers0