[gnu.gdb.bug] Strange System V/386 problem

johnl@esegue.segue.boston.ma.us (John R. Levine) (01/24/90)

I'm running gdb 3.4 under 386/ix 2.0.2, which is a derivative of AT&T's
Sys V/386 3.2.

On some machines, gdb crashes when it's starting up while calling the
vendor's termio tgetent() routine.  It always works when run under
itself (actually, under 3.2, it's not an infinitely recursive bug.)
After some poking around, it appears that depending on the environment
size, or whether you're running YP, or the phase of the moon or something,
the stack is not always long-aligned when main() is called, and tgetent()
takes strong offense at that.  On some machines this bug never appears, but
on those where it does, it occurs quite reliably.

If you put this:

	(void)alloca(1);

before the first executable statement in main(), alloca will, being a good
citizen, long-align the stack before it returns, after which everything
works just fine.  Note that you should use the assembler alloca() in -lPW
or the equivalent, not the clever portable malloc-based version.
-- 
John R. Levine, Segue Software, POB 349, Cambridge MA 02238, +1 617 864 9650
johnl@esegue.segue.boston.ma.us, {ima|lotus|spdcc}!esegue!johnl
"Now, we are all jelly doughnuts."

johnl@esegue.segue.boston.ma.us (John R. Levine) (01/24/90)

In article <1990Jan24.022138.12102@esegue.segue.boston.ma.us> johnl@esegue.segue.boston.ma.us (John R. Levine) writes:
>alloca will, being a good citizen, long-align the stack before it returns,
>after which everything works just fine.  ...

Oops, I should have checked more carefully.  If you compile gdb in the
obvious way with gcc you get the builtin alloca which just subtracts its
argument from the stack pointer without trying to align it.  So try the
following at the beginning of main(), just after the "register int i;".

  i = (int)&count & 0x3;
  if(i) alloca(4-i);	/* align the stack, a gross hack */
-- 
John R. Levine, Segue Software, POB 349, Cambridge MA 02238, +1 617 864 9650
johnl@esegue.segue.boston.ma.us, {ima|lotus|spdcc}!esegue!johnl
"Now, we are all jelly doughnuts."