This commit brings support for the DWARF line table is_stmt field to GDB. The is_stmt field is used by the compiler when a single source line is split into multiple assembler instructions, especially if the assembler instructions are interleaved with instruction from other source lines. The compiler will set the is_stmt flag false from some instructions from the source lines, these instructions are not a good place to insert a breakpoint in order to stop at the source line. Instructions which are marked with the is_stmt flag true are a good place to insert a breakpoint for that source line. Currently GDB ignores all instructions for which is_stmt is false. This is fine in a lot of cases, however, there are some cases where this means the debug experience is not as good as it could be. Consider stopping at a random instruction, currently this instruction will be attributed to the last line table entry before this point for which is_stmt was true - as these are the only line table entries that GDB tracks. This can easily be incorrect in code with even a low level of optimisation. With is_stmt tracking in place, when stopping at a random instruction we now attribute the instruction back to the real source line, even when is_stmt is false for that instruction in the line table. When inserting breakpoints we still select line table entries for which is_stmt is true, so the breakpoint placing behaviour should not change. When stepping though code (at the line level, not the instruction level) we will still stop at instruction where is_stmt is true, I think this is more likely to be the desired behaviour. Instruction stepping is, of course, unchanged, stepping one instruction at a time, but we should now report more accurate line table information with each instruction step. The original motivation for this work was a patch posted by Bernd here: https://sourceware.org/ml/gdb-patches/2019-11/msg00792.html As part of that thread it was suggested that many issues would be resolved if GDB supported line table views, this isn't something I've attempted in this patch, though reading the spec, it seems like this would be a useful feature to support in GDB in the future. The spec is here: http://dwarfstd.org/ShowIssue.php?issue=170427.1 And Bernd gives a brief description of the benefits here: https://sourceware.org/ml/gdb-patches/2020-01/msg00147.html With that all said, I think that there is benefit to having proper is_stmt support regardless of whether we have views support, so I think we should consider getting this in first, and then building view support on top of this. The gdb.cp/step-and-next-inline.exp test is based off a test proposed by Bernd Edlinger in this message: https://sourceware.org/ml/gdb-patches/2019-12/msg00842.html gdb/ChangeLog: * buildsym-legacy.c (record_line): Pass extra parameter to record_line. * buildsym.c (buildsym_compunit::record_line): Take an extra parameter, reduce duplication in the line table, and record the is_stmt flag in the line table. * buildsym.h (buildsym_compunit::record_line): Add extra parameter. * disasm.c (do_mixed_source_and_assembly_deprecated): Ignore non-statement lines. * dwarf2/read.c (dwarf_record_line_1): Add extra parameter, pass this to the symtab builder. (dwarf_finish_line): Pass extra parameter to dwarf_record_line_1. (lnp_state_machine::record_line): Pass a suitable is_stmt flag through to dwarf_record_line_1. * infrun.c (process_event_stop_test): When stepping, don't stop at a non-statement instruction, and only refresh the step info when we land in the middle of a line's range. Also add an extra comment. * jit.c (jit_symtab_line_mapping_add_impl): Initialise is_stmt field. * record-btrace.c (btrace_find_line_range): Only record lines marked as is-statement. * stack.c (frame_show_address): Show the frame address if we are in a non-statement sal. * symmisc.c (dump_symtab_1): Print the is_stmt flag. (maintenance_print_one_line_table): Print a header for the is_stmt column, and include is_stmt information in the output. * symtab.c (find_pc_sect_line): Find lines marked as statements in preference to non-statements. (find_pcs_for_symtab_line): Prefer is-statement entries. (find_line_common): Likewise. * symtab.h (struct linetable_entry): Add is_stmt field. (struct symtab_and_line): Likewise. * xcoffread.c (arrange_linetable): Initialise is_stmt field when arranging the line table. gdb/testsuite/ChangeLog: * gdb.cp/step-and-next-inline.cc: New file. * gdb.cp/step-and-next-inline.exp: New file. * gdb.cp/step-and-next-inline.h: New file. * gdb.dwarf2/dw2-is-stmt.c: New file. * gdb.dwarf2/dw2-is-stmt.exp: New file. * gdb.dwarf2/dw2-is-stmt-2.c: New file. * gdb.dwarf2/dw2-is-stmt-2.exp: New file. * gdb.dwarf2/dw2-ranges-base.exp: Update line table pattern.
266 lines
7.4 KiB
Plaintext
266 lines
7.4 KiB
Plaintext
# Copyright 2020 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 test shows the importance of not corrupting the order of line
|
|
# table information. When multiple lines are given for the same
|
|
# address the compiler usually lists these in the order in which we
|
|
# would expect to encounter them. When stepping through nested inline
|
|
# frames the last line given for an address is assumed by GDB to be
|
|
# the most inner frame, and this is what GDB displays.
|
|
#
|
|
# If we corrupt the order of the line table entries then GDB will
|
|
# display the wrong line as being the inner most frame.
|
|
|
|
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 [get_compiler_info] {
|
|
return -1
|
|
}
|
|
if !$gcc_compiled {
|
|
return 0
|
|
}
|
|
|
|
standard_testfile dw2-is-stmt-2.c dw2-is-stmt-2.S
|
|
|
|
# Extract the start, length, and end for function called NAME and
|
|
# create suitable variables in the callers scope.
|
|
proc get_func_info { name } {
|
|
global srcdir subdir srcfile
|
|
|
|
upvar 1 "${name}_start" func_start
|
|
upvar 1 "${name}_len" func_len
|
|
upvar 1 "${name}_end" func_end
|
|
|
|
lassign [function_range ${name} [list ${srcdir}/${subdir}/$srcfile]] \
|
|
func_start func_len
|
|
set func_end "$func_start + $func_len"
|
|
}
|
|
|
|
set asm_file [standard_output_file $srcfile2]
|
|
Dwarf::assemble $asm_file {
|
|
global srcdir subdir srcfile
|
|
declare_labels lines_label
|
|
|
|
get_func_info main
|
|
|
|
cu {} {
|
|
compile_unit {
|
|
{language @DW_LANG_C}
|
|
{name dw2-is-stmt.c}
|
|
{low_pc 0 addr}
|
|
{stmt_list ${lines_label} DW_FORM_sec_offset}
|
|
} {
|
|
subprogram {
|
|
{external 1 flag}
|
|
{name main}
|
|
{low_pc $main_start addr}
|
|
{high_pc "$main_start + $main_len" addr}
|
|
} {}
|
|
}
|
|
}
|
|
|
|
lines {version 2 default_is_stmt 1} lines_label {
|
|
include_dir "${srcdir}/${subdir}"
|
|
file_name "$srcfile" 1
|
|
|
|
program {
|
|
{DW_LNE_set_address main}
|
|
{DW_LNS_advance_line \
|
|
[expr [gdb_get_line_number "main prologue"] - 1]}
|
|
{DW_LNS_copy}
|
|
|
|
{DW_LNE_set_address line_label_0}
|
|
{DW_LNS_advance_line \
|
|
[expr [gdb_get_line_number "main start"] \
|
|
- [gdb_get_line_number "main prologue"]]}
|
|
{DW_LNS_copy}
|
|
|
|
{DW_LNE_set_address line_label_1}
|
|
{DW_LNS_advance_line \
|
|
[expr [gdb_get_line_number "Line 1"] \
|
|
- [gdb_get_line_number "main start"]]}
|
|
{DW_LNS_negate_stmt}
|
|
{DW_LNS_copy}
|
|
|
|
{DW_LNE_set_address line_label_2}
|
|
{DW_LNS_negate_stmt}
|
|
{DW_LNS_copy}
|
|
|
|
{DW_LNE_set_address line_label_3}
|
|
{DW_LNS_advance_line \
|
|
[expr [gdb_get_line_number "Line 2"] \
|
|
- [gdb_get_line_number "Line 1"]]}
|
|
{DW_LNS_negate_stmt}
|
|
{DW_LNS_copy}
|
|
|
|
{DW_LNE_set_address line_label_4}
|
|
{DW_LNS_advance_line \
|
|
[expr [gdb_get_line_number "Line 1"] \
|
|
- [gdb_get_line_number "Line 2"]]}
|
|
{DW_LNS_copy}
|
|
|
|
{DW_LNE_set_address line_label_5}
|
|
{DW_LNS_advance_line \
|
|
[expr [gdb_get_line_number "Line 3"] \
|
|
- [gdb_get_line_number "Line 1"]]}
|
|
{DW_LNS_copy}
|
|
|
|
{DW_LNE_set_address line_label_6}
|
|
{DW_LNS_advance_line \
|
|
[expr [gdb_get_line_number "Line 4"] \
|
|
- [gdb_get_line_number "Line 3"]]}
|
|
{DW_LNS_copy}
|
|
|
|
{DW_LNE_set_address line_label_7}
|
|
{DW_LNS_negate_stmt}
|
|
{DW_LNS_copy}
|
|
|
|
{DW_LNE_set_address line_label_8}
|
|
{DW_LNS_advance_line \
|
|
[expr [gdb_get_line_number "Line 2"] \
|
|
- [gdb_get_line_number "Line 4"]]}
|
|
{DW_LNS_copy}
|
|
|
|
{DW_LNE_set_address line_label_9}
|
|
{DW_LNS_negate_stmt}
|
|
{DW_LNS_copy}
|
|
|
|
{DW_LNE_set_address line_label_10}
|
|
{DW_LNS_advance_line \
|
|
[expr [gdb_get_line_number "Line 3"] \
|
|
- [gdb_get_line_number "Line 2"]]}
|
|
{DW_LNS_copy}
|
|
|
|
{DW_LNE_set_address line_label_11}
|
|
{DW_LNS_advance_line \
|
|
[expr [gdb_get_line_number "Line 5"] \
|
|
- [gdb_get_line_number "Line 3"]]}
|
|
{DW_LNS_copy}
|
|
|
|
{DW_LNE_set_address line_label_12}
|
|
{DW_LNS_negate_stmt}
|
|
{DW_LNS_copy}
|
|
|
|
{DW_LNE_set_address line_label_13}
|
|
{DW_LNS_advance_line \
|
|
[expr [gdb_get_line_number "Line 3"] \
|
|
- [gdb_get_line_number "Line 5"]]}
|
|
{DW_LNS_copy}
|
|
|
|
{DW_LNE_set_address line_label_14}
|
|
{DW_LNS_advance_line \
|
|
[expr [gdb_get_line_number "Line 4"] \
|
|
- [gdb_get_line_number "Line 3"]]}
|
|
{DW_LNS_negate_stmt}
|
|
{DW_LNS_copy}
|
|
|
|
{DW_LNE_set_address line_label_15}
|
|
{DW_LNS_advance_line \
|
|
[expr [gdb_get_line_number "Line 5"] \
|
|
- [gdb_get_line_number "Line 4"]]}
|
|
{DW_LNS_copy}
|
|
|
|
{DW_LNE_set_address line_label_16}
|
|
{DW_LNS_advance_line \
|
|
[expr [gdb_get_line_number "main end"] \
|
|
- [gdb_get_line_number "Line 5"]]}
|
|
{DW_LNS_negate_stmt}
|
|
{DW_LNS_copy}
|
|
|
|
{DW_LNE_set_address ${main_end}}
|
|
{DW_LNE_end_sequence}
|
|
}
|
|
}
|
|
}
|
|
|
|
if { [prepare_for_testing "failed to prepare" ${testfile} \
|
|
[list $srcfile $asm_file] {nodebug}] } {
|
|
return -1
|
|
}
|
|
|
|
if ![runto_main] {
|
|
return -1
|
|
}
|
|
|
|
# Check stepping through the out of order lines gives the experience
|
|
# we expect; lines in the correct order, and stop at the correct
|
|
# labels.Q
|
|
set locs { { "Line 1." "line_label_2" } \
|
|
{ "Line 4." "line_label_7" } \
|
|
{ "Line 2." "line_label_8" } \
|
|
{ "Line 5." "line_label_12" } \
|
|
{ "Line 3." "line_label_13" } }
|
|
foreach entry $locs {
|
|
set pattern [lindex $entry 0]
|
|
set label [lindex $entry 1]
|
|
|
|
set linum [gdb_get_line_number "$pattern"]
|
|
gdb_test "step" "\r\n$linum\[ \t\]+/\\* $pattern \\*/" \
|
|
"step to $pattern"
|
|
|
|
set pc [get_hexadecimal_valueof "\$pc" "NO-PC" \
|
|
"read \$pc at $pattern"]
|
|
set val [get_hexadecimal_valueof "&${label}" "INVALID"]
|
|
gdb_assert { $pc == $val } \
|
|
"check pc at $pattern"
|
|
}
|
|
|
|
# Now restart the test, and this time, single instruction step
|
|
# through. This is checking that the is-stmt marked lines are
|
|
# displayed differently (without addresses) to addresses that are
|
|
# mid-way through a line, or not marked as is-stmt.
|
|
clean_restart $binfile
|
|
runto_main
|
|
|
|
foreach entry $locs {
|
|
set pattern [lindex $entry 0]
|
|
set label [lindex $entry 1]
|
|
|
|
with_test_prefix "stepi to $label" {
|
|
# If can take many instruction steps to get to the next label.
|
|
set i 0
|
|
set pc [get_hexadecimal_valueof "\$pc" "NO-PC" ]
|
|
set val [get_hexadecimal_valueof "&${label}" "INVALID"]
|
|
while { $pc < $val } {
|
|
incr i
|
|
set line_changed -1
|
|
gdb_test_multiple "stepi" "stepi $i" {
|
|
-re "\r\n$hex\[ \t\]+$decimal\[^\r\n\]+\r\n$gdb_prompt" {
|
|
set line_changed 0
|
|
}
|
|
-re "\r\n$decimal\[ \t\]+/\\* $pattern \\*/\r\n$gdb_prompt" {
|
|
set line_changed 1
|
|
}
|
|
}
|
|
gdb_assert { $line_changed != -1 } \
|
|
"ensure we saw a valid pattern, $i"
|
|
set pc [get_hexadecimal_valueof "\$pc" "NO-PC" \
|
|
"get pc inside stepi loop, $i"]
|
|
if { $pc == $val } {
|
|
gdb_assert { $line_changed } \
|
|
"line must change at $label"
|
|
} else {
|
|
gdb_assert { !$line_changed } "same line $i"
|
|
}
|
|
}
|
|
}
|
|
}
|