Setup a watchpoint/breakpoint over a range of addresses with ptrace

75 Views Asked by At

I'm writing a code in which the parent process shares a shared memory with a child process.

  1. I would like to be able to let the father replace the content of the shared memory, right before the child reads a value.

I know that I can set a hardware breakpoint like in the example below, but this is not working, I guess because there some permission errors, but even with sudo I can't make it work. In any case, the system is limited in the number of breakpoints, so I can't set a breakpoint for every single address.

  1. Also, I know that after a breakpoint is triggered, it disappears. I would like to keep it permanent.

What can I do?

Example code

1

There are 1 best solutions below

0
Maray97 On

A hardware breakpoint is what I would need, however, hardware breakpoints are limited in number (usually 4 in total), then it is not possible to cover a large range of addresses. The alternative is to use a watchpoint like in GDB, which performs single steps in the code until it finds the correct addresses.