aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.dwarf2/rnglists-sec-offset.exp
blob: 7e7a610a809a2e40e76b179eeb2795d18b2f65c0 (plain)
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
# Copyright 2020-2023 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/>.

# Test DW_AT_ranges attributes referencing the .debug_rnglists section using the
# DW_FORM_sec_offset form.

load_lib dwarf.exp

require dwarf2_support

foreach_with_prefix is_64 {false true} {
    if { $is_64 } {
	standard_testfile main.c -dw64.S
	set testfile ${testfile}-dw64
    } else {
	standard_testfile main.c -dw32.S
	set testfile ${testfile}-dw32
    }

    set asm_file [standard_output_file $srcfile2]
    Dwarf::assemble $asm_file {
	global is_64

	declare_labels cu1_range_list cu2_range_list cu3_range_list
	declare_labels foo_range_list bar_range_list baz_range_list

	# This CU uses the DW_FORM_sec_offset form to refer to the .debug_rnglists
	# section.
	cu {
	    version 5
	    is_64 $is_64
	} {
	    DW_TAG_compile_unit {
		{DW_AT_ranges $cu1_range_list DW_FORM_sec_offset}
	    } {
		DW_TAG_subprogram {
		    {DW_AT_name "foo"}
		    {DW_AT_ranges $foo_range_list DW_FORM_sec_offset}
		}
	    }
	}

	# This CU uses the DW_FORM_sec_offset form to refer to the
	# .debug_rnglists section, but also has the DW_AT_rnglists_base
	# attribute present.  The DW_AT_rnglists_base attribute is not used to
	# interpret the DW_AT_ranges value, but it should also do no harm.
	cu {
	    version 5
	    is_64 $is_64
	} {
	    DW_TAG_compile_unit {
		{DW_AT_ranges $cu2_range_list DW_FORM_sec_offset}
		{DW_AT_rnglists_base cu2_table DW_FORM_sec_offset}
	    } {
		DW_TAG_subprogram {
		    {DW_AT_name "bar"}
		    {DW_AT_ranges $bar_range_list DW_FORM_sec_offset}
		}
	    }
	}

	# This CU uses the DW_FORM_sec_offset form to refer to the .debug_rnglists
	# section.  The corresponding contribution in the .debug_rnglists has no
	# offset array.
	cu {
	    version 5
	    is_64 $is_64
	} {
	    DW_TAG_compile_unit {
		{DW_AT_ranges $cu3_range_list DW_FORM_sec_offset}
	    } {
		DW_TAG_subprogram {
		    {DW_AT_name "baz"}
		    {DW_AT_ranges $baz_range_list DW_FORM_sec_offset}
		}
	    }
	}

	rnglists {is-64 $is_64} {
	    # The lists in this table are accessed by direct offset
	    # (DW_FORM_sec_offset).
	    table {} {
		# For the first CU.
		cu1_range_list: list_ {
		    start_end 0x4000 0x5000
		}

		# For function foo.
		foo_range_list: list_ {
		    start_end 0x4000 0x4010
		}
	    }

	    table {post-header-label cu2_table} {
		# For the second CU.
		cu2_range_list: list_ {
		    start_end 0x5000 0x6000
		}

		# For the bar function.
		bar_range_list: list_ {
		    start_end 0x5000 0x5010
		}
	    }

	    table {with-offset-array false} {
		# For the third CU.
		cu3_range_list: list_ {
		    start_end 0x6000 0x7000
		}

		# For the baz function.
		baz_range_list: list_ {
		    start_end 0x6000 0x6010
		}
	    }
	}
    }

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

    # Sanity checks to make sure GDB slurped the symbols correctly.
    gdb_test "p/x &foo" " = 0x4000"
    gdb_test "p/x &bar" " = 0x5000"
    gdb_test "p/x &baz" " = 0x6000"
}