1 /* Handle set and show GDB commands.
3 Copyright (c) 2000-2003, 2007-2012 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 3 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, see <http://www.gnu.org/licenses/>. */
19 #include "readline/tilde.h"
22 #include "gdb_string.h"
23 #include "arch-utils.h"
27 #include "cli/cli-decode.h"
28 #include "cli/cli-cmds.h"
29 #include "cli/cli-setshow.h"
31 /* Prototypes for local functions. */
33 static int parse_binary_operation (char *);
36 static enum auto_boolean
37 parse_auto_binary_operation (const char *arg
)
39 if (arg
!= NULL
&& *arg
!= '\0')
41 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."));
94 deprecated_show_value_hack (struct ui_file
*ignore_file
,
96 struct cmd_list_element
*c
,
99 /* If there's no command or value, don't try to print it out. */
100 if (c
== NULL
|| value
== NULL
)
102 /* Print doc minus "show" at start. */
103 print_doc_line (gdb_stdout
, c
->doc
+ 5);
107 case var_string_noescape
:
108 case var_optional_filename
:
111 printf_filtered ((" is \"%s\".\n"), value
);
114 printf_filtered ((" is %s.\n"), value
);
119 /* Do a "set" or "show" command. ARG is NULL if no argument, or the
120 text of the argument, and FROM_TTY is nonzero if this command is
121 being entered directly by the user (i.e. these are just like any
122 other command). C is the command list element for the command. */
125 do_setshow_command (char *arg
, int from_tty
, struct cmd_list_element
*c
)
127 struct ui_out
*uiout
= current_uiout
;
129 if (c
->type
== set_cmd
)
142 new = (char *) xmalloc (strlen (arg
) + 2);
145 while ((ch
= *p
++) != '\000')
149 /* \ at end of argument is used after spaces
150 so they won't be lost. */
151 /* This is obsolete now that we no longer strip
152 trailing whitespace and actually, the backslash
153 didn't get here in my test, readline or
154 something did something funky with a backslash
155 right before a newline. */
158 ch
= parse_escape (get_current_arch (), &p
);
168 if (*(p
- 1) != '\\')
172 new = (char *) xrealloc (new, q
- new);
173 xfree (*(char **) c
->var
);
174 *(char **) c
->var
= new;
177 case var_string_noescape
:
180 xfree (*(char **) c
->var
);
181 *(char **) c
->var
= xstrdup (arg
);
185 error_no_arg (_("filename to set it to."));
187 case var_optional_filename
:
188 xfree (*(char **) c
->var
);
192 /* Clear trailing whitespace of filename. */
193 char *ptr
= arg
+ strlen (arg
) - 1;
195 while (ptr
>= arg
&& (*ptr
== ' ' || *ptr
== '\t'))
199 *(char **) c
->var
= tilde_expand (arg
);
202 *(char **) c
->var
= xstrdup ("");
205 *(int *) c
->var
= parse_binary_operation (arg
);
207 case var_auto_boolean
:
208 *(enum auto_boolean
*) c
->var
= parse_auto_binary_operation (arg
);
213 error_no_arg (_("integer to set it to."));
214 *(unsigned int *) c
->var
= parse_and_eval_long (arg
);
215 if (c
->var_type
== var_uinteger
&& *(unsigned int *) c
->var
== 0)
216 *(unsigned int *) c
->var
= UINT_MAX
;
224 error_no_arg (_("integer to set it to."));
225 val
= parse_and_eval_long (arg
);
226 if (val
== 0 && c
->var_type
== var_integer
)
227 *(int *) c
->var
= INT_MAX
;
228 else if (val
>= INT_MAX
)
229 error (_("integer %u out of range"), val
);
231 *(int *) c
->var
= val
;
239 const char *match
= NULL
;
242 /* If no argument was supplied, print an informative error
249 for (i
= 0; c
->enums
[i
]; i
++)
250 msg_len
+= strlen (c
->enums
[i
]) + 2;
252 msg
= xmalloc (msg_len
);
254 make_cleanup (xfree
, msg
);
256 for (i
= 0; c
->enums
[i
]; i
++)
260 strcat (msg
, c
->enums
[i
]);
262 error (_("Requires an argument. Valid arguments are %s."),
266 p
= strchr (arg
, ' ');
274 for (i
= 0; c
->enums
[i
]; i
++)
275 if (strncmp (arg
, c
->enums
[i
], len
) == 0)
277 if (c
->enums
[i
][len
] == '\0')
281 break; /* Exact match. */
291 error (_("Undefined item: \"%s\"."), arg
);
294 error (_("Ambiguous item \"%s\"."), arg
);
296 *(const char **) c
->var
= match
;
300 error (_("gdb internal error: bad var_type in do_setshow_command"));
303 else if (c
->type
== show_cmd
)
305 struct cleanup
*old_chain
;
308 stb
= mem_fileopen ();
309 old_chain
= make_cleanup_ui_file_delete (stb
);
311 /* Possibly call the pre hook. */
312 if (c
->pre_show_hook
)
313 (c
->pre_show_hook
) (c
);
318 if (*(char **) c
->var
)
319 fputstr_filtered (*(char **) c
->var
, '"', stb
);
321 case var_string_noescape
:
322 case var_optional_filename
:
325 if (*(char **) c
->var
)
326 fputs_filtered (*(char **) c
->var
, stb
);
329 fputs_filtered (*(int *) c
->var
? "on" : "off", stb
);
331 case var_auto_boolean
:
332 switch (*(enum auto_boolean
*) c
->var
)
334 case AUTO_BOOLEAN_TRUE
:
335 fputs_filtered ("on", stb
);
337 case AUTO_BOOLEAN_FALSE
:
338 fputs_filtered ("off", stb
);
340 case AUTO_BOOLEAN_AUTO
:
341 fputs_filtered ("auto", stb
);
344 internal_error (__FILE__
, __LINE__
,
345 _("do_setshow_command: "
346 "invalid var_auto_boolean"));
352 if (c
->var_type
== var_uinteger
353 && *(unsigned int *) c
->var
== UINT_MAX
)
354 fputs_filtered ("unlimited", stb
);
356 fprintf_filtered (stb
, "%u", *(unsigned int *) c
->var
);
360 if (c
->var_type
== var_integer
361 && *(int *) c
->var
== INT_MAX
)
362 fputs_filtered ("unlimited", stb
);
364 fprintf_filtered (stb
, "%d", *(int *) c
->var
);
368 error (_("gdb internal error: bad var_type in do_setshow_command"));
372 /* FIXME: cagney/2005-02-10: Need to split this in half: code to
373 convert the value into a string (esentially the above); and
374 code to print the value out. For the latter there should be
375 MI and CLI specific versions. */
377 if (ui_out_is_mi_like_p (uiout
))
378 ui_out_field_stream (uiout
, "value", stb
);
381 char *value
= ui_file_xstrdup (stb
, NULL
);
383 make_cleanup (xfree
, value
);
384 if (c
->show_value_func
!= NULL
)
385 c
->show_value_func (gdb_stdout
, from_tty
, c
, value
);
387 deprecated_show_value_hack (gdb_stdout
, from_tty
, c
, value
);
389 do_cleanups (old_chain
);
392 error (_("gdb internal error: bad cmd_type in do_setshow_command"));
393 c
->func (c
, NULL
, from_tty
);
394 if (c
->type
== set_cmd
&& deprecated_set_hook
)
395 deprecated_set_hook (c
);
398 /* Show all the settings in a list of show commands. */
401 cmd_show_list (struct cmd_list_element
*list
, int from_tty
, char *prefix
)
403 struct cleanup
*showlist_chain
;
404 struct ui_out
*uiout
= current_uiout
;
406 showlist_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "showlist");
407 for (; list
!= NULL
; list
= list
->next
)
409 /* If we find a prefix, run its list, prefixing our output by its
410 prefix (with "show " skipped). */
411 if (list
->prefixlist
&& !list
->abbrev_flag
)
413 struct cleanup
*optionlist_chain
414 = make_cleanup_ui_out_tuple_begin_end (uiout
, "optionlist");
415 char *new_prefix
= strstr (list
->prefixname
, "show ") + 5;
417 if (ui_out_is_mi_like_p (uiout
))
418 ui_out_field_string (uiout
, "prefix", new_prefix
);
419 cmd_show_list (*list
->prefixlist
, from_tty
, new_prefix
);
420 /* Close the tuple. */
421 do_cleanups (optionlist_chain
);
425 if (list
->class != no_set_class
)
427 struct cleanup
*option_chain
428 = make_cleanup_ui_out_tuple_begin_end (uiout
, "option");
430 ui_out_text (uiout
, prefix
);
431 ui_out_field_string (uiout
, "name", list
->name
);
432 ui_out_text (uiout
, ": ");
433 if (list
->type
== show_cmd
)
434 do_setshow_command ((char *) NULL
, from_tty
, list
);
436 cmd_func (list
, NULL
, from_tty
);
437 /* Close the tuple. */
438 do_cleanups (option_chain
);
442 /* Close the tuple. */
443 do_cleanups (showlist_chain
);
This page took 0.050885 seconds and 5 git commands to generate.