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;
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;
299 gdb_assert (c_smob != NULL);
305 error (_(
"Could not convert arguments to Scheme string."));
307 tty_scm = scm_from_bool (from_tty);
318 gdb::unique_xmalloc_ptr<char> msg
321 error (
"%s", msg.get ());
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);
355 if (!scm_is_string (completion))
363 gdb::unique_xmalloc_ptr<char> item
383 const char *text,
const char *word)
386 SCM completer_result_scm;
387 SCM text_scm, word_scm;
389 gdb_assert (c_smob != NULL);
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);
423 list = scm_cdr (list);
428 SCM iter = completer_result_scm;
450 completer_result_scm);
471 const char *func_name,
int arg_pos,
476 int len = strlen (
name);
481 for (i = len - 1; i >= 0 && (
name[i] ==
' ' ||
name[i] ==
'\t'); --i)
487 _(
"no command name found"));
494 gdb::unique_xmalloc_ptr<char> result ((
char *)
xmalloc (lastchar - i + 2));
495 memcpy (result.get (), &
name[i], lastchar - i + 1);
496 result.get ()[lastchar - i + 1] =
'\0';
499 for (--i; i >= 0 && (
name[i] ==
' ' ||
name[i] ==
'\t'); --i)
503 *base_list = start_list;
504 return result.release ();
507 gdb::unique_xmalloc_ptr<char> prefix_text ((
char *)
xmalloc (i + 2));
508 memcpy (prefix_text.get (),
name, i + 1);
509 prefix_text.get ()[i + 1] =
'\0';
511 const char *prefix_text2 = prefix_text.get ();
512 elt =
lookup_cmd_1 (&prefix_text2, *start_list, NULL, NULL, 1);
515 msg = xstrprintf (_(
"could not find command prefix '%s'"),
516 prefix_text.get ()).release ();
517 scm_dynwind_begin ((scm_t_dynwind_flags) 0);
526 return result.release ();
529 msg = xstrprintf (_(
"'%s' is not a prefix command"),
530 prefix_text.get ()).release ();
531 scm_dynwind_begin ((scm_t_dynwind_flags) 0);
585 int i, out, seen_word;
587 = (
char *) scm_gc_malloc_pointerless (strlen (
name) + 2,
FUNC_NAME);
589 i = out = seen_word = 0;
593 while (
name[i] ==
' ' ||
name[i] ==
'\t')
601 result[out++] =
name[i++];
605 if (want_trailing_space)
650 const SCM keywords[] = {
654 int invoke_arg_pos = -1, command_class_arg_pos = 1;
655 int completer_class_arg_pos = -1, is_prefix_arg_pos = -1;
656 int doc_arg_pos = -1;
660 SCM completer_class = SCM_BOOL_F;
663 SCM invoke = SCM_BOOL_F;
668 name_scm, &
name, rest,
669 &invoke_arg_pos, &invoke,
671 &completer_class_arg_pos, &completer_class,
676 doc = xstrdup (_(
"This command is not documented."));
690 _(
"no command name found"));
696 invoke_arg_pos,
FUNC_NAME, _(
"procedure"));
703 _(
"invalid command class argument"));
707 || scm_is_integer (completer_class)
709 completer_class, completer_class_arg_pos,
FUNC_NAME,
710 _(
"integer or procedure"));
711 if (scm_is_integer (completer_class)
712 && !scm_is_signed_integer (completer_class, 0,
N_COMPLETERS - 1))
716 _(
"invalid completion type argument"));
745 scm_misc_error (
FUNC_NAME, _(
"command is already registered"), SCM_EOL);
768 c_smob->
doc, cmd_list);
771 catch (
const gdb_exception &except)
799 return SCM_UNSPECIFIED;
808Make a GDB command object.\n\
810 Arguments: name [#:invoke lambda]\n\
811 [#:command-class <class>] [#:completer-class <completer>]\n\
812 [#:prefix? <bool>] [#:doc string]\n\
813 name: The name of the command. It may consist of multiple words,\n\
814 in which case the final word is the name of the new command, and\n\
815 earlier words must be prefix commands.\n\
816 invoke: A procedure of three arguments to perform the command.\n\
817 (lambda (self arg from-tty) ...)\n\
818 Its result is unspecified.\n\
819 class: The class of the command, one of COMMAND_*.\n\
820 The default is COMMAND_NONE.\n\
821 completer: The kind of completer, #f, one of COMPLETE_*, or a procedure\n\
822 to perform the completion: (lambda (self text word) ...).\n\
823 prefix?: If true then the command is a prefix command.\n\
824 doc: The \"doc string\" of the command.\n\
825 Returns: <gdb:command> object" },
829Register a <gdb:command> object with GDB." },
833Return #t if the object is a <gdb:command> object." },
837Return #t if the <gdb:command> object is valid." },
841Prevent command repetition when user enters an empty line.\n\
843 Arguments: <gdb:command>\n\
844 Returns: unspecified" },
static struct parser_state * pstate
const char * host_charset(void)
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)
struct cmd_list_element * cmdlist
struct cmd_list_element * add_cmd(const char *name, enum command_class theclass, const char *doc, struct cmd_list_element **list)
bool valid_cmd_char_p(int c)
struct cmd_list_element * lookup_cmd_1(const char **text, struct cmd_list_element *clist, struct cmd_list_element **result_list, std::string *default_args, int ignore_help_classes, bool lookup_for_completion_p)
void set_cmd_completer(struct cmd_list_element *cmd, completer_ftype *completer)
struct cmd_list_element * add_prefix_cmd(const char *name, enum command_class theclass, cmd_simple_func_ftype *fun, const char *doc, struct cmd_list_element **subcommands, int allow_unknown, struct cmd_list_element **list)
#define CMD_LIST_AMBIGUOUS
void completer_ftype(struct cmd_list_element *, completion_tracker &tracker, const char *text, const char *word)
void command_completer(struct cmd_list_element *ignore, completion_tracker &tracker, const char *text, const char *word)
void noop_completer(struct cmd_list_element *ignore, completion_tracker &tracker, const char *text, const char *prefix)
void expression_completer(struct cmd_list_element *ignore, completion_tracker &tracker, const char *text, const char *word)
void location_completer(struct cmd_list_element *ignore, completion_tracker &tracker, const char *text, const char *)
void filename_completer(struct cmd_list_element *ignore, completion_tracker &tracker, const char *text, const char *word)
void symbol_completer(struct cmd_list_element *ignore, completion_tracker &tracker, const char *text, const char *word)
#define gdbscm_is_true(scm)
void gdbscm_parse_function_args(const char *function_name, int beginning_arg_pos, const SCM *keywords, const char *format,...)
#define END_INTEGER_CONSTANTS
gdbscm_gdb_exception unpack(const gdb_exception &exc)
int gdbscm_is_procedure(SCM proc)
void gdbscm_init_gsmob(gdb_smob *base)
void gdbscm_print_gdb_exception(SCM port, SCM exception)
void gdbscm_invalid_object_error(const char *subr, int arg_pos, SCM bad_value, const char *error) ATTRIBUTE_NORETURN
void gdbscm_dynwind_xfree(void *ptr)
char * gdbscm_gc_xstrdup(const char *)
gdb::unique_xmalloc_ptr< char > gdbscm_exception_message_to_string(SCM exception)
SCM gdbscm_exception_key(SCM excp)
void gdbscm_out_of_range_error(const char *subr, int arg_pos, SCM bad_value, const char *error) ATTRIBUTE_NORETURN
SCM itscm_safe_call_next_x(SCM iter, excp_matcher_func *ok_excps)
#define gdbscm_is_false(scm)
void gdbscm_printf(SCM port, const char *format,...) ATTRIBUTE_PRINTF(2
SCM gdbscm_scm_from_string(const char *string, size_t len, const char *charset, int strict)
SCM gdb::unique_xmalloc_ptr< char > gdbscm_scm_to_string(SCM string, size_t *lenp, const char *charset, int strict, SCM *except_scmp)
void gdbscm_define_integer_constants(const scheme_integer_constant *, int is_public)
int itscm_is_iterator(SCM scm)
static SCM scm_new_smob(scm_t_bits tc, scm_t_bits data)
int gdbscm_is_exception(SCM scm)
void gdbscm_define_functions(const scheme_function *, int is_public)
#define GDBSCM_HANDLE_GDB_EXCEPTION(exception)
scm_t_bits gdbscm_make_smob_type(const char *name, size_t size)
static scm_t_subr as_a_scm_t_subr(SCM(*func)(void))
excp_matcher_func gdbscm_user_error_p
SCM gdbscm_safe_call_3(SCM proc, SCM arg0, SCM arg1, SCM arg2, excp_matcher_func *ok_excps)
SCM gdbscm_scm_from_c_string(const char *string)
static SCM gdbscm_register_command_x(SCM self)
static int cmdscm_print_command_smob(SCM self, SCM port, scm_print_state *pstate)
static SCM gdbscm_make_command(SCM name_scm, SCM rest)
static SCM gdbscm_dont_repeat(SCM self)
static command_smob * cmdscm_get_valid_command_smob_arg_unsafe(SCM self, int arg_pos, const char *func_name)
static const struct cmdscm_completer cmdscm_completers[]
static void cmdscm_release_command(command_smob *c_smob)
void gdbscm_initialize_commands(void)
static SCM completer_class_keyword
static SCM prefix_p_keyword
static SCM cmdscm_get_command_arg_unsafe(SCM self, int arg_pos, const char *func_name)
static int cmdscm_add_completion(SCM completion, completion_tracker &tracker)
static void cmdscm_destroyer(struct cmd_list_element *self, void *context)
static int cmdscm_is_command(SCM scm)
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_function(const char *args, int from_tty, cmd_list_element *command)
static const char command_smob_name[]
static SCM command_class_keyword
static SCM gdbscm_command_valid_p(SCM self)
static const scheme_integer_constant command_classes[]
char * gdbscm_canonicalize_command_name(const char *name, int want_trailing_space)
static SCM cmdscm_make_command_smob(void)
static int cmdscm_is_valid(command_smob *)
static void cmdscm_bad_completion_result(const char *msg, SCM completion)
int gdbscm_valid_command_class_p(int command_class)
static const scheme_function command_functions[]
static void cmdscm_completer(struct cmd_list_element *command, completion_tracker &tracker, const char *text, const char *word)
static command_smob * cmdscm_get_command_smob_arg_unsafe(SCM self, int arg_pos, const char *func_name)
static SCM invoke_keyword
static scm_t_bits command_smob_tag
static SCM gdbscm_command_p(SCM scm)
struct cmd_list_element ** subcommands
void(* destroyer)(struct cmd_list_element *self, void *context)
unsigned int allow_unknown
void set_context(void *context)
completer_ftype * completer
struct cmd_list_element * command
enum command_class cmd_class
struct cmd_list_element * sub_list