target-descriptions.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. /* Target description support for GDB.
  2. Copyright (C) 2006-2022 Free Software Foundation, Inc.
  3. Contributed by CodeSourcery.
  4. This file is part of GDB.
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  15. #ifndef TARGET_DESCRIPTIONS_H
  16. #define TARGET_DESCRIPTIONS_H 1
  17. #include "gdbsupport/tdesc.h"
  18. #include "gdbarch.h"
  19. struct tdesc_arch_data;
  20. struct target_ops;
  21. /* An inferior's target description info is stored in this opaque
  22. object. There's one such object per inferior. */
  23. struct target_desc_info;
  24. struct inferior;
  25. /* Fetch the current inferior's description, and switch its current
  26. architecture to one which incorporates that description. */
  27. void target_find_description (void);
  28. /* Discard any description fetched from the target for the current
  29. inferior, and switch the current architecture to one with no target
  30. description. */
  31. void target_clear_description (void);
  32. /* Return the current inferior's target description. This should only
  33. be used by gdbarch initialization code; most access should be
  34. through an existing gdbarch. */
  35. const struct target_desc *target_current_description (void);
  36. /* Copy inferior target description data. Used for example when
  37. handling (v)forks, where child's description is the same as the
  38. parent's, since the child really is a copy of the parent. */
  39. void copy_inferior_target_desc_info (struct inferior *destinf,
  40. struct inferior *srcinf);
  41. /* Free a target_desc_info object. */
  42. void target_desc_info_free (struct target_desc_info *tdesc_info);
  43. /* Returns true if INFO indicates the target description had been
  44. supplied by the user. */
  45. int target_desc_info_from_user_p (struct target_desc_info *info);
  46. /* Record architecture-specific functions to call for pseudo-register
  47. support. If tdesc_use_registers is called and gdbarch_num_pseudo_regs
  48. is greater than zero, then these should be called as well.
  49. They are equivalent to the gdbarch methods with similar names,
  50. except that they will only be called for pseudo registers. */
  51. void set_tdesc_pseudo_register_name
  52. (struct gdbarch *gdbarch, gdbarch_register_name_ftype *pseudo_name);
  53. void set_tdesc_pseudo_register_type
  54. (struct gdbarch *gdbarch, gdbarch_register_type_ftype *pseudo_type);
  55. void set_tdesc_pseudo_register_reggroup_p
  56. (struct gdbarch *gdbarch,
  57. gdbarch_register_reggroup_p_ftype *pseudo_reggroup_p);
  58. /* Pointer to a function that should be called for each unknown register in
  59. a target description, used by TDESC_USE_REGISTERS.
  60. GDBARCH is the architecture the target description is for, FEATURE is
  61. the feature the unknown register is in, and REG_NAME is the name of the
  62. register from the target description. The POSSIBLE_REGNUM is a proposed
  63. (GDB internal) number for this register.
  64. The callback function can return, (-1) to indicate that the register
  65. should not be assigned POSSIBLE_REGNUM now (though it might be later),
  66. GDB will number the register automatically later on. Return
  67. POSSIBLE_REGNUM (or greater) to have this register assigned that number.
  68. Returning a value less that POSSIBLE_REGNUM is also acceptable, but take
  69. care not to clash with a register number that has already been
  70. assigned.
  71. The callback will always be called on the registers in the order they
  72. appear in the target description. This means all unknown registers
  73. within a single feature will be called one after another. */
  74. typedef int (*tdesc_unknown_register_ftype)
  75. (struct gdbarch *gdbarch, tdesc_feature *feature,
  76. const char *reg_name, int possible_regnum);
  77. /* A deleter adapter for a target arch data. */
  78. struct tdesc_arch_data_deleter
  79. {
  80. void operator() (struct tdesc_arch_data *data) const;
  81. };
  82. /* A unique pointer specialization that holds a target_desc. */
  83. typedef std::unique_ptr<tdesc_arch_data, tdesc_arch_data_deleter>
  84. tdesc_arch_data_up;
  85. /* Update GDBARCH to use the TARGET_DESC for registers. TARGET_DESC
  86. may be GDBARCH's target description or (if GDBARCH does not have
  87. one which describes registers) another target description
  88. constructed by the gdbarch initialization routine.
  89. Fixed register assignments are taken from EARLY_DATA, which is freed.
  90. All registers which have not been assigned fixed numbers are given
  91. numbers above the current value of gdbarch_num_regs.
  92. gdbarch_num_regs and various register-related predicates are updated to
  93. refer to the target description. This function should only be called from
  94. the architecture's gdbarch initialization routine, and only after
  95. successfully validating the required registers. */
  96. void tdesc_use_registers (struct gdbarch *gdbarch,
  97. const struct target_desc *target_desc,
  98. tdesc_arch_data_up &&early_data,
  99. tdesc_unknown_register_ftype unk_reg_cb = NULL);
  100. /* Allocate initial data for validation of a target description during
  101. gdbarch initialization. */
  102. tdesc_arch_data_up tdesc_data_alloc ();
  103. /* Search FEATURE for a register named NAME. Record REGNO and the
  104. register in DATA; when tdesc_use_registers is called, REGNO will be
  105. assigned to the register. 1 is returned if the register was found,
  106. 0 if it was not. */
  107. int tdesc_numbered_register (const struct tdesc_feature *feature,
  108. struct tdesc_arch_data *data,
  109. int regno, const char *name);
  110. /* Search FEATURE for a register named NAME, but do not assign a fixed
  111. register number to it. */
  112. int tdesc_unnumbered_register (const struct tdesc_feature *feature,
  113. const char *name);
  114. /* Search FEATURE for a register named NAME, and return its size in
  115. bits. The register must exist. */
  116. int tdesc_register_bitsize (const struct tdesc_feature *feature,
  117. const char *name);
  118. /* Search FEATURE for a register with any of the names from NAMES
  119. (NULL-terminated). Record REGNO and the register in DATA; when
  120. tdesc_use_registers is called, REGNO will be assigned to the
  121. register. 1 is returned if the register was found, 0 if it was
  122. not. */
  123. int tdesc_numbered_register_choices (const struct tdesc_feature *feature,
  124. struct tdesc_arch_data *data,
  125. int regno, const char *const names[]);
  126. /* Accessors for target descriptions. */
  127. /* Return the BFD architecture associated with this target
  128. description, or NULL if no architecture was specified. */
  129. const struct bfd_arch_info *tdesc_architecture
  130. (const struct target_desc *);
  131. /* Return the OSABI associated with this target description, or
  132. GDB_OSABI_UNKNOWN if no osabi was specified. */
  133. enum gdb_osabi tdesc_osabi (const struct target_desc *);
  134. /* Return non-zero if this target description is compatible
  135. with the given BFD architecture. */
  136. int tdesc_compatible_p (const struct target_desc *,
  137. const struct bfd_arch_info *);
  138. /* Return the string value of a property named KEY, or NULL if the
  139. property was not specified. */
  140. const char *tdesc_property (const struct target_desc *,
  141. const char *key);
  142. /* Return 1 if this target description describes any registers. */
  143. int tdesc_has_registers (const struct target_desc *);
  144. /* Return the feature with the given name, if present, or NULL if
  145. the named feature is not found. */
  146. const struct tdesc_feature *tdesc_find_feature (const struct target_desc *,
  147. const char *name);
  148. /* Return the name of FEATURE. */
  149. const char *tdesc_feature_name (const struct tdesc_feature *feature);
  150. /* Return the name of register REGNO, from the target description or
  151. from an architecture-provided pseudo_register_name method. */
  152. const char *tdesc_register_name (struct gdbarch *gdbarch, int regno);
  153. /* Return the type of register REGNO, from the target description or
  154. from an architecture-provided pseudo_register_type method. */
  155. struct type *tdesc_register_type (struct gdbarch *gdbarch, int regno);
  156. /* Return the type associated with ID, from the target description. */
  157. struct type *tdesc_find_type (struct gdbarch *gdbarch, const char *id);
  158. /* Check whether REGNUM is a member of REGGROUP using the target
  159. description. Return -1 if the target description does not
  160. specify a group. */
  161. int tdesc_register_in_reggroup_p (struct gdbarch *gdbarch, int regno,
  162. const struct reggroup *reggroup);
  163. /* Methods for constructing a target description. */
  164. void set_tdesc_architecture (struct target_desc *,
  165. const struct bfd_arch_info *);
  166. void set_tdesc_osabi (struct target_desc *, enum gdb_osabi osabi);
  167. void set_tdesc_property (struct target_desc *,
  168. const char *key, const char *value);
  169. void tdesc_add_compatible (struct target_desc *,
  170. const struct bfd_arch_info *);
  171. #if GDB_SELF_TEST
  172. namespace selftests {
  173. /* Record that XML_FILE should generate a target description that equals
  174. TDESC, to be verified by the "maintenance check xml-descriptions"
  175. command. This function takes ownership of TDESC. */
  176. void record_xml_tdesc (const char *xml_file,
  177. const struct target_desc *tdesc);
  178. }
  179. #endif
  180. #endif /* TARGET_DESCRIPTIONS_H */