File: missing-type-name-for-templates.exp

package info (click to toggle)
gdb-doc 16.3-1
  • links: PTS, VCS
  • area: non-free
  • in suites: forky, sid, trixie
  • size: 244,264 kB
  • sloc: ansic: 2,134,731; asm: 375,582; exp: 206,875; cpp: 73,639; makefile: 70,232; sh: 26,038; python: 13,697; yacc: 11,341; ada: 7,358; xml: 6,098; perl: 5,077; pascal: 3,389; tcl: 2,986; f90: 2,764; lisp: 1,984; cs: 879; lex: 738; sed: 228; awk: 181; objc: 137; fortran: 57
file content (168 lines) | stat: -rw-r--r-- 4,414 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# Copyright 2022-2024 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 <http://www.gnu.org/licenses/>.

# This tests GDB's handling of DW_TAG_template_type_parameter and
# DW_TAG_template_value_parameter tags that do not have a DW_AT_name attribute.
# The attribute is optional for the tags and a bug about GDB not recording
# the respective symbols (because of the missing name) was reported in PR
# gdb/28396.

load_lib dwarf.exp

require dwarf2_support

standard_testfile .cc .S

set asm_file [standard_output_file $srcfile2]
Dwarf::assemble $asm_file {
    cu {} {
	DW_TAG_compile_unit {
	    {DW_AT_language @DW_LANG_C_plus_plus}
	} {
	    declare_labels int float template_var1 template_var2 template_var3

	    int: DW_TAG_base_type {
		{DW_AT_name "int"}
		{DW_AT_byte_size 4 DW_FORM_data1}
		{DW_AT_encoding @DW_ATE_signed}
	    }

	    float: base_type {
		{DW_AT_name float}
		{DW_AT_byte_size 4 DW_FORM_sdata}
		{DW_AT_encoding @DW_ATE_float}
	    }

	    DW_TAG_subprogram {
		{DW_AT_name "main"}
		{MACRO_AT_range "main"}
		{DW_AT_type :$int}
		{DW_AT_external 1 DW_FORM_flag}
	    } {
		DW_TAG_variable {
		    {DW_AT_name "var1"}
		    {DW_AT_type :$template_var1}
		}
		DW_TAG_variable {
		    {DW_AT_name "var2"}
		    {DW_AT_type :$template_var2}
		}
		DW_TAG_variable {
		    {DW_AT_name "var3"}
		    {DW_AT_type :$template_var3}
		}
	    }

	    # A variable whose type is a template instantiation with two
	    # template parameters, one unnamed.
	    template_var1: DW_TAG_structure_type {
		{DW_AT_name "template_var1<int, float>"}
	    } {
		DW_TAG_member {
		    {DW_AT_name "me"}
		    {DW_AT_type :$int}
		}
		DW_TAG_member {
		    {DW_AT_name "me2"}
		    {DW_AT_type :$float}
		}
		DW_TAG_template_type_param {
		    {DW_AT_type :$int}
		}
		DW_TAG_template_type_param {
		    {DW_AT_name "second"}
		    {DW_AT_type :$float}
		}
	    }

	    # A variable whose type is a template instantiation with two
	    # template parameters, both unnamed.
	    template_var2: DW_TAG_class_type {
		{DW_AT_name "template_var2<int, float>"}
	    } {
		DW_TAG_member {
		    {DW_AT_name "me"}
		    {DW_AT_type :$int}
		}
		DW_TAG_member {
		    {DW_AT_name "me2"}
		    {DW_AT_type :$float}
		}
		DW_TAG_template_type_param {
		    {DW_AT_type :$int}
		}
		DW_TAG_template_type_param {
		    {DW_AT_type :$float}
		}
	    }

	    # A variable whose type is a template instantiation with four
	    # template arguments, two types, two values, all unnamed.
	    template_var3: DW_TAG_structure_type {
		{DW_AT_name "template_var3<0, int, 11, float>"}
	    } {
		DW_TAG_member {
		    {DW_AT_name "me"}
		    {DW_AT_type :$int}
		}
		DW_TAG_member {
		    {DW_AT_name "me2"}
		    {DW_AT_type :$float}
		}
		DW_TAG_template_value_param {
		    {DW_AT_type :$int}
		    {DW_AT_const_value 0 DW_FORM_sdata}
		}
		DW_TAG_template_type_param {
		    {DW_AT_type :$int}
		}
		DW_TAG_template_value_param {
		    {DW_AT_type :$int}
		    {DW_AT_const_value 11 DW_FORM_sdata}
		}
		DW_TAG_template_type_param {
		    {DW_AT_type :$float}
		}
	    }
	}
    }
}

if { [prepare_for_testing "failed to prepare" ${testfile} \
	[list $srcfile $asm_file] {nodebug c++}] } {
    return -1
}

if ![runto_main] {
    return -1
}

gdb_test "ptype var1" [multi_line \
    "type = struct template_var1<int, float> \\\[with <unnamed0> = int, second = float\\\] {" \
    "    <unnamed0> me;" \
    "    second me2;" \
    "}"]

gdb_test "ptype var2" [multi_line \
    "type = class template_var2<int, float> \\\[with <unnamed0> = int, <unnamed1> = float\\\] {" \
    "    <unnamed0> me;" \
    "    <unnamed1> me2;" \
    "}"]

gdb_test "ptype var3" [multi_line \
    "type = struct template_var3<0, int, 11, float> \\\[with <unnamed1> = int, <unnamed3> = float\\\] {" \
    "    <unnamed1> me;" \
    "    <unnamed3> me2;" \
    "}"]