This is a follow up to my previous question about creating a debugger for C source files in Python. The current issue I am facing is monitoring changes to variables. I want to monitor 8 variables say B, B0...B7. My approach is polling every second where ReadProcessMemory is called. This feels inefficient but it works for programs with longer execution times. I want it to work on source code like:
for (int i = 0; i < 10; i++) {
B = i;
printf("B = %d\n", B);
}
I have done research and I found:
- Hardware breakpoints. These are not very easy to implement and so far I found they do not work on variable addresses but "line" addresses. Additionally, they can only be used for a maximum of 4 debug registers.
- Software breakpoints. This also works on "line" addresses not really for variable addresses and monitoring.
- Page guards. Using
VirtualProtectExdoes not help in my case because this monitors an entire page not just select addresses. So this fires on addresses I am not interested in. Filtering them by matching their addresses to the ones in a list does not work. This is also slow and inefficient. - I would need assstance in understanding whether this answer involving
WaitOnAddressorWaitForSingleObjectis appropriate to my use case.
FYI this debugger will be for 32 bit programs.
ctypesto Python. This isn't simple and we're not doing the work for you, but can help fix problems if you get stuck.