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