2008-08-06 21:41:33 +02:00
|
|
|
|
/* General python/gdb code
|
|
|
|
|
|
2013-01-01 07:33:28 +01:00
|
|
|
|
Copyright (C) 2008-2013 Free Software Foundation, Inc.
|
2008-08-06 21:41:33 +02:00
|
|
|
|
|
|
|
|
|
This file is part of GDB.
|
|
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
|
|
|
|
|
|
|
|
#include "defs.h"
|
* python/python-internal.h (struct language_defn): Declare.
(python_gdbarch, python_language): Likewise.
(ensure_python_env): Add prototype.
(make_cleanup_py_restore_gil): Remove prototype.
* python/python.c: Include "arch-utils.h", "value.h" and "language.h".
(python_gdbarch, python_language): New global variables.
(struct python_env): New data type.
(ensure_python_env, restore_python_env): New functions.
(eval_python_from_control_command): Call ensure_python_env to
install current architecture and language.
(python_command, gdbpy_new_objfile): Likewise.
* python/python-cmd.c: Include "arch-utils.h" and "language.h".
(cmdpy_destroyer, cmdpy_function, cmdpy_completer): Call
ensure_python_env.
* python/python-type.c (clean_up_objfile_types): Likewise.
* python/python-objfile.c: Include "language.h".
(clean_up_objfile): Call ensure_python_env.
* python/python-prettyprint.c (apply_val_pretty_printer): Likewise.
(apply_varobj_pretty_printer): Do not call PyGILState_Ensure.
* varobj.c (varobj_ensure_python_env): New helper function.
(varobj_get_display_hint, update_dynamic_varobj_children,
install_default_visualizer, varobj_set_visualizer, free_variable,
value_get_print_value): Call it.
(value_get_print_value): Add varobj argument instead of pretty
printer argument. Update all callers.
* python/python-utils.c (py_gil_restore, make_cleanup_py_restore_gil):
Remove.
* value.h (internal_function_fn): Add GDBARCH and LANGUAGE argument.
(call_internal_function): Likewise.
* value.c (call_internal_function): Likewise. Pass to handler.
* eval.c (evaluate_subexp_standard): Update call.
* python/python-function.c: Include "language.h".
(fnpy_call): Add GDBARCH and LANGAUAGE arguments and call
make_cleanup_python_env.
* python/python-value.c (builtin_type_pyint, builtin_type_pyfloat,
builtin_type_pylong, builtin_type_pybool, builtin_type_pychar,
valpy_str): Use python_gdbarch and python_language instead of
current_gdbarch and current_language.
* python/python-type.c (typy_lookup_typename): Likewise.
2009-07-02 19:04:23 +02:00
|
|
|
|
#include "arch-utils.h"
|
2008-08-06 21:41:33 +02:00
|
|
|
|
#include "command.h"
|
|
|
|
|
#include "ui-out.h"
|
|
|
|
|
#include "cli/cli-script.h"
|
|
|
|
|
#include "gdbcmd.h"
|
2010-04-15 21:54:13 +02:00
|
|
|
|
#include "progspace.h"
|
2009-05-28 02:40:24 +02:00
|
|
|
|
#include "objfiles.h"
|
* python/python-internal.h (struct language_defn): Declare.
(python_gdbarch, python_language): Likewise.
(ensure_python_env): Add prototype.
(make_cleanup_py_restore_gil): Remove prototype.
* python/python.c: Include "arch-utils.h", "value.h" and "language.h".
(python_gdbarch, python_language): New global variables.
(struct python_env): New data type.
(ensure_python_env, restore_python_env): New functions.
(eval_python_from_control_command): Call ensure_python_env to
install current architecture and language.
(python_command, gdbpy_new_objfile): Likewise.
* python/python-cmd.c: Include "arch-utils.h" and "language.h".
(cmdpy_destroyer, cmdpy_function, cmdpy_completer): Call
ensure_python_env.
* python/python-type.c (clean_up_objfile_types): Likewise.
* python/python-objfile.c: Include "language.h".
(clean_up_objfile): Call ensure_python_env.
* python/python-prettyprint.c (apply_val_pretty_printer): Likewise.
(apply_varobj_pretty_printer): Do not call PyGILState_Ensure.
* varobj.c (varobj_ensure_python_env): New helper function.
(varobj_get_display_hint, update_dynamic_varobj_children,
install_default_visualizer, varobj_set_visualizer, free_variable,
value_get_print_value): Call it.
(value_get_print_value): Add varobj argument instead of pretty
printer argument. Update all callers.
* python/python-utils.c (py_gil_restore, make_cleanup_py_restore_gil):
Remove.
* value.h (internal_function_fn): Add GDBARCH and LANGUAGE argument.
(call_internal_function): Likewise.
* value.c (call_internal_function): Likewise. Pass to handler.
* eval.c (evaluate_subexp_standard): Update call.
* python/python-function.c: Include "language.h".
(fnpy_call): Add GDBARCH and LANGAUAGE arguments and call
make_cleanup_python_env.
* python/python-value.c (builtin_type_pyint, builtin_type_pyfloat,
builtin_type_pylong, builtin_type_pybool, builtin_type_pychar,
valpy_str): Use python_gdbarch and python_language instead of
current_gdbarch and current_language.
* python/python-type.c (typy_lookup_typename): Likewise.
2009-07-02 19:04:23 +02:00
|
|
|
|
#include "value.h"
|
|
|
|
|
#include "language.h"
|
2010-01-18 11:50:45 +01:00
|
|
|
|
#include "exceptions.h"
|
2010-08-11 22:54:12 +02:00
|
|
|
|
#include "event-loop.h"
|
2010-08-20 20:52:11 +02:00
|
|
|
|
#include "serial.h"
|
2011-11-04 13:07:53 +01:00
|
|
|
|
#include "readline/tilde.h"
|
2011-03-14 17:09:55 +01:00
|
|
|
|
#include "python.h"
|
2013-03-07 22:57:30 +01:00
|
|
|
|
#include "cli/cli-utils.h"
|
2008-08-06 21:41:33 +02:00
|
|
|
|
|
|
|
|
|
#include <ctype.h>
|
|
|
|
|
|
2011-12-16 16:55:40 +01:00
|
|
|
|
/* Declared constants and enum for python stack printing. */
|
|
|
|
|
static const char python_excp_none[] = "none";
|
|
|
|
|
static const char python_excp_full[] = "full";
|
|
|
|
|
static const char python_excp_message[] = "message";
|
|
|
|
|
|
|
|
|
|
/* "set python print-stack" choices. */
|
2012-01-28 19:08:22 +01:00
|
|
|
|
static const char *const python_excp_enums[] =
|
2011-12-16 16:55:40 +01:00
|
|
|
|
{
|
|
|
|
|
python_excp_none,
|
|
|
|
|
python_excp_full,
|
|
|
|
|
python_excp_message,
|
|
|
|
|
NULL
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* The exception printing variable. 'full' if we want to print the
|
|
|
|
|
error message and stack, 'none' if we want to print nothing, and
|
|
|
|
|
'message' if we only want to print the error message. 'message' is
|
|
|
|
|
the default. */
|
|
|
|
|
static const char *gdbpy_should_print_stack = python_excp_message;
|
2008-08-06 21:41:33 +02:00
|
|
|
|
|
|
|
|
|
#ifdef HAVE_PYTHON
|
|
|
|
|
|
|
|
|
|
#include "libiberty.h"
|
|
|
|
|
#include "cli/cli-decode.h"
|
|
|
|
|
#include "charset.h"
|
|
|
|
|
#include "top.h"
|
2010-08-11 14:48:24 +02:00
|
|
|
|
#include "solib.h"
|
2008-08-06 21:41:33 +02:00
|
|
|
|
#include "python-internal.h"
|
2010-08-11 14:48:24 +02:00
|
|
|
|
#include "linespec.h"
|
|
|
|
|
#include "source.h"
|
2008-08-06 21:41:33 +02:00
|
|
|
|
#include "version.h"
|
|
|
|
|
#include "target.h"
|
|
|
|
|
#include "gdbthread.h"
|
2011-07-21 13:03:48 +02:00
|
|
|
|
#include "observer.h"
|
2011-09-02 18:56:30 +02:00
|
|
|
|
#include "interps.h"
|
2012-12-12 17:47:30 +01:00
|
|
|
|
#include "event-top.h"
|
2008-08-06 21:41:33 +02:00
|
|
|
|
|
2009-02-05 17:40:34 +01:00
|
|
|
|
static PyMethodDef GdbMethods[];
|
2008-08-06 21:41:33 +02:00
|
|
|
|
|
2012-12-12 17:47:30 +01:00
|
|
|
|
#ifdef IS_PY3K
|
|
|
|
|
static struct PyModuleDef GdbModuleDef;
|
|
|
|
|
#endif
|
|
|
|
|
|
2008-08-06 21:41:33 +02:00
|
|
|
|
PyObject *gdb_module;
|
Refactor Python "gdb" module into a proper Python package, by introducing
a new "_gdb" module for code implemented in C, and using reload/__import__
instead of exec.
gdb/
* python/lib/gdb/__init__.py: Import * from _gdb.
(GdbOutputFile, sys.stdout, GdbOutputErrorFile, sys.stderr,
prompt_hook, sys.argv): Moved from finish_python_initialization.
(pretty_printers, PYTHONDIR): Moved from _initialize_python.
(packages, auto_load_packages): New list and function replacing
module_dict and auto-loading code, using __file__ instead of
gdb.PYTHONDIR and reload/__import__ instead of exec.
(GdbSetPythonDirectory): Replacing function of the same name
from finish_python_initialization, using reload/__import__ instead
of exec, as well as call auto_load_packages.
* python/py-prettyprint.c (find_pretty_printer_from_gdb): Check
gdb_python_module and not gdb_module.
* python/python-internal.h (gdb_python_module): Declare.
* python/python.c (gdb_python_module): New global.
(before_prompt_hook): Check gdb_python_module and not gdb_module.
(_initialize_python): Rename gdb module to _gdb.
Move gdb.PYTHONDIR and gdb.pretty_printer to lib/gdb/__init__.py.
(finish_python_initialization): Move Python code to
lib/gdb/__init__.py; instead, set up sys.path and import gdb into
__main__.
gdb/testsuite/
* gdb.python/python.exp (Test stderr location): Update module
location of GDB-specific sys.stderr.
(Test stdout location): Ditto for sys.stdout.
2012-09-13 23:49:32 +02:00
|
|
|
|
PyObject *gdb_python_module;
|
2008-08-06 21:41:33 +02:00
|
|
|
|
|
2009-05-28 03:05:14 +02:00
|
|
|
|
/* Some string constants we may wish to use. */
|
|
|
|
|
PyObject *gdbpy_to_string_cst;
|
|
|
|
|
PyObject *gdbpy_children_cst;
|
|
|
|
|
PyObject *gdbpy_display_hint_cst;
|
2009-02-06 22:33:59 +01:00
|
|
|
|
PyObject *gdbpy_doc_cst;
|
2010-06-04 20:18:28 +02:00
|
|
|
|
PyObject *gdbpy_enabled_cst;
|
2011-02-28 20:38:34 +01:00
|
|
|
|
PyObject *gdbpy_value_cst;
|
2009-02-06 22:33:59 +01:00
|
|
|
|
|
2010-05-25 17:27:17 +02:00
|
|
|
|
/* The GdbError exception. */
|
|
|
|
|
PyObject *gdbpy_gdberror_exc;
|
* python/python-internal.h (struct language_defn): Declare.
(python_gdbarch, python_language): Likewise.
(ensure_python_env): Add prototype.
(make_cleanup_py_restore_gil): Remove prototype.
* python/python.c: Include "arch-utils.h", "value.h" and "language.h".
(python_gdbarch, python_language): New global variables.
(struct python_env): New data type.
(ensure_python_env, restore_python_env): New functions.
(eval_python_from_control_command): Call ensure_python_env to
install current architecture and language.
(python_command, gdbpy_new_objfile): Likewise.
* python/python-cmd.c: Include "arch-utils.h" and "language.h".
(cmdpy_destroyer, cmdpy_function, cmdpy_completer): Call
ensure_python_env.
* python/python-type.c (clean_up_objfile_types): Likewise.
* python/python-objfile.c: Include "language.h".
(clean_up_objfile): Call ensure_python_env.
* python/python-prettyprint.c (apply_val_pretty_printer): Likewise.
(apply_varobj_pretty_printer): Do not call PyGILState_Ensure.
* varobj.c (varobj_ensure_python_env): New helper function.
(varobj_get_display_hint, update_dynamic_varobj_children,
install_default_visualizer, varobj_set_visualizer, free_variable,
value_get_print_value): Call it.
(value_get_print_value): Add varobj argument instead of pretty
printer argument. Update all callers.
* python/python-utils.c (py_gil_restore, make_cleanup_py_restore_gil):
Remove.
* value.h (internal_function_fn): Add GDBARCH and LANGUAGE argument.
(call_internal_function): Likewise.
* value.c (call_internal_function): Likewise. Pass to handler.
* eval.c (evaluate_subexp_standard): Update call.
* python/python-function.c: Include "language.h".
(fnpy_call): Add GDBARCH and LANGAUAGE arguments and call
make_cleanup_python_env.
* python/python-value.c (builtin_type_pyint, builtin_type_pyfloat,
builtin_type_pylong, builtin_type_pybool, builtin_type_pychar,
valpy_str): Use python_gdbarch and python_language instead of
current_gdbarch and current_language.
* python/python-type.c (typy_lookup_typename): Likewise.
2009-07-02 19:04:23 +02:00
|
|
|
|
|
2010-11-12 21:49:43 +01:00
|
|
|
|
/* The `gdb.error' base class. */
|
|
|
|
|
PyObject *gdbpy_gdb_error;
|
|
|
|
|
|
|
|
|
|
/* The `gdb.MemoryError' exception. */
|
|
|
|
|
PyObject *gdbpy_gdb_memory_error;
|
|
|
|
|
|
* python/python-internal.h (struct language_defn): Declare.
(python_gdbarch, python_language): Likewise.
(ensure_python_env): Add prototype.
(make_cleanup_py_restore_gil): Remove prototype.
* python/python.c: Include "arch-utils.h", "value.h" and "language.h".
(python_gdbarch, python_language): New global variables.
(struct python_env): New data type.
(ensure_python_env, restore_python_env): New functions.
(eval_python_from_control_command): Call ensure_python_env to
install current architecture and language.
(python_command, gdbpy_new_objfile): Likewise.
* python/python-cmd.c: Include "arch-utils.h" and "language.h".
(cmdpy_destroyer, cmdpy_function, cmdpy_completer): Call
ensure_python_env.
* python/python-type.c (clean_up_objfile_types): Likewise.
* python/python-objfile.c: Include "language.h".
(clean_up_objfile): Call ensure_python_env.
* python/python-prettyprint.c (apply_val_pretty_printer): Likewise.
(apply_varobj_pretty_printer): Do not call PyGILState_Ensure.
* varobj.c (varobj_ensure_python_env): New helper function.
(varobj_get_display_hint, update_dynamic_varobj_children,
install_default_visualizer, varobj_set_visualizer, free_variable,
value_get_print_value): Call it.
(value_get_print_value): Add varobj argument instead of pretty
printer argument. Update all callers.
* python/python-utils.c (py_gil_restore, make_cleanup_py_restore_gil):
Remove.
* value.h (internal_function_fn): Add GDBARCH and LANGUAGE argument.
(call_internal_function): Likewise.
* value.c (call_internal_function): Likewise. Pass to handler.
* eval.c (evaluate_subexp_standard): Update call.
* python/python-function.c: Include "language.h".
(fnpy_call): Add GDBARCH and LANGAUAGE arguments and call
make_cleanup_python_env.
* python/python-value.c (builtin_type_pyint, builtin_type_pyfloat,
builtin_type_pylong, builtin_type_pybool, builtin_type_pychar,
valpy_str): Use python_gdbarch and python_language instead of
current_gdbarch and current_language.
* python/python-type.c (typy_lookup_typename): Likewise.
2009-07-02 19:04:23 +02:00
|
|
|
|
/* Architecture and language to be used in callbacks from
|
|
|
|
|
the Python interpreter. */
|
|
|
|
|
struct gdbarch *python_gdbarch;
|
|
|
|
|
const struct language_defn *python_language;
|
|
|
|
|
|
|
|
|
|
/* Restore global language and architecture and Python GIL state
|
|
|
|
|
when leaving the Python interpreter. */
|
|
|
|
|
|
|
|
|
|
struct python_env
|
|
|
|
|
{
|
|
|
|
|
PyGILState_STATE state;
|
|
|
|
|
struct gdbarch *gdbarch;
|
|
|
|
|
const struct language_defn *language;
|
2010-10-13 15:24:40 +02:00
|
|
|
|
PyObject *error_type, *error_value, *error_traceback;
|
* python/python-internal.h (struct language_defn): Declare.
(python_gdbarch, python_language): Likewise.
(ensure_python_env): Add prototype.
(make_cleanup_py_restore_gil): Remove prototype.
* python/python.c: Include "arch-utils.h", "value.h" and "language.h".
(python_gdbarch, python_language): New global variables.
(struct python_env): New data type.
(ensure_python_env, restore_python_env): New functions.
(eval_python_from_control_command): Call ensure_python_env to
install current architecture and language.
(python_command, gdbpy_new_objfile): Likewise.
* python/python-cmd.c: Include "arch-utils.h" and "language.h".
(cmdpy_destroyer, cmdpy_function, cmdpy_completer): Call
ensure_python_env.
* python/python-type.c (clean_up_objfile_types): Likewise.
* python/python-objfile.c: Include "language.h".
(clean_up_objfile): Call ensure_python_env.
* python/python-prettyprint.c (apply_val_pretty_printer): Likewise.
(apply_varobj_pretty_printer): Do not call PyGILState_Ensure.
* varobj.c (varobj_ensure_python_env): New helper function.
(varobj_get_display_hint, update_dynamic_varobj_children,
install_default_visualizer, varobj_set_visualizer, free_variable,
value_get_print_value): Call it.
(value_get_print_value): Add varobj argument instead of pretty
printer argument. Update all callers.
* python/python-utils.c (py_gil_restore, make_cleanup_py_restore_gil):
Remove.
* value.h (internal_function_fn): Add GDBARCH and LANGUAGE argument.
(call_internal_function): Likewise.
* value.c (call_internal_function): Likewise. Pass to handler.
* eval.c (evaluate_subexp_standard): Update call.
* python/python-function.c: Include "language.h".
(fnpy_call): Add GDBARCH and LANGAUAGE arguments and call
make_cleanup_python_env.
* python/python-value.c (builtin_type_pyint, builtin_type_pyfloat,
builtin_type_pylong, builtin_type_pybool, builtin_type_pychar,
valpy_str): Use python_gdbarch and python_language instead of
current_gdbarch and current_language.
* python/python-type.c (typy_lookup_typename): Likewise.
2009-07-02 19:04:23 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
restore_python_env (void *p)
|
|
|
|
|
{
|
|
|
|
|
struct python_env *env = (struct python_env *)p;
|
2010-05-17 23:23:25 +02:00
|
|
|
|
|
2010-10-13 15:24:40 +02:00
|
|
|
|
/* Leftover Python error is forbidden by Python Exception Handling. */
|
|
|
|
|
if (PyErr_Occurred ())
|
|
|
|
|
{
|
|
|
|
|
/* This order is similar to the one calling error afterwards. */
|
|
|
|
|
gdbpy_print_stack ();
|
|
|
|
|
warning (_("internal error: Unhandled Python exception"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PyErr_Restore (env->error_type, env->error_value, env->error_traceback);
|
|
|
|
|
|
* python/python-internal.h (struct language_defn): Declare.
(python_gdbarch, python_language): Likewise.
(ensure_python_env): Add prototype.
(make_cleanup_py_restore_gil): Remove prototype.
* python/python.c: Include "arch-utils.h", "value.h" and "language.h".
(python_gdbarch, python_language): New global variables.
(struct python_env): New data type.
(ensure_python_env, restore_python_env): New functions.
(eval_python_from_control_command): Call ensure_python_env to
install current architecture and language.
(python_command, gdbpy_new_objfile): Likewise.
* python/python-cmd.c: Include "arch-utils.h" and "language.h".
(cmdpy_destroyer, cmdpy_function, cmdpy_completer): Call
ensure_python_env.
* python/python-type.c (clean_up_objfile_types): Likewise.
* python/python-objfile.c: Include "language.h".
(clean_up_objfile): Call ensure_python_env.
* python/python-prettyprint.c (apply_val_pretty_printer): Likewise.
(apply_varobj_pretty_printer): Do not call PyGILState_Ensure.
* varobj.c (varobj_ensure_python_env): New helper function.
(varobj_get_display_hint, update_dynamic_varobj_children,
install_default_visualizer, varobj_set_visualizer, free_variable,
value_get_print_value): Call it.
(value_get_print_value): Add varobj argument instead of pretty
printer argument. Update all callers.
* python/python-utils.c (py_gil_restore, make_cleanup_py_restore_gil):
Remove.
* value.h (internal_function_fn): Add GDBARCH and LANGUAGE argument.
(call_internal_function): Likewise.
* value.c (call_internal_function): Likewise. Pass to handler.
* eval.c (evaluate_subexp_standard): Update call.
* python/python-function.c: Include "language.h".
(fnpy_call): Add GDBARCH and LANGAUAGE arguments and call
make_cleanup_python_env.
* python/python-value.c (builtin_type_pyint, builtin_type_pyfloat,
builtin_type_pylong, builtin_type_pybool, builtin_type_pychar,
valpy_str): Use python_gdbarch and python_language instead of
current_gdbarch and current_language.
* python/python-type.c (typy_lookup_typename): Likewise.
2009-07-02 19:04:23 +02:00
|
|
|
|
PyGILState_Release (env->state);
|
|
|
|
|
python_gdbarch = env->gdbarch;
|
|
|
|
|
python_language = env->language;
|
|
|
|
|
xfree (env);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Called before entering the Python interpreter to install the
|
|
|
|
|
current language and architecture to be used for Python values. */
|
|
|
|
|
|
|
|
|
|
struct cleanup *
|
|
|
|
|
ensure_python_env (struct gdbarch *gdbarch,
|
|
|
|
|
const struct language_defn *language)
|
|
|
|
|
{
|
|
|
|
|
struct python_env *env = xmalloc (sizeof *env);
|
|
|
|
|
|
|
|
|
|
env->state = PyGILState_Ensure ();
|
|
|
|
|
env->gdbarch = python_gdbarch;
|
|
|
|
|
env->language = python_language;
|
|
|
|
|
|
|
|
|
|
python_gdbarch = gdbarch;
|
|
|
|
|
python_language = language;
|
|
|
|
|
|
2010-10-13 15:24:40 +02:00
|
|
|
|
/* Save it and ensure ! PyErr_Occurred () afterwards. */
|
|
|
|
|
PyErr_Fetch (&env->error_type, &env->error_value, &env->error_traceback);
|
|
|
|
|
|
* python/python-internal.h (struct language_defn): Declare.
(python_gdbarch, python_language): Likewise.
(ensure_python_env): Add prototype.
(make_cleanup_py_restore_gil): Remove prototype.
* python/python.c: Include "arch-utils.h", "value.h" and "language.h".
(python_gdbarch, python_language): New global variables.
(struct python_env): New data type.
(ensure_python_env, restore_python_env): New functions.
(eval_python_from_control_command): Call ensure_python_env to
install current architecture and language.
(python_command, gdbpy_new_objfile): Likewise.
* python/python-cmd.c: Include "arch-utils.h" and "language.h".
(cmdpy_destroyer, cmdpy_function, cmdpy_completer): Call
ensure_python_env.
* python/python-type.c (clean_up_objfile_types): Likewise.
* python/python-objfile.c: Include "language.h".
(clean_up_objfile): Call ensure_python_env.
* python/python-prettyprint.c (apply_val_pretty_printer): Likewise.
(apply_varobj_pretty_printer): Do not call PyGILState_Ensure.
* varobj.c (varobj_ensure_python_env): New helper function.
(varobj_get_display_hint, update_dynamic_varobj_children,
install_default_visualizer, varobj_set_visualizer, free_variable,
value_get_print_value): Call it.
(value_get_print_value): Add varobj argument instead of pretty
printer argument. Update all callers.
* python/python-utils.c (py_gil_restore, make_cleanup_py_restore_gil):
Remove.
* value.h (internal_function_fn): Add GDBARCH and LANGUAGE argument.
(call_internal_function): Likewise.
* value.c (call_internal_function): Likewise. Pass to handler.
* eval.c (evaluate_subexp_standard): Update call.
* python/python-function.c: Include "language.h".
(fnpy_call): Add GDBARCH and LANGAUAGE arguments and call
make_cleanup_python_env.
* python/python-value.c (builtin_type_pyint, builtin_type_pyfloat,
builtin_type_pylong, builtin_type_pybool, builtin_type_pychar,
valpy_str): Use python_gdbarch and python_language instead of
current_gdbarch and current_language.
* python/python-type.c (typy_lookup_typename): Likewise.
2009-07-02 19:04:23 +02:00
|
|
|
|
return make_cleanup (restore_python_env, env);
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-22 19:48:55 +02:00
|
|
|
|
/* Clear the quit flag. */
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
clear_quit_flag (void)
|
|
|
|
|
{
|
|
|
|
|
/* This clears the flag as a side effect. */
|
|
|
|
|
PyOS_InterruptOccurred ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Set the quit flag. */
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
set_quit_flag (void)
|
|
|
|
|
{
|
|
|
|
|
PyErr_SetInterrupt ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Return true if the quit flag has been set, false otherwise. */
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
check_quit_flag (void)
|
|
|
|
|
{
|
|
|
|
|
return PyOS_InterruptOccurred ();
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-22 21:15:15 +02:00
|
|
|
|
/* Evaluate a Python command like PyRun_SimpleString, but uses
|
|
|
|
|
Py_single_input which prints the result of expressions, and does
|
|
|
|
|
not automatically print the stack on errors. */
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
eval_python_command (const char *command)
|
|
|
|
|
{
|
|
|
|
|
PyObject *m, *d, *v;
|
|
|
|
|
|
|
|
|
|
m = PyImport_AddModule ("__main__");
|
|
|
|
|
if (m == NULL)
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
d = PyModule_GetDict (m);
|
|
|
|
|
if (d == NULL)
|
|
|
|
|
return -1;
|
|
|
|
|
v = PyRun_StringFlags (command, Py_single_input, d, d, NULL);
|
|
|
|
|
if (v == NULL)
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
Py_DECREF (v);
|
2012-12-12 17:47:30 +01:00
|
|
|
|
#ifndef IS_PY3K
|
2012-08-22 21:15:15 +02:00
|
|
|
|
if (Py_FlushLine ())
|
|
|
|
|
PyErr_Clear ();
|
2012-12-12 17:47:30 +01:00
|
|
|
|
#endif
|
2012-08-22 21:15:15 +02:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Implementation of the gdb "python-interactive" command. */
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
python_interactive_command (char *arg, int from_tty)
|
|
|
|
|
{
|
|
|
|
|
struct cleanup *cleanup;
|
|
|
|
|
int err;
|
|
|
|
|
|
|
|
|
|
cleanup = make_cleanup_restore_integer (&interpreter_async);
|
|
|
|
|
interpreter_async = 0;
|
|
|
|
|
|
2013-03-07 22:57:30 +01:00
|
|
|
|
arg = skip_spaces (arg);
|
2012-08-22 21:15:15 +02:00
|
|
|
|
|
|
|
|
|
ensure_python_env (get_current_arch (), current_language);
|
|
|
|
|
|
|
|
|
|
if (arg && *arg)
|
|
|
|
|
{
|
|
|
|
|
int len = strlen (arg);
|
|
|
|
|
char *script = xmalloc (len + 2);
|
|
|
|
|
|
|
|
|
|
strcpy (script, arg);
|
|
|
|
|
script[len] = '\n';
|
|
|
|
|
script[len + 1] = '\0';
|
|
|
|
|
err = eval_python_command (script);
|
|
|
|
|
xfree (script);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
err = PyRun_InteractiveLoop (instream, "<stdin>");
|
|
|
|
|
dont_repeat ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (err)
|
|
|
|
|
{
|
|
|
|
|
gdbpy_print_stack ();
|
|
|
|
|
error (_("Error while executing Python code."));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
do_cleanups (cleanup);
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-26 22:54:45 +01:00
|
|
|
|
/* A wrapper around PyRun_SimpleFile. FILE is the Python script to run
|
|
|
|
|
named FILENAME.
|
|
|
|
|
|
|
|
|
|
On Windows hosts few users would build Python themselves (this is no
|
|
|
|
|
trivial task on this platform), and thus use binaries built by
|
|
|
|
|
someone else instead. There may happen situation where the Python
|
|
|
|
|
library and GDB are using two different versions of the C runtime
|
|
|
|
|
library. Python, being built with VC, would use one version of the
|
|
|
|
|
msvcr DLL (Eg. msvcr100.dll), while MinGW uses msvcrt.dll.
|
|
|
|
|
A FILE * from one runtime does not necessarily operate correctly in
|
2011-10-03 22:46:19 +02:00
|
|
|
|
the other runtime.
|
|
|
|
|
|
2012-01-26 22:54:45 +01:00
|
|
|
|
To work around this potential issue, we create on Windows hosts the
|
|
|
|
|
FILE object using Python routines, thus making sure that it is
|
|
|
|
|
compatible with the Python library. */
|
2011-10-03 22:46:19 +02:00
|
|
|
|
|
|
|
|
|
static void
|
2012-01-26 22:54:45 +01:00
|
|
|
|
python_run_simple_file (FILE *file, const char *filename)
|
2011-10-03 22:46:19 +02:00
|
|
|
|
{
|
2012-01-26 22:54:45 +01:00
|
|
|
|
#ifndef _WIN32
|
|
|
|
|
|
|
|
|
|
PyRun_SimpleFile (file, filename);
|
|
|
|
|
|
|
|
|
|
#else /* _WIN32 */
|
|
|
|
|
|
2011-11-04 13:07:53 +01:00
|
|
|
|
char *full_path;
|
2011-10-03 22:46:19 +02:00
|
|
|
|
PyObject *python_file;
|
|
|
|
|
struct cleanup *cleanup;
|
|
|
|
|
|
2011-11-04 13:07:53 +01:00
|
|
|
|
/* Because we have a string for a filename, and are using Python to
|
|
|
|
|
open the file, we need to expand any tilde in the path first. */
|
|
|
|
|
full_path = tilde_expand (filename);
|
|
|
|
|
cleanup = make_cleanup (xfree, full_path);
|
|
|
|
|
python_file = PyFile_FromString (full_path, "r");
|
|
|
|
|
if (! python_file)
|
|
|
|
|
{
|
|
|
|
|
do_cleanups (cleanup);
|
|
|
|
|
gdbpy_print_stack ();
|
|
|
|
|
error (_("Error while opening file: %s"), full_path);
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-03 22:46:19 +02:00
|
|
|
|
make_cleanup_py_decref (python_file);
|
|
|
|
|
PyRun_SimpleFile (PyFile_AsFile (python_file), filename);
|
|
|
|
|
do_cleanups (cleanup);
|
2012-01-26 22:54:45 +01:00
|
|
|
|
|
|
|
|
|
#endif /* _WIN32 */
|
2011-10-03 22:46:19 +02:00
|
|
|
|
}
|
* python/python-internal.h (struct language_defn): Declare.
(python_gdbarch, python_language): Likewise.
(ensure_python_env): Add prototype.
(make_cleanup_py_restore_gil): Remove prototype.
* python/python.c: Include "arch-utils.h", "value.h" and "language.h".
(python_gdbarch, python_language): New global variables.
(struct python_env): New data type.
(ensure_python_env, restore_python_env): New functions.
(eval_python_from_control_command): Call ensure_python_env to
install current architecture and language.
(python_command, gdbpy_new_objfile): Likewise.
* python/python-cmd.c: Include "arch-utils.h" and "language.h".
(cmdpy_destroyer, cmdpy_function, cmdpy_completer): Call
ensure_python_env.
* python/python-type.c (clean_up_objfile_types): Likewise.
* python/python-objfile.c: Include "language.h".
(clean_up_objfile): Call ensure_python_env.
* python/python-prettyprint.c (apply_val_pretty_printer): Likewise.
(apply_varobj_pretty_printer): Do not call PyGILState_Ensure.
* varobj.c (varobj_ensure_python_env): New helper function.
(varobj_get_display_hint, update_dynamic_varobj_children,
install_default_visualizer, varobj_set_visualizer, free_variable,
value_get_print_value): Call it.
(value_get_print_value): Add varobj argument instead of pretty
printer argument. Update all callers.
* python/python-utils.c (py_gil_restore, make_cleanup_py_restore_gil):
Remove.
* value.h (internal_function_fn): Add GDBARCH and LANGUAGE argument.
(call_internal_function): Likewise.
* value.c (call_internal_function): Likewise. Pass to handler.
* eval.c (evaluate_subexp_standard): Update call.
* python/python-function.c: Include "language.h".
(fnpy_call): Add GDBARCH and LANGAUAGE arguments and call
make_cleanup_python_env.
* python/python-value.c (builtin_type_pyint, builtin_type_pyfloat,
builtin_type_pylong, builtin_type_pybool, builtin_type_pychar,
valpy_str): Use python_gdbarch and python_language instead of
current_gdbarch and current_language.
* python/python-type.c (typy_lookup_typename): Likewise.
2009-07-02 19:04:23 +02:00
|
|
|
|
|
2008-08-06 21:41:33 +02:00
|
|
|
|
/* Given a command_line, return a command string suitable for passing
|
|
|
|
|
to Python. Lines in the string are separated by newlines. The
|
|
|
|
|
return value is allocated using xmalloc and the caller is
|
|
|
|
|
responsible for freeing it. */
|
|
|
|
|
|
|
|
|
|
static char *
|
|
|
|
|
compute_python_string (struct command_line *l)
|
|
|
|
|
{
|
|
|
|
|
struct command_line *iter;
|
|
|
|
|
char *script = NULL;
|
|
|
|
|
int size = 0;
|
|
|
|
|
int here;
|
|
|
|
|
|
|
|
|
|
for (iter = l; iter; iter = iter->next)
|
|
|
|
|
size += strlen (iter->line) + 1;
|
|
|
|
|
|
|
|
|
|
script = xmalloc (size + 1);
|
|
|
|
|
here = 0;
|
|
|
|
|
for (iter = l; iter; iter = iter->next)
|
|
|
|
|
{
|
|
|
|
|
int len = strlen (iter->line);
|
2010-05-17 23:23:25 +02:00
|
|
|
|
|
2008-08-06 21:41:33 +02:00
|
|
|
|
strcpy (&script[here], iter->line);
|
|
|
|
|
here += len;
|
|
|
|
|
script[here++] = '\n';
|
|
|
|
|
}
|
|
|
|
|
script[here] = '\0';
|
|
|
|
|
return script;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 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)
|
|
|
|
|
{
|
2009-02-05 17:40:34 +01:00
|
|
|
|
int ret;
|
2008-08-06 21:41:33 +02:00
|
|
|
|
char *script;
|
2008-11-21 15:59:56 +01:00
|
|
|
|
struct cleanup *cleanup;
|
2008-08-06 21:41:33 +02:00
|
|
|
|
|
|
|
|
|
if (cmd->body_count != 1)
|
|
|
|
|
error (_("Invalid \"python\" block structure."));
|
|
|
|
|
|
* python/python-internal.h (struct language_defn): Declare.
(python_gdbarch, python_language): Likewise.
(ensure_python_env): Add prototype.
(make_cleanup_py_restore_gil): Remove prototype.
* python/python.c: Include "arch-utils.h", "value.h" and "language.h".
(python_gdbarch, python_language): New global variables.
(struct python_env): New data type.
(ensure_python_env, restore_python_env): New functions.
(eval_python_from_control_command): Call ensure_python_env to
install current architecture and language.
(python_command, gdbpy_new_objfile): Likewise.
* python/python-cmd.c: Include "arch-utils.h" and "language.h".
(cmdpy_destroyer, cmdpy_function, cmdpy_completer): Call
ensure_python_env.
* python/python-type.c (clean_up_objfile_types): Likewise.
* python/python-objfile.c: Include "language.h".
(clean_up_objfile): Call ensure_python_env.
* python/python-prettyprint.c (apply_val_pretty_printer): Likewise.
(apply_varobj_pretty_printer): Do not call PyGILState_Ensure.
* varobj.c (varobj_ensure_python_env): New helper function.
(varobj_get_display_hint, update_dynamic_varobj_children,
install_default_visualizer, varobj_set_visualizer, free_variable,
value_get_print_value): Call it.
(value_get_print_value): Add varobj argument instead of pretty
printer argument. Update all callers.
* python/python-utils.c (py_gil_restore, make_cleanup_py_restore_gil):
Remove.
* value.h (internal_function_fn): Add GDBARCH and LANGUAGE argument.
(call_internal_function): Likewise.
* value.c (call_internal_function): Likewise. Pass to handler.
* eval.c (evaluate_subexp_standard): Update call.
* python/python-function.c: Include "language.h".
(fnpy_call): Add GDBARCH and LANGAUAGE arguments and call
make_cleanup_python_env.
* python/python-value.c (builtin_type_pyint, builtin_type_pyfloat,
builtin_type_pylong, builtin_type_pybool, builtin_type_pychar,
valpy_str): Use python_gdbarch and python_language instead of
current_gdbarch and current_language.
* python/python-type.c (typy_lookup_typename): Likewise.
2009-07-02 19:04:23 +02:00
|
|
|
|
cleanup = ensure_python_env (get_current_arch (), current_language);
|
2008-11-21 15:59:56 +01:00
|
|
|
|
|
2008-08-06 21:41:33 +02:00
|
|
|
|
script = compute_python_string (cmd->body_list[0]);
|
2009-02-05 17:40:34 +01:00
|
|
|
|
ret = PyRun_SimpleString (script);
|
2008-08-06 21:41:33 +02:00
|
|
|
|
xfree (script);
|
2009-02-05 17:40:34 +01:00
|
|
|
|
if (ret)
|
2011-12-16 16:55:40 +01:00
|
|
|
|
error (_("Error while executing Python code."));
|
2008-11-21 15:59:56 +01:00
|
|
|
|
|
|
|
|
|
do_cleanups (cleanup);
|
2008-08-06 21:41:33 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Implementation of the gdb "python" command. */
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
python_command (char *arg, int from_tty)
|
|
|
|
|
{
|
2008-11-21 15:59:56 +01:00
|
|
|
|
struct cleanup *cleanup;
|
|
|
|
|
|
2010-05-17 23:23:25 +02:00
|
|
|
|
cleanup = ensure_python_env (get_current_arch (), current_language);
|
2011-09-02 18:56:30 +02:00
|
|
|
|
|
|
|
|
|
make_cleanup_restore_integer (&interpreter_async);
|
|
|
|
|
interpreter_async = 0;
|
|
|
|
|
|
2013-03-07 22:57:30 +01:00
|
|
|
|
arg = skip_spaces (arg);
|
2008-08-06 21:41:33 +02:00
|
|
|
|
if (arg && *arg)
|
|
|
|
|
{
|
2009-02-05 17:40:34 +01:00
|
|
|
|
if (PyRun_SimpleString (arg))
|
2011-12-16 16:55:40 +01:00
|
|
|
|
error (_("Error while executing Python code."));
|
2008-08-06 21:41:33 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
struct command_line *l = get_command_line (python_control, "");
|
2010-05-17 23:23:25 +02:00
|
|
|
|
|
2008-11-21 15:59:56 +01:00
|
|
|
|
make_cleanup_free_command_lines (&l);
|
2008-08-06 21:41:33 +02:00
|
|
|
|
execute_control_command_untraced (l);
|
|
|
|
|
}
|
2008-11-21 15:59:56 +01:00
|
|
|
|
|
|
|
|
|
do_cleanups (cleanup);
|
2008-08-06 21:41:33 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Transform a gdb parameters's value into a Python value. May return
|
|
|
|
|
NULL (and set a Python exception) on error. Helper function for
|
|
|
|
|
get_parameter. */
|
2010-04-29 17:45:57 +02:00
|
|
|
|
PyObject *
|
|
|
|
|
gdbpy_parameter_value (enum var_types type, void *var)
|
2008-08-06 21:41:33 +02:00
|
|
|
|
{
|
2010-04-29 17:45:57 +02:00
|
|
|
|
switch (type)
|
2008-08-06 21:41:33 +02:00
|
|
|
|
{
|
|
|
|
|
case var_string:
|
|
|
|
|
case var_string_noescape:
|
|
|
|
|
case var_optional_filename:
|
|
|
|
|
case var_filename:
|
|
|
|
|
case var_enum:
|
|
|
|
|
{
|
2010-04-29 17:45:57 +02:00
|
|
|
|
char *str = * (char **) var;
|
2010-05-17 23:23:25 +02:00
|
|
|
|
|
2008-08-06 21:41:33 +02:00
|
|
|
|
if (! str)
|
|
|
|
|
str = "";
|
|
|
|
|
return PyString_Decode (str, strlen (str), host_charset (), NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case var_boolean:
|
|
|
|
|
{
|
2010-04-29 17:45:57 +02:00
|
|
|
|
if (* (int *) var)
|
2008-08-06 21:41:33 +02:00
|
|
|
|
Py_RETURN_TRUE;
|
|
|
|
|
else
|
|
|
|
|
Py_RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case var_auto_boolean:
|
|
|
|
|
{
|
2010-04-29 17:45:57 +02:00
|
|
|
|
enum auto_boolean ab = * (enum auto_boolean *) var;
|
2010-05-17 23:23:25 +02:00
|
|
|
|
|
2008-08-06 21:41:33 +02:00
|
|
|
|
if (ab == AUTO_BOOLEAN_TRUE)
|
|
|
|
|
Py_RETURN_TRUE;
|
|
|
|
|
else if (ab == AUTO_BOOLEAN_FALSE)
|
|
|
|
|
Py_RETURN_FALSE;
|
|
|
|
|
else
|
|
|
|
|
Py_RETURN_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case var_integer:
|
2010-04-29 17:45:57 +02:00
|
|
|
|
if ((* (int *) var) == INT_MAX)
|
2008-08-06 21:41:33 +02:00
|
|
|
|
Py_RETURN_NONE;
|
|
|
|
|
/* Fall through. */
|
|
|
|
|
case var_zinteger:
|
2010-04-29 17:45:57 +02:00
|
|
|
|
return PyLong_FromLong (* (int *) var);
|
2008-08-06 21:41:33 +02:00
|
|
|
|
|
|
|
|
|
case var_uinteger:
|
|
|
|
|
{
|
2010-04-29 17:45:57 +02:00
|
|
|
|
unsigned int val = * (unsigned int *) var;
|
2010-05-17 23:23:25 +02:00
|
|
|
|
|
2008-08-06 21:41:33 +02:00
|
|
|
|
if (val == UINT_MAX)
|
|
|
|
|
Py_RETURN_NONE;
|
|
|
|
|
return PyLong_FromUnsignedLong (val);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-14 15:18:55 +02:00
|
|
|
|
return PyErr_Format (PyExc_RuntimeError,
|
|
|
|
|
_("Programmer error: unhandled type."));
|
2008-08-06 21:41:33 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* A Python function which returns a gdb parameter's value as a Python
|
|
|
|
|
value. */
|
|
|
|
|
|
2010-04-29 17:45:57 +02:00
|
|
|
|
PyObject *
|
2009-05-28 18:49:55 +02:00
|
|
|
|
gdbpy_parameter (PyObject *self, PyObject *args)
|
2008-08-06 21:41:33 +02:00
|
|
|
|
{
|
|
|
|
|
struct cmd_list_element *alias, *prefix, *cmd;
|
2011-06-24 21:47:37 +02:00
|
|
|
|
const char *arg;
|
|
|
|
|
char *newarg;
|
2009-03-21 04:13:02 +01:00
|
|
|
|
int found = -1;
|
2008-08-06 21:41:33 +02:00
|
|
|
|
volatile struct gdb_exception except;
|
|
|
|
|
|
|
|
|
|
if (! PyArg_ParseTuple (args, "s", &arg))
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
newarg = concat ("show ", arg, (char *) NULL);
|
|
|
|
|
|
|
|
|
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
|
|
|
|
{
|
2009-03-21 04:13:02 +01:00
|
|
|
|
found = lookup_cmd_composition (newarg, &alias, &prefix, &cmd);
|
2008-08-06 21:41:33 +02:00
|
|
|
|
}
|
|
|
|
|
xfree (newarg);
|
|
|
|
|
GDB_PY_HANDLE_EXCEPTION (except);
|
2009-03-21 04:13:02 +01:00
|
|
|
|
if (!found)
|
|
|
|
|
return PyErr_Format (PyExc_RuntimeError,
|
2010-04-14 15:18:55 +02:00
|
|
|
|
_("Could not find parameter `%s'."), arg);
|
2008-08-06 21:41:33 +02:00
|
|
|
|
|
|
|
|
|
if (! cmd->var)
|
2010-04-14 15:18:55 +02:00
|
|
|
|
return PyErr_Format (PyExc_RuntimeError,
|
|
|
|
|
_("`%s' is not a parameter."), arg);
|
2010-04-29 17:45:57 +02:00
|
|
|
|
return gdbpy_parameter_value (cmd->var_type, cmd->var);
|
2008-08-06 21:41:33 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-03-05 21:18:19 +01:00
|
|
|
|
/* Wrapper for target_charset. */
|
|
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
|
gdbpy_target_charset (PyObject *self, PyObject *args)
|
|
|
|
|
{
|
|
|
|
|
const char *cset = target_charset (python_gdbarch);
|
2010-05-17 23:23:25 +02:00
|
|
|
|
|
2010-03-05 21:18:19 +01:00
|
|
|
|
return PyUnicode_Decode (cset, strlen (cset), host_charset (), NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Wrapper for target_wide_charset. */
|
|
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
|
gdbpy_target_wide_charset (PyObject *self, PyObject *args)
|
|
|
|
|
{
|
|
|
|
|
const char *cset = target_wide_charset (python_gdbarch);
|
2010-05-17 23:23:25 +02:00
|
|
|
|
|
2010-03-05 21:18:19 +01:00
|
|
|
|
return PyUnicode_Decode (cset, strlen (cset), host_charset (), NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2008-08-06 21:41:33 +02:00
|
|
|
|
/* A Python function which evaluates a string using the gdb CLI. */
|
|
|
|
|
|
|
|
|
|
static PyObject *
|
2010-06-25 20:15:18 +02:00
|
|
|
|
execute_gdb_command (PyObject *self, PyObject *args, PyObject *kw)
|
2008-08-06 21:41:33 +02:00
|
|
|
|
{
|
2011-06-24 21:47:37 +02:00
|
|
|
|
const char *arg;
|
2010-06-25 20:15:18 +02:00
|
|
|
|
PyObject *from_tty_obj = NULL, *to_string_obj = NULL;
|
|
|
|
|
int from_tty, to_string;
|
2008-08-06 21:41:33 +02:00
|
|
|
|
volatile struct gdb_exception except;
|
2010-06-25 20:15:18 +02:00
|
|
|
|
static char *keywords[] = {"command", "from_tty", "to_string", NULL };
|
|
|
|
|
char *result = NULL;
|
2008-08-06 21:41:33 +02:00
|
|
|
|
|
2010-06-25 20:15:18 +02:00
|
|
|
|
if (! PyArg_ParseTupleAndKeywords (args, kw, "s|O!O!", keywords, &arg,
|
|
|
|
|
&PyBool_Type, &from_tty_obj,
|
|
|
|
|
&PyBool_Type, &to_string_obj))
|
2008-08-06 21:41:33 +02:00
|
|
|
|
return NULL;
|
|
|
|
|
|
2009-02-05 17:40:34 +01:00
|
|
|
|
from_tty = 0;
|
|
|
|
|
if (from_tty_obj)
|
|
|
|
|
{
|
2010-06-25 20:15:18 +02:00
|
|
|
|
int cmp = PyObject_IsTrue (from_tty_obj);
|
2009-02-05 17:40:34 +01:00
|
|
|
|
if (cmp < 0)
|
2010-06-25 20:15:18 +02:00
|
|
|
|
return NULL;
|
2009-02-05 17:40:34 +01:00
|
|
|
|
from_tty = cmp;
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-25 20:15:18 +02:00
|
|
|
|
to_string = 0;
|
|
|
|
|
if (to_string_obj)
|
|
|
|
|
{
|
|
|
|
|
int cmp = PyObject_IsTrue (to_string_obj);
|
|
|
|
|
if (cmp < 0)
|
|
|
|
|
return NULL;
|
|
|
|
|
to_string = cmp;
|
|
|
|
|
}
|
|
|
|
|
|
2008-08-06 21:41:33 +02:00
|
|
|
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
|
|
|
|
{
|
2009-11-09 19:29:12 +01:00
|
|
|
|
/* Copy the argument text in case the command modifies it. */
|
|
|
|
|
char *copy = xstrdup (arg);
|
|
|
|
|
struct cleanup *cleanup = make_cleanup (xfree, copy);
|
2010-06-25 20:15:18 +02:00
|
|
|
|
|
2011-09-02 18:56:30 +02:00
|
|
|
|
make_cleanup_restore_integer (&interpreter_async);
|
|
|
|
|
interpreter_async = 0;
|
|
|
|
|
|
2011-01-31 17:52:35 +01:00
|
|
|
|
prevent_dont_repeat ();
|
2010-06-25 20:15:18 +02:00
|
|
|
|
if (to_string)
|
2010-08-07 17:00:39 +02:00
|
|
|
|
result = execute_command_to_string (copy, from_tty);
|
|
|
|
|
else
|
2010-06-25 20:15:18 +02:00
|
|
|
|
{
|
2010-08-07 17:00:39 +02:00
|
|
|
|
result = NULL;
|
|
|
|
|
execute_command (copy, from_tty);
|
2010-06-25 20:15:18 +02:00
|
|
|
|
}
|
2010-05-17 23:23:25 +02:00
|
|
|
|
|
2009-11-09 19:29:12 +01:00
|
|
|
|
do_cleanups (cleanup);
|
2008-08-06 21:41:33 +02:00
|
|
|
|
}
|
|
|
|
|
GDB_PY_HANDLE_EXCEPTION (except);
|
|
|
|
|
|
2008-09-08 23:46:21 +02:00
|
|
|
|
/* Do any commands attached to breakpoint we stopped at. */
|
|
|
|
|
bpstat_do_actions ();
|
2008-08-06 21:41:33 +02:00
|
|
|
|
|
2010-06-25 20:15:18 +02:00
|
|
|
|
if (result)
|
|
|
|
|
{
|
|
|
|
|
PyObject *r = PyString_FromString (result);
|
|
|
|
|
xfree (result);
|
|
|
|
|
return r;
|
|
|
|
|
}
|
2008-08-06 21:41:33 +02:00
|
|
|
|
Py_RETURN_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-11 14:48:24 +02:00
|
|
|
|
/* Implementation of gdb.solib_name (Long) -> String.
|
|
|
|
|
Returns the name of the shared library holding a given address, or None. */
|
|
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
|
gdbpy_solib_name (PyObject *self, PyObject *args)
|
|
|
|
|
{
|
|
|
|
|
char *soname;
|
|
|
|
|
PyObject *str_obj;
|
2011-01-26 21:53:45 +01:00
|
|
|
|
gdb_py_longest pc;
|
|
|
|
|
|
|
|
|
|
if (!PyArg_ParseTuple (args, GDB_PY_LL_ARG, &pc))
|
2010-08-11 14:48:24 +02:00
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
soname = solib_name_from_address (current_program_space, pc);
|
|
|
|
|
if (soname)
|
|
|
|
|
str_obj = PyString_Decode (soname, strlen (soname), host_charset (), NULL);
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
str_obj = Py_None;
|
|
|
|
|
Py_INCREF (Py_None);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return str_obj;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* A Python function which is a wrapper for decode_line_1. */
|
|
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
|
gdbpy_decode_line (PyObject *self, PyObject *args)
|
|
|
|
|
{
|
2011-01-06 01:57:05 +01:00
|
|
|
|
struct symtabs_and_lines sals = { NULL, 0 }; /* Initialize to
|
|
|
|
|
appease gcc. */
|
2010-08-11 14:48:24 +02:00
|
|
|
|
struct symtab_and_line sal;
|
2011-06-24 21:47:37 +02:00
|
|
|
|
const char *arg = NULL;
|
2012-03-30 22:05:55 +02:00
|
|
|
|
char *copy_to_free = NULL, *copy = NULL;
|
2010-08-11 14:48:24 +02:00
|
|
|
|
struct cleanup *cleanups;
|
|
|
|
|
PyObject *result = NULL;
|
|
|
|
|
PyObject *return_result = NULL;
|
|
|
|
|
PyObject *unparsed = NULL;
|
|
|
|
|
volatile struct gdb_exception except;
|
|
|
|
|
|
|
|
|
|
if (! PyArg_ParseTuple (args, "|s", &arg))
|
|
|
|
|
return NULL;
|
|
|
|
|
|
2011-11-28 16:49:43 +01:00
|
|
|
|
cleanups = make_cleanup (null_cleanup, NULL);
|
2010-08-11 14:48:24 +02:00
|
|
|
|
|
2012-03-30 22:05:55 +02:00
|
|
|
|
sals.sals = NULL;
|
2010-08-11 14:48:24 +02:00
|
|
|
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
|
|
|
|
{
|
|
|
|
|
if (arg)
|
|
|
|
|
{
|
2011-06-24 21:47:37 +02:00
|
|
|
|
copy = xstrdup (arg);
|
2012-03-30 22:05:55 +02:00
|
|
|
|
copy_to_free = copy;
|
the "ambiguous linespec" series
gdb
2011-12-06 Joel Brobecker <brobecker@acacore.com>
* language.h (struct language_defn): Add new component
la_symbol_name_compare.
* symfile.h (struct quick_symbol_functions): Update the profile
of parameter "name_matcher" for the expand_symtabs_matching
method. Update the documentation accordingly.
* ada-lang.h (ada_name_for_lookup): Add declaration.
* ada-lang.c (ada_name_for_lookup): New function, extracted out
from ada_iterate_over_symbols.
(ada_iterate_over_symbols): Do not encode symbol name anymore.
(ada_expand_partial_symbol_name): Adjust profile.
(ada_language_defn): Add value for la_symbol_name_compare field.
* linespec.c: #include "ada-lang.h".
(iterate_name_matcher): Add language parameter. Replace call
to strcmp_iw by call to language->la_symbol_name_compare.
(decode_variable): Encode COPY if current language is Ada.
* dwarf2read.c (dw2_expand_symtabs_matching): Adjust profile
of name_matcher parameter. Adjust call to name_matcher.
* psymtab.c (expand_symtabs_matching_via_partial): Likewise.
(expand_partial_symbol_names): Update profile of parameter "fun".
* psymtab.h (expand_partial_symbol_names): Update profile of
parameter "fun".
* symtab.c (demangle_for_lookup): Update function documentation.
(search_symbols_name_matches): Add language parameter.
(expand_partial_symbol_name): Likewise.
* c-lang.c (c_language_defn, cplus_language_defn)
(asm_language_defn, minimal_language_defn): Add value for
la_symbol_name_compare field.
* d-lang.c (d_language_defn): Likewise.
* f-lang.c (f_language_defn): Ditto.
* jv-lang.c (java_language_defn): Ditto.
* m2-lang.c (m2_language_defn): Ditto.
* objc-lang.c (objc_language_defn): Ditto.
* opencl-lang.c (opencl_language_defn): Ditto.
* p-lang.c (pascal_language_defn): Ditto.
* language.c (unknown_language_defn, auto_language_defn)
(local_language_defn): Ditto.
2011-12-06 Tom Tromey <tromey@redhat.com>
* linespec.c (iterate_over_all_matching_symtabs): Use
LA_ITERATE_OVER_SYMBOLS.
(lookup_prefix_sym, add_matching_symbols_to_info): Likewise.
(find_function_symbols, decode_variable): Remove Ada special
case.
* language.h (struct language_defn) <la_iterate_over_symbols>: New
field.
(LA_ITERATE_OVER_SYMBOLS): New macro.
* language.c (unknown_language_defn, auto_language_defn)
(local_language_defn): Update.
* c-lang.c (c_language_defn, cplus_language_defn)
(asm_language_defn, minimal_language_defn): Update.
* d-lang.c (d_language_defn): Update.
* f-lang.c (f_language_defn): Update.
* jv-lang.c (java_language_defn): Update.
* m2-lang.c (m2_language_defn): Update.
* objc-lang.c (objc_language_defn): Update.
* opencl-lang.c (opencl_language_defn): Update.
* p-lang.c (pascal_language_defn): Update.
* ada-lang.c (ada_iterate_over_symbols): New function.
(ada_language_defn): Update.
2011-12-06 Tom Tromey <tromey@redhat.com>
Joel Brobecker <brobecker@acacore.com>
PR breakpoints/13105, PR objc/8341, PR objc/8343, PR objc/8366,
PR objc/8535, PR breakpoints/11657, PR breakpoints/11970,
PR breakpoints/12023, PR breakpoints/12334, PR breakpoints/12856,
PR shlibs/8929, PR shlibs/7393:
* python/py-type.c (compare_maybe_null_strings): Rename from
compare_strings.
(check_types_equal): Update.
* utils.c (compare_strings): New function.
* tui/tui-winsource.c (tui_update_breakpoint_info): Update for
location changes.
* tracepoint.c (scope_info): Update.
(trace_find_line_command): Use DECODE_LINE_FUNFIRSTLINE.
* symtab.h (iterate_over_minimal_symbols)
(iterate_over_some_symtabs, iterate_over_symtabs)
(find_pcs_for_symtab_line, iterate_over_symbols)
(demangle_for_lookup): Declare.
(expand_line_sal): Remove.
* symtab.c (iterate_over_some_symtabs, iterate_over_symtabs)
(lookup_symtab_callback): New functions.
(lookup_symtab): Rewrite.
(demangle_for_lookup): New function, extract from
lookup_symbol_in_language.
(lookup_symbol_in_language): Use it.
(iterate_over_symbols): New function.
(find_line_symtab): Update.
(find_pcs_for_symtab_line): New functions.
(find_line_common): Add 'start' argument.
(decode_line_spec): Update. Change argument to 'flags', change
interpretation.
(append_expanded_sal): Remove.
(append_exact_match_to_sals): Remove.
(expand_line_sal): Remove.
* symfile.h (struct quick_symbol_functions) <lookup_symtab>:
Remove.
<map_symtabs_matching_filename>: New field.
* stack.c (func_command): Only look in the current program space.
Use DECODE_LINE_FUNFIRSTLINE.
* source.c (line_info): Set pspace on sal. Check program space in
the loop. Use DECODE_LINE_LIST_MODE.
(select_source_symtab): Use DECODE_LINE_FUNFIRSTLINE.
* solib-target.c: Remove DEF_VEC_I(CORE_ADDR).
* python/python.c (gdbpy_decode_line): Update.
* psymtab.c (partial_map_expand_apply): New function.
(partial_map_symtabs_matching_filename): Rename from
lookup_partial_symbol. Update arguments.
(lookup_symtab_via_partial_symtab): Remove.
(psym_functions): Update.
* objc-lang.h (parse_selector, parse_method): Don't declare.
(find_imps): Update.
* objc-lang.c (parse_selector, parse_method): Now static.
(find_methods): Change arguments. Fill in a vector of symbol
names.
(uniquify_strings): New function.
(find_imps): Change arguments.
* minsyms.c (iterate_over_minimal_symbols): New function.
* linespec.h (enum decode_line_flags): New.
(struct linespec_sals): New.
(struct linespec_result) <canonical>: Remove.
<pre_expanded, addr_string, sals>: New fields.
(destroy_linespec_result, make_cleanup_destroy_linespec_result)
(decode_line_full): Declare.
(decode_line_1): Update.
* linespec.c (struct address_entry, struct linespec_state, struct
collect_info): New types.
(add_sal_to_sals_basic, add_sal_to_sals, hash_address_entry)
(eq_address_entry, maybe_add_address): New functions.
(total_number_of_methods): Remove.
(iterate_name_matcher, iterate_over_all_matching_symtabs): New
functions.
(find_methods): Change arguments. Don't canonicalize input.
Simplify logic.
(add_matching_methods, add_constructors)
(build_canonical_line_spec): Remove.
(filter_results, convert_results_to_lsals): New functions.
(decode_line_2): Change arguments. Rewrite for new data
structures.
(decode_line_internal): Rename from decode_line_1. Change
arguments. Add cleanups. Update for new data structures.
(linespec_state_constructor, linespec_state_destructor)
(decode_line_full, decode_line_1): New functions.
(decode_indirect): Change arguments. Update.
(locate_first_half): Use skip_spaces.
(decode_objc): Change arguments. Update for new data structures.
Simplify logic.
(decode_compound): Change arguments. Add cleanups. Remove
fallback code, replace with error.
(struct decode_compound_collector): New type.
(collect_one_symbol): New function.
(lookup_prefix_sym): Change arguments. Update.
(compare_symbol_name, add_all_symbol_names_from_pspace)
(find_superclass_methods ): New functions.
(find_method): Rewrite.
(struct symtab_collector): New type.
(add_symtabs_to_list, collect_symtabs_from_filename): New
functions.
(symtabs_from_filename): Change API. Rename from
symtab_from_filename.
(collect_function_symbols): New function.
(find_function_symbols): Change API. Rename from
find_function_symbol. Rewrite.
(decode_all_digits): Change arguments. Rewrite.
(decode_dollar): Change arguments. Use decode_variable.
(decode_label): Change arguments. Rewrite.
(collect_symbols): New function.
(minsym_found): Change arguments. Rewrite.
(check_minsym, search_minsyms_for_name)
(add_matching_symbols_to_info): New function.
(decode_variable): Change arguments. Iterate over all symbols.
(symbol_found): Remove.
(symbol_to_sal): New function.
(init_linespec_result, destroy_linespec_result)
(cleanup_linespec_result, make_cleanup_destroy_linespec_result):
New functions.
(decode_digits_list_mode, decode_digits_ordinary): New functions.
* dwarf2read.c (dw2_map_expand_apply): New function.
(dw2_map_symtabs_matching_filename): Rename from
dw2_lookup_symtab. Change arguments.
(dwarf2_gdb_index_functions): Update.
* dwarf2loc.c: Remove DEF_VEC_I(CORE_ADDR).
* defs.h (compare_strings): Declare.
* cli/cli-cmds.c (compare_strings): Move to utils.c.
(edit_command, list_command): Use DECODE_LINE_LIST_MODE. Call
filter_sals.
(compare_symtabs, filter_sals): New functions.
* breakpoint.h (struct bp_location) <line_number, source_file>:
New fields.
(struct breakpoint) <line_number, source_file>: Remove.
<filter>: New field.
* breakpoint.c (print_breakpoint_location, init_raw_breakpoint)
(momentary_breakpoint_from_master, add_location_to_breakpoint):
Update for changes to locations.
(init_breakpoint_sal): Add 'filter' argument. Set 'filter' on
breakpoint.
(create_breakpoint_sal): Add 'filter' argument.
(remove_sal, expand_line_sal_maybe): Remove.
(create_breakpoints_sal): Remove 'sals' argument. Handle
pre-expanded sals and the filter.
(parse_breakpoint_sals): Use decode_line_full.
(check_fast_tracepoint_sals): Use get_sal_arch.
(create_breakpoint): Create a linespec_sals. Update.
(break_range_command): Use decode_line_full. Update.
(until_break_command): Update.
(clear_command): Update match conditions for linespec.c changes.
Use DECODE_LINE_LIST_MODE.
(say_where): Update for changes to locations.
(bp_location_dtor): Free 'source_file'.
(base_breakpoint_dtor): Free 'filter'. Don't free 'source_file'.
(update_static_tracepoint): Update for changes to locations.
(update_breakpoint_locations): Disable ranged breakpoint if too
many locations match. Update.
(addr_string_to_sals): Use decode_line_full. Resolve all sal
PCs.
(breakpoint_re_set_default): Don't call expand_line_sal_maybe.
(decode_line_spec_1): Update. Change argument name to 'flags',
change interpretation.
* block.h (block_containing_function): Declare.
* block.c (block_containing_function): New function.
* skip.c (skip_function_command): Update.
(skip_re_set): Update.
* infcmd.c (jump_command): Use DECODE_LINE_FUNFIRSTLINE.
* mi/mi-main.c (mi_cmd_trace_find): Use DECODE_LINE_FUNFIRSTLINE.
* NEWS: Add entry.
2011-12-06 Tom Tromey <tromey@redhat.com>
* elfread.c (elf_gnu_ifunc_resolver_return_stop): Allow
breakpoint's pspace to be NULL.
* breakpoint.h (struct breakpoint) <pspace>: Update comment.
* breakpoint.c (init_raw_breakpoint): Conditionally set
breakpoint's pspace.
(init_breakpoint_sal): Don't set breakpoint's pspace.
(prepare_re_set_context): Conditionally switch program space.
(addr_string_to_sals): Check executing_startup on location's
program space.
2011-12-06 Tom Tromey <tromey@redhat.com>
* breakpoint.h (enum enable_state) <bp_startup_disabled>: Remove.
* breakpoint.c (should_be_inserted): Explicitly check if program
space is executing startup.
(describe_other_breakpoints): Update.
(disable_breakpoints_before_startup): Change executing_startup
earlier. Remove loop.
(enable_breakpoints_after_startup): Likewise.
(init_breakpoint_sal): Don't use bp_startup_disabled.
(create_breakpoint): Don't use bp_startup_disabled.
(update_global_location_list): Use should_be_inserted.
(bkpt_re_set): Update.
gdb/testsuite
2011-12-06 Joel Brobecker <brobecker@acacore.com>
* gdb.ada/fullname_bp.exp: Add tests for other valid linespecs
involving a fully qualified function name.
2011-12-06 Tom Tromey <tromey@redhat.com>
* gdb.ada/homonym.exp: Add three breakpoint tests.
2011-12-06 Tom Tromey <tromey@redhat.com>
* gdb.base/solib-weak.exp (do_test): Remove kfail.
* gdb.trace/tracecmd.exp: Disable pending breakpoints earlier.
* gdb.objc/objcdecode.exp: Update for output changes.
* gdb.linespec/linespec.exp: New file.
* gdb.linespec/lspec.cc: New file.
* gdb.linespec/lspec.h: New file.
* gdb.linespec/body.h: New file.
* gdb.linespec/base/two/thefile.cc: New file.
* gdb.linespec/base/one/thefile.cc: New file.
* gdb.linespec/Makefile.in: New file.
* gdb.cp/templates.exp (test_template_breakpoints): Update for
output changes.
* gdb.cp/re-set-overloaded.exp: Remove kfail.
* gdb.cp/ovldbreak.exp: Update for output changes. "all" test now
makes one breakpoint.
* gdb.cp/method2.exp (test_break): Update for output changes.
* gdb.cp/mb-templates.exp: Update for output changes.
* gdb.cp/mb-inline.exp: Update for output changes.
* gdb.cp/mb-ctor.exp: Update for output changes.
* gdb.cp/ovsrch.exp: Use fully-qualified names.
* gdb.base/solib-symbol.exp: Run to main later. Breakpoint now
has multiple matches.
* gdb.base/sepdebug.exp: Disable pending breakpoints. Update for
error message change.
* gdb.base/list.exp (test_list_filename_and_number): Update for
error message change.
* gdb.base/break.exp: Disable pending breakpoints. Update for
output changes.
* configure.ac: Add gdb.linespec.
* configure: Rebuild.
* Makefile.in (ALL_SUBDIRS): Add gdb.linespec.
gdb/doc
2011-12-06 Tom Tromey <tromey@redhat.com>
* gdb.texinfo (Set Breaks): Update for new behavior.
2011-12-06 19:54:43 +01:00
|
|
|
|
sals = decode_line_1 (©, 0, 0, 0);
|
2010-08-11 14:48:24 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
set_default_source_symtab_and_line ();
|
|
|
|
|
sal = get_current_source_symtab_and_line ();
|
|
|
|
|
sals.sals = &sal;
|
|
|
|
|
sals.nelts = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-03-30 22:05:55 +02:00
|
|
|
|
|
|
|
|
|
if (sals.sals != NULL && sals.sals != &sal)
|
|
|
|
|
{
|
|
|
|
|
make_cleanup (xfree, copy_to_free);
|
|
|
|
|
make_cleanup (xfree, sals.sals);
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-11 14:48:24 +02:00
|
|
|
|
if (except.reason < 0)
|
|
|
|
|
{
|
|
|
|
|
do_cleanups (cleanups);
|
|
|
|
|
/* We know this will always throw. */
|
|
|
|
|
GDB_PY_HANDLE_EXCEPTION (except);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (sals.nelts)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
result = PyTuple_New (sals.nelts);
|
|
|
|
|
if (! result)
|
|
|
|
|
goto error;
|
|
|
|
|
for (i = 0; i < sals.nelts; ++i)
|
|
|
|
|
{
|
|
|
|
|
PyObject *obj;
|
|
|
|
|
|
|
|
|
|
obj = symtab_and_line_to_sal_object (sals.sals[i]);
|
|
|
|
|
if (! obj)
|
|
|
|
|
{
|
|
|
|
|
Py_DECREF (result);
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PyTuple_SetItem (result, i, obj);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
result = Py_None;
|
|
|
|
|
Py_INCREF (Py_None);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return_result = PyTuple_New (2);
|
|
|
|
|
if (! return_result)
|
|
|
|
|
{
|
|
|
|
|
Py_DECREF (result);
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (copy && strlen (copy) > 0)
|
2012-03-30 22:05:55 +02:00
|
|
|
|
{
|
|
|
|
|
unparsed = PyString_FromString (copy);
|
|
|
|
|
if (unparsed == NULL)
|
|
|
|
|
{
|
|
|
|
|
Py_DECREF (result);
|
|
|
|
|
Py_DECREF (return_result);
|
|
|
|
|
return_result = NULL;
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-08-11 14:48:24 +02:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
unparsed = Py_None;
|
|
|
|
|
Py_INCREF (Py_None);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PyTuple_SetItem (return_result, 0, unparsed);
|
|
|
|
|
PyTuple_SetItem (return_result, 1, result);
|
|
|
|
|
|
2012-03-30 22:05:55 +02:00
|
|
|
|
error:
|
2010-08-11 14:48:24 +02:00
|
|
|
|
do_cleanups (cleanups);
|
|
|
|
|
|
|
|
|
|
return return_result;
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-03 19:30:02 +01:00
|
|
|
|
/* Parse a string and evaluate it as an expression. */
|
|
|
|
|
static PyObject *
|
|
|
|
|
gdbpy_parse_and_eval (PyObject *self, PyObject *args)
|
|
|
|
|
{
|
2011-06-24 21:47:37 +02:00
|
|
|
|
const char *expr_str;
|
2009-12-03 19:30:02 +01:00
|
|
|
|
struct value *result = NULL;
|
|
|
|
|
volatile struct gdb_exception except;
|
|
|
|
|
|
|
|
|
|
if (!PyArg_ParseTuple (args, "s", &expr_str))
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
|
|
|
|
{
|
2013-03-12 18:39:45 +01:00
|
|
|
|
result = parse_and_eval (expr_str);
|
2009-12-03 19:30:02 +01:00
|
|
|
|
}
|
|
|
|
|
GDB_PY_HANDLE_EXCEPTION (except);
|
|
|
|
|
|
|
|
|
|
return value_to_value_object (result);
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-13 13:33:44 +02:00
|
|
|
|
/* Implementation of gdb.find_pc_line function.
|
|
|
|
|
Returns the gdb.Symtab_and_line object corresponding to a PC value. */
|
|
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
|
gdbpy_find_pc_line (PyObject *self, PyObject *args)
|
|
|
|
|
{
|
2012-05-15 22:26:10 +02:00
|
|
|
|
gdb_py_ulongest pc_llu;
|
2013-02-28 20:23:57 +01:00
|
|
|
|
volatile struct gdb_exception except;
|
2013-02-28 21:01:10 +01:00
|
|
|
|
PyObject *result = NULL; /* init for gcc -Wall */
|
2012-05-13 13:33:44 +02:00
|
|
|
|
|
|
|
|
|
if (!PyArg_ParseTuple (args, GDB_PY_LLU_ARG, &pc_llu))
|
|
|
|
|
return NULL;
|
|
|
|
|
|
2013-02-28 20:23:57 +01:00
|
|
|
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
|
|
|
|
{
|
|
|
|
|
struct symtab_and_line sal;
|
|
|
|
|
CORE_ADDR pc;
|
|
|
|
|
|
|
|
|
|
pc = (CORE_ADDR) pc_llu;
|
|
|
|
|
sal = find_pc_line (pc, 0);
|
|
|
|
|
result = symtab_and_line_to_sal_object (sal);
|
|
|
|
|
}
|
|
|
|
|
GDB_PY_HANDLE_EXCEPTION (except);
|
|
|
|
|
|
|
|
|
|
return result;
|
2012-05-13 13:33:44 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-10-27 17:46:11 +02:00
|
|
|
|
/* Read a file as Python code.
|
2012-01-26 22:54:45 +01:00
|
|
|
|
FILE is the file to run. FILENAME is name of the file FILE.
|
2011-10-27 17:46:11 +02:00
|
|
|
|
This does not throw any errors. If an exception occurs python will print
|
|
|
|
|
the traceback and clear the error indicator. */
|
2010-01-18 07:25:22 +01:00
|
|
|
|
|
|
|
|
|
void
|
2012-01-26 22:54:45 +01:00
|
|
|
|
source_python_script (FILE *file, const char *filename)
|
2010-01-18 07:25:22 +01:00
|
|
|
|
{
|
2010-04-08 06:57:25 +02:00
|
|
|
|
struct cleanup *cleanup;
|
2010-01-18 07:25:22 +01:00
|
|
|
|
|
2010-04-08 06:57:25 +02:00
|
|
|
|
cleanup = ensure_python_env (get_current_arch (), current_language);
|
2012-01-26 22:54:45 +01:00
|
|
|
|
python_run_simple_file (file, filename);
|
2010-04-08 06:57:25 +02:00
|
|
|
|
do_cleanups (cleanup);
|
2010-01-18 07:25:22 +01:00
|
|
|
|
}
|
|
|
|
|
|
2008-08-06 21:41:33 +02:00
|
|
|
|
|
|
|
|
|
|
2010-08-11 22:54:12 +02:00
|
|
|
|
/* Posting and handling events. */
|
|
|
|
|
|
|
|
|
|
/* A single event. */
|
|
|
|
|
struct gdbpy_event
|
|
|
|
|
{
|
|
|
|
|
/* The Python event. This is just a callable object. */
|
|
|
|
|
PyObject *event;
|
|
|
|
|
/* The next event. */
|
|
|
|
|
struct gdbpy_event *next;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* All pending events. */
|
|
|
|
|
static struct gdbpy_event *gdbpy_event_list;
|
|
|
|
|
/* The final link of the event list. */
|
|
|
|
|
static struct gdbpy_event **gdbpy_event_list_end;
|
|
|
|
|
|
|
|
|
|
/* We use a file handler, and not an async handler, so that we can
|
|
|
|
|
wake up the main thread even when it is blocked in poll(). */
|
2010-08-20 20:52:11 +02:00
|
|
|
|
static struct serial *gdbpy_event_fds[2];
|
2010-08-11 22:54:12 +02:00
|
|
|
|
|
|
|
|
|
/* The file handler callback. This reads from the internal pipe, and
|
|
|
|
|
then processes the Python event queue. This will always be run in
|
|
|
|
|
the main gdb thread. */
|
2010-08-20 20:52:11 +02:00
|
|
|
|
|
2010-08-11 22:54:12 +02:00
|
|
|
|
static void
|
2010-08-20 20:52:11 +02:00
|
|
|
|
gdbpy_run_events (struct serial *scb, void *context)
|
2010-08-11 22:54:12 +02:00
|
|
|
|
{
|
|
|
|
|
struct cleanup *cleanup;
|
|
|
|
|
|
|
|
|
|
cleanup = ensure_python_env (get_current_arch (), current_language);
|
|
|
|
|
|
2010-08-20 20:52:11 +02:00
|
|
|
|
/* Flush the fd. Do this before flushing the events list, so that
|
|
|
|
|
any new event post afterwards is sure to re-awake the event
|
|
|
|
|
loop. */
|
|
|
|
|
while (serial_readchar (gdbpy_event_fds[0], 0) >= 0)
|
|
|
|
|
;
|
2010-08-11 22:54:12 +02:00
|
|
|
|
|
|
|
|
|
while (gdbpy_event_list)
|
|
|
|
|
{
|
|
|
|
|
/* Dispatching the event might push a new element onto the event
|
|
|
|
|
loop, so we update here "atomically enough". */
|
|
|
|
|
struct gdbpy_event *item = gdbpy_event_list;
|
|
|
|
|
gdbpy_event_list = gdbpy_event_list->next;
|
|
|
|
|
if (gdbpy_event_list == NULL)
|
|
|
|
|
gdbpy_event_list_end = &gdbpy_event_list;
|
|
|
|
|
|
|
|
|
|
/* Ignore errors. */
|
|
|
|
|
if (PyObject_CallObject (item->event, NULL) == NULL)
|
|
|
|
|
PyErr_Clear ();
|
|
|
|
|
|
|
|
|
|
Py_DECREF (item->event);
|
|
|
|
|
xfree (item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
do_cleanups (cleanup);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Submit an event to the gdb thread. */
|
|
|
|
|
static PyObject *
|
|
|
|
|
gdbpy_post_event (PyObject *self, PyObject *args)
|
|
|
|
|
{
|
|
|
|
|
struct gdbpy_event *event;
|
|
|
|
|
PyObject *func;
|
|
|
|
|
int wakeup;
|
|
|
|
|
|
|
|
|
|
if (!PyArg_ParseTuple (args, "O", &func))
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
if (!PyCallable_Check (func))
|
|
|
|
|
{
|
|
|
|
|
PyErr_SetString (PyExc_RuntimeError,
|
|
|
|
|
_("Posted event is not callable"));
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Py_INCREF (func);
|
|
|
|
|
|
|
|
|
|
/* From here until the end of the function, we have the GIL, so we
|
|
|
|
|
can operate on our global data structures without worrying. */
|
|
|
|
|
wakeup = gdbpy_event_list == NULL;
|
|
|
|
|
|
|
|
|
|
event = XNEW (struct gdbpy_event);
|
|
|
|
|
event->event = func;
|
|
|
|
|
event->next = NULL;
|
|
|
|
|
*gdbpy_event_list_end = event;
|
|
|
|
|
gdbpy_event_list_end = &event->next;
|
|
|
|
|
|
|
|
|
|
/* Wake up gdb when needed. */
|
|
|
|
|
if (wakeup)
|
|
|
|
|
{
|
|
|
|
|
char c = 'q'; /* Anything. */
|
2010-08-20 20:52:11 +02:00
|
|
|
|
|
|
|
|
|
if (serial_write (gdbpy_event_fds[1], &c, 1))
|
2010-08-11 22:54:12 +02:00
|
|
|
|
return PyErr_SetFromErrno (PyExc_IOError);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Py_RETURN_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Initialize the Python event handler. */
|
|
|
|
|
static void
|
|
|
|
|
gdbpy_initialize_events (void)
|
|
|
|
|
{
|
2010-08-20 20:52:11 +02:00
|
|
|
|
if (serial_pipe (gdbpy_event_fds) == 0)
|
2010-08-11 22:54:12 +02:00
|
|
|
|
{
|
|
|
|
|
gdbpy_event_list_end = &gdbpy_event_list;
|
2010-08-20 20:52:11 +02:00
|
|
|
|
serial_async (gdbpy_event_fds[0], gdbpy_run_events, NULL);
|
2010-08-11 22:54:12 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-21 13:03:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
before_prompt_hook (const char *current_gdb_prompt)
|
|
|
|
|
{
|
|
|
|
|
struct cleanup *cleanup;
|
|
|
|
|
char *prompt = NULL;
|
|
|
|
|
|
|
|
|
|
cleanup = ensure_python_env (get_current_arch (), current_language);
|
|
|
|
|
|
Refactor Python "gdb" module into a proper Python package, by introducing
a new "_gdb" module for code implemented in C, and using reload/__import__
instead of exec.
gdb/
* python/lib/gdb/__init__.py: Import * from _gdb.
(GdbOutputFile, sys.stdout, GdbOutputErrorFile, sys.stderr,
prompt_hook, sys.argv): Moved from finish_python_initialization.
(pretty_printers, PYTHONDIR): Moved from _initialize_python.
(packages, auto_load_packages): New list and function replacing
module_dict and auto-loading code, using __file__ instead of
gdb.PYTHONDIR and reload/__import__ instead of exec.
(GdbSetPythonDirectory): Replacing function of the same name
from finish_python_initialization, using reload/__import__ instead
of exec, as well as call auto_load_packages.
* python/py-prettyprint.c (find_pretty_printer_from_gdb): Check
gdb_python_module and not gdb_module.
* python/python-internal.h (gdb_python_module): Declare.
* python/python.c (gdb_python_module): New global.
(before_prompt_hook): Check gdb_python_module and not gdb_module.
(_initialize_python): Rename gdb module to _gdb.
Move gdb.PYTHONDIR and gdb.pretty_printer to lib/gdb/__init__.py.
(finish_python_initialization): Move Python code to
lib/gdb/__init__.py; instead, set up sys.path and import gdb into
__main__.
gdb/testsuite/
* gdb.python/python.exp (Test stderr location): Update module
location of GDB-specific sys.stderr.
(Test stdout location): Ditto for sys.stdout.
2012-09-13 23:49:32 +02:00
|
|
|
|
if (gdb_python_module
|
|
|
|
|
&& PyObject_HasAttrString (gdb_python_module, "prompt_hook"))
|
2011-07-21 13:03:48 +02:00
|
|
|
|
{
|
|
|
|
|
PyObject *hook;
|
|
|
|
|
|
Refactor Python "gdb" module into a proper Python package, by introducing
a new "_gdb" module for code implemented in C, and using reload/__import__
instead of exec.
gdb/
* python/lib/gdb/__init__.py: Import * from _gdb.
(GdbOutputFile, sys.stdout, GdbOutputErrorFile, sys.stderr,
prompt_hook, sys.argv): Moved from finish_python_initialization.
(pretty_printers, PYTHONDIR): Moved from _initialize_python.
(packages, auto_load_packages): New list and function replacing
module_dict and auto-loading code, using __file__ instead of
gdb.PYTHONDIR and reload/__import__ instead of exec.
(GdbSetPythonDirectory): Replacing function of the same name
from finish_python_initialization, using reload/__import__ instead
of exec, as well as call auto_load_packages.
* python/py-prettyprint.c (find_pretty_printer_from_gdb): Check
gdb_python_module and not gdb_module.
* python/python-internal.h (gdb_python_module): Declare.
* python/python.c (gdb_python_module): New global.
(before_prompt_hook): Check gdb_python_module and not gdb_module.
(_initialize_python): Rename gdb module to _gdb.
Move gdb.PYTHONDIR and gdb.pretty_printer to lib/gdb/__init__.py.
(finish_python_initialization): Move Python code to
lib/gdb/__init__.py; instead, set up sys.path and import gdb into
__main__.
gdb/testsuite/
* gdb.python/python.exp (Test stderr location): Update module
location of GDB-specific sys.stderr.
(Test stdout location): Ditto for sys.stdout.
2012-09-13 23:49:32 +02:00
|
|
|
|
hook = PyObject_GetAttrString (gdb_python_module, "prompt_hook");
|
2011-07-21 13:03:48 +02:00
|
|
|
|
if (hook == NULL)
|
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
|
|
if (PyCallable_Check (hook))
|
|
|
|
|
{
|
|
|
|
|
PyObject *result;
|
|
|
|
|
PyObject *current_prompt;
|
|
|
|
|
|
|
|
|
|
current_prompt = PyString_FromString (current_gdb_prompt);
|
|
|
|
|
if (current_prompt == NULL)
|
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
|
|
result = PyObject_CallFunctionObjArgs (hook, current_prompt, NULL);
|
|
|
|
|
|
|
|
|
|
Py_DECREF (current_prompt);
|
|
|
|
|
|
|
|
|
|
if (result == NULL)
|
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
|
|
make_cleanup_py_decref (result);
|
|
|
|
|
|
|
|
|
|
/* Return type should be None, or a String. If it is None,
|
|
|
|
|
fall through, we will not set a prompt. If it is a
|
|
|
|
|
string, set PROMPT. Anything else, set an exception. */
|
|
|
|
|
if (result != Py_None && ! PyString_Check (result))
|
|
|
|
|
{
|
|
|
|
|
PyErr_Format (PyExc_RuntimeError,
|
|
|
|
|
_("Return from prompt_hook must " \
|
|
|
|
|
"be either a Python string, or None"));
|
|
|
|
|
goto fail;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (result != Py_None)
|
|
|
|
|
{
|
|
|
|
|
prompt = python_string_to_host_string (result);
|
|
|
|
|
|
|
|
|
|
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)
|
2011-09-06 Pedro Alves <pedro@codesourcery.com>
* event-top.h (MAXPROMPTS, struct prompts): Delete.
(set_async_annotation_level, set_async_prompt, pop_prompt)
(push_prompt, new_async_prompt): Delete declarations.
* top.h (get_prompt, set_prompt): Change prototype.
(get_prefix, set_prefix, get_suffix, set_suffix): Delete
declarations.
* top.c (command_loop):
(top_prompt): New global.
(get_prefix, set_prefix, get_suffix, ): Delete.
(get_prompt, set_prompt): Rewrite.
(show_new_async_prompt): Rename to ...
(show_prompt): ... this.
(init_main): Adjust. Don't handle --annotate=2 here.
* event-top.c (new_async_prompt): Delete.
(the_prompts): Delete.
(more_to_come): Make static.
(display_gdb_prompt): Use top_level_prompt() to compute the top
level prompt, and don't notify the before_prompt observers
directly here. Always trick readline into not trying to display
the prompt if sync_execution and displaying the primary prompt.
If displaying a local/secondary prompt, always show it, even if
sync_execution is set.
(change_annotation_level): Delete.
(top_level_prompt): New, based on change_annotation_level.
(push_prompt, pop_prompt): Delete.
(async_disable_stdin): No longer pushes prompt.
(command_line_handler): No longer pushes or pops prompt. If more
input is expected, call display_gdb_prompt with an explicit empty
prompt.
(async_stop_sig): Adjust.
(set_async_annotation_level, set_async_prompt): Delete.
* python/python.c (before_prompt_hook): Adjust.
2011-09-06 16:49:00 +02:00
|
|
|
|
set_prompt (prompt);
|
2011-07-21 13:03:48 +02:00
|
|
|
|
|
|
|
|
|
do_cleanups (cleanup);
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
fail:
|
|
|
|
|
gdbpy_print_stack ();
|
|
|
|
|
do_cleanups (cleanup);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-08-06 21:41:33 +02:00
|
|
|
|
/* Printing. */
|
|
|
|
|
|
|
|
|
|
/* A python function to write a single string using gdb's filtered
|
2011-03-18 09:44:47 +01:00
|
|
|
|
output stream . The optional keyword STREAM can be used to write
|
|
|
|
|
to a particular stream. The default stream is to gdb_stdout. */
|
|
|
|
|
|
2008-08-06 21:41:33 +02:00
|
|
|
|
static PyObject *
|
2011-03-18 09:44:47 +01:00
|
|
|
|
gdbpy_write (PyObject *self, PyObject *args, PyObject *kw)
|
2008-08-06 21:41:33 +02:00
|
|
|
|
{
|
2011-06-24 21:47:37 +02:00
|
|
|
|
const char *arg;
|
2011-03-18 09:44:47 +01:00
|
|
|
|
static char *keywords[] = {"text", "stream", NULL };
|
|
|
|
|
int stream_type = 0;
|
2012-06-25 18:53:20 +02:00
|
|
|
|
volatile struct gdb_exception except;
|
2011-03-18 09:44:47 +01:00
|
|
|
|
|
|
|
|
|
if (! PyArg_ParseTupleAndKeywords (args, kw, "s|i", keywords, &arg,
|
|
|
|
|
&stream_type))
|
2008-08-06 21:41:33 +02:00
|
|
|
|
return NULL;
|
2011-03-18 09:44:47 +01:00
|
|
|
|
|
2012-06-25 18:53:20 +02:00
|
|
|
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
2011-03-18 09:44:47 +01:00
|
|
|
|
{
|
2012-06-25 18:53:20 +02:00
|
|
|
|
switch (stream_type)
|
|
|
|
|
{
|
|
|
|
|
case 1:
|
|
|
|
|
{
|
|
|
|
|
fprintf_filtered (gdb_stderr, "%s", arg);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case 2:
|
|
|
|
|
{
|
|
|
|
|
fprintf_filtered (gdb_stdlog, "%s", arg);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
fprintf_filtered (gdb_stdout, "%s", arg);
|
|
|
|
|
}
|
2011-03-18 09:44:47 +01:00
|
|
|
|
}
|
2012-06-25 18:53:20 +02:00
|
|
|
|
GDB_PY_HANDLE_EXCEPTION (except);
|
2011-03-18 09:44:47 +01:00
|
|
|
|
|
2008-08-06 21:41:33 +02:00
|
|
|
|
Py_RETURN_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-18 09:44:47 +01:00
|
|
|
|
/* A python function to flush a gdb stream. The optional keyword
|
|
|
|
|
STREAM can be used to flush a particular stream. The default stream
|
|
|
|
|
is gdb_stdout. */
|
|
|
|
|
|
2008-08-06 21:41:33 +02:00
|
|
|
|
static PyObject *
|
2011-03-18 09:44:47 +01:00
|
|
|
|
gdbpy_flush (PyObject *self, PyObject *args, PyObject *kw)
|
2008-08-06 21:41:33 +02:00
|
|
|
|
{
|
2011-03-18 09:44:47 +01:00
|
|
|
|
static char *keywords[] = {"stream", NULL };
|
|
|
|
|
int stream_type = 0;
|
|
|
|
|
|
|
|
|
|
if (! PyArg_ParseTupleAndKeywords (args, kw, "|i", keywords,
|
|
|
|
|
&stream_type))
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
switch (stream_type)
|
|
|
|
|
{
|
|
|
|
|
case 1:
|
|
|
|
|
{
|
|
|
|
|
gdb_flush (gdb_stderr);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case 2:
|
|
|
|
|
{
|
|
|
|
|
gdb_flush (gdb_stdlog);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
gdb_flush (gdb_stdout);
|
|
|
|
|
}
|
|
|
|
|
|
2008-08-06 21:41:33 +02:00
|
|
|
|
Py_RETURN_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-16 16:55:40 +01:00
|
|
|
|
/* Print a python exception trace, print just a message, or print
|
|
|
|
|
nothing and clear the python exception, depending on
|
|
|
|
|
gdbpy_should_print_stack. Only call this if a python exception is
|
|
|
|
|
set. */
|
2008-08-06 21:41:33 +02:00
|
|
|
|
void
|
|
|
|
|
gdbpy_print_stack (void)
|
|
|
|
|
{
|
2013-02-28 20:25:42 +01:00
|
|
|
|
volatile struct gdb_exception except;
|
|
|
|
|
|
2011-12-16 16:55:40 +01:00
|
|
|
|
/* Print "none", just clear exception. */
|
|
|
|
|
if (gdbpy_should_print_stack == python_excp_none)
|
|
|
|
|
{
|
|
|
|
|
PyErr_Clear ();
|
|
|
|
|
}
|
|
|
|
|
/* Print "full" message and backtrace. */
|
|
|
|
|
else if (gdbpy_should_print_stack == python_excp_full)
|
2010-05-20 01:32:24 +02:00
|
|
|
|
{
|
|
|
|
|
PyErr_Print ();
|
|
|
|
|
/* PyErr_Print doesn't necessarily end output with a newline.
|
|
|
|
|
This works because Python's stdout/stderr is fed through
|
|
|
|
|
printf_filtered. */
|
2013-02-28 20:25:42 +01:00
|
|
|
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
|
|
|
|
{
|
|
|
|
|
begin_line ();
|
|
|
|
|
}
|
2010-05-20 01:32:24 +02:00
|
|
|
|
}
|
2011-12-16 16:55:40 +01:00
|
|
|
|
/* Print "message", just error print message. */
|
2008-08-06 21:41:33 +02:00
|
|
|
|
else
|
2011-12-16 16:55:40 +01:00
|
|
|
|
{
|
|
|
|
|
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);
|
2013-02-28 20:25:42 +01:00
|
|
|
|
|
|
|
|
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
2011-12-16 16:55:40 +01:00
|
|
|
|
{
|
2013-02-28 20:25:42 +01:00
|
|
|
|
if (msg == NULL)
|
|
|
|
|
{
|
|
|
|
|
/* An error occurred computing the string representation of the
|
|
|
|
|
error message. */
|
|
|
|
|
fprintf_filtered (gdb_stderr,
|
|
|
|
|
_("Error occurred computing Python error" \
|
|
|
|
|
"message.\n"));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
fprintf_filtered (gdb_stderr, "Python Exception %s %s: \n",
|
|
|
|
|
type, msg);
|
2011-12-16 16:55:40 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Py_XDECREF (ptype);
|
|
|
|
|
Py_XDECREF (pvalue);
|
|
|
|
|
Py_XDECREF (ptraceback);
|
|
|
|
|
xfree (msg);
|
|
|
|
|
}
|
2008-08-06 21:41:33 +02:00
|
|
|
|
}
|
|
|
|
|
|
2009-05-28 02:40:24 +02:00
|
|
|
|
|
|
|
|
|
|
2010-04-15 21:54:13 +02:00
|
|
|
|
/* Return the current Progspace.
|
|
|
|
|
There always is one. */
|
|
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
|
gdbpy_get_current_progspace (PyObject *unused1, PyObject *unused2)
|
|
|
|
|
{
|
|
|
|
|
PyObject *result;
|
|
|
|
|
|
|
|
|
|
result = pspace_to_pspace_object (current_program_space);
|
|
|
|
|
if (result)
|
|
|
|
|
Py_INCREF (result);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Return a sequence holding all the Progspaces. */
|
|
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
|
gdbpy_progspaces (PyObject *unused1, PyObject *unused2)
|
|
|
|
|
{
|
|
|
|
|
struct program_space *ps;
|
|
|
|
|
PyObject *list;
|
|
|
|
|
|
|
|
|
|
list = PyList_New (0);
|
|
|
|
|
if (!list)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
ALL_PSPACES (ps)
|
|
|
|
|
{
|
|
|
|
|
PyObject *item = pspace_to_pspace_object (ps);
|
2010-05-17 23:23:25 +02:00
|
|
|
|
|
2010-04-15 21:54:13 +02:00
|
|
|
|
if (!item || PyList_Append (list, item) == -1)
|
|
|
|
|
{
|
|
|
|
|
Py_DECREF (list);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-05-28 02:40:24 +02:00
|
|
|
|
/* The "current" objfile. This is set when gdb detects that a new
|
2010-04-23 18:20:13 +02:00
|
|
|
|
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. */
|
2009-05-28 02:40:24 +02:00
|
|
|
|
static struct objfile *gdbpy_current_objfile;
|
|
|
|
|
|
2012-01-26 22:54:45 +01:00
|
|
|
|
/* 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. */
|
2009-05-28 02:40:24 +02:00
|
|
|
|
|
2010-04-23 18:20:13 +02:00
|
|
|
|
void
|
2012-01-26 22:54:45 +01:00
|
|
|
|
source_python_script_for_objfile (struct objfile *objfile, FILE *file,
|
|
|
|
|
const char *filename)
|
2009-05-28 02:40:24 +02:00
|
|
|
|
{
|
|
|
|
|
struct cleanup *cleanups;
|
|
|
|
|
|
* python/python-internal.h (struct language_defn): Declare.
(python_gdbarch, python_language): Likewise.
(ensure_python_env): Add prototype.
(make_cleanup_py_restore_gil): Remove prototype.
* python/python.c: Include "arch-utils.h", "value.h" and "language.h".
(python_gdbarch, python_language): New global variables.
(struct python_env): New data type.
(ensure_python_env, restore_python_env): New functions.
(eval_python_from_control_command): Call ensure_python_env to
install current architecture and language.
(python_command, gdbpy_new_objfile): Likewise.
* python/python-cmd.c: Include "arch-utils.h" and "language.h".
(cmdpy_destroyer, cmdpy_function, cmdpy_completer): Call
ensure_python_env.
* python/python-type.c (clean_up_objfile_types): Likewise.
* python/python-objfile.c: Include "language.h".
(clean_up_objfile): Call ensure_python_env.
* python/python-prettyprint.c (apply_val_pretty_printer): Likewise.
(apply_varobj_pretty_printer): Do not call PyGILState_Ensure.
* varobj.c (varobj_ensure_python_env): New helper function.
(varobj_get_display_hint, update_dynamic_varobj_children,
install_default_visualizer, varobj_set_visualizer, free_variable,
value_get_print_value): Call it.
(value_get_print_value): Add varobj argument instead of pretty
printer argument. Update all callers.
* python/python-utils.c (py_gil_restore, make_cleanup_py_restore_gil):
Remove.
* value.h (internal_function_fn): Add GDBARCH and LANGUAGE argument.
(call_internal_function): Likewise.
* value.c (call_internal_function): Likewise. Pass to handler.
* eval.c (evaluate_subexp_standard): Update call.
* python/python-function.c: Include "language.h".
(fnpy_call): Add GDBARCH and LANGAUAGE arguments and call
make_cleanup_python_env.
* python/python-value.c (builtin_type_pyint, builtin_type_pyfloat,
builtin_type_pylong, builtin_type_pybool, builtin_type_pychar,
valpy_str): Use python_gdbarch and python_language instead of
current_gdbarch and current_language.
* python/python-type.c (typy_lookup_typename): Likewise.
2009-07-02 19:04:23 +02:00
|
|
|
|
cleanups = ensure_python_env (get_objfile_arch (objfile), current_language);
|
2009-05-28 02:40:24 +02:00
|
|
|
|
gdbpy_current_objfile = objfile;
|
|
|
|
|
|
2012-01-26 22:54:45 +01:00
|
|
|
|
python_run_simple_file (file, filename);
|
2009-05-28 02:40:24 +02:00
|
|
|
|
|
|
|
|
|
do_cleanups (cleanups);
|
|
|
|
|
gdbpy_current_objfile = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Return the current Objfile, or None if there isn't one. */
|
2010-04-23 18:20:13 +02:00
|
|
|
|
|
2009-05-28 02:40:24 +02:00
|
|
|
|
static PyObject *
|
|
|
|
|
gdbpy_get_current_objfile (PyObject *unused1, PyObject *unused2)
|
|
|
|
|
{
|
|
|
|
|
PyObject *result;
|
|
|
|
|
|
|
|
|
|
if (! gdbpy_current_objfile)
|
|
|
|
|
Py_RETURN_NONE;
|
|
|
|
|
|
|
|
|
|
result = objfile_to_objfile_object (gdbpy_current_objfile);
|
|
|
|
|
if (result)
|
|
|
|
|
Py_INCREF (result);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Return a sequence holding all the Objfiles. */
|
2010-04-15 21:54:13 +02:00
|
|
|
|
|
2009-05-28 02:40:24 +02:00
|
|
|
|
static PyObject *
|
|
|
|
|
gdbpy_objfiles (PyObject *unused1, PyObject *unused2)
|
|
|
|
|
{
|
|
|
|
|
struct objfile *objf;
|
|
|
|
|
PyObject *list;
|
|
|
|
|
|
|
|
|
|
list = PyList_New (0);
|
|
|
|
|
if (!list)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
ALL_OBJFILES (objf)
|
|
|
|
|
{
|
|
|
|
|
PyObject *item = objfile_to_objfile_object (objf);
|
2010-05-17 23:23:25 +02:00
|
|
|
|
|
2009-05-28 02:40:24 +02:00
|
|
|
|
if (!item || PyList_Append (list, item) == -1)
|
|
|
|
|
{
|
|
|
|
|
Py_DECREF (list);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
* NEWS: Update.
* data-directory/Makefile.in (PYTHON_FILES): Add
type_printers.py.
* python/lib/gdb/command/type_printers.py: New file.
* python/lib/gdb/command/types.py (TypePrinter): New class.
(_get_some_type_recognizers, get_type_recognizers,
apply_type_recognizers, register_type_printer): New
functions.
* python/py-objfile.c (objfile_object) <type_printers>: New
field.
(objfpy_dealloc): Decref new field.
(objfpy_new): Set new field.
(objfpy_get_type_printers, objfpy_set_type_printers): New
functions.
(objfile_to_objfile_object): Set new field.
(objfile_getset): Add "type_printers".
* python/py-progspace.c (pspace_object) <type_printers>: New
field.
(pspy_dealloc): Decref new field.
(pspy_new): Set new field.
(pspy_get_type_printers, pspy_set_type_printers): New functions.
(pspace_to_pspace_object): Set new field.
(pspace_getset): Add "type_printers".
* python/python.c (start_type_printers, apply_type_printers,
free_type_printers): New functions.
(_initialize_python): Set gdb.type_printers.
* python/python.h (start_type_printers, apply_type_printers,
free_type_printers): Declare.
* typeprint.c (type_print_raw_options, default_ptype_flags):
Update for new fields.
(do_free_global_table, create_global_typedef_table,
find_global_typedef): New functions.
(find_typedef_in_hash): Use find_global_typedef.
(whatis_exp): Use create_global_typedef_table. Change cleanup
handling.
* typeprint.h (struct type_print_options) <global_typedefs,
global_printers>: New fields.
doc
* gdb.texinfo (Symbols): Document "info type-printers",
"enable type-printer" and "disable type-printer".
(Python API): Add new node to menu.
(Type Printing API): New node.
(Progspaces In Python): Document type_printers field.
(Objfiles In Python): Likewise.
(gdb.types) <get_type_recognizers, apply_type_recognizers,
register_type_printer, TypePrinter>: Document.
testsuite
* gdb.base/completion.exp: Update for "info type-printers".
* gdb.python/py-typeprint.cc: New file.
* gdb.python/py-typeprint.exp: New file.
* gdb.python/py-typeprint.py: New file.
2012-11-12 18:41:59 +01:00
|
|
|
|
/* 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. */
|
|
|
|
|
|
|
|
|
|
void *
|
|
|
|
|
start_type_printers (void)
|
|
|
|
|
{
|
|
|
|
|
struct cleanup *cleanups;
|
2012-11-12 20:24:14 +01:00
|
|
|
|
PyObject *type_module, *func, *result_obj = NULL;
|
* NEWS: Update.
* data-directory/Makefile.in (PYTHON_FILES): Add
type_printers.py.
* python/lib/gdb/command/type_printers.py: New file.
* python/lib/gdb/command/types.py (TypePrinter): New class.
(_get_some_type_recognizers, get_type_recognizers,
apply_type_recognizers, register_type_printer): New
functions.
* python/py-objfile.c (objfile_object) <type_printers>: New
field.
(objfpy_dealloc): Decref new field.
(objfpy_new): Set new field.
(objfpy_get_type_printers, objfpy_set_type_printers): New
functions.
(objfile_to_objfile_object): Set new field.
(objfile_getset): Add "type_printers".
* python/py-progspace.c (pspace_object) <type_printers>: New
field.
(pspy_dealloc): Decref new field.
(pspy_new): Set new field.
(pspy_get_type_printers, pspy_set_type_printers): New functions.
(pspace_to_pspace_object): Set new field.
(pspace_getset): Add "type_printers".
* python/python.c (start_type_printers, apply_type_printers,
free_type_printers): New functions.
(_initialize_python): Set gdb.type_printers.
* python/python.h (start_type_printers, apply_type_printers,
free_type_printers): Declare.
* typeprint.c (type_print_raw_options, default_ptype_flags):
Update for new fields.
(do_free_global_table, create_global_typedef_table,
find_global_typedef): New functions.
(find_typedef_in_hash): Use find_global_typedef.
(whatis_exp): Use create_global_typedef_table. Change cleanup
handling.
* typeprint.h (struct type_print_options) <global_typedefs,
global_printers>: New fields.
doc
* gdb.texinfo (Symbols): Document "info type-printers",
"enable type-printer" and "disable type-printer".
(Python API): Add new node to menu.
(Type Printing API): New node.
(Progspaces In Python): Document type_printers field.
(Objfiles In Python): Likewise.
(gdb.types) <get_type_recognizers, apply_type_recognizers,
register_type_printer, TypePrinter>: Document.
testsuite
* gdb.base/completion.exp: Update for "info type-printers".
* gdb.python/py-typeprint.cc: New file.
* gdb.python/py-typeprint.exp: New file.
* gdb.python/py-typeprint.py: New file.
2012-11-12 18:41:59 +01:00
|
|
|
|
|
|
|
|
|
cleanups = ensure_python_env (get_current_arch (), current_language);
|
|
|
|
|
|
|
|
|
|
type_module = PyImport_ImportModule ("gdb.types");
|
|
|
|
|
if (type_module == NULL)
|
|
|
|
|
{
|
|
|
|
|
gdbpy_print_stack ();
|
|
|
|
|
goto done;
|
|
|
|
|
}
|
|
|
|
|
make_cleanup_py_decref (type_module);
|
|
|
|
|
|
|
|
|
|
func = PyObject_GetAttrString (type_module, "get_type_recognizers");
|
|
|
|
|
if (func == NULL)
|
|
|
|
|
{
|
|
|
|
|
gdbpy_print_stack ();
|
|
|
|
|
goto done;
|
|
|
|
|
}
|
|
|
|
|
make_cleanup_py_decref (func);
|
|
|
|
|
|
|
|
|
|
result_obj = PyObject_CallFunctionObjArgs (func, (char *) NULL);
|
|
|
|
|
if (result_obj == NULL)
|
|
|
|
|
gdbpy_print_stack ();
|
|
|
|
|
|
|
|
|
|
done:
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
struct cleanup *cleanups;
|
|
|
|
|
PyObject *type_obj, *type_module, *func, *result_obj;
|
|
|
|
|
PyObject *printers_obj = printers;
|
|
|
|
|
char *result = NULL;
|
|
|
|
|
|
|
|
|
|
if (printers_obj == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
cleanups = ensure_python_env (get_current_arch (), current_language);
|
|
|
|
|
|
|
|
|
|
type_obj = type_to_type_object (type);
|
|
|
|
|
if (type_obj == NULL)
|
|
|
|
|
{
|
|
|
|
|
gdbpy_print_stack ();
|
|
|
|
|
goto done;
|
|
|
|
|
}
|
|
|
|
|
make_cleanup_py_decref (type_obj);
|
|
|
|
|
|
|
|
|
|
type_module = PyImport_ImportModule ("gdb.types");
|
|
|
|
|
if (type_module == NULL)
|
|
|
|
|
{
|
|
|
|
|
gdbpy_print_stack ();
|
|
|
|
|
goto done;
|
|
|
|
|
}
|
|
|
|
|
make_cleanup_py_decref (type_module);
|
|
|
|
|
|
|
|
|
|
func = PyObject_GetAttrString (type_module, "apply_type_recognizers");
|
|
|
|
|
if (func == NULL)
|
|
|
|
|
{
|
|
|
|
|
gdbpy_print_stack ();
|
|
|
|
|
goto done;
|
|
|
|
|
}
|
|
|
|
|
make_cleanup_py_decref (func);
|
|
|
|
|
|
|
|
|
|
result_obj = PyObject_CallFunctionObjArgs (func, printers_obj,
|
|
|
|
|
type_obj, (char *) NULL);
|
|
|
|
|
if (result_obj == NULL)
|
|
|
|
|
{
|
|
|
|
|
gdbpy_print_stack ();
|
|
|
|
|
goto done;
|
|
|
|
|
}
|
|
|
|
|
make_cleanup_py_decref (result_obj);
|
|
|
|
|
|
|
|
|
|
if (result_obj != Py_None)
|
|
|
|
|
{
|
|
|
|
|
result = python_string_to_host_string (result_obj);
|
|
|
|
|
if (result == NULL)
|
|
|
|
|
gdbpy_print_stack ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
done:
|
|
|
|
|
do_cleanups (cleanups);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Free the result of start_type_printers. */
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
free_type_printers (void *arg)
|
|
|
|
|
{
|
|
|
|
|
struct cleanup *cleanups;
|
|
|
|
|
PyObject *printers = arg;
|
|
|
|
|
|
|
|
|
|
if (printers == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
cleanups = ensure_python_env (get_current_arch (), current_language);
|
|
|
|
|
Py_DECREF (printers);
|
|
|
|
|
do_cleanups (cleanups);
|
|
|
|
|
}
|
|
|
|
|
|
2008-08-06 21:41:33 +02:00
|
|
|
|
#else /* HAVE_PYTHON */
|
|
|
|
|
|
2012-08-22 21:15:15 +02:00
|
|
|
|
/* Dummy implementation of the gdb "python-interactive" and "python"
|
|
|
|
|
command. */
|
2008-08-06 21:41:33 +02:00
|
|
|
|
|
|
|
|
|
static void
|
2012-08-22 21:15:15 +02:00
|
|
|
|
python_interactive_command (char *arg, int from_tty)
|
2008-08-06 21:41:33 +02:00
|
|
|
|
{
|
2013-03-07 22:57:30 +01:00
|
|
|
|
arg = skip_spaces (arg);
|
2008-08-06 21:41:33 +02:00
|
|
|
|
if (arg && *arg)
|
|
|
|
|
error (_("Python scripting is not supported in this copy of GDB."));
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
struct command_line *l = get_command_line (python_control, "");
|
|
|
|
|
struct cleanup *cleanups = make_cleanup_free_command_lines (&l);
|
2010-05-17 23:23:25 +02:00
|
|
|
|
|
2008-08-06 21:41:33 +02:00
|
|
|
|
execute_control_command_untraced (l);
|
|
|
|
|
do_cleanups (cleanups);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-22 21:15:15 +02:00
|
|
|
|
static void
|
|
|
|
|
python_command (char *arg, int from_tty)
|
|
|
|
|
{
|
|
|
|
|
python_interactive_command (arg, from_tty);
|
|
|
|
|
}
|
|
|
|
|
|
2008-08-06 21:41:33 +02:00
|
|
|
|
void
|
|
|
|
|
eval_python_from_control_command (struct command_line *cmd)
|
|
|
|
|
{
|
|
|
|
|
error (_("Python scripting is not supported in this copy of GDB."));
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-18 07:25:22 +01:00
|
|
|
|
void
|
2012-01-26 22:54:45 +01:00
|
|
|
|
source_python_script (FILE *file, const char *filename)
|
2010-01-18 07:25:22 +01:00
|
|
|
|
{
|
|
|
|
|
throw_error (UNSUPPORTED_ERROR,
|
|
|
|
|
_("Python scripting is not supported in this copy of GDB."));
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-14 17:09:55 +01:00
|
|
|
|
int
|
|
|
|
|
gdbpy_should_stop (struct 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 breakpoint_object *bp_obj)
|
|
|
|
|
{
|
|
|
|
|
internal_error (__FILE__, __LINE__,
|
|
|
|
|
_("gdbpy_breakpoint_has_py_cond called when Python " \
|
|
|
|
|
"scripting is not supported."));
|
|
|
|
|
}
|
|
|
|
|
|
* NEWS: Update.
* data-directory/Makefile.in (PYTHON_FILES): Add
type_printers.py.
* python/lib/gdb/command/type_printers.py: New file.
* python/lib/gdb/command/types.py (TypePrinter): New class.
(_get_some_type_recognizers, get_type_recognizers,
apply_type_recognizers, register_type_printer): New
functions.
* python/py-objfile.c (objfile_object) <type_printers>: New
field.
(objfpy_dealloc): Decref new field.
(objfpy_new): Set new field.
(objfpy_get_type_printers, objfpy_set_type_printers): New
functions.
(objfile_to_objfile_object): Set new field.
(objfile_getset): Add "type_printers".
* python/py-progspace.c (pspace_object) <type_printers>: New
field.
(pspy_dealloc): Decref new field.
(pspy_new): Set new field.
(pspy_get_type_printers, pspy_set_type_printers): New functions.
(pspace_to_pspace_object): Set new field.
(pspace_getset): Add "type_printers".
* python/python.c (start_type_printers, apply_type_printers,
free_type_printers): New functions.
(_initialize_python): Set gdb.type_printers.
* python/python.h (start_type_printers, apply_type_printers,
free_type_printers): Declare.
* typeprint.c (type_print_raw_options, default_ptype_flags):
Update for new fields.
(do_free_global_table, create_global_typedef_table,
find_global_typedef): New functions.
(find_typedef_in_hash): Use find_global_typedef.
(whatis_exp): Use create_global_typedef_table. Change cleanup
handling.
* typeprint.h (struct type_print_options) <global_typedefs,
global_printers>: New fields.
doc
* gdb.texinfo (Symbols): Document "info type-printers",
"enable type-printer" and "disable type-printer".
(Python API): Add new node to menu.
(Type Printing API): New node.
(Progspaces In Python): Document type_printers field.
(Objfiles In Python): Likewise.
(gdb.types) <get_type_recognizers, apply_type_recognizers,
register_type_printer, TypePrinter>: Document.
testsuite
* gdb.base/completion.exp: Update for "info type-printers".
* gdb.python/py-typeprint.cc: New file.
* gdb.python/py-typeprint.exp: New file.
* gdb.python/py-typeprint.py: New file.
2012-11-12 18:41:59 +01:00
|
|
|
|
void *
|
|
|
|
|
start_type_printers (void)
|
|
|
|
|
{
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char *
|
|
|
|
|
apply_type_printers (void *ignore, struct type *type)
|
|
|
|
|
{
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
free_type_printers (void *arg)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2008-08-06 21:41:33 +02:00
|
|
|
|
#endif /* HAVE_PYTHON */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-07-11 15:07:38 +02:00
|
|
|
|
/* Lists for 'set python' commands. */
|
|
|
|
|
|
|
|
|
|
static struct cmd_list_element *user_set_python_list;
|
|
|
|
|
static struct cmd_list_element *user_show_python_list;
|
2008-08-06 21:41:33 +02:00
|
|
|
|
|
2011-07-11 15:07:38 +02:00
|
|
|
|
/* Function for use by 'set python' prefix command. */
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
user_set_python (char *args, int from_tty)
|
|
|
|
|
{
|
|
|
|
|
help_list (user_set_python_list, "set python ", all_commands,
|
|
|
|
|
gdb_stdout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Function for use by 'show python' prefix command. */
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
user_show_python (char *args, int from_tty)
|
2008-08-06 21:41:33 +02:00
|
|
|
|
{
|
2011-07-11 15:07:38 +02:00
|
|
|
|
cmd_show_list (user_show_python_list, from_tty, "");
|
2008-08-06 21:41:33 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Initialize the Python code. */
|
|
|
|
|
|
2012-09-21 14:57:34 +02:00
|
|
|
|
#ifdef HAVE_PYTHON
|
|
|
|
|
|
2012-09-20 22:54:11 +02:00
|
|
|
|
/* This is installed as a final cleanup and cleans up the
|
|
|
|
|
interpreter. This lets Python's 'atexit' work. */
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
finalize_python (void *ignore)
|
|
|
|
|
{
|
|
|
|
|
/* 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. */
|
2012-11-29 20:11:48 +01:00
|
|
|
|
(void) PyGILState_Ensure ();
|
* gdbarch.sh (target_gdbarch): Remove macro.
(get_target_gdbarch): Rename to target_gdbarch.
* gdbarch.c, gdbarch.h: Rebuild.
* ada-tasks.c, aix-thread.c, amd64-linux-nat.c, arch-utils.c,
arm-tdep.c, auxv.c, breakpoint.c, bsd-uthread.c, corefile.c,
darwin-nat-info.c, dcache.c, dsrec.c, exec.c, fbsd-nat.c,
filesystem.c, gcore.c, gnu-nat.c, i386-darwin-nat.c, i386-nat.c,
ia64-vms-tdep.c, inf-ptrace.c, infcmd.c, jit.c, linux-nat.c,
linux-tdep.c, linux-thread-db.c, m32r-rom.c, memattr.c,
mep-tdep.c, microblaze-tdep.c, mips-linux-nat.c,
mips-linux-tdep.c, mips-tdep.c, monitor.c, moxie-tdep.c,
nto-procfs.c, nto-tdep.c, ppc-linux-nat.c, proc-service.c,
procfs.c, progspace.c, ravenscar-thread.c, record.c,
remote-m32r-sdi.c, remote-mips.c, remote-sim.c, remote.c,
rl78-tdep.c, rs6000-nat.c, rx-tdep.c, s390-nat.c, sol-thread.c,
solib-darwin.c, solib-dsbt.c, solib-frv.c, solib-ia64-hpux.c,
solib-irix.c, solib-pa64.c, solib-som.c, solib-spu.c,
solib-sunos.c, solib-svr4.c, solib.c, spu-linux-nat.c,
spu-multiarch.c, spu-tdep.c, symfile-mem.c, symfile.c, symtab.c,
target-descriptions.c, target.c, target.h, tracepoint.c,
windows-nat.c, windows-tdep.c, xcoffsolib.c, cli/cli-dump.c,
common/agent.c, mi/mi-interp.c, python/py-finishbreakpoint.c,
python/py-inferior.c, python/python.c: Update.
2012-11-09 20:58:03 +01:00
|
|
|
|
python_gdbarch = target_gdbarch ();
|
2012-09-20 22:54:11 +02:00
|
|
|
|
python_language = current_language;
|
|
|
|
|
|
|
|
|
|
Py_Finalize ();
|
|
|
|
|
}
|
2012-09-21 14:57:34 +02:00
|
|
|
|
#endif
|
2012-09-20 22:54:11 +02:00
|
|
|
|
|
2008-02-21 Pedro Alves <pedro@codesorcery.com>
Silence a few -Wmissing-prototypes warnings.
PR build/9877:
* amd64-nat.c: Include "amd64-nat.h".
* fork-child.c (_initialize_fork_child): Ditto.
* gcore.c (_initialize_gcore): Ditto.
* inf-ptrace.c: Include "inf-ptrace.h".
(inf_ptrace_store_registers): Make it static.
* linux-nat.c (linux_nat_terminal_ours): Make it static.
(_initialize_linux_nat): Declare before definition.
* linux-tdep.c: Include "linux-tdep.h".
* linux-thread-db.c (_initialize_thread_db): Declare before
definition.
* proc-service.c (_initialize_proc_service): Ditto.
* remote.c (remote_send_printf): Make it static.
* solib.c: Include "solib.h".
* symfile-mem.c (_initialize_symfile_mem): Declare before
definition.
* ada-lang.c (ada_la_decode, ada_match_name)
(ada_suppress_symbol_printing, ada_is_array_type)
(ada_value_ptr_subscript, ada_array_length)
(ada_to_static_fixed_value): Make them static.
(_initialize_ada_language): Declare before definition.
* ada-tasks.c (ada_get_task_number, ada_get_environment_task)
(ada_task_list_changed, ada_new_objfile_observer): Make them
static.
(_initialize_tasks): Declare before definition.
* addrmap.c (_initialize_addrmap): Declare before definition.
* auxv.c (default_auxv_parse): Make it static.
* bfd-target.c (target_bfd_xfer_partial, target_bfd_xclose): Make
them static.
* breakpoint.c (remove_sal): Add line break.
(expand_line_sal_maybe): Make it static.
* cp-name-parser.y: Include "cp-support.h".
* cp-valprint.c (cp_find_class_member): Make it static.
* eval.c (value_f90_subarray): Ditto.
* exceptions.c (print_any_exception): Ditto.
* findcmd.c (_initialize_mem_search): Declare before definition.
* frame.c (frame_observer_target_changed): Make it static.
* gnu-v3-abi.c (gnuv3_find_method_in): Make it static.
* inf-child.c: Include "inf-child.h".
* inferior.h (valid_inferior_id): Rename to ...
(valid_gdb_inferior_id): ... this.
* infrun.c (infrun_thread_stop_requested, siginfo_make_value):
Make them static.
* jv-lang.c (java_language_arch_info): Make it static.
* m2-typeprint.c (m2_get_discrete_bounds): Ditto.
* osdata.c (info_osdata_command): Make it static.
* regcache.c (regcache_observer_target_changed): Make it static.
* reverse.c (_initialize_reverse): Declare before definition.
* stabsread.c (cleanup_undefined_types_noname)
(cleanup_undefined_types_1): Make them static.
* symfile.c (place_section): Make it static.
* symtab.c (find_pc_sect_psymtab_closer): Make it static.
* target-descriptions.c (_initialize_target_descriptions): Declare
before definition.
* target.c (default_get_ada_task_ptid, find_default_can_async_p)
(find_default_is_async_p, find_default_supports_non_stop): Make
them static.
(target_supports_non_stop): Add prototype.
(dummy_pid_to_str): Make it static.
* utils.c (_initialize_utils): Declare before definition.
* ada-exp.y (_initialize_ada_exp): Declare before definition.
* solib-svr4.c (HAS_LM_DYNAMIC_FROM_LINK_MAP): Add a prototype.
* target.h (struct target_ops): Add a prototype to the
to_can_execute_reverse callback.
* macroscope.c (_initialize_macroscope): Declare before definition.
* cp-namespace.c (_initialize_cp_namespace): Declare before definition.
* python/python.c (_initialize_python): Declare before definition.
* tui/tui-command.c: Include "tui/tui-command.h".
* tui/tui-data.c (init_content_element, init_win_info): Make them
static.
* tui/tui-disasm.c: Include "tui/tui-disasm.h".
* tui/tui-interp.c (_initialize_tui_interp): Declare before
definition.
* tui/tui-layout.c: Include "tui/tui-layout.h".
(_initialize_tui_layout): Declare before definition.
* tui/tui-regs.c: Include "tui/tui-regs.h".
(tui_display_reg_element_at_line): Make it static.
(_initialize_tui_regs): Declare before definition.
* tui/tui-stack.c (_initialize_tui_stack): Declare before
definition.
* tui/tui-win.c: Include "tui/tui-win.h".
(_initialize_tui_win): Declare before definition.
(tui_sigwinch_handler): Make it static. Wrap in ifdef SIGWINCH.
* tui/tui-win.h (tui_sigwinch_handler): Delete declaration.
(tui_get_cmd_list): Add a prototype.
* tui/tui-windata.c: Include tui-windata.h.
* tui/tui-wingeneral.c (box_win): Make it static.
* cli/cli-logging.c (show_logging_command): Make it static.
(_initialize_cli_logging): Declare before definition.
* mi/mi-common.c (_initialize_gdb_mi_common): Declare before
definition.
2009-02-21 17:14:50 +01:00
|
|
|
|
/* Provide a prototype to silence -Wmissing-prototypes. */
|
|
|
|
|
extern initialize_file_ftype _initialize_python;
|
|
|
|
|
|
2008-08-06 21:41:33 +02:00
|
|
|
|
void
|
|
|
|
|
_initialize_python (void)
|
|
|
|
|
{
|
2012-12-12 17:47:30 +01:00
|
|
|
|
char *progname;
|
|
|
|
|
#ifdef IS_PY3K
|
|
|
|
|
int i;
|
|
|
|
|
size_t progsize, count;
|
|
|
|
|
char *oldloc;
|
|
|
|
|
wchar_t *progname_copy;
|
|
|
|
|
#endif
|
2011-07-11 15:07:38 +02:00
|
|
|
|
|
2012-08-22 21:15:15 +02:00
|
|
|
|
add_com ("python-interactive", class_obscure,
|
|
|
|
|
python_interactive_command,
|
|
|
|
|
#ifdef HAVE_PYTHON
|
|
|
|
|
_("\
|
2012-08-23 20:55:25 +02:00
|
|
|
|
Start an interactive Python prompt.\n\
|
|
|
|
|
\n\
|
|
|
|
|
To return to GDB, type the EOF character (e.g., Ctrl-D on an empty\n\
|
|
|
|
|
prompt).\n\
|
2012-08-22 21:15:15 +02:00
|
|
|
|
\n\
|
|
|
|
|
Alternatively, a single-line Python command can be given as an\n\
|
|
|
|
|
argument, and if the command is an expression, the result will be\n\
|
|
|
|
|
printed. For example:\n\
|
|
|
|
|
\n\
|
|
|
|
|
(gdb) python-interactive 2 + 3\n\
|
|
|
|
|
5\n\
|
|
|
|
|
")
|
|
|
|
|
#else /* HAVE_PYTHON */
|
|
|
|
|
_("\
|
|
|
|
|
Start a Python interactive prompt.\n\
|
|
|
|
|
\n\
|
|
|
|
|
Python scripting is not supported in this copy of GDB.\n\
|
|
|
|
|
This command is only a placeholder.")
|
|
|
|
|
#endif /* HAVE_PYTHON */
|
|
|
|
|
);
|
|
|
|
|
add_com_alias ("pi", "python-interactive", class_obscure, 1);
|
|
|
|
|
|
2008-08-06 21:41:33 +02:00
|
|
|
|
add_com ("python", class_obscure, python_command,
|
|
|
|
|
#ifdef HAVE_PYTHON
|
|
|
|
|
_("\
|
|
|
|
|
Evaluate a Python command.\n\
|
|
|
|
|
\n\
|
|
|
|
|
The command can be given as an argument, for instance:\n\
|
|
|
|
|
\n\
|
|
|
|
|
python print 23\n\
|
|
|
|
|
\n\
|
|
|
|
|
If no argument is given, the following lines are read and used\n\
|
|
|
|
|
as the Python commands. Type a line containing \"end\" to indicate\n\
|
|
|
|
|
the end of the command.")
|
|
|
|
|
#else /* HAVE_PYTHON */
|
|
|
|
|
_("\
|
|
|
|
|
Evaluate a Python command.\n\
|
|
|
|
|
\n\
|
|
|
|
|
Python scripting is not supported in this copy of GDB.\n\
|
|
|
|
|
This command is only a placeholder.")
|
|
|
|
|
#endif /* HAVE_PYTHON */
|
|
|
|
|
);
|
2012-08-22 21:15:15 +02:00
|
|
|
|
add_com_alias ("py", "python", class_obscure, 1);
|
2008-08-06 21:41:33 +02:00
|
|
|
|
|
2011-07-11 15:07:38 +02:00
|
|
|
|
/* Add set/show python print-stack. */
|
|
|
|
|
add_prefix_cmd ("python", no_class, user_show_python,
|
|
|
|
|
_("Prefix command for python preference settings."),
|
|
|
|
|
&user_show_python_list, "show python ", 0,
|
|
|
|
|
&showlist);
|
|
|
|
|
|
|
|
|
|
add_prefix_cmd ("python", no_class, user_set_python,
|
|
|
|
|
_("Prefix command for python preference settings."),
|
|
|
|
|
&user_set_python_list, "set python ", 0,
|
|
|
|
|
&setlist);
|
|
|
|
|
|
2011-12-16 16:55:40 +01:00
|
|
|
|
add_setshow_enum_cmd ("print-stack", no_class, python_excp_enums,
|
|
|
|
|
&gdbpy_should_print_stack, _("\
|
|
|
|
|
Set mode for Python stack dump on error."), _("\
|
|
|
|
|
Show the mode of Python stack printing on error."), _("\
|
|
|
|
|
none == no stack or message will be printed.\n\
|
|
|
|
|
full == a message and a stack will be printed.\n\
|
|
|
|
|
message == an error message without a stack will be printed."),
|
|
|
|
|
NULL, NULL,
|
|
|
|
|
&user_set_python_list,
|
|
|
|
|
&user_show_python_list);
|
2008-08-06 21:41:33 +02:00
|
|
|
|
|
|
|
|
|
#ifdef HAVE_PYTHON
|
2010-05-27 05:40:45 +02:00
|
|
|
|
#ifdef WITH_PYTHON_PATH
|
|
|
|
|
/* Work around problem where python gets confused about where it is,
|
|
|
|
|
and then can't find its libraries, etc.
|
|
|
|
|
NOTE: Python assumes the following layout:
|
|
|
|
|
/foo/bin/python
|
|
|
|
|
/foo/lib/pythonX.Y/...
|
|
|
|
|
This must be done before calling Py_Initialize. */
|
2012-12-12 17:47:30 +01:00
|
|
|
|
progname = concat (ldirname (python_libdir), SLASH_STRING, "bin",
|
|
|
|
|
SLASH_STRING, "python", NULL);
|
|
|
|
|
#ifdef IS_PY3K
|
|
|
|
|
oldloc = setlocale (LC_ALL, NULL);
|
|
|
|
|
setlocale (LC_ALL, "");
|
|
|
|
|
progsize = strlen (progname);
|
|
|
|
|
if (progsize == (size_t) -1)
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "Could not convert python path to string\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
progname_copy = PyMem_Malloc ((progsize + 1) * sizeof (wchar_t));
|
|
|
|
|
if (!progname_copy)
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "out of memory\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
count = mbstowcs (progname_copy, progname, progsize + 1);
|
|
|
|
|
if (count == (size_t) -1)
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "Could not convert python path to string\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
setlocale (LC_ALL, oldloc);
|
|
|
|
|
|
|
|
|
|
/* Note that Py_SetProgramName expects the string it is passed to
|
|
|
|
|
remain alive for the duration of the program's execution, so
|
|
|
|
|
it is not freed after this call. */
|
|
|
|
|
Py_SetProgramName (progname_copy);
|
|
|
|
|
#else
|
|
|
|
|
Py_SetProgramName (progname);
|
|
|
|
|
#endif
|
2010-05-27 05:40:45 +02:00
|
|
|
|
#endif
|
|
|
|
|
|
2008-08-06 21:41:33 +02:00
|
|
|
|
Py_Initialize ();
|
2008-11-21 15:59:56 +01:00
|
|
|
|
PyEval_InitThreads ();
|
2008-08-06 21:41:33 +02:00
|
|
|
|
|
2012-12-12 17:47:30 +01:00
|
|
|
|
#ifdef IS_PY3K
|
|
|
|
|
gdb_module = PyModule_Create (&GdbModuleDef);
|
|
|
|
|
/* Add _gdb module to the list of known built-in modules. */
|
|
|
|
|
_PyImport_FixupBuiltin (gdb_module, "_gdb");
|
|
|
|
|
#else
|
Refactor Python "gdb" module into a proper Python package, by introducing
a new "_gdb" module for code implemented in C, and using reload/__import__
instead of exec.
gdb/
* python/lib/gdb/__init__.py: Import * from _gdb.
(GdbOutputFile, sys.stdout, GdbOutputErrorFile, sys.stderr,
prompt_hook, sys.argv): Moved from finish_python_initialization.
(pretty_printers, PYTHONDIR): Moved from _initialize_python.
(packages, auto_load_packages): New list and function replacing
module_dict and auto-loading code, using __file__ instead of
gdb.PYTHONDIR and reload/__import__ instead of exec.
(GdbSetPythonDirectory): Replacing function of the same name
from finish_python_initialization, using reload/__import__ instead
of exec, as well as call auto_load_packages.
* python/py-prettyprint.c (find_pretty_printer_from_gdb): Check
gdb_python_module and not gdb_module.
* python/python-internal.h (gdb_python_module): Declare.
* python/python.c (gdb_python_module): New global.
(before_prompt_hook): Check gdb_python_module and not gdb_module.
(_initialize_python): Rename gdb module to _gdb.
Move gdb.PYTHONDIR and gdb.pretty_printer to lib/gdb/__init__.py.
(finish_python_initialization): Move Python code to
lib/gdb/__init__.py; instead, set up sys.path and import gdb into
__main__.
gdb/testsuite/
* gdb.python/python.exp (Test stderr location): Update module
location of GDB-specific sys.stderr.
(Test stdout location): Ditto for sys.stdout.
2012-09-13 23:49:32 +02:00
|
|
|
|
gdb_module = Py_InitModule ("_gdb", GdbMethods);
|
2012-12-12 17:47:30 +01:00
|
|
|
|
#endif
|
2008-08-06 21:41:33 +02:00
|
|
|
|
|
|
|
|
|
/* The casts to (char*) are for python 2.4. */
|
|
|
|
|
PyModule_AddStringConstant (gdb_module, "VERSION", (char*) version);
|
|
|
|
|
PyModule_AddStringConstant (gdb_module, "HOST_CONFIG", (char*) host_name);
|
2011-01-06 01:57:05 +01:00
|
|
|
|
PyModule_AddStringConstant (gdb_module, "TARGET_CONFIG",
|
|
|
|
|
(char*) target_name);
|
2010-10-04 17:30:25 +02:00
|
|
|
|
|
2011-03-18 09:44:47 +01:00
|
|
|
|
/* Add stream constants. */
|
|
|
|
|
PyModule_AddIntConstant (gdb_module, "STDOUT", 0);
|
|
|
|
|
PyModule_AddIntConstant (gdb_module, "STDERR", 1);
|
|
|
|
|
PyModule_AddIntConstant (gdb_module, "STDLOG", 2);
|
2008-08-06 21:41:33 +02:00
|
|
|
|
|
2010-11-12 21:49:43 +01:00
|
|
|
|
gdbpy_gdb_error = PyErr_NewException ("gdb.error", PyExc_RuntimeError, NULL);
|
|
|
|
|
PyModule_AddObject (gdb_module, "error", gdbpy_gdb_error);
|
|
|
|
|
|
|
|
|
|
gdbpy_gdb_memory_error = PyErr_NewException ("gdb.MemoryError",
|
|
|
|
|
gdbpy_gdb_error, NULL);
|
|
|
|
|
PyModule_AddObject (gdb_module, "MemoryError", gdbpy_gdb_memory_error);
|
|
|
|
|
|
2010-05-25 17:27:17 +02:00
|
|
|
|
gdbpy_gdberror_exc = PyErr_NewException ("gdb.GdbError", NULL, NULL);
|
|
|
|
|
PyModule_AddObject (gdb_module, "GdbError", gdbpy_gdberror_exc);
|
|
|
|
|
|
2012-08-22 23:04:55 +02:00
|
|
|
|
gdbpy_initialize_gdb_readline ();
|
2010-04-23 18:20:13 +02:00
|
|
|
|
gdbpy_initialize_auto_load ();
|
2008-10-16 05:54:00 +02:00
|
|
|
|
gdbpy_initialize_values ();
|
2009-03-30 21:54:33 +02:00
|
|
|
|
gdbpy_initialize_frames ();
|
2009-02-06 22:33:59 +01:00
|
|
|
|
gdbpy_initialize_commands ();
|
2010-02-24 Phil Muldoon <pmuldoon@redhat.com>
Tom Tromey <tromey@redhat.com>
Thiago Jung Bauermann <bauerman@br.ibm.com>
* python/python.c (_initialize_python): Call
gdbpy_initialize_symtabs, gdbpy_initialize_symbols and
gdbpy_initialize_blocks.
* python/python-internal.h: Declare struct symbol, block and
symtab_and_line. Declare block_object_type and
symbol_object_type
(gdbpy_lookup_symbol gdbpy_block_for_pc)
(symtab_and_line_to_sal_object, symtab_to_symtab_object)
(symbol_to_symbol_object, block_to_block_object)
(gdbpy_initialize_symtabs,gdbpy_initialize_symbols)
(gdbpy_initialize_blocks ): Declare.
* python/py-frame.c (frapy_block, frapy_function, frapy_find_sal)
(frapy_select): Add methods.
(frapy_read_var): Add symbol branch.
* Makefile.in (SUBDIR_PYTHON_OBS): Add py-symbol, py-symtab,
py-block.
(SUBDIR_PYTHON_SRCS): Likewise.
(py-symbol.o): New rule.
(py-symtab.o): Likewise.
(py-block.o): Likewise.
* python/py-symbol.c: New file.
* python/py-symtab.c: Likewise.
* python/py-block.c: Likewise.
2010-02-24 Phil Muldoon <pmuldoon@redhat.com>
* Makefile.in: Add py-block and py-symbol.
* gdb.python/py-symbol.exp: New File.
* gdb.python/py-symtab.exp: New File.
* gdb.python/py-block.exp: New File.
* gdb.python/py-symbol.c: New File.
* gdb.python/py-block.c: New File.
2010-02-24 Phil Muldoon <pmuldoon@redhat.com>
* gdb.texinfo (Frames In Python): Add block, find_sal, function
and select method descriptions.
(Python API): Add Blocks In Python, Symbols in Python and Symbol
Tables in Python to menu.
(Blocks In Python): New node.
(Symbols In Python): New node.
(Symbol Tables in Python): New node.
2010-02-24 22:18:28 +01:00
|
|
|
|
gdbpy_initialize_symbols ();
|
|
|
|
|
gdbpy_initialize_symtabs ();
|
|
|
|
|
gdbpy_initialize_blocks ();
|
gdb/
2009-03-05 Tom Tromey <tromey@redhat.com>
Add support for convenience functions in Python.
* Makefile.in (SUBDIR_PYTHON_OBS): Add python-function.o.
(SUBDIR_PYTHON_SRCS): Add python-function.c.
(python-function.o): New target.
* eval.c: Include "python/python.h" and <ctype.h>.
(evaluate_subexp_standard): Handle values of type
TYPE_CODE_INTERNAL_FUNCTION.
* gdbtypes.h (type_code): Add TYPE_CODE_INTERNAL_FUNCTION.
* parse.c (write_exp_string): Remove duplicate word in comment.
* python/python-function.c: New file.
* python/python-internal.h (gdbpy_initialize_functions): Add
prototype.
* python/python.c (_initialize_python): Call
gdbpy_initialize_functions.
* valprint.c (value_check_printable): Handle values of type
TYPE_CODE_INTERNAL_FUNCTION.
* value.c: Include "cli/cli-decode.h".
(internal_function): New struct.
(functionlist, internal_fn_type): New static variables.
(lookup_only_internalvar,
lookup_internalvar): Add const qualifier to name argument.
(create_internalvar): Likewise. Initialize new field.
(set_internal_var): Fix typo in comment. Don't allow assignment
to canonical variable.
(value_create_internal_function, value_internal_function_name,
call_internal_function, function_command, function_destroyer,
add_internal_function): New functions.
(_initialize_values): Create `function' placeholder command.
Initialize internal_fn_type.
* value.h (lookup_only_internalvar, create_internalvar,
lookup_internalvar): Add const qualifier to name argument.
(internal_function_fn, add_internal_function, call_internal_function,
value_internal_function_name): Add prototypes.
(struct internalvar) <canonical>: New field.
gdb/doc/
2008-03-05 Tom Tromey <tromey@redhat.com>
* gdb.texinfo (Convenience Vars): Document convenience functions.
(Functions In Python): New node.
(Python API): Update.
gdb/testsuite/
2009-03-05 Thiago Jung Bauermann <bauerman@br.ibm.com>
* gdb.python/python-function.exp: New file.
2009-03-21 04:03:56 +01:00
|
|
|
|
gdbpy_initialize_functions ();
|
2010-04-29 17:45:57 +02:00
|
|
|
|
gdbpy_initialize_parameters ();
|
2009-05-28 02:47:20 +02:00
|
|
|
|
gdbpy_initialize_types ();
|
2010-04-15 21:54:13 +02:00
|
|
|
|
gdbpy_initialize_pspace ();
|
2009-05-28 02:40:24 +02:00
|
|
|
|
gdbpy_initialize_objfile ();
|
2010-04-09 11:41:43 +02:00
|
|
|
|
gdbpy_initialize_breakpoints ();
|
2011-12-23 18:06:16 +01:00
|
|
|
|
gdbpy_initialize_finishbreakpoints ();
|
2010-01-14 09:03:37 +01:00
|
|
|
|
gdbpy_initialize_lazy_string ();
|
2010-06-28 23:16:04 +02:00
|
|
|
|
gdbpy_initialize_thread ();
|
|
|
|
|
gdbpy_initialize_inferior ();
|
2010-08-11 22:54:12 +02:00
|
|
|
|
gdbpy_initialize_events ();
|
2008-10-16 05:54:00 +02:00
|
|
|
|
|
Add Python support for GDB events.
2011-02-04 Sami Wagiaalla <swagiaal@redhat.com>
* gdb.python/py-evthreads.c: New file.
* gdb.python/py-evthreads.exp: New file.
* gdb.python/py-events.py: New file.
* gdb.python/py-events.exp: New file.
* gdb.python/py-events.c: New file.
2011-02-04 Sami Wagiaalla <swagiaal@redhat.com>
Oguz Kayral <oguzkayral@gmail.com>
* python/py-inferior.c (python_on_normal_stop): New function.
(python_on_resume): New function.
(python_inferior_exit): New function.
(gdbpy_initialize_inferior): Add normal_stop, target_resumed, and
inferior_exit observers.
* python/py-evtregistry.c: New file.
* python/py-threadevent.c : New file.
* python/py-event.c: New file.
* python/py-evts.c: New file.
* python/py-continueevent.c: New file.
* python/py-bpevent.c: New file.
* python/py-signalevent.c: New file.
* python/py-exetiedevent.c: New file.
* python/py-breakpoint.c (gdbpy_breakpoint_from_bpstats): New function.
Move struct breakpoint_object from here...
* python/python-internal.h: ... to here.
* python/py-event.h: New file.
* python/py-events.h: New file.
* Makefile.in (SUBDIR_PYTHON_OBS): Add py-breakpointstopevent.o,
py-continueevent.o, py-event.o, py-eventregistry.o, py-events.o,
py-exitedevent.o, py-signalstopevent.o, and py-stopevent.o.
(SUBDIR_PYTHON_SRCS): Add py-breakpointstopevent.c,
py-continueevent.c, py-event.c, py-eventregistry.c, py-events.c,
py-exitedevent.c, py-signalstopevent.c, and py-stopevent.c.
Add build rules for all the above.
2011-02-04 22:54:16 +01:00
|
|
|
|
gdbpy_initialize_eventregistry ();
|
|
|
|
|
gdbpy_initialize_py_events ();
|
|
|
|
|
gdbpy_initialize_event ();
|
|
|
|
|
gdbpy_initialize_stop_event ();
|
|
|
|
|
gdbpy_initialize_signal_event ();
|
|
|
|
|
gdbpy_initialize_breakpoint_event ();
|
|
|
|
|
gdbpy_initialize_continue_event ();
|
|
|
|
|
gdbpy_initialize_exited_event ();
|
|
|
|
|
gdbpy_initialize_thread_event ();
|
2011-10-07 09:38:30 +02:00
|
|
|
|
gdbpy_initialize_new_objfile_event () ;
|
2013-01-23 20:59:13 +01:00
|
|
|
|
gdbpy_initialize_arch ();
|
Add Python support for GDB events.
2011-02-04 Sami Wagiaalla <swagiaal@redhat.com>
* gdb.python/py-evthreads.c: New file.
* gdb.python/py-evthreads.exp: New file.
* gdb.python/py-events.py: New file.
* gdb.python/py-events.exp: New file.
* gdb.python/py-events.c: New file.
2011-02-04 Sami Wagiaalla <swagiaal@redhat.com>
Oguz Kayral <oguzkayral@gmail.com>
* python/py-inferior.c (python_on_normal_stop): New function.
(python_on_resume): New function.
(python_inferior_exit): New function.
(gdbpy_initialize_inferior): Add normal_stop, target_resumed, and
inferior_exit observers.
* python/py-evtregistry.c: New file.
* python/py-threadevent.c : New file.
* python/py-event.c: New file.
* python/py-evts.c: New file.
* python/py-continueevent.c: New file.
* python/py-bpevent.c: New file.
* python/py-signalevent.c: New file.
* python/py-exetiedevent.c: New file.
* python/py-breakpoint.c (gdbpy_breakpoint_from_bpstats): New function.
Move struct breakpoint_object from here...
* python/python-internal.h: ... to here.
* python/py-event.h: New file.
* python/py-events.h: New file.
* Makefile.in (SUBDIR_PYTHON_OBS): Add py-breakpointstopevent.o,
py-continueevent.o, py-event.o, py-eventregistry.o, py-events.o,
py-exitedevent.o, py-signalstopevent.o, and py-stopevent.o.
(SUBDIR_PYTHON_SRCS): Add py-breakpointstopevent.c,
py-continueevent.c, py-event.c, py-eventregistry.c, py-events.c,
py-exitedevent.c, py-signalstopevent.c, and py-stopevent.c.
Add build rules for all the above.
2011-02-04 22:54:16 +01:00
|
|
|
|
|
2011-07-21 13:03:48 +02:00
|
|
|
|
observer_attach_before_prompt (before_prompt_hook);
|
|
|
|
|
|
2009-05-28 03:05:14 +02:00
|
|
|
|
gdbpy_to_string_cst = PyString_FromString ("to_string");
|
|
|
|
|
gdbpy_children_cst = PyString_FromString ("children");
|
|
|
|
|
gdbpy_display_hint_cst = PyString_FromString ("display_hint");
|
2009-02-06 22:33:59 +01:00
|
|
|
|
gdbpy_doc_cst = PyString_FromString ("__doc__");
|
2010-06-04 20:18:28 +02:00
|
|
|
|
gdbpy_enabled_cst = PyString_FromString ("enabled");
|
2011-02-28 20:38:34 +01:00
|
|
|
|
gdbpy_value_cst = PyString_FromString ("value");
|
2009-02-06 22:33:59 +01:00
|
|
|
|
|
2010-11-02 17:48:43 +01:00
|
|
|
|
/* Release the GIL while gdb runs. */
|
|
|
|
|
PyThreadState_Swap (NULL);
|
|
|
|
|
PyEval_ReleaseLock ();
|
|
|
|
|
|
2012-09-20 22:54:11 +02:00
|
|
|
|
make_final_cleanup (finalize_python, NULL);
|
2010-11-02 17:48:43 +01:00
|
|
|
|
#endif /* HAVE_PYTHON */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_PYTHON
|
|
|
|
|
|
|
|
|
|
/* 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. */
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
finish_python_initialization (void)
|
|
|
|
|
{
|
Refactor Python "gdb" module into a proper Python package, by introducing
a new "_gdb" module for code implemented in C, and using reload/__import__
instead of exec.
gdb/
* python/lib/gdb/__init__.py: Import * from _gdb.
(GdbOutputFile, sys.stdout, GdbOutputErrorFile, sys.stderr,
prompt_hook, sys.argv): Moved from finish_python_initialization.
(pretty_printers, PYTHONDIR): Moved from _initialize_python.
(packages, auto_load_packages): New list and function replacing
module_dict and auto-loading code, using __file__ instead of
gdb.PYTHONDIR and reload/__import__ instead of exec.
(GdbSetPythonDirectory): Replacing function of the same name
from finish_python_initialization, using reload/__import__ instead
of exec, as well as call auto_load_packages.
* python/py-prettyprint.c (find_pretty_printer_from_gdb): Check
gdb_python_module and not gdb_module.
* python/python-internal.h (gdb_python_module): Declare.
* python/python.c (gdb_python_module): New global.
(before_prompt_hook): Check gdb_python_module and not gdb_module.
(_initialize_python): Rename gdb module to _gdb.
Move gdb.PYTHONDIR and gdb.pretty_printer to lib/gdb/__init__.py.
(finish_python_initialization): Move Python code to
lib/gdb/__init__.py; instead, set up sys.path and import gdb into
__main__.
gdb/testsuite/
* gdb.python/python.exp (Test stderr location): Update module
location of GDB-specific sys.stderr.
(Test stdout location): Ditto for sys.stdout.
2012-09-13 23:49:32 +02:00
|
|
|
|
PyObject *m;
|
|
|
|
|
char *gdb_pythondir;
|
|
|
|
|
PyObject *sys_path;
|
2010-11-02 17:48:43 +01:00
|
|
|
|
struct cleanup *cleanup;
|
|
|
|
|
|
|
|
|
|
cleanup = ensure_python_env (get_current_arch (), current_language);
|
2010-10-04 17:30:25 +02:00
|
|
|
|
|
Refactor Python "gdb" module into a proper Python package, by introducing
a new "_gdb" module for code implemented in C, and using reload/__import__
instead of exec.
gdb/
* python/lib/gdb/__init__.py: Import * from _gdb.
(GdbOutputFile, sys.stdout, GdbOutputErrorFile, sys.stderr,
prompt_hook, sys.argv): Moved from finish_python_initialization.
(pretty_printers, PYTHONDIR): Moved from _initialize_python.
(packages, auto_load_packages): New list and function replacing
module_dict and auto-loading code, using __file__ instead of
gdb.PYTHONDIR and reload/__import__ instead of exec.
(GdbSetPythonDirectory): Replacing function of the same name
from finish_python_initialization, using reload/__import__ instead
of exec, as well as call auto_load_packages.
* python/py-prettyprint.c (find_pretty_printer_from_gdb): Check
gdb_python_module and not gdb_module.
* python/python-internal.h (gdb_python_module): Declare.
* python/python.c (gdb_python_module): New global.
(before_prompt_hook): Check gdb_python_module and not gdb_module.
(_initialize_python): Rename gdb module to _gdb.
Move gdb.PYTHONDIR and gdb.pretty_printer to lib/gdb/__init__.py.
(finish_python_initialization): Move Python code to
lib/gdb/__init__.py; instead, set up sys.path and import gdb into
__main__.
gdb/testsuite/
* gdb.python/python.exp (Test stderr location): Update module
location of GDB-specific sys.stderr.
(Test stdout location): Ditto for sys.stdout.
2012-09-13 23:49:32 +02:00
|
|
|
|
/* Add the initial data-directory to sys.path. */
|
|
|
|
|
|
|
|
|
|
gdb_pythondir = concat (gdb_datadir, SLASH_STRING, "python", NULL);
|
|
|
|
|
make_cleanup (xfree, gdb_pythondir);
|
|
|
|
|
|
|
|
|
|
sys_path = PySys_GetObject ("path");
|
2008-11-21 15:59:56 +01:00
|
|
|
|
|
2012-12-12 17:47:30 +01:00
|
|
|
|
/* If sys.path is not defined yet, define it first. */
|
|
|
|
|
if (!(sys_path && PyList_Check (sys_path)))
|
|
|
|
|
{
|
|
|
|
|
#ifdef IS_PY3K
|
|
|
|
|
PySys_SetPath (L"");
|
|
|
|
|
#else
|
|
|
|
|
PySys_SetPath ("");
|
|
|
|
|
#endif
|
|
|
|
|
sys_path = PySys_GetObject ("path");
|
|
|
|
|
}
|
|
|
|
|
if (sys_path && PyList_Check (sys_path))
|
Refactor Python "gdb" module into a proper Python package, by introducing
a new "_gdb" module for code implemented in C, and using reload/__import__
instead of exec.
gdb/
* python/lib/gdb/__init__.py: Import * from _gdb.
(GdbOutputFile, sys.stdout, GdbOutputErrorFile, sys.stderr,
prompt_hook, sys.argv): Moved from finish_python_initialization.
(pretty_printers, PYTHONDIR): Moved from _initialize_python.
(packages, auto_load_packages): New list and function replacing
module_dict and auto-loading code, using __file__ instead of
gdb.PYTHONDIR and reload/__import__ instead of exec.
(GdbSetPythonDirectory): Replacing function of the same name
from finish_python_initialization, using reload/__import__ instead
of exec, as well as call auto_load_packages.
* python/py-prettyprint.c (find_pretty_printer_from_gdb): Check
gdb_python_module and not gdb_module.
* python/python-internal.h (gdb_python_module): Declare.
* python/python.c (gdb_python_module): New global.
(before_prompt_hook): Check gdb_python_module and not gdb_module.
(_initialize_python): Rename gdb module to _gdb.
Move gdb.PYTHONDIR and gdb.pretty_printer to lib/gdb/__init__.py.
(finish_python_initialization): Move Python code to
lib/gdb/__init__.py; instead, set up sys.path and import gdb into
__main__.
gdb/testsuite/
* gdb.python/python.exp (Test stderr location): Update module
location of GDB-specific sys.stderr.
(Test stdout location): Ditto for sys.stdout.
2012-09-13 23:49:32 +02:00
|
|
|
|
{
|
|
|
|
|
PyObject *pythondir;
|
|
|
|
|
int err;
|
|
|
|
|
|
|
|
|
|
pythondir = PyString_FromString (gdb_pythondir);
|
|
|
|
|
if (pythondir == NULL)
|
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
|
|
err = PyList_Insert (sys_path, 0, pythondir);
|
|
|
|
|
if (err)
|
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
|
|
Py_DECREF (pythondir);
|
|
|
|
|
}
|
|
|
|
|
else
|
2012-12-12 17:47:30 +01:00
|
|
|
|
goto fail;
|
Refactor Python "gdb" module into a proper Python package, by introducing
a new "_gdb" module for code implemented in C, and using reload/__import__
instead of exec.
gdb/
* python/lib/gdb/__init__.py: Import * from _gdb.
(GdbOutputFile, sys.stdout, GdbOutputErrorFile, sys.stderr,
prompt_hook, sys.argv): Moved from finish_python_initialization.
(pretty_printers, PYTHONDIR): Moved from _initialize_python.
(packages, auto_load_packages): New list and function replacing
module_dict and auto-loading code, using __file__ instead of
gdb.PYTHONDIR and reload/__import__ instead of exec.
(GdbSetPythonDirectory): Replacing function of the same name
from finish_python_initialization, using reload/__import__ instead
of exec, as well as call auto_load_packages.
* python/py-prettyprint.c (find_pretty_printer_from_gdb): Check
gdb_python_module and not gdb_module.
* python/python-internal.h (gdb_python_module): Declare.
* python/python.c (gdb_python_module): New global.
(before_prompt_hook): Check gdb_python_module and not gdb_module.
(_initialize_python): Rename gdb module to _gdb.
Move gdb.PYTHONDIR and gdb.pretty_printer to lib/gdb/__init__.py.
(finish_python_initialization): Move Python code to
lib/gdb/__init__.py; instead, set up sys.path and import gdb into
__main__.
gdb/testsuite/
* gdb.python/python.exp (Test stderr location): Update module
location of GDB-specific sys.stderr.
(Test stdout location): Ditto for sys.stdout.
2012-09-13 23:49:32 +02:00
|
|
|
|
|
|
|
|
|
/* Import the gdb module to finish the initialization, and
|
|
|
|
|
add it to __main__ for convenience. */
|
|
|
|
|
m = PyImport_AddModule ("__main__");
|
|
|
|
|
if (m == NULL)
|
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
|
|
gdb_python_module = PyImport_ImportModule ("gdb");
|
|
|
|
|
if (gdb_python_module == NULL)
|
|
|
|
|
{
|
|
|
|
|
gdbpy_print_stack ();
|
2013-03-28 17:39:09 +01:00
|
|
|
|
/* This is passed in one call to warning so that blank lines aren't
|
|
|
|
|
inserted between each line of text. */
|
|
|
|
|
warning (_("\n"
|
|
|
|
|
"Could not load the Python gdb module from `%s'.\n"
|
|
|
|
|
"Limited Python support is available from the _gdb module.\n"
|
|
|
|
|
"Suggest passing --data-directory=/path/to/gdb/data-directory.\n"),
|
Refactor Python "gdb" module into a proper Python package, by introducing
a new "_gdb" module for code implemented in C, and using reload/__import__
instead of exec.
gdb/
* python/lib/gdb/__init__.py: Import * from _gdb.
(GdbOutputFile, sys.stdout, GdbOutputErrorFile, sys.stderr,
prompt_hook, sys.argv): Moved from finish_python_initialization.
(pretty_printers, PYTHONDIR): Moved from _initialize_python.
(packages, auto_load_packages): New list and function replacing
module_dict and auto-loading code, using __file__ instead of
gdb.PYTHONDIR and reload/__import__ instead of exec.
(GdbSetPythonDirectory): Replacing function of the same name
from finish_python_initialization, using reload/__import__ instead
of exec, as well as call auto_load_packages.
* python/py-prettyprint.c (find_pretty_printer_from_gdb): Check
gdb_python_module and not gdb_module.
* python/python-internal.h (gdb_python_module): Declare.
* python/python.c (gdb_python_module): New global.
(before_prompt_hook): Check gdb_python_module and not gdb_module.
(_initialize_python): Rename gdb module to _gdb.
Move gdb.PYTHONDIR and gdb.pretty_printer to lib/gdb/__init__.py.
(finish_python_initialization): Move Python code to
lib/gdb/__init__.py; instead, set up sys.path and import gdb into
__main__.
gdb/testsuite/
* gdb.python/python.exp (Test stderr location): Update module
location of GDB-specific sys.stderr.
(Test stdout location): Ditto for sys.stdout.
2012-09-13 23:49:32 +02:00
|
|
|
|
gdb_pythondir);
|
|
|
|
|
do_cleanups (cleanup);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (PyModule_AddObject (m, "gdb", gdb_python_module))
|
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
|
|
/* Keep the reference to gdb_python_module since it is in a global
|
|
|
|
|
variable. */
|
|
|
|
|
|
|
|
|
|
do_cleanups (cleanup);
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
fail:
|
|
|
|
|
gdbpy_print_stack ();
|
|
|
|
|
warning (_("internal error: Unhandled Python exception"));
|
2010-11-02 17:48:43 +01:00
|
|
|
|
do_cleanups (cleanup);
|
|
|
|
|
}
|
2008-11-21 15:59:56 +01:00
|
|
|
|
|
2008-08-06 21:41:33 +02:00
|
|
|
|
#endif /* HAVE_PYTHON */
|
2009-02-05 17:40:34 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-11-02 17:48:43 +01:00
|
|
|
|
#ifdef HAVE_PYTHON
|
2009-02-05 17:40:34 +01:00
|
|
|
|
|
|
|
|
|
static PyMethodDef GdbMethods[] =
|
|
|
|
|
{
|
|
|
|
|
{ "history", gdbpy_history, METH_VARARGS,
|
|
|
|
|
"Get a value from history" },
|
2010-06-25 20:15:18 +02:00
|
|
|
|
{ "execute", (PyCFunction) execute_gdb_command, METH_VARARGS | METH_KEYWORDS,
|
2009-02-05 17:40:34 +01:00
|
|
|
|
"Execute a gdb command" },
|
2009-05-28 18:49:55 +02:00
|
|
|
|
{ "parameter", gdbpy_parameter, METH_VARARGS,
|
2009-02-05 17:40:34 +01:00
|
|
|
|
"Return a gdb parameter's value" },
|
|
|
|
|
|
2010-04-09 11:41:43 +02:00
|
|
|
|
{ "breakpoints", gdbpy_breakpoints, METH_NOARGS,
|
|
|
|
|
"Return a tuple of all breakpoint objects" },
|
|
|
|
|
|
2009-05-28 03:09:20 +02:00
|
|
|
|
{ "default_visualizer", gdbpy_default_visualizer, METH_VARARGS,
|
|
|
|
|
"Find the default visualizer for a Value." },
|
|
|
|
|
|
2010-04-15 21:54:13 +02:00
|
|
|
|
{ "current_progspace", gdbpy_get_current_progspace, METH_NOARGS,
|
|
|
|
|
"Return the current Progspace." },
|
|
|
|
|
{ "progspaces", gdbpy_progspaces, METH_NOARGS,
|
|
|
|
|
"Return a sequence of all progspaces." },
|
|
|
|
|
|
2009-05-28 02:40:24 +02:00
|
|
|
|
{ "current_objfile", gdbpy_get_current_objfile, METH_NOARGS,
|
|
|
|
|
"Return the current Objfile being loaded, or None." },
|
|
|
|
|
{ "objfiles", gdbpy_objfiles, METH_NOARGS,
|
|
|
|
|
"Return a sequence of all loaded objfiles." },
|
|
|
|
|
|
2011-01-06 22:10:53 +01:00
|
|
|
|
{ "newest_frame", gdbpy_newest_frame, METH_NOARGS,
|
|
|
|
|
"newest_frame () -> gdb.Frame.\n\
|
|
|
|
|
Return the newest frame object." },
|
2009-03-30 21:54:33 +02:00
|
|
|
|
{ "selected_frame", gdbpy_selected_frame, METH_NOARGS,
|
|
|
|
|
"selected_frame () -> gdb.Frame.\n\
|
|
|
|
|
Return the selected frame object." },
|
|
|
|
|
{ "frame_stop_reason_string", gdbpy_frame_stop_reason_string, METH_VARARGS,
|
|
|
|
|
"stop_reason_string (Integer) -> String.\n\
|
|
|
|
|
Return a string explaining unwind stop reason." },
|
|
|
|
|
|
2009-05-28 02:47:20 +02:00
|
|
|
|
{ "lookup_type", (PyCFunction) gdbpy_lookup_type,
|
|
|
|
|
METH_VARARGS | METH_KEYWORDS,
|
|
|
|
|
"lookup_type (name [, block]) -> type\n\
|
|
|
|
|
Return a Type corresponding to the given name." },
|
2010-02-24 Phil Muldoon <pmuldoon@redhat.com>
Tom Tromey <tromey@redhat.com>
Thiago Jung Bauermann <bauerman@br.ibm.com>
* python/python.c (_initialize_python): Call
gdbpy_initialize_symtabs, gdbpy_initialize_symbols and
gdbpy_initialize_blocks.
* python/python-internal.h: Declare struct symbol, block and
symtab_and_line. Declare block_object_type and
symbol_object_type
(gdbpy_lookup_symbol gdbpy_block_for_pc)
(symtab_and_line_to_sal_object, symtab_to_symtab_object)
(symbol_to_symbol_object, block_to_block_object)
(gdbpy_initialize_symtabs,gdbpy_initialize_symbols)
(gdbpy_initialize_blocks ): Declare.
* python/py-frame.c (frapy_block, frapy_function, frapy_find_sal)
(frapy_select): Add methods.
(frapy_read_var): Add symbol branch.
* Makefile.in (SUBDIR_PYTHON_OBS): Add py-symbol, py-symtab,
py-block.
(SUBDIR_PYTHON_SRCS): Likewise.
(py-symbol.o): New rule.
(py-symtab.o): Likewise.
(py-block.o): Likewise.
* python/py-symbol.c: New file.
* python/py-symtab.c: Likewise.
* python/py-block.c: Likewise.
2010-02-24 Phil Muldoon <pmuldoon@redhat.com>
* Makefile.in: Add py-block and py-symbol.
* gdb.python/py-symbol.exp: New File.
* gdb.python/py-symtab.exp: New File.
* gdb.python/py-block.exp: New File.
* gdb.python/py-symbol.c: New File.
* gdb.python/py-block.c: New File.
2010-02-24 Phil Muldoon <pmuldoon@redhat.com>
* gdb.texinfo (Frames In Python): Add block, find_sal, function
and select method descriptions.
(Python API): Add Blocks In Python, Symbols in Python and Symbol
Tables in Python to menu.
(Blocks In Python): New node.
(Symbols In Python): New node.
(Symbol Tables in Python): New node.
2010-02-24 22:18:28 +01:00
|
|
|
|
{ "lookup_symbol", (PyCFunction) gdbpy_lookup_symbol,
|
|
|
|
|
METH_VARARGS | METH_KEYWORDS,
|
|
|
|
|
"lookup_symbol (name [, block] [, domain]) -> (symbol, is_field_of_this)\n\
|
|
|
|
|
Return a tuple with the symbol corresponding to the given name (or None) and\n\
|
|
|
|
|
a boolean indicating if name is a field of the current implied argument\n\
|
|
|
|
|
`this' (when the current language is object-oriented)." },
|
2011-02-22 23:48:12 +01:00
|
|
|
|
{ "lookup_global_symbol", (PyCFunction) gdbpy_lookup_global_symbol,
|
|
|
|
|
METH_VARARGS | METH_KEYWORDS,
|
|
|
|
|
"lookup_global_symbol (name [, domain]) -> symbol\n\
|
|
|
|
|
Return the symbol corresponding to the given name (or None)." },
|
2010-02-24 Phil Muldoon <pmuldoon@redhat.com>
Tom Tromey <tromey@redhat.com>
Thiago Jung Bauermann <bauerman@br.ibm.com>
* python/python.c (_initialize_python): Call
gdbpy_initialize_symtabs, gdbpy_initialize_symbols and
gdbpy_initialize_blocks.
* python/python-internal.h: Declare struct symbol, block and
symtab_and_line. Declare block_object_type and
symbol_object_type
(gdbpy_lookup_symbol gdbpy_block_for_pc)
(symtab_and_line_to_sal_object, symtab_to_symtab_object)
(symbol_to_symbol_object, block_to_block_object)
(gdbpy_initialize_symtabs,gdbpy_initialize_symbols)
(gdbpy_initialize_blocks ): Declare.
* python/py-frame.c (frapy_block, frapy_function, frapy_find_sal)
(frapy_select): Add methods.
(frapy_read_var): Add symbol branch.
* Makefile.in (SUBDIR_PYTHON_OBS): Add py-symbol, py-symtab,
py-block.
(SUBDIR_PYTHON_SRCS): Likewise.
(py-symbol.o): New rule.
(py-symtab.o): Likewise.
(py-block.o): Likewise.
* python/py-symbol.c: New file.
* python/py-symtab.c: Likewise.
* python/py-block.c: Likewise.
2010-02-24 Phil Muldoon <pmuldoon@redhat.com>
* Makefile.in: Add py-block and py-symbol.
* gdb.python/py-symbol.exp: New File.
* gdb.python/py-symtab.exp: New File.
* gdb.python/py-block.exp: New File.
* gdb.python/py-symbol.c: New File.
* gdb.python/py-block.c: New File.
2010-02-24 Phil Muldoon <pmuldoon@redhat.com>
* gdb.texinfo (Frames In Python): Add block, find_sal, function
and select method descriptions.
(Python API): Add Blocks In Python, Symbols in Python and Symbol
Tables in Python to menu.
(Blocks In Python): New node.
(Symbols In Python): New node.
(Symbol Tables in Python): New node.
2010-02-24 22:18:28 +01:00
|
|
|
|
{ "block_for_pc", gdbpy_block_for_pc, METH_VARARGS,
|
|
|
|
|
"Return the block containing the given pc value, or None." },
|
2010-08-11 14:48:24 +02:00
|
|
|
|
{ "solib_name", gdbpy_solib_name, METH_VARARGS,
|
|
|
|
|
"solib_name (Long) -> String.\n\
|
|
|
|
|
Return the name of the shared library holding a given address, or None." },
|
|
|
|
|
{ "decode_line", gdbpy_decode_line, METH_VARARGS,
|
|
|
|
|
"decode_line (String) -> Tuple. Decode a string argument the way\n\
|
|
|
|
|
that 'break' or 'edit' does. Return a tuple containing two elements.\n\
|
|
|
|
|
The first element contains any unparsed portion of the String parameter\n\
|
|
|
|
|
(or None if the string was fully parsed). The second element contains\n\
|
|
|
|
|
a tuple that contains all the locations that match, represented as\n\
|
|
|
|
|
gdb.Symtab_and_line objects (or None)."},
|
2009-12-03 19:30:02 +01:00
|
|
|
|
{ "parse_and_eval", gdbpy_parse_and_eval, METH_VARARGS,
|
|
|
|
|
"parse_and_eval (String) -> Value.\n\
|
|
|
|
|
Parse String as an expression, evaluate it, and return the result as a Value."
|
|
|
|
|
},
|
2012-05-13 13:33:44 +02:00
|
|
|
|
{ "find_pc_line", gdbpy_find_pc_line, METH_VARARGS,
|
|
|
|
|
"find_pc_line (pc) -> Symtab_and_line.\n\
|
|
|
|
|
Return the gdb.Symtab_and_line object corresponding to the pc value." },
|
2009-12-03 19:30:02 +01:00
|
|
|
|
|
2010-08-11 22:54:12 +02:00
|
|
|
|
{ "post_event", gdbpy_post_event, METH_VARARGS,
|
|
|
|
|
"Post an event into gdb's event loop." },
|
|
|
|
|
|
2010-03-05 21:18:19 +01:00
|
|
|
|
{ "target_charset", gdbpy_target_charset, METH_NOARGS,
|
|
|
|
|
"target_charset () -> string.\n\
|
|
|
|
|
Return the name of the current target charset." },
|
|
|
|
|
{ "target_wide_charset", gdbpy_target_wide_charset, METH_NOARGS,
|
|
|
|
|
"target_wide_charset () -> string.\n\
|
|
|
|
|
Return the name of the current target wide charset." },
|
|
|
|
|
|
2010-05-25 17:27:17 +02:00
|
|
|
|
{ "string_to_argv", gdbpy_string_to_argv, METH_VARARGS,
|
|
|
|
|
"string_to_argv (String) -> Array.\n\
|
|
|
|
|
Parse String and return an argv-like array.\n\
|
|
|
|
|
Arguments are separate by spaces and may be quoted."
|
|
|
|
|
},
|
2011-03-18 09:44:47 +01:00
|
|
|
|
{ "write", (PyCFunction)gdbpy_write, METH_VARARGS | METH_KEYWORDS,
|
2009-02-05 17:40:34 +01:00
|
|
|
|
"Write a string using gdb's filtered stream." },
|
2011-03-18 09:44:47 +01:00
|
|
|
|
{ "flush", (PyCFunction)gdbpy_flush, METH_VARARGS | METH_KEYWORDS,
|
2009-02-05 17:40:34 +01:00
|
|
|
|
"Flush gdb's filtered stdout stream." },
|
2010-06-28 23:16:04 +02:00
|
|
|
|
{ "selected_thread", gdbpy_selected_thread, METH_NOARGS,
|
|
|
|
|
"selected_thread () -> gdb.InferiorThread.\n\
|
|
|
|
|
Return the selected thread object." },
|
2011-09-15 14:42:30 +02:00
|
|
|
|
{ "selected_inferior", gdbpy_selected_inferior, METH_NOARGS,
|
|
|
|
|
"selected_inferior () -> gdb.Inferior.\n\
|
|
|
|
|
Return the selected inferior object." },
|
2010-06-28 23:16:04 +02:00
|
|
|
|
{ "inferiors", gdbpy_inferiors, METH_NOARGS,
|
|
|
|
|
"inferiors () -> (gdb.Inferior, ...).\n\
|
|
|
|
|
Return a tuple containing all inferiors." },
|
2009-02-05 17:40:34 +01:00
|
|
|
|
{NULL, NULL, 0, NULL}
|
|
|
|
|
};
|
|
|
|
|
|
2012-12-12 17:47:30 +01:00
|
|
|
|
#ifdef IS_PY3K
|
|
|
|
|
static struct PyModuleDef GdbModuleDef =
|
|
|
|
|
{
|
|
|
|
|
PyModuleDef_HEAD_INIT,
|
|
|
|
|
"_gdb",
|
|
|
|
|
NULL,
|
|
|
|
|
-1,
|
|
|
|
|
GdbMethods,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL
|
|
|
|
|
};
|
|
|
|
|
#endif
|
2009-02-05 17:40:34 +01:00
|
|
|
|
#endif /* HAVE_PYTHON */
|