gpt4 book ai didi

c - 我无法理解 gdb 的输出

转载 作者:太空宇宙 更新时间:2023-11-04 03:34:28 28 4
gpt4 key购买 nike

此时我只是想学习使用 gdb。我正在使用它的程序工作得很好;我不是要调试它或其他任何东西;我只是在测试 gdb 的功能。这是源代码:

#include <stdio.h>
#include <ctype.h>
#include <string.h>

int main( int argc, char **argv ){
int wordcount = 0;
int len = strlen( argv[1] );
for( int i = 0; i < len; i++ ){
if( isspace( argv[1][i] ) && !isspace( argv[1][i-1] ) )
wordcount++;
}
if( !isspace( argv[1][len-1] ) ) wordcount++;
if( wordcount == 0 && len > 0 ) // if all characters were non-whitespace,
wordcount = 1; // then there was exactly one word
printf( "%d\n", wordcount );
return 0;
}

我启动了 gdb 并运行了程序,在第 7 行和第 9 行设置了断点。我使用了 backtrace 和 step 命令,但我根本不理解它们的输出。当我输入“backtrace full”时,gdb 给了我这个:

#0  _start () at ../sysdeps/i386/elf/start.S:65
No locals.

这到底是什么意思?什么是_start?什么是../sysdeps/i386/elf/start.S:65?当我清楚地声明了 wordcount 和 len 时,怎么可能没有本地人呢?我试过谷歌,但我在 gdb 上找到的每个教程都显示它产生了与我得到的完全不同(更详细)的输出。当我用 Google 搜索我得到的字符串时,我得到了一堆关于 ARM 架构的结果。

最佳答案

The program I'm using it on works perfectly fine;

对于作品的一些定义。您的程序至少有 2 个错误。

When I typed "backtrace full" gdb gave me this: ... What exactly does this mean?

如果不知道您在达到这一点之前使用了哪些命令,则很难判断。很可能你做了 next直到你从main回来,因此降落在_start (这是调用 main 的例程,也是任何程序通常开始执行的地方)。

What is ../sysdeps/i386/elf/start.S:65?

_start routine 是 GLIBC 的一部分,在 sysdeps/i386/elf/start.S 中定义源文件。

how can there be no locals, when clearly I have declared wordcount and len?

main里面,所以无论本地人在main无关紧要:它们仅在 main 时有效正在执行,但没有(尚未执行或不再执行)。

关于c - 我无法理解 gdb 的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33703690/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com