[PR,31727,for,gdb-15-branch] Recognize -2 as a tombstone value in .debug_line

Message ID 20240904130529.3172-1-dmitry.neverov@jetbrains.com
State New
Headers
Series [PR,31727,for,gdb-15-branch] Recognize -2 as a tombstone value in .debug_line |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-arm warning Patch is already merged
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 warning Patch is already merged

Commit Message

Dmitry.Neverov Sept. 4, 2024, 1:05 p.m. UTC
  Commit a8caed5d7faa639a1e6769eba551d15d8ddd9510 handled the tombstone
value -1 used by lld (https://reviews.llvm.org/D81784).  The
referenced lld commit also uses the tombstone value -2 for
pre-DWARF-v5
(https://github.com/llvm/llvm-project/commit/e618ccbf431f6730edb6d1467a127c3a52fd57f7).

If not handled, -2 breaks the pc step range calculation and triggers
the assertion:

  gdb/infrun.c:2794: internal-error: resume_1: Assertion
  `pc_in_thread_step_range (pc, tp)' failed.

This commit adds -2 tombstone value and handles it in the same way as -1.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31727
Cherry-picked from e814012b2b108743e21b7ef2799310a0f4e0a86d
---
 gdb/dwarf2/read.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
  

Comments

Dmitry.Neverov Sept. 4, 2024, 1:06 p.m. UTC | #1
Submitting the patch for gdb-15-branch as was requested in
https://sourceware.org/pipermail/gdb-patches/2024-September/211505.html.

I ran tests on linux/x64, got the same failures with and without
the patch:

FAIL: gdb.base/branch-to-self.exp: single-step: si
FAIL: gdb.base/break-interp.exp: ldprelink=NO: ldsepdebug=NO: first backtrace: dl bt
FAIL: gdb.base/break-interp.exp: ldprelink=NO: ldsepdebug=NO: binprelink=NO: binsepdebug=NO: binpie=NO: INNER: first backtrace: dl bt
FAIL: gdb.base/break-interp.exp: ldprelink=NO: ldsepdebug=NO: binprelink=NO: binsepdebug=NO: binpie=YES: INNER: first backtrace: dl bt
FAIL: gdb.base/break-interp.exp: ldprelink=NO: ldsepdebug=NO: binprelink=NO: binsepdebug=IN: binpie=NO: INNER: first backtrace: dl bt
FAIL: gdb.base/break-interp.exp: ldprelink=NO: ldsepdebug=NO: binprelink=NO: binsepdebug=IN: binpie=YES: INNER: first backtrace: dl bt
FAIL: gdb.base/break-interp.exp: ldprelink=NO: ldsepdebug=NO: binprelink=NO: binsepdebug=SEP: binpie=NO: INNER: first backtrace: dl bt
FAIL: gdb.base/break-interp.exp: ldprelink=NO: ldsepdebug=NO: binprelink=NO: binsepdebug=SEP: binpie=YES: INNER: first backtrace: dl bt
FAIL: gdb.base/break-interp.exp: ldprelink=NO: ldsepdebug=IN: first backtrace: dl bt
FAIL: gdb.base/break-interp.exp: ldprelink=NO: ldsepdebug=IN: binprelink=NO: binsepdebug=NO: binpie=NO: INNER: first backtrace: dl bt
FAIL: gdb.base/break-interp.exp: ldprelink=NO: ldsepdebug=IN: binprelink=NO: binsepdebug=NO: binpie=YES: INNER: first backtrace: dl bt
FAIL: gdb.base/break-interp.exp: ldprelink=NO: ldsepdebug=IN: binprelink=NO: binsepdebug=IN: binpie=NO: INNER: first backtrace: dl bt
FAIL: gdb.base/break-interp.exp: ldprelink=NO: ldsepdebug=IN: binprelink=NO: binsepdebug=IN: binpie=YES: INNER: first backtrace: dl bt
FAIL: gdb.base/break-interp.exp: ldprelink=NO: ldsepdebug=IN: binprelink=NO: binsepdebug=SEP: binpie=NO: INNER: first backtrace: dl bt
FAIL: gdb.base/break-interp.exp: ldprelink=NO: ldsepdebug=IN: binprelink=NO: binsepdebug=SEP: binpie=YES: INNER: first backtrace: dl bt
FAIL: gdb.base/empty-host-env-vars.exp: env_var_name=HOME: show index-cache directory
FAIL: gdb.base/new-ui.exp: do_test_invalid_args: new-ui with tui

The don't seem to be related to the patch.

--
Dmitry
  
Tom Tromey Sept. 4, 2024, 6:19 p.m. UTC | #2
>>>>> "Dmitry" == Dmitry Neverov <dmitry.neverov@jetbrains.com> writes:

I replied in another thread but FAOD:

Dmitry> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31727
Dmitry> Cherry-picked from e814012b2b108743e21b7ef2799310a0f4e0a86d

Approved-By: Tom Tromey <tom@tromey.com>

thanks,
Tom
  

Patch

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 4818da58acb..2bdb022c4e2 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -17914,8 +17914,8 @@  class lnp_state_machine
      we're processing the end of a sequence.  */
   void record_line (bool end_sequence);
 
-  /* Check ADDRESS is -1, or zero and less than UNRELOCATED_LOWPC, and if true
-     nop-out rest of the lines in this sequence.  */
+  /* Check ADDRESS is -1, -2, or zero and less than UNRELOCATED_LOWPC, and if
+     true nop-out rest of the lines in this sequence.  */
   void check_line_address (struct dwarf2_cu *cu,
 			   const gdb_byte *line_ptr,
 			   unrelocated_addr unrelocated_lowpc,
@@ -18325,13 +18325,16 @@  lnp_state_machine::check_line_address (struct dwarf2_cu *cu,
 				       unrelocated_addr unrelocated_lowpc,
 				       unrelocated_addr address)
 {
-  /* Linkers resolve a symbolic relocation referencing a GC'd function to 0 or
-     -1.  If ADDRESS is 0, ignoring the opcode will err if the text section is
+  /* Linkers resolve a symbolic relocation referencing a GC'd function to 0,
+     -1 or -2 (-2 is used by certain lld versions, see
+     https://github.com/llvm/llvm-project/commit/e618ccbf431f6730edb6d1467a127c3a52fd57f7).
+     If ADDRESS is 0, ignoring the opcode will err if the text section is
      located at 0x0.  In this case, additionally check that if
      ADDRESS < UNRELOCATED_LOWPC.  */
 
   if ((address == (unrelocated_addr) 0 && address < unrelocated_lowpc)
-      || address == (unrelocated_addr) -1)
+      || address == (unrelocated_addr) -1
+      || address == (unrelocated_addr) -2)
     {
       /* This line table is for a function which has been
 	 GCd by the linker.  Ignore it.  PR gdb/12528 */