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

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