使用 GDB 调试从 shell 脚本调用的 C++ 程序 [英] Use GDB to debug a C++ program called from a shell script

查看:24
本文介绍了使用 GDB 调试从 shell 脚本调用的 C++ 程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个极其复杂的 shell 脚本,它在其中调用一个我想通过 GDB 调试的 C++ 程序.将这个 c++ 程序与 shell 分开是非常困难的,因为它有很多分支和很多环境变量设置.

I have a extremely complicated shell script, within which it calls a C++ program I want to debug via GDB. It is extremely hard to separate this c++ program from the shell since it has a lot of branches and a lot of environmental variables setting.

有没有办法在这个 shell 脚本上调用 GDB?看起来 gdb 需要我直接调用 C++ 程序.

Is there a way to invoke GDB on this shell script? Looks like gdb requires me to call on a C++ program directly.

推荐答案

有两种选择:

  1. 直接在 shell 脚本中调用 GDB.这意味着您没有重定向标准输入和标准输出.

  1. Invoke GDB directly within the shell script. This would imply that you don't have standard in and standard out redirected.

运行 shell 脚本,然后将调试器附加到已经运行的 C++ 进程,如下所示: gdb progname 1234 其中 1234 是正在运行的进程 IDC++ 进程.

Run the shell script and then attach the debugger to the already running C++ process like so: gdb progname 1234 where 1234 is the process ID of the running C++ process.

如果您需要在程序开始运行之前做一些事情,那么选项 1 会是更好的选择,否则选项 2 是更简洁的方式.

If you need to do things before the program starts running then option 1 would be the better choice, otherwise option 2 is the cleaner way.

这篇关于使用 GDB 调试从 shell 脚本调用的 C++ 程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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