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