I'm just trying to learn to use gdb at this point. The program I'm using it on works perfectly fine; I'm not trying to debug it or anything; I'm just testing the functionality of gdb. Here's the source code:
#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;
}
I started gdb and ran the program, setting breakpoints at lines 7 and 9. I used the backtrace and step commands, and I don't understand their output at all. When I typed "backtrace full" gdb gave me this:
#0 _start () at ../sysdeps/i386/elf/start.S:65
No locals.
What exactly does this mean? What is _start? What is ../sysdeps/i386/elf/start.S:65? And how can there be no locals, when clearly I have declared wordcount and len? I have tried Google, but every tutorial I can find on gdb shows it producing completely different (more detailed) output from what I got. When I Google the string I got, I get a bunch of results on the ARM architecture.
The program I'm using it on works perfectly fine;
For some definition of works. Your program has at least 2 bugs.
When I typed "backtrace full" gdb gave me this: ... What exactly does this mean?
It's hard to tell without knowing which commands you used before reaching this point. Most likely you did next
until you returned from main
, and thus landed in _start
(which is the routine that calls main
, and which is where the execution of any program usually starts).
What is ../sysdeps/i386/elf/start.S:65?
The _start
routine is part of GLIBC, and is defined in sysdeps/i386/elf/start.S
source file.
how can there be no locals, when clearly I have declared wordcount and len?
You are not inside main
, so whatever locals are present in main
is irrelevant: they are only active while main
is executing, and it's not (either not yet, or not any longer).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.