用gdb调试基于参数的C程序
Debug argument based C program with gdb
我有一个c++程序,我通过传递字符串来运行它。
g++ -o a main.cpp -lpthread
并用./a "Good nice"
执行
但是我如何用gdb调试它呢?main.cpp从包含在其中的其他文件调用函数。
gdb ./a "Good nice"
把"--"作为文件,并说没有这样的文件!
我想逐行调试!
使用gdb:的--args
选项
gdb --args ./a "Good nice"
还要将-g
选项添加到编译器调用中,因为否则gdb将无法将可执行文件与源代码连接起来:
g++ -g -o a main.cpp -lpthread
使用没有参数的gdb
gdb ./a
然后在gdb中,在运行程序之前
set args "Good nice"
你可以看到你设置了什么参数,使用
show args
请参阅此处了解详细信息。
gdb/prog->设置参数string
->运行。
选择在run
之后提供参数
$gdb ./a
run "Good nice"
相关文章:
- 用于检查值是否为其任何参数的帮助程序函数
- 如何访问QT中传递给程序的参数
- 在运行时使用枚举器值作为模板函数的模板参数的元程序
- 如何从 x64 程序集中的堆栈中获取参数?
- 如何在程序中运行带有参数C++ VBS 脚本?
- 程序告诉我,即使它们明显匹配,参数也不匹配
- C2783: 无法推断帮助程序函数的模板参数
- 将 C# 对象(包含静态对象成员)作为参数传递给 C++/CLI 程序
- 编写一个将 LLVM IR 文件作为命令行参数的程序
- c++程序,在windows下发送带有参数的http get请求
- 此程序中不调用没有参数的构造函数
- 如何将参数传递给Google基准测试程序
- 为什么EclipseCDT代码格式化程序有时会在模板参数中引入空格
- 从带有参数的C++程序中调用shell脚本
- 如何在程序集函数中将元素数组作为参数传递时转发 ARM 寄存器的地址指针
- 如何通过opencv中的程序参数定义特征类型?
- 类参数化与类和帮助程序函数混淆
- 使用参数 + stdout + stderr 从命令行调用 MFC 应用程序
- C++程序给出了太多参数警告
- 将命令行参数程序转换为菜单驱动程序