aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorPhil Muldoon <pmuldoon@redhat.com>2009-12-03 21:19:49 +0000
committerPhil Muldoon <pmuldoon@redhat.com>2009-12-03 21:19:49 +0000
commitbfd31e71181e450159f7540aaad11184544cabe0 (patch)
tree031e40b0a29918e607b1ce9921f8c02364f93379 /gdb
parent57a1d736959fb92e39abab59511a903b7ec59547 (diff)
downloadgdb-bfd31e71181e450159f7540aaad11184544cabe0.zip
gdb-bfd31e71181e450159f7540aaad11184544cabe0.tar.gz
gdb-bfd31e71181e450159f7540aaad11184544cabe0.tar.bz2
2009-12-03 Richard Ward <richard.j.ward1@googlemail.com>
* python/py-type.c (convert_field): New attribute "is_base_class". doc/ 2009-12-03 Richard Ward <richard.j.ward1@googlemail.com> * gdb.texinfo (Types In Python): Describe "is_base_class". testsuite/ 2009-12-03 Phil Muldoon <pmuldoon@redhat.com> PR python/10805 * gdb.python/py-type.exp: New file. * gdb.python/py-type.c: New file. * Makefile.in: Add py-type.
Diffstat (limited to 'gdb')
-rw-r--r--gdb/ChangeLog4
-rw-r--r--gdb/doc/ChangeLog4
-rw-r--r--gdb/doc/gdb.texinfo6
-rw-r--r--gdb/python/py-type.c8
-rw-r--r--gdb/testsuite/ChangeLog8
-rw-r--r--gdb/testsuite/gdb.python/Makefile.in2
-rw-r--r--gdb/testsuite/gdb.python/py-type.c56
-rw-r--r--gdb/testsuite/gdb.python/py-type.exp114
8 files changed, 201 insertions, 1 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 70da313..461b01a 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,7 @@
+2009-12-03 Richard Ward <richard.j.ward1@googlemail.com>
+
+ * python/py-type.c (convert_field): New attribute "is_base_class".
+
2009-12-03 Tom Tromey <tromey@redhat.com>
* python/python.c (gdbpy_parse_and_eval): New function.
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index 553abae..8e5eed6 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,3 +1,7 @@
+2009-12-03 Richard Ward <richard.j.ward1@googlemail.com>
+
+ * gdb.texinfo (Types In Python): Describe "is_base_class".
+
2009-12-03 Tom Tromey <tromey@redhat.com>
* gdb.texinfo (Basic Python): Document gdb.parse_and_eval.
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 8cdab8f..b5862c1 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -19621,6 +19621,12 @@ This is @code{True} if the field is artificial, usually meaning that
it was provided by the compiler and not the user. This attribute is
always provided, and is @code{False} if the field is not artificial.
+@item is_base_class
+This is @code{True} if the field represents a base class of a C@t{++}
+structure. This attribute is always provided, and is @code{False}
+if the field is not a base class of the type that is the argument of
+@code{fields}, or if that type was not a C@t{++} class.
+
@item bitsize
If the field is packed, or is a bitfield, then this will have a
non-zero value, which is the size of the field in bits. Otherwise,
diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
index 590d90a..e73185e 100644
--- a/gdb/python/py-type.c
+++ b/gdb/python/py-type.c
@@ -169,6 +169,14 @@ convert_field (struct type *type, int field)
if (PyObject_SetAttrString (result, "artificial", arg) < 0)
goto failarg;
+ if (TYPE_CODE (type) == TYPE_CODE_CLASS)
+ arg = field < TYPE_N_BASECLASSES (type) ? Py_True : Py_False;
+ else
+ arg = Py_False;
+ Py_INCREF (arg);
+ if (PyObject_SetAttrString (result, "is_base_class", arg) < 0)
+ goto failarg;
+
arg = PyLong_FromLong (TYPE_FIELD_BITSIZE (type, field));
if (!arg)
goto fail;
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 4ad760e..65d1ee6 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,11 @@
+2009-12-03 Phil Muldoon <pmuldoon@redhat.com>
+
+ PR python/10805
+
+ * gdb.python/py-type.exp: New file.
+ * gdb.python/py-type.c: New file.
+ * Makefile.in: Add py-type.
+
2009-12-03 Tom Tromey <tromey@redhat.com>
* gdb.python/py-value.exp (test_parse_and_eval): New
diff --git a/gdb/testsuite/gdb.python/Makefile.in b/gdb/testsuite/gdb.python/Makefile.in
index ca5cdc7..3e81bd3 100644
--- a/gdb/testsuite/gdb.python/Makefile.in
+++ b/gdb/testsuite/gdb.python/Makefile.in
@@ -1,7 +1,7 @@
VPATH = @srcdir@
srcdir = @srcdir@
-EXECUTABLES = py-value py-prettyprint py-template
+EXECUTABLES = py-type py-value py-prettyprint py-template
all info install-info dvi install uninstall installcheck check:
@echo "Nothing to be done for $@..."
diff --git a/gdb/testsuite/gdb.python/py-type.c b/gdb/testsuite/gdb.python/py-type.c
new file mode 100644
index 0000000..9d4b57b
--- /dev/null
+++ b/gdb/testsuite/gdb.python/py-type.c
@@ -0,0 +1,56 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2009 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/>. */
+
+struct s
+{
+ int a;
+ int b;
+};
+
+#ifdef __cplusplus
+struct C
+{
+ int c;
+ int d;
+};
+
+struct D : C
+{
+ int e;
+ int f;
+};
+#endif
+
+int
+main ()
+{
+ int ar[2] = {1,2};
+ struct s st;
+#ifdef __cplusplus
+ C c;
+ c.c = 1;
+ c.d = 2;
+ D d;
+ d.e = 3;
+ d.f = 4;
+#endif
+
+ st.a = 3;
+ st.b = 5;
+
+ return 0; /* break to inspect struct and array. */
+}
diff --git a/gdb/testsuite/gdb.python/py-type.exp b/gdb/testsuite/gdb.python/py-type.exp
new file mode 100644
index 0000000..fabda5b
--- /dev/null
+++ b/gdb/testsuite/gdb.python/py-type.exp
@@ -0,0 +1,114 @@
+# Copyright (C) 2009 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/>.
+
+# This file is part of the GDB testsuite. It tests the mechanism
+# of exposing types to Python.
+
+if $tracelevel then {
+ strace $tracelevel
+}
+
+set testfile "py-type"
+set srcfile ${testfile}.c
+set binfile ${objdir}/${subdir}/${testfile}
+
+# Build inferior to language specification.
+proc build_inferior {lang} {
+ global srcdir subdir srcfile binfile testfile hex
+
+ if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable "debug $lang"] != "" } {
+ untested "Couldn't compile ${srcfile} in $lang mode"
+ return -1
+ }
+}
+
+# Restart GDB, set breakpoint and run to that breakpoint.
+proc restart_gdb {bp} {
+ global srcdir subdir srcfile binfile testfile hex
+
+ gdb_exit
+ gdb_start
+ gdb_reinitialize_dir $srcdir/$subdir
+ gdb_load ${binfile}
+
+ if ![runto_main ] then {
+ perror "couldn't run to breakpoint"
+ return
+ }
+
+ gdb_breakpoint [gdb_get_line_number $bp]
+ gdb_continue_to_breakpoint $bp
+}
+
+
+# Run a command in GDB, and report a failure if a Python exception is thrown.
+# If report_pass is true, report a pass if no exception is thrown.
+proc gdb_py_test_silent_cmd {cmd name report_pass} {
+ global gdb_prompt
+
+ gdb_test_multiple $cmd $name {
+ -re "Traceback.*$gdb_prompt $" { fail $name }
+ -re "$gdb_prompt $" { if $report_pass { pass $name } }
+ }
+}
+
+proc test_fields {lang} {
+ global gdb_prompt
+
+ if {$lang == "c++"} {
+ # Test usage with a class
+ gdb_py_test_silent_cmd "print c" "print value" 1
+ gdb_py_test_silent_cmd "python c = gdb.history (0)" "get value from history" 1
+ gdb_py_test_silent_cmd "python fields = c.type.fields()" "get fields" 1
+ gdb_test "python print len(fields)" "2" "Check number of fields"
+ gdb_test "python print fields\[0\].name" "c" "Check class field c name"
+ gdb_test "python print fields\[1\].name" "d" "Check class field d name"
+ }
+
+ # Test normal fields usage in structs.
+ gdb_py_test_silent_cmd "print st" "print value" 1
+ gdb_py_test_silent_cmd "python st = gdb.history (0)" "get value from history" 1
+ gdb_py_test_silent_cmd "python fields = st.type.fields()" "get fields" 1
+ gdb_test "python print len(fields)" "2" "Check number of fields"
+ gdb_test "python print fields\[0\].name" "a" "Check structure field a name"
+ gdb_test "python print fields\[1\].name" "b" "Check structure field b name"
+
+ # Test regression PR python/10805
+ gdb_py_test_silent_cmd "print ar" "print value" 1
+ gdb_py_test_silent_cmd "python ar = gdb.history (0)" "get value from history" 1
+ gdb_test "python fields = ar.type.fields()"
+ gdb_test "python print len(fields)" "1" "Check the number of fields"
+ gdb_test "python print fields\[0\].type" "<range type>" "Check array field type"
+}
+
+proc test_base_class {} {
+ gdb_py_test_silent_cmd "print d" "print value" 1
+ gdb_py_test_silent_cmd "python d = gdb.history (0)" "get value from history" 1
+ gdb_py_test_silent_cmd "python fields = d.type.fields()" "get value from history" 1
+ gdb_test "python print len(fields)" "3" "Check the number of fields"
+ gdb_test "python print fields\[0\].is_base_class" "True" "Check base class"
+ gdb_test "python print fields\[1\].is_base_class" "False" "Check base class"
+}
+
+# Perform C Tests.
+build_inferior "c"
+restart_gdb "break to inspect struct and array."
+test_fields "c"
+
+# Perform C++ Tests.
+build_inferior "c++"
+restart_gdb "break to inspect struct and array."
+test_fields "c++"
+test_base_class