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++ 程序
基础教程推荐
- 提升 ASIO 流缓冲 2021-01-01
- 随机插入/删除的综合向量与链表基准 2022-01-01
- 如何更改 SysDateTimePick32 或 CDateTimeCtrl 的背景颜色? 2022-01-01
- 与 CAS 的原子交换(使用 gcc 同步内置函数) 2022-01-01
- 如何在 C++ 中正确使用命名空间? 2022-01-01
- c++ STL设置差异 2022-01-01
- 如何部分禁用 cmake C/C++ 自定义编译器检查 2021-01-01
- C++:获取传递给函数的多维数组的行大小 2021-01-01
- 为什么我们不能使用“虚拟继承"?在 COM 中? 2022-01-01
- 将不可复制的闭包对象传递给 std::function 参数 2021-01-01
