Blame SOURCES/gdb-rhbz1013453-value-struct-elt-memory-leak.patch

01917d
https://sourceware.org/ml/gdb-patches/2013-07/msg00469.html
01917d
01917d
Hi.
01917d
This patch adds the missing calls to check_typedef
01917d
and adds a testcase to show the issue.
01917d
01917d
The PR is not closeable yet, but the remaining issues are more cleanups
01917d
than actual bug fixes.
01917d
01917d
Regression tested on amd64-linux.
01917d
01917d
I will check this in in a few days if there are no objections.
01917d
01917d
[The multiple calls to check_typedef (value_type (*argp)) are
01917d
bothersome, but the code is simpler this way, and I expect
01917d
resolving the rest of the issues in 15695 to potentially change this
01917d
code significantly.]
01917d
01917d
---
01917d
01917d
commit cbb25189b69e501ddca64917d810b54bb1466c93
01917d
Author: Doug Evans <dje@google.com>
01917d
Date:   Thu Aug 1 23:59:47 2013 +0000
01917d
01917d
    	PR symtab/15695
01917d
    	* valops.c (value_struct_elt): Add missing call to check_typedef.
01917d
    	(value_find_oload_method_list): Ditto.
01917d
    
01917d
    	testsuite/
01917d
    	* gdb.base/func-ptr.exp: New file.
01917d
    	* gdb.base/func-ptr.c: New file.
01917d
01917d
2013-08-01  Doug Evans  <dje@google.com>
01917d
 
01917d
	PR symtab/15695
01917d
	* valops.c (value_struct_elt): Add missing call to check_typedef.
01917d
	(value_find_oload_method_list): Ditto.
01917d
01917d
2013-08-01  Doug Evans  <dje@google.com>
01917d
01917d
	PR symtab/15695
01917d
	* gdb.base/func-ptr.exp: New file.
01917d
	* gdb.base/func-ptr.c: New file.
01917d
01917d
Index: gdb-7.6.1/gdb/testsuite/gdb.base/func-ptr.c
01917d
===================================================================
01917d
--- /dev/null
01917d
+++ gdb-7.6.1/gdb/testsuite/gdb.base/func-ptr.c
01917d
@@ -0,0 +1,30 @@
01917d
+/* This testcase is part of GDB, the GNU debugger.
01917d
+
01917d
+   Copyright 2013 Free Software Foundation, Inc.
01917d
+
01917d
+   This program is free software; you can redistribute it and/or modify
01917d
+   it under the terms of the GNU General Public License as published by
01917d
+   the Free Software Foundation; either version 3 of the License, or
01917d
+   (at your option) any later version.
01917d
+
01917d
+   This program is distributed in the hope that it will be useful,
01917d
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
01917d
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
01917d
+   GNU General Public License for more details.
01917d
+
01917d
+   You should have received a copy of the GNU General Public License
01917d
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
01917d
+
01917d
+void
01917d
+bar ()
01917d
+{
01917d
+}
01917d
+
01917d
+typedef void foo (void);
01917d
+foo *pbar = bar;
01917d
+
01917d
+int
01917d
+main ()
01917d
+{
01917d
+  return 0;
01917d
+}
01917d
Index: gdb-7.6.1/gdb/testsuite/gdb.base/func-ptr.exp
01917d
===================================================================
01917d
--- /dev/null
01917d
+++ gdb-7.6.1/gdb/testsuite/gdb.base/func-ptr.exp
01917d
@@ -0,0 +1,30 @@
01917d
+# Copyright 2013 Free Software Foundation, Inc.
01917d
+
01917d
+# This program is free software; you can redistribute it and/or modify
01917d
+# it under the terms of the GNU General Public License as published by
01917d
+# the Free Software Foundation; either version 3 of the License, or
01917d
+# (at your option) any later version.
01917d
+#
01917d
+# This program is distributed in the hope that it will be useful,
01917d
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
01917d
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
01917d
+# GNU General Public License for more details.
01917d
+#
01917d
+# You should have received a copy of the GNU General Public License
01917d
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
01917d
+
01917d
+# This testcase exercises bug 15695.
01917d
+# Trying to print foo->bar if foo is a pointer to a typedef of a pointer
01917d
+# to a function will put gdb into an infinite loop.
01917d
+
01917d
+if { [prepare_for_testing func-ptr.exp "func-ptr" {func-ptr.c} {debug}] } {
01917d
+    return -1
01917d
+}
01917d
+
01917d
+if ![runto_main] {
01917d
+    fail "Can't run to main"
01917d
+    return 0
01917d
+}
01917d
+
01917d
+# This would put gdb into an infinite loop.
01917d
+gdb_test "print pbar->baz" "Attempt to extract .*"
01917d
Index: gdb-7.6.1/gdb/valops.c
01917d
===================================================================
01917d
--- gdb-7.6.1.orig/gdb/valops.c
01917d
+++ gdb-7.6.1/gdb/valops.c
01917d
@@ -2450,7 +2450,7 @@ value_struct_elt (struct value **argp, s
01917d
     {
01917d
       *argp = value_ind (*argp);
01917d
       /* Don't coerce fn pointer to fn and then back again!  */
01917d
-      if (TYPE_CODE (value_type (*argp)) != TYPE_CODE_FUNC)
01917d
+      if (TYPE_CODE (check_typedef (value_type (*argp))) != TYPE_CODE_FUNC)
01917d
 	*argp = coerce_array (*argp);
01917d
       t = check_typedef (value_type (*argp));
01917d
     }
01917d
@@ -2614,7 +2614,7 @@ value_find_oload_method_list (struct val
01917d
     {
01917d
       *argp = value_ind (*argp);
01917d
       /* Don't coerce fn pointer to fn and then back again!  */
01917d
-      if (TYPE_CODE (value_type (*argp)) != TYPE_CODE_FUNC)
01917d
+      if (TYPE_CODE (check_typedef (value_type (*argp))) != TYPE_CODE_FUNC)
01917d
 	*argp = coerce_array (*argp);
01917d
       t = check_typedef (value_type (*argp));
01917d
     }