aboutsummaryrefslogtreecommitdiff
path: root/gdb/python
diff options
context:
space:
mode:
authorDoug Evans <xdje42@gmail.com>2014-02-05 19:27:58 -0800
committerDoug Evans <xdje42@gmail.com>2014-02-05 19:27:58 -0800
commit6dddc817c1680fc97756cbcb017fcf306fa5d07c (patch)
tree0c64ab10a49516d6ef76642e3b5adf18b9121622 /gdb/python
parent6af7998535fe2e125101af714b37fce3edb66995 (diff)
downloadgdb-6dddc817c1680fc97756cbcb017fcf306fa5d07c.zip
gdb-6dddc817c1680fc97756cbcb017fcf306fa5d07c.tar.gz
gdb-6dddc817c1680fc97756cbcb017fcf306fa5d07c.tar.bz2
Extension Language API
* configure.ac (libpython checking): Remove all but python.o from CONFIG_OBS. Remove all but python.c from CONFIG_SRCS. * configure: Regenerate. * Makefile.in (SFILES): Add extension.c. (HFILES_NO_SRCDIR): Add extension.h, extension-priv.h (COMMON_OBS): Add extension.o. * extension.h: New file. * extension-priv.h: New file. * extension.c: New file. * python/python-internal.h: #include "extension.h". (gdbpy_auto_load_enabled): Declare. (gdbpy_apply_val_pretty_printer): Declare. (gdbpy_apply_frame_filter): Declare. (gdbpy_preserve_values): Declare. (gdbpy_breakpoint_cond_says_stop): Declare. (gdbpy_breakpoint_has_cond): Declare. (void source_python_script_for_objfile): Delete. * python/python.c: #include "extension-priv.h". Delete inclusion of "observer.h". (extension_language_python): Moved here and renamed from script_language_python in py-auto-load.c. Redefined to be of type extension_language_defn. (python_extension_script_ops): New global. (python_extension_ops): New global. (struct python_env): New member previous_active. (restore_python_env): Call restore_active_ext_lang. (ensure_python_env): Call set_active_ext_lang. (gdbpy_clear_quit_flag): Renamed from clear_quit_flag, made static. New arg extlang. (gdbpy_set_quit_flag): Renamed from set_quit_flag, made static. New arg extlang. (gdbpy_check_quit_flag): Renamed from check_quit_flag, made static. New arg extlang. (gdbpy_eval_from_control_command): Renamed from eval_python_from_control_command, made static. New arg extlang. (gdbpy_source_script) Renamed from source_python_script, made static. New arg extlang. (gdbpy_before_prompt_hook): Renamed from before_prompt_hook. Change result to int. New arg extlang. (gdbpy_source_objfile_script): Renamed from source_python_script_for_objfile, made static. New arg extlang. (gdbpy_start_type_printers): Renamed from start_type_printers, made static. New args extlang, extlang_printers. Change result type to "void". (gdbpy_apply_type_printers): Renamed from apply_type_printers, made static. New arg extlang. Rename arg printers to extlang_printers and change type to ext_lang_type_printers *. (gdbpy_free_type_printers): Renamed from free_type_printers, made static. Replace argument arg with extlang, extlang_printers. (!HAVE_PYTHON, eval_python_from_control_command): Delete. (!HAVE_PYTHON, source_python_script): Delete. (!HAVE_PYTHON, gdbpy_should_stop): Delete. (!HAVE_PYTHON, gdbpy_breakpoint_has_py_cond): Delete. (!HAVE_PYTHON, start_type_printers): Delete. (!HAVE_PYTHON, apply_type_printers): Delete. (!HAVE_PYTHON, free_type_printers): Delete. (_initialize_python): Delete call to observer_attach_before_prompt. (finalize_python): Set/restore active extension language. (gdbpy_finish_initialization) Renamed from finish_python_initialization, made static. New arg extlang. (gdbpy_initialized): New function. * python/python.h: #include "extension.h". Delete #include "value.h", "mi/mi-cmds.h". (extension_language_python): Declare. (GDBPY_AUTO_FILE_NAME): Delete. (enum py_bt_status): Moved to extension.h and renamed to ext_lang_bt_status. (enum frame_filter_flags): Moved to extension.h. (enum py_frame_args): Moved to extension.h and renamed to ext_lang_frame_args. (finish_python_initialization): Delete. (eval_python_from_control_command): Delete. (source_python_script): Delete. (apply_val_pretty_printer): Delete. (apply_frame_filter): Delete. (preserve_python_values): Delete. (gdbpy_script_language_defn): Delete. (gdbpy_should_stop, gdbpy_breakpoint_has_py_cond): Delete. (start_type_printers, apply_type_printers, free_type_printers): Delete. * auto-load.c: #include "extension.h". (GDB_AUTO_FILE_NAME): Delete. (auto_load_gdb_scripts_enabled): Make public. New arg extlang. (script_language_gdb): Delete, moved to extension.c and renamed to extension_language_gdb. (source_gdb_script_for_objfile): Delete. (auto_load_pspace_info): New member unsupported_script_warning_printed. (loaded_script): Change type of language member to struct extension_language_defn *. (init_loaded_scripts_info): Initialize unsupported_script_warning_printed. (maybe_add_script): Make static. Change type of language arg to struct extension_language_defn *. (clear_section_scripts): Reset unsupported_script_warning_printed. (auto_load_objfile_script_1): Rewrite to use extension language API. (auto_load_objfile_script): Make public. Remove support-compiled-in and auto-load-enabled checks, moved to auto_load_scripts_for_objfile. (source_section_scripts): Rewrite to use extension language API. (load_auto_scripts_for_objfile): Rewrite to use auto_load_scripts_for_objfile. (collect_matching_scripts_data): Change type of language member to struct extension_language_defn *. (auto_load_info_scripts): Change type of language arg to struct extension_language_defn *. (unsupported_script_warning_print): New function. (script_not_found_warning_print): Make static. (_initialize_auto_load): Rewrite construction of scripts-directory help. * auto-load.h (struct objfile): Add forward decl. (struct script_language): Delete. (struct auto_load_pspace_info): Add forward decl. (struct extension_language_defn): Add forward decl. (maybe_add_script): Delete. (auto_load_objfile_script): Declare. (script_not_found_warning_print): Delete. (auto_load_info_scripts): Update prototype. (auto_load_gdb_scripts_enabled): Declare. * python/py-auto-load.c (gdbpy_auto_load_enabled): Renamed from auto_load_python_scripts_enabled and made public. (script_language_python): Delete, moved to python.c. (gdbpy_script_language_defn): Delete. (info_auto_load_python_scripts): Update to use extension_language_python. * breakpoint.c (condition_command): Replace call to gdbpy_breakpoint_has_py_cond with call to get_breakpoint_cond_ext_lang. (bpstat_check_breakpoint_conditions): Replace call to gdbpy_should_stop with call to breakpoint_ext_lang_cond_says_stop. * python/py-breakpoint.c (gdbpy_breakpoint_cond_says_stop): Renamed from gdbpy_should_stop. Change result type to enum scr_bp_stop. New arg slang. Return SCR_BP_STOP_UNSET if py_bp_object is NULL. (gdbpy_breakpoint_has_cond): Renamed from gdbpy_breakpoint_has_py_cond. New arg slang. (local_setattro): Print name of extension language with existing stop condition. * valprint.c (val_print, value_print): Update to call apply_ext_lang_val_pretty_printer. * cp-valprint.c (cp_print_value): Update call to apply_ext_lang_val_pretty_printer. * python/py-prettyprint.c: Remove #ifdef HAVE_PYTHON. (gdbpy_apply_val_pretty_printer): Renamed from apply_val_pretty_printer. New arg extlang. (!HAVE_PYTHON, apply_val_pretty_printer): Delete. * cli/cli-cmds.c (source_script_from_stream): Rewrite to use extension language API. * cli/cli-script.c (execute_control_command): Update to call eval_ext_lang_from_control_command. * mi/mi-cmd-stack.c (mi_cmd_stack_list_frames): Update to use enum ext_lang_bt_status values. Update call to apply_ext_lang_frame_filter. (mi_cmd_stack_list_locals): Ditto. (mi_cmd_stack_list_args): Ditto. (mi_cmd_stack_list_variables): Ditto. * mi/mi-main.c: Delete #include "python/python-internal.h". Add #include "extension.h". (mi_cmd_list_features): Replace reference to python internal variable gdb_python_initialized with call to ext_lang_initialized_p. * stack.c (backtrace_command_1): Update to use enum ext_lang_bt_status. Update to use enum ext_lang_frame_args. Update to call apply_ext_lang_frame_filter. * python/py-framefilter.c (extract_sym): Update to use enum ext_lang_bt_status. (extract_value, py_print_type, py_print_value): Ditto. (py_print_single_arg, enumerate_args, enumerate_locals): Ditto. (py_mi_print_variables, py_print_locals, py_print_args): Ditto. (py_print_frame): Ditto. (gdbpy_apply_frame_filter): Renamed from apply_frame_filter. New arg extlang. Update to use enum ext_lang_bt_status. * top.c (gdb_init): Delete #ifdef HAVE_PYTHON call to finish_python_initialization. Replace with call to finish_ext_lang_initialization. * typeprint.c (do_free_global_table): Update to call free_ext_lang_type_printers. (create_global_typedef_table): Update to call start_ext_lang_type_printers. (find_global_typedef): Update to call apply_ext_lang_type_printers. * typeprint.h (struct ext_lang_type_printers): Add forward decl. (type_print_options): Change type of global_printers from "void *" to "struct ext_lang_type_printers *". * value.c (preserve_values): Update to call preserve_ext_lang_values. * python/py-value.c: Remove #ifdef HAVE_PYTHON. (gdbpy_preserve_values): Renamed from preserve_python_values. New arg extlang. (!HAVE_PYTHON, preserve_python_values): Delete. * utils.c (quit_flag): Delete, moved to extension.c. (clear_quit_flag, set_quit_flag, check_quit_flag): Delete, moved to extension.c. * eval.c: Delete #include "python/python.h". * main.c: Delete #include "python/python.h". * defs.h: Update comment. testsuite/ * gdb.python/py-breakpoint.exp (test_bkpt_eval_funcs): Update expected output. * gdb.gdb/python-interrupts.exp: New file.
Diffstat (limited to 'gdb/python')
-rw-r--r--gdb/python/py-auto-load.c43
-rw-r--r--gdb/python/py-breakpoint.c82
-rw-r--r--gdb/python/py-framefilter.c230
-rw-r--r--gdb/python/py-prettyprint.c62
-rw-r--r--gdb/python/py-value.c15
-rw-r--r--gdb/python/python-internal.h33
-rw-r--r--gdb/python/python.c298
-rw-r--r--gdb/python/python.h115
8 files changed, 422 insertions, 456 deletions
diff --git a/gdb/python/py-auto-load.c b/gdb/python/py-auto-load.c
index ebea0c6..66f7316 100644
--- a/gdb/python/py-auto-load.c
+++ b/gdb/python/py-auto-load.c
@@ -25,9 +25,6 @@
#include "objfiles.h"
#include "python.h"
#include "auto-load.h"
-
-#ifdef HAVE_PYTHON
-
#include "python-internal.h"
/* User-settable option to enable/disable auto-loading of Python scripts:
@@ -45,38 +42,21 @@ show_auto_load_python_scripts (struct ui_file *file, int from_tty,
fprintf_filtered (file, _("Auto-loading of Python scripts is %s.\n"), value);
}
-/* Return non-zero if auto-loading Python scripts is enabled. */
+/* Return non-zero if auto-loading Python scripts is enabled.
+ This is the extension_language_script_ops.auto_load_enabled "method". */
-static int
-auto_load_python_scripts_enabled (void)
+int
+gdbpy_auto_load_enabled (const struct extension_language_defn *extlang)
{
return auto_load_python_scripts;
}
-/* Definition of script language for Python scripts. */
-
-static const struct script_language script_language_python =
-{
- "python",
- GDBPY_AUTO_FILE_NAME,
- auto_load_python_scripts_enabled,
- source_python_script_for_objfile
-};
-
-/* Return the Python script language definition. */
-
-const struct script_language *
-gdbpy_script_language_defn (void)
-{
- return &script_language_python;
-}
-
/* Wrapper for "info auto-load python-scripts". */
static void
info_auto_load_python_scripts (char *pattern, int from_tty)
{
- auto_load_info_scripts (pattern, from_tty, &script_language_python);
+ auto_load_info_scripts (pattern, from_tty, &extension_language_python);
}
int
@@ -125,16 +105,3 @@ Print the list of automatically loaded Python scripts, deprecated."));
return 0;
}
-
-#else /* ! HAVE_PYTHON */
-
-/* Return the Python script language definition.
- Since support isn't compiled in, return NULL. */
-
-const struct script_language *
-gdbpy_script_language_defn (void)
-{
- return NULL;
-}
-
-#endif /* ! HAVE_PYTHON */
diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
index aa404b7..125c6fd 100644
--- a/gdb/python/py-breakpoint.c
+++ b/gdb/python/py-breakpoint.c
@@ -750,15 +750,22 @@ gdbpy_breakpoints (PyObject *self, PyObject *args)
stopped at the breakpoint. Otherwise the inferior will be
allowed to continue. */
-int
-gdbpy_should_stop (struct gdbpy_breakpoint_object *bp_obj)
+enum ext_lang_bp_stop
+gdbpy_breakpoint_cond_says_stop (const struct extension_language_defn *extlang,
+ struct breakpoint *b)
{
- int stop = 1;
-
+ int stop;
+ struct gdbpy_breakpoint_object *bp_obj = b->py_bp_object;
PyObject *py_bp = (PyObject *) bp_obj;
- struct breakpoint *b = bp_obj->bp;
- struct gdbarch *garch = b->gdbarch ? b->gdbarch : get_current_arch ();
- struct cleanup *cleanup = ensure_python_env (garch, current_language);
+ struct gdbarch *garch;
+ struct cleanup *cleanup;
+
+ if (bp_obj == NULL)
+ return EXT_LANG_BP_STOP_UNSET;
+
+ stop = -1;
+ garch = b->gdbarch ? b->gdbarch : get_current_arch ();
+ cleanup = ensure_python_env (garch, current_language);
if (bp_obj->is_finish_bp)
bpfinishpy_pre_stop_hook (bp_obj);
@@ -767,6 +774,7 @@ gdbpy_should_stop (struct gdbpy_breakpoint_object *bp_obj)
{
PyObject *result = PyObject_CallMethod (py_bp, stop_func, NULL);
+ stop = 1;
if (result)
{
int evaluate = PyObject_IsTrue (result);
@@ -790,7 +798,9 @@ gdbpy_should_stop (struct gdbpy_breakpoint_object *bp_obj)
do_cleanups (cleanup);
- return stop;
+ if (stop < 0)
+ return EXT_LANG_BP_STOP_UNSET;
+ return stop ? EXT_LANG_BP_STOP_YES : EXT_LANG_BP_STOP_NO;
}
/* Checks if the "stop" method exists in this breakpoint.
@@ -798,17 +808,21 @@ gdbpy_should_stop (struct gdbpy_breakpoint_object *bp_obj)
conditions. */
int
-gdbpy_breakpoint_has_py_cond (struct gdbpy_breakpoint_object *bp_obj)
+gdbpy_breakpoint_has_cond (const struct extension_language_defn *extlang,
+ struct breakpoint *b)
{
- int has_func = 0;
- PyObject *py_bp = (PyObject *) bp_obj;
- struct gdbarch *garch = bp_obj->bp->gdbarch ? bp_obj->bp->gdbarch :
- get_current_arch ();
- struct cleanup *cleanup = ensure_python_env (garch, current_language);
-
- if (py_bp != NULL)
- has_func = PyObject_HasAttrString (py_bp, stop_func);
-
+ int has_func;
+ PyObject *py_bp;
+ struct gdbarch *garch;
+ struct cleanup *cleanup;
+
+ if (b->py_bp_object == NULL)
+ return 0;
+
+ py_bp = (PyObject *) b->py_bp_object;
+ garch = b->gdbarch ? b->gdbarch : get_current_arch ();
+ cleanup = ensure_python_env (garch, current_language);
+ has_func = PyObject_HasAttrString (py_bp, stop_func);
do_cleanups (cleanup);
return has_func;
@@ -947,16 +961,30 @@ local_setattro (PyObject *self, PyObject *name, PyObject *v)
return -1;
/* If the attribute trying to be set is the "stop" method,
- but we already have a condition set in the CLI, disallow this
- operation. */
- if (strcmp (attr, stop_func) == 0 && obj->bp->cond_string)
+ but we already have a condition set in the CLI or other extension
+ language, disallow this operation. */
+ if (strcmp (attr, stop_func) == 0)
{
- xfree (attr);
- PyErr_SetString (PyExc_RuntimeError,
- _("Cannot set 'stop' method. There is an " \
- "existing GDB condition attached to the " \
- "breakpoint."));
- return -1;
+ const struct extension_language_defn *extlang = NULL;
+
+ if (obj->bp->cond_string != NULL)
+ extlang = get_ext_lang_defn (EXT_LANG_GDB);
+ if (extlang == NULL)
+ extlang = get_breakpoint_cond_ext_lang (obj->bp, EXT_LANG_PYTHON);
+ if (extlang != NULL)
+ {
+ char *error_text;
+
+ xfree (attr);
+ error_text
+ = xstrprintf (_("Only one stop condition allowed. There is"
+ " currently a %s stop condition defined for"
+ " this breakpoint."),
+ ext_lang_capitalized_name (extlang));
+ PyErr_SetString (PyExc_RuntimeError, error_text);
+ xfree (error_text);
+ return -1;
+ }
}
xfree (attr);
diff --git a/gdb/python/py-framefilter.c b/gdb/python/py-framefilter.c
index 1a9f3e0..ec38225 100644
--- a/gdb/python/py-framefilter.c
+++ b/gdb/python/py-framefilter.c
@@ -48,17 +48,17 @@ enum mi_print_types
this will be set to NULL. LANGUAGE is also a pass-through argument
denoting the language attributed to the Symbol. In the case of SYM
being NULL, this will be set to the current language. Returns
- PY_BT_ERROR on error with the appropriate Python exception set, and
- PY_BT_OK on success. */
+ EXT_LANG_BT_ERROR on error with the appropriate Python exception set, and
+ EXT_LANG_BT_OK on success. */
-static enum py_bt_status
+static enum ext_lang_bt_status
extract_sym (PyObject *obj, char **name, struct symbol **sym,
const struct language_defn **language)
{
PyObject *result = PyObject_CallMethod (obj, "symbol", NULL);
if (result == NULL)
- return PY_BT_ERROR;
+ return EXT_LANG_BT_ERROR;
/* For 'symbol' callback, the function can return a symbol or a
string. */
@@ -68,7 +68,7 @@ extract_sym (PyObject *obj, char **name, struct symbol **sym,
Py_DECREF (result);
if (*name == NULL)
- return PY_BT_ERROR;
+ return EXT_LANG_BT_ERROR;
/* If the API returns a string (and not a symbol), then there is
no symbol derived language available and the frame filter has
either overridden the symbol with a string, or supplied a
@@ -90,7 +90,7 @@ extract_sym (PyObject *obj, char **name, struct symbol **sym,
PyErr_SetString (PyExc_RuntimeError,
_("Unexpected value. Expecting a "
"gdb.Symbol or a Python string."));
- return PY_BT_ERROR;
+ return EXT_LANG_BT_ERROR;
}
/* Duplicate the symbol name, so the caller has consistency
@@ -106,7 +106,7 @@ extract_sym (PyObject *obj, char **name, struct symbol **sym,
*language = current_language;
}
- return PY_BT_OK;
+ return EXT_LANG_BT_OK;
}
/* Helper function to extract a value from an object that conforms to
@@ -114,11 +114,11 @@ extract_sym (PyObject *obj, char **name, struct symbol **sym,
the value from. VALUE is a pass-through argument where the value
will be written. If the object does not have the value attribute,
or provides the Python None for a value, VALUE will be set to NULL
- and this function will return as successful. Returns PY_BT_ERROR
- on error with the appropriate Python exception set, and PY_BT_OK on
+ and this function will return as successful. Returns EXT_LANG_BT_ERROR
+ on error with the appropriate Python exception set, and EXT_LANG_BT_OK on
success. */
-static enum py_bt_status
+static enum ext_lang_bt_status
extract_value (PyObject *obj, struct value **value)
{
if (PyObject_HasAttrString (obj, "value"))
@@ -126,7 +126,7 @@ extract_value (PyObject *obj, struct value **value)
PyObject *vresult = PyObject_CallMethod (obj, "value", NULL);
if (vresult == NULL)
- return PY_BT_ERROR;
+ return EXT_LANG_BT_ERROR;
/* The Python code has returned 'None' for a value, so we set
value to NULL. This flags that GDB should read the
@@ -135,7 +135,7 @@ extract_value (PyObject *obj, struct value **value)
{
Py_DECREF (vresult);
*value = NULL;
- return PY_BT_OK;
+ return EXT_LANG_BT_OK;
}
else
{
@@ -143,15 +143,15 @@ extract_value (PyObject *obj, struct value **value)
Py_DECREF (vresult);
if (*value == NULL)
- return PY_BT_ERROR;
+ return EXT_LANG_BT_ERROR;
- return PY_BT_OK;
+ return EXT_LANG_BT_OK;
}
}
else
*value = NULL;
- return PY_BT_OK;
+ return EXT_LANG_BT_OK;
}
/* MI prints only certain values according to the type of symbol and
@@ -195,11 +195,11 @@ mi_should_print (struct symbol *sym, enum mi_print_types type)
/* Helper function which outputs a type name extracted from VAL to a
"type" field in the output stream OUT. OUT is the ui-out structure
the type name will be output too, and VAL is the value that the
- type will be extracted from. Returns PY_BT_ERROR on error, with
- any GDB exceptions converted to a Python exception, or PY_BT_OK on
+ type will be extracted from. Returns EXT_LANG_BT_ERROR on error, with
+ any GDB exceptions converted to a Python exception, or EXT_LANG_BT_OK on
success. */
-static enum py_bt_status
+static enum ext_lang_bt_status
py_print_type (struct ui_out *out, struct value *val)
{
volatile struct gdb_exception except;
@@ -220,10 +220,10 @@ py_print_type (struct ui_out *out, struct value *val)
if (except.reason < 0)
{
gdbpy_convert_exception (except);
- return PY_BT_ERROR;
+ return EXT_LANG_BT_ERROR;
}
- return PY_BT_OK;
+ return EXT_LANG_BT_OK;
}
/* Helper function which outputs a value to an output field in a
@@ -231,15 +231,15 @@ py_print_type (struct ui_out *out, struct value *val)
VAL is the value that will be printed, OPTS contains the value
printing options, ARGS_TYPE is an enumerator describing the
argument format, and LANGUAGE is the language_defn that the value
- will be printed with. Returns PY_BT_ERROR on error, with any GDB
- exceptions converted to a Python exception, or PY_BT_OK on
+ will be printed with. Returns EXT_LANG_BT_ERROR on error, with any GDB
+ exceptions converted to a Python exception, or EXT_LANG_BT_OK on
success. */
-static enum py_bt_status
+static enum ext_lang_bt_status
py_print_value (struct ui_out *out, struct value *val,
const struct value_print_options *opts,
int indent,
- enum py_frame_args args_type,
+ enum ext_lang_frame_args args_type,
const struct language_defn *language)
{
int should_print = 0;
@@ -265,7 +265,7 @@ py_print_value (struct ui_out *out, struct value *val,
if (except.reason < 0)
{
gdbpy_convert_exception (except);
- return PY_BT_ERROR;
+ return EXT_LANG_BT_ERROR;
}
if (args_type == MI_PRINT_ALL_VALUES)
@@ -295,11 +295,11 @@ py_print_value (struct ui_out *out, struct value *val,
if (except.reason < 0)
{
gdbpy_convert_exception (except);
- return PY_BT_ERROR;
+ return EXT_LANG_BT_ERROR;
}
}
- return PY_BT_OK;
+ return EXT_LANG_BT_OK;
}
/* Helper function to call a Python method and extract an iterator
@@ -350,16 +350,16 @@ get_py_iter_from_func (PyObject *filter, char *func)
ARGS_TYPE is an enumerator describing the argument format,
PRINT_ARGS_FIELD is a flag which indicates if we output "ARGS=1"
in MI output in commands where both arguments and locals are
- printed. Returns PY_BT_ERROR on error, with any GDB exceptions
- converted to a Python exception, or PY_BT_OK on success. */
+ printed. Returns EXT_LANG_BT_ERROR on error, with any GDB exceptions
+ converted to a Python exception, or EXT_LANG_BT_OK on success. */
-static enum py_bt_status
+static enum ext_lang_bt_status
py_print_single_arg (struct ui_out *out,
const char *sym_name,
struct frame_arg *fa,
struct value *fv,
const struct value_print_options *opts,
- enum py_frame_args args_type,
+ enum ext_lang_frame_args args_type,
int print_args_field,
const struct language_defn *language)
{
@@ -435,7 +435,7 @@ py_print_single_arg (struct ui_out *out,
types. */
if (args_type == MI_PRINT_SIMPLE_VALUES)
{
- if (py_print_type (out, val) == PY_BT_ERROR)
+ if (py_print_type (out, val) == EXT_LANG_BT_ERROR)
{
do_cleanups (cleanups);
goto error;
@@ -455,7 +455,7 @@ py_print_single_arg (struct ui_out *out,
if (args_type != NO_VALUES)
{
if (py_print_value (out, val, opts, 0, args_type, language)
- == PY_BT_ERROR)
+ == EXT_LANG_BT_ERROR)
{
do_cleanups (cleanups);
goto error;
@@ -471,10 +471,10 @@ py_print_single_arg (struct ui_out *out,
goto error;
}
- return PY_BT_OK;
+ return EXT_LANG_BT_OK;
error:
- return PY_BT_ERROR;
+ return EXT_LANG_BT_ERROR;
}
/* Helper function to loop over frame arguments provided by the
@@ -484,14 +484,14 @@ py_print_single_arg (struct ui_out *out,
enumerator describing the argument format, PRINT_ARGS_FIELD is a
flag which indicates if we output "ARGS=1" in MI output in commands
where both arguments and locals are printed, and FRAME is the
- backing frame. Returns PY_BT_ERROR on error, with any GDB
- exceptions converted to a Python exception, or PY_BT_OK on
+ backing frame. Returns EXT_LANG_BT_ERROR on error, with any GDB
+ exceptions converted to a Python exception, or EXT_LANG_BT_OK on
success. */
-static enum py_bt_status
+static enum ext_lang_bt_status
enumerate_args (PyObject *iter,
struct ui_out *out,
- enum py_frame_args args_type,
+ enum ext_lang_frame_args args_type,
int print_args_field,
struct frame_info *frame)
{
@@ -533,17 +533,17 @@ enumerate_args (PyObject *iter,
char *sym_name;
struct symbol *sym;
struct value *val;
- enum py_bt_status success = PY_BT_ERROR;
+ enum ext_lang_bt_status success = EXT_LANG_BT_ERROR;
success = extract_sym (item, &sym_name, &sym, &language);
- if (success == PY_BT_ERROR)
+ if (success == EXT_LANG_BT_ERROR)
{
Py_DECREF (item);
goto error;
}
success = extract_value (item, &val);
- if (success == PY_BT_ERROR)
+ if (success == EXT_LANG_BT_ERROR)
{
xfree (sym_name);
Py_DECREF (item);
@@ -597,7 +597,7 @@ enumerate_args (PyObject *iter,
NULL, &opts,
args_type,
print_args_field,
- NULL) == PY_BT_ERROR)
+ NULL) == EXT_LANG_BT_ERROR)
{
xfree (arg.error);
xfree (entryarg.error);
@@ -625,9 +625,9 @@ enumerate_args (PyObject *iter,
}
}
- if (py_print_single_arg (out, NULL, &entryarg, NULL,
- &opts, args_type,
- print_args_field, NULL) == PY_BT_ERROR)
+ if (py_print_single_arg (out, NULL, &entryarg, NULL, &opts,
+ args_type, print_args_field, NULL)
+ == EXT_LANG_BT_ERROR)
{
xfree (arg.error);
xfree (entryarg.error);
@@ -646,7 +646,7 @@ enumerate_args (PyObject *iter,
{
if (py_print_single_arg (out, sym_name, NULL, val, &opts,
args_type, print_args_field,
- language) == PY_BT_ERROR)
+ language) == EXT_LANG_BT_ERROR)
{
xfree (sym_name);
goto error;
@@ -688,10 +688,10 @@ enumerate_args (PyObject *iter,
}
}
- return PY_BT_OK;
+ return EXT_LANG_BT_OK;
error:
- return PY_BT_ERROR;
+ return EXT_LANG_BT_ERROR;
}
@@ -703,14 +703,14 @@ enumerate_args (PyObject *iter,
the argument format, PRINT_ARGS_FIELD is flag which indicates
whether to output the ARGS field in the case of
-stack-list-variables and FRAME is the backing frame. Returns
- PY_BT_ERROR on error, with any GDB exceptions converted to a Python
- exception, or PY_BT_OK on success. */
+ EXT_LANG_BT_ERROR on error, with any GDB exceptions converted to a Python
+ exception, or EXT_LANG_BT_OK on success. */
-static enum py_bt_status
+static enum ext_lang_bt_status
enumerate_locals (PyObject *iter,
struct ui_out *out,
int indent,
- enum py_frame_args args_type,
+ enum ext_lang_frame_args args_type,
int print_args_field,
struct frame_info *frame)
{
@@ -725,7 +725,7 @@ enumerate_locals (PyObject *iter,
const struct language_defn *language;
char *sym_name;
struct value *val;
- enum py_bt_status success = PY_BT_ERROR;
+ enum ext_lang_bt_status success = EXT_LANG_BT_ERROR;
struct symbol *sym;
volatile struct gdb_exception except;
int local_indent = 8 + (8 * indent);
@@ -734,7 +734,7 @@ enumerate_locals (PyObject *iter,
locals_cleanups = make_cleanup_py_decref (item);
success = extract_sym (item, &sym_name, &sym, &language);
- if (success == PY_BT_ERROR)
+ if (success == EXT_LANG_BT_ERROR)
{
do_cleanups (locals_cleanups);
goto error;
@@ -743,7 +743,7 @@ enumerate_locals (PyObject *iter,
make_cleanup (xfree, sym_name);
success = extract_value (item, &val);
- if (success == PY_BT_ERROR)
+ if (success == EXT_LANG_BT_ERROR)
{
do_cleanups (locals_cleanups);
goto error;
@@ -801,7 +801,7 @@ enumerate_locals (PyObject *iter,
if (args_type == MI_PRINT_SIMPLE_VALUES)
{
- if (py_print_type (out, val) == PY_BT_ERROR)
+ if (py_print_type (out, val) == EXT_LANG_BT_ERROR)
{
do_cleanups (locals_cleanups);
goto error;
@@ -815,7 +815,7 @@ enumerate_locals (PyObject *iter,
int val_indent = (indent + 1) * 4;
if (py_print_value (out, val, &opts, val_indent, args_type,
- language) == PY_BT_ERROR)
+ language) == EXT_LANG_BT_ERROR)
{
do_cleanups (locals_cleanups);
goto error;
@@ -826,7 +826,7 @@ enumerate_locals (PyObject *iter,
if (args_type != NO_VALUES)
{
if (py_print_value (out, val, &opts, 0, args_type,
- language) == PY_BT_ERROR)
+ language) == EXT_LANG_BT_ERROR)
{
do_cleanups (locals_cleanups);
goto error;
@@ -850,19 +850,19 @@ enumerate_locals (PyObject *iter,
if (item == NULL && PyErr_Occurred ())
goto error;
- return PY_BT_OK;
+ return EXT_LANG_BT_OK;
error:
- return PY_BT_ERROR;
+ return EXT_LANG_BT_ERROR;
}
-/* Helper function for -stack-list-variables. Returns PY_BT_ERROR on
- error, or PY_BT_OK on success. */
+/* Helper function for -stack-list-variables. Returns EXT_LANG_BT_ERROR on
+ error, or EXT_LANG_BT_OK on success. */
-static enum py_bt_status
+static enum ext_lang_bt_status
py_mi_print_variables (PyObject *filter, struct ui_out *out,
struct value_print_options *opts,
- enum py_frame_args args_type,
+ enum ext_lang_frame_args args_type,
struct frame_info *frame)
{
struct cleanup *old_chain;
@@ -882,30 +882,31 @@ py_mi_print_variables (PyObject *filter, struct ui_out *out,
make_cleanup_ui_out_list_begin_end (out, "variables");
if (args_iter != Py_None)
- if (enumerate_args (args_iter, out, args_type, 1, frame) == PY_BT_ERROR)
+ if (enumerate_args (args_iter, out, args_type, 1, frame)
+ == EXT_LANG_BT_ERROR)
goto error;
if (locals_iter != Py_None)
if (enumerate_locals (locals_iter, out, 1, args_type, 1, frame)
- == PY_BT_ERROR)
+ == EXT_LANG_BT_ERROR)
goto error;
do_cleanups (old_chain);
- return PY_BT_OK;
+ return EXT_LANG_BT_OK;
error:
do_cleanups (old_chain);
- return PY_BT_ERROR;
+ return EXT_LANG_BT_ERROR;
}
/* Helper function for printing locals. This function largely just
creates the wrapping tuple, and calls enumerate_locals. Returns
- PY_BT_ERROR on error, or PY_BT_OK on success.*/
+ EXT_LANG_BT_ERROR on error, or EXT_LANG_BT_OK on success. */
-static enum py_bt_status
+static enum ext_lang_bt_status
py_print_locals (PyObject *filter,
struct ui_out *out,
- enum py_frame_args args_type,
+ enum ext_lang_frame_args args_type,
int indent,
struct frame_info *frame)
{
@@ -920,26 +921,26 @@ py_print_locals (PyObject *filter,
if (locals_iter != Py_None)
if (enumerate_locals (locals_iter, out, indent, args_type,
- 0, frame) == PY_BT_ERROR)
+ 0, frame) == EXT_LANG_BT_ERROR)
goto locals_error;
do_cleanups (old_chain);
- return PY_BT_OK;;
+ return EXT_LANG_BT_OK;
locals_error:
do_cleanups (old_chain);
- return PY_BT_ERROR;
+ return EXT_LANG_BT_ERROR;
}
/* Helper function for printing frame arguments. This function
largely just creates the wrapping tuple, and calls enumerate_args.
- Returns PY_BT_ERROR on error, with any GDB exceptions converted to
- a Python exception, or PY_BT_OK on success. */
+ Returns EXT_LANG_BT_ERROR on error, with any GDB exceptions converted to
+ a Python exception, or EXT_LANG_BT_OK on success. */
-static enum py_bt_status
+static enum ext_lang_bt_status
py_print_args (PyObject *filter,
struct ui_out *out,
- enum py_frame_args args_type,
+ enum ext_lang_frame_args args_type,
struct frame_info *frame)
{
PyObject *args_iter = get_py_iter_from_func (filter, "frame_args");
@@ -964,7 +965,8 @@ py_print_args (PyObject *filter,
}
if (args_iter != Py_None)
- if (enumerate_args (args_iter, out, args_type, 0, frame) == PY_BT_ERROR)
+ if (enumerate_args (args_iter, out, args_type, 0, frame)
+ == EXT_LANG_BT_ERROR)
goto args_error;
TRY_CATCH (except, RETURN_MASK_ALL)
@@ -979,11 +981,11 @@ py_print_args (PyObject *filter,
}
do_cleanups (old_chain);
- return PY_BT_OK;
+ return EXT_LANG_BT_OK;
args_error:
do_cleanups (old_chain);
- return PY_BT_ERROR;
+ return EXT_LANG_BT_ERROR;
}
/* Print a single frame to the designated output stream, detecting
@@ -997,12 +999,13 @@ py_print_args (PyObject *filter,
(in the case of elided frames), and LEVELS_PRINTED is a hash-table
containing all the frames level that have already been printed.
If a frame level has been printed, do not print it again (in the
- case of elided frames). Returns PY_BT_ERROR on error, with any
- GDB exceptions converted to a Python exception, or PY_BT_COMPLETED
+ case of elided frames). Returns EXT_LANG_BT_ERROR on error, with any
+ GDB exceptions converted to a Python exception, or EXT_LANG_BT_COMPLETED
on success. */
-static enum py_bt_status
-py_print_frame (PyObject *filter, int flags, enum py_frame_args args_type,
+static enum ext_lang_bt_status
+py_print_frame (PyObject *filter, int flags,
+ enum ext_lang_frame_args args_type,
struct ui_out *out, int indent, htab_t levels_printed)
{
int has_addr = 0;
@@ -1052,12 +1055,12 @@ py_print_frame (PyObject *filter, int flags, enum py_frame_args args_type,
if (print_locals && print_args && ! print_frame_info)
{
if (py_mi_print_variables (filter, out, &opts,
- args_type, frame) == PY_BT_ERROR)
+ args_type, frame) == EXT_LANG_BT_ERROR)
goto error;
else
{
do_cleanups (cleanup_stack);
- return PY_BT_COMPLETED;
+ return EXT_LANG_BT_COMPLETED;
}
}
@@ -1230,7 +1233,7 @@ py_print_frame (PyObject *filter, int flags, enum py_frame_args args_type,
wrong. */
if (print_args)
{
- if (py_print_args (filter, out, args_type, frame) == PY_BT_ERROR)
+ if (py_print_args (filter, out, args_type, frame) == EXT_LANG_BT_ERROR)
goto error;
}
@@ -1334,7 +1337,7 @@ py_print_frame (PyObject *filter, int flags, enum py_frame_args args_type,
if (print_locals)
{
if (py_print_locals (filter, out, args_type, indent,
- frame) == PY_BT_ERROR)
+ frame) == EXT_LANG_BT_ERROR)
goto error;
}
@@ -1355,12 +1358,12 @@ py_print_frame (PyObject *filter, int flags, enum py_frame_args args_type,
while ((item = PyIter_Next (elided)))
{
- enum py_bt_status success = py_print_frame (item, flags,
- args_type, out,
- indent,
- levels_printed);
+ enum ext_lang_bt_status success = py_print_frame (item, flags,
+ args_type, out,
+ indent,
+ levels_printed);
- if (success == PY_BT_ERROR)
+ if (success == EXT_LANG_BT_ERROR)
{
Py_DECREF (item);
goto error;
@@ -1374,11 +1377,11 @@ py_print_frame (PyObject *filter, int flags, enum py_frame_args args_type,
do_cleanups (cleanup_stack);
- return PY_BT_COMPLETED;
+ return EXT_LANG_BT_COMPLETED;
error:
do_cleanups (cleanup_stack);
- return PY_BT_ERROR;
+ return EXT_LANG_BT_ERROR;
}
/* Helper function to initiate frame filter invocation at starting
@@ -1456,26 +1459,25 @@ bootstrap_python_frame_filters (struct frame_info *frame,
variables. ARGS_TYPE is an enumerator describing the argument
format, OUT is the output stream to print. FRAME_LOW is the
beginning of the slice of frames to print, and FRAME_HIGH is the
- upper limit of the frames to count. Returns PY_BT_ERROR on error,
- or PY_BT_COMPLETED on success.*/
-
-enum py_bt_status
-apply_frame_filter (struct frame_info *frame, int flags,
- enum py_frame_args args_type,
- struct ui_out *out, int frame_low,
- int frame_high)
-
+ upper limit of the frames to count. Returns EXT_LANG_BT_ERROR on error,
+ or EXT_LANG_BT_COMPLETED on success. */
+
+enum ext_lang_bt_status
+gdbpy_apply_frame_filter (const struct extension_language_defn *extlang,
+ struct frame_info *frame, int flags,
+ enum ext_lang_frame_args args_type,
+ struct ui_out *out, int frame_low, int frame_high)
{
struct gdbarch *gdbarch = NULL;
struct cleanup *cleanups;
- enum py_bt_status success = PY_BT_ERROR;
+ enum ext_lang_bt_status success = EXT_LANG_BT_ERROR;
PyObject *iterable;
volatile struct gdb_exception except;
PyObject *item;
htab_t levels_printed;
if (!gdb_python_initialized)
- return PY_BT_NO_FILTERS;
+ return EXT_LANG_BT_NO_FILTERS;
TRY_CATCH (except, RETURN_MASK_ALL)
{
@@ -1484,7 +1486,7 @@ apply_frame_filter (struct frame_info *frame, int flags,
if (except.reason < 0)
{
/* Let gdb try to print the stack trace. */
- return PY_BT_NO_FILTERS;
+ return EXT_LANG_BT_NO_FILTERS;
}
cleanups = ensure_python_env (gdbarch, current_language);
@@ -1501,14 +1503,14 @@ apply_frame_filter (struct frame_info *frame, int flags,
where GDB cannot initialize the frame filters (most likely
due to incorrect auto-load paths), GDB has printed nothing.
In this case it is OK to print the default backtrace after
- printing the error message. GDB returns PY_BT_NO_FILTERS
+ printing the error message. GDB returns EXT_LANG_BT_NO_FILTERS
here to signify there are no filters after printing the
initialization error. This return code will trigger a
default backtrace. */
gdbpy_print_stack ();
do_cleanups (cleanups);
- return PY_BT_NO_FILTERS;
+ return EXT_LANG_BT_NO_FILTERS;
}
/* If iterable is None, then there are no frame filters registered.
@@ -1517,7 +1519,7 @@ apply_frame_filter (struct frame_info *frame, int flags,
make_cleanup_py_decref (iterable);
if (iterable == Py_None)
{
- success = PY_BT_NO_FILTERS;
+ success = EXT_LANG_BT_NO_FILTERS;
goto done;
}
@@ -1534,7 +1536,7 @@ apply_frame_filter (struct frame_info *frame, int flags,
/* Do not exit on error printing a single frame. Print the
error and continue with other frames. */
- if (success == PY_BT_ERROR)
+ if (success == EXT_LANG_BT_ERROR)
gdbpy_print_stack ();
Py_DECREF (item);
@@ -1552,5 +1554,5 @@ apply_frame_filter (struct frame_info *frame, int flags,
error:
gdbpy_print_stack ();
do_cleanups (cleanups);
- return PY_BT_ERROR;
+ return EXT_LANG_BT_ERROR;
}
diff --git a/gdb/python/py-prettyprint.c b/gdb/python/py-prettyprint.c
index 879f0de..a7cd337 100644
--- a/gdb/python/py-prettyprint.c
+++ b/gdb/python/py-prettyprint.c
@@ -23,10 +23,8 @@
#include "symtab.h"
#include "language.h"
#include "valprint.h"
-
+#include "extension-priv.h"
#include "python.h"
-
-#ifdef HAVE_PYTHON
#include "python-internal.h"
/* Return type of print_string_repr. */
@@ -300,7 +298,7 @@ print_stack_unless_memory_error (struct ui_file *stream)
gdbpy_print_stack ();
}
-/* Helper for apply_val_pretty_printer which calls to_string and
+/* Helper for gdbpy_apply_val_pretty_printer which calls to_string and
formats the result. */
static enum string_repr_result
@@ -467,7 +465,7 @@ push_dummy_python_frame (void)
}
#endif
-/* Helper for apply_val_pretty_printer that formats children of the
+/* Helper for gdbpy_apply_val_pretty_printer that formats children of the
printer, if any exist. If is_py_none is true, then nothing has
been printed by to_string, and format output accordingly. */
static void
@@ -686,13 +684,14 @@ print_children (PyObject *printer, const char *hint,
do_cleanups (cleanups);
}
-int
-apply_val_pretty_printer (struct type *type, const gdb_byte *valaddr,
- int embedded_offset, CORE_ADDR address,
- struct ui_file *stream, int recurse,
- const struct value *val,
- const struct value_print_options *options,
- const struct language_defn *language)
+enum ext_lang_rc
+gdbpy_apply_val_pretty_printer (const struct extension_language_defn *extlang,
+ struct type *type, const gdb_byte *valaddr,
+ int embedded_offset, CORE_ADDR address,
+ struct ui_file *stream, int recurse,
+ const struct value *val,
+ const struct value_print_options *options,
+ const struct language_defn *language)
{
struct gdbarch *gdbarch = get_type_arch (type);
PyObject *printer = NULL;
@@ -700,15 +699,15 @@ apply_val_pretty_printer (struct type *type, const gdb_byte *valaddr,
struct value *value;
char *hint = NULL;
struct cleanup *cleanups;
- int result = 0;
+ enum ext_lang_rc result = EXT_LANG_RC_NOP;
enum string_repr_result print_result;
/* No pretty-printer support for unavailable values. */
if (!value_bytes_available (val, embedded_offset, TYPE_LENGTH (type)))
- return 0;
+ return EXT_LANG_RC_NOP;
if (!gdb_python_initialized)
- return 0;
+ return EXT_LANG_RC_NOP;
cleanups = ensure_python_env (gdbarch, language);
@@ -728,18 +727,27 @@ apply_val_pretty_printer (struct type *type, const gdb_byte *valaddr,
val_obj = value_to_value_object (value);
if (! val_obj)
- goto done;
+ {
+ result = EXT_LANG_RC_ERROR;
+ goto done;
+ }
/* Find the constructor. */
printer = find_pretty_printer (val_obj);
Py_DECREF (val_obj);
if (printer == NULL)
- goto done;
+ {
+ result = EXT_LANG_RC_ERROR;
+ goto done;
+ }
make_cleanup_py_decref (printer);
if (printer == Py_None)
- goto done;
+ {
+ result = EXT_LANG_RC_NOP;
+ goto done;
+ }
/* If we are printing a map, we want some special formatting. */
hint = gdbpy_get_display_hint (printer);
@@ -752,8 +760,7 @@ apply_val_pretty_printer (struct type *type, const gdb_byte *valaddr,
print_children (printer, hint, stream, recurse, options, language,
print_result == string_repr_none);
- result = 1;
-
+ result = EXT_LANG_RC_OK;
done:
if (PyErr_Occurred ())
@@ -838,18 +845,3 @@ gdbpy_default_visualizer (PyObject *self, PyObject *args)
cons = find_pretty_printer (val_obj);
return cons;
}
-
-#else /* HAVE_PYTHON */
-
-int
-apply_val_pretty_printer (struct type *type, const gdb_byte *valaddr,
- int embedded_offset, CORE_ADDR address,
- struct ui_file *stream, int recurse,
- const struct value *val,
- const struct value_print_options *options,
- const struct language_defn *language)
-{
- return 0;
-}
-
-#endif /* HAVE_PYTHON */
diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c
index 67e6c4e..f8a8a98 100644
--- a/gdb/python/py-value.c
+++ b/gdb/python/py-value.c
@@ -30,8 +30,6 @@
#include "cp-abi.h"
#include "python.h"
-#ifdef HAVE_PYTHON
-
#include "python-internal.h"
/* Even though Python scalar types directly map to host types, we use
@@ -163,7 +161,8 @@ valpy_new (PyTypeObject *subtype, PyObject *args, PyObject *keywords)
/* Iterate over all the Value objects, calling preserve_one_value on
each. */
void
-preserve_python_values (struct objfile *objfile, htab_t copied_types)
+gdbpy_preserve_values (const struct extension_language_defn *extlang,
+ struct objfile *objfile, htab_t copied_types)
{
value_object *iter;
@@ -1702,13 +1701,3 @@ PyTypeObject value_object_type = {
0, /* tp_alloc */
valpy_new /* tp_new */
};
-
-#else
-
-void
-preserve_python_values (struct objfile *objfile, htab_t copied_types)
-{
- /* Nothing. */
-}
-
-#endif /* HAVE_PYTHON */
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index ef5cd3f..07650f7 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -20,6 +20,8 @@
#ifndef GDB_PYTHON_INTERNAL_H
#define GDB_PYTHON_INTERNAL_H
+#include "extension.h"
+
/* These WITH_* macros are defined by the CPython API checker that
comes with the Python plugin for GCC. See:
https://gcc-python-plugin.readthedocs.org/en/latest/cpychecker.html
@@ -279,7 +281,33 @@ typedef struct
extern struct cmd_list_element *set_python_list;
extern struct cmd_list_element *show_python_list;
-
+
+/* extension_language_script_ops "methods". */
+
+extern int gdbpy_auto_load_enabled (const struct extension_language_defn *);
+
+/* extension_language_ops "methods". */
+
+extern enum ext_lang_rc gdbpy_apply_val_pretty_printer
+ (const struct extension_language_defn *,
+ struct type *type, const gdb_byte *valaddr,
+ int embedded_offset, CORE_ADDR address,
+ struct ui_file *stream, int recurse,
+ const struct value *val,
+ const struct value_print_options *options,
+ const struct language_defn *language);
+extern enum ext_lang_bt_status gdbpy_apply_frame_filter
+ (const struct extension_language_defn *,
+ struct frame_info *frame, int flags, enum ext_lang_frame_args args_type,
+ struct ui_out *out, int frame_low, int frame_high);
+extern void gdbpy_preserve_values (const struct extension_language_defn *,
+ struct objfile *objfile,
+ htab_t copied_types);
+extern enum ext_lang_bp_stop gdbpy_breakpoint_cond_says_stop
+ (const struct extension_language_defn *, struct breakpoint *);
+extern int gdbpy_breakpoint_has_cond (const struct extension_language_defn *,
+ struct breakpoint *b);
+
PyObject *gdbpy_history (PyObject *self, PyObject *args);
PyObject *gdbpy_breakpoints (PyObject *, PyObject *);
PyObject *gdbpy_frame_stop_reason_string (PyObject *, PyObject *);
@@ -436,9 +464,6 @@ extern const struct language_defn *python_language;
void gdbpy_print_stack (void);
-void source_python_script_for_objfile (struct objfile *objfile, FILE *file,
- const char *filename);
-
PyObject *python_string_to_unicode (PyObject *obj);
char *unicode_to_target_string (PyObject *unicode_str);
char *python_string_to_target_string (PyObject *obj);
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 337c170..cbfa73a 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -32,8 +32,8 @@
#include "serial.h"
#include "readline/tilde.h"
#include "python.h"
+#include "extension-priv.h"
#include "cli/cli-utils.h"
-
#include <ctype.h>
/* Declared constants and enum for python stack printing. */
@@ -57,6 +57,34 @@ static const char *const python_excp_enums[] =
static const char *gdbpy_should_print_stack = python_excp_message;
#ifdef HAVE_PYTHON
+/* Forward decls, these are defined later. */
+static const struct extension_language_script_ops python_extension_script_ops;
+static const struct extension_language_ops python_extension_ops;
+#endif
+
+/* The main struct describing GDB's interface to the Python
+ extension language. */
+const struct extension_language_defn extension_language_python =
+{
+ EXT_LANG_PYTHON,
+ "python",
+ "Python",
+
+ ".py",
+ "-gdb.py",
+
+ python_control,
+
+#ifdef HAVE_PYTHON
+ &python_extension_script_ops,
+ &python_extension_ops
+#else
+ NULL,
+ NULL
+#endif
+};
+
+#ifdef HAVE_PYTHON
#include "libiberty.h"
#include "cli/cli-decode.h"
@@ -69,7 +97,6 @@ static const char *gdbpy_should_print_stack = python_excp_message;
#include "version.h"
#include "target.h"
#include "gdbthread.h"
-#include "observer.h"
#include "interps.h"
#include "event-top.h"
@@ -104,6 +131,64 @@ PyObject *gdbpy_gdb_error;
/* The `gdb.MemoryError' exception. */
PyObject *gdbpy_gdb_memory_error;
+static script_sourcer_func gdbpy_source_script;
+static objfile_script_sourcer_func gdbpy_source_objfile_script;
+static void gdbpy_finish_initialization
+ (const struct extension_language_defn *);
+static int gdbpy_initialized (const struct extension_language_defn *);
+static void gdbpy_eval_from_control_command
+ (const struct extension_language_defn *, struct command_line *cmd);
+static void gdbpy_start_type_printers (const struct extension_language_defn *,
+ struct ext_lang_type_printers *);
+static enum ext_lang_rc gdbpy_apply_type_printers
+ (const struct extension_language_defn *,
+ const struct ext_lang_type_printers *, struct type *, char **);
+static void gdbpy_free_type_printers (const struct extension_language_defn *,
+ struct ext_lang_type_printers *);
+static void gdbpy_clear_quit_flag (const struct extension_language_defn *);
+static void gdbpy_set_quit_flag (const struct extension_language_defn *);
+static int gdbpy_check_quit_flag (const struct extension_language_defn *);
+static enum ext_lang_rc gdbpy_before_prompt_hook
+ (const struct extension_language_defn *, const char *current_gdb_prompt);
+
+/* The interface between gdb proper and loading of python scripts. */
+
+static const struct extension_language_script_ops python_extension_script_ops =
+{
+ gdbpy_source_script,
+ gdbpy_source_objfile_script,
+ gdbpy_auto_load_enabled
+};
+
+/* The interface between gdb proper and python extensions. */
+
+static const struct extension_language_ops python_extension_ops =
+{
+ gdbpy_finish_initialization,
+ gdbpy_initialized,
+
+ gdbpy_eval_from_control_command,
+
+ gdbpy_start_type_printers,
+ gdbpy_apply_type_printers,
+ gdbpy_free_type_printers,
+
+ gdbpy_apply_val_pretty_printer,
+
+ gdbpy_apply_frame_filter,
+
+ gdbpy_preserve_values,
+
+ gdbpy_breakpoint_has_cond,
+ gdbpy_breakpoint_cond_says_stop,
+
+ gdbpy_clear_quit_flag,
+ gdbpy_set_quit_flag,
+ gdbpy_check_quit_flag,
+
+ gdbpy_before_prompt_hook
+};
+
/* Architecture and language to be used in callbacks from
the Python interpreter. */
struct gdbarch *python_gdbarch;
@@ -114,6 +199,7 @@ const struct language_defn *python_language;
struct python_env
{
+ struct active_ext_lang_state *previous_active;
PyGILState_STATE state;
struct gdbarch *gdbarch;
const struct language_defn *language;
@@ -138,11 +224,17 @@ restore_python_env (void *p)
PyGILState_Release (env->state);
python_gdbarch = env->gdbarch;
python_language = env->language;
+
+ restore_active_ext_lang (env->previous_active);
+
xfree (env);
}
/* Called before entering the Python interpreter to install the
- current language and architecture to be used for Python values. */
+ current language and architecture to be used for Python values.
+ Also set the active extension language for GDB so that SIGINT's
+ are directed our way, and if necessary install the right SIGINT
+ handler. */
struct cleanup *
ensure_python_env (struct gdbarch *gdbarch,
@@ -154,6 +246,8 @@ ensure_python_env (struct gdbarch *gdbarch,
if (!gdb_python_initialized)
error (_("Python not initialized"));
+ env->previous_active = set_active_ext_lang (&extension_language_python);
+
env->state = PyGILState_Ensure ();
env->gdbarch = python_gdbarch;
env->language = python_language;
@@ -169,8 +263,8 @@ ensure_python_env (struct gdbarch *gdbarch,
/* Clear the quit flag. */
-void
-clear_quit_flag (void)
+static void
+gdbpy_clear_quit_flag (const struct extension_language_defn *extlang)
{
/* This clears the flag as a side effect. */
PyOS_InterruptOccurred ();
@@ -178,16 +272,16 @@ clear_quit_flag (void)
/* Set the quit flag. */
-void
-set_quit_flag (void)
+static void
+gdbpy_set_quit_flag (const struct extension_language_defn *extlang)
{
PyErr_SetInterrupt ();
}
/* Return true if the quit flag has been set, false otherwise. */
-int
-check_quit_flag (void)
+static int
+gdbpy_check_quit_flag (const struct extension_language_defn *extlang)
{
return PyOS_InterruptOccurred ();
}
@@ -343,8 +437,9 @@ compute_python_string (struct command_line *l)
/* Take a command line structure representing a 'python' command, and
evaluate its body using the Python interpreter. */
-void
-eval_python_from_control_command (struct command_line *cmd)
+static void
+gdbpy_eval_from_control_command (const struct extension_language_defn *extlang,
+ struct command_line *cmd)
{
int ret;
char *script;
@@ -765,12 +860,14 @@ gdbpy_find_pc_line (PyObject *self, PyObject *args)
}
/* Read a file as Python code.
- FILE is the file to run. FILENAME is name of the file FILE.
+ This is the extension_language_script_ops.script_sourcer "method".
+ FILE is the file to load. FILENAME is name of the file FILE.
This does not throw any errors. If an exception occurs python will print
the traceback and clear the error indicator. */
-void
-source_python_script (FILE *file, const char *filename)
+static void
+gdbpy_source_script (const struct extension_language_defn *extlang,
+ FILE *file, const char *filename)
{
struct cleanup *cleanup;
@@ -899,14 +996,17 @@ gdbpy_initialize_events (void)
-static void
-before_prompt_hook (const char *current_gdb_prompt)
+/* This is the extension_language_ops.before_prompt "method". */
+
+static enum ext_lang_rc
+gdbpy_before_prompt_hook (const struct extension_language_defn *extlang,
+ const char *current_gdb_prompt)
{
struct cleanup *cleanup;
char *prompt = NULL;
if (!gdb_python_initialized)
- return;
+ return EXT_LANG_RC_NOP;
cleanup = ensure_python_env (get_current_arch (), current_language);
@@ -968,12 +1068,12 @@ before_prompt_hook (const char *current_gdb_prompt)
set_prompt (prompt);
do_cleanups (cleanup);
- return;
+ return prompt != NULL ? EXT_LANG_RC_OK : EXT_LANG_RC_NOP;
fail:
gdbpy_print_stack ();
do_cleanups (cleanup);
- return;
+ return EXT_LANG_RC_ERROR;
}
@@ -1158,16 +1258,19 @@ gdbpy_progspaces (PyObject *unused1, PyObject *unused2)
/* The "current" objfile. This is set when gdb detects that a new
objfile has been loaded. It is only set for the duration of a call to
- source_python_script_for_objfile; it is NULL at other times. */
+ gdbpy_source_objfile_script; it is NULL at other times. */
static struct objfile *gdbpy_current_objfile;
/* Set the current objfile to OBJFILE and then read FILE named FILENAME
as Python code. This does not throw any errors. If an exception
- occurs python will print the traceback and clear the error indicator. */
+ occurs python will print the traceback and clear the error indicator.
+ This is the extension_language_script_ops.objfile_script_sourcer
+ "method". */
-void
-source_python_script_for_objfile (struct objfile *objfile, FILE *file,
- const char *filename)
+static void
+gdbpy_source_objfile_script (const struct extension_language_defn *extlang,
+ struct objfile *objfile, FILE *file,
+ const char *filename)
{
struct cleanup *cleanups;
@@ -1225,18 +1328,20 @@ gdbpy_objfiles (PyObject *unused1, PyObject *unused2)
return list;
}
-/* Compute the list of active type printers and return it. The result
- of this function can be passed to apply_type_printers, and should
- be freed by free_type_printers. */
+/* Compute the list of active python type printers and store them in
+ EXT_PRINTERS->py_type_printers. The product of this function is used by
+ gdbpy_apply_type_printers, and freed by gdbpy_free_type_printers.
+ This is the extension_language_ops.start_type_printers "method". */
-void *
-start_type_printers (void)
+static void
+gdbpy_start_type_printers (const struct extension_language_defn *extlang,
+ struct ext_lang_type_printers *ext_printers)
{
struct cleanup *cleanups;
- PyObject *type_module, *func = NULL, *result_obj = NULL;
+ PyObject *type_module, *func = NULL, *printers_obj = NULL;
if (!gdb_python_initialized)
- return NULL;
+ return;
cleanups = ensure_python_env (get_current_arch (), current_language);
@@ -1254,39 +1359,41 @@ start_type_printers (void)
goto done;
}
- result_obj = PyObject_CallFunctionObjArgs (func, (char *) NULL);
- if (result_obj == NULL)
+ printers_obj = PyObject_CallFunctionObjArgs (func, (char *) NULL);
+ if (printers_obj == NULL)
gdbpy_print_stack ();
+ else
+ ext_printers->py_type_printers = printers_obj;
done:
Py_XDECREF (type_module);
Py_XDECREF (func);
do_cleanups (cleanups);
- return result_obj;
}
-/* If TYPE is recognized by some type printer, return a newly
- allocated string holding the type's replacement name. The caller
- is responsible for freeing the string. Otherwise, return NULL.
-
- This function has a bit of a funny name, since it actually applies
- recognizers, but this seemed clearer given the start_type_printers
- and free_type_printers functions. */
-
-char *
-apply_type_printers (void *printers, struct type *type)
+/* If TYPE is recognized by some type printer, store in *PRETTIED_TYPE
+ a newly allocated string holding the type's replacement name, and return
+ EXT_LANG_RC_OK. The caller is responsible for freeing the string.
+ If there's a Python error return EXT_LANG_RC_ERROR.
+ Otherwise, return EXT_LANG_RC_NOP.
+ This is the extension_language_ops.apply_type_printers "method". */
+
+static enum ext_lang_rc
+gdbpy_apply_type_printers (const struct extension_language_defn *extlang,
+ const struct ext_lang_type_printers *ext_printers,
+ struct type *type, char **prettied_type)
{
struct cleanup *cleanups;
PyObject *type_obj, *type_module = NULL, *func = NULL;
PyObject *result_obj = NULL;
- PyObject *printers_obj = printers;
+ PyObject *printers_obj = ext_printers->py_type_printers;
char *result = NULL;
if (printers_obj == NULL)
- return NULL;
+ return EXT_LANG_RC_NOP;
if (!gdb_python_initialized)
- return NULL;
+ return EXT_LANG_RC_NOP;
cleanups = ensure_python_env (get_current_arch (), current_language);
@@ -1332,16 +1439,20 @@ apply_type_printers (void *printers, struct type *type)
Py_XDECREF (func);
Py_XDECREF (result_obj);
do_cleanups (cleanups);
- return result;
+ if (result != NULL)
+ *prettied_type = result;
+ return result != NULL ? EXT_LANG_RC_OK : EXT_LANG_RC_ERROR;
}
-/* Free the result of start_type_printers. */
+/* Free the result of start_type_printers.
+ This is the extension_language_ops.free_type_printers "method". */
-void
-free_type_printers (void *arg)
+static void
+gdbpy_free_type_printers (const struct extension_language_defn *extlang,
+ struct ext_lang_type_printers *ext_printers)
{
struct cleanup *cleanups;
- PyObject *printers = arg;
+ PyObject *printers = ext_printers->py_type_printers;
if (printers == NULL)
return;
@@ -1381,62 +1492,6 @@ python_command (char *arg, int from_tty)
python_interactive_command (arg, from_tty);
}
-void
-eval_python_from_control_command (struct command_line *cmd)
-{
- error (_("Python scripting is not supported in this copy of GDB."));
-}
-
-void
-source_python_script (FILE *file, const char *filename)
-{
- internal_error (__FILE__, __LINE__,
- _("source_python_script called when Python scripting is "
- "not supported."));
-}
-
-int
-gdbpy_should_stop (struct gdbpy_breakpoint_object *bp_obj)
-{
- internal_error (__FILE__, __LINE__,
- _("gdbpy_should_stop called when Python scripting is " \
- "not supported."));
-}
-
-int
-gdbpy_breakpoint_has_py_cond (struct gdbpy_breakpoint_object *bp_obj)
-{
- internal_error (__FILE__, __LINE__,
- _("gdbpy_breakpoint_has_py_cond called when Python " \
- "scripting is not supported."));
-}
-
-void *
-start_type_printers (void)
-{
- return NULL;
-}
-
-char *
-apply_type_printers (void *ignore, struct type *type)
-{
- return NULL;
-}
-
-void
-free_type_printers (void *arg)
-{
-}
-
-enum py_bt_status
-apply_frame_filter (struct frame_info *frame, int flags,
- enum py_frame_args args_type,
- struct ui_out *out, int frame_low,
- int frame_high)
-{
- return PY_BT_NO_FILTERS;
-}
-
#endif /* HAVE_PYTHON */
@@ -1473,16 +1528,25 @@ user_show_python (char *args, int from_tty)
static void
finalize_python (void *ignore)
{
+ struct active_ext_lang_state *previous_active;
+
/* We don't use ensure_python_env here because if we ever ran the
cleanup, gdb would crash -- because the cleanup calls into the
Python interpreter, which we are about to destroy. It seems
clearer to make the needed calls explicitly here than to create a
cleanup and then mysteriously discard it. */
+
+ /* This is only called as a final cleanup so we can assume the active
+ SIGINT handler is gdb's. We still need to tell it to notify Python. */
+ previous_active = set_active_ext_lang (&extension_language_python);
+
(void) PyGILState_Ensure ();
python_gdbarch = target_gdbarch ();
python_language = current_language;
Py_Finalize ();
+
+ restore_active_ext_lang (previous_active);
}
#endif
@@ -1691,8 +1755,6 @@ message == an error message without a stack will be printed."),
|| gdbpy_initialize_arch () < 0)
goto fail;
- observer_attach_before_prompt (before_prompt_hook);
-
gdbpy_to_string_cst = PyString_FromString ("to_string");
if (gdbpy_to_string_cst == NULL)
goto fail;
@@ -1734,10 +1796,11 @@ message == an error message without a stack will be printed."),
/* Perform the remaining python initializations.
These must be done after GDB is at least mostly initialized.
E.g., The "info pretty-printer" command needs the "info" prefix
- command installed. */
+ command installed.
+ This is the extension_language_ops.finish_initialization "method". */
-void
-finish_python_initialization (void)
+static void
+gdbpy_finish_initialization (const struct extension_language_defn *extlang)
{
PyObject *m;
char *gdb_pythondir;
@@ -1816,6 +1879,15 @@ finish_python_initialization (void)
do_cleanups (cleanup);
}
+/* Return non-zero if Python has successfully initialized.
+ This is the extension_languages_ops.initialized "method". */
+
+static int
+gdbpy_initialized (const struct extension_language_defn *extlang)
+{
+ return gdb_python_initialized;
+}
+
#endif /* HAVE_PYTHON */
diff --git a/gdb/python/python.h b/gdb/python/python.h
index 96bf7c2..9e99992 100644
--- a/gdb/python/python.h
+++ b/gdb/python/python.h
@@ -20,118 +20,9 @@
#ifndef GDB_PYTHON_H
#define GDB_PYTHON_H
-#include "value.h"
-#include "mi/mi-cmds.h"
+#include "extension.h"
-struct gdbpy_breakpoint_object;
-
-/* The suffix of per-objfile scripts to auto-load.
- E.g. When the program loads libfoo.so, look for libfoo-gdb.py. */
-#define GDBPY_AUTO_FILE_NAME "-gdb.py"
-
-/* Python frame-filter status return values. */
-enum py_bt_status
- {
- /* Return when an error has occurred in processing frame filters,
- or when printing the stack. */
- PY_BT_ERROR = -1,
-
- /* Return from internal routines to indicate that the function
- succeeded. */
- PY_BT_OK = 1,
-
- /* Return when the frame filter process is complete, and all
- operations have succeeded. */
- PY_BT_COMPLETED = 2,
-
- /* Return when the frame filter process is complete, but there
- were no filter registered and enabled to process. */
- PY_BT_NO_FILTERS = 3
- };
-
-/* Flags to pass to apply_frame_filter. */
-
-enum frame_filter_flags
- {
- /* Set this flag if frame level is to be printed. */
- PRINT_LEVEL = 1,
-
- /* Set this flag if frame information is to be printed. */
- PRINT_FRAME_INFO = 2,
-
- /* Set this flag if frame arguments are to be printed. */
- PRINT_ARGS = 4,
-
- /* Set this flag if frame locals are to be printed. */
- PRINT_LOCALS = 8,
- };
-
-/* A choice of the different frame argument printing strategies that
- can occur in different cases of frame filter instantiation. */
-typedef enum py_frame_args
-{
- /* Print no values for arguments when invoked from the MI. */
- NO_VALUES = PRINT_NO_VALUES,
-
- MI_PRINT_ALL_VALUES = PRINT_ALL_VALUES,
-
- /* Print only simple values (what MI defines as "simple") for
- arguments when invoked from the MI. */
- MI_PRINT_SIMPLE_VALUES = PRINT_SIMPLE_VALUES,
-
-
- /* Print only scalar values for arguments when invoked from the
- CLI. */
- CLI_SCALAR_VALUES,
-
- /* Print all values for arguments when invoked from the
- CLI. */
- CLI_ALL_VALUES
-} py_frame_args;
-
-/* Returns true if Python support is built into GDB, false
- otherwise. */
-
-static inline int
-have_python (void)
-{
-#ifdef HAVE_PYTHON
- return 1;
-#else
- return 0;
-#endif
-}
-
-extern void finish_python_initialization (void);
-
-void eval_python_from_control_command (struct command_line *);
-
-void source_python_script (FILE *file, const char *filename);
-
-int apply_val_pretty_printer (struct type *type, const gdb_byte *valaddr,
- int embedded_offset, CORE_ADDR address,
- struct ui_file *stream, int recurse,
- const struct value *val,
- const struct value_print_options *options,
- const struct language_defn *language);
-
-enum py_bt_status apply_frame_filter (struct frame_info *frame, int flags,
- enum py_frame_args args_type,
- struct ui_out *out, int frame_low,
- int frame_high);
-
-void preserve_python_values (struct objfile *objfile, htab_t copied_types);
-
-const struct script_language *gdbpy_script_language_defn (void);
-
-int gdbpy_should_stop (struct gdbpy_breakpoint_object *bp_obj);
-
-int gdbpy_breakpoint_has_py_cond (struct gdbpy_breakpoint_object *bp_obj);
-
-void *start_type_printers (void);
-
-char *apply_type_printers (void *, struct type *type);
-
-void free_type_printers (void *arg);
+/* This is all that python exports to gdb. */
+extern const struct extension_language_defn extension_language_python;
#endif /* GDB_PYTHON_H */