SouraVX created this revision.
SouraVX added reviewers: JDevlieghere, clayborg, labath.
SouraVX added a project: LLDB.
Herald added subscribers: lldb-commits, aprantl.
Herald added a reviewer: jdoerfert.

This patch adds support for DWARFv5 new forms:  DW_MACRO_define_strx, 
DW_MACRO_undef_strx.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D72597

Files:
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugMacro.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugMacro.h
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  lldb/test/Shell/Commands/Inputs/dwarf5-macro.s
  lldb/test/Shell/Commands/dwarf5-macro.test

Index: lldb/test/Shell/Commands/dwarf5-macro.test
===================================================================
--- /dev/null
+++ lldb/test/Shell/Commands/dwarf5-macro.test
@@ -0,0 +1,16 @@
+# REQUIRES: x86
+# This test checks lldb macro expansion when macro section
+# contains DWARFv5 DW_MACRO_define_strx/DW_MACRO_undef_strx forms
+#
+# RUN: %clang_host -gdwarf-5 %p/Inputs/dwarf5-macro.s -o %t
+# RUN: %lldb -s %s %t 2>&1 | FileCheck %s
+
+display FOO
+display BAR
+b main
+run
+# CHECK: Hook {{.*}} (expr -- FOO)
+# CHECK-NEXT: {{.*}} 5
+#
+# CHECK: Hook {{.*}} (expr -- BAR)
+# CHECK-NEXT: {{.*}} 6
Index: lldb/test/Shell/Commands/Inputs/dwarf5-macro.s
===================================================================
--- /dev/null
+++ lldb/test/Shell/Commands/Inputs/dwarf5-macro.s
@@ -0,0 +1,266 @@
+	.text
+	.file	"test.c"
+	.file	0 "/home/" "test.c" md5 0xef6a7032e0c7ceeef621583f2c00dc80
+	.globl	main                    # -- Begin function main
+	.p2align	4, 0x90
+	.type	main,@function
+main:                                   # @main
+.Lfunc_begin0:
+	.loc	0 9 0                   # test.c:9:0
+	.cfi_startproc
+# %bb.0:
+	xorl	%eax, %eax
+.Ltmp0:
+	.loc	0 10 5 prologue_end     # test.c:10:5
+	movl	$3, -4(%rsp)
+	.loc	0 11 5                  # test.c:11:5
+	movl	$5, -8(%rsp)
+	.loc	0 12 1                  # test.c:12:1
+	retq
+.Ltmp1:
+.Lfunc_end0:
+	.size	main, .Lfunc_end0-main
+	.cfi_endproc
+                                        # -- End function
+	.section	.debug_abbrev,"",@progbits
+	.byte	1                       # Abbreviation Code
+	.byte	17                      # DW_TAG_compile_unit
+	.byte	1                       # DW_CHILDREN_yes
+	.byte	37                      # DW_AT_producer
+	.byte	37                      # DW_FORM_strx1
+	.byte	19                      # DW_AT_language
+	.byte	5                       # DW_FORM_data2
+	.byte	3                       # DW_AT_name
+	.byte	37                      # DW_FORM_strx1
+	.byte	114                     # DW_AT_str_offsets_base
+	.byte	23                      # DW_FORM_sec_offset
+	.byte	16                      # DW_AT_stmt_list
+	.byte	23                      # DW_FORM_sec_offset
+	.byte	27                      # DW_AT_comp_dir
+	.byte	37                      # DW_FORM_strx1
+	.byte	17                      # DW_AT_low_pc
+	.byte	27                      # DW_FORM_addrx
+	.byte	18                      # DW_AT_high_pc
+	.byte	6                       # DW_FORM_data4
+	.byte	115                     # DW_AT_addr_base
+	.byte	23                      # DW_FORM_sec_offset
+	.byte	121                     # DW_AT_macros
+	.byte	23                      # DW_FORM_sec_offset
+	.byte	0                       # EOM(1)
+	.byte	0                       # EOM(2)
+	.byte	2                       # Abbreviation Code
+	.byte	46                      # DW_TAG_subprogram
+	.byte	1                       # DW_CHILDREN_yes
+	.byte	17                      # DW_AT_low_pc
+	.byte	27                      # DW_FORM_addrx
+	.byte	18                      # DW_AT_high_pc
+	.byte	6                       # DW_FORM_data4
+	.byte	64                      # DW_AT_frame_base
+	.byte	24                      # DW_FORM_exprloc
+	.byte	3                       # DW_AT_name
+	.byte	37                      # DW_FORM_strx1
+	.byte	58                      # DW_AT_decl_file
+	.byte	11                      # DW_FORM_data1
+	.byte	59                      # DW_AT_decl_line
+	.byte	11                      # DW_FORM_data1
+	.byte	73                      # DW_AT_type
+	.byte	19                      # DW_FORM_ref4
+	.byte	63                      # DW_AT_external
+	.byte	25                      # DW_FORM_flag_present
+	.byte	0                       # EOM(1)
+	.byte	0                       # EOM(2)
+	.byte	3                       # Abbreviation Code
+	.byte	52                      # DW_TAG_variable
+	.byte	0                       # DW_CHILDREN_no
+	.byte	2                       # DW_AT_location
+	.byte	24                      # DW_FORM_exprloc
+	.byte	3                       # DW_AT_name
+	.byte	37                      # DW_FORM_strx1
+	.byte	58                      # DW_AT_decl_file
+	.byte	11                      # DW_FORM_data1
+	.byte	59                      # DW_AT_decl_line
+	.byte	11                      # DW_FORM_data1
+	.byte	73                      # DW_AT_type
+	.byte	19                      # DW_FORM_ref4
+	.byte	0                       # EOM(1)
+	.byte	0                       # EOM(2)
+	.byte	4                       # Abbreviation Code
+	.byte	36                      # DW_TAG_base_type
+	.byte	0                       # DW_CHILDREN_no
+	.byte	3                       # DW_AT_name
+	.byte	37                      # DW_FORM_strx1
+	.byte	62                      # DW_AT_encoding
+	.byte	11                      # DW_FORM_data1
+	.byte	11                      # DW_AT_byte_size
+	.byte	11                      # DW_FORM_data1
+	.byte	0                       # EOM(1)
+	.byte	0                       # EOM(2)
+	.byte	0                       # EOM(3)
+	.section	.debug_info,"",@progbits
+.Lcu_begin0:
+	.long	.Ldebug_info_end0-.Ldebug_info_start0 # Length of Unit
+.Ldebug_info_start0:
+	.short	5                       # DWARF version number
+	.byte	1                       # DWARF Unit Type
+	.byte	8                       # Address Size (in bytes)
+	.long	.debug_abbrev           # Offset Into Abbrev. Section
+	.byte	1                       # Abbrev [1] 0xc:0x46 DW_TAG_compile_unit
+	.byte	0                       # DW_AT_producer
+	.short	12                      # DW_AT_language
+	.byte	1                       # DW_AT_name
+	.long	.Lstr_offsets_base0     # DW_AT_str_offsets_base
+	.long	.Lline_table_start0     # DW_AT_stmt_list
+	.byte	2                       # DW_AT_comp_dir
+	.byte	0                       # DW_AT_low_pc
+	.long	.Lfunc_end0-.Lfunc_begin0 # DW_AT_high_pc
+	.long	.Laddr_table_base0      # DW_AT_addr_base
+	.long	.Lcu_macro_begin0-.debug_macro # DW_AT_macros
+	.byte	2                       # Abbrev [2] 0x27:0x26 DW_TAG_subprogram
+	.byte	0                       # DW_AT_low_pc
+	.long	.Lfunc_end0-.Lfunc_begin0 # DW_AT_high_pc
+	.byte	1                       # DW_AT_frame_base
+	.byte	87
+	.byte	3                       # DW_AT_name
+	.byte	0                       # DW_AT_decl_file
+	.byte	9                       # DW_AT_decl_line
+	.long	77                      # DW_AT_type
+                                        # DW_AT_external
+	.byte	3                       # Abbrev [3] 0x36:0xb DW_TAG_variable
+	.byte	2                       # DW_AT_location
+	.byte	145
+	.byte	124
+	.byte	5                       # DW_AT_name
+	.byte	0                       # DW_AT_decl_file
+	.byte	10                      # DW_AT_decl_line
+	.long	77                      # DW_AT_type
+	.byte	3                       # Abbrev [3] 0x41:0xb DW_TAG_variable
+	.byte	2                       # DW_AT_location
+	.byte	145
+	.byte	120
+	.byte	6                       # DW_AT_name
+	.byte	0                       # DW_AT_decl_file
+	.byte	11                      # DW_AT_decl_line
+	.long	77                      # DW_AT_type
+	.byte	0                       # End Of Children Mark
+	.byte	4                       # Abbrev [4] 0x4d:0x4 DW_TAG_base_type
+	.byte	4                       # DW_AT_name
+	.byte	5                       # DW_AT_encoding
+	.byte	4                       # DW_AT_byte_size
+	.byte	0                       # End Of Children Mark
+.Ldebug_info_end0:
+	.section	.debug_macro,"",@progbits
+.Lcu_macro_begin0:
+	.short	5                       # Macro information version
+	.byte	2                       # Flags: 32 bit, lineptr present
+	.long	.Lline_table_start0     # lineptr
+	.byte	3                       # DW_MACRO_start_file
+	.byte	0                       # Line Number
+	.byte	0                       # File Number
+	.byte	3                       # DW_MACRO_start_file
+	.byte	1                       # Line Number
+	.file	1 "." "foo.h" md5 0x0f0cd0e22b44f49d3944992c8dc28661 # File Number
+	.byte	1
+	.byte	11                      # DW_MACRO_define_strx
+	.byte	1                       # Line Number
+	.byte	7                       # Macro String Index
+	.byte	4                       # DW_MACRO_end_file
+	.byte	3                       # DW_MACRO_start_file
+	.byte	2                       # Line Number
+	.file	2 "." "bar.h" md5 0xbf4b34c333eaaa1d7085c25313b8d100 # File Number
+	.byte	2
+	.byte	11                      # DW_MACRO_define_strx
+	.byte	1                       # Line Number
+	.byte	8                       # Macro String Index
+	.byte	4                       # DW_MACRO_end_file
+	.byte	11                      # DW_MACRO_define_strx
+	.byte	4                       # Line Number
+	.byte	9                       # Macro String Index
+	.byte	11                      # DW_MACRO_define_strx
+	.byte	5                       # Line Number
+	.byte	10                      # Macro String Index
+	.byte	12                      # DW_MACRO_undef_strx
+	.byte	14                      # Line Number
+	.byte	11                      # Macro String Index
+	.byte	4                       # DW_MACRO_end_file
+	.byte	11                      # DW_MACRO_define_strx
+	.byte	0                       # Line Number
+	.byte	12                      # Macro String Index
+	.byte	11                      # DW_MACRO_define_strx
+	.byte	0                       # Line Number
+	.byte	13                      # Macro String Index
+	.byte	11                      # DW_MACRO_define_strx
+	.byte	0                       # Line Number
+	.byte	14                      # Macro String Index
+	.byte	11                      # DW_MACRO_define_strx
+	.byte	0                       # Line Number
+	.byte	15                      # Macro String Index
+	.byte	0                       # End Of Macro List Mark
+	.section	.debug_str_offsets,"",@progbits
+	.long	68
+	.short	5
+	.short	0
+.Lstr_offsets_base0:
+	.section	.debug_str,"MS",@progbits,1
+.Linfo_string0:
+	.asciz	"clang version 10.0.0"  # string offset=0
+.Linfo_string1:
+	.asciz	"test.c"                # string offset=21
+.Linfo_string2:
+	.asciz	"/home/"                # string offset=28
+.Linfo_string3:
+	.asciz	"main"                  # string offset=35
+.Linfo_string4:
+	.asciz	"int"                   # string offset=40
+.Linfo_string5:
+	.asciz	"a"                     # string offset=44
+.Linfo_string6:
+	.asciz	"b"                     # string offset=46
+.Linfo_string7:
+	.asciz	"FOO 5"                 # string offset=48
+.Linfo_string8:
+	.asciz	"BAR 6"                 # string offset=54
+.Linfo_string9:
+	.asciz	"BAZ 7"                 # string offset=60
+.Linfo_string10:
+	.asciz	"YEA 8"                 # string offset=66
+.Linfo_string11:
+	.asciz	"YEA "                  # string offset=72
+.Linfo_string12:
+	.asciz	"__llvm__ 1"            # string offset=77
+.Linfo_string13:
+	.asciz	"__clang__ 1"           # string offset=88
+.Linfo_string14:
+	.asciz	"__clang_major__ 10"    # string offset=100
+.Linfo_string15:
+	.asciz	"__clang_minor__ 0"     # string offset=119
+	.section	.debug_str_offsets,"",@progbits
+	.long	.Linfo_string0
+	.long	.Linfo_string1
+	.long	.Linfo_string2
+	.long	.Linfo_string3
+	.long	.Linfo_string4
+	.long	.Linfo_string5
+	.long	.Linfo_string6
+	.long	.Linfo_string7
+	.long	.Linfo_string8
+	.long	.Linfo_string9
+	.long	.Linfo_string10
+	.long	.Linfo_string11
+	.long	.Linfo_string12
+	.long	.Linfo_string13
+	.long	.Linfo_string14
+	.long	.Linfo_string15
+	.section	.debug_addr,"",@progbits
+	.long	.Ldebug_addr_end0-.Ldebug_addr_start0 # Length of contribution
+.Ldebug_addr_start0:
+	.short	5                       # DWARF version number
+	.byte	8                       # Address size
+	.byte	0                       # Segment selector size
+.Laddr_table_base0:
+	.quad	.Lfunc_begin0
+.Ldebug_addr_end0:
+	.ident	"clang version 10.0.0"
+	.section	".note.GNU-stack","",@progbits
+	.addrsig
+	.section	.debug_line,"",@progbits
+.Lline_table_start0:
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -1056,8 +1056,9 @@
   const DWARFDebugMacroHeader &header =
       DWARFDebugMacroHeader::ParseHeader(debug_macro_data, offset);
   DWARFDebugMacroEntry::ReadMacroEntries(
-      debug_macro_data, m_context.getOrLoadStrData(), header.OffsetIs64Bit(),
-      offset, this, debug_macros_sp);
+      debug_macro_data, m_context.getOrLoadStrOffsetsData(),
+      m_context.getOrLoadStrData(), header.OffsetIs64Bit(), offset, this,
+      debug_macros_sp);
 
   return debug_macros_sp;
 }
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugMacro.h
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugMacro.h
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugMacro.h
@@ -50,12 +50,13 @@
 
 class DWARFDebugMacroEntry {
 public:
-  static void
-  ReadMacroEntries(const lldb_private::DWARFDataExtractor &debug_macro_data,
-                   const lldb_private::DWARFDataExtractor &debug_str_data,
-                   const bool offset_is_64_bit, lldb::offset_t *sect_offset,
-                   SymbolFileDWARF *sym_file_dwarf,
-                   lldb_private::DebugMacrosSP &debug_macros_sp);
+  static void ReadMacroEntries(
+      const lldb_private::DWARFDataExtractor &debug_macro_data,
+      const lldb_private::DWARFDataExtractor &debug_str_offset_data,
+      const lldb_private::DWARFDataExtractor &debug_str_data,
+      const bool offset_is_64_bit, lldb::offset_t *sect_offset,
+      SymbolFileDWARF *sym_file_dwarf,
+      lldb_private::DebugMacrosSP &debug_macros_sp);
 };
 
 #endif // SymbolFileDWARF_DWARFDebugMacro_h_
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugMacro.cpp
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugMacro.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugMacro.cpp
@@ -58,6 +58,7 @@
 
 void DWARFDebugMacroEntry::ReadMacroEntries(
     const DWARFDataExtractor &debug_macro_data,
+    const DWARFDataExtractor &debug_str_offset_data,
     const DWARFDataExtractor &debug_str_data, const bool offset_is_64_bit,
     lldb::offset_t *offset, SymbolFileDWARF *sym_file_dwarf,
     DebugMacrosSP &debug_macros_sp) {
@@ -65,7 +66,9 @@
       static_cast<llvm::dwarf::MacroEntryType>(debug_macro_data.GetU8(offset));
   while (type != 0) {
     lldb::offset_t new_offset = 0, str_offset = 0;
-    uint32_t line = 0;
+    // For DWARF32 debug_str_offsets header size is 8 bytes.
+    uint8_t str_offsets_base = 8, index_size = 4;
+    uint32_t line = 0, str_index = 0;
     const char *macro_str = nullptr;
     uint32_t debug_line_file_idx = 0;
 
@@ -96,6 +99,21 @@
         debug_macros_sp->AddMacroEntry(
             DebugMacroEntry::CreateUndefEntry(line, macro_str));
       break;
+    case DW_MACRO_define_strx:
+    case DW_MACRO_undef_strx:
+      line = debug_macro_data.GetULEB128(offset);
+      str_index = debug_macro_data.GetULEB128(offset);
+      str_offset = str_offsets_base + str_index * index_size;
+      str_offset = debug_str_offset_data.GetMaxU64(&str_offset, index_size);
+      macro_str = debug_str_data.GetCStr(&str_offset);
+      if (type == DW_MACRO_define_strx)
+        debug_macros_sp->AddMacroEntry(
+            DebugMacroEntry::CreateDefineEntry(line, macro_str));
+      else
+        debug_macros_sp->AddMacroEntry(
+            DebugMacroEntry::CreateUndefEntry(line, macro_str));
+      break;
+
     case DW_MACRO_start_file:
       line = debug_macro_data.GetULEB128(offset);
       debug_line_file_idx = debug_macro_data.GetULEB128(offset);
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to