/* GDB commands implemented in Scheme.
- Copyright (C) 2008-2014 Free Software Foundation, Inc.
+ Copyright (C) 2008-2020 Free Software Foundation, Inc.
This file is part of GDB.
#include "defs.h"
#include <ctype.h>
-#include "exceptions.h"
#include "charset.h"
#include "gdbcmd.h"
#include "cli/cli-decode.h"
{ "COMPLETE_FILENAME", filename_completer },
{ "COMPLETE_LOCATION", location_completer },
{ "COMPLETE_COMMAND", command_completer },
- { "COMPLETE_SYMBOL", make_symbol_completion_list_fn },
+ { "COMPLETE_SYMBOL", symbol_completer },
{ "COMPLETE_EXPRESSION", expression_completer },
};
static SCM
gdbscm_dont_repeat (SCM self)
{
- /* We currently don't need anything from SELF, but still verify it. */
- command_smob *c_smob
- = cmdscm_get_valid_command_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
+ /* We currently don't need anything from SELF, but still verify it.
+ Call for side effects. */
+ cmdscm_get_valid_command_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
dont_repeat ();
command_smob *c_smob = (command_smob *) context;
cmdscm_release_command (c_smob);
-
- /* We allocated the name, doc string, and perhaps the prefix name. */
- xfree ((char *) self->name);
- xfree ((char *) self->doc);
- xfree ((char *) self->prefixname);
}
/* Called by gdb to invoke the command. */
static void
-cmdscm_function (struct cmd_list_element *command, char *args, int from_tty)
+cmdscm_function (struct cmd_list_element *command,
+ const char *args, int from_tty)
{
command_smob *c_smob/*obj*/ = (command_smob *) get_cmd_context (command);
SCM arg_scm, tty_scm, result;
itself. */
if (gdbscm_user_error_p (gdbscm_exception_key (result)))
{
- char *msg = gdbscm_exception_message_to_string (result);
+ gdb::unique_xmalloc_ptr<char> msg
+ = gdbscm_exception_message_to_string (result);
- make_cleanup (xfree, msg);
- error ("%s", msg);
+ error ("%s", msg.get ());
}
else
{
The result is a boolean indicating success. */
static int
-cmdscm_add_completion (SCM completion, VEC (char_ptr) **result)
+cmdscm_add_completion (SCM completion, completion_tracker &tracker)
{
- char *item;
SCM except_scm;
if (!scm_is_string (completion))
return 0;
}
- item = gdbscm_scm_to_string (completion, NULL, host_charset (), 1,
- &except_scm);
+ gdb::unique_xmalloc_ptr<char> item
+ = gdbscm_scm_to_string (completion, NULL, host_charset (), 1,
+ &except_scm);
if (item == NULL)
{
/* Inform the user, but otherwise ignore the entire result. */
return 0;
}
- VEC_safe_push (char_ptr, *result, item);
+ tracker.add_completion (std::move (item));
return 1;
}
/* Called by gdb for command completion. */
-static VEC (char_ptr) *
+static void
cmdscm_completer (struct cmd_list_element *command,
+ completion_tracker &tracker,
const char *text, const char *word)
{
command_smob *c_smob/*obj*/ = (command_smob *) get_cmd_context (command);
SCM completer_result_scm;
- SCM text_scm, word_scm, result_scm;
- VEC (char_ptr) *result = NULL;
+ SCM text_scm, word_scm;
gdb_assert (c_smob != NULL);
gdb_assert (gdbscm_is_procedure (c_smob->complete));
{
/* Inform the user, but otherwise ignore. */
gdbscm_print_gdb_exception (SCM_BOOL_F, completer_result_scm);
- goto done;
+ return;
}
if (gdbscm_is_true (scm_list_p (completer_result_scm)))
{
SCM next = scm_car (list);
- if (!cmdscm_add_completion (next, &result))
- {
- VEC_free (char_ptr, result);
- goto done;
- }
+ if (!cmdscm_add_completion (next, tracker))
+ break;
list = scm_cdr (list);
}
{
if (gdbscm_is_exception (next))
{
- /* Inform the user, but otherwise ignore the entire result. */
+ /* Inform the user. */
gdbscm_print_gdb_exception (SCM_BOOL_F, completer_result_scm);
- VEC_free (char_ptr, result);
- goto done;
+ break;
}
- if (!cmdscm_add_completion (next, &result))
- {
- VEC_free (char_ptr, result);
- goto done;
- }
+ if (cmdscm_add_completion (next, tracker))
+ break;
next = itscm_safe_call_next_x (iter, NULL);
}
cmdscm_bad_completion_result (_("Bad completer result: "),
completer_result_scm);
}
-
- done:
- return result;
}
/* Helper for gdbscm_make_command which locates the command list to use and
lastchar = i;
/* Find first character of the final word. */
- for (; i > 0 && (isalnum (name[i - 1])
- || name[i - 1] == '-'
- || name[i - 1] == '_');
- --i)
+ for (; i > 0 && valid_cmd_char_p (name[i - 1]); --i)
;
- result = xmalloc (lastchar - i + 2);
+ result = (char *) xmalloc (lastchar - i + 2);
memcpy (result, &name[i], lastchar - i + 1);
result[lastchar - i + 1] = '\0';
return result;
}
- prefix_text = xmalloc (i + 2);
+ prefix_text = (char *) xmalloc (i + 2);
memcpy (prefix_text, name, i + 1);
prefix_text[i + 1] = '\0';
prefix_text2 = prefix_text;
- elt = lookup_cmd_1 (&prefix_text2, *start_list, NULL, 1);
- if (!elt || elt == (struct cmd_list_element *) -1)
+ elt = lookup_cmd_1 (&prefix_text2, *start_list, NULL, NULL, 1);
+ if (elt == NULL || elt == CMD_LIST_AMBIGUOUS)
{
msg = xstrprintf (_("could not find command prefix '%s'"), prefix_text);
xfree (prefix_text);
xfree (result);
- scm_dynwind_begin (0);
+ scm_dynwind_begin ((scm_t_dynwind_flags) 0);
gdbscm_dynwind_xfree (msg);
gdbscm_out_of_range_error (func_name, arg_pos,
gdbscm_scm_from_c_string (name), msg);
msg = xstrprintf (_("'%s' is not a prefix command"), prefix_text);
xfree (prefix_text);
xfree (result);
- scm_dynwind_begin (0);
+ scm_dynwind_begin ((scm_t_dynwind_flags) 0);
gdbscm_dynwind_xfree (msg);
gdbscm_out_of_range_error (func_name, arg_pos,
gdbscm_scm_from_c_string (name), msg);
static const scheme_integer_constant command_classes[] =
{
/* Note: alias and user are special; pseudo appears to be unused,
- and there is no reason to expose tui or xdb, I think. */
+ and there is no reason to expose tui, I think. */
{ "COMMAND_NONE", no_class },
{ "COMMAND_RUNNING", class_run },
{ "COMMAND_DATA", class_vars },
gdbscm_canonicalize_command_name (const char *name, int want_trailing_space)
{
int i, out, seen_word;
- char *result = scm_gc_malloc_pointerless (strlen (name) + 2, FUNC_NAME);
+ char *result
+ = (char *) scm_gc_malloc_pointerless (strlen (name) + 2, FUNC_NAME);
i = out = seen_word = 0;
while (name[i])
One of the COMPLETE_* constants defined in the gdb module.
A procedure of three arguments: (lambda (self text word) ...).
Its result is one of:
- A list of strings.
- A <gdb:iterator> object that returns the set of possible completions,
- ending with #f.
+ A list of strings.
+ A <gdb:iterator> object that returns the set of possible completions,
+ ending with #f.
TODO(dje): Once PR 16699 is fixed, add support for returning
a COMPLETE_* constant.
If not specified, then completion is not supported for this command.
int doc_arg_pos = -1;
char *s;
char *name;
- int command_class = no_class;
+ enum command_class command_class = no_class;
SCM completer_class = SCM_BOOL_F;
int is_prefix = 0;
char *doc = NULL;
{
command_smob *c_smob
= cmdscm_get_command_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
- char *cmd_name, *pfx_name;
+ char *cmd_name;
struct cmd_list_element **cmd_list;
struct cmd_list_element *cmd = NULL;
- volatile struct gdb_exception except;
if (cmdscm_is_valid (c_smob))
scm_misc_error (FUNC_NAME, _("command is already registered"), SCM_EOL);
c_smob->cmd_name = gdbscm_gc_xstrdup (cmd_name);
xfree (cmd_name);
- TRY_CATCH (except, RETURN_MASK_ALL)
+ gdbscm_gdb_exception exc {};
+ try
{
if (c_smob->is_prefix)
{
else
{
cmd = add_cmd (c_smob->cmd_name, c_smob->cmd_class,
- NULL, c_smob->doc, cmd_list);
+ c_smob->doc, cmd_list);
}
}
- GDBSCM_HANDLE_GDB_EXCEPTION (except);
+ catch (const gdb_exception &except)
+ {
+ exc = unpack (except);
+ }
+ GDBSCM_HANDLE_GDB_EXCEPTION (exc);
/* Note: At this point the command exists in gdb.
So no more errors after this point. */
static const scheme_function command_functions[] =
{
- { "make-command", 1, 0, 1, gdbscm_make_command,
+ { "make-command", 1, 0, 1, as_a_scm_t_subr (gdbscm_make_command),
"\
Make a GDB command object.\n\
\n\
doc: The \"doc string\" of the command.\n\
Returns: <gdb:command> object" },
- { "register-command!", 1, 0, 0, gdbscm_register_command_x,
+ { "register-command!", 1, 0, 0, as_a_scm_t_subr (gdbscm_register_command_x),
"\
Register a <gdb:command> object with GDB." },
- { "command?", 1, 0, 0, gdbscm_command_p,
+ { "command?", 1, 0, 0, as_a_scm_t_subr (gdbscm_command_p),
"\
Return #t if the object is a <gdb:command> object." },
- { "command-valid?", 1, 0, 0, gdbscm_command_valid_p,
+ { "command-valid?", 1, 0, 0, as_a_scm_t_subr (gdbscm_command_valid_p),
"\
Return #t if the <gdb:command> object is valid." },
- { "dont-repeat", 1, 0, 0, gdbscm_dont_repeat,
+ { "dont-repeat", 1, 0, 0, as_a_scm_t_subr (gdbscm_dont_repeat),
"\
Prevent command repetition when user enters an empty line.\n\
\n\