This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


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

Re: What is TYPE_STUB_DECL?


In article <3A71EDE1.13C59BE3@melbpc.org.au> you write:
>If I do not populate TYPE_STUB_DECL in my COBOL compiler in
>certain cirsumstances (in the type tree for record structures) my
>compiler aborts in dbxout.c. This is due to the NULL value. 

The debug output routines only provide entry points for declarations (decl
nodes).  There are no entry points for types.  If your language allows you
to declare types, and you want debug info for them, then you need to generate
corresponding TYPE_DECL nodes for them.  These "stub" TYPE_DECL nodes have
no name, and simply point at the type node.  You then set the TYPE_STUB_DECL
field of the type node to point back at the TYPE_DECL node.  This allows the
debug routines to know that the two nodes represent the same type, so that
we only get one debug info record for them.

In the C language, we can declare types in two cases, by using typedef, or
by defining a tagged type like struct, enum, or union.  In both cases,
we create a TYPE_DECL node to represent the declared type.  In the first
case, typedef, the TYPE_DECL node has a name, and points at the type node
representing the type.  In the second case, tagged types, the TYPE_DECL node
has no name, points at the type node representing the type, and the type
node points back at the TYPE_DECL node.

In C++, defining a tagged type, e.g. struct foo, gives us a type with two
names.  It can be referenced as either struct foo or as foo.  This is similar
to having "typedef struct foo foo" in C, except that in C we have two distinct
types, and in C++ we have only one type.  We represent this case by creating
a TYPE_DECL node with a name, setting DECL_ARTIFICIAL, making it point at the
struct's type node, and then making the TYPE_STUB_DECL field of the type node
point back at the TYPE_DECL.

It should now be possible to understand what the dwarf2out.c TYPE_DECL_IS_STUB
macro is doing.  TYPE_DECLs with no name are always stub decls.  TYPE_DECLS
with a name, with DECL_ARTIFICIAL set, and whose type points back at them
via TYPE_STUB_DECL are also stub decls.  We don't emit debug info for stub
decls, but we do emit debug info for the types that they represent.

Jim

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