binutils-gdb/gdb/testsuite/gdb.dwarf2/dw2-inline-header-2.exp
Andrew Burgess ef7a6b977b gdb/testsuite: remove global gcc_compiled from gdb.exp
After this commit the gcc_compiled global is no longer exported from
lib/gdb.exp.  In theory we could switch over all uses of gcc_compiled
to instead call test_compiler_info directly, however, I have instead
added a new proc to gdb.exp: 'is_c_compiler_gcc'.  I've then updated
the testsuite to call this proc instead of using the global.

Having a new proc specifically for this task means that we have a
single consistent pattern for detecting gcc.  By wrapping this logic
within a proc that calls test_compiler_info, rather than using the
global, means that test scripts don't need to call get_compiler_info
before they read the global, simply calling the new proc does
everything in one go.

As a result I've been able to remove the get_compiler_info calls from
all the test scripts that I've touched in this commit.

In some of the tests e.g. gdb.dwarf2/*.exp, the $gcc_compiled flag was
being checked at the top of the script to decide if the whole script
should be skipped or not.  In these cases I've called the new proc
directly and removed all uses of gcc_compiled.

In other cases, e.g. most of the gdb.base scripts, there were many
uses of gcc_compiled.  In these cases I set a new global gcc_compiled
near the top of the script, and leave the rest of the script
unchanged.

There should be no changes in what is tested after this commit.
2022-06-24 15:07:28 +01:00

187 lines
5.5 KiB
Plaintext

# Copyright 2020-2022 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/>.
# Setup a line table where:
#
# | Addr | File | Line | Stmt | Inline |
# |------|------|------|------|--------|
# | 1 | 1 | 16 | Y | |
# | 2 | 1 | 17 | Y | |
# | 3 | 2 | 21 | Y | X |
# | 4 | 2 | 22 | Y | X |
# | 4 | 1 | 18 | N | X |
# | 5 | 1 | 19 | Y | |
# | 6 | 1 | 20 | Y | |
# | 7 | 1 | END | Y | |
# |------|------|------|------|--------|
#
#
# Place the first brekpoint at file 2, line 22 and a second breakpoint
# at file 1, line 19. A third breakpoint is placed at file 1, line
# 18, but as this line table entry will have been discarded[1] the
# third breakpoint will actually be placed at the same location as the
# second breakpoint.
#
# This test is designed to test GDB's internal behaviour with respect
# to discarding particular line table entries. GCC and DWARF are
# starting to introduce the idea of line table views. As the views
# information becomes better supported within GDB it is likely that
# this will become out of date. This is fine, the test will have
# served its purpose by that point and can be deleted.
#
# [1] The entry for file 1, line 18 is discarded because it is at the
# same address as the previous entry, but the previous entry is-stmt,
# while line 18 is a non-stmt.
load_lib dwarf.exp
# This test can only be run on targets which support DWARF-2 and use gas.
if {![dwarf2_support]} {
return 0
}
# The .c files use __attribute__.
if ![is_c_compiler_gcc] {
return 0
}
standard_testfile dw2-inline-header-lbls.c dw2-inline-header.S \
dw2-inline-header.c dw2-inline-header.h
set build_options {nodebug optimize=-O1}
set asm_file [standard_output_file $srcfile2]
Dwarf::assemble $asm_file {
global srcdir subdir srcfile srcfile3 srcfile4
global build_options
declare_labels lines_label callee_subprog_label
get_func_info main $build_options
cu {} {
compile_unit {
{producer "gcc" }
{language @DW_LANG_C}
{name ${srcfile3}}
{low_pc 0 addr}
{stmt_list ${lines_label} DW_FORM_sec_offset}
} {
callee_subprog_label: subprogram {
{external 1 flag}
{name callee}
{inline 3 data1}
}
subprogram {
{external 1 flag}
{name main}
{low_pc $main_start addr}
{high_pc "$main_start + $main_len" addr}
} {
inlined_subroutine {
{abstract_origin %$callee_subprog_label}
{low_pc line_label_3 addr}
{high_pc line_label_5 addr}
{call_file 1 data1}
{call_line 18 data1}
}
}
}
}
lines {version 2 default_is_stmt 1} lines_label {
include_dir "${srcdir}/${subdir}"
file_name "$srcfile3" 1
file_name "$srcfile4" 1
program {
DW_LNE_set_address line_label_1
DW_LNS_advance_line 15
DW_LNS_copy
DW_LNE_set_address line_label_2
DW_LNS_advance_line 1
DW_LNS_copy
DW_LNS_set_file 2
DW_LNE_set_address line_label_3
DW_LNS_advance_line 4
DW_LNS_copy
DW_LNE_set_address line_label_4
DW_LNS_advance_line 1
DW_LNS_copy
DW_LNS_advance_line -4
DW_LNS_set_file 1
DW_LNS_negate_stmt
DW_LNS_copy
DW_LNE_set_address line_label_5
DW_LNS_advance_line 1
DW_LNS_negate_stmt
DW_LNS_copy
DW_LNE_set_address line_label_6
DW_LNS_advance_line 1
DW_LNS_copy
DW_LNE_set_address line_label_7
DW_LNE_end_sequence
}
}
}
if { [prepare_for_testing "failed to prepare" ${testfile} \
[list $srcfile $asm_file] $build_options] } {
return -1
}
if ![runto_main] {
return -1
}
# Delete all breakpoints so that the output of "info breakpoints"
# below will only contain a single breakpoint.
delete_breakpoints
# Place a breakpoint within the function in the header file.
gdb_breakpoint "${srcfile4}:22"
# Check that the breakpoint was placed where we expected. It should
# appear at the requested line. When the bug in GDB was present the
# breakpoint would be placed on one of the following lines instead.
gdb_test "info breakpoints" \
".* in callee at \[^\r\n\]+${srcfile4}:22\\y.*" \
"check for breakpoint at ${srcfile4}"
# Delete all breakpoints so that the output of "info breakpoints"
# below will only contain a single breakpoint.
delete_breakpoints
# Place a breakpoint within the function in the header file.
gdb_breakpoint "${srcfile3}:19"
# Check that the breakpoint was placed where we expected. It should
# appear at the requested line. When the bug in GDB was present the
# breakpoint would be placed on one of the following lines instead.
gdb_test "info breakpoints" \
".* in main at \[^\r\n\]+${srcfile3}:19\\y.*" \
"check for breakpoint at ${srcfile3}"
# Line table entry for line 18 will have been discarded, so this
# brekpoint will be at the same location as line 19.
gdb_test "break ${srcfile3}:18" \
"Note: breakpoint $decimal also set at pc $hex.*"