[2/2] Add unit test for bug 13669 "Infinite recursion in cp_print_value_fields"

Message ID 20171018131729.23137-2-osscontribute@gmail.com
State New, archived
Headers

Commit Message

Patrick Frants Oct. 18, 2017, 1:17 p.m. UTC
  ---
 gdb/testsuite/gdb.cp/printstaticrecursion.cc  | 65 +++++++++++++++++++++++++++
 gdb/testsuite/gdb.cp/printstaticrecursion.exp | 41 +++++++++++++++++
 2 files changed, 106 insertions(+)
 create mode 100644 gdb/testsuite/gdb.cp/printstaticrecursion.cc
 create mode 100644 gdb/testsuite/gdb.cp/printstaticrecursion.exp
  

Patch

diff --git a/gdb/testsuite/gdb.cp/printstaticrecursion.cc b/gdb/testsuite/gdb.cp/printstaticrecursion.cc
new file mode 100644
index 0000000000..17312e6982
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/printstaticrecursion.cc
@@ -0,0 +1,65 @@ 
+#include <new>
+using namespace std;
+//// Pixel
+
+class Pixel
+{
+    int m_red;
+
+public:
+    Pixel()
+        : m_red(0)
+    {}
+
+    // Static instances of Pixel
+    static const Pixel sm_black;
+};
+
+const Pixel Pixel::sm_black;
+
+
+//// BlendState
+
+class BlendState
+{
+    Pixel m_blendColour;
+
+    // Static instances of BlendState
+    static const BlendState sm_alphaBlending;
+};
+
+const BlendState BlendState::sm_alphaBlending;
+
+
+//// Context
+
+class Context
+{
+    BlendState m_blendStack;
+
+    // Static instances of Context
+    static Context * sm_instance;
+public:
+    static Context & instance();
+};
+
+Context * Context::sm_instance;
+
+Context & Context::instance()
+{
+    sm_instance = new Context;
+
+    Context & ref = *sm_instance;
+    return ref;  /* break-here */
+}
+
+// + }}}
+
+
+
+int main()
+{
+    Context & context = Context::instance();
+
+    return 0;
+}
\ No newline at end of file
diff --git a/gdb/testsuite/gdb.cp/printstaticrecursion.exp b/gdb/testsuite/gdb.cp/printstaticrecursion.exp
new file mode 100644
index 0000000000..37e3fed05f
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/printstaticrecursion.exp
@@ -0,0 +1,41 @@ 
+# Copyright 2008-2017 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/>.
+
+
+if { [skip_cplus_tests] } { continue }
+
+standard_testfile printstaticrecursion.cc
+
+# Create and source the file that provides information about the compiler
+# used to compile the test case.
+if [get_compiler_info "c++"] {
+    untested "couldn't find a valid c++ compiler"
+    return -1
+}
+
+if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug c++}]} {
+    return -1
+}
+
+if ![runto_main] then {
+    perror "couldn't run to main"
+    continue
+} 
+
+gdb_breakpoint ${srcfile}:[gdb_get_line_number "break-here"]
+gdb_continue_to_breakpoint "Continue to first breakpoint"
+gdb_test "finish"
+gdb_exit
+return 0