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

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