自动连接到CGI进程并在退出前中断GDB? [英] Automatically connect to a CGI process and break in GDB before it exits?

查看:82
本文介绍了自动连接到CGI进程并在退出前中断GDB?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于通过CGI-BIN访问的C应用程序,在线文档要访问该流程并中断GDB,必须处理源代码(即添加无限循环),以使该流程足够长的时间供开发人员使用,以附加,退出该循环并进行调试。



一种工具可以监视进程列表并通过GDB附加,并立即中断以便开发人员在无需更改源代码的情况下实现这一目标是否可行? ?



我要开发的粗略结构大致如下:

1.我的流程监视以下流程的清单:

2.一个与我的应用程序名称匹配的进程,所有者 Apache 出现在列表中。

3.我的进程立即执行一个'pgrep''gdb -p'命令,然后发送断点

4.开发人员然后可以访问该进程并查看执行流程。



由于某些限制(例如,可能不一定总是满足的比赛条件),这是否可行? div class = h2_lin>解决方案


这可行吗


确定:一个简单的shell脚本将执行以下操作:

 而为true;如果[[-n $ PID]]执行
PID = $(pgrep my_app)
;然后
gdb -p $ PID
fi
完成




比赛条件


问题是在 pgrep gdb -p 应用程序可能会取得重大进展,甚至运行完成。



唯一避免这种情况的方法是拦截系统上的所有 execve 系统调用,例如Tom Tromey的 preattach.stp 可以。


For a C application accessed via CGI-BIN, documentation online for accessing the process and breaking in GDB relies on manipulating the source code (i.e. adding an infinite loop), in order for the process to be available long enough for a developer to attach, exit the loop, and debug.

Is it feasible that a tool could monitor the process list, and attach via GDB, immediately breaking in order for a developer to achieve this without requiring source code changes?

The rough structure of what I have in mind to develop is something along the lines of:
1. My process monitors the process list on the system.
2. A process matching the name of my application, and owner Apache appears in the list.
3. My process immediately performs a 'pgrep' and 'gdb -p' command, then sending a break-point command to pause the process.
4. The developer can then access the process and look at the flow of execution.

Is this feasible as an idea or not possible due to some constraints (i.e. a race condition which may not always be fufilled?)

解决方案

Is this feasible

Sure: a trivial shell script will do:

while true; do
  PID=$(pgrep my_app)
  if [[ -n "$PID" ]]; then
    gdb -p "$PID"
  fi
done

a race condition

The problem is that between pgrep and gdb -p the application may make significant progress, or even run to completion.

The only way to avoid that is to intercept all execve system calls on the system, as Tom Tromey's preattach.stp does.

这篇关于自动连接到CGI进程并在退出前中断GDB?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆