GDB在C函数的条目上显示错误的函数参数
用GDB调试C程序我看到以下内容(简称): 请注意,在进入函数后,GDB将参数,特别是形式参数GDB在C函数的条目上显示错误的函数参数,c,gdb,arguments,C,Gdb,Arguments,用GDB调试C程序我看到以下内容(简称): 请注意,在进入函数后,GDB将参数,特别是形式参数file,显示为0x0,这不是我所期望的,因为实际参数options\u file在调用之前打印为0xa812140。即使在此时打印它也会显示这个不正确的值。但是,在next之后,它的后续p再次显示值0xa812140 我可以从技术角度(函数序言、堆栈帧等)理解这一点,但作为用户,我真的希望从GDB获得正确的输出。这是已知/预期的行为还是错误 我使用的是GNUGDB(Ubuntu 8.3-0ubuntu
file
,显示为0x0
,这不是我所期望的,因为实际参数options\u file
在调用之前打印为0xa812140。即使在此时打印它也会显示这个不正确的值。但是,在next
之后,它的后续p
再次显示值0xa812140
我可以从技术角度(函数序言、堆栈帧等)理解这一点,但作为用户,我真的希望从GDB获得正确的输出。这是已知/预期的行为还是错误
我使用的是GNUGDB(Ubuntu 8.3-0ubuntu1)8.3
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=19.10
DISTRIB_CODENAME=eoan
DISTRIB_DESCRIPTION="Ubuntu 19.10"
(实际上是在WSL上)尽管
-O0
Reduce compilation time and make debugging produce the expected results.
This is the default.
当然,你可以讨论“预期结果”部分
但这也会影响到国家
-Og
Optimize debugging experience. -Og should be the optimization level of choice
for the standard edit-compile-debug cycle, offering a reasonable level of
optimization while maintaining fast compilation and a good debugging experience.
It is a better choice than -O0 for producing debuggable code because some
compiler passes that collect debug information are disabled at -O0.
使用-Og
应该可以解决这个问题
更新:我发现调试的最佳选项实际上可能是
-O0
,因为-Og
允许优化许多变量,因为。从2016年开始就有了。这显然是错误的
为什么?为什么错了?为什么是显而易见的?请发布一个.shadowing的帖子,也许是吧?这可能在某种程度上也与WSL有关,因为我从来没有在标准Linux上遇到过-O0的问题,但今天在WSL上看到过。
-Og
Optimize debugging experience. -Og should be the optimization level of choice
for the standard edit-compile-debug cycle, offering a reasonable level of
optimization while maintaining fast compilation and a good debugging experience.
It is a better choice than -O0 for producing debuggable code because some
compiler passes that collect debug information are disabled at -O0.