From patchwork Sun Jun 14 04:48:43 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Galvan X-Patchwork-Id: 7161 Received: (qmail 24640 invoked by alias); 14 Jun 2015 04:49:02 -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 24619 invoked by uid 89); 14 Jun 2015 04:48:58 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-qk0-f179.google.com Received: from mail-qk0-f179.google.com (HELO mail-qk0-f179.google.com) (209.85.220.179) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Sun, 14 Jun 2015 04:48:57 +0000 Received: by qkx62 with SMTP id 62so37380686qkx.3 for ; Sat, 13 Jun 2015 21:48:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id; bh=rGuIGH82jeh9yjHZaOFWqxoFRR7lGzhuW7ExIknLdNY=; b=IHJJIVPBPgyXRLJ4RU434FIlyVGWJc6oODGzRXNDkpP4OW1gWvLrqurczxKUuIfjfc AhCZ691tj9CyvXrpjPkxx1vcmbrE5+8bNqGZtRshqTUR7zcCJkBkVNAiktVq9JEg6DYb ECleetdROe3Qyk3P6g2PJHPHHYtu4jDkO4T7ptCImNfRW8O5Ognk5RuQGvQS34Yxc4Ij WSzcI4aZWiaNiTXghG6pD6VoP4qStyrYG5gclnzBZ3fTGwWUdJJUZynGzIlcvq+oPCrr w7E48QGttVFEGuBHiJ2nT69cXBy+Y0lbk1VdJSzECwj0tE1j356Zm2ORY+sFcXaEyVs6 Mnbw== X-Gm-Message-State: ALoCoQkby/hY2/AnGCA48hL+kgJL6Bs/L3GWPyVFSMJWs6qgcBUd6aP2hshu+Ru8VUUbAytfizsA X-Received: by 10.140.237.68 with SMTP id i65mr29686946qhc.42.1434257334593; Sat, 13 Jun 2015 21:48:54 -0700 (PDT) Received: from localhost.localdomain ([181.31.101.84]) by mx.google.com with ESMTPSA id a102sm4233877qka.0.2015.06.13.21.48.52 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 13 Jun 2015 21:48:53 -0700 (PDT) From: Martin Galvan To: gdb-patches@sourceware.org, palves@redhat.com Subject: [PATCH v2] Fix gdb crash when trying to print the address of a synthetic pointer. Date: Sun, 14 Jun 2015 01:48:43 -0300 Message-Id: <1434257323-18553-1-git-send-email-martin.galvan@tallertechnologies.com> Changes in v2: * Added a test case to cover this. Trying to print the address of a synthetic pointer (such as a C++ reference after O3 optimization) will cause gdb to crash with the following message: ../gdb/dwarf2loc.c:1625: internal-error: Should not be able to create a lazy value with an enclosing type This patch fixes that by doing a check for synthetic pointers in value_addr and printing an error message. Ok to commit? gdb/ChangeLog: 2015-06-14 Martin Galvan * valops.c (value_addr): Don't try to get the address of a synthetic pointer. gdb/testsuite/ChangeLog: 2015-06-14 Martin Galvan * synthetic-pointer-reference.exp: New file. * synthetic-pointer-reference.cc: New file. --- .../gdb.dwarf2/synthetic-pointer-reference.cc | 32 ++++++++++++++++++ .../gdb.dwarf2/synthetic-pointer-reference.exp | 39 ++++++++++++++++++++++ gdb/valops.c | 6 ++++ 3 files changed, 77 insertions(+) create mode 100644 gdb/testsuite/gdb.dwarf2/synthetic-pointer-reference.cc create mode 100644 gdb/testsuite/gdb.dwarf2/synthetic-pointer-reference.exp diff --git a/gdb/testsuite/gdb.dwarf2/synthetic-pointer-reference.cc b/gdb/testsuite/gdb.dwarf2/synthetic-pointer-reference.cc new file mode 100644 index 0000000..36d775e --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/synthetic-pointer-reference.cc @@ -0,0 +1,32 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright (C) 2015 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 . */ + +#include + +static void function(int& arg) +{ + /* We do this to ensure that neither function nor arg are optimized out */ + printf("%d\n", arg); +} + +int main() +{ + int var = 42; + function(var); + + return 0; +} diff --git a/gdb/testsuite/gdb.dwarf2/synthetic-pointer-reference.exp b/gdb/testsuite/gdb.dwarf2/synthetic-pointer-reference.exp new file mode 100644 index 0000000..9e327f8 --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/synthetic-pointer-reference.exp @@ -0,0 +1,39 @@ +# Copyright (C) 2015 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 . +# This file is part of the gdb testsuite. + +# Test taking the address of a synthetic pointer created from a C++ reference. + +if { [skip_cplus_tests] } { continue } + +standard_testfile .cc + +set options {debug c++ optimize=-O3} + +if {[prepare_for_testing $testfile.exp $testfile $srcfile $options]} { + return -1 +} + +runto_main + +# If we tried to set a breakpoint and then 'continue' up to it, the program +# would exit without us hitting it because of the optimizations performed +# by gcc. We must advance using 'next' and 'step' instead. + +gdb_test "next" ".*" "next" +gdb_test "step" ".*function.*arg=.*" \ + "stepped inside 'function'; 'arg' is a synthetic pointer" +gdb_test "print &arg" "Attempt to take address of a synthetic pointer." \ + "Can't take the address of a synthetic pointer" diff --git a/gdb/valops.c b/gdb/valops.c index 66c63c1..1174a5e 100644 --- a/gdb/valops.c +++ b/gdb/valops.c @@ -1474,6 +1474,12 @@ value_addr (struct value *arg1) struct value *arg2; struct type *type = check_typedef (value_type (arg1)); + /* The TYPE_CODE_REF path below causes gdb to crash for synthetic pointers + created from C++ references. Catch those cases here. */ + if (value_bits_synthetic_pointer (arg1, value_embedded_offset (arg1), + TARGET_CHAR_BIT * TYPE_LENGTH (type))) + error (_("Attempt to take address of a synthetic pointer.")); + if (TYPE_CODE (type) == TYPE_CODE_REF) { /* Copy the value, but change the type from (T&) to (T*). We