Skip to content

Commit

Permalink
Added support for turning off dwarf warnings from the command line.
Browse files Browse the repository at this point in the history
  • Loading branch information
nmoinvaz committed Jun 6, 2023
1 parent a2d3df5 commit 8adc4d3
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 17 deletions.
70 changes: 59 additions & 11 deletions src/common/dwarf_cu_to_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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 &section_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
Expand Down
18 changes: 15 additions & 3 deletions src/common/mac/dump_syms.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}
}

Expand Down
12 changes: 10 additions & 2 deletions src/common/mac/dump_syms.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
9 changes: 8 additions & 1 deletion src/tools/mac/dump_syms/dump_syms_tool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -219,6 +222,7 @@ static void Usage(int argc, const char *argv[]) {
fprintf(stderr, "Usage: %s [-a ARCHITECTURE] [-c] [-g dSYM path] "
"<Mach-o file>\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 "
Expand All @@ -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);
Expand Down

0 comments on commit 8adc4d3

Please sign in to comment.