]> Git Repo - binutils.git/blame - gdb/mi/mi-cmd-var.c
2010-05-17 Michael Snyder <[email protected]>
[binutils.git] / gdb / mi / mi-cmd-var.c
CommitLineData
fb40c209 1/* MI Command Set - varobj commands.
349c5d5f 2
4c38e0a4 3 Copyright (C) 2000, 2002, 2004, 2005, 2007, 2008, 2009, 2010
9b254dd1 4 Free Software Foundation, Inc.
349c5d5f 5
ab91fdd5 6 Contributed by Cygnus Solutions (a Red Hat company).
fb40c209
AC
7
8 This file is part of GDB.
9
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
a9762ec7 12 the Free Software Foundation; either version 3 of the License, or
fb40c209
AC
13 (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
a9762ec7 21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
fb40c209
AC
22
23#include "defs.h"
24#include "mi-cmds.h"
25#include "ui-out.h"
26#include "mi-out.h"
27#include "varobj.h"
28#include "value.h"
29#include <ctype.h>
5f8a3188 30#include "gdb_string.h"
de051565 31#include "mi-getopt.h"
dbba8251 32#include "gdbthread.h"
fb40c209 33
1ecb4ee0
DJ
34const char mi_no_values[] = "--no-values";
35const char mi_simple_values[] = "--simple-values";
36const char mi_all_values[] = "--all-values";
37
8756216b 38extern int varobjdebug; /* defined in varobj.c. */
fb40c209 39
8756216b 40static void varobj_update_one (struct varobj *var,
25d5ea92
VP
41 enum print_values print_values,
42 int explicit);
fb40c209 43
0cc7d26f 44static int mi_print_value_p (struct varobj *var, enum print_values print_values);
a217f3f5
VP
45
46/* Print variable object VAR. The PRINT_VALUES parameter controls
47 if the value should be printed. The PRINT_EXPRESSION parameter
48 controls if the expression should be printed. */
49static void
50print_varobj (struct varobj *var, enum print_values print_values,
51 int print_expression)
52{
53 char *type;
c5b48eac 54 int thread_id;
0cc7d26f 55 char *display_hint;
a217f3f5
VP
56
57 ui_out_field_string (uiout, "name", varobj_get_objname (var));
58 if (print_expression)
59 ui_out_field_string (uiout, "exp", varobj_get_expression (var));
60 ui_out_field_int (uiout, "numchild", varobj_get_num_children (var));
61
0cc7d26f
TT
62 if (mi_print_value_p (var, print_values))
63 {
64 char *val = varobj_get_value (var);
65 ui_out_field_string (uiout, "value", val);
66 xfree (val);
67 }
a217f3f5
VP
68
69 type = varobj_get_type (var);
70 if (type != NULL)
71 {
72 ui_out_field_string (uiout, "type", type);
73 xfree (type);
74 }
25d5ea92 75
c5b48eac
VP
76 thread_id = varobj_get_thread_id (var);
77 if (thread_id > 0)
78 ui_out_field_int (uiout, "thread-id", thread_id);
79
25d5ea92
VP
80 if (varobj_get_frozen (var))
81 ui_out_field_int (uiout, "frozen", 1);
0cc7d26f
TT
82
83 display_hint = varobj_get_display_hint (var);
84 if (display_hint)
85 {
86 ui_out_field_string (uiout, "displayhint", display_hint);
87 xfree (display_hint);
88 }
89
90 if (varobj_pretty_printed_p (var))
91 ui_out_field_int (uiout, "dynamic", 1);
a217f3f5
VP
92}
93
fb40c209
AC
94/* VAROBJ operations */
95
ce8f13f8 96void
fb40c209
AC
97mi_cmd_var_create (char *command, char **argv, int argc)
98{
73a93a32 99 CORE_ADDR frameaddr = 0;
fb40c209
AC
100 struct varobj *var;
101 char *name;
102 char *frame;
103 char *expr;
fb40c209 104 struct cleanup *old_cleanups;
73a93a32 105 enum varobj_type var_type;
fb40c209
AC
106
107 if (argc != 3)
108 {
c6902d46
AC
109 /* mi_error_message = xstrprintf ("mi_cmd_var_create: Usage:
110 ...."); return MI_CMD_ERROR; */
8a3fe4f8 111 error (_("mi_cmd_var_create: Usage: NAME FRAME EXPRESSION."));
fb40c209
AC
112 }
113
114 name = xstrdup (argv[0]);
115 /* Add cleanup for name. Must be free_current_contents as
116 name can be reallocated */
47cf603e 117 old_cleanups = make_cleanup (free_current_contents, &name);
fb40c209
AC
118
119 frame = xstrdup (argv[1]);
51b57b6b 120 make_cleanup (xfree, frame);
fb40c209
AC
121
122 expr = xstrdup (argv[2]);
51b57b6b 123 make_cleanup (xfree, expr);
fb40c209
AC
124
125 if (strcmp (name, "-") == 0)
126 {
b8c9b27d 127 xfree (name);
fb40c209
AC
128 name = varobj_gen_name ();
129 }
130 else if (!isalpha (*name))
8a3fe4f8 131 error (_("mi_cmd_var_create: name of object must begin with a letter"));
fb40c209
AC
132
133 if (strcmp (frame, "*") == 0)
73a93a32
JI
134 var_type = USE_CURRENT_FRAME;
135 else if (strcmp (frame, "@") == 0)
136 var_type = USE_SELECTED_FRAME;
fb40c209 137 else
73a93a32
JI
138 {
139 var_type = USE_SPECIFIED_FRAME;
1bd34ded 140 frameaddr = string_to_core_addr (frame);
73a93a32 141 }
fb40c209
AC
142
143 if (varobjdebug)
144 fprintf_unfiltered (gdb_stdlog,
5af949e3
UW
145 "Name=\"%s\", Frame=\"%s\" (%s), Expression=\"%s\"\n",
146 name, frame, hex_string (frameaddr), expr);
fb40c209 147
73a93a32 148 var = varobj_create (name, expr, frameaddr, var_type);
fb40c209
AC
149
150 if (var == NULL)
8a3fe4f8 151 error (_("mi_cmd_var_create: unable to create variable object"));
fb40c209 152
224e4ca7 153 print_varobj (var, PRINT_ALL_VALUES, 0 /* don't print expression */);
fb40c209 154
0cc7d26f
TT
155 ui_out_field_int (uiout, "has_more", varobj_has_more (var, 0));
156
fb40c209 157 do_cleanups (old_cleanups);
fb40c209
AC
158}
159
ce8f13f8 160void
fb40c209
AC
161mi_cmd_var_delete (char *command, char **argv, int argc)
162{
163 char *name;
fb40c209
AC
164 struct varobj *var;
165 int numdel;
166 int children_only_p = 0;
167 struct cleanup *old_cleanups;
168
169 if (argc < 1 || argc > 2)
8a3fe4f8 170 error (_("mi_cmd_var_delete: Usage: [-c] EXPRESSION."));
fb40c209
AC
171
172 name = xstrdup (argv[0]);
173 /* Add cleanup for name. Must be free_current_contents as
174 name can be reallocated */
47cf603e 175 old_cleanups = make_cleanup (free_current_contents, &name);
fb40c209
AC
176
177 /* If we have one single argument it cannot be '-c' or any string
178 starting with '-'. */
179 if (argc == 1)
180 {
181 if (strcmp (name, "-c") == 0)
8a3fe4f8 182 error (_("mi_cmd_var_delete: Missing required argument after '-c': variable object name"));
fb40c209 183 if (*name == '-')
8a3fe4f8 184 error (_("mi_cmd_var_delete: Illegal variable object name"));
fb40c209
AC
185 }
186
187 /* If we have 2 arguments they must be '-c' followed by a string
188 which would be the variable name. */
189 if (argc == 2)
190 {
fb40c209 191 if (strcmp (name, "-c") != 0)
8a3fe4f8 192 error (_("mi_cmd_var_delete: Invalid option."));
fb40c209 193 children_only_p = 1;
474d0d0c
MS
194 do_cleanups (old_cleanups);
195 name = xstrdup (argv[1]);
196 make_cleanup (free_current_contents, &name);
fb40c209
AC
197 }
198
199 /* If we didn't error out, now NAME contains the name of the
200 variable. */
201
202 var = varobj_get_handle (name);
203
fb40c209
AC
204 numdel = varobj_delete (var, NULL, children_only_p);
205
206 ui_out_field_int (uiout, "ndeleted", numdel);
207
208 do_cleanups (old_cleanups);
fb40c209
AC
209}
210
de051565
MK
211/* Parse a string argument into a format value. */
212
213static enum varobj_display_formats
214mi_parse_format (const char *arg)
215{
216 if (arg != NULL)
217 {
218 int len;
219
220 len = strlen (arg);
221
222 if (strncmp (arg, "natural", len) == 0)
223 return FORMAT_NATURAL;
224 else if (strncmp (arg, "binary", len) == 0)
225 return FORMAT_BINARY;
226 else if (strncmp (arg, "decimal", len) == 0)
227 return FORMAT_DECIMAL;
228 else if (strncmp (arg, "hexadecimal", len) == 0)
229 return FORMAT_HEXADECIMAL;
230 else if (strncmp (arg, "octal", len) == 0)
231 return FORMAT_OCTAL;
232 }
233
234 error (_("Must specify the format as: \"natural\", \"binary\", \"decimal\", \"hexadecimal\", or \"octal\""));
235}
236
ce8f13f8 237void
fb40c209
AC
238mi_cmd_var_set_format (char *command, char **argv, int argc)
239{
240 enum varobj_display_formats format;
fb40c209 241 struct varobj *var;
0cc7d26f 242 char *val;
fb40c209
AC
243
244 if (argc != 2)
8a3fe4f8 245 error (_("mi_cmd_var_set_format: Usage: NAME FORMAT."));
fb40c209
AC
246
247 /* Get varobj handle, if a valid var obj name was specified */
248 var = varobj_get_handle (argv[0]);
249
de051565
MK
250 format = mi_parse_format (argv[1]);
251
fb40c209
AC
252 /* Set the format of VAR to given format */
253 varobj_set_display_format (var, format);
254
255 /* Report the new current format */
256 ui_out_field_string (uiout, "format", varobj_format_string[(int) format]);
00ee6348
NR
257
258 /* Report the value in the new format */
0cc7d26f
TT
259 val = varobj_get_value (var);
260 ui_out_field_string (uiout, "value", val);
261 xfree (val);
fb40c209
AC
262}
263
b6313243
TT
264void
265mi_cmd_var_set_visualizer (char *command, char **argv, int argc)
266{
267 struct varobj *var;
268
269 if (argc != 2)
270 error ("Usage: NAME VISUALIZER_FUNCTION.");
271
272 var = varobj_get_handle (argv[0]);
273
274 if (var == NULL)
275 error ("Variable object not found");
276
277 varobj_set_visualizer (var, argv[1]);
278}
279
ce8f13f8 280void
25d5ea92
VP
281mi_cmd_var_set_frozen (char *command, char **argv, int argc)
282{
283 struct varobj *var;
284 int frozen;
285
286 if (argc != 2)
287 error (_("-var-set-format: Usage: NAME FROZEN_FLAG."));
288
289 var = varobj_get_handle (argv[0]);
25d5ea92
VP
290
291 if (strcmp (argv[1], "0") == 0)
292 frozen = 0;
293 else if (strcmp (argv[1], "1") == 0)
294 frozen = 1;
295 else
296 error (_("Invalid flag value"));
297
298 varobj_set_frozen (var, frozen);
299
300 /* We don't automatically return the new value, or what varobjs got new
301 values during unfreezing. If this information is required, client
302 should call -var-update explicitly. */
25d5ea92
VP
303}
304
305
ce8f13f8 306void
fb40c209
AC
307mi_cmd_var_show_format (char *command, char **argv, int argc)
308{
309 enum varobj_display_formats format;
310 struct varobj *var;
311
312 if (argc != 1)
8a3fe4f8 313 error (_("mi_cmd_var_show_format: Usage: NAME."));
fb40c209
AC
314
315 /* Get varobj handle, if a valid var obj name was specified */
316 var = varobj_get_handle (argv[0]);
fb40c209
AC
317
318 format = varobj_get_display_format (var);
319
320 /* Report the current format */
321 ui_out_field_string (uiout, "format", varobj_format_string[(int) format]);
fb40c209
AC
322}
323
ce8f13f8 324void
fb40c209
AC
325mi_cmd_var_info_num_children (char *command, char **argv, int argc)
326{
327 struct varobj *var;
328
329 if (argc != 1)
8a3fe4f8 330 error (_("mi_cmd_var_info_num_children: Usage: NAME."));
fb40c209
AC
331
332 /* Get varobj handle, if a valid var obj name was specified */
333 var = varobj_get_handle (argv[0]);
fb40c209
AC
334
335 ui_out_field_int (uiout, "numchild", varobj_get_num_children (var));
fb40c209
AC
336}
337
1ecb4ee0
DJ
338/* Parse a string argument into a print_values value. */
339
340static enum print_values
341mi_parse_values_option (const char *arg)
342{
343 if (strcmp (arg, "0") == 0
344 || strcmp (arg, mi_no_values) == 0)
345 return PRINT_NO_VALUES;
346 else if (strcmp (arg, "1") == 0
347 || strcmp (arg, mi_all_values) == 0)
348 return PRINT_ALL_VALUES;
349 else if (strcmp (arg, "2") == 0
350 || strcmp (arg, mi_simple_values) == 0)
351 return PRINT_SIMPLE_VALUES;
352 else
353 error (_("Unknown value for PRINT_VALUES\n\
354Must be: 0 or \"%s\", 1 or \"%s\", 2 or \"%s\""),
355 mi_no_values, mi_simple_values, mi_all_values);
356}
357
358/* Return 1 if given the argument PRINT_VALUES we should display
0cc7d26f 359 the varobj VAR. */
1ecb4ee0
DJ
360
361static int
0cc7d26f 362mi_print_value_p (struct varobj *var, enum print_values print_values)
1ecb4ee0 363{
0cc7d26f 364 struct type *type;
1ecb4ee0
DJ
365
366 if (print_values == PRINT_NO_VALUES)
367 return 0;
368
369 if (print_values == PRINT_ALL_VALUES)
370 return 1;
371
0cc7d26f
TT
372 if (varobj_pretty_printed_p (var))
373 return 1;
374
375 type = varobj_get_gdb_type (var);
9265acad
NR
376 if (type == NULL)
377 return 1;
378 else
379 {
380 type = check_typedef (type);
1ecb4ee0 381
9265acad
NR
382 /* For PRINT_SIMPLE_VALUES, only print the value if it has a type
383 and that type is not a compound type. */
384 return (TYPE_CODE (type) != TYPE_CODE_ARRAY
385 && TYPE_CODE (type) != TYPE_CODE_STRUCT
386 && TYPE_CODE (type) != TYPE_CODE_UNION);
387 }
1ecb4ee0
DJ
388}
389
ce8f13f8 390void
fb40c209
AC
391mi_cmd_var_list_children (char *command, char **argv, int argc)
392{
d56d46f5
VP
393 struct varobj *var;
394 VEC(varobj_p) *children;
395 struct varobj *child;
c9e1f0fc 396 enum print_values print_values;
d56d46f5 397 int ix;
0cc7d26f 398 int from, to;
b6313243 399 char *display_hint;
fb40c209 400
0cc7d26f
TT
401 if (argc < 1 || argc > 4)
402 error (_("mi_cmd_var_list_children: Usage: [PRINT_VALUES] NAME [FROM TO]"));
fb40c209
AC
403
404 /* Get varobj handle, if a valid var obj name was specified */
0cc7d26f 405 if (argc == 1 || argc == 3)
1ecb4ee0
DJ
406 var = varobj_get_handle (argv[0]);
407 else
408 var = varobj_get_handle (argv[1]);
fb40c209 409
0cc7d26f
TT
410 if (argc > 2)
411 {
412 from = atoi (argv[argc - 2]);
413 to = atoi (argv[argc - 1]);
414 }
415 else
416 {
417 from = -1;
418 to = -1;
419 }
420
421 children = varobj_list_children (var, &from, &to);
422 ui_out_field_int (uiout, "numchild", to - from);
423 if (argc == 2 || argc == 4)
1ecb4ee0
DJ
424 print_values = mi_parse_values_option (argv[0]);
425 else
426 print_values = PRINT_NO_VALUES;
fb40c209 427
b6313243
TT
428 display_hint = varobj_get_display_hint (var);
429 if (display_hint)
430 {
431 ui_out_field_string (uiout, "displayhint", display_hint);
432 xfree (display_hint);
433 }
434
0cc7d26f 435 if (from < to)
fb40c209 436 {
0cc7d26f
TT
437 struct cleanup *cleanup_children;
438 if (mi_version (uiout) == 1)
439 cleanup_children
440 = make_cleanup_ui_out_tuple_begin_end (uiout, "children");
441 else
442 cleanup_children
443 = make_cleanup_ui_out_list_begin_end (uiout, "children");
444 for (ix = from;
445 ix < to && VEC_iterate (varobj_p, children, ix, child);
446 ++ix)
447 {
448 struct cleanup *cleanup_child;
449 cleanup_child = make_cleanup_ui_out_tuple_begin_end (uiout, "child");
450 print_varobj (child, print_values, 1 /* print expression */);
451 do_cleanups (cleanup_child);
452 }
453 do_cleanups (cleanup_children);
fb40c209 454 }
0cc7d26f
TT
455
456 ui_out_field_int (uiout, "has_more", varobj_has_more (var, to));
fb40c209
AC
457}
458
ce8f13f8 459void
fb40c209
AC
460mi_cmd_var_info_type (char *command, char **argv, int argc)
461{
462 struct varobj *var;
463
464 if (argc != 1)
8a3fe4f8 465 error (_("mi_cmd_var_info_type: Usage: NAME."));
fb40c209
AC
466
467 /* Get varobj handle, if a valid var obj name was specified */
468 var = varobj_get_handle (argv[0]);
fb40c209
AC
469
470 ui_out_field_string (uiout, "type", varobj_get_type (var));
fb40c209
AC
471}
472
ce8f13f8 473void
02142340
VP
474mi_cmd_var_info_path_expression (char *command, char **argv, int argc)
475{
476 struct varobj *var;
477 char *path_expr;
478
479 if (argc != 1)
480 error (_("Usage: NAME."));
481
482 /* Get varobj handle, if a valid var obj name was specified. */
483 var = varobj_get_handle (argv[0]);
02142340
VP
484
485 path_expr = varobj_get_path_expr (var);
486
487 ui_out_field_string (uiout, "path_expr", path_expr);
02142340
VP
488}
489
ce8f13f8 490void
fb40c209
AC
491mi_cmd_var_info_expression (char *command, char **argv, int argc)
492{
493 enum varobj_languages lang;
494 struct varobj *var;
495
496 if (argc != 1)
8a3fe4f8 497 error (_("mi_cmd_var_info_expression: Usage: NAME."));
fb40c209
AC
498
499 /* Get varobj handle, if a valid var obj name was specified */
500 var = varobj_get_handle (argv[0]);
fb40c209
AC
501
502 lang = varobj_get_language (var);
503
504 ui_out_field_string (uiout, "lang", varobj_language_string[(int) lang]);
505 ui_out_field_string (uiout, "exp", varobj_get_expression (var));
fb40c209
AC
506}
507
ce8f13f8 508void
fb40c209
AC
509mi_cmd_var_show_attributes (char *command, char **argv, int argc)
510{
511 int attr;
512 char *attstr;
513 struct varobj *var;
514
515 if (argc != 1)
8a3fe4f8 516 error (_("mi_cmd_var_show_attributes: Usage: NAME."));
fb40c209
AC
517
518 /* Get varobj handle, if a valid var obj name was specified */
519 var = varobj_get_handle (argv[0]);
fb40c209
AC
520
521 attr = varobj_get_attributes (var);
522 /* FIXME: define masks for attributes */
523 if (attr & 0x00000001)
524 attstr = "editable";
525 else
526 attstr = "noneditable";
527
528 ui_out_field_string (uiout, "attr", attstr);
fb40c209
AC
529}
530
ce8f13f8 531void
fb40c209
AC
532mi_cmd_var_evaluate_expression (char *command, char **argv, int argc)
533{
534 struct varobj *var;
535
de051565
MK
536 enum varobj_display_formats format;
537 int formatFound;
538 int optind;
539 char *optarg;
540
541 enum opt
542 {
543 OP_FORMAT
544 };
545 static struct mi_opt opts[] =
546 {
547 {"f", OP_FORMAT, 1},
548 { 0, 0, 0 }
549 };
550
551 /* Parse arguments */
552 format = FORMAT_NATURAL;
553 formatFound = 0;
554 optind = 0;
555 while (1)
556 {
557 int opt = mi_getopt ("-var-evaluate-expression", argc, argv, opts, &optind, &optarg);
558 if (opt < 0)
559 break;
560 switch ((enum opt) opt)
561 {
562 case OP_FORMAT:
563 if (formatFound)
564 error (_("Cannot specify format more than once"));
565
566 format = mi_parse_format (optarg);
567 formatFound = 1;
568 break;
569 }
570 }
fb40c209 571
de051565
MK
572 if (optind >= argc)
573 error (_("Usage: [-f FORMAT] NAME"));
574
575 if (optind < argc - 1)
576 error (_("Garbage at end of command"));
577
578 /* Get varobj handle, if a valid var obj name was specified */
579 var = varobj_get_handle (argv[optind]);
de051565
MK
580
581 if (formatFound)
0cc7d26f
TT
582 {
583 char *val = varobj_get_formatted_value (var, format);
584 ui_out_field_string (uiout, "value", val);
585 xfree (val);
586 }
de051565 587 else
0cc7d26f
TT
588 {
589 char *val = varobj_get_value (var);
590 ui_out_field_string (uiout, "value", val);
591 xfree (val);
592 }
fb40c209
AC
593}
594
ce8f13f8 595void
fb40c209
AC
596mi_cmd_var_assign (char *command, char **argv, int argc)
597{
598 struct varobj *var;
0cc7d26f 599 char *expression, *val;
fb40c209
AC
600
601 if (argc != 2)
8a3fe4f8 602 error (_("mi_cmd_var_assign: Usage: NAME EXPRESSION."));
fb40c209
AC
603
604 /* Get varobj handle, if a valid var obj name was specified */
605 var = varobj_get_handle (argv[0]);
fb40c209 606
d2562500 607 if (!varobj_editable_p (var))
8a3fe4f8 608 error (_("mi_cmd_var_assign: Variable object is not editable"));
fb40c209
AC
609
610 expression = xstrdup (argv[1]);
611
612 if (!varobj_set_value (var, expression))
98a29c7e 613 error (_("mi_cmd_var_assign: Could not assign expression to variable object"));
fb40c209 614
0cc7d26f
TT
615 val = varobj_get_value (var);
616 ui_out_field_string (uiout, "value", val);
617 xfree (val);
fb40c209
AC
618}
619
54333c3b
JK
620/* Type used for parameters passing to mi_cmd_var_update_iter. */
621
622struct mi_cmd_var_update
623 {
624 int only_floating;
625 enum print_values print_values;
626 };
627
628/* Helper for mi_cmd_var_update - update each VAR. */
629
630static void
631mi_cmd_var_update_iter (struct varobj *var, void *data_pointer)
632{
633 struct mi_cmd_var_update *data = data_pointer;
634 int thread_id, thread_stopped;
635
636 thread_id = varobj_get_thread_id (var);
637
638 if (thread_id == -1 && is_stopped (inferior_ptid))
639 thread_stopped = 1;
640 else
641 {
642 struct thread_info *tp = find_thread_id (thread_id);
643
644 if (tp)
645 thread_stopped = is_stopped (tp->ptid);
646 else
647 thread_stopped = 1;
648 }
649
650 if (thread_stopped)
651 if (!data->only_floating || varobj_floating_p (var))
652 varobj_update_one (var, data->print_values, 0 /* implicit */);
653}
654
ce8f13f8 655void
fb40c209
AC
656mi_cmd_var_update (char *command, char **argv, int argc)
657{
3a387118 658 struct cleanup *cleanup;
fb40c209 659 char *name;
1ecb4ee0 660 enum print_values print_values;
fb40c209 661
1ecb4ee0
DJ
662 if (argc != 1 && argc != 2)
663 error (_("mi_cmd_var_update: Usage: [PRINT_VALUES] NAME."));
664
665 if (argc == 1)
666 name = argv[0];
667 else
668 name = (argv[1]);
fb40c209 669
1ecb4ee0
DJ
670 if (argc == 2)
671 print_values = mi_parse_values_option (argv[0]);
672 else
673 print_values = PRINT_NO_VALUES;
fb40c209 674
6e9ef2a8
JK
675 if (mi_version (uiout) <= 1)
676 cleanup = make_cleanup_ui_out_tuple_begin_end (uiout, "changelist");
677 else
678 cleanup = make_cleanup_ui_out_list_begin_end (uiout, "changelist");
679
fb40c209
AC
680 /* Check if the parameter is a "*" which means that we want
681 to update all variables */
682
5a413362 683 if ((*name == '*' || *name == '@') && (*(name + 1) == '\0'))
fb40c209 684 {
54333c3b
JK
685 struct mi_cmd_var_update data;
686
687 data.only_floating = *name == '@';
688 data.print_values = print_values;
689
690 /* varobj_update_one automatically updates all the children of VAROBJ.
691 Therefore update each VAROBJ only once by iterating only the root
692 VAROBJs. */
693
694 all_root_varobjs (mi_cmd_var_update_iter, &data);
fb40c209
AC
695 }
696 else
697 {
698 /* Get varobj handle, if a valid var obj name was specified */
6e9ef2a8 699 struct varobj *var = varobj_get_handle (name);
fb40c209 700
25d5ea92 701 varobj_update_one (var, print_values, 1 /* explicit */);
fb40c209 702 }
6e9ef2a8
JK
703
704 do_cleanups (cleanup);
fb40c209
AC
705}
706
8756216b 707/* Helper for mi_cmd_var_update(). */
fb40c209 708
8756216b 709static void
25d5ea92
VP
710varobj_update_one (struct varobj *var, enum print_values print_values,
711 int explicit)
fb40c209 712{
3a387118 713 struct cleanup *cleanup = NULL;
f7f9ae2c
VP
714 VEC (varobj_update_result) *changes;
715 varobj_update_result *r;
716 int i;
717
718 changes = varobj_update (&var, explicit);
73a93a32 719
f7f9ae2c 720 for (i = 0; VEC_iterate (varobj_update_result, changes, i, r); ++i)
fb40c209 721 {
b6313243 722 char *display_hint;
0cc7d26f 723 int from, to;
b6313243 724
3a387118
JJ
725 if (mi_version (uiout) > 1)
726 cleanup = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
f7f9ae2c 727 ui_out_field_string (uiout, "name", varobj_get_objname (r->varobj));
8756216b 728
f7f9ae2c
VP
729 switch (r->status)
730 {
731 case VAROBJ_IN_SCOPE:
0cc7d26f
TT
732 if (mi_print_value_p (r->varobj, print_values))
733 {
734 char *val = varobj_get_value (r->varobj);
735 ui_out_field_string (uiout, "value", val);
736 xfree (val);
737 }
f7f9ae2c
VP
738 ui_out_field_string (uiout, "in_scope", "true");
739 break;
740 case VAROBJ_NOT_IN_SCOPE:
8756216b
DP
741 ui_out_field_string (uiout, "in_scope", "false");
742 break;
f7f9ae2c 743 case VAROBJ_INVALID:
8756216b
DP
744 ui_out_field_string (uiout, "in_scope", "invalid");
745 break;
f7f9ae2c
VP
746 }
747
748 if (r->status != VAROBJ_INVALID)
73a93a32 749 {
f7f9ae2c
VP
750 if (r->type_changed)
751 ui_out_field_string (uiout, "type_changed", "true");
752 else
753 ui_out_field_string (uiout, "type_changed", "false");
73a93a32 754 }
f7f9ae2c
VP
755
756 if (r->type_changed)
0cc7d26f
TT
757 ui_out_field_string (uiout, "new_type", varobj_get_type (r->varobj));
758
759 if (r->type_changed || r->children_changed)
760 ui_out_field_int (uiout, "new_num_children",
761 varobj_get_num_children (r->varobj));
b6313243
TT
762
763 display_hint = varobj_get_display_hint (var);
764 if (display_hint)
765 {
766 ui_out_field_string (uiout, "displayhint", display_hint);
767 xfree (display_hint);
768 }
769
0cc7d26f
TT
770 if (varobj_pretty_printed_p (var))
771 ui_out_field_int (uiout, "dynamic", 1);
b6313243 772
0cc7d26f
TT
773 varobj_get_child_range (r->varobj, &from, &to);
774 ui_out_field_int (uiout, "has_more",
775 varobj_has_more (r->varobj, to));
b6313243 776
0cc7d26f
TT
777 if (r->new)
778 {
779 int j;
780 varobj_p child;
781 struct cleanup *cleanup;
782
783 cleanup = make_cleanup_ui_out_list_begin_end (uiout, "new_children");
784 for (j = 0; VEC_iterate (varobj_p, r->new, j, child); ++j)
b6313243
TT
785 {
786 struct cleanup *cleanup_child;
787 cleanup_child = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
0cc7d26f 788 print_varobj (child, print_values, 1 /* print_expression */);
b6313243
TT
789 do_cleanups (cleanup_child);
790 }
791
792 do_cleanups (cleanup);
0cc7d26f
TT
793 VEC_free (varobj_p, r->new);
794 r->new = NULL; /* Paranoia. */
b6313243 795 }
0cc7d26f 796
f7f9ae2c
VP
797 if (mi_version (uiout) > 1)
798 do_cleanups (cleanup);
fb40c209 799 }
f7f9ae2c 800 VEC_free (varobj_update_result, changes);
fb40c209 801}
0cc7d26f
TT
802
803void
804mi_cmd_enable_pretty_printing (char *command, char **argv, int argc)
805{
806 if (argc != 0)
807 error (_("mi_cmd_enable_pretty_printing: no arguments allowed"));
808 varobj_enable_pretty_printing ();
809}
810
811void
812mi_cmd_var_set_update_range (char *command, char **argv, int argc)
813{
814 struct varobj *var;
815 int from, to;
816
817 if (argc != 3)
818 error (_("mi_cmd_var_set_update_range: Usage: VAROBJ FROM TO"));
819
820 var = varobj_get_handle (argv[0]);
821 from = atoi (argv[1]);
822 to = atoi (argv[2]);
823
824 varobj_set_child_range (var, from, to);
825}
This page took 1.860465 seconds and 4 git commands to generate.