1 /* GDB variable objects API.
2 Copyright (C) 1999-2017 Free Software Foundation, Inc.
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.
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.
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/>. */
24 /* Enumeration for the format types */
25 enum varobj_display_formats
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 */
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. */
42 /* Enumerator describing if a variable object is in scope. */
43 enum varobj_scope_status
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
49 VAROBJ_INVALID = 2, /* Varobj no longer has any value, and never
53 /* String representations of gdb's format codes (defined in varobj.c). */
54 extern char *varobj_format_string[];
56 /* Struct that describes a variable object instance. */
60 typedef struct varobj *varobj_p;
63 typedef struct varobj_update_result_t
65 struct varobj *varobj;
69 enum varobj_scope_status status;
70 /* This variable is used internally by varobj_update to indicate if the
71 new value of varobj is already computed and installed, or has to
72 be yet installed. Don't use this outside varobj.c. */
75 /* This will be non-NULL when new children were added to the varobj.
76 It lists the new children (which must necessarily come at the end
77 of the child list) added during an update. The caller is
78 responsible for freeing this vector. */
79 VEC (varobj_p) *newobj;
80 } varobj_update_result;
82 DEF_VEC_O (varobj_update_result);
85 struct varobj_dynamic;
87 /* Every variable in the system has a structure of this type defined
88 for it. This structure holds all information necessary to manipulate
89 a particular object variable. */
92 /* Name of the variable for this object. If this variable is a
93 child, then this name will be the child's source name.
94 (bar, not foo.bar). */
95 /* NOTE: This is the "expression". */
98 /* Expression for this child. Can be used to create a root variable
99 corresponding to this child. */
100 std::string path_expr;
102 /* The name for this variable's object. This is here for
103 convenience when constructing this object's children. */
104 std::string obj_name;
106 /* Index of this variable in its parent or -1. */
109 /* The type of this variable. This can be NULL
110 for artificial variable objects -- currently, the "accessibility"
111 variable objects in C++. */
114 /* The value of this expression or subexpression. A NULL value
115 indicates there was an error getting this value.
116 Invariant: if varobj_value_is_changeable_p (this) is non-zero,
117 the value is either NULL, or not lazy. */
120 /* The number of (immediate) children this variable has. */
123 /* If this object is a child, this points to its immediate parent. */
124 const struct varobj *parent;
126 /* Children of this object. */
127 VEC (varobj_p) *children;
129 /* Description of the root variable. Points to root variable for
131 struct varobj_root *root;
133 /* The format of the output for this object. */
134 enum varobj_display_formats format;
136 /* Was this variable updated via a varobj_set_value operation. */
139 /* Last print value. */
140 std::string print_value;
142 /* Is this variable frozen. Frozen variables are never implicitly
143 updated by -var-update *
144 or -var-update <direct-or-indirect-parent>. */
147 /* Is the value of this variable intentionally not fetched? It is
148 not fetched if either the variable is frozen, or any parents is
152 /* Sub-range of children which the MI consumer has requested. If
153 FROM < 0 or TO < 0, means that all children have been
158 /* Dynamic part of varobj. */
159 struct varobj_dynamic *dynamic;
162 /* Is the variable X one of our "fake" children? */
163 #define CPLUS_FAKE_CHILD(x) \
164 ((x) != NULL && (x)->type == NULL && (x)->value == NULL)
166 /* The language specific vector */
168 struct lang_varobj_ops
170 /* The number of children of PARENT. */
171 int (*number_of_children) (const struct varobj *parent);
173 /* The name (expression) of a root varobj. */
174 std::string (*name_of_variable) (const struct varobj *parent);
176 /* The name of the INDEX'th child of PARENT. */
177 std::string (*name_of_child) (const struct varobj *parent, int index);
179 /* Returns the rooted expression of CHILD, which is a variable
180 obtain that has some parent. */
181 std::string (*path_expr_of_child) (const struct varobj *child);
183 /* The ``struct value *'' of the INDEX'th child of PARENT. */
184 struct value *(*value_of_child) (const struct varobj *parent, int index);
186 /* The type of the INDEX'th child of PARENT. */
187 struct type *(*type_of_child) (const struct varobj *parent, int index);
189 /* The current value of VAR. */
190 std::string (*value_of_variable) (const struct varobj *var,
191 enum varobj_display_formats format);
193 /* Return non-zero if changes in value of VAR must be detected and
194 reported by -var-update. Return zero if -var-update should never
195 report changes of such values. This makes sense for structures
196 (since the changes in children values will be reported separately),
197 or for artificial objects (like 'public' pseudo-field in C++).
199 Return value of 0 means that gdb need not call value_fetch_lazy
200 for the value of this variable object. */
201 int (*value_is_changeable_p) (const struct varobj *var);
203 /* Return nonzero if the type of VAR has mutated.
205 VAR's value is still the varobj's previous value, while NEW_VALUE
206 is VAR's new value and NEW_TYPE is the var's new type. NEW_VALUE
207 may be NULL indicating that there is no value available (the varobj
208 may be out of scope, of may be the child of a null pointer, for
209 instance). NEW_TYPE, on the other hand, must never be NULL.
211 This function should also be able to assume that var's number of
212 children is set (not < 0).
214 Languages where types do not mutate can set this to NULL. */
215 int (*value_has_mutated) (const struct varobj *var, struct value *new_value,
216 struct type *new_type);
218 /* Return nonzero if VAR is a suitable path expression parent.
220 For C like languages with anonymous structures and unions an anonymous
221 structure or union is not a suitable parent. */
222 int (*is_path_expr_parent) (const struct varobj *var);
225 extern const struct lang_varobj_ops c_varobj_ops;
226 extern const struct lang_varobj_ops cplus_varobj_ops;
227 extern const struct lang_varobj_ops ada_varobj_ops;
229 #define default_varobj_ops c_varobj_ops
232 extern struct varobj *varobj_create (const char *objname,
233 const char *expression, CORE_ADDR frame,
234 enum varobj_type type);
236 extern char *varobj_gen_name (void);
238 extern struct varobj *varobj_get_handle (const char *name);
240 extern const char *varobj_get_objname (const struct varobj *var);
242 extern std::string varobj_get_expression (const struct varobj *var);
244 /* Delete a varobj and all its children if only_children == 0, otherwise delete
245 only the children. Return the number of deleted variables. */
247 extern int varobj_delete (struct varobj *var, int only_children);
249 extern enum varobj_display_formats varobj_set_display_format (
251 enum varobj_display_formats format);
253 extern enum varobj_display_formats varobj_get_display_format (
254 const struct varobj *var);
256 extern int varobj_get_thread_id (const struct varobj *var);
258 extern void varobj_set_frozen (struct varobj *var, int frozen);
260 extern int varobj_get_frozen (const struct varobj *var);
262 extern void varobj_get_child_range (const struct varobj *var, int *from,
265 extern void varobj_set_child_range (struct varobj *var, int from, int to);
267 extern gdb::unique_xmalloc_ptr<char>
268 varobj_get_display_hint (const struct varobj *var);
270 extern int varobj_get_num_children (struct varobj *var);
272 /* Return the list of children of VAR. The returned vector should not
273 be modified in any way. FROM and TO are in/out parameters
274 indicating the range of children to return. If either *FROM or *TO
275 is less than zero on entry, then all children will be returned. On
276 return, *FROM and *TO will be updated to indicate the real range
277 that was returned. The resulting VEC will contain at least the
278 children from *FROM to just before *TO; it might contain more
279 children, depending on whether any more were available. */
280 extern VEC (varobj_p)* varobj_list_children (struct varobj *var,
283 extern std::string varobj_get_type (struct varobj *var);
285 extern struct type *varobj_get_gdb_type (const struct varobj *var);
287 extern const char *varobj_get_path_expr (const struct varobj *var);
289 extern const struct language_defn *
290 varobj_get_language (const struct varobj *var);
292 extern int varobj_get_attributes (const struct varobj *var);
295 varobj_get_formatted_value (struct varobj *var,
296 enum varobj_display_formats format);
298 extern std::string varobj_get_value (struct varobj *var);
300 extern int varobj_set_value (struct varobj *var, const char *expression);
302 extern void all_root_varobjs (void (*func) (struct varobj *var, void *data),
305 extern VEC(varobj_update_result) *varobj_update (struct varobj **varp,
308 extern void varobj_invalidate (void);
310 extern int varobj_editable_p (const struct varobj *var);
312 extern int varobj_floating_p (const struct varobj *var);
314 extern void varobj_set_visualizer (struct varobj *var,
315 const char *visualizer);
317 extern void varobj_enable_pretty_printing (void);
319 extern int varobj_has_more (const struct varobj *var, int to);
321 extern int varobj_is_dynamic_p (const struct varobj *var);
323 extern int varobj_default_value_is_changeable_p (const struct varobj *var);
324 extern int varobj_value_is_changeable_p (const struct varobj *var);
326 extern struct type *varobj_get_value_type (const struct varobj *var);
328 extern int varobj_is_anonymous_child (const struct varobj *child);
330 extern const struct varobj *
331 varobj_get_path_expr_parent (const struct varobj *var);
334 varobj_value_get_print_value (struct value *value,
335 enum varobj_display_formats format,
336 const struct varobj *var);
338 extern void varobj_formatted_print_options (struct value_print_options *opts,
339 enum varobj_display_formats format);
341 extern void varobj_restrict_range (VEC (varobj_p) *children, int *from,
344 extern int varobj_default_is_path_expr_parent (const struct varobj *var);
346 #endif /* VAROBJ_H */