As the headline says, I’m looking for a way to set breakpoints on other processes from within a c/c++ application, ideally via some existing library, and react when those breakpoints are triggered (without interrupting the host process).
The end goal is a small and very general scripting engine, portable across unices, for user land processes.
So, does anyone have ideas on how this could be achieved, or heard about similar projects or functionality? If my general approach is off I’d gladly take feedback on how to achieve this in another way.
EDIT: In keeping with SO standards, the specific question is whether breakpoints/process interaction is available through libraries or unix syscalls in c/c++.
Yes:
ptraceis the only portable Unix system call for this.You will quickly discover that to do anything useful with it, you’ll have to write a ton of code.
I expect you’ll have to implement ~50% of GDB before you have anything scriptable and generally useful, so a better approach might be to start with GDB, and use its built-in python scripting instead.
There are also platform-specific improvements over
ptrace, (Solaris implementsptracein terms of/procfs; Linux hasutrace, though it appears to be stillborn).You may also look at Linux-specific
fryskfor ideas.