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