Currently there is a problem when debugging optimized code when the inferior stops at an inline sub-range end PC. It is unclear if that location is from the inline function or from the calling function. Therefore the call stack is often wrong. This patch detects the "weak" line table entries which are likely part of the previous inline block, and if we have such a location, it assumes the location belongs to the previous block. Additionally it may happen that the infrun machinery steps from one inline range to another inline range of the same inline function. That can look like jumping back and forth from the calling program to the inline function, while really the inline function just jumps from a hot to a cold section of the code, i.e. error handling. Additionally it may happen that one inline sub-range is empty or the inline is completely empty. But filtering that information away is not the right solution, since although there is no actual code from the inline, it is still possible that variables from an inline function can be inspected here. Conceptually this patch uses a heuristic to work around a deficiency in the dwarf-4 and dwarf-5 rnglists structure. There should be a location view number for each inline sub-range begin PC and end PC, similar to the DW_AT_GNU_entry_view which is the location view for the inline entry point. gdb: 2021-01-01 Bernd Edlinger * block.c (blockvector_for_pc_sect): For weak line table values, use the inline frame at PC - 1 if it is deeper. * dwarf2/read.c (dwarf2_rnglists_process, dwarf2_ranges_process): Don't ignore empty ranges here. (dwarf2_ranges_read): Ignore empty ranges here. (dwarf2_get_pc_bounds): Allow empty inlined subroutines. (partial_die_info::read): Likewise. (dwarf_finish_line): Add new parameter end_sequence. (lnp_state_machine::m_last_file, lnp_state_machine::m_last_address, lnp_state_machine::m_stmt_at_address): Remove data items. (lnp_state_machine::record_line): Do not filter line entries here, except for line == 0. Pass end_sequence to dwarf_finish_line. * infcmd.c (prepare_one_step): Ignore empty inline ranges. * infrun.c (process_event_stop_test): Don't stop in !is_stmt lines when stepping into inlines. Don't stop at the call site again, when stepping within inlined subroutines with multiple ranges. Don't refresh the step info the when executing !is_stmt lines of of a different inlined subroutine. * symtab.c (find_pc_sect_line): Handle is_weak. gdb/testsuite: 2021-01-01 Bernd Edlinger * gdb.base/empty-inline.exp: New test. * gdb.base/empty-inline.c: New test. * gdb.cp/empty-inline.exp: New test. * gdb.cp/empty-inline.cc: New test. * gdb.cp/step-and-next-inline.exp: Remove KFAILs, enhance test. * gdb.cp/step-and-next-inline.cc: Work around failure with gcc-9.3.0 from ubuntu 20.04. --- gdb/block.c | 15 ++- gdb/dwarf2/read.c | 84 +++---------- gdb/infcmd.c | 3 +- gdb/infrun.c | 33 ++++- gdb/symtab.c | 18 +-- gdb/testsuite/gdb.base/empty-inline.c | 43 +++++++ gdb/testsuite/gdb.base/empty-inline.exp | 50 ++++++++ gdb/testsuite/gdb.cp/empty-inline.cc | 33 +++++ gdb/testsuite/gdb.cp/empty-inline.exp | 55 ++++++++ gdb/testsuite/gdb.cp/step-and-next-inline.cc | 6 + gdb/testsuite/gdb.cp/step-and-next-inline.exp | 174 ++++++++++---------------- 11 files changed, 329 insertions(+), 185 deletions(-) create mode 100644 gdb/testsuite/gdb.base/empty-inline.c create mode 100644 gdb/testsuite/gdb.base/empty-inline.exp create mode 100644 gdb/testsuite/gdb.cp/empty-inline.cc create mode 100644 gdb/testsuite/gdb.cp/empty-inline.exp