Upgrade GDB from 7.0 and 7.2 on the vendor branch
[dragonfly.git] / contrib / gdb-7 / gdb / cp-abi.h
1 /* Abstraction of various C++ ABI's we support, and the info we need
2    to get from them.
3
4    Contributed by Daniel Berlin <dberlin@redhat.com>
5
6    Copyright (C) 2001, 2005, 2006, 2007, 2008, 2009, 2010
7    Free Software Foundation, Inc.
8
9    This file is part of GDB.
10
11    This program is free software; you can redistribute it and/or modify
12    it under the terms of the GNU General Public License as published by
13    the Free Software Foundation; either version 3 of the License, or
14    (at your option) any later version.
15
16    This program is distributed in the hope that it will be useful,
17    but WITHOUT ANY WARRANTY; without even the implied warranty of
18    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19    GNU General Public License for more details.
20
21    You should have received a copy of the GNU General Public License
22    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
23
24 #ifndef CP_ABI_H_
25 #define CP_ABI_H_ 1
26
27 struct fn_field;
28 struct type;
29 struct value;
30 struct ui_file;
31 struct frame_info;
32
33 /* The functions here that attempt to determine what sort of thing a
34    mangled name refers to may well be revised in the future.  It would
35    certainly be cleaner to carry this information explicitly in GDB's
36    data structures than to derive it from the mangled name.  */
37
38
39 /* Kinds of constructors.  All these values are guaranteed to be
40    non-zero.  */
41 enum ctor_kinds {
42
43   /* Initialize a complete object, including virtual bases, using
44      memory provided by caller.  */
45   complete_object_ctor = 1,
46
47   /* Initialize a base object of some larger object.  */
48   base_object_ctor,
49
50   /* An allocating complete-object constructor.  */
51   complete_object_allocating_ctor
52 };
53
54 /* Return non-zero iff NAME is the mangled name of a constructor.
55    Actually, return an `enum ctor_kind' value describing what *kind*
56    of constructor it is.  */
57 extern enum ctor_kinds is_constructor_name (const char *name);
58
59
60 /* Kinds of destructors.  All these values are guaranteed to be
61    non-zero.  */
62 enum dtor_kinds {
63
64   /* A destructor which finalizes the entire object, and then calls
65      `delete' on its storage.  */
66   deleting_dtor = 1,
67
68   /* A destructor which finalizes the entire object, but does not call
69      `delete'.  */
70   complete_object_dtor,
71
72   /* A destructor which finalizes a subobject of some larger object.  */
73   base_object_dtor
74 };
75   
76 /* Return non-zero iff NAME is the mangled name of a destructor.
77    Actually, return an `enum dtor_kind' value describing what *kind*
78    of destructor it is.  */
79 extern enum dtor_kinds is_destructor_name (const char *name);
80
81
82 /* Return non-zero iff NAME is the mangled name of a vtable.  */
83 extern int is_vtable_name (const char *name);
84
85
86 /* Return non-zero iff NAME is the un-mangled name of an operator,
87    perhaps scoped within some class.  */
88 extern int is_operator_name (const char *name);
89
90
91 /* Return an object's virtual function as a value.
92
93    VALUEP is a pointer to a pointer to a value, holding the object
94    whose virtual function we want to invoke.  If the ABI requires a
95    virtual function's caller to adjust the `this' pointer by an amount
96    retrieved from the vtable before invoking the function (i.e., we're
97    not using "vtable thunks" to do the adjustment automatically), then
98    this function may set *VALUEP to point to a new object with an
99    appropriately tweaked address.
100
101    The J'th element of the overload set F is the virtual function of
102    *VALUEP we want to invoke.
103
104    TYPE is the base type of *VALUEP whose method we're invoking ---
105    this is the type containing F.  OFFSET is the offset of that base
106    type within *VALUEP.  */
107 extern struct value *value_virtual_fn_field (struct value **valuep,
108                                              struct fn_field *f, int j,
109                                              struct type *type, int offset);
110
111
112 /* Try to find the run-time type of VALUE, using C++ run-time type
113    information.  Return the run-time type, or zero if we can't figure
114    it out.
115
116    If we do find the run-time type:
117    - Set *FULL to non-zero if VALUE already contains the complete
118      run-time object, not just some embedded base class of the object.
119    - Set *TOP and *USING_ENC to indicate where the enclosing object
120      starts relative to VALUE:
121      - If *USING_ENC is zero, then *TOP is the offset from the start
122        of the complete object to the start of the embedded subobject
123        VALUE represents.  In other words, the enclosing object starts
124        at VALUE_ADDR (VALUE) + VALUE_OFFSET (VALUE) +
125        value_embedded_offset (VALUE) + *TOP
126      - If *USING_ENC is non-zero, then *TOP is the offset from the
127        address of the complete object to the enclosing object stored
128        in VALUE.  In other words, the enclosing object starts at
129        VALUE_ADDR (VALUE) + VALUE_OFFSET (VALUE) + *TOP.
130      If VALUE's type and enclosing type are the same, then these two
131      cases are equivalent.
132
133    FULL, TOP, and USING_ENC can each be zero, in which case we don't
134    provide the corresponding piece of information.  */
135 extern struct type *value_rtti_type (struct value *value,
136                                      int *full, int *top, int *using_enc);
137
138 /* Compute the offset of the baseclass which is
139    the INDEXth baseclass of class TYPE,
140    for value at VALADDR (in host) at ADDRESS (in target).
141    The result is the offset of the baseclass value relative
142    to (the address of)(ARG) + OFFSET.
143
144    -1 is returned on error. */
145
146 extern int baseclass_offset (struct type *type, int index,
147                              const bfd_byte *valaddr, CORE_ADDR address);
148                   
149 /* Describe the target of a pointer to method.  CONTENTS is the byte
150    pattern representing the pointer to method.  TYPE is the pointer to
151    method type.  STREAM is the stream to print it to.  */
152 void cplus_print_method_ptr (const gdb_byte *contents, struct type *type,
153                              struct ui_file *stream);
154
155 /* Return the size of a pointer to member function of type TO_TYPE.  */
156 int cplus_method_ptr_size (struct type *to_type);
157
158 /* Return the method which should be called by applying METHOD_PTR
159    to *THIS_P, and adjust *THIS_P if necessary.  */
160 struct value *cplus_method_ptr_to_value (struct value **this_p,
161                                          struct value *method_ptr);
162
163 /* Create the byte pattern in CONTENTS representing a pointer of
164    type TYPE to member function at ADDRESS (if IS_VIRTUAL is 0)
165    or with virtual table offset ADDRESS (if IS_VIRTUAL is 1).
166    This is the opposite of cplus_method_ptr_to_value.  */
167 void cplus_make_method_ptr (struct type *type, gdb_byte *CONTENTS,
168                             CORE_ADDR address, int is_virtual);
169
170 /* Determine if we are currently in a C++ thunk.  If so, get the address
171    of the routine we are thunking to and continue to there instead.  */
172
173 CORE_ADDR cplus_skip_trampoline (struct frame_info *frame, CORE_ADDR stop_pc);
174
175 /* Return non-zero if an argument of type TYPE should be passed by reference
176    instead of value.  */
177 extern int cp_pass_by_reference (struct type *type);
178
179 struct cp_abi_ops
180 {
181   const char *shortname;
182   const char *longname;
183   const char *doc;
184
185   /* ABI-specific implementations for the functions declared above.  */
186   enum ctor_kinds (*is_constructor_name) (const char *name);
187   enum dtor_kinds (*is_destructor_name) (const char *name);
188   int (*is_vtable_name) (const char *name);
189   int (*is_operator_name) (const char *name);
190   struct value *(*virtual_fn_field) (struct value **arg1p, struct fn_field * f,
191                                      int j, struct type * type, int offset);
192   struct type *(*rtti_type) (struct value *v, int *full, int *top,
193                              int *using_enc);
194   int (*baseclass_offset) (struct type *type, int index,
195                            const bfd_byte *valaddr, CORE_ADDR address);
196   void (*print_method_ptr) (const gdb_byte *contents, struct type *type,
197                             struct ui_file *stream);
198   int (*method_ptr_size) (struct type *);
199   void (*make_method_ptr) (struct type *, gdb_byte *, CORE_ADDR, int);
200   struct value * (*method_ptr_to_value) (struct value **, struct value *);
201   CORE_ADDR (*skip_trampoline) (struct frame_info *, CORE_ADDR);
202   int (*pass_by_reference) (struct type *type);
203 };
204
205
206 extern int register_cp_abi (struct cp_abi_ops *abi);
207 extern void set_cp_abi_as_auto_default (const char *short_name);
208
209 #endif
210