Hi,

The i386 4.4-release gcc-4.2.20070307p7 package generates executables
for which gdb can't produce stack backtraces, either from a core dump
(e.g., as generated by assert(0)), or when the program is stopped at
a gdb breakpoint.  The gcc3 in base (/usr/bin/gcc) has no problems
(i.e., it produces executables for which gdb *can* produce stack
backtraces).

gcc optimization does not seem to be an issue here: this behavior
is independent of whether I compile with '-g', '-g -O0', or '-g -O2'.

In contrast, on amd64, both the gcc3 in base (/usr/bin/gcd) *and*
the gcc-4.2.20070307p7 port have no problems.  I have not tested
other architectures besides i386 and amd64.

I also see the same behavior with g++: the i386 g++4 package produces
executables for which gdb can't produce stack backtraces, while the
g++3 in base is ok, as are both the amd64 g++3 and g++4.  I have seen
the same problems in past versions of OpenBSD (4.3-stable, 4.2-stable,
and earlier), though I don't have those installed any more to test.

Here's a simple test case to illustrate the problem for the i386
4.4-release gcc4:

Script started on Sun Dec 28 21:52:38 2008
% cat -n stack-bug2.c
     1  #include <stdio.h>
     2
     3  /* prototypes */
     4  void foo(int i);
     5  void bar(int i);
     6
     7  int main(void)
     8  {
     9  foo(69);
    10  return 0;
    11  }
    12
    13  void foo(int i)
    14  {
    15  bar(i);
    16  }
    17
    18  void bar(int i)
    19  {
    20  printf("hello, world: i=%d\n", i);
    21  }
% /usr/local/bin/gcc --version
gcc (GCC) 4.2.0 20070307 (prerelease)
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

% /usr/local/bin/gcc -g -O0 -o stack-bug2 stack-bug2.c
% gdb stack-bug2
GNU gdb 6.3
Copyright 2004 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-openbsd4.4"...
(gdb) break stack-bug2.c:20
Breakpoint 1 at 0x1c0005d7: file stack-bug2.c, line 20.
(gdb) run
Starting program: /home/jonathan/sf/null/cctry/stack-bug2

Breakpoint 1, bar (i=69) at stack-bug2.c:20
20      printf("hello, world: i=%d\n", i);
(gdb) bt
#0  bar (i=69) at stack-bug2.c:20
#1  0x1c0005d7 in bar (i=69) at stack-bug2.c:19
#2  0x1c0005d7 in bar (i=469763433) at stack-bug2.c:19
#3  0x1c0005d7 in bar (i=1) at stack-bug2.c:19
#4  0x1c0005d7 in bar (i=0) at stack-bug2.c:19
#5  0x1c0005d7 in bar (i=Cannot access memory at address 0x9
) at stack-bug2.c:19
Previous frame inner to this frame (corrupt stack?)
(gdb) quit
The program is running.  Exit anyway? (y or n) y
% exit
Script done on Sun Dec 28 21:53:25 2008

In contrast, here's this same test (identical source code) run on
amd64 4.4-release gcc4, where the stack traceback works fine:

Script started on Sun Dec 28 22:02:12 2008
% cat -n stack-bug2.c
     1  #include <stdio.h>
     2
     3  /* prototypes */
     4  void foo(int i);
     5  void bar(int i);
     6
     7  int main(void)
     8  {
     9  foo(69);
    10  return 0;
    11  }
    12
    13  void foo(int i)
    14  {
    15  bar(i);
    16  }
    17
    18  void bar(int i)
    19  {
    20  printf("hello, world: i=%d\n", i);
    21  }
% /usr/local/bin/gcc --version
gcc (GCC) 4.2.0 20070307 (prerelease)
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

% /usr/local/bin/gcc -g -O0 -o stack-bug2 stack-bug2.c
% gdb stack-bug2
GNU gdb 6.3
Copyright 2004 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 "amd64-unknown-openbsd4.4"...
(gdb) break stack-bug2.c:20
Breakpoint 1 at 0x400845: file stack-bug2.c, line 20.
(gdb) run
Starting program: /home/jonathan/sf/null/cctry/stack-bug2

Breakpoint 1, bar (i=69) at stack-bug2.c:20
20      printf("hello, world: i=%d\n", i);
(gdb) bt
#0  bar (i=69) at stack-bug2.c:20
#1  0x0000000000400838 in foo (i=69) at stack-bug2.c:15
#2  0x000000000040081e in main () at stack-bug2.c:9
(gdb) quit
The program is running.  Exit anyway? (y or n) y
% exit
Script done on Sun Dec 28 22:02:49 2008

Is this a known problem with (hopefully) a known workaround?  I've
searched the ports list, but not found any discussion of this.

-- 
-- From: "Jonathan Thornburg [remove -animal to reply]" 
<jth...@astro.indiana-zebra.edu>
   Dept of Astronomy, Indiana University, Bloomington, Indiana, USA
   "Washing one's hands of the conflict between the powerful and the
    powerless means to side with the powerful, not to be neutral."
                                      -- quote by Freire / poster by Oxfam

Reply via email to