我有c ++程序,我通过传递字符串来运行它.
g++ -o a main.cpp -lpthread
Run Code Online (Sandbox Code Playgroud)
并执行它 ./a "Good nice"
但我如何使用gdb调试它?main.cpp从包含在其中的其他文件中调用函数.
gdb ./a "Good nice"
Run Code Online (Sandbox Code Playgroud)
将" - "作为文件,并说没有这样的文件!
我想逐行调试!
使用--argsgdb 的选项:
gdb --args ./a "Good nice"
Run Code Online (Sandbox Code Playgroud)
还要-g为编译器调用添加选项,否则gdb将无法将您的可执行文件与源代码连接:
g++ -g -o a main.cpp -lpthread
Run Code Online (Sandbox Code Playgroud)
不带参数使用gdb
gdb ./a
Run Code Online (Sandbox Code Playgroud)
然后在gdb中运行程序之前
set args "Good nice"
Run Code Online (Sandbox Code Playgroud)
你可以看到你设置的参数,使用
show args
Run Code Online (Sandbox Code Playgroud)
详情请见此处.