如何自动启动/调试大型项目?
场景:
有一个复杂的软件,手动启动很烦人。 我所做的是创建一个 python 脚本来启动可执行文件并附加 gdb 进行调试。
进程启动脚本:
- 确保设置环境变量。
- 确保将本地构建目录添加到环境的 LD_LIBRARY_PATH 变量中。
- 将当前工作目录更改为可执行文件期望的位置(不是我的设计)
- 使用配置文件启动可执行文件唯一的命令行选项
- 将输出从可执行文件传输到第二个日志记录进程
- 记住可执行文件的PID,然后启动并运行它。 将 gdb 附加到正在运行的可执行文件。
该脚本有效,但有一点需要注意。 ctrl-c 不会中断调试程序并将控制权返回给 gdb。 因此,如果我在没有活动断点的情况下“继续”,我将永远无法再次停止该进程,它必须从另一个 shell 中终止/中断。 顺便说一句,运行“kill -s SIGINT
起初我以为Python正在抓取SIGINT信号,但我设置的情况似乎并非如此up 信号处理程序将信号转发给调试者,但这并不能解决问题。
我已经尝试了对 python 脚本的各种配置(调用 os.spawn* 而不是子进程等)。似乎无论我采取什么方式,如果 python 启动了子进程,SIGINT (ctrl-c) 信号都不会路由到 gdb 或子进程。
当前的思路
- 这可能与需要 调试者和调试者的单独进程组 ID gdb...对此有任何可信度吗?
- SELinux 可能存在错误吗?
信息:
- gdb 6.8
- Python 2.5.2(Python 2.6.1 也存在问题)
- SELinux 环境(向进程传递信号的错误?)
我考虑过的替代方案:
- 设置建立一个 .gdbinit 文件来完成脚本所做的大部分事情,环境变量和当前工作目录是这种方法的问题。
- 手动启动可执行文件并附加 gdb(恶心)
问题: 如何自动启动/调试大型项目?
更新: 我在下面尝试了 Nicholas Riley 的示例,在我家里的 Macintosh 上,它们都允许 cntl-c 在不同程度上工作,在生产 boxen 上(我现在相信可能正在运行 SELinux),它们不允许...
Scenario:
There is a complex piece of software that is annoying to launch by hand. What I've done is to create a python script to launch the executable and attach gdb for debugging.
The process launching script:
- ensures an environment variable is set.
- ensures a local build directory gets added to the environment's
LD_LIBRARY_PATH
variable. - changes the current working directory to where the executable expects to be (not my design)
- launches the executable with a config file the only command line option
- pipes the output from the executable to a second logging process
- remembers PID of executable, then launches & attaches gdb to running executable.
The script works, with one caveat. ctrl-c doesn't interrupt the debugee and return control to gdb. So if I "continue" with no active breakpoints I can never stop the process again, it has to be killed/interrupted from another shell. BTW, running "kill -s SIGINT <pid>" where <pid> is the debuggee's pid does get me back to gdb's prompt... but it is really annoying to have to do things this way
At first I thought Python was grabbing the SIGINT signal, but this doesn't seem to be the case as I set up signal handlers forward the signal to the debugee and that doesn't fix the problem.
I've tried various configurations to the python script (calling os.spawn* instead of subprocess, etc.) It seems that any way I go about it, if python launched the child process, SIGINT (ctrl-c) signals DO NOT to get routed to gdb or the child process.
Current line of thinking
- This might be related to needing a
separate process group id for the debugee & gdb...any credence to this? - Possible bug with SELinux?
Info:
- gdb 6.8
- Python 2.5.2 (problem present with Python 2.6.1 as well)
- SELinux Environment (bug delivering signals to processes?)
Alternatives I've considered:
- Setting up a .gdbinit file to do as much of what the script does, environment variables and current working directory are a problem with this approach.
- Launching executable and attaching gdb manually (yuck)
Question:
How do you automate the launching/debugging of large scale projects?
Update:
I've tried Nicholas Riley's examples below, on my Macintosh at home they all allow cntl-c to work to varrying degrees, on the production boxen (which I now to believe may be running SELinux) they don't...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以尝试忽略它,而不是将信号从 Python 转发到调试对象。 以下内容对我有用:
这样我就可以在 GDB 内重复 ^C 并毫无问题地中断调试程序,但是我确实看到了一些奇怪的行为。
顺便说一句,我在将信号转发到目标进程时也没有问题。
那么,也许您的情况还发生了其他情况? 如果您发布了一些损坏的代码,这可能会有所帮助。
Instead of forwarding the signal to the debuggee from Python, you could try just ignoring it. The following worked for me:
With this I was able to ^C repeatedly inside GDB and interrupt the debuggee without a problem, however I did see some weird behavior.
Incidentally, I also had no problem when forwarding the signal to the target process.
So, maybe something else is going on in your case? It might help if you posted some code that breaks.
您的评论指出您正在使用 putty 登录...您有控制 tty 吗? 使用 openssh,您需要添加 -T 选项,我不知道 putty 如何/是否会按照您使用的方式执行此操作。
另外:您可以尝试使用 cygwin 的 ssh 而不是 putty。
Your comment notes that you're sshing in with putty... do you have a controlling tty? With openssh you would want to add the -T option, I don't know how/if putty will do this the way you're using it.
Also: you might try using cygwin's ssh instead of putty.
如果您已经设置了一个当前脚本来执行此操作,但在自动化部分操作时遇到问题,也许您可以抓住 Expect 并使用它来提供设置,然后返回到交互模式以启动该过程。 然后你仍然可以使用 ctrl-c 来中断。
if you already have a current script set up to do this, but are having problems automating part of it, maybe you can just grab expect and use it to provide the setup, then drop back into interactive mode in expect to launch the process. Then you can still have your ctrl-c available to interrupt.