1 /* Handle set and show GDB commands.
3 Copyright 2000, 2001, 2002, 2003 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. */
21 #include <readline/tilde.h>
24 #include "gdb_string.h"
28 #include "cli/cli-decode.h"
29 #include "cli/cli-cmds.h"
30 #include "cli/cli-setshow.h"
32 /* Prototypes for local functions */
34 static int parse_binary_operation (char *);
37 static enum auto_boolean
38 parse_auto_binary_operation (const char *arg
)
40 if (arg
!= NULL
&& *arg
!= '\0')
42 int length
= strlen (arg
);
43 while (isspace (arg
[length
- 1]) && length
> 0)
45 if (strncmp (arg
, "on", length
) == 0
46 || strncmp (arg
, "1", length
) == 0
47 || strncmp (arg
, "yes", length
) == 0
48 || strncmp (arg
, "enable", length
) == 0)
49 return AUTO_BOOLEAN_TRUE
;
50 else if (strncmp (arg
, "off", length
) == 0
51 || strncmp (arg
, "0", length
) == 0
52 || strncmp (arg
, "no", length
) == 0
53 || strncmp (arg
, "disable", length
) == 0)
54 return AUTO_BOOLEAN_FALSE
;
55 else if (strncmp (arg
, "auto", length
) == 0
56 || (strncmp (arg
, "-1", length
) == 0 && length
> 1))
57 return AUTO_BOOLEAN_AUTO
;
59 error ("\"on\", \"off\" or \"auto\" expected.");
60 return AUTO_BOOLEAN_AUTO
; /* pacify GCC */
64 parse_binary_operation (char *arg
)
71 length
= strlen (arg
);
73 while (arg
[length
- 1] == ' ' || arg
[length
- 1] == '\t')
76 if (strncmp (arg
, "on", length
) == 0
77 || strncmp (arg
, "1", length
) == 0
78 || strncmp (arg
, "yes", length
) == 0
79 || strncmp (arg
, "enable", length
) == 0)
81 else if (strncmp (arg
, "off", length
) == 0
82 || strncmp (arg
, "0", length
) == 0
83 || strncmp (arg
, "no", length
) == 0
84 || strncmp (arg
, "disable", length
) == 0)
88 error ("\"on\" or \"off\" expected.");
93 /* Do a "set" or "show" command. ARG is NULL if no argument, or the text
94 of the argument, and FROM_TTY is nonzero if this command is being entered
95 directly by the user (i.e. these are just like any other
96 command). C is the command list element for the command. */
99 do_setshow_command (char *arg
, int from_tty
, struct cmd_list_element
*c
)
101 if (c
->type
== set_cmd
)
114 new = (char *) xmalloc (strlen (arg
) + 2);
117 while ((ch
= *p
++) != '\000')
121 /* \ at end of argument is used after spaces
122 so they won't be lost. */
123 /* This is obsolete now that we no longer strip
124 trailing whitespace and actually, the backslash
125 didn't get here in my test, readline or
126 something did something funky with a backslash
127 right before a newline. */
130 ch
= parse_escape (&p
);
140 if (*(p
- 1) != '\\')
144 new = (char *) xrealloc (new, q
- new);
145 if (*(char **) c
->var
!= NULL
)
146 xfree (*(char **) c
->var
);
147 *(char **) c
->var
= new;
150 case var_string_noescape
:
153 if (*(char **) c
->var
!= NULL
)
154 xfree (*(char **) c
->var
);
155 *(char **) c
->var
= savestring (arg
, strlen (arg
));
159 error_no_arg ("filename to set it to.");
160 if (*(char **) c
->var
!= NULL
)
161 xfree (*(char **) c
->var
);
162 *(char **) c
->var
= tilde_expand (arg
);
165 *(int *) c
->var
= parse_binary_operation (arg
);
167 case var_auto_boolean
:
168 *(enum auto_boolean
*) c
->var
= parse_auto_binary_operation (arg
);
172 error_no_arg ("integer to set it to.");
173 *(unsigned int *) c
->var
= parse_and_eval_long (arg
);
174 if (*(unsigned int *) c
->var
== 0)
175 *(unsigned int *) c
->var
= UINT_MAX
;
181 error_no_arg ("integer to set it to.");
182 val
= parse_and_eval_long (arg
);
184 *(int *) c
->var
= INT_MAX
;
185 else if (val
>= INT_MAX
)
186 error ("integer %u out of range", val
);
188 *(int *) c
->var
= val
;
193 error_no_arg ("integer to set it to.");
194 *(int *) c
->var
= parse_and_eval_long (arg
);
201 const char *match
= NULL
;
204 /* if no argument was supplied, print an informative error message */
208 strcpy (msg
, "Requires an argument. Valid arguments are ");
209 for (i
= 0; c
->enums
[i
]; i
++)
213 strcat (msg
, c
->enums
[i
]);
219 p
= strchr (arg
, ' ');
227 for (i
= 0; c
->enums
[i
]; i
++)
228 if (strncmp (arg
, c
->enums
[i
], len
) == 0)
230 if (c
->enums
[i
][len
] == '\0')
234 break; /* exact match. */
244 error ("Undefined item: \"%s\".", arg
);
247 error ("Ambiguous item \"%s\".", arg
);
249 *(const char **) c
->var
= match
;
253 error ("gdb internal error: bad var_type in do_setshow_command");
256 else if (c
->type
== show_cmd
)
258 struct cleanup
*old_chain
;
259 struct ui_stream
*stb
;
262 stb
= ui_out_stream_new (uiout
);
263 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
265 /* Possibly call the pre hook. */
266 if (c
->pre_show_hook
)
267 (c
->pre_show_hook
) (c
);
269 /* Print doc minus "show" at start. */
270 print_doc_line (gdb_stdout
, c
->doc
+ 5);
272 ui_out_text (uiout
, " is ");
273 ui_out_wrap_hint (uiout
, " ");
281 if (*(unsigned char **) c
->var
)
282 fputstr_filtered (*(unsigned char **) c
->var
, '"', stb
->stream
);
286 case var_string_noescape
:
289 if (*(char **) c
->var
)
290 fputs_filtered (*(char **) c
->var
, stb
->stream
);
294 fputs_filtered (*(int *) c
->var
? "on" : "off", stb
->stream
);
296 case var_auto_boolean
:
297 switch (*(enum auto_boolean
*) c
->var
)
299 case AUTO_BOOLEAN_TRUE
:
300 fputs_filtered ("on", stb
->stream
);
302 case AUTO_BOOLEAN_FALSE
:
303 fputs_filtered ("off", stb
->stream
);
305 case AUTO_BOOLEAN_AUTO
:
306 fputs_filtered ("auto", stb
->stream
);
309 internal_error (__FILE__
, __LINE__
,
310 "do_setshow_command: invalid var_auto_boolean");
315 if (*(unsigned int *) c
->var
== UINT_MAX
)
317 fputs_filtered ("unlimited", stb
->stream
);
320 /* else fall through */
322 fprintf_filtered (stb
->stream
, "%u", *(unsigned int *) c
->var
);
325 if (*(int *) c
->var
== INT_MAX
)
327 fputs_filtered ("unlimited", stb
->stream
);
330 fprintf_filtered (stb
->stream
, "%d", *(int *) c
->var
);
334 error ("gdb internal error: bad var_type in do_setshow_command");
337 ui_out_text (uiout
, "\"");
338 ui_out_field_stream (uiout
, "value", stb
);
340 ui_out_text (uiout
, "\"");
341 ui_out_text (uiout
, ".\n");
342 do_cleanups (old_chain
);
345 error ("gdb internal error: bad cmd_type in do_setshow_command");
346 c
->func (c
, NULL
, from_tty
);
347 if (c
->type
== set_cmd
&& set_hook
)
351 /* Show all the settings in a list of show commands. */
354 cmd_show_list (struct cmd_list_element
*list
, int from_tty
, char *prefix
)
356 struct cleanup
*showlist_chain
;
358 showlist_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "showlist");
359 for (; list
!= NULL
; list
= list
->next
)
361 /* If we find a prefix, run its list, prefixing our output by its
362 prefix (with "show " skipped). */
363 if (list
->prefixlist
&& !list
->abbrev_flag
)
365 struct cleanup
*optionlist_chain
366 = make_cleanup_ui_out_tuple_begin_end (uiout
, "optionlist");
367 ui_out_field_string (uiout
, "prefix", list
->prefixname
+ 5);
368 cmd_show_list (*list
->prefixlist
, from_tty
, list
->prefixname
+ 5);
369 /* Close the tuple. */
370 do_cleanups (optionlist_chain
);
372 if (list
->type
== show_cmd
)
374 struct cleanup
*option_chain
375 = make_cleanup_ui_out_tuple_begin_end (uiout
, "option");
376 ui_out_text (uiout
, prefix
);
377 ui_out_field_string (uiout
, "name", list
->name
);
378 ui_out_text (uiout
, ": ");
379 do_setshow_command ((char *) NULL
, from_tty
, list
);
380 /* Close the tuple. */
381 do_cleanups (option_chain
);
384 /* Close the tuple. */
385 do_cleanups (showlist_chain
);
This page took 0.037841 seconds and 4 git commands to generate.