From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9574 invoked by alias); 3 Dec 2009 15:10:08 -0000 Received: (qmail 9522 invoked by uid 22791); 3 Dec 2009 15:10:04 -0000 X-SWARE-Spam-Status: No, hits=-2.3 required=5.0 tests=AWL,BAYES_00,HK_OBFDOM,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 03 Dec 2009 15:09:58 +0000 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nB3F9vda018953 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 3 Dec 2009 10:09:57 -0500 Received: from localhost.localdomain (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nB3F9tRd011280; Thu, 3 Dec 2009 10:09:56 -0500 Message-ID: <4B17D4C3.1040703@redhat.com> Date: Thu, 03 Dec 2009 15:10:00 -0000 From: Phil Muldoon User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.4pre) Gecko/20090922 Fedora/3.0-3.9.b4.fc12 Lightning/1.0pre Thunderbird/3.0b4 MIME-Version: 1.0 To: tromey@redhat.com CC: gdb-patches ml Subject: Re: [python][patch] Add is_base_class attribute to fields. References: <4B13A147.2040208@redhat.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2009-12/txt/msg00026.txt.bz2 On 12/01/2009 08:51 PM, Tom Tromey wrote: >>>>>> "Phil" == Phil Muldoon writes: > > Phil> Later I fixed a bug/added tests to capture a regression this > Phil> functionality caused. > Phil> http://sourceware.org/ml/archer/2009-q4/msg00016.html? > > The tests are nice but they don't actually check the is_base_class field. > Could you add a test to do that? > > Other than that I think the code bits are ok. It needs a doc review. > I've modified the patch as attached. If Eli does not have any comments or changes to the doc section, this is what I will commit. Cheers, Phil -- Index: doc/gdb.texinfo =================================================================== RCS file: /cvs/src/src/gdb/doc/gdb.texinfo,v retrieving revision 1.645 diff -u -r1.645 gdb.texinfo --- doc/gdb.texinfo 1 Dec 2009 22:15:27 -0000 1.645 +++ doc/gdb.texinfo 3 Dec 2009 08:41:57 -0000 @@ -19608,6 +19608,12 @@ 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 on which @code{fields} was +called, 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, Index: python/py-type.c =================================================================== RCS file: /cvs/src/src/gdb/python/py-type.c,v retrieving revision 1.2 diff -u -r1.2 py-type.c --- python/py-type.c 11 Sep 2009 18:51:31 -0000 1.2 +++ python/py-type.c 3 Dec 2009 08:41:58 -0000 @@ -169,6 +169,14 @@ 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; Index: testsuite/gdb.python/Makefile.in =================================================================== RCS file: /cvs/src/src/gdb/testsuite/gdb.python/Makefile.in,v retrieving revision 1.2 diff -u -r1.2 Makefile.in --- testsuite/gdb.python/Makefile.in 9 Sep 2009 17:45:42 -0000 1.2 +++ testsuite/gdb.python/Makefile.in 3 Dec 2009 08:41:59 -0000 @@ -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 $@..." Index: testsuite/gdb.python/py-type.c =================================================================== RCS file: testsuite/gdb.python/py-type.c diff -N testsuite/gdb.python/py-type.c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ testsuite/gdb.python/py-type.c 3 Dec 2009 08:41:59 -0000 @@ -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 . */ + +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. */ +} Index: testsuite/gdb.python/py-type.exp =================================================================== RCS file: testsuite/gdb.python/py-type.exp diff -N testsuite/gdb.python/py-type.exp --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ testsuite/gdb.python/py-type.exp 3 Dec 2009 08:41:59 -0000 @@ -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 . + +# 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" "" "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