1 /* Handle set and show GDB commands.
3 Copyright (c) 2000, 2001, 2002, 2003, 2007, 2008, 2009, 2010, 2011
4 Free Software Foundation, Inc.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #include "readline/tilde.h"
23 #include "gdb_string.h"
24 #include "arch-utils.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
);
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."));
95 deprecated_show_value_hack (struct ui_file
*ignore_file
,
97 struct cmd_list_element
*c
,
100 /* If there's no command or value, don't try to print it out. */
101 if (c
== NULL
|| value
== NULL
)
103 /* Print doc minus "show" at start. */
104 print_doc_line (gdb_stdout
, c
->doc
+ 5);
108 case var_string_noescape
:
109 case var_optional_filename
:
112 printf_filtered ((" is \"%s\".\n"), value
);
115 printf_filtered ((" is %s.\n"), value
);
120 /* Do a "set" or "show" command. ARG is NULL if no argument, or the
121 text of the argument, and FROM_TTY is nonzero if this command is
122 being entered directly by the user (i.e. these are just like any
123 other command). C is the command list element for the command. */
126 do_setshow_command (char *arg
, int from_tty
, struct cmd_list_element
*c
)
128 if (c
->type
== set_cmd
)
141 new = (char *) xmalloc (strlen (arg
) + 2);
144 while ((ch
= *p
++) != '\000')
148 /* \ at end of argument is used after spaces
149 so they won't be lost. */
150 /* This is obsolete now that we no longer strip
151 trailing whitespace and actually, the backslash
152 didn't get here in my test, readline or
153 something did something funky with a backslash
154 right before a newline. */
157 ch
= parse_escape (get_current_arch (), &p
);
167 if (*(p
- 1) != '\\')
171 new = (char *) xrealloc (new, q
- new);
172 if (*(char **) c
->var
!= NULL
)
173 xfree (*(char **) c
->var
);
174 *(char **) c
->var
= new;
177 case var_string_noescape
:
180 if (*(char **) c
->var
!= NULL
)
181 xfree (*(char **) c
->var
);
182 *(char **) c
->var
= xstrdup (arg
);
184 case var_optional_filename
:
187 if (*(char **) c
->var
!= NULL
)
188 xfree (*(char **) c
->var
);
189 *(char **) c
->var
= xstrdup (arg
);
193 error_no_arg (_("filename to set it to."));
194 if (*(char **) c
->var
!= NULL
)
195 xfree (*(char **) c
->var
);
197 /* Clear trailing whitespace of filename. */
198 char *ptr
= arg
+ strlen (arg
) - 1;
200 while (ptr
>= arg
&& (*ptr
== ' ' || *ptr
== '\t'))
204 *(char **) c
->var
= tilde_expand (arg
);
207 *(int *) c
->var
= parse_binary_operation (arg
);
209 case var_auto_boolean
:
210 *(enum auto_boolean
*) c
->var
= parse_auto_binary_operation (arg
);
214 error_no_arg (_("integer to set it to."));
215 *(unsigned int *) c
->var
= parse_and_eval_long (arg
);
216 if (*(unsigned int *) c
->var
== 0)
217 *(unsigned int *) c
->var
= UINT_MAX
;
224 error_no_arg (_("integer to set it to."));
225 val
= parse_and_eval_long (arg
);
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
;
236 error_no_arg (_("integer to set it to."));
237 *(int *) c
->var
= parse_and_eval_long (arg
);
241 error_no_arg (_("integer to set it to."));
242 *(unsigned int *) c
->var
= parse_and_eval_long (arg
);
249 const char *match
= NULL
;
252 /* If no argument was supplied, print an informative error
259 for (i
= 0; c
->enums
[i
]; i
++)
260 msg_len
+= strlen (c
->enums
[i
]) + 2;
262 msg
= xmalloc (msg_len
);
264 make_cleanup (xfree
, msg
);
266 for (i
= 0; c
->enums
[i
]; i
++)
270 strcat (msg
, c
->enums
[i
]);
272 error (_("Requires an argument. Valid arguments are %s."),
276 p
= strchr (arg
, ' ');
284 for (i
= 0; c
->enums
[i
]; i
++)
285 if (strncmp (arg
, c
->enums
[i
], len
) == 0)
287 if (c
->enums
[i
][len
] == '\0')
291 break; /* Exact match. */
301 error (_("Undefined item: \"%s\"."), arg
);
304 error (_("Ambiguous item \"%s\"."), arg
);
306 *(const char **) c
->var
= match
;
310 error (_("gdb internal error: bad var_type in do_setshow_command"));
313 else if (c
->type
== show_cmd
)
315 struct cleanup
*old_chain
;
316 struct ui_stream
*stb
;
318 stb
= ui_out_stream_new (uiout
);
319 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
321 /* Possibly call the pre hook. */
322 if (c
->pre_show_hook
)
323 (c
->pre_show_hook
) (c
);
328 if (*(char **) c
->var
)
329 fputstr_filtered (*(char **) c
->var
, '"', stb
->stream
);
331 case var_string_noescape
:
332 case var_optional_filename
:
335 if (*(char **) c
->var
)
336 fputs_filtered (*(char **) c
->var
, stb
->stream
);
339 fputs_filtered (*(int *) c
->var
? "on" : "off", stb
->stream
);
341 case var_auto_boolean
:
342 switch (*(enum auto_boolean
*) c
->var
)
344 case AUTO_BOOLEAN_TRUE
:
345 fputs_filtered ("on", stb
->stream
);
347 case AUTO_BOOLEAN_FALSE
:
348 fputs_filtered ("off", stb
->stream
);
350 case AUTO_BOOLEAN_AUTO
:
351 fputs_filtered ("auto", stb
->stream
);
354 internal_error (__FILE__
, __LINE__
,
355 _("do_setshow_command: "
356 "invalid var_auto_boolean"));
362 if (c
->var_type
== var_uinteger
363 && *(unsigned int *) c
->var
== UINT_MAX
)
364 fputs_filtered ("unlimited", stb
->stream
);
366 fprintf_filtered (stb
->stream
, "%u", *(unsigned int *) c
->var
);
370 if (c
->var_type
== var_integer
371 && *(int *) c
->var
== INT_MAX
)
372 fputs_filtered ("unlimited", stb
->stream
);
374 fprintf_filtered (stb
->stream
, "%d", *(int *) c
->var
);
378 error (_("gdb internal error: bad var_type in do_setshow_command"));
382 /* FIXME: cagney/2005-02-10: Need to split this in half: code to
383 convert the value into a string (esentially the above); and
384 code to print the value out. For the latter there should be
385 MI and CLI specific versions. */
387 if (ui_out_is_mi_like_p (uiout
))
388 ui_out_field_stream (uiout
, "value", stb
);
391 char *value
= ui_file_xstrdup (stb
->stream
, NULL
);
393 make_cleanup (xfree
, value
);
394 if (c
->show_value_func
!= NULL
)
395 c
->show_value_func (gdb_stdout
, from_tty
, c
, value
);
397 deprecated_show_value_hack (gdb_stdout
, from_tty
, c
, value
);
399 do_cleanups (old_chain
);
402 error (_("gdb internal error: bad cmd_type in do_setshow_command"));
403 c
->func (c
, NULL
, from_tty
);
404 if (c
->type
== set_cmd
&& deprecated_set_hook
)
405 deprecated_set_hook (c
);
408 /* Show all the settings in a list of show commands. */
411 cmd_show_list (struct cmd_list_element
*list
, int from_tty
, char *prefix
)
413 struct cleanup
*showlist_chain
;
415 showlist_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "showlist");
416 for (; list
!= NULL
; list
= list
->next
)
418 /* If we find a prefix, run its list, prefixing our output by its
419 prefix (with "show " skipped). */
420 if (list
->prefixlist
&& !list
->abbrev_flag
)
422 struct cleanup
*optionlist_chain
423 = make_cleanup_ui_out_tuple_begin_end (uiout
, "optionlist");
424 char *new_prefix
= strstr (list
->prefixname
, "show ") + 5;
426 if (ui_out_is_mi_like_p (uiout
))
427 ui_out_field_string (uiout
, "prefix", new_prefix
);
428 cmd_show_list (*list
->prefixlist
, from_tty
, new_prefix
);
429 /* Close the tuple. */
430 do_cleanups (optionlist_chain
);
434 if (list
->class != no_set_class
)
436 struct cleanup
*option_chain
437 = make_cleanup_ui_out_tuple_begin_end (uiout
, "option");
439 ui_out_text (uiout
, prefix
);
440 ui_out_field_string (uiout
, "name", list
->name
);
441 ui_out_text (uiout
, ": ");
442 if (list
->type
== show_cmd
)
443 do_setshow_command ((char *) NULL
, from_tty
, list
);
445 cmd_func (list
, NULL
, from_tty
);
446 /* Close the tuple. */
447 do_cleanups (option_chain
);
451 /* Close the tuple. */
452 do_cleanups (showlist_chain
);
This page took 0.043699 seconds and 5 git commands to generate.