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