Files
binutils-gdb/gdb/testsuite/gdb.dwarf2/dw2-lines.exp
Tom de Vries 3bd0f5c4d9 [gdb/testsuite] Fix gdb.dwarf2/dw2-lines.exp on arm-linux
With test-case gdb.dwarf2/dw2-lines.exp on arm-linux, I run into:
...
(gdb) break bar_label^M
Breakpoint 2 at 0x4004f6: file dw2-lines.c, line 29.^M
(gdb) continue^M
Continuing.^M
^M
Breakpoint 2, bar () at dw2-lines.c:29^M
29        foo (2);^M
(gdb) PASS: $exp: cv=2: cdw=32: lv=2: ldw=32: continue to breakpoint: foo \(1\)
...

The pass is incorrect because the continue lands at line 29 with "foo (2)"
instead of line line 27 with "foo (1)".

A minimal version is:
...
$ gdb -q -batch dw2-lines.cv-2-cdw-32-lv-2-ldw-32 -ex "b bar_label"
Breakpoint 1 at 0x4f6: file dw2-lines.c, line 29.
...
where:
...
000004ec <bar>:
 4ec:	b580      	push	{r7, lr}
 4ee:	af00      	add	r7, sp, #0

000004f0 <bar_label>:
 4f0:	2001      	movs	r0, #1
 4f2:	f7ff fff1 	bl	4d8 <foo>

000004f6 <bar_label_2>:
 4f6:	2002      	movs	r0, #2
 4f8:	f7ff ffee 	bl	4d8 <foo>
...

So, how does this happen?  In short:
- skip_prologue_sal calls arm_skip_prologue with pc == 0x4ec,
- thumb_analyze_prologue returns 0x4f2
  (overshooting by 1 insn, PR tdep/31981), and
- skip_prologue_sal decides that we're mid-line, and updates to 0x4f6.

However, this is a test-case about .debug_line info, so why didn't arm_skip_prologue
use the line info to skip the prologue?

The answer is that the line info starts at bar_label, not at bar.

Fixing that allows us to work around PR tdep/31981.

Likewise in gdb.dwarf2/dw2-line-number-zero.exp.

Instead, add a new test-case gdb.arch/skip-prologue.exp that is dedicated to
checking quality of architecture-specific prologue analysis, without being
written in an architecture-specific way.

If fails on arm-linux for both marm and mthumb:
...
FAIL: gdb.arch/skip-prologue.exp: f2: $bp_addr == $prologue_end_addr (skipped too much)
FAIL: gdb.arch/skip-prologue.exp: f4: $bp_addr == $prologue_end_addr (skipped too much)
...
and passes for:
- x86_64-linux for {m64,m32}x{-fno-PIE/-no-pie,-fPIE/-pie}
- aarch64-linux.

Tested on arm-linux.
2024-09-04 10:07:19 +02:00

182 lines
4.2 KiB
Plaintext

# Copyright 2021-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 line number information in various configurations.
load_lib dwarf.exp
# This test can only be run on targets which support DWARF-2 and use gas.
require dwarf2_support
standard_testfile .c
with_shared_gdb {
set func_info_vars \
[concat \
[get_func_info main] \
[get_func_info bar]]
}
# Helper function.
proc line_for { l } {
global srcfile
set line [gdb_get_line_number "$l:" $srcfile]
return [expr $line + 1]
}
# Execute test.
proc test_1 { _cv _cdw64 _lv _ldw64 {_string_form ""}} {
global srcfile srcfile2 testfile
global cv cdw64 lv ldw64 string_form
set cv $_cv
set cdw64 $_cdw64
set lv $_lv
set ldw64 $_ldw64
set string_form $_string_form
standard_testfile .c [prefix_id]-dw.S
set asm_file [standard_output_file $srcfile2]
Dwarf::assemble $asm_file {
declare_labels Llines
global srcdir subdir srcfile cv cdw64 lv ldw64 string_form
global func_info_vars
foreach var $func_info_vars {
global $var
}
cu { version $cv is_64 $cdw64 } {
compile_unit {
{language @DW_LANG_C}
{name $srcfile}
{stmt_list $Llines DW_FORM_sec_offset}
} {
subprogram {
{external 1 flag}
{name main}
{low_pc $main_start addr}
{high_pc "$main_start + $main_len" addr}
}
subprogram {
{external 1 flag}
{name bar}
{low_pc $bar_start addr}
{high_pc "$bar_start + $bar_len" addr}
}
}
}
lines [list version $lv is_64 $ldw64 string_form $string_form] Llines {
set diridx [include_dir "${srcdir}/${subdir}"]
file_name "$srcfile" $diridx
program {
# If using DWARF 5, we want to refer to file 0, but the LNP
# state machine is still initialized with file 1. So we need
# to set the current file explicitly.
DW_LNS_set_file $diridx
DW_LNE_set_address $bar_start
line [line_for bar]
DW_LNS_copy
DW_LNE_set_address bar_label
line [line_for bar_label]
DW_LNS_copy
DW_LNE_set_address bar_label_2
line [line_for bar_label_2]
DW_LNS_copy
DW_LNE_set_address bar_label_3
line [line_for bar_label_3]
DW_LNS_copy
DW_LNE_set_address bar_label_4
line [line_for bar_label_4]
DW_LNS_copy
DW_LNE_set_address "$bar_start + $bar_len"
DW_LNE_end_sequence
}
}
}
if { [prepare_for_testing "failed to prepare" ${testfile}.[prefix_id] \
[list $srcfile $asm_file] {nodebug}] } {
return -1
}
if ![runto_main] {
return -1
}
gdb_breakpoint "bar_label"
gdb_continue_to_breakpoint "foo \\(1\\)"
gdb_test "next" "foo \\(2\\).*" "next to foo(2)"
gdb_test "next" "foo \\(3\\).*" "next to foo(3)"
gdb_test "next" "foo \\(4\\).*" "next to foo(4)"
}
# Add unique test prefix.
proc test { cv cdw64 lv ldw64 {string_form ""}} {
with_test_prefix cv=$cv {
with_test_prefix cdw=[expr $cdw64 ? 64 : 32] {
with_test_prefix lv=$lv {
with_test_prefix ldw=[expr $ldw64 ? 64 : 32] {
if { $string_form == "" } {
test_1 $cv $cdw64 $lv $ldw64
} else {
with_test_prefix string_form=$string_form {
test_1 $cv $cdw64 $lv $ldw64 $string_form
}
}
}
}
}
}
}
set cv_low 2
set cv_high 4
set lv_low 2
set lv_high 4
for { set cv $cv_low } { $cv <= $cv_high } { incr cv } {
for { set lv $lv_low } { $lv <= $lv_high } { incr lv } {
# I'm not sure if it makes sense to have a dwarf vx CU with
# a dwarf vx+1 line unit.
if { $lv > $lv } {
continue
}
foreach cdw64 { 0 1 } {
foreach ldw64 { 0 1 } {
test $cv $cdw64 $lv $ldw64
}
}
}
}
foreach cdw64 { 0 1 } {
foreach ldw64 { 0 1 } {
test 5 $cdw64 5 $ldw64 string
test 5 $cdw64 5 $ldw64 line_strp
}
}