From patchwork Tue Oct 24 10:55:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Patrick Frants X-Patchwork-Id: 23777 Received: (qmail 30595 invoked by alias); 24 Oct 2017 10:55:56 -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 30097 invoked by uid 89); 24 Oct 2017 10:55:55 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.4 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-wm0-f65.google.com Received: from mail-wm0-f65.google.com (HELO mail-wm0-f65.google.com) (74.125.82.65) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 24 Oct 2017 10:55:53 +0000 Received: by mail-wm0-f65.google.com with SMTP id u138so14854516wmu.5 for ; Tue, 24 Oct 2017 03:55:53 -0700 (PDT) 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:mime-version :content-transfer-encoding; bh=F/9QAf5OvjRMrLTovFhyFbOLJpUbRFzXgUfgKuuskzs=; b=tAb7kNi0ZA0owMwWFe9J+7wf0l5gdaUtThcpwdN3uabHy5rIpdJjrTrRSROkhvgfVu OYLIKpAtyVT1Kuku3HGSEKH6HPUDwExdutdzeiVg8pOMVCxFzUP/h6XMGb+ig8W+Gi3J 6Tgon2jBX85rsUHI66NghrMDcErOQAAhFUCS/MHZyoqzwcsdhU18Ob4SI47QL19WOtrh TbukZPF2VXipxBq+frS4lr4TBZmNY52OGeIEDvjpnusP+S8d/Kn+DV6fx4dKGPyLQfD8 9iba6OrzzVbmPrqNdlmrdA96YRDVh7wQ3BkJYSmF2V7jJqgi3NAJnhFDBLb0WP0cd7AQ 4/2w== X-Gm-Message-State: AMCzsaX1pJH6gGp5GQJfPN3btqv7Mz+2rJrjbePWcD6VwONurUmwHTj8 /6MDyTFygbqL6mpl673cgSZYhGb0 X-Google-Smtp-Source: ABhQp+QxRufal+DGitnO8Lc+X3duBpzXcvW4nAXaT2ck3SidoQrEpLYSZc491LrFW4pn5mQ24dpEWw== X-Received: by 10.80.189.205 with SMTP id z13mr20006786edh.184.1508842551261; Tue, 24 Oct 2017 03:55:51 -0700 (PDT) Received: from centos7dev.quintiq.nl ([213.207.96.130]) by smtp.gmail.com with ESMTPSA id r15sm7820edi.52.2017.10.24.03.55.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 Oct 2017 03:55:50 -0700 (PDT) From: Patrick Frants To: gdb-patches@sourceware.org Cc: Patrick Frants Subject: [PATCH] Fix broken recursion detection when printing static members Date: Tue, 24 Oct 2017 12:55:35 +0200 Message-Id: <20171024105535.13287-1-osscontribute@gmail.com> MIME-Version: 1.0 The fix shrinks the stack using obstack_blank_fast() with a negative value as described at the bottom of this page: https://gcc.gnu.org/onlinedocs/libiberty/Extra-Fast-Growing.html "You can use obstack_blank_fast with a “negative” size argument to make the current object smaller. Just don’t try to shrink it beyond zero length—there’s no telling what will happen if you do that. Earlier versions of obstacks allowed you to use obstack_blank to shrink objects. This will no longer work." A unit test (gdb.cp/printstaticrecursion.exp) was added. No new regression has been observed in testsuite/gdb.cp/*.exp. --- gdb/cp-valprint.c | 9 ++----- gdb/testsuite/gdb.cp/printstaticrecursion.cc | 18 +++++++++++++ gdb/testsuite/gdb.cp/printstaticrecursion.exp | 37 +++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 7 deletions(-) create mode 100644 gdb/testsuite/gdb.cp/printstaticrecursion.cc create mode 100644 gdb/testsuite/gdb.cp/printstaticrecursion.exp diff --git a/gdb/cp-valprint.c b/gdb/cp-valprint.c index fb9bfd904f..927273f8a2 100644 --- a/gdb/cp-valprint.c +++ b/gdb/cp-valprint.c @@ -371,13 +371,8 @@ cp_print_value_fields (struct type *type, struct type *real_type, if (obstack_final_size > statmem_obstack_initial_size) { /* In effect, a pop of the printed-statics stack. */ - - void *free_to_ptr = - (char *) obstack_next_free (&dont_print_statmem_obstack) - - (obstack_final_size - statmem_obstack_initial_size); - - obstack_free (&dont_print_statmem_obstack, - free_to_ptr); + size_t shrink_bytes = statmem_obstack_initial_size - obstack_final_size; + obstack_blank_fast (&dont_print_statmem_obstack, shrink_bytes); } if (last_set_recurse != recurse) diff --git a/gdb/testsuite/gdb.cp/printstaticrecursion.cc b/gdb/testsuite/gdb.cp/printstaticrecursion.cc new file mode 100644 index 0000000000..40fd3c0c27 --- /dev/null +++ b/gdb/testsuite/gdb.cp/printstaticrecursion.cc @@ -0,0 +1,18 @@ +struct Inner +{ + static Inner instance; +}; + +struct Outer +{ + Inner inner; + static Outer instance; +}; + +Inner Inner::instance; +Outer Outer::instance; + +int main() +{ + return 0; /* break-here */ +} \ 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..a71adc7d03 --- /dev/null +++ b/gdb/testsuite/gdb.cp/printstaticrecursion.exp @@ -0,0 +1,37 @@ +# 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 . + + +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_test "print Outer::instance" "{inner = {static instance = {static instance = }}, static instance = {inner = {static instance = {static instance = }}, static instance = }}" "print recursive static member"