diff mbox

[fix,segfault,when,it,is,working,with,incorrect,debug,info] Skip loop iteration after catch error

Message ID 20180119211320.24031-1-dzabraew@gmail.com
State New
Headers show

Commit Message

Максим Дзабраев Jan. 19, 2018, 9:13 p.m. UTC
From: Maxim Dzabraev <dzabraew@gmail.com>

When compiler generate incorrect debug/symbol information
function value_static_field may raise exception. As far as
function is not finished, we should not use it's returned value,
because it is NULL. After exception gdb print error message and
goto the next iteration.
---
 gdb/ChangeLog                        |  5 +++++
 gdb/cp-valprint.c                    |  1 +
 gdb/testsuite/ChangeLog              |  5 +++++
 gdb/testsuite/gdb.cp/print-regex.cc  |  6 ++++++
 gdb/testsuite/gdb.cp/print-regex.exp | 33 +++++++++++++++++++++++++++++++++
 5 files changed, 50 insertions(+)
 create mode 100644 gdb/testsuite/gdb.cp/print-regex.cc
 create mode 100644 gdb/testsuite/gdb.cp/print-regex.exp
diff mbox

Patch

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index aaadf142a4..8b09e2574f 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@ 
+2018-01-19  Maksim Dzabraev  <dzabraew@gmail.com>
+
+	* cp-valprint.c (cp_print_value_fields): Execute
+	"continue" in loop iteration if catch error.
+
 2017-12-31  Ruslan Kabatsayev  <b7.10110111@gmail.com>
 
 	* psymtab.c (recursively_search_psymtabs): Use pointer arithmetic
diff --git a/gdb/cp-valprint.c b/gdb/cp-valprint.c
index 609dabb660..ef46c0084c 100644
--- a/gdb/cp-valprint.c
+++ b/gdb/cp-valprint.c
@@ -326,6 +326,7 @@  cp_print_value_fields (struct type *type, struct type *real_type,
 		      fprintf_filtered (stream,
 					_("<error reading variable: %s>"),
 					ex.message);
+		      continue;
 		    }
 		  END_CATCH
 
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index e3f18aeeea..61a64c1413 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,8 @@ 
+2018-01-19  Maksim Dzabraev  <dzabraew@gmail.com>
+
+	* gdb.cp/print-regex.exp: Test gdb doesn't get segfault
+	when it is printing std::regex.
+
 2017-12-27  Stafford Horne  <shorne@gmail.com>
 
 	* gdb.xml/extra-regs.xml: Add example foo reggroup.
diff --git a/gdb/testsuite/gdb.cp/print-regex.cc b/gdb/testsuite/gdb.cp/print-regex.cc
new file mode 100644
index 0000000000..cab4bdf16f
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/print-regex.cc
@@ -0,0 +1,6 @@ 
+#include <regex>
+
+int main(void) {
+  std::regex regex("");
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.cp/print-regex.exp b/gdb/testsuite/gdb.cp/print-regex.exp
new file mode 100644
index 0000000000..17b8f643a7
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/print-regex.exp
@@ -0,0 +1,33 @@ 
+# Copyright 2018 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 .cc
+
+if {[prepare_for_testing "failed to prepare" $testfile $srcfile \
+    {debug c++ additional_flags="-std=c++17"}]} {
+    return -1
+}
+
+if ![runto_main] then {
+    fail "can't run to main"
+    return 0
+}
+
+# When program is being compiled with gcc 7.2.0 and with -std=c++17
+# and if we try to print std::regex regex("") gdb crashes with segfaul
+gdb_test "print regex" "{.*" "check that gdb did not crash with segfault"