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