2008-10-16 14:46:20 +00:00
|
|
|
|
/* Python interface to values.
|
|
|
|
|
|
2014-01-01 03:54:24 +00:00
|
|
|
|
Copyright (C) 2008-2014 Free Software Foundation, Inc.
|
2008-10-16 14:46:20 +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"
|
|
|
|
|
#include "charset.h"
|
|
|
|
|
#include "value.h"
|
|
|
|
|
#include "exceptions.h"
|
|
|
|
|
#include "language.h"
|
|
|
|
|
#include "dfp.h"
|
gdb
* varobj.c (value_get_print_value): Include valprint.h.
(value_get_print_value): Use get_formatted_print_options.
* value.h (struct value_print_options): Declare.
(value_print, val_print, common_val_print, val_print_string):
Update.
* value.c: Include valprint.h.
(show_values): Use get_user_print_options.
(show_convenience): Likewise.
* valprint.h (prettyprint_arrays, prettyprint_structs): Don't
declare.
(struct value_print_options): New type.
(vtblprint, unionprint, addressprint, objectprint, print_max,
inspect_it, repeat_count_threshold, output_format,
stop_print_at_null): Don't declare.
(user_print_options, get_user_print_options,
get_raw_print_options, get_formatted_print_options): Declare.
(print_array_indexes_p): Don't declare.
(maybe_print_array_index, val_print_array_elements): Update.
* valprint.c (print_max): Remove.
(user_print_options): New global.
(get_user_print_options, get_raw_print_options,
get_formatted_print_options): New functions.
(print_array_indexes, repeat_count_threshold, stop_print_at_null,
prettyprint_structs, prettyprint_arrays, unionprint,
addressprint): Remove.
(val_print): Remove format, deref_ref, pretty arguments; add
options. Update.
(common_val_print): Likewise.
(print_array_indexes_p): Remove.
(maybe_print_array_index): Remove format, pretty arguments; add
options. Update.
(val_print_array_elements): Remove format, deref_ref, pretty
arguments; add options. Update.
(val_print_string): Add options argument. Update.
(_initialize_valprint): Use user_print_options.
(output_format): Remove.
(set_output_radix_1): Use user_print_options.
* typeprint.c: Include valprint.h.
(objectprint): Don't declare.
(whatis_exp): Use get_user_print_options.
* tui/tui-regs.c: Include valprint.h.
(tui_register_format): Use get_formatted_print_options.
* tracepoint.c: Include valprint.h.
(addressprint): Don't declare.
(trace_mention): Use get_user_print_options.
(tracepoints_info): Likewise.
* stack.c (print_frame_args): Use get_raw_print_options.
(print_frame_info): Use get_user_print_options.
(print_frame): Likewise.
* sh64-tdep.c: Include valprint.h
(sh64_do_register): Use get_formatted_print_options.
* scm-valprint.c (scm_inferior_print): Remove format, deref_ref,
pretty arguments; add options.
(scm_scmlist_print): Likewise. Update.
(scm_scmval_print): Likewise.
(scm_val_print): Likewise.
(scm_value_print): Remove format, pretty arguments; add options.
Update.
* scm-lang.h (scm_value_print, scm_val_print, scm_scmval_print):
Update.
* scm-lang.c (scm_printstr): Add options argument.
* python/python-value.c: Include valprint.h.
(valpy_str): Use get_user_print_options.
* printcmd.c: Include valprint.h.
(addressprint): Don't declare.
(inspect_it): Remove.
(print_formatted): Remove format option; add options. Update.
(print_scalar_formatted): Likewise.
(print_address_demangle): Use get_user_print_options.
(do_examine): Use get_formatted_print_options.
(print_command_1): Likewise.
(output_command): Use get_formatted_print_options.
(do_one_display): Likewise.
(print_variable_value): Use get_user_print_options.
* p-valprint.c (pascal_val_print): Remove format, deref_ref,
pretty arguments; add options. Update.
(pascal_value_print): Remove format, pretty arguments; add
options. Update.
(vtblprint, objectprint): Don't declare.
(pascal_static_field_print): Remove.
(pascal_object_print_value_fields): Remove format, pretty
arguments; add options. Update.
(pascal_object_print_static_field): Likewise.
(_initialize_pascal_valprint): Use user_print_options. Update.
* p-lang.h (pascal_val_print, pascal_value_print,
pascal_printstr, pascal_object_print_value_fields): Update.
(vtblprint, static_field_print): Don't declare.
* p-lang.c (pascal_printstr): Add options argument. Update.
* objc-lang.c (objc_printstr): Add options argument. Update.
* mt-tdep.c: Include valprint.h.
(mt_registers_info): Use get_raw_print_options.
* mips-tdep.c: Include valprint.h.
(mips_print_fp_register): Use get_formatted_print_options.
(mips_print_register): Likewise.
* mi/mi-main.c: Include valprint.h.
(get_register): Use get_user_print_options.
(mi_cmd_data_evaluate_expression): Likewise.
(mi_cmd_data_read_memory): Use get_formatted_print_options.
* mi/mi-cmd-stack.c: Include valprint.h.
(list_args_or_locals): Use get_raw_print_options.
* m2-valprint.c (print_function_pointer_address): Add addressprint
argument.
(m2_print_long_set): Remove format, pretty arguments.
(m2_print_unbounded_array): Remove format, deref_ref, pretty
arguments; add options. Update.
(print_unpacked_pointer): Remove format argument; add options.
Now static. Update.
(print_variable_at_address): Remove format, deref_ref, pretty
arguments; add options. Update.
(m2_print_array_contents): Likewise.
(m2_val_print): Likewise.
* m2-lang.h (m2_val_print): Update.
* m2-lang.c (m2_printstr): Add options argument. Update.
* language.h (struct value_print_options): Declare.
(struct language_defn) <la_printstr>: Add options argument.
<la_val_print>: Remove format, deref_ref, pretty argument; add
options.
<la_value_print>: Remove format, pretty arguments; add options.
<la_print_array_index>: Likewise.
(LA_VAL_PRINT, LA_VALUE_PRINT, LA_PRINT_STRING,
LA_PRINT_ARRAY_INDEX): Update.
(default_print_array_index): Update.
* language.c (default_print_array_index): Remove format, pretty
arguments; add options. Update.
(unk_lang_printstr): Add options argument.
(unk_lang_val_print): Remove format, deref_ref, pretty arguments;
add options.
(unk_lang_value_print): Remove format, pretty arguments; add
options.
* jv-valprint.c (java_value_print): Remove format, pretty
arguments; add options. Update.
(java_print_value_fields): Likewise.
(java_val_print): Remove format, deref_ref, pretty arguments; add
options. Update.
* jv-lang.h (java_val_print, java_value_print): Declare.
* infcmd.c: Include valprint.h.
(print_return_value): Use get_raw_print_options.
(default_print_registers_info): Use get_user_print_options,
get_formatted_print_options.
(registers_info): Use get_formatted_print_options.
* gdbtypes.h (struct value_print_options): Declare.
(print_scalar_formatted): Update.
* f-valprint.c (f77_print_array_1): Remove format, deref_ref,
pretty arguments; add options. Update.
(f77_print_array): Likewise.
(f_val_print): Likewise.
* f-lang.h (f_val_print): Update.
* f-lang.c (f_printstr): Add options argument. Update.
(c_value_print): Update declaration.
* expprint.c: Include valprint.h.
(print_subexp_standard): Use get_raw_print_options,
get_user_print_options.
* eval.c: Include valprint.h.
(objectprint): Don't declare.
(evaluate_subexp_standard): Use get_user_print_options.
* cp-valprint.c (vtblprint, objectprint, static_field_print):
Remove.
(cp_print_value_fields): Remove format, pretty arguments; add
options. Update.
(cp_print_value): Likewise.
(cp_print_static_field): Likewise.
(_initialize_cp_valprint): Use user_print_options. Update.
* c-valprint.c (print_function_pointer_address): Add addressprint
argument.
(c_val_print): Remove format, deref_ref, pretty arguments; add
options. Update.
(c_value_print): Add options argument. Update.
* c-lang.h (c_val_print, c_value_print, c_printstr): Update.
(vtblprint, static_field_print): Don't declare.
(cp_print_value_fields): Update.
* c-lang.c (c_printstr): Add options argument. Update.
* breakpoint.c: Include valprint.h.
(addressprint): Don't declare.
(watchpoint_value_print): Use get_user_print_options.
(print_one_breakpoint_location): Likewise.
(breakpoint_1, print_it_catch_fork, print_it_catch_vfork, mention,
print_exception_catchpoint): Likewise.
* auxv.c (fprint_target_auxv): Don't declare addressprint. Use
get_user_print_options.
* ada-valprint.c (struct ada_val_print_args): Remove format,
deref_ref, and pretty; add options.
(print_optional_low_bound): Add options argument.
(val_print_packed_array_elements): Remove format and pretty
arguments; add options. Update.
(printstr): Add options argument. Update.
(ada_printstr): Likewise.
(ada_val_print): Remove format, deref_ref, pretty arguments; add
options argument. Update.
(ada_val_print_stub): Update.
(ada_val_print_array): Remove format, deref_ref, pretty arguments;
add options. Update.
(ada_val_print_1): Likewise.
(print_variant_part): Likewise.
(ada_value_print): Remove format, pretty arguments; add options.
Update.
(print_record): Likewise.
(print_field_values): Likewise.
* ada-lang.h (ada_val_print, ada_value_print, ada_printstr):
Update.
* ada-lang.c (ada_print_array_index): Add options argument; remove
format and pretty arguments.
(print_one_exception): Use get_user_print_options.
gdb/testsuite
* gdb.base/exprs.exp (test_expr): Add enum formatting tests.
2008-10-28 17:19:58 +00:00
|
|
|
|
#include "valprint.h"
|
2010-07-27 12:40:42 +00:00
|
|
|
|
#include "infcall.h"
|
2010-08-23 20:29:19 +00:00
|
|
|
|
#include "expression.h"
|
2010-08-30 20:28:31 +00:00
|
|
|
|
#include "cp-abi.h"
|
2012-03-01 21:06:54 +00:00
|
|
|
|
#include "python.h"
|
2008-10-16 14:46:20 +00:00
|
|
|
|
|
|
|
|
|
#include "python-internal.h"
|
|
|
|
|
|
|
|
|
|
/* Even though Python scalar types directly map to host types, we use
|
2011-02-26 02:07:10 +00:00
|
|
|
|
target types here to remain consistent with the values system in
|
2008-10-16 14:46:20 +00:00
|
|
|
|
GDB (which uses target arithmetic). */
|
|
|
|
|
|
|
|
|
|
/* Python's integer type corresponds to C's long type. */
|
* 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
|
|
|
|
#define builtin_type_pyint builtin_type (python_gdbarch)->builtin_long
|
2008-10-16 14:46:20 +00:00
|
|
|
|
|
|
|
|
|
/* Python's float type corresponds to C's double type. */
|
* 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
|
|
|
|
#define builtin_type_pyfloat builtin_type (python_gdbarch)->builtin_double
|
2008-10-16 14:46:20 +00:00
|
|
|
|
|
|
|
|
|
/* Python's long type corresponds to C's long long type. */
|
* 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
|
|
|
|
#define builtin_type_pylong builtin_type (python_gdbarch)->builtin_long_long
|
2008-10-16 14:46:20 +00:00
|
|
|
|
|
2010-06-28 21:16:04 +00:00
|
|
|
|
/* Python's long type corresponds to C's long long type. Unsigned version. */
|
|
|
|
|
#define builtin_type_upylong builtin_type \
|
|
|
|
|
(python_gdbarch)->builtin_unsigned_long_long
|
|
|
|
|
|
2008-10-16 14:46:20 +00:00
|
|
|
|
#define builtin_type_pybool \
|
* 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
|
|
|
|
language_bool_type (python_language, python_gdbarch)
|
2008-10-16 14:46:20 +00:00
|
|
|
|
|
2009-06-17 18:47:35 +00:00
|
|
|
|
#define builtin_type_pychar \
|
* 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
|
|
|
|
language_string_char_type (python_language, python_gdbarch)
|
2009-06-17 18:47:35 +00:00
|
|
|
|
|
2009-08-13 18:39:20 +00:00
|
|
|
|
typedef struct value_object {
|
2008-10-16 14:46:20 +00:00
|
|
|
|
PyObject_HEAD
|
2009-08-13 18:39:20 +00:00
|
|
|
|
struct value_object *next;
|
|
|
|
|
struct value_object *prev;
|
2008-10-16 14:46:20 +00:00
|
|
|
|
struct value *value;
|
2009-03-29 21:11:11 +00:00
|
|
|
|
PyObject *address;
|
2009-05-28 00:47:20 +00:00
|
|
|
|
PyObject *type;
|
2010-08-30 20:28:31 +00:00
|
|
|
|
PyObject *dynamic_type;
|
2008-10-16 14:46:20 +00:00
|
|
|
|
} value_object;
|
|
|
|
|
|
2009-08-13 18:39:20 +00:00
|
|
|
|
/* List of all values which are currently exposed to Python. It is
|
|
|
|
|
maintained so that when an objfile is discarded, preserve_values
|
|
|
|
|
can copy the values' types if needed. */
|
|
|
|
|
/* This variable is unnecessarily initialized to NULL in order to
|
|
|
|
|
work around a linker bug on MacOS. */
|
|
|
|
|
static value_object *values_in_python = NULL;
|
|
|
|
|
|
2008-10-16 14:46:20 +00:00
|
|
|
|
/* Called by the Python interpreter when deallocating a value object. */
|
|
|
|
|
static void
|
|
|
|
|
valpy_dealloc (PyObject *obj)
|
|
|
|
|
{
|
|
|
|
|
value_object *self = (value_object *) obj;
|
|
|
|
|
|
2009-08-13 18:39:20 +00:00
|
|
|
|
/* Remove SELF from the global list. */
|
|
|
|
|
if (self->prev)
|
|
|
|
|
self->prev->next = self->next;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
gdb_assert (values_in_python == self);
|
|
|
|
|
values_in_python = self->next;
|
|
|
|
|
}
|
|
|
|
|
if (self->next)
|
|
|
|
|
self->next->prev = self->prev;
|
2008-10-16 14:46:20 +00:00
|
|
|
|
|
2009-03-29 21:19:40 +00:00
|
|
|
|
value_free (self->value);
|
2009-03-29 21:11:11 +00:00
|
|
|
|
|
|
|
|
|
if (self->address)
|
|
|
|
|
/* Use braces to appease gcc warning. *sigh* */
|
|
|
|
|
{
|
|
|
|
|
Py_DECREF (self->address);
|
|
|
|
|
}
|
|
|
|
|
|
2009-05-28 00:47:20 +00:00
|
|
|
|
if (self->type)
|
|
|
|
|
{
|
|
|
|
|
Py_DECREF (self->type);
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-30 20:28:31 +00:00
|
|
|
|
Py_XDECREF (self->dynamic_type);
|
|
|
|
|
|
2012-12-12 16:47:30 +00:00
|
|
|
|
Py_TYPE (self)->tp_free (self);
|
2008-10-16 14:46:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-08-13 18:39:20 +00:00
|
|
|
|
/* Helper to push a Value object on the global list. */
|
|
|
|
|
static void
|
|
|
|
|
note_value (value_object *value_obj)
|
|
|
|
|
{
|
|
|
|
|
value_obj->next = values_in_python;
|
|
|
|
|
if (value_obj->next)
|
|
|
|
|
value_obj->next->prev = value_obj;
|
|
|
|
|
value_obj->prev = NULL;
|
|
|
|
|
values_in_python = value_obj;
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-13 13:24:40 +00:00
|
|
|
|
/* Called when a new gdb.Value object needs to be allocated. Returns NULL on
|
|
|
|
|
error, with a python exception set. */
|
2008-10-16 14:46:20 +00:00
|
|
|
|
static PyObject *
|
|
|
|
|
valpy_new (PyTypeObject *subtype, PyObject *args, PyObject *keywords)
|
|
|
|
|
{
|
|
|
|
|
struct value *value = NULL; /* Initialize to appease gcc warning. */
|
|
|
|
|
value_object *value_obj;
|
|
|
|
|
|
|
|
|
|
if (PyTuple_Size (args) != 1)
|
|
|
|
|
{
|
|
|
|
|
PyErr_SetString (PyExc_TypeError, _("Value object creation takes only "
|
|
|
|
|
"1 argument"));
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
value_obj = (value_object *) subtype->tp_alloc (subtype, 1);
|
|
|
|
|
if (value_obj == NULL)
|
|
|
|
|
{
|
|
|
|
|
PyErr_SetString (PyExc_MemoryError, _("Could not allocate memory to "
|
|
|
|
|
"create Value object."));
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2009-02-04 21:55:40 +00:00
|
|
|
|
value = convert_value_from_python (PyTuple_GetItem (args, 0));
|
|
|
|
|
if (value == NULL)
|
2008-10-16 14:46:20 +00:00
|
|
|
|
{
|
|
|
|
|
subtype->tp_free (value_obj);
|
2009-02-04 21:55:40 +00:00
|
|
|
|
return NULL;
|
2008-10-16 14:46:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
value_obj->value = value;
|
2011-12-22 19:51:10 +00:00
|
|
|
|
release_value_or_incref (value);
|
2009-03-29 21:11:11 +00:00
|
|
|
|
value_obj->address = NULL;
|
2009-05-28 00:47:20 +00:00
|
|
|
|
value_obj->type = NULL;
|
2010-08-30 20:28:31 +00:00
|
|
|
|
value_obj->dynamic_type = NULL;
|
2009-08-13 18:39:20 +00:00
|
|
|
|
note_value (value_obj);
|
2008-10-16 14:46:20 +00:00
|
|
|
|
|
|
|
|
|
return (PyObject *) value_obj;
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-13 18:39:20 +00:00
|
|
|
|
/* Iterate over all the Value objects, calling preserve_one_value on
|
|
|
|
|
each. */
|
|
|
|
|
void
|
Extension Language API
* configure.ac (libpython checking): Remove all but python.o from
CONFIG_OBS. Remove all but python.c from CONFIG_SRCS.
* configure: Regenerate.
* Makefile.in (SFILES): Add extension.c.
(HFILES_NO_SRCDIR): Add extension.h, extension-priv.h
(COMMON_OBS): Add extension.o.
* extension.h: New file.
* extension-priv.h: New file.
* extension.c: New file.
* python/python-internal.h: #include "extension.h".
(gdbpy_auto_load_enabled): Declare.
(gdbpy_apply_val_pretty_printer): Declare.
(gdbpy_apply_frame_filter): Declare.
(gdbpy_preserve_values): Declare.
(gdbpy_breakpoint_cond_says_stop): Declare.
(gdbpy_breakpoint_has_cond): Declare.
(void source_python_script_for_objfile): Delete.
* python/python.c: #include "extension-priv.h".
Delete inclusion of "observer.h".
(extension_language_python): Moved here and renamed from
script_language_python in py-auto-load.c.
Redefined to be of type extension_language_defn.
(python_extension_script_ops): New global.
(python_extension_ops): New global.
(struct python_env): New member previous_active.
(restore_python_env): Call restore_active_ext_lang.
(ensure_python_env): Call set_active_ext_lang.
(gdbpy_clear_quit_flag): Renamed from clear_quit_flag, made static.
New arg extlang.
(gdbpy_set_quit_flag): Renamed from set_quit_flag, made static.
New arg extlang.
(gdbpy_check_quit_flag): Renamed from check_quit_flag, made static.
New arg extlang.
(gdbpy_eval_from_control_command): Renamed from
eval_python_from_control_command, made static. New arg extlang.
(gdbpy_source_script) Renamed from source_python_script, made static.
New arg extlang.
(gdbpy_before_prompt_hook): Renamed from before_prompt_hook. Change
result to int. New arg extlang.
(gdbpy_source_objfile_script): Renamed from
source_python_script_for_objfile, made static. New arg extlang.
(gdbpy_start_type_printers): Renamed from start_type_printers, made
static. New args extlang, extlang_printers. Change result type to
"void".
(gdbpy_apply_type_printers): Renamed from apply_type_printers, made
static. New arg extlang. Rename arg printers to extlang_printers
and change type to ext_lang_type_printers *.
(gdbpy_free_type_printers): Renamed from free_type_printers, made
static. Replace argument arg with extlang, extlang_printers.
(!HAVE_PYTHON, eval_python_from_control_command): Delete.
(!HAVE_PYTHON, source_python_script): Delete.
(!HAVE_PYTHON, gdbpy_should_stop): Delete.
(!HAVE_PYTHON, gdbpy_breakpoint_has_py_cond): Delete.
(!HAVE_PYTHON, start_type_printers): Delete.
(!HAVE_PYTHON, apply_type_printers): Delete.
(!HAVE_PYTHON, free_type_printers): Delete.
(_initialize_python): Delete call to observer_attach_before_prompt.
(finalize_python): Set/restore active extension language.
(gdbpy_finish_initialization) Renamed from
finish_python_initialization, made static. New arg extlang.
(gdbpy_initialized): New function.
* python/python.h: #include "extension.h". Delete #include
"value.h", "mi/mi-cmds.h".
(extension_language_python): Declare.
(GDBPY_AUTO_FILE_NAME): Delete.
(enum py_bt_status): Moved to extension.h and renamed to
ext_lang_bt_status.
(enum frame_filter_flags): Moved to extension.h.
(enum py_frame_args): Moved to extension.h and renamed to
ext_lang_frame_args.
(finish_python_initialization): Delete.
(eval_python_from_control_command): Delete.
(source_python_script): Delete.
(apply_val_pretty_printer): Delete.
(apply_frame_filter): Delete.
(preserve_python_values): Delete.
(gdbpy_script_language_defn): Delete.
(gdbpy_should_stop, gdbpy_breakpoint_has_py_cond): Delete.
(start_type_printers, apply_type_printers, free_type_printers): Delete.
* auto-load.c: #include "extension.h".
(GDB_AUTO_FILE_NAME): Delete.
(auto_load_gdb_scripts_enabled): Make public. New arg extlang.
(script_language_gdb): Delete, moved to extension.c and renamed to
extension_language_gdb.
(source_gdb_script_for_objfile): Delete.
(auto_load_pspace_info): New member unsupported_script_warning_printed.
(loaded_script): Change type of language member to
struct extension_language_defn *.
(init_loaded_scripts_info): Initialize
unsupported_script_warning_printed.
(maybe_add_script): Make static. Change type of language arg to
struct extension_language_defn *.
(clear_section_scripts): Reset unsupported_script_warning_printed.
(auto_load_objfile_script_1): Rewrite to use extension language API.
(auto_load_objfile_script): Make public. Remove support-compiled-in
and auto-load-enabled checks, moved to auto_load_scripts_for_objfile.
(source_section_scripts): Rewrite to use extension language API.
(load_auto_scripts_for_objfile): Rewrite to use
auto_load_scripts_for_objfile.
(collect_matching_scripts_data): Change type of language member to
struct extension_language_defn *.
(auto_load_info_scripts): Change type of language arg to
struct extension_language_defn *.
(unsupported_script_warning_print): New function.
(script_not_found_warning_print): Make static.
(_initialize_auto_load): Rewrite construction of scripts-directory
help.
* auto-load.h (struct objfile): Add forward decl.
(struct script_language): Delete.
(struct auto_load_pspace_info): Add forward decl.
(struct extension_language_defn): Add forward decl.
(maybe_add_script): Delete.
(auto_load_objfile_script): Declare.
(script_not_found_warning_print): Delete.
(auto_load_info_scripts): Update prototype.
(auto_load_gdb_scripts_enabled): Declare.
* python/py-auto-load.c (gdbpy_auto_load_enabled): Renamed from
auto_load_python_scripts_enabled and made public.
(script_language_python): Delete, moved to python.c.
(gdbpy_script_language_defn): Delete.
(info_auto_load_python_scripts): Update to use
extension_language_python.
* breakpoint.c (condition_command): Replace call to
gdbpy_breakpoint_has_py_cond with call to get_breakpoint_cond_ext_lang.
(bpstat_check_breakpoint_conditions): Replace call to gdbpy_should_stop
with call to breakpoint_ext_lang_cond_says_stop.
* python/py-breakpoint.c (gdbpy_breakpoint_cond_says_stop): Renamed
from gdbpy_should_stop. Change result type to enum scr_bp_stop.
New arg slang. Return SCR_BP_STOP_UNSET if py_bp_object is NULL.
(gdbpy_breakpoint_has_cond): Renamed from gdbpy_breakpoint_has_py_cond.
New arg slang.
(local_setattro): Print name of extension language with existing
stop condition.
* valprint.c (val_print, value_print): Update to call
apply_ext_lang_val_pretty_printer.
* cp-valprint.c (cp_print_value): Update call to
apply_ext_lang_val_pretty_printer.
* python/py-prettyprint.c: Remove #ifdef HAVE_PYTHON.
(gdbpy_apply_val_pretty_printer): Renamed from
apply_val_pretty_printer. New arg extlang.
(!HAVE_PYTHON, apply_val_pretty_printer): Delete.
* cli/cli-cmds.c (source_script_from_stream): Rewrite to use
extension language API.
* cli/cli-script.c (execute_control_command): Update to call
eval_ext_lang_from_control_command.
* mi/mi-cmd-stack.c (mi_cmd_stack_list_frames): Update to use
enum ext_lang_bt_status values. Update call to
apply_ext_lang_frame_filter.
(mi_cmd_stack_list_locals): Ditto.
(mi_cmd_stack_list_args): Ditto.
(mi_cmd_stack_list_variables): Ditto.
* mi/mi-main.c: Delete #include "python/python-internal.h".
Add #include "extension.h".
(mi_cmd_list_features): Replace reference to python internal variable
gdb_python_initialized with call to ext_lang_initialized_p.
* stack.c (backtrace_command_1): Update to use enum ext_lang_bt_status.
Update to use enum ext_lang_frame_args. Update to call
apply_ext_lang_frame_filter.
* python/py-framefilter.c (extract_sym): Update to use enum
ext_lang_bt_status.
(extract_value, py_print_type, py_print_value): Ditto.
(py_print_single_arg, enumerate_args, enumerate_locals): Ditto.
(py_mi_print_variables, py_print_locals, py_print_args): Ditto.
(py_print_frame): Ditto.
(gdbpy_apply_frame_filter): Renamed from apply_frame_filter.
New arg extlang. Update to use enum ext_lang_bt_status.
* top.c (gdb_init): Delete #ifdef HAVE_PYTHON call to
finish_python_initialization. Replace with call to
finish_ext_lang_initialization.
* typeprint.c (do_free_global_table): Update to call
free_ext_lang_type_printers.
(create_global_typedef_table): Update to call
start_ext_lang_type_printers.
(find_global_typedef): Update to call apply_ext_lang_type_printers.
* typeprint.h (struct ext_lang_type_printers): Add forward decl.
(type_print_options): Change type of global_printers from "void *"
to "struct ext_lang_type_printers *".
* value.c (preserve_values): Update to call preserve_ext_lang_values.
* python/py-value.c: Remove #ifdef HAVE_PYTHON.
(gdbpy_preserve_values): Renamed from preserve_python_values.
New arg extlang.
(!HAVE_PYTHON, preserve_python_values): Delete.
* utils.c (quit_flag): Delete, moved to extension.c.
(clear_quit_flag, set_quit_flag, check_quit_flag): Delete, moved to
extension.c.
* eval.c: Delete #include "python/python.h".
* main.c: Delete #include "python/python.h".
* defs.h: Update comment.
testsuite/
* gdb.python/py-breakpoint.exp (test_bkpt_eval_funcs): Update expected
output.
* gdb.gdb/python-interrupts.exp: New file.
2014-02-06 03:27:58 +00:00
|
|
|
|
gdbpy_preserve_values (const struct extension_language_defn *extlang,
|
|
|
|
|
struct objfile *objfile, htab_t copied_types)
|
2009-08-13 18:39:20 +00:00
|
|
|
|
{
|
|
|
|
|
value_object *iter;
|
|
|
|
|
|
|
|
|
|
for (iter = values_in_python; iter; iter = iter->next)
|
|
|
|
|
preserve_one_value (iter->value, objfile, copied_types);
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-16 14:46:20 +00:00
|
|
|
|
/* Given a value of a pointer type, apply the C unary * operator to it. */
|
|
|
|
|
static PyObject *
|
|
|
|
|
valpy_dereference (PyObject *self, PyObject *args)
|
|
|
|
|
{
|
|
|
|
|
volatile struct gdb_exception except;
|
2012-01-03 19:27:52 +00:00
|
|
|
|
PyObject *result = NULL;
|
2008-10-16 14:46:20 +00:00
|
|
|
|
|
|
|
|
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
|
|
|
|
{
|
2012-01-03 19:27:52 +00:00
|
|
|
|
struct value *res_val;
|
|
|
|
|
struct cleanup *cleanup = make_cleanup_value_free_to_mark (value_mark ());
|
|
|
|
|
|
2008-10-16 14:46:20 +00:00
|
|
|
|
res_val = value_ind (((value_object *) self)->value);
|
2012-01-03 19:27:52 +00:00
|
|
|
|
result = value_to_value_object (res_val);
|
|
|
|
|
do_cleanups (cleanup);
|
2008-10-16 14:46:20 +00:00
|
|
|
|
}
|
|
|
|
|
GDB_PY_HANDLE_EXCEPTION (except);
|
|
|
|
|
|
2012-01-03 19:27:52 +00:00
|
|
|
|
return result;
|
2008-10-16 14:46:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-03-22 08:10:44 +00:00
|
|
|
|
/* Given a value of a pointer type or a reference type, return the value
|
|
|
|
|
referenced. The difference between this function and valpy_dereference is
|
|
|
|
|
that the latter applies * unary operator to a value, which need not always
|
|
|
|
|
result in the value referenced. For example, for a value which is a reference
|
|
|
|
|
to an 'int' pointer ('int *'), valpy_dereference will result in a value of
|
|
|
|
|
type 'int' while valpy_referenced_value will result in a value of type
|
|
|
|
|
'int *'. */
|
|
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
|
valpy_referenced_value (PyObject *self, PyObject *args)
|
|
|
|
|
{
|
|
|
|
|
volatile struct gdb_exception except;
|
|
|
|
|
PyObject *result = NULL;
|
|
|
|
|
|
|
|
|
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
|
|
|
|
{
|
|
|
|
|
struct value *self_val, *res_val;
|
|
|
|
|
struct cleanup *cleanup = make_cleanup_value_free_to_mark (value_mark ());
|
|
|
|
|
|
|
|
|
|
self_val = ((value_object *) self)->value;
|
|
|
|
|
switch (TYPE_CODE (check_typedef (value_type (self_val))))
|
|
|
|
|
{
|
|
|
|
|
case TYPE_CODE_PTR:
|
|
|
|
|
res_val = value_ind (self_val);
|
|
|
|
|
break;
|
|
|
|
|
case TYPE_CODE_REF:
|
|
|
|
|
res_val = coerce_ref (self_val);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
error(_("Trying to get the referenced value from a value which is "
|
|
|
|
|
"neither a pointer nor a reference."));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result = value_to_value_object (res_val);
|
|
|
|
|
do_cleanups (cleanup);
|
|
|
|
|
}
|
|
|
|
|
GDB_PY_HANDLE_EXCEPTION (except);
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2009-02-04 21:55:40 +00:00
|
|
|
|
/* Return "&value". */
|
|
|
|
|
static PyObject *
|
2009-03-29 21:11:11 +00:00
|
|
|
|
valpy_get_address (PyObject *self, void *closure)
|
2009-02-04 21:55:40 +00:00
|
|
|
|
{
|
2009-03-29 21:11:11 +00:00
|
|
|
|
value_object *val_obj = (value_object *) self;
|
2009-02-04 21:55:40 +00:00
|
|
|
|
volatile struct gdb_exception except;
|
|
|
|
|
|
2009-03-29 21:11:11 +00:00
|
|
|
|
if (!val_obj->address)
|
2009-02-04 21:55:40 +00:00
|
|
|
|
{
|
2009-03-29 21:11:11 +00:00
|
|
|
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
|
|
|
|
{
|
2012-01-03 19:27:52 +00:00
|
|
|
|
struct value *res_val;
|
|
|
|
|
struct cleanup *cleanup
|
|
|
|
|
= make_cleanup_value_free_to_mark (value_mark ());
|
|
|
|
|
|
2009-03-29 21:11:11 +00:00
|
|
|
|
res_val = value_addr (val_obj->value);
|
2012-01-03 19:27:52 +00:00
|
|
|
|
val_obj->address = value_to_value_object (res_val);
|
|
|
|
|
do_cleanups (cleanup);
|
2009-03-29 21:11:11 +00:00
|
|
|
|
}
|
|
|
|
|
if (except.reason < 0)
|
|
|
|
|
{
|
|
|
|
|
val_obj->address = Py_None;
|
|
|
|
|
Py_INCREF (Py_None);
|
|
|
|
|
}
|
2009-02-04 21:55:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-10-03 16:14:39 +00:00
|
|
|
|
Py_XINCREF (val_obj->address);
|
2009-03-29 21:11:11 +00:00
|
|
|
|
|
|
|
|
|
return val_obj->address;
|
2009-02-04 21:55:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-05-28 00:47:20 +00:00
|
|
|
|
/* Return type of the value. */
|
|
|
|
|
static PyObject *
|
|
|
|
|
valpy_get_type (PyObject *self, void *closure)
|
|
|
|
|
{
|
|
|
|
|
value_object *obj = (value_object *) self;
|
2010-05-17 21:23:25 +00:00
|
|
|
|
|
2009-05-28 00:47:20 +00:00
|
|
|
|
if (!obj->type)
|
|
|
|
|
{
|
|
|
|
|
obj->type = type_to_type_object (value_type (obj->value));
|
|
|
|
|
if (!obj->type)
|
2010-08-30 20:28:31 +00:00
|
|
|
|
return NULL;
|
2009-05-28 00:47:20 +00:00
|
|
|
|
}
|
|
|
|
|
Py_INCREF (obj->type);
|
|
|
|
|
return obj->type;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-30 20:28:31 +00:00
|
|
|
|
/* Return dynamic type of the value. */
|
|
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
|
valpy_get_dynamic_type (PyObject *self, void *closure)
|
|
|
|
|
{
|
|
|
|
|
value_object *obj = (value_object *) self;
|
|
|
|
|
volatile struct gdb_exception except;
|
|
|
|
|
struct type *type = NULL;
|
|
|
|
|
|
|
|
|
|
if (obj->dynamic_type != NULL)
|
|
|
|
|
{
|
|
|
|
|
Py_INCREF (obj->dynamic_type);
|
|
|
|
|
return obj->dynamic_type;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
|
|
|
|
{
|
|
|
|
|
struct value *val = obj->value;
|
2012-01-03 19:27:52 +00:00
|
|
|
|
struct cleanup *cleanup = make_cleanup_value_free_to_mark (value_mark ());
|
2010-08-30 20:28:31 +00:00
|
|
|
|
|
|
|
|
|
type = value_type (val);
|
|
|
|
|
CHECK_TYPEDEF (type);
|
|
|
|
|
|
|
|
|
|
if (((TYPE_CODE (type) == TYPE_CODE_PTR)
|
|
|
|
|
|| (TYPE_CODE (type) == TYPE_CODE_REF))
|
|
|
|
|
&& (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_CLASS))
|
|
|
|
|
{
|
|
|
|
|
struct value *target;
|
|
|
|
|
int was_pointer = TYPE_CODE (type) == TYPE_CODE_PTR;
|
|
|
|
|
|
2014-03-21 13:42:50 +00:00
|
|
|
|
if (was_pointer)
|
|
|
|
|
target = value_ind (val);
|
|
|
|
|
else
|
|
|
|
|
target = coerce_ref (val);
|
2010-08-30 20:28:31 +00:00
|
|
|
|
type = value_rtti_type (target, NULL, NULL, NULL);
|
|
|
|
|
|
|
|
|
|
if (type)
|
|
|
|
|
{
|
|
|
|
|
if (was_pointer)
|
|
|
|
|
type = lookup_pointer_type (type);
|
|
|
|
|
else
|
|
|
|
|
type = lookup_reference_type (type);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (TYPE_CODE (type) == TYPE_CODE_CLASS)
|
|
|
|
|
type = value_rtti_type (val, NULL, NULL, NULL);
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* Re-use object's static type. */
|
|
|
|
|
type = NULL;
|
|
|
|
|
}
|
2012-01-03 19:27:52 +00:00
|
|
|
|
|
|
|
|
|
do_cleanups (cleanup);
|
2010-08-30 20:28:31 +00:00
|
|
|
|
}
|
|
|
|
|
GDB_PY_HANDLE_EXCEPTION (except);
|
|
|
|
|
|
|
|
|
|
if (type == NULL)
|
2013-05-20 20:38:47 +00:00
|
|
|
|
obj->dynamic_type = valpy_get_type (self, NULL);
|
2010-08-30 20:28:31 +00:00
|
|
|
|
else
|
|
|
|
|
obj->dynamic_type = type_to_type_object (type);
|
|
|
|
|
|
2013-05-20 20:38:47 +00:00
|
|
|
|
Py_XINCREF (obj->dynamic_type);
|
2010-08-30 20:28:31 +00:00
|
|
|
|
return obj->dynamic_type;
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-14 08:03:37 +00:00
|
|
|
|
/* Implementation of gdb.Value.lazy_string ([encoding] [, length]) ->
|
|
|
|
|
string. Return a PyObject representing a lazy_string_object type.
|
|
|
|
|
A lazy string is a pointer to a string with an optional encoding and
|
|
|
|
|
length. If ENCODING is not given, encoding is set to None. If an
|
|
|
|
|
ENCODING is provided the encoding parameter is set to ENCODING, but
|
|
|
|
|
the string is not encoded. If LENGTH is provided then the length
|
|
|
|
|
parameter is set to LENGTH, otherwise length will be set to -1 (first
|
|
|
|
|
null of appropriate with). */
|
|
|
|
|
static PyObject *
|
|
|
|
|
valpy_lazy_string (PyObject *self, PyObject *args, PyObject *kw)
|
|
|
|
|
{
|
2011-01-26 20:53:45 +00:00
|
|
|
|
gdb_py_longest length = -1;
|
2010-01-14 08:03:37 +00:00
|
|
|
|
struct value *value = ((value_object *) self)->value;
|
|
|
|
|
const char *user_encoding = NULL;
|
|
|
|
|
static char *keywords[] = { "encoding", "length", NULL };
|
2012-01-03 19:27:52 +00:00
|
|
|
|
PyObject *str_obj = NULL;
|
2011-10-07 13:46:11 +00:00
|
|
|
|
volatile struct gdb_exception except;
|
2010-01-14 08:03:37 +00:00
|
|
|
|
|
2011-01-26 20:53:45 +00:00
|
|
|
|
if (!PyArg_ParseTupleAndKeywords (args, kw, "|s" GDB_PY_LL_ARG, keywords,
|
2010-01-14 08:03:37 +00:00
|
|
|
|
&user_encoding, &length))
|
|
|
|
|
return NULL;
|
|
|
|
|
|
2011-10-07 13:46:11 +00:00
|
|
|
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
|
|
|
|
{
|
2012-01-03 19:27:52 +00:00
|
|
|
|
struct cleanup *cleanup = make_cleanup_value_free_to_mark (value_mark ());
|
|
|
|
|
|
2011-10-07 13:46:11 +00:00
|
|
|
|
if (TYPE_CODE (value_type (value)) == TYPE_CODE_PTR)
|
|
|
|
|
value = value_ind (value);
|
2012-01-03 19:27:52 +00:00
|
|
|
|
|
|
|
|
|
str_obj = gdbpy_create_lazy_string_object (value_address (value), length,
|
|
|
|
|
user_encoding,
|
|
|
|
|
value_type (value));
|
|
|
|
|
|
|
|
|
|
do_cleanups (cleanup);
|
2011-10-07 13:46:11 +00:00
|
|
|
|
}
|
|
|
|
|
GDB_PY_HANDLE_EXCEPTION (except);
|
2010-01-14 08:03:37 +00:00
|
|
|
|
|
2012-01-03 19:27:52 +00:00
|
|
|
|
return str_obj;
|
2010-01-14 08:03:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-07-10 10:35:17 +00:00
|
|
|
|
/* Implementation of gdb.Value.string ([encoding] [, errors]
|
|
|
|
|
[, length]) -> string. Return Unicode string with value contents.
|
|
|
|
|
If ENCODING is not given, the string is assumed to be encoded in
|
|
|
|
|
the target's charset. If LENGTH is provided, only fetch string to
|
|
|
|
|
the length provided. */
|
|
|
|
|
|
2009-02-05 21:16:09 +00:00
|
|
|
|
static PyObject *
|
2009-03-21 03:13:02 +00:00
|
|
|
|
valpy_string (PyObject *self, PyObject *args, PyObject *kw)
|
2009-02-05 21:16:09 +00:00
|
|
|
|
{
|
2010-05-07 19:26:30 +00:00
|
|
|
|
int length = -1;
|
2009-02-05 21:16:09 +00:00
|
|
|
|
gdb_byte *buffer;
|
|
|
|
|
struct value *value = ((value_object *) self)->value;
|
|
|
|
|
volatile struct gdb_exception except;
|
|
|
|
|
PyObject *unicode;
|
|
|
|
|
const char *encoding = NULL;
|
|
|
|
|
const char *errors = NULL;
|
|
|
|
|
const char *user_encoding = NULL;
|
|
|
|
|
const char *la_encoding = NULL;
|
2009-09-25 21:39:53 +00:00
|
|
|
|
struct type *char_type;
|
2009-09-29 15:13:45 +00:00
|
|
|
|
static char *keywords[] = { "encoding", "errors", "length", NULL };
|
2009-02-05 21:16:09 +00:00
|
|
|
|
|
2009-07-10 10:35:17 +00:00
|
|
|
|
if (!PyArg_ParseTupleAndKeywords (args, kw, "|ssi", keywords,
|
|
|
|
|
&user_encoding, &errors, &length))
|
2009-02-05 21:16:09 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
|
|
|
|
{
|
2009-09-25 21:39:53 +00:00
|
|
|
|
LA_GET_STRING (value, &buffer, &length, &char_type, &la_encoding);
|
2009-02-05 21:16:09 +00:00
|
|
|
|
}
|
|
|
|
|
GDB_PY_HANDLE_EXCEPTION (except);
|
|
|
|
|
|
|
|
|
|
encoding = (user_encoding && *user_encoding) ? user_encoding : la_encoding;
|
2013-04-19 15:29:09 +00:00
|
|
|
|
unicode = PyUnicode_Decode ((const char *) buffer,
|
|
|
|
|
length * TYPE_LENGTH (char_type),
|
2009-09-25 21:39:53 +00:00
|
|
|
|
encoding, errors);
|
2009-02-05 21:16:09 +00:00
|
|
|
|
xfree (buffer);
|
|
|
|
|
|
|
|
|
|
return unicode;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-23 20:29:19 +00:00
|
|
|
|
/* A helper function that implements the various cast operators. */
|
|
|
|
|
|
2009-05-28 00:47:20 +00:00
|
|
|
|
static PyObject *
|
2010-08-23 20:29:19 +00:00
|
|
|
|
valpy_do_cast (PyObject *self, PyObject *args, enum exp_opcode op)
|
2009-05-28 00:47:20 +00:00
|
|
|
|
{
|
2012-01-03 19:27:52 +00:00
|
|
|
|
PyObject *type_obj, *result = NULL;
|
2009-05-28 00:47:20 +00:00
|
|
|
|
struct type *type;
|
|
|
|
|
volatile struct gdb_exception except;
|
|
|
|
|
|
|
|
|
|
if (! PyArg_ParseTuple (args, "O", &type_obj))
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
type = type_object_to_type (type_obj);
|
|
|
|
|
if (! type)
|
|
|
|
|
{
|
2013-11-29 20:00:47 +00:00
|
|
|
|
PyErr_SetString (PyExc_RuntimeError,
|
2010-04-14 13:18:55 +00:00
|
|
|
|
_("Argument must be a type."));
|
2009-05-28 00:47:20 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
|
|
|
|
{
|
2010-08-23 20:29:19 +00:00
|
|
|
|
struct value *val = ((value_object *) self)->value;
|
2012-01-03 19:27:52 +00:00
|
|
|
|
struct value *res_val;
|
|
|
|
|
struct cleanup *cleanup = make_cleanup_value_free_to_mark (value_mark ());
|
2010-08-23 20:29:19 +00:00
|
|
|
|
|
|
|
|
|
if (op == UNOP_DYNAMIC_CAST)
|
|
|
|
|
res_val = value_dynamic_cast (type, val);
|
|
|
|
|
else if (op == UNOP_REINTERPRET_CAST)
|
|
|
|
|
res_val = value_reinterpret_cast (type, val);
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
gdb_assert (op == UNOP_CAST);
|
|
|
|
|
res_val = value_cast (type, val);
|
|
|
|
|
}
|
2012-01-03 19:27:52 +00:00
|
|
|
|
|
|
|
|
|
result = value_to_value_object (res_val);
|
|
|
|
|
do_cleanups (cleanup);
|
2009-05-28 00:47:20 +00:00
|
|
|
|
}
|
|
|
|
|
GDB_PY_HANDLE_EXCEPTION (except);
|
|
|
|
|
|
2012-01-03 19:27:52 +00:00
|
|
|
|
return result;
|
2009-05-28 00:47:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-08-23 20:29:19 +00:00
|
|
|
|
/* Implementation of the "cast" method. */
|
|
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
|
valpy_cast (PyObject *self, PyObject *args)
|
|
|
|
|
{
|
|
|
|
|
return valpy_do_cast (self, args, UNOP_CAST);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Implementation of the "dynamic_cast" method. */
|
|
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
|
valpy_dynamic_cast (PyObject *self, PyObject *args)
|
|
|
|
|
{
|
|
|
|
|
return valpy_do_cast (self, args, UNOP_DYNAMIC_CAST);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Implementation of the "reinterpret_cast" method. */
|
|
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
|
valpy_reinterpret_cast (PyObject *self, PyObject *args)
|
|
|
|
|
{
|
|
|
|
|
return valpy_do_cast (self, args, UNOP_REINTERPRET_CAST);
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-16 14:46:20 +00:00
|
|
|
|
static Py_ssize_t
|
|
|
|
|
valpy_length (PyObject *self)
|
|
|
|
|
{
|
|
|
|
|
/* We don't support getting the number of elements in a struct / class. */
|
|
|
|
|
PyErr_SetString (PyExc_NotImplementedError,
|
2010-04-14 13:18:55 +00:00
|
|
|
|
_("Invalid operation on gdb.Value."));
|
2008-10-16 14:46:20 +00:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-12 23:18:27 +00:00
|
|
|
|
/* Return 1 if the gdb.Field object FIELD is present in the value V.
|
|
|
|
|
Returns 0 otherwise. If any Python error occurs, -1 is returned. */
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
value_has_field (struct value *v, PyObject *field)
|
|
|
|
|
{
|
|
|
|
|
struct type *parent_type, *val_type;
|
|
|
|
|
enum type_code type_code;
|
|
|
|
|
PyObject *type_object = PyObject_GetAttrString (field, "parent_type");
|
|
|
|
|
volatile struct gdb_exception except;
|
|
|
|
|
int has_field = 0;
|
|
|
|
|
|
|
|
|
|
if (type_object == NULL)
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
parent_type = type_object_to_type (type_object);
|
|
|
|
|
Py_DECREF (type_object);
|
|
|
|
|
if (parent_type == NULL)
|
|
|
|
|
{
|
|
|
|
|
PyErr_SetString (PyExc_TypeError,
|
|
|
|
|
_("'parent_type' attribute of gdb.Field object is not a"
|
|
|
|
|
"gdb.Type object."));
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
|
|
|
|
{
|
|
|
|
|
val_type = value_type (v);
|
|
|
|
|
val_type = check_typedef (val_type);
|
|
|
|
|
if (TYPE_CODE (val_type) == TYPE_CODE_REF
|
|
|
|
|
|| TYPE_CODE (val_type) == TYPE_CODE_PTR)
|
|
|
|
|
val_type = check_typedef (TYPE_TARGET_TYPE (val_type));
|
|
|
|
|
|
|
|
|
|
type_code = TYPE_CODE (val_type);
|
|
|
|
|
if ((type_code == TYPE_CODE_STRUCT || type_code == TYPE_CODE_UNION)
|
|
|
|
|
&& types_equal (val_type, parent_type))
|
|
|
|
|
has_field = 1;
|
|
|
|
|
else
|
|
|
|
|
has_field = 0;
|
|
|
|
|
}
|
|
|
|
|
GDB_PY_SET_HANDLE_EXCEPTION (except);
|
|
|
|
|
|
|
|
|
|
return has_field;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Return the value of a flag FLAG_NAME in a gdb.Field object FIELD.
|
|
|
|
|
Returns 1 if the flag value is true, 0 if it is false, and -1 if
|
|
|
|
|
a Python error occurs. */
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
get_field_flag (PyObject *field, const char *flag_name)
|
|
|
|
|
{
|
|
|
|
|
int flag_value;
|
2014-06-04 17:50:11 +00:00
|
|
|
|
PyObject *flag_object = PyObject_GetAttrString (field, flag_name);
|
2013-12-12 23:18:27 +00:00
|
|
|
|
|
|
|
|
|
if (flag_object == NULL)
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
flag_value = PyObject_IsTrue (flag_object);
|
|
|
|
|
Py_DECREF (flag_object);
|
|
|
|
|
|
|
|
|
|
return flag_value;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-27 20:20:59 +00:00
|
|
|
|
/* Return the "type" attribute of a gdb.Field object.
|
|
|
|
|
Returns NULL on error, with a Python exception set. */
|
|
|
|
|
|
|
|
|
|
static struct type *
|
|
|
|
|
get_field_type (PyObject *field)
|
|
|
|
|
{
|
|
|
|
|
PyObject *ftype_obj = PyObject_GetAttrString (field, "type");
|
|
|
|
|
struct type *ftype;
|
|
|
|
|
|
|
|
|
|
if (ftype_obj == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
ftype = type_object_to_type (ftype_obj);
|
|
|
|
|
Py_DECREF (ftype_obj);
|
|
|
|
|
if (ftype == NULL)
|
2014-01-15 12:40:22 +00:00
|
|
|
|
PyErr_SetString (PyExc_TypeError,
|
|
|
|
|
_("'type' attribute of gdb.Field object is not a "
|
|
|
|
|
"gdb.Type object."));
|
2013-12-27 20:20:59 +00:00
|
|
|
|
|
|
|
|
|
return ftype;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-12 23:18:27 +00:00
|
|
|
|
/* Given string name or a gdb.Field object corresponding to an element inside
|
|
|
|
|
a structure, return its value object. Returns NULL on error, with a python
|
|
|
|
|
exception set. */
|
|
|
|
|
|
2008-10-16 14:46:20 +00:00
|
|
|
|
static PyObject *
|
|
|
|
|
valpy_getitem (PyObject *self, PyObject *key)
|
|
|
|
|
{
|
|
|
|
|
value_object *self_value = (value_object *) self;
|
2009-02-04 21:55:40 +00:00
|
|
|
|
char *field = NULL;
|
2013-12-27 20:20:59 +00:00
|
|
|
|
struct type *base_class_type = NULL, *field_type = NULL;
|
|
|
|
|
long bitpos = -1;
|
2008-10-16 14:46:20 +00:00
|
|
|
|
volatile struct gdb_exception except;
|
2012-01-03 19:27:52 +00:00
|
|
|
|
PyObject *result = NULL;
|
2008-10-16 14:46:20 +00:00
|
|
|
|
|
2009-02-04 21:55:40 +00:00
|
|
|
|
if (gdbpy_is_string (key))
|
2013-11-29 20:00:47 +00:00
|
|
|
|
{
|
2009-02-04 21:55:40 +00:00
|
|
|
|
field = python_string_to_host_string (key);
|
|
|
|
|
if (field == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2013-12-12 23:18:27 +00:00
|
|
|
|
else if (gdbpy_is_field (key))
|
|
|
|
|
{
|
|
|
|
|
int is_base_class, valid_field;
|
|
|
|
|
|
|
|
|
|
valid_field = value_has_field (self_value->value, key);
|
|
|
|
|
if (valid_field < 0)
|
|
|
|
|
return NULL;
|
|
|
|
|
else if (valid_field == 0)
|
|
|
|
|
{
|
|
|
|
|
PyErr_SetString (PyExc_TypeError,
|
|
|
|
|
_("Invalid lookup for a field not contained in "
|
|
|
|
|
"the value."));
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
is_base_class = get_field_flag (key, "is_base_class");
|
|
|
|
|
if (is_base_class < 0)
|
|
|
|
|
return NULL;
|
|
|
|
|
else if (is_base_class > 0)
|
|
|
|
|
{
|
2013-12-27 20:20:59 +00:00
|
|
|
|
base_class_type = get_field_type (key);
|
|
|
|
|
if (base_class_type == NULL)
|
2013-12-12 23:18:27 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
PyObject *name_obj = PyObject_GetAttrString (key, "name");
|
|
|
|
|
|
|
|
|
|
if (name_obj == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
2013-12-27 20:20:59 +00:00
|
|
|
|
if (name_obj != Py_None)
|
|
|
|
|
{
|
|
|
|
|
field = python_string_to_host_string (name_obj);
|
|
|
|
|
Py_DECREF (name_obj);
|
|
|
|
|
if (field == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
PyObject *bitpos_obj;
|
|
|
|
|
int valid;
|
|
|
|
|
|
|
|
|
|
Py_DECREF (name_obj);
|
|
|
|
|
|
|
|
|
|
if (!PyObject_HasAttrString (key, "bitpos"))
|
|
|
|
|
{
|
|
|
|
|
PyErr_SetString (PyExc_AttributeError,
|
|
|
|
|
_("gdb.Field object has no name and no "
|
|
|
|
|
"'bitpos' attribute."));
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
bitpos_obj = PyObject_GetAttrString (key, "bitpos");
|
|
|
|
|
if (bitpos_obj == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
valid = gdb_py_int_as_long (bitpos_obj, &bitpos);
|
|
|
|
|
Py_DECREF (bitpos_obj);
|
|
|
|
|
if (!valid)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
field_type = get_field_type (key);
|
|
|
|
|
if (field_type == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2013-12-12 23:18:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2008-10-16 14:46:20 +00:00
|
|
|
|
|
|
|
|
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
|
|
|
|
{
|
2008-10-23 22:48:40 +00:00
|
|
|
|
struct value *tmp = self_value->value;
|
2012-01-03 19:27:52 +00:00
|
|
|
|
struct cleanup *cleanup = make_cleanup_value_free_to_mark (value_mark ());
|
|
|
|
|
struct value *res_val = NULL;
|
2009-02-04 21:55:40 +00:00
|
|
|
|
|
|
|
|
|
if (field)
|
|
|
|
|
res_val = value_struct_elt (&tmp, NULL, field, 0, NULL);
|
2013-12-27 20:20:59 +00:00
|
|
|
|
else if (bitpos >= 0)
|
|
|
|
|
res_val = value_struct_elt_bitpos (&tmp, bitpos, field_type,
|
|
|
|
|
"struct/class/union");
|
|
|
|
|
else if (base_class_type != NULL)
|
2013-12-12 23:18:27 +00:00
|
|
|
|
{
|
2013-12-27 20:20:59 +00:00
|
|
|
|
struct type *val_type;
|
2013-12-12 23:18:27 +00:00
|
|
|
|
|
|
|
|
|
val_type = check_typedef (value_type (tmp));
|
|
|
|
|
if (TYPE_CODE (val_type) == TYPE_CODE_PTR)
|
|
|
|
|
res_val = value_cast (lookup_pointer_type (base_class_type), tmp);
|
|
|
|
|
else if (TYPE_CODE (val_type) == TYPE_CODE_REF)
|
|
|
|
|
res_val = value_cast (lookup_reference_type (base_class_type), tmp);
|
|
|
|
|
else
|
|
|
|
|
res_val = value_cast (base_class_type, tmp);
|
|
|
|
|
}
|
2009-02-04 21:55:40 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* Assume we are attempting an array access, and let the
|
|
|
|
|
value code throw an exception if the index has an invalid
|
|
|
|
|
type. */
|
|
|
|
|
struct value *idx = convert_value_from_python (key);
|
2010-05-17 21:23:25 +00:00
|
|
|
|
|
2009-07-07 19:36:09 +00:00
|
|
|
|
if (idx != NULL)
|
2009-09-21 09:32:28 +00:00
|
|
|
|
{
|
|
|
|
|
/* Check the value's type is something that can be accessed via
|
|
|
|
|
a subscript. */
|
|
|
|
|
struct type *type;
|
2010-05-17 21:23:25 +00:00
|
|
|
|
|
2009-09-21 09:32:28 +00:00
|
|
|
|
tmp = coerce_ref (tmp);
|
|
|
|
|
type = check_typedef (value_type (tmp));
|
|
|
|
|
if (TYPE_CODE (type) != TYPE_CODE_ARRAY
|
|
|
|
|
&& TYPE_CODE (type) != TYPE_CODE_PTR)
|
2011-03-18 16:09:57 +00:00
|
|
|
|
error (_("Cannot subscript requested type."));
|
2009-09-21 09:32:28 +00:00
|
|
|
|
else
|
|
|
|
|
res_val = value_subscript (tmp, value_as_long (idx));
|
|
|
|
|
}
|
2009-02-04 21:55:40 +00:00
|
|
|
|
}
|
2012-01-03 19:27:52 +00:00
|
|
|
|
|
|
|
|
|
if (res_val)
|
|
|
|
|
result = value_to_value_object (res_val);
|
|
|
|
|
do_cleanups (cleanup);
|
2008-10-16 14:46:20 +00:00
|
|
|
|
}
|
2009-07-07 19:36:09 +00:00
|
|
|
|
|
2009-07-07 21:03:00 +00:00
|
|
|
|
xfree (field);
|
2008-10-16 14:46:20 +00:00
|
|
|
|
GDB_PY_HANDLE_EXCEPTION (except);
|
|
|
|
|
|
2012-01-03 19:27:52 +00:00
|
|
|
|
return result;
|
2008-10-16 14:46:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
valpy_setitem (PyObject *self, PyObject *key, PyObject *value)
|
|
|
|
|
{
|
|
|
|
|
PyErr_Format (PyExc_NotImplementedError,
|
|
|
|
|
_("Setting of struct elements is not currently supported."));
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-27 12:40:42 +00:00
|
|
|
|
/* Called by the Python interpreter to perform an inferior function
|
2010-10-13 13:24:40 +00:00
|
|
|
|
call on the value. Returns NULL on error, with a python exception set. */
|
2010-07-27 12:40:42 +00:00
|
|
|
|
static PyObject *
|
|
|
|
|
valpy_call (PyObject *self, PyObject *args, PyObject *keywords)
|
|
|
|
|
{
|
|
|
|
|
Py_ssize_t args_count;
|
|
|
|
|
volatile struct gdb_exception except;
|
|
|
|
|
struct value *function = ((value_object *) self)->value;
|
|
|
|
|
struct value **vargs = NULL;
|
2011-10-07 22:02:42 +00:00
|
|
|
|
struct type *ftype = NULL;
|
2012-01-03 19:27:52 +00:00
|
|
|
|
struct value *mark = value_mark ();
|
|
|
|
|
PyObject *result = NULL;
|
2011-10-07 13:46:11 +00:00
|
|
|
|
|
|
|
|
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
|
|
|
|
{
|
|
|
|
|
ftype = check_typedef (value_type (function));
|
|
|
|
|
}
|
|
|
|
|
GDB_PY_HANDLE_EXCEPTION (except);
|
2010-07-27 12:40:42 +00:00
|
|
|
|
|
|
|
|
|
if (TYPE_CODE (ftype) != TYPE_CODE_FUNC)
|
|
|
|
|
{
|
|
|
|
|
PyErr_SetString (PyExc_RuntimeError,
|
|
|
|
|
_("Value is not callable (not TYPE_CODE_FUNC)."));
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-07 13:46:11 +00:00
|
|
|
|
if (! PyTuple_Check (args))
|
|
|
|
|
{
|
|
|
|
|
PyErr_SetString (PyExc_TypeError,
|
|
|
|
|
_("Inferior arguments must be provided in a tuple."));
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-27 12:40:42 +00:00
|
|
|
|
args_count = PyTuple_Size (args);
|
|
|
|
|
if (args_count > 0)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
vargs = alloca (sizeof (struct value *) * args_count);
|
|
|
|
|
for (i = 0; i < args_count; i++)
|
|
|
|
|
{
|
|
|
|
|
PyObject *item = PyTuple_GetItem (args, i);
|
|
|
|
|
|
|
|
|
|
if (item == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
vargs[i] = convert_value_from_python (item);
|
|
|
|
|
if (vargs[i] == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
|
|
|
|
{
|
2012-01-03 19:27:52 +00:00
|
|
|
|
struct cleanup *cleanup = make_cleanup_value_free_to_mark (mark);
|
|
|
|
|
struct value *return_value;
|
|
|
|
|
|
2010-07-27 12:40:42 +00:00
|
|
|
|
return_value = call_function_by_hand (function, args_count, vargs);
|
2012-01-03 19:27:52 +00:00
|
|
|
|
result = value_to_value_object (return_value);
|
|
|
|
|
do_cleanups (cleanup);
|
2010-07-27 12:40:42 +00:00
|
|
|
|
}
|
|
|
|
|
GDB_PY_HANDLE_EXCEPTION (except);
|
|
|
|
|
|
2012-01-03 19:27:52 +00:00
|
|
|
|
return result;
|
2010-07-27 12:40:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-10-16 14:46:20 +00:00
|
|
|
|
/* Called by the Python interpreter to obtain string representation
|
|
|
|
|
of the object. */
|
|
|
|
|
static PyObject *
|
|
|
|
|
valpy_str (PyObject *self)
|
|
|
|
|
{
|
|
|
|
|
char *s = NULL;
|
|
|
|
|
PyObject *result;
|
gdb
* varobj.c (value_get_print_value): Include valprint.h.
(value_get_print_value): Use get_formatted_print_options.
* value.h (struct value_print_options): Declare.
(value_print, val_print, common_val_print, val_print_string):
Update.
* value.c: Include valprint.h.
(show_values): Use get_user_print_options.
(show_convenience): Likewise.
* valprint.h (prettyprint_arrays, prettyprint_structs): Don't
declare.
(struct value_print_options): New type.
(vtblprint, unionprint, addressprint, objectprint, print_max,
inspect_it, repeat_count_threshold, output_format,
stop_print_at_null): Don't declare.
(user_print_options, get_user_print_options,
get_raw_print_options, get_formatted_print_options): Declare.
(print_array_indexes_p): Don't declare.
(maybe_print_array_index, val_print_array_elements): Update.
* valprint.c (print_max): Remove.
(user_print_options): New global.
(get_user_print_options, get_raw_print_options,
get_formatted_print_options): New functions.
(print_array_indexes, repeat_count_threshold, stop_print_at_null,
prettyprint_structs, prettyprint_arrays, unionprint,
addressprint): Remove.
(val_print): Remove format, deref_ref, pretty arguments; add
options. Update.
(common_val_print): Likewise.
(print_array_indexes_p): Remove.
(maybe_print_array_index): Remove format, pretty arguments; add
options. Update.
(val_print_array_elements): Remove format, deref_ref, pretty
arguments; add options. Update.
(val_print_string): Add options argument. Update.
(_initialize_valprint): Use user_print_options.
(output_format): Remove.
(set_output_radix_1): Use user_print_options.
* typeprint.c: Include valprint.h.
(objectprint): Don't declare.
(whatis_exp): Use get_user_print_options.
* tui/tui-regs.c: Include valprint.h.
(tui_register_format): Use get_formatted_print_options.
* tracepoint.c: Include valprint.h.
(addressprint): Don't declare.
(trace_mention): Use get_user_print_options.
(tracepoints_info): Likewise.
* stack.c (print_frame_args): Use get_raw_print_options.
(print_frame_info): Use get_user_print_options.
(print_frame): Likewise.
* sh64-tdep.c: Include valprint.h
(sh64_do_register): Use get_formatted_print_options.
* scm-valprint.c (scm_inferior_print): Remove format, deref_ref,
pretty arguments; add options.
(scm_scmlist_print): Likewise. Update.
(scm_scmval_print): Likewise.
(scm_val_print): Likewise.
(scm_value_print): Remove format, pretty arguments; add options.
Update.
* scm-lang.h (scm_value_print, scm_val_print, scm_scmval_print):
Update.
* scm-lang.c (scm_printstr): Add options argument.
* python/python-value.c: Include valprint.h.
(valpy_str): Use get_user_print_options.
* printcmd.c: Include valprint.h.
(addressprint): Don't declare.
(inspect_it): Remove.
(print_formatted): Remove format option; add options. Update.
(print_scalar_formatted): Likewise.
(print_address_demangle): Use get_user_print_options.
(do_examine): Use get_formatted_print_options.
(print_command_1): Likewise.
(output_command): Use get_formatted_print_options.
(do_one_display): Likewise.
(print_variable_value): Use get_user_print_options.
* p-valprint.c (pascal_val_print): Remove format, deref_ref,
pretty arguments; add options. Update.
(pascal_value_print): Remove format, pretty arguments; add
options. Update.
(vtblprint, objectprint): Don't declare.
(pascal_static_field_print): Remove.
(pascal_object_print_value_fields): Remove format, pretty
arguments; add options. Update.
(pascal_object_print_static_field): Likewise.
(_initialize_pascal_valprint): Use user_print_options. Update.
* p-lang.h (pascal_val_print, pascal_value_print,
pascal_printstr, pascal_object_print_value_fields): Update.
(vtblprint, static_field_print): Don't declare.
* p-lang.c (pascal_printstr): Add options argument. Update.
* objc-lang.c (objc_printstr): Add options argument. Update.
* mt-tdep.c: Include valprint.h.
(mt_registers_info): Use get_raw_print_options.
* mips-tdep.c: Include valprint.h.
(mips_print_fp_register): Use get_formatted_print_options.
(mips_print_register): Likewise.
* mi/mi-main.c: Include valprint.h.
(get_register): Use get_user_print_options.
(mi_cmd_data_evaluate_expression): Likewise.
(mi_cmd_data_read_memory): Use get_formatted_print_options.
* mi/mi-cmd-stack.c: Include valprint.h.
(list_args_or_locals): Use get_raw_print_options.
* m2-valprint.c (print_function_pointer_address): Add addressprint
argument.
(m2_print_long_set): Remove format, pretty arguments.
(m2_print_unbounded_array): Remove format, deref_ref, pretty
arguments; add options. Update.
(print_unpacked_pointer): Remove format argument; add options.
Now static. Update.
(print_variable_at_address): Remove format, deref_ref, pretty
arguments; add options. Update.
(m2_print_array_contents): Likewise.
(m2_val_print): Likewise.
* m2-lang.h (m2_val_print): Update.
* m2-lang.c (m2_printstr): Add options argument. Update.
* language.h (struct value_print_options): Declare.
(struct language_defn) <la_printstr>: Add options argument.
<la_val_print>: Remove format, deref_ref, pretty argument; add
options.
<la_value_print>: Remove format, pretty arguments; add options.
<la_print_array_index>: Likewise.
(LA_VAL_PRINT, LA_VALUE_PRINT, LA_PRINT_STRING,
LA_PRINT_ARRAY_INDEX): Update.
(default_print_array_index): Update.
* language.c (default_print_array_index): Remove format, pretty
arguments; add options. Update.
(unk_lang_printstr): Add options argument.
(unk_lang_val_print): Remove format, deref_ref, pretty arguments;
add options.
(unk_lang_value_print): Remove format, pretty arguments; add
options.
* jv-valprint.c (java_value_print): Remove format, pretty
arguments; add options. Update.
(java_print_value_fields): Likewise.
(java_val_print): Remove format, deref_ref, pretty arguments; add
options. Update.
* jv-lang.h (java_val_print, java_value_print): Declare.
* infcmd.c: Include valprint.h.
(print_return_value): Use get_raw_print_options.
(default_print_registers_info): Use get_user_print_options,
get_formatted_print_options.
(registers_info): Use get_formatted_print_options.
* gdbtypes.h (struct value_print_options): Declare.
(print_scalar_formatted): Update.
* f-valprint.c (f77_print_array_1): Remove format, deref_ref,
pretty arguments; add options. Update.
(f77_print_array): Likewise.
(f_val_print): Likewise.
* f-lang.h (f_val_print): Update.
* f-lang.c (f_printstr): Add options argument. Update.
(c_value_print): Update declaration.
* expprint.c: Include valprint.h.
(print_subexp_standard): Use get_raw_print_options,
get_user_print_options.
* eval.c: Include valprint.h.
(objectprint): Don't declare.
(evaluate_subexp_standard): Use get_user_print_options.
* cp-valprint.c (vtblprint, objectprint, static_field_print):
Remove.
(cp_print_value_fields): Remove format, pretty arguments; add
options. Update.
(cp_print_value): Likewise.
(cp_print_static_field): Likewise.
(_initialize_cp_valprint): Use user_print_options. Update.
* c-valprint.c (print_function_pointer_address): Add addressprint
argument.
(c_val_print): Remove format, deref_ref, pretty arguments; add
options. Update.
(c_value_print): Add options argument. Update.
* c-lang.h (c_val_print, c_value_print, c_printstr): Update.
(vtblprint, static_field_print): Don't declare.
(cp_print_value_fields): Update.
* c-lang.c (c_printstr): Add options argument. Update.
* breakpoint.c: Include valprint.h.
(addressprint): Don't declare.
(watchpoint_value_print): Use get_user_print_options.
(print_one_breakpoint_location): Likewise.
(breakpoint_1, print_it_catch_fork, print_it_catch_vfork, mention,
print_exception_catchpoint): Likewise.
* auxv.c (fprint_target_auxv): Don't declare addressprint. Use
get_user_print_options.
* ada-valprint.c (struct ada_val_print_args): Remove format,
deref_ref, and pretty; add options.
(print_optional_low_bound): Add options argument.
(val_print_packed_array_elements): Remove format and pretty
arguments; add options. Update.
(printstr): Add options argument. Update.
(ada_printstr): Likewise.
(ada_val_print): Remove format, deref_ref, pretty arguments; add
options argument. Update.
(ada_val_print_stub): Update.
(ada_val_print_array): Remove format, deref_ref, pretty arguments;
add options. Update.
(ada_val_print_1): Likewise.
(print_variant_part): Likewise.
(ada_value_print): Remove format, pretty arguments; add options.
Update.
(print_record): Likewise.
(print_field_values): Likewise.
* ada-lang.h (ada_val_print, ada_value_print, ada_printstr):
Update.
* ada-lang.c (ada_print_array_index): Add options argument; remove
format and pretty arguments.
(print_one_exception): Use get_user_print_options.
gdb/testsuite
* gdb.base/exprs.exp (test_expr): Add enum formatting tests.
2008-10-28 17:19:58 +00:00
|
|
|
|
struct value_print_options opts;
|
2008-10-16 14:46:20 +00:00
|
|
|
|
volatile struct gdb_exception except;
|
|
|
|
|
|
gdb
* varobj.c (value_get_print_value): Include valprint.h.
(value_get_print_value): Use get_formatted_print_options.
* value.h (struct value_print_options): Declare.
(value_print, val_print, common_val_print, val_print_string):
Update.
* value.c: Include valprint.h.
(show_values): Use get_user_print_options.
(show_convenience): Likewise.
* valprint.h (prettyprint_arrays, prettyprint_structs): Don't
declare.
(struct value_print_options): New type.
(vtblprint, unionprint, addressprint, objectprint, print_max,
inspect_it, repeat_count_threshold, output_format,
stop_print_at_null): Don't declare.
(user_print_options, get_user_print_options,
get_raw_print_options, get_formatted_print_options): Declare.
(print_array_indexes_p): Don't declare.
(maybe_print_array_index, val_print_array_elements): Update.
* valprint.c (print_max): Remove.
(user_print_options): New global.
(get_user_print_options, get_raw_print_options,
get_formatted_print_options): New functions.
(print_array_indexes, repeat_count_threshold, stop_print_at_null,
prettyprint_structs, prettyprint_arrays, unionprint,
addressprint): Remove.
(val_print): Remove format, deref_ref, pretty arguments; add
options. Update.
(common_val_print): Likewise.
(print_array_indexes_p): Remove.
(maybe_print_array_index): Remove format, pretty arguments; add
options. Update.
(val_print_array_elements): Remove format, deref_ref, pretty
arguments; add options. Update.
(val_print_string): Add options argument. Update.
(_initialize_valprint): Use user_print_options.
(output_format): Remove.
(set_output_radix_1): Use user_print_options.
* typeprint.c: Include valprint.h.
(objectprint): Don't declare.
(whatis_exp): Use get_user_print_options.
* tui/tui-regs.c: Include valprint.h.
(tui_register_format): Use get_formatted_print_options.
* tracepoint.c: Include valprint.h.
(addressprint): Don't declare.
(trace_mention): Use get_user_print_options.
(tracepoints_info): Likewise.
* stack.c (print_frame_args): Use get_raw_print_options.
(print_frame_info): Use get_user_print_options.
(print_frame): Likewise.
* sh64-tdep.c: Include valprint.h
(sh64_do_register): Use get_formatted_print_options.
* scm-valprint.c (scm_inferior_print): Remove format, deref_ref,
pretty arguments; add options.
(scm_scmlist_print): Likewise. Update.
(scm_scmval_print): Likewise.
(scm_val_print): Likewise.
(scm_value_print): Remove format, pretty arguments; add options.
Update.
* scm-lang.h (scm_value_print, scm_val_print, scm_scmval_print):
Update.
* scm-lang.c (scm_printstr): Add options argument.
* python/python-value.c: Include valprint.h.
(valpy_str): Use get_user_print_options.
* printcmd.c: Include valprint.h.
(addressprint): Don't declare.
(inspect_it): Remove.
(print_formatted): Remove format option; add options. Update.
(print_scalar_formatted): Likewise.
(print_address_demangle): Use get_user_print_options.
(do_examine): Use get_formatted_print_options.
(print_command_1): Likewise.
(output_command): Use get_formatted_print_options.
(do_one_display): Likewise.
(print_variable_value): Use get_user_print_options.
* p-valprint.c (pascal_val_print): Remove format, deref_ref,
pretty arguments; add options. Update.
(pascal_value_print): Remove format, pretty arguments; add
options. Update.
(vtblprint, objectprint): Don't declare.
(pascal_static_field_print): Remove.
(pascal_object_print_value_fields): Remove format, pretty
arguments; add options. Update.
(pascal_object_print_static_field): Likewise.
(_initialize_pascal_valprint): Use user_print_options. Update.
* p-lang.h (pascal_val_print, pascal_value_print,
pascal_printstr, pascal_object_print_value_fields): Update.
(vtblprint, static_field_print): Don't declare.
* p-lang.c (pascal_printstr): Add options argument. Update.
* objc-lang.c (objc_printstr): Add options argument. Update.
* mt-tdep.c: Include valprint.h.
(mt_registers_info): Use get_raw_print_options.
* mips-tdep.c: Include valprint.h.
(mips_print_fp_register): Use get_formatted_print_options.
(mips_print_register): Likewise.
* mi/mi-main.c: Include valprint.h.
(get_register): Use get_user_print_options.
(mi_cmd_data_evaluate_expression): Likewise.
(mi_cmd_data_read_memory): Use get_formatted_print_options.
* mi/mi-cmd-stack.c: Include valprint.h.
(list_args_or_locals): Use get_raw_print_options.
* m2-valprint.c (print_function_pointer_address): Add addressprint
argument.
(m2_print_long_set): Remove format, pretty arguments.
(m2_print_unbounded_array): Remove format, deref_ref, pretty
arguments; add options. Update.
(print_unpacked_pointer): Remove format argument; add options.
Now static. Update.
(print_variable_at_address): Remove format, deref_ref, pretty
arguments; add options. Update.
(m2_print_array_contents): Likewise.
(m2_val_print): Likewise.
* m2-lang.h (m2_val_print): Update.
* m2-lang.c (m2_printstr): Add options argument. Update.
* language.h (struct value_print_options): Declare.
(struct language_defn) <la_printstr>: Add options argument.
<la_val_print>: Remove format, deref_ref, pretty argument; add
options.
<la_value_print>: Remove format, pretty arguments; add options.
<la_print_array_index>: Likewise.
(LA_VAL_PRINT, LA_VALUE_PRINT, LA_PRINT_STRING,
LA_PRINT_ARRAY_INDEX): Update.
(default_print_array_index): Update.
* language.c (default_print_array_index): Remove format, pretty
arguments; add options. Update.
(unk_lang_printstr): Add options argument.
(unk_lang_val_print): Remove format, deref_ref, pretty arguments;
add options.
(unk_lang_value_print): Remove format, pretty arguments; add
options.
* jv-valprint.c (java_value_print): Remove format, pretty
arguments; add options. Update.
(java_print_value_fields): Likewise.
(java_val_print): Remove format, deref_ref, pretty arguments; add
options. Update.
* jv-lang.h (java_val_print, java_value_print): Declare.
* infcmd.c: Include valprint.h.
(print_return_value): Use get_raw_print_options.
(default_print_registers_info): Use get_user_print_options,
get_formatted_print_options.
(registers_info): Use get_formatted_print_options.
* gdbtypes.h (struct value_print_options): Declare.
(print_scalar_formatted): Update.
* f-valprint.c (f77_print_array_1): Remove format, deref_ref,
pretty arguments; add options. Update.
(f77_print_array): Likewise.
(f_val_print): Likewise.
* f-lang.h (f_val_print): Update.
* f-lang.c (f_printstr): Add options argument. Update.
(c_value_print): Update declaration.
* expprint.c: Include valprint.h.
(print_subexp_standard): Use get_raw_print_options,
get_user_print_options.
* eval.c: Include valprint.h.
(objectprint): Don't declare.
(evaluate_subexp_standard): Use get_user_print_options.
* cp-valprint.c (vtblprint, objectprint, static_field_print):
Remove.
(cp_print_value_fields): Remove format, pretty arguments; add
options. Update.
(cp_print_value): Likewise.
(cp_print_static_field): Likewise.
(_initialize_cp_valprint): Use user_print_options. Update.
* c-valprint.c (print_function_pointer_address): Add addressprint
argument.
(c_val_print): Remove format, deref_ref, pretty arguments; add
options. Update.
(c_value_print): Add options argument. Update.
* c-lang.h (c_val_print, c_value_print, c_printstr): Update.
(vtblprint, static_field_print): Don't declare.
(cp_print_value_fields): Update.
* c-lang.c (c_printstr): Add options argument. Update.
* breakpoint.c: Include valprint.h.
(addressprint): Don't declare.
(watchpoint_value_print): Use get_user_print_options.
(print_one_breakpoint_location): Likewise.
(breakpoint_1, print_it_catch_fork, print_it_catch_vfork, mention,
print_exception_catchpoint): Likewise.
* auxv.c (fprint_target_auxv): Don't declare addressprint. Use
get_user_print_options.
* ada-valprint.c (struct ada_val_print_args): Remove format,
deref_ref, and pretty; add options.
(print_optional_low_bound): Add options argument.
(val_print_packed_array_elements): Remove format and pretty
arguments; add options. Update.
(printstr): Add options argument. Update.
(ada_printstr): Likewise.
(ada_val_print): Remove format, deref_ref, pretty arguments; add
options argument. Update.
(ada_val_print_stub): Update.
(ada_val_print_array): Remove format, deref_ref, pretty arguments;
add options. Update.
(ada_val_print_1): Likewise.
(print_variant_part): Likewise.
(ada_value_print): Remove format, pretty arguments; add options.
Update.
(print_record): Likewise.
(print_field_values): Likewise.
* ada-lang.h (ada_val_print, ada_value_print, ada_printstr):
Update.
* ada-lang.c (ada_print_array_index): Add options argument; remove
format and pretty arguments.
(print_one_exception): Use get_user_print_options.
gdb/testsuite
* gdb.base/exprs.exp (test_expr): Add enum formatting tests.
2008-10-28 17:19:58 +00:00
|
|
|
|
get_user_print_options (&opts);
|
|
|
|
|
opts.deref_ref = 0;
|
|
|
|
|
|
2008-10-16 14:46:20 +00:00
|
|
|
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
|
|
|
|
{
|
2011-06-27 19:21:51 +00:00
|
|
|
|
struct ui_file *stb = mem_fileopen ();
|
|
|
|
|
struct cleanup *old_chain = make_cleanup_ui_file_delete (stb);
|
|
|
|
|
|
gdb
* varobj.c (value_get_print_value): Include valprint.h.
(value_get_print_value): Use get_formatted_print_options.
* value.h (struct value_print_options): Declare.
(value_print, val_print, common_val_print, val_print_string):
Update.
* value.c: Include valprint.h.
(show_values): Use get_user_print_options.
(show_convenience): Likewise.
* valprint.h (prettyprint_arrays, prettyprint_structs): Don't
declare.
(struct value_print_options): New type.
(vtblprint, unionprint, addressprint, objectprint, print_max,
inspect_it, repeat_count_threshold, output_format,
stop_print_at_null): Don't declare.
(user_print_options, get_user_print_options,
get_raw_print_options, get_formatted_print_options): Declare.
(print_array_indexes_p): Don't declare.
(maybe_print_array_index, val_print_array_elements): Update.
* valprint.c (print_max): Remove.
(user_print_options): New global.
(get_user_print_options, get_raw_print_options,
get_formatted_print_options): New functions.
(print_array_indexes, repeat_count_threshold, stop_print_at_null,
prettyprint_structs, prettyprint_arrays, unionprint,
addressprint): Remove.
(val_print): Remove format, deref_ref, pretty arguments; add
options. Update.
(common_val_print): Likewise.
(print_array_indexes_p): Remove.
(maybe_print_array_index): Remove format, pretty arguments; add
options. Update.
(val_print_array_elements): Remove format, deref_ref, pretty
arguments; add options. Update.
(val_print_string): Add options argument. Update.
(_initialize_valprint): Use user_print_options.
(output_format): Remove.
(set_output_radix_1): Use user_print_options.
* typeprint.c: Include valprint.h.
(objectprint): Don't declare.
(whatis_exp): Use get_user_print_options.
* tui/tui-regs.c: Include valprint.h.
(tui_register_format): Use get_formatted_print_options.
* tracepoint.c: Include valprint.h.
(addressprint): Don't declare.
(trace_mention): Use get_user_print_options.
(tracepoints_info): Likewise.
* stack.c (print_frame_args): Use get_raw_print_options.
(print_frame_info): Use get_user_print_options.
(print_frame): Likewise.
* sh64-tdep.c: Include valprint.h
(sh64_do_register): Use get_formatted_print_options.
* scm-valprint.c (scm_inferior_print): Remove format, deref_ref,
pretty arguments; add options.
(scm_scmlist_print): Likewise. Update.
(scm_scmval_print): Likewise.
(scm_val_print): Likewise.
(scm_value_print): Remove format, pretty arguments; add options.
Update.
* scm-lang.h (scm_value_print, scm_val_print, scm_scmval_print):
Update.
* scm-lang.c (scm_printstr): Add options argument.
* python/python-value.c: Include valprint.h.
(valpy_str): Use get_user_print_options.
* printcmd.c: Include valprint.h.
(addressprint): Don't declare.
(inspect_it): Remove.
(print_formatted): Remove format option; add options. Update.
(print_scalar_formatted): Likewise.
(print_address_demangle): Use get_user_print_options.
(do_examine): Use get_formatted_print_options.
(print_command_1): Likewise.
(output_command): Use get_formatted_print_options.
(do_one_display): Likewise.
(print_variable_value): Use get_user_print_options.
* p-valprint.c (pascal_val_print): Remove format, deref_ref,
pretty arguments; add options. Update.
(pascal_value_print): Remove format, pretty arguments; add
options. Update.
(vtblprint, objectprint): Don't declare.
(pascal_static_field_print): Remove.
(pascal_object_print_value_fields): Remove format, pretty
arguments; add options. Update.
(pascal_object_print_static_field): Likewise.
(_initialize_pascal_valprint): Use user_print_options. Update.
* p-lang.h (pascal_val_print, pascal_value_print,
pascal_printstr, pascal_object_print_value_fields): Update.
(vtblprint, static_field_print): Don't declare.
* p-lang.c (pascal_printstr): Add options argument. Update.
* objc-lang.c (objc_printstr): Add options argument. Update.
* mt-tdep.c: Include valprint.h.
(mt_registers_info): Use get_raw_print_options.
* mips-tdep.c: Include valprint.h.
(mips_print_fp_register): Use get_formatted_print_options.
(mips_print_register): Likewise.
* mi/mi-main.c: Include valprint.h.
(get_register): Use get_user_print_options.
(mi_cmd_data_evaluate_expression): Likewise.
(mi_cmd_data_read_memory): Use get_formatted_print_options.
* mi/mi-cmd-stack.c: Include valprint.h.
(list_args_or_locals): Use get_raw_print_options.
* m2-valprint.c (print_function_pointer_address): Add addressprint
argument.
(m2_print_long_set): Remove format, pretty arguments.
(m2_print_unbounded_array): Remove format, deref_ref, pretty
arguments; add options. Update.
(print_unpacked_pointer): Remove format argument; add options.
Now static. Update.
(print_variable_at_address): Remove format, deref_ref, pretty
arguments; add options. Update.
(m2_print_array_contents): Likewise.
(m2_val_print): Likewise.
* m2-lang.h (m2_val_print): Update.
* m2-lang.c (m2_printstr): Add options argument. Update.
* language.h (struct value_print_options): Declare.
(struct language_defn) <la_printstr>: Add options argument.
<la_val_print>: Remove format, deref_ref, pretty argument; add
options.
<la_value_print>: Remove format, pretty arguments; add options.
<la_print_array_index>: Likewise.
(LA_VAL_PRINT, LA_VALUE_PRINT, LA_PRINT_STRING,
LA_PRINT_ARRAY_INDEX): Update.
(default_print_array_index): Update.
* language.c (default_print_array_index): Remove format, pretty
arguments; add options. Update.
(unk_lang_printstr): Add options argument.
(unk_lang_val_print): Remove format, deref_ref, pretty arguments;
add options.
(unk_lang_value_print): Remove format, pretty arguments; add
options.
* jv-valprint.c (java_value_print): Remove format, pretty
arguments; add options. Update.
(java_print_value_fields): Likewise.
(java_val_print): Remove format, deref_ref, pretty arguments; add
options. Update.
* jv-lang.h (java_val_print, java_value_print): Declare.
* infcmd.c: Include valprint.h.
(print_return_value): Use get_raw_print_options.
(default_print_registers_info): Use get_user_print_options,
get_formatted_print_options.
(registers_info): Use get_formatted_print_options.
* gdbtypes.h (struct value_print_options): Declare.
(print_scalar_formatted): Update.
* f-valprint.c (f77_print_array_1): Remove format, deref_ref,
pretty arguments; add options. Update.
(f77_print_array): Likewise.
(f_val_print): Likewise.
* f-lang.h (f_val_print): Update.
* f-lang.c (f_printstr): Add options argument. Update.
(c_value_print): Update declaration.
* expprint.c: Include valprint.h.
(print_subexp_standard): Use get_raw_print_options,
get_user_print_options.
* eval.c: Include valprint.h.
(objectprint): Don't declare.
(evaluate_subexp_standard): Use get_user_print_options.
* cp-valprint.c (vtblprint, objectprint, static_field_print):
Remove.
(cp_print_value_fields): Remove format, pretty arguments; add
options. Update.
(cp_print_value): Likewise.
(cp_print_static_field): Likewise.
(_initialize_cp_valprint): Use user_print_options. Update.
* c-valprint.c (print_function_pointer_address): Add addressprint
argument.
(c_val_print): Remove format, deref_ref, pretty arguments; add
options. Update.
(c_value_print): Add options argument. Update.
* c-lang.h (c_val_print, c_value_print, c_printstr): Update.
(vtblprint, static_field_print): Don't declare.
(cp_print_value_fields): Update.
* c-lang.c (c_printstr): Add options argument. Update.
* breakpoint.c: Include valprint.h.
(addressprint): Don't declare.
(watchpoint_value_print): Use get_user_print_options.
(print_one_breakpoint_location): Likewise.
(breakpoint_1, print_it_catch_fork, print_it_catch_vfork, mention,
print_exception_catchpoint): Likewise.
* auxv.c (fprint_target_auxv): Don't declare addressprint. Use
get_user_print_options.
* ada-valprint.c (struct ada_val_print_args): Remove format,
deref_ref, and pretty; add options.
(print_optional_low_bound): Add options argument.
(val_print_packed_array_elements): Remove format and pretty
arguments; add options. Update.
(printstr): Add options argument. Update.
(ada_printstr): Likewise.
(ada_val_print): Remove format, deref_ref, pretty arguments; add
options argument. Update.
(ada_val_print_stub): Update.
(ada_val_print_array): Remove format, deref_ref, pretty arguments;
add options. Update.
(ada_val_print_1): Likewise.
(print_variant_part): Likewise.
(ada_value_print): Remove format, pretty arguments; add options.
Update.
(print_record): Likewise.
(print_field_values): Likewise.
* ada-lang.h (ada_val_print, ada_value_print, ada_printstr):
Update.
* ada-lang.c (ada_print_array_index): Add options argument; remove
format and pretty arguments.
(print_one_exception): Use get_user_print_options.
gdb/testsuite
* gdb.base/exprs.exp (test_expr): Add enum formatting tests.
2008-10-28 17:19:58 +00:00
|
|
|
|
common_val_print (((value_object *) self)->value, stb, 0,
|
* 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
|
|
|
|
&opts, python_language);
|
2009-08-14 00:32:33 +00:00
|
|
|
|
s = ui_file_xstrdup (stb, NULL);
|
2011-06-27 19:21:51 +00:00
|
|
|
|
|
|
|
|
|
do_cleanups (old_chain);
|
2008-10-16 14:46:20 +00:00
|
|
|
|
}
|
|
|
|
|
GDB_PY_HANDLE_EXCEPTION (except);
|
|
|
|
|
|
|
|
|
|
result = PyUnicode_Decode (s, strlen (s), host_charset (), NULL);
|
|
|
|
|
xfree (s);
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-26 20:58:11 +00:00
|
|
|
|
/* Implements gdb.Value.is_optimized_out. */
|
|
|
|
|
static PyObject *
|
|
|
|
|
valpy_get_is_optimized_out (PyObject *self, void *closure)
|
|
|
|
|
{
|
|
|
|
|
struct value *value = ((value_object *) self)->value;
|
2011-10-07 13:46:11 +00:00
|
|
|
|
int opt = 0;
|
|
|
|
|
volatile struct gdb_exception except;
|
2009-03-26 20:58:11 +00:00
|
|
|
|
|
2011-10-07 13:46:11 +00:00
|
|
|
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
|
|
|
|
{
|
|
|
|
|
opt = value_optimized_out (value);
|
|
|
|
|
}
|
|
|
|
|
GDB_PY_HANDLE_EXCEPTION (except);
|
|
|
|
|
|
|
|
|
|
if (opt)
|
2009-03-26 20:58:11 +00:00
|
|
|
|
Py_RETURN_TRUE;
|
|
|
|
|
|
|
|
|
|
Py_RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-25 18:34:51 +00:00
|
|
|
|
/* Implements gdb.Value.is_lazy. */
|
|
|
|
|
static PyObject *
|
|
|
|
|
valpy_get_is_lazy (PyObject *self, void *closure)
|
|
|
|
|
{
|
|
|
|
|
struct value *value = ((value_object *) self)->value;
|
|
|
|
|
int opt = 0;
|
|
|
|
|
volatile struct gdb_exception except;
|
|
|
|
|
|
|
|
|
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
|
|
|
|
{
|
|
|
|
|
opt = value_lazy (value);
|
|
|
|
|
}
|
|
|
|
|
GDB_PY_HANDLE_EXCEPTION (except);
|
|
|
|
|
|
|
|
|
|
if (opt)
|
|
|
|
|
Py_RETURN_TRUE;
|
|
|
|
|
|
|
|
|
|
Py_RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Implements gdb.Value.fetch_lazy (). */
|
|
|
|
|
static PyObject *
|
|
|
|
|
valpy_fetch_lazy (PyObject *self, PyObject *args)
|
|
|
|
|
{
|
|
|
|
|
struct value *value = ((value_object *) self)->value;
|
|
|
|
|
volatile struct gdb_exception except;
|
|
|
|
|
|
|
|
|
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
|
|
|
|
{
|
|
|
|
|
if (value_lazy (value))
|
|
|
|
|
value_fetch_lazy (value);
|
|
|
|
|
}
|
|
|
|
|
GDB_PY_HANDLE_EXCEPTION (except);
|
|
|
|
|
|
|
|
|
|
Py_RETURN_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-14 11:11:28 +00:00
|
|
|
|
/* Calculate and return the address of the PyObject as the value of
|
|
|
|
|
the builtin __hash__ call. */
|
2013-11-29 20:00:47 +00:00
|
|
|
|
static long
|
2010-05-14 11:11:28 +00:00
|
|
|
|
valpy_hash (PyObject *self)
|
|
|
|
|
{
|
|
|
|
|
return (long) (intptr_t) self;
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-16 14:46:20 +00:00
|
|
|
|
enum valpy_opcode
|
|
|
|
|
{
|
|
|
|
|
VALPY_ADD,
|
|
|
|
|
VALPY_SUB,
|
|
|
|
|
VALPY_MUL,
|
|
|
|
|
VALPY_DIV,
|
|
|
|
|
VALPY_REM,
|
2009-02-04 21:55:40 +00:00
|
|
|
|
VALPY_POW,
|
|
|
|
|
VALPY_LSH,
|
|
|
|
|
VALPY_RSH,
|
|
|
|
|
VALPY_BITAND,
|
|
|
|
|
VALPY_BITOR,
|
|
|
|
|
VALPY_BITXOR
|
2008-10-16 14:46:20 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* If TYPE is a reference, return the target; otherwise return TYPE. */
|
|
|
|
|
#define STRIP_REFERENCE(TYPE) \
|
|
|
|
|
((TYPE_CODE (TYPE) == TYPE_CODE_REF) ? (TYPE_TARGET_TYPE (TYPE)) : (TYPE))
|
|
|
|
|
|
|
|
|
|
/* Returns a value object which is the result of applying the operation
|
2010-10-13 13:24:40 +00:00
|
|
|
|
specified by OPCODE to the given arguments. Returns NULL on error, with
|
|
|
|
|
a python exception set. */
|
2008-10-16 14:46:20 +00:00
|
|
|
|
static PyObject *
|
|
|
|
|
valpy_binop (enum valpy_opcode opcode, PyObject *self, PyObject *other)
|
|
|
|
|
{
|
|
|
|
|
volatile struct gdb_exception except;
|
2012-01-03 19:27:52 +00:00
|
|
|
|
PyObject *result = NULL;
|
2008-10-16 14:46:20 +00:00
|
|
|
|
|
|
|
|
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
|
|
|
|
{
|
|
|
|
|
struct value *arg1, *arg2;
|
2012-01-03 19:27:52 +00:00
|
|
|
|
struct cleanup *cleanup = make_cleanup_value_free_to_mark (value_mark ());
|
2012-01-04 16:15:14 +00:00
|
|
|
|
struct value *res_val = NULL;
|
2013-12-02 14:45:09 +00:00
|
|
|
|
enum exp_opcode op = OP_NULL;
|
|
|
|
|
int handled = 0;
|
2008-10-16 14:46:20 +00:00
|
|
|
|
|
|
|
|
|
/* If the gdb.Value object is the second operand, then it will be passed
|
|
|
|
|
to us as the OTHER argument, and SELF will be an entirely different
|
|
|
|
|
kind of object, altogether. Because of this, we can't assume self is
|
|
|
|
|
a gdb.Value object and need to convert it from python as well. */
|
|
|
|
|
arg1 = convert_value_from_python (self);
|
2009-02-04 21:55:40 +00:00
|
|
|
|
if (arg1 == NULL)
|
2013-05-30 17:18:54 +00:00
|
|
|
|
{
|
|
|
|
|
do_cleanups (cleanup);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2009-02-04 21:55:40 +00:00
|
|
|
|
|
2008-10-16 14:46:20 +00:00
|
|
|
|
arg2 = convert_value_from_python (other);
|
2009-02-04 21:55:40 +00:00
|
|
|
|
if (arg2 == NULL)
|
2013-05-30 17:18:54 +00:00
|
|
|
|
{
|
|
|
|
|
do_cleanups (cleanup);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2008-10-16 14:46:20 +00:00
|
|
|
|
|
|
|
|
|
switch (opcode)
|
|
|
|
|
{
|
|
|
|
|
case VALPY_ADD:
|
|
|
|
|
{
|
|
|
|
|
struct type *ltype = value_type (arg1);
|
|
|
|
|
struct type *rtype = value_type (arg2);
|
|
|
|
|
|
|
|
|
|
CHECK_TYPEDEF (ltype);
|
|
|
|
|
ltype = STRIP_REFERENCE (ltype);
|
|
|
|
|
CHECK_TYPEDEF (rtype);
|
|
|
|
|
rtype = STRIP_REFERENCE (rtype);
|
|
|
|
|
|
2013-12-02 14:45:09 +00:00
|
|
|
|
handled = 1;
|
* value.h (value_subscript, value_subscripted_rvalue,
value_bitstring_subscript, value_ptradd): Use LONGEST instead
of value as type of the index argument.
(value_ptrsub): Remove.
* valarith.c (value_subscript, value_subscripted_rvalue,
value_bitstring_subscript, value_ptradd): Use LONGEST instead
of value as type of the index argument.
(value_ptrsub): Remove.
* wrapper.h (gdb_value_subscript): Use LONGEST instead of
value as type of the index argument.
* wrapper.c (gdb_value_subscript): Likewise.
Update calls to gdb_value_subscript, value_subscript,
value_subscripted_rvalue, value_bitstring_subscript and
value_ptradd to use LONGEST instead of value as index
argument type. Use value_ptradd instead of value_ptrsub.
* ada-lang.c (ada_value_subscript, ada_value_ptr_subscript,
ada_tag_name_2): Update.
* ada-tasks.c (read_atcb): Update.
* eval.c (evaluate_subexp_standard): Update.
* valarith.c (value_subscript): Update.
* gnu-v2-abi.c (gnuv2_virtual_fn_field): Update.
* gnu-v3-abi.c (gnuv3_get_virtual_fn, gnuv3_baseclass_offset,
gnuv3_method_ptr_to_value): Update.
* jv-lang.c (evaluate_subexp_java): Update.
* m2-lang.c (evaluate_subexp_modula2): Update.
* python/python-value.c (valpy_getitem, valpy_binop): Update.
* wrapper.c (gdb_value_subscript): Update.
* varobj.c (c_describe_child): Update.
2009-06-29 13:24:41 +00:00
|
|
|
|
if (TYPE_CODE (ltype) == TYPE_CODE_PTR
|
|
|
|
|
&& is_integral_type (rtype))
|
|
|
|
|
res_val = value_ptradd (arg1, value_as_long (arg2));
|
|
|
|
|
else if (TYPE_CODE (rtype) == TYPE_CODE_PTR
|
|
|
|
|
&& is_integral_type (ltype))
|
|
|
|
|
res_val = value_ptradd (arg2, value_as_long (arg1));
|
2008-10-16 14:46:20 +00:00
|
|
|
|
else
|
2013-12-02 14:45:09 +00:00
|
|
|
|
{
|
|
|
|
|
handled = 0;
|
|
|
|
|
op = BINOP_ADD;
|
|
|
|
|
}
|
2008-10-16 14:46:20 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case VALPY_SUB:
|
|
|
|
|
{
|
|
|
|
|
struct type *ltype = value_type (arg1);
|
|
|
|
|
struct type *rtype = value_type (arg2);
|
|
|
|
|
|
|
|
|
|
CHECK_TYPEDEF (ltype);
|
|
|
|
|
ltype = STRIP_REFERENCE (ltype);
|
|
|
|
|
CHECK_TYPEDEF (rtype);
|
|
|
|
|
rtype = STRIP_REFERENCE (rtype);
|
|
|
|
|
|
2013-12-02 14:45:09 +00:00
|
|
|
|
handled = 1;
|
* value.h (value_subscript, value_subscripted_rvalue,
value_bitstring_subscript, value_ptradd): Use LONGEST instead
of value as type of the index argument.
(value_ptrsub): Remove.
* valarith.c (value_subscript, value_subscripted_rvalue,
value_bitstring_subscript, value_ptradd): Use LONGEST instead
of value as type of the index argument.
(value_ptrsub): Remove.
* wrapper.h (gdb_value_subscript): Use LONGEST instead of
value as type of the index argument.
* wrapper.c (gdb_value_subscript): Likewise.
Update calls to gdb_value_subscript, value_subscript,
value_subscripted_rvalue, value_bitstring_subscript and
value_ptradd to use LONGEST instead of value as index
argument type. Use value_ptradd instead of value_ptrsub.
* ada-lang.c (ada_value_subscript, ada_value_ptr_subscript,
ada_tag_name_2): Update.
* ada-tasks.c (read_atcb): Update.
* eval.c (evaluate_subexp_standard): Update.
* valarith.c (value_subscript): Update.
* gnu-v2-abi.c (gnuv2_virtual_fn_field): Update.
* gnu-v3-abi.c (gnuv3_get_virtual_fn, gnuv3_baseclass_offset,
gnuv3_method_ptr_to_value): Update.
* jv-lang.c (evaluate_subexp_java): Update.
* m2-lang.c (evaluate_subexp_modula2): Update.
* python/python-value.c (valpy_getitem, valpy_binop): Update.
* wrapper.c (gdb_value_subscript): Update.
* varobj.c (c_describe_child): Update.
2009-06-29 13:24:41 +00:00
|
|
|
|
if (TYPE_CODE (ltype) == TYPE_CODE_PTR
|
|
|
|
|
&& TYPE_CODE (rtype) == TYPE_CODE_PTR)
|
|
|
|
|
/* A ptrdiff_t for the target would be preferable here. */
|
|
|
|
|
res_val = value_from_longest (builtin_type_pyint,
|
|
|
|
|
value_ptrdiff (arg1, arg2));
|
|
|
|
|
else if (TYPE_CODE (ltype) == TYPE_CODE_PTR
|
|
|
|
|
&& is_integral_type (rtype))
|
|
|
|
|
res_val = value_ptradd (arg1, - value_as_long (arg2));
|
2008-10-16 14:46:20 +00:00
|
|
|
|
else
|
2013-12-02 14:45:09 +00:00
|
|
|
|
{
|
|
|
|
|
handled = 0;
|
|
|
|
|
op = BINOP_SUB;
|
|
|
|
|
}
|
2008-10-16 14:46:20 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case VALPY_MUL:
|
2013-12-02 14:45:09 +00:00
|
|
|
|
op = BINOP_MUL;
|
2008-10-16 14:46:20 +00:00
|
|
|
|
break;
|
|
|
|
|
case VALPY_DIV:
|
2013-12-02 14:45:09 +00:00
|
|
|
|
op = BINOP_DIV;
|
2008-10-16 14:46:20 +00:00
|
|
|
|
break;
|
|
|
|
|
case VALPY_REM:
|
2013-12-02 14:45:09 +00:00
|
|
|
|
op = BINOP_REM;
|
2008-10-16 14:46:20 +00:00
|
|
|
|
break;
|
|
|
|
|
case VALPY_POW:
|
2013-12-02 14:45:09 +00:00
|
|
|
|
op = BINOP_EXP;
|
2008-10-16 14:46:20 +00:00
|
|
|
|
break;
|
2009-02-04 21:55:40 +00:00
|
|
|
|
case VALPY_LSH:
|
2013-12-02 14:45:09 +00:00
|
|
|
|
op = BINOP_LSH;
|
2009-02-04 21:55:40 +00:00
|
|
|
|
break;
|
|
|
|
|
case VALPY_RSH:
|
2013-12-02 14:45:09 +00:00
|
|
|
|
op = BINOP_RSH;
|
2009-02-04 21:55:40 +00:00
|
|
|
|
break;
|
|
|
|
|
case VALPY_BITAND:
|
2013-12-02 14:45:09 +00:00
|
|
|
|
op = BINOP_BITWISE_AND;
|
2009-02-04 21:55:40 +00:00
|
|
|
|
break;
|
|
|
|
|
case VALPY_BITOR:
|
2013-12-02 14:45:09 +00:00
|
|
|
|
op = BINOP_BITWISE_IOR;
|
2009-02-04 21:55:40 +00:00
|
|
|
|
break;
|
|
|
|
|
case VALPY_BITXOR:
|
2013-12-02 14:45:09 +00:00
|
|
|
|
op = BINOP_BITWISE_XOR;
|
2009-02-04 21:55:40 +00:00
|
|
|
|
break;
|
2008-10-16 14:46:20 +00:00
|
|
|
|
}
|
2012-01-03 19:27:52 +00:00
|
|
|
|
|
2013-12-02 14:45:09 +00:00
|
|
|
|
if (!handled)
|
|
|
|
|
{
|
|
|
|
|
if (binop_user_defined_p (op, arg1, arg2))
|
|
|
|
|
res_val = value_x_binop (arg1, arg2, op, OP_NULL, EVAL_NORMAL);
|
|
|
|
|
else
|
|
|
|
|
res_val = value_binop (arg1, arg2, op);
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-03 19:27:52 +00:00
|
|
|
|
if (res_val)
|
|
|
|
|
result = value_to_value_object (res_val);
|
|
|
|
|
|
|
|
|
|
do_cleanups (cleanup);
|
2008-10-16 14:46:20 +00:00
|
|
|
|
}
|
|
|
|
|
GDB_PY_HANDLE_EXCEPTION (except);
|
|
|
|
|
|
2012-01-03 19:27:52 +00:00
|
|
|
|
return result;
|
2008-10-16 14:46:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
|
valpy_add (PyObject *self, PyObject *other)
|
|
|
|
|
{
|
|
|
|
|
return valpy_binop (VALPY_ADD, self, other);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
|
valpy_subtract (PyObject *self, PyObject *other)
|
|
|
|
|
{
|
|
|
|
|
return valpy_binop (VALPY_SUB, self, other);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
|
valpy_multiply (PyObject *self, PyObject *other)
|
|
|
|
|
{
|
|
|
|
|
return valpy_binop (VALPY_MUL, self, other);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
|
valpy_divide (PyObject *self, PyObject *other)
|
|
|
|
|
{
|
|
|
|
|
return valpy_binop (VALPY_DIV, self, other);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
|
valpy_remainder (PyObject *self, PyObject *other)
|
|
|
|
|
{
|
|
|
|
|
return valpy_binop (VALPY_REM, self, other);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
|
valpy_power (PyObject *self, PyObject *other, PyObject *unused)
|
|
|
|
|
{
|
|
|
|
|
/* We don't support the ternary form of pow. I don't know how to express
|
|
|
|
|
that, so let's just throw NotImplementedError to at least do something
|
|
|
|
|
about it. */
|
|
|
|
|
if (unused != Py_None)
|
|
|
|
|
{
|
|
|
|
|
PyErr_SetString (PyExc_NotImplementedError,
|
|
|
|
|
"Invalid operation on gdb.Value.");
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return valpy_binop (VALPY_POW, self, other);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
|
valpy_negative (PyObject *self)
|
|
|
|
|
{
|
|
|
|
|
volatile struct gdb_exception except;
|
2012-01-03 19:27:52 +00:00
|
|
|
|
PyObject *result = NULL;
|
2008-10-16 14:46:20 +00:00
|
|
|
|
|
|
|
|
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
|
|
|
|
{
|
2012-01-03 19:27:52 +00:00
|
|
|
|
/* Perhaps overkill, but consistency has some virtue. */
|
|
|
|
|
struct cleanup *cleanup = make_cleanup_value_free_to_mark (value_mark ());
|
|
|
|
|
struct value *val;
|
|
|
|
|
|
2008-10-16 14:46:20 +00:00
|
|
|
|
val = value_neg (((value_object *) self)->value);
|
2012-01-03 19:27:52 +00:00
|
|
|
|
result = value_to_value_object (val);
|
|
|
|
|
do_cleanups (cleanup);
|
2008-10-16 14:46:20 +00:00
|
|
|
|
}
|
|
|
|
|
GDB_PY_HANDLE_EXCEPTION (except);
|
|
|
|
|
|
2012-01-03 19:27:52 +00:00
|
|
|
|
return result;
|
2008-10-16 14:46:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
|
valpy_positive (PyObject *self)
|
|
|
|
|
{
|
2009-08-13 18:39:20 +00:00
|
|
|
|
return value_to_value_object (((value_object *) self)->value);
|
2008-10-16 14:46:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
|
valpy_absolute (PyObject *self)
|
|
|
|
|
{
|
2009-07-02 12:20:18 +00:00
|
|
|
|
struct value *value = ((value_object *) self)->value;
|
2011-10-07 13:46:11 +00:00
|
|
|
|
volatile struct gdb_exception except;
|
|
|
|
|
int isabs = 1;
|
2010-05-17 21:23:25 +00:00
|
|
|
|
|
2011-10-07 13:46:11 +00:00
|
|
|
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
|
|
|
|
{
|
2012-01-03 19:27:52 +00:00
|
|
|
|
struct cleanup *cleanup = make_cleanup_value_free_to_mark (value_mark ());
|
|
|
|
|
|
2011-10-07 13:46:11 +00:00
|
|
|
|
if (value_less (value, value_zero (value_type (value), not_lval)))
|
|
|
|
|
isabs = 0;
|
2012-01-03 19:27:52 +00:00
|
|
|
|
|
|
|
|
|
do_cleanups (cleanup);
|
2011-10-07 13:46:11 +00:00
|
|
|
|
}
|
|
|
|
|
GDB_PY_HANDLE_EXCEPTION (except);
|
|
|
|
|
|
|
|
|
|
if (isabs)
|
2008-10-16 14:46:20 +00:00
|
|
|
|
return valpy_positive (self);
|
2011-10-07 13:46:11 +00:00
|
|
|
|
else
|
|
|
|
|
return valpy_negative (self);
|
2008-10-16 14:46:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Implements boolean evaluation of gdb.Value. */
|
|
|
|
|
static int
|
|
|
|
|
valpy_nonzero (PyObject *self)
|
|
|
|
|
{
|
2011-10-07 13:46:11 +00:00
|
|
|
|
volatile struct gdb_exception except;
|
2008-10-16 14:46:20 +00:00
|
|
|
|
value_object *self_value = (value_object *) self;
|
|
|
|
|
struct type *type;
|
2011-10-07 13:46:11 +00:00
|
|
|
|
int nonzero = 0; /* Appease GCC warning. */
|
2008-10-16 14:46:20 +00:00
|
|
|
|
|
2011-10-07 13:46:11 +00:00
|
|
|
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
|
|
|
|
{
|
2011-11-28 15:49:43 +00:00
|
|
|
|
type = check_typedef (value_type (self_value->value));
|
|
|
|
|
|
2011-10-07 13:46:11 +00:00
|
|
|
|
if (is_integral_type (type) || TYPE_CODE (type) == TYPE_CODE_PTR)
|
|
|
|
|
nonzero = !!value_as_long (self_value->value);
|
|
|
|
|
else if (TYPE_CODE (type) == TYPE_CODE_FLT)
|
|
|
|
|
nonzero = value_as_double (self_value->value) != 0;
|
|
|
|
|
else if (TYPE_CODE (type) == TYPE_CODE_DECFLOAT)
|
|
|
|
|
nonzero = !decimal_is_zero (value_contents (self_value->value),
|
|
|
|
|
TYPE_LENGTH (type),
|
|
|
|
|
gdbarch_byte_order (get_type_arch (type)));
|
|
|
|
|
else
|
|
|
|
|
/* All other values are True. */
|
|
|
|
|
nonzero = 1;
|
|
|
|
|
}
|
|
|
|
|
/* This is not documented in the Python documentation, but if this
|
|
|
|
|
function fails, return -1 as slot_nb_nonzero does (the default
|
|
|
|
|
Python nonzero function). */
|
|
|
|
|
GDB_PY_SET_HANDLE_EXCEPTION (except);
|
|
|
|
|
|
|
|
|
|
return nonzero;
|
2008-10-16 14:46:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-02-04 21:55:40 +00:00
|
|
|
|
/* Implements ~ for value objects. */
|
2008-10-16 14:46:20 +00:00
|
|
|
|
static PyObject *
|
2009-02-04 21:55:40 +00:00
|
|
|
|
valpy_invert (PyObject *self)
|
2008-10-16 14:46:20 +00:00
|
|
|
|
{
|
2009-02-04 21:55:40 +00:00
|
|
|
|
struct value *val = NULL;
|
2008-10-16 14:46:20 +00:00
|
|
|
|
volatile struct gdb_exception except;
|
|
|
|
|
|
2009-02-04 21:55:40 +00:00
|
|
|
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
2008-10-16 14:46:20 +00:00
|
|
|
|
{
|
2009-02-04 21:55:40 +00:00
|
|
|
|
val = value_complement (((value_object *) self)->value);
|
|
|
|
|
}
|
|
|
|
|
GDB_PY_HANDLE_EXCEPTION (except);
|
2008-10-16 14:46:20 +00:00
|
|
|
|
|
2009-02-04 21:55:40 +00:00
|
|
|
|
return value_to_value_object (val);
|
|
|
|
|
}
|
2008-10-16 14:46:20 +00:00
|
|
|
|
|
2009-02-04 21:55:40 +00:00
|
|
|
|
/* Implements left shift for value objects. */
|
|
|
|
|
static PyObject *
|
|
|
|
|
valpy_lsh (PyObject *self, PyObject *other)
|
|
|
|
|
{
|
|
|
|
|
return valpy_binop (VALPY_LSH, self, other);
|
|
|
|
|
}
|
2008-10-16 14:46:20 +00:00
|
|
|
|
|
2009-02-04 21:55:40 +00:00
|
|
|
|
/* Implements right shift for value objects. */
|
|
|
|
|
static PyObject *
|
|
|
|
|
valpy_rsh (PyObject *self, PyObject *other)
|
|
|
|
|
{
|
|
|
|
|
return valpy_binop (VALPY_RSH, self, other);
|
|
|
|
|
}
|
2008-10-16 14:46:20 +00:00
|
|
|
|
|
2009-02-04 21:55:40 +00:00
|
|
|
|
/* Implements bitwise and for value objects. */
|
|
|
|
|
static PyObject *
|
|
|
|
|
valpy_and (PyObject *self, PyObject *other)
|
|
|
|
|
{
|
|
|
|
|
return valpy_binop (VALPY_BITAND, self, other);
|
|
|
|
|
}
|
2008-10-16 14:46:20 +00:00
|
|
|
|
|
2009-02-04 21:55:40 +00:00
|
|
|
|
/* Implements bitwise or for value objects. */
|
|
|
|
|
static PyObject *
|
|
|
|
|
valpy_or (PyObject *self, PyObject *other)
|
|
|
|
|
{
|
|
|
|
|
return valpy_binop (VALPY_BITOR, self, other);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Implements bitwise xor for value objects. */
|
|
|
|
|
static PyObject *
|
|
|
|
|
valpy_xor (PyObject *self, PyObject *other)
|
|
|
|
|
{
|
|
|
|
|
return valpy_binop (VALPY_BITXOR, self, other);
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-13 13:24:40 +00:00
|
|
|
|
/* Implements comparison operations for value objects. Returns NULL on error,
|
|
|
|
|
with a python exception set. */
|
2009-02-04 21:55:40 +00:00
|
|
|
|
static PyObject *
|
|
|
|
|
valpy_richcompare (PyObject *self, PyObject *other, int op)
|
|
|
|
|
{
|
|
|
|
|
int result = 0;
|
|
|
|
|
volatile struct gdb_exception except;
|
|
|
|
|
|
|
|
|
|
if (other == Py_None)
|
2008-10-16 14:46:20 +00:00
|
|
|
|
/* Comparing with None is special. From what I can tell, in Python
|
|
|
|
|
None is smaller than anything else. */
|
|
|
|
|
switch (op) {
|
|
|
|
|
case Py_LT:
|
|
|
|
|
case Py_LE:
|
|
|
|
|
case Py_EQ:
|
|
|
|
|
Py_RETURN_FALSE;
|
|
|
|
|
case Py_NE:
|
|
|
|
|
case Py_GT:
|
|
|
|
|
case Py_GE:
|
|
|
|
|
Py_RETURN_TRUE;
|
|
|
|
|
default:
|
|
|
|
|
/* Can't happen. */
|
|
|
|
|
PyErr_SetString (PyExc_NotImplementedError,
|
2010-04-14 13:18:55 +00:00
|
|
|
|
_("Invalid operation on gdb.Value."));
|
2008-10-16 14:46:20 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
|
|
|
|
{
|
2012-01-03 19:27:52 +00:00
|
|
|
|
struct value *value_other, *mark = value_mark ();
|
|
|
|
|
struct cleanup *cleanup;
|
|
|
|
|
|
2009-02-04 21:55:40 +00:00
|
|
|
|
value_other = convert_value_from_python (other);
|
|
|
|
|
if (value_other == NULL)
|
2009-08-24 18:55:21 +00:00
|
|
|
|
{
|
|
|
|
|
result = -1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2009-02-04 21:55:40 +00:00
|
|
|
|
|
2012-01-03 19:27:52 +00:00
|
|
|
|
cleanup = make_cleanup_value_free_to_mark (mark);
|
|
|
|
|
|
2008-10-16 14:46:20 +00:00
|
|
|
|
switch (op) {
|
|
|
|
|
case Py_LT:
|
|
|
|
|
result = value_less (((value_object *) self)->value, value_other);
|
|
|
|
|
break;
|
|
|
|
|
case Py_LE:
|
|
|
|
|
result = value_less (((value_object *) self)->value, value_other)
|
|
|
|
|
|| value_equal (((value_object *) self)->value, value_other);
|
|
|
|
|
break;
|
|
|
|
|
case Py_EQ:
|
|
|
|
|
result = value_equal (((value_object *) self)->value, value_other);
|
|
|
|
|
break;
|
|
|
|
|
case Py_NE:
|
|
|
|
|
result = !value_equal (((value_object *) self)->value, value_other);
|
|
|
|
|
break;
|
|
|
|
|
case Py_GT:
|
|
|
|
|
result = value_less (value_other, ((value_object *) self)->value);
|
|
|
|
|
break;
|
|
|
|
|
case Py_GE:
|
|
|
|
|
result = value_less (value_other, ((value_object *) self)->value)
|
|
|
|
|
|| value_equal (((value_object *) self)->value, value_other);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
/* Can't happen. */
|
|
|
|
|
PyErr_SetString (PyExc_NotImplementedError,
|
2010-04-14 13:18:55 +00:00
|
|
|
|
_("Invalid operation on gdb.Value."));
|
2009-08-24 18:55:21 +00:00
|
|
|
|
result = -1;
|
|
|
|
|
break;
|
2008-10-16 14:46:20 +00:00
|
|
|
|
}
|
2012-01-03 19:27:52 +00:00
|
|
|
|
|
|
|
|
|
do_cleanups (cleanup);
|
2008-10-16 14:46:20 +00:00
|
|
|
|
}
|
|
|
|
|
GDB_PY_HANDLE_EXCEPTION (except);
|
|
|
|
|
|
2009-08-24 18:55:21 +00:00
|
|
|
|
/* In this case, the Python exception has already been set. */
|
|
|
|
|
if (result < 0)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
2008-10-16 14:46:20 +00:00
|
|
|
|
if (result == 1)
|
|
|
|
|
Py_RETURN_TRUE;
|
|
|
|
|
|
|
|
|
|
Py_RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-12 16:47:30 +00:00
|
|
|
|
#ifndef IS_PY3K
|
2009-02-04 21:55:40 +00:00
|
|
|
|
/* Implements conversion to int. */
|
|
|
|
|
static PyObject *
|
|
|
|
|
valpy_int (PyObject *self)
|
|
|
|
|
{
|
|
|
|
|
struct value *value = ((value_object *) self)->value;
|
|
|
|
|
struct type *type = value_type (value);
|
|
|
|
|
LONGEST l = 0;
|
|
|
|
|
volatile struct gdb_exception except;
|
|
|
|
|
|
|
|
|
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
|
|
|
|
{
|
2013-11-19 02:56:00 +00:00
|
|
|
|
if (!is_integral_type (type))
|
2011-10-07 13:46:11 +00:00
|
|
|
|
error (_("Cannot convert value to int."));
|
|
|
|
|
|
2009-02-04 21:55:40 +00:00
|
|
|
|
l = value_as_long (value);
|
|
|
|
|
}
|
|
|
|
|
GDB_PY_HANDLE_EXCEPTION (except);
|
|
|
|
|
|
2011-01-26 20:53:45 +00:00
|
|
|
|
return gdb_py_object_from_longest (l);
|
2009-02-04 21:55:40 +00:00
|
|
|
|
}
|
2012-12-12 16:47:30 +00:00
|
|
|
|
#endif
|
2009-02-04 21:55:40 +00:00
|
|
|
|
|
|
|
|
|
/* Implements conversion to long. */
|
|
|
|
|
static PyObject *
|
|
|
|
|
valpy_long (PyObject *self)
|
|
|
|
|
{
|
|
|
|
|
struct value *value = ((value_object *) self)->value;
|
|
|
|
|
struct type *type = value_type (value);
|
|
|
|
|
LONGEST l = 0;
|
|
|
|
|
volatile struct gdb_exception except;
|
|
|
|
|
|
|
|
|
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
|
|
|
|
{
|
2011-10-07 13:46:11 +00:00
|
|
|
|
CHECK_TYPEDEF (type);
|
|
|
|
|
|
2013-11-19 02:56:00 +00:00
|
|
|
|
if (!is_integral_type (type)
|
|
|
|
|
&& TYPE_CODE (type) != TYPE_CODE_PTR)
|
2011-10-07 13:46:11 +00:00
|
|
|
|
error (_("Cannot convert value to long."));
|
|
|
|
|
|
2009-02-04 21:55:40 +00:00
|
|
|
|
l = value_as_long (value);
|
|
|
|
|
}
|
|
|
|
|
GDB_PY_HANDLE_EXCEPTION (except);
|
|
|
|
|
|
2011-01-26 20:53:45 +00:00
|
|
|
|
return gdb_py_long_from_longest (l);
|
2009-02-04 21:55:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Implements conversion to float. */
|
|
|
|
|
static PyObject *
|
|
|
|
|
valpy_float (PyObject *self)
|
|
|
|
|
{
|
|
|
|
|
struct value *value = ((value_object *) self)->value;
|
|
|
|
|
struct type *type = value_type (value);
|
|
|
|
|
double d = 0;
|
|
|
|
|
volatile struct gdb_exception except;
|
|
|
|
|
|
|
|
|
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
|
|
|
|
{
|
2011-10-07 13:46:11 +00:00
|
|
|
|
CHECK_TYPEDEF (type);
|
|
|
|
|
|
|
|
|
|
if (TYPE_CODE (type) != TYPE_CODE_FLT)
|
|
|
|
|
error (_("Cannot convert value to float."));
|
|
|
|
|
|
2009-02-04 21:55:40 +00:00
|
|
|
|
d = value_as_double (value);
|
|
|
|
|
}
|
|
|
|
|
GDB_PY_HANDLE_EXCEPTION (except);
|
|
|
|
|
|
|
|
|
|
return PyFloat_FromDouble (d);
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-16 14:46:20 +00:00
|
|
|
|
/* Returns an object for a value which is released from the all_values chain,
|
|
|
|
|
so its lifetime is not bound to the execution of a command. */
|
|
|
|
|
PyObject *
|
|
|
|
|
value_to_value_object (struct value *val)
|
|
|
|
|
{
|
|
|
|
|
value_object *val_obj;
|
|
|
|
|
|
|
|
|
|
val_obj = PyObject_New (value_object, &value_object_type);
|
|
|
|
|
if (val_obj != NULL)
|
|
|
|
|
{
|
|
|
|
|
val_obj->value = val;
|
2011-12-22 19:51:10 +00:00
|
|
|
|
release_value_or_incref (val);
|
2009-03-29 21:11:11 +00:00
|
|
|
|
val_obj->address = NULL;
|
2009-05-28 00:47:20 +00:00
|
|
|
|
val_obj->type = NULL;
|
2010-08-30 20:28:31 +00:00
|
|
|
|
val_obj->dynamic_type = NULL;
|
2009-08-13 18:39:20 +00:00
|
|
|
|
note_value (val_obj);
|
2008-10-16 14:46:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (PyObject *) val_obj;
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-13 18:39:20 +00:00
|
|
|
|
/* Returns a borrowed reference to the struct value corresponding to
|
|
|
|
|
the given value object. */
|
2009-05-28 01:05:14 +00:00
|
|
|
|
struct value *
|
|
|
|
|
value_object_to_value (PyObject *self)
|
|
|
|
|
{
|
|
|
|
|
value_object *real;
|
2010-05-17 21:23:25 +00:00
|
|
|
|
|
2009-05-28 01:05:14 +00:00
|
|
|
|
if (! PyObject_TypeCheck (self, &value_object_type))
|
|
|
|
|
return NULL;
|
|
|
|
|
real = (value_object *) self;
|
|
|
|
|
return real->value;
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-16 14:46:20 +00:00
|
|
|
|
/* Try to convert a Python value to a gdb value. If the value cannot
|
2009-08-13 18:39:20 +00:00
|
|
|
|
be converted, set a Python exception and return NULL. Returns a
|
|
|
|
|
reference to a new value on the all_values chain. */
|
2008-10-16 14:46:20 +00:00
|
|
|
|
|
|
|
|
|
struct value *
|
|
|
|
|
convert_value_from_python (PyObject *obj)
|
|
|
|
|
{
|
|
|
|
|
struct value *value = NULL; /* -Wall */
|
2009-02-04 21:55:40 +00:00
|
|
|
|
volatile struct gdb_exception except;
|
|
|
|
|
int cmp;
|
2008-10-16 14:46:20 +00:00
|
|
|
|
|
2009-02-04 21:55:40 +00:00
|
|
|
|
gdb_assert (obj != NULL);
|
2008-10-16 14:46:20 +00:00
|
|
|
|
|
2009-02-04 21:55:40 +00:00
|
|
|
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
2008-10-16 14:46:20 +00:00
|
|
|
|
{
|
2013-11-29 20:00:47 +00:00
|
|
|
|
if (PyBool_Check (obj))
|
2009-02-04 21:55:40 +00:00
|
|
|
|
{
|
|
|
|
|
cmp = PyObject_IsTrue (obj);
|
|
|
|
|
if (cmp >= 0)
|
|
|
|
|
value = value_from_longest (builtin_type_pybool, cmp);
|
|
|
|
|
}
|
2013-10-03 14:43:32 +00:00
|
|
|
|
/* Make a long logic check first. In Python 3.x, internally,
|
|
|
|
|
all integers are represented as longs. In Python 2.x, there
|
|
|
|
|
is still a differentiation internally between a PyInt and a
|
|
|
|
|
PyLong. Explicitly do this long check conversion first. In
|
|
|
|
|
GDB, for Python 3.x, we #ifdef PyInt = PyLong. This check has
|
|
|
|
|
to be done first to ensure we do not lose information in the
|
|
|
|
|
conversion process. */
|
2009-02-04 21:55:40 +00:00
|
|
|
|
else if (PyLong_Check (obj))
|
|
|
|
|
{
|
|
|
|
|
LONGEST l = PyLong_AsLongLong (obj);
|
2008-10-16 14:46:20 +00:00
|
|
|
|
|
2010-06-28 21:16:04 +00:00
|
|
|
|
if (PyErr_Occurred ())
|
|
|
|
|
{
|
|
|
|
|
/* If the error was an overflow, we can try converting to
|
|
|
|
|
ULONGEST instead. */
|
|
|
|
|
if (PyErr_ExceptionMatches (PyExc_OverflowError))
|
|
|
|
|
{
|
|
|
|
|
PyObject *etype, *evalue, *etraceback, *zero;
|
|
|
|
|
|
|
|
|
|
PyErr_Fetch (&etype, &evalue, &etraceback);
|
|
|
|
|
zero = PyInt_FromLong (0);
|
|
|
|
|
|
|
|
|
|
/* Check whether obj is positive. */
|
|
|
|
|
if (PyObject_RichCompareBool (obj, zero, Py_GT) > 0)
|
|
|
|
|
{
|
|
|
|
|
ULONGEST ul;
|
|
|
|
|
|
|
|
|
|
ul = PyLong_AsUnsignedLongLong (obj);
|
|
|
|
|
if (! PyErr_Occurred ())
|
|
|
|
|
value = value_from_ulongest (builtin_type_upylong, ul);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
/* There's nothing we can do. */
|
|
|
|
|
PyErr_Restore (etype, evalue, etraceback);
|
|
|
|
|
|
|
|
|
|
Py_DECREF (zero);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
2009-02-04 21:55:40 +00:00
|
|
|
|
value = value_from_longest (builtin_type_pylong, l);
|
|
|
|
|
}
|
2013-10-03 14:43:32 +00:00
|
|
|
|
else if (PyInt_Check (obj))
|
|
|
|
|
{
|
|
|
|
|
long l = PyInt_AsLong (obj);
|
|
|
|
|
|
|
|
|
|
if (! PyErr_Occurred ())
|
|
|
|
|
value = value_from_longest (builtin_type_pyint, l);
|
|
|
|
|
}
|
2009-02-04 21:55:40 +00:00
|
|
|
|
else if (PyFloat_Check (obj))
|
|
|
|
|
{
|
|
|
|
|
double d = PyFloat_AsDouble (obj);
|
2008-10-16 14:46:20 +00:00
|
|
|
|
|
2009-02-04 21:55:40 +00:00
|
|
|
|
if (! PyErr_Occurred ())
|
|
|
|
|
value = value_from_double (builtin_type_pyfloat, d);
|
|
|
|
|
}
|
|
|
|
|
else if (gdbpy_is_string (obj))
|
|
|
|
|
{
|
|
|
|
|
char *s;
|
|
|
|
|
|
|
|
|
|
s = python_string_to_target_string (obj);
|
|
|
|
|
if (s != NULL)
|
|
|
|
|
{
|
2012-03-30 20:05:55 +00:00
|
|
|
|
struct cleanup *old;
|
|
|
|
|
|
2009-02-04 21:55:40 +00:00
|
|
|
|
old = make_cleanup (xfree, s);
|
2009-06-17 18:47:35 +00:00
|
|
|
|
value = value_cstring (s, strlen (s), builtin_type_pychar);
|
2009-02-04 21:55:40 +00:00
|
|
|
|
do_cleanups (old);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (PyObject_TypeCheck (obj, &value_object_type))
|
2009-03-21 03:13:02 +00:00
|
|
|
|
value = value_copy (((value_object *) obj)->value);
|
2010-01-14 08:03:37 +00:00
|
|
|
|
else if (gdbpy_is_lazy_string (obj))
|
|
|
|
|
{
|
|
|
|
|
PyObject *result;
|
2010-05-17 21:23:25 +00:00
|
|
|
|
|
2011-02-28 19:38:34 +00:00
|
|
|
|
result = PyObject_CallMethodObjArgs (obj, gdbpy_value_cst, NULL);
|
2010-01-14 08:03:37 +00:00
|
|
|
|
value = value_copy (((value_object *) result)->value);
|
|
|
|
|
}
|
2009-02-04 21:55:40 +00:00
|
|
|
|
else
|
2012-12-12 16:47:30 +00:00
|
|
|
|
#ifdef IS_PY3K
|
|
|
|
|
PyErr_Format (PyExc_TypeError,
|
|
|
|
|
_("Could not convert Python object: %S."), obj);
|
|
|
|
|
#else
|
2011-01-06 00:57:05 +00:00
|
|
|
|
PyErr_Format (PyExc_TypeError,
|
|
|
|
|
_("Could not convert Python object: %s."),
|
2009-02-04 21:55:40 +00:00
|
|
|
|
PyString_AsString (PyObject_Str (obj)));
|
2012-12-12 16:47:30 +00:00
|
|
|
|
#endif
|
2009-02-04 21:55:40 +00:00
|
|
|
|
}
|
|
|
|
|
if (except.reason < 0)
|
|
|
|
|
{
|
|
|
|
|
PyErr_Format (except.reason == RETURN_QUIT
|
|
|
|
|
? PyExc_KeyboardInterrupt : PyExc_RuntimeError,
|
|
|
|
|
"%s", except.message);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2008-10-16 14:46:20 +00:00
|
|
|
|
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Returns value object in the ARGth position in GDB's history. */
|
|
|
|
|
PyObject *
|
2009-02-04 21:55:40 +00:00
|
|
|
|
gdbpy_history (PyObject *self, PyObject *args)
|
2008-10-16 14:46:20 +00:00
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
struct value *res_val = NULL; /* Initialize to appease gcc warning. */
|
|
|
|
|
volatile struct gdb_exception except;
|
|
|
|
|
|
|
|
|
|
if (!PyArg_ParseTuple (args, "i", &i))
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
|
|
|
|
{
|
|
|
|
|
res_val = access_value_history (i);
|
|
|
|
|
}
|
|
|
|
|
GDB_PY_HANDLE_EXCEPTION (except);
|
|
|
|
|
|
|
|
|
|
return value_to_value_object (res_val);
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-28 21:16:04 +00:00
|
|
|
|
/* Returns 1 in OBJ is a gdb.Value object, 0 otherwise. */
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
gdbpy_is_value_object (PyObject *obj)
|
|
|
|
|
{
|
|
|
|
|
return PyObject_TypeCheck (obj, &value_object_type);
|
|
|
|
|
}
|
|
|
|
|
|
* python/py-arch.c (gdbpy_initialize_arch): Return 'int'.
Check errors.
* python/py-auto-load.c (gdbpy_initialize_auto_load): Return 'int'.
* python/py-block.c (gdbpy_initialize_blocks): Return 'int'.
Check errors.
* python/py-breakpoint.c (gdbpy_initialize_breakpoints): Return 'int'.
Check errors.
* python/py-cmd.c (gdbpy_initialize_commands): Return 'int'.
Check errors.
* python/py-event.c (gdbpy_initialize_event): Return 'int'.
Check errors.
* python/py-event.h (GDBPY_NEW_EVENT_TYPE): Change generated
init function to return 'int'.
* python/py-evtregistry.c (gdbpy_initialize_eventregistry):
Return 'int'. Check errors.
* python/py-evts.c (gdbpy_initialize_py_events): Return 'int'.
Check errors.
* python/py-finishbreakpoint.c (gdbpy_initialize_finishbreakpoints):
Return 'int'. Check errors.
* python/py-frame.c (gdbpy_initialize_frames): Return 'int'.
Check errors.
* python/py-function.c (gdbpy_initialize_functions): Return 'int'.
Check errors.
* python/py-gdb-readline.c (gdbpy_initialize_gdb_readline):
Check errors.
* python/py-inferior.c (gdbpy_initialize_inferior): Return 'int'.
Check errors.
* python/py-infthread.c (gdbpy_initialize_thread): Return 'int'.
Check errors.
* python/py-lazy-string.c (gdbpy_initialize_lazy_string): Return 'int'.
Check errors.
* python/py-objfile.c (gdbpy_initialize_objfile): Return 'int'.
Check errors.
* python/py-param.c (gdbpy_initialize_parameters): Return 'int'.
Check errors.
* python/py-progspace.c (gdbpy_initialize_pspace): Return 'int'.
Check errors.
* python/py-symbol.c (gdbpy_initialize_symbols): Return 'int'.
Check errors.
* python/py-symtab.c (gdbpy_initialize_symtabs): Return 'int'.
Check errors.
* python/py-type.c (gdbpy_initialize_types): Return 'int'.
Check errors.
* python/py-value.c (gdbpy_initialize_values): Return 'int'.
Check errors.
* python/python-internal.h (gdbpy_initialize_auto_load,
gdbpy_initialize_values, gdbpy_initialize_frames,
gdbpy_initialize_symtabs, gdbpy_initialize_commands,
gdbpy_initialize_symbols, gdbpy_initialize_symtabs,
gdbpy_initialize_blocks, gdbpy_initialize_types,
gdbpy_initialize_functions, gdbpy_initialize_pspace,
gdbpy_initialize_objfile, gdbpy_initialize_breakpoints,
gdbpy_initialize_finishbreakpoints,
gdbpy_initialize_lazy_string, gdbpy_initialize_parameters,
gdbpy_initialize_thread, gdbpy_initialize_inferior,
gdbpy_initialize_eventregistry, gdbpy_initialize_event,
gdbpy_initialize_py_events, gdbpy_initialize_stop_event,
gdbpy_initialize_signal_event,
gdbpy_initialize_breakpoint_event,
gdbpy_initialize_continue_event,
gdbpy_initialize_exited_event, gdbpy_initialize_thread_event,
gdbpy_initialize_new_objfile_event, gdbpy_initialize_arch):
Update. Use CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION.
* python/python.c (gdb_python_initialized): New global.
(gdbpy_initialize_events): Return 'int'. Check errors.
(_initialize_python): Check errors. Set
gdb_python_initialized.
2013-05-20 20:28:52 +00:00
|
|
|
|
int
|
2008-10-16 14:46:20 +00:00
|
|
|
|
gdbpy_initialize_values (void)
|
|
|
|
|
{
|
|
|
|
|
if (PyType_Ready (&value_object_type) < 0)
|
* python/py-arch.c (gdbpy_initialize_arch): Return 'int'.
Check errors.
* python/py-auto-load.c (gdbpy_initialize_auto_load): Return 'int'.
* python/py-block.c (gdbpy_initialize_blocks): Return 'int'.
Check errors.
* python/py-breakpoint.c (gdbpy_initialize_breakpoints): Return 'int'.
Check errors.
* python/py-cmd.c (gdbpy_initialize_commands): Return 'int'.
Check errors.
* python/py-event.c (gdbpy_initialize_event): Return 'int'.
Check errors.
* python/py-event.h (GDBPY_NEW_EVENT_TYPE): Change generated
init function to return 'int'.
* python/py-evtregistry.c (gdbpy_initialize_eventregistry):
Return 'int'. Check errors.
* python/py-evts.c (gdbpy_initialize_py_events): Return 'int'.
Check errors.
* python/py-finishbreakpoint.c (gdbpy_initialize_finishbreakpoints):
Return 'int'. Check errors.
* python/py-frame.c (gdbpy_initialize_frames): Return 'int'.
Check errors.
* python/py-function.c (gdbpy_initialize_functions): Return 'int'.
Check errors.
* python/py-gdb-readline.c (gdbpy_initialize_gdb_readline):
Check errors.
* python/py-inferior.c (gdbpy_initialize_inferior): Return 'int'.
Check errors.
* python/py-infthread.c (gdbpy_initialize_thread): Return 'int'.
Check errors.
* python/py-lazy-string.c (gdbpy_initialize_lazy_string): Return 'int'.
Check errors.
* python/py-objfile.c (gdbpy_initialize_objfile): Return 'int'.
Check errors.
* python/py-param.c (gdbpy_initialize_parameters): Return 'int'.
Check errors.
* python/py-progspace.c (gdbpy_initialize_pspace): Return 'int'.
Check errors.
* python/py-symbol.c (gdbpy_initialize_symbols): Return 'int'.
Check errors.
* python/py-symtab.c (gdbpy_initialize_symtabs): Return 'int'.
Check errors.
* python/py-type.c (gdbpy_initialize_types): Return 'int'.
Check errors.
* python/py-value.c (gdbpy_initialize_values): Return 'int'.
Check errors.
* python/python-internal.h (gdbpy_initialize_auto_load,
gdbpy_initialize_values, gdbpy_initialize_frames,
gdbpy_initialize_symtabs, gdbpy_initialize_commands,
gdbpy_initialize_symbols, gdbpy_initialize_symtabs,
gdbpy_initialize_blocks, gdbpy_initialize_types,
gdbpy_initialize_functions, gdbpy_initialize_pspace,
gdbpy_initialize_objfile, gdbpy_initialize_breakpoints,
gdbpy_initialize_finishbreakpoints,
gdbpy_initialize_lazy_string, gdbpy_initialize_parameters,
gdbpy_initialize_thread, gdbpy_initialize_inferior,
gdbpy_initialize_eventregistry, gdbpy_initialize_event,
gdbpy_initialize_py_events, gdbpy_initialize_stop_event,
gdbpy_initialize_signal_event,
gdbpy_initialize_breakpoint_event,
gdbpy_initialize_continue_event,
gdbpy_initialize_exited_event, gdbpy_initialize_thread_event,
gdbpy_initialize_new_objfile_event, gdbpy_initialize_arch):
Update. Use CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION.
* python/python.c (gdb_python_initialized): New global.
(gdbpy_initialize_events): Return 'int'. Check errors.
(_initialize_python): Check errors. Set
gdb_python_initialized.
2013-05-20 20:28:52 +00:00
|
|
|
|
return -1;
|
2008-10-16 14:46:20 +00:00
|
|
|
|
|
2013-05-20 20:36:19 +00:00
|
|
|
|
return gdb_pymodule_addobject (gdb_module, "Value",
|
|
|
|
|
(PyObject *) &value_object_type);
|
2008-10-16 14:46:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-05-28 00:47:20 +00:00
|
|
|
|
|
|
|
|
|
|
2009-03-26 20:58:11 +00:00
|
|
|
|
static PyGetSetDef value_object_getset[] = {
|
2009-03-29 21:11:11 +00:00
|
|
|
|
{ "address", valpy_get_address, NULL, "The address of the value.",
|
|
|
|
|
NULL },
|
2009-03-26 20:58:11 +00:00
|
|
|
|
{ "is_optimized_out", valpy_get_is_optimized_out, NULL,
|
2011-01-06 00:57:05 +00:00
|
|
|
|
"Boolean telling whether the value is optimized "
|
|
|
|
|
"out (i.e., not available).",
|
2009-03-26 20:58:11 +00:00
|
|
|
|
NULL },
|
2009-05-28 00:47:20 +00:00
|
|
|
|
{ "type", valpy_get_type, NULL, "Type of the value.", NULL },
|
2010-08-30 20:28:31 +00:00
|
|
|
|
{ "dynamic_type", valpy_get_dynamic_type, NULL,
|
|
|
|
|
"Dynamic type of the value.", NULL },
|
2011-10-25 18:34:51 +00:00
|
|
|
|
{ "is_lazy", valpy_get_is_lazy, NULL,
|
|
|
|
|
"Boolean telling whether the value is lazy (not fetched yet\n\
|
|
|
|
|
from the inferior). A lazy value is fetched when needed, or when\n\
|
|
|
|
|
the \"fetch_lazy()\" method is called.", NULL },
|
2009-03-26 20:58:11 +00:00
|
|
|
|
{NULL} /* Sentinel */
|
|
|
|
|
};
|
|
|
|
|
|
* python/python-value.c (value_object_methods)
(value_object_as_number, value_object_as_mapping): Move to bottom
of file.
(valpy_dealloc, valpy_new, valpy_length, valpy_getitem)
(valpy_setitem, valpy_str, valpy_add, valpy_subtract)
(valpy_multiply, valpy_divide, valpy_remainder, valpy_power)
(valpy_negative, valpy_positive, valpy_absolute, valpy_nonzero)
(valpy_richcompare, valpy_dereference): Don't forward-declare.
(valpy_length) [HAVE_LIBPYTHON2_4]: Change return type to `int'.
2008-10-19 20:25:00 +00:00
|
|
|
|
static PyMethodDef value_object_methods[] = {
|
2009-05-28 00:47:20 +00:00
|
|
|
|
{ "cast", valpy_cast, METH_VARARGS, "Cast the value to the supplied type." },
|
2010-08-23 20:29:19 +00:00
|
|
|
|
{ "dynamic_cast", valpy_dynamic_cast, METH_VARARGS,
|
|
|
|
|
"dynamic_cast (gdb.Type) -> gdb.Value\n\
|
|
|
|
|
Cast the value to the supplied type, as if by the C++ dynamic_cast operator."
|
|
|
|
|
},
|
|
|
|
|
{ "reinterpret_cast", valpy_reinterpret_cast, METH_VARARGS,
|
|
|
|
|
"reinterpret_cast (gdb.Type) -> gdb.Value\n\
|
|
|
|
|
Cast the value to the supplied type, as if by the C++\n\
|
|
|
|
|
reinterpret_cast operator."
|
|
|
|
|
},
|
* python/python-value.c (value_object_methods)
(value_object_as_number, value_object_as_mapping): Move to bottom
of file.
(valpy_dealloc, valpy_new, valpy_length, valpy_getitem)
(valpy_setitem, valpy_str, valpy_add, valpy_subtract)
(valpy_multiply, valpy_divide, valpy_remainder, valpy_power)
(valpy_negative, valpy_positive, valpy_absolute, valpy_nonzero)
(valpy_richcompare, valpy_dereference): Don't forward-declare.
(valpy_length) [HAVE_LIBPYTHON2_4]: Change return type to `int'.
2008-10-19 20:25:00 +00:00
|
|
|
|
{ "dereference", valpy_dereference, METH_NOARGS, "Dereferences the value." },
|
2012-03-22 08:10:44 +00:00
|
|
|
|
{ "referenced_value", valpy_referenced_value, METH_NOARGS,
|
|
|
|
|
"Return the value referenced by a TYPE_CODE_REF or TYPE_CODE_PTR value." },
|
2011-01-06 00:57:05 +00:00
|
|
|
|
{ "lazy_string", (PyCFunction) valpy_lazy_string,
|
|
|
|
|
METH_VARARGS | METH_KEYWORDS,
|
2010-01-14 08:03:37 +00:00
|
|
|
|
"lazy_string ([encoding] [, length]) -> lazy_string\n\
|
|
|
|
|
Return a lazy string representation of the value." },
|
2009-03-21 03:13:02 +00:00
|
|
|
|
{ "string", (PyCFunction) valpy_string, METH_VARARGS | METH_KEYWORDS,
|
2009-07-10 10:35:17 +00:00
|
|
|
|
"string ([encoding] [, errors] [, length]) -> string\n\
|
2009-03-21 03:13:02 +00:00
|
|
|
|
Return Unicode string representation of the value." },
|
2013-11-29 20:00:47 +00:00
|
|
|
|
{ "fetch_lazy", valpy_fetch_lazy, METH_NOARGS,
|
2011-10-25 18:34:51 +00:00
|
|
|
|
"Fetches the value from the inferior, if it was lazy." },
|
* python/python-value.c (value_object_methods)
(value_object_as_number, value_object_as_mapping): Move to bottom
of file.
(valpy_dealloc, valpy_new, valpy_length, valpy_getitem)
(valpy_setitem, valpy_str, valpy_add, valpy_subtract)
(valpy_multiply, valpy_divide, valpy_remainder, valpy_power)
(valpy_negative, valpy_positive, valpy_absolute, valpy_nonzero)
(valpy_richcompare, valpy_dereference): Don't forward-declare.
(valpy_length) [HAVE_LIBPYTHON2_4]: Change return type to `int'.
2008-10-19 20:25:00 +00:00
|
|
|
|
{NULL} /* Sentinel */
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static PyNumberMethods value_object_as_number = {
|
|
|
|
|
valpy_add,
|
|
|
|
|
valpy_subtract,
|
|
|
|
|
valpy_multiply,
|
2012-12-12 16:47:30 +00:00
|
|
|
|
#ifndef IS_PY3K
|
* python/python-value.c (value_object_methods)
(value_object_as_number, value_object_as_mapping): Move to bottom
of file.
(valpy_dealloc, valpy_new, valpy_length, valpy_getitem)
(valpy_setitem, valpy_str, valpy_add, valpy_subtract)
(valpy_multiply, valpy_divide, valpy_remainder, valpy_power)
(valpy_negative, valpy_positive, valpy_absolute, valpy_nonzero)
(valpy_richcompare, valpy_dereference): Don't forward-declare.
(valpy_length) [HAVE_LIBPYTHON2_4]: Change return type to `int'.
2008-10-19 20:25:00 +00:00
|
|
|
|
valpy_divide,
|
2012-12-12 16:47:30 +00:00
|
|
|
|
#endif
|
* python/python-value.c (value_object_methods)
(value_object_as_number, value_object_as_mapping): Move to bottom
of file.
(valpy_dealloc, valpy_new, valpy_length, valpy_getitem)
(valpy_setitem, valpy_str, valpy_add, valpy_subtract)
(valpy_multiply, valpy_divide, valpy_remainder, valpy_power)
(valpy_negative, valpy_positive, valpy_absolute, valpy_nonzero)
(valpy_richcompare, valpy_dereference): Don't forward-declare.
(valpy_length) [HAVE_LIBPYTHON2_4]: Change return type to `int'.
2008-10-19 20:25:00 +00:00
|
|
|
|
valpy_remainder,
|
|
|
|
|
NULL, /* nb_divmod */
|
|
|
|
|
valpy_power, /* nb_power */
|
|
|
|
|
valpy_negative, /* nb_negative */
|
|
|
|
|
valpy_positive, /* nb_positive */
|
|
|
|
|
valpy_absolute, /* nb_absolute */
|
2009-02-04 21:55:40 +00:00
|
|
|
|
valpy_nonzero, /* nb_nonzero */
|
|
|
|
|
valpy_invert, /* nb_invert */
|
|
|
|
|
valpy_lsh, /* nb_lshift */
|
|
|
|
|
valpy_rsh, /* nb_rshift */
|
|
|
|
|
valpy_and, /* nb_and */
|
|
|
|
|
valpy_xor, /* nb_xor */
|
|
|
|
|
valpy_or, /* nb_or */
|
2012-12-12 16:47:30 +00:00
|
|
|
|
#ifdef IS_PY3K
|
|
|
|
|
valpy_long, /* nb_int */
|
|
|
|
|
NULL, /* reserved */
|
|
|
|
|
#else
|
2009-02-04 21:55:40 +00:00
|
|
|
|
NULL, /* nb_coerce */
|
|
|
|
|
valpy_int, /* nb_int */
|
|
|
|
|
valpy_long, /* nb_long */
|
2012-12-12 16:47:30 +00:00
|
|
|
|
#endif
|
2009-02-04 21:55:40 +00:00
|
|
|
|
valpy_float, /* nb_float */
|
2012-12-12 16:47:30 +00:00
|
|
|
|
#ifndef IS_PY3K
|
2009-02-04 21:55:40 +00:00
|
|
|
|
NULL, /* nb_oct */
|
2012-12-12 16:47:30 +00:00
|
|
|
|
NULL, /* nb_hex */
|
|
|
|
|
#endif
|
|
|
|
|
NULL, /* nb_inplace_add */
|
|
|
|
|
NULL, /* nb_inplace_subtract */
|
|
|
|
|
NULL, /* nb_inplace_multiply */
|
|
|
|
|
NULL, /* nb_inplace_remainder */
|
|
|
|
|
NULL, /* nb_inplace_power */
|
|
|
|
|
NULL, /* nb_inplace_lshift */
|
|
|
|
|
NULL, /* nb_inplace_rshift */
|
|
|
|
|
NULL, /* nb_inplace_and */
|
|
|
|
|
NULL, /* nb_inplace_xor */
|
|
|
|
|
NULL, /* nb_inplace_or */
|
|
|
|
|
NULL, /* nb_floor_divide */
|
|
|
|
|
valpy_divide /* nb_true_divide */
|
* python/python-value.c (value_object_methods)
(value_object_as_number, value_object_as_mapping): Move to bottom
of file.
(valpy_dealloc, valpy_new, valpy_length, valpy_getitem)
(valpy_setitem, valpy_str, valpy_add, valpy_subtract)
(valpy_multiply, valpy_divide, valpy_remainder, valpy_power)
(valpy_negative, valpy_positive, valpy_absolute, valpy_nonzero)
(valpy_richcompare, valpy_dereference): Don't forward-declare.
(valpy_length) [HAVE_LIBPYTHON2_4]: Change return type to `int'.
2008-10-19 20:25:00 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static PyMappingMethods value_object_as_mapping = {
|
|
|
|
|
valpy_length,
|
|
|
|
|
valpy_getitem,
|
|
|
|
|
valpy_setitem
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
PyTypeObject value_object_type = {
|
2012-12-12 16:47:30 +00:00
|
|
|
|
PyVarObject_HEAD_INIT (NULL, 0)
|
* python/python-value.c (value_object_methods)
(value_object_as_number, value_object_as_mapping): Move to bottom
of file.
(valpy_dealloc, valpy_new, valpy_length, valpy_getitem)
(valpy_setitem, valpy_str, valpy_add, valpy_subtract)
(valpy_multiply, valpy_divide, valpy_remainder, valpy_power)
(valpy_negative, valpy_positive, valpy_absolute, valpy_nonzero)
(valpy_richcompare, valpy_dereference): Don't forward-declare.
(valpy_length) [HAVE_LIBPYTHON2_4]: Change return type to `int'.
2008-10-19 20:25:00 +00:00
|
|
|
|
"gdb.Value", /*tp_name*/
|
|
|
|
|
sizeof (value_object), /*tp_basicsize*/
|
|
|
|
|
0, /*tp_itemsize*/
|
|
|
|
|
valpy_dealloc, /*tp_dealloc*/
|
|
|
|
|
0, /*tp_print*/
|
|
|
|
|
0, /*tp_getattr*/
|
|
|
|
|
0, /*tp_setattr*/
|
|
|
|
|
0, /*tp_compare*/
|
|
|
|
|
0, /*tp_repr*/
|
|
|
|
|
&value_object_as_number, /*tp_as_number*/
|
|
|
|
|
0, /*tp_as_sequence*/
|
|
|
|
|
&value_object_as_mapping, /*tp_as_mapping*/
|
2010-05-14 11:11:28 +00:00
|
|
|
|
valpy_hash, /*tp_hash*/
|
2010-07-27 12:40:42 +00:00
|
|
|
|
valpy_call, /*tp_call*/
|
* python/python-value.c (value_object_methods)
(value_object_as_number, value_object_as_mapping): Move to bottom
of file.
(valpy_dealloc, valpy_new, valpy_length, valpy_getitem)
(valpy_setitem, valpy_str, valpy_add, valpy_subtract)
(valpy_multiply, valpy_divide, valpy_remainder, valpy_power)
(valpy_negative, valpy_positive, valpy_absolute, valpy_nonzero)
(valpy_richcompare, valpy_dereference): Don't forward-declare.
(valpy_length) [HAVE_LIBPYTHON2_4]: Change return type to `int'.
2008-10-19 20:25:00 +00:00
|
|
|
|
valpy_str, /*tp_str*/
|
|
|
|
|
0, /*tp_getattro*/
|
|
|
|
|
0, /*tp_setattro*/
|
|
|
|
|
0, /*tp_as_buffer*/
|
2011-01-06 00:57:05 +00:00
|
|
|
|
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_CHECKTYPES
|
|
|
|
|
| Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
* python/python-value.c (value_object_methods)
(value_object_as_number, value_object_as_mapping): Move to bottom
of file.
(valpy_dealloc, valpy_new, valpy_length, valpy_getitem)
(valpy_setitem, valpy_str, valpy_add, valpy_subtract)
(valpy_multiply, valpy_divide, valpy_remainder, valpy_power)
(valpy_negative, valpy_positive, valpy_absolute, valpy_nonzero)
(valpy_richcompare, valpy_dereference): Don't forward-declare.
(valpy_length) [HAVE_LIBPYTHON2_4]: Change return type to `int'.
2008-10-19 20:25:00 +00:00
|
|
|
|
"GDB value object", /* tp_doc */
|
|
|
|
|
0, /* tp_traverse */
|
|
|
|
|
0, /* tp_clear */
|
|
|
|
|
valpy_richcompare, /* tp_richcompare */
|
|
|
|
|
0, /* tp_weaklistoffset */
|
|
|
|
|
0, /* tp_iter */
|
|
|
|
|
0, /* tp_iternext */
|
2009-02-04 21:55:40 +00:00
|
|
|
|
value_object_methods, /* tp_methods */
|
|
|
|
|
0, /* tp_members */
|
2009-03-26 20:58:11 +00:00
|
|
|
|
value_object_getset, /* tp_getset */
|
2009-02-04 21:55:40 +00:00
|
|
|
|
0, /* tp_base */
|
|
|
|
|
0, /* tp_dict */
|
|
|
|
|
0, /* tp_descr_get */
|
|
|
|
|
0, /* tp_descr_set */
|
|
|
|
|
0, /* tp_dictoffset */
|
|
|
|
|
0, /* tp_init */
|
|
|
|
|
0, /* tp_alloc */
|
|
|
|
|
valpy_new /* tp_new */
|
* python/python-value.c (value_object_methods)
(value_object_as_number, value_object_as_mapping): Move to bottom
of file.
(valpy_dealloc, valpy_new, valpy_length, valpy_getitem)
(valpy_setitem, valpy_str, valpy_add, valpy_subtract)
(valpy_multiply, valpy_divide, valpy_remainder, valpy_power)
(valpy_negative, valpy_positive, valpy_absolute, valpy_nonzero)
(valpy_richcompare, valpy_dereference): Don't forward-declare.
(valpy_length) [HAVE_LIBPYTHON2_4]: Change return type to `int'.
2008-10-19 20:25:00 +00:00
|
|
|
|
};
|