aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/common/linux/dwarf_cu_to_module.cc4
-rw-r--r--src/common/linux/dwarf_cu_to_module.h15
-rw-r--r--src/common/linux/dwarf_cu_to_module_unittest.cc64
3 files changed, 82 insertions, 1 deletions
diff --git a/src/common/linux/dwarf_cu_to_module.cc b/src/common/linux/dwarf_cu_to_module.cc
index 9ad3393c..59efebc4 100644
--- a/src/common/linux/dwarf_cu_to_module.cc
+++ b/src/common/linux/dwarf_cu_to_module.cc
@@ -493,6 +493,8 @@ void DwarfCUToModule::WarningReporter::UncoveredHeading() {
void DwarfCUToModule::WarningReporter::UncoveredFunction(
const Module::Function &function) {
+ if (!uncovered_warnings_enabled_)
+ return;
UncoveredHeading();
fprintf(stderr, " function%s: %s\n",
function.size == 0 ? " (zero-length)" : "",
@@ -500,6 +502,8 @@ void DwarfCUToModule::WarningReporter::UncoveredFunction(
}
void DwarfCUToModule::WarningReporter::UncoveredLine(const Module::Line &line) {
+ if (!uncovered_warnings_enabled_)
+ return;
UncoveredHeading();
fprintf(stderr, " line%s: %s:%d at 0x%llx\n",
(line.size == 0 ? " (zero-length)" : ""),
diff --git a/src/common/linux/dwarf_cu_to_module.h b/src/common/linux/dwarf_cu_to_module.h
index af330cff..8d8a0b2c 100644
--- a/src/common/linux/dwarf_cu_to_module.h
+++ b/src/common/linux/dwarf_cu_to_module.h
@@ -120,12 +120,24 @@ class DwarfCUToModule: public dwarf2reader::RootDIEHandler {
// compilation unit at OFFSET.
WarningReporter(const string &filename, uint64 cu_offset)
: filename_(filename), cu_offset_(cu_offset), printed_cu_header_(false),
- printed_unpaired_header_(false) { }
+ printed_unpaired_header_(false),
+ uncovered_warnings_enabled_(false) { }
virtual ~WarningReporter() { }
// Set the name of the compilation unit we're processing to NAME.
virtual void SetCUName(const string &name) { cu_name_ = 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.
+ virtual bool uncovered_warnings_enabled() const {
+ return uncovered_warnings_enabled_;
+ }
+ virtual void set_uncovered_warnings_enabled(bool value) {
+ uncovered_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.
@@ -154,6 +166,7 @@ class DwarfCUToModule: public dwarf2reader::RootDIEHandler {
string cu_name_;
bool printed_cu_header_;
bool printed_unpaired_header_;
+ bool uncovered_warnings_enabled_;
private:
// Print a per-CU heading, once.
diff --git a/src/common/linux/dwarf_cu_to_module_unittest.cc b/src/common/linux/dwarf_cu_to_module_unittest.cc
index 7553c533..1cfbee69 100644
--- a/src/common/linux/dwarf_cu_to_module_unittest.cc
+++ b/src/common/linux/dwarf_cu_to_module_unittest.cc
@@ -1633,5 +1633,69 @@ TEST_F(Errors, BadCURootDIETag) {
no_attrs));
}
+// Tests for DwarfCUToModule::Reporter. These just produce (or fail to
+// produce) output, so their results need to be checked by hand.
+struct Reporter: public Test {
+ Reporter()
+ : reporter("filename", 0x123456789abcdef0ULL) {
+ reporter.SetCUName("compilation-unit-name");
+
+ function.name = "function name";
+ function.address = 0x19c45c30770c1eb0ULL;
+ function.size = 0x89808a5bdfa0a6a3ULL;
+ function.parameter_size = 0x6a329f18683dcd51ULL;
+
+ file.name = "source file name";
+
+ line.address = 0x3606ac6267aebeccULL;
+ line.size = 0x5de482229f32556aULL;
+ line.file = &file;
+ line.number = 93400201;
+ }
+
+ DwarfCUToModule::WarningReporter reporter;
+ Module::Function function;
+ Module::File file;
+ Module::Line line;
+};
+
+TEST_F(Reporter, UnknownSpecification) {
+ reporter.UnknownSpecification(0x123456789abcdef1ULL, 0x323456789abcdef2ULL);
+}
+
+TEST_F(Reporter, UnknownAbstractOrigin) {
+ reporter.UnknownAbstractOrigin(0x123456789abcdef1ULL, 0x323456789abcdef2ULL);
+}
+
+TEST_F(Reporter, MissingSection) {
+ reporter.MissingSection("section name");
+}
+
+TEST_F(Reporter, BadLineInfoOffset) {
+ reporter.BadLineInfoOffset(0x123456789abcdef1ULL);
+}
+
+TEST_F(Reporter, UncoveredFunctionDisabled) {
+ reporter.UncoveredFunction(function);
+ EXPECT_FALSE(reporter.uncovered_warnings_enabled());
+}
+
+TEST_F(Reporter, UncoveredFunctionEnabled) {
+ reporter.set_uncovered_warnings_enabled(true);
+ reporter.UncoveredFunction(function);
+ EXPECT_TRUE(reporter.uncovered_warnings_enabled());
+}
+
+TEST_F(Reporter, UncoveredLineDisabled) {
+ reporter.UncoveredLine(line);
+ EXPECT_FALSE(reporter.uncovered_warnings_enabled());
+}
+
+TEST_F(Reporter, UncoveredLineEnabled) {
+ reporter.set_uncovered_warnings_enabled(true);
+ reporter.UncoveredLine(line);
+ EXPECT_TRUE(reporter.uncovered_warnings_enabled());
+}
+
// Would be nice to also test:
// - overlapping lines, functions