51 #define N_COMPLETERS (sizeof (completers) / sizeof (completers[0])) 104 xfree ((
char *) self->name);
105 xfree ((
char *) self->doc);
106 xfree ((
char *) self->prefixname);
113 const char *args,
int from_tty)
120 error (
_(
"Invalid invocation of Python command object."));
121 if (! PyObject_HasAttr ((PyObject *) obj,
invoke_cst))
123 if (obj->command->prefixname)
128 error (
_(
"Python command object missing 'invoke' method."));
138 error (
_(
"Could not convert arguments to Python string."));
141 gdbpy_ref<> ttyobj (from_tty ? Py_True : Py_False);
142 Py_INCREF (ttyobj.
get ());
144 argobj.
get (), ttyobj.
get (),
149 PyObject *ptype, *pvalue, *ptraceback;
151 PyErr_Fetch (&ptype, &pvalue, &ptraceback);
165 "and then another occurred computing the " 166 "error message.\n"));
178 || msg == NULL || *msg ==
'\0')
180 PyErr_Restore (ptype, pvalue, ptraceback);
182 if (msg != NULL && *msg !=
'\0')
183 error (
_(
"Error occurred in Python command: %s"), msg.get ());
185 error (
_(
"Error occurred in Python command."));
191 Py_XDECREF (ptraceback);
192 error (
"%s", msg.get ());
228 const char *text,
const char *word)
233 error (
_(
"Invalid invocation of Python command object."));
243 error (
_(
"Could not convert argument to Python string."));
249 wordobj.
reset (Py_None);
257 error (
_(
"Could not convert argument to Python string."));
260 gdbpy_ref<> resultobj (PyObject_CallMethodObjArgs ((PyObject *) obj,
263 wordobj.
get (), NULL));
264 if (resultobj == NULL)
281 const char *text,
const char *word)
290 if (resultobj == NULL)
293 if (PyInt_Check (resultobj.
get ()))
314 brkchars_fn (
command, tracker, text, word);
324 const char *text,
const char *word)
334 if (resultobj == NULL)
337 if (PyInt_Check (resultobj.
get ()))
358 bool got_matches =
false;
384 if (got_matches && PyErr_Occurred ())
410 int len = strlen (
name);
413 const char *prefix_text2;
417 for (i = len - 1; i >= 0 && (
name[i] ==
' ' ||
name[i] ==
'\t'); --i)
421 PyErr_SetString (PyExc_RuntimeError,
_(
"No command name found."));
427 for (; i > 0 && (isalnum (
name[i - 1])
428 ||
name[i - 1] ==
'-' 429 ||
name[i - 1] ==
'_');
432 result = (
char *)
xmalloc (lastchar - i + 2);
433 memcpy (result, &
name[i], lastchar - i + 1);
434 result[lastchar - i + 1] =
'\0';
437 for (--i; i >= 0 && (
name[i] ==
' ' ||
name[i] ==
'\t'); --i)
441 *base_list = start_list;
445 prefix_text = (
char *)
xmalloc (i + 2);
446 memcpy (prefix_text,
name, i + 1);
447 prefix_text[i + 1] =
'\0';
449 prefix_text2 = prefix_text;
450 elt =
lookup_cmd_1 (&prefix_text2, *start_list, NULL, 1);
453 PyErr_Format (PyExc_RuntimeError,
_(
"Could not find command prefix %s."),
467 PyErr_Format (PyExc_RuntimeError,
_(
"'%s' is not a prefix command."),
500 int completetype = -1;
501 char *docstring = NULL;
503 char *cmd_name, *pfx_name;
504 static const char *keywords[] = {
"name",
"command_class",
"completer_class",
506 PyObject *is_prefix = NULL;
513 PyErr_Format (PyExc_RuntimeError,
514 _(
"Command object already initialized."));
519 keywords, &
name, &cmdtype,
520 &completetype, &is_prefix))
530 PyErr_Format (PyExc_RuntimeError,
_(
"Invalid command class argument."));
534 if (completetype < -1 || completetype >= (
int)
N_COMPLETERS)
536 PyErr_Format (PyExc_RuntimeError,
537 _(
"Invalid completion type argument."));
546 if (is_prefix != NULL)
548 cmp = PyObject_IsTrue (is_prefix);
561 while (
name[i] ==
' ' ||
name[i] ==
'\t')
565 pfx_name[out++] =
name[i++];
568 pfx_name[out++] =
' ';
570 pfx_name[out] =
'\0';
585 if (docstring == NULL)
594 docstring = xstrdup (
_(
"This command is not documented."));
615 docstring, cmd_list);
625 if (completetype == -1)
636 ? PyExc_KeyboardInterrupt : PyExc_RuntimeError,
637 "%s", except.message);
665 || PyModule_AddIntConstant (
gdb_module,
"COMMAND_SUPPORT",
668 || PyModule_AddIntConstant (
gdb_module,
"COMMAND_BREAKPOINTS",
670 || PyModule_AddIntConstant (
gdb_module,
"COMMAND_TRACEPOINTS",
672 || PyModule_AddIntConstant (
gdb_module,
"COMMAND_OBSCURE",
674 || PyModule_AddIntConstant (
gdb_module,
"COMMAND_MAINTENANCE",
704 "Prevent command repetition when user enters empty line." },
730 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
731 "GDB command object",
764 if (!PyArg_ParseTuple (args,
"s", &input))
779 for (
char *arg : c_argv)
784 || PyList_Append (py_argv.
get (), argp.
get ()) < 0)
int gdb_pymodule_addobject(PyObject *module, const char *name, PyObject *object)
void set_cmd_context(struct cmd_list_element *cmd, void *context)
static void cmdpy_function(struct cmd_list_element *command, const char *args, int from_tty)
PyTypeObject cmdpy_object_type
struct cmdpy_object cmdpy_object
struct cmd_list_element * sub_list
void * get_cmd_context(struct cmd_list_element *cmd)
static void cmdpy_completer(struct cmd_list_element *command, completion_tracker &tracker, const char *text, const char *word)
completer_handle_brkchars_ftype * completer_handle_brkchars_func_for_completer(completer_ftype *fn)
int gdbpy_is_string(PyObject *obj)
unsigned int allow_unknown
struct cmd_list_element * add_cmd(const char *name, enum command_class theclass, const char *doc, struct cmd_list_element **list)
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)
void filename_completer(struct cmd_list_element *ignore, completion_tracker &tracker, const char *text, const char *word)
struct cmd_list_element * cmdlist
static PyObject * cmdpy_dont_repeat(PyObject *self, PyObject *args)
static int gdb_PyArg_ParseTupleAndKeywords(PyObject *args, PyObject *kw, const char *format, const char **keywords,...)
#define PyVarObject_HEAD_INIT(type, size)
static void cmdpy_completer_handle_brkchars(struct cmd_list_element *command, completion_tracker &tracker, const char *text, const char *word)
void printf_filtered(const char *format,...)
static PyObject * invoke_cst
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)
#define CATCH(EXCEPTION, MASK)
void noop_completer(struct cmd_list_element *ignore, completion_tracker &tracker, const char *text, const char *prefix)
std::unique_ptr< T, xfree_deleter< T > > unique_xmalloc_ptr
void set_cmd_completer(struct cmd_list_element *cmd, completer_ftype *completer)
void(* destroyer)(struct cmd_list_element *self, void *context)
PyObject_HEAD struct cmd_list_element * command
static void cmdpy_destroyer(struct cmd_list_element *self, void *context)
void command_completer(struct cmd_list_element *ignore, completion_tracker &tracker, const char *text, const char *word)
void set_cmd_completer_handle_brkchars(struct cmd_list_element *cmd, completer_handle_brkchars_ftype *func)
int gdbpy_initialize_commands(void)
void symbol_completer(struct cmd_list_element *ignore, completion_tracker &tracker, const char *text, const char *word)
struct gdbarch * get_current_arch(void)
char * gdbpy_parse_command_name(const char *name, struct cmd_list_element ***base_list, struct cmd_list_element **start_list)
static PyObject * complete_cst
PyObject * gdbpy_gdberror_exc
#define CMD_LIST_AMBIGUOUS
gdb::unique_xmalloc_ptr< char > python_string_to_host_string(PyObject *obj)
void completer_ftype(struct cmd_list_element *, completion_tracker &tracker, const char *text, const char *word)
PyTypeObject cmdpy_object_type CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF("cmdpy_object")
static const struct cmdpy_completer completers[]
static PyMethodDef cmdpy_object_methods[]
static int cmdpy_init(PyObject *self, PyObject *args, PyObject *kw)
void location_completer(struct cmd_list_element *ignore, completion_tracker &tracker, const char *text, const char *)
PyObject * gdbpy_string_to_argv(PyObject *self, PyObject *args)
const struct language_defn * current_language
void expression_completer(struct cmd_list_element *ignore, completion_tracker &tracker, const char *text, const char *word)
void gdbpy_print_stack(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)
completer_ftype * completer
void(* func)(struct cmd_list_element *c, const char *args, int from_tty)
int gdb_py_int_as_long(PyObject *obj, long *result)
void completer_handle_brkchars_ftype(struct cmd_list_element *, completion_tracker &tracker, const char *text, const char *word)
struct cmd_list_element ** prefixlist
gdb::unique_xmalloc_ptr< char > gdbpy_exception_to_string(PyObject *ptype, PyObject *pvalue)
const char * host_charset(void)
completer_ftype * completer
static PyObject * cmdpy_completer_helper(struct cmd_list_element *command, const char *text, const char *word)
void error(const char *fmt,...)