🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gdb.bug
Article #20

gdb4.7 lossage with extracting bitfield enums (resending)

#20
From: Robert R. Henry
Date: Wed, 28 Oct 1992 17:15
52 lines
1542 bytes
gdb4.7 target==sparc, host==sparc (g++ from gcc2.2.2) does
a sign extension when it extracts enumerations contained in bit fields;
gdb4.6 does not do the sign extension, and neither does gcc from gcc2.2.2.
(Note that enums contained in bitfields are legal in c++, since they
are integral types)

For the program at the bottom,
breaking at the first printf in main,
and doing
  (gdb4.7) print e
  $1 = {
    x = -2
  }
  (gdb4.7) print u
  $2 = {
    x = 2
  }
whereas in gdb4.6 doing the same thing:
  (gdb4.6) print e
  $1 = {
    x = VAL2
  }
  (gdb4.6) print u
  $2 = {
    x = 2
  }
is better, and agrees in the sign-extendedness behaviour
with the output of executing the program:
  VAL2 = 2
  e.x = 2
  u.x = 2

#include <stdio.h>

typedef enum { VAL0 = 0, VAL1 = 1, VAL2 = 2 } junk_t;

struct e_struct { junk_t x : 2; };

struct ui_struct { unsigned int x : 2; };

main()
{
    struct e_struct e;
    struct ui_struct u;

    e.x = VAL2;
    u.x = VAL2;

    printf("VAL2 = %d\n", VAL2);
    printf("e.x = %d\n", e.x);
    printf("u.x = %d\n", u.x);
}
Technical Details
Message-ID: <9210281715.AA27807@tera.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!think.com!rpi!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!tera.com!rrh

Show Full Headers
Complete Article Headers
Newsgroups: gnu.gdb.bug
Path: arc1-ca.pugleaf.net!sparky!uunet!think.com!rpi!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!tera.com!rrh
From: rrh@tera.com (Robert R. Henry)
Subject: gdb4.7 lossage with extracting bitfield enums (resending)
Message-ID: <9210281715.AA27807@tera.com>
Sender: gnulists@ai.mit.edu
Organization: GNUs Not Usenet
Distribution: gnu
Date: Wed, 28 Oct 1992 17:15:50 GMT
Approved: bug-gdb@prep.ai.mit.edu
Lines: 53