113 {
"COMPLETE_NONE", noop_completer },
114 {
"COMPLETE_FILENAME", filename_completer },
115 {
"COMPLETE_LOCATION", location_completer },
116 {
"COMPLETE_COMMAND", command_completer },
117 {
"COMPLETE_SYMBOL", make_symbol_completion_list_fn },
118 {
"COMPLETE_EXPRESSION", expression_completer },
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;
166 c_scm =
scm_new_smob (command_smob_tag, (scm_t_bits) c_smob);
167 c_smob->containing_scm = c_scm;
187 return SCM_SMOB_PREDICATE (command_smob_tag, scm);
215 const char *func_name)
228 return c_smob->
command != NULL;
236 const char *func_name)
276 return SCM_UNSPECIFIED;
297 SCM arg_scm, tty_scm, result;
305 error (
_(
"Could not convert arguments to Scheme string."));
307 tty_scm = scm_from_bool (from_tty);
326 error (
_(
"Error occurred in Scheme-implemented GDB command."));
338 SCM port = scm_current_error_port ();
340 scm_puts (msg, port);
341 scm_display (completion, port);
356 if (!scm_is_string (completion))
382 const char *text,
const char *
word)
385 SCM completer_result_scm;
386 SCM text_scm, word_scm, result_scm;
395 error (
_(
"Could not convert \"text\" argument to Scheme string."));
399 error (
_(
"Could not convert \"word\" argument to Scheme string."));
403 text_scm, word_scm, NULL);
414 SCM list = completer_result_scm;
416 while (!scm_is_eq (list, SCM_EOL))
418 SCM next = scm_car (list);
426 list = scm_cdr (list);
431 SCM iter = completer_result_scm;
457 completer_result_scm);
481 const char *func_name,
int arg_pos,
486 int len = strlen (name);
489 const char *prefix_text2;
493 for (i = len - 1; i >= 0 && (name[i] ==
' ' || name[i] ==
'\t'); --i)
499 _(
"no command name found"));
504 for (; i > 0 && (isalnum (name[i - 1])
505 || name[i - 1] ==
'-'
506 || name[i - 1] ==
'_');
509 result =
xmalloc (lastchar - i + 2);
510 memcpy (result, &name[i], lastchar - i + 1);
511 result[lastchar - i + 1] =
'\0';
514 for (--i; i >= 0 && (name[i] ==
' ' || name[i] ==
'\t'); --i)
518 *base_list = start_list;
523 memcpy (prefix_text, name, i + 1);
524 prefix_text[i + 1] =
'\0';
526 prefix_text2 = prefix_text;
527 elt =
lookup_cmd_1 (&prefix_text2, *start_list, NULL, 1);
530 msg =
xstrprintf (
_(
"could not find command prefix '%s'"), prefix_text);
533 scm_dynwind_begin (0);
546 msg =
xstrprintf (
_(
"'%s' is not a prefix command"), prefix_text);
549 scm_dynwind_begin (0);
583 for (i = 0; command_classes[i].
name != NULL; ++i)
585 if (command_classes[i].
value == command_class)
603 int i, out, seen_word;
604 char *result = scm_gc_malloc_pointerless (strlen (name) + 2,
FUNC_NAME);
606 i = out = seen_word = 0;
610 while (name[i] ==
' ' || name[i] ==
'\t')
617 while (name[i] && name[i] !=
' ' && name[i] !=
'\t')
618 result[out++] = name[i++];
622 if (want_trailing_space)
667 const SCM keywords[] = {
671 int invoke_arg_pos = -1, command_class_arg_pos = 1;
672 int completer_class_arg_pos = -1, is_prefix_arg_pos = -1;
673 int doc_arg_pos = -1;
677 SCM completer_class = SCM_BOOL_F;
680 SCM invoke = SCM_BOOL_F;
685 name_scm, &name, rest,
686 &invoke_arg_pos, &invoke,
687 &command_class_arg_pos, &command_class,
688 &completer_class_arg_pos, &completer_class,
689 &is_prefix_arg_pos, &is_prefix,
693 doc = xstrdup (
_(
"This command is not documented."));
707 _(
"no command name found"));
719 scm_from_int (command_class),
720 _(
"invalid command class argument"));
724 || scm_is_integer (completer_class)
726 completer_class, completer_class_arg_pos,
FUNC_NAME,
727 _(
"integer or procedure"));
728 if (scm_is_integer (completer_class)
729 && !scm_is_signed_integer (completer_class, 0,
N_COMPLETERS - 1))
733 _(
"invalid completion type argument"));
757 char *cmd_name, *pfx_name;
762 scm_misc_error (
FUNC_NAME,
_(
"command is already registered"), SCM_EOL);
779 c_smob->
name, allow_unknown, cmd_list);
784 NULL, c_smob->
doc, cmd_list);
815 return SCM_UNSPECIFIED;
824 Make a GDB command object.\n\
826 Arguments: name [#:invoke lambda]\n\
827 [#:command-class <class>] [#:completer-class <completer>]\n\
828 [#:prefix? <bool>] [#:doc string]\n\
829 name: The name of the command. It may consist of multiple words,\n\
830 in which case the final word is the name of the new command, and\n\
831 earlier words must be prefix commands.\n\
832 invoke: A procedure of three arguments to perform the command.\n\
833 (lambda (self arg from-tty) ...)\n\
834 Its result is unspecified.\n\
835 class: The class of the command, one of COMMAND_*.\n\
836 The default is COMMAND_NONE.\n\
837 completer: The kind of completer, #f, one of COMPLETE_*, or a procedure\n\
838 to perform the completion: (lambda (self text word) ...).\n\
839 prefix?: If true then the command is a prefix command.\n\
840 doc: The \"doc string\" of the command.\n\
841 Returns: <gdb:command> object" },
845 Register a <gdb:command> object with GDB." },
849 Return #t if the object is a <gdb:command> object." },
853 Return #t if the <gdb:command> object is valid." },
857 Prevent command repetition when user enters an empty line.\n\
859 Arguments: <gdb:command>\n\
860 Returns: unspecified" },
881 scm_c_define (cmdscm_completers[i].
name, scm_from_int (i));
882 scm_c_export (cmdscm_completers[i].name, NULL);
885 invoke_keyword = scm_from_latin1_keyword (
"invoke");
886 command_class_keyword = scm_from_latin1_keyword (
"command-class");
887 completer_class_keyword = scm_from_latin1_keyword (
"completer-class");
888 prefix_p_keyword = scm_from_latin1_keyword (
"prefix?");
889 doc_keyword = scm_from_latin1_keyword (
"doc");
void set_cmd_context(struct cmd_list_element *cmd, void *context)
struct cmd_list_element * add_prefix_cmd(const char *name, enum command_class theclass, cmd_cfunc_ftype *fun, const char *doc, struct cmd_list_element **prefixlist, const char *prefixname, int allow_unknown, struct cmd_list_element **list)
static const char command_smob_name[]
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 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)
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)
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)
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)
scm_t_bits gdbscm_make_smob_type(const char *name, size_t size)
#define VEC_safe_push(T, V, O)
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)
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)
static void cmdscm_function(struct cmd_list_element *command, char *args, int from_tty)
struct cmd_list_element * command
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
struct cmd_list_element * add_cmd(const char *name, enum command_class theclass, cmd_cfunc_ftype *fun, const char *doc, struct cmd_list_element **list)
static SCM cmdscm_get_command_arg_unsafe(SCM self, int arg_pos, const char *func_name)
struct cleanup * make_cleanup(make_cleanup_ftype *function, void *arg)
static SCM completer_class_keyword
int gdbscm_valid_command_class_p(int command_class)
static int cmdscm_add_completion(SCM completion, VEC(char_ptr)**result)
#define CMD_LIST_AMBIGUOUS
char * xstrprintf(const char *format,...)
void gdbscm_printf(SCM port, const char *format,...) ATTRIBUTE_PRINTF(2
static SCM invoke_keyword
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(* func)(struct cmd_list_element *c, char *args, int from_tty)
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 gdbscm_parse_function_args(const char *function_name, int beginning_arg_pos, const SCM *keywords, const char *format,...)
#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 *)
const ULONGEST const LONGEST len
#define END_INTEGER_CONSTANTS