From 8adc4d36e95f9134b19607f62217f30eed9eeb5a Mon Sep 17 00:00:00 2001 From: Nathan Moinvaziri Date: Fri, 8 Feb 2019 13:27:01 -0800 Subject: [PATCH] Added support for turning off dwarf warnings from the command line. --- src/common/dwarf_cu_to_module.h | 70 +++++++++++++++++++---- src/common/mac/dump_syms.cc | 18 +++++- src/common/mac/dump_syms.h | 12 +++- src/tools/mac/dump_syms/dump_syms_tool.cc | 9 ++- 4 files changed, 92 insertions(+), 17 deletions(-) diff --git a/src/common/dwarf_cu_to_module.h b/src/common/dwarf_cu_to_module.h index 41eca069b..f297f4078 100644 --- a/src/common/dwarf_cu_to_module.h +++ b/src/common/dwarf_cu_to_module.h @@ -176,8 +176,7 @@ class DwarfCUToModule: public RootDIEHandler { WarningReporter(const string& filename, uint64_t cu_offset) : filename_(filename), cu_offset_(cu_offset), printed_cu_header_(false), printed_unpaired_header_(false), - uncovered_warnings_enabled_(false), - unnamed_function_warnings_enabled_(false) { } + uncovered_warnings_enabled_(false) { } virtual ~WarningReporter() { } // Set the name of the compilation unit we're processing to NAME. @@ -193,15 +192,7 @@ class DwarfCUToModule: public RootDIEHandler { virtual void set_uncovered_warnings_enabled(bool value) { uncovered_warnings_enabled_ = value; } - - // Accessor and setting for unnamed_function_warnings_enabled. - virtual bool unnamed_function_warnings_enabled() const { - return unnamed_function_warnings_enabled_; - } - virtual void set_unnamed_function_warnings_enabled(bool value) { - unnamed_function_warnings_enabled_ = value; - } - + // A DW_AT_specification in the DIE at OFFSET refers to a DIE we // haven't processed yet, or that wasn't marked as a declaration, // at TARGET. @@ -264,6 +255,63 @@ class DwarfCUToModule: public RootDIEHandler { void UncoveredHeading(); }; + class NullWarningReporter: public WarningReporter { + public: + NullWarningReporter(const string &filename, uint64_t cu_offset): + WarningReporter(filename, cu_offset) { } + + // Set the name of the compilation unit we're processing to NAME. + void SetCUName(const string &name) { } + + // Accessor and setter for uncovered_warnings_enabled_. + // UncoveredFunction and UncoveredLine only report a problem if that is + // true. By default, these warnings are disabled, because those + // conditions occur occasionally in healthy code. + void set_uncovered_warnings_enabled(bool value) { } + + // A DW_AT_specification in the DIE at OFFSET refers to a DIE we + // haven't processed yet, or that wasn't marked as a declaration, + // at TARGET. + void UnknownSpecification(uint64_t offset, uint64_t target) { } + + // A DW_AT_abstract_origin in the DIE at OFFSET refers to a DIE we + // haven't processed yet, or that wasn't marked as inline, at TARGET. + void UnknownAbstractOrigin(uint64_t offset, uint64_t target) { } + + // We were unable to find the DWARF section named SECTION_NAME. + void MissingSection(const string §ion_name) { } + + // The CU's DW_AT_stmt_list offset OFFSET is bogus. + void BadLineInfoOffset(uint64_t offset) { } + + // FUNCTION includes code covered by no line number data. + void UncoveredFunction(const Module::Function &function) { } + + // Line number NUMBER in LINE_FILE, of length LENGTH, includes code + // covered by no function. + void UncoveredLine(const Module::Line &line) { } + + // The DW_TAG_subprogram DIE at OFFSET has no name specified directly + // in the DIE, nor via a DW_AT_specification or DW_AT_abstract_origin + // link. + void UnnamedFunction(uint64_t offset) { } + + // __cxa_demangle() failed to demangle INPUT. + void DemangleError(const string &input) { } + + // The DW_FORM_ref_addr at OFFSET to TARGET was not handled because + // FilePrivate did not retain the inter-CU specification data. + void UnhandledInterCUReference(uint64_t offset, uint64_t target) { } + + // The DW_AT_ranges at offset is malformed (truncated or outside of the + // .debug_ranges section's bound). + void MalformedRangeList(uint64_t offset) { } + + // A DW_AT_ranges attribute was encountered but the no .debug_ranges + // section was found. + void MissingRanges() { } + }; + // Create a DWARF debugging info handler for a compilation unit // within FILE_CONTEXT. This uses information received from the // CompilationUnit DWARF parser to populate diff --git a/src/common/mac/dump_syms.cc b/src/common/mac/dump_syms.cc index 9658b2c6d..c8128ed5a 100644 --- a/src/common/mac/dump_syms.cc +++ b/src/common/mac/dump_syms.cc @@ -239,6 +239,11 @@ bool DumpSymbols::SetArchitecture(const std::string& arch_name) { return arch_set; } +void DumpSymbols::SetReportWarnings(bool report_warnings) +{ + report_warnings_ = report_warnings; +} + SuperFatArch* DumpSymbols::FindBestMatchForArchitecture( cpu_type_t cpu_type, cpu_subtype_t cpu_subtype) { // Check if all the object files can be converted to struct fat_arch. @@ -497,10 +502,16 @@ void DumpSymbols::ReadDwarf(google_breakpad::Module* module, for (uint64_t offset = 0; offset < debug_info_length;) { // Make a handler for the root DIE that populates MODULE with the // debug info. - DwarfCUToModule::WarningReporter reporter(selected_object_name_, - offset); + DwarfCUToModule::WarningReporter *reporter = NULL; + if (report_warnings_) { + reporter = new DwarfCUToModule::WarningReporter( + selected_object_name_, offset); + } else { + reporter = new DwarfCUToModule::NullWarningReporter( + selected_object_name_, offset); + } DwarfCUToModule root_handler(&file_context, &line_to_module, - &ranges_handler, &reporter, + &ranges_handler, reporter, symbol_data_ & INLINES); // Make a Dwarf2Handler that drives our DIEHandler. DIEDispatcher die_dispatcher(&root_handler); @@ -512,6 +523,7 @@ void DumpSymbols::ReadDwarf(google_breakpad::Module* module, &die_dispatcher); // Process the entire compilation unit; get the offset of the next. offset += dwarf_reader.Start(); + delete reporter; } } diff --git a/src/common/mac/dump_syms.h b/src/common/mac/dump_syms.h index c2e1b40b9..beb3caacb 100644 --- a/src/common/mac/dump_syms.h +++ b/src/common/mac/dump_syms.h @@ -65,8 +65,10 @@ class DumpSymbols { object_files_(), selected_object_file_(), selected_object_name_(), - enable_multiple_(enable_multiple) {} - ~DumpSymbols() = default; + enable_multiple_(enable_multiple), + report_warnings_(true) {} + ~DumpSymbols() { + } // Prepare to read debugging information from |filename|. |filename| may be // the name of a fat file, a Mach-O file, or a dSYM bundle containing either @@ -103,6 +105,9 @@ class DumpSymbols { // architecture matches that of this dumper program. bool SetArchitecture(const std::string& arch_name); + // Set whether or not to report DWARF warnings + void SetReportWarnings(bool report_warnings); + // Return a pointer to an array of SuperFatArch structures describing the // object files contained in this dumper's file. Set *|count| to the number // of elements in the array. The returned array is owned by this DumpSymbols @@ -204,6 +209,9 @@ class DumpSymbols { // See: https://crbug.com/google-breakpad/751 and docs at // docs/symbol_files.md#records-3 bool enable_multiple_; + + // Whether or not to report warnings + bool report_warnings_; }; } // namespace google_breakpad diff --git a/src/tools/mac/dump_syms/dump_syms_tool.cc b/src/tools/mac/dump_syms/dump_syms_tool.cc index 2e05cbf3b..c0cd605f7 100644 --- a/src/tools/mac/dump_syms/dump_syms_tool.cc +++ b/src/tools/mac/dump_syms/dump_syms_tool.cc @@ -69,6 +69,7 @@ struct Options { bool handle_inter_cu_refs; bool handle_inlines; bool enable_multiple; + bool report_warnings; }; static bool StackFrameEntryComparator(const Module::StackFrameEntry* a, @@ -165,6 +166,8 @@ static bool Start(const Options& options) { const string& primary_file = split_module ? options.dsymPath : options.srcPath; + dump_symbols.SetReportWarnings(options.report_warnings); + if (!dump_symbols.Read(primary_file)) return false; @@ -219,6 +222,7 @@ static void Usage(int argc, const char *argv[]) { fprintf(stderr, "Usage: %s [-a ARCHITECTURE] [-c] [-g dSYM path] " "\n", argv[0]); fprintf(stderr, "\t-i: Output module header information only.\n"); + fprintf(stderr, "\t-w: Output warning information.\n"); fprintf(stderr, "\t-a: Architecture type [default: native, or whatever is\n"); fprintf(stderr, "\t in the file, if it contains only one architecture]\n"); fprintf(stderr, "\t-g: Debug symbol file (dSYM) to dump in addition to the " @@ -238,11 +242,14 @@ static void SetupOptions(int argc, const char *argv[], Options *options) { extern int optind; signed char ch; - while ((ch = getopt(argc, (char* const*)argv, "ia:g:crdm?h")) != -1) { + while ((ch = getopt(argc, (char* const*)argv, "iwa:g:crdm?h")) != -1) { switch (ch) { case 'i': options->header_only = true; break; + case 'w': + options->report_warnings = true; + break; case 'a': { const NXArchInfo *arch_info = google_breakpad::BreakpadGetArchInfoFromName(optarg);