如何自动启动/调试大型项目?

发布于 2024-07-17 07:55:13 字数 1374 浏览 9 评论 0原文

场景

有一个复杂的软件,手动启动很烦人。 我所做的是创建一个 python 脚本来启动可执行文件并附加 gdb 进行调试。

进程启动脚本:

  • 确保设置环境变量。
  • 确保将本地构建目录添加到环境的 LD_LIBRARY_PATH 变量中。
  • 将当前工作目录更改为可执行文件期望的位置(不是我的设计)
  • 使用配置文件启动可执行文件唯一的命令行选项
  • 将输出从可执行文件传输到第二个日志记录进程
  • 记住可执行文件的PID,然后启动并运行它。 将 gdb 附加到正在运行的可执行文件。

该脚本有效,但有一点需要注意。 ctrl-c 不会中断调试程序并将控制权返回给 gdb。 因此,如果我在没有活动断点的情况下“继续”,我将永远无法再次停止该进程,它必须从另一个 shell 中终止/中断。 顺便说一句,运行“kill -s SIGINT” 其中被调试者的pid确实让我回到gdb的提示符...但是必须以这种方式做事真的很烦人

起初我以为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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

兲鉂ぱ嘚淚 2024-07-24 07:55:13

您可以尝试忽略它,而不是将信号从 Python 转发到调试对象。 以下内容对我有用:

import signal
signal.signal(signal.SIGINT, signal.SIG_IGN)

import subprocess
cat = subprocess.Popen(['cat'])
subprocess.call(['gdb', '--pid=%d' % cat.pid])

这样我就可以在 GDB 内重复 ^C 并毫无问题地中断调试程序,但是我确实看到了一些奇怪的行为。

顺便说一句,我在将信号转发到目标进程时也没有问题。

import subprocess
cat = subprocess.Popen(['cat'])

import signal, os
signal.signal(signal.SIGINT,
              lambda signum, frame: os.kill(cat.pid, signum))

subprocess.call(['gdb', '--pid=%d' % cat.pid])

那么,也许您的情况还发生了其他情况? 如果您发布了一些损坏的代码,这可能会有所帮助。

Instead of forwarding the signal to the debuggee from Python, you could try just ignoring it. The following worked for me:

import signal
signal.signal(signal.SIGINT, signal.SIG_IGN)

import subprocess
cat = subprocess.Popen(['cat'])
subprocess.call(['gdb', '--pid=%d' % cat.pid])

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.

import subprocess
cat = subprocess.Popen(['cat'])

import signal, os
signal.signal(signal.SIGINT,
              lambda signum, frame: os.kill(cat.pid, signum))

subprocess.call(['gdb', '--pid=%d' % cat.pid])

So, maybe something else is going on in your case? It might help if you posted some code that breaks.

勿忘初心 2024-07-24 07:55:13

您的评论指出您正在使用 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.

童话里做英雄 2024-07-24 07:55:13

如果您已经设置了一个当前脚本来执行此操作,但在自动化部分操作时遇到问题,也许您可​​以抓住 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文