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