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