1# Copyright 2020-2023 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/>.
15load_lib dwarf.exp
16
17# This test can only be run on targets which support DWARF-2 and use gas.
18if {![dwarf2_support]} {
19    return 0
20}
21
22standard_testfile main-foo.c .S
23
24# Make some DWARF for the test.
25set asm_file [standard_output_file $srcfile2]
26Dwarf::assemble $asm_file {
27    cu {} {
28	compile_unit {
29	    {DW_AT_language @DW_LANG_C}
30	    {DW_AT_name main.c}
31	} {
32	    structure_type {
33		{name s}
34		{signature 0x0000000000000001 ref_sig8}
35		{declaration 1 flag}
36	    }
37	    DW_TAG_subprogram {
38		{MACRO_AT_func {main}}
39	    }
40	}
41    }
42
43    cu {} {
44	compile_unit {
45	    {DW_AT_language @DW_LANG_C}
46	    {DW_AT_name     foo.c}
47	} {
48	    structure_type {
49		{name s}
50		{signature 0x0000000000000002 ref_sig8}
51		{declaration 1 flag}
52	    }
53	    DW_TAG_subprogram {
54		{MACRO_AT_func {foo}}
55	    }
56	}
57    }
58
59    tu {} 0x0000000000000001 the_type_i {
60	type_unit {} {
61	    declare_labels int_type
62
63	    the_type_i: structure_type {
64		{name s}
65		{byte_size 4 sdata}
66	    } {
67		member {
68		    {name i}
69		    {type :$int_type}
70		}
71	    }
72	    int_type: base_type {
73		{name int}
74		{encoding @DW_ATE_signed}
75		{byte_size 4 sdata}
76	    }
77	}
78    }
79
80    tu {} 0x0000000000000002 the_type_j {
81	type_unit {} {
82	    declare_labels int_type
83
84	    the_type_j: structure_type {
85		{name s}
86		{byte_size 4 sdata}
87	    } {
88		member {
89		    {name j}
90		    {type :$int_type}
91		}
92	    }
93	    int_type: base_type {
94		{name int}
95		{encoding @DW_ATE_signed}
96		{byte_size 4 sdata}
97	    }
98	}
99    }
100}
101
102if { [prepare_for_testing "failed to prepare" ${testfile} \
103	  [list $srcfile $asm_file] {nodebug}] } {
104    return -1
105}
106
107set struct_s_i_re \
108    [multi_line \
109	 "type = struct s {" \
110	 "    int i;" \
111	 "}"]
112set struct_s_j_re \
113    [multi_line \
114	 "type = struct s {" \
115	 "    int j;" \
116	 "}"]
117
118if ![runto_main] {
119    return -1
120}
121
122gdb_test "ptype struct s" $struct_s_i_re \
123    "struct s with int i"
124
125gdb_breakpoint "foo"
126gdb_continue_to_breakpoint "foo"
127
128gdb_test "ptype struct s" $struct_s_j_re \
129    "struct s with int j"
130