Package: gdb Version: 6.8-3 Severity: important
debugging a program that uses the glibc getopt function shows the wrong address and value for the "optind" variable. For example: Script started on Mon 06 Jul 2009 22:46:37 CEST j...@cedric:~$ cat optind-bug.c #include <stdio.h> #include <unistd.h> #define LEN(arr) (sizeof arr / sizeof arr[0]) char *args[] = {"optind", "-a", "-b", "one"}; int main () { int ch; while ((ch = getopt (LEN (args), args, "ab:")) != -1) { printf ("opt %c\n", ch); } printf ("optind %p = %d\n", &optind, optind); return 0; } j...@cedric:~$ gdb ./a.out GNU gdb 6.8-debian Copyright (C) 2008 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-linux-gnu"... (gdb) b 13 Breakpoint 1 at 0x4005bf: file ./optind-bug.c, line 13. (gdb) r Starting program: /home/john/a.out opt a opt b optind 0x600a00 = 4 Breakpoint 1, main () at ./optind-bug.c:13 13 return 0; (gdb) p optind $1 = 1 (gdb) p &optind $2 = (int *) 0x7f73faee6124 (gdb) quit The program is running. Exit anyway? (y or n) y j...@cedric:~$ exit Script done on Mon 06 Jul 2009 22:47:46 CEST -- System Information: Debian Release: 5.0.1 APT prefers stable APT policy: (500, 'stable') Architecture: amd64 (x86_64) Kernel: Linux 2.6.26-2-xen-amd64 (SMP w/2 CPU cores) Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8) Shell: /bin/sh linked to /bin/bash Versions of packages gdb depends on: ii libc6 2.7-18 GNU C Library: Shared libraries ii libexpat1 2.0.1-4 XML parsing C library - runtime li ii libncurses5 5.7+20081213-1 shared libraries for terminal hand ii libreadline5 5.2-3.1 GNU readline and history libraries gdb recommends no packages. Versions of packages gdb suggests: pn gdb-doc <none> (no description available) -- no debconf information -- To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org