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