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++ 程序
基础教程推荐
- 如何在 C++ 中处理或避免堆栈溢出 2022-01-01
- 运算符重载的基本规则和习语是什么? 2022-10-31
- 什么是T&&(双与号)在 C++11 中是什么意思? 2022-11-04
- 调用std::Package_TASK::Get_Future()时可能出现争用情况 2022-12-17
- C++ 程序在执行 std::string 分配时总是崩溃 2022-01-01
- 如何定义双括号/双迭代器运算符,类似于向量的向量? 2022-01-01
- C++,'if' 表达式中的变量声明 2021-01-01
- 设计字符串本地化的最佳方法 2022-01-01
- C++ 标准:取消引用 NULL 指针以获取引用? 2021-01-01
- 您如何将 CreateThread 用于属于类成员的函数? 2021-01-01