Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [patch] C++ operators do not resolve through typedefs
@ 2011-02-18 16:00 Jan Kratochvil
  2011-02-18 18:40 ` Tom Tromey
  0 siblings, 1 reply; 3+ messages in thread
From: Jan Kratochvil @ 2011-02-18 16:00 UTC (permalink / raw)
  To: gdb-patches

Hi,

https://bugzilla.redhat.com/show_bug.cgi?id=678454

operators do not get resolved through a typedef.

The other unrelated part is that GDB crashes when trying to resolve operator
without running inferior.  I did not split it to a separate mail as I find it
separated here well enough.

No regressions on {x86_64,x86_64-m32,i686}-fedora15-linux-gnu.

I find it safe enough so I will check it in in some time.


Thanks,
Jan


gdb/
2011-02-18  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* cp-support.c (make_symbol_overload_list_namespace) Do not call
	make_symbol_overload_list_block with NULL BLOCK.
	* valarith.c (unop_user_defined_p): Resolve also TYPE_CODE_TYPEDEF.

gdb/testsuite/
2011-02-18  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* gdb.cp/typedef-operator.exp: New file.
	* gdb.cp/typedef-operator.cc: New file.

--- a/gdb/cp-support.c
+++ b/gdb/cp-support.c
@@ -778,11 +778,13 @@ make_symbol_overload_list_namespace (const char *func_name,
 
   /* Look in the static block.  */
   block = block_static_block (get_selected_block (0));
-  make_symbol_overload_list_block (name, block);
+  if (block)
+    make_symbol_overload_list_block (name, block);
 
   /* Look in the global block.  */
   block = block_global_block (block);
-  make_symbol_overload_list_block (name, block);
+  if (block)
+    make_symbol_overload_list_block (name, block);
 
 }
 
--- a/gdb/valarith.c
+++ b/gdb/valarith.c
@@ -315,15 +315,26 @@ unop_user_defined_p (enum exp_opcode op, struct value *arg1)
   if (op == UNOP_ADDR)
     return 0;
   type1 = check_typedef (value_type (arg1));
-  for (;;)
+  while (type1)
     {
       if (TYPE_CODE (type1) == TYPE_CODE_STRUCT)
 	return 1;
       else if (TYPE_CODE (type1) == TYPE_CODE_REF)
 	type1 = TYPE_TARGET_TYPE (type1);
+      else if (TYPE_CODE (type1) == TYPE_CODE_TYPEDEF)
+	{
+	  struct type *type2 = check_typedef (type1);
+
+	  /* Abort if this TYPE_CODE_TYPEDEF cannot be resolved.  */
+	  if (type2 == type1)
+	    break;
+
+	  type1 = type2;
+	}
       else
-	return 0;
+	break;
     }
+  return 0;
 }
 
 /* Try to find an operator named OPERATOR which takes NARGS arguments
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/typedef-operator.cc
@@ -0,0 +1,29 @@
+/* This test case is part of GDB, the GNU debugger.
+
+   Copyright 2011 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/>.  */
+
+class C
+{
+public:
+  int operator* () { return 42; }
+};
+typedef C D;
+D u;
+D &v = u;
+int main ()
+{
+  return *v;
+}
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/typedef-operator.exp
@@ -0,0 +1,33 @@
+# Copyright 2011 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.
+
+if {[skip_cplus_tests]} { continue }
+
+set testfile "typedef-operator"
+if [prepare_for_testing $testfile $testfile $testfile.cc {c++ debug}] {
+    return -1
+}
+
+gdb_test_no_output "set language c++"
+
+gdb_test "p *u" {You can't do that without a process to debug.} "test crash"
+
+if ![runto_main] {
+    return -1
+}
+
+gdb_test "p *v" " = 42" "test typedef"


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

* Re: [patch] C++ operators do not resolve through typedefs
  2011-02-18 16:00 [patch] C++ operators do not resolve through typedefs Jan Kratochvil
@ 2011-02-18 18:40 ` Tom Tromey
  2011-02-18 19:44   ` Jan Kratochvil
  0 siblings, 1 reply; 3+ messages in thread
From: Tom Tromey @ 2011-02-18 18:40 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: gdb-patches

>>>>> "Jan" == Jan Kratochvil <jan.kratochvil@redhat.com> writes:

The whole patch looks good to me.

Jan> 	* valarith.c (unop_user_defined_p): Resolve also TYPE_CODE_TYPEDEF.

The formulation of this check in binop_types_user_defined_p is simpler,
not involving a loop:

  type1 = check_typedef (type1);
  if (TYPE_CODE (type1) == TYPE_CODE_REF)
    type1 = check_typedef (TYPE_TARGET_TYPE (type1));
  [...]
  return (TYPE_CODE (type1) == TYPE_CODE_STRUCT [...]

Tom


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

* Re: [patch] C++ operators do not resolve through typedefs
  2011-02-18 18:40 ` Tom Tromey
@ 2011-02-18 19:44   ` Jan Kratochvil
  0 siblings, 0 replies; 3+ messages in thread
From: Jan Kratochvil @ 2011-02-18 19:44 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

On Fri, 18 Feb 2011 19:17:10 +0100, Tom Tromey wrote:
>   type1 = check_typedef (type1);
>   if (TYPE_CODE (type1) == TYPE_CODE_REF)
>     type1 = check_typedef (TYPE_TARGET_TYPE (type1));
>   [...]
>   return (TYPE_CODE (type1) == TYPE_CODE_STRUCT [...]

As there is never a reference to reference, OK, nice.

Checked in.

No regressions on {x86_64,x86_64-m32,i686}-fedora15-linux-gnu.


Thanks,
Jan


http://sourceware.org/ml/gdb-cvs/2011-02/msg00133.html

--- src/gdb/ChangeLog	2011/02/18 16:43:50	1.12607
+++ src/gdb/ChangeLog	2011/02/18 19:10:44	1.12608
@@ -1,3 +1,10 @@
+2011-02-18  Jan Kratochvil  <jan.kratochvil@redhat.com>
+	    Tom Tromey  <tromey@redhat.com>
+
+	* cp-support.c (make_symbol_overload_list_namespace): Do not call
+	make_symbol_overload_list_block with NULL BLOCK.
+	* valarith.c (unop_user_defined_p): Resolve also TYPE_CODE_TYPEDEF.
+
 2011-02-18  Pedro Alves  <pedro@codesourcery.com>
 
 	* breakpoint.c (get_number_trailer): No longer accept a NULL PP.
--- src/gdb/cp-support.c	2011/01/05 22:22:47	1.47
+++ src/gdb/cp-support.c	2011/02/18 19:10:46	1.48
@@ -778,11 +778,13 @@
 
   /* Look in the static block.  */
   block = block_static_block (get_selected_block (0));
-  make_symbol_overload_list_block (name, block);
+  if (block)
+    make_symbol_overload_list_block (name, block);
 
   /* Look in the global block.  */
   block = block_global_block (block);
-  make_symbol_overload_list_block (name, block);
+  if (block)
+    make_symbol_overload_list_block (name, block);
 
 }
 
--- src/gdb/valarith.c	2011/02/14 11:30:37	1.98
+++ src/gdb/valarith.c	2011/02/18 19:10:46	1.99
@@ -315,15 +315,9 @@
   if (op == UNOP_ADDR)
     return 0;
   type1 = check_typedef (value_type (arg1));
-  for (;;)
-    {
-      if (TYPE_CODE (type1) == TYPE_CODE_STRUCT)
-	return 1;
-      else if (TYPE_CODE (type1) == TYPE_CODE_REF)
-	type1 = TYPE_TARGET_TYPE (type1);
-      else
-	return 0;
-    }
+  if (TYPE_CODE (type1) == TYPE_CODE_REF)
+    type1 = check_typedef (TYPE_TARGET_TYPE (type1));
+  return TYPE_CODE (type1) == TYPE_CODE_STRUCT;
 }
 
 /* Try to find an operator named OPERATOR which takes NARGS arguments
--- src/gdb/testsuite/ChangeLog	2011/02/17 22:08:12	1.2594
+++ src/gdb/testsuite/ChangeLog	2011/02/18 19:10:46	1.2595
@@ -1,3 +1,8 @@
+2011-02-18  Jan Kratochvil  <jan.kratochvil@redhat.com>
+
+	* gdb.cp/typedef-operator.exp: New file.
+	* gdb.cp/typedef-operator.cc: New file.
+
 2011-02-17  Michael Snyder  <msnyder@vmware.com>
 
 	* gdb.threads/thread-find.exp: Fix regular expressions.
--- src/gdb/testsuite/gdb.cp/typedef-operator.cc
+++ src/gdb/testsuite/gdb.cp/typedef-operator.cc	2011-02-18 19:11:01.266772000 +0000
@@ -0,0 +1,31 @@
+/* This test case is part of GDB, the GNU debugger.
+
+   Copyright 2011 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/>.  */
+
+class C
+{
+public:
+  int operator* () { return 42; }
+};
+typedef C D;
+
+D u;
+D &v = u;
+
+int main ()
+{
+  return *v;
+}
--- src/gdb/testsuite/gdb.cp/typedef-operator.exp
+++ src/gdb/testsuite/gdb.cp/typedef-operator.exp	2011-02-18 19:11:01.559204000 +0000
@@ -0,0 +1,33 @@
+# Copyright 2011 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.
+
+if {[skip_cplus_tests]} { continue }
+
+set testfile "typedef-operator"
+if [prepare_for_testing $testfile $testfile $testfile.cc {c++ debug}] {
+    return -1
+}
+
+gdb_test_no_output "set language c++"
+
+gdb_test "p *u" {You can't do that without a process to debug.} "test crash"
+
+if ![runto_main] {
+    return -1
+}
+
+gdb_test "p *v" " = 42" "test typedef"


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

end of thread, other threads:[~2011-02-18 19:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-02-18 16:00 [patch] C++ operators do not resolve through typedefs Jan Kratochvil
2011-02-18 18:40 ` Tom Tromey
2011-02-18 19:44   ` Jan Kratochvil

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox