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, | |
131 | "Name=\"%s\", Frame=\"%s\" (0x%s), Expression=\"%s\"\n", | |
132 | name, frame, paddr (frameaddr), expr); | |
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 | ||
188 | if (var == NULL) | |
8a3fe4f8 | 189 | error (_("mi_cmd_var_delete: Variable object not found.")); |
fb40c209 AC |
190 | |
191 | numdel = varobj_delete (var, NULL, children_only_p); | |
192 | ||
193 | ui_out_field_int (uiout, "ndeleted", numdel); | |
194 | ||
195 | do_cleanups (old_cleanups); | |
fb40c209 AC |
196 | } |
197 | ||
de051565 MK |
198 | /* Parse a string argument into a format value. */ |
199 | ||
200 | static enum varobj_display_formats | |
201 | mi_parse_format (const char *arg) | |
202 | { | |
203 | if (arg != NULL) | |
204 | { | |
205 | int len; | |
206 | ||
207 | len = strlen (arg); | |
208 | ||
209 | if (strncmp (arg, "natural", len) == 0) | |
210 | return FORMAT_NATURAL; | |
211 | else if (strncmp (arg, "binary", len) == 0) | |
212 | return FORMAT_BINARY; | |
213 | else if (strncmp (arg, "decimal", len) == 0) | |
214 | return FORMAT_DECIMAL; | |
215 | else if (strncmp (arg, "hexadecimal", len) == 0) | |
216 | return FORMAT_HEXADECIMAL; | |
217 | else if (strncmp (arg, "octal", len) == 0) | |
218 | return FORMAT_OCTAL; | |
219 | } | |
220 | ||
221 | error (_("Must specify the format as: \"natural\", \"binary\", \"decimal\", \"hexadecimal\", or \"octal\"")); | |
222 | } | |
223 | ||
ce8f13f8 | 224 | void |
fb40c209 AC |
225 | mi_cmd_var_set_format (char *command, char **argv, int argc) |
226 | { | |
227 | enum varobj_display_formats format; | |
fb40c209 | 228 | struct varobj *var; |
fb40c209 AC |
229 | |
230 | if (argc != 2) | |
8a3fe4f8 | 231 | error (_("mi_cmd_var_set_format: Usage: NAME FORMAT.")); |
fb40c209 AC |
232 | |
233 | /* Get varobj handle, if a valid var obj name was specified */ | |
234 | var = varobj_get_handle (argv[0]); | |
235 | ||
236 | if (var == NULL) | |
8a3fe4f8 | 237 | error (_("mi_cmd_var_set_format: Variable object not found")); |
fb40c209 | 238 | |
de051565 MK |
239 | format = mi_parse_format (argv[1]); |
240 | ||
fb40c209 AC |
241 | /* Set the format of VAR to given format */ |
242 | varobj_set_display_format (var, format); | |
243 | ||
244 | /* Report the new current format */ | |
245 | ui_out_field_string (uiout, "format", varobj_format_string[(int) format]); | |
00ee6348 NR |
246 | |
247 | /* Report the value in the new format */ | |
248 | ui_out_field_string (uiout, "value", varobj_get_value (var)); | |
fb40c209 AC |
249 | } |
250 | ||
ce8f13f8 | 251 | void |
25d5ea92 VP |
252 | mi_cmd_var_set_frozen (char *command, char **argv, int argc) |
253 | { | |
254 | struct varobj *var; | |
255 | int frozen; | |
256 | ||
257 | if (argc != 2) | |
258 | error (_("-var-set-format: Usage: NAME FROZEN_FLAG.")); | |
259 | ||
260 | var = varobj_get_handle (argv[0]); | |
261 | if (var == NULL) | |
262 | error (_("Variable object not found")); | |
263 | ||
264 | if (strcmp (argv[1], "0") == 0) | |
265 | frozen = 0; | |
266 | else if (strcmp (argv[1], "1") == 0) | |
267 | frozen = 1; | |
268 | else | |
269 | error (_("Invalid flag value")); | |
270 | ||
271 | varobj_set_frozen (var, frozen); | |
272 | ||
273 | /* We don't automatically return the new value, or what varobjs got new | |
274 | values during unfreezing. If this information is required, client | |
275 | should call -var-update explicitly. */ | |
25d5ea92 VP |
276 | } |
277 | ||
278 | ||
ce8f13f8 | 279 | void |
fb40c209 AC |
280 | mi_cmd_var_show_format (char *command, char **argv, int argc) |
281 | { | |
282 | enum varobj_display_formats format; | |
283 | struct varobj *var; | |
284 | ||
285 | if (argc != 1) | |
8a3fe4f8 | 286 | error (_("mi_cmd_var_show_format: Usage: NAME.")); |
fb40c209 AC |
287 | |
288 | /* Get varobj handle, if a valid var obj name was specified */ | |
289 | var = varobj_get_handle (argv[0]); | |
290 | if (var == NULL) | |
8a3fe4f8 | 291 | error (_("mi_cmd_var_show_format: Variable object not found")); |
fb40c209 AC |
292 | |
293 | format = varobj_get_display_format (var); | |
294 | ||
295 | /* Report the current format */ | |
296 | ui_out_field_string (uiout, "format", varobj_format_string[(int) format]); | |
fb40c209 AC |
297 | } |
298 | ||
ce8f13f8 | 299 | void |
fb40c209 AC |
300 | mi_cmd_var_info_num_children (char *command, char **argv, int argc) |
301 | { | |
302 | struct varobj *var; | |
303 | ||
304 | if (argc != 1) | |
8a3fe4f8 | 305 | error (_("mi_cmd_var_info_num_children: Usage: NAME.")); |
fb40c209 AC |
306 | |
307 | /* Get varobj handle, if a valid var obj name was specified */ | |
308 | var = varobj_get_handle (argv[0]); | |
309 | if (var == NULL) | |
8a3fe4f8 | 310 | error (_("mi_cmd_var_info_num_children: Variable object not found")); |
fb40c209 AC |
311 | |
312 | ui_out_field_int (uiout, "numchild", varobj_get_num_children (var)); | |
fb40c209 AC |
313 | } |
314 | ||
1ecb4ee0 DJ |
315 | /* Parse a string argument into a print_values value. */ |
316 | ||
317 | static enum print_values | |
318 | mi_parse_values_option (const char *arg) | |
319 | { | |
320 | if (strcmp (arg, "0") == 0 | |
321 | || strcmp (arg, mi_no_values) == 0) | |
322 | return PRINT_NO_VALUES; | |
323 | else if (strcmp (arg, "1") == 0 | |
324 | || strcmp (arg, mi_all_values) == 0) | |
325 | return PRINT_ALL_VALUES; | |
326 | else if (strcmp (arg, "2") == 0 | |
327 | || strcmp (arg, mi_simple_values) == 0) | |
328 | return PRINT_SIMPLE_VALUES; | |
329 | else | |
330 | error (_("Unknown value for PRINT_VALUES\n\ | |
331 | Must be: 0 or \"%s\", 1 or \"%s\", 2 or \"%s\""), | |
332 | mi_no_values, mi_simple_values, mi_all_values); | |
333 | } | |
334 | ||
335 | /* Return 1 if given the argument PRINT_VALUES we should display | |
336 | a value of type TYPE. */ | |
337 | ||
338 | static int | |
339 | mi_print_value_p (struct type *type, enum print_values print_values) | |
340 | { | |
1ecb4ee0 DJ |
341 | |
342 | if (print_values == PRINT_NO_VALUES) | |
343 | return 0; | |
344 | ||
345 | if (print_values == PRINT_ALL_VALUES) | |
346 | return 1; | |
347 | ||
9265acad NR |
348 | if (type == NULL) |
349 | return 1; | |
350 | else | |
351 | { | |
352 | type = check_typedef (type); | |
1ecb4ee0 | 353 | |
9265acad NR |
354 | /* For PRINT_SIMPLE_VALUES, only print the value if it has a type |
355 | and that type is not a compound type. */ | |
356 | return (TYPE_CODE (type) != TYPE_CODE_ARRAY | |
357 | && TYPE_CODE (type) != TYPE_CODE_STRUCT | |
358 | && TYPE_CODE (type) != TYPE_CODE_UNION); | |
359 | } | |
1ecb4ee0 DJ |
360 | } |
361 | ||
ce8f13f8 | 362 | void |
fb40c209 AC |
363 | mi_cmd_var_list_children (char *command, char **argv, int argc) |
364 | { | |
d56d46f5 VP |
365 | struct varobj *var; |
366 | VEC(varobj_p) *children; | |
367 | struct varobj *child; | |
6ad4a2cf | 368 | struct cleanup *cleanup_children; |
fb40c209 | 369 | int numchild; |
c9e1f0fc | 370 | enum print_values print_values; |
d56d46f5 | 371 | int ix; |
fb40c209 | 372 | |
c9e1f0fc | 373 | if (argc != 1 && argc != 2) |
8a3fe4f8 | 374 | error (_("mi_cmd_var_list_children: Usage: [PRINT_VALUES] NAME")); |
fb40c209 AC |
375 | |
376 | /* Get varobj handle, if a valid var obj name was specified */ | |
1ecb4ee0 DJ |
377 | if (argc == 1) |
378 | var = varobj_get_handle (argv[0]); | |
379 | else | |
380 | var = varobj_get_handle (argv[1]); | |
fb40c209 | 381 | if (var == NULL) |
8a3fe4f8 | 382 | error (_("Variable object not found")); |
fb40c209 | 383 | |
d56d46f5 VP |
384 | children = varobj_list_children (var); |
385 | ui_out_field_int (uiout, "numchild", VEC_length (varobj_p, children)); | |
c9e1f0fc | 386 | if (argc == 2) |
1ecb4ee0 DJ |
387 | print_values = mi_parse_values_option (argv[0]); |
388 | else | |
389 | print_values = PRINT_NO_VALUES; | |
fb40c209 | 390 | |
d56d46f5 | 391 | if (VEC_length (varobj_p, children) == 0) |
ce8f13f8 | 392 | return; |
fb40c209 | 393 | |
e7494ffb AC |
394 | if (mi_version (uiout) == 1) |
395 | cleanup_children = make_cleanup_ui_out_tuple_begin_end (uiout, "children"); | |
396 | else | |
397 | cleanup_children = make_cleanup_ui_out_list_begin_end (uiout, "children"); | |
d56d46f5 | 398 | for (ix = 0; VEC_iterate (varobj_p, children, ix, child); ++ix) |
fb40c209 | 399 | { |
6ad4a2cf JJ |
400 | struct cleanup *cleanup_child; |
401 | cleanup_child = make_cleanup_ui_out_tuple_begin_end (uiout, "child"); | |
d56d46f5 | 402 | print_varobj (child, print_values, 1 /* print expression */); |
a217f3f5 | 403 | do_cleanups (cleanup_child); |
fb40c209 | 404 | } |
6ad4a2cf | 405 | do_cleanups (cleanup_children); |
fb40c209 AC |
406 | } |
407 | ||
ce8f13f8 | 408 | void |
fb40c209 AC |
409 | mi_cmd_var_info_type (char *command, char **argv, int argc) |
410 | { | |
411 | struct varobj *var; | |
412 | ||
413 | if (argc != 1) | |
8a3fe4f8 | 414 | error (_("mi_cmd_var_info_type: Usage: NAME.")); |
fb40c209 AC |
415 | |
416 | /* Get varobj handle, if a valid var obj name was specified */ | |
417 | var = varobj_get_handle (argv[0]); | |
418 | if (var == NULL) | |
8a3fe4f8 | 419 | error (_("mi_cmd_var_info_type: Variable object not found")); |
fb40c209 AC |
420 | |
421 | ui_out_field_string (uiout, "type", varobj_get_type (var)); | |
fb40c209 AC |
422 | } |
423 | ||
ce8f13f8 | 424 | void |
02142340 VP |
425 | mi_cmd_var_info_path_expression (char *command, char **argv, int argc) |
426 | { | |
427 | struct varobj *var; | |
428 | char *path_expr; | |
429 | ||
430 | if (argc != 1) | |
431 | error (_("Usage: NAME.")); | |
432 | ||
433 | /* Get varobj handle, if a valid var obj name was specified. */ | |
434 | var = varobj_get_handle (argv[0]); | |
435 | if (var == NULL) | |
436 | error (_("Variable object not found")); | |
437 | ||
438 | path_expr = varobj_get_path_expr (var); | |
439 | ||
440 | ui_out_field_string (uiout, "path_expr", path_expr); | |
02142340 VP |
441 | } |
442 | ||
ce8f13f8 | 443 | void |
fb40c209 AC |
444 | mi_cmd_var_info_expression (char *command, char **argv, int argc) |
445 | { | |
446 | enum varobj_languages lang; | |
447 | struct varobj *var; | |
448 | ||
449 | if (argc != 1) | |
8a3fe4f8 | 450 | error (_("mi_cmd_var_info_expression: Usage: NAME.")); |
fb40c209 AC |
451 | |
452 | /* Get varobj handle, if a valid var obj name was specified */ | |
453 | var = varobj_get_handle (argv[0]); | |
454 | if (var == NULL) | |
8a3fe4f8 | 455 | error (_("mi_cmd_var_info_expression: Variable object not found")); |
fb40c209 AC |
456 | |
457 | lang = varobj_get_language (var); | |
458 | ||
459 | ui_out_field_string (uiout, "lang", varobj_language_string[(int) lang]); | |
460 | ui_out_field_string (uiout, "exp", varobj_get_expression (var)); | |
fb40c209 AC |
461 | } |
462 | ||
ce8f13f8 | 463 | void |
fb40c209 AC |
464 | mi_cmd_var_show_attributes (char *command, char **argv, int argc) |
465 | { | |
466 | int attr; | |
467 | char *attstr; | |
468 | struct varobj *var; | |
469 | ||
470 | if (argc != 1) | |
8a3fe4f8 | 471 | error (_("mi_cmd_var_show_attributes: Usage: NAME.")); |
fb40c209 AC |
472 | |
473 | /* Get varobj handle, if a valid var obj name was specified */ | |
474 | var = varobj_get_handle (argv[0]); | |
475 | if (var == NULL) | |
8a3fe4f8 | 476 | error (_("mi_cmd_var_show_attributes: Variable object not found")); |
fb40c209 AC |
477 | |
478 | attr = varobj_get_attributes (var); | |
479 | /* FIXME: define masks for attributes */ | |
480 | if (attr & 0x00000001) | |
481 | attstr = "editable"; | |
482 | else | |
483 | attstr = "noneditable"; | |
484 | ||
485 | ui_out_field_string (uiout, "attr", attstr); | |
fb40c209 AC |
486 | } |
487 | ||
ce8f13f8 | 488 | void |
fb40c209 AC |
489 | mi_cmd_var_evaluate_expression (char *command, char **argv, int argc) |
490 | { | |
491 | struct varobj *var; | |
492 | ||
de051565 MK |
493 | enum varobj_display_formats format; |
494 | int formatFound; | |
495 | int optind; | |
496 | char *optarg; | |
497 | ||
498 | enum opt | |
499 | { | |
500 | OP_FORMAT | |
501 | }; | |
502 | static struct mi_opt opts[] = | |
503 | { | |
504 | {"f", OP_FORMAT, 1}, | |
505 | { 0, 0, 0 } | |
506 | }; | |
507 | ||
508 | /* Parse arguments */ | |
509 | format = FORMAT_NATURAL; | |
510 | formatFound = 0; | |
511 | optind = 0; | |
512 | while (1) | |
513 | { | |
514 | int opt = mi_getopt ("-var-evaluate-expression", argc, argv, opts, &optind, &optarg); | |
515 | if (opt < 0) | |
516 | break; | |
517 | switch ((enum opt) opt) | |
518 | { | |
519 | case OP_FORMAT: | |
520 | if (formatFound) | |
521 | error (_("Cannot specify format more than once")); | |
522 | ||
523 | format = mi_parse_format (optarg); | |
524 | formatFound = 1; | |
525 | break; | |
526 | } | |
527 | } | |
fb40c209 | 528 | |
de051565 MK |
529 | if (optind >= argc) |
530 | error (_("Usage: [-f FORMAT] NAME")); | |
531 | ||
532 | if (optind < argc - 1) | |
533 | error (_("Garbage at end of command")); | |
534 | ||
535 | /* Get varobj handle, if a valid var obj name was specified */ | |
536 | var = varobj_get_handle (argv[optind]); | |
fb40c209 | 537 | if (var == NULL) |
de051565 MK |
538 | error (_("Variable object not found")); |
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]); | |
557 | if (var == NULL) | |
8a3fe4f8 | 558 | error (_("mi_cmd_var_assign: Variable object not found")); |
fb40c209 | 559 | |
d2562500 | 560 | if (!varobj_editable_p (var)) |
8a3fe4f8 | 561 | error (_("mi_cmd_var_assign: Variable object is not editable")); |
fb40c209 AC |
562 | |
563 | expression = xstrdup (argv[1]); | |
564 | ||
565 | if (!varobj_set_value (var, expression)) | |
98a29c7e | 566 | error (_("mi_cmd_var_assign: Could not assign expression to variable object")); |
fb40c209 AC |
567 | |
568 | ui_out_field_string (uiout, "value", varobj_get_value (var)); | |
fb40c209 AC |
569 | } |
570 | ||
ce8f13f8 | 571 | void |
fb40c209 AC |
572 | mi_cmd_var_update (char *command, char **argv, int argc) |
573 | { | |
574 | struct varobj *var; | |
575 | struct varobj **rootlist; | |
576 | struct varobj **cr; | |
3a387118 | 577 | struct cleanup *cleanup; |
fb40c209 AC |
578 | char *name; |
579 | int nv; | |
1ecb4ee0 | 580 | enum print_values print_values; |
fb40c209 | 581 | |
1ecb4ee0 DJ |
582 | if (argc != 1 && argc != 2) |
583 | error (_("mi_cmd_var_update: Usage: [PRINT_VALUES] NAME.")); | |
584 | ||
585 | if (argc == 1) | |
586 | name = argv[0]; | |
587 | else | |
588 | name = (argv[1]); | |
fb40c209 | 589 | |
1ecb4ee0 DJ |
590 | if (argc == 2) |
591 | print_values = mi_parse_values_option (argv[0]); | |
592 | else | |
593 | print_values = PRINT_NO_VALUES; | |
fb40c209 AC |
594 | |
595 | /* Check if the parameter is a "*" which means that we want | |
596 | to update all variables */ | |
597 | ||
5a413362 | 598 | if ((*name == '*' || *name == '@') && (*(name + 1) == '\0')) |
fb40c209 AC |
599 | { |
600 | nv = varobj_list (&rootlist); | |
db9a518b | 601 | cleanup = make_cleanup (xfree, rootlist); |
3a387118 | 602 | if (mi_version (uiout) <= 1) |
db9a518b | 603 | make_cleanup_ui_out_tuple_begin_end (uiout, "changelist"); |
3a387118 | 604 | else |
db9a518b | 605 | make_cleanup_ui_out_list_begin_end (uiout, "changelist"); |
fb40c209 AC |
606 | if (nv <= 0) |
607 | { | |
3a387118 | 608 | do_cleanups (cleanup); |
ce8f13f8 | 609 | return; |
fb40c209 AC |
610 | } |
611 | cr = rootlist; | |
612 | while (*cr != NULL) | |
613 | { | |
dbba8251 VP |
614 | int thread_id = varobj_get_thread_id (*cr); |
615 | int thread_stopped = 0; | |
616 | if (thread_id == -1 && is_stopped (inferior_ptid)) | |
617 | thread_stopped = 1; | |
618 | else | |
619 | { | |
620 | struct thread_info *tp = find_thread_id (thread_id); | |
621 | if (tp) | |
622 | thread_stopped = is_stopped (tp->ptid); | |
623 | else | |
624 | thread_stopped = 1; | |
625 | } | |
626 | if (thread_stopped) | |
627 | if (*name == '*' || varobj_floating_p (*cr)) | |
628 | varobj_update_one (*cr, print_values, 0 /* implicit */); | |
fb40c209 AC |
629 | cr++; |
630 | } | |
3a387118 | 631 | do_cleanups (cleanup); |
fb40c209 AC |
632 | } |
633 | else | |
634 | { | |
635 | /* Get varobj handle, if a valid var obj name was specified */ | |
636 | var = varobj_get_handle (name); | |
637 | if (var == NULL) | |
8a3fe4f8 | 638 | error (_("mi_cmd_var_update: Variable object not found")); |
fb40c209 | 639 | |
3a387118 JJ |
640 | if (mi_version (uiout) <= 1) |
641 | cleanup = make_cleanup_ui_out_tuple_begin_end (uiout, "changelist"); | |
642 | else | |
643 | cleanup = make_cleanup_ui_out_list_begin_end (uiout, "changelist"); | |
25d5ea92 | 644 | varobj_update_one (var, print_values, 1 /* explicit */); |
3a387118 | 645 | do_cleanups (cleanup); |
fb40c209 | 646 | } |
fb40c209 AC |
647 | } |
648 | ||
8756216b | 649 | /* Helper for mi_cmd_var_update(). */ |
fb40c209 | 650 | |
8756216b | 651 | static void |
25d5ea92 VP |
652 | varobj_update_one (struct varobj *var, enum print_values print_values, |
653 | int explicit) | |
fb40c209 | 654 | { |
fb40c209 | 655 | struct varobj **cc; |
3a387118 | 656 | struct cleanup *cleanup = NULL; |
f7f9ae2c VP |
657 | VEC (varobj_update_result) *changes; |
658 | varobj_update_result *r; | |
659 | int i; | |
660 | ||
661 | changes = varobj_update (&var, explicit); | |
73a93a32 | 662 | |
f7f9ae2c | 663 | for (i = 0; VEC_iterate (varobj_update_result, changes, i, r); ++i) |
fb40c209 | 664 | { |
3a387118 JJ |
665 | if (mi_version (uiout) > 1) |
666 | cleanup = make_cleanup_ui_out_tuple_begin_end (uiout, NULL); | |
f7f9ae2c | 667 | ui_out_field_string (uiout, "name", varobj_get_objname (r->varobj)); |
8756216b | 668 | |
f7f9ae2c VP |
669 | switch (r->status) |
670 | { | |
671 | case VAROBJ_IN_SCOPE: | |
672 | if (mi_print_value_p (varobj_get_gdb_type (r->varobj), print_values)) | |
673 | ui_out_field_string (uiout, "value", varobj_get_value (r->varobj)); | |
674 | ui_out_field_string (uiout, "in_scope", "true"); | |
675 | break; | |
676 | case VAROBJ_NOT_IN_SCOPE: | |
8756216b DP |
677 | ui_out_field_string (uiout, "in_scope", "false"); |
678 | break; | |
f7f9ae2c | 679 | case VAROBJ_INVALID: |
8756216b DP |
680 | ui_out_field_string (uiout, "in_scope", "invalid"); |
681 | break; | |
f7f9ae2c VP |
682 | } |
683 | ||
684 | if (r->status != VAROBJ_INVALID) | |
73a93a32 | 685 | { |
f7f9ae2c VP |
686 | if (r->type_changed) |
687 | ui_out_field_string (uiout, "type_changed", "true"); | |
688 | else | |
689 | ui_out_field_string (uiout, "type_changed", "false"); | |
73a93a32 | 690 | } |
f7f9ae2c VP |
691 | |
692 | if (r->type_changed) | |
693 | { | |
694 | ui_out_field_string (uiout, "new_type", varobj_get_type (r->varobj)); | |
695 | ui_out_field_int (uiout, "new_num_children", | |
696 | varobj_get_num_children (r->varobj)); | |
697 | } | |
698 | ||
699 | if (mi_version (uiout) > 1) | |
700 | do_cleanups (cleanup); | |
fb40c209 | 701 | } |
f7f9ae2c | 702 | VEC_free (varobj_update_result, changes); |
fb40c209 | 703 | } |