const struct breakpoint_ops *ops =
breakpoint_ops_for_event_location (location.get (), false);
- create_breakpoint (python_gdbarch,
+ create_breakpoint (gdbpy_enter::get_gdbarch (),
location.get (), NULL, -1, NULL, false,
0,
temporary_bp, type,
int stop;
struct gdbpy_breakpoint_object *bp_obj = b->py_bp_object;
PyObject *py_bp = (PyObject *) bp_obj;
- struct gdbarch *garch;
if (bp_obj == NULL)
return EXT_LANG_BP_STOP_UNSET;
stop = -1;
- garch = b->gdbarch ? b->gdbarch : get_current_arch ();
- gdbpy_enter enter_py (garch, current_language);
+ gdbpy_enter enter_py (b->gdbarch);
if (bp_obj->is_finish_bp)
bpfinishpy_pre_stop_hook (bp_obj);
struct breakpoint *b)
{
PyObject *py_bp;
- struct gdbarch *garch;
if (b->py_bp_object == NULL)
return 0;
py_bp = (PyObject *) b->py_bp_object;
- garch = b->gdbarch ? b->gdbarch : get_current_arch ();
- gdbpy_enter enter_py (garch, current_language);
+ gdbpy_enter enter_py (b->gdbarch);
return PyObject_HasAttrString (py_bp, stop_func);
}
return;
}
- struct gdbarch *garch = bp->gdbarch ? bp->gdbarch : get_current_arch ();
- gdbpy_enter enter_py (garch, current_language);
+ gdbpy_enter enter_py (bp->gdbarch);
if (bppy_pending_object)
{
bp = get_breakpoint (num);
if (bp)
{
- struct gdbarch *garch = bp->gdbarch ? bp->gdbarch : get_current_arch ();
- gdbpy_enter enter_py (garch, current_language);
+ gdbpy_enter enter_py (b->gdbarch);
gdbpy_ref<gdbpy_breakpoint_object> bp_obj (bp->py_bp_object);
if (bp_obj != NULL)
bp = get_breakpoint (num);
if (bp)
{
- struct gdbarch *garch = bp->gdbarch ? bp->gdbarch : get_current_arch ();
- gdbpy_enter enter_py (garch, current_language);
+ gdbpy_enter enter_py (b->gdbarch);
PyObject *bp_obj = (PyObject *) bp->py_bp_object;
if (bp_obj)
static void
cmdpy_destroyer (struct cmd_list_element *self, void *context)
{
- gdbpy_enter enter_py (get_current_arch (), current_language);
+ gdbpy_enter enter_py;
/* Release our hold on the command object. */
gdbpy_ref<cmdpy_object> cmd ((cmdpy_object *) context);
{
cmdpy_object *obj = (cmdpy_object *) command->context ();
- gdbpy_enter enter_py (get_current_arch (), current_language);
+ gdbpy_enter enter_py;
if (! obj)
error (_("Invalid invocation of Python command object."));
completion_tracker &tracker,
const char *text, const char *word)
{
- gdbpy_enter enter_py (get_current_arch (), current_language);
+ gdbpy_enter enter_py;
/* Calling our helper to obtain a reference to the PyObject of the Python
function. */
completion_tracker &tracker,
const char *text, const char *word)
{
- gdbpy_enter enter_py (get_current_arch (), current_language);
+ gdbpy_enter enter_py;
/* Calling our helper to obtain a reference to the PyObject of the Python
function. */
if (!gdb_python_initialized)
return;
- gdbpy_enter enter_py (get_current_arch (), current_language);
+ gdbpy_enter enter_py;
if (!evregpy_no_listeners_p (gdb_py_events.connection_removed))
if (emit_connection_event (target, gdb_py_events.connection_removed) < 0)
/* Set a breakpoint on the return address. */
event_location_up location
= new_address_location (get_frame_pc (prev_frame), NULL, 0);
- create_breakpoint (python_gdbarch,
+ create_breakpoint (gdbpy_enter::get_gdbarch (),
location.get (), NULL, thread, NULL, false,
0,
1 /*temp_flag*/,
static void
bpfinishpy_handle_stop (struct bpstat *bs, int print_frame)
{
- gdbpy_enter enter_py (get_current_arch (), current_language);
+ gdbpy_enter enter_py;
for (breakpoint *bp : all_breakpoints_safe ())
bpfinishpy_detect_out_scope_cb (bp, bs == NULL ? NULL : bs->breakpoint_at);
static void
bpfinishpy_handle_exit (struct inferior *inf)
{
- gdbpy_enter enter_py (target_gdbarch (), current_language);
+ gdbpy_enter enter_py (target_gdbarch ());
for (breakpoint *bp : all_breakpoints_safe ())
bpfinishpy_detect_out_scope_cb (bp, nullptr);
if (*name == NULL)
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
- entirely synthetic symbol/value pairing. In that case, use
- python_language. */
- *language = python_language;
+ no symbol derived language available and the frame filter has
+ either overridden the symbol with a string, or supplied a
+ entirely synthetic symbol/value pairing. In that case, use
+ the current language. */
+ *language = current_language;
*sym = NULL;
*sym_block = NULL;
}
return EXT_LANG_BT_NO_FILTERS;
}
- gdbpy_enter enter_py (gdbarch, current_language);
+ gdbpy_enter enter_py (gdbarch);
/* When we're limiting the number of frames, be careful to request
one extra frame, so that we can print a message if there are more
stop_signal = inferior_thread ()->stop_signal ();
- gdbpy_enter enter_py (get_current_arch (), current_language);
+ gdbpy_enter enter_py;
if (emit_stop_event (bs, stop_signal) < 0)
gdbpy_print_stack ();
if (!gdb_python_initialized)
return;
- gdbpy_enter enter_py (target_gdbarch (), current_language);
+ gdbpy_enter enter_py (target_gdbarch ());
if (emit_continue_event (ptid) < 0)
gdbpy_print_stack ();
static void
python_on_inferior_call_pre (ptid_t thread, CORE_ADDR address)
{
- gdbpy_enter enter_py (target_gdbarch (), current_language);
+ gdbpy_enter enter_py (target_gdbarch ());
if (emit_inferior_call_event (INFERIOR_CALL_PRE, thread, address) < 0)
gdbpy_print_stack ();
static void
python_on_inferior_call_post (ptid_t thread, CORE_ADDR address)
{
- gdbpy_enter enter_py (target_gdbarch (), current_language);
+ gdbpy_enter enter_py (target_gdbarch ());
if (emit_inferior_call_event (INFERIOR_CALL_POST, thread, address) < 0)
gdbpy_print_stack ();
static void
python_on_memory_change (struct inferior *inferior, CORE_ADDR addr, ssize_t len, const bfd_byte *data)
{
- gdbpy_enter enter_py (target_gdbarch (), current_language);
+ gdbpy_enter enter_py (target_gdbarch ());
if (emit_memory_changed_event (addr, len) < 0)
gdbpy_print_stack ();
static void
python_on_register_change (struct frame_info *frame, int regnum)
{
- gdbpy_enter enter_py (target_gdbarch (), current_language);
+ gdbpy_enter enter_py (target_gdbarch ());
if (emit_register_changed_event (frame, regnum) < 0)
gdbpy_print_stack ();
if (!gdb_python_initialized)
return;
- gdbpy_enter enter_py (target_gdbarch (), current_language);
+ gdbpy_enter enter_py (target_gdbarch ());
if (inf->has_exit_code)
exit_code = &inf->exit_code;
gdbpy_enter enter_py (objfile != NULL
? objfile->arch ()
- : target_gdbarch (),
- current_language);
+ : target_gdbarch ());
if (objfile == NULL)
{
if (!gdb_python_initialized)
return;
- gdbpy_enter enter_py (python_gdbarch, python_language);
+ gdbpy_enter enter_py;
if (evregpy_no_listeners_p (gdb_py_events.new_inferior))
return;
if (!gdb_python_initialized)
return;
- gdbpy_enter enter_py (python_gdbarch, python_language);
+ gdbpy_enter enter_py;
if (evregpy_no_listeners_p (gdb_py_events.inferior_deleted))
return;
if (!gdb_python_initialized)
return;
- gdbpy_enter enter_py (python_gdbarch, python_language);
+ gdbpy_enter enter_py;
gdbpy_ref<thread_object> thread_obj = create_thread_object (tp);
if (thread_obj == NULL)
if (!gdb_python_initialized)
return;
- gdbpy_enter enter_py (python_gdbarch, python_language);
+ gdbpy_enter enter_py;
gdbpy_ref<inferior_object> inf_obj = inferior_to_inferior_object (tp->inf);
if (inf_obj == NULL)
if (!gdb_python_initialized)
return;
- gdbpy_enter enter_py (python_gdbarch, python_language);
+ gdbpy_enter enter_py;
gdbpy_ref<inferior_object> inf_obj ((inferior_object *) datum);
inf_obj->inferior = NULL;
return PyString_FromFormat (_("Memory buffer for address %s, \
which is %s bytes long."),
- paddress (python_gdbarch, membuf_obj->addr),
+ paddress (gdbpy_enter::get_gdbarch (),
+ membuf_obj->addr),
pulongest (membuf_obj->length));
}
static void
py_free_objfile (struct objfile *objfile, void *datum)
{
- gdbpy_enter enter_py (objfile->arch (), current_language);
+ gdbpy_enter enter_py (objfile->arch ());
gdbpy_ref<objfile_object> object ((objfile_object *) datum);
object->objfile = NULL;
}
PyObject *obj = (PyObject *) c->context ();
gdb::unique_xmalloc_ptr<char> set_doc_string;
- gdbpy_enter enter_py (get_current_arch (), current_language);
+ gdbpy_enter enter_py;
gdbpy_ref<> set_doc_func (PyString_FromString ("get_set_string"));
if (set_doc_func == NULL)
PyObject *obj = (PyObject *) c->context ();
gdb::unique_xmalloc_ptr<char> show_doc_string;
- gdbpy_enter enter_py (get_current_arch (), current_language);
+ gdbpy_enter enter_py;
gdbpy_ref<> show_doc_func (PyString_FromString ("get_show_string"));
if (show_doc_func == NULL)
being deleted. */
struct gdbarch *arch = target_gdbarch ();
- gdbpy_enter enter_py (arch, current_language);
+ gdbpy_enter enter_py (arch);
gdbpy_ref<pspace_object> object ((pspace_object *) datum);
object->pspace = NULL;
}
tui_py_window::~tui_py_window ()
{
- gdbpy_enter enter_py (get_current_arch (), current_language);
+ gdbpy_enter enter_py;
/* This can be null if the user-provided Python construction
function failed. */
{
tui_win_info::rerender ();
- gdbpy_enter enter_py (get_current_arch (), current_language);
+ gdbpy_enter enter_py;
int h = viewport_height ();
int w = viewport_width ();
void
tui_py_window::do_scroll_horizontal (int num_to_scroll)
{
- gdbpy_enter enter_py (get_current_arch (), current_language);
+ gdbpy_enter enter_py;
if (PyObject_HasAttrString (m_window.get (), "hscroll"))
{
void
tui_py_window::do_scroll_vertical (int num_to_scroll)
{
- gdbpy_enter enter_py (get_current_arch (), current_language);
+ gdbpy_enter enter_py;
if (PyObject_HasAttrString (m_window.get (), "vscroll"))
{
void
tui_py_window::click (int mouse_x, int mouse_y, int mouse_button)
{
- gdbpy_enter enter_py (get_current_arch (), current_language);
+ gdbpy_enter enter_py;
if (PyObject_HasAttrString (m_window.get (), "click"))
{
gdbpy_tui_window_maker (const gdbpy_tui_window_maker &other)
{
- gdbpy_enter enter_py (get_current_arch (), current_language);
+ gdbpy_enter enter_py;
m_constr = other.m_constr;
}
gdbpy_tui_window_maker &operator= (const gdbpy_tui_window_maker &other)
{
- gdbpy_enter enter_py (get_current_arch (), current_language);
+ gdbpy_enter enter_py;
m_constr = other.m_constr;
return *this;
}
gdbpy_tui_window_maker::~gdbpy_tui_window_maker ()
{
- gdbpy_enter enter_py (get_current_arch (), current_language);
+ gdbpy_enter enter_py;
m_constr.reset (nullptr);
}
tui_win_info *
gdbpy_tui_window_maker::operator() (const char *win_name)
{
- gdbpy_enter enter_py (get_current_arch (), current_language);
+ gdbpy_enter enter_py;
gdbpy_ref<gdbpy_tui_window> wrapper
(PyObject_New (gdbpy_tui_window, &gdbpy_tui_window_object_type));
else if (startswith (type_name, "enum "))
type = lookup_enum (type_name + 5, NULL);
else
- type = lookup_typename (python_language,
+ type = lookup_typename (current_language,
type_name, block, 0);
}
catch (const gdb_exception &except)
/* This prevents another thread from freeing the objects we're
operating on. */
- gdbpy_enter enter_py (objfile->arch (), current_language);
+ gdbpy_enter enter_py (objfile->arch ());
htab_up copied_types = create_copied_types_hash (objfile);
struct gdbarch *gdbarch = (struct gdbarch *) (self->unwind_data);
cached_frame_info *cached_frame;
- gdbpy_enter enter_py (gdbarch, current_language);
+ gdbpy_enter enter_py (gdbarch);
pyuw_debug_printf ("frame=%d, sp=%s, pc=%s",
frame_relative_level (this_frame),
gdb::unique_xmalloc_ptr<char>
unicode_to_target_string (PyObject *unicode_str)
{
- return unicode_to_encoded_string (unicode_str,
- target_charset (python_gdbarch));
+ return (unicode_to_encoded_string
+ (unicode_str,
+ target_charset (gdbpy_enter::get_gdbarch ())));
}
/* Returns a PyObject with the contents of the given unicode string
static gdbpy_ref<>
unicode_to_target_python_string (PyObject *unicode_str)
{
- return unicode_to_encoded_python_string (unicode_str,
- target_charset (python_gdbarch));
+ return (unicode_to_encoded_python_string
+ (unicode_str,
+ target_charset (gdbpy_enter::get_gdbarch ())));
}
/* Converts a python string (8-bit or unicode) to a target string in
GDB (which uses target arithmetic). */
/* Python's integer type corresponds to C's long type. */
-#define builtin_type_pyint builtin_type (python_gdbarch)->builtin_long
+#define builtin_type_pyint \
+ builtin_type (gdbpy_enter::get_gdbarch ())->builtin_long
/* Python's float type corresponds to C's double type. */
-#define builtin_type_pyfloat builtin_type (python_gdbarch)->builtin_double
+#define builtin_type_pyfloat \
+ builtin_type (gdbpy_enter::get_gdbarch ())->builtin_double
/* Python's long type corresponds to C's long long type. */
-#define builtin_type_pylong builtin_type (python_gdbarch)->builtin_long_long
+#define builtin_type_pylong \
+ builtin_type (gdbpy_enter::get_gdbarch ())->builtin_long_long
/* Python's long type corresponds to C's long long type. Unsigned version. */
#define builtin_type_upylong builtin_type \
- (python_gdbarch)->builtin_unsigned_long_long
+ (gdbpy_enter::get_gdbarch ())->builtin_unsigned_long_long
#define builtin_type_pybool \
- language_bool_type (python_language, python_gdbarch)
+ language_bool_type (current_language, gdbpy_enter::get_gdbarch ())
#define builtin_type_pychar \
- language_string_char_type (python_language, python_gdbarch)
+ language_string_char_type (current_language, gdbpy_enter::get_gdbarch ())
struct value_object {
PyObject_HEAD
try
{
common_val_print (((value_object *) self)->value, &stb, 0,
- &opts, python_language);
+ &opts, current_language);
}
catch (const gdb_exception &except)
{
try
{
common_val_print (((value_object *) self)->value, &stb, 0,
- &opts, python_language);
+ &opts, current_language);
}
catch (const gdb_exception &except)
{
if (var != NULL)
{
- res_val = value_of_internalvar (python_gdbarch, var);
+ res_val = value_of_internalvar (gdbpy_enter::get_gdbarch (), var);
if (value_type (res_val)->code () == TYPE_CODE_VOID)
res_val = NULL;
}
python_xmethod_worker::~python_xmethod_worker ()
{
/* We don't do much here, but we still need the GIL. */
- gdbpy_enter enter_py (get_current_arch (), current_language);
+ gdbpy_enter enter_py;
Py_DECREF (m_py_worker);
Py_DECREF (m_this_type);
{
gdb_assert (obj_type != NULL && method_name != NULL);
- gdbpy_enter enter_py (get_current_arch (), current_language);
+ gdbpy_enter enter_py;
gdbpy_ref<> py_type (type_to_type_object (obj_type));
if (py_type == NULL)
{
/* The gdbpy_enter object needs to be placed first, so that it's the last to
be destroyed. */
- gdbpy_enter enter_py (get_current_arch (), current_language);
+ gdbpy_enter enter_py;
struct type *obj_type;
int i = 1, arg_count;
gdbpy_ref<> list_iter;
struct type *obj_type, *this_type;
int i;
- gdbpy_enter enter_py (get_current_arch (), current_language);
+ gdbpy_enter enter_py;
/* First see if there is a get_result_type method.
If not this could be an old xmethod (pre 7.9.1). */
python_xmethod_worker::invoke (struct value *obj,
gdb::array_view<value *> args)
{
- gdbpy_enter enter_py (get_current_arch (), current_language);
+ gdbpy_enter enter_py;
int i;
struct type *obj_type, *this_type;
}
else
{
- res = allocate_value (lookup_typename (python_language,
+ res = allocate_value (lookup_typename (current_language,
"void", NULL, 0));
}
{
public:
- gdbpy_enter (struct gdbarch *gdbarch, const struct language_defn *language);
+ /* Set the ambient Python architecture to GDBARCH and the language
+ to LANGUAGE. If GDBARCH is nullptr, then the architecture will
+ be computed, when needed, using get_current_arch; see the
+ get_gdbarch method. If LANGUAGE is not nullptr, then the current
+ language at time of construction will be saved (to be restored on
+ destruction), and the current language will be set to
+ LANGUAGE. */
+ explicit gdbpy_enter (struct gdbarch *gdbarch = nullptr,
+ const struct language_defn *language = nullptr);
~gdbpy_enter ();
DISABLE_COPY_AND_ASSIGN (gdbpy_enter);
+ /* Return the current gdbarch, as known to the Python layer. This
+ is either python_gdbarch (which comes from the most recent call
+ to the gdbpy_enter constructor), or, if that is nullptr, the
+ result of get_current_arch. */
+ static struct gdbarch *get_gdbarch ();
+
+ /* Called only during gdb shutdown. This sets python_gdbarch to an
+ acceptable value. */
+ static void finalize ();
+
private:
+ /* The current gdbarch, according to Python. This can be
+ nullptr. */
+ static struct gdbarch *python_gdbarch;
+
struct active_ext_lang_state *m_previous_active;
PyGILState_STATE m_state;
struct gdbarch *m_gdbarch;
PyThreadState *m_save;
};
-extern struct gdbarch *python_gdbarch;
-extern const struct language_defn *python_language;
-
/* Use this after a TRY_EXCEPT to throw the appropriate Python
exception. */
#define GDB_PY_HANDLE_EXCEPTION(Exception) \
/* Architecture and language to be used in callbacks from
the Python interpreter. */
-struct gdbarch *python_gdbarch;
-const struct language_defn *python_language;
+struct gdbarch *gdbpy_enter::python_gdbarch;
gdbpy_enter::gdbpy_enter (struct gdbarch *gdbarch,
const struct language_defn *language)
: m_gdbarch (python_gdbarch),
- m_language (python_language)
+ m_language (language == nullptr ? nullptr : current_language)
{
/* We should not ever enter Python unless initialized. */
if (!gdb_python_initialized)
m_state = PyGILState_Ensure ();
python_gdbarch = gdbarch;
- python_language = language;
+ if (language != nullptr)
+ set_language (language->la_language);
/* Save it and ensure ! PyErr_Occurred () afterwards. */
m_error.emplace ();
m_error->restore ();
python_gdbarch = m_gdbarch;
- python_language = m_language;
+ if (m_language != nullptr)
+ set_language (m_language->la_language);
restore_active_ext_lang (m_previous_active);
PyGILState_Release (m_state);
}
+struct gdbarch *
+gdbpy_enter::get_gdbarch ()
+{
+ if (python_gdbarch != nullptr)
+ return python_gdbarch;
+ return get_current_arch ();
+}
+
+void
+gdbpy_enter::finalize ()
+{
+ python_gdbarch = target_gdbarch ();
+}
+
/* A helper class to save and restore the GIL, but without touching
the other globals that are handled by gdbpy_enter. */
arg = skip_spaces (arg);
- gdbpy_enter enter_py (get_current_arch (), current_language);
+ gdbpy_enter enter_py;
if (arg && *arg)
{
if (cmd->body_list_1 != nullptr)
error (_("Invalid \"python\" block structure."));
- gdbpy_enter enter_py (get_current_arch (), current_language);
+ gdbpy_enter enter_py;
std::string script = compute_python_string (cmd->body_list_0.get ());
ret = PyRun_SimpleString (script.c_str ());
static void
python_command (const char *arg, int from_tty)
{
- gdbpy_enter enter_py (get_current_arch (), current_language);
+ gdbpy_enter enter_py;
scoped_restore save_async = make_scoped_restore (¤t_ui->async, 0);
static PyObject *
gdbpy_target_charset (PyObject *self, PyObject *args)
{
- const char *cset = target_charset (python_gdbarch);
+ const char *cset = target_charset (gdbpy_enter::get_gdbarch ());
return PyUnicode_Decode (cset, strlen (cset), host_charset (), NULL);
}
static PyObject *
gdbpy_target_wide_charset (PyObject *self, PyObject *args)
{
- const char *cset = target_wide_charset (python_gdbarch);
+ const char *cset = target_wide_charset (gdbpy_enter::get_gdbarch ());
return PyUnicode_Decode (cset, strlen (cset), host_charset (), NULL);
}
}
if (arg != NULL)
- location = string_to_event_location_basic (&arg, python_language,
+ location = string_to_event_location_basic (&arg, current_language,
symbol_name_match_type::WILD);
std::vector<symtab_and_line> decoded_sals;
gdbpy_source_script (const struct extension_language_defn *extlang,
FILE *file, const char *filename)
{
- gdbpy_enter enter_py (get_current_arch (), current_language);
+ gdbpy_enter enter_py;
python_run_simple_file (file, filename);
}
void operator() ()
{
- gdbpy_enter enter_py (get_current_arch (), current_language);
+ gdbpy_enter enter_py;
gdbpy_ref<> call_result (PyObject_CallObject (m_func, NULL));
if (call_result == NULL)
if (!gdb_python_initialized)
return EXT_LANG_RC_NOP;
- gdbpy_enter enter_py (get_current_arch (), current_language);
+ gdbpy_enter enter_py;
if (!evregpy_no_listeners_p (gdb_py_events.before_prompt)
&& evpy_emit_event (NULL, gdb_py_events.before_prompt) < 0)
if (!gdb_python_initialized)
return {};
- gdbpy_enter enter_py (get_current_arch (), current_language);
+ gdbpy_enter enter_py;
if (gdb_python_module == nullptr
|| !PyObject_HasAttrString (gdb_python_module, "colorize"))
if (!gdb_python_initialized)
return;
- gdbpy_enter enter_py (objfile->arch (), current_language);
+ gdbpy_enter enter_py (objfile->arch ());
scoped_restore restire_current_objfile
= make_scoped_restore (&gdbpy_current_objfile, objfile);
if (!gdb_python_initialized)
return;
- gdbpy_enter enter_py (objfile->arch (), current_language);
+ gdbpy_enter enter_py (objfile->arch ());
scoped_restore restire_current_objfile
= make_scoped_restore (&gdbpy_current_objfile, objfile);
if (!gdb_python_initialized)
return;
- gdbpy_enter enter_py (get_current_arch (), current_language);
+ gdbpy_enter enter_py;
gdbpy_ref<> type_module (PyImport_ImportModule ("gdb.types"));
if (type_module == NULL)
if (!gdb_python_initialized)
return EXT_LANG_RC_NOP;
- gdbpy_enter enter_py (get_current_arch (), current_language);
+ gdbpy_enter enter_py;
gdbpy_ref<> type_obj (type_to_type_object (type));
if (type_obj == NULL)
if (!gdb_python_initialized)
return;
- gdbpy_enter enter_py (get_current_arch (), current_language);
+ gdbpy_enter enter_py;
Py_DECREF (printers);
}
previous_active = set_active_ext_lang (&extension_language_python);
(void) PyGILState_Ensure ();
- python_gdbarch = target_gdbarch ();
- python_language = current_language;
+ gdbpy_enter::finalize ();
Py_Finalize ();
if (!gdb_python_initialized)
return;
- gdbpy_enter enter_py (python_gdbarch, python_language);
+ gdbpy_enter enter_py;
if (emit_exiting_event (exit_code) < 0)
gdbpy_print_stack ();
if (!do_start_initialization () && PyErr_Occurred ())
gdbpy_print_stack ();
- gdbpy_enter enter_py (get_current_arch (), current_language);
+ gdbpy_enter enter_py;
if (!do_initialize (extlang))
{
gdb_test "python print (inf_list\[0\].is_valid())" "True" \
"check inferior validity 1"
+ # The "dummy" line below used to cause a gdb crash.
gdb_test_multiline "install new inferior event handler" \
"python" "" \
"my_inferior_count = 1" "" \
" global my_inferior_count" "" \
" if evt.inferior is not None:" "" \
" my_inferior_count = my_inferior_count + 1" "" \
+ " dummy = gdb.Value(True)" "" \
"gdb.events.new_inferior.connect(new_inf_handler)" "" \
"end" ""
gdb_test_multiline "install inferior deleted event handler" \
test_lookup_type "objective-c" "char"
test_lookup_type "pascal" "char"
+
+# Ensure that the language can be changed from within Python and still
+# affect the results.
+gdb_test_multiline "look up ada type from another language" \
+ "python" "" \
+ "gdb.execute('set language ada')" "" \
+ "print(gdb.lookup_type('character'))" "" \
+ "end" "character"