binutils-gdb/gdb/testsuite/gdb.python/py-value.c

121 lines
2.2 KiB
C
Raw Normal View History

/* This testcase is part of GDB, the GNU debugger.
Copyright 2008-2014 Free Software Foundation, Inc.
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 <stdio.h>
#include <stdlib.h>
#include <string.h>
struct s
{
int a;
int b;
};
union u
{
int a;
float b;
};
gdb/ 2009-02-04 Tom Tromey <tromey@redhat.com> Thiago Jung Bauermann <bauerman@br.ibm.com> Phil Muldoon <pmuldoon@redhat.com> * python/python-internal.h (gdbpy_get_value_from_history): Rename prototype to gdbpy_history. (gdbpy_is_string): Declare. (python_string_to_host_string): Declare. * python/python-utils.c (gdbpy_is_string): New function. (unicode_to_encoded_string): New function. (unicode_to_target_string): Use it. (python_string_to_host_string): New function. * python/python-value.c (valpy_address): New function. (convert_value_from_python): Use gdbpy_is_string. Change to throw Python exception instead of a GDB exception on error. Properly check Python booleans. (valpy_getitem): Convert field name to host string. Handle array accesses. Adapt to new behaviour of convert_value_from_python. (valpy_new): Adapt to new behaviour of convert_value_from_python. (enum valpy_opcode) <VALPY_LSH, VALPY_RSH, VALPY_BITAND, VALPY_BITXOR, VALPY_BITOR>: New constants. (valpy_binop): Update. Adapt to new behaviour of convert_value_from_python. (valpy_invert): New function. (valpy_lsh): Likewise. (valpy_rsh): Likewise. (valpy_and): Likewise. (valpy_or): Likewise. (valpy_xor): Likewise. (valpy_richcompare): Call convert_value_from_python instead of doing conversions itself. (is_intlike, valpy_int, valpy_long, valpy_float): New functions. (gdbpy_get_value_from_history): Rename function to gdbpy_history. (gdbpy_initialize_values): Don't set tp_new. (value_object_type): Add valpy_new. (value_object_methods): Add `address' entry. (value_object_as_number): Update for new methods. * python/python.c (GdbMethods): Rename entry from `get_value_from_history' to `history'. gdb/doc/ 2009-02-04 Tom Tromey <tromey@redhat.com> * gdb.texinfo (Basic Python): Document gdb.history. gdb/testsuite/ 2009-02-04 Tom Tromey <tromey@redhat.com> Thiago Jung Bauermann <bauerman@br.ibm.com> * gdb.python/python-value.exp: Use `gdb.history' instead of `gdb.value_from_history'. (test_value_numeric_ops): Add test for conversion of enum constant. * gdb.python/python-value.c (enum e): New type. (evalue): New global. (main): Use argv.
2009-02-04 22:55:40 +01:00
enum e
{
ONE = 1,
TWO = 2
};
gdb 2009-05-27 Tom Tromey <tromey@redhat.com> Thiago Jung Bauermann <bauerman@br.ibm.com> Phil Muldoon <pmuldoon@redhat.com> Paul Pluzhnikov <ppluzhnikov@google.com> * python/python.c (_initialize_python): Call gdbpy_initialize_types. (GdbMethods): Add "lookup_type". * python/python-value.c (value_object) <type>: New field. (valpy_dealloc): Decref type. (valpy_new): Initialize type. (valpy_get_type): New function. (value_to_value_object): Initialize type. (valpy_cast): New function. (value_object_getset): Add "type". (value_object_methods): Add "cast". * python/python-internal.h (type_to_type_object): Declare. (type_object_to_type): Likewise. (gdbpy_initialize_types): Likewise. (gdbpy_lookup_type): Declare. * Makefile.in (SUBDIR_PYTHON_OBS): Add python-type.o. (SUBDIR_PYTHON_SRCS): Add python-type.c. (python-type.o): New target. * python/python-type.c: New file. gdb/doc 2009-05-27 Thiago Jung Bauermann <bauerman@br.ibm.com> Tom Tromey <tromey@redhat.com> * gdb.texinfo (Types In Python): New node. (Values From Inferior): "type" is now an attribute. (Python API): Update. gdb/testsuite 2009-05-27 Thiago Jung Bauermann <bauerman@br.ibm.com> Tom Tromey <tromey@redhat.com> Pedro Alves <pedro@codesourcery.com> Paul Pluzhnikov <ppluzhnikov@google.com> * gdb.python/python-template.exp: New file. * gdb.python/python-template.cc: New file. * gdb.python/python.exp (gdb_py_test_multiple): Add two objfile tests. * gdb.python/python-value.exp (py_objfile_tests): New proc. Call it. (test_value_after_death): New proc. * gdb.python/python-value.c (PTR): New typedef. (main): New variable 'x'.
2009-05-28 02:47:20 +02:00
typedef struct s *PTR;
gdb/ 2009-02-04 Tom Tromey <tromey@redhat.com> Thiago Jung Bauermann <bauerman@br.ibm.com> Phil Muldoon <pmuldoon@redhat.com> * python/python-internal.h (gdbpy_get_value_from_history): Rename prototype to gdbpy_history. (gdbpy_is_string): Declare. (python_string_to_host_string): Declare. * python/python-utils.c (gdbpy_is_string): New function. (unicode_to_encoded_string): New function. (unicode_to_target_string): Use it. (python_string_to_host_string): New function. * python/python-value.c (valpy_address): New function. (convert_value_from_python): Use gdbpy_is_string. Change to throw Python exception instead of a GDB exception on error. Properly check Python booleans. (valpy_getitem): Convert field name to host string. Handle array accesses. Adapt to new behaviour of convert_value_from_python. (valpy_new): Adapt to new behaviour of convert_value_from_python. (enum valpy_opcode) <VALPY_LSH, VALPY_RSH, VALPY_BITAND, VALPY_BITXOR, VALPY_BITOR>: New constants. (valpy_binop): Update. Adapt to new behaviour of convert_value_from_python. (valpy_invert): New function. (valpy_lsh): Likewise. (valpy_rsh): Likewise. (valpy_and): Likewise. (valpy_or): Likewise. (valpy_xor): Likewise. (valpy_richcompare): Call convert_value_from_python instead of doing conversions itself. (is_intlike, valpy_int, valpy_long, valpy_float): New functions. (gdbpy_get_value_from_history): Rename function to gdbpy_history. (gdbpy_initialize_values): Don't set tp_new. (value_object_type): Add valpy_new. (value_object_methods): Add `address' entry. (value_object_as_number): Update for new methods. * python/python.c (GdbMethods): Rename entry from `get_value_from_history' to `history'. gdb/doc/ 2009-02-04 Tom Tromey <tromey@redhat.com> * gdb.texinfo (Basic Python): Document gdb.history. gdb/testsuite/ 2009-02-04 Tom Tromey <tromey@redhat.com> Thiago Jung Bauermann <bauerman@br.ibm.com> * gdb.python/python-value.exp: Use `gdb.history' instead of `gdb.value_from_history'. (test_value_numeric_ops): Add test for conversion of enum constant. * gdb.python/python-value.c (enum e): New type. (evalue): New global. (main): Use argv.
2009-02-04 22:55:40 +01:00
enum e evalue = TWO;
struct str
{
int length;
/* Variable length. */
char text[1];
};
#ifdef __cplusplus
struct Base {
virtual int x() { return 5; }
};
struct Derived : public Base {
};
Base *base = new Derived ();
Derived derived;
Base &base_ref = derived;
void ptr_ref(int*& rptr_int)
{
return; /* break to inspect pointer by reference. */
}
#endif
void func1 ()
{
printf ("void function called\n");
}
int func2 (int arg1, int arg2)
{
return arg1 + arg2;
}
char **save_argv;
int
main (int argc, char *argv[])
{
gdb 2009-05-27 Tom Tromey <tromey@redhat.com> Thiago Jung Bauermann <bauerman@br.ibm.com> Phil Muldoon <pmuldoon@redhat.com> Paul Pluzhnikov <ppluzhnikov@google.com> * python/python.c (_initialize_python): Call gdbpy_initialize_types. (GdbMethods): Add "lookup_type". * python/python-value.c (value_object) <type>: New field. (valpy_dealloc): Decref type. (valpy_new): Initialize type. (valpy_get_type): New function. (value_to_value_object): Initialize type. (valpy_cast): New function. (value_object_getset): Add "type". (value_object_methods): Add "cast". * python/python-internal.h (type_to_type_object): Declare. (type_object_to_type): Likewise. (gdbpy_initialize_types): Likewise. (gdbpy_lookup_type): Declare. * Makefile.in (SUBDIR_PYTHON_OBS): Add python-type.o. (SUBDIR_PYTHON_SRCS): Add python-type.c. (python-type.o): New target. * python/python-type.c: New file. gdb/doc 2009-05-27 Thiago Jung Bauermann <bauerman@br.ibm.com> Tom Tromey <tromey@redhat.com> * gdb.texinfo (Types In Python): New node. (Values From Inferior): "type" is now an attribute. (Python API): Update. gdb/testsuite 2009-05-27 Thiago Jung Bauermann <bauerman@br.ibm.com> Tom Tromey <tromey@redhat.com> Pedro Alves <pedro@codesourcery.com> Paul Pluzhnikov <ppluzhnikov@google.com> * gdb.python/python-template.exp: New file. * gdb.python/python-template.cc: New file. * gdb.python/python.exp (gdb_py_test_multiple): Add two objfile tests. * gdb.python/python-value.exp (py_objfile_tests): New proc. Call it. (test_value_after_death): New proc. * gdb.python/python-value.c (PTR): New typedef. (main): New variable 'x'.
2009-05-28 02:47:20 +02:00
char *cp = argv[0]; /* Prevent gcc from optimizing argv[] out. */
struct s s;
union u u;
gdb 2009-05-27 Tom Tromey <tromey@redhat.com> Thiago Jung Bauermann <bauerman@br.ibm.com> Phil Muldoon <pmuldoon@redhat.com> Paul Pluzhnikov <ppluzhnikov@google.com> * python/python.c (_initialize_python): Call gdbpy_initialize_types. (GdbMethods): Add "lookup_type". * python/python-value.c (value_object) <type>: New field. (valpy_dealloc): Decref type. (valpy_new): Initialize type. (valpy_get_type): New function. (value_to_value_object): Initialize type. (valpy_cast): New function. (value_object_getset): Add "type". (value_object_methods): Add "cast". * python/python-internal.h (type_to_type_object): Declare. (type_object_to_type): Likewise. (gdbpy_initialize_types): Likewise. (gdbpy_lookup_type): Declare. * Makefile.in (SUBDIR_PYTHON_OBS): Add python-type.o. (SUBDIR_PYTHON_SRCS): Add python-type.c. (python-type.o): New target. * python/python-type.c: New file. gdb/doc 2009-05-27 Thiago Jung Bauermann <bauerman@br.ibm.com> Tom Tromey <tromey@redhat.com> * gdb.texinfo (Types In Python): New node. (Values From Inferior): "type" is now an attribute. (Python API): Update. gdb/testsuite 2009-05-27 Thiago Jung Bauermann <bauerman@br.ibm.com> Tom Tromey <tromey@redhat.com> Pedro Alves <pedro@codesourcery.com> Paul Pluzhnikov <ppluzhnikov@google.com> * gdb.python/python-template.exp: New file. * gdb.python/python-template.cc: New file. * gdb.python/python.exp (gdb_py_test_multiple): Add two objfile tests. * gdb.python/python-value.exp (py_objfile_tests): New proc. Call it. (test_value_after_death): New proc. * gdb.python/python-value.c (PTR): New typedef. (main): New variable 'x'.
2009-05-28 02:47:20 +02:00
PTR x = &s;
char st[17] = "divide et impera";
char nullst[17] = "divide\0et\0impera";
void (*fp1) (void) = &func1;
int (*fp2) (int, int) = &func2;
2010-01-13 Phil Muldoon <pmuldoon@redhat.com> PR python/10705 * python/python-internal.h: Add lazy_string_object_type definition. (create_lazy_string_object, gdbpy_initialize_lazy_string) (gdbpy_is_lazystring, gdbpy_extract_lazy_string): Define. * python/py-value.c (valpy_lazy_string): New function. (convert_value_from_python): Add lazy string conversion. * python/py-prettyprint.c (pretty_print_one_value): Check if return is also a lazy string. (print_string_repr): Add lazy string printing branch. (print_children): Likewise. * python/py-lazy-string.c: New file. Implement lazy strings. * python/python.c (_initialize_python): Call gdbpy_initialize_lazy_string. * varobj.c (value_get_print_value): Add lazy string printing branch. Account for encoding. * c-lang.c (c_printstr): Account for new encoding argument. If encoding is NULL, find encoding suited for type, otherwise use user encoding. * language.h (language_defn): Add encoding argument. (LA_PRINT_STRING): Likewise. * language.c (unk_lang_printstr): Update to reflect new encoding argument to language_defn. * ada-lang.h (ada_printstr): Likewise. * c-lang.h (c_printstr): Likewise. * p-lang.h (pascal_printstr); * f-lang.c (f_printstr): Likewise. * m2-lang.c (m2_printstr): Likewise. * objc-lang.c (objc_printstr): Likewise. * p-lang.c (pascal_printstr): Likewise. * scm-lang.c (scm_printstr): Likewise. * c-valprint.c (c_val_print): Update LA_PRINT_STRING call for encoding argument. * ada-valprint.c (ada_printstr): Likewise. * f-valprint.c (f_val_print): Likewise * m2-valprint.c (m2_val_print): Likewise. * p-valprint.c (pascal_val_print): Likewise. * expprint.c (print_subexp_standard): Likewise. * valprint.c (val_print_string): Likewise. * Makefile.in (SUBDIR_PYTHON_OBS): Add py-lazy-string. (SUBDIR_PYTHON_SRCS): Likewise. (py-lazy-string.o): New rule. 2010-01-13 Phil Muldoon <pmuldoon@redhat.com> * gdb.texinfo (Values From Inferior): Document lazy_string value method. (Python API): Add Lazy strings menu item. (Lazy Strings In Python): New node. 2010-01-13 Phil Muldoon <pmuldoon@redhat.com> * gdb.python/py-value.exp (test_lazy_strings): Add lazy string test. * gdb.python/py-prettyprint.py (pp_ls): New printer. * gdb.python/py-prettyprint.exp (run_lang_tests): Add lazy string test. * gdb.python/py-prettyprint.c: Define lazystring test structure. * gdb.python/py-mi.exp: Add lazy string test.
2010-01-14 09:03:37 +01:00
const char *sptr = "pointer";
const char *embed = "embedded x\201\202\203\204";
int a[3] = {1,2,3};
int *p = a;
int i = 2;
int *ptr_i = &i;
const char *sn = 0;
struct str *xstr;
s.a = 3;
s.b = 5;
u.a = 7;
(*fp1) ();
(*fp2) (10,20);
#ifdef __cplusplus
ptr_ref(ptr_i);
#endif
#define STR_LENGTH 100
xstr = (struct str *) malloc (sizeof (*xstr) + STR_LENGTH);
xstr->length = STR_LENGTH;
memset (xstr->text, 'x', STR_LENGTH);
#undef STR_LENGTH
save_argv = argv; /* break to inspect struct and union */
return 0;
}