This is the mail archive of the gdb@sourceware.cygnus.com mailing list for the GDB project. See the GDB home page for more information.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Possible bug in GDB-4.17??


Can anyone shed some light on whether or not we've run into a
limitation of GDB under Solaris?  We've got a class that has bitfields 
declared which printout and otherwise work fine from the application
itself.  However, if we fire up DDD (with GDB-4.17 underneath) and
examine the class specific data, GDB is unable to properly display the 
class values due to them being bitfields.  I've enclosed the program
which is ready to run.  We are currently using egcs-1.1 under Solaris
2.6.

To see if the problem shows, fire up GDB and step into the "printout"
class member function.  Once inside, tell GDB to "print *this" and the 
output should look something like :

(gdb) print *this
$1 = {
  c_Length = 4, 
  c_Seqno = 45122, 
  c_Flag = ON, 
  c_src = ITEM_2, 
  c_dest = ITEM_3
}
(gdb) 

The c_Seqno value is trashed due to it being a bitfield that is shared 
with the c_Flag, c_src, and c_dest within the same short-word (16 bit size).
However, when you run it and have it dump out the individual fields,
it is apparent that the compiler gets it right (you'll have to map the 
enums back to their original values by hand) :

====================================

% ./test1 
Contents of l_my_header : 

Length              : 4
Sequence Number     : 5
Mix Message Flag    : 1
Source              : 1
Destination         : 2


===================================

Is this a design "feature" of GDB or a bug?  Also, might this behave
differntly if I used some other debugging information backend instead
of ELF (if that is applicable)?  Any information would be appreciated!

-- Rick


#include <iostream>

namespace n_Scalars
{
   // define unsigned integers, logical values, bit arrays, etc.,
   typedef unsigned char Unsigned_Char_Type;
   typedef unsigned short Unsigned_Short_Int_Type;
   typedef unsigned int Unsigned_Int_Type;
   typedef unsigned long Unsigned_Long_Int;   
};

namespace n_Header          
{
   typedef enum Type1_eType { ITEM_1, ITEM_2, ITEM_3, ITEM_4 };
                                           
   typedef enum Type2_eType { OFF, ON };
};

class Header
{
public:
   Header (            // Class constructor
         n_Scalars::Unsigned_Int_Type   p_Length,
         n_Scalars::Unsigned_Int_Type   p_Seqno,
         n_Header::Type2_eType          p_Flag,
         n_Header::Type1_eType          p_src,
         n_Header::Type1_eType          p_dest
         ) :
            c_Length(p_Length),
            c_Seqno(p_Seqno),
            c_Flag(p_Flag),
            c_src(p_src),
            c_dest(p_dest) {}
 
   Header() {}            // Empty class constructor
   ~Header() {}           // Class destructor

   void printout(void)
   {
      cout << "Contents of l_my_header : " << endl     << endl;
      cout << "Length                  : " << c_Length << endl;
      cout << "SeqNo                   : " << c_Seqno  << endl;
      cout << "Flag Value              : " << c_Flag   << endl;
      cout << "Source                  : " << c_src    << endl;
      cout << "Destination             : " << c_dest   << endl;
   }

protected:
   n_Scalars::Unsigned_Short_Int_Type   c_Length        : 16;
   n_Scalars::Unsigned_Short_Int_Type   c_Seqno         :  3;
   n_Header::Type2_eType                c_Flag          :  1;
   n_Header::Type1_eType                c_src           :  6;
   n_Header::Type1_eType                c_dest          :  6;
};

int main()
{
   Header l_my_header(4,
                      5,
                      n_Header::ON,
                      n_Header::ITEM_2,
                      n_Header::ITEM_3);
   l_my_header.printout();
}