2008-10-16 14:46:20 +00:00
|
|
|
/* Python interface to values.
|
|
|
|
|
2009-01-03 05:58:08 +00:00
|
|
|
Copyright (C) 2008, 2009 Free Software Foundation, Inc.
|
2008-10-16 14:46:20 +00:00
|
|
|
|
|
|
|
This file is part of GDB.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
|
|
|
|
|
|
#include "defs.h"
|
2009-02-04 21:55:40 +00:00
|
|
|
#include "gdb_assert.h"
|
2008-10-16 14:46:20 +00: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 17:19:58 +00:00
|
|
|
#include "valprint.h"
|
2008-10-16 14:46:20 +00:00
|
|
|
|
|
|
|
/* List of all values which are currently exposed to Python. It is
|
|
|
|
maintained so that when an objfile is discarded, preserve_values
|
|
|
|
can copy the values' types if needed. This is declared
|
|
|
|
unconditionally to reduce the number of uses of HAVE_PYTHON in the
|
|
|
|
generic code. */
|
2008-12-08 17:13:30 +00:00
|
|
|
/* This variable is unnecessarily initialized to NULL in order to
|
|
|
|
work around a linker bug on MacOS. */
|
|
|
|
struct value *values_in_python = NULL;
|
2008-10-16 14:46:20 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_PYTHON
|
|
|
|
|
|
|
|
#include "python-internal.h"
|
|
|
|
|
|
|
|
/* Even though Python scalar types directly map to host types, we use
|
|
|
|
target types here to remain consistent with the the values system in
|
|
|
|
GDB (which uses target arithmetic). */
|
|
|
|
|
|
|
|
/* Python's integer type corresponds to C's long type. */
|
|
|
|
#define builtin_type_pyint builtin_type (current_gdbarch)->builtin_long
|
|
|
|
|
|
|
|
/* Python's float type corresponds to C's double type. */
|
|
|
|
#define builtin_type_pyfloat builtin_type (current_gdbarch)->builtin_double
|
|
|
|
|
|
|
|
/* Python's long type corresponds to C's long long type. */
|
|
|
|
#define builtin_type_pylong builtin_type (current_gdbarch)->builtin_long_long
|
|
|
|
|
|
|
|
#define builtin_type_pybool \
|
|
|
|
language_bool_type (current_language, current_gdbarch)
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
PyObject_HEAD
|
|
|
|
struct value *value;
|
|
|
|
int owned_by_gdb;
|
|
|
|
} value_object;
|
|
|
|
|
|
|
|
/* Called by the Python interpreter when deallocating a value object. */
|
|
|
|
static void
|
|
|
|
valpy_dealloc (PyObject *obj)
|
|
|
|
{
|
|
|
|
value_object *self = (value_object *) obj;
|
|
|
|
|
|
|
|
value_remove_from_list (&values_in_python, self->value);
|
|
|
|
|
|
|
|
if (!self->owned_by_gdb)
|
|
|
|
value_free (self->value);
|
|
|
|
self->ob_type->tp_free (self);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Called when a new gdb.Value object needs to be allocated. */
|
|
|
|
static PyObject *
|
|
|
|
valpy_new (PyTypeObject *subtype, PyObject *args, PyObject *keywords)
|
|
|
|
{
|
|
|
|
struct value *value = NULL; /* Initialize to appease gcc warning. */
|
|
|
|
value_object *value_obj;
|
|
|
|
|
|
|
|
if (PyTuple_Size (args) != 1)
|
|
|
|
{
|
|
|
|
PyErr_SetString (PyExc_TypeError, _("Value object creation takes only "
|
|
|
|
"1 argument"));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
value_obj = (value_object *) subtype->tp_alloc (subtype, 1);
|
|
|
|
if (value_obj == NULL)
|
|
|
|
{
|
|
|
|
PyErr_SetString (PyExc_MemoryError, _("Could not allocate memory to "
|
|
|
|
"create Value object."));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-02-04 21:55:40 +00:00
|
|
|
value = convert_value_from_python (PyTuple_GetItem (args, 0));
|
|
|
|
if (value == NULL)
|
2008-10-16 14:46:20 +00:00
|
|
|
{
|
|
|
|
subtype->tp_free (value_obj);
|
2009-02-04 21:55:40 +00:00
|
|
|
return NULL;
|
2008-10-16 14:46:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
value_obj->value = value;
|
2008-10-23 17:14:20 +00:00
|
|
|
value_obj->owned_by_gdb = 0;
|
2008-10-16 14:46:20 +00:00
|
|
|
release_value (value);
|
|
|
|
value_prepend_to_list (&values_in_python, value);
|
|
|
|
|
|
|
|
return (PyObject *) value_obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Given a value of a pointer type, apply the C unary * operator to it. */
|
|
|
|
static PyObject *
|
|
|
|
valpy_dereference (PyObject *self, PyObject *args)
|
|
|
|
{
|
|
|
|
struct value *res_val = NULL; /* Initialize to appease gcc warning. */
|
|
|
|
volatile struct gdb_exception except;
|
|
|
|
|
|
|
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
|
|
|
{
|
|
|
|
res_val = value_ind (((value_object *) self)->value);
|
|
|
|
}
|
|
|
|
GDB_PY_HANDLE_EXCEPTION (except);
|
|
|
|
|
|
|
|
return value_to_value_object (res_val);
|
|
|
|
}
|
|
|
|
|
2009-02-04 21:55:40 +00:00
|
|
|
/* Return "&value". */
|
|
|
|
static PyObject *
|
|
|
|
valpy_address (PyObject *self, PyObject *args)
|
|
|
|
{
|
|
|
|
struct value *res_val = NULL; /* Initialize to appease gcc warning. */
|
|
|
|
volatile struct gdb_exception except;
|
|
|
|
|
|
|
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
|
|
|
{
|
|
|
|
res_val = value_addr (((value_object *) self)->value);
|
|
|
|
}
|
|
|
|
GDB_PY_HANDLE_EXCEPTION (except);
|
|
|
|
|
|
|
|
return value_to_value_object (res_val);
|
|
|
|
}
|
|
|
|
|
2008-10-16 14:46:20 +00:00
|
|
|
static Py_ssize_t
|
|
|
|
valpy_length (PyObject *self)
|
|
|
|
{
|
|
|
|
/* We don't support getting the number of elements in a struct / class. */
|
|
|
|
PyErr_SetString (PyExc_NotImplementedError,
|
|
|
|
"Invalid operation on gdb.Value.");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Given string name of an element inside structure, return its value
|
|
|
|
object. */
|
|
|
|
static PyObject *
|
|
|
|
valpy_getitem (PyObject *self, PyObject *key)
|
|
|
|
{
|
|
|
|
value_object *self_value = (value_object *) self;
|
2009-02-04 21:55:40 +00:00
|
|
|
char *field = NULL;
|
|
|
|
struct value *idx = NULL;
|
2008-10-16 14:46:20 +00:00
|
|
|
struct value *res_val = NULL; /* Initialize to appease gcc warning. */
|
|
|
|
volatile struct gdb_exception except;
|
|
|
|
|
2009-02-04 21:55:40 +00:00
|
|
|
if (gdbpy_is_string (key))
|
|
|
|
{
|
|
|
|
field = python_string_to_host_string (key);
|
|
|
|
if (field == NULL)
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-10-16 14:46:20 +00:00
|
|
|
|
|
|
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
|
|
|
{
|
2008-10-23 22:48:40 +00:00
|
|
|
struct value *tmp = self_value->value;
|
2009-02-04 21:55:40 +00: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);
|
|
|
|
if (idx == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
res_val = value_subscript (tmp, idx);
|
|
|
|
}
|
2008-10-16 14:46:20 +00:00
|
|
|
}
|
2009-02-04 21:55:40 +00:00
|
|
|
if (field)
|
|
|
|
xfree (field);
|
2008-10-16 14:46:20 +00:00
|
|
|
GDB_PY_HANDLE_EXCEPTION (except);
|
|
|
|
|
|
|
|
return value_to_value_object (res_val);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
valpy_setitem (PyObject *self, PyObject *key, PyObject *value)
|
|
|
|
{
|
|
|
|
PyErr_Format (PyExc_NotImplementedError,
|
|
|
|
_("Setting of struct elements is not currently supported."));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Called by the Python interpreter to obtain string representation
|
|
|
|
of the object. */
|
|
|
|
static PyObject *
|
|
|
|
valpy_str (PyObject *self)
|
|
|
|
{
|
|
|
|
char *s = NULL;
|
|
|
|
long dummy;
|
|
|
|
struct ui_file *stb;
|
|
|
|
struct cleanup *old_chain;
|
|
|
|
PyObject *result;
|
gdb
* varobj.c (value_get_print_value): Include valprint.h.
(value_get_print_value): Use get_formatted_print_options.
* value.h (struct value_print_options): Declare.
(value_print, val_print, common_val_print, val_print_string):
Update.
* value.c: Include valprint.h.
(show_values): Use get_user_print_options.
(show_convenience): Likewise.
* valprint.h (prettyprint_arrays, prettyprint_structs): Don't
declare.
(struct value_print_options): New type.
(vtblprint, unionprint, addressprint, objectprint, print_max,
inspect_it, repeat_count_threshold, output_format,
stop_print_at_null): Don't declare.
(user_print_options, get_user_print_options,
get_raw_print_options, get_formatted_print_options): Declare.
(print_array_indexes_p): Don't declare.
(maybe_print_array_index, val_print_array_elements): Update.
* valprint.c (print_max): Remove.
(user_print_options): New global.
(get_user_print_options, get_raw_print_options,
get_formatted_print_options): New functions.
(print_array_indexes, repeat_count_threshold, stop_print_at_null,
prettyprint_structs, prettyprint_arrays, unionprint,
addressprint): Remove.
(val_print): Remove format, deref_ref, pretty arguments; add
options. Update.
(common_val_print): Likewise.
(print_array_indexes_p): Remove.
(maybe_print_array_index): Remove format, pretty arguments; add
options. Update.
(val_print_array_elements): Remove format, deref_ref, pretty
arguments; add options. Update.
(val_print_string): Add options argument. Update.
(_initialize_valprint): Use user_print_options.
(output_format): Remove.
(set_output_radix_1): Use user_print_options.
* typeprint.c: Include valprint.h.
(objectprint): Don't declare.
(whatis_exp): Use get_user_print_options.
* tui/tui-regs.c: Include valprint.h.
(tui_register_format): Use get_formatted_print_options.
* tracepoint.c: Include valprint.h.
(addressprint): Don't declare.
(trace_mention): Use get_user_print_options.
(tracepoints_info): Likewise.
* stack.c (print_frame_args): Use get_raw_print_options.
(print_frame_info): Use get_user_print_options.
(print_frame): Likewise.
* sh64-tdep.c: Include valprint.h
(sh64_do_register): Use get_formatted_print_options.
* scm-valprint.c (scm_inferior_print): Remove format, deref_ref,
pretty arguments; add options.
(scm_scmlist_print): Likewise. Update.
(scm_scmval_print): Likewise.
(scm_val_print): Likewise.
(scm_value_print): Remove format, pretty arguments; add options.
Update.
* scm-lang.h (scm_value_print, scm_val_print, scm_scmval_print):
Update.
* scm-lang.c (scm_printstr): Add options argument.
* python/python-value.c: Include valprint.h.
(valpy_str): Use get_user_print_options.
* printcmd.c: Include valprint.h.
(addressprint): Don't declare.
(inspect_it): Remove.
(print_formatted): Remove format option; add options. Update.
(print_scalar_formatted): Likewise.
(print_address_demangle): Use get_user_print_options.
(do_examine): Use get_formatted_print_options.
(print_command_1): Likewise.
(output_command): Use get_formatted_print_options.
(do_one_display): Likewise.
(print_variable_value): Use get_user_print_options.
* p-valprint.c (pascal_val_print): Remove format, deref_ref,
pretty arguments; add options. Update.
(pascal_value_print): Remove format, pretty arguments; add
options. Update.
(vtblprint, objectprint): Don't declare.
(pascal_static_field_print): Remove.
(pascal_object_print_value_fields): Remove format, pretty
arguments; add options. Update.
(pascal_object_print_static_field): Likewise.
(_initialize_pascal_valprint): Use user_print_options. Update.
* p-lang.h (pascal_val_print, pascal_value_print,
pascal_printstr, pascal_object_print_value_fields): Update.
(vtblprint, static_field_print): Don't declare.
* p-lang.c (pascal_printstr): Add options argument. Update.
* objc-lang.c (objc_printstr): Add options argument. Update.
* mt-tdep.c: Include valprint.h.
(mt_registers_info): Use get_raw_print_options.
* mips-tdep.c: Include valprint.h.
(mips_print_fp_register): Use get_formatted_print_options.
(mips_print_register): Likewise.
* mi/mi-main.c: Include valprint.h.
(get_register): Use get_user_print_options.
(mi_cmd_data_evaluate_expression): Likewise.
(mi_cmd_data_read_memory): Use get_formatted_print_options.
* mi/mi-cmd-stack.c: Include valprint.h.
(list_args_or_locals): Use get_raw_print_options.
* m2-valprint.c (print_function_pointer_address): Add addressprint
argument.
(m2_print_long_set): Remove format, pretty arguments.
(m2_print_unbounded_array): Remove format, deref_ref, pretty
arguments; add options. Update.
(print_unpacked_pointer): Remove format argument; add options.
Now static. Update.
(print_variable_at_address): Remove format, deref_ref, pretty
arguments; add options. Update.
(m2_print_array_contents): Likewise.
(m2_val_print): Likewise.
* m2-lang.h (m2_val_print): Update.
* m2-lang.c (m2_printstr): Add options argument. Update.
* language.h (struct value_print_options): Declare.
(struct language_defn) <la_printstr>: Add options argument.
<la_val_print>: Remove format, deref_ref, pretty argument; add
options.
<la_value_print>: Remove format, pretty arguments; add options.
<la_print_array_index>: Likewise.
(LA_VAL_PRINT, LA_VALUE_PRINT, LA_PRINT_STRING,
LA_PRINT_ARRAY_INDEX): Update.
(default_print_array_index): Update.
* language.c (default_print_array_index): Remove format, pretty
arguments; add options. Update.
(unk_lang_printstr): Add options argument.
(unk_lang_val_print): Remove format, deref_ref, pretty arguments;
add options.
(unk_lang_value_print): Remove format, pretty arguments; add
options.
* jv-valprint.c (java_value_print): Remove format, pretty
arguments; add options. Update.
(java_print_value_fields): Likewise.
(java_val_print): Remove format, deref_ref, pretty arguments; add
options. Update.
* jv-lang.h (java_val_print, java_value_print): Declare.
* infcmd.c: Include valprint.h.
(print_return_value): Use get_raw_print_options.
(default_print_registers_info): Use get_user_print_options,
get_formatted_print_options.
(registers_info): Use get_formatted_print_options.
* gdbtypes.h (struct value_print_options): Declare.
(print_scalar_formatted): Update.
* f-valprint.c (f77_print_array_1): Remove format, deref_ref,
pretty arguments; add options. Update.
(f77_print_array): Likewise.
(f_val_print): Likewise.
* f-lang.h (f_val_print): Update.
* f-lang.c (f_printstr): Add options argument. Update.
(c_value_print): Update declaration.
* expprint.c: Include valprint.h.
(print_subexp_standard): Use get_raw_print_options,
get_user_print_options.
* eval.c: Include valprint.h.
(objectprint): Don't declare.
(evaluate_subexp_standard): Use get_user_print_options.
* cp-valprint.c (vtblprint, objectprint, static_field_print):
Remove.
(cp_print_value_fields): Remove format, pretty arguments; add
options. Update.
(cp_print_value): Likewise.
(cp_print_static_field): Likewise.
(_initialize_cp_valprint): Use user_print_options. Update.
* c-valprint.c (print_function_pointer_address): Add addressprint
argument.
(c_val_print): Remove format, deref_ref, pretty arguments; add
options. Update.
(c_value_print): Add options argument. Update.
* c-lang.h (c_val_print, c_value_print, c_printstr): Update.
(vtblprint, static_field_print): Don't declare.
(cp_print_value_fields): Update.
* c-lang.c (c_printstr): Add options argument. Update.
* breakpoint.c: Include valprint.h.
(addressprint): Don't declare.
(watchpoint_value_print): Use get_user_print_options.
(print_one_breakpoint_location): Likewise.
(breakpoint_1, print_it_catch_fork, print_it_catch_vfork, mention,
print_exception_catchpoint): Likewise.
* auxv.c (fprint_target_auxv): Don't declare addressprint. Use
get_user_print_options.
* ada-valprint.c (struct ada_val_print_args): Remove format,
deref_ref, and pretty; add options.
(print_optional_low_bound): Add options argument.
(val_print_packed_array_elements): Remove format and pretty
arguments; add options. Update.
(printstr): Add options argument. Update.
(ada_printstr): Likewise.
(ada_val_print): Remove format, deref_ref, pretty arguments; add
options argument. Update.
(ada_val_print_stub): Update.
(ada_val_print_array): Remove format, deref_ref, pretty arguments;
add options. Update.
(ada_val_print_1): Likewise.
(print_variant_part): Likewise.
(ada_value_print): Remove format, pretty arguments; add options.
Update.
(print_record): Likewise.
(print_field_values): Likewise.
* ada-lang.h (ada_val_print, ada_value_print, ada_printstr):
Update.
* ada-lang.c (ada_print_array_index): Add options argument; remove
format and pretty arguments.
(print_one_exception): Use get_user_print_options.
gdb/testsuite
* gdb.base/exprs.exp (test_expr): Add enum formatting tests.
2008-10-28 17:19:58 +00:00
|
|
|
struct value_print_options opts;
|
2008-10-16 14:46:20 +00:00
|
|
|
volatile struct gdb_exception except;
|
|
|
|
|
gdb
* varobj.c (value_get_print_value): Include valprint.h.
(value_get_print_value): Use get_formatted_print_options.
* value.h (struct value_print_options): Declare.
(value_print, val_print, common_val_print, val_print_string):
Update.
* value.c: Include valprint.h.
(show_values): Use get_user_print_options.
(show_convenience): Likewise.
* valprint.h (prettyprint_arrays, prettyprint_structs): Don't
declare.
(struct value_print_options): New type.
(vtblprint, unionprint, addressprint, objectprint, print_max,
inspect_it, repeat_count_threshold, output_format,
stop_print_at_null): Don't declare.
(user_print_options, get_user_print_options,
get_raw_print_options, get_formatted_print_options): Declare.
(print_array_indexes_p): Don't declare.
(maybe_print_array_index, val_print_array_elements): Update.
* valprint.c (print_max): Remove.
(user_print_options): New global.
(get_user_print_options, get_raw_print_options,
get_formatted_print_options): New functions.
(print_array_indexes, repeat_count_threshold, stop_print_at_null,
prettyprint_structs, prettyprint_arrays, unionprint,
addressprint): Remove.
(val_print): Remove format, deref_ref, pretty arguments; add
options. Update.
(common_val_print): Likewise.
(print_array_indexes_p): Remove.
(maybe_print_array_index): Remove format, pretty arguments; add
options. Update.
(val_print_array_elements): Remove format, deref_ref, pretty
arguments; add options. Update.
(val_print_string): Add options argument. Update.
(_initialize_valprint): Use user_print_options.
(output_format): Remove.
(set_output_radix_1): Use user_print_options.
* typeprint.c: Include valprint.h.
(objectprint): Don't declare.
(whatis_exp): Use get_user_print_options.
* tui/tui-regs.c: Include valprint.h.
(tui_register_format): Use get_formatted_print_options.
* tracepoint.c: Include valprint.h.
(addressprint): Don't declare.
(trace_mention): Use get_user_print_options.
(tracepoints_info): Likewise.
* stack.c (print_frame_args): Use get_raw_print_options.
(print_frame_info): Use get_user_print_options.
(print_frame): Likewise.
* sh64-tdep.c: Include valprint.h
(sh64_do_register): Use get_formatted_print_options.
* scm-valprint.c (scm_inferior_print): Remove format, deref_ref,
pretty arguments; add options.
(scm_scmlist_print): Likewise. Update.
(scm_scmval_print): Likewise.
(scm_val_print): Likewise.
(scm_value_print): Remove format, pretty arguments; add options.
Update.
* scm-lang.h (scm_value_print, scm_val_print, scm_scmval_print):
Update.
* scm-lang.c (scm_printstr): Add options argument.
* python/python-value.c: Include valprint.h.
(valpy_str): Use get_user_print_options.
* printcmd.c: Include valprint.h.
(addressprint): Don't declare.
(inspect_it): Remove.
(print_formatted): Remove format option; add options. Update.
(print_scalar_formatted): Likewise.
(print_address_demangle): Use get_user_print_options.
(do_examine): Use get_formatted_print_options.
(print_command_1): Likewise.
(output_command): Use get_formatted_print_options.
(do_one_display): Likewise.
(print_variable_value): Use get_user_print_options.
* p-valprint.c (pascal_val_print): Remove format, deref_ref,
pretty arguments; add options. Update.
(pascal_value_print): Remove format, pretty arguments; add
options. Update.
(vtblprint, objectprint): Don't declare.
(pascal_static_field_print): Remove.
(pascal_object_print_value_fields): Remove format, pretty
arguments; add options. Update.
(pascal_object_print_static_field): Likewise.
(_initialize_pascal_valprint): Use user_print_options. Update.
* p-lang.h (pascal_val_print, pascal_value_print,
pascal_printstr, pascal_object_print_value_fields): Update.
(vtblprint, static_field_print): Don't declare.
* p-lang.c (pascal_printstr): Add options argument. Update.
* objc-lang.c (objc_printstr): Add options argument. Update.
* mt-tdep.c: Include valprint.h.
(mt_registers_info): Use get_raw_print_options.
* mips-tdep.c: Include valprint.h.
(mips_print_fp_register): Use get_formatted_print_options.
(mips_print_register): Likewise.
* mi/mi-main.c: Include valprint.h.
(get_register): Use get_user_print_options.
(mi_cmd_data_evaluate_expression): Likewise.
(mi_cmd_data_read_memory): Use get_formatted_print_options.
* mi/mi-cmd-stack.c: Include valprint.h.
(list_args_or_locals): Use get_raw_print_options.
* m2-valprint.c (print_function_pointer_address): Add addressprint
argument.
(m2_print_long_set): Remove format, pretty arguments.
(m2_print_unbounded_array): Remove format, deref_ref, pretty
arguments; add options. Update.
(print_unpacked_pointer): Remove format argument; add options.
Now static. Update.
(print_variable_at_address): Remove format, deref_ref, pretty
arguments; add options. Update.
(m2_print_array_contents): Likewise.
(m2_val_print): Likewise.
* m2-lang.h (m2_val_print): Update.
* m2-lang.c (m2_printstr): Add options argument. Update.
* language.h (struct value_print_options): Declare.
(struct language_defn) <la_printstr>: Add options argument.
<la_val_print>: Remove format, deref_ref, pretty argument; add
options.
<la_value_print>: Remove format, pretty arguments; add options.
<la_print_array_index>: Likewise.
(LA_VAL_PRINT, LA_VALUE_PRINT, LA_PRINT_STRING,
LA_PRINT_ARRAY_INDEX): Update.
(default_print_array_index): Update.
* language.c (default_print_array_index): Remove format, pretty
arguments; add options. Update.
(unk_lang_printstr): Add options argument.
(unk_lang_val_print): Remove format, deref_ref, pretty arguments;
add options.
(unk_lang_value_print): Remove format, pretty arguments; add
options.
* jv-valprint.c (java_value_print): Remove format, pretty
arguments; add options. Update.
(java_print_value_fields): Likewise.
(java_val_print): Remove format, deref_ref, pretty arguments; add
options. Update.
* jv-lang.h (java_val_print, java_value_print): Declare.
* infcmd.c: Include valprint.h.
(print_return_value): Use get_raw_print_options.
(default_print_registers_info): Use get_user_print_options,
get_formatted_print_options.
(registers_info): Use get_formatted_print_options.
* gdbtypes.h (struct value_print_options): Declare.
(print_scalar_formatted): Update.
* f-valprint.c (f77_print_array_1): Remove format, deref_ref,
pretty arguments; add options. Update.
(f77_print_array): Likewise.
(f_val_print): Likewise.
* f-lang.h (f_val_print): Update.
* f-lang.c (f_printstr): Add options argument. Update.
(c_value_print): Update declaration.
* expprint.c: Include valprint.h.
(print_subexp_standard): Use get_raw_print_options,
get_user_print_options.
* eval.c: Include valprint.h.
(objectprint): Don't declare.
(evaluate_subexp_standard): Use get_user_print_options.
* cp-valprint.c (vtblprint, objectprint, static_field_print):
Remove.
(cp_print_value_fields): Remove format, pretty arguments; add
options. Update.
(cp_print_value): Likewise.
(cp_print_static_field): Likewise.
(_initialize_cp_valprint): Use user_print_options. Update.
* c-valprint.c (print_function_pointer_address): Add addressprint
argument.
(c_val_print): Remove format, deref_ref, pretty arguments; add
options. Update.
(c_value_print): Add options argument. Update.
* c-lang.h (c_val_print, c_value_print, c_printstr): Update.
(vtblprint, static_field_print): Don't declare.
(cp_print_value_fields): Update.
* c-lang.c (c_printstr): Add options argument. Update.
* breakpoint.c: Include valprint.h.
(addressprint): Don't declare.
(watchpoint_value_print): Use get_user_print_options.
(print_one_breakpoint_location): Likewise.
(breakpoint_1, print_it_catch_fork, print_it_catch_vfork, mention,
print_exception_catchpoint): Likewise.
* auxv.c (fprint_target_auxv): Don't declare addressprint. Use
get_user_print_options.
* ada-valprint.c (struct ada_val_print_args): Remove format,
deref_ref, and pretty; add options.
(print_optional_low_bound): Add options argument.
(val_print_packed_array_elements): Remove format and pretty
arguments; add options. Update.
(printstr): Add options argument. Update.
(ada_printstr): Likewise.
(ada_val_print): Remove format, deref_ref, pretty arguments; add
options argument. Update.
(ada_val_print_stub): Update.
(ada_val_print_array): Remove format, deref_ref, pretty arguments;
add options. Update.
(ada_val_print_1): Likewise.
(print_variant_part): Likewise.
(ada_value_print): Remove format, pretty arguments; add options.
Update.
(print_record): Likewise.
(print_field_values): Likewise.
* ada-lang.h (ada_val_print, ada_value_print, ada_printstr):
Update.
* ada-lang.c (ada_print_array_index): Add options argument; remove
format and pretty arguments.
(print_one_exception): Use get_user_print_options.
gdb/testsuite
* gdb.base/exprs.exp (test_expr): Add enum formatting tests.
2008-10-28 17:19:58 +00:00
|
|
|
get_user_print_options (&opts);
|
|
|
|
opts.deref_ref = 0;
|
|
|
|
|
2008-10-16 14:46:20 +00:00
|
|
|
stb = mem_fileopen ();
|
|
|
|
old_chain = make_cleanup_ui_file_delete (stb);
|
|
|
|
|
|
|
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
|
|
|
{
|
gdb
* varobj.c (value_get_print_value): Include valprint.h.
(value_get_print_value): Use get_formatted_print_options.
* value.h (struct value_print_options): Declare.
(value_print, val_print, common_val_print, val_print_string):
Update.
* value.c: Include valprint.h.
(show_values): Use get_user_print_options.
(show_convenience): Likewise.
* valprint.h (prettyprint_arrays, prettyprint_structs): Don't
declare.
(struct value_print_options): New type.
(vtblprint, unionprint, addressprint, objectprint, print_max,
inspect_it, repeat_count_threshold, output_format,
stop_print_at_null): Don't declare.
(user_print_options, get_user_print_options,
get_raw_print_options, get_formatted_print_options): Declare.
(print_array_indexes_p): Don't declare.
(maybe_print_array_index, val_print_array_elements): Update.
* valprint.c (print_max): Remove.
(user_print_options): New global.
(get_user_print_options, get_raw_print_options,
get_formatted_print_options): New functions.
(print_array_indexes, repeat_count_threshold, stop_print_at_null,
prettyprint_structs, prettyprint_arrays, unionprint,
addressprint): Remove.
(val_print): Remove format, deref_ref, pretty arguments; add
options. Update.
(common_val_print): Likewise.
(print_array_indexes_p): Remove.
(maybe_print_array_index): Remove format, pretty arguments; add
options. Update.
(val_print_array_elements): Remove format, deref_ref, pretty
arguments; add options. Update.
(val_print_string): Add options argument. Update.
(_initialize_valprint): Use user_print_options.
(output_format): Remove.
(set_output_radix_1): Use user_print_options.
* typeprint.c: Include valprint.h.
(objectprint): Don't declare.
(whatis_exp): Use get_user_print_options.
* tui/tui-regs.c: Include valprint.h.
(tui_register_format): Use get_formatted_print_options.
* tracepoint.c: Include valprint.h.
(addressprint): Don't declare.
(trace_mention): Use get_user_print_options.
(tracepoints_info): Likewise.
* stack.c (print_frame_args): Use get_raw_print_options.
(print_frame_info): Use get_user_print_options.
(print_frame): Likewise.
* sh64-tdep.c: Include valprint.h
(sh64_do_register): Use get_formatted_print_options.
* scm-valprint.c (scm_inferior_print): Remove format, deref_ref,
pretty arguments; add options.
(scm_scmlist_print): Likewise. Update.
(scm_scmval_print): Likewise.
(scm_val_print): Likewise.
(scm_value_print): Remove format, pretty arguments; add options.
Update.
* scm-lang.h (scm_value_print, scm_val_print, scm_scmval_print):
Update.
* scm-lang.c (scm_printstr): Add options argument.
* python/python-value.c: Include valprint.h.
(valpy_str): Use get_user_print_options.
* printcmd.c: Include valprint.h.
(addressprint): Don't declare.
(inspect_it): Remove.
(print_formatted): Remove format option; add options. Update.
(print_scalar_formatted): Likewise.
(print_address_demangle): Use get_user_print_options.
(do_examine): Use get_formatted_print_options.
(print_command_1): Likewise.
(output_command): Use get_formatted_print_options.
(do_one_display): Likewise.
(print_variable_value): Use get_user_print_options.
* p-valprint.c (pascal_val_print): Remove format, deref_ref,
pretty arguments; add options. Update.
(pascal_value_print): Remove format, pretty arguments; add
options. Update.
(vtblprint, objectprint): Don't declare.
(pascal_static_field_print): Remove.
(pascal_object_print_value_fields): Remove format, pretty
arguments; add options. Update.
(pascal_object_print_static_field): Likewise.
(_initialize_pascal_valprint): Use user_print_options. Update.
* p-lang.h (pascal_val_print, pascal_value_print,
pascal_printstr, pascal_object_print_value_fields): Update.
(vtblprint, static_field_print): Don't declare.
* p-lang.c (pascal_printstr): Add options argument. Update.
* objc-lang.c (objc_printstr): Add options argument. Update.
* mt-tdep.c: Include valprint.h.
(mt_registers_info): Use get_raw_print_options.
* mips-tdep.c: Include valprint.h.
(mips_print_fp_register): Use get_formatted_print_options.
(mips_print_register): Likewise.
* mi/mi-main.c: Include valprint.h.
(get_register): Use get_user_print_options.
(mi_cmd_data_evaluate_expression): Likewise.
(mi_cmd_data_read_memory): Use get_formatted_print_options.
* mi/mi-cmd-stack.c: Include valprint.h.
(list_args_or_locals): Use get_raw_print_options.
* m2-valprint.c (print_function_pointer_address): Add addressprint
argument.
(m2_print_long_set): Remove format, pretty arguments.
(m2_print_unbounded_array): Remove format, deref_ref, pretty
arguments; add options. Update.
(print_unpacked_pointer): Remove format argument; add options.
Now static. Update.
(print_variable_at_address): Remove format, deref_ref, pretty
arguments; add options. Update.
(m2_print_array_contents): Likewise.
(m2_val_print): Likewise.
* m2-lang.h (m2_val_print): Update.
* m2-lang.c (m2_printstr): Add options argument. Update.
* language.h (struct value_print_options): Declare.
(struct language_defn) <la_printstr>: Add options argument.
<la_val_print>: Remove format, deref_ref, pretty argument; add
options.
<la_value_print>: Remove format, pretty arguments; add options.
<la_print_array_index>: Likewise.
(LA_VAL_PRINT, LA_VALUE_PRINT, LA_PRINT_STRING,
LA_PRINT_ARRAY_INDEX): Update.
(default_print_array_index): Update.
* language.c (default_print_array_index): Remove format, pretty
arguments; add options. Update.
(unk_lang_printstr): Add options argument.
(unk_lang_val_print): Remove format, deref_ref, pretty arguments;
add options.
(unk_lang_value_print): Remove format, pretty arguments; add
options.
* jv-valprint.c (java_value_print): Remove format, pretty
arguments; add options. Update.
(java_print_value_fields): Likewise.
(java_val_print): Remove format, deref_ref, pretty arguments; add
options. Update.
* jv-lang.h (java_val_print, java_value_print): Declare.
* infcmd.c: Include valprint.h.
(print_return_value): Use get_raw_print_options.
(default_print_registers_info): Use get_user_print_options,
get_formatted_print_options.
(registers_info): Use get_formatted_print_options.
* gdbtypes.h (struct value_print_options): Declare.
(print_scalar_formatted): Update.
* f-valprint.c (f77_print_array_1): Remove format, deref_ref,
pretty arguments; add options. Update.
(f77_print_array): Likewise.
(f_val_print): Likewise.
* f-lang.h (f_val_print): Update.
* f-lang.c (f_printstr): Add options argument. Update.
(c_value_print): Update declaration.
* expprint.c: Include valprint.h.
(print_subexp_standard): Use get_raw_print_options,
get_user_print_options.
* eval.c: Include valprint.h.
(objectprint): Don't declare.
(evaluate_subexp_standard): Use get_user_print_options.
* cp-valprint.c (vtblprint, objectprint, static_field_print):
Remove.
(cp_print_value_fields): Remove format, pretty arguments; add
options. Update.
(cp_print_value): Likewise.
(cp_print_static_field): Likewise.
(_initialize_cp_valprint): Use user_print_options. Update.
* c-valprint.c (print_function_pointer_address): Add addressprint
argument.
(c_val_print): Remove format, deref_ref, pretty arguments; add
options. Update.
(c_value_print): Add options argument. Update.
* c-lang.h (c_val_print, c_value_print, c_printstr): Update.
(vtblprint, static_field_print): Don't declare.
(cp_print_value_fields): Update.
* c-lang.c (c_printstr): Add options argument. Update.
* breakpoint.c: Include valprint.h.
(addressprint): Don't declare.
(watchpoint_value_print): Use get_user_print_options.
(print_one_breakpoint_location): Likewise.
(breakpoint_1, print_it_catch_fork, print_it_catch_vfork, mention,
print_exception_catchpoint): Likewise.
* auxv.c (fprint_target_auxv): Don't declare addressprint. Use
get_user_print_options.
* ada-valprint.c (struct ada_val_print_args): Remove format,
deref_ref, and pretty; add options.
(print_optional_low_bound): Add options argument.
(val_print_packed_array_elements): Remove format and pretty
arguments; add options. Update.
(printstr): Add options argument. Update.
(ada_printstr): Likewise.
(ada_val_print): Remove format, deref_ref, pretty arguments; add
options argument. Update.
(ada_val_print_stub): Update.
(ada_val_print_array): Remove format, deref_ref, pretty arguments;
add options. Update.
(ada_val_print_1): Likewise.
(print_variant_part): Likewise.
(ada_value_print): Remove format, pretty arguments; add options.
Update.
(print_record): Likewise.
(print_field_values): Likewise.
* ada-lang.h (ada_val_print, ada_value_print, ada_printstr):
Update.
* ada-lang.c (ada_print_array_index): Add options argument; remove
format and pretty arguments.
(print_one_exception): Use get_user_print_options.
gdb/testsuite
* gdb.base/exprs.exp (test_expr): Add enum formatting tests.
2008-10-28 17:19:58 +00:00
|
|
|
common_val_print (((value_object *) self)->value, stb, 0,
|
|
|
|
&opts, current_language);
|
2008-10-16 14:46:20 +00:00
|
|
|
s = ui_file_xstrdup (stb, &dummy);
|
|
|
|
}
|
|
|
|
GDB_PY_HANDLE_EXCEPTION (except);
|
|
|
|
|
|
|
|
do_cleanups (old_chain);
|
|
|
|
|
|
|
|
result = PyUnicode_Decode (s, strlen (s), host_charset (), NULL);
|
|
|
|
xfree (s);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum valpy_opcode
|
|
|
|
{
|
|
|
|
VALPY_ADD,
|
|
|
|
VALPY_SUB,
|
|
|
|
VALPY_MUL,
|
|
|
|
VALPY_DIV,
|
|
|
|
VALPY_REM,
|
2009-02-04 21:55:40 +00:00
|
|
|
VALPY_POW,
|
|
|
|
VALPY_LSH,
|
|
|
|
VALPY_RSH,
|
|
|
|
VALPY_BITAND,
|
|
|
|
VALPY_BITOR,
|
|
|
|
VALPY_BITXOR
|
2008-10-16 14:46:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* If TYPE is a reference, return the target; otherwise return TYPE. */
|
|
|
|
#define STRIP_REFERENCE(TYPE) \
|
|
|
|
((TYPE_CODE (TYPE) == TYPE_CODE_REF) ? (TYPE_TARGET_TYPE (TYPE)) : (TYPE))
|
|
|
|
|
|
|
|
/* Returns a value object which is the result of applying the operation
|
|
|
|
specified by OPCODE to the given arguments. */
|
|
|
|
static PyObject *
|
|
|
|
valpy_binop (enum valpy_opcode opcode, PyObject *self, PyObject *other)
|
|
|
|
{
|
|
|
|
struct value *res_val = NULL; /* Initialize to appease gcc warning. */
|
|
|
|
volatile struct gdb_exception except;
|
|
|
|
|
|
|
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
|
|
|
{
|
|
|
|
struct value *arg1, *arg2;
|
|
|
|
|
|
|
|
/* If the gdb.Value object is the second operand, then it will be passed
|
|
|
|
to us as the OTHER argument, and SELF will be an entirely different
|
|
|
|
kind of object, altogether. Because of this, we can't assume self is
|
|
|
|
a gdb.Value object and need to convert it from python as well. */
|
|
|
|
arg1 = convert_value_from_python (self);
|
2009-02-04 21:55:40 +00:00
|
|
|
if (arg1 == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2008-10-16 14:46:20 +00:00
|
|
|
arg2 = convert_value_from_python (other);
|
2009-02-04 21:55:40 +00:00
|
|
|
if (arg2 == NULL)
|
|
|
|
return NULL;
|
2008-10-16 14:46:20 +00:00
|
|
|
|
|
|
|
switch (opcode)
|
|
|
|
{
|
|
|
|
case VALPY_ADD:
|
|
|
|
{
|
|
|
|
struct type *ltype = value_type (arg1);
|
|
|
|
struct type *rtype = value_type (arg2);
|
|
|
|
|
|
|
|
CHECK_TYPEDEF (ltype);
|
|
|
|
ltype = STRIP_REFERENCE (ltype);
|
|
|
|
CHECK_TYPEDEF (rtype);
|
|
|
|
rtype = STRIP_REFERENCE (rtype);
|
|
|
|
|
|
|
|
if (TYPE_CODE (ltype) == TYPE_CODE_PTR)
|
|
|
|
res_val = value_ptradd (arg1, arg2);
|
|
|
|
else if (TYPE_CODE (rtype) == TYPE_CODE_PTR)
|
|
|
|
res_val = value_ptradd (arg2, arg1);
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (TYPE_CODE (ltype) == TYPE_CODE_PTR)
|
|
|
|
{
|
|
|
|
if (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
|
|
|
|
res_val = value_ptrsub (arg1, arg2);
|
|
|
|
}
|
|
|
|
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 21:55:40 +00: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 14:46:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
GDB_PY_HANDLE_EXCEPTION (except);
|
|
|
|
|
|
|
|
return value_to_value_object (res_val);
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
struct value *val = NULL;
|
|
|
|
volatile struct gdb_exception except;
|
|
|
|
|
|
|
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
|
|
|
{
|
|
|
|
val = value_neg (((value_object *) self)->value);
|
|
|
|
}
|
|
|
|
GDB_PY_HANDLE_EXCEPTION (except);
|
|
|
|
|
|
|
|
return value_to_value_object (val);
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
valpy_positive (PyObject *self)
|
|
|
|
{
|
|
|
|
struct value *copy = value_copy (((value_object *) self)->value);
|
|
|
|
|
|
|
|
return value_to_value_object (copy);
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
valpy_absolute (PyObject *self)
|
|
|
|
{
|
|
|
|
if (value_less (((value_object *) self)->value,
|
|
|
|
value_from_longest (builtin_type_int8, 0)))
|
|
|
|
return valpy_negative (self);
|
|
|
|
else
|
|
|
|
return valpy_positive (self);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Implements boolean evaluation of gdb.Value. */
|
|
|
|
static int
|
|
|
|
valpy_nonzero (PyObject *self)
|
|
|
|
{
|
|
|
|
value_object *self_value = (value_object *) self;
|
|
|
|
struct type *type;
|
|
|
|
|
|
|
|
type = check_typedef (value_type (self_value->value));
|
|
|
|
|
|
|
|
if (is_integral_type (type) || TYPE_CODE (type) == TYPE_CODE_PTR)
|
|
|
|
return !!value_as_long (self_value->value);
|
|
|
|
else if (TYPE_CODE (type) == TYPE_CODE_FLT)
|
|
|
|
return value_as_double (self_value->value) != 0;
|
|
|
|
else if (TYPE_CODE (type) == TYPE_CODE_DECFLOAT)
|
|
|
|
return !decimal_is_zero (value_contents (self_value->value),
|
|
|
|
TYPE_LENGTH (type));
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PyErr_SetString (PyExc_TypeError, _("Attempted truth testing on invalid "
|
|
|
|
"gdb.Value type."));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-04 21:55:40 +00:00
|
|
|
/* Implements ~ for value objects. */
|
2008-10-16 14:46:20 +00:00
|
|
|
static PyObject *
|
2009-02-04 21:55:40 +00:00
|
|
|
valpy_invert (PyObject *self)
|
2008-10-16 14:46:20 +00:00
|
|
|
{
|
2009-02-04 21:55:40 +00:00
|
|
|
struct value *val = NULL;
|
2008-10-16 14:46:20 +00:00
|
|
|
volatile struct gdb_exception except;
|
|
|
|
|
2009-02-04 21:55:40 +00:00
|
|
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
2008-10-16 14:46:20 +00:00
|
|
|
{
|
2009-02-04 21:55:40 +00:00
|
|
|
val = value_complement (((value_object *) self)->value);
|
|
|
|
}
|
|
|
|
GDB_PY_HANDLE_EXCEPTION (except);
|
2008-10-16 14:46:20 +00:00
|
|
|
|
2009-02-04 21:55:40 +00:00
|
|
|
return value_to_value_object (val);
|
|
|
|
}
|
2008-10-16 14:46:20 +00:00
|
|
|
|
2009-02-04 21:55:40 +00:00
|
|
|
/* Implements left shift for value objects. */
|
|
|
|
static PyObject *
|
|
|
|
valpy_lsh (PyObject *self, PyObject *other)
|
|
|
|
{
|
|
|
|
return valpy_binop (VALPY_LSH, self, other);
|
|
|
|
}
|
2008-10-16 14:46:20 +00:00
|
|
|
|
2009-02-04 21:55:40 +00:00
|
|
|
/* Implements right shift for value objects. */
|
|
|
|
static PyObject *
|
|
|
|
valpy_rsh (PyObject *self, PyObject *other)
|
|
|
|
{
|
|
|
|
return valpy_binop (VALPY_RSH, self, other);
|
|
|
|
}
|
2008-10-16 14:46:20 +00:00
|
|
|
|
2009-02-04 21:55:40 +00:00
|
|
|
/* Implements bitwise and for value objects. */
|
|
|
|
static PyObject *
|
|
|
|
valpy_and (PyObject *self, PyObject *other)
|
|
|
|
{
|
|
|
|
return valpy_binop (VALPY_BITAND, self, other);
|
|
|
|
}
|
2008-10-16 14:46:20 +00:00
|
|
|
|
2009-02-04 21:55:40 +00:00
|
|
|
/* Implements bitwise or for value objects. */
|
|
|
|
static PyObject *
|
|
|
|
valpy_or (PyObject *self, PyObject *other)
|
|
|
|
{
|
|
|
|
return valpy_binop (VALPY_BITOR, self, other);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Implements bitwise xor for value objects. */
|
|
|
|
static PyObject *
|
|
|
|
valpy_xor (PyObject *self, PyObject *other)
|
|
|
|
{
|
|
|
|
return valpy_binop (VALPY_BITXOR, self, other);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Implements comparison operations for value objects. */
|
|
|
|
static PyObject *
|
|
|
|
valpy_richcompare (PyObject *self, PyObject *other, int op)
|
|
|
|
{
|
|
|
|
int result = 0;
|
|
|
|
struct value *value_other;
|
|
|
|
volatile struct gdb_exception except;
|
|
|
|
|
|
|
|
if (other == Py_None)
|
2008-10-16 14:46:20 +00:00
|
|
|
/* Comparing with None is special. From what I can tell, in Python
|
|
|
|
None is smaller than anything else. */
|
|
|
|
switch (op) {
|
|
|
|
case Py_LT:
|
|
|
|
case Py_LE:
|
|
|
|
case Py_EQ:
|
|
|
|
Py_RETURN_FALSE;
|
|
|
|
case Py_NE:
|
|
|
|
case Py_GT:
|
|
|
|
case Py_GE:
|
|
|
|
Py_RETURN_TRUE;
|
|
|
|
default:
|
|
|
|
/* Can't happen. */
|
|
|
|
PyErr_SetString (PyExc_NotImplementedError,
|
|
|
|
"Invalid operation on gdb.Value.");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
|
|
|
{
|
2009-02-04 21:55:40 +00:00
|
|
|
value_other = convert_value_from_python (other);
|
|
|
|
if (value_other == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2008-10-16 14:46:20 +00:00
|
|
|
switch (op) {
|
|
|
|
case Py_LT:
|
|
|
|
result = value_less (((value_object *) self)->value, value_other);
|
|
|
|
break;
|
|
|
|
case Py_LE:
|
|
|
|
result = value_less (((value_object *) self)->value, value_other)
|
|
|
|
|| value_equal (((value_object *) self)->value, value_other);
|
|
|
|
break;
|
|
|
|
case Py_EQ:
|
|
|
|
result = value_equal (((value_object *) self)->value, value_other);
|
|
|
|
break;
|
|
|
|
case Py_NE:
|
|
|
|
result = !value_equal (((value_object *) self)->value, value_other);
|
|
|
|
break;
|
|
|
|
case Py_GT:
|
|
|
|
result = value_less (value_other, ((value_object *) self)->value);
|
|
|
|
break;
|
|
|
|
case Py_GE:
|
|
|
|
result = value_less (value_other, ((value_object *) self)->value)
|
|
|
|
|| value_equal (((value_object *) self)->value, value_other);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* Can't happen. */
|
|
|
|
PyErr_SetString (PyExc_NotImplementedError,
|
|
|
|
"Invalid operation on gdb.Value.");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
GDB_PY_HANDLE_EXCEPTION (except);
|
|
|
|
|
|
|
|
if (result == 1)
|
|
|
|
Py_RETURN_TRUE;
|
|
|
|
|
|
|
|
Py_RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2009-02-04 21:55:40 +00:00
|
|
|
/* Helper function to determine if a type is "int-like". */
|
|
|
|
static int
|
|
|
|
is_intlike (struct type *type, int ptr_ok)
|
|
|
|
{
|
|
|
|
CHECK_TYPEDEF (type);
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
|
|
|
|
CHECK_TYPEDEF (type);
|
|
|
|
if (!is_intlike (type, 0))
|
|
|
|
{
|
|
|
|
PyErr_SetString (PyExc_RuntimeError, "cannot convert value to int");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
|
|
|
{
|
|
|
|
l = value_as_long (value);
|
|
|
|
}
|
|
|
|
GDB_PY_HANDLE_EXCEPTION (except);
|
|
|
|
|
|
|
|
return PyInt_FromLong (l);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
|
|
|
|
if (!is_intlike (type, 1))
|
|
|
|
{
|
|
|
|
PyErr_SetString (PyExc_RuntimeError, "cannot convert value to long");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
|
|
|
{
|
|
|
|
l = value_as_long (value);
|
|
|
|
}
|
|
|
|
GDB_PY_HANDLE_EXCEPTION (except);
|
|
|
|
|
|
|
|
return PyLong_FromLong (l);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
|
|
|
|
CHECK_TYPEDEF (type);
|
|
|
|
if (TYPE_CODE (type) != TYPE_CODE_FLT)
|
|
|
|
{
|
|
|
|
PyErr_SetString (PyExc_RuntimeError, "cannot convert value to float");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
|
|
|
{
|
|
|
|
d = value_as_double (value);
|
|
|
|
}
|
|
|
|
GDB_PY_HANDLE_EXCEPTION (except);
|
|
|
|
|
|
|
|
return PyFloat_FromDouble (d);
|
|
|
|
}
|
|
|
|
|
2008-10-16 14:46:20 +00:00
|
|
|
/* Returns an object for a value which is released from the all_values chain,
|
|
|
|
so its lifetime is not bound to the execution of a command. */
|
|
|
|
PyObject *
|
|
|
|
value_to_value_object (struct value *val)
|
|
|
|
{
|
|
|
|
value_object *val_obj;
|
|
|
|
|
|
|
|
val_obj = PyObject_New (value_object, &value_object_type);
|
|
|
|
if (val_obj != NULL)
|
|
|
|
{
|
|
|
|
val_obj->value = val;
|
2008-10-23 17:14:20 +00:00
|
|
|
val_obj->owned_by_gdb = 0;
|
2008-10-16 14:46:20 +00:00
|
|
|
release_value (val);
|
|
|
|
value_prepend_to_list (&values_in_python, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (PyObject *) val_obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Try to convert a Python value to a gdb value. If the value cannot
|
2009-02-04 21:55:40 +00:00
|
|
|
be converted, set a Python exception and return NULL. */
|
2008-10-16 14:46:20 +00:00
|
|
|
|
|
|
|
struct value *
|
|
|
|
convert_value_from_python (PyObject *obj)
|
|
|
|
{
|
|
|
|
struct value *value = NULL; /* -Wall */
|
|
|
|
PyObject *target_str, *unicode_str;
|
|
|
|
struct cleanup *old;
|
2009-02-04 21:55:40 +00:00
|
|
|
volatile struct gdb_exception except;
|
|
|
|
int cmp;
|
2008-10-16 14:46:20 +00:00
|
|
|
|
2009-02-04 21:55:40 +00:00
|
|
|
gdb_assert (obj != NULL);
|
2008-10-16 14:46:20 +00:00
|
|
|
|
2009-02-04 21:55:40 +00:00
|
|
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
2008-10-16 14:46:20 +00:00
|
|
|
{
|
2009-02-04 21:55:40 +00:00
|
|
|
if (PyBool_Check (obj))
|
|
|
|
{
|
|
|
|
cmp = PyObject_IsTrue (obj);
|
|
|
|
if (cmp >= 0)
|
|
|
|
value = value_from_longest (builtin_type_pybool, cmp);
|
|
|
|
}
|
|
|
|
else if (PyInt_Check (obj))
|
|
|
|
{
|
|
|
|
long l = PyInt_AsLong (obj);
|
2008-10-16 14:46:20 +00:00
|
|
|
|
2009-02-04 21:55:40 +00:00
|
|
|
if (! PyErr_Occurred ())
|
|
|
|
value = value_from_longest (builtin_type_pyint, l);
|
|
|
|
}
|
|
|
|
else if (PyLong_Check (obj))
|
|
|
|
{
|
|
|
|
LONGEST l = PyLong_AsLongLong (obj);
|
2008-10-16 14:46:20 +00:00
|
|
|
|
2009-02-04 21:55:40 +00:00
|
|
|
if (! PyErr_Occurred ())
|
|
|
|
value = value_from_longest (builtin_type_pylong, l);
|
|
|
|
}
|
|
|
|
else if (PyFloat_Check (obj))
|
|
|
|
{
|
|
|
|
double d = PyFloat_AsDouble (obj);
|
2008-10-16 14:46:20 +00:00
|
|
|
|
2009-02-04 21:55:40 +00:00
|
|
|
if (! PyErr_Occurred ())
|
|
|
|
value = value_from_double (builtin_type_pyfloat, d);
|
|
|
|
}
|
|
|
|
else if (gdbpy_is_string (obj))
|
|
|
|
{
|
|
|
|
char *s;
|
|
|
|
|
|
|
|
s = python_string_to_target_string (obj);
|
|
|
|
if (s != NULL)
|
|
|
|
{
|
|
|
|
old = make_cleanup (xfree, s);
|
|
|
|
value = value_from_string (s);
|
|
|
|
do_cleanups (old);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (PyObject_TypeCheck (obj, &value_object_type))
|
|
|
|
value = ((value_object *) obj)->value;
|
|
|
|
else
|
|
|
|
PyErr_Format (PyExc_TypeError, _("Could not convert Python object: %s"),
|
|
|
|
PyString_AsString (PyObject_Str (obj)));
|
|
|
|
}
|
|
|
|
if (except.reason < 0)
|
|
|
|
{
|
|
|
|
PyErr_Format (except.reason == RETURN_QUIT
|
|
|
|
? PyExc_KeyboardInterrupt : PyExc_RuntimeError,
|
|
|
|
"%s", except.message);
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-10-16 14:46:20 +00:00
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns value object in the ARGth position in GDB's history. */
|
|
|
|
PyObject *
|
2009-02-04 21:55:40 +00:00
|
|
|
gdbpy_history (PyObject *self, PyObject *args)
|
2008-10-16 14:46:20 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct value *res_val = NULL; /* Initialize to appease gcc warning. */
|
|
|
|
volatile struct gdb_exception except;
|
|
|
|
|
|
|
|
if (!PyArg_ParseTuple (args, "i", &i))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
|
|
|
{
|
|
|
|
res_val = access_value_history (i);
|
|
|
|
}
|
|
|
|
GDB_PY_HANDLE_EXCEPTION (except);
|
|
|
|
|
|
|
|
return value_to_value_object (res_val);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gdbpy_initialize_values (void)
|
|
|
|
{
|
|
|
|
if (PyType_Ready (&value_object_type) < 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Py_INCREF (&value_object_type);
|
|
|
|
PyModule_AddObject (gdb_module, "Value", (PyObject *) &value_object_type);
|
|
|
|
|
|
|
|
values_in_python = NULL;
|
|
|
|
}
|
|
|
|
|
* python/python-value.c (value_object_methods)
(value_object_as_number, value_object_as_mapping): Move to bottom
of file.
(valpy_dealloc, valpy_new, valpy_length, valpy_getitem)
(valpy_setitem, valpy_str, valpy_add, valpy_subtract)
(valpy_multiply, valpy_divide, valpy_remainder, valpy_power)
(valpy_negative, valpy_positive, valpy_absolute, valpy_nonzero)
(valpy_richcompare, valpy_dereference): Don't forward-declare.
(valpy_length) [HAVE_LIBPYTHON2_4]: Change return type to `int'.
2008-10-19 20:25:00 +00:00
|
|
|
static PyMethodDef value_object_methods[] = {
|
2009-02-04 21:55:40 +00:00
|
|
|
{ "address", valpy_address, METH_NOARGS, "Return the address of the value." },
|
* python/python-value.c (value_object_methods)
(value_object_as_number, value_object_as_mapping): Move to bottom
of file.
(valpy_dealloc, valpy_new, valpy_length, valpy_getitem)
(valpy_setitem, valpy_str, valpy_add, valpy_subtract)
(valpy_multiply, valpy_divide, valpy_remainder, valpy_power)
(valpy_negative, valpy_positive, valpy_absolute, valpy_nonzero)
(valpy_richcompare, valpy_dereference): Don't forward-declare.
(valpy_length) [HAVE_LIBPYTHON2_4]: Change return type to `int'.
2008-10-19 20:25:00 +00:00
|
|
|
{ "dereference", valpy_dereference, METH_NOARGS, "Dereferences the value." },
|
|
|
|
{NULL} /* Sentinel */
|
|
|
|
};
|
|
|
|
|
|
|
|
static PyNumberMethods value_object_as_number = {
|
|
|
|
valpy_add,
|
|
|
|
valpy_subtract,
|
|
|
|
valpy_multiply,
|
|
|
|
valpy_divide,
|
|
|
|
valpy_remainder,
|
|
|
|
NULL, /* nb_divmod */
|
|
|
|
valpy_power, /* nb_power */
|
|
|
|
valpy_negative, /* nb_negative */
|
|
|
|
valpy_positive, /* nb_positive */
|
|
|
|
valpy_absolute, /* nb_absolute */
|
2009-02-04 21:55:40 +00:00
|
|
|
valpy_nonzero, /* nb_nonzero */
|
|
|
|
valpy_invert, /* nb_invert */
|
|
|
|
valpy_lsh, /* nb_lshift */
|
|
|
|
valpy_rsh, /* nb_rshift */
|
|
|
|
valpy_and, /* nb_and */
|
|
|
|
valpy_xor, /* nb_xor */
|
|
|
|
valpy_or, /* nb_or */
|
|
|
|
NULL, /* nb_coerce */
|
|
|
|
valpy_int, /* nb_int */
|
|
|
|
valpy_long, /* nb_long */
|
|
|
|
valpy_float, /* nb_float */
|
|
|
|
NULL, /* nb_oct */
|
|
|
|
NULL /* nb_hex */
|
* python/python-value.c (value_object_methods)
(value_object_as_number, value_object_as_mapping): Move to bottom
of file.
(valpy_dealloc, valpy_new, valpy_length, valpy_getitem)
(valpy_setitem, valpy_str, valpy_add, valpy_subtract)
(valpy_multiply, valpy_divide, valpy_remainder, valpy_power)
(valpy_negative, valpy_positive, valpy_absolute, valpy_nonzero)
(valpy_richcompare, valpy_dereference): Don't forward-declare.
(valpy_length) [HAVE_LIBPYTHON2_4]: Change return type to `int'.
2008-10-19 20:25:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static PyMappingMethods value_object_as_mapping = {
|
|
|
|
valpy_length,
|
|
|
|
valpy_getitem,
|
|
|
|
valpy_setitem
|
|
|
|
};
|
|
|
|
|
|
|
|
PyTypeObject value_object_type = {
|
|
|
|
PyObject_HEAD_INIT (NULL)
|
|
|
|
0, /*ob_size*/
|
|
|
|
"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*/
|
|
|
|
0, /*tp_hash */
|
|
|
|
0, /*tp_call*/
|
|
|
|
valpy_str, /*tp_str*/
|
|
|
|
0, /*tp_getattro*/
|
|
|
|
0, /*tp_setattro*/
|
|
|
|
0, /*tp_as_buffer*/
|
|
|
|
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_CHECKTYPES, /*tp_flags*/
|
|
|
|
"GDB value object", /* tp_doc */
|
|
|
|
0, /* tp_traverse */
|
|
|
|
0, /* tp_clear */
|
|
|
|
valpy_richcompare, /* tp_richcompare */
|
|
|
|
0, /* tp_weaklistoffset */
|
|
|
|
0, /* tp_iter */
|
|
|
|
0, /* tp_iternext */
|
2009-02-04 21:55:40 +00:00
|
|
|
value_object_methods, /* tp_methods */
|
|
|
|
0, /* tp_members */
|
|
|
|
0, /* tp_getset */
|
|
|
|
0, /* tp_base */
|
|
|
|
0, /* tp_dict */
|
|
|
|
0, /* tp_descr_get */
|
|
|
|
0, /* tp_descr_set */
|
|
|
|
0, /* tp_dictoffset */
|
|
|
|
0, /* tp_init */
|
|
|
|
0, /* tp_alloc */
|
|
|
|
valpy_new /* tp_new */
|
* python/python-value.c (value_object_methods)
(value_object_as_number, value_object_as_mapping): Move to bottom
of file.
(valpy_dealloc, valpy_new, valpy_length, valpy_getitem)
(valpy_setitem, valpy_str, valpy_add, valpy_subtract)
(valpy_multiply, valpy_divide, valpy_remainder, valpy_power)
(valpy_negative, valpy_positive, valpy_absolute, valpy_nonzero)
(valpy_richcompare, valpy_dereference): Don't forward-declare.
(valpy_length) [HAVE_LIBPYTHON2_4]: Change return type to `int'.
2008-10-19 20:25:00 +00:00
|
|
|
};
|
|
|
|
|
2008-10-16 14:46:20 +00:00
|
|
|
#endif /* HAVE_PYTHON */
|