xref: /openbsd-src/gnu/usr.bin/binutils/gdb/cp-abi.h (revision b725ae7711052a2233e31a66fefb8a752c388d7a)
1*b725ae77Skettenis /* Abstraction of various C++ ABI's we support, and the info we need
2*b725ae77Skettenis    to get from them.
3*b725ae77Skettenis    Contributed by Daniel Berlin <dberlin@redhat.com>
4*b725ae77Skettenis    Copyright 2001 Free Software Foundation, Inc.
5*b725ae77Skettenis 
6*b725ae77Skettenis    This file is part of GDB.
7*b725ae77Skettenis 
8*b725ae77Skettenis    This program is free software; you can redistribute it and/or
9*b725ae77Skettenis    modify
10*b725ae77Skettenis    it under the terms of the GNU General Public License as published
11*b725ae77Skettenis    by
12*b725ae77Skettenis    the Free Software Foundation; either version 2 of the License, or
13*b725ae77Skettenis    (at your option) any later version.
14*b725ae77Skettenis 
15*b725ae77Skettenis    This program is distributed in the hope that it will be useful,
16*b725ae77Skettenis    but WITHOUT ANY WARRANTY; without even the implied warranty of
17*b725ae77Skettenis    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*b725ae77Skettenis    GNU General Public License for more details.
19*b725ae77Skettenis 
20*b725ae77Skettenis    You should have received a copy of the GNU General Public License
21*b725ae77Skettenis    along with this program; if not, write to the Free Software
22*b725ae77Skettenis    Foundation, Inc., 59 Temple Place - Suite 330,
23*b725ae77Skettenis    Boston, MA 02111-1307, USA.  */
24*b725ae77Skettenis 
25*b725ae77Skettenis #ifndef CP_ABI_H_
26*b725ae77Skettenis #define CP_ABI_H_ 1
27*b725ae77Skettenis 
28*b725ae77Skettenis struct fn_field;
29*b725ae77Skettenis struct type;
30*b725ae77Skettenis struct value;
31*b725ae77Skettenis 
32*b725ae77Skettenis /* The functions here that attempt to determine what sort of thing a
33*b725ae77Skettenis    mangled name refers to may well be revised in the future.  It would
34*b725ae77Skettenis    certainly be cleaner to carry this information explicitly in GDB's
35*b725ae77Skettenis    data structures than to derive it from the mangled name.  */
36*b725ae77Skettenis 
37*b725ae77Skettenis 
38*b725ae77Skettenis /* Kinds of constructors.  All these values are guaranteed to be
39*b725ae77Skettenis    non-zero.  */
40*b725ae77Skettenis enum ctor_kinds {
41*b725ae77Skettenis 
42*b725ae77Skettenis   /* Initialize a complete object, including virtual bases, using
43*b725ae77Skettenis      memory provided by caller.  */
44*b725ae77Skettenis   complete_object_ctor = 1,
45*b725ae77Skettenis 
46*b725ae77Skettenis   /* Initialize a base object of some larger object.  */
47*b725ae77Skettenis   base_object_ctor,
48*b725ae77Skettenis 
49*b725ae77Skettenis   /* An allocating complete-object constructor.  */
50*b725ae77Skettenis   complete_object_allocating_ctor
51*b725ae77Skettenis };
52*b725ae77Skettenis 
53*b725ae77Skettenis /* Return non-zero iff NAME is the mangled name of a constructor.
54*b725ae77Skettenis    Actually, return an `enum ctor_kind' value describing what *kind*
55*b725ae77Skettenis    of constructor it is.  */
56*b725ae77Skettenis extern enum ctor_kinds is_constructor_name (const char *name);
57*b725ae77Skettenis 
58*b725ae77Skettenis 
59*b725ae77Skettenis /* Kinds of destructors.  All these values are guaranteed to be
60*b725ae77Skettenis    non-zero.  */
61*b725ae77Skettenis enum dtor_kinds {
62*b725ae77Skettenis 
63*b725ae77Skettenis   /* A destructor which finalizes the entire object, and then calls
64*b725ae77Skettenis      `delete' on its storage.  */
65*b725ae77Skettenis   deleting_dtor = 1,
66*b725ae77Skettenis 
67*b725ae77Skettenis   /* A destructor which finalizes the entire object, but does not call
68*b725ae77Skettenis      `delete'.  */
69*b725ae77Skettenis   complete_object_dtor,
70*b725ae77Skettenis 
71*b725ae77Skettenis   /* A destructor which finalizes a subobject of some larger object.  */
72*b725ae77Skettenis   base_object_dtor
73*b725ae77Skettenis };
74*b725ae77Skettenis 
75*b725ae77Skettenis /* Return non-zero iff NAME is the mangled name of a destructor.
76*b725ae77Skettenis    Actually, return an `enum dtor_kind' value describing what *kind*
77*b725ae77Skettenis    of destructor it is.  */
78*b725ae77Skettenis extern enum dtor_kinds is_destructor_name (const char *name);
79*b725ae77Skettenis 
80*b725ae77Skettenis 
81*b725ae77Skettenis /* Return non-zero iff NAME is the mangled name of a vtable.  */
82*b725ae77Skettenis extern int is_vtable_name (const char *name);
83*b725ae77Skettenis 
84*b725ae77Skettenis 
85*b725ae77Skettenis /* Return non-zero iff NAME is the un-mangled name of an operator,
86*b725ae77Skettenis    perhaps scoped within some class.  */
87*b725ae77Skettenis extern int is_operator_name (const char *name);
88*b725ae77Skettenis 
89*b725ae77Skettenis 
90*b725ae77Skettenis /* Return an object's virtual function as a value.
91*b725ae77Skettenis 
92*b725ae77Skettenis    VALUEP is a pointer to a pointer to a value, holding the object
93*b725ae77Skettenis    whose virtual function we want to invoke.  If the ABI requires a
94*b725ae77Skettenis    virtual function's caller to adjust the `this' pointer by an amount
95*b725ae77Skettenis    retrieved from the vtable before invoking the function (i.e., we're
96*b725ae77Skettenis    not using "vtable thunks" to do the adjustment automatically), then
97*b725ae77Skettenis    this function may set *VALUEP to point to a new object with an
98*b725ae77Skettenis    appropriately tweaked address.
99*b725ae77Skettenis 
100*b725ae77Skettenis    The J'th element of the overload set F is the virtual function of
101*b725ae77Skettenis    *VALUEP we want to invoke.
102*b725ae77Skettenis 
103*b725ae77Skettenis    TYPE is the base type of *VALUEP whose method we're invoking ---
104*b725ae77Skettenis    this is the type containing F.  OFFSET is the offset of that base
105*b725ae77Skettenis    type within *VALUEP.  */
106*b725ae77Skettenis extern struct value *value_virtual_fn_field (struct value **valuep,
107*b725ae77Skettenis 					     struct fn_field *f, int j,
108*b725ae77Skettenis 					     struct type *type, int offset);
109*b725ae77Skettenis 
110*b725ae77Skettenis 
111*b725ae77Skettenis /* Try to find the run-time type of VALUE, using C++ run-time type
112*b725ae77Skettenis    information.  Return the run-time type, or zero if we can't figure
113*b725ae77Skettenis    it out.
114*b725ae77Skettenis 
115*b725ae77Skettenis    If we do find the run-time type:
116*b725ae77Skettenis    - Set *FULL to non-zero if VALUE already contains the complete
117*b725ae77Skettenis      run-time object, not just some embedded base class of the object.
118*b725ae77Skettenis    - Set *TOP and *USING_ENC to indicate where the enclosing object
119*b725ae77Skettenis      starts relative to VALUE:
120*b725ae77Skettenis      - If *USING_ENC is zero, then *TOP is the offset from the start
121*b725ae77Skettenis        of the complete object to the start of the embedded subobject
122*b725ae77Skettenis        VALUE represents.  In other words, the enclosing object starts
123*b725ae77Skettenis        at VALUE_ADDR (VALUE) + VALUE_OFFSET (VALUE) +
124*b725ae77Skettenis        VALUE_EMBEDDED_OFFSET (VALUE) + *TOP
125*b725ae77Skettenis      - If *USING_ENC is non-zero, then *TOP is the offset from the
126*b725ae77Skettenis        address of the complete object to the enclosing object stored
127*b725ae77Skettenis        in VALUE.  In other words, the enclosing object starts at
128*b725ae77Skettenis        VALUE_ADDR (VALUE) + VALUE_OFFSET (VALUE) + *TOP.
129*b725ae77Skettenis      If VALUE's type and enclosing type are the same, then these two
130*b725ae77Skettenis      cases are equivalent.
131*b725ae77Skettenis 
132*b725ae77Skettenis    FULL, TOP, and USING_ENC can each be zero, in which case we don't
133*b725ae77Skettenis    provide the corresponding piece of information.  */
134*b725ae77Skettenis extern struct type *value_rtti_type (struct value *value,
135*b725ae77Skettenis                                      int *full, int *top, int *using_enc);
136*b725ae77Skettenis 
137*b725ae77Skettenis /* Compute the offset of the baseclass which is
138*b725ae77Skettenis    the INDEXth baseclass of class TYPE,
139*b725ae77Skettenis    for value at VALADDR (in host) at ADDRESS (in target).
140*b725ae77Skettenis    The result is the offset of the baseclass value relative
141*b725ae77Skettenis    to (the address of)(ARG) + OFFSET.
142*b725ae77Skettenis 
143*b725ae77Skettenis    -1 is returned on error. */
144*b725ae77Skettenis 
145*b725ae77Skettenis extern int baseclass_offset (struct type *type, int index, char *valaddr,
146*b725ae77Skettenis 			     CORE_ADDR address);
147*b725ae77Skettenis 
148*b725ae77Skettenis struct cp_abi_ops
149*b725ae77Skettenis {
150*b725ae77Skettenis   const char *shortname;
151*b725ae77Skettenis   const char *longname;
152*b725ae77Skettenis   const char *doc;
153*b725ae77Skettenis 
154*b725ae77Skettenis   /* ABI-specific implementations for the functions declared above.  */
155*b725ae77Skettenis   enum ctor_kinds (*is_constructor_name) (const char *name);
156*b725ae77Skettenis   enum dtor_kinds (*is_destructor_name) (const char *name);
157*b725ae77Skettenis   int (*is_vtable_name) (const char *name);
158*b725ae77Skettenis   int (*is_operator_name) (const char *name);
159*b725ae77Skettenis   struct value *(*virtual_fn_field) (struct value **arg1p, struct fn_field * f,
160*b725ae77Skettenis 				     int j, struct type * type, int offset);
161*b725ae77Skettenis   struct type *(*rtti_type) (struct value *v, int *full, int *top,
162*b725ae77Skettenis 			     int *using_enc);
163*b725ae77Skettenis   int (*baseclass_offset) (struct type *type, int index, char *valaddr,
164*b725ae77Skettenis 			   CORE_ADDR address);
165*b725ae77Skettenis };
166*b725ae77Skettenis 
167*b725ae77Skettenis 
168*b725ae77Skettenis extern int register_cp_abi (struct cp_abi_ops *abi);
169*b725ae77Skettenis extern void set_cp_abi_as_auto_default (const char *short_name);
170*b725ae77Skettenis 
171*b725ae77Skettenis #endif
172*b725ae77Skettenis 
173