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