Bug 33584

Summary: 'gcc -ggdb' doesn't work with GDB
Product: Base System Reporter: smkelly <smkelly>
Component: binAssignee: freebsd-bugs (Nobody) <bugs>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: 4.5-PRERELEASE   
Hardware: Any   
OS: Any   

Description smkelly 2002-01-05 22:10:01 UTC
	According to the 'gcc' manpage, there is a '-ggdb' flag which adds
	more debugging information to the compiled binary.  However, when
	one attempts to use 'gdb' on a binary compiled with -ggdb, oddities
	occur when dealing with pointers.

Fix: 

Wish I knew.
How-To-Repeat: 	Compile this code with '-ggdb':
#include <stdio.h>

int pointtest(char *arg)
{
    printf("pointtest(\"%s\")\n", arg);
    return 1;
}

int main(int argc, char *argv[])
{
    char *x = (char *)malloc(512);
    printf("argc=%d, argv=%X\n", argc, argv);
    strcpy(x, "Got Milk?");
    pointtest(x);
    return 0;
}

	Then 'gdb' it:
	$ gcc -ggdb -o gdbtest gdbtest.c
	$ gdb gdbtest
	(gdb) break main
	Breakpoint 1 at 0x804855e
	(gdb) run
	*keep 'step'ping through*
	13          strcpy(x, "Got Milk?");
	(gdb) step
	14          pointtest(x);
	* BAD BEHAVIOR FOLLOWS *
	(gdb) print x
	$1 = 0xbfbffbac "\210ü¿¿"
	(gdb) print *x
	$2 = -120 '\210'
	(gdb) step
	pointtest (arg=0xbfbffb58 "¤û¿¿¡\204\004\b\001") at gdbtest.c:5
	5           printf("pointtest(\"%s\")\n", arg);
	(gdb) step
	pointtest("Got Milk?")

So it is clear that the program is working right, but gdb is totally broken
when dealing with the pointers in the program.
Comment 1 Peter Pentchev freebsd_committer freebsd_triage 2002-01-06 15:29:59 UTC
State Changed
From-To: open->closed

Duplicate of bin/23472; not that anyone has done anything about 
the original one :(
Comment 2 Kris Kennaway 2002-01-10 01:06:25 UTC
> >Description:
> 	According to the 'gcc' manpage, there is a '-ggdb' flag which adds
> 	more debugging information to the compiled binary.  However, when
> 	one attempts to use 'gdb' on a binary compiled with -ggdb, oddities
> 	occur when dealing with pointers.

You probably should bring this up with the gdb maintainers, since it's
not a FreeBSD bug.

Kris