]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/varobj.c
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / varobj.c
CommitLineData
8b93c638 1/* Implementation of the GDB variable objects API.
bc8332bb 2
1d506c26 3 Copyright (C) 1999-2024 Free Software Foundation, Inc.
8b93c638
JM
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
a9762ec7 7 the Free Software Foundation; either version 3 of the License, or
8b93c638
JM
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
a9762ec7 16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
8b93c638
JM
17
18#include "defs.h"
19#include "value.h"
20#include "expression.h"
21#include "frame.h"
8b93c638 22#include "language.h"
8b93c638 23#include "gdbcmd.h"
d2353924 24#include "block.h"
79a45b7d 25#include "valprint.h"
d322d6d6 26#include "gdbsupport/gdb_regex.h"
8b93c638
JM
27
28#include "varobj.h"
6208b47d
VP
29#include "gdbthread.h"
30#include "inferior.h"
827f100c 31#include "varobj-iter.h"
396af9a1 32#include "parser-defs.h"
0d12e84c 33#include "gdbarch.h"
76deb5d9 34#include <algorithm>
bc20e562 35#include "observable.h"
8b93c638 36
b6313243
TT
37#if HAVE_PYTHON
38#include "python/python.h"
39#include "python/python-internal.h"
50389644
PA
40#else
41typedef int PyObject;
b6313243
TT
42#endif
43
c2c440a9 44/* See varobj.h. */
8b93c638 45
ccce17b0 46unsigned int varobjdebug = 0;
920d2a44
AC
47static void
48show_varobjdebug (struct ui_file *file, int from_tty,
49 struct cmd_list_element *c, const char *value)
50{
6cb06a8c 51 gdb_printf (file, _("Varobj debugging is %s.\n"), value);
920d2a44 52}
8b93c638 53
581e13c1 54/* String representations of gdb's format codes. */
a121b7c1 55const char *varobj_format_string[] =
1c35a88f 56 { "natural", "binary", "decimal", "hexadecimal", "octal", "zero-hexadecimal" };
8b93c638 57
0cc7d26f 58/* True if we want to allow Python-based pretty-printing. */
4c37490d 59static bool pretty_printing = false;
0cc7d26f
TT
60
61void
62varobj_enable_pretty_printing (void)
63{
4c37490d 64 pretty_printing = true;
0cc7d26f
TT
65}
66
8b93c638
JM
67/* Data structures */
68
69/* Every root variable has one of these structures saved in its
4d01a485 70 varobj. */
8b93c638 71struct varobj_root
72330bd6 72{
4d01a485
PA
73 /* The expression for this parent. */
74 expression_up exp;
8b93c638 75
bc20e562
LS
76 /* Cached arch from exp, for use in case exp gets invalidated. */
77 struct gdbarch *gdbarch = nullptr;
78
79 /* Cached language from exp, for use in case exp gets invalidated. */
80 const struct language_defn *language_defn = nullptr;
81
581e13c1 82 /* Block for which this expression is valid. */
9e5b9d2b 83 const struct block *valid_block = NULL;
8b93c638 84
44a67aa7
VP
85 /* The frame for this expression. This field is set iff valid_block is
86 not NULL. */
9e5b9d2b 87 struct frame_id frame = null_frame_id;
8b93c638 88
5d5658a1 89 /* The global thread ID that this varobj_root belongs to. This field
581e13c1 90 is only valid if valid_block is not NULL.
c5b48eac
VP
91 When not 0, indicates which thread 'frame' belongs to.
92 When 0, indicates that the thread list was empty when the varobj_root
93 was created. */
9e5b9d2b 94 int thread_id = 0;
c5b48eac 95
4c37490d 96 /* If true, the -var-update always recomputes the value in the
a5defcdc 97 current thread and frame. Otherwise, variable object is
581e13c1 98 always updated in the specific scope/thread/frame. */
4c37490d 99 bool floating = false;
73a93a32 100
4c37490d 101 /* Flag that indicates validity: set to false when this varobj_root refers
8756216b 102 to symbols that do not exist anymore. */
4c37490d 103 bool is_valid = true;
8756216b 104
f74a5e6f
LS
105 /* Set to true if the varobj was created as tracking a global. */
106 bool global = false;
107
99ad9427
YQ
108 /* Language-related operations for this variable and its
109 children. */
9e5b9d2b 110 const struct lang_varobj_ops *lang_ops = NULL;
8b93c638 111
581e13c1 112 /* The varobj for this root node. */
9e5b9d2b 113 struct varobj *rootvar = NULL;
72330bd6 114};
8b93c638 115
bb5ce47a 116/* Dynamic part of varobj. */
8b93c638 117
bb5ce47a
YQ
118struct varobj_dynamic
119{
b6313243
TT
120 /* Whether the children of this varobj were requested. This field is
121 used to decide if dynamic varobj should recompute their children.
122 In the event that the frontend never asked for the children, we
123 can avoid that. */
bd046f64 124 bool children_requested = false;
b6313243 125
0cc7d26f
TT
126 /* The pretty-printer constructor. If NULL, then the default
127 pretty-printer will be looked up. If None, then no
128 pretty-printer will be installed. */
9e5b9d2b 129 PyObject *constructor = NULL;
0cc7d26f 130
b6313243
TT
131 /* The pretty-printer that has been constructed. If NULL, then a
132 new printer object is needed, and one will be constructed. */
9e5b9d2b 133 PyObject *pretty_printer = NULL;
0cc7d26f
TT
134
135 /* The iterator returned by the printer's 'children' method, or NULL
136 if not available. */
24fd95b4 137 std::unique_ptr<varobj_iter> child_iter;
0cc7d26f
TT
138
139 /* We request one extra item from the iterator, so that we can
140 report to the caller whether there are more items than we have
141 already reported. However, we don't want to install this value
142 when we read it, because that will mess up future updates. So,
143 we stash it here instead. */
74462664 144 std::unique_ptr<varobj_item> saved_item;
72330bd6 145};
8b93c638 146
8b93c638
JM
147/* Private function prototypes */
148
581e13c1 149/* Helper functions for the above subcommands. */
8b93c638 150
4c37490d 151static int delete_variable (struct varobj *, bool);
8b93c638 152
4c37490d 153static void delete_variable_1 (int *, struct varobj *, bool, bool);
8b93c638 154
07d9937a 155static void install_variable (struct varobj *);
8b93c638 156
a14ed312 157static void uninstall_variable (struct varobj *);
8b93c638 158
2f408ecb 159static struct varobj *create_child (struct varobj *, int, std::string &);
8b93c638 160
b6313243 161static struct varobj *
5a2e0d6e
YQ
162create_child_with_value (struct varobj *parent, int index,
163 struct varobj_item *item);
b6313243 164
8b93c638
JM
165/* Utility routines */
166
4c37490d
SM
167static bool update_type_if_necessary (struct varobj *var,
168 struct value *new_value);
8264ba82 169
4c37490d
SM
170static bool install_new_value (struct varobj *var, struct value *value,
171 bool initial);
acd65feb 172
581e13c1 173/* Language-specific routines. */
8b93c638 174
b09e2c59 175static int number_of_children (const struct varobj *);
8b93c638 176
2f408ecb 177static std::string name_of_variable (const struct varobj *);
8b93c638 178
2f408ecb 179static std::string name_of_child (struct varobj *, int);
8b93c638 180
4c37490d 181static struct value *value_of_root (struct varobj **var_handle, bool *);
8b93c638 182
c1cc6152 183static struct value *value_of_child (const struct varobj *parent, int index);
8b93c638 184
2f408ecb
PA
185static std::string my_value_of_variable (struct varobj *var,
186 enum varobj_display_formats format);
8b93c638 187
4c37490d 188static bool is_root_p (const struct varobj *var);
8b93c638 189
9a1edae6 190static struct varobj *varobj_add_child (struct varobj *var,
5a2e0d6e 191 struct varobj_item *item);
b6313243 192
8b93c638
JM
193/* Private data */
194
581e13c1 195/* Mappings of varobj_display_formats enums to gdb's format codes. */
1c35a88f 196static int format_code[] = { 0, 't', 'd', 'x', 'o', 'z' };
8b93c638 197
76deb5d9
TT
198/* List of root variable objects. */
199static std::list<struct varobj_root *> rootlist;
8b93c638 200
581e13c1 201/* Pointer to the varobj hash table (built at run time). */
2c1413a9 202static htab_t varobj_table;
8b93c638 203
8b93c638
JM
204\f
205
206/* API Implementation */
4c37490d 207static bool
b09e2c59 208is_root_p (const struct varobj *var)
b2c2bd75
VP
209{
210 return (var->root->rootvar == var);
211}
8b93c638 212
d452c4bc 213#ifdef HAVE_PYTHON
6cd67bea
TT
214
215/* See python-internal.h. */
216gdbpy_enter_varobj::gdbpy_enter_varobj (const struct varobj *var)
bc20e562 217: gdbpy_enter (var->root->gdbarch, var->root->language_defn)
6cd67bea
TT
218{
219}
220
d452c4bc
UW
221#endif
222
7d8547c9
AC
223/* Return the full FRAME which corresponds to the given CORE_ADDR
224 or NULL if no FRAME on the chain corresponds to CORE_ADDR. */
225
bd2b40ac 226static frame_info_ptr
7d8547c9
AC
227find_frame_addr_in_frame_chain (CORE_ADDR frame_addr)
228{
bd2b40ac 229 frame_info_ptr frame = NULL;
7d8547c9
AC
230
231 if (frame_addr == (CORE_ADDR) 0)
232 return NULL;
233
9d49bdc2
PA
234 for (frame = get_current_frame ();
235 frame != NULL;
236 frame = get_prev_frame (frame))
7d8547c9 237 {
1fac167a
UW
238 /* The CORE_ADDR we get as argument was parsed from a string GDB
239 output as $fp. This output got truncated to gdbarch_addr_bit.
240 Truncate the frame base address in the same manner before
241 comparing it against our argument. */
242 CORE_ADDR frame_base = get_frame_base_address (frame);
243 int addr_bit = gdbarch_addr_bit (get_frame_arch (frame));
a109c7c1 244
1fac167a
UW
245 if (addr_bit < (sizeof (CORE_ADDR) * HOST_CHAR_BIT))
246 frame_base &= ((CORE_ADDR) 1 << addr_bit) - 1;
247
248 if (frame_base == frame_addr)
7d8547c9
AC
249 return frame;
250 }
9d49bdc2
PA
251
252 return NULL;
7d8547c9
AC
253}
254
5fa13070
SM
255/* Creates a varobj (not its children). */
256
8b93c638 257struct varobj *
2f408ecb
PA
258varobj_create (const char *objname,
259 const char *expression, CORE_ADDR frame, enum varobj_type type)
8b93c638 260{
581e13c1 261 /* Fill out a varobj structure for the (root) variable being constructed. */
6b62451a 262 auto var = std::make_unique<varobj> (new varobj_root);
8b93c638
JM
263
264 if (expression != NULL)
265 {
bd2b40ac 266 frame_info_ptr fi;
35633fef 267 struct frame_id old_id = null_frame_id;
3977b71f 268 const struct block *block;
bbc13ae3 269 const char *p;
e55dccf0 270 struct value *value = NULL;
1bb9788d 271 CORE_ADDR pc;
8b93c638 272
9d49bdc2 273 /* Parse and evaluate the expression, filling in as much of the
dda83cd7 274 variable's data as possible. */
9d49bdc2
PA
275
276 if (has_stack_frames ())
277 {
581e13c1 278 /* Allow creator to specify context of variable. */
9d49bdc2
PA
279 if ((type == USE_CURRENT_FRAME) || (type == USE_SELECTED_FRAME))
280 fi = get_selected_frame (NULL);
281 else
282 /* FIXME: cagney/2002-11-23: This code should be doing a
283 lookup using the frame ID and not just the frame's
284 ``address''. This, of course, means an interface
285 change. However, with out that interface change ISAs,
286 such as the ia64 with its two stacks, won't work.
287 Similar goes for the case where there is a frameless
288 function. */
289 fi = find_frame_addr_in_frame_chain (frame);
290 }
8b93c638 291 else
9d49bdc2 292 fi = NULL;
8b93c638 293
73a93a32 294 if (type == USE_SELECTED_FRAME)
4c37490d 295 var->root->floating = true;
73a93a32 296
1bb9788d 297 pc = 0;
8b93c638
JM
298 block = NULL;
299 if (fi != NULL)
1bb9788d
TT
300 {
301 block = get_frame_block (fi, 0);
302 pc = get_frame_pc (fi);
303 }
8b93c638
JM
304
305 p = expression;
699bd4cf
TT
306
307 innermost_block_tracker tracker (INNERMOST_BLOCK_FOR_SYMBOLS
308 | INNERMOST_BLOCK_FOR_REGISTERS);
73a93a32 309 /* Wrap the call to parse expression, so we can
dda83cd7 310 return a sensible error. */
a70b8144 311 try
8e7b59a5 312 {
699bd4cf 313 var->root->exp = parse_exp_1 (&p, pc, block, 0, &tracker);
bc20e562
LS
314
315 /* Cache gdbarch and language_defn as they might be used even
316 after var is invalidated and var->root->exp cleared. */
317 var->root->gdbarch = var->root->exp->gdbarch;
318 var->root->language_defn = var->root->exp->language_defn;
8e7b59a5
KS
319 }
320
230d2906 321 catch (const gdb_exception_error &except)
73a93a32
JI
322 {
323 return NULL;
324 }
8b93c638 325
581e13c1 326 /* Don't allow variables to be created for types. */
2adab65c
TT
327 enum exp_opcode opcode = var->root->exp->first_opcode ();
328 if (opcode == OP_TYPE
329 || opcode == OP_TYPEOF
330 || opcode == OP_DECLTYPE)
8b93c638 331 {
6cb06a8c
TT
332 gdb_printf (gdb_stderr, "Attempt to use a type name"
333 " as an expression.\n");
8b93c638
JM
334 return NULL;
335 }
336
78dfcce3 337 var->format = FORMAT_NATURAL;
e707fc44 338 var->root->valid_block =
699bd4cf 339 var->root->floating ? NULL : tracker.block ();
f74a5e6f
LS
340 var->root->global
341 = var->root->floating ? false : var->root->valid_block == nullptr;
2f408ecb 342 var->name = expression;
02142340 343 /* For a root var, the name and the expr are the same. */
2f408ecb 344 var->path_expr = expression;
8b93c638
JM
345
346 /* When the frame is different from the current frame,
dda83cd7
SM
347 we must select the appropriate frame before parsing
348 the expression, otherwise the value will not be current.
349 Since select_frame is so benign, just call it for all cases. */
aee1fcdf 350 if (var->root->valid_block)
8b93c638 351 {
4e22772d
JK
352 /* User could specify explicit FRAME-ADDR which was not found but
353 EXPRESSION is frame specific and we would not be able to evaluate
354 it correctly next time. With VALID_BLOCK set we must also set
355 FRAME and THREAD_ID. */
356 if (fi == NULL)
357 error (_("Failed to find the specified frame"));
358
7a424e99 359 var->root->frame = get_frame_id (fi);
00431a78 360 var->root->thread_id = inferior_thread ()->global_num;
35633fef 361 old_id = get_frame_id (get_selected_frame (NULL));
c5b48eac 362 select_frame (fi);
8b93c638
JM
363 }
364
43048e46
TT
365 /* We definitely need to catch errors here. If evaluation of
366 the expression succeeds, we got the value we wanted. But if
367 it fails, we still go on with a call to evaluate_type(). */
a70b8144 368 try
8e7b59a5 369 {
43048e46 370 value = var->root->exp->evaluate ();
8e7b59a5 371 }
230d2906 372 catch (const gdb_exception_error &except)
e55dccf0
VP
373 {
374 /* Error getting the value. Try to at least get the
375 right type. */
ba71385e 376 struct value *type_only_value = var->root->exp->evaluate_type ();
a109c7c1 377
d0c97917 378 var->type = type_only_value->type ();
e55dccf0 379 }
8264ba82 380
492d29ea
PA
381 if (value != NULL)
382 {
383 int real_type_found = 0;
384
385 var->type = value_actual_type (value, 0, &real_type_found);
386 if (real_type_found)
387 value = value_cast (var->type, value);
388 }
acd65feb 389
8b93c638 390 /* Set language info */
b63a3f3f 391 var->root->lang_ops = var->root->exp->language_defn->varobj_ops ();
8b93c638 392
9e5b9d2b 393 install_new_value (var.get (), value, 1 /* Initial assignment */);
d32cafc7 394
581e13c1 395 /* Set ourselves as our root. */
9e5b9d2b 396 var->root->rootvar = var.get ();
8b93c638 397
581e13c1 398 /* Reset the selected frame. */
35633fef
JK
399 if (frame_id_p (old_id))
400 select_frame (frame_find_by_id (old_id));
8b93c638
JM
401 }
402
73a93a32 403 /* If the variable object name is null, that means this
581e13c1 404 is a temporary variable, so don't install it. */
73a93a32
JI
405
406 if ((var != NULL) && (objname != NULL))
8b93c638 407 {
2f408ecb 408 var->obj_name = objname;
07d9937a 409 install_variable (var.get ());
8b93c638
JM
410 }
411
9e5b9d2b 412 return var.release ();
8b93c638
JM
413}
414
581e13c1 415/* Generates an unique name that can be used for a varobj. */
8b93c638 416
2d6960b4 417std::string
8b93c638
JM
418varobj_gen_name (void)
419{
420 static int id = 0;
8b93c638 421
581e13c1 422 /* Generate a name for this object. */
8b93c638 423 id++;
2d6960b4 424 return string_printf ("var%d", id);
8b93c638
JM
425}
426
61d8f275
JK
427/* Given an OBJNAME, returns the pointer to the corresponding varobj. Call
428 error if OBJNAME cannot be found. */
8b93c638
JM
429
430struct varobj *
2f408ecb 431varobj_get_handle (const char *objname)
8b93c638 432{
2c1413a9
TT
433 varobj *var = (varobj *) htab_find_with_hash (varobj_table, objname,
434 htab_hash_string (objname));
8b93c638 435
2c1413a9 436 if (var == NULL)
8a3fe4f8 437 error (_("Variable object not found"));
8b93c638 438
2c1413a9 439 return var;
8b93c638
JM
440}
441
581e13c1 442/* Given the handle, return the name of the object. */
8b93c638 443
2f408ecb 444const char *
b09e2c59 445varobj_get_objname (const struct varobj *var)
8b93c638 446{
2f408ecb 447 return var->obj_name.c_str ();
8b93c638
JM
448}
449
2f408ecb
PA
450/* Given the handle, return the expression represented by the
451 object. */
8b93c638 452
2f408ecb 453std::string
b09e2c59 454varobj_get_expression (const struct varobj *var)
8b93c638
JM
455{
456 return name_of_variable (var);
457}
458
30914ca8 459/* See varobj.h. */
8b93c638
JM
460
461int
4c37490d 462varobj_delete (struct varobj *var, bool only_children)
8b93c638 463{
30914ca8 464 return delete_variable (var, only_children);
8b93c638
JM
465}
466
d8b65138
JK
467#if HAVE_PYTHON
468
b6313243
TT
469/* Convenience function for varobj_set_visualizer. Instantiate a
470 pretty-printer for a given value. */
471static PyObject *
472instantiate_pretty_printer (PyObject *constructor, struct value *value)
473{
1345dee2
TT
474 gdbpy_ref<> val_obj (value_to_value_object (value));
475 if (val_obj == nullptr)
b6313243
TT
476 return NULL;
477
1345dee2 478 return PyObject_CallFunctionObjArgs (constructor, val_obj.get (), NULL);
b6313243
TT
479}
480
d8b65138
JK
481#endif
482
581e13c1 483/* Set/Get variable object display format. */
8b93c638
JM
484
485enum varobj_display_formats
486varobj_set_display_format (struct varobj *var,
487 enum varobj_display_formats format)
488{
665b55a9 489 var->format = format;
8b93c638 490
ae7d22a6 491 if (varobj_value_is_changeable_p (var)
f28085df 492 && var->value != nullptr && !var->value->lazy ())
ae7d22a6 493 {
b4d61099 494 var->print_value = varobj_value_get_print_value (var->value.get (),
99ad9427 495 var->format, var);
ae7d22a6
VP
496 }
497
8b93c638
JM
498 return var->format;
499}
500
501enum varobj_display_formats
b09e2c59 502varobj_get_display_format (const struct varobj *var)
8b93c638
JM
503{
504 return var->format;
505}
506
9b972014 507gdb::unique_xmalloc_ptr<char>
b09e2c59 508varobj_get_display_hint (const struct varobj *var)
b6313243 509{
9b972014 510 gdb::unique_xmalloc_ptr<char> result;
b6313243
TT
511
512#if HAVE_PYTHON
0646da15
TT
513 if (!gdb_python_initialized)
514 return NULL;
515
bde7b3e3 516 gdbpy_enter_varobj enter_py (var);
d452c4bc 517
bb5ce47a
YQ
518 if (var->dynamic->pretty_printer != NULL)
519 result = gdbpy_get_display_hint (var->dynamic->pretty_printer);
b6313243
TT
520#endif
521
522 return result;
523}
524
0cc7d26f
TT
525/* Return true if the varobj has items after TO, false otherwise. */
526
4c37490d 527bool
b09e2c59 528varobj_has_more (const struct varobj *var, int to)
0cc7d26f 529{
ddf0ea08 530 if (var->children.size () > to)
4c37490d 531 return true;
ddf0ea08
SM
532
533 return ((to == -1 || var->children.size () == to)
bb5ce47a 534 && (var->dynamic->saved_item != NULL));
0cc7d26f
TT
535}
536
c5b48eac
VP
537/* If the variable object is bound to a specific thread, that
538 is its evaluation can always be done in context of a frame
539 inside that thread, returns GDB id of the thread -- which
581e13c1 540 is always positive. Otherwise, returns -1. */
c5b48eac 541int
b09e2c59 542varobj_get_thread_id (const struct varobj *var)
c5b48eac
VP
543{
544 if (var->root->valid_block && var->root->thread_id > 0)
545 return var->root->thread_id;
546 else
547 return -1;
548}
549
25d5ea92 550void
4c37490d 551varobj_set_frozen (struct varobj *var, bool frozen)
25d5ea92
VP
552{
553 /* When a variable is unfrozen, we don't fetch its value.
554 The 'not_fetched' flag remains set, so next -var-update
555 won't complain.
556
557 We don't fetch the value, because for structures the client
558 should do -var-update anyway. It would be bad to have different
559 client-size logic for structure and other types. */
560 var->frozen = frozen;
561}
562
4c37490d 563bool
b09e2c59 564varobj_get_frozen (const struct varobj *var)
25d5ea92
VP
565{
566 return var->frozen;
567}
568
791b7405
AB
569/* A helper function that updates the contents of FROM and TO based on the
570 size of the vector CHILDREN. If the contents of either FROM or TO are
571 negative the entire range is used. */
0cc7d26f 572
99ad9427 573void
ddf0ea08
SM
574varobj_restrict_range (const std::vector<varobj *> &children,
575 int *from, int *to)
0cc7d26f 576{
ddf0ea08
SM
577 int len = children.size ();
578
0cc7d26f
TT
579 if (*from < 0 || *to < 0)
580 {
581 *from = 0;
ddf0ea08 582 *to = len;
0cc7d26f
TT
583 }
584 else
585 {
ddf0ea08
SM
586 if (*from > len)
587 *from = len;
588 if (*to > len)
589 *to = len;
0cc7d26f
TT
590 if (*from > *to)
591 *from = *to;
592 }
593}
594
595/* A helper for update_dynamic_varobj_children that installs a new
596 child when needed. */
597
598static void
599install_dynamic_child (struct varobj *var,
0604393c
SM
600 std::vector<varobj *> *changed,
601 std::vector<varobj *> *type_changed,
602 std::vector<varobj *> *newobj,
603 std::vector<varobj *> *unchanged,
4c37490d 604 bool *cchanged,
0cc7d26f 605 int index,
5a2e0d6e 606 struct varobj_item *item)
0cc7d26f 607{
ddf0ea08 608 if (var->children.size () < index + 1)
0cc7d26f
TT
609 {
610 /* There's no child yet. */
5a2e0d6e 611 struct varobj *child = varobj_add_child (var, item);
a109c7c1 612
0604393c 613 if (newobj != NULL)
0cc7d26f 614 {
0604393c 615 newobj->push_back (child);
4c37490d 616 *cchanged = true;
0cc7d26f
TT
617 }
618 }
bf8793bb 619 else
0cc7d26f 620 {
ddf0ea08 621 varobj *existing = var->children[index];
11106495
TT
622 bool type_updated = update_type_if_necessary (existing,
623 item->value.get ());
bf8793bb 624
8264ba82
AG
625 if (type_updated)
626 {
0604393c
SM
627 if (type_changed != NULL)
628 type_changed->push_back (existing);
8264ba82 629 }
11106495 630 if (install_new_value (existing, item->value.get (), 0))
0cc7d26f 631 {
0604393c
SM
632 if (!type_updated && changed != NULL)
633 changed->push_back (existing);
0cc7d26f 634 }
0604393c
SM
635 else if (!type_updated && unchanged != NULL)
636 unchanged->push_back (existing);
0cc7d26f
TT
637 }
638}
639
e5250216
YQ
640/* A factory for creating dynamic varobj's iterators. Returns an
641 iterator object suitable for iterating over VAR's children. */
642
24fd95b4 643static std::unique_ptr<varobj_iter>
e5250216
YQ
644varobj_get_iterator (struct varobj *var)
645{
576ea091 646#if HAVE_PYTHON
e5250216 647 if (var->dynamic->pretty_printer)
c4a3dbaf
TT
648 {
649 value_print_options opts;
650 varobj_formatted_print_options (&opts, var->format);
651 return py_varobj_get_iterator (var, var->dynamic->pretty_printer, &opts);
652 }
576ea091 653#endif
e5250216 654
557b4d76 655 gdb_assert_not_reached ("requested an iterator from a non-dynamic varobj");
e5250216
YQ
656}
657
4c37490d 658static bool
b6313243 659update_dynamic_varobj_children (struct varobj *var,
0604393c
SM
660 std::vector<varobj *> *changed,
661 std::vector<varobj *> *type_changed,
662 std::vector<varobj *> *newobj,
663 std::vector<varobj *> *unchanged,
4c37490d
SM
664 bool *cchanged,
665 bool update_children,
0cc7d26f
TT
666 int from,
667 int to)
b6313243 668{
b6313243 669 int i;
b6313243 670
4c37490d 671 *cchanged = false;
b6313243 672
bb5ce47a 673 if (update_children || var->dynamic->child_iter == NULL)
b6313243 674 {
e5250216 675 var->dynamic->child_iter = varobj_get_iterator (var);
446d2c03 676 var->dynamic->saved_item.reset (nullptr);
b6313243 677
e5250216 678 i = 0;
b6313243 679
bb5ce47a 680 if (var->dynamic->child_iter == NULL)
4c37490d 681 return false;
b6313243 682 }
0cc7d26f 683 else
ddf0ea08 684 i = var->children.size ();
b6313243 685
0cc7d26f
TT
686 /* We ask for one extra child, so that MI can report whether there
687 are more children. */
688 for (; to < 0 || i < to + 1; ++i)
b6313243 689 {
60ee72f6 690 std::unique_ptr<varobj_item> item;
b6313243 691
0cc7d26f 692 /* See if there was a leftover from last time. */
827f100c 693 if (var->dynamic->saved_item != NULL)
74462664 694 item = std::move (var->dynamic->saved_item);
0cc7d26f 695 else
11106495 696 item = var->dynamic->child_iter->next ();
b6313243 697
e5250216
YQ
698 if (item == NULL)
699 {
700 /* Iteration is done. Remove iterator from VAR. */
24fd95b4 701 var->dynamic->child_iter.reset (nullptr);
e5250216
YQ
702 break;
703 }
0cc7d26f
TT
704 /* We don't want to push the extra child on any report list. */
705 if (to < 0 || i < to)
b6313243 706 {
4c37490d 707 bool can_mention = from < 0 || i >= from;
0cc7d26f 708
0cc7d26f 709 install_dynamic_child (var, can_mention ? changed : NULL,
8264ba82 710 can_mention ? type_changed : NULL,
fe978cb0 711 can_mention ? newobj : NULL,
0cc7d26f 712 can_mention ? unchanged : NULL,
5e5ac9a5 713 can_mention ? cchanged : NULL, i,
60ee72f6 714 item.get ());
b6313243 715 }
0cc7d26f 716 else
b6313243 717 {
74462664 718 var->dynamic->saved_item = std::move (item);
b6313243 719
0cc7d26f
TT
720 /* We want to truncate the child list just before this
721 element. */
722 break;
723 }
b6313243
TT
724 }
725
ddf0ea08 726 if (i < var->children.size ())
b6313243 727 {
4c37490d 728 *cchanged = true;
ddf0ea08
SM
729 for (int j = i; j < var->children.size (); ++j)
730 varobj_delete (var->children[j], 0);
731
732 var->children.resize (i);
b6313243 733 }
0cc7d26f
TT
734
735 /* If there are fewer children than requested, note that the list of
736 children changed. */
ddf0ea08 737 if (to >= 0 && var->children.size () < to)
4c37490d 738 *cchanged = true;
0cc7d26f 739
ddf0ea08 740 var->num_children = var->children.size ();
b6313243 741
4c37490d 742 return true;
b6313243 743}
25d5ea92 744
8b93c638
JM
745int
746varobj_get_num_children (struct varobj *var)
747{
748 if (var->num_children == -1)
b6313243 749 {
31f628ae 750 if (varobj_is_dynamic_p (var))
0cc7d26f 751 {
4c37490d 752 bool dummy;
0cc7d26f
TT
753
754 /* If we have a dynamic varobj, don't report -1 children.
755 So, try to fetch some children first. */
8264ba82 756 update_dynamic_varobj_children (var, NULL, NULL, NULL, NULL, &dummy,
4c37490d 757 false, 0, 0);
0cc7d26f
TT
758 }
759 else
b6313243
TT
760 var->num_children = number_of_children (var);
761 }
8b93c638 762
0cc7d26f 763 return var->num_children >= 0 ? var->num_children : 0;
8b93c638
JM
764}
765
766/* Creates a list of the immediate children of a variable object;
581e13c1 767 the return code is the number of such children or -1 on error. */
8b93c638 768
ddf0ea08 769const std::vector<varobj *> &
0cc7d26f 770varobj_list_children (struct varobj *var, int *from, int *to)
8b93c638 771{
bd046f64 772 var->dynamic->children_requested = true;
b6313243 773
31f628ae 774 if (varobj_is_dynamic_p (var))
0cc7d26f 775 {
4c37490d
SM
776 bool children_changed;
777
b6313243
TT
778 /* This, in theory, can result in the number of children changing without
779 frontend noticing. But well, calling -var-list-children on the same
780 varobj twice is not something a sane frontend would do. */
8264ba82 781 update_dynamic_varobj_children (var, NULL, NULL, NULL, NULL,
4c37490d 782 &children_changed, false, 0, *to);
99ad9427 783 varobj_restrict_range (var->children, from, to);
0cc7d26f
TT
784 return var->children;
785 }
8b93c638 786
8b93c638
JM
787 if (var->num_children == -1)
788 var->num_children = number_of_children (var);
789
74a44383
DJ
790 /* If that failed, give up. */
791 if (var->num_children == -1)
d56d46f5 792 return var->children;
74a44383 793
28335dcc
VP
794 /* If we're called when the list of children is not yet initialized,
795 allocate enough elements in it. */
ddf0ea08
SM
796 while (var->children.size () < var->num_children)
797 var->children.push_back (NULL);
28335dcc 798
ddf0ea08 799 for (int i = 0; i < var->num_children; i++)
8b93c638 800 {
ddf0ea08 801 if (var->children[i] == NULL)
28335dcc
VP
802 {
803 /* Either it's the first call to varobj_list_children for
804 this variable object, and the child was never created,
805 or it was explicitly deleted by the client. */
2f408ecb 806 std::string name = name_of_child (var, i);
ddf0ea08 807 var->children[i] = create_child (var, i, name);
28335dcc 808 }
8b93c638
JM
809 }
810
99ad9427 811 varobj_restrict_range (var->children, from, to);
d56d46f5 812 return var->children;
8b93c638
JM
813}
814
b6313243 815static struct varobj *
5a2e0d6e 816varobj_add_child (struct varobj *var, struct varobj_item *item)
b6313243 817{
ddf0ea08
SM
818 varobj *v = create_child_with_value (var, var->children.size (), item);
819
820 var->children.push_back (v);
a109c7c1 821
b6313243
TT
822 return v;
823}
824
8b93c638 825/* Obtain the type of an object Variable as a string similar to the one gdb
afa269ae
SM
826 prints on the console. The caller is responsible for freeing the string.
827 */
8b93c638 828
2f408ecb 829std::string
8b93c638
JM
830varobj_get_type (struct varobj *var)
831{
8ab91b96 832 /* For the "fake" variables, do not return a type. (Its type is
8756216b
DP
833 NULL, too.)
834 Do not return a type for invalid variables as well. */
835 if (CPLUS_FAKE_CHILD (var) || !var->root->is_valid)
2f408ecb 836 return std::string ();
8b93c638 837
1a4300e9 838 return type_to_string (var->type);
8b93c638
JM
839}
840
1ecb4ee0
DJ
841/* Obtain the type of an object variable. */
842
843struct type *
b09e2c59 844varobj_get_gdb_type (const struct varobj *var)
1ecb4ee0
DJ
845{
846 return var->type;
847}
848
85254831
KS
849/* Is VAR a path expression parent, i.e., can it be used to construct
850 a valid path expression? */
851
4c37490d 852static bool
b09e2c59 853is_path_expr_parent (const struct varobj *var)
85254831 854{
9a9a7608
AB
855 gdb_assert (var->root->lang_ops->is_path_expr_parent != NULL);
856 return var->root->lang_ops->is_path_expr_parent (var);
857}
85254831 858
9a9a7608
AB
859/* Is VAR a path expression parent, i.e., can it be used to construct
860 a valid path expression? By default we assume any VAR can be a path
861 parent. */
85254831 862
4c37490d 863bool
b09e2c59 864varobj_default_is_path_expr_parent (const struct varobj *var)
9a9a7608 865{
4c37490d 866 return true;
85254831
KS
867}
868
869/* Return the path expression parent for VAR. */
870
c1cc6152
SM
871const struct varobj *
872varobj_get_path_expr_parent (const struct varobj *var)
85254831 873{
c1cc6152 874 const struct varobj *parent = var;
85254831
KS
875
876 while (!is_root_p (parent) && !is_path_expr_parent (parent))
877 parent = parent->parent;
878
5abe0f0c
JV
879 /* Computation of full rooted expression for children of dynamic
880 varobjs is not supported. */
881 if (varobj_is_dynamic_p (parent))
882 error (_("Invalid variable object (child of a dynamic varobj)"));
883
85254831
KS
884 return parent;
885}
886
02142340
VP
887/* Return a pointer to the full rooted expression of varobj VAR.
888 If it has not been computed yet, compute it. */
2f408ecb
PA
889
890const char *
c1cc6152 891varobj_get_path_expr (const struct varobj *var)
02142340 892{
2f408ecb 893 if (var->path_expr.empty ())
02142340
VP
894 {
895 /* For root varobjs, we initialize path_expr
896 when creating varobj, so here it should be
897 child varobj. */
c1cc6152 898 struct varobj *mutable_var = (struct varobj *) var;
02142340 899 gdb_assert (!is_root_p (var));
2568868e 900
c1cc6152 901 mutable_var->path_expr = (*var->root->lang_ops->path_expr_of_child) (var);
02142340 902 }
2568868e 903
2f408ecb 904 return var->path_expr.c_str ();
02142340
VP
905}
906
fa4d0c40 907const struct language_defn *
b09e2c59 908varobj_get_language (const struct varobj *var)
8b93c638 909{
fa4d0c40 910 return var->root->exp->language_defn;
8b93c638
JM
911}
912
913int
b09e2c59 914varobj_get_attributes (const struct varobj *var)
8b93c638
JM
915{
916 int attributes = 0;
917
340a7723 918 if (varobj_editable_p (var))
581e13c1 919 /* FIXME: define masks for attributes. */
8b93c638
JM
920 attributes |= 0x00000001; /* Editable */
921
922 return attributes;
923}
924
cde5ef40
YQ
925/* Return true if VAR is a dynamic varobj. */
926
4c37490d 927bool
b09e2c59 928varobj_is_dynamic_p (const struct varobj *var)
0cc7d26f 929{
bb5ce47a 930 return var->dynamic->pretty_printer != NULL;
0cc7d26f
TT
931}
932
2f408ecb 933std::string
de051565
MK
934varobj_get_formatted_value (struct varobj *var,
935 enum varobj_display_formats format)
936{
937 return my_value_of_variable (var, format);
938}
939
2f408ecb 940std::string
8b93c638
JM
941varobj_get_value (struct varobj *var)
942{
de051565 943 return my_value_of_variable (var, var->format);
8b93c638
JM
944}
945
946/* Set the value of an object variable (if it is editable) to the
581e13c1
MS
947 value of the given expression. */
948/* Note: Invokes functions that can call error(). */
8b93c638 949
4c37490d 950bool
2f408ecb 951varobj_set_value (struct varobj *var, const char *expression)
8b93c638 952{
34365054 953 struct value *val = NULL; /* Initialize to keep gcc happy. */
8b93c638 954 /* The argument "expression" contains the variable's new value.
581e13c1
MS
955 We need to first construct a legal expression for this -- ugh! */
956 /* Does this cover all the bases? */
34365054 957 struct value *value = NULL; /* Initialize to keep gcc happy. */
bbc13ae3 958 const char *s = expression;
8b93c638 959
340a7723 960 gdb_assert (varobj_editable_p (var));
8b93c638 961
b6fc08e8
TT
962 /* ALWAYS reset to decimal temporarily. */
963 auto save_input_radix = make_scoped_restore (&input_radix, 10);
4d01a485 964 expression_up exp = parse_exp_1 (&s, 0, 0, 0);
a70b8144 965 try
8e7b59a5 966 {
43048e46 967 value = exp->evaluate ();
8e7b59a5
KS
968 }
969
230d2906 970 catch (const gdb_exception_error &except)
340a7723 971 {
581e13c1 972 /* We cannot proceed without a valid expression. */
4c37490d 973 return false;
8b93c638
JM
974 }
975
340a7723
NR
976 /* All types that are editable must also be changeable. */
977 gdb_assert (varobj_value_is_changeable_p (var));
978
979 /* The value of a changeable variable object must not be lazy. */
f28085df 980 gdb_assert (!var->value->lazy ());
340a7723
NR
981
982 /* Need to coerce the input. We want to check if the
983 value of the variable object will be different
984 after assignment, and the first thing value_assign
985 does is coerce the input.
986 For example, if we are assigning an array to a pointer variable we
b021a221 987 should compare the pointer with the array's address, not with the
340a7723
NR
988 array's content. */
989 value = coerce_array (value);
990
8e7b59a5
KS
991 /* The new value may be lazy. value_assign, or
992 rather value_contents, will take care of this. */
a70b8144 993 try
8e7b59a5 994 {
b4d61099 995 val = value_assign (var->value.get (), value);
8e7b59a5
KS
996 }
997
230d2906 998 catch (const gdb_exception_error &except)
492d29ea 999 {
4c37490d 1000 return false;
492d29ea 1001 }
8e7b59a5 1002
340a7723
NR
1003 /* If the value has changed, record it, so that next -var-update can
1004 report this change. If a variable had a value of '1', we've set it
1005 to '333' and then set again to '1', when -var-update will report this
1006 variable as changed -- because the first assignment has set the
1007 'updated' flag. There's no need to optimize that, because return value
1008 of -var-update should be considered an approximation. */
4c37490d 1009 var->updated = install_new_value (var, val, false /* Compare values. */);
4c37490d 1010 return true;
8b93c638
JM
1011}
1012
0cc7d26f
TT
1013#if HAVE_PYTHON
1014
1015/* A helper function to install a constructor function and visualizer
bb5ce47a 1016 in a varobj_dynamic. */
0cc7d26f
TT
1017
1018static void
bb5ce47a 1019install_visualizer (struct varobj_dynamic *var, PyObject *constructor,
0cc7d26f
TT
1020 PyObject *visualizer)
1021{
1022 Py_XDECREF (var->constructor);
1023 var->constructor = constructor;
1024
1025 Py_XDECREF (var->pretty_printer);
1026 var->pretty_printer = visualizer;
1027
24fd95b4 1028 var->child_iter.reset (nullptr);
0cc7d26f
TT
1029}
1030
1031/* Install the default visualizer for VAR. */
1032
1033static void
1034install_default_visualizer (struct varobj *var)
1035{
d65aec65
PM
1036 /* Do not install a visualizer on a CPLUS_FAKE_CHILD. */
1037 if (CPLUS_FAKE_CHILD (var))
1038 return;
1039
0cc7d26f
TT
1040 if (pretty_printing)
1041 {
a31abe80 1042 gdbpy_ref<> pretty_printer;
0cc7d26f 1043
b4d61099 1044 if (var->value != nullptr)
0cc7d26f 1045 {
b4d61099 1046 pretty_printer = gdbpy_get_varobj_pretty_printer (var->value.get ());
a31abe80 1047 if (pretty_printer == nullptr)
0cc7d26f
TT
1048 {
1049 gdbpy_print_stack ();
1050 error (_("Cannot instantiate printer for default visualizer"));
1051 }
1052 }
a31abe80 1053
0cc7d26f 1054 if (pretty_printer == Py_None)
895dafa6 1055 pretty_printer.reset (nullptr);
0cc7d26f 1056
a31abe80 1057 install_visualizer (var->dynamic, NULL, pretty_printer.release ());
0cc7d26f
TT
1058 }
1059}
1060
1061/* Instantiate and install a visualizer for VAR using CONSTRUCTOR to
1062 make a new object. */
1063
1064static void
1065construct_visualizer (struct varobj *var, PyObject *constructor)
1066{
1067 PyObject *pretty_printer;
1068
d65aec65
PM
1069 /* Do not install a visualizer on a CPLUS_FAKE_CHILD. */
1070 if (CPLUS_FAKE_CHILD (var))
1071 return;
1072
0cc7d26f
TT
1073 Py_INCREF (constructor);
1074 if (constructor == Py_None)
1075 pretty_printer = NULL;
1076 else
1077 {
b4d61099
TT
1078 pretty_printer = instantiate_pretty_printer (constructor,
1079 var->value.get ());
0cc7d26f
TT
1080 if (! pretty_printer)
1081 {
1082 gdbpy_print_stack ();
1083 Py_DECREF (constructor);
1084 constructor = Py_None;
1085 Py_INCREF (constructor);
1086 }
1087
1088 if (pretty_printer == Py_None)
1089 {
1090 Py_DECREF (pretty_printer);
1091 pretty_printer = NULL;
1092 }
1093 }
1094
bb5ce47a 1095 install_visualizer (var->dynamic, constructor, pretty_printer);
0cc7d26f
TT
1096}
1097
1098#endif /* HAVE_PYTHON */
1099
1100/* A helper function for install_new_value. This creates and installs
1101 a visualizer for VAR, if appropriate. */
1102
1103static void
1104install_new_value_visualizer (struct varobj *var)
1105{
1106#if HAVE_PYTHON
1107 /* If the constructor is None, then we want the raw value. If VAR
1108 does not have a value, just skip this. */
0646da15
TT
1109 if (!gdb_python_initialized)
1110 return;
1111
bb5ce47a 1112 if (var->dynamic->constructor != Py_None && var->value != NULL)
0cc7d26f 1113 {
bde7b3e3 1114 gdbpy_enter_varobj enter_py (var);
0cc7d26f 1115
bb5ce47a 1116 if (var->dynamic->constructor == NULL)
0cc7d26f
TT
1117 install_default_visualizer (var);
1118 else
bb5ce47a 1119 construct_visualizer (var, var->dynamic->constructor);
0cc7d26f
TT
1120 }
1121#else
1122 /* Do nothing. */
1123#endif
1124}
1125
8264ba82
AG
1126/* When using RTTI to determine variable type it may be changed in runtime when
1127 the variable value is changed. This function checks whether type of varobj
1128 VAR will change when a new value NEW_VALUE is assigned and if it is so
1129 updates the type of VAR. */
1130
4c37490d 1131static bool
8264ba82
AG
1132update_type_if_necessary (struct varobj *var, struct value *new_value)
1133{
1134 if (new_value)
1135 {
1136 struct value_print_options opts;
1137
1138 get_user_print_options (&opts);
1139 if (opts.objectprint)
1140 {
2f408ecb
PA
1141 struct type *new_type = value_actual_type (new_value, 0, 0);
1142 std::string new_type_str = type_to_string (new_type);
1143 std::string curr_type_str = varobj_get_type (var);
8264ba82 1144
2f408ecb
PA
1145 /* Did the type name change? */
1146 if (curr_type_str != new_type_str)
8264ba82
AG
1147 {
1148 var->type = new_type;
1149
1150 /* This information may be not valid for a new type. */
30914ca8 1151 varobj_delete (var, 1);
ddf0ea08 1152 var->children.clear ();
8264ba82 1153 var->num_children = -1;
4c37490d 1154 return true;
8264ba82
AG
1155 }
1156 }
1157 }
1158
4c37490d 1159 return false;
8264ba82
AG
1160}
1161
4c37490d
SM
1162/* Assign a new value to a variable object. If INITIAL is true,
1163 this is the first assignment after the variable object was just
acd65feb 1164 created, or changed type. In that case, just assign the value
4c37490d
SM
1165 and return false.
1166 Otherwise, assign the new value, and return true if the value is
1167 different from the current one, false otherwise. The comparison is
581e13c1
MS
1168 done on textual representation of value. Therefore, some types
1169 need not be compared. E.g. for structures the reported value is
1170 always "{...}", so no comparison is necessary here. If the old
4c37490d 1171 value was NULL and new one is not, or vice versa, we always return true.
b26ed50d
VP
1172
1173 The VALUE parameter should not be released -- the function will
1174 take care of releasing it when needed. */
4c37490d
SM
1175static bool
1176install_new_value (struct varobj *var, struct value *value, bool initial)
acd65feb 1177{
4c37490d
SM
1178 bool changeable;
1179 bool need_to_fetch;
1180 bool changed = false;
1181 bool intentionally_not_fetched = false;
acd65feb 1182
acd65feb 1183 /* We need to know the varobj's type to decide if the value should
3e43a32a 1184 be fetched or not. C++ fake children (public/protected/private)
581e13c1 1185 don't have a type. */
acd65feb 1186 gdb_assert (var->type || CPLUS_FAKE_CHILD (var));
b2c2bd75 1187 changeable = varobj_value_is_changeable_p (var);
b6313243
TT
1188
1189 /* If the type has custom visualizer, we consider it to be always
581e13c1 1190 changeable. FIXME: need to make sure this behaviour will not
b6313243 1191 mess up read-sensitive values. */
bb5ce47a 1192 if (var->dynamic->pretty_printer != NULL)
4c37490d 1193 changeable = true;
b6313243 1194
acd65feb
VP
1195 need_to_fetch = changeable;
1196
b26ed50d
VP
1197 /* We are not interested in the address of references, and given
1198 that in C++ a reference is not rebindable, it cannot
1199 meaningfully change. So, get hold of the real value. */
1200 if (value)
0cc7d26f 1201 value = coerce_ref (value);
b26ed50d 1202
78134374 1203 if (var->type && var->type->code () == TYPE_CODE_UNION)
acd65feb
VP
1204 /* For unions, we need to fetch the value implicitly because
1205 of implementation of union member fetch. When gdb
1206 creates a value for a field and the value of the enclosing
1207 structure is not lazy, it immediately copies the necessary
1208 bytes from the enclosing values. If the enclosing value is
1209 lazy, the call to value_fetch_lazy on the field will read
1210 the data from memory. For unions, that means we'll read the
1211 same memory more than once, which is not desirable. So
1212 fetch now. */
4c37490d 1213 need_to_fetch = true;
acd65feb
VP
1214
1215 /* The new value might be lazy. If the type is changeable,
1216 that is we'll be comparing values of this type, fetch the
1217 value now. Otherwise, on the next update the old value
1218 will be lazy, which means we've lost that old value. */
3ee3b270 1219 if (need_to_fetch && value && value->lazy ())
acd65feb 1220 {
c1cc6152 1221 const struct varobj *parent = var->parent;
4c37490d 1222 bool frozen = var->frozen;
a109c7c1 1223
25d5ea92
VP
1224 for (; !frozen && parent; parent = parent->parent)
1225 frozen |= parent->frozen;
1226
1227 if (frozen && initial)
1228 {
1229 /* For variables that are frozen, or are children of frozen
1230 variables, we don't do fetch on initial assignment.
30baf67b 1231 For non-initial assignment we do the fetch, since it means we're
25d5ea92 1232 explicitly asked to compare the new value with the old one. */
4c37490d 1233 intentionally_not_fetched = true;
25d5ea92 1234 }
8e7b59a5 1235 else
acd65feb 1236 {
8e7b59a5 1237
a70b8144 1238 try
8e7b59a5 1239 {
78259c36 1240 value->fetch_lazy ();
8e7b59a5
KS
1241 }
1242
230d2906 1243 catch (const gdb_exception_error &except)
8e7b59a5
KS
1244 {
1245 /* Set the value to NULL, so that for the next -var-update,
1246 we don't try to compare the new value with this value,
1247 that we couldn't even read. */
1248 value = NULL;
1249 }
acd65feb 1250 }
acd65feb
VP
1251 }
1252
e848a8a5
TT
1253 /* Get a reference now, before possibly passing it to any Python
1254 code that might release it. */
b4d61099 1255 value_ref_ptr value_holder;
e848a8a5 1256 if (value != NULL)
bbfa6f00 1257 value_holder = value_ref_ptr::new_reference (value);
b6313243 1258
7a4d50bf
VP
1259 /* Below, we'll be comparing string rendering of old and new
1260 values. Don't get string rendering if the value is
1261 lazy -- if it is, the code above has decided that the value
1262 should not be fetched. */
2f408ecb 1263 std::string print_value;
3ee3b270 1264 if (value != NULL && !value->lazy ()
bb5ce47a 1265 && var->dynamic->pretty_printer == NULL)
99ad9427 1266 print_value = varobj_value_get_print_value (value, var->format, var);
7a4d50bf 1267
acd65feb
VP
1268 /* If the type is changeable, compare the old and the new values.
1269 If this is the initial assignment, we don't have any old value
1270 to compare with. */
7a4d50bf 1271 if (!initial && changeable)
acd65feb 1272 {
3e43a32a
MS
1273 /* If the value of the varobj was changed by -var-set-value,
1274 then the value in the varobj and in the target is the same.
1275 However, that value is different from the value that the
581e13c1 1276 varobj had after the previous -var-update. So need to the
3e43a32a 1277 varobj as changed. */
acd65feb 1278 if (var->updated)
4c37490d 1279 changed = true;
bb5ce47a 1280 else if (var->dynamic->pretty_printer == NULL)
acd65feb
VP
1281 {
1282 /* Try to compare the values. That requires that both
1283 values are non-lazy. */
f28085df 1284 if (var->not_fetched && var->value->lazy ())
25d5ea92
VP
1285 {
1286 /* This is a frozen varobj and the value was never read.
1287 Presumably, UI shows some "never read" indicator.
1288 Now that we've fetched the real value, we need to report
1289 this varobj as changed so that UI can show the real
1290 value. */
4c37490d 1291 changed = true;
25d5ea92 1292 }
dda83cd7 1293 else if (var->value == NULL && value == NULL)
581e13c1 1294 /* Equal. */
acd65feb
VP
1295 ;
1296 else if (var->value == NULL || value == NULL)
57e66780 1297 {
4c37490d 1298 changed = true;
57e66780 1299 }
acd65feb
VP
1300 else
1301 {
f28085df 1302 gdb_assert (!var->value->lazy ());
3ee3b270 1303 gdb_assert (!value->lazy ());
85265413 1304
2f408ecb
PA
1305 gdb_assert (!var->print_value.empty () && !print_value.empty ());
1306 if (var->print_value != print_value)
4c37490d 1307 changed = true;
acd65feb
VP
1308 }
1309 }
1310 }
85265413 1311
ee342b23
VP
1312 if (!initial && !changeable)
1313 {
1314 /* For values that are not changeable, we don't compare the values.
1315 However, we want to notice if a value was not NULL and now is NULL,
1316 or vise versa, so that we report when top-level varobjs come in scope
1317 and leave the scope. */
1318 changed = (var->value != NULL) != (value != NULL);
1319 }
1320
acd65feb 1321 /* We must always keep the new value, since children depend on it. */
b4d61099 1322 var->value = value_holder;
3ee3b270 1323 if (value && value->lazy () && intentionally_not_fetched)
4c37490d 1324 var->not_fetched = true;
25d5ea92 1325 else
4c37490d
SM
1326 var->not_fetched = false;
1327 var->updated = false;
85265413 1328
0cc7d26f
TT
1329 install_new_value_visualizer (var);
1330
1331 /* If we installed a pretty-printer, re-compare the printed version
1332 to see if the variable changed. */
bb5ce47a 1333 if (var->dynamic->pretty_printer != NULL)
0cc7d26f 1334 {
b4d61099
TT
1335 print_value = varobj_value_get_print_value (var->value.get (),
1336 var->format, var);
a80f2680
TT
1337 if (var->print_value != print_value)
1338 changed = true;
0cc7d26f 1339 }
0cc7d26f
TT
1340 var->print_value = print_value;
1341
f28085df 1342 gdb_assert (var->value == nullptr || var->value->type ());
acd65feb
VP
1343
1344 return changed;
1345}
acd65feb 1346
0cc7d26f
TT
1347/* Return the requested range for a varobj. VAR is the varobj. FROM
1348 and TO are out parameters; *FROM and *TO will be set to the
1349 selected sub-range of VAR. If no range was selected using
1350 -var-set-update-range, then both will be -1. */
1351void
b09e2c59 1352varobj_get_child_range (const struct varobj *var, int *from, int *to)
b6313243 1353{
0cc7d26f
TT
1354 *from = var->from;
1355 *to = var->to;
b6313243
TT
1356}
1357
0cc7d26f
TT
1358/* Set the selected sub-range of children of VAR to start at index
1359 FROM and end at index TO. If either FROM or TO is less than zero,
1360 this is interpreted as a request for all children. */
1361void
1362varobj_set_child_range (struct varobj *var, int from, int to)
b6313243 1363{
0cc7d26f
TT
1364 var->from = from;
1365 var->to = to;
b6313243
TT
1366}
1367
1368void
1369varobj_set_visualizer (struct varobj *var, const char *visualizer)
1370{
1371#if HAVE_PYTHON
bde7b3e3 1372 PyObject *mainmod;
b6313243 1373
0646da15
TT
1374 if (!gdb_python_initialized)
1375 return;
1376
bde7b3e3 1377 gdbpy_enter_varobj enter_py (var);
b6313243
TT
1378
1379 mainmod = PyImport_AddModule ("__main__");
7c66fffc
TT
1380 gdbpy_ref<> globals
1381 = gdbpy_ref<>::new_reference (PyModule_GetDict (mainmod));
7780f186
TT
1382 gdbpy_ref<> constructor (PyRun_String (visualizer, Py_eval_input,
1383 globals.get (), globals.get ()));
b6313243 1384
bde7b3e3 1385 if (constructor == NULL)
b6313243
TT
1386 {
1387 gdbpy_print_stack ();
da1f2771 1388 error (_("Could not evaluate visualizer expression: %s"), visualizer);
b6313243
TT
1389 }
1390
bde7b3e3 1391 construct_visualizer (var, constructor.get ());
b6313243 1392
0cc7d26f 1393 /* If there are any children now, wipe them. */
30914ca8 1394 varobj_delete (var, 1 /* children only */);
0cc7d26f 1395 var->num_children = -1;
d1369de6
TT
1396
1397 /* Also be sure to reset the print value. */
1398 varobj_set_display_format (var, var->format);
b6313243 1399#else
da1f2771 1400 error (_("Python support required"));
b6313243
TT
1401#endif
1402}
1403
7a290c40 1404/* If NEW_VALUE is the new value of the given varobj (var), return
4c37490d 1405 true if var has mutated. In other words, if the type of
7a290c40
JB
1406 the new value is different from the type of the varobj's old
1407 value.
1408
1409 NEW_VALUE may be NULL, if the varobj is now out of scope. */
1410
4c37490d 1411static bool
b09e2c59 1412varobj_value_has_mutated (const struct varobj *var, struct value *new_value,
7a290c40
JB
1413 struct type *new_type)
1414{
1415 /* If we haven't previously computed the number of children in var,
1416 it does not matter from the front-end's perspective whether
1417 the type has mutated or not. For all intents and purposes,
1418 it has not mutated. */
1419 if (var->num_children < 0)
4c37490d 1420 return false;
7a290c40 1421
4c37490d 1422 if (var->root->lang_ops->value_has_mutated != NULL)
8776cfe9
JB
1423 {
1424 /* The varobj module, when installing new values, explicitly strips
1425 references, saying that we're not interested in those addresses.
1426 But detection of mutation happens before installing the new
1427 value, so our value may be a reference that we need to strip
1428 in order to remain consistent. */
1429 if (new_value != NULL)
1430 new_value = coerce_ref (new_value);
1431 return var->root->lang_ops->value_has_mutated (var, new_value, new_type);
1432 }
7a290c40 1433 else
4c37490d 1434 return false;
7a290c40
JB
1435}
1436
8b93c638
JM
1437/* Update the values for a variable and its children. This is a
1438 two-pronged attack. First, re-parse the value for the root's
1439 expression to see if it's changed. Then go all the way
1440 through its children, reconstructing them and noting if they've
1441 changed.
1442
4c37490d 1443 The IS_EXPLICIT parameter specifies if this call is result
25d5ea92 1444 of MI request to update this specific variable, or
581e13c1 1445 result of implicit -var-update *. For implicit request, we don't
25d5ea92 1446 update frozen variables.
705da579 1447
581e13c1 1448 NOTE: This function may delete the caller's varobj. If it
8756216b
DP
1449 returns TYPE_CHANGED, then it has done this and VARP will be modified
1450 to point to the new varobj. */
8b93c638 1451
0604393c 1452std::vector<varobj_update_result>
4c37490d 1453varobj_update (struct varobj **varp, bool is_explicit)
8b93c638 1454{
4c37490d 1455 bool type_changed = false;
fe978cb0 1456 struct value *newobj;
0604393c
SM
1457 std::vector<varobj_update_result> stack;
1458 std::vector<varobj_update_result> result;
8b93c638 1459
25d5ea92
VP
1460 /* Frozen means frozen -- we don't check for any change in
1461 this varobj, including its going out of scope, or
1462 changing type. One use case for frozen varobjs is
1463 retaining previously evaluated expressions, and we don't
1464 want them to be reevaluated at all. */
fe978cb0 1465 if (!is_explicit && (*varp)->frozen)
f7f9ae2c 1466 return result;
8756216b
DP
1467
1468 if (!(*varp)->root->is_valid)
f7f9ae2c 1469 {
0604393c 1470 result.emplace_back (*varp, VAROBJ_INVALID);
f7f9ae2c
VP
1471 return result;
1472 }
8b93c638 1473
25d5ea92 1474 if ((*varp)->root->rootvar == *varp)
ae093f96 1475 {
0604393c 1476 varobj_update_result r (*varp);
f7f9ae2c 1477
581e13c1 1478 /* Update the root variable. value_of_root can return NULL
25d5ea92 1479 if the variable is no longer around, i.e. we stepped out of
581e13c1 1480 the frame in which a local existed. We are letting the
25d5ea92
VP
1481 value_of_root variable dispose of the varobj if the type
1482 has changed. */
fe978cb0 1483 newobj = value_of_root (varp, &type_changed);
4c37490d
SM
1484 if (update_type_if_necessary (*varp, newobj))
1485 type_changed = true;
f7f9ae2c 1486 r.varobj = *varp;
f7f9ae2c 1487 r.type_changed = type_changed;
fe978cb0 1488 if (install_new_value ((*varp), newobj, type_changed))
4c37490d 1489 r.changed = true;
ea56f9c2 1490
fe978cb0 1491 if (newobj == NULL)
f7f9ae2c 1492 r.status = VAROBJ_NOT_IN_SCOPE;
4c37490d 1493 r.value_installed = true;
f7f9ae2c
VP
1494
1495 if (r.status == VAROBJ_NOT_IN_SCOPE)
b6313243 1496 {
0b4bc29a 1497 if (r.type_changed || r.changed)
0604393c
SM
1498 result.push_back (std::move (r));
1499
b6313243
TT
1500 return result;
1501 }
a109c7c1 1502
0604393c 1503 stack.push_back (std::move (r));
b20d8971 1504 }
0604393c
SM
1505 else
1506 stack.emplace_back (*varp);
8b93c638 1507
8756216b 1508 /* Walk through the children, reconstructing them all. */
0604393c 1509 while (!stack.empty ())
8b93c638 1510 {
0604393c
SM
1511 varobj_update_result r = std::move (stack.back ());
1512 stack.pop_back ();
b6313243
TT
1513 struct varobj *v = r.varobj;
1514
b6313243
TT
1515 /* Update this variable, unless it's a root, which is already
1516 updated. */
1517 if (!r.value_installed)
7a290c40
JB
1518 {
1519 struct type *new_type;
1520
fe978cb0 1521 newobj = value_of_child (v->parent, v->index);
4c37490d
SM
1522 if (update_type_if_necessary (v, newobj))
1523 r.type_changed = true;
fe978cb0 1524 if (newobj)
d0c97917 1525 new_type = newobj->type ();
7a290c40 1526 else
ca20d462 1527 new_type = v->root->lang_ops->type_of_child (v->parent, v->index);
7a290c40 1528
fe978cb0 1529 if (varobj_value_has_mutated (v, newobj, new_type))
7a290c40
JB
1530 {
1531 /* The children are no longer valid; delete them now.
dda83cd7 1532 Report the fact that its type changed as well. */
30914ca8 1533 varobj_delete (v, 1 /* only_children */);
7a290c40
JB
1534 v->num_children = -1;
1535 v->to = -1;
1536 v->from = -1;
1537 v->type = new_type;
4c37490d 1538 r.type_changed = true;
7a290c40
JB
1539 }
1540
fe978cb0 1541 if (install_new_value (v, newobj, r.type_changed))
b6313243 1542 {
4c37490d
SM
1543 r.changed = true;
1544 v->updated = false;
b6313243
TT
1545 }
1546 }
1547
31f628ae
YQ
1548 /* We probably should not get children of a dynamic varobj, but
1549 for which -var-list-children was never invoked. */
1550 if (varobj_is_dynamic_p (v))
b6313243 1551 {
b926417a 1552 std::vector<varobj *> changed, type_changed_vec, unchanged, newobj_vec;
4c37490d 1553 bool children_changed = false;
b6313243
TT
1554
1555 if (v->frozen)
1556 continue;
1557
bd046f64 1558 if (!v->dynamic->children_requested)
0cc7d26f 1559 {
4c37490d 1560 bool dummy;
0cc7d26f
TT
1561
1562 /* If we initially did not have potential children, but
1563 now we do, consider the varobj as changed.
1564 Otherwise, if children were never requested, consider
1565 it as unchanged -- presumably, such varobj is not yet
1566 expanded in the UI, so we need not bother getting
1567 it. */
1568 if (!varobj_has_more (v, 0))
1569 {
8264ba82 1570 update_dynamic_varobj_children (v, NULL, NULL, NULL, NULL,
4c37490d 1571 &dummy, false, 0, 0);
0cc7d26f 1572 if (varobj_has_more (v, 0))
4c37490d 1573 r.changed = true;
0cc7d26f
TT
1574 }
1575
1576 if (r.changed)
0604393c 1577 result.push_back (std::move (r));
0cc7d26f
TT
1578
1579 continue;
1580 }
1581
4c37490d 1582 /* If update_dynamic_varobj_children returns false, then we have
b6313243 1583 a non-conforming pretty-printer, so we skip it. */
b926417a
TT
1584 if (update_dynamic_varobj_children (v, &changed, &type_changed_vec,
1585 &newobj_vec,
1586 &unchanged, &children_changed,
1587 true, v->from, v->to))
b6313243 1588 {
b926417a 1589 if (children_changed || !newobj_vec.empty ())
b6313243 1590 {
4c37490d 1591 r.children_changed = true;
b926417a 1592 r.newobj = std::move (newobj_vec);
b6313243 1593 }
0cc7d26f
TT
1594 /* Push in reverse order so that the first child is
1595 popped from the work stack first, and so will be
1596 added to result first. This does not affect
1597 correctness, just "nicer". */
b926417a 1598 for (int i = type_changed_vec.size () - 1; i >= 0; --i)
8264ba82 1599 {
b926417a 1600 varobj_update_result item (type_changed_vec[i]);
8264ba82
AG
1601
1602 /* Type may change only if value was changed. */
b926417a
TT
1603 item.changed = true;
1604 item.type_changed = true;
1605 item.value_installed = true;
0604393c 1606
b926417a 1607 stack.push_back (std::move (item));
8264ba82 1608 }
0604393c 1609 for (int i = changed.size () - 1; i >= 0; --i)
b6313243 1610 {
b926417a 1611 varobj_update_result item (changed[i]);
a109c7c1 1612
b926417a
TT
1613 item.changed = true;
1614 item.value_installed = true;
0604393c 1615
b926417a 1616 stack.push_back (std::move (item));
b6313243 1617 }
0604393c
SM
1618 for (int i = unchanged.size () - 1; i >= 0; --i)
1619 {
1620 if (!unchanged[i]->frozen)
1621 {
b926417a 1622 varobj_update_result item (unchanged[i]);
0604393c 1623
b926417a 1624 item.value_installed = true;
0cc7d26f 1625
b926417a 1626 stack.push_back (std::move (item));
0604393c
SM
1627 }
1628 }
1629 if (r.changed || r.children_changed)
1630 result.push_back (std::move (r));
0cc7d26f 1631
b6313243
TT
1632 continue;
1633 }
1634 }
28335dcc
VP
1635
1636 /* Push any children. Use reverse order so that the first
1637 child is popped from the work stack first, and so
1638 will be added to result first. This does not
1639 affect correctness, just "nicer". */
0604393c 1640 for (int i = v->children.size () - 1; i >= 0; --i)
8b93c638 1641 {
ddf0ea08 1642 varobj *c = v->children[i];
a109c7c1 1643
28335dcc 1644 /* Child may be NULL if explicitly deleted by -var-delete. */
25d5ea92 1645 if (c != NULL && !c->frozen)
0604393c 1646 stack.emplace_back (c);
8b93c638 1647 }
b6313243
TT
1648
1649 if (r.changed || r.type_changed)
0604393c 1650 result.push_back (std::move (r));
8b93c638
JM
1651 }
1652
f7f9ae2c 1653 return result;
8b93c638 1654}
8b93c638
JM
1655
1656/* Helper functions */
1657
1658/*
1659 * Variable object construction/destruction
1660 */
1661
1662static int
4c37490d 1663delete_variable (struct varobj *var, bool only_children_p)
8b93c638
JM
1664{
1665 int delcount = 0;
1666
30914ca8 1667 delete_variable_1 (&delcount, var, only_children_p,
4c37490d 1668 true /* remove_from_parent_p */ );
8b93c638
JM
1669
1670 return delcount;
1671}
1672
581e13c1 1673/* Delete the variable object VAR and its children. */
8b93c638
JM
1674/* IMPORTANT NOTE: If we delete a variable which is a child
1675 and the parent is not removed we dump core. It must be always
581e13c1 1676 initially called with remove_from_parent_p set. */
8b93c638 1677static void
4c37490d
SM
1678delete_variable_1 (int *delcountp, struct varobj *var, bool only_children_p,
1679 bool remove_from_parent_p)
8b93c638 1680{
581e13c1 1681 /* Delete any children of this variable, too. */
ddf0ea08 1682 for (varobj *child : var->children)
28335dcc 1683 {
214270ab
VP
1684 if (!child)
1685 continue;
ddf0ea08 1686
8b93c638 1687 if (!remove_from_parent_p)
28335dcc 1688 child->parent = NULL;
ddf0ea08 1689
4c37490d 1690 delete_variable_1 (delcountp, child, false, only_children_p);
8b93c638 1691 }
ddf0ea08 1692 var->children.clear ();
8b93c638 1693
581e13c1 1694 /* if we were called to delete only the children we are done here. */
8b93c638
JM
1695 if (only_children_p)
1696 return;
1697
581e13c1 1698 /* Otherwise, add it to the list of deleted ones and proceed to do so. */
2f408ecb 1699 /* If the name is empty, this is a temporary variable, that has not
581e13c1 1700 yet been installed, don't report it, it belongs to the caller... */
2f408ecb 1701 if (!var->obj_name.empty ())
8b93c638 1702 {
8b93c638
JM
1703 *delcountp = *delcountp + 1;
1704 }
1705
581e13c1 1706 /* If this variable has a parent, remove it from its parent's list. */
8b93c638
JM
1707 /* OPTIMIZATION: if the parent of this variable is also being deleted,
1708 (as indicated by remove_from_parent_p) we don't bother doing an
1709 expensive list search to find the element to remove when we are
581e13c1 1710 discarding the list afterwards. */
72330bd6 1711 if ((remove_from_parent_p) && (var->parent != NULL))
ddf0ea08 1712 var->parent->children[var->index] = NULL;
72330bd6 1713
2f408ecb 1714 if (!var->obj_name.empty ())
73a93a32 1715 uninstall_variable (var);
8b93c638 1716
581e13c1 1717 /* Free memory associated with this variable. */
9e5b9d2b 1718 delete var;
8b93c638
JM
1719}
1720
581e13c1 1721/* Install the given variable VAR with the object name VAR->OBJ_NAME. */
07d9937a 1722static void
fba45db2 1723install_variable (struct varobj *var)
8b93c638 1724{
2c1413a9
TT
1725 hashval_t hash = htab_hash_string (var->obj_name.c_str ());
1726 void **slot = htab_find_slot_with_hash (varobj_table,
1727 var->obj_name.c_str (),
1728 hash, INSERT);
1729 if (*slot != nullptr)
8a3fe4f8 1730 error (_("Duplicate variable object name"));
8b93c638 1731
581e13c1 1732 /* Add varobj to hash table. */
2c1413a9 1733 *slot = var;
8b93c638 1734
581e13c1 1735 /* If root, add varobj to root list. */
b2c2bd75 1736 if (is_root_p (var))
76deb5d9 1737 rootlist.push_front (var->root);
8b93c638
JM
1738}
1739
405feb71 1740/* Uninstall the object VAR. */
8b93c638 1741static void
fba45db2 1742uninstall_variable (struct varobj *var)
8b93c638 1743{
2c1413a9
TT
1744 hashval_t hash = htab_hash_string (var->obj_name.c_str ());
1745 htab_remove_elt_with_hash (varobj_table, var->obj_name.c_str (), hash);
8b93c638
JM
1746
1747 if (varobjdebug)
6cb06a8c 1748 gdb_printf (gdb_stdlog, "Deleting %s\n", var->obj_name.c_str ());
8b93c638 1749
581e13c1 1750 /* If root, remove varobj from root list. */
b2c2bd75 1751 if (is_root_p (var))
8b93c638 1752 {
76deb5d9
TT
1753 auto iter = std::find (rootlist.begin (), rootlist.end (), var->root);
1754 rootlist.erase (iter);
8b93c638 1755 }
8b93c638
JM
1756}
1757
837ce252
SM
1758/* Create and install a child of the parent of the given name.
1759
1760 The created VAROBJ takes ownership of the allocated NAME. */
1761
8b93c638 1762static struct varobj *
2f408ecb 1763create_child (struct varobj *parent, int index, std::string &name)
b6313243 1764{
5a2e0d6e
YQ
1765 struct varobj_item item;
1766
2f408ecb 1767 std::swap (item.name, name);
11106495 1768 item.value = release_value (value_of_child (parent, index));
5a2e0d6e
YQ
1769
1770 return create_child_with_value (parent, index, &item);
b6313243
TT
1771}
1772
1773static struct varobj *
5a2e0d6e
YQ
1774create_child_with_value (struct varobj *parent, int index,
1775 struct varobj_item *item)
8b93c638 1776{
9e5b9d2b 1777 varobj *child = new varobj (parent->root);
8b93c638 1778
5e5ac9a5 1779 /* NAME is allocated by caller. */
2f408ecb 1780 std::swap (child->name, item->name);
8b93c638 1781 child->index = index;
8b93c638 1782 child->parent = parent;
85254831 1783
99ad9427 1784 if (varobj_is_anonymous_child (child))
2f408ecb
PA
1785 child->obj_name = string_printf ("%s.%d_anonymous",
1786 parent->obj_name.c_str (), index);
85254831 1787 else
2f408ecb
PA
1788 child->obj_name = string_printf ("%s.%s",
1789 parent->obj_name.c_str (),
1790 child->name.c_str ());
85254831 1791
8b93c638
JM
1792 install_variable (child);
1793
acd65feb
VP
1794 /* Compute the type of the child. Must do this before
1795 calling install_new_value. */
5a2e0d6e 1796 if (item->value != NULL)
acd65feb 1797 /* If the child had no evaluation errors, var->value
581e13c1 1798 will be non-NULL and contain a valid type. */
11106495 1799 child->type = value_actual_type (item->value.get (), 0, NULL);
acd65feb 1800 else
581e13c1 1801 /* Otherwise, we must compute the type. */
ca20d462
YQ
1802 child->type = (*child->root->lang_ops->type_of_child) (child->parent,
1803 child->index);
11106495 1804 install_new_value (child, item->value.get (), 1);
acd65feb 1805
8b93c638
JM
1806 return child;
1807}
8b93c638
JM
1808\f
1809
1810/*
1811 * Miscellaneous utility functions.
1812 */
1813
581e13c1 1814/* Allocate memory and initialize a new variable. */
9e5b9d2b
SM
1815varobj::varobj (varobj_root *root_)
1816: root (root_), dynamic (new varobj_dynamic)
8b93c638 1817{
8b93c638
JM
1818}
1819
581e13c1 1820/* Free any allocated memory associated with VAR. */
9e5b9d2b
SM
1821
1822varobj::~varobj ()
8b93c638 1823{
9e5b9d2b
SM
1824 varobj *var = this;
1825
d452c4bc 1826#if HAVE_PYTHON
bb5ce47a 1827 if (var->dynamic->pretty_printer != NULL)
d452c4bc 1828 {
bde7b3e3 1829 gdbpy_enter_varobj enter_py (var);
bb5ce47a
YQ
1830
1831 Py_XDECREF (var->dynamic->constructor);
1832 Py_XDECREF (var->dynamic->pretty_printer);
d452c4bc
UW
1833 }
1834#endif
1835
4d0754c5
TT
1836 /* This must be deleted before the root object, because Python-based
1837 destructors need access to some components. */
1838 delete var->dynamic;
1839
b2c2bd75 1840 if (is_root_p (var))
4d01a485 1841 delete var->root;
74b7792f
AC
1842}
1843
6e2a9270
VP
1844/* Return the type of the value that's stored in VAR,
1845 or that would have being stored there if the
581e13c1 1846 value were accessible.
6e2a9270
VP
1847
1848 This differs from VAR->type in that VAR->type is always
85102364 1849 the true type of the expression in the source language.
6e2a9270
VP
1850 The return value of this function is the type we're
1851 actually storing in varobj, and using for displaying
1852 the values and for comparing previous and new values.
1853
1854 For example, top-level references are always stripped. */
99ad9427 1855struct type *
b09e2c59 1856varobj_get_value_type (const struct varobj *var)
6e2a9270
VP
1857{
1858 struct type *type;
1859
b4d61099 1860 if (var->value != nullptr)
f28085df 1861 type = var->value->type ();
6e2a9270
VP
1862 else
1863 type = var->type;
1864
1865 type = check_typedef (type);
1866
aa006118 1867 if (TYPE_IS_REFERENCE (type))
6e2a9270
VP
1868 type = get_target_type (type);
1869
1870 type = check_typedef (type);
1871
1872 return type;
1873}
1874
8b93c638
JM
1875/*
1876 * Language-dependencies
1877 */
1878
1879/* Common entry points */
1880
8b93c638
JM
1881/* Return the number of children for a given variable.
1882 The result of this function is defined by the language
581e13c1 1883 implementation. The number of children returned by this function
8b93c638 1884 is the number of children that the user will see in the variable
581e13c1 1885 display. */
8b93c638 1886static int
b09e2c59 1887number_of_children (const struct varobj *var)
8b93c638 1888{
ca20d462 1889 return (*var->root->lang_ops->number_of_children) (var);
8b93c638
JM
1890}
1891
2f408ecb
PA
1892/* What is the expression for the root varobj VAR? */
1893
1894static std::string
b09e2c59 1895name_of_variable (const struct varobj *var)
8b93c638 1896{
ca20d462 1897 return (*var->root->lang_ops->name_of_variable) (var);
8b93c638
JM
1898}
1899
2f408ecb
PA
1900/* What is the name of the INDEX'th child of VAR? */
1901
1902static std::string
fba45db2 1903name_of_child (struct varobj *var, int index)
8b93c638 1904{
ca20d462 1905 return (*var->root->lang_ops->name_of_child) (var, index);
8b93c638
JM
1906}
1907
2213e2be 1908/* If frame associated with VAR can be found, switch
4c37490d 1909 to it and return true. Otherwise, return false. */
2213e2be 1910
4c37490d 1911static bool
b09e2c59 1912check_scope (const struct varobj *var)
2213e2be 1913{
bd2b40ac 1914 frame_info_ptr fi;
4c37490d 1915 bool scope;
2213e2be
YQ
1916
1917 fi = frame_find_by_id (var->root->frame);
1918 scope = fi != NULL;
1919
1920 if (fi)
1921 {
1922 CORE_ADDR pc = get_frame_pc (fi);
1923
4b8791e1
SM
1924 if (pc < var->root->valid_block->start () ||
1925 pc >= var->root->valid_block->end ())
4c37490d 1926 scope = false;
2213e2be
YQ
1927 else
1928 select_frame (fi);
1929 }
1930 return scope;
1931}
1932
1933/* Helper function to value_of_root. */
1934
1935static struct value *
1936value_of_root_1 (struct varobj **var_handle)
1937{
1938 struct value *new_val = NULL;
1939 struct varobj *var = *var_handle;
4c37490d 1940 bool within_scope = false;
2213e2be
YQ
1941
1942 /* Only root variables can be updated... */
1943 if (!is_root_p (var))
1944 /* Not a root var. */
1945 return NULL;
1946
5ed8105e 1947 scoped_restore_current_thread restore_thread;
2213e2be
YQ
1948
1949 /* Determine whether the variable is still around. */
1950 if (var->root->valid_block == NULL || var->root->floating)
4c37490d 1951 within_scope = true;
2213e2be
YQ
1952 else if (var->root->thread_id == 0)
1953 {
1954 /* The program was single-threaded when the variable object was
1955 created. Technically, it's possible that the program became
1956 multi-threaded since then, but we don't support such
1957 scenario yet. */
1958 within_scope = check_scope (var);
1959 }
1960 else
1961 {
00431a78 1962 thread_info *thread = find_thread_global_id (var->root->thread_id);
5d5658a1 1963
00431a78 1964 if (thread != NULL)
2213e2be 1965 {
00431a78 1966 switch_to_thread (thread);
2213e2be
YQ
1967 within_scope = check_scope (var);
1968 }
1969 }
1970
1971 if (within_scope)
1972 {
2213e2be
YQ
1973
1974 /* We need to catch errors here, because if evaluate
dda83cd7 1975 expression fails we want to just return NULL. */
a70b8144 1976 try
2213e2be 1977 {
43048e46 1978 new_val = var->root->exp->evaluate ();
2213e2be 1979 }
230d2906 1980 catch (const gdb_exception_error &except)
492d29ea
PA
1981 {
1982 }
2213e2be
YQ
1983 }
1984
2213e2be
YQ
1985 return new_val;
1986}
1987
a5defcdc
VP
1988/* What is the ``struct value *'' of the root variable VAR?
1989 For floating variable object, evaluation can get us a value
1990 of different type from what is stored in varobj already. In
1991 that case:
1992 - *type_changed will be set to 1
1993 - old varobj will be freed, and new one will be
1994 created, with the same name.
1995 - *var_handle will be set to the new varobj
1996 Otherwise, *type_changed will be set to 0. */
30b28db1 1997static struct value *
4c37490d 1998value_of_root (struct varobj **var_handle, bool *type_changed)
8b93c638 1999{
73a93a32
JI
2000 struct varobj *var;
2001
2002 if (var_handle == NULL)
2003 return NULL;
2004
2005 var = *var_handle;
2006
2007 /* This should really be an exception, since this should
581e13c1 2008 only get called with a root variable. */
73a93a32 2009
b2c2bd75 2010 if (!is_root_p (var))
73a93a32
JI
2011 return NULL;
2012
a5defcdc 2013 if (var->root->floating)
73a93a32
JI
2014 {
2015 struct varobj *tmp_var;
6225abfa 2016
2f408ecb 2017 tmp_var = varobj_create (NULL, var->name.c_str (), (CORE_ADDR) 0,
73a93a32
JI
2018 USE_SELECTED_FRAME);
2019 if (tmp_var == NULL)
2020 {
2021 return NULL;
2022 }
2f408ecb
PA
2023 std::string old_type = varobj_get_type (var);
2024 std::string new_type = varobj_get_type (tmp_var);
2025 if (old_type == new_type)
73a93a32 2026 {
fcacd99f
VP
2027 /* The expression presently stored inside var->root->exp
2028 remembers the locations of local variables relatively to
2029 the frame where the expression was created (in DWARF location
2030 button, for example). Naturally, those locations are not
2031 correct in other frames, so update the expression. */
2032
4d01a485 2033 std::swap (var->root->exp, tmp_var->root->exp);
fcacd99f 2034
30914ca8 2035 varobj_delete (tmp_var, 0);
73a93a32
JI
2036 *type_changed = 0;
2037 }
2038 else
2039 {
2f408ecb 2040 tmp_var->obj_name = var->obj_name;
0cc7d26f
TT
2041 tmp_var->from = var->from;
2042 tmp_var->to = var->to;
30914ca8 2043 varobj_delete (var, 0);
a5defcdc 2044
73a93a32
JI
2045 install_variable (tmp_var);
2046 *var_handle = tmp_var;
705da579 2047 var = *var_handle;
4c37490d 2048 *type_changed = true;
73a93a32
JI
2049 }
2050 }
2051 else
2052 {
2053 *type_changed = 0;
2054 }
2055
7a290c40
JB
2056 {
2057 struct value *value;
2058
2213e2be 2059 value = value_of_root_1 (var_handle);
7a290c40
JB
2060 if (var->value == NULL || value == NULL)
2061 {
2062 /* For root varobj-s, a NULL value indicates a scoping issue.
2063 So, nothing to do in terms of checking for mutations. */
2064 }
d0c97917 2065 else if (varobj_value_has_mutated (var, value, value->type ()))
7a290c40
JB
2066 {
2067 /* The type has mutated, so the children are no longer valid.
2068 Just delete them, and tell our caller that the type has
2069 changed. */
30914ca8 2070 varobj_delete (var, 1 /* only_children */);
7a290c40
JB
2071 var->num_children = -1;
2072 var->to = -1;
2073 var->from = -1;
4c37490d 2074 *type_changed = true;
7a290c40
JB
2075 }
2076 return value;
2077 }
8b93c638
JM
2078}
2079
581e13c1 2080/* What is the ``struct value *'' for the INDEX'th child of PARENT? */
30b28db1 2081static struct value *
c1cc6152 2082value_of_child (const struct varobj *parent, int index)
8b93c638 2083{
30b28db1 2084 struct value *value;
8b93c638 2085
ca20d462 2086 value = (*parent->root->lang_ops->value_of_child) (parent, index);
8b93c638 2087
8b93c638
JM
2088 return value;
2089}
2090
581e13c1 2091/* GDB already has a command called "value_of_variable". Sigh. */
2f408ecb 2092static std::string
de051565 2093my_value_of_variable (struct varobj *var, enum varobj_display_formats format)
8b93c638 2094{
8756216b 2095 if (var->root->is_valid)
0cc7d26f 2096 {
bb5ce47a 2097 if (var->dynamic->pretty_printer != NULL)
b4d61099
TT
2098 return varobj_value_get_print_value (var->value.get (), var->format,
2099 var);
aa15623f
TT
2100 else if (var->parent != nullptr && varobj_is_dynamic_p (var->parent))
2101 return var->print_value;
2102
ca20d462 2103 return (*var->root->lang_ops->value_of_variable) (var, format);
0cc7d26f 2104 }
8756216b 2105 else
2f408ecb 2106 return std::string ();
8b93c638
JM
2107}
2108
99ad9427
YQ
2109void
2110varobj_formatted_print_options (struct value_print_options *opts,
2111 enum varobj_display_formats format)
2112{
2113 get_formatted_print_options (opts, format_code[(int) format]);
dad6b350 2114 opts->deref_ref = false;
0625771b 2115 opts->raw = !pretty_printing;
99ad9427
YQ
2116}
2117
2f408ecb 2118std::string
99ad9427
YQ
2119varobj_value_get_print_value (struct value *value,
2120 enum varobj_display_formats format,
b09e2c59 2121 const struct varobj *var)
85265413 2122{
79a45b7d 2123 struct value_print_options opts;
be759fcf
PM
2124 struct type *type = NULL;
2125 long len = 0;
1eba6383 2126 gdb::unique_xmalloc_ptr<char> encoding;
3a182a69
JK
2127 /* Initialize it just to avoid a GCC false warning. */
2128 CORE_ADDR str_addr = 0;
4c37490d 2129 bool string_print = false;
57e66780
DJ
2130
2131 if (value == NULL)
2f408ecb 2132 return std::string ();
57e66780 2133
d7e74731 2134 string_file stb;
2f408ecb
PA
2135 std::string thevalue;
2136
c4a3dbaf
TT
2137 varobj_formatted_print_options (&opts, format);
2138
b6313243 2139#if HAVE_PYTHON
0646da15
TT
2140 if (gdb_python_initialized)
2141 {
bb5ce47a 2142 PyObject *value_formatter = var->dynamic->pretty_printer;
d452c4bc 2143
68cdc557 2144 gdbpy_enter_varobj enter_py (var);
09ca9e2e 2145
0646da15
TT
2146 if (value_formatter)
2147 {
0646da15
TT
2148 if (PyObject_HasAttr (value_formatter, gdbpy_to_string_cst))
2149 {
2150 struct value *replacement;
0646da15 2151
a5c5eda7
SM
2152 gdbpy_ref<> output = apply_varobj_pretty_printer (value_formatter,
2153 &replacement,
c4a3dbaf
TT
2154 &stb,
2155 &opts);
0646da15
TT
2156
2157 /* If we have string like output ... */
3e815477 2158 if (output != nullptr && output != Py_None)
0646da15 2159 {
0646da15
TT
2160 /* If this is a lazy string, extract it. For lazy
2161 strings we always print as a string, so set
2162 string_print. */
68cdc557 2163 if (gdbpy_is_lazy_string (output.get ()))
0646da15 2164 {
68cdc557
TT
2165 gdbpy_extract_lazy_string (output.get (), &str_addr,
2166 &type, &len, &encoding);
4c37490d 2167 string_print = true;
0646da15
TT
2168 }
2169 else
2170 {
2171 /* If it is a regular (non-lazy) string, extract
2172 it and copy the contents into THEVALUE. If the
2173 hint says to print it as a string, set
2174 string_print. Otherwise just return the extracted
2175 string as a value. */
2176
9b972014 2177 gdb::unique_xmalloc_ptr<char> s
68cdc557 2178 = python_string_to_target_string (output.get ());
0646da15
TT
2179
2180 if (s)
2181 {
e3821cca 2182 struct gdbarch *gdbarch;
0646da15 2183
9b972014
TT
2184 gdb::unique_xmalloc_ptr<char> hint
2185 = gdbpy_get_display_hint (value_formatter);
0646da15
TT
2186 if (hint)
2187 {
9b972014 2188 if (!strcmp (hint.get (), "string"))
4c37490d 2189 string_print = true;
0646da15
TT
2190 }
2191
9b972014 2192 thevalue = std::string (s.get ());
2f408ecb 2193 len = thevalue.size ();
d0c97917 2194 gdbarch = value->type ()->arch ();
0646da15 2195 type = builtin_type (gdbarch)->builtin_char;
0646da15
TT
2196
2197 if (!string_print)
d7e74731 2198 return thevalue;
0646da15
TT
2199 }
2200 else
2201 gdbpy_print_stack ();
2202 }
2203 }
2204 /* If the printer returned a replacement value, set VALUE
2205 to REPLACEMENT. If there is not a replacement value,
2206 just use the value passed to this function. */
2207 if (replacement)
2208 value = replacement;
2209 }
3e815477
TT
2210 else
2211 {
2212 /* No to_string method, so if there is a 'children'
2213 method, return the default. */
2214 if (PyObject_HasAttr (value_formatter, gdbpy_children_cst))
2215 return "{...}";
2216 }
0646da15 2217 }
d1369de6
TT
2218 else
2219 {
2220 /* If we've made it here, we don't want a pretty-printer --
2221 if we had one, it would already have been used. */
2222 opts.raw = true;
2223 }
0646da15 2224 }
b6313243
TT
2225#endif
2226
00bd41d6 2227 /* If the THEVALUE has contents, it is a regular string. */
2f408ecb 2228 if (!thevalue.empty ())
660da3c1
TT
2229 current_language->printstr (&stb, type, (gdb_byte *) thevalue.c_str (),
2230 len, encoding.get (), 0, &opts);
09ca9e2e 2231 else if (string_print)
00bd41d6
PM
2232 /* Otherwise, if string_print is set, and it is not a regular
2233 string, it is a lazy string. */
d7e74731 2234 val_print_string (type, encoding.get (), str_addr, len, &stb, &opts);
b6313243 2235 else
00bd41d6 2236 /* All other cases. */
d7e74731 2237 common_val_print (value, &stb, 0, &opts, current_language);
57e66780 2238
5d10a204 2239 return stb.release ();
85265413
NR
2240}
2241
4c37490d 2242bool
b09e2c59 2243varobj_editable_p (const struct varobj *var)
340a7723
NR
2244{
2245 struct type *type;
340a7723 2246
b4d61099 2247 if (!(var->root->is_valid && var->value != nullptr
f28085df 2248 && var->value->lval ()))
4c37490d 2249 return false;
340a7723 2250
99ad9427 2251 type = varobj_get_value_type (var);
340a7723 2252
78134374 2253 switch (type->code ())
340a7723
NR
2254 {
2255 case TYPE_CODE_STRUCT:
2256 case TYPE_CODE_UNION:
2257 case TYPE_CODE_ARRAY:
2258 case TYPE_CODE_FUNC:
2259 case TYPE_CODE_METHOD:
4c37490d 2260 return false;
340a7723
NR
2261 break;
2262
2263 default:
4c37490d 2264 return true;
340a7723
NR
2265 break;
2266 }
2267}
2268
d32cafc7 2269/* Call VAR's value_is_changeable_p language-specific callback. */
acd65feb 2270
4c37490d 2271bool
b09e2c59 2272varobj_value_is_changeable_p (const struct varobj *var)
8b93c638 2273{
ca20d462 2274 return var->root->lang_ops->value_is_changeable_p (var);
8b93c638
JM
2275}
2276
4c37490d 2277/* Return true if that varobj is floating, that is is always evaluated in the
5a413362
VP
2278 selected frame, and not bound to thread/frame. Such variable objects
2279 are created using '@' as frame specifier to -var-create. */
4c37490d 2280bool
b09e2c59 2281varobj_floating_p (const struct varobj *var)
5a413362
VP
2282{
2283 return var->root->floating;
2284}
2285
d32cafc7
JB
2286/* Implement the "value_is_changeable_p" varobj callback for most
2287 languages. */
2288
4c37490d 2289bool
b09e2c59 2290varobj_default_value_is_changeable_p (const struct varobj *var)
d32cafc7 2291{
4c37490d 2292 bool r;
d32cafc7
JB
2293 struct type *type;
2294
2295 if (CPLUS_FAKE_CHILD (var))
4c37490d 2296 return false;
d32cafc7 2297
99ad9427 2298 type = varobj_get_value_type (var);
d32cafc7 2299
78134374 2300 switch (type->code ())
d32cafc7
JB
2301 {
2302 case TYPE_CODE_STRUCT:
2303 case TYPE_CODE_UNION:
2304 case TYPE_CODE_ARRAY:
4c37490d 2305 r = false;
d32cafc7
JB
2306 break;
2307
2308 default:
4c37490d 2309 r = true;
d32cafc7
JB
2310 }
2311
2312 return r;
2313}
2314
d8f168dd
TT
2315/* Iterate all the existing _root_ VAROBJs and call the FUNC callback
2316 for each one. */
54333c3b
JK
2317
2318void
d8f168dd 2319all_root_varobjs (gdb::function_view<void (struct varobj *var)> func)
54333c3b 2320{
54333c3b 2321 /* Iterate "safely" - handle if the callee deletes its passed VAROBJ. */
76deb5d9
TT
2322 auto iter = rootlist.begin ();
2323 auto end = rootlist.end ();
2324 while (iter != end)
54333c3b 2325 {
76deb5d9 2326 auto self = iter++;
d8f168dd 2327 func ((*self)->rootvar);
54333c3b
JK
2328 }
2329}
8756216b 2330
ccb5e559
TV
2331/* Try to recreate the varobj VAR if it is a global or floating. This is a
2332 helper function for varobj_re_set. */
2dbd25e5 2333
54333c3b 2334static void
ccb5e559 2335varobj_re_set_iter (struct varobj *var)
8756216b 2336{
906dca17
LS
2337 /* Invalidated global varobjs must be re-evaluated. */
2338 if (!var->root->is_valid && var->root->global)
2dbd25e5 2339 {
54333c3b 2340 struct varobj *tmp_var;
2dbd25e5 2341
54333c3b 2342 /* Try to create a varobj with same expression. If we succeed
906dca17 2343 and have a global replace the old varobj. */
6c96b937 2344 tmp_var = varobj_create (nullptr, var->name.c_str (), (CORE_ADDR) 0,
906dca17
LS
2345 USE_CURRENT_FRAME);
2346 if (tmp_var != nullptr && tmp_var->root->global)
6c96b937 2347 {
2f408ecb 2348 tmp_var->obj_name = var->obj_name;
30914ca8 2349 varobj_delete (var, 0);
54333c3b 2350 install_variable (tmp_var);
2dbd25e5
JK
2351 }
2352 }
54333c3b
JK
2353}
2354
ccb5e559 2355/* See varobj.h. */
54333c3b
JK
2356
2357void
ccb5e559 2358varobj_re_set (void)
54333c3b 2359{
ccb5e559 2360 all_root_varobjs (varobj_re_set_iter);
8756216b 2361}
481695ed 2362
bc20e562
LS
2363/* Ensure that no varobj keep references to OBJFILE. */
2364
2365static void
2366varobj_invalidate_if_uses_objfile (struct objfile *objfile)
2367{
2368 if (objfile->separate_debug_objfile_backlink != nullptr)
2369 objfile = objfile->separate_debug_objfile_backlink;
2370
2371 all_root_varobjs ([objfile] (struct varobj *var)
2372 {
2373 if (var->root->valid_block != nullptr)
2374 {
46baa3c6 2375 struct objfile *bl_objfile = var->root->valid_block->objfile ();
bc20e562
LS
2376 if (bl_objfile->separate_debug_objfile_backlink != nullptr)
2377 bl_objfile = bl_objfile->separate_debug_objfile_backlink;
2378
2379 if (bl_objfile == objfile)
2380 {
2381 /* The varobj is tied to a block which is going away. There is
2382 no way to reconstruct something later, so invalidate the
33b5899f 2383 varobj completely and drop the reference to the block which is
bc20e562
LS
2384 being freed. */
2385 var->root->is_valid = false;
2386 var->root->valid_block = nullptr;
2387 }
2388 }
2389
aa9bd445 2390 if (var->root->exp != nullptr && var->root->exp->uses_objfile (objfile))
bc20e562
LS
2391 {
2392 /* The varobj's current expression references the objfile. For
2393 globals and floating, it is possible that when we try to
2394 re-evaluate the expression later it is still valid with
2395 whatever is in scope at that moment. Just invalidate the
2396 expression for now. */
2397 var->root->exp.reset ();
2398
2399 /* It only makes sense to keep a floating varobj around. */
2400 if (!var->root->floating)
2401 var->root->is_valid = false;
2402 }
2403
2404 /* var->value->type and var->type might also reference the objfile.
2405 This is taken care of in value.c:preserve_values which deals with
3bfdcabb 2406 making sure that objfile-owned types are replaced with
bc20e562
LS
2407 gdbarch-owned equivalents. */
2408 });
2409}
2410
2c1413a9
TT
2411/* A hash function for a varobj. */
2412
2413static hashval_t
2414hash_varobj (const void *a)
2415{
2416 const varobj *obj = (const varobj *) a;
2417 return htab_hash_string (obj->obj_name.c_str ());
2418}
2419
2420/* A hash table equality function for varobjs. */
2421
2422static int
2423eq_varobj_and_string (const void *a, const void *b)
2424{
2425 const varobj *obj = (const varobj *) a;
2426 const char *name = (const char *) b;
2427
2428 return obj->obj_name == name;
2429}
2430
6c265988 2431void _initialize_varobj ();
1c3569d4 2432void
6c265988 2433_initialize_varobj ()
1c3569d4 2434{
2c1413a9
TT
2435 varobj_table = htab_create_alloc (5, hash_varobj, eq_varobj_and_string,
2436 nullptr, xcalloc, xfree);
1c3569d4
MR
2437
2438 add_setshow_zuinteger_cmd ("varobj", class_maintenance,
2439 &varobjdebug,
2440 _("Set varobj debugging."),
2441 _("Show varobj debugging."),
2442 _("When non-zero, varobj debugging is enabled."),
2443 NULL, show_varobjdebug,
2444 &setdebuglist, &showdebuglist);
bc20e562
LS
2445
2446 gdb::observers::free_objfile.attach (varobj_invalidate_if_uses_objfile,
2447 "varobj");
1c3569d4 2448}