🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gdb.bug
Article #9951

gdb bug

#9951
From: Lawrence Holloway
Date: Wed, 01 Aug 1990 02:34
67 lines
2685 bytes

I am running gdb 3.2 on a file compiled by g++ 1.35.0, and am unable
to check values of members of "anonymous unions" under gdb.

Under C++, you can declare a union of class members, and access those members
directly without having to go through an intermediate union name.  These
anonymous unions (see Dewhurst and Stark, Programming in C++, Prentice Hall 
1989,pg57) appear to be handled without any problem by the g++ compiler, but
gdb does not seem to recognize their existence.  For example, in the short
program below, entering "ptype Node_Class" in gdb returns the following:
	|(gdb) ptype Node_Class
	|struct Node_Class  {
	|    int type;	
	|}
Gdb appears to not even recognize the existence of the union members.
Similarly, if you try to access the union members directly, we get:
	|(gdb) print example[0].nextnode
	|there is no field named nextnode	

Is gdb capable of accessing anonymous unions when debugging or is this a 
bug in gdb?? 

	Thank you, 
	Larry Holloway
	holloway@galley.ece.cmu.edu
	

____________________________________________________________________________
#include<stdio.h>
#define ACTIVE 101
#define DELETED 102

class Node_Class  {
  public:	
    int type;
    union{
	Node_Class *nextnode;   // when type = DELETED
	int mylabel;             // when type = ACTIVE
    };
};

main() 
{
    Node_Class example[2];

    // clear elements (just to be safe)
    example[0].nextnode = 0;
    example[0].mylabel = 0;
    example[0].type = 0;
    printf("\n Node test: nextnode = %x (mylabel=%d)",example[0].nextnode,example[0].mylabel);


    // first let node be of deleted type
    example[0].type = DELETED;
    example[0].nextnode = &(example[1]);
    printf("\n Node is Deleted, nextnode = %x (should be garbage:mylabel=%d)",example[0].nextnode,example[0].mylabel);
    
    //now let node be of ACTIVE type
    example[0].type = ACTIVE;
    example[0].mylabel = 7;
    printf("\n Node is Active, mylabel = %d (should be garbage: nextnode = %x)",example[0].mylabel,example[0].nextnode);

}

    
    
Technical Details
Message-ID: <9008010234.AA16694@galley.ece.cmu.edu>
Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!cs.utexas.edu!tut.cis.ohio-state.edu!GALLEY.ECE.CMU.EDU!holloway

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f5053,9762bacd4d1e3ab,start
X-Google-Attributes: gidf5053,public
X-Google-ArrivalTime: 1990-07-31 19:34:53 PST
Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!cs.utexas.edu!tut.cis.ohio-state.edu!GALLEY.ECE.CMU.EDU!holloway
From: holloway@GALLEY.ECE.CMU.EDU (Lawrence Holloway)
Newsgroups: gnu.gdb.bug
Subject: gdb bug
Message-ID: <9008010234.AA16694@galley.ece.cmu.edu>
Date: 1 Aug 90 02:34:53 GMT
Sender: daemon@tut.cis.ohio-state.edu
Distribution: gnu
Organization: GNUs Not Usenet
Lines: 67
Posted: Wed Aug  1 03:34:53 1990