]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/cli/cli-setshow.c
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / cli / cli-setshow.c
CommitLineData
d318976c 1/* Handle set and show GDB commands.
8926118c 2
1d506c26 3 Copyright (C) 2000-2024 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"
3d654fa7 24#include "interps.h"
d318976c 25
d318976c 26#include "ui-out.h"
d318976c
FN
27
28#include "cli/cli-decode.h"
29#include "cli/cli-cmds.h"
30#include "cli/cli-setshow.h"
f81d1120 31#include "cli/cli-utils.h"
d318976c 32
5b9afe8a
YQ
33/* Return true if the change of command parameter should be notified. */
34
9413ea16
SM
35static bool
36notify_command_param_changed_p (bool param_changed, struct cmd_list_element *c)
5b9afe8a 37{
9413ea16
SM
38 if (!param_changed)
39 return false;
5b9afe8a 40
7ead06a8 41 return c->theclass != class_maintenance && c->theclass != class_obscure;
5b9afe8a
YQ
42}
43
d318976c 44\f
7f19b9a2 45static enum auto_boolean
d318976c
FN
46parse_auto_binary_operation (const char *arg)
47{
48 if (arg != NULL && *arg != '\0')
49 {
50 int length = strlen (arg);
cdb27c12 51
d318976c
FN
52 while (isspace (arg[length - 1]) && length > 0)
53 length--;
dee7b4c8
PA
54
55 /* Note that "o" is ambiguous. */
56
57 if ((length == 2 && strncmp (arg, "on", length) == 0)
d318976c
FN
58 || strncmp (arg, "1", length) == 0
59 || strncmp (arg, "yes", length) == 0
60 || strncmp (arg, "enable", length) == 0)
7f19b9a2 61 return AUTO_BOOLEAN_TRUE;
dee7b4c8 62 else if ((length >= 2 && strncmp (arg, "off", length) == 0)
d318976c
FN
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 67 else if (strncmp (arg, "auto", length) == 0
dee7b4c8 68 || (length > 1 && strncmp (arg, "-1", length) == 0))
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
77int
9d0faba9 78parse_cli_boolean_value (const char **arg)
d318976c 79{
9d0faba9
PA
80 const char *p = skip_to_space (*arg);
81 size_t length = p - *arg;
d318976c 82
9d0faba9 83 /* Note that "o" is ambiguous. */
d318976c 84
9d0faba9
PA
85 if ((length == 2 && strncmp (*arg, "on", length) == 0)
86 || strncmp (*arg, "1", length) == 0
87 || strncmp (*arg, "yes", length) == 0
88 || strncmp (*arg, "enable", length) == 0)
89 {
90 *arg = skip_spaces (*arg + length);
91 return 1;
92 }
93 else if ((length >= 2 && strncmp (*arg, "off", length) == 0)
94 || strncmp (*arg, "0", length) == 0
95 || strncmp (*arg, "no", length) == 0
96 || strncmp (*arg, "disable", length) == 0)
97 {
98 *arg = skip_spaces (*arg + length);
99 return 0;
100 }
101 else
102 return -1;
103}
d318976c 104
9d0faba9 105/* See cli-setshow.h. */
dee7b4c8 106
9d0faba9
PA
107int
108parse_cli_boolean_value (const char *arg)
109{
110 if (!arg || !*arg)
d318976c 111 return 1;
9d0faba9
PA
112
113 int b = parse_cli_boolean_value (&arg);
114 if (b >= 0 && *arg != '\0')
bd712aed 115 return -1;
9d0faba9
PA
116
117 return b;
d318976c 118}
9d0faba9 119
d318976c 120\f
b63c50f9 121static void
08546159
AC
122deprecated_show_value_hack (struct ui_file *ignore_file,
123 int ignore_from_tty,
124 struct cmd_list_element *c,
125 const char *value)
126{
4d28ad1e
AC
127 /* If there's no command or value, don't try to print it out. */
128 if (c == NULL || value == NULL)
129 return;
1d7fe7f0 130
590042fc
PW
131 /* Print doc minus "Show " at start. Tell print_doc_line that
132 this is for a 'show value' prefix. */
133 print_doc_line (gdb_stdout, c->doc + 5, true);
1d7fe7f0
LS
134
135 gdb_assert (c->var.has_value ());
136
137 switch (c->var->type ())
08546159
AC
138 {
139 case var_string:
140 case var_string_noescape:
b4b4ac0b 141 case var_optional_filename:
08546159
AC
142 case var_filename:
143 case var_enum:
6cb06a8c 144 gdb_printf ((" is \"%s\".\n"), value);
08546159 145 break;
1d7fe7f0 146
08546159 147 default:
6cb06a8c 148 gdb_printf ((" is %s.\n"), value);
08546159
AC
149 break;
150 }
151}
152
7aeb03e2 153/* Returns true and the value in VAL if ARG is an accepted literal. */
f81d1120 154
9d0faba9 155static bool
7aeb03e2
MR
156get_literal_val (LONGEST &val, const literal_def *extra_literals,
157 const char **arg, bool expression)
f81d1120 158{
9d0faba9 159 *arg = skip_spaces (*arg);
f81d1120 160
4c048731
PA
161 const char *unl_start = *arg;
162
9d0faba9 163 const char *p = skip_to_space (*arg);
93bcb043 164
9d0faba9 165 size_t len = p - *arg;
93bcb043 166
7aeb03e2
MR
167 if (len > 0 && extra_literals != nullptr)
168 for (const literal_def *l = extra_literals;
169 l->literal != nullptr;
170 l++)
171 if (strncmp (l->literal, *arg, len) == 0)
4c048731 172 {
7aeb03e2 173 *arg += len;
4c048731 174
7aeb03e2
MR
175 /* If parsing an expression (i.e., parsing for a "set" command),
176 anything after the literal is junk. For options, anything
177 after the literal might be a command argument or another
178 option. */
179 if (expression)
180 {
181 const char *after = skip_spaces (*arg);
182 if (*after != '\0')
183 error (_("Junk after \"%.*s\": %s"),
184 (int) len, unl_start, after);
185 }
186
187 val = l->use;
188 return true;
189 }
93bcb043
PA
190
191 return false;
f81d1120
PA
192}
193
9d0faba9
PA
194/* See cli-setshow.h. */
195
7aeb03e2
MR
196LONGEST
197parse_cli_var_integer (var_types var_type, const literal_def *extra_literals,
198 const char **arg, bool expression)
9d0faba9
PA
199{
200 LONGEST val;
201
fdbc9870 202 if (*arg == nullptr || **arg == '\0')
9d0faba9 203 {
7aeb03e2 204 if (extra_literals == nullptr)
575fd4cf 205 error_no_arg (_("integer to set it to"));
7aeb03e2
MR
206 else
207 {
208 std::string buffer = "";
209 size_t count = 0;
9d0faba9 210
7aeb03e2
MR
211 for (const literal_def *l = extra_literals;
212 l->literal != nullptr;
213 l++, count++)
214 {
215 if (count != 0)
216 buffer += ", ";
217 buffer = buffer + '"' + l->literal + '"';
218 }
219 if (count > 1)
220 error_no_arg
221 (string_printf (_("integer to set it to, or one of: %s"),
222 buffer.c_str ()).c_str ());
223 else
224 error_no_arg
225 (string_printf (_("integer to set it to, or %s"),
226 buffer.c_str ()).c_str ());
227 }
228 }
9d0faba9 229
7aeb03e2
MR
230 if (!get_literal_val (val, extra_literals, arg, expression))
231 {
232 if (expression)
233 val = parse_and_eval_long (*arg);
234 else
235 val = get_ulongest (arg);
9d0faba9 236
7aeb03e2
MR
237 enum tribool allowed = TRIBOOL_UNKNOWN;
238 if (extra_literals != nullptr)
239 {
240 for (const literal_def *l = extra_literals;
241 l->literal != nullptr;
242 l++)
243 if (l->val.has_value () && val == *l->val)
244 {
245 allowed = TRIBOOL_TRUE;
246 val = l->use;
247 break;
248 }
249 else if (val == l->use)
250 allowed = TRIBOOL_FALSE;
251 }
9d0faba9 252
7aeb03e2
MR
253 if (allowed == TRIBOOL_UNKNOWN)
254 {
255 if (val > UINT_MAX || val < INT_MIN
256 || (var_type == var_uinteger && val < 0)
257 || (var_type == var_integer && val > INT_MAX)
258 || (var_type == var_pinteger && val < 0)
259 || (var_type == var_pinteger && val > INT_MAX))
260 allowed = TRIBOOL_FALSE;
261 }
262 if (allowed == TRIBOOL_FALSE)
263 error (_("integer %s out of range"), plongest (val));
264 }
9d0faba9
PA
265
266 return val;
267}
268
269/* See cli-setshow.h. */
270
271const char *
272parse_cli_var_enum (const char **args, const char *const *enums)
273{
274 /* If no argument was supplied, print an informative error
275 message. */
276 if (args == NULL || *args == NULL || **args == '\0')
277 {
278 std::string msg;
279
280 for (size_t i = 0; enums[i]; i++)
281 {
282 if (i != 0)
283 msg += ", ";
284 msg += enums[i];
285 }
286 error (_("Requires an argument. Valid arguments are %s."),
287 msg.c_str ());
288 }
289
290 const char *p = skip_to_space (*args);
291 size_t len = p - *args;
292
293 int nmatches = 0;
294 const char *match = NULL;
295 for (size_t i = 0; enums[i]; i++)
296 if (strncmp (*args, enums[i], len) == 0)
297 {
298 if (enums[i][len] == '\0')
299 {
300 match = enums[i];
301 nmatches = 1;
302 break; /* Exact match. */
303 }
304 else
305 {
306 match = enums[i];
307 nmatches++;
308 }
309 }
310
311 if (nmatches == 0)
312 error (_("Undefined item: \"%.*s\"."), (int) len, *args);
313
314 if (nmatches > 1)
315 error (_("Ambiguous item \"%.*s\"."), (int) len, *args);
316
317 *args += len;
318 return match;
319}
f81d1120 320
5b9afe8a 321/* Do a "set" command. ARG is NULL if no argument, or the
ebcd3b23
MS
322 text of the argument, and FROM_TTY is nonzero if this command is
323 being entered directly by the user (i.e. these are just like any
324 other command). C is the command list element for the command. */
d318976c
FN
325
326void
06900326 327do_set_command (const char *arg, int from_tty, struct cmd_list_element *c)
d318976c 328{
5b9afe8a 329 /* A flag to indicate the option is changed or not. */
9413ea16 330 bool option_changed = false;
5b9afe8a
YQ
331
332 gdb_assert (c->type == set_cmd);
79a45e25 333
fdbc9870
PA
334 if (arg == NULL)
335 arg = "";
336
1d7fe7f0
LS
337 gdb_assert (c->var.has_value ());
338
339 switch (c->var->type ())
d318976c 340 {
5b9afe8a
YQ
341 case var_string:
342 {
c6503096 343 std::string newobj;
d7561cbb 344 const char *p;
5b9afe8a
YQ
345 int ch;
346
c6503096 347 newobj.reserve (strlen (arg));
5b9afe8a 348 p = arg;
5b9afe8a 349 while ((ch = *p++) != '\000')
d318976c 350 {
5b9afe8a 351 if (ch == '\\')
d318976c 352 {
5b9afe8a
YQ
353 /* \ at end of argument is used after spaces
354 so they won't be lost. */
355 /* This is obsolete now that we no longer strip
356 trailing whitespace and actually, the backslash
357 didn't get here in my test, readline or
358 something did something funky with a backslash
359 right before a newline. */
360 if (*p == 0)
361 break;
362 ch = parse_escape (get_current_arch (), &p);
363 if (ch == 0)
364 break; /* C loses */
365 else if (ch > 0)
c6503096 366 newobj.push_back (ch);
d318976c 367 }
5b9afe8a 368 else
c6503096 369 newobj.push_back (ch);
5b9afe8a 370 }
c6503096
TT
371 newobj.shrink_to_fit ();
372
373 option_changed = c->var->set<std::string> (std::move (newobj));
5b9afe8a
YQ
374 }
375 break;
376 case var_string_noescape:
1a98bb55 377 option_changed = c->var->set<std::string> (std::string (arg));
5b9afe8a
YQ
378 break;
379 case var_filename:
fdbc9870 380 if (*arg == '\0')
5b9afe8a 381 error_no_arg (_("filename to set it to."));
d182e398 382 [[fallthrough]];
5b9afe8a
YQ
383 case var_optional_filename:
384 {
385 char *val = NULL;
6ace3df1 386
fdbc9870 387 if (*arg != '\0')
5b9afe8a
YQ
388 {
389 /* Clear trailing whitespace of filename. */
06900326 390 const char *ptr = arg + strlen (arg) - 1;
6ace3df1 391
5b9afe8a
YQ
392 while (ptr >= arg && (*ptr == ' ' || *ptr == '\t'))
393 ptr--;
be77dd73
TT
394 gdb::unique_xmalloc_ptr<char> copy
395 = make_unique_xstrndup (arg, ptr + 1 - arg);
5b9afe8a 396
be77dd73 397 val = tilde_expand (copy.get ());
5b9afe8a
YQ
398 }
399 else
400 val = xstrdup ("");
401
1a98bb55
LS
402 option_changed
403 = c->var->set<std::string> (std::string (val));
e0700ba4 404 xfree (val);
5b9afe8a
YQ
405 }
406 break;
407 case var_boolean:
408 {
bd712aed 409 int val = parse_cli_boolean_value (arg);
5b9afe8a 410
bd712aed
DE
411 if (val < 0)
412 error (_("\"on\" or \"off\" expected."));
5b9afe8a 413
1a98bb55 414 option_changed = c->var->set<bool> (val);
5b9afe8a
YQ
415 }
416 break;
417 case var_auto_boolean:
1a98bb55 418 option_changed = c->var->set<enum auto_boolean> (parse_auto_binary_operation (arg));
5b9afe8a
YQ
419 break;
420 case var_uinteger:
1a98bb55 421 option_changed
7aeb03e2
MR
422 = c->var->set<unsigned int> (parse_cli_var_integer (c->var->type (),
423 c->var->
424 extra_literals (),
425 &arg, true));
5b9afe8a
YQ
426 break;
427 case var_integer:
7aeb03e2
MR
428 case var_pinteger:
429 option_changed
430 = c->var->set<int> (parse_cli_var_integer (c->var->type (),
431 c->var->extra_literals (),
432 &arg, true));
1d7fe7f0 433 break;
5b9afe8a
YQ
434 case var_enum:
435 {
9d0faba9
PA
436 const char *end_arg = arg;
437 const char *match = parse_cli_var_enum (&end_arg, c->enums);
5b9afe8a 438
9d0faba9
PA
439 int len = end_arg - arg;
440 const char *after = skip_spaces (end_arg);
48c410fb
PA
441 if (*after != '\0')
442 error (_("Junk after item \"%.*s\": %s"), len, arg, after);
443
1a98bb55 444 option_changed = c->var->set<const char *> (match);
5b9afe8a
YQ
445 }
446 break;
447 default:
448 error (_("gdb internal error: bad var_type in do_setshow_command"));
d318976c 449 }
5538b03c
SM
450
451 c->func (NULL, from_tty, c);
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
14b42fc4 484 /* Don't trigger any observer notification if subcommands is not
5b9afe8a
YQ
485 setlist. */
486 i--;
14b42fc4 487 if (cmds[i]->subcommands != &setlist)
5b9afe8a
YQ
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
1d7fe7f0 511 switch (c->var->type ())
d318976c
FN
512 {
513 case var_string:
d318976c
FN
514 case var_string_noescape:
515 case var_filename:
5b9afe8a 516 case var_optional_filename:
3d654fa7 517 interps_notify_param_changed
e0700ba4
SM
518 (name, c->var->get<std::string> ().c_str ());
519 break;
d318976c 520 case var_enum:
3d654fa7 521 interps_notify_param_changed
e0700ba4 522 (name, c->var->get<const char *> ());
d318976c
FN
523 break;
524 case var_boolean:
5b9afe8a 525 {
1d7fe7f0 526 const char *opt = c->var->get<bool> () ? "on" : "off";
5b9afe8a 527
3d654fa7 528 interps_notify_param_changed (name, opt);
5b9afe8a 529 }
d318976c
FN
530 break;
531 case var_auto_boolean:
5b9afe8a 532 {
1d7fe7f0
LS
533 const char *s
534 = auto_boolean_enums[c->var->get<enum auto_boolean> ()];
5b9afe8a 535
3d654fa7 536 interps_notify_param_changed (name, s);
5b9afe8a 537 }
d318976c
FN
538 break;
539 case var_uinteger:
5b9afe8a
YQ
540 {
541 char s[64];
542
1d7fe7f0 543 xsnprintf (s, sizeof s, "%u", c->var->get<unsigned int> ());
3d654fa7 544 interps_notify_param_changed (name, s);
5b9afe8a 545 }
d318976c
FN
546 break;
547 case var_integer:
7aeb03e2 548 case var_pinteger:
5b9afe8a
YQ
549 {
550 char s[64];
d318976c 551
1d7fe7f0 552 xsnprintf (s, sizeof s, "%d", c->var->get<int> ());
3d654fa7 553 interps_notify_param_changed (name, s);
5b9afe8a
YQ
554 }
555 break;
d318976c 556 }
5b9afe8a
YQ
557 xfree (name);
558 }
559}
899506a8 560
fdbc9870 561/* See cli/cli-setshow.h. */
899506a8 562
fdbc9870 563std::string
1d7fe7f0 564get_setshow_command_value_string (const setting &var)
5b9afe8a 565{
d7e74731 566 string_file stb;
cdb27c12 567
1d7fe7f0 568 switch (var.type ())
5b9afe8a
YQ
569 {
570 case var_string:
1d7fe7f0 571 {
e0700ba4
SM
572 std::string value = var.get<std::string> ();
573 if (!value.empty ())
574 stb.putstr (value.c_str (), '"');
1d7fe7f0 575 }
5b9afe8a
YQ
576 break;
577 case var_string_noescape:
578 case var_optional_filename:
579 case var_filename:
e0700ba4
SM
580 stb.puts (var.get<std::string> ().c_str ());
581 break;
5b9afe8a 582 case var_enum:
1d7fe7f0 583 {
e0700ba4 584 const char *value = var.get<const char *> ();
1d7fe7f0
LS
585 if (value != nullptr)
586 stb.puts (value);
587 }
5b9afe8a
YQ
588 break;
589 case var_boolean:
1d7fe7f0 590 stb.puts (var.get<bool> () ? "on" : "off");
5b9afe8a
YQ
591 break;
592 case var_auto_boolean:
1d7fe7f0 593 switch (var.get<enum auto_boolean> ())
5b9afe8a
YQ
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:
fdbc9870 605 gdb_assert_not_reached ("invalid var_auto_boolean");
5b9afe8a 606 break;
899506a8 607 }
5b9afe8a
YQ
608 break;
609 case var_uinteger:
5b9afe8a 610 case var_integer:
7aeb03e2 611 case var_pinteger:
6fc1c773 612 {
7aeb03e2
MR
613 bool printed = false;
614 const LONGEST value
615 = (var.type () == var_uinteger
616 ? static_cast<LONGEST> (var.get<unsigned int> ())
617 : static_cast<LONGEST> (var.get<int> ()));
618
619 if (var.extra_literals () != nullptr)
620 for (const literal_def *l = var.extra_literals ();
621 l->literal != nullptr;
622 l++)
623 if (value == l->use)
624 {
625 stb.puts (l->literal);
626 printed = true;
627 break;
628 }
629 if (!printed)
630 {
631 if (var.type () == var_uinteger)
632 stb.printf ("%u", static_cast<unsigned int> (value));
633 else
634 stb.printf ("%d", static_cast<int> (value));
635 }
6fc1c773
YQ
636 }
637 break;
5b9afe8a 638 default:
fdbc9870 639 gdb_assert_not_reached ("bad var_type");
d318976c 640 }
5b9afe8a 641
5d10a204 642 return stb.release ();
fdbc9870
PA
643}
644
645
646/* Do a "show" command. ARG is NULL if no argument, or the
647 text of the argument, and FROM_TTY is nonzero if this command is
648 being entered directly by the user (i.e. these are just like any
649 other command). C is the command list element for the command. */
650
651void
652do_show_command (const char *arg, int from_tty, struct cmd_list_element *c)
653{
654 struct ui_out *uiout = current_uiout;
655
656 gdb_assert (c->type == show_cmd);
1d7fe7f0 657 gdb_assert (c->var.has_value ());
fdbc9870 658
1d7fe7f0 659 std::string val = get_setshow_command_value_string (*c->var);
5b9afe8a 660
fdbc9870
PA
661 /* FIXME: cagney/2005-02-10: There should be MI and CLI specific
662 versions of code to print the value out. */
5b9afe8a 663
112e8700 664 if (uiout->is_mi_like_p ())
8dd8c8d4 665 uiout->field_string ("value", val);
d318976c 666 else
5b9afe8a 667 {
5b9afe8a 668 if (c->show_value_func != NULL)
fdbc9870 669 c->show_value_func (gdb_stdout, from_tty, c, val.c_str ());
5b9afe8a 670 else
fdbc9870 671 deprecated_show_value_hack (gdb_stdout, from_tty, c, val.c_str ());
5b9afe8a 672 }
5b9afe8a 673
5538b03c 674 c->func (NULL, from_tty, c);
d318976c
FN
675}
676
677/* Show all the settings in a list of show commands. */
678
679void
7aa1b46f 680cmd_show_list (struct cmd_list_element *list, int from_tty)
d318976c 681{
79a45e25 682 struct ui_out *uiout = current_uiout;
3b31d625 683
2e783024 684 ui_out_emit_tuple tuple_emitter (uiout, "showlist");
d318976c
FN
685 for (; list != NULL; list = list->next)
686 {
7aa1b46f
PW
687 /* We skip show command aliases to avoid showing duplicated values. */
688
d318976c 689 /* If we find a prefix, run its list, prefixing our output by its
dda83cd7 690 prefix (with "show " skipped). */
3d0b3564 691 if (list->is_prefix () && !list->is_alias ())
d318976c 692 {
2e783024 693 ui_out_emit_tuple optionlist_emitter (uiout, "optionlist");
2f822da5
MB
694 std::string prefixname = list->prefixname ();
695 const char *new_prefix = strstr (prefixname.c_str (), "show ") + 5;
cdb27c12 696
112e8700
SM
697 if (uiout->is_mi_like_p ())
698 uiout->field_string ("prefix", new_prefix);
14b42fc4 699 cmd_show_list (*list->subcommands, from_tty);
d318976c 700 }
1be99b11 701 else if (list->theclass != no_set_class && !list->is_alias ())
d318976c 702 {
7aa1b46f
PW
703 ui_out_emit_tuple option_emitter (uiout, "option");
704
2f822da5
MB
705 if (list->prefix != nullptr)
706 {
707 /* If we find a prefix, output it (with "show " skipped). */
708 std::string prefixname = list->prefix->prefixname ();
3d0b3564 709 prefixname = (!list->prefix->is_prefix () ? ""
2f822da5 710 : strstr (prefixname.c_str (), "show ") + 5);
4915bfdc 711 uiout->text (prefixname);
2f822da5 712 }
7aa1b46f
PW
713 uiout->field_string ("name", list->name);
714 uiout->text (": ");
715 if (list->type == show_cmd)
716 do_show_command (NULL, from_tty, list);
717 else
718 cmd_func (list, NULL, from_tty);
d318976c 719 }
d318976c 720 }
d318976c
FN
721}
722
7aa1b46f 723