简体   繁体   中英

Breakpointing/debugging other user processes from c/c++ on unix

As the headline says, I'm looking for a way to set breakpoints on other processes from within ac/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++.

the specific question is whether breakpoints/process interaction is available through libraries or unix syscalls in c/c++.

Yes: ptrace is 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 implements ptrace in terms of /procfs ; Linux has utrace , though it appears to be stillborn).

You may also look at Linux-specific frysk for ideas.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM