static void
python_interactive_command (char *arg, int from_tty)
{
- struct cleanup *cleanup;
+ struct ui *ui = current_ui;
int err;
- cleanup = make_cleanup_restore_integer (&interpreter_async);
- interpreter_async = 0;
+ scoped_restore save_async = make_scoped_restore (¤t_ui->async, 0);
arg = skip_spaces (arg);
}
else
{
- err = PyRun_InteractiveLoop (instream, "<stdin>");
+ err = PyRun_InteractiveLoop (ui->instream, "<stdin>");
dont_repeat ();
}
gdbpy_print_stack ();
error (_("Error while executing Python code."));
}
-
- do_cleanups (cleanup);
}
/* A wrapper around PyRun_SimpleFile. FILE is the Python script to run
cleanup = ensure_python_env (get_current_arch (), current_language);
- make_cleanup_restore_integer (&interpreter_async);
- interpreter_async = 0;
+ scoped_restore save_async = make_scoped_restore (¤t_ui->async, 0);
arg = skip_spaces (arg);
if (arg && *arg)
/* A Python function which returns a gdb parameter's value as a Python
value. */
-PyObject *
+static PyObject *
gdbpy_parameter (PyObject *self, PyObject *args)
{
struct gdb_exception except = exception_none;
PyObject *from_tty_obj = NULL, *to_string_obj = NULL;
int from_tty, to_string;
static char *keywords[] = {"command", "from_tty", "to_string", NULL };
- char *result = NULL;
if (! PyArg_ParseTupleAndKeywords (args, kw, "s|O!O!", keywords, &arg,
&PyBool_Type, &from_tty_obj,
to_string = cmp;
}
+ std::string to_string_res;
+
TRY
{
/* Copy the argument text in case the command modifies it. */
struct cleanup *cleanup = make_cleanup (xfree, copy);
struct interp *interp;
- make_cleanup_restore_integer (&interpreter_async);
- interpreter_async = 0;
+ scoped_restore save_async = make_scoped_restore (¤t_ui->async, 0);
+
+ scoped_restore save_uiout = make_scoped_restore (¤t_uiout);
- make_cleanup_restore_ui_out (¤t_uiout);
/* Use the console interpreter uiout to have the same print format
for console or MI. */
- interp = interp_lookup ("console");
+ interp = interp_lookup (current_ui, "console");
current_uiout = interp_ui_out (interp);
prevent_dont_repeat ();
if (to_string)
- result = execute_command_to_string (copy, from_tty);
+ to_string_res = execute_command_to_string (copy, from_tty);
else
- {
- result = NULL;
- execute_command (copy, from_tty);
- }
-
+ execute_command (copy, from_tty);
do_cleanups (cleanup);
}
CATCH (except, RETURN_MASK_ALL)
/* Do any commands attached to breakpoint we stopped at. */
bpstat_do_actions ();
- if (result)
- {
- PyObject *r = PyString_FromString (result);
- xfree (result);
- return r;
- }
+ if (to_string)
+ return PyString_FromString (to_string_res.c_str ());
Py_RETURN_NONE;
}
{
char *soname;
PyObject *str_obj;
- gdb_py_longest pc;
+ gdb_py_ulongest pc;
- if (!PyArg_ParseTuple (args, GDB_PY_LL_ARG, &pc))
+ if (!PyArg_ParseTuple (args, GDB_PY_LLU_ARG, &pc))
return NULL;
soname = solib_name_from_address (current_program_space, pc);
if (arg != NULL)
{
- location = new_linespec_location (&arg);
+ location = string_to_event_location_basic (&arg, python_language);
make_cleanup_delete_event_location (location);
}
return result;
}
+/* Implementation of gdb.invalidate_cached_frames. */
+
+static PyObject *
+gdbpy_invalidate_cached_frames (PyObject *self, PyObject *args)
+{
+ reinit_frame_cache ();
+ Py_RETURN_NONE;
+}
+
/* Read a file as Python code.
This is the extension_language_script_ops.script_sourcer "method".
FILE is the file to load. FILENAME is name of the file FILE.
const char *current_gdb_prompt)
{
struct cleanup *cleanup;
- char *prompt = NULL;
+ gdb::unique_xmalloc_ptr<char> prompt;
if (!gdb_python_initialized)
return EXT_LANG_RC_NOP;
if (prompt == NULL)
goto fail;
- else
- make_cleanup (xfree, prompt);
}
}
}
/* If a prompt has been set, PROMPT will not be NULL. If it is
NULL, do not set the prompt. */
if (prompt != NULL)
- set_prompt (prompt);
+ set_prompt (prompt.get ());
do_cleanups (cleanup);
return prompt != NULL ? EXT_LANG_RC_OK : EXT_LANG_RC_NOP;
else
{
PyObject *ptype, *pvalue, *ptraceback;
- char *msg = NULL, *type = NULL;
PyErr_Fetch (&ptype, &pvalue, &ptraceback);
/* Fetch the error message contained within ptype, pvalue. */
- msg = gdbpy_exception_to_string (ptype, pvalue);
- type = gdbpy_obj_to_string (ptype);
+ gdb::unique_xmalloc_ptr<char>
+ msg (gdbpy_exception_to_string (ptype, pvalue));
+ gdb::unique_xmalloc_ptr<char> type (gdbpy_obj_to_string (ptype));
TRY
{
}
else
fprintf_filtered (gdb_stderr, "Python Exception %s %s: \n",
- type, msg);
+ type.get (), msg.get ());
}
CATCH (except, RETURN_MASK_ALL)
{
Py_XDECREF (ptype);
Py_XDECREF (pvalue);
Py_XDECREF (ptraceback);
- xfree (msg);
}
}
PyObject *type_obj, *type_module = NULL, *func = NULL;
PyObject *result_obj = NULL;
PyObject *printers_obj = (PyObject *) ext_printers->py_type_printers;
- char *result = NULL;
+ gdb::unique_xmalloc_ptr<char> result;
if (printers_obj == NULL)
return EXT_LANG_RC_NOP;
Py_XDECREF (result_obj);
do_cleanups (cleanups);
if (result != NULL)
- *prettied_type = result;
- return result != NULL ? EXT_LANG_RC_OK : EXT_LANG_RC_ERROR;
+ {
+ *prettied_type = result.release ();
+ return EXT_LANG_RC_OK;
+ }
+ return EXT_LANG_RC_ERROR;
}
/* Free the result of start_type_printers.
progname = concat (ldirname (python_libdir), SLASH_STRING, "bin",
SLASH_STRING, "python", (char *) NULL);
#ifdef IS_PY3K
- oldloc = setlocale (LC_ALL, NULL);
+ oldloc = xstrdup (setlocale (LC_ALL, NULL));
setlocale (LC_ALL, "");
progsize = strlen (progname);
progname_copy = (wchar_t *) PyMem_Malloc ((progsize + 1) * sizeof (wchar_t));
if (!progname_copy)
{
+ xfree (oldloc);
fprintf (stderr, "out of memory\n");
return;
}
count = mbstowcs (progname_copy, progname, progsize + 1);
if (count == (size_t) -1)
{
+ xfree (oldloc);
fprintf (stderr, "Could not convert python path to string\n");
return;
}
setlocale (LC_ALL, oldloc);
+ xfree (oldloc);
/* Note that Py_SetProgramName expects the string it is passed to
remain alive for the duration of the program's execution, so
{ "inferiors", gdbpy_inferiors, METH_NOARGS,
"inferiors () -> (gdb.Inferior, ...).\n\
Return a tuple containing all inferiors." },
+
+ { "invalidate_cached_frames", gdbpy_invalidate_cached_frames, METH_NOARGS,
+ "invalidate_cached_frames () -> None.\n\
+Invalidate any cached frame objects in gdb.\n\
+Intended for internal use only." },
+
{NULL, NULL, 0, NULL}
};