xref: /dragonfly/contrib/gdb-7/gdb/cp-abi.h (revision ef5ccd6c)
15796c8dcSSimon Schubert /* Abstraction of various C++ ABI's we support, and the info we need
25796c8dcSSimon Schubert    to get from them.
35796c8dcSSimon Schubert 
45796c8dcSSimon Schubert    Contributed by Daniel Berlin <dberlin@redhat.com>
55796c8dcSSimon Schubert 
6*ef5ccd6cSJohn Marino    Copyright (C) 2001-2013 Free Software Foundation, Inc.
75796c8dcSSimon Schubert 
85796c8dcSSimon Schubert    This file is part of GDB.
95796c8dcSSimon Schubert 
105796c8dcSSimon Schubert    This program is free software; you can redistribute it and/or modify
115796c8dcSSimon Schubert    it under the terms of the GNU General Public License as published by
125796c8dcSSimon Schubert    the Free Software Foundation; either version 3 of the License, or
135796c8dcSSimon Schubert    (at your option) any later version.
145796c8dcSSimon Schubert 
155796c8dcSSimon Schubert    This program is distributed in the hope that it will be useful,
165796c8dcSSimon Schubert    but WITHOUT ANY WARRANTY; without even the implied warranty of
175796c8dcSSimon Schubert    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
185796c8dcSSimon Schubert    GNU General Public License for more details.
195796c8dcSSimon Schubert 
205796c8dcSSimon Schubert    You should have received a copy of the GNU General Public License
215796c8dcSSimon Schubert    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
225796c8dcSSimon Schubert 
235796c8dcSSimon Schubert #ifndef CP_ABI_H_
245796c8dcSSimon Schubert #define CP_ABI_H_ 1
255796c8dcSSimon Schubert 
265796c8dcSSimon Schubert struct fn_field;
275796c8dcSSimon Schubert struct type;
285796c8dcSSimon Schubert struct value;
295796c8dcSSimon Schubert struct ui_file;
305796c8dcSSimon Schubert struct frame_info;
315796c8dcSSimon Schubert 
325796c8dcSSimon Schubert /* The functions here that attempt to determine what sort of thing a
335796c8dcSSimon Schubert    mangled name refers to may well be revised in the future.  It would
345796c8dcSSimon Schubert    certainly be cleaner to carry this information explicitly in GDB's
355796c8dcSSimon Schubert    data structures than to derive it from the mangled name.  */
365796c8dcSSimon Schubert 
375796c8dcSSimon Schubert 
385796c8dcSSimon Schubert /* Kinds of constructors.  All these values are guaranteed to be
395796c8dcSSimon Schubert    non-zero.  */
405796c8dcSSimon Schubert enum ctor_kinds {
415796c8dcSSimon Schubert 
425796c8dcSSimon Schubert   /* Initialize a complete object, including virtual bases, using
435796c8dcSSimon Schubert      memory provided by caller.  */
445796c8dcSSimon Schubert   complete_object_ctor = 1,
455796c8dcSSimon Schubert 
465796c8dcSSimon Schubert   /* Initialize a base object of some larger object.  */
475796c8dcSSimon Schubert   base_object_ctor,
485796c8dcSSimon Schubert 
495796c8dcSSimon Schubert   /* An allocating complete-object constructor.  */
505796c8dcSSimon Schubert   complete_object_allocating_ctor
515796c8dcSSimon Schubert };
525796c8dcSSimon Schubert 
535796c8dcSSimon Schubert /* Return non-zero iff NAME is the mangled name of a constructor.
545796c8dcSSimon Schubert    Actually, return an `enum ctor_kind' value describing what *kind*
555796c8dcSSimon Schubert    of constructor it is.  */
565796c8dcSSimon Schubert extern enum ctor_kinds is_constructor_name (const char *name);
575796c8dcSSimon Schubert 
585796c8dcSSimon Schubert 
595796c8dcSSimon Schubert /* Kinds of destructors.  All these values are guaranteed to be
605796c8dcSSimon Schubert    non-zero.  */
615796c8dcSSimon Schubert enum dtor_kinds {
625796c8dcSSimon Schubert 
635796c8dcSSimon Schubert   /* A destructor which finalizes the entire object, and then calls
645796c8dcSSimon Schubert      `delete' on its storage.  */
655796c8dcSSimon Schubert   deleting_dtor = 1,
665796c8dcSSimon Schubert 
675796c8dcSSimon Schubert   /* A destructor which finalizes the entire object, but does not call
685796c8dcSSimon Schubert      `delete'.  */
695796c8dcSSimon Schubert   complete_object_dtor,
705796c8dcSSimon Schubert 
71c50c785cSJohn Marino   /* A destructor which finalizes a subobject of some larger
72c50c785cSJohn Marino      object.  */
735796c8dcSSimon Schubert   base_object_dtor
745796c8dcSSimon Schubert };
755796c8dcSSimon Schubert 
765796c8dcSSimon Schubert /* Return non-zero iff NAME is the mangled name of a destructor.
775796c8dcSSimon Schubert    Actually, return an `enum dtor_kind' value describing what *kind*
785796c8dcSSimon Schubert    of destructor it is.  */
795796c8dcSSimon Schubert extern enum dtor_kinds is_destructor_name (const char *name);
805796c8dcSSimon Schubert 
815796c8dcSSimon Schubert 
825796c8dcSSimon Schubert /* Return non-zero iff NAME is the mangled name of a vtable.  */
835796c8dcSSimon Schubert extern int is_vtable_name (const char *name);
845796c8dcSSimon Schubert 
855796c8dcSSimon Schubert 
865796c8dcSSimon Schubert /* Return non-zero iff NAME is the un-mangled name of an operator,
875796c8dcSSimon Schubert    perhaps scoped within some class.  */
885796c8dcSSimon Schubert extern int is_operator_name (const char *name);
895796c8dcSSimon Schubert 
905796c8dcSSimon Schubert 
915796c8dcSSimon Schubert /* Return an object's virtual function as a value.
925796c8dcSSimon Schubert 
935796c8dcSSimon Schubert    VALUEP is a pointer to a pointer to a value, holding the object
945796c8dcSSimon Schubert    whose virtual function we want to invoke.  If the ABI requires a
955796c8dcSSimon Schubert    virtual function's caller to adjust the `this' pointer by an amount
965796c8dcSSimon Schubert    retrieved from the vtable before invoking the function (i.e., we're
975796c8dcSSimon Schubert    not using "vtable thunks" to do the adjustment automatically), then
985796c8dcSSimon Schubert    this function may set *VALUEP to point to a new object with an
995796c8dcSSimon Schubert    appropriately tweaked address.
1005796c8dcSSimon Schubert 
1015796c8dcSSimon Schubert    The J'th element of the overload set F is the virtual function of
1025796c8dcSSimon Schubert    *VALUEP we want to invoke.
1035796c8dcSSimon Schubert 
1045796c8dcSSimon Schubert    TYPE is the base type of *VALUEP whose method we're invoking ---
1055796c8dcSSimon Schubert    this is the type containing F.  OFFSET is the offset of that base
1065796c8dcSSimon Schubert    type within *VALUEP.  */
1075796c8dcSSimon Schubert extern struct value *value_virtual_fn_field (struct value **valuep,
108c50c785cSJohn Marino 					     struct fn_field *f,
109c50c785cSJohn Marino 					     int j,
110c50c785cSJohn Marino 					     struct type *type,
111c50c785cSJohn Marino 					     int offset);
1125796c8dcSSimon Schubert 
1135796c8dcSSimon Schubert 
1145796c8dcSSimon Schubert /* Try to find the run-time type of VALUE, using C++ run-time type
1155796c8dcSSimon Schubert    information.  Return the run-time type, or zero if we can't figure
1165796c8dcSSimon Schubert    it out.
1175796c8dcSSimon Schubert 
1185796c8dcSSimon Schubert    If we do find the run-time type:
1195796c8dcSSimon Schubert    - Set *FULL to non-zero if VALUE already contains the complete
1205796c8dcSSimon Schubert      run-time object, not just some embedded base class of the object.
1215796c8dcSSimon Schubert    - Set *TOP and *USING_ENC to indicate where the enclosing object
1225796c8dcSSimon Schubert      starts relative to VALUE:
1235796c8dcSSimon Schubert      - If *USING_ENC is zero, then *TOP is the offset from the start
1245796c8dcSSimon Schubert        of the complete object to the start of the embedded subobject
1255796c8dcSSimon Schubert        VALUE represents.  In other words, the enclosing object starts
1265796c8dcSSimon Schubert        at VALUE_ADDR (VALUE) + VALUE_OFFSET (VALUE) +
1275796c8dcSSimon Schubert        value_embedded_offset (VALUE) + *TOP
1285796c8dcSSimon Schubert      - If *USING_ENC is non-zero, then *TOP is the offset from the
1295796c8dcSSimon Schubert        address of the complete object to the enclosing object stored
1305796c8dcSSimon Schubert        in VALUE.  In other words, the enclosing object starts at
1315796c8dcSSimon Schubert        VALUE_ADDR (VALUE) + VALUE_OFFSET (VALUE) + *TOP.
1325796c8dcSSimon Schubert      If VALUE's type and enclosing type are the same, then these two
1335796c8dcSSimon Schubert      cases are equivalent.
1345796c8dcSSimon Schubert 
1355796c8dcSSimon Schubert    FULL, TOP, and USING_ENC can each be zero, in which case we don't
1365796c8dcSSimon Schubert    provide the corresponding piece of information.  */
1375796c8dcSSimon Schubert extern struct type *value_rtti_type (struct value *value,
138c50c785cSJohn Marino                                      int *full, int *top,
139c50c785cSJohn Marino 				     int *using_enc);
1405796c8dcSSimon Schubert 
141c50c785cSJohn Marino /* Compute the offset of the baseclass which is the INDEXth baseclass
142c50c785cSJohn Marino    of class TYPE, for value at VALADDR (in host) at ADDRESS (in
143c50c785cSJohn Marino    target), offset by EMBEDDED_OFFSET.  VALADDR points to the raw
144c50c785cSJohn Marino    contents of VAL.  The result is the offset of the baseclass value
145c50c785cSJohn Marino    relative to (the address of)(ARG) + OFFSET.  */
1465796c8dcSSimon Schubert 
147c50c785cSJohn Marino extern int baseclass_offset (struct type *type,
148c50c785cSJohn Marino 			     int index, const gdb_byte *valaddr,
149c50c785cSJohn Marino 			     int embedded_offset,
150c50c785cSJohn Marino 			     CORE_ADDR address,
151c50c785cSJohn Marino 			     const struct value *val);
1525796c8dcSSimon Schubert 
1535796c8dcSSimon Schubert /* Describe the target of a pointer to method.  CONTENTS is the byte
1545796c8dcSSimon Schubert    pattern representing the pointer to method.  TYPE is the pointer to
1555796c8dcSSimon Schubert    method type.  STREAM is the stream to print it to.  */
156c50c785cSJohn Marino void cplus_print_method_ptr (const gdb_byte *contents,
157c50c785cSJohn Marino 			     struct type *type,
1585796c8dcSSimon Schubert 			     struct ui_file *stream);
1595796c8dcSSimon Schubert 
160c50c785cSJohn Marino /* Return the size of a pointer to member function of type
161c50c785cSJohn Marino    TO_TYPE.  */
1625796c8dcSSimon Schubert int cplus_method_ptr_size (struct type *to_type);
1635796c8dcSSimon Schubert 
164c50c785cSJohn Marino /* Return the method which should be called by applying METHOD_PTR to
165c50c785cSJohn Marino    *THIS_P, and adjust *THIS_P if necessary.  */
1665796c8dcSSimon Schubert struct value *cplus_method_ptr_to_value (struct value **this_p,
1675796c8dcSSimon Schubert 					 struct value *method_ptr);
1685796c8dcSSimon Schubert 
169c50c785cSJohn Marino /* Create the byte pattern in CONTENTS representing a pointer of type
170c50c785cSJohn Marino    TYPE to member function at ADDRESS (if IS_VIRTUAL is 0) or with
171c50c785cSJohn Marino    virtual table offset ADDRESS (if IS_VIRTUAL is 1).  This is the
172c50c785cSJohn Marino    opposite of cplus_method_ptr_to_value.  */
1735796c8dcSSimon Schubert void cplus_make_method_ptr (struct type *type, gdb_byte *CONTENTS,
1745796c8dcSSimon Schubert 			    CORE_ADDR address, int is_virtual);
1755796c8dcSSimon Schubert 
176*ef5ccd6cSJohn Marino /* Print the vtable for VALUE, if there is one.  If there is no
177*ef5ccd6cSJohn Marino    vtable, print a message, but do not throw.  */
178*ef5ccd6cSJohn Marino 
179*ef5ccd6cSJohn Marino void cplus_print_vtable (struct value *value);
180*ef5ccd6cSJohn Marino 
181c50c785cSJohn Marino /* Determine if we are currently in a C++ thunk.  If so, get the
182c50c785cSJohn Marino    address of the routine we are thunking to and continue to there
183c50c785cSJohn Marino    instead.  */
1845796c8dcSSimon Schubert 
185c50c785cSJohn Marino CORE_ADDR cplus_skip_trampoline (struct frame_info *frame,
186c50c785cSJohn Marino 				 CORE_ADDR stop_pc);
1875796c8dcSSimon Schubert 
188c50c785cSJohn Marino /* Return non-zero if an argument of type TYPE should be passed by
189c50c785cSJohn Marino    reference instead of value.  */
1905796c8dcSSimon Schubert extern int cp_pass_by_reference (struct type *type);
1915796c8dcSSimon Schubert 
1925796c8dcSSimon Schubert struct cp_abi_ops
1935796c8dcSSimon Schubert {
1945796c8dcSSimon Schubert   const char *shortname;
1955796c8dcSSimon Schubert   const char *longname;
1965796c8dcSSimon Schubert   const char *doc;
1975796c8dcSSimon Schubert 
198c50c785cSJohn Marino   /* ABI-specific implementations for the functions declared
199c50c785cSJohn Marino      above.  */
2005796c8dcSSimon Schubert   enum ctor_kinds (*is_constructor_name) (const char *name);
2015796c8dcSSimon Schubert   enum dtor_kinds (*is_destructor_name) (const char *name);
2025796c8dcSSimon Schubert   int (*is_vtable_name) (const char *name);
2035796c8dcSSimon Schubert   int (*is_operator_name) (const char *name);
204c50c785cSJohn Marino   struct value *(*virtual_fn_field) (struct value **arg1p,
205c50c785cSJohn Marino 				     struct fn_field * f,
206c50c785cSJohn Marino 				     int j, struct type * type,
207c50c785cSJohn Marino 				     int offset);
208c50c785cSJohn Marino   struct type *(*rtti_type) (struct value *v, int *full,
209c50c785cSJohn Marino 			     int *top, int *using_enc);
2105796c8dcSSimon Schubert   int (*baseclass_offset) (struct type *type, int index,
211c50c785cSJohn Marino 			   const bfd_byte *valaddr, int embedded_offset,
212c50c785cSJohn Marino 			   CORE_ADDR address, const struct value *val);
213c50c785cSJohn Marino   void (*print_method_ptr) (const gdb_byte *contents,
214c50c785cSJohn Marino 			    struct type *type,
2155796c8dcSSimon Schubert 			    struct ui_file *stream);
2165796c8dcSSimon Schubert   int (*method_ptr_size) (struct type *);
217c50c785cSJohn Marino   void (*make_method_ptr) (struct type *, gdb_byte *,
218c50c785cSJohn Marino 			   CORE_ADDR, int);
219c50c785cSJohn Marino   struct value * (*method_ptr_to_value) (struct value **,
220c50c785cSJohn Marino 					 struct value *);
221*ef5ccd6cSJohn Marino   void (*print_vtable) (struct value *);
2225796c8dcSSimon Schubert   CORE_ADDR (*skip_trampoline) (struct frame_info *, CORE_ADDR);
2235796c8dcSSimon Schubert   int (*pass_by_reference) (struct type *type);
2245796c8dcSSimon Schubert };
2255796c8dcSSimon Schubert 
2265796c8dcSSimon Schubert 
2275796c8dcSSimon Schubert extern int register_cp_abi (struct cp_abi_ops *abi);
2285796c8dcSSimon Schubert extern void set_cp_abi_as_auto_default (const char *short_name);
2295796c8dcSSimon Schubert 
2305796c8dcSSimon Schubert #endif
2315796c8dcSSimon Schubert 
232