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