121 #define N_COMPLETERS (sizeof (cmdscm_completers) \ 122 / sizeof (cmdscm_completers[0])) 138 c_smob->
name != NULL ? c_smob->
name :
"{unnamed}");
141 scm_puts (
" {invalid}", port);
143 scm_puts (
">", port);
145 scm_remember_upto_here_1 (
self);
162 memset (c_smob, 0,
sizeof (*c_smob));
164 c_smob->
invoke = SCM_BOOL_F;
167 c_smob->containing_scm = c_scm;
215 const char *func_name)
228 return c_smob->
command != NULL;
236 const char *func_name)
276 return SCM_UNSPECIFIED;
295 const char *args,
int from_tty)
298 SCM arg_scm, tty_scm, result;
306 error (
_(
"Could not convert arguments to Scheme string."));
308 tty_scm = scm_from_bool (from_tty);
327 error (
_(
"Error occurred in Scheme-implemented GDB command."));
339 SCM port = scm_current_error_port ();
341 scm_puts (msg, port);
342 scm_display (completion, port);
356 if (!scm_is_string (completion))
384 const char *text,
const char *word)
387 SCM completer_result_scm;
388 SCM text_scm, word_scm;
396 error (
_(
"Could not convert \"text\" argument to Scheme string."));
400 error (
_(
"Could not convert \"word\" argument to Scheme string."));
404 text_scm, word_scm, NULL);
415 SCM list = completer_result_scm;
417 while (!scm_is_eq (list, SCM_EOL))
419 SCM next = scm_car (list);
424 list = scm_cdr (list);
429 SCM iter = completer_result_scm;
451 completer_result_scm);
472 const char *func_name,
int arg_pos,
477 int len = strlen (
name);
480 const char *prefix_text2;
484 for (i = len - 1; i >= 0 && (
name[i] ==
' ' ||
name[i] ==
'\t'); --i)
490 _(
"no command name found"));
495 for (; i > 0 && (isalnum (
name[i - 1])
496 ||
name[i - 1] ==
'-' 497 ||
name[i - 1] ==
'_');
500 result = (
char *)
xmalloc (lastchar - i + 2);
501 memcpy (result, &
name[i], lastchar - i + 1);
502 result[lastchar - i + 1] =
'\0';
505 for (--i; i >= 0 && (
name[i] ==
' ' ||
name[i] ==
'\t'); --i)
509 *base_list = start_list;
513 prefix_text = (
char *)
xmalloc (i + 2);
514 memcpy (prefix_text,
name, i + 1);
515 prefix_text[i + 1] =
'\0';
517 prefix_text2 = prefix_text;
518 elt =
lookup_cmd_1 (&prefix_text2, *start_list, NULL, 1);
521 msg =
xstrprintf (
_(
"could not find command prefix '%s'"), prefix_text);
524 scm_dynwind_begin ((scm_t_dynwind_flags) 0);
537 msg =
xstrprintf (
_(
"'%s' is not a prefix command"), prefix_text);
540 scm_dynwind_begin ((scm_t_dynwind_flags) 0);
594 int i, out, seen_word;
596 = (
char *) scm_gc_malloc_pointerless (strlen (
name) + 2,
FUNC_NAME);
598 i = out = seen_word = 0;
602 while (
name[i] ==
' ' ||
name[i] ==
'\t')
610 result[out++] =
name[i++];
614 if (want_trailing_space)
659 const SCM keywords[] = {
663 int invoke_arg_pos = -1, command_class_arg_pos = 1;
664 int completer_class_arg_pos = -1, is_prefix_arg_pos = -1;
665 int doc_arg_pos = -1;
669 SCM completer_class = SCM_BOOL_F;
672 SCM invoke = SCM_BOOL_F;
677 name_scm, &
name, rest,
678 &invoke_arg_pos, &invoke,
680 &completer_class_arg_pos, &completer_class,
681 &is_prefix_arg_pos, &is_prefix,
685 doc = xstrdup (
_(
"This command is not documented."));
699 _(
"no command name found"));
712 _(
"invalid command class argument"));
716 || scm_is_integer (completer_class)
718 completer_class, completer_class_arg_pos,
FUNC_NAME,
719 _(
"integer or procedure"));
720 if (scm_is_integer (completer_class)
721 && !scm_is_signed_integer (completer_class, 0,
N_COMPLETERS - 1))
725 _(
"invalid completion type argument"));
754 scm_misc_error (
FUNC_NAME,
_(
"command is already registered"), SCM_EOL);
776 c_smob->
doc, cmd_list);
807 return SCM_UNSPECIFIED;
816 Make a GDB command object.\n\ 818 Arguments: name [#:invoke lambda]\n\ 819 [#:command-class <class>] [#:completer-class <completer>]\n\ 820 [#:prefix? <bool>] [#:doc string]\n\ 821 name: The name of the command. It may consist of multiple words,\n\ 822 in which case the final word is the name of the new command, and\n\ 823 earlier words must be prefix commands.\n\ 824 invoke: A procedure of three arguments to perform the command.\n\ 825 (lambda (self arg from-tty) ...)\n\ 826 Its result is unspecified.\n\ 827 class: The class of the command, one of COMMAND_*.\n\ 828 The default is COMMAND_NONE.\n\ 829 completer: The kind of completer, #f, one of COMPLETE_*, or a procedure\n\ 830 to perform the completion: (lambda (self text word) ...).\n\ 831 prefix?: If true then the command is a prefix command.\n\ 832 doc: The \"doc string\" of the command.\n\ 833 Returns: <gdb:command> object" },
837 Register a <gdb:command> object with GDB." },
841 Return #t if the object is a <gdb:command> object." },
845 Return #t if the <gdb:command> object is valid." },
849 Prevent command repetition when user enters an empty line.\n\ 851 Arguments: <gdb:command>\n\ 852 Returns: unspecified" },
void set_cmd_context(struct cmd_list_element *cmd, void *context)
static scm_t_subr as_a_scm_t_subr(SCM(*func)(void))
static const char command_smob_name[]
static void cmdscm_completer(struct cmd_list_element *command, completion_tracker &tracker, const char *text, const char *word)
static SCM scm_new_smob(scm_t_bits tc, scm_t_bits data)
static int cmdscm_is_valid(command_smob *)
void * get_cmd_context(struct cmd_list_element *cmd)
void gdbscm_define_functions(const scheme_function *, int is_public)
static void cmdscm_function(struct cmd_list_element *command, const char *args, int from_tty)
static SCM gdbscm_make_command(SCM name_scm, SCM rest)
static int cmdscm_print_command_smob(SCM self, SCM port, scm_print_state *pstate)
static command_smob * cmdscm_get_command_smob_arg_unsafe(SCM self, int arg_pos, const char *func_name)
static const scheme_integer_constant command_classes[]
SCM gdbscm_safe_call_3(SCM proc, SCM arg0, SCM arg1, SCM arg2, excp_matcher_func *ok_excps)
static SCM gdbscm_command_p(SCM scm)
static void cmdscm_destroyer(struct cmd_list_element *self, void *context)
unsigned int allow_unknown
static command_smob * cmdscm_get_valid_command_smob_arg_unsafe(SCM self, int arg_pos, const char *func_name)
void * memset(T *s, int c, size_t n)=delete
char * gdbscm_parse_command_name(const char *name, const char *func_name, int arg_pos, struct cmd_list_element ***base_list, struct cmd_list_element **start_list)
struct cmd_list_element * add_cmd(const char *name, enum command_class theclass, const char *doc, struct cmd_list_element **list)
static void cmdscm_bad_completion_result(const char *msg, SCM completion)
struct cmd_list_element * lookup_cmd_1(const char **text, struct cmd_list_element *clist, struct cmd_list_element **result_list, int ignore_help_classes)
static int cmdscm_add_completion(SCM completion, completion_tracker &tracker)
scm_t_bits gdbscm_make_smob_type(const char *name, size_t size)
void filename_completer(struct cmd_list_element *ignore, completion_tracker &tracker, const char *text, const char *word)
struct cmd_list_element * cmdlist
static scm_t_bits command_smob_tag
static SCM command_class_keyword
int gdbscm_is_exception(SCM scm)
#define gdbscm_is_true(scm)
struct cmd_list_element * add_prefix_cmd(const char *name, enum command_class theclass, cmd_const_cfunc_ftype *fun, const char *doc, struct cmd_list_element **prefixlist, const char *prefixname, int allow_unknown, struct cmd_list_element **list)
void gdbscm_dynwind_xfree(void *ptr)
SCM gdbscm_scm_from_string(const char *string, size_t len, const char *charset, int strict)
void gdbscm_initialize_commands(void)
void gdbscm_init_gsmob(gdb_smob *base)
#define CATCH(EXCEPTION, MASK)
char * gdbscm_exception_message_to_string(SCM exception)
void noop_completer(struct cmd_list_element *ignore, completion_tracker &tracker, const char *text, const char *prefix)
struct cmd_list_element * command
std::unique_ptr< T, xfree_deleter< T > > unique_xmalloc_ptr
static struct parser_state * pstate
enum command_class cmd_class
SCM gdbscm_scm_from_c_string(const char *string)
SCM gdbscm_exception_key(SCM excp)
void set_cmd_completer(struct cmd_list_element *cmd, completer_ftype *completer)
static SCM prefix_p_keyword
struct _command_smob command_smob
#define gdbscm_is_false(scm)
void(* destroyer)(struct cmd_list_element *self, void *context)
excp_matcher_func gdbscm_user_error_p
static SCM cmdscm_get_command_arg_unsafe(SCM self, int arg_pos, const char *func_name)
void command_completer(struct cmd_list_element *ignore, completion_tracker &tracker, const char *text, const char *word)
struct cleanup * make_cleanup(make_cleanup_ftype *function, void *arg)
void symbol_completer(struct cmd_list_element *ignore, completion_tracker &tracker, const char *text, const char *word)
static SCM completer_class_keyword
int gdbscm_valid_command_class_p(int command_class)
#define CMD_LIST_AMBIGUOUS
static const struct cmdscm_completer cmdscm_completers[]
char * xstrprintf(const char *format,...)
void completer_ftype(struct cmd_list_element *, completion_tracker &tracker, const char *text, const char *word)
void gdbscm_printf(SCM port, const char *format,...) ATTRIBUTE_PRINTF(2
static SCM invoke_keyword
void location_completer(struct cmd_list_element *ignore, completion_tracker &tracker, const char *text, const char *)
static const scheme_function command_functions[]
void gdbscm_define_integer_constants(const scheme_integer_constant *, int is_public)
void gdbscm_invalid_object_error(const char *subr, int arg_pos, SCM bad_value, const char *error) ATTRIBUTE_NORETURN
static void cmdscm_release_command(command_smob *c_smob)
static SCM gdbscm_register_command_x(SCM self)
void gdbscm_print_gdb_exception(SCM port, SCM exception)
void expression_completer(struct cmd_list_element *ignore, completion_tracker &tracker, const char *text, const char *word)
void gdbscm_out_of_range_error(const char *subr, int arg_pos, SCM bad_value, const char *error) ATTRIBUTE_NORETURN
completer_ftype * completer
static SCM gdbscm_command_valid_p(SCM self)
void add_completion(gdb::unique_xmalloc_ptr< char > name, completion_match_for_lcd *match_for_lcd=NULL, const char *text=NULL, const char *word=NULL)
void gdbscm_parse_function_args(const char *function_name, int beginning_arg_pos, const SCM *keywords, const char *format,...)
void(* func)(struct cmd_list_element *c, const char *args, int from_tty)
#define GDBSCM_HANDLE_GDB_EXCEPTION(exception)
SCM itscm_safe_call_next_x(SCM iter, excp_matcher_func *ok_excps)
struct cmd_list_element ** prefixlist
static SCM gdbscm_dont_repeat(SCM self)
char * gdbscm_canonicalize_command_name(const char *name, int want_trailing_space)
static int cmdscm_is_command(SCM scm)
int itscm_is_iterator(SCM scm)
const char * host_charset(void)
static SCM cmdscm_make_command_smob(void)
int gdbscm_is_procedure(SCM proc)
struct cmd_list_element * sub_list
SCM char * gdbscm_scm_to_string(SCM string, size_t *lenp, const char *charset, int strict, SCM *except_scmp)
void error(const char *fmt,...)
char * gdbscm_gc_xstrdup(const char *)
#define END_INTEGER_CONSTANTS