Re: Wrong debug info for argc at -O2

Luis Machado via Gdb <[email protected]>
Newsgroups gmane.comp.gdb.devel
Message-ID <[email protected]>
On 5/29/20 12:58 PM, 杨已彪 wrote:
> 
> 
> Consider test-case:
> ...
> $ cat small.c
> #include <stdio.h>
> 
> int main(int argc, char **argv) {
>    char buf[6];
>    char c[] = "abc";
>    sprintf(buf, (char *)c, 1);
> 
>    return 0;
> }
> ...
> 
> 
> Stepping with step and print the values of arguments:
> ...
> $ gcc -O2 -g small.c; gdb -q a.out
> Reading symbols from a.out...
> (gdb) b main
> Breakpoint 1 at 0x401040: file small.c, line 5.
> (gdb) r
> Starting program: /home/yibiao/Debugger/a.out
> 
> Breakpoint 1, main (argc=1, argv=0x7fffffffdff8) at small.c:5
> 5      char c[] = "abc";
> (gdb) info args argc
> argc = 1
> (gdb) step
> 6      sprintf(buf, (char *)c, 1);
> (gdb) info args argc
> argc = -8454
> (gdb)

What architecture is this?

If you want precise debug information, you should use -O0 instead. With 
O2 you are likely to run into situations where the debug info has been 
lost or is just incorrect.

With that said, GCC has improved over the past few years in terms of 
debug info generation for O2+.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.