Handle CRLF when reading XML on Windows
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.dwarf2 / imported-unit.exp
CommitLineData
d22670f0
KB
1# Copyright 2019 Free Software Foundation, Inc.
2
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation; either version 3 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16# Import a CU into an "artificial" CU. For each DW_TAG DIE in the
17# artificial CU, use DW_AT_abstract_origin to refer to a DIE in the
18# imported CU. This DWARF file organization is frequently found in
19# programs compiled with -flto (and -g) using GCC.
20#
21# This test reproduces the bug described in BZ 25065 without relying
22# on specific compiler versions or use of optimization switches, in
23# this case -flto.
24
25if [skip_cplus_tests] {
26 continue
27}
28
29load_lib dwarf.exp
30
31# This test can only be run on targets which support DWARF-2 and use gas.
32if {![dwarf2_support]} {
33 return 0
34};
35
36standard_testfile .c .S
37
38# ${testfile} is now "implref-struct". srcfile2 is "implref-struct.S".
39set executable ${testfile}
40set asm_file [standard_output_file ${srcfile2}]
41
42# We need to know the size of integer and address types in order
43# to write some of the debugging info we'd like to generate.
44if [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} {debug c++}] {
45 return -1
46}
47
48# Create the DWARF.
49Dwarf::assemble $asm_file {
50 declare_labels cu_label main_label doit_label int_label
51 declare_labels Foo_label Foo_pointer_type doit_self_label
52 declare_labels foo_label Foo_destructor_obj_pointer_label
53 declare_labels Foo_constructor_obj_pointer_label
54 set int_size [get_sizeof "int" 4]
55 set addr_size [get_sizeof "void *" 8]
56
57 global srcdir subdir srcfile
58
59 extern main
60 extern doit
61
62 set main_range [function_range main ${srcdir}/${subdir}/${srcfile}]
63 set main_start [lindex $main_range 0]
64 set main_length [lindex $main_range 1]
65
66 set doit_range [function_range doit ${srcdir}/${subdir}/${srcfile}]
67 set doit_start [lindex $doit_range 0]
68 set doit_length [lindex $doit_range 1]
69
70 cu {} {
71 compile_unit {
72 {language @DW_LANG_C_plus_plus}
73 {name "<artificial>"}
74 } {
75 imported_unit {
c14aab8c 76 {import %$cu_label}
d22670f0
KB
77 }
78 subprogram {
c14aab8c 79 {abstract_origin %$main_label}
d22670f0
KB
80 {low_pc $main_start addr}
81 {high_pc "$main_start + $main_length" addr}
82 } {
83 subprogram {
c14aab8c 84 {abstract_origin %$doit_label}
d22670f0
KB
85 {low_pc $doit_start addr}
86 {high_pc "$doit_start + $doit_length" addr}
87 } {
88 formal_parameter {
c14aab8c 89 {abstract_origin %$doit_self_label}
d22670f0
KB
90 }
91 }
92 DW_TAG_variable {
c14aab8c 93 {abstract_origin %$foo_label}
d22670f0
KB
94 {location 4 data1}
95 }
96 }
97 }
98 }
99
100 cu {} {
101 cu_label: compile_unit {
102 {language @DW_LANG_C_plus_plus}
103 {name "imported_unit.c"}
104 } {
105 int_label: base_type {
106 {byte_size $int_size sdata}
107 {encoding @DW_ATE_signed}
108 {name int}
109 }
110
111 main_label: subprogram {
112 {name main}
113 {type :$int_label}
114 {external 1 flag}
115 } {
116 Foo_label: class_type {
117 {name Foo}
118 {byte_size 1 sdata}
119 } {
120 doit_label: subprogram {
121 {name doit}
122 {type :$int_label}
123 {accessibility 1 DW_FORM_data1}
124 } {
125 doit_self_label: formal_parameter {
126 {name this}
127 {artificial 1 DW_FORM_flag_present}
128 {type :$Foo_pointer_type}
129 }
130 }
131 Foo_pointer_type: pointer_type {
132 {byte_size $addr_size sdata}
133 {type :$Foo_label}
134 }
135 }
136 foo_label: DW_TAG_variable {
137 {name foo}
138 {type :$Foo_label}
139 }
140 }
141 }
142 }
143}
144
145if { [prepare_for_testing "failed to prepare" ${testfile} \
146 [list $srcfile $asm_file] {nodebug}] } {
147 return -1
148}
149
150gdb_test_no_output "set language c++"
151
152# Sanity check
153gdb_test "ptype main" "= int \\(void\\)"
154
155# Each of these tests caused a segfault prior to fixing BZ 25065.
156gdb_test "ptype main::Foo" "= class Foo \{\\s+public:\\s+int doit\\(void\\);\\s+\}"
157gdb_test "ptype main::foo" "= class Foo \{\\s+public:\\s+int doit\\(void\\);\\s+\}"
This page took 0.043346 seconds and 4 git commands to generate.