Replace VEC (varobj_update_result) with std::vector
[external/binutils.git] / gdb / varobj.h
1 /* GDB variable objects API.
2    Copyright (C) 1999-2017 Free Software Foundation, Inc.
3
4    This program is free software; you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation; either version 3 of the License, or
7    (at your option) any later version.
8
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
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
17 #ifndef VAROBJ_H
18 #define VAROBJ_H 1
19
20 #include "symtab.h"
21 #include "gdbtypes.h"
22 #include "vec.h"
23
24 /* Enumeration for the format types */
25 enum varobj_display_formats
26   {
27     FORMAT_NATURAL,             /* What gdb actually calls 'natural' */
28     FORMAT_BINARY,              /* Binary display                    */
29     FORMAT_DECIMAL,             /* Decimal display                   */
30     FORMAT_HEXADECIMAL,         /* Hex display                       */
31     FORMAT_OCTAL,               /* Octal display                     */
32     FORMAT_ZHEXADECIMAL         /* Zero padded hexadecimal           */
33   };
34
35 enum varobj_type
36   {
37     USE_SPECIFIED_FRAME,        /* Use the frame passed to varobj_create.  */
38     USE_CURRENT_FRAME,          /* Use the current frame.  */
39     USE_SELECTED_FRAME          /* Always reevaluate in selected frame.  */
40   };
41
42 /* Enumerator describing if a variable object is in scope.  */
43 enum varobj_scope_status
44   {
45     VAROBJ_IN_SCOPE = 0,        /* Varobj is scope, value available.  */
46     VAROBJ_NOT_IN_SCOPE = 1,    /* Varobj is not in scope, value not
47                                    available, but varobj can become in
48                                    scope later.  */
49     VAROBJ_INVALID = 2,         /* Varobj no longer has any value, and never
50                                    will.  */
51   };
52
53 /* String representations of gdb's format codes (defined in varobj.c).  */
54 extern const char *varobj_format_string[];
55
56 /* Struct that describes a variable object instance.  */
57
58 struct varobj;
59
60 typedef struct varobj *varobj_p;
61 DEF_VEC_P (varobj_p);
62
63 struct varobj_update_result
64 {
65   varobj_update_result (struct varobj *varobj_,
66                         varobj_scope_status status_ = VAROBJ_IN_SCOPE)
67   : varobj (varobj_), status (status_)
68   {}
69
70   varobj_update_result (varobj_update_result &&other) = default;
71
72   DISABLE_COPY_AND_ASSIGN (varobj_update_result);
73
74   struct varobj *varobj;
75   int type_changed = 0;
76   int children_changed = 0;
77   int changed = 0;
78   enum varobj_scope_status status;
79   /* This variable is used internally by varobj_update to indicate if the
80      new value of varobj is already computed and installed, or has to
81      be yet installed.  Don't use this outside varobj.c.  */
82   int value_installed = 0;
83
84   /* This will be non-NULL when new children were added to the varobj.
85      It lists the new children (which must necessarily come at the end
86      of the child list) added during an update.  The caller is
87      responsible for freeing this vector.  */
88   std::vector<struct varobj *> newobj;
89 };
90
91 struct varobj_root;
92 struct varobj_dynamic;
93
94 /* Every variable in the system has a structure of this type defined
95    for it.  This structure holds all information necessary to manipulate
96    a particular object variable.  */
97 struct varobj
98 {
99   explicit varobj (varobj_root *root_);
100   ~varobj ();
101
102   /* Name of the variable for this object.  If this variable is a
103      child, then this name will be the child's source name.
104      (bar, not foo.bar).  */
105   /* NOTE: This is the "expression".  */
106   std::string name;
107
108   /* Expression for this child.  Can be used to create a root variable
109      corresponding to this child.  */
110   std::string path_expr;
111
112   /* The name for this variable's object.  This is here for
113      convenience when constructing this object's children.  */
114   std::string obj_name;
115
116   /* Index of this variable in its parent or -1.  */
117   int index = -1;
118
119   /* The type of this variable.  This can be NULL
120      for artificial variable objects -- currently, the "accessibility"
121      variable objects in C++.  */
122   struct type *type = NULL;
123
124   /* The value of this expression or subexpression.  A NULL value
125      indicates there was an error getting this value.
126      Invariant: if varobj_value_is_changeable_p (this) is non-zero, 
127      the value is either NULL, or not lazy.  */
128   struct value *value = NULL;
129
130   /* The number of (immediate) children this variable has.  */
131   int num_children = -1;
132
133   /* If this object is a child, this points to its immediate parent.  */
134   struct varobj *parent = NULL;
135
136   /* Children of this object.  */
137   std::vector<varobj *> children;
138
139   /* Description of the root variable.  Points to root variable for
140      children.  */
141   struct varobj_root *root;
142
143   /* The format of the output for this object.  */
144   enum varobj_display_formats format = FORMAT_NATURAL;
145
146   /* Was this variable updated via a varobj_set_value operation.  */
147   int updated = 0;
148
149   /* Last print value.  */
150   std::string print_value;
151
152   /* Is this variable frozen.  Frozen variables are never implicitly
153      updated by -var-update * 
154      or -var-update <direct-or-indirect-parent>.  */
155   int frozen = 0;
156
157   /* Is the value of this variable intentionally not fetched?  It is
158      not fetched if either the variable is frozen, or any parents is
159      frozen.  */
160   int not_fetched = 0;
161
162   /* Sub-range of children which the MI consumer has requested.  If
163      FROM < 0 or TO < 0, means that all children have been
164      requested.  */
165   int from = -1;
166   int to = -1;
167
168   /* Dynamic part of varobj.  */
169   struct varobj_dynamic *dynamic;
170 };
171
172 /* Is the variable X one of our "fake" children?  */
173 #define CPLUS_FAKE_CHILD(x) \
174 ((x) != NULL && (x)->type == NULL && (x)->value == NULL)
175
176 /* The language specific vector */
177
178 struct lang_varobj_ops
179 {
180   /* The number of children of PARENT.  */
181   int (*number_of_children) (const struct varobj *parent);
182
183   /* The name (expression) of a root varobj.  */
184   std::string (*name_of_variable) (const struct varobj *parent);
185
186   /* The name of the INDEX'th child of PARENT.  */
187   std::string (*name_of_child) (const struct varobj *parent, int index);
188
189   /* Returns the rooted expression of CHILD, which is a variable
190      obtain that has some parent.  */
191   std::string (*path_expr_of_child) (const struct varobj *child);
192
193   /* The ``struct value *'' of the INDEX'th child of PARENT.  */
194   struct value *(*value_of_child) (const struct varobj *parent, int index);
195
196   /* The type of the INDEX'th child of PARENT.  */
197   struct type *(*type_of_child) (const struct varobj *parent, int index);
198
199   /* The current value of VAR.  */
200   std::string (*value_of_variable) (const struct varobj *var,
201                                     enum varobj_display_formats format);
202
203   /* Return non-zero if changes in value of VAR must be detected and
204      reported by -var-update.  Return zero if -var-update should never
205      report changes of such values.  This makes sense for structures
206      (since the changes in children values will be reported separately),
207      or for artificial objects (like 'public' pseudo-field in C++).
208
209      Return value of 0 means that gdb need not call value_fetch_lazy
210      for the value of this variable object.  */
211   int (*value_is_changeable_p) (const struct varobj *var);
212
213   /* Return nonzero if the type of VAR has mutated.
214
215      VAR's value is still the varobj's previous value, while NEW_VALUE
216      is VAR's new value and NEW_TYPE is the var's new type.  NEW_VALUE
217      may be NULL indicating that there is no value available (the varobj
218      may be out of scope, of may be the child of a null pointer, for
219      instance).  NEW_TYPE, on the other hand, must never be NULL.
220
221      This function should also be able to assume that var's number of
222      children is set (not < 0).
223
224      Languages where types do not mutate can set this to NULL.  */
225   int (*value_has_mutated) (const struct varobj *var, struct value *new_value,
226                             struct type *new_type);
227
228   /* Return nonzero if VAR is a suitable path expression parent.
229
230      For C like languages with anonymous structures and unions an anonymous
231      structure or union is not a suitable parent.  */
232   int (*is_path_expr_parent) (const struct varobj *var);
233 };
234
235 extern const struct lang_varobj_ops c_varobj_ops;
236 extern const struct lang_varobj_ops cplus_varobj_ops;
237 extern const struct lang_varobj_ops ada_varobj_ops;
238
239 #define default_varobj_ops c_varobj_ops
240 /* API functions */
241
242 extern struct varobj *varobj_create (const char *objname,
243                                      const char *expression, CORE_ADDR frame,
244                                      enum varobj_type type);
245
246 extern std::string varobj_gen_name (void);
247
248 extern struct varobj *varobj_get_handle (const char *name);
249
250 extern const char *varobj_get_objname (const struct varobj *var);
251
252 extern std::string varobj_get_expression (const struct varobj *var);
253
254 /* Delete a varobj and all its children if only_children == 0, otherwise delete
255    only the children.  Return the number of deleted variables.  */
256
257 extern int varobj_delete (struct varobj *var, int only_children);
258
259 extern enum varobj_display_formats varobj_set_display_format (
260                                                          struct varobj *var,
261                                         enum varobj_display_formats format);
262
263 extern enum varobj_display_formats varobj_get_display_format (
264                                                 const struct varobj *var);
265
266 extern int varobj_get_thread_id (const struct varobj *var);
267
268 extern void varobj_set_frozen (struct varobj *var, int frozen);
269
270 extern int varobj_get_frozen (const struct varobj *var);
271
272 extern void varobj_get_child_range (const struct varobj *var, int *from,
273                                     int *to);
274
275 extern void varobj_set_child_range (struct varobj *var, int from, int to);
276
277 extern gdb::unique_xmalloc_ptr<char>
278      varobj_get_display_hint (const struct varobj *var);
279
280 extern int varobj_get_num_children (struct varobj *var);
281
282 /* Return the list of children of VAR.  The returned vector should not
283    be modified in any way.  FROM and TO are in/out parameters
284    indicating the range of children to return.  If either *FROM or *TO
285    is less than zero on entry, then all children will be returned.  On
286    return, *FROM and *TO will be updated to indicate the real range
287    that was returned.  The resulting VEC will contain at least the
288    children from *FROM to just before *TO; it might contain more
289    children, depending on whether any more were available.  */
290 extern const std::vector<varobj *> &
291   varobj_list_children (struct varobj *var, int *from, int *to);
292
293 extern std::string varobj_get_type (struct varobj *var);
294
295 extern struct type *varobj_get_gdb_type (const struct varobj *var);
296
297 extern const char *varobj_get_path_expr (const struct varobj *var);
298
299 extern const struct language_defn *
300   varobj_get_language (const struct varobj *var);
301
302 extern int varobj_get_attributes (const struct varobj *var);
303
304 extern std::string
305   varobj_get_formatted_value (struct varobj *var,
306                               enum varobj_display_formats format);
307
308 extern std::string varobj_get_value (struct varobj *var);
309
310 extern int varobj_set_value (struct varobj *var, const char *expression);
311
312 extern void all_root_varobjs (void (*func) (struct varobj *var, void *data),
313                               void *data);
314
315 extern std::vector<varobj_update_result>
316   varobj_update (struct varobj **varp, int is_explicit);
317
318 extern void varobj_invalidate (void);
319
320 extern int varobj_editable_p (const struct varobj *var);
321
322 extern int varobj_floating_p (const struct varobj *var);
323
324 extern void varobj_set_visualizer (struct varobj *var,
325                                    const char *visualizer);
326
327 extern void varobj_enable_pretty_printing (void);
328
329 extern int varobj_has_more (const struct varobj *var, int to);
330
331 extern int varobj_is_dynamic_p (const struct varobj *var);
332
333 extern int varobj_default_value_is_changeable_p (const struct varobj *var);
334 extern int varobj_value_is_changeable_p (const struct varobj *var);
335
336 extern struct type *varobj_get_value_type (const struct varobj *var);
337
338 extern int varobj_is_anonymous_child (const struct varobj *child);
339
340 extern const struct varobj *
341   varobj_get_path_expr_parent (const struct varobj *var);
342
343 extern std::string
344   varobj_value_get_print_value (struct value *value,
345                                 enum varobj_display_formats format,
346                                 const struct varobj *var);
347
348 extern void varobj_formatted_print_options (struct value_print_options *opts,
349                                             enum varobj_display_formats format);
350
351 extern void varobj_restrict_range (const std::vector<varobj *> &children,
352                                    int *from, int *to);
353
354 extern int varobj_default_is_path_expr_parent (const struct varobj *var);
355
356 #endif /* VAROBJ_H */