X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=gdb%2Fpython%2Fpython.c;h=9854c79c103aa9fb2cab2516f67f8e57440e1e62;hb=e36122e9;hp=1362bd24e5a98f521c16e695c1c9648bf9881525;hpb=dc6c87175b672f00e72997c0ff9dcf984e305285;p=deliverable%2Fbinutils-gdb.git diff --git a/gdb/python/python.c b/gdb/python/python.c index 1362bd24e5..9854c79c10 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -1,6 +1,6 @@ /* 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. @@ -57,8 +57,8 @@ 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; +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 @@ -131,6 +131,7 @@ PyObject *gdbpy_gdb_memory_error; 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 *); @@ -151,16 +152,17 @@ static enum ext_lang_rc gdbpy_before_prompt_hook /* 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, @@ -1262,7 +1264,8 @@ 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 - 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 @@ -1290,6 +1293,31 @@ gdbpy_source_objfile_script (const struct extension_language_defn *extlang, 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 * @@ -1956,6 +1984,14 @@ a boolean indicating if name is a field of the current implied argument\n\ 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,