Subject: gdb and bitfields
To: None <tech-toolchain@netbsd.org>
From: Wolfgang Rupprecht <wolfgang@wsrcc.com>
List: tech-toolchain
Date: 02/25/2000 16:19:07
In an ELF system is gdb supposed to know how to display bitfields?  I
swear I could remember it doing the right thing at one point.

On current I'm seeing gdb display the following:

    (gdb) ptype m.w1
    type = struct msghw1 {
        uint _pad;
        uint preamble;
        uint msgtype;
        uint refstaid;
        uint parity;
    }
    (gdb) p/x m->w1
    $4 = {
      _pad = 0x7b0598, 
      preamble = 0x7b0598, 
      msgtype = 0x30007b05, 
      refstaid = 0x7830007b, 
      parity = 0x783000
    }
    (gdb) 

    This is the C-code def:

    struct msghw1 {			/* header word 1 */
        uint            _pad:2;
        /* start of word 1 */
        uint            preamble:8;	/* 01100110 */
        uint            msgtype:6;
        uint            refstaid:10;
        uint            parity:6;
    };

For example "_pad" looks awfully big for a 2-bit unsigned number.  It
looks like gdb thinks the struct members are uints and is printing
them accordingly.  (Although it does seem to know that "_pad" and
"preable" have the same offset from the start of the struct.

-wolfgang
-- 
       Wolfgang Rupprecht <wolfgang+gnus@dailyplanet.wsrcc.com>
		    http://www.wsrcc.com/wolfgang/
DGPS signals via the Internet  http://www.wsrcc.com/wolfgang/gps/dgps-ip.html