gdb/cp-abi.h - gdb

Data types defined

Macros defined

Source code

  1. /* Abstraction of various C++ ABI's we support, and the info we need
  2.    to get from them.

  3.    Contributed by Daniel Berlin <dberlin@redhat.com>

  4.    Copyright (C) 2001-2015 Free Software Foundation, Inc.

  5.    This file is part of GDB.

  6.    This program is free software; you can redistribute it and/or modify
  7.    it under the terms of the GNU General Public License as published by
  8.    the Free Software Foundation; either version 3 of the License, or
  9.    (at your option) any later version.

  10.    This program is distributed in the hope that it will be useful,
  11.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.    GNU General Public License for more details.

  14.    You should have received a copy of the GNU General Public License
  15.    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

  16. #ifndef CP_ABI_H_
  17. #define CP_ABI_H_ 1

  18. struct fn_field;
  19. struct type;
  20. struct value;
  21. struct ui_file;
  22. struct frame_info;

  23. /* The functions here that attempt to determine what sort of thing a
  24.    mangled name refers to may well be revised in the future.  It would
  25.    certainly be cleaner to carry this information explicitly in GDB's
  26.    data structures than to derive it from the mangled name.  */


  27. /* Kinds of constructors.  All these values are guaranteed to be
  28.    non-zero.  */
  29. enum ctor_kinds {

  30.   /* Initialize a complete object, including virtual bases, using
  31.      memory provided by caller.  */
  32.   complete_object_ctor = 1,

  33.   /* Initialize a base object of some larger object.  */
  34.   base_object_ctor,

  35.   /* An allocating complete-object constructor.  */
  36.   complete_object_allocating_ctor
  37. };

  38. /* Return non-zero iff NAME is the mangled name of a constructor.
  39.    Actually, return an `enum ctor_kind' value describing what *kind*
  40.    of constructor it is.  */
  41. extern enum ctor_kinds is_constructor_name (const char *name);


  42. /* Kinds of destructors.  All these values are guaranteed to be
  43.    non-zero.  */
  44. enum dtor_kinds {

  45.   /* A destructor which finalizes the entire object, and then calls
  46.      `delete' on its storage.  */
  47.   deleting_dtor = 1,

  48.   /* A destructor which finalizes the entire object, but does not call
  49.      `delete'.  */
  50.   complete_object_dtor,

  51.   /* A destructor which finalizes a subobject of some larger
  52.      object.  */
  53.   base_object_dtor
  54. };

  55. /* Return non-zero iff NAME is the mangled name of a destructor.
  56.    Actually, return an `enum dtor_kind' value describing what *kind*
  57.    of destructor it is.  */
  58. extern enum dtor_kinds is_destructor_name (const char *name);


  59. /* Return non-zero iff NAME is the mangled name of a vtable.  */
  60. extern int is_vtable_name (const char *name);


  61. /* Return non-zero iff NAME is the un-mangled name of an operator,
  62.    perhaps scoped within some class.  */
  63. extern int is_operator_name (const char *name);


  64. /* Return an object's virtual function as a value.

  65.    VALUEP is a pointer to a pointer to a value, holding the object
  66.    whose virtual function we want to invoke.  If the ABI requires a
  67.    virtual function's caller to adjust the `this' pointer by an amount
  68.    retrieved from the vtable before invoking the function (i.e., we're
  69.    not using "vtable thunks" to do the adjustment automatically), then
  70.    this function may set *VALUEP to point to a new object with an
  71.    appropriately tweaked address.

  72.    The J'th element of the overload set F is the virtual function of
  73.    *VALUEP we want to invoke.

  74.    TYPE is the base type of *VALUEP whose method we're invoking ---
  75.    this is the type containing F.  OFFSET is the offset of that base
  76.    type within *VALUEP.  */
  77. extern struct value *value_virtual_fn_field (struct value **valuep,
  78.                                              struct fn_field *f,
  79.                                              int j,
  80.                                              struct type *type,
  81.                                              int offset);


  82. /* Try to find the run-time type of VALUE, using C++ run-time type
  83.    information.  Return the run-time type, or zero if we can't figure
  84.    it out.

  85.    If we do find the run-time type:
  86.    - Set *FULL to non-zero if VALUE already contains the complete
  87.      run-time object, not just some embedded base class of the object.
  88.    - Set *TOP and *USING_ENC to indicate where the enclosing object
  89.      starts relative to VALUE:
  90.      - If *USING_ENC is zero, then *TOP is the offset from the start
  91.        of the complete object to the start of the embedded subobject
  92.        VALUE represents.  In other words, the enclosing object starts
  93.        at VALUE_ADDR (VALUE) + VALUE_OFFSET (VALUE) +
  94.        value_embedded_offset (VALUE) + *TOP
  95.      - If *USING_ENC is non-zero, then *TOP is the offset from the
  96.        address of the complete object to the enclosing object stored
  97.        in VALUE.  In other words, the enclosing object starts at
  98.        VALUE_ADDR (VALUE) + VALUE_OFFSET (VALUE) + *TOP.
  99.      If VALUE's type and enclosing type are the same, then these two
  100.      cases are equivalent.

  101.    FULL, TOP, and USING_ENC can each be zero, in which case we don't
  102.    provide the corresponding piece of information.  */
  103. extern struct type *value_rtti_type (struct value *value,
  104.                                      int *full, int *top,
  105.                                      int *using_enc);

  106. /* Compute the offset of the baseclass which is the INDEXth baseclass
  107.    of class TYPE, for value at VALADDR (in host) at ADDRESS (in
  108.    target), offset by EMBEDDED_OFFSET.  VALADDR points to the raw
  109.    contents of VAL.  The result is the offset of the baseclass value
  110.    relative to (the address of)(ARG) + OFFSET.  */

  111. extern int baseclass_offset (struct type *type,
  112.                              int index, const gdb_byte *valaddr,
  113.                              int embedded_offset,
  114.                              CORE_ADDR address,
  115.                              const struct value *val);

  116. /* Describe the target of a pointer to method.  CONTENTS is the byte
  117.    pattern representing the pointer to methodTYPE is the pointer to
  118.    method type.  STREAM is the stream to print it to.  */
  119. void cplus_print_method_ptr (const gdb_byte *contents,
  120.                              struct type *type,
  121.                              struct ui_file *stream);

  122. /* Return the size of a pointer to member function of type
  123.    TO_TYPE.  */
  124. int cplus_method_ptr_size (struct type *to_type);

  125. /* Return the method which should be called by applying METHOD_PTR to
  126.    *THIS_P, and adjust *THIS_P if necessary.  */
  127. struct value *cplus_method_ptr_to_value (struct value **this_p,
  128.                                          struct value *method_ptr);

  129. /* Create the byte pattern in CONTENTS representing a pointer of type
  130.    TYPE to member function at ADDRESS (if IS_VIRTUAL is 0) or with
  131.    virtual table offset ADDRESS (if IS_VIRTUAL is 1).  This is the
  132.    opposite of cplus_method_ptr_to_value.  */
  133. void cplus_make_method_ptr (struct type *type, gdb_byte *CONTENTS,
  134.                             CORE_ADDR address, int is_virtual);

  135. /* Print the vtable for VALUE, if there is one.  If there is no
  136.    vtable, print a message, but do not throw.  */

  137. void cplus_print_vtable (struct value *value);

  138. /* Implement 'typeid': find the type info for VALUE, if possible.  If
  139.    the type info cannot be found, throw an exception.  */

  140. extern struct value *cplus_typeid (struct value *value);

  141. /* Return the type of 'typeid' for the current C++ ABI on the given
  142.    architecture.  */

  143. extern struct type *cplus_typeid_type (struct gdbarch *gdbarch);

  144. /* Given a value which holds a pointer to a std::type_info, return the
  145.    type which that type_info represents.  Throw an exception if the
  146.    type cannot be found.  */

  147. extern struct type *cplus_type_from_type_info (struct value *value);

  148. /* Given a value which holds a pointer to a std::type_info, return the
  149.    name of the type which that type_info represents.  Throw an
  150.    exception if the type name cannot be found.  The result is
  151.    xmalloc'd and must be freed by the caller.  */

  152. extern char *cplus_typename_from_type_info (struct value *value);

  153. /* Determine if we are currently in a C++ thunk.  If so, get the
  154.    address of the routine we are thunking to and continue to there
  155.    instead.  */

  156. CORE_ADDR cplus_skip_trampoline (struct frame_info *frame,
  157.                                  CORE_ADDR stop_pc);

  158. /* Return non-zero if an argument of type TYPE should be passed by
  159.    reference instead of value.  */
  160. extern int cp_pass_by_reference (struct type *type);

  161. struct cp_abi_ops
  162. {
  163.   const char *shortname;
  164.   const char *longname;
  165.   const char *doc;

  166.   /* ABI-specific implementations for the functions declared
  167.      above.  */
  168.   enum ctor_kinds (*is_constructor_name) (const char *name);
  169.   enum dtor_kinds (*is_destructor_name) (const char *name);
  170.   int (*is_vtable_name) (const char *name);
  171.   int (*is_operator_name) (const char *name);
  172.   struct value *(*virtual_fn_field) (struct value **arg1p,
  173.                                      struct fn_field * f,
  174.                                      int j, struct type * type,
  175.                                      int offset);
  176.   struct type *(*rtti_type) (struct value *v, int *full,
  177.                              int *top, int *using_enc);
  178.   int (*baseclass_offset) (struct type *type, int index,
  179.                            const bfd_byte *valaddr, int embedded_offset,
  180.                            CORE_ADDR address, const struct value *val);
  181.   void (*print_method_ptr) (const gdb_byte *contents,
  182.                             struct type *type,
  183.                             struct ui_file *stream);
  184.   int (*method_ptr_size) (struct type *);
  185.   void (*make_method_ptr) (struct type *, gdb_byte *,
  186.                            CORE_ADDR, int);
  187.   struct value * (*method_ptr_to_value) (struct value **,
  188.                                          struct value *);
  189.   void (*print_vtable) (struct value *);
  190.   struct value *(*get_typeid) (struct value *value);
  191.   struct type *(*get_typeid_type) (struct gdbarch *gdbarch);
  192.   struct type *(*get_type_from_type_info) (struct value *value);
  193.   char *(*get_typename_from_type_info) (struct value *value);
  194.   CORE_ADDR (*skip_trampoline) (struct frame_info *, CORE_ADDR);
  195.   int (*pass_by_reference) (struct type *type);
  196. };


  197. extern int register_cp_abi (struct cp_abi_ops *abi);
  198. extern void set_cp_abi_as_auto_default (const char *short_name);

  199. #endif