From patchwork Fri Jan 19 21:13:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?0JzQsNC60YHQuNC8INCU0LfQsNCx0YDQsNC10LI=?= X-Patchwork-Id: 25464 Received: (qmail 30078 invoked by alias); 19 Jan 2018 21:13:30 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 30065 invoked by uid 89); 19 Jan 2018 21:13:29 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=Maxim, maxim X-HELO: mail-lf0-f67.google.com Received: from mail-lf0-f67.google.com (HELO mail-lf0-f67.google.com) (209.85.215.67) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 19 Jan 2018 21:13:27 +0000 Received: by mail-lf0-f67.google.com with SMTP id g72so3658141lfg.5 for ; Fri, 19 Jan 2018 13:13:26 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=xWmy06c4fj4Gbx3jcI93cTgP0a8QnKHhG8Z2CyFrQ68=; b=M1dqPm0jyeB90yr7b7niCFXtEJvmHSpeAKF78ZtmGtvQVMmZ9/DKaRkZCmwH7QFJ/0 6LuXxbiFNQRkUlxBjXQJQI32rkIlBTu7mBg9PceHikh3u8rtsf9ekozeljcWDv7page+ A9mqb8y7paVt9zgqZcKa8UjWRq12MqMdGQf4B7OFkrTaRSLhawTNJAZ/v+WhkHANuA4W Bg8Q6R2WxgYPzMszwZ1hgVx/lI6qF2JTCNURT0DxbEbh78cD5BIrc9aHQ3ov8Bu9v/Bu K8j/PlnIfhU4Uwkzqp7Ja7RyzDuUZAG89cDscqvIPqa4iu2SUA9YbTrdBNs0FE4RSTJD bN/g== X-Gm-Message-State: AKwxyte3liGQu2A6Rb5QLUDySy0hQiKa5n3ZQJyLq8nsEbDMQ6xpBLqo Qrdykzu14X8W1XprMu7ebknt0wCM X-Google-Smtp-Source: ACJfBou1B+/Xpjt3Om5hUGqVt4yPrtdiwFMgBU9parwFD2/heWpCQrJoYqoVmwXYxQrd5IaemRMdmg== X-Received: by 10.46.42.195 with SMTP id q186mr8714564ljq.57.1516396404343; Fri, 19 Jan 2018 13:13:24 -0800 (PST) Received: from localhost.localdomain (nat-1-36.msu.umos.ru. [85.89.127.36]) by smtp.googlemail.com with ESMTPSA id r84sm997477lff.72.2018.01.19.13.13.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Jan 2018 13:13:23 -0800 (PST) From: Maksim Dzabraev To: gdb-patches@sourceware.org Cc: simon.marchi@polymtl.ca, Maxim Dzabraev Subject: [fix gdb segfault when it is working with incorrect debug info] Skip loop iteration after catch error Date: Sat, 20 Jan 2018 00:13:20 +0300 Message-Id: <20180119211320.24031-1-dzabraew@gmail.com> From: Maxim Dzabraev 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 --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 + + * cp-valprint.c (cp_print_value_fields): Execute + "continue" in loop iteration if catch error. + 2017-12-31 Ruslan Kabatsayev * 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, _(""), 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 + + * gdb.cp/print-regex.exp: Test gdb doesn't get segfault + when it is printing std::regex. + 2017-12-27 Stafford Horne * 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 + +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 . */ + + +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"