0

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:

  1. 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.
  2. Software breakpoints. This also works on "line" addresses not really for variable addresses and monitoring.
  3. Page guards. Using VirtualProtectEx does 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.
  4. I would need assstance in understanding whether this answer involving WaitOnAddress or WaitForSingleObject is appropriate to my use case.

FYI this debugger will be for 32 bit programs.

6
  • 1
    Configure the x86 debug registers DR0-DR7 as a hardware data breakpoint. Start with querying "how to set an x86 data breakpoint with the win32 api". Once you have some code, post a specific problem. Commented yesterday
  • 1
    I recommend writing a minimal reproducible example in C, then port it via ctypes to Python. This isn't simple and we're not doing the work for you, but can help fix problems if you get stuck. Commented yesterday
  • The function WaitOnAddress is not useful in your case, because, as stated in the documentation of that function, it will only be triggered by changes that were reported by WakeByAddressSingle or WakeByAddressAll. These functions are only intended for thread synchronization. Commented yesterday
  • Hardware breakpoints are less complicated (here is an implementation in Rust, with explanations). If both hardware and software breakpoints are too hard for you to implement, you'll have to use an existing debug engine instead. Commented yesterday
  • @IInspectable I had already implemented software breakpoints. You are probably aware of this as you are a commenter in my previous question. The issue is that it doesn't work for variable addresses but line addresses. Commented yesterday

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.