Use GDB to debug a C++ program called from a shell script(使用 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.
推荐答案
有两种选择:
直接在 shell 脚本中调用 GDB.这意味着您没有重定向标准输入和标准输出.
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++ 程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 GDB 调试从 shell 脚本调用的 C++ 程序


基础教程推荐
- 这个宏可以转换成函数吗? 2022-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 我有静态或动态 boost 库吗? 2021-01-01
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 常量变量在标题中不起作用 2021-01-01
- 如何在 C++ 中初始化静态常量成员? 2022-01-01