50#define N_COMPLETERS (sizeof (completers) / sizeof (completers[0]))
110 error (_(
"Invalid invocation of Python command object."));
118 error (_(
"Python command object missing 'invoke' method."));
128 error (_(
"Could not convert arguments to Python string."));
133 argobj.get (), ttyobj.get (),
171 const char *text,
const char *word)
176 error (_(
"Invalid invocation of Python command object."));
186 error (_(
"Could not convert argument to Python string."));
196 wordobj.reset (PyUnicode_Decode (word, strlen (word),
host_charset (),
199 error (_(
"Could not convert argument to Python string."));
205 wordobj.get (), NULL));
206 if (resultobj == NULL)
223 const char *text,
const char *word)
232 if (resultobj == NULL)
235 if (PyLong_Check (resultobj.get ()))
256 brkchars_fn (command, tracker, text, word);
266 const char *text,
const char *word)
276 if (resultobj == NULL)
279 if (PyLong_Check (resultobj.get ()))
295 gdbpy_ref<> iter (PyObject_GetIter (resultobj.get ()));
300 bool got_matches =
false;
312 gdb::unique_xmalloc_ptr<char>
326 if (got_matches && PyErr_Occurred ())
346gdb::unique_xmalloc_ptr<char>
352 int len = strlen (
name);
354 const char *prefix_text2;
357 for (i = len - 1; i >= 0 && (
name[i] ==
' ' ||
name[i] ==
'\t'); --i)
361 PyErr_SetString (PyExc_RuntimeError, _(
"No command name found."));
370 gdb::unique_xmalloc_ptr<char> result ((
char *)
xmalloc (lastchar - i + 2));
371 memcpy (result.get (), &
name[i], lastchar - i + 1);
372 result.get ()[lastchar - i + 1] =
'\0';
375 for (--i; i >= 0 && (
name[i] ==
' ' ||
name[i] ==
'\t'); --i)
379 *base_list = start_list;
383 std::string prefix_text (
name, i + 1);
385 prefix_text2 = prefix_text.c_str ();
386 elt =
lookup_cmd_1 (&prefix_text2, *start_list, NULL, NULL, 1);
389 PyErr_Format (PyExc_RuntimeError, _(
"Could not find command prefix %s."),
390 prefix_text.c_str ());
400 PyErr_Format (PyExc_RuntimeError, _(
"'%s' is not a prefix command."),
401 prefix_text.c_str ());
431 int completetype = -1;
433 static const char *keywords[] = {
"name",
"command_class",
"completer_class",
442 PyErr_Format (PyExc_RuntimeError,
443 _(
"Command object already initialized."));
448 keywords, &
name, &cmdtype,
449 &completetype, &is_prefix_obj))
460 PyErr_Format (PyExc_RuntimeError, _(
"Invalid command class argument."));
464 if (completetype < -1 || completetype >= (
int)
N_COMPLETERS)
466 PyErr_Format (PyExc_RuntimeError,
467 _(
"Invalid completion type argument."));
471 gdb::unique_xmalloc_ptr<char> cmd_name
473 if (cmd_name ==
nullptr)
476 if (is_prefix_obj != NULL)
478 int cmp = PyObject_IsTrue (is_prefix_obj);
485 gdb::unique_xmalloc_ptr<char> docstring =
nullptr;
493 if (docstring ==
nullptr)
498 if (docstring ==
nullptr)
499 docstring = make_unique_xstrdup (_(
"This command is not documented."));
516 NULL, docstring.release (), &obj->
sub_list,
521 docstring.release (), cmd_list);
537 if (completetype == -1)
541 catch (
const gdb_exception &except)
569 || PyModule_AddIntConstant (
gdb_module,
"COMMAND_SUPPORT",
572 || PyModule_AddIntConstant (
gdb_module,
"COMMAND_BREAKPOINTS",
574 || PyModule_AddIntConstant (
gdb_module,
"COMMAND_TRACEPOINTS",
576 || PyModule_AddIntConstant (
gdb_module,
"COMMAND_OBSCURE",
578 || PyModule_AddIntConstant (
gdb_module,
"COMMAND_MAINTENANCE",
611 "Prevent command repetition when user enters empty line." },
618 PyVarObject_HEAD_INIT (NULL, 0)
637 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
638 "GDB command object",
671 if (!PyArg_ParseTuple (args,
"s", &input))
684 gdb_argv c_argv (input);
686 for (
char *arg : c_argv)
691 || PyList_Append (py_argv.get (), argp.get ()) < 0)
696 return py_argv.release ();
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)
void set_cmd_completer_handle_brkchars(struct cmd_list_element *cmd, completer_handle_brkchars_ftype *func)
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 completer_handle_brkchars_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)
completer_handle_brkchars_ftype * completer_handle_brkchars_func_for_completer(completer_ftype *fn)
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)
static int cmdpy_init(PyObject *self, PyObject *args, PyObject *kw)
static PyObject * cmdpy_dont_repeat(PyObject *self, PyObject *args)
gdb::unique_xmalloc_ptr< char > gdbpy_parse_command_name(const char *name, struct cmd_list_element ***base_list, struct cmd_list_element **start_list)
static PyObject * invoke_cst
static void cmdpy_destroyer(struct cmd_list_element *self, void *context)
PyObject * gdbpy_string_to_argv(PyObject *self, PyObject *args)
static gdbpy_ref cmdpy_completer_helper(struct cmd_list_element *command, const char *text, const char *word)
PyTypeObject cmdpy_object_type
static void cmdpy_completer_handle_brkchars(struct cmd_list_element *command, completion_tracker &tracker, const char *text, const char *word)
static PyObject * complete_cst
static void cmdpy_function(const char *args, int from_tty, cmd_list_element *command)
static PyMethodDef cmdpy_object_methods[]
static void cmdpy_completer(struct cmd_list_element *command, completion_tracker &tracker, const char *text, const char *word)
static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION gdbpy_initialize_commands(void)
static const struct cmdpy_completer completers[]
gdb::ref_ptr< T, gdbpy_ref_policy< T > > gdbpy_ref
gdb::unique_xmalloc_ptr< char > gdbpy_fix_doc_string_indentation(gdb::unique_xmalloc_ptr< char > doc)
void gdbpy_convert_exception(const struct gdb_exception &exception)
int gdb_py_int_as_long(PyObject *obj, long *result)
int gdb_pymodule_addobject(PyObject *module, const char *name, PyObject *object)
gdb::unique_xmalloc_ptr< char > python_string_to_host_string(PyObject *obj)
void gdbpy_handle_exception()
int gdbpy_is_string(PyObject *obj)
void gdbpy_print_stack(void)
#define CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF(ARG)
#define CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
#define GDBPY_INITIALIZE_FILE(INIT,...)
static int gdb_PyArg_ParseTupleAndKeywords(PyObject *args, PyObject *kw, const char *format, const char **keywords,...)
unsigned int doc_allocated
struct cmd_list_element ** subcommands
completer_ftype * completer
void(* destroyer)(struct cmd_list_element *self, void *context)
unsigned int name_allocated
unsigned int allow_unknown
void set_context(void *context)
completer_ftype * completer
PyObject_HEAD struct cmd_list_element * command
struct cmd_list_element * sub_list