2008-08-06 19:41:33 +00:00
|
|
|
|
/* General python/gdb code
|
|
|
|
|
|
2010-01-01 07:32:07 +00:00
|
|
|
|
Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
|
2008-08-06 19:41:33 +00: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 17:04:23 +00:00
|
|
|
|
#include "arch-utils.h"
|
2008-08-06 19:41:33 +00:00
|
|
|
|
#include "command.h"
|
|
|
|
|
#include "ui-out.h"
|
|
|
|
|
#include "cli/cli-script.h"
|
|
|
|
|
#include "gdbcmd.h"
|
2010-04-15 19:54:13 +00:00
|
|
|
|
#include "progspace.h"
|
2009-05-28 00:40:24 +00: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 17:04:23 +00:00
|
|
|
|
#include "value.h"
|
|
|
|
|
#include "language.h"
|
2010-01-18 10:50:45 +00:00
|
|
|
|
#include "exceptions.h"
|
2008-08-06 19:41:33 +00:00
|
|
|
|
|
|
|
|
|
#include <ctype.h>
|
|
|
|
|
|
|
|
|
|
/* True if we should print the stack when catching a Python error,
|
|
|
|
|
false otherwise. */
|
|
|
|
|
static int gdbpy_should_print_stack = 1;
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_PYTHON
|
|
|
|
|
|
|
|
|
|
#include "python.h"
|
|
|
|
|
#include "libiberty.h"
|
|
|
|
|
#include "cli/cli-decode.h"
|
|
|
|
|
#include "charset.h"
|
|
|
|
|
#include "top.h"
|
|
|
|
|
#include "python-internal.h"
|
|
|
|
|
#include "version.h"
|
|
|
|
|
#include "target.h"
|
|
|
|
|
#include "gdbthread.h"
|
|
|
|
|
|
2009-02-05 16:40:34 +00:00
|
|
|
|
static PyMethodDef GdbMethods[];
|
2008-08-06 19:41:33 +00:00
|
|
|
|
|
|
|
|
|
PyObject *gdb_module;
|
|
|
|
|
|
2009-05-28 01:05:14 +00: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 21:33:59 +00:00
|
|
|
|
PyObject *gdbpy_doc_cst;
|
2010-06-04 18:18:28 +00:00
|
|
|
|
PyObject *gdbpy_enabled_cst;
|
2009-02-06 21:33:59 +00:00
|
|
|
|
|
2010-05-25 15:27:17 +00: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 17:04:23 +00: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;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
restore_python_env (void *p)
|
|
|
|
|
{
|
|
|
|
|
struct python_env *env = (struct python_env *)p;
|
2010-05-17 21:23:25 +00: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 17:04:23 +00: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;
|
|
|
|
|
|
|
|
|
|
return make_cleanup (restore_python_env, env);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-08-06 19:41:33 +00: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 21:23:25 +00:00
|
|
|
|
|
2008-08-06 19:41:33 +00: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 16:40:34 +00:00
|
|
|
|
int ret;
|
2008-08-06 19:41:33 +00:00
|
|
|
|
char *script;
|
2008-11-21 14:59:56 +00:00
|
|
|
|
struct cleanup *cleanup;
|
2008-08-06 19:41:33 +00: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 17:04:23 +00:00
|
|
|
|
cleanup = ensure_python_env (get_current_arch (), current_language);
|
2008-11-21 14:59:56 +00:00
|
|
|
|
|
2008-08-06 19:41:33 +00:00
|
|
|
|
script = compute_python_string (cmd->body_list[0]);
|
2009-02-05 16:40:34 +00:00
|
|
|
|
ret = PyRun_SimpleString (script);
|
2008-08-06 19:41:33 +00:00
|
|
|
|
xfree (script);
|
2009-02-05 16:40:34 +00:00
|
|
|
|
if (ret)
|
2008-08-06 19:41:33 +00:00
|
|
|
|
{
|
|
|
|
|
gdbpy_print_stack ();
|
2009-02-05 16:40:34 +00:00
|
|
|
|
error (_("Error while executing Python code."));
|
2008-08-06 19:41:33 +00:00
|
|
|
|
}
|
2008-11-21 14:59:56 +00:00
|
|
|
|
|
|
|
|
|
do_cleanups (cleanup);
|
2008-08-06 19:41:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Implementation of the gdb "python" command. */
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
python_command (char *arg, int from_tty)
|
|
|
|
|
{
|
2008-11-21 14:59:56 +00:00
|
|
|
|
struct cleanup *cleanup;
|
|
|
|
|
|
2010-05-17 21:23:25 +00:00
|
|
|
|
cleanup = ensure_python_env (get_current_arch (), current_language);
|
2008-08-06 19:41:33 +00:00
|
|
|
|
while (arg && *arg && isspace (*arg))
|
|
|
|
|
++arg;
|
|
|
|
|
if (arg && *arg)
|
|
|
|
|
{
|
2009-02-05 16:40:34 +00:00
|
|
|
|
if (PyRun_SimpleString (arg))
|
2008-08-06 19:41:33 +00:00
|
|
|
|
{
|
|
|
|
|
gdbpy_print_stack ();
|
2009-02-05 16:40:34 +00:00
|
|
|
|
error (_("Error while executing Python code."));
|
2008-08-06 19:41:33 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
struct command_line *l = get_command_line (python_control, "");
|
2010-05-17 21:23:25 +00:00
|
|
|
|
|
2008-11-21 14:59:56 +00:00
|
|
|
|
make_cleanup_free_command_lines (&l);
|
2008-08-06 19:41:33 +00:00
|
|
|
|
execute_control_command_untraced (l);
|
|
|
|
|
}
|
2008-11-21 14:59:56 +00:00
|
|
|
|
|
|
|
|
|
do_cleanups (cleanup);
|
2008-08-06 19:41:33 +00: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 15:45:57 +00:00
|
|
|
|
PyObject *
|
|
|
|
|
gdbpy_parameter_value (enum var_types type, void *var)
|
2008-08-06 19:41:33 +00:00
|
|
|
|
{
|
2010-04-29 15:45:57 +00:00
|
|
|
|
switch (type)
|
2008-08-06 19:41:33 +00:00
|
|
|
|
{
|
|
|
|
|
case var_string:
|
|
|
|
|
case var_string_noescape:
|
|
|
|
|
case var_optional_filename:
|
|
|
|
|
case var_filename:
|
|
|
|
|
case var_enum:
|
|
|
|
|
{
|
2010-04-29 15:45:57 +00:00
|
|
|
|
char *str = * (char **) var;
|
2010-05-17 21:23:25 +00:00
|
|
|
|
|
2008-08-06 19:41:33 +00:00
|
|
|
|
if (! str)
|
|
|
|
|
str = "";
|
|
|
|
|
return PyString_Decode (str, strlen (str), host_charset (), NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case var_boolean:
|
|
|
|
|
{
|
2010-04-29 15:45:57 +00:00
|
|
|
|
if (* (int *) var)
|
2008-08-06 19:41:33 +00:00
|
|
|
|
Py_RETURN_TRUE;
|
|
|
|
|
else
|
|
|
|
|
Py_RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case var_auto_boolean:
|
|
|
|
|
{
|
2010-04-29 15:45:57 +00:00
|
|
|
|
enum auto_boolean ab = * (enum auto_boolean *) var;
|
2010-05-17 21:23:25 +00:00
|
|
|
|
|
2008-08-06 19:41:33 +00: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 15:45:57 +00:00
|
|
|
|
if ((* (int *) var) == INT_MAX)
|
2008-08-06 19:41:33 +00:00
|
|
|
|
Py_RETURN_NONE;
|
|
|
|
|
/* Fall through. */
|
|
|
|
|
case var_zinteger:
|
2010-04-29 15:45:57 +00:00
|
|
|
|
return PyLong_FromLong (* (int *) var);
|
2008-08-06 19:41:33 +00:00
|
|
|
|
|
|
|
|
|
case var_uinteger:
|
|
|
|
|
{
|
2010-04-29 15:45:57 +00:00
|
|
|
|
unsigned int val = * (unsigned int *) var;
|
2010-05-17 21:23:25 +00:00
|
|
|
|
|
2008-08-06 19:41:33 +00:00
|
|
|
|
if (val == UINT_MAX)
|
|
|
|
|
Py_RETURN_NONE;
|
|
|
|
|
return PyLong_FromUnsignedLong (val);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-14 13:18:55 +00:00
|
|
|
|
return PyErr_Format (PyExc_RuntimeError,
|
|
|
|
|
_("Programmer error: unhandled type."));
|
2008-08-06 19:41:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* A Python function which returns a gdb parameter's value as a Python
|
|
|
|
|
value. */
|
|
|
|
|
|
2010-04-29 15:45:57 +00:00
|
|
|
|
PyObject *
|
2009-05-28 16:49:55 +00:00
|
|
|
|
gdbpy_parameter (PyObject *self, PyObject *args)
|
2008-08-06 19:41:33 +00:00
|
|
|
|
{
|
|
|
|
|
struct cmd_list_element *alias, *prefix, *cmd;
|
|
|
|
|
char *arg, *newarg;
|
2009-03-21 03:13:02 +00:00
|
|
|
|
int found = -1;
|
2008-08-06 19:41:33 +00: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 03:13:02 +00:00
|
|
|
|
found = lookup_cmd_composition (newarg, &alias, &prefix, &cmd);
|
2008-08-06 19:41:33 +00:00
|
|
|
|
}
|
|
|
|
|
xfree (newarg);
|
|
|
|
|
GDB_PY_HANDLE_EXCEPTION (except);
|
2009-03-21 03:13:02 +00:00
|
|
|
|
if (!found)
|
|
|
|
|
return PyErr_Format (PyExc_RuntimeError,
|
2010-04-14 13:18:55 +00:00
|
|
|
|
_("Could not find parameter `%s'."), arg);
|
2008-08-06 19:41:33 +00:00
|
|
|
|
|
|
|
|
|
if (! cmd->var)
|
2010-04-14 13:18:55 +00:00
|
|
|
|
return PyErr_Format (PyExc_RuntimeError,
|
|
|
|
|
_("`%s' is not a parameter."), arg);
|
2010-04-29 15:45:57 +00:00
|
|
|
|
return gdbpy_parameter_value (cmd->var_type, cmd->var);
|
2008-08-06 19:41:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-03-05 20:18:19 +00:00
|
|
|
|
/* Wrapper for target_charset. */
|
|
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
|
gdbpy_target_charset (PyObject *self, PyObject *args)
|
|
|
|
|
{
|
|
|
|
|
const char *cset = target_charset (python_gdbarch);
|
2010-05-17 21:23:25 +00:00
|
|
|
|
|
2010-03-05 20:18:19 +00: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 21:23:25 +00:00
|
|
|
|
|
2010-03-05 20:18:19 +00:00
|
|
|
|
return PyUnicode_Decode (cset, strlen (cset), host_charset (), NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-25 18:15:18 +00:00
|
|
|
|
struct restore_ui_file_closure
|
|
|
|
|
{
|
|
|
|
|
struct ui_file **variable;
|
|
|
|
|
struct ui_file *value;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
restore_ui_file (void *p)
|
|
|
|
|
{
|
|
|
|
|
struct restore_ui_file_closure *closure = p;
|
|
|
|
|
|
|
|
|
|
*(closure->variable) = closure->value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Remember the current value of *VARIABLE and make it restored when
|
|
|
|
|
the cleanup is run. */
|
|
|
|
|
struct cleanup *
|
|
|
|
|
make_cleanup_restore_ui_file (struct ui_file **variable)
|
|
|
|
|
{
|
|
|
|
|
struct restore_ui_file_closure *c = XNEW (struct restore_ui_file_closure);
|
|
|
|
|
|
|
|
|
|
c->variable = variable;
|
|
|
|
|
c->value = *variable;
|
|
|
|
|
|
|
|
|
|
return make_cleanup_dtor (restore_ui_file, (void *) c, xfree);
|
|
|
|
|
}
|
|
|
|
|
|
2008-08-06 19:41:33 +00:00
|
|
|
|
/* A Python function which evaluates a string using the gdb CLI. */
|
|
|
|
|
|
|
|
|
|
static PyObject *
|
2010-06-25 18:15:18 +00:00
|
|
|
|
execute_gdb_command (PyObject *self, PyObject *args, PyObject *kw)
|
2008-08-06 19:41:33 +00:00
|
|
|
|
{
|
2010-05-07 19:26:30 +00:00
|
|
|
|
char *arg;
|
2010-06-25 18:15:18 +00:00
|
|
|
|
PyObject *from_tty_obj = NULL, *to_string_obj = NULL;
|
|
|
|
|
int from_tty, to_string;
|
2008-08-06 19:41:33 +00:00
|
|
|
|
volatile struct gdb_exception except;
|
2010-06-25 18:15:18 +00:00
|
|
|
|
static char *keywords[] = {"command", "from_tty", "to_string", NULL };
|
|
|
|
|
char *result = NULL;
|
2008-08-06 19:41:33 +00:00
|
|
|
|
|
2010-06-25 18:15:18 +00:00
|
|
|
|
if (! PyArg_ParseTupleAndKeywords (args, kw, "s|O!O!", keywords, &arg,
|
|
|
|
|
&PyBool_Type, &from_tty_obj,
|
|
|
|
|
&PyBool_Type, &to_string_obj))
|
2008-08-06 19:41:33 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
|
2009-02-05 16:40:34 +00:00
|
|
|
|
from_tty = 0;
|
|
|
|
|
if (from_tty_obj)
|
|
|
|
|
{
|
2010-06-25 18:15:18 +00:00
|
|
|
|
int cmp = PyObject_IsTrue (from_tty_obj);
|
2009-02-05 16:40:34 +00:00
|
|
|
|
if (cmp < 0)
|
2010-06-25 18:15:18 +00:00
|
|
|
|
return NULL;
|
2009-02-05 16:40:34 +00:00
|
|
|
|
from_tty = cmp;
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-25 18:15:18 +00: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 19:41:33 +00:00
|
|
|
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
|
|
|
|
{
|
2009-11-09 18:29:12 +00: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 18:15:18 +00:00
|
|
|
|
struct ui_file *str_file = NULL;
|
|
|
|
|
|
|
|
|
|
if (to_string)
|
|
|
|
|
{
|
|
|
|
|
str_file = mem_fileopen ();
|
|
|
|
|
|
|
|
|
|
make_cleanup_restore_ui_file (&gdb_stdout);
|
|
|
|
|
make_cleanup_restore_ui_file (&gdb_stderr);
|
|
|
|
|
make_cleanup_ui_file_delete (str_file);
|
|
|
|
|
|
|
|
|
|
gdb_stdout = str_file;
|
|
|
|
|
gdb_stderr = str_file;
|
|
|
|
|
}
|
2010-05-17 21:23:25 +00:00
|
|
|
|
|
2009-11-09 18:29:12 +00:00
|
|
|
|
execute_command (copy, from_tty);
|
2010-06-25 18:15:18 +00:00
|
|
|
|
|
|
|
|
|
if (str_file)
|
|
|
|
|
result = ui_file_xstrdup (str_file, NULL);
|
|
|
|
|
else
|
|
|
|
|
result = NULL;
|
|
|
|
|
|
2009-11-09 18:29:12 +00:00
|
|
|
|
do_cleanups (cleanup);
|
2008-08-06 19:41:33 +00:00
|
|
|
|
}
|
|
|
|
|
GDB_PY_HANDLE_EXCEPTION (except);
|
|
|
|
|
|
2008-09-08 21:46:21 +00:00
|
|
|
|
/* Do any commands attached to breakpoint we stopped at. */
|
|
|
|
|
bpstat_do_actions ();
|
2008-08-06 19:41:33 +00:00
|
|
|
|
|
2010-06-25 18:15:18 +00:00
|
|
|
|
if (result)
|
|
|
|
|
{
|
|
|
|
|
PyObject *r = PyString_FromString (result);
|
|
|
|
|
xfree (result);
|
|
|
|
|
return r;
|
|
|
|
|
}
|
2008-08-06 19:41:33 +00:00
|
|
|
|
Py_RETURN_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-03 18:30:02 +00:00
|
|
|
|
/* Parse a string and evaluate it as an expression. */
|
|
|
|
|
static PyObject *
|
|
|
|
|
gdbpy_parse_and_eval (PyObject *self, PyObject *args)
|
|
|
|
|
{
|
|
|
|
|
char *expr_str;
|
|
|
|
|
struct value *result = NULL;
|
|
|
|
|
volatile struct gdb_exception except;
|
|
|
|
|
|
|
|
|
|
if (!PyArg_ParseTuple (args, "s", &expr_str))
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
|
|
|
|
{
|
|
|
|
|
result = parse_and_eval (expr_str);
|
|
|
|
|
}
|
|
|
|
|
GDB_PY_HANDLE_EXCEPTION (except);
|
|
|
|
|
|
|
|
|
|
return value_to_value_object (result);
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-18 06:25:22 +00:00
|
|
|
|
/* Read a file as Python code. STREAM is the input file; FILE is the
|
2010-04-15 17:45:57 +00:00
|
|
|
|
name of the file.
|
|
|
|
|
STREAM is not closed, that is the caller's responsibility. */
|
2010-01-18 06:25:22 +00:00
|
|
|
|
|
|
|
|
|
void
|
2010-04-15 17:45:57 +00:00
|
|
|
|
source_python_script (FILE *stream, const char *file)
|
2010-01-18 06:25:22 +00:00
|
|
|
|
{
|
2010-04-08 04:57:25 +00:00
|
|
|
|
struct cleanup *cleanup;
|
2010-01-18 06:25:22 +00:00
|
|
|
|
|
2010-04-08 04:57:25 +00:00
|
|
|
|
cleanup = ensure_python_env (get_current_arch (), current_language);
|
2010-01-18 06:25:22 +00:00
|
|
|
|
|
2010-05-19 21:57:24 +00:00
|
|
|
|
/* Note: If an exception occurs python will print the traceback and
|
|
|
|
|
clear the error indicator. */
|
2010-01-18 06:25:22 +00:00
|
|
|
|
PyRun_SimpleFile (stream, file);
|
|
|
|
|
|
2010-04-08 04:57:25 +00:00
|
|
|
|
do_cleanups (cleanup);
|
2010-01-18 06:25:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-08-06 19:41:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Printing. */
|
|
|
|
|
|
|
|
|
|
/* A python function to write a single string using gdb's filtered
|
|
|
|
|
output stream. */
|
|
|
|
|
static PyObject *
|
|
|
|
|
gdbpy_write (PyObject *self, PyObject *args)
|
|
|
|
|
{
|
|
|
|
|
char *arg;
|
2010-05-17 21:23:25 +00:00
|
|
|
|
|
2008-08-06 19:41:33 +00:00
|
|
|
|
if (! PyArg_ParseTuple (args, "s", &arg))
|
|
|
|
|
return NULL;
|
|
|
|
|
printf_filtered ("%s", arg);
|
|
|
|
|
Py_RETURN_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* A python function to flush gdb's filtered output stream. */
|
|
|
|
|
static PyObject *
|
|
|
|
|
gdbpy_flush (PyObject *self, PyObject *args)
|
|
|
|
|
{
|
|
|
|
|
gdb_flush (gdb_stdout);
|
|
|
|
|
Py_RETURN_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Print a python exception trace, or print nothing and clear the
|
|
|
|
|
python exception, depending on gdbpy_should_print_stack. Only call
|
|
|
|
|
this if a python exception is set. */
|
|
|
|
|
void
|
|
|
|
|
gdbpy_print_stack (void)
|
|
|
|
|
{
|
|
|
|
|
if (gdbpy_should_print_stack)
|
2010-05-19 23:32:24 +00: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. */
|
|
|
|
|
begin_line ();
|
|
|
|
|
}
|
2008-08-06 19:41:33 +00:00
|
|
|
|
else
|
|
|
|
|
PyErr_Clear ();
|
|
|
|
|
}
|
|
|
|
|
|
2009-05-28 00:40:24 +00:00
|
|
|
|
|
|
|
|
|
|
2010-04-15 19:54:13 +00: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 21:23:25 +00:00
|
|
|
|
|
2010-04-15 19:54:13 +00:00
|
|
|
|
if (!item || PyList_Append (list, item) == -1)
|
|
|
|
|
{
|
|
|
|
|
Py_DECREF (list);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-05-28 00:40:24 +00:00
|
|
|
|
/* The "current" objfile. This is set when gdb detects that a new
|
2010-04-23 16:20:13 +00: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 00:40:24 +00:00
|
|
|
|
static struct objfile *gdbpy_current_objfile;
|
|
|
|
|
|
2010-04-23 16:20:13 +00:00
|
|
|
|
/* Set the current objfile to OBJFILE and then read STREAM,FILE as
|
|
|
|
|
Python code. */
|
2009-05-28 00:40:24 +00:00
|
|
|
|
|
2010-04-23 16:20:13 +00:00
|
|
|
|
void
|
|
|
|
|
source_python_script_for_objfile (struct objfile *objfile,
|
|
|
|
|
FILE *stream, const char *file)
|
2009-05-28 00:40:24 +00: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 17:04:23 +00:00
|
|
|
|
cleanups = ensure_python_env (get_objfile_arch (objfile), current_language);
|
2009-05-28 00:40:24 +00:00
|
|
|
|
gdbpy_current_objfile = objfile;
|
|
|
|
|
|
2010-05-19 21:57:24 +00:00
|
|
|
|
/* Note: If an exception occurs python will print the traceback and
|
|
|
|
|
clear the error indicator. */
|
|
|
|
|
PyRun_SimpleFile (stream, file);
|
2009-05-28 00:40:24 +00:00
|
|
|
|
|
|
|
|
|
do_cleanups (cleanups);
|
|
|
|
|
gdbpy_current_objfile = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Return the current Objfile, or None if there isn't one. */
|
2010-04-23 16:20:13 +00:00
|
|
|
|
|
2009-05-28 00:40:24 +00: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 19:54:13 +00:00
|
|
|
|
|
2009-05-28 00:40:24 +00: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 21:23:25 +00:00
|
|
|
|
|
2009-05-28 00:40:24 +00:00
|
|
|
|
if (!item || PyList_Append (list, item) == -1)
|
|
|
|
|
{
|
|
|
|
|
Py_DECREF (list);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
2008-08-06 19:41:33 +00:00
|
|
|
|
#else /* HAVE_PYTHON */
|
|
|
|
|
|
|
|
|
|
/* Dummy implementation of the gdb "python" command. */
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
python_command (char *arg, int from_tty)
|
|
|
|
|
{
|
|
|
|
|
while (arg && *arg && isspace (*arg))
|
|
|
|
|
++arg;
|
|
|
|
|
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 21:23:25 +00:00
|
|
|
|
|
2008-08-06 19:41:33 +00:00
|
|
|
|
execute_control_command_untraced (l);
|
|
|
|
|
do_cleanups (cleanups);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
eval_python_from_control_command (struct command_line *cmd)
|
|
|
|
|
{
|
|
|
|
|
error (_("Python scripting is not supported in this copy of GDB."));
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-18 06:25:22 +00:00
|
|
|
|
void
|
2010-04-15 17:45:57 +00:00
|
|
|
|
source_python_script (FILE *stream, const char *file)
|
2010-01-18 06:25:22 +00:00
|
|
|
|
{
|
|
|
|
|
throw_error (UNSUPPORTED_ERROR,
|
|
|
|
|
_("Python scripting is not supported in this copy of GDB."));
|
|
|
|
|
}
|
|
|
|
|
|
2008-08-06 19:41:33 +00:00
|
|
|
|
#endif /* HAVE_PYTHON */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Lists for 'maint set python' commands. */
|
|
|
|
|
|
2010-04-23 16:20:13 +00:00
|
|
|
|
struct cmd_list_element *set_python_list;
|
|
|
|
|
struct cmd_list_element *show_python_list;
|
2008-08-06 19:41:33 +00:00
|
|
|
|
|
|
|
|
|
/* Function for use by 'maint set python' prefix command. */
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
set_python (char *args, int from_tty)
|
|
|
|
|
{
|
|
|
|
|
help_list (set_python_list, "maintenance set python ", -1, gdb_stdout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Function for use by 'maint show python' prefix command. */
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
show_python (char *args, int from_tty)
|
|
|
|
|
{
|
|
|
|
|
cmd_show_list (show_python_list, from_tty, "");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Initialize the Python code. */
|
|
|
|
|
|
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 16:14:50 +00:00
|
|
|
|
/* Provide a prototype to silence -Wmissing-prototypes. */
|
|
|
|
|
extern initialize_file_ftype _initialize_python;
|
|
|
|
|
|
2008-08-06 19:41:33 +00:00
|
|
|
|
void
|
|
|
|
|
_initialize_python (void)
|
|
|
|
|
{
|
|
|
|
|
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 */
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
add_prefix_cmd ("python", no_class, show_python,
|
|
|
|
|
_("Prefix command for python maintenance settings."),
|
2008-08-09 19:17:03 +00:00
|
|
|
|
&show_python_list, "maintenance show python ", 0,
|
2008-08-06 19:41:33 +00:00
|
|
|
|
&maintenance_show_cmdlist);
|
|
|
|
|
add_prefix_cmd ("python", no_class, set_python,
|
|
|
|
|
_("Prefix command for python maintenance settings."),
|
2008-08-09 19:17:03 +00:00
|
|
|
|
&set_python_list, "maintenance set python ", 0,
|
2008-08-06 19:41:33 +00:00
|
|
|
|
&maintenance_set_cmdlist);
|
|
|
|
|
|
|
|
|
|
add_setshow_boolean_cmd ("print-stack", class_maintenance,
|
|
|
|
|
&gdbpy_should_print_stack, _("\
|
|
|
|
|
Enable or disable printing of Python stack dump on error."), _("\
|
|
|
|
|
Show whether Python stack will be printed on error."), _("\
|
|
|
|
|
Enables or disables printing of Python stack traces."),
|
|
|
|
|
NULL, NULL,
|
|
|
|
|
&set_python_list,
|
|
|
|
|
&show_python_list);
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_PYTHON
|
2010-05-27 03:40:45 +00: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. */
|
|
|
|
|
Py_SetProgramName (concat (ldirname (python_libdir), SLASH_STRING, "bin",
|
|
|
|
|
SLASH_STRING, "python", NULL));
|
|
|
|
|
#endif
|
|
|
|
|
|
2008-08-06 19:41:33 +00:00
|
|
|
|
Py_Initialize ();
|
2008-11-21 14:59:56 +00:00
|
|
|
|
PyEval_InitThreads ();
|
2008-08-06 19:41:33 +00:00
|
|
|
|
|
|
|
|
|
gdb_module = Py_InitModule ("gdb", GdbMethods);
|
|
|
|
|
|
|
|
|
|
/* 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);
|
|
|
|
|
PyModule_AddStringConstant (gdb_module, "TARGET_CONFIG", (char*) target_name);
|
2010-06-24 22:52:04 +00:00
|
|
|
|
{
|
|
|
|
|
char *gdb_pythondir;
|
|
|
|
|
|
|
|
|
|
gdb_pythondir = concat (gdb_datadir, SLASH_STRING, "python", NULL);
|
|
|
|
|
PyModule_AddStringConstant (gdb_module, "PYTHONDIR", gdb_pythondir);
|
|
|
|
|
xfree (gdb_pythondir);
|
|
|
|
|
}
|
2008-08-06 19:41:33 +00:00
|
|
|
|
|
2010-05-25 15:27:17 +00:00
|
|
|
|
gdbpy_gdberror_exc = PyErr_NewException ("gdb.GdbError", NULL, NULL);
|
|
|
|
|
PyModule_AddObject (gdb_module, "GdbError", gdbpy_gdberror_exc);
|
|
|
|
|
|
2010-04-23 16:20:13 +00:00
|
|
|
|
gdbpy_initialize_auto_load ();
|
2008-10-16 03:54:00 +00:00
|
|
|
|
gdbpy_initialize_values ();
|
2009-03-30 19:54:33 +00:00
|
|
|
|
gdbpy_initialize_frames ();
|
2009-02-06 21:33:59 +00: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 21:18:28 +00: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 03:03:56 +00:00
|
|
|
|
gdbpy_initialize_functions ();
|
2010-04-29 15:45:57 +00:00
|
|
|
|
gdbpy_initialize_parameters ();
|
2009-05-28 00:47:20 +00:00
|
|
|
|
gdbpy_initialize_types ();
|
2010-04-15 19:54:13 +00:00
|
|
|
|
gdbpy_initialize_pspace ();
|
2009-05-28 00:40:24 +00:00
|
|
|
|
gdbpy_initialize_objfile ();
|
2010-04-09 09:41:43 +00:00
|
|
|
|
gdbpy_initialize_breakpoints ();
|
2010-01-14 08:03:37 +00:00
|
|
|
|
gdbpy_initialize_lazy_string ();
|
2010-06-28 21:16:04 +00:00
|
|
|
|
gdbpy_initialize_thread ();
|
|
|
|
|
gdbpy_initialize_inferior ();
|
2008-10-16 03:54:00 +00:00
|
|
|
|
|
2008-08-06 19:41:33 +00:00
|
|
|
|
PyRun_SimpleString ("import gdb");
|
2009-05-28 01:05:14 +00:00
|
|
|
|
PyRun_SimpleString ("gdb.pretty_printers = []");
|
2008-08-06 19:41:33 +00:00
|
|
|
|
|
2009-05-28 01:05:14 +00: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 21:33:59 +00:00
|
|
|
|
gdbpy_doc_cst = PyString_FromString ("__doc__");
|
2010-06-04 18:18:28 +00:00
|
|
|
|
gdbpy_enabled_cst = PyString_FromString ("enabled");
|
2009-02-06 21:33:59 +00:00
|
|
|
|
|
2008-08-06 19:41:33 +00:00
|
|
|
|
/* Create a couple objects which are used for Python's stdout and
|
|
|
|
|
stderr. */
|
|
|
|
|
PyRun_SimpleString ("\
|
|
|
|
|
import sys\n\
|
|
|
|
|
class GdbOutputFile:\n\
|
|
|
|
|
def close(self):\n\
|
|
|
|
|
# Do nothing.\n\
|
|
|
|
|
return None\n\
|
|
|
|
|
\n\
|
|
|
|
|
def isatty(self):\n\
|
|
|
|
|
return False\n\
|
|
|
|
|
\n\
|
|
|
|
|
def write(self, s):\n\
|
|
|
|
|
gdb.write(s)\n\
|
|
|
|
|
\n\
|
|
|
|
|
def writelines(self, iterable):\n\
|
|
|
|
|
for line in iterable:\n\
|
|
|
|
|
self.write(line)\n\
|
|
|
|
|
\n\
|
|
|
|
|
def flush(self):\n\
|
|
|
|
|
gdb.flush()\n\
|
|
|
|
|
\n\
|
|
|
|
|
sys.stderr = GdbOutputFile()\n\
|
|
|
|
|
sys.stdout = GdbOutputFile()\n\
|
2010-06-24 22:52:04 +00:00
|
|
|
|
\n\
|
|
|
|
|
# GDB's python scripts are stored inside gdb.PYTHONDIR. So insert\n\
|
|
|
|
|
# that directory name at the start of sys.path to allow the Python\n\
|
|
|
|
|
# interpreter to find them.\n\
|
|
|
|
|
sys.path.insert(0, gdb.PYTHONDIR)\n\
|
|
|
|
|
\n\
|
|
|
|
|
# The gdb module is implemented in C rather than in Python. As a result,\n\
|
|
|
|
|
# the associated __init.py__ script is not not executed by default when\n\
|
|
|
|
|
# the gdb module gets imported. Execute that script manually if it exists.\n\
|
|
|
|
|
gdb.__path__ = [gdb.PYTHONDIR + '/gdb']\n\
|
|
|
|
|
from os.path import exists\n\
|
|
|
|
|
ipy = gdb.PYTHONDIR + '/gdb/__init__.py'\n\
|
|
|
|
|
if exists (ipy):\n\
|
|
|
|
|
execfile (ipy)\n\
|
2008-08-06 19:41:33 +00:00
|
|
|
|
");
|
2008-11-21 14:59:56 +00:00
|
|
|
|
|
|
|
|
|
/* Release the GIL while gdb runs. */
|
|
|
|
|
PyThreadState_Swap (NULL);
|
|
|
|
|
PyEval_ReleaseLock ();
|
|
|
|
|
|
2008-08-06 19:41:33 +00:00
|
|
|
|
#endif /* HAVE_PYTHON */
|
|
|
|
|
}
|
2009-02-05 16:40:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if HAVE_PYTHON
|
|
|
|
|
|
|
|
|
|
static PyMethodDef GdbMethods[] =
|
|
|
|
|
{
|
|
|
|
|
{ "history", gdbpy_history, METH_VARARGS,
|
|
|
|
|
"Get a value from history" },
|
2010-06-25 18:15:18 +00:00
|
|
|
|
{ "execute", (PyCFunction) execute_gdb_command, METH_VARARGS | METH_KEYWORDS,
|
2009-02-05 16:40:34 +00:00
|
|
|
|
"Execute a gdb command" },
|
2009-05-28 16:49:55 +00:00
|
|
|
|
{ "parameter", gdbpy_parameter, METH_VARARGS,
|
2009-02-05 16:40:34 +00:00
|
|
|
|
"Return a gdb parameter's value" },
|
|
|
|
|
|
2010-04-09 09:41:43 +00:00
|
|
|
|
{ "breakpoints", gdbpy_breakpoints, METH_NOARGS,
|
|
|
|
|
"Return a tuple of all breakpoint objects" },
|
|
|
|
|
|
2009-05-28 01:09:20 +00:00
|
|
|
|
{ "default_visualizer", gdbpy_default_visualizer, METH_VARARGS,
|
|
|
|
|
"Find the default visualizer for a Value." },
|
|
|
|
|
|
2010-04-15 19:54:13 +00: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 00:40:24 +00: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." },
|
|
|
|
|
|
2009-03-30 19:54:33 +00: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 00:47:20 +00: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 21:18:28 +00: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)." },
|
|
|
|
|
{ "block_for_pc", gdbpy_block_for_pc, METH_VARARGS,
|
|
|
|
|
"Return the block containing the given pc value, or None." },
|
2009-12-03 18:30:02 +00: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."
|
|
|
|
|
},
|
|
|
|
|
|
2010-03-05 20:18:19 +00: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 15:27:17 +00: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."
|
|
|
|
|
},
|
|
|
|
|
|
2009-02-05 16:40:34 +00:00
|
|
|
|
{ "write", gdbpy_write, METH_VARARGS,
|
|
|
|
|
"Write a string using gdb's filtered stream." },
|
|
|
|
|
{ "flush", gdbpy_flush, METH_NOARGS,
|
|
|
|
|
"Flush gdb's filtered stdout stream." },
|
2010-06-28 21:16:04 +00:00
|
|
|
|
{ "selected_thread", gdbpy_selected_thread, METH_NOARGS,
|
|
|
|
|
"selected_thread () -> gdb.InferiorThread.\n\
|
|
|
|
|
Return the selected thread object." },
|
|
|
|
|
{ "inferiors", gdbpy_inferiors, METH_NOARGS,
|
|
|
|
|
"inferiors () -> (gdb.Inferior, ...).\n\
|
|
|
|
|
Return a tuple containing all inferiors." },
|
2009-02-05 16:40:34 +00:00
|
|
|
|
{NULL, NULL, 0, NULL}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif /* HAVE_PYTHON */
|