From roam@orbitel.bg  Mon Dec 11 09:30:10 2000
Return-Path: <roam@orbitel.bg>
Received: from ringworld.nanolink.com (pool249-tch-1.Sofia.0rbitel.net [212.95.170.249])
	by hub.freebsd.org (Postfix) with SMTP id 7F67D37B400
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 11 Dec 2000 09:30:07 -0800 (PST)
Received: (qmail 4382 invoked by uid 1000); 11 Dec 2000 17:29:16 -0000
Message-Id: <20001211172916.4381.qmail@ringworld.nanolink.com>
Date: 11 Dec 2000 17:29:16 -0000
From: Peter Pentchev <roam@orbitel.bg>
Reply-To: Peter Pentchev <roam@orbitel.bg>
To: FreeBSD-gnats-submit@freebsd.org
Subject: gdb weirdness on programs compiled with -ggdb
X-Send-Pr-Version: 3.2

>Number:         23472
>Category:       bin
>Synopsis:       gdb weirdness on programs compiled with -ggdb
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    mp
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Dec 11 09:40:00 PST 2000
>Closed-Date:    Fri Sep 09 01:01:05 GMT 2005
>Last-Modified:  Fri Sep 09 01:01:05 GMT 2005
>Originator:     Peter Pentchev
>Release:        FreeBSD 4.2-STABLE i386
>Organization:
Orbitel JSCo.
>Environment:

FreeBSD FreeBSD 4.2-STABLE #6: Mon Dec 11 12:57:38 EET 2000     root@ringworld.oblivion.bg:/usr/obj/usr/src/sys/RINGWORLD 

>Description:

If a program is compiled with -ggdb, gdb sometimes loses track of local
variables' addresses and/or contents.

>How-To-Repeat:

Consider the following program:

#include <stdio.h>
#include <unistd.h>

#define BUFLEN	100

int
readstring(char *s, int len) {

  printf("readstring(%p, %d) called, s='%s'\n", s, len, s);
  return 0;
}

int
main(void) {
  char str[BUFLEN] = "string";

  printf("in main: str=%p, sizeof(str)=%d, str='%s'\n", str, sizeof(str), str);
  readstring(str, sizeof(str));
  return 0;
}

..and the following Makefile:

CFLAGS	= -g3 -ggdb

all:	zettest

clean:
	rm -f zettest

Following is the transcript of a gdb session.

Script started on Mon Dec 11 17:48:52 2000
[roam@ringwraith ~/c/misc/zettest]$ gdb zettest
GNU gdb 4.18
Copyright 1998 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-unknown-freebsd"...
(gdb) br main
Breakpoint 1 at 0x8048572: file zettest.c, line 15.
(gdb) r
Starting program: /usr/home/roam/lang/c/misc/zettest/zettest 

Breakpoint 1, main () at zettest.c:15
15	  char str[BUFLEN] = "string";
(gdb) n
17	  printf("in main: str=%p, sizeof(str)=%d, str='%s'\n", str, sizeof(str), str);
(gdb) 
in main: str=0xbfbff904, sizeof(str)=100, str='string'
             ^^^^^^^^^^ real address          ^^^^^^^^ real contents
18	  readstring(str, sizeof(str));
(gdb) print (void *) str
$1 = (void *) 0xbfbff88c
              ^^^^^^^^^^ something's fishy..
(gdb) print &str[0]
$2 = 0xbfbff88c ""
(gdb) s
readstring (s=0xbfbff968 "\211\204\004\b\001", len=134514114)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ uhm  ^^^^^^^^^ excuse me?!
    at zettest.c:9
9	  printf("readstring(%p, %d) called, s='%s'\n", s, len, s);
(gdb) n
readstring(0xbfbff904, 100) called, s='string'
           ^^^^^^^^^^  ^^^             ^^^^^^ everyhing's just fine
10	  return 0;
(gdb) c
Continuing.

Program exited normally.
(gdb) quit
[roam@ringwraith ~/c/misc/zettest]$ exit
exit

Script done on Mon Dec 11 17:49:15 2000


Well, so.. the program executed correctly, the addresses and values
as printed by the printf() in readstring() were perfectly OK.  Just gdb
showed something wrong - in a program compiled with additional info
for the purpose of debugging with gdb :)

Here's the 'ident gdb' output..

/usr/bin/gdb:
     $FreeBSD: src/lib/libc/i386/string/strrchr.S,v 1.5 1999/08/27 23:59:35 peter Exp $
     $FreeBSD: src/lib/libc/i386/string/strncmp.S,v 1.6 1999/08/27 23:59:35 peter Exp $
     $FreeBSD: src/lib/libc/i386/string/index.S,v 1.5 1999/08/27 23:59:30 peter Exp $
     $FreeBSD: src/lib/libc/i386/string/strcpy.S,v 1.5 1999/08/27 23:59:34 peter Exp $
     $FreeBSD: src/lib/libc/i386/string/strcmp.S,v 1.5 1999/08/27 23:59:33 peter Exp $
     $FreeBSD: src/lib/libc/i386/string/memchr.S,v 1.8 1999/08/27 23:59:31 peter Exp $
     $NetBSD: bcopy.S,v 1.6 1996/11/12 00:50:06 jtc Exp $
     $FreeBSD: src/lib/libc/i386/string/memset.S,v 1.5 1999/08/27 23:59:32 peter Exp $
     $NetBSD: bcopy.S,v 1.6 1996/11/12 00:50:06 jtc Exp $
     $FreeBSD: src/lib/libc/i386/sys/brk.S,v 1.7 1999/08/27 23:59:38 peter Exp $
     $FreeBSD: src/lib/libc/i386/sys/sbrk.S,v 1.7 1999/08/27 23:59:44 peter Exp $
     $FreeBSD: src/lib/libc/i386/sys/cerror.S,v 1.10 1999/08/27 23:59:38 peter Exp $
     $FreeBSD: src/lib/libc/gen/err.c,v 1.6 1999/08/27 23:58:33 peter Exp $
     $FreeBSD: src/lib/libc/i386/gen/isinf.c,v 1.6 1999/08/27 23:59:21 peter Exp $
     $FreeBSD: src/lib/libc/stdio/asprintf.c,v 1.6 1999/08/28 00:00:55 peter Exp $


I do not know which FreeBSD releases are affected by this - I only have
very recent 4.2-STABLE and -current machines :(  And freefall was updated
to a very-very recent 4.2-STABLE just hours before I needed to test :)

>Fix:

Wish I knew :(  A friend wasted hours today in a gdb session, thinking
his program was passing a value of 100 as 134 millions..  and at the same
time marvelling at the program's perfectly fine output :(

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->obrien 
Responsible-Changed-By: roam 
Responsible-Changed-When: Sun Jan 7 12:52:59 PST 2001 
Responsible-Changed-Why:  
gnu/13427? 

http://www.freebsd.org/cgi/query-pr.cgi?pr=23472 
Responsible-Changed-From-To: obrien->freebsd-bugs 
Responsible-Changed-By: obrien 
Responsible-Changed-When: Mon Sep 10 09:32:38 PDT 2001 
Responsible-Changed-Why:  
I am not the maintainer. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=23472 
State-Changed-From-To: open->feedback 
State-Changed-By: sheldonh 
State-Changed-When: Wed Jan 30 05:25:02 PST 2002 
State-Changed-Why:  
Opened in error. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=23472 
State-Changed-From-To: feedback->open 
State-Changed-By: sheldonh 
State-Changed-When: Wed Jan 30 05:26:37 PST 2002 
State-Changed-Why:  


Responsible-Changed-From-To: freebsd-bugs->mp 
Responsible-Changed-By: sheldonh 
Responsible-Changed-When: Wed Jan 30 05:26:37 PST 2002 
Responsible-Changed-Why:  
Over to maintainer. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=23472 
State-Changed-From-To: open->closed 
State-Changed-By: mp 
State-Changed-When: Sat Jun 29 18:26:50 PDT 2002 
State-Changed-Why:  


http://www.freebsd.org/cgi/query-pr.cgi?pr=23472 
State-Changed-From-To: closed->patched 
State-Changed-By: mp 
State-Changed-When: Sat Jun 29 18:27:43 PDT 2002 
State-Changed-Why:  
This is fixed in -current with the import of gdb-5.2. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=23472 
State-Changed-From-To: patched->closed 
State-Changed-By: marcel 
State-Changed-When: Fri Sep 9 01:00:46 GMT 2005 
State-Changed-Why:  
Should have been closed eons ago. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=23472 
>Unformatted:
