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