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 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483
|
# Copyright 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/>.
# Test different ways in which DW_AT_entry_pc can be expressed in the
# DWARF. Also test with DWARF-4 and DWARF-5. See the individule test
# procs below precise details of what DW_AT_entry_pc forms are tested.
load_lib dwarf.exp
require dwarf2_support
standard_testfile
# This compiles the source file and starts and stops GDB, so run it
# before calling prepare_for_testing otherwise GDB will have exited.
get_func_info foo
if { [prepare_for_testing "failed to prepare" ${testfile} \
[list ${srcfile}]] } {
return -1
}
if ![runto_main] {
return -1
}
# Address for the middle of foo. This is used as our entry point when
# the entry_pc is defined as an address.
set foo_middle_addr [get_hexadecimal_valueof "&foo_middle" "UNKNOWN" \
"get address for middle of foo"]
# The FOO_START and FOO_END we get from get_func_info is an expression
# involving symbols and offsets. To check the 'maint info blocks'
# output we need these converted into actual addresses.
set foo_start_addr [get_hexadecimal_valueof "$foo_start" "UNKNOWN" \
"get address for start of foo"]
set foo_end_addr [get_hexadecimal_valueof "$foo_end" "UNKNOWN" \
"get address for end of foo"]
# The ranges within foo. Used when foo is defined using ranges rather
# than a low pc and high pc pair. The entry point is in the middle of
# the second range.
foreach var { r1_s r1_e r2_s r2_e r3_s r3_e } {
set $var [get_hexadecimal_valueof "&foo_$var" "UNKNOWN" \
"get address for foo_$var"]
}
# Line on which 'foo' is declared. Used in generated debug.
set foo_decl_line [gdb_get_line_number "foo decl line"]
if [is_ilp32_target] {
set ptr_type "data4"
} else {
set ptr_type "data8"
}
# Generate a suffix number. Called from each of the test procs below
# to acquire a unique suffix for naming asm files and executables.
set global_test_suffix 0
proc get_next_suffix {} {
global global_test_suffix
incr global_test_suffix
return $global_test_suffix
}
# Helper for the two build_and_test_* procs below. Combine ASM_FILE
# with the global SRCFILE and build an executable. Use SUFFIX to give
# the executable a unique name.
proc build_and_runto_main { suffix asm_file } {
if {[prepare_for_testing "failed to prepare" "${::testfile}-${suffix}" \
[list $::srcfile $asm_file] {nodebug}]} {
return false
}
if ![runto_main] {
return false
}
# Ensure the CU containing 'foo' is expanded, so the blocks are
# visible.
gdb_test "info function foo" \
"File \[^\r\n\]+/$::srcfile:\r\n$::foo_decl_line:\\s+void foo\\(\\);.*"
return true
}
# Combine ASM_FILE with the global SRCFILE and build an executable,
# use SUFFIX to make the executable name unique.
#
# Then check the blocks at the symbol `foo_middle'. The inner most
# block should be a block for 'foo' with a continuous address range
# and an entry address of ENTRY_PC.
proc build_and_test_continuous { suffix asm_file entry_pc } {
if { ![build_and_runto_main $suffix $asm_file] } {
return false
}
gdb_test "maint info blocks foo_middle" \
[multi_line \
"\\\[\[^\]\]+\\\] $::foo_start_addr\.\.$::foo_end_addr" \
" entry pc: $entry_pc" \
" function: foo" \
" is contiguous"]
}
# Combine ASM_FILE with the global SRCFILE and build an executable,
# use SUFFIX to make the executable name unique.
#
# Then check the blocks at the symbol `foo_middle'. The inner most
# block should be a block for 'foo' which has 3 address ranges and an
# entry address of ENTRY_PC.
proc build_and_test_ranged { suffix asm_file entry_pc } {
if { ![build_and_runto_main $suffix $asm_file] } {
return false
}
gdb_test "maint info blocks foo_middle" \
[multi_line \
"\\\[\[^\]\]+\\\] $::r1_s\.\.$::r3_e" \
" entry pc: $entry_pc" \
" function: foo" \
" address ranges:" \
" $::r1_s\.\.$::r1_e" \
" $::r2_s\.\.$::r2_e" \
" $::r3_s\.\.$::r3_e" ]
}
# The function's address range is defined using low/high bounds and
# the entry_pc attribute is not given. The function's entry PC will
# default to the low address.
proc_with_prefix use_low_high_bounds_without_entry_pc { dwarf_vesion } {
set suffix [get_next_suffix]
# Make some DWARF for the test.
set asm_file [standard_output_file "$::testfile-dw-$suffix.S"]
Dwarf::assemble $asm_file {
global srcfile
declare_labels lines_table
cu { version $::dwarf_version } {
compile_unit {
{producer "gcc"}
{language @DW_LANG_C}
{name ${srcfile}}
{comp_dir /tmp}
{stmt_list $lines_table DW_FORM_sec_offset}
} {
subprogram {
{name foo}
{decl_file 1 data1}
{decl_line $::foo_decl_line data1}
{decl_column 1 data1}
{low_pc $::foo_start addr}
{high_pc $::foo_len $::ptr_type}
{external 1 flag}
}
}
}
lines {version 2} lines_table {
include_dir "$::srcdir/$::subdir"
file_name "$srcfile" 1
}
}
build_and_test_continuous $suffix $asm_file $::foo_start_addr
}
# The function's address range is defined using low/high bounds and an
# entry_pc attribute is given (which contains an address), which will
# be used as the function's entry address.
proc_with_prefix use_low_high_bounds_with_entry_pc { dwarf_version } {
set suffix [get_next_suffix]
# Make some DWARF for the test.
set asm_file [standard_output_file "$::testfile-dw-$suffix.S"]
Dwarf::assemble $asm_file {
global srcfile
declare_labels lines_table
cu { version $::dwarf_version } {
compile_unit {
{producer "gcc"}
{language @DW_LANG_C}
{name ${srcfile}}
{comp_dir /tmp}
{stmt_list $lines_table DW_FORM_sec_offset}
} {
subprogram {
{name foo}
{decl_file 1 data1}
{decl_line $::foo_decl_line data1}
{decl_column 1 data1}
{low_pc $::foo_start addr}
{high_pc $::foo_len $::ptr_type}
{external 1 flag}
{entry_pc foo_middle addr}
}
}
}
lines {version 2} lines_table {
include_dir "$::srcdir/$::subdir"
file_name "$srcfile" 1
}
}
build_and_test_continuous $suffix $asm_file $::foo_middle_addr
}
# The function's address range is defined using low/high bounds and an
# entry_pc attribute is given (which contains an offset from the base
# address), which will be used to compute the function's entry address.
proc_with_prefix use_low_high_bounds_with_entry_offset { dwarf_version } {
set suffix [get_next_suffix]
# Make some DWARF for the test.
set asm_file [standard_output_file "$::testfile-dw-$suffix.S"]
Dwarf::assemble $asm_file {
global srcfile
declare_labels lines_table
set foo_offset [expr $::foo_middle_addr - $::foo_start_addr]
cu { version $::dwarf_version } {
compile_unit {
{producer "gcc"}
{language @DW_LANG_C}
{name ${srcfile}}
{comp_dir /tmp}
{stmt_list $lines_table DW_FORM_sec_offset}
} {
subprogram {
{name foo}
{decl_file 1 data1}
{decl_line $::foo_decl_line data1}
{decl_column 1 data1}
{low_pc $::foo_start addr}
{high_pc $::foo_len $::ptr_type}
{external 1 flag}
{entry_pc $foo_offset data4}
}
}
}
lines {version 2} lines_table {
include_dir "$::srcdir/$::subdir"
file_name "$srcfile" 1
}
}
build_and_test_continuous $suffix $asm_file $::foo_middle_addr
}
# The function's address range is defined using range information. No
# entry_pc attribute is used. The entry PC for the function will
# default to the first address of the first range.
proc_with_prefix use_ranges_without_entry_pc { dwarf_version } {
set suffix [get_next_suffix]
# Make some DWARF for the test.
set asm_file [standard_output_file "$::testfile-dw-$suffix.S"]
Dwarf::assemble $asm_file {
upvar dwarf_version dwarf_version
global srcfile
declare_labels lines_table ranges_label
cu { version $::dwarf_version } {
compile_unit {
{producer "gcc"}
{language @DW_LANG_C}
{name ${srcfile}}
{comp_dir /tmp}
{stmt_list $lines_table DW_FORM_sec_offset}
{low_pc 0 addr}
} {
subprogram {
{name foo}
{decl_file 1 data1}
{decl_line $::foo_decl_line data1}
{decl_column 1 data1}
{external 1 flag}
{ranges ${ranges_label} DW_FORM_sec_offset}
}
}
}
lines {version 2} lines_table {
include_dir "$::srcdir/$::subdir"
file_name "$srcfile" 1
}
if { $dwarf_version == 5 } {
rnglists {} {
table {} {
ranges_label: list_ {
start_end foo_r1_s foo_r1_e
start_end foo_r2_s foo_r2_e
start_end foo_r3_s foo_r3_e
}
}
}
} else {
ranges { } {
ranges_label: sequence {
range foo_r1_s foo_r1_e
range foo_r2_s foo_r2_e
range foo_r3_s foo_r3_e
}
}
}
}
build_and_test_ranged $suffix $asm_file $::r1_s
}
# The function's address range is defined using range information and
# an entry_pc attribute (which is an address) is used, this will be
# the entry PC for the function.
proc_with_prefix use_ranges_with_entry_pc { dwarf_version } {
set suffix [get_next_suffix]
# Make some DWARF for the test.
set asm_file [standard_output_file "$::testfile-dw-$suffix.S"]
Dwarf::assemble $asm_file {
upvar dwarf_version dwarf_version
global srcfile
declare_labels lines_table ranges_label
cu { version $::dwarf_version } {
compile_unit {
{producer "gcc"}
{language @DW_LANG_C}
{name ${srcfile}}
{comp_dir /tmp}
{stmt_list $lines_table DW_FORM_sec_offset}
{low_pc 0 addr}
} {
subprogram {
{name foo}
{decl_file 1 data1}
{decl_line $::foo_decl_line data1}
{decl_column 1 data1}
{external 1 flag}
{ranges ${ranges_label} DW_FORM_sec_offset}
{entry_pc foo_middle addr}
}
}
}
lines {version 2} lines_table {
include_dir "$::srcdir/$::subdir"
file_name "$srcfile" 1
}
if { $dwarf_version == 5 } {
rnglists {} {
table {} {
ranges_label: list_ {
start_end foo_r1_s foo_r1_e
start_end foo_r2_s foo_r2_e
start_end foo_r3_s foo_r3_e
}
}
}
} else {
ranges { } {
ranges_label: sequence {
range foo_r1_s foo_r1_e
range foo_r2_s foo_r2_e
range foo_r3_s foo_r3_e
}
}
}
}
build_and_test_ranged $suffix $asm_file $::foo_middle_addr
}
# The function's address range is defined using range information and
# an entry_pc attribute (which is an offset) is used, this will be
# used to calculate the entry PC for the function.
proc_with_prefix use_ranges_with_entry_offset { dwarf_version } {
set suffix [get_next_suffix]
# Make some DWARF for the test.
set asm_file [standard_output_file "$::testfile-dw-$suffix.S"]
Dwarf::assemble $asm_file {
upvar dwarf_version dwarf_version
global srcfile
declare_labels lines_table ranges_label
set foo_offset [expr $::foo_middle_addr - $::r1_s]
cu { version $::dwarf_version } {
compile_unit {
{producer "gcc"}
{language @DW_LANG_C}
{name ${srcfile}}
{comp_dir /tmp}
{stmt_list $lines_table DW_FORM_sec_offset}
{low_pc 0 addr}
} {
subprogram {
{name foo}
{decl_file 1 data1}
{decl_line $::foo_decl_line data1}
{decl_column 1 data1}
{external 1 flag}
{ranges ${ranges_label} DW_FORM_sec_offset}
{entry_pc $foo_offset data4}
}
}
}
lines {version 2} lines_table {
include_dir "$::srcdir/$::subdir"
file_name "$srcfile" 1
}
if { $dwarf_version == 5 } {
rnglists {} {
table {} {
ranges_label: list_ {
start_end foo_r1_s foo_r1_e
start_end foo_r2_s foo_r2_e
start_end foo_r3_s foo_r3_e
}
}
}
} else {
ranges { } {
ranges_label: sequence {
range foo_r1_s foo_r1_e
range foo_r2_s foo_r2_e
range foo_r3_s foo_r3_e
}
}
}
}
build_and_test_ranged $suffix $asm_file $::foo_middle_addr
}
# Run the tests.
foreach_with_prefix dwarf_version { 4 5 } {
use_low_high_bounds_without_entry_pc $dwarf_version
use_low_high_bounds_with_entry_offset $dwarf_version
use_low_high_bounds_with_entry_pc $dwarf_version
use_ranges_without_entry_pc $dwarf_version
use_ranges_with_entry_pc $dwarf_version
use_ranges_with_entry_offset $dwarf_version
}
|