/* General python/gdb code
- Copyright (C) 2008-2014 Free Software Foundation, Inc.
+ Copyright (C) 2008-2015 Free Software Foundation, Inc.
This file is part of GDB.
#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;
+extern const struct extension_language_script_ops python_extension_script_ops;
+extern const struct extension_language_ops python_extension_ops;
#endif
/* The main struct describing GDB's interface to the Python
static script_sourcer_func gdbpy_source_script;
static objfile_script_sourcer_func gdbpy_source_objfile_script;
+static objfile_script_executor_func gdbpy_execute_objfile_script;
static void gdbpy_finish_initialization
(const struct extension_language_defn *);
static int gdbpy_initialized (const struct extension_language_defn *);
/* The interface between gdb proper and loading of python scripts. */
-static const struct extension_language_script_ops python_extension_script_ops =
+const struct extension_language_script_ops python_extension_script_ops =
{
gdbpy_source_script,
gdbpy_source_objfile_script,
+ gdbpy_execute_objfile_script,
gdbpy_auto_load_enabled
};
/* The interface between gdb proper and python extensions. */
-static const struct extension_language_ops python_extension_ops =
+const struct extension_language_ops python_extension_ops =
{
gdbpy_finish_initialization,
gdbpy_initialized,
/* 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
- gdbpy_source_objfile_script; it is NULL at other times. */
+ gdbpy_source_objfile_script and gdbpy_execute_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
gdbpy_current_objfile = NULL;
}
+/* Set the current objfile to OBJFILE and then execute SCRIPT
+ as Python code. This does not throw any errors. If an exception
+ occurs python will print the traceback and clear the error indicator.
+ This is the extension_language_script_ops.objfile_script_executor
+ "method". */
+
+static void
+gdbpy_execute_objfile_script (const struct extension_language_defn *extlang,
+ struct objfile *objfile, const char *name,
+ const char *script)
+{
+ struct cleanup *cleanups;
+
+ if (!gdb_python_initialized)
+ return;
+
+ cleanups = ensure_python_env (get_objfile_arch (objfile), current_language);
+ gdbpy_current_objfile = objfile;
+
+ PyRun_SimpleString (script);
+
+ do_cleanups (cleanups);
+ gdbpy_current_objfile = NULL;
+}
+
/* Return the current Objfile, or None if there isn't one. */
static PyObject *
METH_VARARGS | METH_KEYWORDS,
"lookup_global_symbol (name [, domain]) -> symbol\n\
Return the symbol corresponding to the given name (or None)." },
+
+ { "lookup_objfile", (PyCFunction) gdbpy_lookup_objfile,
+ METH_VARARGS | METH_KEYWORDS,
+ "lookup_objfile (name, [by_build_id]) -> objfile\n\
+Look up the specified objfile.\n\
+If by_build_id is True, the objfile is looked up by using name\n\
+as its build id." },
+
{ "block_for_pc", gdbpy_block_for_pc, METH_VARARGS,
"Return the block containing the given pc value, or None." },
{ "solib_name", gdbpy_solib_name, METH_VARARGS,