Skip to content

Commit

Permalink
Add command line switch for reporting DWARF warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
nmoinvaz committed Dec 20, 2023
1 parent 11e8341 commit a2d51bc
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 5 deletions.
57 changes: 57 additions & 0 deletions src/common/dwarf_cu_to_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,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 @@ -265,6 +265,10 @@ SuperFatArch* DumpSymbols::FindBestMatchForArchitecture(
return nullptr;
}

void DumpSymbols::SetReportWarnings(bool report_warnings) {
report_warnings_ = report_warnings;
}

string DumpSymbols::Identifier() {
scoped_ptr<FileID> file_id;

Expand Down Expand Up @@ -524,10 +528,17 @@ 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 = nullptr;
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, handle_inline);
&ranges_handler, reporter,
handle_inline);
// Make a Dwarf2Handler that drives our DIEHandler.
DIEDispatcher die_dispatcher(&root_handler);
// Make a DWARF parser for the compilation unit at OFFSET.
Expand All @@ -543,6 +554,7 @@ void DumpSymbols::ReadDwarf(google_breakpad::Module* module,
StartProcessSplitDwarf(&dwarf_reader, module, endianness,
handle_inter_cu_refs, handle_inline);
}
delete reporter;
}
}

Expand Down
9 changes: 8 additions & 1 deletion src/common/mac/dump_syms.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ class DumpSymbols {
selected_object_name_(),
enable_multiple_(enable_multiple),
module_name_(module_name),
prefer_extern_name_(prefer_extern_name) {}
prefer_extern_name_(prefer_extern_name),
report_warnings_(true) {}
~DumpSymbols() = default;

// Prepare to read debugging information from |filename|. |filename| may be
Expand Down Expand Up @@ -103,6 +104,9 @@ class DumpSymbols {
// architecture matches that of this dumper program.
bool SetArchitecture(const ArchInfo& info);

// 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 @@ -224,6 +228,9 @@ class DumpSymbols {
// (which are placed in the Extern), not in the DWARF symbols (which are
// placed in the Function).
bool prefer_extern_name_;

// 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 @@ -77,6 +77,7 @@ struct Options {
bool enable_multiple;
string module_name;
bool prefer_extern_name;
bool report_warnings;
};

static bool StackFrameEntryComparator(const Module::StackFrameEntry* a,
Expand Down Expand Up @@ -169,6 +170,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 @@ -250,6 +253,7 @@ static void Usage(int argc, const char *argv[]) {
"[-n MODULE] [-x] <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 @@ -275,11 +279,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?hn:x")) != -1) {
while ((ch = getopt(argc, (char* const*)argv, "iwa:g:crdm?hn:x")) != -1) {
switch (ch) {
case 'i':
options->header_only = true;
break;
case 'w':
options->report_warnings = true;
break;
case 'a': {
std::optional<ArchInfo> arch_info = GetArchInfoFromName(optarg);
if (!arch_info) {
Expand Down

0 comments on commit a2d51bc

Please sign in to comment.