[Lldb-commits] [lldb] r367983 - Fix line table resolution near the end of a section

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Mon Aug 5 23:52:05 PDT 2019


Author: labath
Date: Mon Aug  5 23:52:05 2019
New Revision: 367983

URL: http://llvm.org/viewvc/llvm-project?rev=367983&view=rev
Log:
Fix line table resolution near the end of a section

Summary:
lld r367537 changed the way the linker organizes sections and segments.
This exposed an lldb bug and caused some tests to fail.

In all of the failing tests the root cause was the same -- when we were
trying to resolve the last address in the line_table section, we failed
because it pointed past the end of the section.

This patch changes the line table address resolution code to back up the
address by one for end-of-sequence entries. This ensures the address
still points inside a section/module even if the line table sequence
ends at the very end of a section.

It also reverts the linker flags which were added to the failing tests
to restore previous behavior.

Reviewers: clayborg, jingham

Subscribers: mgorny, MaskRay, lldb-commits

Differential Revision: https://reviews.llvm.org/D65647

Modified:
    lldb/trunk/lit/SymbolFile/DWARF/debug-line-basic.s
    lldb/trunk/lit/SymbolFile/DWARF/dir-separator-no-comp-dir-relative-name.s
    lldb/trunk/lit/SymbolFile/DWARF/dir-separator-no-comp-dir.s
    lldb/trunk/lit/SymbolFile/DWARF/dir-separator-posix.s
    lldb/trunk/lit/SymbolFile/DWARF/dir-separator-windows.s
    lldb/trunk/source/Symbol/LineTable.cpp

Modified: lldb/trunk/lit/SymbolFile/DWARF/debug-line-basic.s
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/SymbolFile/DWARF/debug-line-basic.s?rev=367983&r1=367982&r2=367983&view=diff
==============================================================================
--- lldb/trunk/lit/SymbolFile/DWARF/debug-line-basic.s (original)
+++ lldb/trunk/lit/SymbolFile/DWARF/debug-line-basic.s Mon Aug  5 23:52:05 2019
@@ -1,7 +1,7 @@
 # REQUIRES: lld, x86
 
 # RUN: llvm-mc -triple x86_64-pc-linux %s -filetype=obj > %t.o
-# RUN: ld.lld -z separate-code %t.o -o %t
+# RUN: ld.lld %t.o -o %t
 # RUN: %lldb %t -o "image dump line-table -v a.c" -o exit | FileCheck %s
 
 

Modified: lldb/trunk/lit/SymbolFile/DWARF/dir-separator-no-comp-dir-relative-name.s
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/SymbolFile/DWARF/dir-separator-no-comp-dir-relative-name.s?rev=367983&r1=367982&r2=367983&view=diff
==============================================================================
--- lldb/trunk/lit/SymbolFile/DWARF/dir-separator-no-comp-dir-relative-name.s (original)
+++ lldb/trunk/lit/SymbolFile/DWARF/dir-separator-no-comp-dir-relative-name.s Mon Aug  5 23:52:05 2019
@@ -5,7 +5,7 @@
 # REQUIRES: lld, x86
 
 # RUN: llvm-mc -triple x86_64-pc-linux %s -filetype=obj > %t.o
-# RUN: ld.lld -z separate-code %t.o -o %t
+# RUN: ld.lld %t.o -o %t
 # RUN: %lldb %t -s %S/Inputs/dir-separator-no-comp-dir-relative-name.lldbinit -o exit | FileCheck %s
 
 # CHECK-LABEL: image dump line-table a.c

Modified: lldb/trunk/lit/SymbolFile/DWARF/dir-separator-no-comp-dir.s
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/SymbolFile/DWARF/dir-separator-no-comp-dir.s?rev=367983&r1=367982&r2=367983&view=diff
==============================================================================
--- lldb/trunk/lit/SymbolFile/DWARF/dir-separator-no-comp-dir.s (original)
+++ lldb/trunk/lit/SymbolFile/DWARF/dir-separator-no-comp-dir.s Mon Aug  5 23:52:05 2019
@@ -4,7 +4,7 @@
 # REQUIRES: lld, x86
 
 # RUN: llvm-mc -triple x86_64-pc-linux %s -filetype=obj > %t.o
-# RUN: ld.lld -z separate-code %t.o -o %t
+# RUN: ld.lld %t.o -o %t
 # RUN: %lldb %t -s %S/Inputs/dir-separator-windows.lldbinit -o exit | FileCheck %s
 
 # CHECK-LABEL: image dump line-table a.c

Modified: lldb/trunk/lit/SymbolFile/DWARF/dir-separator-posix.s
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/SymbolFile/DWARF/dir-separator-posix.s?rev=367983&r1=367982&r2=367983&view=diff
==============================================================================
--- lldb/trunk/lit/SymbolFile/DWARF/dir-separator-posix.s (original)
+++ lldb/trunk/lit/SymbolFile/DWARF/dir-separator-posix.s Mon Aug  5 23:52:05 2019
@@ -4,7 +4,7 @@
 # REQUIRES: lld, x86
 
 # RUN: llvm-mc -triple x86_64-pc-linux %s -filetype=obj > %t.o
-# RUN: ld.lld -z separate-code %t.o -o %t
+# RUN: ld.lld %t.o -o %t
 # RUN: %lldb %t -s %S/Inputs/dir-separator-posix.lldbinit -o exit | FileCheck %s
 
 # CHECK-LABEL: image dump line-table a.c

Modified: lldb/trunk/lit/SymbolFile/DWARF/dir-separator-windows.s
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/SymbolFile/DWARF/dir-separator-windows.s?rev=367983&r1=367982&r2=367983&view=diff
==============================================================================
--- lldb/trunk/lit/SymbolFile/DWARF/dir-separator-windows.s (original)
+++ lldb/trunk/lit/SymbolFile/DWARF/dir-separator-windows.s Mon Aug  5 23:52:05 2019
@@ -4,7 +4,7 @@
 # REQUIRES: lld, x86
 
 # RUN: llvm-mc -triple x86_64-pc-linux %s -filetype=obj > %t.o
-# RUN: ld.lld -z separate-code %t.o -o %t
+# RUN: ld.lld %t.o -o %t
 # RUN: %lldb %t -s %S/Inputs/dir-separator-windows.lldbinit -o exit | FileCheck %s
 
 # CHECK-LABEL: image dump line-table a.c

Modified: lldb/trunk/source/Symbol/LineTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/LineTable.cpp?rev=367983&r1=367982&r2=367983&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/LineTable.cpp (original)
+++ lldb/trunk/source/Symbol/LineTable.cpp Mon Aug  5 23:52:05 2019
@@ -241,33 +241,47 @@ bool LineTable::FindLineEntryByAddress(c
 
 bool LineTable::ConvertEntryAtIndexToLineEntry(uint32_t idx,
                                                LineEntry &line_entry) {
-  if (idx < m_entries.size()) {
-    const Entry &entry = m_entries[idx];
-    ModuleSP module_sp(m_comp_unit->GetModule());
-    if (module_sp &&
-        module_sp->ResolveFileAddress(entry.file_addr,
-                                      line_entry.range.GetBaseAddress())) {
-      if (!entry.is_terminal_entry && idx + 1 < m_entries.size())
-        line_entry.range.SetByteSize(m_entries[idx + 1].file_addr -
-                                     entry.file_addr);
-      else
-        line_entry.range.SetByteSize(0);
-
-      line_entry.file =
-          m_comp_unit->GetSupportFiles().GetFileSpecAtIndex(entry.file_idx);
-      line_entry.original_file =
-          m_comp_unit->GetSupportFiles().GetFileSpecAtIndex(entry.file_idx);
-      line_entry.line = entry.line;
-      line_entry.column = entry.column;
-      line_entry.is_start_of_statement = entry.is_start_of_statement;
-      line_entry.is_start_of_basic_block = entry.is_start_of_basic_block;
-      line_entry.is_prologue_end = entry.is_prologue_end;
-      line_entry.is_epilogue_begin = entry.is_epilogue_begin;
-      line_entry.is_terminal_entry = entry.is_terminal_entry;
-      return true;
-    }
-  }
-  return false;
+  if (idx >= m_entries.size())
+    return false;
+
+  const Entry &entry = m_entries[idx];
+  ModuleSP module_sp(m_comp_unit->GetModule());
+  if (!module_sp)
+    return false;
+
+  addr_t file_addr = entry.file_addr;
+
+  // A terminal entry can point outside of a module or a section. Decrement the
+  // address to ensure it resolves correctly.
+  if (entry.is_terminal_entry)
+    --file_addr;
+
+  if (!module_sp->ResolveFileAddress(file_addr,
+                                     line_entry.range.GetBaseAddress()))
+    return false;
+
+  // Now undo the decrement above.
+  if (entry.is_terminal_entry)
+    line_entry.range.GetBaseAddress().Slide(1);
+
+  if (!entry.is_terminal_entry && idx + 1 < m_entries.size())
+    line_entry.range.SetByteSize(m_entries[idx + 1].file_addr -
+                                 entry.file_addr);
+  else
+    line_entry.range.SetByteSize(0);
+
+  line_entry.file =
+      m_comp_unit->GetSupportFiles().GetFileSpecAtIndex(entry.file_idx);
+  line_entry.original_file =
+      m_comp_unit->GetSupportFiles().GetFileSpecAtIndex(entry.file_idx);
+  line_entry.line = entry.line;
+  line_entry.column = entry.column;
+  line_entry.is_start_of_statement = entry.is_start_of_statement;
+  line_entry.is_start_of_basic_block = entry.is_start_of_basic_block;
+  line_entry.is_prologue_end = entry.is_prologue_end;
+  line_entry.is_epilogue_begin = entry.is_epilogue_begin;
+  line_entry.is_terminal_entry = entry.is_terminal_entry;
+  return true;
 }
 
 uint32_t LineTable::FindLineEntryIndexByFileIndex(




More information about the lldb-commits mailing list