[llvm] a7b209a - llvm-symbolizer: Exit non-zero when DWARF parsing errors have been rendered

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 14 23:42:10 PDT 2020


Author: David Blaikie
Date: 2020-10-14T23:42:00-07:00
New Revision: a7b209a6d40d77b43a38664b1fe64513587f24c6

URL: https://github.com/llvm/llvm-project/commit/a7b209a6d40d77b43a38664b1fe64513587f24c6
DIFF: https://github.com/llvm/llvm-project/commit/a7b209a6d40d77b43a38664b1fe64513587f24c6.diff

LOG: llvm-symbolizer: Exit non-zero when DWARF parsing errors have been rendered

Added: 
    llvm/test/tools/llvm-symbolizer/invalid-dwarf.s

Modified: 
    llvm/include/llvm/DebugInfo/Symbolize/Symbolize.h
    llvm/lib/DebugInfo/Symbolize/Symbolize.cpp
    llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/DebugInfo/Symbolize/Symbolize.h b/llvm/include/llvm/DebugInfo/Symbolize/Symbolize.h
index 085e4bb4ccb8..43c89aafea9b 100644
--- a/llvm/include/llvm/DebugInfo/Symbolize/Symbolize.h
+++ b/llvm/include/llvm/DebugInfo/Symbolize/Symbolize.h
@@ -49,6 +49,7 @@ class LLVMSymbolizer {
     std::string FallbackDebugPath;
     std::string DWPName;
     std::vector<std::string> DebugFileDirectory;
+    std::function<void(Error)> RecoverableErrorHandler = WithColor::defaultErrorHandler;
   };
 
   LLVMSymbolizer() = default;

diff  --git a/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp b/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp
index 383e2c0d3054..ed53ea9712b6 100644
--- a/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp
+++ b/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp
@@ -68,7 +68,8 @@ LLVMSymbolizer::symbolizeCode(const ObjectFile &Obj,
   if (I != Modules.end())
     return symbolizeCodeCommon(I->second.get(), ModuleOffset);
 
-  std::unique_ptr<DIContext> Context = DWARFContext::create(Obj);
+  std::unique_ptr<DIContext> Context =
+      DWARFContext::create(Obj, nullptr, "", Opts.RecoverableErrorHandler);
   Expected<SymbolizableModule *> InfoOrErr =
                      createModuleInfo(&Obj, std::move(Context), ModuleName);
   if (!InfoOrErr)
@@ -572,7 +573,8 @@ LLVMSymbolizer::getOrCreateModuleInfo(const std::string &ModuleName) {
     }
   }
   if (!Context)
-    Context = DWARFContext::create(*Objects.second, nullptr, Opts.DWPName);
+    Context = DWARFContext::create(*Objects.second, nullptr, Opts.DWPName,
+                                   Opts.RecoverableErrorHandler);
   return createModuleInfo(Objects.first, std::move(Context), ModuleName);
 }
 

diff  --git a/llvm/test/tools/llvm-symbolizer/invalid-dwarf.s b/llvm/test/tools/llvm-symbolizer/invalid-dwarf.s
new file mode 100644
index 000000000000..d9039acb2457
--- /dev/null
+++ b/llvm/test/tools/llvm-symbolizer/invalid-dwarf.s
@@ -0,0 +1,204 @@
+# Source:
+# void f1() { }
+# void f2() { }
+#
+# Build as: clang -ffunction-sections -gdwarf-5 -c test.c
+# Hand modify the rnglist to include an invalid RLE encoding (42)
+#
+# RUN: llvm-mc -dwarf-version=5 %s -filetype=obj -o %t
+# RUN: not llvm-symbolizer -obj=%t 0x0 2>&1 | FileCheck %s
+#
+# CHECK: error: decoding address ranges: unknown rnglists encoding 0x2a at offset 0x10
+
+	.text
+	.file	"test.c"
+	.section	.text.f1,"ax", at progbits
+	.globl	f1                              # -- Begin function f1
+	.p2align	4, 0x90
+	.type	f1, at function
+f1:                                     # @f1
+.Lfunc_begin0:
+	.file	0 "/usr/local/google/home/blaikie/dev/scratch" "test.c" md5 0x39c2464ceaf7fd68a00d44ca40e99028
+	.loc	0 1 0                           # test.c:1:0
+	.cfi_startproc
+# %bb.0:                                # %entry
+	pushq	%rbp
+	.cfi_def_cfa_offset 16
+	.cfi_offset %rbp, -16
+	movq	%rsp, %rbp
+	.cfi_def_cfa_register %rbp
+.Ltmp0:
+	.loc	0 1 13 prologue_end             # test.c:1:13
+	popq	%rbp
+	.cfi_def_cfa %rsp, 8
+	retq
+.Ltmp1:
+.Lfunc_end0:
+	.size	f1, .Lfunc_end0-f1
+	.cfi_endproc
+                                        # -- End function
+	.section	.text.f2,"ax", at progbits
+	.globl	f2                              # -- Begin function f2
+	.p2align	4, 0x90
+	.type	f2, at function
+f2:                                     # @f2
+.Lfunc_begin1:
+	.loc	0 2 0                           # test.c:2:0
+	.cfi_startproc
+# %bb.0:                                # %entry
+	pushq	%rbp
+	.cfi_def_cfa_offset 16
+	.cfi_offset %rbp, -16
+	movq	%rsp, %rbp
+	.cfi_def_cfa_register %rbp
+.Ltmp2:
+	.loc	0 2 13 prologue_end             # test.c:2:13
+	popq	%rbp
+	.cfi_def_cfa %rsp, 8
+	retq
+.Ltmp3:
+.Lfunc_end1:
+	.size	f2, .Lfunc_end1-f2
+	.cfi_endproc
+                                        # -- End function
+	.section	.debug_abbrev,"", at 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	1                               # DW_FORM_addr
+	.byte	85                              # DW_AT_ranges
+	.byte	35                              # DW_FORM_rnglistx
+	.byte	115                             # DW_AT_addr_base
+	.byte	23                              # DW_FORM_sec_offset
+	.byte	116                             # DW_AT_rnglists_base
+	.byte	23                              # DW_FORM_sec_offset
+	.byte	0                               # EOM(1)
+	.byte	0                               # EOM(2)
+	.byte	2                               # Abbreviation Code
+	.byte	46                              # DW_TAG_subprogram
+	.byte	0                               # DW_CHILDREN_no
+	.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	63                              # DW_AT_external
+	.byte	25                              # DW_FORM_flag_present
+	.byte	0                               # EOM(1)
+	.byte	0                               # EOM(2)
+	.byte	0                               # EOM(3)
+	.section	.debug_info,"", at 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:0x36 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
+	.quad	0                               # DW_AT_low_pc
+	.byte	0                               # DW_AT_ranges
+	.long	.Laddr_table_base0              # DW_AT_addr_base
+	.long	.Lrnglists_table_base0          # DW_AT_rnglists_base
+	.byte	2                               # Abbrev [2] 0x2b:0xb 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	86
+	.byte	3                               # DW_AT_name
+	.byte	0                               # DW_AT_decl_file
+	.byte	1                               # DW_AT_decl_line
+                                        # DW_AT_external
+	.byte	2                               # Abbrev [2] 0x36:0xb DW_TAG_subprogram
+	.byte	1                               # DW_AT_low_pc
+	.long	.Lfunc_end1-.Lfunc_begin1       # DW_AT_high_pc
+	.byte	1                               # DW_AT_frame_base
+	.byte	86
+	.byte	4                               # DW_AT_name
+	.byte	0                               # DW_AT_decl_file
+	.byte	2                               # DW_AT_decl_line
+                                        # DW_AT_external
+	.byte	0                               # End Of Children Mark
+.Ldebug_info_end0:
+	.section	.debug_rnglists,"", at progbits
+	.long	.Ldebug_list_header_end0-.Ldebug_list_header_start0 # Length
+.Ldebug_list_header_start0:
+	.short	5                               # Version
+	.byte	8                               # Address size
+	.byte	0                               # Segment selector size
+	.long	1                               # Offset entry count
+.Lrnglists_table_base0:
+	.long	.Ldebug_ranges0-.Lrnglists_table_base0
+.Ldebug_ranges0:
+	.byte	42                               # DW_RLE_startx_length
+	.byte	0                               #   start index
+	.uleb128 .Lfunc_end0-.Lfunc_begin0      #   length
+	.byte	3                               # DW_RLE_startx_length
+	.byte	1                               #   start index
+	.uleb128 .Lfunc_end1-.Lfunc_begin1      #   length
+	.byte	0                               # DW_RLE_end_of_list
+.Ldebug_list_header_end0:
+	.section	.debug_str_offsets,"", at progbits
+	.long	24                              # Length of String Offsets Set
+	.short	5
+	.short	0
+.Lstr_offsets_base0:
+	.section	.debug_str,"MS", at progbits,1
+.Linfo_string0:
+	.asciz	"clang version 12.0.0 (git at github.com:llvm/llvm-project.git 9a33f027ac7d73e14ae287e78ab554142d1cbc8f)" # string offset=0
+.Linfo_string1:
+	.asciz	"test.c"                        # string offset=101
+.Linfo_string2:
+	.asciz	"/usr/local/google/home/blaikie/dev/scratch" # string offset=108
+.Linfo_string3:
+	.asciz	"f1"                            # string offset=151
+.Linfo_string4:
+	.asciz	"f2"                            # string offset=154
+	.section	.debug_str_offsets,"", at progbits
+	.long	.Linfo_string0
+	.long	.Linfo_string1
+	.long	.Linfo_string2
+	.long	.Linfo_string3
+	.long	.Linfo_string4
+	.section	.debug_addr,"", at 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
+	.quad	.Lfunc_begin1
+.Ldebug_addr_end0:
+	.ident	"clang version 12.0.0 (git at github.com:llvm/llvm-project.git 9a33f027ac7d73e14ae287e78ab554142d1cbc8f)"
+	.section	".note.GNU-stack","", at progbits
+	.addrsig
+	.section	.debug_line,"", at progbits
+.Lline_table_start0:
+

diff  --git a/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp b/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
index 509449a5d127..e4061408a821 100644
--- a/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
+++ b/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
@@ -293,6 +293,10 @@ int main(int argc, char **argv) {
       Args.hasFlag(OPT_untag_addresses, OPT_no_untag_addresses, !IsAddr2Line);
   Opts.UseNativePDBReader = Args.hasArg(OPT_use_native_pdb_reader);
   Opts.UseSymbolTable = true;
+  Opts.RecoverableErrorHandler = [&](Error E) {
+    HasError = true;
+    WithColor::defaultErrorHandler(std::move(E));
+  };
 
   for (const opt::Arg *A : Args.filtered(OPT_dsym_hint_EQ)) {
     StringRef Hint(A->getValue());


        


More information about the llvm-commits mailing list