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