Description of problem: gdb loses information about args for main() if only one statement refers to them. Example: int main(int argc, char *argv[]) { int fd; fd = open(argv[1], O_RDONLY); return 0; } /usr/bin/gcc -ggdb3 -Wall -O0 test2.c -o test2 gdb test2 (gdb) b main Breakpoint 1 at 0x80483b5: file test2.c, line 13. (gdb) r asdf Breakpoint 1, main (argc=2, argv=0xbff05ad4) at test2.c:13 13 fd = open(argv[1], O_RDONLY); (gdb) info arg argc = 2 argv = (char **) 0xbff05ad4 (gdb) n 15 return 0; (gdb) info arg argc = Cannot access memory at address 0xffffffc8 Now, with another fd = open(argv[1], O_RDONLY) (or printf(.., argc, argv[0])): (gdb) b main Breakpoint 1 at 0x80483b8: file test2.c, line 13. (gdb) r asdf Breakpoint 1, main (argc=2, argv=0xbfb9cf64) at test2.c:13 13 fd = open(argv[1], O_RDONLY); (gdb) info arg argc = 2 argv = (char **) 0xbfb9cf64 (gdb) n 14 fd = open(argv[1], O_RDONLY); (gdb) info arg argc = 2 argv = (char **) 0xbfb9cf64 (gdb) n 16 return 0; (gdb) info arg argc = 2 argv = (char **) 0xbfb9cf64 Version-Release number of selected component (if applicable): gdb-6.6-15.fc7: GNU gdb Red Hat Linux (6.6-15.fc7rh) gcc-4.1.2-12: gcc (GCC) 4.1.2 20070502 (Red Hat 4.1.2-12) glibc-2.6-4 How reproducible: Always, with combinations of -g, -g3, -ggdb, -ggdb3, -O0, -O1 and -O2. Additional info: The original test and its gdb session will be added as attachments. The original program had a single use of argc/argv: sinit(argv[0]), that called openlog(arg, ...).
Created attachment 160412 [details] test case
Created attachment 160414 [details] gdb session for test case
*** This bug has been marked as a duplicate of 228744 ***