2008-10-16 16:46:20 +02:00
|
|
|
|
/* Python interface to values.
|
|
|
|
|
|
2013-01-01 07:33:28 +01:00
|
|
|
|
Copyright (C) 2008-2013 Free Software Foundation, Inc.
|
2008-10-16 16:46:20 +02:00
|
|
|
|
|
|
|
|
|
This file is part of GDB.
|
|
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
|
|
|
|
|
|
|
|
#include "defs.h"
|
2009-02-04 22:55:40 +01:00
|
|
|
|
#include "gdb_assert.h"
|
2008-10-16 16:46:20 +02:00
|
|
|
|
#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 18:19:58 +01:00
|
|
|
|
#include "valprint.h"
|
2010-07-27 14:40:42 +02:00
|
|
|
|
#include "infcall.h"
|
2010-08-23 22:29:19 +02:00
|
|
|
|
#include "expression.h"
|
2010-08-30 22:28:31 +02:00
|
|
|
|
#include "cp-abi.h"
|
2012-03-01 22:06:54 +01:00
|
|
|
|
#include "python.h"
|
2008-10-16 16:46:20 +02:00
|
|
|
|
|
|
|
|
|
#ifdef HAVE_PYTHON
|
|
|
|
|
|
|
|
|
|
#include "python-internal.h"
|
|
|
|
|
|
|
|
|
|
/* Even though Python scalar types directly map to host types, we use
|
2011-02-26 03:07:10 +01:00
|
|
|
|
target types here to remain consistent with the values system in
|
2008-10-16 16:46:20 +02: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 19:04:23 +02:00
|
|
|
|
#define builtin_type_pyint builtin_type (python_gdbarch)->builtin_long
|
2008-10-16 16:46:20 +02: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 19:04:23 +02:00
|
|
|
|
#define builtin_type_pyfloat builtin_type (python_gdbarch)->builtin_double
|
2008-10-16 16:46:20 +02: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 19:04:23 +02:00
|
|
|
|
#define builtin_type_pylong builtin_type (python_gdbarch)->builtin_long_long
|
2008-10-16 16:46:20 +02:00
|
|
|
|
|
2010-06-28 23:16:04 +02: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 16:46:20 +02: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 19:04:23 +02:00
|
|
|
|
language_bool_type (python_language, python_gdbarch)
|
2008-10-16 16:46:20 +02:00
|
|
|
|
|
2009-06-17 20:47:35 +02: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 19:04:23 +02:00
|
|
|
|
language_string_char_type (python_language, python_gdbarch)
|
2009-06-17 20:47:35 +02:00
|
|
|
|
|
2009-08-13 20:39:20 +02:00
|
|
|
|
typedef struct value_object {
|
2008-10-16 16:46:20 +02:00
|
|
|
|
PyObject_HEAD
|
2009-08-13 20:39:20 +02:00
|
|
|
|
struct value_object *next;
|
|
|
|
|
struct value_object *prev;
|
2008-10-16 16:46:20 +02:00
|
|
|
|
struct value *value;
|
2009-03-29 23:11:11 +02:00
|
|
|
|
PyObject *address;
|
2009-05-28 02:47:20 +02:00
|
|
|
|
PyObject *type;
|
2010-08-30 22:28:31 +02:00
|
|
|
|
PyObject *dynamic_type;
|
2008-10-16 16:46:20 +02:00
|
|
|
|
} value_object;
|
|
|
|
|
|
2009-08-13 20:39:20 +02: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 16:46:20 +02: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 20:39:20 +02: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 16:46:20 +02:00
|
|
|
|
|
2009-03-29 23:19:40 +02:00
|
|
|
|
value_free (self->value);
|
2009-03-29 23:11:11 +02:00
|
|
|
|
|
|
|
|
|
if (self->address)
|
|
|
|
|
/* Use braces to appease gcc warning. *sigh* */
|
|
|
|
|
{
|
|
|
|
|
Py_DECREF (self->address);
|
|
|
|
|
}
|
|
|
|
|
|
2009-05-28 02:47:20 +02:00
|
|
|
|
if (self->type)
|
|
|
|
|
{
|
|
|
|
|
Py_DECREF (self->type);
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-30 22:28:31 +02:00
|
|
|
|
Py_XDECREF (self->dynamic_type);
|
|
|
|
|
|
2012-12-12 17:47:30 +01:00
|
|
|
|
Py_TYPE (self)->tp_free (self);
|
2008-10-16 16:46:20 +02:00
|
|
|
|
}
|
|
|
|
|
|
2009-08-13 20:39:20 +02: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 15:24:40 +02:00
|
|
|
|
/* Called when a new gdb.Value object needs to be allocated. Returns NULL on
|
|
|
|
|
error, with a python exception set. */
|
2008-10-16 16:46:20 +02: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 22:55:40 +01:00
|
|
|
|
value = convert_value_from_python (PyTuple_GetItem (args, 0));
|
|
|
|
|
if (value == NULL)
|
2008-10-16 16:46:20 +02:00
|
|
|
|
{
|
|
|
|
|
subtype->tp_free (value_obj);
|
2009-02-04 22:55:40 +01:00
|
|
|
|
return NULL;
|
2008-10-16 16:46:20 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
value_obj->value = value;
|
2011-12-22 20:51:10 +01:00
|
|
|
|
release_value_or_incref (value);
|
2009-03-29 23:11:11 +02:00
|
|
|
|
value_obj->address = NULL;
|
2009-05-28 02:47:20 +02:00
|
|
|
|
value_obj->type = NULL;
|
2010-08-30 22:28:31 +02:00
|
|
|
|
value_obj->dynamic_type = NULL;
|
2009-08-13 20:39:20 +02:00
|
|
|
|
note_value (value_obj);
|
2008-10-16 16:46:20 +02:00
|
|
|
|
|
|
|
|
|
return (PyObject *) value_obj;
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-13 20:39:20 +02:00
|
|
|
|
/* Iterate over all the Value objects, calling preserve_one_value on
|
|
|
|
|
each. */
|
|
|
|
|
void
|
|
|
|
|
preserve_python_values (struct objfile *objfile, htab_t copied_types)
|
|
|
|
|
{
|
|
|
|
|
value_object *iter;
|
|
|
|
|
|
|
|
|
|
for (iter = values_in_python; iter; iter = iter->next)
|
|
|
|
|
preserve_one_value (iter->value, objfile, copied_types);
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-16 16:46:20 +02: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 20:27:52 +01:00
|
|
|
|
PyObject *result = NULL;
|
2008-10-16 16:46:20 +02:00
|
|
|
|
|
|
|
|
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
|
|
|
|
{
|
2012-01-03 20:27:52 +01:00
|
|
|
|
struct value *res_val;
|
|
|
|
|
struct cleanup *cleanup = make_cleanup_value_free_to_mark (value_mark ());
|
|
|
|
|
|
2008-10-16 16:46:20 +02:00
|
|
|
|
res_val = value_ind (((value_object *) self)->value);
|
2012-01-03 20:27:52 +01:00
|
|
|
|
result = value_to_value_object (res_val);
|
|
|
|
|
do_cleanups (cleanup);
|
2008-10-16 16:46:20 +02:00
|
|
|
|
}
|
|
|
|
|
GDB_PY_HANDLE_EXCEPTION (except);
|
|
|
|
|
|
2012-01-03 20:27:52 +01:00
|
|
|
|
return result;
|
2008-10-16 16:46:20 +02:00
|
|
|
|
}
|
|
|
|
|
|
2012-03-22 09:10:44 +01: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 22:55:40 +01:00
|
|
|
|
/* Return "&value". */
|
|
|
|
|
static PyObject *
|
2009-03-29 23:11:11 +02:00
|
|
|
|
valpy_get_address (PyObject *self, void *closure)
|
2009-02-04 22:55:40 +01:00
|
|
|
|
{
|
2009-03-29 23:11:11 +02:00
|
|
|
|
value_object *val_obj = (value_object *) self;
|
2009-02-04 22:55:40 +01:00
|
|
|
|
volatile struct gdb_exception except;
|
|
|
|
|
|
2009-03-29 23:11:11 +02:00
|
|
|
|
if (!val_obj->address)
|
2009-02-04 22:55:40 +01:00
|
|
|
|
{
|
2009-03-29 23:11:11 +02:00
|
|
|
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
|
|
|
|
{
|
2012-01-03 20:27:52 +01:00
|
|
|
|
struct value *res_val;
|
|
|
|
|
struct cleanup *cleanup
|
|
|
|
|
= make_cleanup_value_free_to_mark (value_mark ());
|
|
|
|
|
|
2009-03-29 23:11:11 +02:00
|
|
|
|
res_val = value_addr (val_obj->value);
|
2012-01-03 20:27:52 +01:00
|
|
|
|
val_obj->address = value_to_value_object (res_val);
|
|
|
|
|
do_cleanups (cleanup);
|
2009-03-29 23:11:11 +02:00
|
|
|
|
}
|
|
|
|
|
if (except.reason < 0)
|
|
|
|
|
{
|
|
|
|
|
val_obj->address = Py_None;
|
|
|
|
|
Py_INCREF (Py_None);
|
|
|
|
|
}
|
2009-02-04 22:55:40 +01:00
|
|
|
|
}
|
|
|
|
|
|
2011-10-03 18:14:39 +02:00
|
|
|
|
Py_XINCREF (val_obj->address);
|
2009-03-29 23:11:11 +02:00
|
|
|
|
|
|
|
|
|
return val_obj->address;
|
2009-02-04 22:55:40 +01:00
|
|
|
|
}
|
|
|
|
|
|
2009-05-28 02:47:20 +02:00
|
|
|
|
/* Return type of the value. */
|
|
|
|
|
static PyObject *
|
|
|
|
|
valpy_get_type (PyObject *self, void *closure)
|
|
|
|
|
{
|
|
|
|
|
value_object *obj = (value_object *) self;
|
2010-05-17 23:23:25 +02:00
|
|
|
|
|
2009-05-28 02:47:20 +02:00
|
|
|
|
if (!obj->type)
|
|
|
|
|
{
|
|
|
|
|
obj->type = type_to_type_object (value_type (obj->value));
|
|
|
|
|
if (!obj->type)
|
2010-08-30 22:28:31 +02:00
|
|
|
|
return NULL;
|
2009-05-28 02:47:20 +02:00
|
|
|
|
}
|
|
|
|
|
Py_INCREF (obj->type);
|
|
|
|
|
return obj->type;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-30 22:28:31 +02: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 20:27:52 +01:00
|
|
|
|
struct cleanup *cleanup = make_cleanup_value_free_to_mark (value_mark ());
|
2010-08-30 22:28:31 +02: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;
|
|
|
|
|
|
|
|
|
|
target = value_ind (val);
|
|
|
|
|
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 20:27:52 +01:00
|
|
|
|
|
|
|
|
|
do_cleanups (cleanup);
|
2010-08-30 22:28:31 +02:00
|
|
|
|
}
|
|
|
|
|
GDB_PY_HANDLE_EXCEPTION (except);
|
|
|
|
|
|
|
|
|
|
if (type == NULL)
|
2013-05-20 22:38:47 +02:00
|
|
|
|
obj->dynamic_type = valpy_get_type (self, NULL);
|
2010-08-30 22:28:31 +02:00
|
|
|
|
else
|
|
|
|
|
obj->dynamic_type = type_to_type_object (type);
|
|
|
|
|
|
2013-05-20 22:38:47 +02:00
|
|
|
|
Py_XINCREF (obj->dynamic_type);
|
2010-08-30 22:28:31 +02:00
|
|
|
|
return obj->dynamic_type;
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-14 09:03:37 +01: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 21:53:45 +01:00
|
|
|
|
gdb_py_longest length = -1;
|
2010-01-14 09:03:37 +01:00
|
|
|
|
struct value *value = ((value_object *) self)->value;
|
|
|
|
|
const char *user_encoding = NULL;
|
|
|
|
|
static char *keywords[] = { "encoding", "length", NULL };
|
2012-01-03 20:27:52 +01:00
|
|
|
|
PyObject *str_obj = NULL;
|
2011-10-07 15:46:11 +02:00
|
|
|
|
volatile struct gdb_exception except;
|
2010-01-14 09:03:37 +01:00
|
|
|
|
|
2011-01-26 21:53:45 +01:00
|
|
|
|
if (!PyArg_ParseTupleAndKeywords (args, kw, "|s" GDB_PY_LL_ARG, keywords,
|
2010-01-14 09:03:37 +01:00
|
|
|
|
&user_encoding, &length))
|
|
|
|
|
return NULL;
|
|
|
|
|
|
2011-10-07 15:46:11 +02:00
|
|
|
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
|
|
|
|
{
|
2012-01-03 20:27:52 +01:00
|
|
|
|
struct cleanup *cleanup = make_cleanup_value_free_to_mark (value_mark ());
|
|
|
|
|
|
2011-10-07 15:46:11 +02:00
|
|
|
|
if (TYPE_CODE (value_type (value)) == TYPE_CODE_PTR)
|
|
|
|
|
value = value_ind (value);
|
2012-01-03 20:27:52 +01:00
|
|
|
|
|
|
|
|
|
str_obj = gdbpy_create_lazy_string_object (value_address (value), length,
|
|
|
|
|
user_encoding,
|
|
|
|
|
value_type (value));
|
|
|
|
|
|
|
|
|
|
do_cleanups (cleanup);
|
2011-10-07 15:46:11 +02:00
|
|
|
|
}
|
|
|
|
|
GDB_PY_HANDLE_EXCEPTION (except);
|
2010-01-14 09:03:37 +01:00
|
|
|
|
|
2012-01-03 20:27:52 +01:00
|
|
|
|
return str_obj;
|
2010-01-14 09:03:37 +01:00
|
|
|
|
}
|
|
|
|
|
|
2009-07-10 12:35:17 +02: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 22:16:09 +01:00
|
|
|
|
static PyObject *
|
2009-03-21 04:13:02 +01:00
|
|
|
|
valpy_string (PyObject *self, PyObject *args, PyObject *kw)
|
2009-02-05 22:16:09 +01:00
|
|
|
|
{
|
2010-05-07 21:26:30 +02:00
|
|
|
|
int length = -1;
|
2009-02-05 22:16:09 +01: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 23:39:53 +02:00
|
|
|
|
struct type *char_type;
|
2009-09-29 17:13:45 +02:00
|
|
|
|
static char *keywords[] = { "encoding", "errors", "length", NULL };
|
2009-02-05 22:16:09 +01:00
|
|
|
|
|
2009-07-10 12:35:17 +02:00
|
|
|
|
if (!PyArg_ParseTupleAndKeywords (args, kw, "|ssi", keywords,
|
|
|
|
|
&user_encoding, &errors, &length))
|
2009-02-05 22:16:09 +01:00
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
|
|
|
|
{
|
2009-09-25 23:39:53 +02:00
|
|
|
|
LA_GET_STRING (value, &buffer, &length, &char_type, &la_encoding);
|
2009-02-05 22:16:09 +01:00
|
|
|
|
}
|
|
|
|
|
GDB_PY_HANDLE_EXCEPTION (except);
|
|
|
|
|
|
|
|
|
|
encoding = (user_encoding && *user_encoding) ? user_encoding : la_encoding;
|
2013-04-19 17:29:09 +02:00
|
|
|
|
unicode = PyUnicode_Decode ((const char *) buffer,
|
|
|
|
|
length * TYPE_LENGTH (char_type),
|
2009-09-25 23:39:53 +02:00
|
|
|
|
encoding, errors);
|
2009-02-05 22:16:09 +01:00
|
|
|
|
xfree (buffer);
|
|
|
|
|
|
|
|
|
|
return unicode;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-23 22:29:19 +02:00
|
|
|
|
/* A helper function that implements the various cast operators. */
|
|
|
|
|
|
2009-05-28 02:47:20 +02:00
|
|
|
|
static PyObject *
|
2010-08-23 22:29:19 +02:00
|
|
|
|
valpy_do_cast (PyObject *self, PyObject *args, enum exp_opcode op)
|
2009-05-28 02:47:20 +02:00
|
|
|
|
{
|
2012-01-03 20:27:52 +01:00
|
|
|
|
PyObject *type_obj, *result = NULL;
|
2009-05-28 02:47:20 +02: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)
|
|
|
|
|
{
|
2010-04-14 15:18:55 +02:00
|
|
|
|
PyErr_SetString (PyExc_RuntimeError,
|
|
|
|
|
_("Argument must be a type."));
|
2009-05-28 02:47:20 +02:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
|
|
|
|
{
|
2010-08-23 22:29:19 +02:00
|
|
|
|
struct value *val = ((value_object *) self)->value;
|
2012-01-03 20:27:52 +01:00
|
|
|
|
struct value *res_val;
|
|
|
|
|
struct cleanup *cleanup = make_cleanup_value_free_to_mark (value_mark ());
|
2010-08-23 22:29:19 +02: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 20:27:52 +01:00
|
|
|
|
|
|
|
|
|
result = value_to_value_object (res_val);
|
|
|
|
|
do_cleanups (cleanup);
|
2009-05-28 02:47:20 +02:00
|
|
|
|
}
|
|
|
|
|
GDB_PY_HANDLE_EXCEPTION (except);
|
|
|
|
|
|
2012-01-03 20:27:52 +01:00
|
|
|
|
return result;
|
2009-05-28 02:47:20 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-08-23 22:29:19 +02: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 16:46:20 +02: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 15:18:55 +02:00
|
|
|
|
_("Invalid operation on gdb.Value."));
|
2008-10-16 16:46:20 +02:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Given string name of an element inside structure, return its value
|
2010-10-13 15:24:40 +02:00
|
|
|
|
object. Returns NULL on error, with a python exception set. */
|
2008-10-16 16:46:20 +02:00
|
|
|
|
static PyObject *
|
|
|
|
|
valpy_getitem (PyObject *self, PyObject *key)
|
|
|
|
|
{
|
|
|
|
|
value_object *self_value = (value_object *) self;
|
2009-02-04 22:55:40 +01:00
|
|
|
|
char *field = NULL;
|
2008-10-16 16:46:20 +02:00
|
|
|
|
volatile struct gdb_exception except;
|
2012-01-03 20:27:52 +01:00
|
|
|
|
PyObject *result = NULL;
|
2008-10-16 16:46:20 +02:00
|
|
|
|
|
2009-02-04 22:55:40 +01:00
|
|
|
|
if (gdbpy_is_string (key))
|
|
|
|
|
{
|
|
|
|
|
field = python_string_to_host_string (key);
|
|
|
|
|
if (field == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2008-10-16 16:46:20 +02:00
|
|
|
|
|
|
|
|
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
|
|
|
|
{
|
2008-10-24 00:48:40 +02:00
|
|
|
|
struct value *tmp = self_value->value;
|
2012-01-03 20:27:52 +01:00
|
|
|
|
struct cleanup *cleanup = make_cleanup_value_free_to_mark (value_mark ());
|
|
|
|
|
struct value *res_val = NULL;
|
2009-02-04 22:55:40 +01:00
|
|
|
|
|
|
|
|
|
if (field)
|
|
|
|
|
res_val = value_struct_elt (&tmp, NULL, field, 0, NULL);
|
|
|
|
|
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 23:23:25 +02:00
|
|
|
|
|
2009-07-07 21:36:09 +02:00
|
|
|
|
if (idx != NULL)
|
2009-09-21 11:32:28 +02:00
|
|
|
|
{
|
|
|
|
|
/* Check the value's type is something that can be accessed via
|
|
|
|
|
a subscript. */
|
|
|
|
|
struct type *type;
|
2010-05-17 23:23:25 +02:00
|
|
|
|
|
2009-09-21 11:32:28 +02: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 17:09:57 +01:00
|
|
|
|
error (_("Cannot subscript requested type."));
|
2009-09-21 11:32:28 +02:00
|
|
|
|
else
|
|
|
|
|
res_val = value_subscript (tmp, value_as_long (idx));
|
|
|
|
|
}
|
2009-02-04 22:55:40 +01:00
|
|
|
|
}
|
2012-01-03 20:27:52 +01:00
|
|
|
|
|
|
|
|
|
if (res_val)
|
|
|
|
|
result = value_to_value_object (res_val);
|
|
|
|
|
do_cleanups (cleanup);
|
2008-10-16 16:46:20 +02:00
|
|
|
|
}
|
2009-07-07 21:36:09 +02:00
|
|
|
|
|
2009-07-07 23:03:00 +02:00
|
|
|
|
xfree (field);
|
2008-10-16 16:46:20 +02:00
|
|
|
|
GDB_PY_HANDLE_EXCEPTION (except);
|
|
|
|
|
|
2012-01-03 20:27:52 +01:00
|
|
|
|
return result;
|
2008-10-16 16:46:20 +02: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 14:40:42 +02:00
|
|
|
|
/* Called by the Python interpreter to perform an inferior function
|
2010-10-13 15:24:40 +02:00
|
|
|
|
call on the value. Returns NULL on error, with a python exception set. */
|
2010-07-27 14:40:42 +02: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-08 00:02:42 +02:00
|
|
|
|
struct type *ftype = NULL;
|
2012-01-03 20:27:52 +01:00
|
|
|
|
struct value *mark = value_mark ();
|
|
|
|
|
PyObject *result = NULL;
|
2011-10-07 15:46:11 +02:00
|
|
|
|
|
|
|
|
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
|
|
|
|
{
|
|
|
|
|
ftype = check_typedef (value_type (function));
|
|
|
|
|
}
|
|
|
|
|
GDB_PY_HANDLE_EXCEPTION (except);
|
2010-07-27 14:40:42 +02: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 15:46:11 +02:00
|
|
|
|
if (! PyTuple_Check (args))
|
|
|
|
|
{
|
|
|
|
|
PyErr_SetString (PyExc_TypeError,
|
|
|
|
|
_("Inferior arguments must be provided in a tuple."));
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-27 14:40:42 +02: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 20:27:52 +01:00
|
|
|
|
struct cleanup *cleanup = make_cleanup_value_free_to_mark (mark);
|
|
|
|
|
struct value *return_value;
|
|
|
|
|
|
2010-07-27 14:40:42 +02:00
|
|
|
|
return_value = call_function_by_hand (function, args_count, vargs);
|
2012-01-03 20:27:52 +01:00
|
|
|
|
result = value_to_value_object (return_value);
|
|
|
|
|
do_cleanups (cleanup);
|
2010-07-27 14:40:42 +02:00
|
|
|
|
}
|
|
|
|
|
GDB_PY_HANDLE_EXCEPTION (except);
|
|
|
|
|
|
2012-01-03 20:27:52 +01:00
|
|
|
|
return result;
|
2010-07-27 14:40:42 +02:00
|
|
|
|
}
|
|
|
|
|
|
2008-10-16 16:46:20 +02: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 18:19:58 +01:00
|
|
|
|
struct value_print_options opts;
|
2008-10-16 16:46:20 +02: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 18:19:58 +01:00
|
|
|
|
get_user_print_options (&opts);
|
|
|
|
|
opts.deref_ref = 0;
|
|
|
|
|
|
2008-10-16 16:46:20 +02:00
|
|
|
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
|
|
|
|
{
|
2011-06-27 21:21:51 +02: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 18:19:58 +01: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 19:04:23 +02:00
|
|
|
|
&opts, python_language);
|
2009-08-14 02:32:33 +02:00
|
|
|
|
s = ui_file_xstrdup (stb, NULL);
|
2011-06-27 21:21:51 +02:00
|
|
|
|
|
|
|
|
|
do_cleanups (old_chain);
|
2008-10-16 16:46:20 +02:00
|
|
|
|
}
|
|
|
|
|
GDB_PY_HANDLE_EXCEPTION (except);
|
|
|
|
|
|
|
|
|
|
result = PyUnicode_Decode (s, strlen (s), host_charset (), NULL);
|
|
|
|
|
xfree (s);
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-26 21:58:11 +01: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 15:46:11 +02:00
|
|
|
|
int opt = 0;
|
|
|
|
|
volatile struct gdb_exception except;
|
2009-03-26 21:58:11 +01:00
|
|
|
|
|
2011-10-07 15:46:11 +02:00
|
|
|
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
|
|
|
|
{
|
|
|
|
|
opt = value_optimized_out (value);
|
|
|
|
|
}
|
|
|
|
|
GDB_PY_HANDLE_EXCEPTION (except);
|
|
|
|
|
|
|
|
|
|
if (opt)
|
2009-03-26 21:58:11 +01:00
|
|
|
|
Py_RETURN_TRUE;
|
|
|
|
|
|
|
|
|
|
Py_RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-25 20:34:51 +02: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 13:11:28 +02:00
|
|
|
|
/* Calculate and return the address of the PyObject as the value of
|
|
|
|
|
the builtin __hash__ call. */
|
|
|
|
|
static long
|
|
|
|
|
valpy_hash (PyObject *self)
|
|
|
|
|
{
|
|
|
|
|
return (long) (intptr_t) self;
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-16 16:46:20 +02:00
|
|
|
|
enum valpy_opcode
|
|
|
|
|
{
|
|
|
|
|
VALPY_ADD,
|
|
|
|
|
VALPY_SUB,
|
|
|
|
|
VALPY_MUL,
|
|
|
|
|
VALPY_DIV,
|
|
|
|
|
VALPY_REM,
|
2009-02-04 22:55:40 +01:00
|
|
|
|
VALPY_POW,
|
|
|
|
|
VALPY_LSH,
|
|
|
|
|
VALPY_RSH,
|
|
|
|
|
VALPY_BITAND,
|
|
|
|
|
VALPY_BITOR,
|
|
|
|
|
VALPY_BITXOR
|
2008-10-16 16:46:20 +02: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 15:24:40 +02:00
|
|
|
|
specified by OPCODE to the given arguments. Returns NULL on error, with
|
|
|
|
|
a python exception set. */
|
2008-10-16 16:46:20 +02:00
|
|
|
|
static PyObject *
|
|
|
|
|
valpy_binop (enum valpy_opcode opcode, PyObject *self, PyObject *other)
|
|
|
|
|
{
|
|
|
|
|
volatile struct gdb_exception except;
|
2012-01-03 20:27:52 +01:00
|
|
|
|
PyObject *result = NULL;
|
2008-10-16 16:46:20 +02:00
|
|
|
|
|
|
|
|
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
|
|
|
|
{
|
|
|
|
|
struct value *arg1, *arg2;
|
2012-01-03 20:27:52 +01:00
|
|
|
|
struct cleanup *cleanup = make_cleanup_value_free_to_mark (value_mark ());
|
2012-01-04 17:15:14 +01:00
|
|
|
|
struct value *res_val = NULL;
|
2008-10-16 16:46:20 +02: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 22:55:40 +01:00
|
|
|
|
if (arg1 == NULL)
|
2013-05-30 19:18:54 +02:00
|
|
|
|
{
|
|
|
|
|
do_cleanups (cleanup);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2009-02-04 22:55:40 +01:00
|
|
|
|
|
2008-10-16 16:46:20 +02:00
|
|
|
|
arg2 = convert_value_from_python (other);
|
2009-02-04 22:55:40 +01:00
|
|
|
|
if (arg2 == NULL)
|
2013-05-30 19:18:54 +02:00
|
|
|
|
{
|
|
|
|
|
do_cleanups (cleanup);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2008-10-16 16:46:20 +02: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);
|
|
|
|
|
|
* 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 15:24:41 +02: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 16:46:20 +02:00
|
|
|
|
else
|
|
|
|
|
res_val = value_binop (arg1, arg2, BINOP_ADD);
|
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
|
* 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 15:24:41 +02: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 16:46:20 +02:00
|
|
|
|
else
|
|
|
|
|
res_val = value_binop (arg1, arg2, BINOP_SUB);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case VALPY_MUL:
|
|
|
|
|
res_val = value_binop (arg1, arg2, BINOP_MUL);
|
|
|
|
|
break;
|
|
|
|
|
case VALPY_DIV:
|
|
|
|
|
res_val = value_binop (arg1, arg2, BINOP_DIV);
|
|
|
|
|
break;
|
|
|
|
|
case VALPY_REM:
|
|
|
|
|
res_val = value_binop (arg1, arg2, BINOP_REM);
|
|
|
|
|
break;
|
|
|
|
|
case VALPY_POW:
|
|
|
|
|
res_val = value_binop (arg1, arg2, BINOP_EXP);
|
|
|
|
|
break;
|
2009-02-04 22:55:40 +01:00
|
|
|
|
case VALPY_LSH:
|
|
|
|
|
res_val = value_binop (arg1, arg2, BINOP_LSH);
|
|
|
|
|
break;
|
|
|
|
|
case VALPY_RSH:
|
|
|
|
|
res_val = value_binop (arg1, arg2, BINOP_RSH);
|
|
|
|
|
break;
|
|
|
|
|
case VALPY_BITAND:
|
|
|
|
|
res_val = value_binop (arg1, arg2, BINOP_BITWISE_AND);
|
|
|
|
|
break;
|
|
|
|
|
case VALPY_BITOR:
|
|
|
|
|
res_val = value_binop (arg1, arg2, BINOP_BITWISE_IOR);
|
|
|
|
|
break;
|
|
|
|
|
case VALPY_BITXOR:
|
|
|
|
|
res_val = value_binop (arg1, arg2, BINOP_BITWISE_XOR);
|
|
|
|
|
break;
|
2008-10-16 16:46:20 +02:00
|
|
|
|
}
|
2012-01-03 20:27:52 +01:00
|
|
|
|
|
|
|
|
|
if (res_val)
|
|
|
|
|
result = value_to_value_object (res_val);
|
|
|
|
|
|
|
|
|
|
do_cleanups (cleanup);
|
2008-10-16 16:46:20 +02:00
|
|
|
|
}
|
|
|
|
|
GDB_PY_HANDLE_EXCEPTION (except);
|
|
|
|
|
|
2012-01-03 20:27:52 +01:00
|
|
|
|
return result;
|
2008-10-16 16:46:20 +02: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 20:27:52 +01:00
|
|
|
|
PyObject *result = NULL;
|
2008-10-16 16:46:20 +02:00
|
|
|
|
|
|
|
|
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
|
|
|
|
{
|
2012-01-03 20:27:52 +01: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 16:46:20 +02:00
|
|
|
|
val = value_neg (((value_object *) self)->value);
|
2012-01-03 20:27:52 +01:00
|
|
|
|
result = value_to_value_object (val);
|
|
|
|
|
do_cleanups (cleanup);
|
2008-10-16 16:46:20 +02:00
|
|
|
|
}
|
|
|
|
|
GDB_PY_HANDLE_EXCEPTION (except);
|
|
|
|
|
|
2012-01-03 20:27:52 +01:00
|
|
|
|
return result;
|
2008-10-16 16:46:20 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
|
valpy_positive (PyObject *self)
|
|
|
|
|
{
|
2009-08-13 20:39:20 +02:00
|
|
|
|
return value_to_value_object (((value_object *) self)->value);
|
2008-10-16 16:46:20 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
|
valpy_absolute (PyObject *self)
|
|
|
|
|
{
|
2009-07-02 14:20:18 +02:00
|
|
|
|
struct value *value = ((value_object *) self)->value;
|
2011-10-07 15:46:11 +02:00
|
|
|
|
volatile struct gdb_exception except;
|
|
|
|
|
int isabs = 1;
|
2010-05-17 23:23:25 +02:00
|
|
|
|
|
2011-10-07 15:46:11 +02:00
|
|
|
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
|
|
|
|
{
|
2012-01-03 20:27:52 +01:00
|
|
|
|
struct cleanup *cleanup = make_cleanup_value_free_to_mark (value_mark ());
|
|
|
|
|
|
2011-10-07 15:46:11 +02:00
|
|
|
|
if (value_less (value, value_zero (value_type (value), not_lval)))
|
|
|
|
|
isabs = 0;
|
2012-01-03 20:27:52 +01:00
|
|
|
|
|
|
|
|
|
do_cleanups (cleanup);
|
2011-10-07 15:46:11 +02:00
|
|
|
|
}
|
|
|
|
|
GDB_PY_HANDLE_EXCEPTION (except);
|
|
|
|
|
|
|
|
|
|
if (isabs)
|
2008-10-16 16:46:20 +02:00
|
|
|
|
return valpy_positive (self);
|
2011-10-07 15:46:11 +02:00
|
|
|
|
else
|
|
|
|
|
return valpy_negative (self);
|
2008-10-16 16:46:20 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Implements boolean evaluation of gdb.Value. */
|
|
|
|
|
static int
|
|
|
|
|
valpy_nonzero (PyObject *self)
|
|
|
|
|
{
|
2011-10-07 15:46:11 +02:00
|
|
|
|
volatile struct gdb_exception except;
|
2008-10-16 16:46:20 +02:00
|
|
|
|
value_object *self_value = (value_object *) self;
|
|
|
|
|
struct type *type;
|
2011-10-07 15:46:11 +02:00
|
|
|
|
int nonzero = 0; /* Appease GCC warning. */
|
2008-10-16 16:46:20 +02:00
|
|
|
|
|
2011-10-07 15:46:11 +02:00
|
|
|
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
|
|
|
|
{
|
2011-11-28 16:49:43 +01:00
|
|
|
|
type = check_typedef (value_type (self_value->value));
|
|
|
|
|
|
2011-10-07 15:46:11 +02: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 16:46:20 +02:00
|
|
|
|
}
|
|
|
|
|
|
2009-02-04 22:55:40 +01:00
|
|
|
|
/* Implements ~ for value objects. */
|
2008-10-16 16:46:20 +02:00
|
|
|
|
static PyObject *
|
2009-02-04 22:55:40 +01:00
|
|
|
|
valpy_invert (PyObject *self)
|
2008-10-16 16:46:20 +02:00
|
|
|
|
{
|
2009-02-04 22:55:40 +01:00
|
|
|
|
struct value *val = NULL;
|
2008-10-16 16:46:20 +02:00
|
|
|
|
volatile struct gdb_exception except;
|
|
|
|
|
|
2009-02-04 22:55:40 +01:00
|
|
|
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
2008-10-16 16:46:20 +02:00
|
|
|
|
{
|
2009-02-04 22:55:40 +01:00
|
|
|
|
val = value_complement (((value_object *) self)->value);
|
|
|
|
|
}
|
|
|
|
|
GDB_PY_HANDLE_EXCEPTION (except);
|
2008-10-16 16:46:20 +02:00
|
|
|
|
|
2009-02-04 22:55:40 +01:00
|
|
|
|
return value_to_value_object (val);
|
|
|
|
|
}
|
2008-10-16 16:46:20 +02:00
|
|
|
|
|
2009-02-04 22:55:40 +01: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 16:46:20 +02:00
|
|
|
|
|
2009-02-04 22:55:40 +01: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 16:46:20 +02:00
|
|
|
|
|
2009-02-04 22:55:40 +01: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 16:46:20 +02:00
|
|
|
|
|
2009-02-04 22:55:40 +01: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 15:24:40 +02:00
|
|
|
|
/* Implements comparison operations for value objects. Returns NULL on error,
|
|
|
|
|
with a python exception set. */
|
2009-02-04 22:55:40 +01: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 16:46:20 +02: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 15:18:55 +02:00
|
|
|
|
_("Invalid operation on gdb.Value."));
|
2008-10-16 16:46:20 +02:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
|
|
|
|
{
|
2012-01-03 20:27:52 +01:00
|
|
|
|
struct value *value_other, *mark = value_mark ();
|
|
|
|
|
struct cleanup *cleanup;
|
|
|
|
|
|
2009-02-04 22:55:40 +01:00
|
|
|
|
value_other = convert_value_from_python (other);
|
|
|
|
|
if (value_other == NULL)
|
2009-08-24 20:55:21 +02:00
|
|
|
|
{
|
|
|
|
|
result = -1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2009-02-04 22:55:40 +01:00
|
|
|
|
|
2012-01-03 20:27:52 +01:00
|
|
|
|
cleanup = make_cleanup_value_free_to_mark (mark);
|
|
|
|
|
|
2008-10-16 16:46:20 +02: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 15:18:55 +02:00
|
|
|
|
_("Invalid operation on gdb.Value."));
|
2009-08-24 20:55:21 +02:00
|
|
|
|
result = -1;
|
|
|
|
|
break;
|
2008-10-16 16:46:20 +02:00
|
|
|
|
}
|
2012-01-03 20:27:52 +01:00
|
|
|
|
|
|
|
|
|
do_cleanups (cleanup);
|
2008-10-16 16:46:20 +02:00
|
|
|
|
}
|
|
|
|
|
GDB_PY_HANDLE_EXCEPTION (except);
|
|
|
|
|
|
2009-08-24 20:55:21 +02:00
|
|
|
|
/* In this case, the Python exception has already been set. */
|
|
|
|
|
if (result < 0)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
2008-10-16 16:46:20 +02:00
|
|
|
|
if (result == 1)
|
|
|
|
|
Py_RETURN_TRUE;
|
|
|
|
|
|
|
|
|
|
Py_RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2009-02-04 22:55:40 +01:00
|
|
|
|
/* Helper function to determine if a type is "int-like". */
|
|
|
|
|
static int
|
|
|
|
|
is_intlike (struct type *type, int ptr_ok)
|
|
|
|
|
{
|
|
|
|
|
return (TYPE_CODE (type) == TYPE_CODE_INT
|
|
|
|
|
|| TYPE_CODE (type) == TYPE_CODE_ENUM
|
|
|
|
|
|| TYPE_CODE (type) == TYPE_CODE_BOOL
|
|
|
|
|
|| TYPE_CODE (type) == TYPE_CODE_CHAR
|
|
|
|
|
|| (ptr_ok && TYPE_CODE (type) == TYPE_CODE_PTR));
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-12 17:47:30 +01:00
|
|
|
|
#ifndef IS_PY3K
|
2009-02-04 22:55:40 +01: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)
|
|
|
|
|
{
|
2011-10-07 15:46:11 +02:00
|
|
|
|
CHECK_TYPEDEF (type);
|
|
|
|
|
if (!is_intlike (type, 0))
|
|
|
|
|
error (_("Cannot convert value to int."));
|
|
|
|
|
|
2009-02-04 22:55:40 +01:00
|
|
|
|
l = value_as_long (value);
|
|
|
|
|
}
|
|
|
|
|
GDB_PY_HANDLE_EXCEPTION (except);
|
|
|
|
|
|
2011-01-26 21:53:45 +01:00
|
|
|
|
return gdb_py_object_from_longest (l);
|
2009-02-04 22:55:40 +01:00
|
|
|
|
}
|
2012-12-12 17:47:30 +01:00
|
|
|
|
#endif
|
2009-02-04 22:55:40 +01: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 15:46:11 +02:00
|
|
|
|
CHECK_TYPEDEF (type);
|
|
|
|
|
|
|
|
|
|
if (!is_intlike (type, 1))
|
|
|
|
|
error (_("Cannot convert value to long."));
|
|
|
|
|
|
2009-02-04 22:55:40 +01:00
|
|
|
|
l = value_as_long (value);
|
|
|
|
|
}
|
|
|
|
|
GDB_PY_HANDLE_EXCEPTION (except);
|
|
|
|
|
|
2011-01-26 21:53:45 +01:00
|
|
|
|
return gdb_py_long_from_longest (l);
|
2009-02-04 22:55:40 +01: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 15:46:11 +02:00
|
|
|
|
CHECK_TYPEDEF (type);
|
|
|
|
|
|
|
|
|
|
if (TYPE_CODE (type) != TYPE_CODE_FLT)
|
|
|
|
|
error (_("Cannot convert value to float."));
|
|
|
|
|
|
2009-02-04 22:55:40 +01:00
|
|
|
|
d = value_as_double (value);
|
|
|
|
|
}
|
|
|
|
|
GDB_PY_HANDLE_EXCEPTION (except);
|
|
|
|
|
|
|
|
|
|
return PyFloat_FromDouble (d);
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-16 16:46:20 +02: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 20:51:10 +01:00
|
|
|
|
release_value_or_incref (val);
|
2009-03-29 23:11:11 +02:00
|
|
|
|
val_obj->address = NULL;
|
2009-05-28 02:47:20 +02:00
|
|
|
|
val_obj->type = NULL;
|
2010-08-30 22:28:31 +02:00
|
|
|
|
val_obj->dynamic_type = NULL;
|
2009-08-13 20:39:20 +02:00
|
|
|
|
note_value (val_obj);
|
2008-10-16 16:46:20 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (PyObject *) val_obj;
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-13 20:39:20 +02:00
|
|
|
|
/* Returns a borrowed reference to the struct value corresponding to
|
|
|
|
|
the given value object. */
|
2009-05-28 03:05:14 +02:00
|
|
|
|
struct value *
|
|
|
|
|
value_object_to_value (PyObject *self)
|
|
|
|
|
{
|
|
|
|
|
value_object *real;
|
2010-05-17 23:23:25 +02:00
|
|
|
|
|
2009-05-28 03:05:14 +02:00
|
|
|
|
if (! PyObject_TypeCheck (self, &value_object_type))
|
|
|
|
|
return NULL;
|
|
|
|
|
real = (value_object *) self;
|
|
|
|
|
return real->value;
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-16 16:46:20 +02:00
|
|
|
|
/* Try to convert a Python value to a gdb value. If the value cannot
|
2009-08-13 20:39:20 +02: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 16:46:20 +02:00
|
|
|
|
|
|
|
|
|
struct value *
|
|
|
|
|
convert_value_from_python (PyObject *obj)
|
|
|
|
|
{
|
|
|
|
|
struct value *value = NULL; /* -Wall */
|
2009-02-04 22:55:40 +01:00
|
|
|
|
volatile struct gdb_exception except;
|
|
|
|
|
int cmp;
|
2008-10-16 16:46:20 +02:00
|
|
|
|
|
2009-02-04 22:55:40 +01:00
|
|
|
|
gdb_assert (obj != NULL);
|
2008-10-16 16:46:20 +02:00
|
|
|
|
|
2009-02-04 22:55:40 +01:00
|
|
|
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
2008-10-16 16:46:20 +02:00
|
|
|
|
{
|
2009-02-04 22:55:40 +01:00
|
|
|
|
if (PyBool_Check (obj))
|
|
|
|
|
{
|
|
|
|
|
cmp = PyObject_IsTrue (obj);
|
|
|
|
|
if (cmp >= 0)
|
|
|
|
|
value = value_from_longest (builtin_type_pybool, cmp);
|
|
|
|
|
}
|
2013-10-03 16:43:32 +02: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 22:55:40 +01:00
|
|
|
|
else if (PyLong_Check (obj))
|
|
|
|
|
{
|
|
|
|
|
LONGEST l = PyLong_AsLongLong (obj);
|
2008-10-16 16:46:20 +02:00
|
|
|
|
|
2010-06-28 23:16:04 +02: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 22:55:40 +01:00
|
|
|
|
value = value_from_longest (builtin_type_pylong, l);
|
|
|
|
|
}
|
2013-10-03 16:43:32 +02: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 22:55:40 +01:00
|
|
|
|
else if (PyFloat_Check (obj))
|
|
|
|
|
{
|
|
|
|
|
double d = PyFloat_AsDouble (obj);
|
2008-10-16 16:46:20 +02:00
|
|
|
|
|
2009-02-04 22:55:40 +01: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 22:05:55 +02:00
|
|
|
|
struct cleanup *old;
|
|
|
|
|
|
2009-02-04 22:55:40 +01:00
|
|
|
|
old = make_cleanup (xfree, s);
|
2009-06-17 20:47:35 +02:00
|
|
|
|
value = value_cstring (s, strlen (s), builtin_type_pychar);
|
2009-02-04 22:55:40 +01:00
|
|
|
|
do_cleanups (old);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (PyObject_TypeCheck (obj, &value_object_type))
|
2009-03-21 04:13:02 +01:00
|
|
|
|
value = value_copy (((value_object *) obj)->value);
|
2010-01-14 09:03:37 +01:00
|
|
|
|
else if (gdbpy_is_lazy_string (obj))
|
|
|
|
|
{
|
|
|
|
|
PyObject *result;
|
2010-05-17 23:23:25 +02:00
|
|
|
|
|
2011-02-28 20:38:34 +01:00
|
|
|
|
result = PyObject_CallMethodObjArgs (obj, gdbpy_value_cst, NULL);
|
2010-01-14 09:03:37 +01:00
|
|
|
|
value = value_copy (((value_object *) result)->value);
|
|
|
|
|
}
|
2009-02-04 22:55:40 +01:00
|
|
|
|
else
|
2012-12-12 17:47:30 +01:00
|
|
|
|
#ifdef IS_PY3K
|
|
|
|
|
PyErr_Format (PyExc_TypeError,
|
|
|
|
|
_("Could not convert Python object: %S."), obj);
|
|
|
|
|
#else
|
2011-01-06 01:57:05 +01:00
|
|
|
|
PyErr_Format (PyExc_TypeError,
|
|
|
|
|
_("Could not convert Python object: %s."),
|
2009-02-04 22:55:40 +01:00
|
|
|
|
PyString_AsString (PyObject_Str (obj)));
|
2012-12-12 17:47:30 +01:00
|
|
|
|
#endif
|
2009-02-04 22:55:40 +01:00
|
|
|
|
}
|
|
|
|
|
if (except.reason < 0)
|
|
|
|
|
{
|
|
|
|
|
PyErr_Format (except.reason == RETURN_QUIT
|
|
|
|
|
? PyExc_KeyboardInterrupt : PyExc_RuntimeError,
|
|
|
|
|
"%s", except.message);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2008-10-16 16:46:20 +02:00
|
|
|
|
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Returns value object in the ARGth position in GDB's history. */
|
|
|
|
|
PyObject *
|
2009-02-04 22:55:40 +01:00
|
|
|
|
gdbpy_history (PyObject *self, PyObject *args)
|
2008-10-16 16:46:20 +02: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 23:16:04 +02: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 22:28:52 +02:00
|
|
|
|
int
|
2008-10-16 16:46:20 +02: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 22:28:52 +02:00
|
|
|
|
return -1;
|
2008-10-16 16:46:20 +02:00
|
|
|
|
|
2013-05-20 22:36:19 +02:00
|
|
|
|
return gdb_pymodule_addobject (gdb_module, "Value",
|
|
|
|
|
(PyObject *) &value_object_type);
|
2008-10-16 16:46:20 +02:00
|
|
|
|
}
|
|
|
|
|
|
2009-05-28 02:47:20 +02:00
|
|
|
|
|
|
|
|
|
|
2009-03-26 21:58:11 +01:00
|
|
|
|
static PyGetSetDef value_object_getset[] = {
|
2009-03-29 23:11:11 +02:00
|
|
|
|
{ "address", valpy_get_address, NULL, "The address of the value.",
|
|
|
|
|
NULL },
|
2009-03-26 21:58:11 +01:00
|
|
|
|
{ "is_optimized_out", valpy_get_is_optimized_out, NULL,
|
2011-01-06 01:57:05 +01:00
|
|
|
|
"Boolean telling whether the value is optimized "
|
|
|
|
|
"out (i.e., not available).",
|
2009-03-26 21:58:11 +01:00
|
|
|
|
NULL },
|
2009-05-28 02:47:20 +02:00
|
|
|
|
{ "type", valpy_get_type, NULL, "Type of the value.", NULL },
|
2010-08-30 22:28:31 +02:00
|
|
|
|
{ "dynamic_type", valpy_get_dynamic_type, NULL,
|
|
|
|
|
"Dynamic type of the value.", NULL },
|
2011-10-25 20:34:51 +02: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 21:58:11 +01: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 22:25:00 +02:00
|
|
|
|
static PyMethodDef value_object_methods[] = {
|
2009-05-28 02:47:20 +02:00
|
|
|
|
{ "cast", valpy_cast, METH_VARARGS, "Cast the value to the supplied type." },
|
2010-08-23 22:29:19 +02: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 22:25:00 +02:00
|
|
|
|
{ "dereference", valpy_dereference, METH_NOARGS, "Dereferences the value." },
|
2012-03-22 09:10:44 +01: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 01:57:05 +01:00
|
|
|
|
{ "lazy_string", (PyCFunction) valpy_lazy_string,
|
|
|
|
|
METH_VARARGS | METH_KEYWORDS,
|
2010-01-14 09:03:37 +01:00
|
|
|
|
"lazy_string ([encoding] [, length]) -> lazy_string\n\
|
|
|
|
|
Return a lazy string representation of the value." },
|
2009-03-21 04:13:02 +01:00
|
|
|
|
{ "string", (PyCFunction) valpy_string, METH_VARARGS | METH_KEYWORDS,
|
2009-07-10 12:35:17 +02:00
|
|
|
|
"string ([encoding] [, errors] [, length]) -> string\n\
|
2009-03-21 04:13:02 +01:00
|
|
|
|
Return Unicode string representation of the value." },
|
2011-10-25 20:34:51 +02:00
|
|
|
|
{ "fetch_lazy", valpy_fetch_lazy, METH_NOARGS,
|
|
|
|
|
"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 22:25:00 +02:00
|
|
|
|
{NULL} /* Sentinel */
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static PyNumberMethods value_object_as_number = {
|
|
|
|
|
valpy_add,
|
|
|
|
|
valpy_subtract,
|
|
|
|
|
valpy_multiply,
|
2012-12-12 17:47:30 +01: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 22:25:00 +02:00
|
|
|
|
valpy_divide,
|
2012-12-12 17:47:30 +01: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 22:25:00 +02: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 22:55:40 +01: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 17:47:30 +01:00
|
|
|
|
#ifdef IS_PY3K
|
|
|
|
|
valpy_long, /* nb_int */
|
|
|
|
|
NULL, /* reserved */
|
|
|
|
|
#else
|
2009-02-04 22:55:40 +01:00
|
|
|
|
NULL, /* nb_coerce */
|
|
|
|
|
valpy_int, /* nb_int */
|
|
|
|
|
valpy_long, /* nb_long */
|
2012-12-12 17:47:30 +01:00
|
|
|
|
#endif
|
2009-02-04 22:55:40 +01:00
|
|
|
|
valpy_float, /* nb_float */
|
2012-12-12 17:47:30 +01:00
|
|
|
|
#ifndef IS_PY3K
|
2009-02-04 22:55:40 +01:00
|
|
|
|
NULL, /* nb_oct */
|
2012-12-12 17:47:30 +01: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 22:25:00 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static PyMappingMethods value_object_as_mapping = {
|
|
|
|
|
valpy_length,
|
|
|
|
|
valpy_getitem,
|
|
|
|
|
valpy_setitem
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
PyTypeObject value_object_type = {
|
2012-12-12 17:47:30 +01: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 22:25:00 +02: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 13:11:28 +02:00
|
|
|
|
valpy_hash, /*tp_hash*/
|
2010-07-27 14:40:42 +02: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 22:25:00 +02:00
|
|
|
|
valpy_str, /*tp_str*/
|
|
|
|
|
0, /*tp_getattro*/
|
|
|
|
|
0, /*tp_setattro*/
|
|
|
|
|
0, /*tp_as_buffer*/
|
2011-01-06 01:57:05 +01: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 22:25:00 +02: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 22:55:40 +01:00
|
|
|
|
value_object_methods, /* tp_methods */
|
|
|
|
|
0, /* tp_members */
|
2009-03-26 21:58:11 +01:00
|
|
|
|
value_object_getset, /* tp_getset */
|
2009-02-04 22:55:40 +01: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 22:25:00 +02:00
|
|
|
|
};
|
|
|
|
|
|
2009-08-13 20:39:20 +02:00
|
|
|
|
#else
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
preserve_python_values (struct objfile *objfile, htab_t copied_types)
|
|
|
|
|
{
|
|
|
|
|
/* Nothing. */
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-16 16:46:20 +02:00
|
|
|
|
#endif /* HAVE_PYTHON */
|