简体   繁体   English

在UNIX上从c / c ++断点/调试其他用户进程

[英]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). 正如标题所说,我正在寻找一种方法,最好是通过一些现有的库在ac / c ++应用程序中在其他进程上设置断点,并在触发这些断点时做出反应(不中断宿主进程)。

The end goal is a small and very general scripting engine, portable across unices, for user land processes. 最终目标是为用户登陆流程提供一个小型且非常通用的脚本引擎,可跨unice移植。

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++. 编辑:与SO标准保持一致,特定的问题是是否可以通过库或c / c ++中的unix syscalls获得断点/进程交互。

the specific question is whether breakpoints/process interaction is available through libraries or unix syscalls in c/c++. 具体的问题是断点/进程交互是否可以通过c / c ++中的库或unix syscalls获得。

Yes: ptrace is the only portable Unix system call for this. 是的: ptrace是对此的唯一便携式Unix系统调用。

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. 我希望您必须先实现〜50%的GDB,然后才能编写任何可编写脚本且通常有用的文件,因此更好的方法可能是 GDB 开始 ,并改用其内置的python脚本。

There are also platform-specific improvements over ptrace , (Solaris implements ptrace in terms of /procfs ; Linux has utrace , though it appears to be stillborn). ptrace ,还具有特定于平台的改进(Solaris以/procfs实现了ptrace ; Linux有了utrace ,尽管看上去已经死了)。

You may also look at Linux-specific frysk for ideas. 您也可以在Linux专用的frysk找到想法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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