public inbox for archer@sourceware.org
 help / color / mirror / Atom feed
* [patch] Fix python/10805
@ 2009-10-20 13:45 Phil Muldoon
  2009-10-30 22:18 ` Tom Tromey
  0 siblings, 1 reply; 3+ messages in thread
From: Phil Muldoon @ 2009-10-20 13:45 UTC (permalink / raw)
  To: Project Archer

[-- Attachment #1: Type: text/plain, Size: 786 bytes --]

This patch fixes python/10805. When fields were being constructed, the 
convert_fields function was not checking if the type was a class before 
determining if it was a base class. Added a check to gate this behaviour.

Additionally, I started a testsuite for Python types. This suite only 
tests for this regression, but it can be expanded later, in separate 
efforts.

Cheers,

Phil

--

ChangeLog

2009-10-20  Phil Muldoon <pmuldoon@redhat.com>

     PR python/10805

     * python/py-type.c (convert_field): Check for TYPE_CODE_CLASS
     before calling TYPE_N_BASECLASSES.


Testsuite ChangeLog

2009-10-20  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.



[-- Attachment #2: pr10805.patch --]
[-- Type: text/plain, Size: 6325 bytes --]

diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
index f512248..d830e43 100644
--- a/gdb/python/py-type.c
+++ b/gdb/python/py-type.c
@@ -177,7 +177,10 @@ convert_field (struct type *type, int field)
   if (PyObject_SetAttrString (result, "artificial", arg) < 0)
     goto failarg;
 
-  arg = field < TYPE_N_BASECLASSES (type) ? Py_True : Py_False;
+  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;
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
index e69de29..a2d1bb8 100644
--- a/gdb/testsuite/gdb.python/py-type.c
+++ b/gdb/testsuite/gdb.python/py-type.c
@@ -0,0 +1,48 @@
+/* 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
+class C
+{
+ public:
+  int c;
+  int d;
+};
+#endif
+
+int
+main ()
+{
+  int ar[2] = {1,2};
+  struct s st;
+#ifdef __cplusplus
+  C c;
+  c.c = 1;
+  c.d = 2;
+#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
index e69de29..de2612f 100644
--- a/gdb/testsuite/gdb.python/py-type.exp
+++ b/gdb/testsuite/gdb.python/py-type.exp
@@ -0,0 +1,104 @@
+# 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"
+}
+
+# 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++"

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [patch] Fix python/10805
  2009-10-20 13:45 [patch] Fix python/10805 Phil Muldoon
@ 2009-10-30 22:18 ` Tom Tromey
  2009-11-02 13:48   ` Phil Muldoon
  0 siblings, 1 reply; 3+ messages in thread
From: Tom Tromey @ 2009-10-30 22:18 UTC (permalink / raw)
  To: Phil Muldoon; +Cc: Project Archer

>>>>> "Phil" == Phil Muldoon <pmuldoon@redhat.com> writes:

Phil> This patch fixes python/10805. When fields were being constructed, the
Phil> convert_fields function was not checking if the type was a class
Phil> before determining if it was a base class. Added a check to gate this
Phil> behaviour.

Looks good, thanks.

Phil> Additionally, I started a testsuite for Python types. This suite only
Phil> tests for this regression, but it can be expanded later, in separate
Phil> efforts.

Awesome.

The is_base_class thing isn't upstream.
It would be good to submit all this sometime.

Tom

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [patch] Fix python/10805
  2009-10-30 22:18 ` Tom Tromey
@ 2009-11-02 13:48   ` Phil Muldoon
  0 siblings, 0 replies; 3+ messages in thread
From: Phil Muldoon @ 2009-11-02 13:48 UTC (permalink / raw)
  To: Tom Tromey; +Cc: Project Archer

On 10/30/2009 10:18 PM, Tom Tromey wrote:
>>>>>> "Phil" == Phil Muldoon<pmuldoon@redhat.com>  writes:
>>>>>>              
> Phil>  This patch fixes python/10805. When fields were being constructed, the
> Phil>  convert_fields function was not checking if the type was a class
> Phil>  before determining if it was a base class. Added a check to gate this
> Phil>  behaviour.
>
> Looks good, thanks.
>
> Phil>  Additionally, I started a testsuite for Python types. This suite only
> Phil>  tests for this regression, but it can be expanded later, in separate
> Phil>  efforts.
>    


Thanks. Committed: as dad6b53fe4a6df586dcd0a57e2151e7663191f18

> Awesome.
>
> The is_base_class thing isn't upstream.
> It would be good to submit all this sometime.
>    


I'll dig out the is_base_class author name and submit the patch and 
ChangeLog upstream, as well as this patchlet.

Cheers,

Phil

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-11-02 13:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-10-20 13:45 [patch] Fix python/10805 Phil Muldoon
2009-10-30 22:18 ` Tom Tromey
2009-11-02 13:48   ` Phil Muldoon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).