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