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