Commit | Line | Data |
---|---|---|
015a42b4 JB |
1 | /* Abstraction of various C++ ABI's we support, and the info we need |
2 | to get from them. | |
06c4d4dc | 3 | |
015a42b4 | 4 | Contributed by Daniel Berlin <dberlin@redhat.com> |
06c4d4dc | 5 | |
ecd75fc8 | 6 | Copyright (C) 2001-2014 Free Software Foundation, Inc. |
015a42b4 JB |
7 | |
8 | This file is part of GDB. | |
9 | ||
a9762ec7 JB |
10 | This program is free software; you can redistribute it and/or modify |
11 | it under the terms of the GNU General Public License as published by | |
12 | the Free Software Foundation; either version 3 of the License, or | |
015a42b4 JB |
13 | (at your option) any later version. |
14 | ||
15 | This program is distributed in the hope that it will be useful, | |
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | GNU General Public License for more details. | |
19 | ||
20 | You should have received a copy of the GNU General Public License | |
a9762ec7 | 21 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
015a42b4 JB |
22 | |
23 | #ifndef CP_ABI_H_ | |
24 | #define CP_ABI_H_ 1 | |
25 | ||
da3331ec AC |
26 | struct fn_field; |
27 | struct type; | |
e933e538 | 28 | struct value; |
0d5de010 | 29 | struct ui_file; |
52f729a7 | 30 | struct frame_info; |
e933e538 | 31 | |
c5f5341b JB |
32 | /* The functions here that attempt to determine what sort of thing a |
33 | mangled name refers to may well be revised in the future. It would | |
34 | certainly be cleaner to carry this information explicitly in GDB's | |
35 | data structures than to derive it from the mangled name. */ | |
36 | ||
37 | ||
015a42b4 JB |
38 | /* Kinds of constructors. All these values are guaranteed to be |
39 | non-zero. */ | |
40 | enum ctor_kinds { | |
41 | ||
42 | /* Initialize a complete object, including virtual bases, using | |
43 | memory provided by caller. */ | |
44 | complete_object_ctor = 1, | |
45 | ||
46 | /* Initialize a base object of some larger object. */ | |
47 | base_object_ctor, | |
48 | ||
49 | /* An allocating complete-object constructor. */ | |
50 | complete_object_allocating_ctor | |
51 | }; | |
52 | ||
c5f5341b JB |
53 | /* Return non-zero iff NAME is the mangled name of a constructor. |
54 | Actually, return an `enum ctor_kind' value describing what *kind* | |
55 | of constructor it is. */ | |
56 | extern enum ctor_kinds is_constructor_name (const char *name); | |
57 | ||
015a42b4 JB |
58 | |
59 | /* Kinds of destructors. All these values are guaranteed to be | |
60 | non-zero. */ | |
61 | enum dtor_kinds { | |
62 | ||
63 | /* A destructor which finalizes the entire object, and then calls | |
64 | `delete' on its storage. */ | |
65 | deleting_dtor = 1, | |
66 | ||
67 | /* A destructor which finalizes the entire object, but does not call | |
68 | `delete'. */ | |
69 | complete_object_dtor, | |
70 | ||
aff410f1 MS |
71 | /* A destructor which finalizes a subobject of some larger |
72 | object. */ | |
015a42b4 JB |
73 | base_object_dtor |
74 | }; | |
75 | ||
c5f5341b JB |
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. */ | |
e933e538 | 107 | extern struct value *value_virtual_fn_field (struct value **valuep, |
aff410f1 MS |
108 | struct fn_field *f, |
109 | int j, | |
110 | struct type *type, | |
111 | int offset); | |
c5f5341b JB |
112 | |
113 | ||
114 | /* Try to find the run-time type of VALUE, using C++ run-time type | |
115 | information. Return the run-time type, or zero if we can't figure | |
116 | it out. | |
117 | ||
118 | If we do find the run-time type: | |
119 | - Set *FULL to non-zero if VALUE already contains the complete | |
120 | run-time object, not just some embedded base class of the object. | |
121 | - Set *TOP and *USING_ENC to indicate where the enclosing object | |
122 | starts relative to VALUE: | |
123 | - If *USING_ENC is zero, then *TOP is the offset from the start | |
124 | of the complete object to the start of the embedded subobject | |
125 | VALUE represents. In other words, the enclosing object starts | |
126 | at VALUE_ADDR (VALUE) + VALUE_OFFSET (VALUE) + | |
13c3b5f5 | 127 | value_embedded_offset (VALUE) + *TOP |
c5f5341b JB |
128 | - If *USING_ENC is non-zero, then *TOP is the offset from the |
129 | address of the complete object to the enclosing object stored | |
130 | in VALUE. In other words, the enclosing object starts at | |
131 | VALUE_ADDR (VALUE) + VALUE_OFFSET (VALUE) + *TOP. | |
132 | If VALUE's type and enclosing type are the same, then these two | |
133 | cases are equivalent. | |
134 | ||
135 | FULL, TOP, and USING_ENC can each be zero, in which case we don't | |
136 | provide the corresponding piece of information. */ | |
137 | extern struct type *value_rtti_type (struct value *value, | |
aff410f1 MS |
138 | int *full, int *top, |
139 | int *using_enc); | |
c5f5341b | 140 | |
8af8e3bc PA |
141 | /* Compute the offset of the baseclass which is the INDEXth baseclass |
142 | of class TYPE, for value at VALADDR (in host) at ADDRESS (in | |
143 | target), offset by EMBEDDED_OFFSET. VALADDR points to the raw | |
144 | contents of VAL. The result is the offset of the baseclass value | |
145 | relative to (the address of)(ARG) + OFFSET. */ | |
146 | ||
147 | extern int baseclass_offset (struct type *type, | |
148 | int index, const gdb_byte *valaddr, | |
149 | int embedded_offset, | |
150 | CORE_ADDR address, | |
151 | const struct value *val); | |
152 | ||
0d5de010 DJ |
153 | /* Describe the target of a pointer to method. CONTENTS is the byte |
154 | pattern representing the pointer to method. TYPE is the pointer to | |
155 | method type. STREAM is the stream to print it to. */ | |
aff410f1 MS |
156 | void cplus_print_method_ptr (const gdb_byte *contents, |
157 | struct type *type, | |
0d5de010 DJ |
158 | struct ui_file *stream); |
159 | ||
aff410f1 MS |
160 | /* Return the size of a pointer to member function of type |
161 | TO_TYPE. */ | |
ad4820ab | 162 | int cplus_method_ptr_size (struct type *to_type); |
0d5de010 | 163 | |
aff410f1 MS |
164 | /* Return the method which should be called by applying METHOD_PTR to |
165 | *THIS_P, and adjust *THIS_P if necessary. */ | |
0d5de010 DJ |
166 | struct value *cplus_method_ptr_to_value (struct value **this_p, |
167 | struct value *method_ptr); | |
168 | ||
aff410f1 MS |
169 | /* Create the byte pattern in CONTENTS representing a pointer of type |
170 | TYPE to member function at ADDRESS (if IS_VIRTUAL is 0) or with | |
171 | virtual table offset ADDRESS (if IS_VIRTUAL is 1). This is the | |
172 | opposite of cplus_method_ptr_to_value. */ | |
ad4820ab UW |
173 | void cplus_make_method_ptr (struct type *type, gdb_byte *CONTENTS, |
174 | CORE_ADDR address, int is_virtual); | |
0d5de010 | 175 | |
c4aeac85 TT |
176 | /* Print the vtable for VALUE, if there is one. If there is no |
177 | vtable, print a message, but do not throw. */ | |
178 | ||
179 | void cplus_print_vtable (struct value *value); | |
180 | ||
6e72ca20 TT |
181 | /* Implement 'typeid': find the type info for VALUE, if possible. If |
182 | the type info cannot be found, throw an exception. */ | |
183 | ||
184 | extern struct value *cplus_typeid (struct value *value); | |
185 | ||
186 | /* Return the type of 'typeid' for the current C++ ABI on the given | |
187 | architecture. */ | |
188 | ||
189 | extern struct type *cplus_typeid_type (struct gdbarch *gdbarch); | |
190 | ||
72f1fe8a TT |
191 | /* Given a value which holds a pointer to a std::type_info, return the |
192 | type which that type_info represents. Throw an exception if the | |
193 | type cannot be found. */ | |
194 | ||
195 | extern struct type *cplus_type_from_type_info (struct value *value); | |
196 | ||
cc16e6c9 TT |
197 | /* Given a value which holds a pointer to a std::type_info, return the |
198 | name of the type which that type_info represents. Throw an | |
199 | exception if the type name cannot be found. The result is | |
200 | xmalloc'd and must be freed by the caller. */ | |
201 | ||
202 | extern char *cplus_typename_from_type_info (struct value *value); | |
203 | ||
aff410f1 MS |
204 | /* Determine if we are currently in a C++ thunk. If so, get the |
205 | address of the routine we are thunking to and continue to there | |
206 | instead. */ | |
b18be20d | 207 | |
aff410f1 MS |
208 | CORE_ADDR cplus_skip_trampoline (struct frame_info *frame, |
209 | CORE_ADDR stop_pc); | |
b18be20d | 210 | |
aff410f1 MS |
211 | /* Return non-zero if an argument of type TYPE should be passed by |
212 | reference instead of value. */ | |
41f1b697 DJ |
213 | extern int cp_pass_by_reference (struct type *type); |
214 | ||
015a42b4 JB |
215 | struct cp_abi_ops |
216 | { | |
217 | const char *shortname; | |
218 | const char *longname; | |
219 | const char *doc; | |
220 | ||
aff410f1 MS |
221 | /* ABI-specific implementations for the functions declared |
222 | above. */ | |
015a42b4 | 223 | enum ctor_kinds (*is_constructor_name) (const char *name); |
015a42b4 | 224 | enum dtor_kinds (*is_destructor_name) (const char *name); |
015a42b4 | 225 | int (*is_vtable_name) (const char *name); |
015a42b4 | 226 | int (*is_operator_name) (const char *name); |
aff410f1 MS |
227 | struct value *(*virtual_fn_field) (struct value **arg1p, |
228 | struct fn_field * f, | |
229 | int j, struct type * type, | |
230 | int offset); | |
231 | struct type *(*rtti_type) (struct value *v, int *full, | |
232 | int *top, int *using_enc); | |
06c4d4dc | 233 | int (*baseclass_offset) (struct type *type, int index, |
8af8e3bc PA |
234 | const bfd_byte *valaddr, int embedded_offset, |
235 | CORE_ADDR address, const struct value *val); | |
aff410f1 MS |
236 | void (*print_method_ptr) (const gdb_byte *contents, |
237 | struct type *type, | |
0d5de010 | 238 | struct ui_file *stream); |
ad4820ab | 239 | int (*method_ptr_size) (struct type *); |
aff410f1 MS |
240 | void (*make_method_ptr) (struct type *, gdb_byte *, |
241 | CORE_ADDR, int); | |
242 | struct value * (*method_ptr_to_value) (struct value **, | |
243 | struct value *); | |
c4aeac85 | 244 | void (*print_vtable) (struct value *); |
6e72ca20 TT |
245 | struct value *(*get_typeid) (struct value *value); |
246 | struct type *(*get_typeid_type) (struct gdbarch *gdbarch); | |
72f1fe8a | 247 | struct type *(*get_type_from_type_info) (struct value *value); |
cc16e6c9 | 248 | char *(*get_typename_from_type_info) (struct value *value); |
52f729a7 | 249 | CORE_ADDR (*skip_trampoline) (struct frame_info *, CORE_ADDR); |
41f1b697 | 250 | int (*pass_by_reference) (struct type *type); |
015a42b4 JB |
251 | }; |
252 | ||
253 | ||
fe1f4a5e DJ |
254 | extern int register_cp_abi (struct cp_abi_ops *abi); |
255 | extern void set_cp_abi_as_auto_default (const char *short_name); | |
015a42b4 JB |
256 | |
257 | #endif | |
258 |