diff options
author | Sterling Augustine <saugustine@google.com> | 2020-01-24 14:36:22 -0800 |
---|---|---|
committer | Sterling Augustine <saugustine@google.com> | 2020-02-11 11:46:20 -0800 |
commit | 417375d785b865b21ca4dc6cb6d70f833fb196cc (patch) | |
tree | 144d90b0ed59670ff65c13427d64817e20773e50 /llvm/unittests/DebugInfo/DWARF/DWARFDebugLineTest.cpp | |
parent | 9c1a88c96457ffde71f13c74fd4d52a77d86cc9f (diff) | |
download | llvm-417375d785b865b21ca4dc6cb6d70f833fb196cc.zip llvm-417375d785b865b21ca4dc6cb6d70f833fb196cc.tar.gz llvm-417375d785b865b21ca4dc6cb6d70f833fb196cc.tar.bz2 |
Allow retrieving source files relative to the compilation directory.
Summary:
Dwarf stores source-file names the three parts:
<compilation_directory><include_directory><filename>
Prior to this change, the code only allowed retrieving either all
three as the absolute path, or just the filename. But many
compile-command lines--especially those in hermetic build systems
don't specify an absolute path, nor just the filename, but rather the
path relative to the compilation directory. This features allows
retrieving them in that style.
Add tests for path printing styles.
Modify createBasicPrologue to handle include directories.
Subscribers: aprantl, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D73383
Diffstat (limited to 'llvm/unittests/DebugInfo/DWARF/DWARFDebugLineTest.cpp')
-rw-r--r-- | llvm/unittests/DebugInfo/DWARF/DWARFDebugLineTest.cpp | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/llvm/unittests/DebugInfo/DWARF/DWARFDebugLineTest.cpp b/llvm/unittests/DebugInfo/DWARF/DWARFDebugLineTest.cpp index 5d03746..10a9f95 100644 --- a/llvm/unittests/DebugInfo/DWARF/DWARFDebugLineTest.cpp +++ b/llvm/unittests/DebugInfo/DWARF/DWARFDebugLineTest.cpp @@ -917,4 +917,51 @@ TEST_F(DebugLineBasicFixture, ParserPrintsStandardOpcodesWhenRequested) { EXPECT_TRUE(InOutput("0x0000003f: 0c DW_LNS_set_isa (66)\n")) << Output; } +TEST_F(DebugLineBasicFixture, PrintPathsProperly) { + if (!setupGenerator(5)) + return; + + LineTable < = Gen->addLineTable(); + DWARFDebugLine::Prologue P = LT.createBasicPrologue(); + P.IncludeDirectories.push_back( + DWARFFormValue::createFromPValue(DW_FORM_string, "b dir")); + P.FileNames.push_back(DWARFDebugLine::FileNameEntry()); + P.FileNames.back().Name = + DWARFFormValue::createFromPValue(DW_FORM_string, "b file"); + P.FileNames.back().DirIdx = 1; + P.PrologueLength += 14; + LT.setPrologue(P); + generate(); + + auto ExpectedLineTable = Line.getOrParseLineTable(LineData, 0, *Context, + nullptr, RecordRecoverable); + EXPECT_THAT_EXPECTED(ExpectedLineTable, Succeeded()); + std::string Result; + // DWARF 5 stores the compilation directory in two places: the Compilation + // Unit and the directory table entry 0, and implementations are free to use + // one or the other. This copy serves as the one stored in the CU. + StringRef CompDir = "a dir"; + EXPECT_FALSE( + (*ExpectedLineTable) + ->Prologue.getFileNameByIndex( + 1, CompDir, DILineInfoSpecifier::FileLineInfoKind::None, Result)); + EXPECT_TRUE((*ExpectedLineTable) + ->Prologue.getFileNameByIndex( + 1, CompDir, + DILineInfoSpecifier::FileLineInfoKind::Default, Result)); + EXPECT_STREQ(Result.c_str(), "b file"); + EXPECT_TRUE((*ExpectedLineTable) + ->Prologue.getFileNameByIndex( + 1, CompDir, + DILineInfoSpecifier::FileLineInfoKind::RelativeFilePath, + Result)); + EXPECT_STREQ(Result.c_str(), "b dir/b file"); + EXPECT_TRUE((*ExpectedLineTable) + ->Prologue.getFileNameByIndex( + 1, CompDir, + DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath, + Result)); + EXPECT_STREQ(Result.c_str(), "a dir/b dir/b file"); +} + } // end anonymous namespace |