1 /* Handle set and show GDB commands.
3 Copyright 2000, 2001, 2002 Free Software Foundation, Inc.
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
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
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.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
24 #include "gdb_string.h"
29 #include "cli/cli-decode.h"
30 #include "cli/cli-cmds.h"
31 #include "cli/cli-setshow.h"
33 /* Prototypes for local functions */
35 static int parse_binary_operation (char *);
38 static enum auto_boolean
39 parse_auto_binary_operation (const char *arg
)
41 if (arg
!= NULL
&& *arg
!= '\0')
43 int length
= strlen (arg
);
44 while (isspace (arg
[length
- 1]) && length
> 0)
46 if (strncmp (arg
, "on", length
) == 0
47 || strncmp (arg
, "1", length
) == 0
48 || strncmp (arg
, "yes", length
) == 0
49 || strncmp (arg
, "enable", length
) == 0)
50 return AUTO_BOOLEAN_TRUE
;
51 else if (strncmp (arg
, "off", length
) == 0
52 || strncmp (arg
, "0", length
) == 0
53 || strncmp (arg
, "no", length
) == 0
54 || strncmp (arg
, "disable", length
) == 0)
55 return AUTO_BOOLEAN_FALSE
;
56 else if (strncmp (arg
, "auto", length
) == 0
57 || (strncmp (arg
, "-1", length
) == 0 && length
> 1))
58 return AUTO_BOOLEAN_AUTO
;
60 error ("\"on\", \"off\" or \"auto\" expected.");
61 return AUTO_BOOLEAN_AUTO
; /* pacify GCC */
65 parse_binary_operation (char *arg
)
72 length
= strlen (arg
);
74 while (arg
[length
- 1] == ' ' || arg
[length
- 1] == '\t')
77 if (strncmp (arg
, "on", length
) == 0
78 || strncmp (arg
, "1", length
) == 0
79 || strncmp (arg
, "yes", length
) == 0
80 || strncmp (arg
, "enable", length
) == 0)
82 else if (strncmp (arg
, "off", length
) == 0
83 || strncmp (arg
, "0", length
) == 0
84 || strncmp (arg
, "no", length
) == 0
85 || strncmp (arg
, "disable", length
) == 0)
89 error ("\"on\" or \"off\" expected.");
94 /* Do a "set" or "show" command. ARG is NULL if no argument, or the text
95 of the argument, and FROM_TTY is nonzero if this command is being entered
96 directly by the user (i.e. these are just like any other
97 command). C is the command list element for the command. */
100 do_setshow_command (char *arg
, int from_tty
, struct cmd_list_element
*c
)
102 if (c
->type
== set_cmd
)
115 new = (char *) xmalloc (strlen (arg
) + 2);
118 while ((ch
= *p
++) != '\000')
122 /* \ at end of argument is used after spaces
123 so they won't be lost. */
124 /* This is obsolete now that we no longer strip
125 trailing whitespace and actually, the backslash
126 didn't get here in my test, readline or
127 something did something funky with a backslash
128 right before a newline. */
131 ch
= parse_escape (&p
);
141 if (*(p
- 1) != '\\')
145 new = (char *) xrealloc (new, q
- new);
146 if (*(char **) c
->var
!= NULL
)
147 xfree (*(char **) c
->var
);
148 *(char **) c
->var
= new;
151 case var_string_noescape
:
154 if (*(char **) c
->var
!= NULL
)
155 xfree (*(char **) c
->var
);
156 *(char **) c
->var
= savestring (arg
, strlen (arg
));
160 error_no_arg ("filename to set it to.");
161 if (*(char **) c
->var
!= NULL
)
162 xfree (*(char **) c
->var
);
163 *(char **) c
->var
= tilde_expand (arg
);
166 *(int *) c
->var
= parse_binary_operation (arg
);
168 case var_auto_boolean
:
169 *(enum auto_boolean
*) c
->var
= parse_auto_binary_operation (arg
);
173 error_no_arg ("integer to set it to.");
174 *(unsigned int *) c
->var
= parse_and_eval_long (arg
);
175 if (*(unsigned int *) c
->var
== 0)
176 *(unsigned int *) c
->var
= UINT_MAX
;
182 error_no_arg ("integer to set it to.");
183 val
= parse_and_eval_long (arg
);
185 *(int *) c
->var
= INT_MAX
;
186 else if (val
>= INT_MAX
)
187 error ("integer %u out of range", val
);
189 *(int *) c
->var
= val
;
194 error_no_arg ("integer to set it to.");
195 *(int *) c
->var
= parse_and_eval_long (arg
);
202 const char *match
= NULL
;
205 /* if no argument was supplied, print an informative error message */
209 strcpy (msg
, "Requires an argument. Valid arguments are ");
210 for (i
= 0; c
->enums
[i
]; i
++)
214 strcat (msg
, c
->enums
[i
]);
220 p
= strchr (arg
, ' ');
228 for (i
= 0; c
->enums
[i
]; i
++)
229 if (strncmp (arg
, c
->enums
[i
], len
) == 0)
231 if (c
->enums
[i
][len
] == '\0')
235 break; /* exact match. */
245 error ("Undefined item: \"%s\".", arg
);
248 error ("Ambiguous item \"%s\".", arg
);
250 *(const char **) c
->var
= match
;
254 error ("gdb internal error: bad var_type in do_setshow_command");
257 else if (c
->type
== show_cmd
)
259 struct cleanup
*old_chain
;
260 struct ui_stream
*stb
;
263 stb
= ui_out_stream_new (uiout
);
264 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
266 /* Possibly call the pre hook. */
267 if (c
->pre_show_hook
)
268 (c
->pre_show_hook
) (c
);
270 /* Print doc minus "show" at start. */
271 print_doc_line (gdb_stdout
, c
->doc
+ 5);
273 ui_out_text (uiout
, " is ");
274 ui_out_wrap_hint (uiout
, " ");
282 if (*(unsigned char **) c
->var
)
283 fputstr_filtered (*(unsigned char **) c
->var
, '"', stb
->stream
);
287 case var_string_noescape
:
290 if (*(char **) c
->var
)
291 fputs_filtered (*(char **) c
->var
, stb
->stream
);
295 fputs_filtered (*(int *) c
->var
? "on" : "off", stb
->stream
);
297 case var_auto_boolean
:
298 switch (*(enum auto_boolean
*) c
->var
)
300 case AUTO_BOOLEAN_TRUE
:
301 fputs_filtered ("on", stb
->stream
);
303 case AUTO_BOOLEAN_FALSE
:
304 fputs_filtered ("off", stb
->stream
);
306 case AUTO_BOOLEAN_AUTO
:
307 fputs_filtered ("auto", stb
->stream
);
310 internal_error (__FILE__
, __LINE__
,
311 "do_setshow_command: invalid var_auto_boolean");
316 if (*(unsigned int *) c
->var
== UINT_MAX
)
318 fputs_filtered ("unlimited", stb
->stream
);
321 /* else fall through */
323 fprintf_filtered (stb
->stream
, "%u", *(unsigned int *) c
->var
);
326 if (*(int *) c
->var
== INT_MAX
)
328 fputs_filtered ("unlimited", stb
->stream
);
331 fprintf_filtered (stb
->stream
, "%d", *(int *) c
->var
);
335 error ("gdb internal error: bad var_type in do_setshow_command");
338 ui_out_text (uiout
, "\"");
339 ui_out_field_stream (uiout
, "value", stb
);
341 ui_out_text (uiout
, "\"");
342 ui_out_text (uiout
, ".\n");
343 do_cleanups (old_chain
);
346 error ("gdb internal error: bad cmd_type in do_setshow_command");
347 c
->func (c
, NULL
, from_tty
);
348 if (c
->type
== set_cmd
&& set_hook
)
352 /* Show all the settings in a list of show commands. */
355 cmd_show_list (struct cmd_list_element
*list
, int from_tty
, char *prefix
)
357 ui_out_tuple_begin (uiout
, "showlist");
358 for (; list
!= NULL
; list
= list
->next
)
360 /* If we find a prefix, run its list, prefixing our output by its
361 prefix (with "show " skipped). */
362 if (list
->prefixlist
&& !list
->abbrev_flag
)
364 ui_out_tuple_begin (uiout
, "optionlist");
365 ui_out_field_string (uiout
, "prefix", list
->prefixname
+ 5);
366 cmd_show_list (*list
->prefixlist
, from_tty
, list
->prefixname
+ 5);
367 ui_out_tuple_end (uiout
);
369 if (list
->type
== show_cmd
)
371 ui_out_tuple_begin (uiout
, "option");
372 ui_out_text (uiout
, prefix
);
373 ui_out_field_string (uiout
, "name", list
->name
);
374 ui_out_text (uiout
, ": ");
375 do_setshow_command ((char *) NULL
, from_tty
, list
);
376 ui_out_tuple_end (uiout
);
379 ui_out_tuple_end (uiout
);
This page took 0.044509 seconds and 4 git commands to generate.