Your message dated Sat, 22 Feb 2025 17:35:59 -0500
with message-id <[email protected]>
and subject line Re: Bug#58322: can't "p environ"
has caused the Debian Bug report #58322,
regarding gdb gets wrong address for glibc optind variable
to be marked as done.

This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
Bug report if necessary, and/or fix the problem forthwith.

(NB: If you are a system administrator and have no idea what this
message is talking about, this may indicate a serious mail system
misconfiguration somewhere. Please contact [email protected]
immediately.)


-- 
58322: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=58322
Debian Bug Tracking System
Contact [email protected] with problems
--- Begin Message ---
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
john@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;
}

john@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
john@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



--- End Message ---
--- Begin Message ---
On Thursday, February 17 2000, [email protected] wrote:

> I wrote envstuff.c:
>
> #include <stdlib.h>
> #include <stdio.h>
>
> extern char **environ;
>
> int main(int argc, char **argv, char **env)
> {
>   printf("argc=%d argv=%p env=%p environ=%p\n", argc, argv, env, environ);
>   exit(0);
> }
>
> and compiled it (gcc -ggdb envstuff.c -o envstuff)
>
> It produces this output:
>
> bash$ ./envstuff 
> argc=1 argv=0xbffff8d4 env=0xbffff8dc environ=0xbffff8dc
>
> but when in gdb, I get:
>
> (gdb) b main
> Breakpoint 1 at 0x8048486: file envstuff.c, line 8.
> (gdb) r
> Starting program: /usr/home/shaslam/perltest/envstuff 
>
> Breakpoint 1, main (argc=1, argv=0xbffff8c4, env=0xbffff8cc) at envstuff.c:8
> 8       printf("argc=%d argv=%p env=%p environ=%p\n", argc, argv, env,
> environ);
> (gdb) p env
> $1 = (char **) 0xbffff8cc
> (gdb) p environ
> $2 = (char **) 0x0

This bug has been fixed a long time ago.  Closing.

-- 
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF  31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
https://sergiodj.net/

Attachment: signature.asc
Description: PGP signature


--- End Message ---

Reply via email to