2009-02-06 22:33:59 +01:00
|
|
|
|
/* gdb commands implemented in Python
|
|
|
|
|
|
2014-01-01 04:54:24 +01:00
|
|
|
|
Copyright (C) 2008-2014 Free Software Foundation, Inc.
|
2009-02-06 22:33:59 +01:00
|
|
|
|
|
|
|
|
|
This file is part of GDB.
|
|
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "defs.h"
|
* python/python-internal.h (struct language_defn): Declare.
(python_gdbarch, python_language): Likewise.
(ensure_python_env): Add prototype.
(make_cleanup_py_restore_gil): Remove prototype.
* python/python.c: Include "arch-utils.h", "value.h" and "language.h".
(python_gdbarch, python_language): New global variables.
(struct python_env): New data type.
(ensure_python_env, restore_python_env): New functions.
(eval_python_from_control_command): Call ensure_python_env to
install current architecture and language.
(python_command, gdbpy_new_objfile): Likewise.
* python/python-cmd.c: Include "arch-utils.h" and "language.h".
(cmdpy_destroyer, cmdpy_function, cmdpy_completer): Call
ensure_python_env.
* python/python-type.c (clean_up_objfile_types): Likewise.
* python/python-objfile.c: Include "language.h".
(clean_up_objfile): Call ensure_python_env.
* python/python-prettyprint.c (apply_val_pretty_printer): Likewise.
(apply_varobj_pretty_printer): Do not call PyGILState_Ensure.
* varobj.c (varobj_ensure_python_env): New helper function.
(varobj_get_display_hint, update_dynamic_varobj_children,
install_default_visualizer, varobj_set_visualizer, free_variable,
value_get_print_value): Call it.
(value_get_print_value): Add varobj argument instead of pretty
printer argument. Update all callers.
* python/python-utils.c (py_gil_restore, make_cleanup_py_restore_gil):
Remove.
* value.h (internal_function_fn): Add GDBARCH and LANGUAGE argument.
(call_internal_function): Likewise.
* value.c (call_internal_function): Likewise. Pass to handler.
* eval.c (evaluate_subexp_standard): Update call.
* python/python-function.c: Include "language.h".
(fnpy_call): Add GDBARCH and LANGAUAGE arguments and call
make_cleanup_python_env.
* python/python-value.c (builtin_type_pyint, builtin_type_pyfloat,
builtin_type_pylong, builtin_type_pybool, builtin_type_pychar,
valpy_str): Use python_gdbarch and python_language instead of
current_gdbarch and current_language.
* python/python-type.c (typy_lookup_typename): Likewise.
2009-07-02 19:04:23 +02:00
|
|
|
|
#include "arch-utils.h"
|
2009-02-06 22:33:59 +01:00
|
|
|
|
#include "value.h"
|
|
|
|
|
#include "exceptions.h"
|
|
|
|
|
#include "python-internal.h"
|
|
|
|
|
#include "charset.h"
|
|
|
|
|
#include "gdbcmd.h"
|
|
|
|
|
#include "cli/cli-decode.h"
|
|
|
|
|
#include "completer.h"
|
* python/python-internal.h (struct language_defn): Declare.
(python_gdbarch, python_language): Likewise.
(ensure_python_env): Add prototype.
(make_cleanup_py_restore_gil): Remove prototype.
* python/python.c: Include "arch-utils.h", "value.h" and "language.h".
(python_gdbarch, python_language): New global variables.
(struct python_env): New data type.
(ensure_python_env, restore_python_env): New functions.
(eval_python_from_control_command): Call ensure_python_env to
install current architecture and language.
(python_command, gdbpy_new_objfile): Likewise.
* python/python-cmd.c: Include "arch-utils.h" and "language.h".
(cmdpy_destroyer, cmdpy_function, cmdpy_completer): Call
ensure_python_env.
* python/python-type.c (clean_up_objfile_types): Likewise.
* python/python-objfile.c: Include "language.h".
(clean_up_objfile): Call ensure_python_env.
* python/python-prettyprint.c (apply_val_pretty_printer): Likewise.
(apply_varobj_pretty_printer): Do not call PyGILState_Ensure.
* varobj.c (varobj_ensure_python_env): New helper function.
(varobj_get_display_hint, update_dynamic_varobj_children,
install_default_visualizer, varobj_set_visualizer, free_variable,
value_get_print_value): Call it.
(value_get_print_value): Add varobj argument instead of pretty
printer argument. Update all callers.
* python/python-utils.c (py_gil_restore, make_cleanup_py_restore_gil):
Remove.
* value.h (internal_function_fn): Add GDBARCH and LANGUAGE argument.
(call_internal_function): Likewise.
* value.c (call_internal_function): Likewise. Pass to handler.
* eval.c (evaluate_subexp_standard): Update call.
* python/python-function.c: Include "language.h".
(fnpy_call): Add GDBARCH and LANGAUAGE arguments and call
make_cleanup_python_env.
* python/python-value.c (builtin_type_pyint, builtin_type_pyfloat,
builtin_type_pylong, builtin_type_pybool, builtin_type_pychar,
valpy_str): Use python_gdbarch and python_language instead of
current_gdbarch and current_language.
* python/python-type.c (typy_lookup_typename): Likewise.
2009-07-02 19:04:23 +02:00
|
|
|
|
#include "language.h"
|
2009-02-06 22:33:59 +01:00
|
|
|
|
|
|
|
|
|
/* Struct representing built-in completion types. */
|
|
|
|
|
struct cmdpy_completer
|
|
|
|
|
{
|
|
|
|
|
/* Python symbol name. */
|
|
|
|
|
char *name;
|
|
|
|
|
/* Completion function. */
|
2012-06-13 17:41:24 +02:00
|
|
|
|
completer_ftype *completer;
|
2009-02-06 22:33:59 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static struct cmdpy_completer completers[] =
|
|
|
|
|
{
|
|
|
|
|
{ "COMPLETE_NONE", noop_completer },
|
|
|
|
|
{ "COMPLETE_FILENAME", filename_completer },
|
|
|
|
|
{ "COMPLETE_LOCATION", location_completer },
|
|
|
|
|
{ "COMPLETE_COMMAND", command_completer },
|
|
|
|
|
{ "COMPLETE_SYMBOL", make_symbol_completion_list_fn },
|
2013-11-07 13:32:31 +01:00
|
|
|
|
{ "COMPLETE_EXPRESSION", expression_completer },
|
2009-02-06 22:33:59 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#define N_COMPLETERS (sizeof (completers) / sizeof (completers[0]))
|
|
|
|
|
|
|
|
|
|
/* A gdb command. For the time being only ordinary commands (not
|
|
|
|
|
set/show commands) are allowed. */
|
|
|
|
|
struct cmdpy_object
|
|
|
|
|
{
|
|
|
|
|
PyObject_HEAD
|
|
|
|
|
|
|
|
|
|
/* The corresponding gdb command object, or NULL if the command is
|
|
|
|
|
no longer installed. */
|
|
|
|
|
struct cmd_list_element *command;
|
|
|
|
|
|
|
|
|
|
/* A prefix command requires storage for a list of its sub-commands.
|
|
|
|
|
A pointer to this is passed to add_prefix_command, and to add_cmd
|
|
|
|
|
for sub-commands of that prefix. If this Command is not a prefix
|
|
|
|
|
command, then this field is unused. */
|
|
|
|
|
struct cmd_list_element *sub_list;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
typedef struct cmdpy_object cmdpy_object;
|
|
|
|
|
|
2013-05-20 22:09:01 +02:00
|
|
|
|
static PyTypeObject cmdpy_object_type
|
|
|
|
|
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("cmdpy_object");
|
2009-02-06 22:33:59 +01:00
|
|
|
|
|
|
|
|
|
/* Constants used by this module. */
|
|
|
|
|
static PyObject *invoke_cst;
|
|
|
|
|
static PyObject *complete_cst;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Python function which wraps dont_repeat. */
|
|
|
|
|
static PyObject *
|
|
|
|
|
cmdpy_dont_repeat (PyObject *self, PyObject *args)
|
|
|
|
|
{
|
|
|
|
|
dont_repeat ();
|
|
|
|
|
Py_RETURN_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Called if the gdb cmd_list_element is destroyed. */
|
2010-05-25 17:27:17 +02:00
|
|
|
|
|
2009-02-06 22:33:59 +01:00
|
|
|
|
static void
|
|
|
|
|
cmdpy_destroyer (struct cmd_list_element *self, void *context)
|
|
|
|
|
{
|
|
|
|
|
cmdpy_object *cmd;
|
* python/python-internal.h (struct language_defn): Declare.
(python_gdbarch, python_language): Likewise.
(ensure_python_env): Add prototype.
(make_cleanup_py_restore_gil): Remove prototype.
* python/python.c: Include "arch-utils.h", "value.h" and "language.h".
(python_gdbarch, python_language): New global variables.
(struct python_env): New data type.
(ensure_python_env, restore_python_env): New functions.
(eval_python_from_control_command): Call ensure_python_env to
install current architecture and language.
(python_command, gdbpy_new_objfile): Likewise.
* python/python-cmd.c: Include "arch-utils.h" and "language.h".
(cmdpy_destroyer, cmdpy_function, cmdpy_completer): Call
ensure_python_env.
* python/python-type.c (clean_up_objfile_types): Likewise.
* python/python-objfile.c: Include "language.h".
(clean_up_objfile): Call ensure_python_env.
* python/python-prettyprint.c (apply_val_pretty_printer): Likewise.
(apply_varobj_pretty_printer): Do not call PyGILState_Ensure.
* varobj.c (varobj_ensure_python_env): New helper function.
(varobj_get_display_hint, update_dynamic_varobj_children,
install_default_visualizer, varobj_set_visualizer, free_variable,
value_get_print_value): Call it.
(value_get_print_value): Add varobj argument instead of pretty
printer argument. Update all callers.
* python/python-utils.c (py_gil_restore, make_cleanup_py_restore_gil):
Remove.
* value.h (internal_function_fn): Add GDBARCH and LANGUAGE argument.
(call_internal_function): Likewise.
* value.c (call_internal_function): Likewise. Pass to handler.
* eval.c (evaluate_subexp_standard): Update call.
* python/python-function.c: Include "language.h".
(fnpy_call): Add GDBARCH and LANGAUAGE arguments and call
make_cleanup_python_env.
* python/python-value.c (builtin_type_pyint, builtin_type_pyfloat,
builtin_type_pylong, builtin_type_pybool, builtin_type_pychar,
valpy_str): Use python_gdbarch and python_language instead of
current_gdbarch and current_language.
* python/python-type.c (typy_lookup_typename): Likewise.
2009-07-02 19:04:23 +02:00
|
|
|
|
struct cleanup *cleanup;
|
2009-02-06 22:33:59 +01:00
|
|
|
|
|
* python/python-internal.h (struct language_defn): Declare.
(python_gdbarch, python_language): Likewise.
(ensure_python_env): Add prototype.
(make_cleanup_py_restore_gil): Remove prototype.
* python/python.c: Include "arch-utils.h", "value.h" and "language.h".
(python_gdbarch, python_language): New global variables.
(struct python_env): New data type.
(ensure_python_env, restore_python_env): New functions.
(eval_python_from_control_command): Call ensure_python_env to
install current architecture and language.
(python_command, gdbpy_new_objfile): Likewise.
* python/python-cmd.c: Include "arch-utils.h" and "language.h".
(cmdpy_destroyer, cmdpy_function, cmdpy_completer): Call
ensure_python_env.
* python/python-type.c (clean_up_objfile_types): Likewise.
* python/python-objfile.c: Include "language.h".
(clean_up_objfile): Call ensure_python_env.
* python/python-prettyprint.c (apply_val_pretty_printer): Likewise.
(apply_varobj_pretty_printer): Do not call PyGILState_Ensure.
* varobj.c (varobj_ensure_python_env): New helper function.
(varobj_get_display_hint, update_dynamic_varobj_children,
install_default_visualizer, varobj_set_visualizer, free_variable,
value_get_print_value): Call it.
(value_get_print_value): Add varobj argument instead of pretty
printer argument. Update all callers.
* python/python-utils.c (py_gil_restore, make_cleanup_py_restore_gil):
Remove.
* value.h (internal_function_fn): Add GDBARCH and LANGUAGE argument.
(call_internal_function): Likewise.
* value.c (call_internal_function): Likewise. Pass to handler.
* eval.c (evaluate_subexp_standard): Update call.
* python/python-function.c: Include "language.h".
(fnpy_call): Add GDBARCH and LANGAUAGE arguments and call
make_cleanup_python_env.
* python/python-value.c (builtin_type_pyint, builtin_type_pyfloat,
builtin_type_pylong, builtin_type_pybool, builtin_type_pychar,
valpy_str): Use python_gdbarch and python_language instead of
current_gdbarch and current_language.
* python/python-type.c (typy_lookup_typename): Likewise.
2009-07-02 19:04:23 +02:00
|
|
|
|
cleanup = ensure_python_env (get_current_arch (), current_language);
|
2009-02-06 22:33:59 +01:00
|
|
|
|
|
|
|
|
|
/* Release our hold on the command object. */
|
|
|
|
|
cmd = (cmdpy_object *) context;
|
|
|
|
|
cmd->command = NULL;
|
|
|
|
|
Py_DECREF (cmd);
|
|
|
|
|
|
|
|
|
|
/* We allocated the name, doc string, and perhaps the prefix
|
|
|
|
|
name. */
|
Constify strings in tracepoint.c, lookup_cmd and the completers.
This is sort of a continuation of Keith's parse_exp_1 constification
patch. It started out by undoing these bits:
@@ -754,9 +754,12 @@ validate_actionline (char **line, struct
tmp_p = p;
for (loc = t->base.loc; loc; loc = loc->next)
{
- p = tmp_p;
- exp = parse_exp_1 (&p, loc->address,
+ const char *q;
+
+ q = tmp_p;
+ exp = parse_exp_1 (&q, loc->address,
block_for_pc (loc->address), 1);
+ p = (char *) q;
and progressively making more things const upwards, fixing fallout,
rinse repeat, until GDB built again (--enable-targets=all).
That ended up constifying lookup_cmd/add_cmd and (lots of) friends,
and the completers.
I didn't try to constify the command hooks themselves, because I know
upfront there are commands that write to the command string argument,
and I think I managed to stop at a nice non-hacky split point already.
I think the only non-really-super-obvious changes are
tracepoint.c:validate_actionline, and tracepoint.c:trace_dump_actions.
The rest is just mostly about 'char *' => 'const char *', 'char **'=>
'const char **', and the occasional (e.g., deprecated_cmd_warning)
case of 'char **'=> 'const char *', where/when I noticed that nothing
actually cares about the pointer to pointer output.
Tested on x86_64 Fedora 17, native and gdbserver.
gdb/
2013-03-13 Pedro Alves <palves@redhat.com>
* ada-lang.c (struct add_partial_datum) <text, text0, word>: Make
fields const.
(ada_make_symbol_completion_list): Make "text0" parameter const.
* ax-gdb.c (agent_eval_command_one): Make "exp" parameter const.
* breakpoint.c (condition_completer): Make "text" and "word"
parameters const. Adjust.
(check_tracepoint_command): Adjust to validate_actionline
prototype change.
(catch_syscall_completer): Make "text" and "word" parameters
const.
* cli/cli-cmds.c (show_user): Make "comname" local const.
(valid_command_p): Make "command" parameter const.
(alias_command): Make "alias_prefix" and "command_prefix" locals
const.
* cli/cli-decode.c (add_cmd): Make "name" parameter const.
(add_alias_cmd): Make "name" and "oldname" parameters const.
Adjust. No longer make copy of OLDNAME.
(add_prefix_cmd, add_abbrev_prefix_cmd, add_set_or_show_cmd)
(add_setshow_cmd_full, add_setshow_enum_cmd)
(add_setshow_auto_boolean_cmd, add_setshow_boolean_cmd)
(add_setshow_filename_cmd, add_setshow_string_cmd)
(add_setshow_string_noescape_cmd)
(add_setshow_optional_filename_cmd, add_setshow_integer_cmd)
(add_setshow_uinteger_cmd, add_setshow_zinteger_cmd)
(add_setshow_zuinteger_unlimited_cmd, add_setshow_zuinteger_cmd)
(delete_cmd, add_info, add_info_alias, add_com, add_com_alias):
Make "name" parameter const.
(help_cmd): Rename "command" parameter to "arg". New const local
"command".
(find_cmd): Make "command" parameter const.
(lookup_cmd_1): Make "text" parameter pointer to const. Adjust to
deprecated_cmd_warning prototype change.
(undef_cmd_error): Make "cmdtype" parameter const.
(lookup_cmd): Make "line" parameter const.
(deprecated_cmd_warning): Change type of "text" parameter to
pointer to const char, from pointer to pointer to char. Adjust.
(lookup_cmd_composition): Make "text" parameter const.
(complete_on_cmdlist, complete_on_enum): Make "text" and "word"
parameters const.
* cli/cli-decode.h (struct cmd_list_element) <name>: Make field
const.
* cli/cli-script.c (validate_comname): Make "tem" local const.
(define_command): New const local "tem_c". Use it in calls to
lookup_cmd.
(document_command): Make "tem" and "comfull" locals const.
(show_user_1): Make "prefix" and "name" parameters const.
* cli-script.h (show_user_1): Make "prefix" and "name" parameters
const.
* command.h (add_cmd, add_alias_cmd, add_prefix_cmd)
(add_abbrev_prefix_cmd, completer_ftype, lookup_cmd, lookup_cmd_1)
(deprecated_cmd_warning, lookup_cmd_composition, add_com)
(add_com_alias, add_info, add_info_alias, complete_on_cmdlist)
(complete_on_enum, add_setshow_enum_cmd)
(add_setshow_auto_boolean_cmd, add_setshow_boolean_cmd)
(add_setshow_filename_cmd, add_setshow_string_cmd)
(add_setshow_string_noescape_cmd)
(add_setshow_optional_filename_cmd, add_setshow_integer_cmd)
(add_setshow_uinteger_cmd, add_setshow_zinteger_cmd)
(add_setshow_zuinteger_cmd, add_setshow_zuinteger_unlimited_cmd):
Change prototypes, constifying strings.
* completer.c (noop_completer, filename_completer): Make "text"
and "prefix" parameters const.
(location_completer, expression_completer)
(complete_line_internal): Make "text" and "prefix" parameters
const and adjust.
(command_completer, signal_completer): Make "text" and "prefix"
parameters const.
* completer.h (noop_completer, filename_completer)
(expression_completer, location_completer, command_completer)
(signal_completer): Change prototypes.
* corefile.c (complete_set_gnutarget): Make "text" and "word"
parameters const.
* cp-abi.c (cp_abi_completer): Likewise.
* expression.h (parse_expression_for_completion): Change
prototype.
* f-lang.c (f_make_symbol_completion_list): Make "text" and "word"
parameters const.
* infcmd.c (_initialize_infcmd): Make "cmd_name" local const.
* infrun.c (handle_completer): Make "text" and "word" parameters
const.
* interps.c (interpreter_completer): Make "text" and "word"
parameters const.
* language.h (struct language_defn)
<la_make_symbol_completion_list>: Make "text" and "word"
parameters const.
* parse.c (parse_exp_1): Move const hack to parse_exp_in_context.
(parse_exp_in_context): Rename to ...
(parse_exp_in_context_1): ... this.
(parse_exp_in_context): Reimplement, with const hack from
parse_exp_1.
(parse_expression_for_completion): Make "string" parameter const.
* printcmd.c (decode_format): Make "string_ptr" parameter pointer
to pointer to const char. Adjust.
(print_command_1): Make "exp" parameter const.
(output_command): Rename to ...
(output_command_const): ... this. Make "exp" parameter const.
(output_command): Reimplement.
(x_command): Adjust.
(display_command): Rename "exp" parameter to "arg". New "exp"
local, const version of "arg".
* python/py-auto-load.c (gdbpy_initialize_auto_load): Make
"cmd_name" local const.
* python/py-cmd.c (cmdpy_destroyer): Cast const away in xfree
call.
(cmdpy_completer): Make "text" and "word" parameters const.
(gdbpy_parse_command_name): Make "prefix_text2" local const.
* python/py-param.c (add_setshow_generic): Make "tmp_name" local
const.
* remote.c (_initialize_remote): Make "cmd_name" local const.
* symtab.c (language_search_unquoted_string): Make "text" and "p"
parameters const. Adjust.
(completion_list_add_fields): Make "sym_text", "text" and "word"
parameters const.
(struct add_name_data) <sym_text, text, word>: Make fields const.
(default_make_symbol_completion_list_break_on): Make "text" and
"word" parameters const. Adjust locals.
(default_make_symbol_completion_list)
(make_symbol_completion_list, make_symbol_completion_type)
(make_symbol_completion_list_fn): Make "text" and "word"
parameters const.
(make_file_symbol_completion_list): Make "text", "word" and
"srcfile" parameters const. Adjust locals.
(add_filename_to_list): Make "text" and "word" parameters const.
(struct add_partial_filename_data) <text, word>: Make fields
const.
(make_source_files_completion_list): Make "text" and "word"
parameters const.
* symtab.h (default_make_symbol_completion_list_break_on)
(default_make_symbol_completion_list, make_symbol_completion_list)
(make_symbol_completion_type enum type_code)
(make_symbol_completion_list_fn make_file_symbol_completion_list)
(make_source_files_completion_list): Change prototype.
* top.c (execute_command): Adjust to pass pointer to pointer to
const char to lookup_cmd, and to deprecated_cmd_warning prototype
change.
(set_verbose): Make "cmdname" local const.
* tracepoint.c (decode_agent_options): Make "exp" parameter const,
and adjust.
(validate_actionline): Make "line" parameter a pointer to const
char, and adjust.
(encode_actions_1): Make "action_exp" local const, and adjust.
(encode_actions): Adjust.
(replace_comma): Delete.
(trace_dump_actions): Make "action_exp" and "next_comma" locals
const, and adjust. Don't frob the action string while splitting
it at commas. Instead, make a copy of each split substring in
turn.
(trace_dump_command): Adjust to validate_actionline prototype
change.
* tracepoint.h (decode_agent_options, decode_agent_options)
(encode_actions, validate_actionline): Change prototypes.
* valprint.h (output_command): Delete declaration.
(output_command_const): Declare.
* value.c (function_destroyer): Cast const away in xfree call.
2013-03-13 19:34:55 +01:00
|
|
|
|
xfree ((char *) self->name);
|
2009-02-06 22:33:59 +01:00
|
|
|
|
xfree (self->doc);
|
|
|
|
|
xfree (self->prefixname);
|
|
|
|
|
|
* python/python-internal.h (struct language_defn): Declare.
(python_gdbarch, python_language): Likewise.
(ensure_python_env): Add prototype.
(make_cleanup_py_restore_gil): Remove prototype.
* python/python.c: Include "arch-utils.h", "value.h" and "language.h".
(python_gdbarch, python_language): New global variables.
(struct python_env): New data type.
(ensure_python_env, restore_python_env): New functions.
(eval_python_from_control_command): Call ensure_python_env to
install current architecture and language.
(python_command, gdbpy_new_objfile): Likewise.
* python/python-cmd.c: Include "arch-utils.h" and "language.h".
(cmdpy_destroyer, cmdpy_function, cmdpy_completer): Call
ensure_python_env.
* python/python-type.c (clean_up_objfile_types): Likewise.
* python/python-objfile.c: Include "language.h".
(clean_up_objfile): Call ensure_python_env.
* python/python-prettyprint.c (apply_val_pretty_printer): Likewise.
(apply_varobj_pretty_printer): Do not call PyGILState_Ensure.
* varobj.c (varobj_ensure_python_env): New helper function.
(varobj_get_display_hint, update_dynamic_varobj_children,
install_default_visualizer, varobj_set_visualizer, free_variable,
value_get_print_value): Call it.
(value_get_print_value): Add varobj argument instead of pretty
printer argument. Update all callers.
* python/python-utils.c (py_gil_restore, make_cleanup_py_restore_gil):
Remove.
* value.h (internal_function_fn): Add GDBARCH and LANGUAGE argument.
(call_internal_function): Likewise.
* value.c (call_internal_function): Likewise. Pass to handler.
* eval.c (evaluate_subexp_standard): Update call.
* python/python-function.c: Include "language.h".
(fnpy_call): Add GDBARCH and LANGAUAGE arguments and call
make_cleanup_python_env.
* python/python-value.c (builtin_type_pyint, builtin_type_pyfloat,
builtin_type_pylong, builtin_type_pybool, builtin_type_pychar,
valpy_str): Use python_gdbarch and python_language instead of
current_gdbarch and current_language.
* python/python-type.c (typy_lookup_typename): Likewise.
2009-07-02 19:04:23 +02:00
|
|
|
|
do_cleanups (cleanup);
|
2009-02-06 22:33:59 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Called by gdb to invoke the command. */
|
2010-05-25 17:27:17 +02:00
|
|
|
|
|
2009-02-06 22:33:59 +01:00
|
|
|
|
static void
|
|
|
|
|
cmdpy_function (struct cmd_list_element *command, char *args, int from_tty)
|
|
|
|
|
{
|
|
|
|
|
cmdpy_object *obj = (cmdpy_object *) get_cmd_context (command);
|
|
|
|
|
PyObject *argobj, *ttyobj, *result;
|
|
|
|
|
struct cleanup *cleanup;
|
|
|
|
|
|
* python/python-internal.h (struct language_defn): Declare.
(python_gdbarch, python_language): Likewise.
(ensure_python_env): Add prototype.
(make_cleanup_py_restore_gil): Remove prototype.
* python/python.c: Include "arch-utils.h", "value.h" and "language.h".
(python_gdbarch, python_language): New global variables.
(struct python_env): New data type.
(ensure_python_env, restore_python_env): New functions.
(eval_python_from_control_command): Call ensure_python_env to
install current architecture and language.
(python_command, gdbpy_new_objfile): Likewise.
* python/python-cmd.c: Include "arch-utils.h" and "language.h".
(cmdpy_destroyer, cmdpy_function, cmdpy_completer): Call
ensure_python_env.
* python/python-type.c (clean_up_objfile_types): Likewise.
* python/python-objfile.c: Include "language.h".
(clean_up_objfile): Call ensure_python_env.
* python/python-prettyprint.c (apply_val_pretty_printer): Likewise.
(apply_varobj_pretty_printer): Do not call PyGILState_Ensure.
* varobj.c (varobj_ensure_python_env): New helper function.
(varobj_get_display_hint, update_dynamic_varobj_children,
install_default_visualizer, varobj_set_visualizer, free_variable,
value_get_print_value): Call it.
(value_get_print_value): Add varobj argument instead of pretty
printer argument. Update all callers.
* python/python-utils.c (py_gil_restore, make_cleanup_py_restore_gil):
Remove.
* value.h (internal_function_fn): Add GDBARCH and LANGUAGE argument.
(call_internal_function): Likewise.
* value.c (call_internal_function): Likewise. Pass to handler.
* eval.c (evaluate_subexp_standard): Update call.
* python/python-function.c: Include "language.h".
(fnpy_call): Add GDBARCH and LANGAUAGE arguments and call
make_cleanup_python_env.
* python/python-value.c (builtin_type_pyint, builtin_type_pyfloat,
builtin_type_pylong, builtin_type_pybool, builtin_type_pychar,
valpy_str): Use python_gdbarch and python_language instead of
current_gdbarch and current_language.
* python/python-type.c (typy_lookup_typename): Likewise.
2009-07-02 19:04:23 +02:00
|
|
|
|
cleanup = ensure_python_env (get_current_arch (), current_language);
|
2009-02-06 22:33:59 +01:00
|
|
|
|
|
|
|
|
|
if (! obj)
|
|
|
|
|
error (_("Invalid invocation of Python command object."));
|
|
|
|
|
if (! PyObject_HasAttr ((PyObject *) obj, invoke_cst))
|
|
|
|
|
{
|
|
|
|
|
if (obj->command->prefixname)
|
|
|
|
|
{
|
|
|
|
|
/* A prefix command does not need an invoke method. */
|
|
|
|
|
do_cleanups (cleanup);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
error (_("Python command object missing 'invoke' method."));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (! args)
|
|
|
|
|
args = "";
|
|
|
|
|
argobj = PyUnicode_Decode (args, strlen (args), host_charset (), NULL);
|
|
|
|
|
if (! argobj)
|
2010-10-13 15:24:40 +02:00
|
|
|
|
{
|
|
|
|
|
gdbpy_print_stack ();
|
|
|
|
|
error (_("Could not convert arguments to Python string."));
|
|
|
|
|
}
|
2009-02-06 22:33:59 +01:00
|
|
|
|
|
|
|
|
|
ttyobj = from_tty ? Py_True : Py_False;
|
|
|
|
|
Py_INCREF (ttyobj);
|
|
|
|
|
result = PyObject_CallMethodObjArgs ((PyObject *) obj, invoke_cst, argobj,
|
|
|
|
|
ttyobj, NULL);
|
|
|
|
|
Py_DECREF (argobj);
|
|
|
|
|
Py_DECREF (ttyobj);
|
2010-05-25 17:27:17 +02:00
|
|
|
|
|
2009-02-06 22:33:59 +01:00
|
|
|
|
if (! result)
|
|
|
|
|
{
|
|
|
|
|
PyObject *ptype, *pvalue, *ptraceback;
|
2010-05-25 17:27:17 +02:00
|
|
|
|
char *msg;
|
2009-02-06 22:33:59 +01:00
|
|
|
|
|
|
|
|
|
PyErr_Fetch (&ptype, &pvalue, &ptraceback);
|
|
|
|
|
|
2010-05-25 17:27:17 +02:00
|
|
|
|
/* Try to fetch an error message contained within ptype, pvalue.
|
|
|
|
|
When fetching the error message we need to make our own copy,
|
|
|
|
|
we no longer own ptype, pvalue after the call to PyErr_Restore. */
|
2009-02-06 22:33:59 +01:00
|
|
|
|
|
2010-05-25 17:27:17 +02:00
|
|
|
|
msg = gdbpy_exception_to_string (ptype, pvalue);
|
|
|
|
|
make_cleanup (xfree, msg);
|
|
|
|
|
|
|
|
|
|
if (msg == NULL)
|
|
|
|
|
{
|
|
|
|
|
/* An error occurred computing the string representation of the
|
|
|
|
|
error message. This is rare, but we should inform the user. */
|
|
|
|
|
printf_filtered (_("An error occurred in a Python command\n"
|
2011-01-06 01:57:05 +01:00
|
|
|
|
"and then another occurred computing the "
|
|
|
|
|
"error message.\n"));
|
2009-02-06 22:33:59 +01:00
|
|
|
|
gdbpy_print_stack ();
|
|
|
|
|
}
|
2010-05-25 17:27:17 +02:00
|
|
|
|
|
|
|
|
|
/* Don't print the stack for gdb.GdbError exceptions.
|
|
|
|
|
It is generally used to flag user errors.
|
|
|
|
|
|
|
|
|
|
We also don't want to print "Error occurred in Python command"
|
|
|
|
|
for user errors. However, a missing message for gdb.GdbError
|
|
|
|
|
exceptions is arguably a bug, so we flag it as such. */
|
|
|
|
|
|
|
|
|
|
if (! PyErr_GivenExceptionMatches (ptype, gdbpy_gdberror_exc)
|
|
|
|
|
|| msg == NULL || *msg == '\0')
|
2009-02-06 22:33:59 +01:00
|
|
|
|
{
|
|
|
|
|
PyErr_Restore (ptype, pvalue, ptraceback);
|
|
|
|
|
gdbpy_print_stack ();
|
2010-05-25 17:27:17 +02:00
|
|
|
|
if (msg != NULL && *msg != '\0')
|
|
|
|
|
error (_("Error occurred in Python command: %s"), msg);
|
|
|
|
|
else
|
|
|
|
|
error (_("Error occurred in Python command."));
|
2009-02-06 22:33:59 +01:00
|
|
|
|
}
|
2010-05-25 17:27:17 +02:00
|
|
|
|
else
|
2010-10-19 22:11:37 +02:00
|
|
|
|
{
|
|
|
|
|
Py_XDECREF (ptype);
|
|
|
|
|
Py_XDECREF (pvalue);
|
|
|
|
|
Py_XDECREF (ptraceback);
|
|
|
|
|
error ("%s", msg);
|
|
|
|
|
}
|
2009-02-06 22:33:59 +01:00
|
|
|
|
}
|
2010-05-25 17:27:17 +02:00
|
|
|
|
|
2009-02-06 22:33:59 +01:00
|
|
|
|
Py_DECREF (result);
|
|
|
|
|
do_cleanups (cleanup);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Called by gdb for command completion. */
|
2011-09-08 21:51:27 +02:00
|
|
|
|
|
* ada-lang.c (ada_make_symbol_completion_list): Return a VEC.
* breakpoint.c (catch_syscall_completer): Return a VEC.
* cli/cli-cmds.c (complete_command): Update.
* cli/cli-decode.c (complete_on_cmdlist): Return a VEC.
(complete_on_enum): Likewise.
* command.h: Include gdb_vecs.h.
(completer_ftype): Change return type.
(complete_on_cmdlist, complete_on_enum): Likewise.
* completer.c (noop_completer, filename_completer)
(location_completer): Return a VEC.
(add_struct_fields): Remove 'nextp' argument. Change 'output'
to a VEC.
(expression_completer, complete_line_internal, complete_line)
(command_completer): Return a VEC.
(gdb_completion_word_break_characters, line_completion_function):
Update.
* completer.h: Include gdb_vecs.h.
(complete_line, noop_completer, filename_completer)
(expression_completer, location_completer, command_completer):
Update.
* f-lang.c (f_word_break_characters): Return a VEC.
* interps.c (interpreter_completer): Return a VEC.
* language.h (struct language_defn)
<la_make_symbol_completion_list>: Return a VEC.
* python/py-cmd.c (cmdpy_completer): Return a VEC.
* symtab.c (free_completion_list): Take a VEC.
(return_val_size, return_val_index): Remove.
(return_val): Now a VEC.
(completion_list_add_name): Update.
(default_make_symbol_completion_list_break_on)
(default_make_symbol_completion_list, make_symbol_completion_list)
(make_symbol_completion_list_fn, make_file_symbol_completion_list):
Return a VEC.
(add_filename_to_list): Update.
(struct add_partial_filename_data) <list_used, list_alloced>: Remove.
<list>: Now a VEC.
(maybe_add_partial_symtab_filename): Update.
(make_source_files_completion_list): Return a VEC.
* symtab.h (default_make_symbol_completion_list_break_on)
(default_make_symbol_completion_list, make_symbol_completion_list)
(make_symbol_completion_list_fn, make_file_symbol_completion_list)
(make_source_files_completion_list): Update.
2012-06-13 17:47:16 +02:00
|
|
|
|
static VEC (char_ptr) *
|
Constify strings in tracepoint.c, lookup_cmd and the completers.
This is sort of a continuation of Keith's parse_exp_1 constification
patch. It started out by undoing these bits:
@@ -754,9 +754,12 @@ validate_actionline (char **line, struct
tmp_p = p;
for (loc = t->base.loc; loc; loc = loc->next)
{
- p = tmp_p;
- exp = parse_exp_1 (&p, loc->address,
+ const char *q;
+
+ q = tmp_p;
+ exp = parse_exp_1 (&q, loc->address,
block_for_pc (loc->address), 1);
+ p = (char *) q;
and progressively making more things const upwards, fixing fallout,
rinse repeat, until GDB built again (--enable-targets=all).
That ended up constifying lookup_cmd/add_cmd and (lots of) friends,
and the completers.
I didn't try to constify the command hooks themselves, because I know
upfront there are commands that write to the command string argument,
and I think I managed to stop at a nice non-hacky split point already.
I think the only non-really-super-obvious changes are
tracepoint.c:validate_actionline, and tracepoint.c:trace_dump_actions.
The rest is just mostly about 'char *' => 'const char *', 'char **'=>
'const char **', and the occasional (e.g., deprecated_cmd_warning)
case of 'char **'=> 'const char *', where/when I noticed that nothing
actually cares about the pointer to pointer output.
Tested on x86_64 Fedora 17, native and gdbserver.
gdb/
2013-03-13 Pedro Alves <palves@redhat.com>
* ada-lang.c (struct add_partial_datum) <text, text0, word>: Make
fields const.
(ada_make_symbol_completion_list): Make "text0" parameter const.
* ax-gdb.c (agent_eval_command_one): Make "exp" parameter const.
* breakpoint.c (condition_completer): Make "text" and "word"
parameters const. Adjust.
(check_tracepoint_command): Adjust to validate_actionline
prototype change.
(catch_syscall_completer): Make "text" and "word" parameters
const.
* cli/cli-cmds.c (show_user): Make "comname" local const.
(valid_command_p): Make "command" parameter const.
(alias_command): Make "alias_prefix" and "command_prefix" locals
const.
* cli/cli-decode.c (add_cmd): Make "name" parameter const.
(add_alias_cmd): Make "name" and "oldname" parameters const.
Adjust. No longer make copy of OLDNAME.
(add_prefix_cmd, add_abbrev_prefix_cmd, add_set_or_show_cmd)
(add_setshow_cmd_full, add_setshow_enum_cmd)
(add_setshow_auto_boolean_cmd, add_setshow_boolean_cmd)
(add_setshow_filename_cmd, add_setshow_string_cmd)
(add_setshow_string_noescape_cmd)
(add_setshow_optional_filename_cmd, add_setshow_integer_cmd)
(add_setshow_uinteger_cmd, add_setshow_zinteger_cmd)
(add_setshow_zuinteger_unlimited_cmd, add_setshow_zuinteger_cmd)
(delete_cmd, add_info, add_info_alias, add_com, add_com_alias):
Make "name" parameter const.
(help_cmd): Rename "command" parameter to "arg". New const local
"command".
(find_cmd): Make "command" parameter const.
(lookup_cmd_1): Make "text" parameter pointer to const. Adjust to
deprecated_cmd_warning prototype change.
(undef_cmd_error): Make "cmdtype" parameter const.
(lookup_cmd): Make "line" parameter const.
(deprecated_cmd_warning): Change type of "text" parameter to
pointer to const char, from pointer to pointer to char. Adjust.
(lookup_cmd_composition): Make "text" parameter const.
(complete_on_cmdlist, complete_on_enum): Make "text" and "word"
parameters const.
* cli/cli-decode.h (struct cmd_list_element) <name>: Make field
const.
* cli/cli-script.c (validate_comname): Make "tem" local const.
(define_command): New const local "tem_c". Use it in calls to
lookup_cmd.
(document_command): Make "tem" and "comfull" locals const.
(show_user_1): Make "prefix" and "name" parameters const.
* cli-script.h (show_user_1): Make "prefix" and "name" parameters
const.
* command.h (add_cmd, add_alias_cmd, add_prefix_cmd)
(add_abbrev_prefix_cmd, completer_ftype, lookup_cmd, lookup_cmd_1)
(deprecated_cmd_warning, lookup_cmd_composition, add_com)
(add_com_alias, add_info, add_info_alias, complete_on_cmdlist)
(complete_on_enum, add_setshow_enum_cmd)
(add_setshow_auto_boolean_cmd, add_setshow_boolean_cmd)
(add_setshow_filename_cmd, add_setshow_string_cmd)
(add_setshow_string_noescape_cmd)
(add_setshow_optional_filename_cmd, add_setshow_integer_cmd)
(add_setshow_uinteger_cmd, add_setshow_zinteger_cmd)
(add_setshow_zuinteger_cmd, add_setshow_zuinteger_unlimited_cmd):
Change prototypes, constifying strings.
* completer.c (noop_completer, filename_completer): Make "text"
and "prefix" parameters const.
(location_completer, expression_completer)
(complete_line_internal): Make "text" and "prefix" parameters
const and adjust.
(command_completer, signal_completer): Make "text" and "prefix"
parameters const.
* completer.h (noop_completer, filename_completer)
(expression_completer, location_completer, command_completer)
(signal_completer): Change prototypes.
* corefile.c (complete_set_gnutarget): Make "text" and "word"
parameters const.
* cp-abi.c (cp_abi_completer): Likewise.
* expression.h (parse_expression_for_completion): Change
prototype.
* f-lang.c (f_make_symbol_completion_list): Make "text" and "word"
parameters const.
* infcmd.c (_initialize_infcmd): Make "cmd_name" local const.
* infrun.c (handle_completer): Make "text" and "word" parameters
const.
* interps.c (interpreter_completer): Make "text" and "word"
parameters const.
* language.h (struct language_defn)
<la_make_symbol_completion_list>: Make "text" and "word"
parameters const.
* parse.c (parse_exp_1): Move const hack to parse_exp_in_context.
(parse_exp_in_context): Rename to ...
(parse_exp_in_context_1): ... this.
(parse_exp_in_context): Reimplement, with const hack from
parse_exp_1.
(parse_expression_for_completion): Make "string" parameter const.
* printcmd.c (decode_format): Make "string_ptr" parameter pointer
to pointer to const char. Adjust.
(print_command_1): Make "exp" parameter const.
(output_command): Rename to ...
(output_command_const): ... this. Make "exp" parameter const.
(output_command): Reimplement.
(x_command): Adjust.
(display_command): Rename "exp" parameter to "arg". New "exp"
local, const version of "arg".
* python/py-auto-load.c (gdbpy_initialize_auto_load): Make
"cmd_name" local const.
* python/py-cmd.c (cmdpy_destroyer): Cast const away in xfree
call.
(cmdpy_completer): Make "text" and "word" parameters const.
(gdbpy_parse_command_name): Make "prefix_text2" local const.
* python/py-param.c (add_setshow_generic): Make "tmp_name" local
const.
* remote.c (_initialize_remote): Make "cmd_name" local const.
* symtab.c (language_search_unquoted_string): Make "text" and "p"
parameters const. Adjust.
(completion_list_add_fields): Make "sym_text", "text" and "word"
parameters const.
(struct add_name_data) <sym_text, text, word>: Make fields const.
(default_make_symbol_completion_list_break_on): Make "text" and
"word" parameters const. Adjust locals.
(default_make_symbol_completion_list)
(make_symbol_completion_list, make_symbol_completion_type)
(make_symbol_completion_list_fn): Make "text" and "word"
parameters const.
(make_file_symbol_completion_list): Make "text", "word" and
"srcfile" parameters const. Adjust locals.
(add_filename_to_list): Make "text" and "word" parameters const.
(struct add_partial_filename_data) <text, word>: Make fields
const.
(make_source_files_completion_list): Make "text" and "word"
parameters const.
* symtab.h (default_make_symbol_completion_list_break_on)
(default_make_symbol_completion_list, make_symbol_completion_list)
(make_symbol_completion_type enum type_code)
(make_symbol_completion_list_fn make_file_symbol_completion_list)
(make_source_files_completion_list): Change prototype.
* top.c (execute_command): Adjust to pass pointer to pointer to
const char to lookup_cmd, and to deprecated_cmd_warning prototype
change.
(set_verbose): Make "cmdname" local const.
* tracepoint.c (decode_agent_options): Make "exp" parameter const,
and adjust.
(validate_actionline): Make "line" parameter a pointer to const
char, and adjust.
(encode_actions_1): Make "action_exp" local const, and adjust.
(encode_actions): Adjust.
(replace_comma): Delete.
(trace_dump_actions): Make "action_exp" and "next_comma" locals
const, and adjust. Don't frob the action string while splitting
it at commas. Instead, make a copy of each split substring in
turn.
(trace_dump_command): Adjust to validate_actionline prototype
change.
* tracepoint.h (decode_agent_options, decode_agent_options)
(encode_actions, validate_actionline): Change prototypes.
* valprint.h (output_command): Delete declaration.
(output_command_const): Declare.
* value.c (function_destroyer): Cast const away in xfree call.
2013-03-13 19:34:55 +01:00
|
|
|
|
cmdpy_completer (struct cmd_list_element *command,
|
|
|
|
|
const char *text, const char *word)
|
2009-02-06 22:33:59 +01:00
|
|
|
|
{
|
|
|
|
|
cmdpy_object *obj = (cmdpy_object *) get_cmd_context (command);
|
|
|
|
|
PyObject *textobj, *wordobj, *resultobj = NULL;
|
* ada-lang.c (ada_make_symbol_completion_list): Return a VEC.
* breakpoint.c (catch_syscall_completer): Return a VEC.
* cli/cli-cmds.c (complete_command): Update.
* cli/cli-decode.c (complete_on_cmdlist): Return a VEC.
(complete_on_enum): Likewise.
* command.h: Include gdb_vecs.h.
(completer_ftype): Change return type.
(complete_on_cmdlist, complete_on_enum): Likewise.
* completer.c (noop_completer, filename_completer)
(location_completer): Return a VEC.
(add_struct_fields): Remove 'nextp' argument. Change 'output'
to a VEC.
(expression_completer, complete_line_internal, complete_line)
(command_completer): Return a VEC.
(gdb_completion_word_break_characters, line_completion_function):
Update.
* completer.h: Include gdb_vecs.h.
(complete_line, noop_completer, filename_completer)
(expression_completer, location_completer, command_completer):
Update.
* f-lang.c (f_word_break_characters): Return a VEC.
* interps.c (interpreter_completer): Return a VEC.
* language.h (struct language_defn)
<la_make_symbol_completion_list>: Return a VEC.
* python/py-cmd.c (cmdpy_completer): Return a VEC.
* symtab.c (free_completion_list): Take a VEC.
(return_val_size, return_val_index): Remove.
(return_val): Now a VEC.
(completion_list_add_name): Update.
(default_make_symbol_completion_list_break_on)
(default_make_symbol_completion_list, make_symbol_completion_list)
(make_symbol_completion_list_fn, make_file_symbol_completion_list):
Return a VEC.
(add_filename_to_list): Update.
(struct add_partial_filename_data) <list_used, list_alloced>: Remove.
<list>: Now a VEC.
(maybe_add_partial_symtab_filename): Update.
(make_source_files_completion_list): Return a VEC.
* symtab.h (default_make_symbol_completion_list_break_on)
(default_make_symbol_completion_list, make_symbol_completion_list)
(make_symbol_completion_list_fn, make_file_symbol_completion_list)
(make_source_files_completion_list): Update.
2012-06-13 17:47:16 +02:00
|
|
|
|
VEC (char_ptr) *result = NULL;
|
2009-02-06 22:33:59 +01:00
|
|
|
|
struct cleanup *cleanup;
|
|
|
|
|
|
* python/python-internal.h (struct language_defn): Declare.
(python_gdbarch, python_language): Likewise.
(ensure_python_env): Add prototype.
(make_cleanup_py_restore_gil): Remove prototype.
* python/python.c: Include "arch-utils.h", "value.h" and "language.h".
(python_gdbarch, python_language): New global variables.
(struct python_env): New data type.
(ensure_python_env, restore_python_env): New functions.
(eval_python_from_control_command): Call ensure_python_env to
install current architecture and language.
(python_command, gdbpy_new_objfile): Likewise.
* python/python-cmd.c: Include "arch-utils.h" and "language.h".
(cmdpy_destroyer, cmdpy_function, cmdpy_completer): Call
ensure_python_env.
* python/python-type.c (clean_up_objfile_types): Likewise.
* python/python-objfile.c: Include "language.h".
(clean_up_objfile): Call ensure_python_env.
* python/python-prettyprint.c (apply_val_pretty_printer): Likewise.
(apply_varobj_pretty_printer): Do not call PyGILState_Ensure.
* varobj.c (varobj_ensure_python_env): New helper function.
(varobj_get_display_hint, update_dynamic_varobj_children,
install_default_visualizer, varobj_set_visualizer, free_variable,
value_get_print_value): Call it.
(value_get_print_value): Add varobj argument instead of pretty
printer argument. Update all callers.
* python/python-utils.c (py_gil_restore, make_cleanup_py_restore_gil):
Remove.
* value.h (internal_function_fn): Add GDBARCH and LANGUAGE argument.
(call_internal_function): Likewise.
* value.c (call_internal_function): Likewise. Pass to handler.
* eval.c (evaluate_subexp_standard): Update call.
* python/python-function.c: Include "language.h".
(fnpy_call): Add GDBARCH and LANGAUAGE arguments and call
make_cleanup_python_env.
* python/python-value.c (builtin_type_pyint, builtin_type_pyfloat,
builtin_type_pylong, builtin_type_pybool, builtin_type_pychar,
valpy_str): Use python_gdbarch and python_language instead of
current_gdbarch and current_language.
* python/python-type.c (typy_lookup_typename): Likewise.
2009-07-02 19:04:23 +02:00
|
|
|
|
cleanup = ensure_python_env (get_current_arch (), current_language);
|
2009-02-06 22:33:59 +01:00
|
|
|
|
|
|
|
|
|
if (! obj)
|
|
|
|
|
error (_("Invalid invocation of Python command object."));
|
|
|
|
|
if (! PyObject_HasAttr ((PyObject *) obj, complete_cst))
|
|
|
|
|
{
|
|
|
|
|
/* If there is no complete method, don't error -- instead, just
|
|
|
|
|
say that there are no completions. */
|
|
|
|
|
goto done;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
textobj = PyUnicode_Decode (text, strlen (text), host_charset (), NULL);
|
|
|
|
|
if (! textobj)
|
|
|
|
|
error (_("Could not convert argument to Python string."));
|
|
|
|
|
wordobj = PyUnicode_Decode (word, strlen (word), host_charset (), NULL);
|
|
|
|
|
if (! wordobj)
|
|
|
|
|
error (_("Could not convert argument to Python string."));
|
|
|
|
|
|
|
|
|
|
resultobj = PyObject_CallMethodObjArgs ((PyObject *) obj, complete_cst,
|
|
|
|
|
textobj, wordobj, NULL);
|
|
|
|
|
Py_DECREF (textobj);
|
|
|
|
|
Py_DECREF (wordobj);
|
|
|
|
|
if (! resultobj)
|
|
|
|
|
{
|
|
|
|
|
/* Just swallow errors here. */
|
|
|
|
|
PyErr_Clear ();
|
|
|
|
|
goto done;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result = NULL;
|
2013-05-20 22:21:55 +02:00
|
|
|
|
if (PyInt_Check (resultobj))
|
2009-02-06 22:33:59 +01:00
|
|
|
|
{
|
2013-05-20 22:21:55 +02:00
|
|
|
|
/* User code may also return one of the completion constants,
|
|
|
|
|
thus requesting that sort of completion. */
|
|
|
|
|
long value;
|
|
|
|
|
|
|
|
|
|
if (! gdb_py_int_as_long (resultobj, &value))
|
|
|
|
|
{
|
|
|
|
|
/* Ignore. */
|
|
|
|
|
PyErr_Clear ();
|
|
|
|
|
}
|
|
|
|
|
else if (value >= 0 && value < (long) N_COMPLETERS)
|
|
|
|
|
result = completers[value].completer (command, text, word);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
PyObject *iter = PyObject_GetIter (resultobj);
|
|
|
|
|
PyObject *elt;
|
2010-05-17 23:23:25 +02:00
|
|
|
|
|
2013-05-20 22:21:55 +02:00
|
|
|
|
if (iter == NULL)
|
2009-02-06 22:33:59 +01:00
|
|
|
|
goto done;
|
|
|
|
|
|
2013-05-20 22:21:55 +02:00
|
|
|
|
while ((elt = PyIter_Next (iter)) != NULL)
|
2009-02-06 22:33:59 +01:00
|
|
|
|
{
|
* ada-lang.c (ada_make_symbol_completion_list): Return a VEC.
* breakpoint.c (catch_syscall_completer): Return a VEC.
* cli/cli-cmds.c (complete_command): Update.
* cli/cli-decode.c (complete_on_cmdlist): Return a VEC.
(complete_on_enum): Likewise.
* command.h: Include gdb_vecs.h.
(completer_ftype): Change return type.
(complete_on_cmdlist, complete_on_enum): Likewise.
* completer.c (noop_completer, filename_completer)
(location_completer): Return a VEC.
(add_struct_fields): Remove 'nextp' argument. Change 'output'
to a VEC.
(expression_completer, complete_line_internal, complete_line)
(command_completer): Return a VEC.
(gdb_completion_word_break_characters, line_completion_function):
Update.
* completer.h: Include gdb_vecs.h.
(complete_line, noop_completer, filename_completer)
(expression_completer, location_completer, command_completer):
Update.
* f-lang.c (f_word_break_characters): Return a VEC.
* interps.c (interpreter_completer): Return a VEC.
* language.h (struct language_defn)
<la_make_symbol_completion_list>: Return a VEC.
* python/py-cmd.c (cmdpy_completer): Return a VEC.
* symtab.c (free_completion_list): Take a VEC.
(return_val_size, return_val_index): Remove.
(return_val): Now a VEC.
(completion_list_add_name): Update.
(default_make_symbol_completion_list_break_on)
(default_make_symbol_completion_list, make_symbol_completion_list)
(make_symbol_completion_list_fn, make_file_symbol_completion_list):
Return a VEC.
(add_filename_to_list): Update.
(struct add_partial_filename_data) <list_used, list_alloced>: Remove.
<list>: Now a VEC.
(maybe_add_partial_symtab_filename): Update.
(make_source_files_completion_list): Return a VEC.
* symtab.h (default_make_symbol_completion_list_break_on)
(default_make_symbol_completion_list, make_symbol_completion_list)
(make_symbol_completion_list_fn, make_file_symbol_completion_list)
(make_source_files_completion_list): Update.
2012-06-13 17:47:16 +02:00
|
|
|
|
char *item;
|
2010-05-17 23:23:25 +02:00
|
|
|
|
|
2013-05-20 22:21:55 +02:00
|
|
|
|
if (! gdbpy_is_string (elt))
|
2009-02-06 22:33:59 +01:00
|
|
|
|
{
|
|
|
|
|
/* Skip problem elements. */
|
2013-05-20 22:21:55 +02:00
|
|
|
|
Py_DECREF (elt);
|
2009-02-06 22:33:59 +01:00
|
|
|
|
continue;
|
|
|
|
|
}
|
* ada-lang.c (ada_make_symbol_completion_list): Return a VEC.
* breakpoint.c (catch_syscall_completer): Return a VEC.
* cli/cli-cmds.c (complete_command): Update.
* cli/cli-decode.c (complete_on_cmdlist): Return a VEC.
(complete_on_enum): Likewise.
* command.h: Include gdb_vecs.h.
(completer_ftype): Change return type.
(complete_on_cmdlist, complete_on_enum): Likewise.
* completer.c (noop_completer, filename_completer)
(location_completer): Return a VEC.
(add_struct_fields): Remove 'nextp' argument. Change 'output'
to a VEC.
(expression_completer, complete_line_internal, complete_line)
(command_completer): Return a VEC.
(gdb_completion_word_break_characters, line_completion_function):
Update.
* completer.h: Include gdb_vecs.h.
(complete_line, noop_completer, filename_completer)
(expression_completer, location_completer, command_completer):
Update.
* f-lang.c (f_word_break_characters): Return a VEC.
* interps.c (interpreter_completer): Return a VEC.
* language.h (struct language_defn)
<la_make_symbol_completion_list>: Return a VEC.
* python/py-cmd.c (cmdpy_completer): Return a VEC.
* symtab.c (free_completion_list): Take a VEC.
(return_val_size, return_val_index): Remove.
(return_val): Now a VEC.
(completion_list_add_name): Update.
(default_make_symbol_completion_list_break_on)
(default_make_symbol_completion_list, make_symbol_completion_list)
(make_symbol_completion_list_fn, make_file_symbol_completion_list):
Return a VEC.
(add_filename_to_list): Update.
(struct add_partial_filename_data) <list_used, list_alloced>: Remove.
<list>: Now a VEC.
(maybe_add_partial_symtab_filename): Update.
(make_source_files_completion_list): Return a VEC.
* symtab.h (default_make_symbol_completion_list_break_on)
(default_make_symbol_completion_list, make_symbol_completion_list)
(make_symbol_completion_list_fn, make_file_symbol_completion_list)
(make_source_files_completion_list): Update.
2012-06-13 17:47:16 +02:00
|
|
|
|
item = python_string_to_host_string (elt);
|
2013-05-20 22:21:55 +02:00
|
|
|
|
Py_DECREF (elt);
|
* ada-lang.c (ada_make_symbol_completion_list): Return a VEC.
* breakpoint.c (catch_syscall_completer): Return a VEC.
* cli/cli-cmds.c (complete_command): Update.
* cli/cli-decode.c (complete_on_cmdlist): Return a VEC.
(complete_on_enum): Likewise.
* command.h: Include gdb_vecs.h.
(completer_ftype): Change return type.
(complete_on_cmdlist, complete_on_enum): Likewise.
* completer.c (noop_completer, filename_completer)
(location_completer): Return a VEC.
(add_struct_fields): Remove 'nextp' argument. Change 'output'
to a VEC.
(expression_completer, complete_line_internal, complete_line)
(command_completer): Return a VEC.
(gdb_completion_word_break_characters, line_completion_function):
Update.
* completer.h: Include gdb_vecs.h.
(complete_line, noop_completer, filename_completer)
(expression_completer, location_completer, command_completer):
Update.
* f-lang.c (f_word_break_characters): Return a VEC.
* interps.c (interpreter_completer): Return a VEC.
* language.h (struct language_defn)
<la_make_symbol_completion_list>: Return a VEC.
* python/py-cmd.c (cmdpy_completer): Return a VEC.
* symtab.c (free_completion_list): Take a VEC.
(return_val_size, return_val_index): Remove.
(return_val): Now a VEC.
(completion_list_add_name): Update.
(default_make_symbol_completion_list_break_on)
(default_make_symbol_completion_list, make_symbol_completion_list)
(make_symbol_completion_list_fn, make_file_symbol_completion_list):
Return a VEC.
(add_filename_to_list): Update.
(struct add_partial_filename_data) <list_used, list_alloced>: Remove.
<list>: Now a VEC.
(maybe_add_partial_symtab_filename): Update.
(make_source_files_completion_list): Return a VEC.
* symtab.h (default_make_symbol_completion_list_break_on)
(default_make_symbol_completion_list, make_symbol_completion_list)
(make_symbol_completion_list_fn, make_file_symbol_completion_list)
(make_source_files_completion_list): Update.
2012-06-13 17:47:16 +02:00
|
|
|
|
if (item == NULL)
|
2010-10-13 15:24:40 +02:00
|
|
|
|
{
|
|
|
|
|
/* Skip problem elements. */
|
|
|
|
|
PyErr_Clear ();
|
|
|
|
|
continue;
|
|
|
|
|
}
|
* ada-lang.c (ada_make_symbol_completion_list): Return a VEC.
* breakpoint.c (catch_syscall_completer): Return a VEC.
* cli/cli-cmds.c (complete_command): Update.
* cli/cli-decode.c (complete_on_cmdlist): Return a VEC.
(complete_on_enum): Likewise.
* command.h: Include gdb_vecs.h.
(completer_ftype): Change return type.
(complete_on_cmdlist, complete_on_enum): Likewise.
* completer.c (noop_completer, filename_completer)
(location_completer): Return a VEC.
(add_struct_fields): Remove 'nextp' argument. Change 'output'
to a VEC.
(expression_completer, complete_line_internal, complete_line)
(command_completer): Return a VEC.
(gdb_completion_word_break_characters, line_completion_function):
Update.
* completer.h: Include gdb_vecs.h.
(complete_line, noop_completer, filename_completer)
(expression_completer, location_completer, command_completer):
Update.
* f-lang.c (f_word_break_characters): Return a VEC.
* interps.c (interpreter_completer): Return a VEC.
* language.h (struct language_defn)
<la_make_symbol_completion_list>: Return a VEC.
* python/py-cmd.c (cmdpy_completer): Return a VEC.
* symtab.c (free_completion_list): Take a VEC.
(return_val_size, return_val_index): Remove.
(return_val): Now a VEC.
(completion_list_add_name): Update.
(default_make_symbol_completion_list_break_on)
(default_make_symbol_completion_list, make_symbol_completion_list)
(make_symbol_completion_list_fn, make_file_symbol_completion_list):
Return a VEC.
(add_filename_to_list): Update.
(struct add_partial_filename_data) <list_used, list_alloced>: Remove.
<list>: Now a VEC.
(maybe_add_partial_symtab_filename): Update.
(make_source_files_completion_list): Return a VEC.
* symtab.h (default_make_symbol_completion_list_break_on)
(default_make_symbol_completion_list, make_symbol_completion_list)
(make_symbol_completion_list_fn, make_file_symbol_completion_list)
(make_source_files_completion_list): Update.
2012-06-13 17:47:16 +02:00
|
|
|
|
VEC_safe_push (char_ptr, result, item);
|
2009-02-06 22:33:59 +01:00
|
|
|
|
}
|
2010-05-17 23:23:25 +02:00
|
|
|
|
|
2013-05-20 22:21:55 +02:00
|
|
|
|
Py_DECREF (iter);
|
|
|
|
|
|
|
|
|
|
/* If we got some results, ignore problems. Otherwise, report
|
|
|
|
|
the problem. */
|
|
|
|
|
if (result != NULL && PyErr_Occurred ())
|
|
|
|
|
PyErr_Clear ();
|
2009-02-06 22:33:59 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
done:
|
|
|
|
|
|
2013-05-20 22:34:49 +02:00
|
|
|
|
Py_XDECREF (resultobj);
|
2009-02-06 22:33:59 +01:00
|
|
|
|
do_cleanups (cleanup);
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Helper for cmdpy_init which locates the command list to use and
|
|
|
|
|
pulls out the command name.
|
2013-11-29 21:00:47 +01:00
|
|
|
|
|
2011-09-08 21:51:27 +02:00
|
|
|
|
NAME is the command name list. The final word in the list is the
|
2009-02-06 22:33:59 +01:00
|
|
|
|
name of the new command. All earlier words must be existing prefix
|
|
|
|
|
commands.
|
|
|
|
|
|
|
|
|
|
*BASE_LIST is set to the final prefix command's list of
|
|
|
|
|
*sub-commands.
|
2013-11-29 21:00:47 +01:00
|
|
|
|
|
2010-04-29 17:45:57 +02:00
|
|
|
|
START_LIST is the list in which the search starts.
|
|
|
|
|
|
2009-02-06 22:33:59 +01:00
|
|
|
|
This function returns the xmalloc()d name of the new command. On
|
|
|
|
|
error sets the Python error and returns NULL. */
|
2011-09-08 21:51:27 +02:00
|
|
|
|
|
2010-04-29 17:45:57 +02:00
|
|
|
|
char *
|
2011-09-08 21:51:27 +02:00
|
|
|
|
gdbpy_parse_command_name (const char *name,
|
2010-04-29 17:45:57 +02:00
|
|
|
|
struct cmd_list_element ***base_list,
|
|
|
|
|
struct cmd_list_element **start_list)
|
2009-02-06 22:33:59 +01:00
|
|
|
|
{
|
|
|
|
|
struct cmd_list_element *elt;
|
2011-09-08 21:51:27 +02:00
|
|
|
|
int len = strlen (name);
|
2009-02-06 22:33:59 +01:00
|
|
|
|
int i, lastchar;
|
Constify strings in tracepoint.c, lookup_cmd and the completers.
This is sort of a continuation of Keith's parse_exp_1 constification
patch. It started out by undoing these bits:
@@ -754,9 +754,12 @@ validate_actionline (char **line, struct
tmp_p = p;
for (loc = t->base.loc; loc; loc = loc->next)
{
- p = tmp_p;
- exp = parse_exp_1 (&p, loc->address,
+ const char *q;
+
+ q = tmp_p;
+ exp = parse_exp_1 (&q, loc->address,
block_for_pc (loc->address), 1);
+ p = (char *) q;
and progressively making more things const upwards, fixing fallout,
rinse repeat, until GDB built again (--enable-targets=all).
That ended up constifying lookup_cmd/add_cmd and (lots of) friends,
and the completers.
I didn't try to constify the command hooks themselves, because I know
upfront there are commands that write to the command string argument,
and I think I managed to stop at a nice non-hacky split point already.
I think the only non-really-super-obvious changes are
tracepoint.c:validate_actionline, and tracepoint.c:trace_dump_actions.
The rest is just mostly about 'char *' => 'const char *', 'char **'=>
'const char **', and the occasional (e.g., deprecated_cmd_warning)
case of 'char **'=> 'const char *', where/when I noticed that nothing
actually cares about the pointer to pointer output.
Tested on x86_64 Fedora 17, native and gdbserver.
gdb/
2013-03-13 Pedro Alves <palves@redhat.com>
* ada-lang.c (struct add_partial_datum) <text, text0, word>: Make
fields const.
(ada_make_symbol_completion_list): Make "text0" parameter const.
* ax-gdb.c (agent_eval_command_one): Make "exp" parameter const.
* breakpoint.c (condition_completer): Make "text" and "word"
parameters const. Adjust.
(check_tracepoint_command): Adjust to validate_actionline
prototype change.
(catch_syscall_completer): Make "text" and "word" parameters
const.
* cli/cli-cmds.c (show_user): Make "comname" local const.
(valid_command_p): Make "command" parameter const.
(alias_command): Make "alias_prefix" and "command_prefix" locals
const.
* cli/cli-decode.c (add_cmd): Make "name" parameter const.
(add_alias_cmd): Make "name" and "oldname" parameters const.
Adjust. No longer make copy of OLDNAME.
(add_prefix_cmd, add_abbrev_prefix_cmd, add_set_or_show_cmd)
(add_setshow_cmd_full, add_setshow_enum_cmd)
(add_setshow_auto_boolean_cmd, add_setshow_boolean_cmd)
(add_setshow_filename_cmd, add_setshow_string_cmd)
(add_setshow_string_noescape_cmd)
(add_setshow_optional_filename_cmd, add_setshow_integer_cmd)
(add_setshow_uinteger_cmd, add_setshow_zinteger_cmd)
(add_setshow_zuinteger_unlimited_cmd, add_setshow_zuinteger_cmd)
(delete_cmd, add_info, add_info_alias, add_com, add_com_alias):
Make "name" parameter const.
(help_cmd): Rename "command" parameter to "arg". New const local
"command".
(find_cmd): Make "command" parameter const.
(lookup_cmd_1): Make "text" parameter pointer to const. Adjust to
deprecated_cmd_warning prototype change.
(undef_cmd_error): Make "cmdtype" parameter const.
(lookup_cmd): Make "line" parameter const.
(deprecated_cmd_warning): Change type of "text" parameter to
pointer to const char, from pointer to pointer to char. Adjust.
(lookup_cmd_composition): Make "text" parameter const.
(complete_on_cmdlist, complete_on_enum): Make "text" and "word"
parameters const.
* cli/cli-decode.h (struct cmd_list_element) <name>: Make field
const.
* cli/cli-script.c (validate_comname): Make "tem" local const.
(define_command): New const local "tem_c". Use it in calls to
lookup_cmd.
(document_command): Make "tem" and "comfull" locals const.
(show_user_1): Make "prefix" and "name" parameters const.
* cli-script.h (show_user_1): Make "prefix" and "name" parameters
const.
* command.h (add_cmd, add_alias_cmd, add_prefix_cmd)
(add_abbrev_prefix_cmd, completer_ftype, lookup_cmd, lookup_cmd_1)
(deprecated_cmd_warning, lookup_cmd_composition, add_com)
(add_com_alias, add_info, add_info_alias, complete_on_cmdlist)
(complete_on_enum, add_setshow_enum_cmd)
(add_setshow_auto_boolean_cmd, add_setshow_boolean_cmd)
(add_setshow_filename_cmd, add_setshow_string_cmd)
(add_setshow_string_noescape_cmd)
(add_setshow_optional_filename_cmd, add_setshow_integer_cmd)
(add_setshow_uinteger_cmd, add_setshow_zinteger_cmd)
(add_setshow_zuinteger_cmd, add_setshow_zuinteger_unlimited_cmd):
Change prototypes, constifying strings.
* completer.c (noop_completer, filename_completer): Make "text"
and "prefix" parameters const.
(location_completer, expression_completer)
(complete_line_internal): Make "text" and "prefix" parameters
const and adjust.
(command_completer, signal_completer): Make "text" and "prefix"
parameters const.
* completer.h (noop_completer, filename_completer)
(expression_completer, location_completer, command_completer)
(signal_completer): Change prototypes.
* corefile.c (complete_set_gnutarget): Make "text" and "word"
parameters const.
* cp-abi.c (cp_abi_completer): Likewise.
* expression.h (parse_expression_for_completion): Change
prototype.
* f-lang.c (f_make_symbol_completion_list): Make "text" and "word"
parameters const.
* infcmd.c (_initialize_infcmd): Make "cmd_name" local const.
* infrun.c (handle_completer): Make "text" and "word" parameters
const.
* interps.c (interpreter_completer): Make "text" and "word"
parameters const.
* language.h (struct language_defn)
<la_make_symbol_completion_list>: Make "text" and "word"
parameters const.
* parse.c (parse_exp_1): Move const hack to parse_exp_in_context.
(parse_exp_in_context): Rename to ...
(parse_exp_in_context_1): ... this.
(parse_exp_in_context): Reimplement, with const hack from
parse_exp_1.
(parse_expression_for_completion): Make "string" parameter const.
* printcmd.c (decode_format): Make "string_ptr" parameter pointer
to pointer to const char. Adjust.
(print_command_1): Make "exp" parameter const.
(output_command): Rename to ...
(output_command_const): ... this. Make "exp" parameter const.
(output_command): Reimplement.
(x_command): Adjust.
(display_command): Rename "exp" parameter to "arg". New "exp"
local, const version of "arg".
* python/py-auto-load.c (gdbpy_initialize_auto_load): Make
"cmd_name" local const.
* python/py-cmd.c (cmdpy_destroyer): Cast const away in xfree
call.
(cmdpy_completer): Make "text" and "word" parameters const.
(gdbpy_parse_command_name): Make "prefix_text2" local const.
* python/py-param.c (add_setshow_generic): Make "tmp_name" local
const.
* remote.c (_initialize_remote): Make "cmd_name" local const.
* symtab.c (language_search_unquoted_string): Make "text" and "p"
parameters const. Adjust.
(completion_list_add_fields): Make "sym_text", "text" and "word"
parameters const.
(struct add_name_data) <sym_text, text, word>: Make fields const.
(default_make_symbol_completion_list_break_on): Make "text" and
"word" parameters const. Adjust locals.
(default_make_symbol_completion_list)
(make_symbol_completion_list, make_symbol_completion_type)
(make_symbol_completion_list_fn): Make "text" and "word"
parameters const.
(make_file_symbol_completion_list): Make "text", "word" and
"srcfile" parameters const. Adjust locals.
(add_filename_to_list): Make "text" and "word" parameters const.
(struct add_partial_filename_data) <text, word>: Make fields
const.
(make_source_files_completion_list): Make "text" and "word"
parameters const.
* symtab.h (default_make_symbol_completion_list_break_on)
(default_make_symbol_completion_list, make_symbol_completion_list)
(make_symbol_completion_type enum type_code)
(make_symbol_completion_list_fn make_file_symbol_completion_list)
(make_source_files_completion_list): Change prototype.
* top.c (execute_command): Adjust to pass pointer to pointer to
const char to lookup_cmd, and to deprecated_cmd_warning prototype
change.
(set_verbose): Make "cmdname" local const.
* tracepoint.c (decode_agent_options): Make "exp" parameter const,
and adjust.
(validate_actionline): Make "line" parameter a pointer to const
char, and adjust.
(encode_actions_1): Make "action_exp" local const, and adjust.
(encode_actions): Adjust.
(replace_comma): Delete.
(trace_dump_actions): Make "action_exp" and "next_comma" locals
const, and adjust. Don't frob the action string while splitting
it at commas. Instead, make a copy of each split substring in
turn.
(trace_dump_command): Adjust to validate_actionline prototype
change.
* tracepoint.h (decode_agent_options, decode_agent_options)
(encode_actions, validate_actionline): Change prototypes.
* valprint.h (output_command): Delete declaration.
(output_command_const): Declare.
* value.c (function_destroyer): Cast const away in xfree call.
2013-03-13 19:34:55 +01:00
|
|
|
|
char *prefix_text;
|
|
|
|
|
const char *prefix_text2;
|
2009-02-06 22:33:59 +01:00
|
|
|
|
char *result;
|
|
|
|
|
|
|
|
|
|
/* Skip trailing whitespace. */
|
2011-09-08 21:51:27 +02:00
|
|
|
|
for (i = len - 1; i >= 0 && (name[i] == ' ' || name[i] == '\t'); --i)
|
2009-02-06 22:33:59 +01:00
|
|
|
|
;
|
|
|
|
|
if (i < 0)
|
|
|
|
|
{
|
2010-04-14 15:18:55 +02:00
|
|
|
|
PyErr_SetString (PyExc_RuntimeError, _("No command name found."));
|
2009-02-06 22:33:59 +01:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
lastchar = i;
|
|
|
|
|
|
|
|
|
|
/* Find first character of the final word. */
|
2011-09-08 21:51:27 +02:00
|
|
|
|
for (; i > 0 && (isalnum (name[i - 1])
|
|
|
|
|
|| name[i - 1] == '-'
|
|
|
|
|
|| name[i - 1] == '_');
|
2009-02-06 22:33:59 +01:00
|
|
|
|
--i)
|
|
|
|
|
;
|
|
|
|
|
result = xmalloc (lastchar - i + 2);
|
2011-09-08 21:51:27 +02:00
|
|
|
|
memcpy (result, &name[i], lastchar - i + 1);
|
2009-02-06 22:33:59 +01:00
|
|
|
|
result[lastchar - i + 1] = '\0';
|
|
|
|
|
|
|
|
|
|
/* Skip whitespace again. */
|
2011-09-08 21:51:27 +02:00
|
|
|
|
for (--i; i >= 0 && (name[i] == ' ' || name[i] == '\t'); --i)
|
2009-02-06 22:33:59 +01:00
|
|
|
|
;
|
|
|
|
|
if (i < 0)
|
|
|
|
|
{
|
2010-04-29 17:45:57 +02:00
|
|
|
|
*base_list = start_list;
|
2009-02-06 22:33:59 +01:00
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
prefix_text = xmalloc (i + 2);
|
2011-09-08 21:51:27 +02:00
|
|
|
|
memcpy (prefix_text, name, i + 1);
|
2009-02-06 22:33:59 +01:00
|
|
|
|
prefix_text[i + 1] = '\0';
|
|
|
|
|
|
2011-09-08 21:51:27 +02:00
|
|
|
|
prefix_text2 = prefix_text;
|
|
|
|
|
elt = lookup_cmd_1 (&prefix_text2, *start_list, NULL, 1);
|
2009-02-06 22:33:59 +01:00
|
|
|
|
if (!elt || elt == (struct cmd_list_element *) -1)
|
|
|
|
|
{
|
2010-04-14 15:18:55 +02:00
|
|
|
|
PyErr_Format (PyExc_RuntimeError, _("Could not find command prefix %s."),
|
2009-02-06 22:33:59 +01:00
|
|
|
|
prefix_text);
|
|
|
|
|
xfree (prefix_text);
|
|
|
|
|
xfree (result);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (elt->prefixlist)
|
|
|
|
|
{
|
|
|
|
|
xfree (prefix_text);
|
|
|
|
|
*base_list = elt->prefixlist;
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-14 15:18:55 +02:00
|
|
|
|
PyErr_Format (PyExc_RuntimeError, _("'%s' is not a prefix command."),
|
2009-02-06 22:33:59 +01:00
|
|
|
|
prefix_text);
|
|
|
|
|
xfree (prefix_text);
|
|
|
|
|
xfree (result);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Object initializer; sets up gdb-side structures for command.
|
|
|
|
|
|
2009-03-21 04:13:02 +01:00
|
|
|
|
Use: __init__(NAME, COMMAND_CLASS [, COMPLETER_CLASS][, PREFIX]]).
|
2009-02-06 22:33:59 +01:00
|
|
|
|
|
|
|
|
|
NAME is the name of the command. It may consist of multiple words,
|
|
|
|
|
in which case the final word is the name of the new command, and
|
|
|
|
|
earlier words must be prefix commands.
|
|
|
|
|
|
2009-03-21 04:13:02 +01:00
|
|
|
|
COMMAND_CLASS is the kind of command. It should be one of the COMMAND_*
|
2009-02-06 22:33:59 +01:00
|
|
|
|
constants defined in the gdb module.
|
|
|
|
|
|
2009-03-21 04:13:02 +01:00
|
|
|
|
COMPLETER_CLASS is the kind of completer. If not given, the
|
2009-02-06 22:33:59 +01:00
|
|
|
|
"complete" method will be used. Otherwise, it should be one of the
|
|
|
|
|
COMPLETE_* constants defined in the gdb module.
|
|
|
|
|
|
|
|
|
|
If PREFIX is True, then this command is a prefix command.
|
|
|
|
|
|
|
|
|
|
The documentation for the command is taken from the doc string for
|
2011-09-08 21:51:27 +02:00
|
|
|
|
the python class. */
|
|
|
|
|
|
2009-02-06 22:33:59 +01:00
|
|
|
|
static int
|
2009-03-21 04:13:02 +01:00
|
|
|
|
cmdpy_init (PyObject *self, PyObject *args, PyObject *kw)
|
2009-02-06 22:33:59 +01:00
|
|
|
|
{
|
|
|
|
|
cmdpy_object *obj = (cmdpy_object *) self;
|
2011-06-24 21:47:37 +02:00
|
|
|
|
const char *name;
|
2009-02-06 22:33:59 +01:00
|
|
|
|
int cmdtype;
|
|
|
|
|
int completetype = -1;
|
|
|
|
|
char *docstring = NULL;
|
|
|
|
|
volatile struct gdb_exception except;
|
|
|
|
|
struct cmd_list_element **cmd_list;
|
|
|
|
|
char *cmd_name, *pfx_name;
|
2009-03-21 04:13:02 +01:00
|
|
|
|
static char *keywords[] = { "name", "command_class", "completer_class",
|
|
|
|
|
"prefix", NULL };
|
2009-02-06 22:33:59 +01:00
|
|
|
|
PyObject *is_prefix = NULL;
|
|
|
|
|
int cmp;
|
|
|
|
|
|
|
|
|
|
if (obj->command)
|
|
|
|
|
{
|
|
|
|
|
/* Note: this is apparently not documented in Python. We return
|
|
|
|
|
0 for success, -1 for failure. */
|
|
|
|
|
PyErr_Format (PyExc_RuntimeError,
|
2010-04-14 15:18:55 +02:00
|
|
|
|
_("Command object already initialized."));
|
2009-02-06 22:33:59 +01:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-06 01:57:05 +01:00
|
|
|
|
if (! PyArg_ParseTupleAndKeywords (args, kw, "si|iO",
|
|
|
|
|
keywords, &name, &cmdtype,
|
2009-02-06 22:33:59 +01:00
|
|
|
|
&completetype, &is_prefix))
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
if (cmdtype != no_class && cmdtype != class_run
|
|
|
|
|
&& cmdtype != class_vars && cmdtype != class_stack
|
|
|
|
|
&& cmdtype != class_files && cmdtype != class_support
|
|
|
|
|
&& cmdtype != class_info && cmdtype != class_breakpoint
|
|
|
|
|
&& cmdtype != class_trace && cmdtype != class_obscure
|
2012-03-01 20:30:25 +01:00
|
|
|
|
&& cmdtype != class_maintenance && cmdtype != class_user)
|
2009-02-06 22:33:59 +01:00
|
|
|
|
{
|
2010-04-14 15:18:55 +02:00
|
|
|
|
PyErr_Format (PyExc_RuntimeError, _("Invalid command class argument."));
|
2009-02-06 22:33:59 +01:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (completetype < -1 || completetype >= (int) N_COMPLETERS)
|
|
|
|
|
{
|
2011-01-06 01:57:05 +01:00
|
|
|
|
PyErr_Format (PyExc_RuntimeError,
|
|
|
|
|
_("Invalid completion type argument."));
|
2009-02-06 22:33:59 +01:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-08 21:51:27 +02:00
|
|
|
|
cmd_name = gdbpy_parse_command_name (name, &cmd_list, &cmdlist);
|
2009-02-06 22:33:59 +01:00
|
|
|
|
if (! cmd_name)
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
pfx_name = NULL;
|
2013-11-29 21:00:47 +01:00
|
|
|
|
if (is_prefix != NULL)
|
2009-02-06 22:33:59 +01:00
|
|
|
|
{
|
|
|
|
|
cmp = PyObject_IsTrue (is_prefix);
|
|
|
|
|
if (cmp == 1)
|
|
|
|
|
{
|
|
|
|
|
int i, out;
|
2013-11-29 21:00:47 +01:00
|
|
|
|
|
2009-02-06 22:33:59 +01:00
|
|
|
|
/* Make a normalized form of the command name. */
|
|
|
|
|
pfx_name = xmalloc (strlen (name) + 2);
|
2013-11-29 21:00:47 +01:00
|
|
|
|
|
2009-02-06 22:33:59 +01:00
|
|
|
|
i = 0;
|
|
|
|
|
out = 0;
|
|
|
|
|
while (name[i])
|
|
|
|
|
{
|
|
|
|
|
/* Skip whitespace. */
|
|
|
|
|
while (name[i] == ' ' || name[i] == '\t')
|
|
|
|
|
++i;
|
|
|
|
|
/* Copy non-whitespace characters. */
|
|
|
|
|
while (name[i] && name[i] != ' ' && name[i] != '\t')
|
|
|
|
|
pfx_name[out++] = name[i++];
|
|
|
|
|
/* Add a single space after each word -- including the final
|
|
|
|
|
word. */
|
|
|
|
|
pfx_name[out++] = ' ';
|
|
|
|
|
}
|
|
|
|
|
pfx_name[out] = '\0';
|
|
|
|
|
}
|
|
|
|
|
else if (cmp < 0)
|
2011-02-28 19:55:22 +01:00
|
|
|
|
{
|
|
|
|
|
xfree (cmd_name);
|
2009-02-06 22:33:59 +01:00
|
|
|
|
return -1;
|
2011-02-28 19:55:22 +01:00
|
|
|
|
}
|
2009-02-06 22:33:59 +01:00
|
|
|
|
}
|
|
|
|
|
if (PyObject_HasAttr (self, gdbpy_doc_cst))
|
|
|
|
|
{
|
|
|
|
|
PyObject *ds_obj = PyObject_GetAttr (self, gdbpy_doc_cst);
|
2010-05-17 23:23:25 +02:00
|
|
|
|
|
2009-02-06 22:33:59 +01:00
|
|
|
|
if (ds_obj && gdbpy_is_string (ds_obj))
|
2010-10-13 15:24:40 +02:00
|
|
|
|
{
|
|
|
|
|
docstring = python_string_to_host_string (ds_obj);
|
|
|
|
|
if (docstring == NULL)
|
|
|
|
|
{
|
|
|
|
|
xfree (cmd_name);
|
|
|
|
|
xfree (pfx_name);
|
2013-05-20 22:20:48 +02:00
|
|
|
|
Py_DECREF (ds_obj);
|
2010-10-13 15:24:40 +02:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-05-20 22:20:48 +02:00
|
|
|
|
|
|
|
|
|
Py_XDECREF (ds_obj);
|
2009-02-06 22:33:59 +01:00
|
|
|
|
}
|
|
|
|
|
if (! docstring)
|
|
|
|
|
docstring = xstrdup (_("This command is not documented."));
|
|
|
|
|
|
|
|
|
|
Py_INCREF (self);
|
|
|
|
|
|
|
|
|
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
|
|
|
|
{
|
|
|
|
|
struct cmd_list_element *cmd;
|
|
|
|
|
|
|
|
|
|
if (pfx_name)
|
|
|
|
|
{
|
|
|
|
|
int allow_unknown;
|
|
|
|
|
|
|
|
|
|
/* If we have our own "invoke" method, then allow unknown
|
|
|
|
|
sub-commands. */
|
|
|
|
|
allow_unknown = PyObject_HasAttr (self, invoke_cst);
|
|
|
|
|
cmd = add_prefix_cmd (cmd_name, (enum command_class) cmdtype,
|
|
|
|
|
NULL, docstring, &obj->sub_list,
|
|
|
|
|
pfx_name, allow_unknown, cmd_list);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
cmd = add_cmd (cmd_name, (enum command_class) cmdtype, NULL,
|
|
|
|
|
docstring, cmd_list);
|
|
|
|
|
|
|
|
|
|
/* There appears to be no API to set this. */
|
|
|
|
|
cmd->func = cmdpy_function;
|
|
|
|
|
cmd->destroyer = cmdpy_destroyer;
|
|
|
|
|
|
|
|
|
|
obj->command = cmd;
|
|
|
|
|
set_cmd_context (cmd, self);
|
|
|
|
|
set_cmd_completer (cmd, ((completetype == -1) ? cmdpy_completer
|
|
|
|
|
: completers[completetype].completer));
|
|
|
|
|
}
|
|
|
|
|
if (except.reason < 0)
|
|
|
|
|
{
|
|
|
|
|
xfree (cmd_name);
|
|
|
|
|
xfree (docstring);
|
|
|
|
|
xfree (pfx_name);
|
|
|
|
|
Py_DECREF (self);
|
|
|
|
|
PyErr_Format (except.reason == RETURN_QUIT
|
|
|
|
|
? PyExc_KeyboardInterrupt : PyExc_RuntimeError,
|
|
|
|
|
"%s", except.message);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Initialize the 'commands' code. */
|
2011-09-08 21:51:27 +02:00
|
|
|
|
|
* python/py-arch.c (gdbpy_initialize_arch): Return 'int'.
Check errors.
* python/py-auto-load.c (gdbpy_initialize_auto_load): Return 'int'.
* python/py-block.c (gdbpy_initialize_blocks): Return 'int'.
Check errors.
* python/py-breakpoint.c (gdbpy_initialize_breakpoints): Return 'int'.
Check errors.
* python/py-cmd.c (gdbpy_initialize_commands): Return 'int'.
Check errors.
* python/py-event.c (gdbpy_initialize_event): Return 'int'.
Check errors.
* python/py-event.h (GDBPY_NEW_EVENT_TYPE): Change generated
init function to return 'int'.
* python/py-evtregistry.c (gdbpy_initialize_eventregistry):
Return 'int'. Check errors.
* python/py-evts.c (gdbpy_initialize_py_events): Return 'int'.
Check errors.
* python/py-finishbreakpoint.c (gdbpy_initialize_finishbreakpoints):
Return 'int'. Check errors.
* python/py-frame.c (gdbpy_initialize_frames): Return 'int'.
Check errors.
* python/py-function.c (gdbpy_initialize_functions): Return 'int'.
Check errors.
* python/py-gdb-readline.c (gdbpy_initialize_gdb_readline):
Check errors.
* python/py-inferior.c (gdbpy_initialize_inferior): Return 'int'.
Check errors.
* python/py-infthread.c (gdbpy_initialize_thread): Return 'int'.
Check errors.
* python/py-lazy-string.c (gdbpy_initialize_lazy_string): Return 'int'.
Check errors.
* python/py-objfile.c (gdbpy_initialize_objfile): Return 'int'.
Check errors.
* python/py-param.c (gdbpy_initialize_parameters): Return 'int'.
Check errors.
* python/py-progspace.c (gdbpy_initialize_pspace): Return 'int'.
Check errors.
* python/py-symbol.c (gdbpy_initialize_symbols): Return 'int'.
Check errors.
* python/py-symtab.c (gdbpy_initialize_symtabs): Return 'int'.
Check errors.
* python/py-type.c (gdbpy_initialize_types): Return 'int'.
Check errors.
* python/py-value.c (gdbpy_initialize_values): Return 'int'.
Check errors.
* python/python-internal.h (gdbpy_initialize_auto_load,
gdbpy_initialize_values, gdbpy_initialize_frames,
gdbpy_initialize_symtabs, gdbpy_initialize_commands,
gdbpy_initialize_symbols, gdbpy_initialize_symtabs,
gdbpy_initialize_blocks, gdbpy_initialize_types,
gdbpy_initialize_functions, gdbpy_initialize_pspace,
gdbpy_initialize_objfile, gdbpy_initialize_breakpoints,
gdbpy_initialize_finishbreakpoints,
gdbpy_initialize_lazy_string, gdbpy_initialize_parameters,
gdbpy_initialize_thread, gdbpy_initialize_inferior,
gdbpy_initialize_eventregistry, gdbpy_initialize_event,
gdbpy_initialize_py_events, gdbpy_initialize_stop_event,
gdbpy_initialize_signal_event,
gdbpy_initialize_breakpoint_event,
gdbpy_initialize_continue_event,
gdbpy_initialize_exited_event, gdbpy_initialize_thread_event,
gdbpy_initialize_new_objfile_event, gdbpy_initialize_arch):
Update. Use CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION.
* python/python.c (gdb_python_initialized): New global.
(gdbpy_initialize_events): Return 'int'. Check errors.
(_initialize_python): Check errors. Set
gdb_python_initialized.
2013-05-20 22:28:52 +02:00
|
|
|
|
int
|
2009-02-06 22:33:59 +01:00
|
|
|
|
gdbpy_initialize_commands (void)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
2011-08-05 16:24:10 +02:00
|
|
|
|
cmdpy_object_type.tp_new = PyType_GenericNew;
|
2009-02-06 22:33:59 +01:00
|
|
|
|
if (PyType_Ready (&cmdpy_object_type) < 0)
|
* python/py-arch.c (gdbpy_initialize_arch): Return 'int'.
Check errors.
* python/py-auto-load.c (gdbpy_initialize_auto_load): Return 'int'.
* python/py-block.c (gdbpy_initialize_blocks): Return 'int'.
Check errors.
* python/py-breakpoint.c (gdbpy_initialize_breakpoints): Return 'int'.
Check errors.
* python/py-cmd.c (gdbpy_initialize_commands): Return 'int'.
Check errors.
* python/py-event.c (gdbpy_initialize_event): Return 'int'.
Check errors.
* python/py-event.h (GDBPY_NEW_EVENT_TYPE): Change generated
init function to return 'int'.
* python/py-evtregistry.c (gdbpy_initialize_eventregistry):
Return 'int'. Check errors.
* python/py-evts.c (gdbpy_initialize_py_events): Return 'int'.
Check errors.
* python/py-finishbreakpoint.c (gdbpy_initialize_finishbreakpoints):
Return 'int'. Check errors.
* python/py-frame.c (gdbpy_initialize_frames): Return 'int'.
Check errors.
* python/py-function.c (gdbpy_initialize_functions): Return 'int'.
Check errors.
* python/py-gdb-readline.c (gdbpy_initialize_gdb_readline):
Check errors.
* python/py-inferior.c (gdbpy_initialize_inferior): Return 'int'.
Check errors.
* python/py-infthread.c (gdbpy_initialize_thread): Return 'int'.
Check errors.
* python/py-lazy-string.c (gdbpy_initialize_lazy_string): Return 'int'.
Check errors.
* python/py-objfile.c (gdbpy_initialize_objfile): Return 'int'.
Check errors.
* python/py-param.c (gdbpy_initialize_parameters): Return 'int'.
Check errors.
* python/py-progspace.c (gdbpy_initialize_pspace): Return 'int'.
Check errors.
* python/py-symbol.c (gdbpy_initialize_symbols): Return 'int'.
Check errors.
* python/py-symtab.c (gdbpy_initialize_symtabs): Return 'int'.
Check errors.
* python/py-type.c (gdbpy_initialize_types): Return 'int'.
Check errors.
* python/py-value.c (gdbpy_initialize_values): Return 'int'.
Check errors.
* python/python-internal.h (gdbpy_initialize_auto_load,
gdbpy_initialize_values, gdbpy_initialize_frames,
gdbpy_initialize_symtabs, gdbpy_initialize_commands,
gdbpy_initialize_symbols, gdbpy_initialize_symtabs,
gdbpy_initialize_blocks, gdbpy_initialize_types,
gdbpy_initialize_functions, gdbpy_initialize_pspace,
gdbpy_initialize_objfile, gdbpy_initialize_breakpoints,
gdbpy_initialize_finishbreakpoints,
gdbpy_initialize_lazy_string, gdbpy_initialize_parameters,
gdbpy_initialize_thread, gdbpy_initialize_inferior,
gdbpy_initialize_eventregistry, gdbpy_initialize_event,
gdbpy_initialize_py_events, gdbpy_initialize_stop_event,
gdbpy_initialize_signal_event,
gdbpy_initialize_breakpoint_event,
gdbpy_initialize_continue_event,
gdbpy_initialize_exited_event, gdbpy_initialize_thread_event,
gdbpy_initialize_new_objfile_event, gdbpy_initialize_arch):
Update. Use CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION.
* python/python.c (gdb_python_initialized): New global.
(gdbpy_initialize_events): Return 'int'. Check errors.
(_initialize_python): Check errors. Set
gdb_python_initialized.
2013-05-20 22:28:52 +02:00
|
|
|
|
return -1;
|
2009-02-06 22:33:59 +01:00
|
|
|
|
|
|
|
|
|
/* Note: alias and user are special; pseudo appears to be unused,
|
|
|
|
|
and there is no reason to expose tui or xdb, I think. */
|
|
|
|
|
if (PyModule_AddIntConstant (gdb_module, "COMMAND_NONE", no_class) < 0
|
|
|
|
|
|| PyModule_AddIntConstant (gdb_module, "COMMAND_RUNNING", class_run) < 0
|
|
|
|
|
|| PyModule_AddIntConstant (gdb_module, "COMMAND_DATA", class_vars) < 0
|
|
|
|
|
|| PyModule_AddIntConstant (gdb_module, "COMMAND_STACK", class_stack) < 0
|
|
|
|
|
|| PyModule_AddIntConstant (gdb_module, "COMMAND_FILES", class_files) < 0
|
|
|
|
|
|| PyModule_AddIntConstant (gdb_module, "COMMAND_SUPPORT",
|
|
|
|
|
class_support) < 0
|
|
|
|
|
|| PyModule_AddIntConstant (gdb_module, "COMMAND_STATUS", class_info) < 0
|
|
|
|
|
|| PyModule_AddIntConstant (gdb_module, "COMMAND_BREAKPOINTS",
|
|
|
|
|
class_breakpoint) < 0
|
|
|
|
|
|| PyModule_AddIntConstant (gdb_module, "COMMAND_TRACEPOINTS",
|
|
|
|
|
class_trace) < 0
|
|
|
|
|
|| PyModule_AddIntConstant (gdb_module, "COMMAND_OBSCURE",
|
|
|
|
|
class_obscure) < 0
|
|
|
|
|
|| PyModule_AddIntConstant (gdb_module, "COMMAND_MAINTENANCE",
|
2012-03-01 20:30:25 +01:00
|
|
|
|
class_maintenance) < 0
|
|
|
|
|
|| PyModule_AddIntConstant (gdb_module, "COMMAND_USER", class_user) < 0)
|
* python/py-arch.c (gdbpy_initialize_arch): Return 'int'.
Check errors.
* python/py-auto-load.c (gdbpy_initialize_auto_load): Return 'int'.
* python/py-block.c (gdbpy_initialize_blocks): Return 'int'.
Check errors.
* python/py-breakpoint.c (gdbpy_initialize_breakpoints): Return 'int'.
Check errors.
* python/py-cmd.c (gdbpy_initialize_commands): Return 'int'.
Check errors.
* python/py-event.c (gdbpy_initialize_event): Return 'int'.
Check errors.
* python/py-event.h (GDBPY_NEW_EVENT_TYPE): Change generated
init function to return 'int'.
* python/py-evtregistry.c (gdbpy_initialize_eventregistry):
Return 'int'. Check errors.
* python/py-evts.c (gdbpy_initialize_py_events): Return 'int'.
Check errors.
* python/py-finishbreakpoint.c (gdbpy_initialize_finishbreakpoints):
Return 'int'. Check errors.
* python/py-frame.c (gdbpy_initialize_frames): Return 'int'.
Check errors.
* python/py-function.c (gdbpy_initialize_functions): Return 'int'.
Check errors.
* python/py-gdb-readline.c (gdbpy_initialize_gdb_readline):
Check errors.
* python/py-inferior.c (gdbpy_initialize_inferior): Return 'int'.
Check errors.
* python/py-infthread.c (gdbpy_initialize_thread): Return 'int'.
Check errors.
* python/py-lazy-string.c (gdbpy_initialize_lazy_string): Return 'int'.
Check errors.
* python/py-objfile.c (gdbpy_initialize_objfile): Return 'int'.
Check errors.
* python/py-param.c (gdbpy_initialize_parameters): Return 'int'.
Check errors.
* python/py-progspace.c (gdbpy_initialize_pspace): Return 'int'.
Check errors.
* python/py-symbol.c (gdbpy_initialize_symbols): Return 'int'.
Check errors.
* python/py-symtab.c (gdbpy_initialize_symtabs): Return 'int'.
Check errors.
* python/py-type.c (gdbpy_initialize_types): Return 'int'.
Check errors.
* python/py-value.c (gdbpy_initialize_values): Return 'int'.
Check errors.
* python/python-internal.h (gdbpy_initialize_auto_load,
gdbpy_initialize_values, gdbpy_initialize_frames,
gdbpy_initialize_symtabs, gdbpy_initialize_commands,
gdbpy_initialize_symbols, gdbpy_initialize_symtabs,
gdbpy_initialize_blocks, gdbpy_initialize_types,
gdbpy_initialize_functions, gdbpy_initialize_pspace,
gdbpy_initialize_objfile, gdbpy_initialize_breakpoints,
gdbpy_initialize_finishbreakpoints,
gdbpy_initialize_lazy_string, gdbpy_initialize_parameters,
gdbpy_initialize_thread, gdbpy_initialize_inferior,
gdbpy_initialize_eventregistry, gdbpy_initialize_event,
gdbpy_initialize_py_events, gdbpy_initialize_stop_event,
gdbpy_initialize_signal_event,
gdbpy_initialize_breakpoint_event,
gdbpy_initialize_continue_event,
gdbpy_initialize_exited_event, gdbpy_initialize_thread_event,
gdbpy_initialize_new_objfile_event, gdbpy_initialize_arch):
Update. Use CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION.
* python/python.c (gdb_python_initialized): New global.
(gdbpy_initialize_events): Return 'int'. Check errors.
(_initialize_python): Check errors. Set
gdb_python_initialized.
2013-05-20 22:28:52 +02:00
|
|
|
|
return -1;
|
2009-02-06 22:33:59 +01:00
|
|
|
|
|
|
|
|
|
for (i = 0; i < N_COMPLETERS; ++i)
|
|
|
|
|
{
|
|
|
|
|
if (PyModule_AddIntConstant (gdb_module, completers[i].name, i) < 0)
|
* python/py-arch.c (gdbpy_initialize_arch): Return 'int'.
Check errors.
* python/py-auto-load.c (gdbpy_initialize_auto_load): Return 'int'.
* python/py-block.c (gdbpy_initialize_blocks): Return 'int'.
Check errors.
* python/py-breakpoint.c (gdbpy_initialize_breakpoints): Return 'int'.
Check errors.
* python/py-cmd.c (gdbpy_initialize_commands): Return 'int'.
Check errors.
* python/py-event.c (gdbpy_initialize_event): Return 'int'.
Check errors.
* python/py-event.h (GDBPY_NEW_EVENT_TYPE): Change generated
init function to return 'int'.
* python/py-evtregistry.c (gdbpy_initialize_eventregistry):
Return 'int'. Check errors.
* python/py-evts.c (gdbpy_initialize_py_events): Return 'int'.
Check errors.
* python/py-finishbreakpoint.c (gdbpy_initialize_finishbreakpoints):
Return 'int'. Check errors.
* python/py-frame.c (gdbpy_initialize_frames): Return 'int'.
Check errors.
* python/py-function.c (gdbpy_initialize_functions): Return 'int'.
Check errors.
* python/py-gdb-readline.c (gdbpy_initialize_gdb_readline):
Check errors.
* python/py-inferior.c (gdbpy_initialize_inferior): Return 'int'.
Check errors.
* python/py-infthread.c (gdbpy_initialize_thread): Return 'int'.
Check errors.
* python/py-lazy-string.c (gdbpy_initialize_lazy_string): Return 'int'.
Check errors.
* python/py-objfile.c (gdbpy_initialize_objfile): Return 'int'.
Check errors.
* python/py-param.c (gdbpy_initialize_parameters): Return 'int'.
Check errors.
* python/py-progspace.c (gdbpy_initialize_pspace): Return 'int'.
Check errors.
* python/py-symbol.c (gdbpy_initialize_symbols): Return 'int'.
Check errors.
* python/py-symtab.c (gdbpy_initialize_symtabs): Return 'int'.
Check errors.
* python/py-type.c (gdbpy_initialize_types): Return 'int'.
Check errors.
* python/py-value.c (gdbpy_initialize_values): Return 'int'.
Check errors.
* python/python-internal.h (gdbpy_initialize_auto_load,
gdbpy_initialize_values, gdbpy_initialize_frames,
gdbpy_initialize_symtabs, gdbpy_initialize_commands,
gdbpy_initialize_symbols, gdbpy_initialize_symtabs,
gdbpy_initialize_blocks, gdbpy_initialize_types,
gdbpy_initialize_functions, gdbpy_initialize_pspace,
gdbpy_initialize_objfile, gdbpy_initialize_breakpoints,
gdbpy_initialize_finishbreakpoints,
gdbpy_initialize_lazy_string, gdbpy_initialize_parameters,
gdbpy_initialize_thread, gdbpy_initialize_inferior,
gdbpy_initialize_eventregistry, gdbpy_initialize_event,
gdbpy_initialize_py_events, gdbpy_initialize_stop_event,
gdbpy_initialize_signal_event,
gdbpy_initialize_breakpoint_event,
gdbpy_initialize_continue_event,
gdbpy_initialize_exited_event, gdbpy_initialize_thread_event,
gdbpy_initialize_new_objfile_event, gdbpy_initialize_arch):
Update. Use CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION.
* python/python.c (gdb_python_initialized): New global.
(gdbpy_initialize_events): Return 'int'. Check errors.
(_initialize_python): Check errors. Set
gdb_python_initialized.
2013-05-20 22:28:52 +02:00
|
|
|
|
return -1;
|
2009-02-06 22:33:59 +01:00
|
|
|
|
}
|
|
|
|
|
|
2013-05-20 22:36:19 +02:00
|
|
|
|
if (gdb_pymodule_addobject (gdb_module, "Command",
|
|
|
|
|
(PyObject *) &cmdpy_object_type) < 0)
|
* python/py-arch.c (gdbpy_initialize_arch): Return 'int'.
Check errors.
* python/py-auto-load.c (gdbpy_initialize_auto_load): Return 'int'.
* python/py-block.c (gdbpy_initialize_blocks): Return 'int'.
Check errors.
* python/py-breakpoint.c (gdbpy_initialize_breakpoints): Return 'int'.
Check errors.
* python/py-cmd.c (gdbpy_initialize_commands): Return 'int'.
Check errors.
* python/py-event.c (gdbpy_initialize_event): Return 'int'.
Check errors.
* python/py-event.h (GDBPY_NEW_EVENT_TYPE): Change generated
init function to return 'int'.
* python/py-evtregistry.c (gdbpy_initialize_eventregistry):
Return 'int'. Check errors.
* python/py-evts.c (gdbpy_initialize_py_events): Return 'int'.
Check errors.
* python/py-finishbreakpoint.c (gdbpy_initialize_finishbreakpoints):
Return 'int'. Check errors.
* python/py-frame.c (gdbpy_initialize_frames): Return 'int'.
Check errors.
* python/py-function.c (gdbpy_initialize_functions): Return 'int'.
Check errors.
* python/py-gdb-readline.c (gdbpy_initialize_gdb_readline):
Check errors.
* python/py-inferior.c (gdbpy_initialize_inferior): Return 'int'.
Check errors.
* python/py-infthread.c (gdbpy_initialize_thread): Return 'int'.
Check errors.
* python/py-lazy-string.c (gdbpy_initialize_lazy_string): Return 'int'.
Check errors.
* python/py-objfile.c (gdbpy_initialize_objfile): Return 'int'.
Check errors.
* python/py-param.c (gdbpy_initialize_parameters): Return 'int'.
Check errors.
* python/py-progspace.c (gdbpy_initialize_pspace): Return 'int'.
Check errors.
* python/py-symbol.c (gdbpy_initialize_symbols): Return 'int'.
Check errors.
* python/py-symtab.c (gdbpy_initialize_symtabs): Return 'int'.
Check errors.
* python/py-type.c (gdbpy_initialize_types): Return 'int'.
Check errors.
* python/py-value.c (gdbpy_initialize_values): Return 'int'.
Check errors.
* python/python-internal.h (gdbpy_initialize_auto_load,
gdbpy_initialize_values, gdbpy_initialize_frames,
gdbpy_initialize_symtabs, gdbpy_initialize_commands,
gdbpy_initialize_symbols, gdbpy_initialize_symtabs,
gdbpy_initialize_blocks, gdbpy_initialize_types,
gdbpy_initialize_functions, gdbpy_initialize_pspace,
gdbpy_initialize_objfile, gdbpy_initialize_breakpoints,
gdbpy_initialize_finishbreakpoints,
gdbpy_initialize_lazy_string, gdbpy_initialize_parameters,
gdbpy_initialize_thread, gdbpy_initialize_inferior,
gdbpy_initialize_eventregistry, gdbpy_initialize_event,
gdbpy_initialize_py_events, gdbpy_initialize_stop_event,
gdbpy_initialize_signal_event,
gdbpy_initialize_breakpoint_event,
gdbpy_initialize_continue_event,
gdbpy_initialize_exited_event, gdbpy_initialize_thread_event,
gdbpy_initialize_new_objfile_event, gdbpy_initialize_arch):
Update. Use CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION.
* python/python.c (gdb_python_initialized): New global.
(gdbpy_initialize_events): Return 'int'. Check errors.
(_initialize_python): Check errors. Set
gdb_python_initialized.
2013-05-20 22:28:52 +02:00
|
|
|
|
return -1;
|
2009-02-06 22:33:59 +01:00
|
|
|
|
|
|
|
|
|
invoke_cst = PyString_FromString ("invoke");
|
* python/py-arch.c (gdbpy_initialize_arch): Return 'int'.
Check errors.
* python/py-auto-load.c (gdbpy_initialize_auto_load): Return 'int'.
* python/py-block.c (gdbpy_initialize_blocks): Return 'int'.
Check errors.
* python/py-breakpoint.c (gdbpy_initialize_breakpoints): Return 'int'.
Check errors.
* python/py-cmd.c (gdbpy_initialize_commands): Return 'int'.
Check errors.
* python/py-event.c (gdbpy_initialize_event): Return 'int'.
Check errors.
* python/py-event.h (GDBPY_NEW_EVENT_TYPE): Change generated
init function to return 'int'.
* python/py-evtregistry.c (gdbpy_initialize_eventregistry):
Return 'int'. Check errors.
* python/py-evts.c (gdbpy_initialize_py_events): Return 'int'.
Check errors.
* python/py-finishbreakpoint.c (gdbpy_initialize_finishbreakpoints):
Return 'int'. Check errors.
* python/py-frame.c (gdbpy_initialize_frames): Return 'int'.
Check errors.
* python/py-function.c (gdbpy_initialize_functions): Return 'int'.
Check errors.
* python/py-gdb-readline.c (gdbpy_initialize_gdb_readline):
Check errors.
* python/py-inferior.c (gdbpy_initialize_inferior): Return 'int'.
Check errors.
* python/py-infthread.c (gdbpy_initialize_thread): Return 'int'.
Check errors.
* python/py-lazy-string.c (gdbpy_initialize_lazy_string): Return 'int'.
Check errors.
* python/py-objfile.c (gdbpy_initialize_objfile): Return 'int'.
Check errors.
* python/py-param.c (gdbpy_initialize_parameters): Return 'int'.
Check errors.
* python/py-progspace.c (gdbpy_initialize_pspace): Return 'int'.
Check errors.
* python/py-symbol.c (gdbpy_initialize_symbols): Return 'int'.
Check errors.
* python/py-symtab.c (gdbpy_initialize_symtabs): Return 'int'.
Check errors.
* python/py-type.c (gdbpy_initialize_types): Return 'int'.
Check errors.
* python/py-value.c (gdbpy_initialize_values): Return 'int'.
Check errors.
* python/python-internal.h (gdbpy_initialize_auto_load,
gdbpy_initialize_values, gdbpy_initialize_frames,
gdbpy_initialize_symtabs, gdbpy_initialize_commands,
gdbpy_initialize_symbols, gdbpy_initialize_symtabs,
gdbpy_initialize_blocks, gdbpy_initialize_types,
gdbpy_initialize_functions, gdbpy_initialize_pspace,
gdbpy_initialize_objfile, gdbpy_initialize_breakpoints,
gdbpy_initialize_finishbreakpoints,
gdbpy_initialize_lazy_string, gdbpy_initialize_parameters,
gdbpy_initialize_thread, gdbpy_initialize_inferior,
gdbpy_initialize_eventregistry, gdbpy_initialize_event,
gdbpy_initialize_py_events, gdbpy_initialize_stop_event,
gdbpy_initialize_signal_event,
gdbpy_initialize_breakpoint_event,
gdbpy_initialize_continue_event,
gdbpy_initialize_exited_event, gdbpy_initialize_thread_event,
gdbpy_initialize_new_objfile_event, gdbpy_initialize_arch):
Update. Use CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION.
* python/python.c (gdb_python_initialized): New global.
(gdbpy_initialize_events): Return 'int'. Check errors.
(_initialize_python): Check errors. Set
gdb_python_initialized.
2013-05-20 22:28:52 +02:00
|
|
|
|
if (invoke_cst == NULL)
|
|
|
|
|
return -1;
|
2009-02-06 22:33:59 +01:00
|
|
|
|
complete_cst = PyString_FromString ("complete");
|
* python/py-arch.c (gdbpy_initialize_arch): Return 'int'.
Check errors.
* python/py-auto-load.c (gdbpy_initialize_auto_load): Return 'int'.
* python/py-block.c (gdbpy_initialize_blocks): Return 'int'.
Check errors.
* python/py-breakpoint.c (gdbpy_initialize_breakpoints): Return 'int'.
Check errors.
* python/py-cmd.c (gdbpy_initialize_commands): Return 'int'.
Check errors.
* python/py-event.c (gdbpy_initialize_event): Return 'int'.
Check errors.
* python/py-event.h (GDBPY_NEW_EVENT_TYPE): Change generated
init function to return 'int'.
* python/py-evtregistry.c (gdbpy_initialize_eventregistry):
Return 'int'. Check errors.
* python/py-evts.c (gdbpy_initialize_py_events): Return 'int'.
Check errors.
* python/py-finishbreakpoint.c (gdbpy_initialize_finishbreakpoints):
Return 'int'. Check errors.
* python/py-frame.c (gdbpy_initialize_frames): Return 'int'.
Check errors.
* python/py-function.c (gdbpy_initialize_functions): Return 'int'.
Check errors.
* python/py-gdb-readline.c (gdbpy_initialize_gdb_readline):
Check errors.
* python/py-inferior.c (gdbpy_initialize_inferior): Return 'int'.
Check errors.
* python/py-infthread.c (gdbpy_initialize_thread): Return 'int'.
Check errors.
* python/py-lazy-string.c (gdbpy_initialize_lazy_string): Return 'int'.
Check errors.
* python/py-objfile.c (gdbpy_initialize_objfile): Return 'int'.
Check errors.
* python/py-param.c (gdbpy_initialize_parameters): Return 'int'.
Check errors.
* python/py-progspace.c (gdbpy_initialize_pspace): Return 'int'.
Check errors.
* python/py-symbol.c (gdbpy_initialize_symbols): Return 'int'.
Check errors.
* python/py-symtab.c (gdbpy_initialize_symtabs): Return 'int'.
Check errors.
* python/py-type.c (gdbpy_initialize_types): Return 'int'.
Check errors.
* python/py-value.c (gdbpy_initialize_values): Return 'int'.
Check errors.
* python/python-internal.h (gdbpy_initialize_auto_load,
gdbpy_initialize_values, gdbpy_initialize_frames,
gdbpy_initialize_symtabs, gdbpy_initialize_commands,
gdbpy_initialize_symbols, gdbpy_initialize_symtabs,
gdbpy_initialize_blocks, gdbpy_initialize_types,
gdbpy_initialize_functions, gdbpy_initialize_pspace,
gdbpy_initialize_objfile, gdbpy_initialize_breakpoints,
gdbpy_initialize_finishbreakpoints,
gdbpy_initialize_lazy_string, gdbpy_initialize_parameters,
gdbpy_initialize_thread, gdbpy_initialize_inferior,
gdbpy_initialize_eventregistry, gdbpy_initialize_event,
gdbpy_initialize_py_events, gdbpy_initialize_stop_event,
gdbpy_initialize_signal_event,
gdbpy_initialize_breakpoint_event,
gdbpy_initialize_continue_event,
gdbpy_initialize_exited_event, gdbpy_initialize_thread_event,
gdbpy_initialize_new_objfile_event, gdbpy_initialize_arch):
Update. Use CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION.
* python/python.c (gdb_python_initialized): New global.
(gdbpy_initialize_events): Return 'int'. Check errors.
(_initialize_python): Check errors. Set
gdb_python_initialized.
2013-05-20 22:28:52 +02:00
|
|
|
|
if (complete_cst == NULL)
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
return 0;
|
2009-02-06 22:33:59 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static PyMethodDef cmdpy_object_methods[] =
|
|
|
|
|
{
|
|
|
|
|
{ "dont_repeat", cmdpy_dont_repeat, METH_NOARGS,
|
|
|
|
|
"Prevent command repetition when user enters empty line." },
|
|
|
|
|
|
|
|
|
|
{ 0 }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static PyTypeObject cmdpy_object_type =
|
|
|
|
|
{
|
2012-12-12 17:47:30 +01:00
|
|
|
|
PyVarObject_HEAD_INIT (NULL, 0)
|
2009-02-06 22:33:59 +01:00
|
|
|
|
"gdb.Command", /*tp_name*/
|
|
|
|
|
sizeof (cmdpy_object), /*tp_basicsize*/
|
|
|
|
|
0, /*tp_itemsize*/
|
|
|
|
|
0, /*tp_dealloc*/
|
|
|
|
|
0, /*tp_print*/
|
|
|
|
|
0, /*tp_getattr*/
|
|
|
|
|
0, /*tp_setattr*/
|
|
|
|
|
0, /*tp_compare*/
|
|
|
|
|
0, /*tp_repr*/
|
|
|
|
|
0, /*tp_as_number*/
|
|
|
|
|
0, /*tp_as_sequence*/
|
|
|
|
|
0, /*tp_as_mapping*/
|
|
|
|
|
0, /*tp_hash */
|
|
|
|
|
0, /*tp_call*/
|
|
|
|
|
0, /*tp_str*/
|
|
|
|
|
0, /*tp_getattro*/
|
|
|
|
|
0, /*tp_setattro*/
|
|
|
|
|
0, /*tp_as_buffer*/
|
|
|
|
|
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
|
|
|
|
"GDB command object", /* tp_doc */
|
|
|
|
|
0, /* tp_traverse */
|
|
|
|
|
0, /* tp_clear */
|
|
|
|
|
0, /* tp_richcompare */
|
|
|
|
|
0, /* tp_weaklistoffset */
|
|
|
|
|
0, /* tp_iter */
|
|
|
|
|
0, /* tp_iternext */
|
|
|
|
|
cmdpy_object_methods, /* tp_methods */
|
|
|
|
|
0, /* tp_members */
|
|
|
|
|
0, /* tp_getset */
|
|
|
|
|
0, /* tp_base */
|
|
|
|
|
0, /* tp_dict */
|
|
|
|
|
0, /* tp_descr_get */
|
|
|
|
|
0, /* tp_descr_set */
|
|
|
|
|
0, /* tp_dictoffset */
|
|
|
|
|
cmdpy_init, /* tp_init */
|
|
|
|
|
0, /* tp_alloc */
|
|
|
|
|
};
|
2010-05-25 17:27:17 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Utility to build a buildargv-like result from ARGS.
|
|
|
|
|
This intentionally parses arguments the way libiberty/argv.c:buildargv
|
|
|
|
|
does. It splits up arguments in a reasonable way, and we want a standard
|
|
|
|
|
way of parsing arguments. Several gdb commands use buildargv to parse their
|
|
|
|
|
arguments. Plus we want to be able to write compatible python
|
|
|
|
|
implementations of gdb commands. */
|
|
|
|
|
|
|
|
|
|
PyObject *
|
|
|
|
|
gdbpy_string_to_argv (PyObject *self, PyObject *args)
|
|
|
|
|
{
|
|
|
|
|
PyObject *py_argv;
|
2011-06-24 21:47:37 +02:00
|
|
|
|
const char *input;
|
2010-05-25 17:27:17 +02:00
|
|
|
|
|
|
|
|
|
if (!PyArg_ParseTuple (args, "s", &input))
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
py_argv = PyList_New (0);
|
2013-05-20 22:14:51 +02:00
|
|
|
|
if (py_argv == NULL)
|
|
|
|
|
return NULL;
|
2010-05-25 17:27:17 +02:00
|
|
|
|
|
|
|
|
|
/* buildargv uses NULL to represent an empty argument list, but we can't use
|
|
|
|
|
that in Python. Instead, if ARGS is "" then return an empty list.
|
|
|
|
|
This undoes the NULL -> "" conversion that cmdpy_function does. */
|
|
|
|
|
|
|
|
|
|
if (*input != '\0')
|
|
|
|
|
{
|
|
|
|
|
char **c_argv = gdb_buildargv (input);
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; c_argv[i] != NULL; ++i)
|
|
|
|
|
{
|
|
|
|
|
PyObject *argp = PyString_FromString (c_argv[i]);
|
|
|
|
|
|
|
|
|
|
if (argp == NULL
|
|
|
|
|
|| PyList_Append (py_argv, argp) < 0)
|
|
|
|
|
{
|
2011-09-15 20:33:15 +02:00
|
|
|
|
Py_XDECREF (argp);
|
2010-05-25 17:27:17 +02:00
|
|
|
|
Py_DECREF (py_argv);
|
|
|
|
|
freeargv (c_argv);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2011-09-15 20:33:15 +02:00
|
|
|
|
Py_DECREF (argp);
|
2010-05-25 17:27:17 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
freeargv (c_argv);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return py_argv;
|
|
|
|
|
}
|