]>
Commit | Line | Data |
---|---|---|
d318976c | 1 | /* Handle set and show GDB commands. |
8926118c | 2 | |
42a4f53d | 3 | Copyright (C) 2000-2019 Free Software Foundation, Inc. |
d318976c FN |
4 | |
5 | This program is free software; you can redistribute it and/or modify | |
6 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 7 | the Free Software Foundation; either version 3 of the License, or |
d318976c FN |
8 | (at your option) any later version. |
9 | ||
10 | This program is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | GNU General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU General Public License | |
a9762ec7 | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
d318976c FN |
17 | |
18 | #include "defs.h" | |
dbda9972 | 19 | #include "readline/tilde.h" |
d318976c FN |
20 | #include "value.h" |
21 | #include <ctype.h> | |
f870a310 | 22 | #include "arch-utils.h" |
76727919 | 23 | #include "observable.h" |
d318976c | 24 | |
d318976c | 25 | #include "ui-out.h" |
d318976c FN |
26 | |
27 | #include "cli/cli-decode.h" | |
28 | #include "cli/cli-cmds.h" | |
29 | #include "cli/cli-setshow.h" | |
f81d1120 | 30 | #include "cli/cli-utils.h" |
d318976c | 31 | |
5b9afe8a YQ |
32 | /* Return true if the change of command parameter should be notified. */ |
33 | ||
34 | static int | |
35 | notify_command_param_changed_p (int param_changed, struct cmd_list_element *c) | |
36 | { | |
37 | if (param_changed == 0) | |
38 | return 0; | |
39 | ||
fe978cb0 PA |
40 | if (c->theclass == class_maintenance || c->theclass == class_deprecated |
41 | || c->theclass == class_obscure) | |
5b9afe8a YQ |
42 | return 0; |
43 | ||
44 | return 1; | |
45 | } | |
46 | ||
d318976c | 47 | \f |
7f19b9a2 | 48 | static enum auto_boolean |
d318976c FN |
49 | parse_auto_binary_operation (const char *arg) |
50 | { | |
51 | if (arg != NULL && *arg != '\0') | |
52 | { | |
53 | int length = strlen (arg); | |
cdb27c12 | 54 | |
d318976c FN |
55 | while (isspace (arg[length - 1]) && length > 0) |
56 | length--; | |
57 | if (strncmp (arg, "on", length) == 0 | |
58 | || strncmp (arg, "1", length) == 0 | |
59 | || strncmp (arg, "yes", length) == 0 | |
60 | || strncmp (arg, "enable", length) == 0) | |
7f19b9a2 | 61 | return AUTO_BOOLEAN_TRUE; |
d318976c FN |
62 | else if (strncmp (arg, "off", length) == 0 |
63 | || strncmp (arg, "0", length) == 0 | |
64 | || strncmp (arg, "no", length) == 0 | |
65 | || strncmp (arg, "disable", length) == 0) | |
7f19b9a2 | 66 | return AUTO_BOOLEAN_FALSE; |
d318976c FN |
67 | else if (strncmp (arg, "auto", length) == 0 |
68 | || (strncmp (arg, "-1", length) == 0 && length > 1)) | |
7f19b9a2 | 69 | return AUTO_BOOLEAN_AUTO; |
d318976c | 70 | } |
8a3fe4f8 | 71 | error (_("\"on\", \"off\" or \"auto\" expected.")); |
ebcd3b23 | 72 | return AUTO_BOOLEAN_AUTO; /* Pacify GCC. */ |
d318976c FN |
73 | } |
74 | ||
bd712aed DE |
75 | /* See cli-setshow.h. */ |
76 | ||
77 | int | |
5bc98e52 | 78 | parse_cli_boolean_value (const char *arg) |
d318976c FN |
79 | { |
80 | int length; | |
81 | ||
82 | if (!arg || !*arg) | |
83 | return 1; | |
84 | ||
85 | length = strlen (arg); | |
86 | ||
87 | while (arg[length - 1] == ' ' || arg[length - 1] == '\t') | |
88 | length--; | |
89 | ||
90 | if (strncmp (arg, "on", length) == 0 | |
91 | || strncmp (arg, "1", length) == 0 | |
92 | || strncmp (arg, "yes", length) == 0 | |
93 | || strncmp (arg, "enable", length) == 0) | |
94 | return 1; | |
95 | else if (strncmp (arg, "off", length) == 0 | |
96 | || strncmp (arg, "0", length) == 0 | |
97 | || strncmp (arg, "no", length) == 0 | |
98 | || strncmp (arg, "disable", length) == 0) | |
99 | return 0; | |
100 | else | |
bd712aed | 101 | return -1; |
d318976c FN |
102 | } |
103 | \f | |
08546159 AC |
104 | void |
105 | deprecated_show_value_hack (struct ui_file *ignore_file, | |
106 | int ignore_from_tty, | |
107 | struct cmd_list_element *c, | |
108 | const char *value) | |
109 | { | |
4d28ad1e AC |
110 | /* If there's no command or value, don't try to print it out. */ |
111 | if (c == NULL || value == NULL) | |
112 | return; | |
08546159 AC |
113 | /* Print doc minus "show" at start. */ |
114 | print_doc_line (gdb_stdout, c->doc + 5); | |
115 | switch (c->var_type) | |
116 | { | |
117 | case var_string: | |
118 | case var_string_noescape: | |
b4b4ac0b | 119 | case var_optional_filename: |
08546159 AC |
120 | case var_filename: |
121 | case var_enum: | |
122 | printf_filtered ((" is \"%s\".\n"), value); | |
123 | break; | |
124 | default: | |
125 | printf_filtered ((" is %s.\n"), value); | |
126 | break; | |
127 | } | |
128 | } | |
129 | ||
f81d1120 PA |
130 | /* Returns true if ARG is "unlimited". */ |
131 | ||
132 | static int | |
133 | is_unlimited_literal (const char *arg) | |
134 | { | |
f1735a53 | 135 | arg = skip_spaces (arg); |
f81d1120 | 136 | |
93bcb043 PA |
137 | const char *p = skip_to_space (arg); |
138 | ||
139 | size_t len = p - arg; | |
140 | ||
141 | if (len > 0 && strncmp ("unlimited", arg, len) == 0) | |
142 | return true; | |
143 | ||
144 | return false; | |
f81d1120 PA |
145 | } |
146 | ||
147 | ||
5b9afe8a | 148 | /* Do a "set" command. ARG is NULL if no argument, or the |
ebcd3b23 MS |
149 | text of the argument, and FROM_TTY is nonzero if this command is |
150 | being entered directly by the user (i.e. these are just like any | |
151 | other command). C is the command list element for the command. */ | |
d318976c FN |
152 | |
153 | void | |
06900326 | 154 | do_set_command (const char *arg, int from_tty, struct cmd_list_element *c) |
d318976c | 155 | { |
5b9afe8a YQ |
156 | /* A flag to indicate the option is changed or not. */ |
157 | int option_changed = 0; | |
158 | ||
159 | gdb_assert (c->type == set_cmd); | |
79a45e25 | 160 | |
5b9afe8a | 161 | switch (c->var_type) |
d318976c | 162 | { |
5b9afe8a YQ |
163 | case var_string: |
164 | { | |
fe978cb0 | 165 | char *newobj; |
d7561cbb | 166 | const char *p; |
5b9afe8a YQ |
167 | char *q; |
168 | int ch; | |
169 | ||
170 | if (arg == NULL) | |
171 | arg = ""; | |
fe978cb0 | 172 | newobj = (char *) xmalloc (strlen (arg) + 2); |
5b9afe8a | 173 | p = arg; |
fe978cb0 | 174 | q = newobj; |
5b9afe8a | 175 | while ((ch = *p++) != '\000') |
d318976c | 176 | { |
5b9afe8a | 177 | if (ch == '\\') |
d318976c | 178 | { |
5b9afe8a YQ |
179 | /* \ at end of argument is used after spaces |
180 | so they won't be lost. */ | |
181 | /* This is obsolete now that we no longer strip | |
182 | trailing whitespace and actually, the backslash | |
183 | didn't get here in my test, readline or | |
184 | something did something funky with a backslash | |
185 | right before a newline. */ | |
186 | if (*p == 0) | |
187 | break; | |
188 | ch = parse_escape (get_current_arch (), &p); | |
189 | if (ch == 0) | |
190 | break; /* C loses */ | |
191 | else if (ch > 0) | |
d318976c FN |
192 | *q++ = ch; |
193 | } | |
5b9afe8a YQ |
194 | else |
195 | *q++ = ch; | |
196 | } | |
d318976c | 197 | #if 0 |
5b9afe8a YQ |
198 | if (*(p - 1) != '\\') |
199 | *q++ = ' '; | |
d318976c | 200 | #endif |
5b9afe8a | 201 | *q++ = '\0'; |
fe978cb0 | 202 | newobj = (char *) xrealloc (newobj, q - newobj); |
5b9afe8a YQ |
203 | |
204 | if (*(char **) c->var == NULL | |
fe978cb0 | 205 | || strcmp (*(char **) c->var, newobj) != 0) |
5b9afe8a | 206 | { |
c24343e2 | 207 | xfree (*(char **) c->var); |
fe978cb0 | 208 | *(char **) c->var = newobj; |
5b9afe8a YQ |
209 | |
210 | option_changed = 1; | |
d318976c | 211 | } |
5b9afe8a | 212 | else |
fe978cb0 | 213 | xfree (newobj); |
5b9afe8a YQ |
214 | } |
215 | break; | |
216 | case var_string_noescape: | |
217 | if (arg == NULL) | |
218 | arg = ""; | |
219 | ||
220 | if (*(char **) c->var == NULL || strcmp (*(char **) c->var, arg) != 0) | |
221 | { | |
c24343e2 | 222 | xfree (*(char **) c->var); |
1b36a34b | 223 | *(char **) c->var = xstrdup (arg); |
cdb27c12 | 224 | |
5b9afe8a YQ |
225 | option_changed = 1; |
226 | } | |
227 | break; | |
228 | case var_filename: | |
229 | if (arg == NULL) | |
230 | error_no_arg (_("filename to set it to.")); | |
231 | /* FALLTHROUGH */ | |
232 | case var_optional_filename: | |
233 | { | |
234 | char *val = NULL; | |
6ace3df1 | 235 | |
5b9afe8a YQ |
236 | if (arg != NULL) |
237 | { | |
238 | /* Clear trailing whitespace of filename. */ | |
06900326 TT |
239 | const char *ptr = arg + strlen (arg) - 1; |
240 | char *copy; | |
6ace3df1 | 241 | |
5b9afe8a YQ |
242 | while (ptr >= arg && (*ptr == ' ' || *ptr == '\t')) |
243 | ptr--; | |
06900326 | 244 | copy = xstrndup (arg, ptr + 1 - arg); |
5b9afe8a | 245 | |
06900326 TT |
246 | val = tilde_expand (copy); |
247 | xfree (copy); | |
5b9afe8a YQ |
248 | } |
249 | else | |
250 | val = xstrdup (""); | |
251 | ||
252 | if (*(char **) c->var == NULL | |
253 | || strcmp (*(char **) c->var, val) != 0) | |
d318976c | 254 | { |
5b9afe8a YQ |
255 | xfree (*(char **) c->var); |
256 | *(char **) c->var = val; | |
257 | ||
258 | option_changed = 1; | |
d318976c | 259 | } |
5b9afe8a YQ |
260 | else |
261 | xfree (val); | |
262 | } | |
263 | break; | |
264 | case var_boolean: | |
265 | { | |
bd712aed | 266 | int val = parse_cli_boolean_value (arg); |
5b9afe8a | 267 | |
bd712aed DE |
268 | if (val < 0) |
269 | error (_("\"on\" or \"off\" expected.")); | |
5b9afe8a YQ |
270 | if (val != *(int *) c->var) |
271 | { | |
272 | *(int *) c->var = val; | |
273 | ||
274 | option_changed = 1; | |
275 | } | |
276 | } | |
277 | break; | |
278 | case var_auto_boolean: | |
279 | { | |
280 | enum auto_boolean val = parse_auto_binary_operation (arg); | |
281 | ||
282 | if (*(enum auto_boolean *) c->var != val) | |
283 | { | |
284 | *(enum auto_boolean *) c->var = val; | |
285 | ||
286 | option_changed = 1; | |
287 | } | |
288 | } | |
289 | break; | |
290 | case var_uinteger: | |
291 | case var_zuinteger: | |
5b9afe8a | 292 | { |
ef0026f0 PA |
293 | LONGEST val; |
294 | ||
295 | if (arg == NULL) | |
f81d1120 PA |
296 | { |
297 | if (c->var_type == var_uinteger) | |
298 | error_no_arg (_("integer to set it to, or \"unlimited\".")); | |
299 | else | |
300 | error_no_arg (_("integer to set it to.")); | |
301 | } | |
302 | ||
303 | if (c->var_type == var_uinteger && is_unlimited_literal (arg)) | |
304 | val = 0; | |
305 | else | |
306 | val = parse_and_eval_long (arg); | |
5b9afe8a YQ |
307 | |
308 | if (c->var_type == var_uinteger && val == 0) | |
309 | val = UINT_MAX; | |
82b821e9 PA |
310 | else if (val < 0 |
311 | /* For var_uinteger, don't let the user set the value | |
312 | to UINT_MAX directly, as that exposes an | |
313 | implementation detail to the user interface. */ | |
314 | || (c->var_type == var_uinteger && val >= UINT_MAX) | |
315 | || (c->var_type == var_zuinteger && val > UINT_MAX)) | |
ef0026f0 | 316 | error (_("integer %s out of range"), plongest (val)); |
5b9afe8a YQ |
317 | |
318 | if (*(unsigned int *) c->var != val) | |
319 | { | |
320 | *(unsigned int *) c->var = val; | |
321 | ||
322 | option_changed = 1; | |
323 | } | |
324 | } | |
325 | break; | |
326 | case var_integer: | |
327 | case var_zinteger: | |
328 | { | |
ef0026f0 | 329 | LONGEST val; |
5b9afe8a YQ |
330 | |
331 | if (arg == NULL) | |
f81d1120 PA |
332 | { |
333 | if (c->var_type == var_integer) | |
334 | error_no_arg (_("integer to set it to, or \"unlimited\".")); | |
335 | else | |
336 | error_no_arg (_("integer to set it to.")); | |
337 | } | |
338 | ||
339 | if (c->var_type == var_integer && is_unlimited_literal (arg)) | |
340 | val = 0; | |
341 | else | |
342 | val = parse_and_eval_long (arg); | |
ef0026f0 | 343 | |
5b9afe8a YQ |
344 | if (val == 0 && c->var_type == var_integer) |
345 | val = INT_MAX; | |
82b821e9 PA |
346 | else if (val < INT_MIN |
347 | /* For var_integer, don't let the user set the value | |
348 | to INT_MAX directly, as that exposes an | |
349 | implementation detail to the user interface. */ | |
350 | || (c->var_type == var_integer && val >= INT_MAX) | |
351 | || (c->var_type == var_zinteger && val > INT_MAX)) | |
ef0026f0 | 352 | error (_("integer %s out of range"), plongest (val)); |
5b9afe8a YQ |
353 | |
354 | if (*(int *) c->var != val) | |
d318976c | 355 | { |
5b9afe8a YQ |
356 | *(int *) c->var = val; |
357 | ||
358 | option_changed = 1; | |
359 | } | |
360 | break; | |
361 | } | |
362 | case var_enum: | |
363 | { | |
364 | int i; | |
365 | int len; | |
366 | int nmatches; | |
367 | const char *match = NULL; | |
1650ca11 | 368 | const char *p; |
5b9afe8a YQ |
369 | |
370 | /* If no argument was supplied, print an informative error | |
371 | message. */ | |
372 | if (arg == NULL) | |
373 | { | |
b57af503 | 374 | std::string msg; |
5b9afe8a YQ |
375 | |
376 | for (i = 0; c->enums[i]; i++) | |
d318976c | 377 | { |
5b9afe8a | 378 | if (i != 0) |
b57af503 TT |
379 | msg += ", "; |
380 | msg += c->enums[i]; | |
d318976c | 381 | } |
5b9afe8a | 382 | error (_("Requires an argument. Valid arguments are %s."), |
b57af503 | 383 | msg.c_str ()); |
5b9afe8a | 384 | } |
d318976c | 385 | |
5b9afe8a | 386 | p = strchr (arg, ' '); |
d318976c | 387 | |
5b9afe8a YQ |
388 | if (p) |
389 | len = p - arg; | |
390 | else | |
391 | len = strlen (arg); | |
d318976c | 392 | |
5b9afe8a YQ |
393 | nmatches = 0; |
394 | for (i = 0; c->enums[i]; i++) | |
395 | if (strncmp (arg, c->enums[i], len) == 0) | |
396 | { | |
397 | if (c->enums[i][len] == '\0') | |
398 | { | |
399 | match = c->enums[i]; | |
400 | nmatches = 1; | |
401 | break; /* Exact match. */ | |
402 | } | |
403 | else | |
d318976c | 404 | { |
5b9afe8a YQ |
405 | match = c->enums[i]; |
406 | nmatches++; | |
d318976c | 407 | } |
5b9afe8a | 408 | } |
d318976c | 409 | |
5b9afe8a YQ |
410 | if (nmatches <= 0) |
411 | error (_("Undefined item: \"%s\"."), arg); | |
d318976c | 412 | |
5b9afe8a YQ |
413 | if (nmatches > 1) |
414 | error (_("Ambiguous item \"%s\"."), arg); | |
d318976c | 415 | |
5b9afe8a YQ |
416 | if (*(const char **) c->var != match) |
417 | { | |
d318976c | 418 | *(const char **) c->var = match; |
5b9afe8a YQ |
419 | |
420 | option_changed = 1; | |
d318976c | 421 | } |
5b9afe8a YQ |
422 | } |
423 | break; | |
6fc1c773 YQ |
424 | case var_zuinteger_unlimited: |
425 | { | |
426 | LONGEST val; | |
427 | ||
428 | if (arg == NULL) | |
f81d1120 PA |
429 | error_no_arg (_("integer to set it to, or \"unlimited\".")); |
430 | ||
431 | if (is_unlimited_literal (arg)) | |
432 | val = -1; | |
433 | else | |
434 | val = parse_and_eval_long (arg); | |
6fc1c773 | 435 | |
ef0026f0 | 436 | if (val > INT_MAX) |
6fc1c773 YQ |
437 | error (_("integer %s out of range"), plongest (val)); |
438 | else if (val < -1) | |
439 | error (_("only -1 is allowed to set as unlimited")); | |
440 | ||
441 | if (*(int *) c->var != val) | |
442 | { | |
443 | *(int *) c->var = val; | |
444 | option_changed = 1; | |
445 | } | |
446 | } | |
447 | break; | |
5b9afe8a YQ |
448 | default: |
449 | error (_("gdb internal error: bad var_type in do_setshow_command")); | |
d318976c | 450 | } |
5b9afe8a | 451 | c->func (c, NULL, from_tty); |
5b9afe8a YQ |
452 | |
453 | if (notify_command_param_changed_p (option_changed, c)) | |
d318976c | 454 | { |
5b9afe8a YQ |
455 | char *name, *cp; |
456 | struct cmd_list_element **cmds; | |
457 | struct cmd_list_element *p; | |
458 | int i; | |
459 | int length = 0; | |
460 | ||
461 | /* Compute the whole multi-word command options. If user types command | |
462 | 'set foo bar baz on', c->name is 'baz', and GDB can't pass "bar" to | |
463 | command option change notification, because it is confusing. We can | |
464 | trace back through field 'prefix' to compute the whole options, | |
465 | and pass "foo bar baz" to notification. */ | |
466 | ||
467 | for (i = 0, p = c; p != NULL; i++) | |
468 | { | |
469 | length += strlen (p->name); | |
470 | length++; | |
471 | ||
472 | p = p->prefix; | |
473 | } | |
8d749320 SM |
474 | cp = name = (char *) xmalloc (length); |
475 | cmds = XNEWVEC (struct cmd_list_element *, i); | |
5b9afe8a YQ |
476 | |
477 | /* Track back through filed 'prefix' and cache them in CMDS. */ | |
478 | for (i = 0, p = c; p != NULL; i++) | |
479 | { | |
480 | cmds[i] = p; | |
481 | p = p->prefix; | |
482 | } | |
483 | ||
484 | /* Don't trigger any observer notification if prefixlist is not | |
485 | setlist. */ | |
486 | i--; | |
487 | if (cmds[i]->prefixlist != &setlist) | |
488 | { | |
489 | xfree (cmds); | |
490 | xfree (name); | |
491 | ||
492 | return; | |
493 | } | |
494 | /* Traverse them in the reversed order, and copy their names into | |
495 | NAME. */ | |
496 | for (i--; i >= 0; i--) | |
497 | { | |
498 | memcpy (cp, cmds[i]->name, strlen (cmds[i]->name)); | |
499 | cp += strlen (cmds[i]->name); | |
d318976c | 500 | |
5b9afe8a YQ |
501 | if (i != 0) |
502 | { | |
503 | cp[0] = ' '; | |
504 | cp++; | |
505 | } | |
506 | } | |
507 | cp[0] = 0; | |
d318976c | 508 | |
5b9afe8a | 509 | xfree (cmds); |
552c04a7 | 510 | |
d318976c FN |
511 | switch (c->var_type) |
512 | { | |
513 | case var_string: | |
d318976c FN |
514 | case var_string_noescape: |
515 | case var_filename: | |
5b9afe8a | 516 | case var_optional_filename: |
d318976c | 517 | case var_enum: |
76727919 | 518 | gdb::observers::command_param_changed.notify (name, *(char **) c->var); |
d318976c FN |
519 | break; |
520 | case var_boolean: | |
5b9afe8a | 521 | { |
e6a959d6 | 522 | const char *opt = *(int *) c->var ? "on" : "off"; |
5b9afe8a | 523 | |
76727919 | 524 | gdb::observers::command_param_changed.notify (name, opt); |
5b9afe8a | 525 | } |
d318976c FN |
526 | break; |
527 | case var_auto_boolean: | |
5b9afe8a YQ |
528 | { |
529 | const char *s = auto_boolean_enums[*(enum auto_boolean *) c->var]; | |
530 | ||
76727919 | 531 | gdb::observers::command_param_changed.notify (name, s); |
5b9afe8a | 532 | } |
d318976c FN |
533 | break; |
534 | case var_uinteger: | |
1e8fb976 | 535 | case var_zuinteger: |
5b9afe8a YQ |
536 | { |
537 | char s[64]; | |
538 | ||
539 | xsnprintf (s, sizeof s, "%u", *(unsigned int *) c->var); | |
76727919 | 540 | gdb::observers::command_param_changed.notify (name, s); |
5b9afe8a | 541 | } |
d318976c FN |
542 | break; |
543 | case var_integer: | |
a40a111f | 544 | case var_zinteger: |
6fc1c773 | 545 | case var_zuinteger_unlimited: |
5b9afe8a YQ |
546 | { |
547 | char s[64]; | |
d318976c | 548 | |
5b9afe8a | 549 | xsnprintf (s, sizeof s, "%d", *(int *) c->var); |
76727919 | 550 | gdb::observers::command_param_changed.notify (name, s); |
5b9afe8a YQ |
551 | } |
552 | break; | |
d318976c | 553 | } |
5b9afe8a YQ |
554 | xfree (name); |
555 | } | |
556 | } | |
899506a8 | 557 | |
5b9afe8a YQ |
558 | /* Do a "show" command. ARG is NULL if no argument, or the |
559 | text of the argument, and FROM_TTY is nonzero if this command is | |
560 | being entered directly by the user (i.e. these are just like any | |
561 | other command). C is the command list element for the command. */ | |
899506a8 | 562 | |
5b9afe8a | 563 | void |
06900326 | 564 | do_show_command (const char *arg, int from_tty, struct cmd_list_element *c) |
5b9afe8a YQ |
565 | { |
566 | struct ui_out *uiout = current_uiout; | |
899506a8 | 567 | |
5b9afe8a YQ |
568 | gdb_assert (c->type == show_cmd); |
569 | ||
d7e74731 | 570 | string_file stb; |
cdb27c12 | 571 | |
5b9afe8a YQ |
572 | /* Possibly call the pre hook. */ |
573 | if (c->pre_show_hook) | |
574 | (c->pre_show_hook) (c); | |
575 | ||
576 | switch (c->var_type) | |
577 | { | |
578 | case var_string: | |
579 | if (*(char **) c->var) | |
d7e74731 | 580 | stb.putstr (*(char **) c->var, '"'); |
5b9afe8a YQ |
581 | break; |
582 | case var_string_noescape: | |
583 | case var_optional_filename: | |
584 | case var_filename: | |
585 | case var_enum: | |
586 | if (*(char **) c->var) | |
d7e74731 | 587 | stb.puts (*(char **) c->var); |
5b9afe8a YQ |
588 | break; |
589 | case var_boolean: | |
d7e74731 | 590 | stb.puts (*(int *) c->var ? "on" : "off"); |
5b9afe8a YQ |
591 | break; |
592 | case var_auto_boolean: | |
593 | switch (*(enum auto_boolean*) c->var) | |
594 | { | |
595 | case AUTO_BOOLEAN_TRUE: | |
d7e74731 | 596 | stb.puts ("on"); |
5b9afe8a YQ |
597 | break; |
598 | case AUTO_BOOLEAN_FALSE: | |
d7e74731 | 599 | stb.puts ("off"); |
5b9afe8a YQ |
600 | break; |
601 | case AUTO_BOOLEAN_AUTO: | |
d7e74731 | 602 | stb.puts ("auto"); |
5b9afe8a YQ |
603 | break; |
604 | default: | |
605 | internal_error (__FILE__, __LINE__, | |
606 | _("do_show_command: " | |
607 | "invalid var_auto_boolean")); | |
608 | break; | |
899506a8 | 609 | } |
5b9afe8a YQ |
610 | break; |
611 | case var_uinteger: | |
612 | case var_zuinteger: | |
613 | if (c->var_type == var_uinteger | |
614 | && *(unsigned int *) c->var == UINT_MAX) | |
d7e74731 | 615 | stb.puts ("unlimited"); |
5b9afe8a | 616 | else |
d7e74731 | 617 | stb.printf ("%u", *(unsigned int *) c->var); |
5b9afe8a YQ |
618 | break; |
619 | case var_integer: | |
620 | case var_zinteger: | |
621 | if (c->var_type == var_integer | |
622 | && *(int *) c->var == INT_MAX) | |
d7e74731 | 623 | stb.puts ("unlimited"); |
5b9afe8a | 624 | else |
d7e74731 | 625 | stb.printf ("%d", *(int *) c->var); |
5b9afe8a | 626 | break; |
6fc1c773 YQ |
627 | case var_zuinteger_unlimited: |
628 | { | |
629 | if (*(int *) c->var == -1) | |
d7e74731 | 630 | stb.puts ("unlimited"); |
6fc1c773 | 631 | else |
d7e74731 | 632 | stb.printf ("%d", *(int *) c->var); |
6fc1c773 YQ |
633 | } |
634 | break; | |
5b9afe8a YQ |
635 | default: |
636 | error (_("gdb internal error: bad var_type in do_show_command")); | |
d318976c | 637 | } |
5b9afe8a YQ |
638 | |
639 | ||
640 | /* FIXME: cagney/2005-02-10: Need to split this in half: code to | |
641 | convert the value into a string (esentially the above); and | |
642 | code to print the value out. For the latter there should be | |
643 | MI and CLI specific versions. */ | |
644 | ||
112e8700 SM |
645 | if (uiout->is_mi_like_p ()) |
646 | uiout->field_stream ("value", stb); | |
d318976c | 647 | else |
5b9afe8a | 648 | { |
5b9afe8a | 649 | if (c->show_value_func != NULL) |
d7e74731 | 650 | c->show_value_func (gdb_stdout, from_tty, c, stb.c_str ()); |
5b9afe8a | 651 | else |
d7e74731 | 652 | deprecated_show_value_hack (gdb_stdout, from_tty, c, stb.c_str ()); |
5b9afe8a | 653 | } |
5b9afe8a | 654 | |
9f60d481 | 655 | c->func (c, NULL, from_tty); |
d318976c FN |
656 | } |
657 | ||
658 | /* Show all the settings in a list of show commands. */ | |
659 | ||
660 | void | |
64e61d29 | 661 | cmd_show_list (struct cmd_list_element *list, int from_tty, const char *prefix) |
d318976c | 662 | { |
79a45e25 | 663 | struct ui_out *uiout = current_uiout; |
3b31d625 | 664 | |
2e783024 | 665 | ui_out_emit_tuple tuple_emitter (uiout, "showlist"); |
d318976c FN |
666 | for (; list != NULL; list = list->next) |
667 | { | |
668 | /* If we find a prefix, run its list, prefixing our output by its | |
669 | prefix (with "show " skipped). */ | |
d318976c FN |
670 | if (list->prefixlist && !list->abbrev_flag) |
671 | { | |
2e783024 | 672 | ui_out_emit_tuple optionlist_emitter (uiout, "optionlist"); |
acaa662f | 673 | const char *new_prefix = strstr (list->prefixname, "show ") + 5; |
cdb27c12 | 674 | |
112e8700 SM |
675 | if (uiout->is_mi_like_p ()) |
676 | uiout->field_string ("prefix", new_prefix); | |
37fc812e | 677 | cmd_show_list (*list->prefixlist, from_tty, new_prefix); |
d318976c | 678 | } |
427c3a89 | 679 | else |
d318976c | 680 | { |
fe978cb0 | 681 | if (list->theclass != no_set_class) |
db5f229b | 682 | { |
2e783024 | 683 | ui_out_emit_tuple option_emitter (uiout, "option"); |
db5f229b | 684 | |
112e8700 SM |
685 | uiout->text (prefix); |
686 | uiout->field_string ("name", list->name); | |
687 | uiout->text (": "); | |
db5f229b | 688 | if (list->type == show_cmd) |
5b9afe8a | 689 | do_show_command ((char *) NULL, from_tty, list); |
db5f229b MS |
690 | else |
691 | cmd_func (list, NULL, from_tty); | |
db5f229b | 692 | } |
d318976c | 693 | } |
d318976c | 694 | } |
d318976c FN |
695 | } |
696 |