]>
Commit | Line | Data |
---|---|---|
fb40c209 | 1 | /* MI Command Set - varobj commands. |
349c5d5f | 2 | |
6aba47ca | 3 | Copyright (C) 2000, 2002, 2004, 2005, 2007 Free Software Foundation, Inc. |
349c5d5f | 4 | |
ab91fdd5 | 5 | Contributed by Cygnus Solutions (a Red Hat company). |
fb40c209 AC |
6 | |
7 | This file is part of GDB. | |
8 | ||
9 | This program is free software; you can redistribute it and/or modify | |
10 | it under the terms of the GNU General Public License as published by | |
11 | the Free Software Foundation; either version 2 of the License, or | |
12 | (at your option) any later version. | |
13 | ||
14 | This program is distributed in the hope that it will be useful, | |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | GNU General Public License for more details. | |
18 | ||
19 | You should have received a copy of the GNU General Public License | |
20 | along with this program; if not, write to the Free Software | |
1caae165 EZ |
21 | Foundation, Inc., 51 Franklin Street, Fifth Floor, |
22 | Boston, MA 02110-1301, USA. */ | |
fb40c209 AC |
23 | |
24 | #include "defs.h" | |
25 | #include "mi-cmds.h" | |
26 | #include "ui-out.h" | |
27 | #include "mi-out.h" | |
28 | #include "varobj.h" | |
29 | #include "value.h" | |
30 | #include <ctype.h> | |
5f8a3188 | 31 | #include "gdb_string.h" |
fb40c209 | 32 | |
1ecb4ee0 DJ |
33 | const char mi_no_values[] = "--no-values"; |
34 | const char mi_simple_values[] = "--simple-values"; | |
35 | const char mi_all_values[] = "--all-values"; | |
36 | ||
fb40c209 AC |
37 | extern int varobjdebug; /* defined in varobj.c */ |
38 | ||
1ecb4ee0 DJ |
39 | static int varobj_update_one (struct varobj *var, |
40 | enum print_values print_values); | |
fb40c209 | 41 | |
a217f3f5 VP |
42 | static int mi_print_value_p (struct type *type, enum print_values print_values); |
43 | ||
44 | /* Print variable object VAR. The PRINT_VALUES parameter controls | |
45 | if the value should be printed. The PRINT_EXPRESSION parameter | |
46 | controls if the expression should be printed. */ | |
47 | static void | |
48 | print_varobj (struct varobj *var, enum print_values print_values, | |
49 | int print_expression) | |
50 | { | |
51 | char *type; | |
52 | ||
53 | ui_out_field_string (uiout, "name", varobj_get_objname (var)); | |
54 | if (print_expression) | |
55 | ui_out_field_string (uiout, "exp", varobj_get_expression (var)); | |
56 | ui_out_field_int (uiout, "numchild", varobj_get_num_children (var)); | |
57 | ||
58 | if (mi_print_value_p (varobj_get_gdb_type (var), print_values)) | |
59 | ui_out_field_string (uiout, "value", varobj_get_value (var)); | |
60 | ||
61 | type = varobj_get_type (var); | |
62 | if (type != NULL) | |
63 | { | |
64 | ui_out_field_string (uiout, "type", type); | |
65 | xfree (type); | |
66 | } | |
67 | } | |
68 | ||
fb40c209 AC |
69 | /* VAROBJ operations */ |
70 | ||
71 | enum mi_cmd_result | |
72 | mi_cmd_var_create (char *command, char **argv, int argc) | |
73 | { | |
73a93a32 | 74 | CORE_ADDR frameaddr = 0; |
fb40c209 AC |
75 | struct varobj *var; |
76 | char *name; | |
77 | char *frame; | |
78 | char *expr; | |
fb40c209 | 79 | struct cleanup *old_cleanups; |
73a93a32 | 80 | enum varobj_type var_type; |
fb40c209 AC |
81 | |
82 | if (argc != 3) | |
83 | { | |
c6902d46 AC |
84 | /* mi_error_message = xstrprintf ("mi_cmd_var_create: Usage: |
85 | ...."); return MI_CMD_ERROR; */ | |
8a3fe4f8 | 86 | error (_("mi_cmd_var_create: Usage: NAME FRAME EXPRESSION.")); |
fb40c209 AC |
87 | } |
88 | ||
89 | name = xstrdup (argv[0]); | |
90 | /* Add cleanup for name. Must be free_current_contents as | |
91 | name can be reallocated */ | |
47cf603e | 92 | old_cleanups = make_cleanup (free_current_contents, &name); |
fb40c209 AC |
93 | |
94 | frame = xstrdup (argv[1]); | |
51b57b6b | 95 | make_cleanup (xfree, frame); |
fb40c209 AC |
96 | |
97 | expr = xstrdup (argv[2]); | |
51b57b6b | 98 | make_cleanup (xfree, expr); |
fb40c209 AC |
99 | |
100 | if (strcmp (name, "-") == 0) | |
101 | { | |
b8c9b27d | 102 | xfree (name); |
fb40c209 AC |
103 | name = varobj_gen_name (); |
104 | } | |
105 | else if (!isalpha (*name)) | |
8a3fe4f8 | 106 | error (_("mi_cmd_var_create: name of object must begin with a letter")); |
fb40c209 AC |
107 | |
108 | if (strcmp (frame, "*") == 0) | |
73a93a32 JI |
109 | var_type = USE_CURRENT_FRAME; |
110 | else if (strcmp (frame, "@") == 0) | |
111 | var_type = USE_SELECTED_FRAME; | |
fb40c209 | 112 | else |
73a93a32 JI |
113 | { |
114 | var_type = USE_SPECIFIED_FRAME; | |
1bd34ded | 115 | frameaddr = string_to_core_addr (frame); |
73a93a32 | 116 | } |
fb40c209 AC |
117 | |
118 | if (varobjdebug) | |
119 | fprintf_unfiltered (gdb_stdlog, | |
120 | "Name=\"%s\", Frame=\"%s\" (0x%s), Expression=\"%s\"\n", | |
121 | name, frame, paddr (frameaddr), expr); | |
122 | ||
73a93a32 | 123 | var = varobj_create (name, expr, frameaddr, var_type); |
fb40c209 AC |
124 | |
125 | if (var == NULL) | |
8a3fe4f8 | 126 | error (_("mi_cmd_var_create: unable to create variable object")); |
fb40c209 | 127 | |
a217f3f5 | 128 | print_varobj (var, PRINT_NO_VALUES, 0 /* don't print expression */); |
fb40c209 AC |
129 | |
130 | do_cleanups (old_cleanups); | |
131 | return MI_CMD_DONE; | |
132 | } | |
133 | ||
134 | enum mi_cmd_result | |
135 | mi_cmd_var_delete (char *command, char **argv, int argc) | |
136 | { | |
137 | char *name; | |
138 | char *expr; | |
139 | struct varobj *var; | |
140 | int numdel; | |
141 | int children_only_p = 0; | |
142 | struct cleanup *old_cleanups; | |
143 | ||
144 | if (argc < 1 || argc > 2) | |
8a3fe4f8 | 145 | error (_("mi_cmd_var_delete: Usage: [-c] EXPRESSION.")); |
fb40c209 AC |
146 | |
147 | name = xstrdup (argv[0]); | |
148 | /* Add cleanup for name. Must be free_current_contents as | |
149 | name can be reallocated */ | |
47cf603e | 150 | old_cleanups = make_cleanup (free_current_contents, &name); |
fb40c209 AC |
151 | |
152 | /* If we have one single argument it cannot be '-c' or any string | |
153 | starting with '-'. */ | |
154 | if (argc == 1) | |
155 | { | |
156 | if (strcmp (name, "-c") == 0) | |
8a3fe4f8 | 157 | error (_("mi_cmd_var_delete: Missing required argument after '-c': variable object name")); |
fb40c209 | 158 | if (*name == '-') |
8a3fe4f8 | 159 | error (_("mi_cmd_var_delete: Illegal variable object name")); |
fb40c209 AC |
160 | } |
161 | ||
162 | /* If we have 2 arguments they must be '-c' followed by a string | |
163 | which would be the variable name. */ | |
164 | if (argc == 2) | |
165 | { | |
166 | expr = xstrdup (argv[1]); | |
167 | if (strcmp (name, "-c") != 0) | |
8a3fe4f8 | 168 | error (_("mi_cmd_var_delete: Invalid option.")); |
fb40c209 | 169 | children_only_p = 1; |
b8c9b27d | 170 | xfree (name); |
fb40c209 | 171 | name = xstrdup (expr); |
b8c9b27d | 172 | xfree (expr); |
fb40c209 AC |
173 | } |
174 | ||
175 | /* If we didn't error out, now NAME contains the name of the | |
176 | variable. */ | |
177 | ||
178 | var = varobj_get_handle (name); | |
179 | ||
180 | if (var == NULL) | |
8a3fe4f8 | 181 | error (_("mi_cmd_var_delete: Variable object not found.")); |
fb40c209 AC |
182 | |
183 | numdel = varobj_delete (var, NULL, children_only_p); | |
184 | ||
185 | ui_out_field_int (uiout, "ndeleted", numdel); | |
186 | ||
187 | do_cleanups (old_cleanups); | |
188 | return MI_CMD_DONE; | |
189 | } | |
190 | ||
191 | enum mi_cmd_result | |
192 | mi_cmd_var_set_format (char *command, char **argv, int argc) | |
193 | { | |
194 | enum varobj_display_formats format; | |
195 | int len; | |
196 | struct varobj *var; | |
197 | char *formspec; | |
198 | ||
199 | if (argc != 2) | |
8a3fe4f8 | 200 | error (_("mi_cmd_var_set_format: Usage: NAME FORMAT.")); |
fb40c209 AC |
201 | |
202 | /* Get varobj handle, if a valid var obj name was specified */ | |
203 | var = varobj_get_handle (argv[0]); | |
204 | ||
205 | if (var == NULL) | |
8a3fe4f8 | 206 | error (_("mi_cmd_var_set_format: Variable object not found")); |
fb40c209 AC |
207 | |
208 | formspec = xstrdup (argv[1]); | |
209 | if (formspec == NULL) | |
8a3fe4f8 | 210 | error (_("mi_cmd_var_set_format: Must specify the format as: \"natural\", \"binary\", \"decimal\", \"hexadecimal\", or \"octal\"")); |
fb40c209 AC |
211 | |
212 | len = strlen (formspec); | |
213 | ||
bf896cb0 | 214 | if (strncmp (formspec, "natural", len) == 0) |
fb40c209 | 215 | format = FORMAT_NATURAL; |
bf896cb0 | 216 | else if (strncmp (formspec, "binary", len) == 0) |
fb40c209 | 217 | format = FORMAT_BINARY; |
bf896cb0 | 218 | else if (strncmp (formspec, "decimal", len) == 0) |
fb40c209 | 219 | format = FORMAT_DECIMAL; |
bf896cb0 | 220 | else if (strncmp (formspec, "hexadecimal", len) == 0) |
fb40c209 | 221 | format = FORMAT_HEXADECIMAL; |
bf896cb0 | 222 | else if (strncmp (formspec, "octal", len) == 0) |
fb40c209 AC |
223 | format = FORMAT_OCTAL; |
224 | else | |
8a3fe4f8 | 225 | error (_("mi_cmd_var_set_format: Unknown display format: must be: \"natural\", \"binary\", \"decimal\", \"hexadecimal\", or \"octal\"")); |
fb40c209 AC |
226 | |
227 | /* Set the format of VAR to given format */ | |
228 | varobj_set_display_format (var, format); | |
229 | ||
230 | /* Report the new current format */ | |
231 | ui_out_field_string (uiout, "format", varobj_format_string[(int) format]); | |
232 | return MI_CMD_DONE; | |
233 | } | |
234 | ||
235 | enum mi_cmd_result | |
236 | mi_cmd_var_show_format (char *command, char **argv, int argc) | |
237 | { | |
238 | enum varobj_display_formats format; | |
239 | struct varobj *var; | |
240 | ||
241 | if (argc != 1) | |
8a3fe4f8 | 242 | error (_("mi_cmd_var_show_format: Usage: NAME.")); |
fb40c209 AC |
243 | |
244 | /* Get varobj handle, if a valid var obj name was specified */ | |
245 | var = varobj_get_handle (argv[0]); | |
246 | if (var == NULL) | |
8a3fe4f8 | 247 | error (_("mi_cmd_var_show_format: Variable object not found")); |
fb40c209 AC |
248 | |
249 | format = varobj_get_display_format (var); | |
250 | ||
251 | /* Report the current format */ | |
252 | ui_out_field_string (uiout, "format", varobj_format_string[(int) format]); | |
253 | return MI_CMD_DONE; | |
254 | } | |
255 | ||
256 | enum mi_cmd_result | |
257 | mi_cmd_var_info_num_children (char *command, char **argv, int argc) | |
258 | { | |
259 | struct varobj *var; | |
260 | ||
261 | if (argc != 1) | |
8a3fe4f8 | 262 | error (_("mi_cmd_var_info_num_children: Usage: NAME.")); |
fb40c209 AC |
263 | |
264 | /* Get varobj handle, if a valid var obj name was specified */ | |
265 | var = varobj_get_handle (argv[0]); | |
266 | if (var == NULL) | |
8a3fe4f8 | 267 | error (_("mi_cmd_var_info_num_children: Variable object not found")); |
fb40c209 AC |
268 | |
269 | ui_out_field_int (uiout, "numchild", varobj_get_num_children (var)); | |
270 | return MI_CMD_DONE; | |
271 | } | |
272 | ||
1ecb4ee0 DJ |
273 | /* Parse a string argument into a print_values value. */ |
274 | ||
275 | static enum print_values | |
276 | mi_parse_values_option (const char *arg) | |
277 | { | |
278 | if (strcmp (arg, "0") == 0 | |
279 | || strcmp (arg, mi_no_values) == 0) | |
280 | return PRINT_NO_VALUES; | |
281 | else if (strcmp (arg, "1") == 0 | |
282 | || strcmp (arg, mi_all_values) == 0) | |
283 | return PRINT_ALL_VALUES; | |
284 | else if (strcmp (arg, "2") == 0 | |
285 | || strcmp (arg, mi_simple_values) == 0) | |
286 | return PRINT_SIMPLE_VALUES; | |
287 | else | |
288 | error (_("Unknown value for PRINT_VALUES\n\ | |
289 | Must be: 0 or \"%s\", 1 or \"%s\", 2 or \"%s\""), | |
290 | mi_no_values, mi_simple_values, mi_all_values); | |
291 | } | |
292 | ||
293 | /* Return 1 if given the argument PRINT_VALUES we should display | |
294 | a value of type TYPE. */ | |
295 | ||
296 | static int | |
297 | mi_print_value_p (struct type *type, enum print_values print_values) | |
298 | { | |
299 | if (type != NULL) | |
300 | type = check_typedef (type); | |
301 | ||
302 | if (print_values == PRINT_NO_VALUES) | |
303 | return 0; | |
304 | ||
305 | if (print_values == PRINT_ALL_VALUES) | |
306 | return 1; | |
307 | ||
308 | /* For PRINT_SIMPLE_VALUES, only print the value if it has a type | |
309 | and that type is not a compound type. */ | |
310 | ||
311 | return (TYPE_CODE (type) != TYPE_CODE_ARRAY | |
312 | && TYPE_CODE (type) != TYPE_CODE_STRUCT | |
313 | && TYPE_CODE (type) != TYPE_CODE_UNION); | |
314 | } | |
315 | ||
fb40c209 AC |
316 | enum mi_cmd_result |
317 | mi_cmd_var_list_children (char *command, char **argv, int argc) | |
318 | { | |
319 | struct varobj *var; | |
320 | struct varobj **childlist; | |
321 | struct varobj **cc; | |
6ad4a2cf | 322 | struct cleanup *cleanup_children; |
fb40c209 | 323 | int numchild; |
c9e1f0fc | 324 | enum print_values print_values; |
fb40c209 | 325 | |
c9e1f0fc | 326 | if (argc != 1 && argc != 2) |
8a3fe4f8 | 327 | error (_("mi_cmd_var_list_children: Usage: [PRINT_VALUES] NAME")); |
fb40c209 AC |
328 | |
329 | /* Get varobj handle, if a valid var obj name was specified */ | |
1ecb4ee0 DJ |
330 | if (argc == 1) |
331 | var = varobj_get_handle (argv[0]); | |
332 | else | |
333 | var = varobj_get_handle (argv[1]); | |
fb40c209 | 334 | if (var == NULL) |
8a3fe4f8 | 335 | error (_("Variable object not found")); |
fb40c209 AC |
336 | |
337 | numchild = varobj_list_children (var, &childlist); | |
338 | ui_out_field_int (uiout, "numchild", numchild); | |
c9e1f0fc | 339 | if (argc == 2) |
1ecb4ee0 DJ |
340 | print_values = mi_parse_values_option (argv[0]); |
341 | else | |
342 | print_values = PRINT_NO_VALUES; | |
fb40c209 AC |
343 | |
344 | if (numchild <= 0) | |
345 | return MI_CMD_DONE; | |
346 | ||
e7494ffb AC |
347 | if (mi_version (uiout) == 1) |
348 | cleanup_children = make_cleanup_ui_out_tuple_begin_end (uiout, "children"); | |
349 | else | |
350 | cleanup_children = make_cleanup_ui_out_list_begin_end (uiout, "children"); | |
fb40c209 AC |
351 | cc = childlist; |
352 | while (*cc != NULL) | |
353 | { | |
6ad4a2cf JJ |
354 | struct cleanup *cleanup_child; |
355 | cleanup_child = make_cleanup_ui_out_tuple_begin_end (uiout, "child"); | |
a217f3f5 | 356 | print_varobj (*cc, print_values, 1 /* print expression */); |
fb40c209 | 357 | cc++; |
a217f3f5 | 358 | do_cleanups (cleanup_child); |
fb40c209 | 359 | } |
6ad4a2cf | 360 | do_cleanups (cleanup_children); |
b8c9b27d | 361 | xfree (childlist); |
fb40c209 AC |
362 | return MI_CMD_DONE; |
363 | } | |
364 | ||
365 | enum mi_cmd_result | |
366 | mi_cmd_var_info_type (char *command, char **argv, int argc) | |
367 | { | |
368 | struct varobj *var; | |
369 | ||
370 | if (argc != 1) | |
8a3fe4f8 | 371 | error (_("mi_cmd_var_info_type: Usage: NAME.")); |
fb40c209 AC |
372 | |
373 | /* Get varobj handle, if a valid var obj name was specified */ | |
374 | var = varobj_get_handle (argv[0]); | |
375 | if (var == NULL) | |
8a3fe4f8 | 376 | error (_("mi_cmd_var_info_type: Variable object not found")); |
fb40c209 AC |
377 | |
378 | ui_out_field_string (uiout, "type", varobj_get_type (var)); | |
379 | return MI_CMD_DONE; | |
380 | } | |
381 | ||
382 | enum mi_cmd_result | |
383 | mi_cmd_var_info_expression (char *command, char **argv, int argc) | |
384 | { | |
385 | enum varobj_languages lang; | |
386 | struct varobj *var; | |
387 | ||
388 | if (argc != 1) | |
8a3fe4f8 | 389 | error (_("mi_cmd_var_info_expression: Usage: NAME.")); |
fb40c209 AC |
390 | |
391 | /* Get varobj handle, if a valid var obj name was specified */ | |
392 | var = varobj_get_handle (argv[0]); | |
393 | if (var == NULL) | |
8a3fe4f8 | 394 | error (_("mi_cmd_var_info_expression: Variable object not found")); |
fb40c209 AC |
395 | |
396 | lang = varobj_get_language (var); | |
397 | ||
398 | ui_out_field_string (uiout, "lang", varobj_language_string[(int) lang]); | |
399 | ui_out_field_string (uiout, "exp", varobj_get_expression (var)); | |
400 | return MI_CMD_DONE; | |
401 | } | |
402 | ||
403 | enum mi_cmd_result | |
404 | mi_cmd_var_show_attributes (char *command, char **argv, int argc) | |
405 | { | |
406 | int attr; | |
407 | char *attstr; | |
408 | struct varobj *var; | |
409 | ||
410 | if (argc != 1) | |
8a3fe4f8 | 411 | error (_("mi_cmd_var_show_attributes: Usage: NAME.")); |
fb40c209 AC |
412 | |
413 | /* Get varobj handle, if a valid var obj name was specified */ | |
414 | var = varobj_get_handle (argv[0]); | |
415 | if (var == NULL) | |
8a3fe4f8 | 416 | error (_("mi_cmd_var_show_attributes: Variable object not found")); |
fb40c209 AC |
417 | |
418 | attr = varobj_get_attributes (var); | |
419 | /* FIXME: define masks for attributes */ | |
420 | if (attr & 0x00000001) | |
421 | attstr = "editable"; | |
422 | else | |
423 | attstr = "noneditable"; | |
424 | ||
425 | ui_out_field_string (uiout, "attr", attstr); | |
426 | return MI_CMD_DONE; | |
427 | } | |
428 | ||
429 | enum mi_cmd_result | |
430 | mi_cmd_var_evaluate_expression (char *command, char **argv, int argc) | |
431 | { | |
432 | struct varobj *var; | |
433 | ||
434 | if (argc != 1) | |
8a3fe4f8 | 435 | error (_("mi_cmd_var_evaluate_expression: Usage: NAME.")); |
fb40c209 AC |
436 | |
437 | /* Get varobj handle, if a valid var obj name was specified */ | |
438 | var = varobj_get_handle (argv[0]); | |
439 | if (var == NULL) | |
8a3fe4f8 | 440 | error (_("mi_cmd_var_evaluate_expression: Variable object not found")); |
fb40c209 AC |
441 | |
442 | ui_out_field_string (uiout, "value", varobj_get_value (var)); | |
443 | return MI_CMD_DONE; | |
444 | } | |
445 | ||
446 | enum mi_cmd_result | |
447 | mi_cmd_var_assign (char *command, char **argv, int argc) | |
448 | { | |
449 | struct varobj *var; | |
450 | char *expression; | |
451 | ||
452 | if (argc != 2) | |
8a3fe4f8 | 453 | error (_("mi_cmd_var_assign: Usage: NAME EXPRESSION.")); |
fb40c209 AC |
454 | |
455 | /* Get varobj handle, if a valid var obj name was specified */ | |
456 | var = varobj_get_handle (argv[0]); | |
457 | if (var == NULL) | |
8a3fe4f8 | 458 | error (_("mi_cmd_var_assign: Variable object not found")); |
fb40c209 AC |
459 | |
460 | /* FIXME: define masks for attributes */ | |
461 | if (!(varobj_get_attributes (var) & 0x00000001)) | |
8a3fe4f8 | 462 | error (_("mi_cmd_var_assign: Variable object is not editable")); |
fb40c209 AC |
463 | |
464 | expression = xstrdup (argv[1]); | |
465 | ||
466 | if (!varobj_set_value (var, expression)) | |
8a3fe4f8 | 467 | error (_("mi_cmd_var_assign: Could not assign expression to varible object")); |
fb40c209 AC |
468 | |
469 | ui_out_field_string (uiout, "value", varobj_get_value (var)); | |
470 | return MI_CMD_DONE; | |
471 | } | |
472 | ||
473 | enum mi_cmd_result | |
474 | mi_cmd_var_update (char *command, char **argv, int argc) | |
475 | { | |
476 | struct varobj *var; | |
477 | struct varobj **rootlist; | |
478 | struct varobj **cr; | |
3a387118 | 479 | struct cleanup *cleanup; |
fb40c209 AC |
480 | char *name; |
481 | int nv; | |
1ecb4ee0 | 482 | enum print_values print_values; |
fb40c209 | 483 | |
1ecb4ee0 DJ |
484 | if (argc != 1 && argc != 2) |
485 | error (_("mi_cmd_var_update: Usage: [PRINT_VALUES] NAME.")); | |
486 | ||
487 | if (argc == 1) | |
488 | name = argv[0]; | |
489 | else | |
490 | name = (argv[1]); | |
fb40c209 | 491 | |
1ecb4ee0 DJ |
492 | if (argc == 2) |
493 | print_values = mi_parse_values_option (argv[0]); | |
494 | else | |
495 | print_values = PRINT_NO_VALUES; | |
fb40c209 AC |
496 | |
497 | /* Check if the parameter is a "*" which means that we want | |
498 | to update all variables */ | |
499 | ||
500 | if ((*name == '*') && (*(name + 1) == '\0')) | |
501 | { | |
502 | nv = varobj_list (&rootlist); | |
db9a518b | 503 | cleanup = make_cleanup (xfree, rootlist); |
3a387118 | 504 | if (mi_version (uiout) <= 1) |
db9a518b | 505 | make_cleanup_ui_out_tuple_begin_end (uiout, "changelist"); |
3a387118 | 506 | else |
db9a518b | 507 | make_cleanup_ui_out_list_begin_end (uiout, "changelist"); |
fb40c209 AC |
508 | if (nv <= 0) |
509 | { | |
3a387118 | 510 | do_cleanups (cleanup); |
fb40c209 AC |
511 | return MI_CMD_DONE; |
512 | } | |
513 | cr = rootlist; | |
514 | while (*cr != NULL) | |
515 | { | |
1ecb4ee0 | 516 | varobj_update_one (*cr, print_values); |
fb40c209 AC |
517 | cr++; |
518 | } | |
3a387118 | 519 | do_cleanups (cleanup); |
fb40c209 AC |
520 | } |
521 | else | |
522 | { | |
523 | /* Get varobj handle, if a valid var obj name was specified */ | |
524 | var = varobj_get_handle (name); | |
525 | if (var == NULL) | |
8a3fe4f8 | 526 | error (_("mi_cmd_var_update: Variable object not found")); |
fb40c209 | 527 | |
3a387118 JJ |
528 | if (mi_version (uiout) <= 1) |
529 | cleanup = make_cleanup_ui_out_tuple_begin_end (uiout, "changelist"); | |
530 | else | |
531 | cleanup = make_cleanup_ui_out_list_begin_end (uiout, "changelist"); | |
1ecb4ee0 | 532 | varobj_update_one (var, print_values); |
3a387118 | 533 | do_cleanups (cleanup); |
fb40c209 | 534 | } |
73a93a32 | 535 | return MI_CMD_DONE; |
fb40c209 AC |
536 | } |
537 | ||
73a93a32 JI |
538 | /* Helper for mi_cmd_var_update() Returns 0 if the update for |
539 | the variable fails (usually because the variable is out of | |
540 | scope), and 1 if it succeeds. */ | |
fb40c209 | 541 | |
73a93a32 | 542 | static int |
1ecb4ee0 | 543 | varobj_update_one (struct varobj *var, enum print_values print_values) |
fb40c209 AC |
544 | { |
545 | struct varobj **changelist; | |
546 | struct varobj **cc; | |
3a387118 | 547 | struct cleanup *cleanup = NULL; |
fb40c209 AC |
548 | int nc; |
549 | ||
4309c8f2 | 550 | nc = varobj_update (&var, &changelist); |
fb40c209 | 551 | |
73a93a32 JI |
552 | /* nc == 0 means that nothing has changed. |
553 | nc == -1 means that an error occured in updating the variable. | |
554 | nc == -2 means the variable has changed type. */ | |
555 | ||
556 | if (nc == 0) | |
557 | return 1; | |
558 | else if (nc == -1) | |
fb40c209 | 559 | { |
3a387118 JJ |
560 | if (mi_version (uiout) > 1) |
561 | cleanup = make_cleanup_ui_out_tuple_begin_end (uiout, NULL); | |
73a93a32 JI |
562 | ui_out_field_string (uiout, "name", varobj_get_objname(var)); |
563 | ui_out_field_string (uiout, "in_scope", "false"); | |
3a387118 JJ |
564 | if (mi_version (uiout) > 1) |
565 | do_cleanups (cleanup); | |
73a93a32 JI |
566 | return -1; |
567 | } | |
568 | else if (nc == -2) | |
569 | { | |
3a387118 JJ |
570 | if (mi_version (uiout) > 1) |
571 | cleanup = make_cleanup_ui_out_tuple_begin_end (uiout, NULL); | |
73a93a32 JI |
572 | ui_out_field_string (uiout, "name", varobj_get_objname (var)); |
573 | ui_out_field_string (uiout, "in_scope", "true"); | |
574 | ui_out_field_string (uiout, "new_type", varobj_get_type(var)); | |
575 | ui_out_field_int (uiout, "new_num_children", | |
576 | varobj_get_num_children(var)); | |
3a387118 JJ |
577 | if (mi_version (uiout) > 1) |
578 | do_cleanups (cleanup); | |
73a93a32 JI |
579 | } |
580 | else | |
581 | { | |
582 | ||
583 | cc = changelist; | |
584 | while (*cc != NULL) | |
585 | { | |
3a387118 JJ |
586 | if (mi_version (uiout) > 1) |
587 | cleanup = make_cleanup_ui_out_tuple_begin_end (uiout, NULL); | |
73a93a32 | 588 | ui_out_field_string (uiout, "name", varobj_get_objname (*cc)); |
1ecb4ee0 DJ |
589 | if (mi_print_value_p (varobj_get_gdb_type (*cc), print_values)) |
590 | ui_out_field_string (uiout, "value", varobj_get_value (*cc)); | |
73a93a32 JI |
591 | ui_out_field_string (uiout, "in_scope", "true"); |
592 | ui_out_field_string (uiout, "type_changed", "false"); | |
3a387118 JJ |
593 | if (mi_version (uiout) > 1) |
594 | do_cleanups (cleanup); | |
73a93a32 JI |
595 | cc++; |
596 | } | |
b8c9b27d | 597 | xfree (changelist); |
73a93a32 | 598 | return 1; |
fb40c209 | 599 | } |
73a93a32 | 600 | return 1; |
fb40c209 | 601 | } |