GDB (API)
/home/stan/gdb/src/gdb/cp-abi.h
Go to the documentation of this file.
00001 /* Abstraction of various C++ ABI's we support, and the info we need
00002    to get from them.
00003 
00004    Contributed by Daniel Berlin <dberlin@redhat.com>
00005 
00006    Copyright (C) 2001-2013 Free Software Foundation, Inc.
00007 
00008    This file is part of GDB.
00009 
00010    This program is free software; you can redistribute it and/or modify
00011    it under the terms of the GNU General Public License as published by
00012    the Free Software Foundation; either version 3 of the License, or
00013    (at your option) any later version.
00014 
00015    This program is distributed in the hope that it will be useful,
00016    but WITHOUT ANY WARRANTY; without even the implied warranty of
00017    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018    GNU General Public License for more details.
00019 
00020    You should have received a copy of the GNU General Public License
00021    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
00022 
00023 #ifndef CP_ABI_H_
00024 #define CP_ABI_H_ 1
00025 
00026 struct fn_field;
00027 struct type;
00028 struct value;
00029 struct ui_file;
00030 struct frame_info;
00031 
00032 /* The functions here that attempt to determine what sort of thing a
00033    mangled name refers to may well be revised in the future.  It would
00034    certainly be cleaner to carry this information explicitly in GDB's
00035    data structures than to derive it from the mangled name.  */
00036 
00037 
00038 /* Kinds of constructors.  All these values are guaranteed to be
00039    non-zero.  */
00040 enum ctor_kinds {
00041 
00042   /* Initialize a complete object, including virtual bases, using
00043      memory provided by caller.  */
00044   complete_object_ctor = 1,
00045 
00046   /* Initialize a base object of some larger object.  */
00047   base_object_ctor,
00048 
00049   /* An allocating complete-object constructor.  */
00050   complete_object_allocating_ctor
00051 };
00052 
00053 /* Return non-zero iff NAME is the mangled name of a constructor.
00054    Actually, return an `enum ctor_kind' value describing what *kind*
00055    of constructor it is.  */
00056 extern enum ctor_kinds is_constructor_name (const char *name);
00057 
00058 
00059 /* Kinds of destructors.  All these values are guaranteed to be
00060    non-zero.  */
00061 enum dtor_kinds {
00062 
00063   /* A destructor which finalizes the entire object, and then calls
00064      `delete' on its storage.  */
00065   deleting_dtor = 1,
00066 
00067   /* A destructor which finalizes the entire object, but does not call
00068      `delete'.  */
00069   complete_object_dtor,
00070 
00071   /* A destructor which finalizes a subobject of some larger
00072      object.  */
00073   base_object_dtor
00074 };
00075   
00076 /* Return non-zero iff NAME is the mangled name of a destructor.
00077    Actually, return an `enum dtor_kind' value describing what *kind*
00078    of destructor it is.  */
00079 extern enum dtor_kinds is_destructor_name (const char *name);
00080 
00081 
00082 /* Return non-zero iff NAME is the mangled name of a vtable.  */
00083 extern int is_vtable_name (const char *name);
00084 
00085 
00086 /* Return non-zero iff NAME is the un-mangled name of an operator,
00087    perhaps scoped within some class.  */
00088 extern int is_operator_name (const char *name);
00089 
00090 
00091 /* Return an object's virtual function as a value.
00092 
00093    VALUEP is a pointer to a pointer to a value, holding the object
00094    whose virtual function we want to invoke.  If the ABI requires a
00095    virtual function's caller to adjust the `this' pointer by an amount
00096    retrieved from the vtable before invoking the function (i.e., we're
00097    not using "vtable thunks" to do the adjustment automatically), then
00098    this function may set *VALUEP to point to a new object with an
00099    appropriately tweaked address.
00100 
00101    The J'th element of the overload set F is the virtual function of
00102    *VALUEP we want to invoke.
00103 
00104    TYPE is the base type of *VALUEP whose method we're invoking ---
00105    this is the type containing F.  OFFSET is the offset of that base
00106    type within *VALUEP.  */
00107 extern struct value *value_virtual_fn_field (struct value **valuep,
00108                                              struct fn_field *f,
00109                                              int j,
00110                                              struct type *type,
00111                                              int offset);
00112 
00113 
00114 /* Try to find the run-time type of VALUE, using C++ run-time type
00115    information.  Return the run-time type, or zero if we can't figure
00116    it out.
00117 
00118    If we do find the run-time type:
00119    - Set *FULL to non-zero if VALUE already contains the complete
00120      run-time object, not just some embedded base class of the object.
00121    - Set *TOP and *USING_ENC to indicate where the enclosing object
00122      starts relative to VALUE:
00123      - If *USING_ENC is zero, then *TOP is the offset from the start
00124        of the complete object to the start of the embedded subobject
00125        VALUE represents.  In other words, the enclosing object starts
00126        at VALUE_ADDR (VALUE) + VALUE_OFFSET (VALUE) +
00127        value_embedded_offset (VALUE) + *TOP
00128      - If *USING_ENC is non-zero, then *TOP is the offset from the
00129        address of the complete object to the enclosing object stored
00130        in VALUE.  In other words, the enclosing object starts at
00131        VALUE_ADDR (VALUE) + VALUE_OFFSET (VALUE) + *TOP.
00132      If VALUE's type and enclosing type are the same, then these two
00133      cases are equivalent.
00134 
00135    FULL, TOP, and USING_ENC can each be zero, in which case we don't
00136    provide the corresponding piece of information.  */
00137 extern struct type *value_rtti_type (struct value *value,
00138                                      int *full, int *top,
00139                                      int *using_enc);
00140 
00141 /* Compute the offset of the baseclass which is the INDEXth baseclass
00142    of class TYPE, for value at VALADDR (in host) at ADDRESS (in
00143    target), offset by EMBEDDED_OFFSET.  VALADDR points to the raw
00144    contents of VAL.  The result is the offset of the baseclass value
00145    relative to (the address of)(ARG) + OFFSET.  */
00146 
00147 extern int baseclass_offset (struct type *type,
00148                              int index, const gdb_byte *valaddr,
00149                              int embedded_offset,
00150                              CORE_ADDR address,
00151                              const struct value *val);
00152 
00153 /* Describe the target of a pointer to method.  CONTENTS is the byte
00154    pattern representing the pointer to method.  TYPE is the pointer to
00155    method type.  STREAM is the stream to print it to.  */
00156 void cplus_print_method_ptr (const gdb_byte *contents,
00157                              struct type *type,
00158                              struct ui_file *stream);
00159 
00160 /* Return the size of a pointer to member function of type
00161    TO_TYPE.  */
00162 int cplus_method_ptr_size (struct type *to_type);
00163 
00164 /* Return the method which should be called by applying METHOD_PTR to
00165    *THIS_P, and adjust *THIS_P if necessary.  */
00166 struct value *cplus_method_ptr_to_value (struct value **this_p,
00167                                          struct value *method_ptr);
00168 
00169 /* Create the byte pattern in CONTENTS representing a pointer of type
00170    TYPE to member function at ADDRESS (if IS_VIRTUAL is 0) or with
00171    virtual table offset ADDRESS (if IS_VIRTUAL is 1).  This is the
00172    opposite of cplus_method_ptr_to_value.  */
00173 void cplus_make_method_ptr (struct type *type, gdb_byte *CONTENTS,
00174                             CORE_ADDR address, int is_virtual);
00175 
00176 /* Print the vtable for VALUE, if there is one.  If there is no
00177    vtable, print a message, but do not throw.  */
00178 
00179 void cplus_print_vtable (struct value *value);
00180 
00181 /* Implement 'typeid': find the type info for VALUE, if possible.  If
00182    the type info cannot be found, throw an exception.  */
00183 
00184 extern struct value *cplus_typeid (struct value *value);
00185 
00186 /* Return the type of 'typeid' for the current C++ ABI on the given
00187    architecture.  */
00188 
00189 extern struct type *cplus_typeid_type (struct gdbarch *gdbarch);
00190 
00191 /* Given a value which holds a pointer to a std::type_info, return the
00192    type which that type_info represents.  Throw an exception if the
00193    type cannot be found.  */
00194 
00195 extern struct type *cplus_type_from_type_info (struct value *value);
00196 
00197 /* Given a value which holds a pointer to a std::type_info, return the
00198    name of the type which that type_info represents.  Throw an
00199    exception if the type name cannot be found.  The result is
00200    xmalloc'd and must be freed by the caller.  */
00201 
00202 extern char *cplus_typename_from_type_info (struct value *value);
00203 
00204 /* Determine if we are currently in a C++ thunk.  If so, get the
00205    address of the routine we are thunking to and continue to there
00206    instead.  */
00207 
00208 CORE_ADDR cplus_skip_trampoline (struct frame_info *frame,
00209                                  CORE_ADDR stop_pc);
00210 
00211 /* Return non-zero if an argument of type TYPE should be passed by
00212    reference instead of value.  */
00213 extern int cp_pass_by_reference (struct type *type);
00214 
00215 struct cp_abi_ops
00216 {
00217   const char *shortname;
00218   const char *longname;
00219   const char *doc;
00220 
00221   /* ABI-specific implementations for the functions declared
00222      above.  */
00223   enum ctor_kinds (*is_constructor_name) (const char *name);
00224   enum dtor_kinds (*is_destructor_name) (const char *name);
00225   int (*is_vtable_name) (const char *name);
00226   int (*is_operator_name) (const char *name);
00227   struct value *(*virtual_fn_field) (struct value **arg1p,
00228                                      struct fn_field * f,
00229                                      int j, struct type * type,
00230                                      int offset);
00231   struct type *(*rtti_type) (struct value *v, int *full,
00232                              int *top, int *using_enc);
00233   int (*baseclass_offset) (struct type *type, int index,
00234                            const bfd_byte *valaddr, int embedded_offset,
00235                            CORE_ADDR address, const struct value *val);
00236   void (*print_method_ptr) (const gdb_byte *contents,
00237                             struct type *type,
00238                             struct ui_file *stream);
00239   int (*method_ptr_size) (struct type *);
00240   void (*make_method_ptr) (struct type *, gdb_byte *,
00241                            CORE_ADDR, int);
00242   struct value * (*method_ptr_to_value) (struct value **,
00243                                          struct value *);
00244   void (*print_vtable) (struct value *);
00245   struct value *(*get_typeid) (struct value *value);
00246   struct type *(*get_typeid_type) (struct gdbarch *gdbarch);
00247   struct type *(*get_type_from_type_info) (struct value *value);
00248   char *(*get_typename_from_type_info) (struct value *value);
00249   CORE_ADDR (*skip_trampoline) (struct frame_info *, CORE_ADDR);
00250   int (*pass_by_reference) (struct type *type);
00251 };
00252 
00253 
00254 extern int register_cp_abi (struct cp_abi_ops *abi);
00255 extern void set_cp_abi_as_auto_default (const char *short_name);
00256 
00257 #endif
00258 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines