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