From patchwork Mon Oct 14 00:18:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Buettner X-Patchwork-Id: 34931 Received: (qmail 39217 invoked by alias); 14 Oct 2019 00:19:11 -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 39172 invoked by uid 89); 14 Oct 2019 00:19:11 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-16.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_NUMSUBJECT, KAM_SHORT, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=foundation, Foundation, foo_label, sk:implref X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 14 Oct 2019 00:19:09 +0000 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 30D6C3084051 for ; Mon, 14 Oct 2019 00:19:08 +0000 (UTC) Received: from f30-1.lan (ovpn-118-26.phx2.redhat.com [10.3.118.26]) by smtp.corp.redhat.com (Postfix) with ESMTP id B4DEE5D6A3; Mon, 14 Oct 2019 00:19:07 +0000 (UTC) From: Kevin Buettner To: gdb-patches@sourceware.org Cc: Kevin Buettner Subject: [PATCH 2/2] Test case for BZ 25065 Date: Sun, 13 Oct 2019 17:18:42 -0700 Message-Id: <20191014001842.27413-3-kevinb@redhat.com> In-Reply-To: <20191014001842.27413-1-kevinb@redhat.com> References: <20191014001842.27413-1-kevinb@redhat.com> MIME-Version: 1.0 X-IsSubscribed: yes Running a GDB with the fix for BZ 25065 should cause these new tests to all pass. When run against a GDB without the fix, there will be 2 unresolved testcases. This is what I see in the gdb.sum file when I try it using a GDB without the fix: ERROR: GDB process no longer exists UNRESOLVED: gdb.dwarf2/imported-unit.exp: ptype main::Foo ERROR: Couldn't send ptype main::foo to GDB. UNRESOLVED: gdb.dwarf2/imported-unit.exp: ptype main::foo These are "unresolved" versus outright failures due to the fact that GDB dies (segfaults) during the running of the test. gdb/testsuite/ChangeLog: * gdb.dwarf2/imported-unit.exp: New file. * gdb.dwarf2/imported-unit.c: New file. --- gdb/testsuite/gdb.dwarf2/imported-unit.c | 56 ++++++++ gdb/testsuite/gdb.dwarf2/imported-unit.exp | 157 +++++++++++++++++++++ 2 files changed, 213 insertions(+) create mode 100644 gdb/testsuite/gdb.dwarf2/imported-unit.c create mode 100644 gdb/testsuite/gdb.dwarf2/imported-unit.exp diff --git a/gdb/testsuite/gdb.dwarf2/imported-unit.c b/gdb/testsuite/gdb.dwarf2/imported-unit.c new file mode 100644 index 0000000000..3c665c507e --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/imported-unit.c @@ -0,0 +1,56 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2019 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 . */ + +/* Using the DWARF assembler - see imported-unit.exp - we'll be constructing + debug info corresponding to the following C++ code that also might have + been compiled using -flto... + + int main() + { + class Foo { + public: + int doit () + { + return 0; + } + }; + + Foo foo; + + return foo.doit (); + } + + An attempt was made to try to use the above code directly, but + finding the start and end address of doit turned out to be + difficult. +*/ + + +int doit (void) +{ + asm ("doit_label: .globl doit_label"); + + return 0; +} + +int +main (int argc, char *argv[]) +{ + asm ("main_label: .globl main_label"); + + return doit (); +} diff --git a/gdb/testsuite/gdb.dwarf2/imported-unit.exp b/gdb/testsuite/gdb.dwarf2/imported-unit.exp new file mode 100644 index 0000000000..25d44874c1 --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/imported-unit.exp @@ -0,0 +1,157 @@ +# Copyright 2019 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 . + +# Import a CU into an "artificial" CU. For each DW_TAG DIE in the +# artificial CU, use DW_AT_abstract_origin to refer to a DIE in the +# imported CU. This DWARF file organization is frequently found in +# programs compiled with -flto (and -g) using GCC. +# +# This test reproduces the bug described in BZ 25065 without relying +# on specific compiler versions or use of optimization switches, in +# this case -flto. + +if [skip_cplus_tests] { + continue +} + +load_lib dwarf.exp + +# This test can only be run on targets which support DWARF-2 and use gas. +if {![dwarf2_support]} { + return 0 +}; + +standard_testfile .c .S + +# ${testfile} is now "implref-struct". srcfile2 is "implref-struct.S". +set executable ${testfile} +set asm_file [standard_output_file ${srcfile2}] + +# We need to know the size of integer and address types in order +# to write some of the debugging info we'd like to generate. +if [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} {debug c++}] { + return -1 +} + +# Create the DWARF. +Dwarf::assemble $asm_file { + declare_labels cu_label main_label doit_label int_label + declare_labels Foo_label Foo_pointer_type doit_self_label + declare_labels foo_label Foo_destructor_obj_pointer_label + declare_labels Foo_constructor_obj_pointer_label + set int_size [get_sizeof "int" 4] + set addr_size [get_sizeof "void *" 8] + + global srcdir subdir srcfile + + extern main + extern doit + + set main_range [function_range main ${srcdir}/${subdir}/${srcfile}] + set main_start [lindex $main_range 0] + set main_length [lindex $main_range 1] + + set doit_range [function_range doit ${srcdir}/${subdir}/${srcfile}] + set doit_start [lindex $doit_range 0] + set doit_length [lindex $doit_range 1] + + cu {} { + compile_unit { + {language @DW_LANG_C_plus_plus} + {name ""} + } { + imported_unit { + {import :$cu_label ref_addr} + } + subprogram { + {abstract_origin :$main_label} + {low_pc $main_start addr} + {high_pc "$main_start + $main_length" addr} + } { + subprogram { + {abstract_origin :$doit_label} + {low_pc $doit_start addr} + {high_pc "$doit_start + $doit_length" addr} + } { + formal_parameter { + {abstract_origin :$doit_self_label} + } + } + DW_TAG_variable { + {abstract_origin :$foo_label} + {location 4 data1} + } + } + } + } + + cu {} { + cu_label: compile_unit { + {language @DW_LANG_C_plus_plus} + {name "imported_unit.c"} + } { + int_label: base_type { + {byte_size $int_size sdata} + {encoding @DW_ATE_signed} + {name int} + } + + main_label: subprogram { + {name main} + {type :$int_label} + {external 1 flag} + } { + Foo_label: class_type { + {name Foo} + {byte_size 1 sdata} + } { + doit_label: subprogram { + {name doit} + {type :$int_label} + {accessibility 1 DW_FORM_data1} + } { + doit_self_label: formal_parameter { + {name this} + {artificial 1 DW_FORM_flag_present} + {type :$Foo_pointer_type} + } + } + Foo_pointer_type: pointer_type { + {byte_size $addr_size sdata} + {type :$Foo_label} + } + } + foo_label: DW_TAG_variable { + {name foo} + {type :$Foo_label} + } + } + } + } +} + +if { [prepare_for_testing "failed to prepare" ${testfile} \ + [list $srcfile $asm_file] {nodebug}] } { + return -1 +} + +gdb_test_no_output "set language c++" + +# Sanity check +gdb_test "ptype main" "= int \\(void\\)" + +# Each of these tests caused a segfault prior to fixing BZ 25065. +gdb_test "ptype main::Foo" "= class Foo \{\\s+public:\\s+int doit\\(void\\);\\s+\}" +gdb_test "ptype main::foo" "= class Foo \{\\s+public:\\s+int doit\\(void\\);\\s+\}"