Commit | Line | Data |
---|---|---|
8b93c638 | 1 | /* Implementation of the GDB variable objects API. |
bc8332bb | 2 | |
9b254dd1 | 3 | Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 |
1ecb4ee0 | 4 | Free Software Foundation, Inc. |
8b93c638 JM |
5 | |
6 | This program is free software; you can redistribute it and/or modify | |
7 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 8 | the Free Software Foundation; either version 3 of the License, or |
8b93c638 JM |
9 | (at your option) any later version. |
10 | ||
11 | This program is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
a9762ec7 | 17 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
8b93c638 JM |
18 | |
19 | #include "defs.h" | |
a6c442d8 | 20 | #include "exceptions.h" |
8b93c638 JM |
21 | #include "value.h" |
22 | #include "expression.h" | |
23 | #include "frame.h" | |
8b93c638 JM |
24 | #include "language.h" |
25 | #include "wrapper.h" | |
26 | #include "gdbcmd.h" | |
d2353924 | 27 | #include "block.h" |
a6c442d8 MK |
28 | |
29 | #include "gdb_assert.h" | |
b66d6d2e | 30 | #include "gdb_string.h" |
8b93c638 JM |
31 | |
32 | #include "varobj.h" | |
28335dcc | 33 | #include "vec.h" |
6208b47d VP |
34 | #include "gdbthread.h" |
35 | #include "inferior.h" | |
8b93c638 JM |
36 | |
37 | /* Non-zero if we want to see trace of varobj level stuff. */ | |
38 | ||
39 | int varobjdebug = 0; | |
920d2a44 AC |
40 | static void |
41 | show_varobjdebug (struct ui_file *file, int from_tty, | |
42 | struct cmd_list_element *c, const char *value) | |
43 | { | |
44 | fprintf_filtered (file, _("Varobj debugging is %s.\n"), value); | |
45 | } | |
8b93c638 JM |
46 | |
47 | /* String representations of gdb's format codes */ | |
48 | char *varobj_format_string[] = | |
72330bd6 | 49 | { "natural", "binary", "decimal", "hexadecimal", "octal" }; |
8b93c638 JM |
50 | |
51 | /* String representations of gdb's known languages */ | |
72330bd6 | 52 | char *varobj_language_string[] = { "unknown", "C", "C++", "Java" }; |
8b93c638 JM |
53 | |
54 | /* Data structures */ | |
55 | ||
56 | /* Every root variable has one of these structures saved in its | |
57 | varobj. Members which must be free'd are noted. */ | |
58 | struct varobj_root | |
72330bd6 | 59 | { |
8b93c638 | 60 | |
72330bd6 AC |
61 | /* Alloc'd expression for this parent. */ |
62 | struct expression *exp; | |
8b93c638 | 63 | |
72330bd6 AC |
64 | /* Block for which this expression is valid */ |
65 | struct block *valid_block; | |
8b93c638 | 66 | |
44a67aa7 VP |
67 | /* The frame for this expression. This field is set iff valid_block is |
68 | not NULL. */ | |
e64d9b3d | 69 | struct frame_id frame; |
8b93c638 | 70 | |
c5b48eac VP |
71 | /* The thread ID that this varobj_root belong to. This field |
72 | is only valid if valid_block is not NULL. | |
73 | When not 0, indicates which thread 'frame' belongs to. | |
74 | When 0, indicates that the thread list was empty when the varobj_root | |
75 | was created. */ | |
76 | int thread_id; | |
77 | ||
a5defcdc VP |
78 | /* If 1, the -var-update always recomputes the value in the |
79 | current thread and frame. Otherwise, variable object is | |
80 | always updated in the specific scope/thread/frame */ | |
81 | int floating; | |
73a93a32 | 82 | |
8756216b DP |
83 | /* Flag that indicates validity: set to 0 when this varobj_root refers |
84 | to symbols that do not exist anymore. */ | |
85 | int is_valid; | |
86 | ||
72330bd6 AC |
87 | /* Language info for this variable and its children */ |
88 | struct language_specific *lang; | |
8b93c638 | 89 | |
72330bd6 AC |
90 | /* The varobj for this root node. */ |
91 | struct varobj *rootvar; | |
8b93c638 | 92 | |
72330bd6 AC |
93 | /* Next root variable */ |
94 | struct varobj_root *next; | |
95 | }; | |
8b93c638 JM |
96 | |
97 | /* Every variable in the system has a structure of this type defined | |
98 | for it. This structure holds all information necessary to manipulate | |
99 | a particular object variable. Members which must be freed are noted. */ | |
100 | struct varobj | |
72330bd6 | 101 | { |
8b93c638 | 102 | |
72330bd6 AC |
103 | /* Alloc'd name of the variable for this object.. If this variable is a |
104 | child, then this name will be the child's source name. | |
105 | (bar, not foo.bar) */ | |
106 | /* NOTE: This is the "expression" */ | |
107 | char *name; | |
8b93c638 | 108 | |
02142340 VP |
109 | /* Alloc'd expression for this child. Can be used to create a |
110 | root variable corresponding to this child. */ | |
111 | char *path_expr; | |
112 | ||
72330bd6 AC |
113 | /* The alloc'd name for this variable's object. This is here for |
114 | convenience when constructing this object's children. */ | |
115 | char *obj_name; | |
8b93c638 | 116 | |
72330bd6 AC |
117 | /* Index of this variable in its parent or -1 */ |
118 | int index; | |
8b93c638 | 119 | |
202ddcaa VP |
120 | /* The type of this variable. This can be NULL |
121 | for artifial variable objects -- currently, the "accessibility" | |
122 | variable objects in C++. */ | |
72330bd6 | 123 | struct type *type; |
8b93c638 | 124 | |
b20d8971 VP |
125 | /* The value of this expression or subexpression. A NULL value |
126 | indicates there was an error getting this value. | |
b2c2bd75 VP |
127 | Invariant: if varobj_value_is_changeable_p (this) is non-zero, |
128 | the value is either NULL, or not lazy. */ | |
30b28db1 | 129 | struct value *value; |
8b93c638 | 130 | |
72330bd6 AC |
131 | /* The number of (immediate) children this variable has */ |
132 | int num_children; | |
8b93c638 | 133 | |
72330bd6 AC |
134 | /* If this object is a child, this points to its immediate parent. */ |
135 | struct varobj *parent; | |
8b93c638 | 136 | |
28335dcc VP |
137 | /* Children of this object. */ |
138 | VEC (varobj_p) *children; | |
8b93c638 | 139 | |
72330bd6 AC |
140 | /* Description of the root variable. Points to root variable for children. */ |
141 | struct varobj_root *root; | |
8b93c638 | 142 | |
72330bd6 AC |
143 | /* The format of the output for this object */ |
144 | enum varobj_display_formats format; | |
fb9b6b35 JJ |
145 | |
146 | /* Was this variable updated via a varobj_set_value operation */ | |
147 | int updated; | |
85265413 NR |
148 | |
149 | /* Last print value. */ | |
150 | char *print_value; | |
25d5ea92 VP |
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; | |
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; | |
72330bd6 | 161 | }; |
8b93c638 | 162 | |
8b93c638 | 163 | struct cpstack |
72330bd6 AC |
164 | { |
165 | char *name; | |
166 | struct cpstack *next; | |
167 | }; | |
8b93c638 JM |
168 | |
169 | /* A list of varobjs */ | |
170 | ||
171 | struct vlist | |
72330bd6 AC |
172 | { |
173 | struct varobj *var; | |
174 | struct vlist *next; | |
175 | }; | |
8b93c638 JM |
176 | |
177 | /* Private function prototypes */ | |
178 | ||
179 | /* Helper functions for the above subcommands. */ | |
180 | ||
a14ed312 | 181 | static int delete_variable (struct cpstack **, struct varobj *, int); |
8b93c638 | 182 | |
a14ed312 KB |
183 | static void delete_variable_1 (struct cpstack **, int *, |
184 | struct varobj *, int, int); | |
8b93c638 | 185 | |
a14ed312 | 186 | static int install_variable (struct varobj *); |
8b93c638 | 187 | |
a14ed312 | 188 | static void uninstall_variable (struct varobj *); |
8b93c638 | 189 | |
a14ed312 | 190 | static struct varobj *create_child (struct varobj *, int, char *); |
8b93c638 | 191 | |
8b93c638 JM |
192 | /* Utility routines */ |
193 | ||
a14ed312 | 194 | static struct varobj *new_variable (void); |
8b93c638 | 195 | |
a14ed312 | 196 | static struct varobj *new_root_variable (void); |
8b93c638 | 197 | |
a14ed312 | 198 | static void free_variable (struct varobj *var); |
8b93c638 | 199 | |
74b7792f AC |
200 | static struct cleanup *make_cleanup_free_variable (struct varobj *var); |
201 | ||
a14ed312 | 202 | static struct type *get_type (struct varobj *var); |
8b93c638 | 203 | |
6e2a9270 VP |
204 | static struct type *get_value_type (struct varobj *var); |
205 | ||
a14ed312 | 206 | static struct type *get_target_type (struct type *); |
8b93c638 | 207 | |
a14ed312 | 208 | static enum varobj_display_formats variable_default_display (struct varobj *); |
8b93c638 | 209 | |
a14ed312 | 210 | static void cppush (struct cpstack **pstack, char *name); |
8b93c638 | 211 | |
a14ed312 | 212 | static char *cppop (struct cpstack **pstack); |
8b93c638 | 213 | |
acd65feb VP |
214 | static int install_new_value (struct varobj *var, struct value *value, |
215 | int initial); | |
216 | ||
8b93c638 JM |
217 | /* Language-specific routines. */ |
218 | ||
a14ed312 | 219 | static enum varobj_languages variable_language (struct varobj *var); |
8b93c638 | 220 | |
a14ed312 | 221 | static int number_of_children (struct varobj *); |
8b93c638 | 222 | |
a14ed312 | 223 | static char *name_of_variable (struct varobj *); |
8b93c638 | 224 | |
a14ed312 | 225 | static char *name_of_child (struct varobj *, int); |
8b93c638 | 226 | |
30b28db1 | 227 | static struct value *value_of_root (struct varobj **var_handle, int *); |
8b93c638 | 228 | |
30b28db1 | 229 | static struct value *value_of_child (struct varobj *parent, int index); |
8b93c638 | 230 | |
de051565 MK |
231 | static char *my_value_of_variable (struct varobj *var, |
232 | enum varobj_display_formats format); | |
8b93c638 | 233 | |
85265413 NR |
234 | static char *value_get_print_value (struct value *value, |
235 | enum varobj_display_formats format); | |
236 | ||
b2c2bd75 VP |
237 | static int varobj_value_is_changeable_p (struct varobj *var); |
238 | ||
239 | static int is_root_p (struct varobj *var); | |
8b93c638 JM |
240 | |
241 | /* C implementation */ | |
242 | ||
a14ed312 | 243 | static int c_number_of_children (struct varobj *var); |
8b93c638 | 244 | |
a14ed312 | 245 | static char *c_name_of_variable (struct varobj *parent); |
8b93c638 | 246 | |
a14ed312 | 247 | static char *c_name_of_child (struct varobj *parent, int index); |
8b93c638 | 248 | |
02142340 VP |
249 | static char *c_path_expr_of_child (struct varobj *child); |
250 | ||
30b28db1 | 251 | static struct value *c_value_of_root (struct varobj **var_handle); |
8b93c638 | 252 | |
30b28db1 | 253 | static struct value *c_value_of_child (struct varobj *parent, int index); |
8b93c638 | 254 | |
a14ed312 | 255 | static struct type *c_type_of_child (struct varobj *parent, int index); |
8b93c638 | 256 | |
de051565 MK |
257 | static char *c_value_of_variable (struct varobj *var, |
258 | enum varobj_display_formats format); | |
8b93c638 JM |
259 | |
260 | /* C++ implementation */ | |
261 | ||
a14ed312 | 262 | static int cplus_number_of_children (struct varobj *var); |
8b93c638 | 263 | |
a14ed312 | 264 | static void cplus_class_num_children (struct type *type, int children[3]); |
8b93c638 | 265 | |
a14ed312 | 266 | static char *cplus_name_of_variable (struct varobj *parent); |
8b93c638 | 267 | |
a14ed312 | 268 | static char *cplus_name_of_child (struct varobj *parent, int index); |
8b93c638 | 269 | |
02142340 VP |
270 | static char *cplus_path_expr_of_child (struct varobj *child); |
271 | ||
30b28db1 | 272 | static struct value *cplus_value_of_root (struct varobj **var_handle); |
8b93c638 | 273 | |
30b28db1 | 274 | static struct value *cplus_value_of_child (struct varobj *parent, int index); |
8b93c638 | 275 | |
a14ed312 | 276 | static struct type *cplus_type_of_child (struct varobj *parent, int index); |
8b93c638 | 277 | |
de051565 MK |
278 | static char *cplus_value_of_variable (struct varobj *var, |
279 | enum varobj_display_formats format); | |
8b93c638 JM |
280 | |
281 | /* Java implementation */ | |
282 | ||
a14ed312 | 283 | static int java_number_of_children (struct varobj *var); |
8b93c638 | 284 | |
a14ed312 | 285 | static char *java_name_of_variable (struct varobj *parent); |
8b93c638 | 286 | |
a14ed312 | 287 | static char *java_name_of_child (struct varobj *parent, int index); |
8b93c638 | 288 | |
02142340 VP |
289 | static char *java_path_expr_of_child (struct varobj *child); |
290 | ||
30b28db1 | 291 | static struct value *java_value_of_root (struct varobj **var_handle); |
8b93c638 | 292 | |
30b28db1 | 293 | static struct value *java_value_of_child (struct varobj *parent, int index); |
8b93c638 | 294 | |
a14ed312 | 295 | static struct type *java_type_of_child (struct varobj *parent, int index); |
8b93c638 | 296 | |
de051565 MK |
297 | static char *java_value_of_variable (struct varobj *var, |
298 | enum varobj_display_formats format); | |
8b93c638 JM |
299 | |
300 | /* The language specific vector */ | |
301 | ||
302 | struct language_specific | |
72330bd6 | 303 | { |
8b93c638 | 304 | |
72330bd6 AC |
305 | /* The language of this variable */ |
306 | enum varobj_languages language; | |
8b93c638 | 307 | |
72330bd6 AC |
308 | /* The number of children of PARENT. */ |
309 | int (*number_of_children) (struct varobj * parent); | |
8b93c638 | 310 | |
72330bd6 AC |
311 | /* The name (expression) of a root varobj. */ |
312 | char *(*name_of_variable) (struct varobj * parent); | |
8b93c638 | 313 | |
72330bd6 AC |
314 | /* The name of the INDEX'th child of PARENT. */ |
315 | char *(*name_of_child) (struct varobj * parent, int index); | |
8b93c638 | 316 | |
02142340 VP |
317 | /* Returns the rooted expression of CHILD, which is a variable |
318 | obtain that has some parent. */ | |
319 | char *(*path_expr_of_child) (struct varobj * child); | |
320 | ||
30b28db1 AC |
321 | /* The ``struct value *'' of the root variable ROOT. */ |
322 | struct value *(*value_of_root) (struct varobj ** root_handle); | |
8b93c638 | 323 | |
30b28db1 AC |
324 | /* The ``struct value *'' of the INDEX'th child of PARENT. */ |
325 | struct value *(*value_of_child) (struct varobj * parent, int index); | |
8b93c638 | 326 | |
72330bd6 AC |
327 | /* The type of the INDEX'th child of PARENT. */ |
328 | struct type *(*type_of_child) (struct varobj * parent, int index); | |
8b93c638 | 329 | |
72330bd6 | 330 | /* The current value of VAR. */ |
de051565 MK |
331 | char *(*value_of_variable) (struct varobj * var, |
332 | enum varobj_display_formats format); | |
72330bd6 | 333 | }; |
8b93c638 JM |
334 | |
335 | /* Array of known source language routines. */ | |
d5d6fca5 | 336 | static struct language_specific languages[vlang_end] = { |
8b93c638 JM |
337 | /* Unknown (try treating as C */ |
338 | { | |
72330bd6 AC |
339 | vlang_unknown, |
340 | c_number_of_children, | |
341 | c_name_of_variable, | |
342 | c_name_of_child, | |
02142340 | 343 | c_path_expr_of_child, |
72330bd6 AC |
344 | c_value_of_root, |
345 | c_value_of_child, | |
346 | c_type_of_child, | |
72330bd6 | 347 | c_value_of_variable} |
8b93c638 JM |
348 | , |
349 | /* C */ | |
350 | { | |
72330bd6 AC |
351 | vlang_c, |
352 | c_number_of_children, | |
353 | c_name_of_variable, | |
354 | c_name_of_child, | |
02142340 | 355 | c_path_expr_of_child, |
72330bd6 AC |
356 | c_value_of_root, |
357 | c_value_of_child, | |
358 | c_type_of_child, | |
72330bd6 | 359 | c_value_of_variable} |
8b93c638 JM |
360 | , |
361 | /* C++ */ | |
362 | { | |
72330bd6 AC |
363 | vlang_cplus, |
364 | cplus_number_of_children, | |
365 | cplus_name_of_variable, | |
366 | cplus_name_of_child, | |
02142340 | 367 | cplus_path_expr_of_child, |
72330bd6 AC |
368 | cplus_value_of_root, |
369 | cplus_value_of_child, | |
370 | cplus_type_of_child, | |
72330bd6 | 371 | cplus_value_of_variable} |
8b93c638 JM |
372 | , |
373 | /* Java */ | |
374 | { | |
72330bd6 AC |
375 | vlang_java, |
376 | java_number_of_children, | |
377 | java_name_of_variable, | |
378 | java_name_of_child, | |
02142340 | 379 | java_path_expr_of_child, |
72330bd6 AC |
380 | java_value_of_root, |
381 | java_value_of_child, | |
382 | java_type_of_child, | |
72330bd6 | 383 | java_value_of_variable} |
8b93c638 JM |
384 | }; |
385 | ||
386 | /* A little convenience enum for dealing with C++/Java */ | |
387 | enum vsections | |
72330bd6 AC |
388 | { |
389 | v_public = 0, v_private, v_protected | |
390 | }; | |
8b93c638 JM |
391 | |
392 | /* Private data */ | |
393 | ||
394 | /* Mappings of varobj_display_formats enums to gdb's format codes */ | |
72330bd6 | 395 | static int format_code[] = { 0, 't', 'd', 'x', 'o' }; |
8b93c638 JM |
396 | |
397 | /* Header of the list of root variable objects */ | |
398 | static struct varobj_root *rootlist; | |
399 | static int rootcount = 0; /* number of root varobjs in the list */ | |
400 | ||
401 | /* Prime number indicating the number of buckets in the hash table */ | |
402 | /* A prime large enough to avoid too many colisions */ | |
403 | #define VAROBJ_TABLE_SIZE 227 | |
404 | ||
405 | /* Pointer to the varobj hash table (built at run time) */ | |
406 | static struct vlist **varobj_table; | |
407 | ||
8b93c638 JM |
408 | /* Is the variable X one of our "fake" children? */ |
409 | #define CPLUS_FAKE_CHILD(x) \ | |
410 | ((x) != NULL && (x)->type == NULL && (x)->value == NULL) | |
411 | \f | |
412 | ||
413 | /* API Implementation */ | |
b2c2bd75 VP |
414 | static int |
415 | is_root_p (struct varobj *var) | |
416 | { | |
417 | return (var->root->rootvar == var); | |
418 | } | |
8b93c638 JM |
419 | |
420 | /* Creates a varobj (not its children) */ | |
421 | ||
7d8547c9 AC |
422 | /* Return the full FRAME which corresponds to the given CORE_ADDR |
423 | or NULL if no FRAME on the chain corresponds to CORE_ADDR. */ | |
424 | ||
425 | static struct frame_info * | |
426 | find_frame_addr_in_frame_chain (CORE_ADDR frame_addr) | |
427 | { | |
428 | struct frame_info *frame = NULL; | |
429 | ||
430 | if (frame_addr == (CORE_ADDR) 0) | |
431 | return NULL; | |
432 | ||
433 | while (1) | |
434 | { | |
435 | frame = get_prev_frame (frame); | |
436 | if (frame == NULL) | |
437 | return NULL; | |
eb5492fa | 438 | if (get_frame_base_address (frame) == frame_addr) |
7d8547c9 AC |
439 | return frame; |
440 | } | |
441 | } | |
442 | ||
8b93c638 JM |
443 | struct varobj * |
444 | varobj_create (char *objname, | |
72330bd6 | 445 | char *expression, CORE_ADDR frame, enum varobj_type type) |
8b93c638 JM |
446 | { |
447 | struct varobj *var; | |
2c67cb8b AC |
448 | struct frame_info *fi; |
449 | struct frame_info *old_fi = NULL; | |
8b93c638 JM |
450 | struct block *block; |
451 | struct cleanup *old_chain; | |
452 | ||
453 | /* Fill out a varobj structure for the (root) variable being constructed. */ | |
454 | var = new_root_variable (); | |
74b7792f | 455 | old_chain = make_cleanup_free_variable (var); |
8b93c638 JM |
456 | |
457 | if (expression != NULL) | |
458 | { | |
459 | char *p; | |
460 | enum varobj_languages lang; | |
e55dccf0 | 461 | struct value *value = NULL; |
02142340 | 462 | int expr_len; |
8b93c638 JM |
463 | |
464 | /* Parse and evaluate the expression, filling in as much | |
465 | of the variable's data as possible */ | |
466 | ||
467 | /* Allow creator to specify context of variable */ | |
72330bd6 | 468 | if ((type == USE_CURRENT_FRAME) || (type == USE_SELECTED_FRAME)) |
206415a3 | 469 | fi = deprecated_safe_get_selected_frame (); |
8b93c638 | 470 | else |
7d8547c9 AC |
471 | /* FIXME: cagney/2002-11-23: This code should be doing a |
472 | lookup using the frame ID and not just the frame's | |
473 | ``address''. This, of course, means an interface change. | |
474 | However, with out that interface change ISAs, such as the | |
475 | ia64 with its two stacks, won't work. Similar goes for the | |
476 | case where there is a frameless function. */ | |
8b93c638 JM |
477 | fi = find_frame_addr_in_frame_chain (frame); |
478 | ||
73a93a32 JI |
479 | /* frame = -2 means always use selected frame */ |
480 | if (type == USE_SELECTED_FRAME) | |
a5defcdc | 481 | var->root->floating = 1; |
73a93a32 | 482 | |
8b93c638 JM |
483 | block = NULL; |
484 | if (fi != NULL) | |
ae767bfb | 485 | block = get_frame_block (fi, 0); |
8b93c638 JM |
486 | |
487 | p = expression; | |
488 | innermost_block = NULL; | |
73a93a32 JI |
489 | /* Wrap the call to parse expression, so we can |
490 | return a sensible error. */ | |
491 | if (!gdb_parse_exp_1 (&p, block, 0, &var->root->exp)) | |
492 | { | |
493 | return NULL; | |
494 | } | |
8b93c638 JM |
495 | |
496 | /* Don't allow variables to be created for types. */ | |
497 | if (var->root->exp->elts[0].opcode == OP_TYPE) | |
498 | { | |
499 | do_cleanups (old_chain); | |
bc8332bb AC |
500 | fprintf_unfiltered (gdb_stderr, "Attempt to use a type name" |
501 | " as an expression.\n"); | |
8b93c638 JM |
502 | return NULL; |
503 | } | |
504 | ||
505 | var->format = variable_default_display (var); | |
506 | var->root->valid_block = innermost_block; | |
02142340 VP |
507 | expr_len = strlen (expression); |
508 | var->name = savestring (expression, expr_len); | |
509 | /* For a root var, the name and the expr are the same. */ | |
510 | var->path_expr = savestring (expression, expr_len); | |
8b93c638 JM |
511 | |
512 | /* When the frame is different from the current frame, | |
513 | we must select the appropriate frame before parsing | |
514 | the expression, otherwise the value will not be current. | |
515 | Since select_frame is so benign, just call it for all cases. */ | |
44a67aa7 | 516 | if (innermost_block && fi != NULL) |
8b93c638 | 517 | { |
7a424e99 | 518 | var->root->frame = get_frame_id (fi); |
c5b48eac | 519 | var->root->thread_id = pid_to_thread_id (inferior_ptid); |
206415a3 | 520 | old_fi = get_selected_frame (NULL); |
c5b48eac | 521 | select_frame (fi); |
8b93c638 JM |
522 | } |
523 | ||
340a7723 | 524 | /* We definitely need to catch errors here. |
8b93c638 JM |
525 | If evaluate_expression succeeds we got the value we wanted. |
526 | But if it fails, we still go on with a call to evaluate_type() */ | |
acd65feb | 527 | if (!gdb_evaluate_expression (var->root->exp, &value)) |
e55dccf0 VP |
528 | { |
529 | /* Error getting the value. Try to at least get the | |
530 | right type. */ | |
531 | struct value *type_only_value = evaluate_type (var->root->exp); | |
532 | var->type = value_type (type_only_value); | |
533 | } | |
534 | else | |
535 | var->type = value_type (value); | |
acd65feb | 536 | |
acd65feb | 537 | install_new_value (var, value, 1 /* Initial assignment */); |
8b93c638 JM |
538 | |
539 | /* Set language info */ | |
540 | lang = variable_language (var); | |
d5d6fca5 | 541 | var->root->lang = &languages[lang]; |
8b93c638 JM |
542 | |
543 | /* Set ourselves as our root */ | |
544 | var->root->rootvar = var; | |
545 | ||
546 | /* Reset the selected frame */ | |
547 | if (fi != NULL) | |
0f7d239c | 548 | select_frame (old_fi); |
8b93c638 JM |
549 | } |
550 | ||
73a93a32 JI |
551 | /* If the variable object name is null, that means this |
552 | is a temporary variable, so don't install it. */ | |
553 | ||
554 | if ((var != NULL) && (objname != NULL)) | |
8b93c638 JM |
555 | { |
556 | var->obj_name = savestring (objname, strlen (objname)); | |
557 | ||
558 | /* If a varobj name is duplicated, the install will fail so | |
559 | we must clenup */ | |
560 | if (!install_variable (var)) | |
561 | { | |
562 | do_cleanups (old_chain); | |
563 | return NULL; | |
564 | } | |
565 | } | |
566 | ||
567 | discard_cleanups (old_chain); | |
568 | return var; | |
569 | } | |
570 | ||
571 | /* Generates an unique name that can be used for a varobj */ | |
572 | ||
573 | char * | |
574 | varobj_gen_name (void) | |
575 | { | |
576 | static int id = 0; | |
e64d9b3d | 577 | char *obj_name; |
8b93c638 JM |
578 | |
579 | /* generate a name for this object */ | |
580 | id++; | |
b435e160 | 581 | obj_name = xstrprintf ("var%d", id); |
8b93c638 | 582 | |
e64d9b3d | 583 | return obj_name; |
8b93c638 JM |
584 | } |
585 | ||
586 | /* Given an "objname", returns the pointer to the corresponding varobj | |
587 | or NULL if not found */ | |
588 | ||
589 | struct varobj * | |
590 | varobj_get_handle (char *objname) | |
591 | { | |
592 | struct vlist *cv; | |
593 | const char *chp; | |
594 | unsigned int index = 0; | |
595 | unsigned int i = 1; | |
596 | ||
597 | for (chp = objname; *chp; chp++) | |
598 | { | |
599 | index = (index + (i++ * (unsigned int) *chp)) % VAROBJ_TABLE_SIZE; | |
600 | } | |
601 | ||
602 | cv = *(varobj_table + index); | |
603 | while ((cv != NULL) && (strcmp (cv->var->obj_name, objname) != 0)) | |
604 | cv = cv->next; | |
605 | ||
606 | if (cv == NULL) | |
8a3fe4f8 | 607 | error (_("Variable object not found")); |
8b93c638 JM |
608 | |
609 | return cv->var; | |
610 | } | |
611 | ||
612 | /* Given the handle, return the name of the object */ | |
613 | ||
614 | char * | |
615 | varobj_get_objname (struct varobj *var) | |
616 | { | |
617 | return var->obj_name; | |
618 | } | |
619 | ||
620 | /* Given the handle, return the expression represented by the object */ | |
621 | ||
622 | char * | |
623 | varobj_get_expression (struct varobj *var) | |
624 | { | |
625 | return name_of_variable (var); | |
626 | } | |
627 | ||
628 | /* Deletes a varobj and all its children if only_children == 0, | |
629 | otherwise deletes only the children; returns a malloc'ed list of all the | |
630 | (malloc'ed) names of the variables that have been deleted (NULL terminated) */ | |
631 | ||
632 | int | |
633 | varobj_delete (struct varobj *var, char ***dellist, int only_children) | |
634 | { | |
635 | int delcount; | |
636 | int mycount; | |
637 | struct cpstack *result = NULL; | |
638 | char **cp; | |
639 | ||
640 | /* Initialize a stack for temporary results */ | |
641 | cppush (&result, NULL); | |
642 | ||
643 | if (only_children) | |
644 | /* Delete only the variable children */ | |
645 | delcount = delete_variable (&result, var, 1 /* only the children */ ); | |
646 | else | |
647 | /* Delete the variable and all its children */ | |
648 | delcount = delete_variable (&result, var, 0 /* parent+children */ ); | |
649 | ||
650 | /* We may have been asked to return a list of what has been deleted */ | |
651 | if (dellist != NULL) | |
652 | { | |
653 | *dellist = xmalloc ((delcount + 1) * sizeof (char *)); | |
654 | ||
655 | cp = *dellist; | |
656 | mycount = delcount; | |
657 | *cp = cppop (&result); | |
658 | while ((*cp != NULL) && (mycount > 0)) | |
659 | { | |
660 | mycount--; | |
661 | cp++; | |
662 | *cp = cppop (&result); | |
663 | } | |
664 | ||
665 | if (mycount || (*cp != NULL)) | |
8a3fe4f8 | 666 | warning (_("varobj_delete: assertion failed - mycount(=%d) <> 0"), |
72330bd6 | 667 | mycount); |
8b93c638 JM |
668 | } |
669 | ||
670 | return delcount; | |
671 | } | |
672 | ||
673 | /* Set/Get variable object display format */ | |
674 | ||
675 | enum varobj_display_formats | |
676 | varobj_set_display_format (struct varobj *var, | |
677 | enum varobj_display_formats format) | |
678 | { | |
679 | switch (format) | |
680 | { | |
681 | case FORMAT_NATURAL: | |
682 | case FORMAT_BINARY: | |
683 | case FORMAT_DECIMAL: | |
684 | case FORMAT_HEXADECIMAL: | |
685 | case FORMAT_OCTAL: | |
686 | var->format = format; | |
687 | break; | |
688 | ||
689 | default: | |
690 | var->format = variable_default_display (var); | |
691 | } | |
692 | ||
ae7d22a6 VP |
693 | if (varobj_value_is_changeable_p (var) |
694 | && var->value && !value_lazy (var->value)) | |
695 | { | |
696 | free (var->print_value); | |
697 | var->print_value = value_get_print_value (var->value, var->format); | |
698 | } | |
699 | ||
8b93c638 JM |
700 | return var->format; |
701 | } | |
702 | ||
703 | enum varobj_display_formats | |
704 | varobj_get_display_format (struct varobj *var) | |
705 | { | |
706 | return var->format; | |
707 | } | |
708 | ||
c5b48eac VP |
709 | /* If the variable object is bound to a specific thread, that |
710 | is its evaluation can always be done in context of a frame | |
711 | inside that thread, returns GDB id of the thread -- which | |
712 | is always positive. Otherwise, returns -1. */ | |
713 | int | |
714 | varobj_get_thread_id (struct varobj *var) | |
715 | { | |
716 | if (var->root->valid_block && var->root->thread_id > 0) | |
717 | return var->root->thread_id; | |
718 | else | |
719 | return -1; | |
720 | } | |
721 | ||
25d5ea92 VP |
722 | void |
723 | varobj_set_frozen (struct varobj *var, int frozen) | |
724 | { | |
725 | /* When a variable is unfrozen, we don't fetch its value. | |
726 | The 'not_fetched' flag remains set, so next -var-update | |
727 | won't complain. | |
728 | ||
729 | We don't fetch the value, because for structures the client | |
730 | should do -var-update anyway. It would be bad to have different | |
731 | client-size logic for structure and other types. */ | |
732 | var->frozen = frozen; | |
733 | } | |
734 | ||
735 | int | |
736 | varobj_get_frozen (struct varobj *var) | |
737 | { | |
738 | return var->frozen; | |
739 | } | |
740 | ||
741 | ||
8b93c638 JM |
742 | int |
743 | varobj_get_num_children (struct varobj *var) | |
744 | { | |
745 | if (var->num_children == -1) | |
746 | var->num_children = number_of_children (var); | |
747 | ||
748 | return var->num_children; | |
749 | } | |
750 | ||
751 | /* Creates a list of the immediate children of a variable object; | |
752 | the return code is the number of such children or -1 on error */ | |
753 | ||
d56d46f5 VP |
754 | VEC (varobj_p)* |
755 | varobj_list_children (struct varobj *var) | |
8b93c638 JM |
756 | { |
757 | struct varobj *child; | |
758 | char *name; | |
759 | int i; | |
760 | ||
8b93c638 JM |
761 | if (var->num_children == -1) |
762 | var->num_children = number_of_children (var); | |
763 | ||
74a44383 DJ |
764 | /* If that failed, give up. */ |
765 | if (var->num_children == -1) | |
d56d46f5 | 766 | return var->children; |
74a44383 | 767 | |
28335dcc VP |
768 | /* If we're called when the list of children is not yet initialized, |
769 | allocate enough elements in it. */ | |
770 | while (VEC_length (varobj_p, var->children) < var->num_children) | |
771 | VEC_safe_push (varobj_p, var->children, NULL); | |
772 | ||
8b93c638 JM |
773 | for (i = 0; i < var->num_children; i++) |
774 | { | |
d56d46f5 | 775 | varobj_p existing = VEC_index (varobj_p, var->children, i); |
28335dcc VP |
776 | |
777 | if (existing == NULL) | |
778 | { | |
779 | /* Either it's the first call to varobj_list_children for | |
780 | this variable object, and the child was never created, | |
781 | or it was explicitly deleted by the client. */ | |
782 | name = name_of_child (var, i); | |
783 | existing = create_child (var, i, name); | |
784 | VEC_replace (varobj_p, var->children, i, existing); | |
785 | } | |
8b93c638 JM |
786 | } |
787 | ||
d56d46f5 | 788 | return var->children; |
8b93c638 JM |
789 | } |
790 | ||
791 | /* Obtain the type of an object Variable as a string similar to the one gdb | |
792 | prints on the console */ | |
793 | ||
794 | char * | |
795 | varobj_get_type (struct varobj *var) | |
796 | { | |
30b28db1 | 797 | struct value *val; |
8b93c638 JM |
798 | struct cleanup *old_chain; |
799 | struct ui_file *stb; | |
800 | char *thetype; | |
801 | long length; | |
802 | ||
803 | /* For the "fake" variables, do not return a type. (It's type is | |
8756216b DP |
804 | NULL, too.) |
805 | Do not return a type for invalid variables as well. */ | |
806 | if (CPLUS_FAKE_CHILD (var) || !var->root->is_valid) | |
8b93c638 JM |
807 | return NULL; |
808 | ||
809 | stb = mem_fileopen (); | |
810 | old_chain = make_cleanup_ui_file_delete (stb); | |
811 | ||
30b28db1 | 812 | /* To print the type, we simply create a zero ``struct value *'' and |
8b93c638 JM |
813 | cast it to our type. We then typeprint this variable. */ |
814 | val = value_zero (var->type, not_lval); | |
df407dfe | 815 | type_print (value_type (val), "", stb, -1); |
8b93c638 JM |
816 | |
817 | thetype = ui_file_xstrdup (stb, &length); | |
818 | do_cleanups (old_chain); | |
819 | return thetype; | |
820 | } | |
821 | ||
1ecb4ee0 DJ |
822 | /* Obtain the type of an object variable. */ |
823 | ||
824 | struct type * | |
825 | varobj_get_gdb_type (struct varobj *var) | |
826 | { | |
827 | return var->type; | |
828 | } | |
829 | ||
02142340 VP |
830 | /* Return a pointer to the full rooted expression of varobj VAR. |
831 | If it has not been computed yet, compute it. */ | |
832 | char * | |
833 | varobj_get_path_expr (struct varobj *var) | |
834 | { | |
835 | if (var->path_expr != NULL) | |
836 | return var->path_expr; | |
837 | else | |
838 | { | |
839 | /* For root varobjs, we initialize path_expr | |
840 | when creating varobj, so here it should be | |
841 | child varobj. */ | |
842 | gdb_assert (!is_root_p (var)); | |
843 | return (*var->root->lang->path_expr_of_child) (var); | |
844 | } | |
845 | } | |
846 | ||
8b93c638 JM |
847 | enum varobj_languages |
848 | varobj_get_language (struct varobj *var) | |
849 | { | |
850 | return variable_language (var); | |
851 | } | |
852 | ||
853 | int | |
854 | varobj_get_attributes (struct varobj *var) | |
855 | { | |
856 | int attributes = 0; | |
857 | ||
340a7723 | 858 | if (varobj_editable_p (var)) |
8b93c638 JM |
859 | /* FIXME: define masks for attributes */ |
860 | attributes |= 0x00000001; /* Editable */ | |
861 | ||
862 | return attributes; | |
863 | } | |
864 | ||
de051565 MK |
865 | char * |
866 | varobj_get_formatted_value (struct varobj *var, | |
867 | enum varobj_display_formats format) | |
868 | { | |
869 | return my_value_of_variable (var, format); | |
870 | } | |
871 | ||
8b93c638 JM |
872 | char * |
873 | varobj_get_value (struct varobj *var) | |
874 | { | |
de051565 | 875 | return my_value_of_variable (var, var->format); |
8b93c638 JM |
876 | } |
877 | ||
878 | /* Set the value of an object variable (if it is editable) to the | |
879 | value of the given expression */ | |
880 | /* Note: Invokes functions that can call error() */ | |
881 | ||
882 | int | |
883 | varobj_set_value (struct varobj *var, char *expression) | |
884 | { | |
30b28db1 | 885 | struct value *val; |
8b93c638 | 886 | int offset = 0; |
a6c442d8 | 887 | int error = 0; |
8b93c638 JM |
888 | |
889 | /* The argument "expression" contains the variable's new value. | |
890 | We need to first construct a legal expression for this -- ugh! */ | |
891 | /* Does this cover all the bases? */ | |
892 | struct expression *exp; | |
30b28db1 | 893 | struct value *value; |
8b93c638 | 894 | int saved_input_radix = input_radix; |
340a7723 NR |
895 | char *s = expression; |
896 | int i; | |
8b93c638 | 897 | |
340a7723 | 898 | gdb_assert (varobj_editable_p (var)); |
8b93c638 | 899 | |
340a7723 NR |
900 | input_radix = 10; /* ALWAYS reset to decimal temporarily */ |
901 | exp = parse_exp_1 (&s, 0, 0); | |
902 | if (!gdb_evaluate_expression (exp, &value)) | |
903 | { | |
904 | /* We cannot proceed without a valid expression. */ | |
905 | xfree (exp); | |
906 | return 0; | |
8b93c638 JM |
907 | } |
908 | ||
340a7723 NR |
909 | /* All types that are editable must also be changeable. */ |
910 | gdb_assert (varobj_value_is_changeable_p (var)); | |
911 | ||
912 | /* The value of a changeable variable object must not be lazy. */ | |
913 | gdb_assert (!value_lazy (var->value)); | |
914 | ||
915 | /* Need to coerce the input. We want to check if the | |
916 | value of the variable object will be different | |
917 | after assignment, and the first thing value_assign | |
918 | does is coerce the input. | |
919 | For example, if we are assigning an array to a pointer variable we | |
920 | should compare the pointer with the the array's address, not with the | |
921 | array's content. */ | |
922 | value = coerce_array (value); | |
923 | ||
924 | /* The new value may be lazy. gdb_value_assign, or | |
925 | rather value_contents, will take care of this. | |
926 | If fetching of the new value will fail, gdb_value_assign | |
927 | with catch the exception. */ | |
928 | if (!gdb_value_assign (var->value, value, &val)) | |
929 | return 0; | |
930 | ||
931 | /* If the value has changed, record it, so that next -var-update can | |
932 | report this change. If a variable had a value of '1', we've set it | |
933 | to '333' and then set again to '1', when -var-update will report this | |
934 | variable as changed -- because the first assignment has set the | |
935 | 'updated' flag. There's no need to optimize that, because return value | |
936 | of -var-update should be considered an approximation. */ | |
937 | var->updated = install_new_value (var, val, 0 /* Compare values. */); | |
938 | input_radix = saved_input_radix; | |
939 | return 1; | |
8b93c638 JM |
940 | } |
941 | ||
942 | /* Returns a malloc'ed list with all root variable objects */ | |
943 | int | |
944 | varobj_list (struct varobj ***varlist) | |
945 | { | |
946 | struct varobj **cv; | |
947 | struct varobj_root *croot; | |
948 | int mycount = rootcount; | |
949 | ||
950 | /* Alloc (rootcount + 1) entries for the result */ | |
951 | *varlist = xmalloc ((rootcount + 1) * sizeof (struct varobj *)); | |
952 | ||
953 | cv = *varlist; | |
954 | croot = rootlist; | |
955 | while ((croot != NULL) && (mycount > 0)) | |
956 | { | |
957 | *cv = croot->rootvar; | |
958 | mycount--; | |
959 | cv++; | |
960 | croot = croot->next; | |
961 | } | |
962 | /* Mark the end of the list */ | |
963 | *cv = NULL; | |
964 | ||
965 | if (mycount || (croot != NULL)) | |
72330bd6 AC |
966 | warning |
967 | ("varobj_list: assertion failed - wrong tally of root vars (%d:%d)", | |
968 | rootcount, mycount); | |
8b93c638 JM |
969 | |
970 | return rootcount; | |
971 | } | |
972 | ||
acd65feb VP |
973 | /* Assign a new value to a variable object. If INITIAL is non-zero, |
974 | this is the first assignement after the variable object was just | |
975 | created, or changed type. In that case, just assign the value | |
976 | and return 0. | |
977 | Otherwise, assign the value and if type_changeable returns non-zero, | |
978 | find if the new value is different from the current value. | |
b26ed50d VP |
979 | Return 1 if so, and 0 if the values are equal. |
980 | ||
981 | The VALUE parameter should not be released -- the function will | |
982 | take care of releasing it when needed. */ | |
acd65feb VP |
983 | static int |
984 | install_new_value (struct varobj *var, struct value *value, int initial) | |
985 | { | |
986 | int changeable; | |
987 | int need_to_fetch; | |
988 | int changed = 0; | |
25d5ea92 | 989 | int intentionally_not_fetched = 0; |
7a4d50bf | 990 | char *print_value = NULL; |
acd65feb | 991 | |
acd65feb VP |
992 | /* We need to know the varobj's type to decide if the value should |
993 | be fetched or not. C++ fake children (public/protected/private) don't have | |
994 | a type. */ | |
995 | gdb_assert (var->type || CPLUS_FAKE_CHILD (var)); | |
b2c2bd75 | 996 | changeable = varobj_value_is_changeable_p (var); |
acd65feb VP |
997 | need_to_fetch = changeable; |
998 | ||
b26ed50d VP |
999 | /* We are not interested in the address of references, and given |
1000 | that in C++ a reference is not rebindable, it cannot | |
1001 | meaningfully change. So, get hold of the real value. */ | |
1002 | if (value) | |
1003 | { | |
1004 | value = coerce_ref (value); | |
1005 | release_value (value); | |
1006 | } | |
1007 | ||
acd65feb VP |
1008 | if (var->type && TYPE_CODE (var->type) == TYPE_CODE_UNION) |
1009 | /* For unions, we need to fetch the value implicitly because | |
1010 | of implementation of union member fetch. When gdb | |
1011 | creates a value for a field and the value of the enclosing | |
1012 | structure is not lazy, it immediately copies the necessary | |
1013 | bytes from the enclosing values. If the enclosing value is | |
1014 | lazy, the call to value_fetch_lazy on the field will read | |
1015 | the data from memory. For unions, that means we'll read the | |
1016 | same memory more than once, which is not desirable. So | |
1017 | fetch now. */ | |
1018 | need_to_fetch = 1; | |
1019 | ||
1020 | /* The new value might be lazy. If the type is changeable, | |
1021 | that is we'll be comparing values of this type, fetch the | |
1022 | value now. Otherwise, on the next update the old value | |
1023 | will be lazy, which means we've lost that old value. */ | |
1024 | if (need_to_fetch && value && value_lazy (value)) | |
1025 | { | |
25d5ea92 VP |
1026 | struct varobj *parent = var->parent; |
1027 | int frozen = var->frozen; | |
1028 | for (; !frozen && parent; parent = parent->parent) | |
1029 | frozen |= parent->frozen; | |
1030 | ||
1031 | if (frozen && initial) | |
1032 | { | |
1033 | /* For variables that are frozen, or are children of frozen | |
1034 | variables, we don't do fetch on initial assignment. | |
1035 | For non-initial assignemnt we do the fetch, since it means we're | |
1036 | explicitly asked to compare the new value with the old one. */ | |
1037 | intentionally_not_fetched = 1; | |
1038 | } | |
1039 | else if (!gdb_value_fetch_lazy (value)) | |
acd65feb | 1040 | { |
acd65feb VP |
1041 | /* Set the value to NULL, so that for the next -var-update, |
1042 | we don't try to compare the new value with this value, | |
1043 | that we couldn't even read. */ | |
1044 | value = NULL; | |
1045 | } | |
acd65feb VP |
1046 | } |
1047 | ||
7a4d50bf VP |
1048 | /* Below, we'll be comparing string rendering of old and new |
1049 | values. Don't get string rendering if the value is | |
1050 | lazy -- if it is, the code above has decided that the value | |
1051 | should not be fetched. */ | |
1052 | if (value && !value_lazy (value)) | |
1053 | print_value = value_get_print_value (value, var->format); | |
1054 | ||
acd65feb VP |
1055 | /* If the type is changeable, compare the old and the new values. |
1056 | If this is the initial assignment, we don't have any old value | |
1057 | to compare with. */ | |
7a4d50bf | 1058 | if (!initial && changeable) |
acd65feb VP |
1059 | { |
1060 | /* If the value of the varobj was changed by -var-set-value, then the | |
1061 | value in the varobj and in the target is the same. However, that value | |
1062 | is different from the value that the varobj had after the previous | |
57e66780 | 1063 | -var-update. So need to the varobj as changed. */ |
acd65feb | 1064 | if (var->updated) |
57e66780 | 1065 | { |
57e66780 DJ |
1066 | changed = 1; |
1067 | } | |
acd65feb VP |
1068 | else |
1069 | { | |
1070 | /* Try to compare the values. That requires that both | |
1071 | values are non-lazy. */ | |
25d5ea92 VP |
1072 | if (var->not_fetched && value_lazy (var->value)) |
1073 | { | |
1074 | /* This is a frozen varobj and the value was never read. | |
1075 | Presumably, UI shows some "never read" indicator. | |
1076 | Now that we've fetched the real value, we need to report | |
1077 | this varobj as changed so that UI can show the real | |
1078 | value. */ | |
1079 | changed = 1; | |
1080 | } | |
1081 | else if (var->value == NULL && value == NULL) | |
acd65feb VP |
1082 | /* Equal. */ |
1083 | ; | |
1084 | else if (var->value == NULL || value == NULL) | |
57e66780 | 1085 | { |
57e66780 DJ |
1086 | changed = 1; |
1087 | } | |
acd65feb VP |
1088 | else |
1089 | { | |
1090 | gdb_assert (!value_lazy (var->value)); | |
1091 | gdb_assert (!value_lazy (value)); | |
85265413 | 1092 | |
57e66780 | 1093 | gdb_assert (var->print_value != NULL && print_value != NULL); |
85265413 | 1094 | if (strcmp (var->print_value, print_value) != 0) |
7a4d50bf | 1095 | changed = 1; |
acd65feb VP |
1096 | } |
1097 | } | |
1098 | } | |
85265413 | 1099 | |
acd65feb | 1100 | /* We must always keep the new value, since children depend on it. */ |
25d5ea92 | 1101 | if (var->value != NULL && var->value != value) |
acd65feb VP |
1102 | value_free (var->value); |
1103 | var->value = value; | |
7a4d50bf VP |
1104 | if (var->print_value) |
1105 | xfree (var->print_value); | |
1106 | var->print_value = print_value; | |
25d5ea92 VP |
1107 | if (value && value_lazy (value) && intentionally_not_fetched) |
1108 | var->not_fetched = 1; | |
1109 | else | |
1110 | var->not_fetched = 0; | |
acd65feb | 1111 | var->updated = 0; |
85265413 | 1112 | |
b26ed50d | 1113 | gdb_assert (!var->value || value_type (var->value)); |
acd65feb VP |
1114 | |
1115 | return changed; | |
1116 | } | |
acd65feb | 1117 | |
8b93c638 JM |
1118 | /* Update the values for a variable and its children. This is a |
1119 | two-pronged attack. First, re-parse the value for the root's | |
1120 | expression to see if it's changed. Then go all the way | |
1121 | through its children, reconstructing them and noting if they've | |
1122 | changed. | |
1123 | ||
25d5ea92 VP |
1124 | The EXPLICIT parameter specifies if this call is result |
1125 | of MI request to update this specific variable, or | |
1126 | result of implicit -var-update *. For implicit request, we don't | |
1127 | update frozen variables. | |
705da579 KS |
1128 | |
1129 | NOTE: This function may delete the caller's varobj. If it | |
8756216b DP |
1130 | returns TYPE_CHANGED, then it has done this and VARP will be modified |
1131 | to point to the new varobj. */ | |
8b93c638 | 1132 | |
f7f9ae2c | 1133 | VEC(varobj_update_result) *varobj_update (struct varobj **varp, int explicit) |
8b93c638 JM |
1134 | { |
1135 | int changed = 0; | |
25d5ea92 | 1136 | int type_changed = 0; |
8b93c638 JM |
1137 | int i; |
1138 | int vleft; | |
8b93c638 JM |
1139 | struct varobj *v; |
1140 | struct varobj **cv; | |
2c67cb8b | 1141 | struct varobj **templist = NULL; |
30b28db1 | 1142 | struct value *new; |
28335dcc | 1143 | VEC (varobj_p) *stack = NULL; |
f7f9ae2c | 1144 | VEC (varobj_update_result) *result = NULL; |
e64d9b3d | 1145 | struct frame_info *fi; |
8b93c638 | 1146 | |
25d5ea92 VP |
1147 | /* Frozen means frozen -- we don't check for any change in |
1148 | this varobj, including its going out of scope, or | |
1149 | changing type. One use case for frozen varobjs is | |
1150 | retaining previously evaluated expressions, and we don't | |
1151 | want them to be reevaluated at all. */ | |
1152 | if (!explicit && (*varp)->frozen) | |
f7f9ae2c | 1153 | return result; |
8756216b DP |
1154 | |
1155 | if (!(*varp)->root->is_valid) | |
f7f9ae2c VP |
1156 | { |
1157 | varobj_update_result r = {*varp}; | |
1158 | r.status = VAROBJ_INVALID; | |
1159 | VEC_safe_push (varobj_update_result, result, &r); | |
1160 | return result; | |
1161 | } | |
8b93c638 | 1162 | |
25d5ea92 | 1163 | if ((*varp)->root->rootvar == *varp) |
ae093f96 | 1164 | { |
f7f9ae2c VP |
1165 | varobj_update_result r = {*varp}; |
1166 | r.status = VAROBJ_IN_SCOPE; | |
1167 | ||
25d5ea92 VP |
1168 | /* Update the root variable. value_of_root can return NULL |
1169 | if the variable is no longer around, i.e. we stepped out of | |
1170 | the frame in which a local existed. We are letting the | |
1171 | value_of_root variable dispose of the varobj if the type | |
1172 | has changed. */ | |
25d5ea92 | 1173 | new = value_of_root (varp, &type_changed); |
f7f9ae2c VP |
1174 | r.varobj = *varp; |
1175 | ||
1176 | r.type_changed = type_changed; | |
ea56f9c2 | 1177 | if (install_new_value ((*varp), new, type_changed)) |
f7f9ae2c | 1178 | r.changed = 1; |
ea56f9c2 | 1179 | |
25d5ea92 | 1180 | if (new == NULL) |
f7f9ae2c VP |
1181 | r.status = VAROBJ_NOT_IN_SCOPE; |
1182 | ||
1183 | if (r.type_changed || r.changed) | |
1184 | VEC_safe_push (varobj_update_result, result, &r); | |
1185 | ||
1186 | if (r.status == VAROBJ_NOT_IN_SCOPE) | |
1187 | return result; | |
b20d8971 VP |
1188 | } |
1189 | ||
28335dcc | 1190 | VEC_safe_push (varobj_p, stack, *varp); |
8b93c638 | 1191 | |
8756216b | 1192 | /* Walk through the children, reconstructing them all. */ |
28335dcc | 1193 | while (!VEC_empty (varobj_p, stack)) |
8b93c638 | 1194 | { |
28335dcc VP |
1195 | v = VEC_pop (varobj_p, stack); |
1196 | ||
1197 | /* Push any children. Use reverse order so that the first | |
1198 | child is popped from the work stack first, and so | |
1199 | will be added to result first. This does not | |
1200 | affect correctness, just "nicer". */ | |
1201 | for (i = VEC_length (varobj_p, v->children)-1; i >= 0; --i) | |
8b93c638 | 1202 | { |
28335dcc VP |
1203 | varobj_p c = VEC_index (varobj_p, v->children, i); |
1204 | /* Child may be NULL if explicitly deleted by -var-delete. */ | |
25d5ea92 | 1205 | if (c != NULL && !c->frozen) |
28335dcc | 1206 | VEC_safe_push (varobj_p, stack, c); |
8b93c638 JM |
1207 | } |
1208 | ||
28335dcc VP |
1209 | /* Update this variable, unless it's a root, which is already |
1210 | updated. */ | |
25d5ea92 | 1211 | if (v->root->rootvar != v) |
28335dcc VP |
1212 | { |
1213 | new = value_of_child (v->parent, v->index); | |
1214 | if (install_new_value (v, new, 0 /* type not changed */)) | |
1215 | { | |
1216 | /* Note that it's changed */ | |
f7f9ae2c VP |
1217 | varobj_update_result r = {v}; |
1218 | r.changed = 1; | |
1219 | VEC_safe_push (varobj_update_result, result, &r); | |
28335dcc VP |
1220 | v->updated = 0; |
1221 | } | |
8b93c638 | 1222 | } |
8b93c638 JM |
1223 | } |
1224 | ||
93b979d6 | 1225 | VEC_free (varobj_p, stack); |
f7f9ae2c | 1226 | return result; |
8b93c638 JM |
1227 | } |
1228 | \f | |
1229 | ||
1230 | /* Helper functions */ | |
1231 | ||
1232 | /* | |
1233 | * Variable object construction/destruction | |
1234 | */ | |
1235 | ||
1236 | static int | |
fba45db2 KB |
1237 | delete_variable (struct cpstack **resultp, struct varobj *var, |
1238 | int only_children_p) | |
8b93c638 JM |
1239 | { |
1240 | int delcount = 0; | |
1241 | ||
1242 | delete_variable_1 (resultp, &delcount, var, | |
1243 | only_children_p, 1 /* remove_from_parent_p */ ); | |
1244 | ||
1245 | return delcount; | |
1246 | } | |
1247 | ||
1248 | /* Delete the variable object VAR and its children */ | |
1249 | /* IMPORTANT NOTE: If we delete a variable which is a child | |
1250 | and the parent is not removed we dump core. It must be always | |
1251 | initially called with remove_from_parent_p set */ | |
1252 | static void | |
72330bd6 AC |
1253 | delete_variable_1 (struct cpstack **resultp, int *delcountp, |
1254 | struct varobj *var, int only_children_p, | |
1255 | int remove_from_parent_p) | |
8b93c638 | 1256 | { |
28335dcc | 1257 | int i; |
8b93c638 JM |
1258 | |
1259 | /* Delete any children of this variable, too. */ | |
28335dcc VP |
1260 | for (i = 0; i < VEC_length (varobj_p, var->children); ++i) |
1261 | { | |
1262 | varobj_p child = VEC_index (varobj_p, var->children, i); | |
214270ab VP |
1263 | if (!child) |
1264 | continue; | |
8b93c638 | 1265 | if (!remove_from_parent_p) |
28335dcc VP |
1266 | child->parent = NULL; |
1267 | delete_variable_1 (resultp, delcountp, child, 0, only_children_p); | |
8b93c638 | 1268 | } |
28335dcc | 1269 | VEC_free (varobj_p, var->children); |
8b93c638 JM |
1270 | |
1271 | /* if we were called to delete only the children we are done here */ | |
1272 | if (only_children_p) | |
1273 | return; | |
1274 | ||
1275 | /* Otherwise, add it to the list of deleted ones and proceed to do so */ | |
73a93a32 JI |
1276 | /* If the name is null, this is a temporary variable, that has not |
1277 | yet been installed, don't report it, it belongs to the caller... */ | |
1278 | if (var->obj_name != NULL) | |
8b93c638 | 1279 | { |
5b616ba1 | 1280 | cppush (resultp, xstrdup (var->obj_name)); |
8b93c638 JM |
1281 | *delcountp = *delcountp + 1; |
1282 | } | |
1283 | ||
1284 | /* If this variable has a parent, remove it from its parent's list */ | |
1285 | /* OPTIMIZATION: if the parent of this variable is also being deleted, | |
1286 | (as indicated by remove_from_parent_p) we don't bother doing an | |
1287 | expensive list search to find the element to remove when we are | |
1288 | discarding the list afterwards */ | |
72330bd6 | 1289 | if ((remove_from_parent_p) && (var->parent != NULL)) |
8b93c638 | 1290 | { |
28335dcc | 1291 | VEC_replace (varobj_p, var->parent->children, var->index, NULL); |
8b93c638 | 1292 | } |
72330bd6 | 1293 | |
73a93a32 JI |
1294 | if (var->obj_name != NULL) |
1295 | uninstall_variable (var); | |
8b93c638 JM |
1296 | |
1297 | /* Free memory associated with this variable */ | |
1298 | free_variable (var); | |
1299 | } | |
1300 | ||
1301 | /* Install the given variable VAR with the object name VAR->OBJ_NAME. */ | |
1302 | static int | |
fba45db2 | 1303 | install_variable (struct varobj *var) |
8b93c638 JM |
1304 | { |
1305 | struct vlist *cv; | |
1306 | struct vlist *newvl; | |
1307 | const char *chp; | |
1308 | unsigned int index = 0; | |
1309 | unsigned int i = 1; | |
1310 | ||
1311 | for (chp = var->obj_name; *chp; chp++) | |
1312 | { | |
1313 | index = (index + (i++ * (unsigned int) *chp)) % VAROBJ_TABLE_SIZE; | |
1314 | } | |
1315 | ||
1316 | cv = *(varobj_table + index); | |
1317 | while ((cv != NULL) && (strcmp (cv->var->obj_name, var->obj_name) != 0)) | |
1318 | cv = cv->next; | |
1319 | ||
1320 | if (cv != NULL) | |
8a3fe4f8 | 1321 | error (_("Duplicate variable object name")); |
8b93c638 JM |
1322 | |
1323 | /* Add varobj to hash table */ | |
1324 | newvl = xmalloc (sizeof (struct vlist)); | |
1325 | newvl->next = *(varobj_table + index); | |
1326 | newvl->var = var; | |
1327 | *(varobj_table + index) = newvl; | |
1328 | ||
1329 | /* If root, add varobj to root list */ | |
b2c2bd75 | 1330 | if (is_root_p (var)) |
8b93c638 JM |
1331 | { |
1332 | /* Add to list of root variables */ | |
1333 | if (rootlist == NULL) | |
1334 | var->root->next = NULL; | |
1335 | else | |
1336 | var->root->next = rootlist; | |
1337 | rootlist = var->root; | |
1338 | rootcount++; | |
1339 | } | |
1340 | ||
1341 | return 1; /* OK */ | |
1342 | } | |
1343 | ||
1344 | /* Unistall the object VAR. */ | |
1345 | static void | |
fba45db2 | 1346 | uninstall_variable (struct varobj *var) |
8b93c638 JM |
1347 | { |
1348 | struct vlist *cv; | |
1349 | struct vlist *prev; | |
1350 | struct varobj_root *cr; | |
1351 | struct varobj_root *prer; | |
1352 | const char *chp; | |
1353 | unsigned int index = 0; | |
1354 | unsigned int i = 1; | |
1355 | ||
1356 | /* Remove varobj from hash table */ | |
1357 | for (chp = var->obj_name; *chp; chp++) | |
1358 | { | |
1359 | index = (index + (i++ * (unsigned int) *chp)) % VAROBJ_TABLE_SIZE; | |
1360 | } | |
1361 | ||
1362 | cv = *(varobj_table + index); | |
1363 | prev = NULL; | |
1364 | while ((cv != NULL) && (strcmp (cv->var->obj_name, var->obj_name) != 0)) | |
1365 | { | |
1366 | prev = cv; | |
1367 | cv = cv->next; | |
1368 | } | |
1369 | ||
1370 | if (varobjdebug) | |
1371 | fprintf_unfiltered (gdb_stdlog, "Deleting %s\n", var->obj_name); | |
1372 | ||
1373 | if (cv == NULL) | |
1374 | { | |
72330bd6 AC |
1375 | warning |
1376 | ("Assertion failed: Could not find variable object \"%s\" to delete", | |
1377 | var->obj_name); | |
8b93c638 JM |
1378 | return; |
1379 | } | |
1380 | ||
1381 | if (prev == NULL) | |
1382 | *(varobj_table + index) = cv->next; | |
1383 | else | |
1384 | prev->next = cv->next; | |
1385 | ||
b8c9b27d | 1386 | xfree (cv); |
8b93c638 JM |
1387 | |
1388 | /* If root, remove varobj from root list */ | |
b2c2bd75 | 1389 | if (is_root_p (var)) |
8b93c638 JM |
1390 | { |
1391 | /* Remove from list of root variables */ | |
1392 | if (rootlist == var->root) | |
1393 | rootlist = var->root->next; | |
1394 | else | |
1395 | { | |
1396 | prer = NULL; | |
1397 | cr = rootlist; | |
1398 | while ((cr != NULL) && (cr->rootvar != var)) | |
1399 | { | |
1400 | prer = cr; | |
1401 | cr = cr->next; | |
1402 | } | |
1403 | if (cr == NULL) | |
1404 | { | |
72330bd6 AC |
1405 | warning |
1406 | ("Assertion failed: Could not find varobj \"%s\" in root list", | |
1407 | var->obj_name); | |
8b93c638 JM |
1408 | return; |
1409 | } | |
1410 | if (prer == NULL) | |
1411 | rootlist = NULL; | |
1412 | else | |
1413 | prer->next = cr->next; | |
1414 | } | |
1415 | rootcount--; | |
1416 | } | |
1417 | ||
1418 | } | |
1419 | ||
8b93c638 JM |
1420 | /* Create and install a child of the parent of the given name */ |
1421 | static struct varobj * | |
fba45db2 | 1422 | create_child (struct varobj *parent, int index, char *name) |
8b93c638 JM |
1423 | { |
1424 | struct varobj *child; | |
1425 | char *childs_name; | |
acd65feb | 1426 | struct value *value; |
8b93c638 JM |
1427 | |
1428 | child = new_variable (); | |
1429 | ||
1430 | /* name is allocated by name_of_child */ | |
1431 | child->name = name; | |
1432 | child->index = index; | |
acd65feb | 1433 | value = value_of_child (parent, index); |
8b93c638 JM |
1434 | child->parent = parent; |
1435 | child->root = parent->root; | |
b435e160 | 1436 | childs_name = xstrprintf ("%s.%s", parent->obj_name, name); |
8b93c638 JM |
1437 | child->obj_name = childs_name; |
1438 | install_variable (child); | |
1439 | ||
acd65feb VP |
1440 | /* Compute the type of the child. Must do this before |
1441 | calling install_new_value. */ | |
1442 | if (value != NULL) | |
1443 | /* If the child had no evaluation errors, var->value | |
1444 | will be non-NULL and contain a valid type. */ | |
1445 | child->type = value_type (value); | |
1446 | else | |
1447 | /* Otherwise, we must compute the type. */ | |
1448 | child->type = (*child->root->lang->type_of_child) (child->parent, | |
1449 | child->index); | |
1450 | install_new_value (child, value, 1); | |
1451 | ||
8b93c638 JM |
1452 | return child; |
1453 | } | |
8b93c638 JM |
1454 | \f |
1455 | ||
1456 | /* | |
1457 | * Miscellaneous utility functions. | |
1458 | */ | |
1459 | ||
1460 | /* Allocate memory and initialize a new variable */ | |
1461 | static struct varobj * | |
1462 | new_variable (void) | |
1463 | { | |
1464 | struct varobj *var; | |
1465 | ||
1466 | var = (struct varobj *) xmalloc (sizeof (struct varobj)); | |
1467 | var->name = NULL; | |
02142340 | 1468 | var->path_expr = NULL; |
8b93c638 JM |
1469 | var->obj_name = NULL; |
1470 | var->index = -1; | |
1471 | var->type = NULL; | |
1472 | var->value = NULL; | |
8b93c638 JM |
1473 | var->num_children = -1; |
1474 | var->parent = NULL; | |
1475 | var->children = NULL; | |
1476 | var->format = 0; | |
1477 | var->root = NULL; | |
fb9b6b35 | 1478 | var->updated = 0; |
85265413 | 1479 | var->print_value = NULL; |
25d5ea92 VP |
1480 | var->frozen = 0; |
1481 | var->not_fetched = 0; | |
8b93c638 JM |
1482 | |
1483 | return var; | |
1484 | } | |
1485 | ||
1486 | /* Allocate memory and initialize a new root variable */ | |
1487 | static struct varobj * | |
1488 | new_root_variable (void) | |
1489 | { | |
1490 | struct varobj *var = new_variable (); | |
1491 | var->root = (struct varobj_root *) xmalloc (sizeof (struct varobj_root));; | |
1492 | var->root->lang = NULL; | |
1493 | var->root->exp = NULL; | |
1494 | var->root->valid_block = NULL; | |
7a424e99 | 1495 | var->root->frame = null_frame_id; |
a5defcdc | 1496 | var->root->floating = 0; |
8b93c638 | 1497 | var->root->rootvar = NULL; |
8756216b | 1498 | var->root->is_valid = 1; |
8b93c638 JM |
1499 | |
1500 | return var; | |
1501 | } | |
1502 | ||
1503 | /* Free any allocated memory associated with VAR. */ | |
1504 | static void | |
fba45db2 | 1505 | free_variable (struct varobj *var) |
8b93c638 JM |
1506 | { |
1507 | /* Free the expression if this is a root variable. */ | |
b2c2bd75 | 1508 | if (is_root_p (var)) |
8b93c638 | 1509 | { |
96c1eda2 | 1510 | free_current_contents (&var->root->exp); |
8038e1e2 | 1511 | xfree (var->root); |
8b93c638 JM |
1512 | } |
1513 | ||
8038e1e2 AC |
1514 | xfree (var->name); |
1515 | xfree (var->obj_name); | |
85265413 | 1516 | xfree (var->print_value); |
02142340 | 1517 | xfree (var->path_expr); |
8038e1e2 | 1518 | xfree (var); |
8b93c638 JM |
1519 | } |
1520 | ||
74b7792f AC |
1521 | static void |
1522 | do_free_variable_cleanup (void *var) | |
1523 | { | |
1524 | free_variable (var); | |
1525 | } | |
1526 | ||
1527 | static struct cleanup * | |
1528 | make_cleanup_free_variable (struct varobj *var) | |
1529 | { | |
1530 | return make_cleanup (do_free_variable_cleanup, var); | |
1531 | } | |
1532 | ||
6766a268 DJ |
1533 | /* This returns the type of the variable. It also skips past typedefs |
1534 | to return the real type of the variable. | |
94b66fa7 KS |
1535 | |
1536 | NOTE: TYPE_TARGET_TYPE should NOT be used anywhere in this file | |
1537 | except within get_target_type and get_type. */ | |
8b93c638 | 1538 | static struct type * |
fba45db2 | 1539 | get_type (struct varobj *var) |
8b93c638 JM |
1540 | { |
1541 | struct type *type; | |
1542 | type = var->type; | |
1543 | ||
6766a268 DJ |
1544 | if (type != NULL) |
1545 | type = check_typedef (type); | |
8b93c638 JM |
1546 | |
1547 | return type; | |
1548 | } | |
1549 | ||
6e2a9270 VP |
1550 | /* Return the type of the value that's stored in VAR, |
1551 | or that would have being stored there if the | |
1552 | value were accessible. | |
1553 | ||
1554 | This differs from VAR->type in that VAR->type is always | |
1555 | the true type of the expession in the source language. | |
1556 | The return value of this function is the type we're | |
1557 | actually storing in varobj, and using for displaying | |
1558 | the values and for comparing previous and new values. | |
1559 | ||
1560 | For example, top-level references are always stripped. */ | |
1561 | static struct type * | |
1562 | get_value_type (struct varobj *var) | |
1563 | { | |
1564 | struct type *type; | |
1565 | ||
1566 | if (var->value) | |
1567 | type = value_type (var->value); | |
1568 | else | |
1569 | type = var->type; | |
1570 | ||
1571 | type = check_typedef (type); | |
1572 | ||
1573 | if (TYPE_CODE (type) == TYPE_CODE_REF) | |
1574 | type = get_target_type (type); | |
1575 | ||
1576 | type = check_typedef (type); | |
1577 | ||
1578 | return type; | |
1579 | } | |
1580 | ||
8b93c638 | 1581 | /* This returns the target type (or NULL) of TYPE, also skipping |
94b66fa7 KS |
1582 | past typedefs, just like get_type (). |
1583 | ||
1584 | NOTE: TYPE_TARGET_TYPE should NOT be used anywhere in this file | |
1585 | except within get_target_type and get_type. */ | |
8b93c638 | 1586 | static struct type * |
fba45db2 | 1587 | get_target_type (struct type *type) |
8b93c638 JM |
1588 | { |
1589 | if (type != NULL) | |
1590 | { | |
1591 | type = TYPE_TARGET_TYPE (type); | |
6766a268 DJ |
1592 | if (type != NULL) |
1593 | type = check_typedef (type); | |
8b93c638 JM |
1594 | } |
1595 | ||
1596 | return type; | |
1597 | } | |
1598 | ||
1599 | /* What is the default display for this variable? We assume that | |
1600 | everything is "natural". Any exceptions? */ | |
1601 | static enum varobj_display_formats | |
fba45db2 | 1602 | variable_default_display (struct varobj *var) |
8b93c638 JM |
1603 | { |
1604 | return FORMAT_NATURAL; | |
1605 | } | |
1606 | ||
8b93c638 JM |
1607 | /* FIXME: The following should be generic for any pointer */ |
1608 | static void | |
fba45db2 | 1609 | cppush (struct cpstack **pstack, char *name) |
8b93c638 JM |
1610 | { |
1611 | struct cpstack *s; | |
1612 | ||
1613 | s = (struct cpstack *) xmalloc (sizeof (struct cpstack)); | |
1614 | s->name = name; | |
1615 | s->next = *pstack; | |
1616 | *pstack = s; | |
1617 | } | |
1618 | ||
1619 | /* FIXME: The following should be generic for any pointer */ | |
1620 | static char * | |
fba45db2 | 1621 | cppop (struct cpstack **pstack) |
8b93c638 JM |
1622 | { |
1623 | struct cpstack *s; | |
1624 | char *v; | |
1625 | ||
1626 | if ((*pstack)->name == NULL && (*pstack)->next == NULL) | |
1627 | return NULL; | |
1628 | ||
1629 | s = *pstack; | |
1630 | v = s->name; | |
1631 | *pstack = (*pstack)->next; | |
b8c9b27d | 1632 | xfree (s); |
8b93c638 JM |
1633 | |
1634 | return v; | |
1635 | } | |
1636 | \f | |
1637 | /* | |
1638 | * Language-dependencies | |
1639 | */ | |
1640 | ||
1641 | /* Common entry points */ | |
1642 | ||
1643 | /* Get the language of variable VAR. */ | |
1644 | static enum varobj_languages | |
fba45db2 | 1645 | variable_language (struct varobj *var) |
8b93c638 JM |
1646 | { |
1647 | enum varobj_languages lang; | |
1648 | ||
1649 | switch (var->root->exp->language_defn->la_language) | |
1650 | { | |
1651 | default: | |
1652 | case language_c: | |
1653 | lang = vlang_c; | |
1654 | break; | |
1655 | case language_cplus: | |
1656 | lang = vlang_cplus; | |
1657 | break; | |
1658 | case language_java: | |
1659 | lang = vlang_java; | |
1660 | break; | |
1661 | } | |
1662 | ||
1663 | return lang; | |
1664 | } | |
1665 | ||
1666 | /* Return the number of children for a given variable. | |
1667 | The result of this function is defined by the language | |
1668 | implementation. The number of children returned by this function | |
1669 | is the number of children that the user will see in the variable | |
1670 | display. */ | |
1671 | static int | |
fba45db2 | 1672 | number_of_children (struct varobj *var) |
8b93c638 JM |
1673 | { |
1674 | return (*var->root->lang->number_of_children) (var);; | |
1675 | } | |
1676 | ||
1677 | /* What is the expression for the root varobj VAR? Returns a malloc'd string. */ | |
1678 | static char * | |
fba45db2 | 1679 | name_of_variable (struct varobj *var) |
8b93c638 JM |
1680 | { |
1681 | return (*var->root->lang->name_of_variable) (var); | |
1682 | } | |
1683 | ||
1684 | /* What is the name of the INDEX'th child of VAR? Returns a malloc'd string. */ | |
1685 | static char * | |
fba45db2 | 1686 | name_of_child (struct varobj *var, int index) |
8b93c638 JM |
1687 | { |
1688 | return (*var->root->lang->name_of_child) (var, index); | |
1689 | } | |
1690 | ||
a5defcdc VP |
1691 | /* What is the ``struct value *'' of the root variable VAR? |
1692 | For floating variable object, evaluation can get us a value | |
1693 | of different type from what is stored in varobj already. In | |
1694 | that case: | |
1695 | - *type_changed will be set to 1 | |
1696 | - old varobj will be freed, and new one will be | |
1697 | created, with the same name. | |
1698 | - *var_handle will be set to the new varobj | |
1699 | Otherwise, *type_changed will be set to 0. */ | |
30b28db1 | 1700 | static struct value * |
fba45db2 | 1701 | value_of_root (struct varobj **var_handle, int *type_changed) |
8b93c638 | 1702 | { |
73a93a32 JI |
1703 | struct varobj *var; |
1704 | ||
1705 | if (var_handle == NULL) | |
1706 | return NULL; | |
1707 | ||
1708 | var = *var_handle; | |
1709 | ||
1710 | /* This should really be an exception, since this should | |
1711 | only get called with a root variable. */ | |
1712 | ||
b2c2bd75 | 1713 | if (!is_root_p (var)) |
73a93a32 JI |
1714 | return NULL; |
1715 | ||
a5defcdc | 1716 | if (var->root->floating) |
73a93a32 JI |
1717 | { |
1718 | struct varobj *tmp_var; | |
1719 | char *old_type, *new_type; | |
6225abfa | 1720 | |
73a93a32 JI |
1721 | tmp_var = varobj_create (NULL, var->name, (CORE_ADDR) 0, |
1722 | USE_SELECTED_FRAME); | |
1723 | if (tmp_var == NULL) | |
1724 | { | |
1725 | return NULL; | |
1726 | } | |
6225abfa | 1727 | old_type = varobj_get_type (var); |
73a93a32 | 1728 | new_type = varobj_get_type (tmp_var); |
72330bd6 | 1729 | if (strcmp (old_type, new_type) == 0) |
73a93a32 | 1730 | { |
fcacd99f VP |
1731 | /* The expression presently stored inside var->root->exp |
1732 | remembers the locations of local variables relatively to | |
1733 | the frame where the expression was created (in DWARF location | |
1734 | button, for example). Naturally, those locations are not | |
1735 | correct in other frames, so update the expression. */ | |
1736 | ||
1737 | struct expression *tmp_exp = var->root->exp; | |
1738 | var->root->exp = tmp_var->root->exp; | |
1739 | tmp_var->root->exp = tmp_exp; | |
1740 | ||
73a93a32 JI |
1741 | varobj_delete (tmp_var, NULL, 0); |
1742 | *type_changed = 0; | |
1743 | } | |
1744 | else | |
1745 | { | |
a5defcdc VP |
1746 | tmp_var->obj_name = |
1747 | savestring (var->obj_name, strlen (var->obj_name)); | |
1748 | varobj_delete (var, NULL, 0); | |
1749 | ||
73a93a32 JI |
1750 | install_variable (tmp_var); |
1751 | *var_handle = tmp_var; | |
705da579 | 1752 | var = *var_handle; |
73a93a32 JI |
1753 | *type_changed = 1; |
1754 | } | |
74dddad3 MS |
1755 | xfree (old_type); |
1756 | xfree (new_type); | |
73a93a32 JI |
1757 | } |
1758 | else | |
1759 | { | |
1760 | *type_changed = 0; | |
1761 | } | |
1762 | ||
1763 | return (*var->root->lang->value_of_root) (var_handle); | |
8b93c638 JM |
1764 | } |
1765 | ||
30b28db1 AC |
1766 | /* What is the ``struct value *'' for the INDEX'th child of PARENT? */ |
1767 | static struct value * | |
fba45db2 | 1768 | value_of_child (struct varobj *parent, int index) |
8b93c638 | 1769 | { |
30b28db1 | 1770 | struct value *value; |
8b93c638 JM |
1771 | |
1772 | value = (*parent->root->lang->value_of_child) (parent, index); | |
1773 | ||
8b93c638 JM |
1774 | return value; |
1775 | } | |
1776 | ||
8b93c638 JM |
1777 | /* GDB already has a command called "value_of_variable". Sigh. */ |
1778 | static char * | |
de051565 | 1779 | my_value_of_variable (struct varobj *var, enum varobj_display_formats format) |
8b93c638 | 1780 | { |
8756216b | 1781 | if (var->root->is_valid) |
de051565 | 1782 | return (*var->root->lang->value_of_variable) (var, format); |
8756216b DP |
1783 | else |
1784 | return NULL; | |
8b93c638 JM |
1785 | } |
1786 | ||
85265413 NR |
1787 | static char * |
1788 | value_get_print_value (struct value *value, enum varobj_display_formats format) | |
1789 | { | |
1790 | long dummy; | |
57e66780 DJ |
1791 | struct ui_file *stb; |
1792 | struct cleanup *old_chain; | |
85265413 | 1793 | char *thevalue; |
57e66780 DJ |
1794 | |
1795 | if (value == NULL) | |
1796 | return NULL; | |
1797 | ||
1798 | stb = mem_fileopen (); | |
1799 | old_chain = make_cleanup_ui_file_delete (stb); | |
1800 | ||
d8ca156b JB |
1801 | common_val_print (value, stb, format_code[(int) format], 1, 0, 0, |
1802 | current_language); | |
85265413 | 1803 | thevalue = ui_file_xstrdup (stb, &dummy); |
57e66780 | 1804 | |
85265413 NR |
1805 | do_cleanups (old_chain); |
1806 | return thevalue; | |
1807 | } | |
1808 | ||
340a7723 NR |
1809 | int |
1810 | varobj_editable_p (struct varobj *var) | |
1811 | { | |
1812 | struct type *type; | |
1813 | struct value *value; | |
1814 | ||
1815 | if (!(var->root->is_valid && var->value && VALUE_LVAL (var->value))) | |
1816 | return 0; | |
1817 | ||
1818 | type = get_value_type (var); | |
1819 | ||
1820 | switch (TYPE_CODE (type)) | |
1821 | { | |
1822 | case TYPE_CODE_STRUCT: | |
1823 | case TYPE_CODE_UNION: | |
1824 | case TYPE_CODE_ARRAY: | |
1825 | case TYPE_CODE_FUNC: | |
1826 | case TYPE_CODE_METHOD: | |
1827 | return 0; | |
1828 | break; | |
1829 | ||
1830 | default: | |
1831 | return 1; | |
1832 | break; | |
1833 | } | |
1834 | } | |
1835 | ||
acd65feb VP |
1836 | /* Return non-zero if changes in value of VAR |
1837 | must be detected and reported by -var-update. | |
1838 | Return zero is -var-update should never report | |
1839 | changes of such values. This makes sense for structures | |
1840 | (since the changes in children values will be reported separately), | |
1841 | or for artifical objects (like 'public' pseudo-field in C++). | |
1842 | ||
1843 | Return value of 0 means that gdb need not call value_fetch_lazy | |
1844 | for the value of this variable object. */ | |
8b93c638 | 1845 | static int |
b2c2bd75 | 1846 | varobj_value_is_changeable_p (struct varobj *var) |
8b93c638 JM |
1847 | { |
1848 | int r; | |
1849 | struct type *type; | |
1850 | ||
1851 | if (CPLUS_FAKE_CHILD (var)) | |
1852 | return 0; | |
1853 | ||
6e2a9270 | 1854 | type = get_value_type (var); |
8b93c638 JM |
1855 | |
1856 | switch (TYPE_CODE (type)) | |
1857 | { | |
72330bd6 AC |
1858 | case TYPE_CODE_STRUCT: |
1859 | case TYPE_CODE_UNION: | |
1860 | case TYPE_CODE_ARRAY: | |
1861 | r = 0; | |
1862 | break; | |
8b93c638 | 1863 | |
72330bd6 AC |
1864 | default: |
1865 | r = 1; | |
8b93c638 JM |
1866 | } |
1867 | ||
1868 | return r; | |
1869 | } | |
1870 | ||
5a413362 VP |
1871 | /* Return 1 if that varobj is floating, that is is always evaluated in the |
1872 | selected frame, and not bound to thread/frame. Such variable objects | |
1873 | are created using '@' as frame specifier to -var-create. */ | |
1874 | int | |
1875 | varobj_floating_p (struct varobj *var) | |
1876 | { | |
1877 | return var->root->floating; | |
1878 | } | |
1879 | ||
2024f65a VP |
1880 | /* Given the value and the type of a variable object, |
1881 | adjust the value and type to those necessary | |
1882 | for getting children of the variable object. | |
1883 | This includes dereferencing top-level references | |
1884 | to all types and dereferencing pointers to | |
1885 | structures. | |
1886 | ||
1887 | Both TYPE and *TYPE should be non-null. VALUE | |
1888 | can be null if we want to only translate type. | |
1889 | *VALUE can be null as well -- if the parent | |
02142340 VP |
1890 | value is not known. |
1891 | ||
1892 | If WAS_PTR is not NULL, set *WAS_PTR to 0 or 1 | |
1893 | depending on whether pointer was deferenced | |
1894 | in this function. */ | |
2024f65a VP |
1895 | static void |
1896 | adjust_value_for_child_access (struct value **value, | |
02142340 VP |
1897 | struct type **type, |
1898 | int *was_ptr) | |
2024f65a VP |
1899 | { |
1900 | gdb_assert (type && *type); | |
1901 | ||
02142340 VP |
1902 | if (was_ptr) |
1903 | *was_ptr = 0; | |
1904 | ||
2024f65a VP |
1905 | *type = check_typedef (*type); |
1906 | ||
1907 | /* The type of value stored in varobj, that is passed | |
1908 | to us, is already supposed to be | |
1909 | reference-stripped. */ | |
1910 | ||
1911 | gdb_assert (TYPE_CODE (*type) != TYPE_CODE_REF); | |
1912 | ||
1913 | /* Pointers to structures are treated just like | |
1914 | structures when accessing children. Don't | |
1915 | dererences pointers to other types. */ | |
1916 | if (TYPE_CODE (*type) == TYPE_CODE_PTR) | |
1917 | { | |
1918 | struct type *target_type = get_target_type (*type); | |
1919 | if (TYPE_CODE (target_type) == TYPE_CODE_STRUCT | |
1920 | || TYPE_CODE (target_type) == TYPE_CODE_UNION) | |
1921 | { | |
1922 | if (value && *value) | |
3f4178d6 DJ |
1923 | { |
1924 | int success = gdb_value_ind (*value, value); | |
1925 | if (!success) | |
1926 | *value = NULL; | |
1927 | } | |
2024f65a | 1928 | *type = target_type; |
02142340 VP |
1929 | if (was_ptr) |
1930 | *was_ptr = 1; | |
2024f65a VP |
1931 | } |
1932 | } | |
1933 | ||
1934 | /* The 'get_target_type' function calls check_typedef on | |
1935 | result, so we can immediately check type code. No | |
1936 | need to call check_typedef here. */ | |
1937 | } | |
1938 | ||
8b93c638 JM |
1939 | /* C */ |
1940 | static int | |
fba45db2 | 1941 | c_number_of_children (struct varobj *var) |
8b93c638 | 1942 | { |
2024f65a VP |
1943 | struct type *type = get_value_type (var); |
1944 | int children = 0; | |
8b93c638 | 1945 | struct type *target; |
8b93c638 | 1946 | |
02142340 | 1947 | adjust_value_for_child_access (NULL, &type, NULL); |
8b93c638 | 1948 | target = get_target_type (type); |
8b93c638 JM |
1949 | |
1950 | switch (TYPE_CODE (type)) | |
1951 | { | |
1952 | case TYPE_CODE_ARRAY: | |
1953 | if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (target) > 0 | |
72330bd6 | 1954 | && TYPE_ARRAY_UPPER_BOUND_TYPE (type) != BOUND_CANNOT_BE_DETERMINED) |
8b93c638 JM |
1955 | children = TYPE_LENGTH (type) / TYPE_LENGTH (target); |
1956 | else | |
74a44383 DJ |
1957 | /* If we don't know how many elements there are, don't display |
1958 | any. */ | |
1959 | children = 0; | |
8b93c638 JM |
1960 | break; |
1961 | ||
1962 | case TYPE_CODE_STRUCT: | |
1963 | case TYPE_CODE_UNION: | |
1964 | children = TYPE_NFIELDS (type); | |
1965 | break; | |
1966 | ||
1967 | case TYPE_CODE_PTR: | |
2024f65a VP |
1968 | /* The type here is a pointer to non-struct. Typically, pointers |
1969 | have one child, except for function ptrs, which have no children, | |
1970 | and except for void*, as we don't know what to show. | |
1971 | ||
0755e6c1 FN |
1972 | We can show char* so we allow it to be dereferenced. If you decide |
1973 | to test for it, please mind that a little magic is necessary to | |
1974 | properly identify it: char* has TYPE_CODE == TYPE_CODE_INT and | |
1975 | TYPE_NAME == "char" */ | |
2024f65a VP |
1976 | if (TYPE_CODE (target) == TYPE_CODE_FUNC |
1977 | || TYPE_CODE (target) == TYPE_CODE_VOID) | |
1978 | children = 0; | |
1979 | else | |
1980 | children = 1; | |
8b93c638 JM |
1981 | break; |
1982 | ||
1983 | default: | |
1984 | /* Other types have no children */ | |
1985 | break; | |
1986 | } | |
1987 | ||
1988 | return children; | |
1989 | } | |
1990 | ||
1991 | static char * | |
fba45db2 | 1992 | c_name_of_variable (struct varobj *parent) |
8b93c638 JM |
1993 | { |
1994 | return savestring (parent->name, strlen (parent->name)); | |
1995 | } | |
1996 | ||
bbec2603 VP |
1997 | /* Return the value of element TYPE_INDEX of a structure |
1998 | value VALUE. VALUE's type should be a structure, | |
1999 | or union, or a typedef to struct/union. | |
2000 | ||
2001 | Returns NULL if getting the value fails. Never throws. */ | |
2002 | static struct value * | |
2003 | value_struct_element_index (struct value *value, int type_index) | |
8b93c638 | 2004 | { |
bbec2603 VP |
2005 | struct value *result = NULL; |
2006 | volatile struct gdb_exception e; | |
8b93c638 | 2007 | |
bbec2603 VP |
2008 | struct type *type = value_type (value); |
2009 | type = check_typedef (type); | |
2010 | ||
2011 | gdb_assert (TYPE_CODE (type) == TYPE_CODE_STRUCT | |
2012 | || TYPE_CODE (type) == TYPE_CODE_UNION); | |
8b93c638 | 2013 | |
bbec2603 VP |
2014 | TRY_CATCH (e, RETURN_MASK_ERROR) |
2015 | { | |
2016 | if (TYPE_FIELD_STATIC (type, type_index)) | |
2017 | result = value_static_field (type, type_index); | |
2018 | else | |
2019 | result = value_primitive_field (value, 0, type_index, type); | |
2020 | } | |
2021 | if (e.reason < 0) | |
2022 | { | |
2023 | return NULL; | |
2024 | } | |
2025 | else | |
2026 | { | |
2027 | return result; | |
2028 | } | |
2029 | } | |
2030 | ||
2031 | /* Obtain the information about child INDEX of the variable | |
2032 | object PARENT. | |
2033 | If CNAME is not null, sets *CNAME to the name of the child relative | |
2034 | to the parent. | |
2035 | If CVALUE is not null, sets *CVALUE to the value of the child. | |
2036 | If CTYPE is not null, sets *CTYPE to the type of the child. | |
2037 | ||
2038 | If any of CNAME, CVALUE, or CTYPE is not null, but the corresponding | |
2039 | information cannot be determined, set *CNAME, *CVALUE, or *CTYPE | |
2040 | to NULL. */ | |
2041 | static void | |
2042 | c_describe_child (struct varobj *parent, int index, | |
02142340 VP |
2043 | char **cname, struct value **cvalue, struct type **ctype, |
2044 | char **cfull_expression) | |
bbec2603 VP |
2045 | { |
2046 | struct value *value = parent->value; | |
2024f65a | 2047 | struct type *type = get_value_type (parent); |
02142340 VP |
2048 | char *parent_expression = NULL; |
2049 | int was_ptr; | |
bbec2603 VP |
2050 | |
2051 | if (cname) | |
2052 | *cname = NULL; | |
2053 | if (cvalue) | |
2054 | *cvalue = NULL; | |
2055 | if (ctype) | |
2056 | *ctype = NULL; | |
02142340 VP |
2057 | if (cfull_expression) |
2058 | { | |
2059 | *cfull_expression = NULL; | |
2060 | parent_expression = varobj_get_path_expr (parent); | |
2061 | } | |
2062 | adjust_value_for_child_access (&value, &type, &was_ptr); | |
bbec2603 | 2063 | |
8b93c638 JM |
2064 | switch (TYPE_CODE (type)) |
2065 | { | |
2066 | case TYPE_CODE_ARRAY: | |
bbec2603 VP |
2067 | if (cname) |
2068 | *cname = xstrprintf ("%d", index | |
2069 | + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type))); | |
2070 | ||
2071 | if (cvalue && value) | |
2072 | { | |
2073 | int real_index = index + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type)); | |
2074 | struct value *indval = | |
2075 | value_from_longest (builtin_type_int, (LONGEST) real_index); | |
2076 | gdb_value_subscript (value, indval, cvalue); | |
2077 | } | |
2078 | ||
2079 | if (ctype) | |
2080 | *ctype = get_target_type (type); | |
2081 | ||
02142340 VP |
2082 | if (cfull_expression) |
2083 | *cfull_expression = xstrprintf ("(%s)[%d]", parent_expression, | |
2084 | index | |
2085 | + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type))); | |
2086 | ||
2087 | ||
8b93c638 JM |
2088 | break; |
2089 | ||
2090 | case TYPE_CODE_STRUCT: | |
2091 | case TYPE_CODE_UNION: | |
bbec2603 VP |
2092 | if (cname) |
2093 | { | |
2094 | char *string = TYPE_FIELD_NAME (type, index); | |
2095 | *cname = savestring (string, strlen (string)); | |
2096 | } | |
2097 | ||
2098 | if (cvalue && value) | |
2099 | { | |
2100 | /* For C, varobj index is the same as type index. */ | |
2101 | *cvalue = value_struct_element_index (value, index); | |
2102 | } | |
2103 | ||
2104 | if (ctype) | |
2105 | *ctype = TYPE_FIELD_TYPE (type, index); | |
2106 | ||
02142340 VP |
2107 | if (cfull_expression) |
2108 | { | |
2109 | char *join = was_ptr ? "->" : "."; | |
2110 | *cfull_expression = xstrprintf ("(%s)%s%s", parent_expression, join, | |
2111 | TYPE_FIELD_NAME (type, index)); | |
2112 | } | |
2113 | ||
8b93c638 JM |
2114 | break; |
2115 | ||
2116 | case TYPE_CODE_PTR: | |
bbec2603 VP |
2117 | if (cname) |
2118 | *cname = xstrprintf ("*%s", parent->name); | |
8b93c638 | 2119 | |
bbec2603 | 2120 | if (cvalue && value) |
3f4178d6 DJ |
2121 | { |
2122 | int success = gdb_value_ind (value, cvalue); | |
2123 | if (!success) | |
2124 | *cvalue = NULL; | |
2125 | } | |
bbec2603 | 2126 | |
2024f65a VP |
2127 | /* Don't use get_target_type because it calls |
2128 | check_typedef and here, we want to show the true | |
2129 | declared type of the variable. */ | |
bbec2603 | 2130 | if (ctype) |
2024f65a | 2131 | *ctype = TYPE_TARGET_TYPE (type); |
02142340 VP |
2132 | |
2133 | if (cfull_expression) | |
2134 | *cfull_expression = xstrprintf ("*(%s)", parent_expression); | |
bbec2603 | 2135 | |
8b93c638 JM |
2136 | break; |
2137 | ||
2138 | default: | |
2139 | /* This should not happen */ | |
bbec2603 VP |
2140 | if (cname) |
2141 | *cname = xstrdup ("???"); | |
02142340 VP |
2142 | if (cfull_expression) |
2143 | *cfull_expression = xstrdup ("???"); | |
bbec2603 | 2144 | /* Don't set value and type, we don't know then. */ |
8b93c638 | 2145 | } |
bbec2603 | 2146 | } |
8b93c638 | 2147 | |
bbec2603 VP |
2148 | static char * |
2149 | c_name_of_child (struct varobj *parent, int index) | |
2150 | { | |
2151 | char *name; | |
02142340 | 2152 | c_describe_child (parent, index, &name, NULL, NULL, NULL); |
8b93c638 JM |
2153 | return name; |
2154 | } | |
2155 | ||
02142340 VP |
2156 | static char * |
2157 | c_path_expr_of_child (struct varobj *child) | |
2158 | { | |
2159 | c_describe_child (child->parent, child->index, NULL, NULL, NULL, | |
2160 | &child->path_expr); | |
2161 | return child->path_expr; | |
2162 | } | |
2163 | ||
c5b48eac VP |
2164 | /* If frame associated with VAR can be found, switch |
2165 | to it and return 1. Otherwise, return 0. */ | |
2166 | static int | |
2167 | check_scope (struct varobj *var) | |
2168 | { | |
2169 | struct frame_info *fi; | |
2170 | int scope; | |
2171 | ||
2172 | fi = frame_find_by_id (var->root->frame); | |
2173 | scope = fi != NULL; | |
2174 | ||
2175 | if (fi) | |
2176 | { | |
2177 | CORE_ADDR pc = get_frame_pc (fi); | |
2178 | if (pc < BLOCK_START (var->root->valid_block) || | |
2179 | pc >= BLOCK_END (var->root->valid_block)) | |
2180 | scope = 0; | |
2181 | else | |
2182 | select_frame (fi); | |
2183 | } | |
2184 | return scope; | |
2185 | } | |
2186 | ||
30b28db1 | 2187 | static struct value * |
fba45db2 | 2188 | c_value_of_root (struct varobj **var_handle) |
8b93c638 | 2189 | { |
5e572bb4 | 2190 | struct value *new_val = NULL; |
73a93a32 | 2191 | struct varobj *var = *var_handle; |
8b93c638 | 2192 | struct frame_info *fi; |
c5b48eac | 2193 | int within_scope = 0; |
6208b47d VP |
2194 | struct cleanup *back_to; |
2195 | ||
73a93a32 | 2196 | /* Only root variables can be updated... */ |
b2c2bd75 | 2197 | if (!is_root_p (var)) |
73a93a32 JI |
2198 | /* Not a root var */ |
2199 | return NULL; | |
2200 | ||
6208b47d VP |
2201 | back_to = make_cleanup_restore_current_thread ( |
2202 | inferior_ptid, get_frame_id (deprecated_safe_get_selected_frame ())); | |
72330bd6 | 2203 | |
8b93c638 | 2204 | /* Determine whether the variable is still around. */ |
a5defcdc | 2205 | if (var->root->valid_block == NULL || var->root->floating) |
8b93c638 | 2206 | within_scope = 1; |
c5b48eac VP |
2207 | else if (var->root->thread_id == 0) |
2208 | { | |
2209 | /* The program was single-threaded when the variable object was | |
2210 | created. Technically, it's possible that the program became | |
2211 | multi-threaded since then, but we don't support such | |
2212 | scenario yet. */ | |
2213 | within_scope = check_scope (var); | |
2214 | } | |
8b93c638 JM |
2215 | else |
2216 | { | |
c5b48eac VP |
2217 | ptid_t ptid = thread_id_to_pid (var->root->thread_id); |
2218 | if (in_thread_list (ptid)) | |
d2353924 | 2219 | { |
c5b48eac VP |
2220 | switch_to_thread (ptid); |
2221 | within_scope = check_scope (var); | |
2222 | } | |
8b93c638 | 2223 | } |
72330bd6 | 2224 | |
8b93c638 JM |
2225 | if (within_scope) |
2226 | { | |
73a93a32 | 2227 | /* We need to catch errors here, because if evaluate |
85d93f1d VP |
2228 | expression fails we want to just return NULL. */ |
2229 | gdb_evaluate_expression (var->root->exp, &new_val); | |
8b93c638 JM |
2230 | return new_val; |
2231 | } | |
2232 | ||
6208b47d VP |
2233 | do_cleanups (back_to); |
2234 | ||
8b93c638 JM |
2235 | return NULL; |
2236 | } | |
2237 | ||
30b28db1 | 2238 | static struct value * |
fba45db2 | 2239 | c_value_of_child (struct varobj *parent, int index) |
8b93c638 | 2240 | { |
bbec2603 | 2241 | struct value *value = NULL; |
02142340 | 2242 | c_describe_child (parent, index, NULL, &value, NULL, NULL); |
8b93c638 JM |
2243 | |
2244 | return value; | |
2245 | } | |
2246 | ||
2247 | static struct type * | |
fba45db2 | 2248 | c_type_of_child (struct varobj *parent, int index) |
8b93c638 | 2249 | { |
bbec2603 | 2250 | struct type *type = NULL; |
02142340 | 2251 | c_describe_child (parent, index, NULL, NULL, &type, NULL); |
8b93c638 JM |
2252 | return type; |
2253 | } | |
2254 | ||
8b93c638 | 2255 | static char * |
de051565 | 2256 | c_value_of_variable (struct varobj *var, enum varobj_display_formats format) |
8b93c638 | 2257 | { |
14b3d9c9 JB |
2258 | /* BOGUS: if val_print sees a struct/class, or a reference to one, |
2259 | it will print out its children instead of "{...}". So we need to | |
2260 | catch that case explicitly. */ | |
2261 | struct type *type = get_type (var); | |
e64d9b3d | 2262 | |
14b3d9c9 JB |
2263 | /* Strip top-level references. */ |
2264 | while (TYPE_CODE (type) == TYPE_CODE_REF) | |
2265 | type = check_typedef (TYPE_TARGET_TYPE (type)); | |
2266 | ||
2267 | switch (TYPE_CODE (type)) | |
8b93c638 JM |
2268 | { |
2269 | case TYPE_CODE_STRUCT: | |
2270 | case TYPE_CODE_UNION: | |
2271 | return xstrdup ("{...}"); | |
2272 | /* break; */ | |
2273 | ||
2274 | case TYPE_CODE_ARRAY: | |
2275 | { | |
e64d9b3d | 2276 | char *number; |
b435e160 | 2277 | number = xstrprintf ("[%d]", var->num_children); |
e64d9b3d | 2278 | return (number); |
8b93c638 JM |
2279 | } |
2280 | /* break; */ | |
2281 | ||
2282 | default: | |
2283 | { | |
575bbeb6 KS |
2284 | if (var->value == NULL) |
2285 | { | |
2286 | /* This can happen if we attempt to get the value of a struct | |
2287 | member when the parent is an invalid pointer. This is an | |
2288 | error condition, so we should tell the caller. */ | |
2289 | return NULL; | |
2290 | } | |
2291 | else | |
2292 | { | |
25d5ea92 VP |
2293 | if (var->not_fetched && value_lazy (var->value)) |
2294 | /* Frozen variable and no value yet. We don't | |
2295 | implicitly fetch the value. MI response will | |
2296 | use empty string for the value, which is OK. */ | |
2297 | return NULL; | |
2298 | ||
b2c2bd75 | 2299 | gdb_assert (varobj_value_is_changeable_p (var)); |
acd65feb | 2300 | gdb_assert (!value_lazy (var->value)); |
de051565 MK |
2301 | |
2302 | /* If the specified format is the current one, | |
2303 | we can reuse print_value */ | |
2304 | if (format == var->format) | |
2305 | return xstrdup (var->print_value); | |
2306 | else | |
2307 | return value_get_print_value (var->value, format); | |
85265413 | 2308 | } |
e64d9b3d | 2309 | } |
8b93c638 JM |
2310 | } |
2311 | } | |
2312 | \f | |
2313 | ||
2314 | /* C++ */ | |
2315 | ||
2316 | static int | |
fba45db2 | 2317 | cplus_number_of_children (struct varobj *var) |
8b93c638 JM |
2318 | { |
2319 | struct type *type; | |
2320 | int children, dont_know; | |
2321 | ||
2322 | dont_know = 1; | |
2323 | children = 0; | |
2324 | ||
2325 | if (!CPLUS_FAKE_CHILD (var)) | |
2326 | { | |
2024f65a | 2327 | type = get_value_type (var); |
02142340 | 2328 | adjust_value_for_child_access (NULL, &type, NULL); |
8b93c638 JM |
2329 | |
2330 | if (((TYPE_CODE (type)) == TYPE_CODE_STRUCT) || | |
72330bd6 | 2331 | ((TYPE_CODE (type)) == TYPE_CODE_UNION)) |
8b93c638 JM |
2332 | { |
2333 | int kids[3]; | |
2334 | ||
2335 | cplus_class_num_children (type, kids); | |
2336 | if (kids[v_public] != 0) | |
2337 | children++; | |
2338 | if (kids[v_private] != 0) | |
2339 | children++; | |
2340 | if (kids[v_protected] != 0) | |
2341 | children++; | |
2342 | ||
2343 | /* Add any baseclasses */ | |
2344 | children += TYPE_N_BASECLASSES (type); | |
2345 | dont_know = 0; | |
2346 | ||
2347 | /* FIXME: save children in var */ | |
2348 | } | |
2349 | } | |
2350 | else | |
2351 | { | |
2352 | int kids[3]; | |
2353 | ||
2024f65a | 2354 | type = get_value_type (var->parent); |
02142340 | 2355 | adjust_value_for_child_access (NULL, &type, NULL); |
8b93c638 JM |
2356 | |
2357 | cplus_class_num_children (type, kids); | |
6e382aa3 | 2358 | if (strcmp (var->name, "public") == 0) |
8b93c638 | 2359 | children = kids[v_public]; |
6e382aa3 | 2360 | else if (strcmp (var->name, "private") == 0) |
8b93c638 JM |
2361 | children = kids[v_private]; |
2362 | else | |
2363 | children = kids[v_protected]; | |
2364 | dont_know = 0; | |
2365 | } | |
2366 | ||
2367 | if (dont_know) | |
2368 | children = c_number_of_children (var); | |
2369 | ||
2370 | return children; | |
2371 | } | |
2372 | ||
2373 | /* Compute # of public, private, and protected variables in this class. | |
2374 | That means we need to descend into all baseclasses and find out | |
2375 | how many are there, too. */ | |
2376 | static void | |
1669605f | 2377 | cplus_class_num_children (struct type *type, int children[3]) |
8b93c638 JM |
2378 | { |
2379 | int i; | |
2380 | ||
2381 | children[v_public] = 0; | |
2382 | children[v_private] = 0; | |
2383 | children[v_protected] = 0; | |
2384 | ||
2385 | for (i = TYPE_N_BASECLASSES (type); i < TYPE_NFIELDS (type); i++) | |
2386 | { | |
2387 | /* If we have a virtual table pointer, omit it. */ | |
72330bd6 | 2388 | if (TYPE_VPTR_BASETYPE (type) == type && TYPE_VPTR_FIELDNO (type) == i) |
8b93c638 JM |
2389 | continue; |
2390 | ||
2391 | if (TYPE_FIELD_PROTECTED (type, i)) | |
2392 | children[v_protected]++; | |
2393 | else if (TYPE_FIELD_PRIVATE (type, i)) | |
2394 | children[v_private]++; | |
2395 | else | |
2396 | children[v_public]++; | |
2397 | } | |
2398 | } | |
2399 | ||
2400 | static char * | |
fba45db2 | 2401 | cplus_name_of_variable (struct varobj *parent) |
8b93c638 JM |
2402 | { |
2403 | return c_name_of_variable (parent); | |
2404 | } | |
2405 | ||
2024f65a VP |
2406 | enum accessibility { private_field, protected_field, public_field }; |
2407 | ||
2408 | /* Check if field INDEX of TYPE has the specified accessibility. | |
2409 | Return 0 if so and 1 otherwise. */ | |
2410 | static int | |
2411 | match_accessibility (struct type *type, int index, enum accessibility acc) | |
8b93c638 | 2412 | { |
2024f65a VP |
2413 | if (acc == private_field && TYPE_FIELD_PRIVATE (type, index)) |
2414 | return 1; | |
2415 | else if (acc == protected_field && TYPE_FIELD_PROTECTED (type, index)) | |
2416 | return 1; | |
2417 | else if (acc == public_field && !TYPE_FIELD_PRIVATE (type, index) | |
2418 | && !TYPE_FIELD_PROTECTED (type, index)) | |
2419 | return 1; | |
2420 | else | |
2421 | return 0; | |
2422 | } | |
2423 | ||
2424 | static void | |
2425 | cplus_describe_child (struct varobj *parent, int index, | |
02142340 VP |
2426 | char **cname, struct value **cvalue, struct type **ctype, |
2427 | char **cfull_expression) | |
2024f65a | 2428 | { |
348144ba | 2429 | char *name = NULL; |
2024f65a | 2430 | struct value *value; |
8b93c638 | 2431 | struct type *type; |
02142340 VP |
2432 | int was_ptr; |
2433 | char *parent_expression = NULL; | |
8b93c638 | 2434 | |
2024f65a VP |
2435 | if (cname) |
2436 | *cname = NULL; | |
2437 | if (cvalue) | |
2438 | *cvalue = NULL; | |
2439 | if (ctype) | |
2440 | *ctype = NULL; | |
02142340 VP |
2441 | if (cfull_expression) |
2442 | *cfull_expression = NULL; | |
2024f65a | 2443 | |
8b93c638 JM |
2444 | if (CPLUS_FAKE_CHILD (parent)) |
2445 | { | |
2024f65a VP |
2446 | value = parent->parent->value; |
2447 | type = get_value_type (parent->parent); | |
02142340 VP |
2448 | if (cfull_expression) |
2449 | parent_expression = varobj_get_path_expr (parent->parent); | |
8b93c638 JM |
2450 | } |
2451 | else | |
2024f65a VP |
2452 | { |
2453 | value = parent->value; | |
2454 | type = get_value_type (parent); | |
02142340 VP |
2455 | if (cfull_expression) |
2456 | parent_expression = varobj_get_path_expr (parent); | |
2024f65a | 2457 | } |
8b93c638 | 2458 | |
02142340 | 2459 | adjust_value_for_child_access (&value, &type, &was_ptr); |
2024f65a VP |
2460 | |
2461 | if (TYPE_CODE (type) == TYPE_CODE_STRUCT | |
3f4178d6 | 2462 | || TYPE_CODE (type) == TYPE_CODE_UNION) |
8b93c638 | 2463 | { |
02142340 | 2464 | char *join = was_ptr ? "->" : "."; |
8b93c638 JM |
2465 | if (CPLUS_FAKE_CHILD (parent)) |
2466 | { | |
6e382aa3 JJ |
2467 | /* The fields of the class type are ordered as they |
2468 | appear in the class. We are given an index for a | |
2469 | particular access control type ("public","protected", | |
2470 | or "private"). We must skip over fields that don't | |
2471 | have the access control we are looking for to properly | |
2472 | find the indexed field. */ | |
2473 | int type_index = TYPE_N_BASECLASSES (type); | |
2024f65a | 2474 | enum accessibility acc = public_field; |
6e382aa3 | 2475 | if (strcmp (parent->name, "private") == 0) |
2024f65a | 2476 | acc = private_field; |
6e382aa3 | 2477 | else if (strcmp (parent->name, "protected") == 0) |
2024f65a VP |
2478 | acc = protected_field; |
2479 | ||
2480 | while (index >= 0) | |
6e382aa3 | 2481 | { |
2024f65a VP |
2482 | if (TYPE_VPTR_BASETYPE (type) == type |
2483 | && type_index == TYPE_VPTR_FIELDNO (type)) | |
2484 | ; /* ignore vptr */ | |
2485 | else if (match_accessibility (type, type_index, acc)) | |
6e382aa3 JJ |
2486 | --index; |
2487 | ++type_index; | |
6e382aa3 | 2488 | } |
2024f65a VP |
2489 | --type_index; |
2490 | ||
2491 | if (cname) | |
2492 | *cname = xstrdup (TYPE_FIELD_NAME (type, type_index)); | |
2493 | ||
2494 | if (cvalue && value) | |
2495 | *cvalue = value_struct_element_index (value, type_index); | |
2496 | ||
2497 | if (ctype) | |
2498 | *ctype = TYPE_FIELD_TYPE (type, type_index); | |
02142340 VP |
2499 | |
2500 | if (cfull_expression) | |
2501 | *cfull_expression = xstrprintf ("((%s)%s%s)", parent_expression, | |
2502 | join, | |
2503 | TYPE_FIELD_NAME (type, type_index)); | |
2024f65a VP |
2504 | } |
2505 | else if (index < TYPE_N_BASECLASSES (type)) | |
2506 | { | |
2507 | /* This is a baseclass. */ | |
2508 | if (cname) | |
2509 | *cname = xstrdup (TYPE_FIELD_NAME (type, index)); | |
2510 | ||
2511 | if (cvalue && value) | |
6e382aa3 | 2512 | { |
2024f65a | 2513 | *cvalue = value_cast (TYPE_FIELD_TYPE (type, index), value); |
02142340 | 2514 | release_value (*cvalue); |
6e382aa3 JJ |
2515 | } |
2516 | ||
2024f65a VP |
2517 | if (ctype) |
2518 | { | |
2519 | *ctype = TYPE_FIELD_TYPE (type, index); | |
2520 | } | |
02142340 VP |
2521 | |
2522 | if (cfull_expression) | |
2523 | { | |
2524 | char *ptr = was_ptr ? "*" : ""; | |
2525 | /* Cast the parent to the base' type. Note that in gdb, | |
2526 | expression like | |
2527 | (Base1)d | |
2528 | will create an lvalue, for all appearences, so we don't | |
2529 | need to use more fancy: | |
2530 | *(Base1*)(&d) | |
2531 | construct. */ | |
2532 | *cfull_expression = xstrprintf ("(%s(%s%s) %s)", | |
2533 | ptr, | |
2534 | TYPE_FIELD_NAME (type, index), | |
2535 | ptr, | |
2536 | parent_expression); | |
2537 | } | |
8b93c638 | 2538 | } |
8b93c638 JM |
2539 | else |
2540 | { | |
348144ba | 2541 | char *access = NULL; |
6e382aa3 | 2542 | int children[3]; |
2024f65a | 2543 | cplus_class_num_children (type, children); |
6e382aa3 | 2544 | |
8b93c638 | 2545 | /* Everything beyond the baseclasses can |
6e382aa3 JJ |
2546 | only be "public", "private", or "protected" |
2547 | ||
2548 | The special "fake" children are always output by varobj in | |
2549 | this order. So if INDEX == 2, it MUST be "protected". */ | |
8b93c638 JM |
2550 | index -= TYPE_N_BASECLASSES (type); |
2551 | switch (index) | |
2552 | { | |
2553 | case 0: | |
6e382aa3 | 2554 | if (children[v_public] > 0) |
2024f65a | 2555 | access = "public"; |
6e382aa3 | 2556 | else if (children[v_private] > 0) |
2024f65a | 2557 | access = "private"; |
6e382aa3 | 2558 | else |
2024f65a | 2559 | access = "protected"; |
6e382aa3 | 2560 | break; |
8b93c638 | 2561 | case 1: |
6e382aa3 | 2562 | if (children[v_public] > 0) |
8b93c638 | 2563 | { |
6e382aa3 | 2564 | if (children[v_private] > 0) |
2024f65a | 2565 | access = "private"; |
6e382aa3 | 2566 | else |
2024f65a | 2567 | access = "protected"; |
8b93c638 | 2568 | } |
6e382aa3 | 2569 | else if (children[v_private] > 0) |
2024f65a | 2570 | access = "protected"; |
6e382aa3 | 2571 | break; |
8b93c638 | 2572 | case 2: |
6e382aa3 | 2573 | /* Must be protected */ |
2024f65a | 2574 | access = "protected"; |
6e382aa3 | 2575 | break; |
8b93c638 JM |
2576 | default: |
2577 | /* error! */ | |
2578 | break; | |
2579 | } | |
348144ba MS |
2580 | |
2581 | gdb_assert (access); | |
2024f65a VP |
2582 | if (cname) |
2583 | *cname = xstrdup (access); | |
8b93c638 | 2584 | |
02142340 | 2585 | /* Value and type and full expression are null here. */ |
2024f65a | 2586 | } |
8b93c638 | 2587 | } |
8b93c638 JM |
2588 | else |
2589 | { | |
02142340 | 2590 | c_describe_child (parent, index, cname, cvalue, ctype, cfull_expression); |
2024f65a VP |
2591 | } |
2592 | } | |
8b93c638 | 2593 | |
2024f65a VP |
2594 | static char * |
2595 | cplus_name_of_child (struct varobj *parent, int index) | |
2596 | { | |
2597 | char *name = NULL; | |
02142340 | 2598 | cplus_describe_child (parent, index, &name, NULL, NULL, NULL); |
8b93c638 JM |
2599 | return name; |
2600 | } | |
2601 | ||
02142340 VP |
2602 | static char * |
2603 | cplus_path_expr_of_child (struct varobj *child) | |
2604 | { | |
2605 | cplus_describe_child (child->parent, child->index, NULL, NULL, NULL, | |
2606 | &child->path_expr); | |
2607 | return child->path_expr; | |
2608 | } | |
2609 | ||
30b28db1 | 2610 | static struct value * |
fba45db2 | 2611 | cplus_value_of_root (struct varobj **var_handle) |
8b93c638 | 2612 | { |
73a93a32 | 2613 | return c_value_of_root (var_handle); |
8b93c638 JM |
2614 | } |
2615 | ||
30b28db1 | 2616 | static struct value * |
fba45db2 | 2617 | cplus_value_of_child (struct varobj *parent, int index) |
8b93c638 | 2618 | { |
2024f65a | 2619 | struct value *value = NULL; |
02142340 | 2620 | cplus_describe_child (parent, index, NULL, &value, NULL, NULL); |
8b93c638 JM |
2621 | return value; |
2622 | } | |
2623 | ||
2624 | static struct type * | |
fba45db2 | 2625 | cplus_type_of_child (struct varobj *parent, int index) |
8b93c638 | 2626 | { |
2024f65a | 2627 | struct type *type = NULL; |
02142340 | 2628 | cplus_describe_child (parent, index, NULL, NULL, &type, NULL); |
8b93c638 JM |
2629 | return type; |
2630 | } | |
2631 | ||
8b93c638 | 2632 | static char * |
de051565 | 2633 | cplus_value_of_variable (struct varobj *var, enum varobj_display_formats format) |
8b93c638 JM |
2634 | { |
2635 | ||
2636 | /* If we have one of our special types, don't print out | |
2637 | any value. */ | |
2638 | if (CPLUS_FAKE_CHILD (var)) | |
2639 | return xstrdup (""); | |
2640 | ||
de051565 | 2641 | return c_value_of_variable (var, format); |
8b93c638 JM |
2642 | } |
2643 | \f | |
2644 | /* Java */ | |
2645 | ||
2646 | static int | |
fba45db2 | 2647 | java_number_of_children (struct varobj *var) |
8b93c638 JM |
2648 | { |
2649 | return cplus_number_of_children (var); | |
2650 | } | |
2651 | ||
2652 | static char * | |
fba45db2 | 2653 | java_name_of_variable (struct varobj *parent) |
8b93c638 JM |
2654 | { |
2655 | char *p, *name; | |
2656 | ||
2657 | name = cplus_name_of_variable (parent); | |
2658 | /* If the name has "-" in it, it is because we | |
2659 | needed to escape periods in the name... */ | |
2660 | p = name; | |
2661 | ||
2662 | while (*p != '\000') | |
2663 | { | |
2664 | if (*p == '-') | |
2665 | *p = '.'; | |
2666 | p++; | |
2667 | } | |
2668 | ||
2669 | return name; | |
2670 | } | |
2671 | ||
2672 | static char * | |
fba45db2 | 2673 | java_name_of_child (struct varobj *parent, int index) |
8b93c638 JM |
2674 | { |
2675 | char *name, *p; | |
2676 | ||
2677 | name = cplus_name_of_child (parent, index); | |
2678 | /* Escape any periods in the name... */ | |
2679 | p = name; | |
2680 | ||
2681 | while (*p != '\000') | |
2682 | { | |
2683 | if (*p == '.') | |
2684 | *p = '-'; | |
2685 | p++; | |
2686 | } | |
2687 | ||
2688 | return name; | |
2689 | } | |
2690 | ||
02142340 VP |
2691 | static char * |
2692 | java_path_expr_of_child (struct varobj *child) | |
2693 | { | |
2694 | return NULL; | |
2695 | } | |
2696 | ||
30b28db1 | 2697 | static struct value * |
fba45db2 | 2698 | java_value_of_root (struct varobj **var_handle) |
8b93c638 | 2699 | { |
73a93a32 | 2700 | return cplus_value_of_root (var_handle); |
8b93c638 JM |
2701 | } |
2702 | ||
30b28db1 | 2703 | static struct value * |
fba45db2 | 2704 | java_value_of_child (struct varobj *parent, int index) |
8b93c638 JM |
2705 | { |
2706 | return cplus_value_of_child (parent, index); | |
2707 | } | |
2708 | ||
2709 | static struct type * | |
fba45db2 | 2710 | java_type_of_child (struct varobj *parent, int index) |
8b93c638 JM |
2711 | { |
2712 | return cplus_type_of_child (parent, index); | |
2713 | } | |
2714 | ||
8b93c638 | 2715 | static char * |
de051565 | 2716 | java_value_of_variable (struct varobj *var, enum varobj_display_formats format) |
8b93c638 | 2717 | { |
de051565 | 2718 | return cplus_value_of_variable (var, format); |
8b93c638 JM |
2719 | } |
2720 | \f | |
2721 | extern void _initialize_varobj (void); | |
2722 | void | |
2723 | _initialize_varobj (void) | |
2724 | { | |
2725 | int sizeof_table = sizeof (struct vlist *) * VAROBJ_TABLE_SIZE; | |
2726 | ||
2727 | varobj_table = xmalloc (sizeof_table); | |
2728 | memset (varobj_table, 0, sizeof_table); | |
2729 | ||
85c07804 AC |
2730 | add_setshow_zinteger_cmd ("debugvarobj", class_maintenance, |
2731 | &varobjdebug, _("\ | |
2732 | Set varobj debugging."), _("\ | |
2733 | Show varobj debugging."), _("\ | |
2734 | When non-zero, varobj debugging is enabled."), | |
2735 | NULL, | |
920d2a44 | 2736 | show_varobjdebug, |
85c07804 | 2737 | &setlist, &showlist); |
8b93c638 | 2738 | } |
8756216b DP |
2739 | |
2740 | /* Invalidate the varobjs that are tied to locals and re-create the ones that | |
2741 | are defined on globals. | |
2742 | Invalidated varobjs will be always printed in_scope="invalid". */ | |
2743 | void | |
2744 | varobj_invalidate (void) | |
2745 | { | |
2746 | struct varobj **all_rootvarobj; | |
2747 | struct varobj **varp; | |
2748 | ||
2749 | if (varobj_list (&all_rootvarobj) > 0) | |
2750 | { | |
2751 | varp = all_rootvarobj; | |
2752 | while (*varp != NULL) | |
2753 | { | |
603ba1de VP |
2754 | /* Floating varobjs are reparsed on each stop, so we don't care if |
2755 | the presently parsed expression refers to something that's gone. */ | |
2756 | if ((*varp)->root->floating) | |
2757 | continue; | |
2758 | ||
8756216b DP |
2759 | /* global var must be re-evaluated. */ |
2760 | if ((*varp)->root->valid_block == NULL) | |
2761 | { | |
2762 | struct varobj *tmp_var; | |
2763 | ||
2764 | /* Try to create a varobj with same expression. If we succeed replace | |
2765 | the old varobj, otherwise invalidate it. */ | |
2766 | tmp_var = varobj_create (NULL, (*varp)->name, (CORE_ADDR) 0, USE_CURRENT_FRAME); | |
2767 | if (tmp_var != NULL) | |
2768 | { | |
2769 | tmp_var->obj_name = xstrdup ((*varp)->obj_name); | |
2770 | varobj_delete (*varp, NULL, 0); | |
2771 | install_variable (tmp_var); | |
2772 | } | |
2773 | else | |
2774 | (*varp)->root->is_valid = 0; | |
2775 | } | |
2776 | else /* locals must be invalidated. */ | |
2777 | (*varp)->root->is_valid = 0; | |
2778 | ||
2779 | varp++; | |
2780 | } | |
2781 | xfree (all_rootvarobj); | |
2782 | } | |
2783 | return; | |
2784 | } |