1 /* Handle set and show GDB commands.
2 Copyright 2000, 2001 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
23 #include "gdb_string.h"
30 #include "cli/cli-decode.h"
31 #include "cli/cli-cmds.h"
32 #include "cli/cli-setshow.h"
34 /* Prototypes for local functions */
36 static int parse_binary_operation (char *);
38 static enum cmd_auto_boolean
parse_auto_binary_operation (const char *arg
);
40 static enum cmd_auto_boolean
41 parse_auto_binary_operation (const char *arg
)
43 if (arg
!= NULL
&& *arg
!= '\0')
45 int length
= strlen (arg
);
46 while (isspace (arg
[length
- 1]) && length
> 0)
48 if (strncmp (arg
, "on", length
) == 0
49 || strncmp (arg
, "1", length
) == 0
50 || strncmp (arg
, "yes", length
) == 0
51 || strncmp (arg
, "enable", length
) == 0)
52 return CMD_AUTO_BOOLEAN_TRUE
;
53 else if (strncmp (arg
, "off", length
) == 0
54 || strncmp (arg
, "0", length
) == 0
55 || strncmp (arg
, "no", length
) == 0
56 || strncmp (arg
, "disable", length
) == 0)
57 return CMD_AUTO_BOOLEAN_FALSE
;
58 else if (strncmp (arg
, "auto", length
) == 0
59 || (strncmp (arg
, "-1", length
) == 0 && length
> 1))
60 return CMD_AUTO_BOOLEAN_AUTO
;
62 error ("\"on\", \"off\" or \"auto\" expected.");
63 return CMD_AUTO_BOOLEAN_AUTO
; /* pacify GCC */
67 parse_binary_operation (char *arg
)
74 length
= strlen (arg
);
76 while (arg
[length
- 1] == ' ' || arg
[length
- 1] == '\t')
79 if (strncmp (arg
, "on", length
) == 0
80 || strncmp (arg
, "1", length
) == 0
81 || strncmp (arg
, "yes", length
) == 0
82 || strncmp (arg
, "enable", length
) == 0)
84 else if (strncmp (arg
, "off", length
) == 0
85 || strncmp (arg
, "0", length
) == 0
86 || strncmp (arg
, "no", length
) == 0
87 || strncmp (arg
, "disable", length
) == 0)
91 error ("\"on\" or \"off\" expected.");
96 /* Do a "set" or "show" command. ARG is NULL if no argument, or the text
97 of the argument, and FROM_TTY is nonzero if this command is being entered
98 directly by the user (i.e. these are just like any other
99 command). C is the command list element for the command. */
102 do_setshow_command (char *arg
, int from_tty
, struct cmd_list_element
*c
)
104 if (c
->type
== set_cmd
)
117 new = (char *) xmalloc (strlen (arg
) + 2);
120 while ((ch
= *p
++) != '\000')
124 /* \ at end of argument is used after spaces
125 so they won't be lost. */
126 /* This is obsolete now that we no longer strip
127 trailing whitespace and actually, the backslash
128 didn't get here in my test, readline or
129 something did something funky with a backslash
130 right before a newline. */
133 ch
= parse_escape (&p
);
143 if (*(p
- 1) != '\\')
147 new = (char *) xrealloc (new, q
- new);
148 if (*(char **) c
->var
!= NULL
)
149 xfree (*(char **) c
->var
);
150 *(char **) c
->var
= new;
153 case var_string_noescape
:
156 if (*(char **) c
->var
!= NULL
)
157 xfree (*(char **) c
->var
);
158 *(char **) c
->var
= savestring (arg
, strlen (arg
));
162 error_no_arg ("filename to set it to.");
163 if (*(char **) c
->var
!= NULL
)
164 xfree (*(char **) c
->var
);
165 *(char **) c
->var
= tilde_expand (arg
);
168 *(int *) c
->var
= parse_binary_operation (arg
);
170 case var_auto_boolean
:
171 *(enum cmd_auto_boolean
*) c
->var
= parse_auto_binary_operation (arg
);
175 error_no_arg ("integer to set it to.");
176 *(unsigned int *) c
->var
= parse_and_eval_long (arg
);
177 if (*(unsigned int *) c
->var
== 0)
178 *(unsigned int *) c
->var
= UINT_MAX
;
184 error_no_arg ("integer to set it to.");
185 val
= parse_and_eval_long (arg
);
187 *(int *) c
->var
= INT_MAX
;
188 else if (val
>= INT_MAX
)
189 error ("integer %u out of range", val
);
191 *(int *) c
->var
= val
;
196 error_no_arg ("integer to set it to.");
197 *(int *) c
->var
= parse_and_eval_long (arg
);
204 const char *match
= NULL
;
207 /* if no argument was supplied, print an informative error message */
211 strcpy (msg
, "Requires an argument. Valid arguments are ");
212 for (i
= 0; c
->enums
[i
]; i
++)
216 strcat (msg
, c
->enums
[i
]);
222 p
= strchr (arg
, ' ');
230 for (i
= 0; c
->enums
[i
]; i
++)
231 if (strncmp (arg
, c
->enums
[i
], len
) == 0)
233 if (c
->enums
[i
][len
] == '\0')
237 break; /* exact match. */
247 error ("Undefined item: \"%s\".", arg
);
250 error ("Ambiguous item \"%s\".", arg
);
252 *(const char **) c
->var
= match
;
256 error ("gdb internal error: bad var_type in do_setshow_command");
259 else if (c
->type
== show_cmd
)
262 struct cleanup
*old_chain
;
263 struct ui_stream
*stb
;
266 stb
= ui_out_stream_new (uiout
);
267 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
270 /* Print doc minus "show" at start. */
271 print_doc_line (gdb_stdout
, c
->doc
+ 5);
274 ui_out_text (uiout
, " is ");
275 ui_out_wrap_hint (uiout
, " ");
283 if (*(unsigned char **) c
->var
)
284 fputstr_filtered (*(unsigned char **) c
->var
, '"', stb
->stream
);
288 case var_string_noescape
:
291 if (*(char **) c
->var
)
292 fputs_filtered (*(char **) c
->var
, stb
->stream
);
296 fputs_filtered (*(int *) c
->var
? "on" : "off", stb
->stream
);
298 case var_auto_boolean
:
299 switch (*(enum cmd_auto_boolean
*) c
->var
)
301 case CMD_AUTO_BOOLEAN_TRUE
:
302 fputs_filtered ("on", stb
->stream
);
304 case CMD_AUTO_BOOLEAN_FALSE
:
305 fputs_filtered ("off", stb
->stream
);
307 case CMD_AUTO_BOOLEAN_AUTO
:
308 fputs_filtered ("auto", stb
->stream
);
311 internal_error (__FILE__
, __LINE__
,
312 "do_setshow_command: invalid var_auto_boolean");
317 if (*(unsigned int *) c
->var
== UINT_MAX
)
319 fputs_filtered ("unlimited", stb
->stream
);
322 /* else fall through */
324 fprintf_filtered (stb
->stream
, "%u", *(unsigned int *) c
->var
);
327 if (*(int *) c
->var
== INT_MAX
)
329 fputs_filtered ("unlimited", stb
->stream
);
332 fprintf_filtered (stb
->stream
, "%d", *(int *) c
->var
);
336 error ("gdb internal error: bad var_type in do_setshow_command");
339 ui_out_text (uiout
, "\"");
340 ui_out_field_stream (uiout
, "value", stb
);
342 ui_out_text (uiout
, "\"");
343 ui_out_text (uiout
, ".\n");
344 do_cleanups (old_chain
);
346 fputs_filtered (" is ", gdb_stdout
);
352 fputs_filtered ("\"", gdb_stdout
);
353 if (*(unsigned char **) c
->var
)
354 fputstr_filtered (*(unsigned char **) c
->var
, '"', gdb_stdout
);
355 fputs_filtered ("\"", gdb_stdout
);
358 case var_string_noescape
:
361 fputs_filtered ("\"", gdb_stdout
);
362 if (*(char **) c
->var
)
363 fputs_filtered (*(char **) c
->var
, gdb_stdout
);
364 fputs_filtered ("\"", gdb_stdout
);
367 fputs_filtered (*(int *) c
->var
? "on" : "off", gdb_stdout
);
369 case var_auto_boolean
:
370 switch (*(enum cmd_auto_boolean
*) c
->var
)
372 case CMD_AUTO_BOOLEAN_TRUE
:
373 fputs_filtered ("on", gdb_stdout
);
375 case CMD_AUTO_BOOLEAN_FALSE
:
376 fputs_filtered ("off", gdb_stdout
);
378 case CMD_AUTO_BOOLEAN_AUTO
:
379 fputs_filtered ("auto", gdb_stdout
);
382 internal_error (__FILE__
, __LINE__
,
383 "do_setshow_command: invalid var_auto_boolean");
388 if (*(unsigned int *) c
->var
== UINT_MAX
)
390 fputs_filtered ("unlimited", gdb_stdout
);
393 /* else fall through */
395 fprintf_filtered (gdb_stdout
, "%u", *(unsigned int *) c
->var
);
398 if (*(int *) c
->var
== INT_MAX
)
400 fputs_filtered ("unlimited", gdb_stdout
);
403 fprintf_filtered (gdb_stdout
, "%d", *(int *) c
->var
);
407 error ("gdb internal error: bad var_type in do_setshow_command");
409 fputs_filtered (".\n", gdb_stdout
);
413 error ("gdb internal error: bad cmd_type in do_setshow_command");
414 (*c
->function
.sfunc
) (NULL
, from_tty
, c
);
415 if (c
->type
== set_cmd
&& set_hook
)
419 /* Show all the settings in a list of show commands. */
422 cmd_show_list (struct cmd_list_element
*list
, int from_tty
, char *prefix
)
425 ui_out_tuple_begin (uiout
, "showlist");
427 for (; list
!= NULL
; list
= list
->next
)
429 /* If we find a prefix, run its list, prefixing our output by its
430 prefix (with "show " skipped). */
432 if (list
->prefixlist
&& !list
->abbrev_flag
)
434 ui_out_tuple_begin (uiout
, "optionlist");
435 ui_out_field_string (uiout
, "prefix", list
->prefixname
+ 5);
436 cmd_show_list (*list
->prefixlist
, from_tty
, list
->prefixname
+ 5);
437 ui_out_tuple_end (uiout
);
439 if (list
->type
== show_cmd
)
441 ui_out_tuple_begin (uiout
, "option");
442 ui_out_text (uiout
, prefix
);
443 ui_out_field_string (uiout
, "name", list
->name
);
444 ui_out_text (uiout
, ": ");
445 do_setshow_command ((char *) NULL
, from_tty
, list
);
446 ui_out_tuple_end (uiout
);
449 if (list
->prefixlist
&& !list
->abbrev_flag
)
450 cmd_show_list (*list
->prefixlist
, from_tty
, list
->prefixname
+ 5);
451 if (list
->type
== show_cmd
)
453 fputs_filtered (prefix
, gdb_stdout
);
454 fputs_filtered (list
->name
, gdb_stdout
);
455 fputs_filtered (": ", gdb_stdout
);
456 do_setshow_command ((char *) NULL
, from_tty
, list
);
461 ui_out_tuple_end (uiout
);
This page took 0.042189 seconds and 4 git commands to generate.