From 76f7457508347fe0ad4c0b5e1aa2f1061867af4e Mon Sep 17 00:00:00 2001 From: Greg Clayton Date: Sat, 15 Feb 2020 21:28:36 -0800 Subject: [PATCH] Add an Offset field to the SourceLocation for LookupResult objects. Summary: The Offset provides the offset within the function in a SourceLocation struct. This allows us to show the byte offset within a function. We also track offsets within inline functions as well. Updated the lookup tests to verify the offset for functions and inline functions. 0x1000: main + 32 @ /tmp/main.cpp:45 Reviewers: labath, aadsm, serhiy.redko, jankratochvil, xiaobai, wallace, aprantl, JDevlieghere Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D74680 --- include/llvm/DebugInfo/GSYM/LookupResult.h | 4 ++- lib/DebugInfo/GSYM/FunctionInfo.cpp | 2 ++ lib/DebugInfo/GSYM/InlineInfo.cpp | 2 ++ unittests/DebugInfo/GSYM/GSYMTest.cpp | 40 +++++++++++----------- 4 files changed, 27 insertions(+), 21 deletions(-) diff --git a/include/llvm/DebugInfo/GSYM/LookupResult.h b/include/llvm/DebugInfo/GSYM/LookupResult.h index 746fd36208e..693a02c50f1 100644 --- a/include/llvm/DebugInfo/GSYM/LookupResult.h +++ b/include/llvm/DebugInfo/GSYM/LookupResult.h @@ -24,11 +24,13 @@ struct SourceLocation { StringRef Dir; ///< Line entry source file directory path. StringRef Base; ///< Line entry source file basename. uint32_t Line = 0; ///< Source file line number. + uint32_t Offset = 0; ///< Byte size offset within the named function. }; inline bool operator==(const SourceLocation &LHS, const SourceLocation &RHS) { return LHS.Name == RHS.Name && LHS.Dir == RHS.Dir && - LHS.Base == RHS.Base && LHS.Line == RHS.Line; + LHS.Base == RHS.Base && LHS.Line == RHS.Line && + LHS.Offset == RHS.Offset; } raw_ostream &operator<<(raw_ostream &OS, const SourceLocation &R); diff --git a/lib/DebugInfo/GSYM/FunctionInfo.cpp b/lib/DebugInfo/GSYM/FunctionInfo.cpp index a555d4e115a..f8afd2c9805 100644 --- a/lib/DebugInfo/GSYM/FunctionInfo.cpp +++ b/lib/DebugInfo/GSYM/FunctionInfo.cpp @@ -223,6 +223,7 @@ llvm::Expected FunctionInfo::lookup(DataExtractor &Data, // location as best we can and return. SourceLocation SrcLoc; SrcLoc.Name = LR.FuncName; + SrcLoc.Offset = Addr - FuncAddr; LR.Locations.push_back(SrcLoc); return LR; } @@ -235,6 +236,7 @@ llvm::Expected FunctionInfo::lookup(DataExtractor &Data, SourceLocation SrcLoc; SrcLoc.Name = LR.FuncName; + SrcLoc.Offset = Addr - FuncAddr; SrcLoc.Dir = GR.getString(LineEntryFile->Dir); SrcLoc.Base = GR.getString(LineEntryFile->Base); SrcLoc.Line = LineEntry->Line; diff --git a/lib/DebugInfo/GSYM/InlineInfo.cpp b/lib/DebugInfo/GSYM/InlineInfo.cpp index 11f3d48d7b0..21679b1b78a 100644 --- a/lib/DebugInfo/GSYM/InlineInfo.cpp +++ b/lib/DebugInfo/GSYM/InlineInfo.cpp @@ -145,10 +145,12 @@ static bool lookup(const GsymReader &GR, DataExtractor &Data, uint64_t &Offset, if (CallFile->Dir || CallFile->Base) { SourceLocation SrcLoc; SrcLoc.Name = SrcLocs.back().Name; + SrcLoc.Offset = SrcLocs.back().Offset; SrcLoc.Dir = GR.getString(CallFile->Dir); SrcLoc.Base = GR.getString(CallFile->Base); SrcLoc.Line = Inline.CallLine; SrcLocs.back().Name = GR.getString(Inline.Name); + SrcLocs.back().Offset = Addr - Inline.Ranges[0].Start; SrcLocs.push_back(SrcLoc); } return true; diff --git a/unittests/DebugInfo/GSYM/GSYMTest.cpp b/unittests/DebugInfo/GSYM/GSYMTest.cpp index d818edd72b4..8a9afc14e09 100644 --- a/unittests/DebugInfo/GSYM/GSYMTest.cpp +++ b/unittests/DebugInfo/GSYM/GSYMTest.cpp @@ -1362,45 +1362,45 @@ TEST(GSYMTest, TestGsymLookups) { LR = GR->lookup(0x100F); ASSERT_THAT_EXPECTED(LR, Succeeded()); EXPECT_THAT(LR->Locations, - testing::ElementsAre(SourceLocation{"main", "/tmp", "main.c", 5})); + testing::ElementsAre(SourceLocation{"main", "/tmp", "main.c", 5, 15})); LR = GR->lookup(0x1010); ASSERT_THAT_EXPECTED(LR, Succeeded()); EXPECT_THAT(LR->Locations, testing::ElementsAre(SourceLocation{"inline1", "/tmp", "foo.h", 10}, - SourceLocation{"main", "/tmp", "main.c", 6})); + SourceLocation{"main", "/tmp", "main.c", 6, 16})); LR = GR->lookup(0x1012); ASSERT_THAT_EXPECTED(LR, Succeeded()); EXPECT_THAT(LR->Locations, testing::ElementsAre(SourceLocation{"inline2", "/tmp", "foo.h", 20}, - SourceLocation{"inline1", "/tmp", "foo.h", 33}, - SourceLocation{"main", "/tmp", "main.c", 6})); + SourceLocation{"inline1", "/tmp", "foo.h", 33, 2}, + SourceLocation{"main", "/tmp", "main.c", 6, 18})); LR = GR->lookup(0x1014); ASSERT_THAT_EXPECTED(LR, Succeeded()); EXPECT_THAT(LR->Locations, - testing::ElementsAre(SourceLocation{"inline1", "/tmp", "foo.h", 11}, - SourceLocation{"main", "/tmp", "main.c", 6})); + testing::ElementsAre(SourceLocation{"inline1", "/tmp", "foo.h", 11, 4}, + SourceLocation{"main", "/tmp", "main.c", 6, 20})); LR = GR->lookup(0x1016); ASSERT_THAT_EXPECTED(LR, Succeeded()); EXPECT_THAT(LR->Locations, testing::ElementsAre(SourceLocation{"inline3", "/tmp", "foo.h", 30}, - SourceLocation{"inline1", "/tmp", "foo.h", 35}, - SourceLocation{"main", "/tmp", "main.c", 6})); + SourceLocation{"inline1", "/tmp", "foo.h", 35, 6}, + SourceLocation{"main", "/tmp", "main.c", 6, 22})); LR = GR->lookup(0x1018); ASSERT_THAT_EXPECTED(LR, Succeeded()); EXPECT_THAT(LR->Locations, - testing::ElementsAre(SourceLocation{"inline1", "/tmp", "foo.h", 12}, - SourceLocation{"main", "/tmp", "main.c", 6})); + testing::ElementsAre(SourceLocation{"inline1", "/tmp", "foo.h", 12, 8}, + SourceLocation{"main", "/tmp", "main.c", 6, 24})); LR = GR->lookup(0x1020); ASSERT_THAT_EXPECTED(LR, Succeeded()); EXPECT_THAT(LR->Locations, - testing::ElementsAre(SourceLocation{"main", "/tmp", "main.c", 8})); + testing::ElementsAre(SourceLocation{"main", "/tmp", "main.c", 8, 32})); } @@ -1968,32 +1968,32 @@ TEST(GSYMTest, TestDWARFInlineInfo) { LR = GR->lookup(0x1100-1); ASSERT_THAT_EXPECTED(LR, Succeeded()); EXPECT_THAT(LR->Locations, - testing::ElementsAre(SourceLocation{"main", "/tmp", "main.c", 10})); + testing::ElementsAre(SourceLocation{"main", "/tmp", "main.c", 10, 255})); LR = GR->lookup(0x1100); ASSERT_THAT_EXPECTED(LR, Succeeded()); EXPECT_THAT(LR->Locations, testing::ElementsAre(SourceLocation{"inline1", "/tmp", "inline.h", 20}, - SourceLocation{"main", "/tmp", "main.c", 10})); + SourceLocation{"main", "/tmp", "main.c", 10, 256})); LR = GR->lookup(0x1180-1); ASSERT_THAT_EXPECTED(LR, Succeeded()); EXPECT_THAT(LR->Locations, - testing::ElementsAre(SourceLocation{"inline1", "/tmp", "inline.h", 20}, - SourceLocation{"main", "/tmp", "main.c", 10})); + testing::ElementsAre(SourceLocation{"inline1", "/tmp", "inline.h", 20, 127}, + SourceLocation{"main", "/tmp", "main.c", 10, 383})); LR = GR->lookup(0x1180); ASSERT_THAT_EXPECTED(LR, Succeeded()); EXPECT_THAT(LR->Locations, - testing::ElementsAre(SourceLocation{"inline1", "/tmp", "inline.h", 21}, - SourceLocation{"main", "/tmp", "main.c", 10})); + testing::ElementsAre(SourceLocation{"inline1", "/tmp", "inline.h", 21, 128}, + SourceLocation{"main", "/tmp", "main.c", 10, 384})); LR = GR->lookup(0x1200-1); ASSERT_THAT_EXPECTED(LR, Succeeded()); EXPECT_THAT(LR->Locations, - testing::ElementsAre(SourceLocation{"inline1", "/tmp", "inline.h", 21}, - SourceLocation{"main", "/tmp", "main.c", 10})); + testing::ElementsAre(SourceLocation{"inline1", "/tmp", "inline.h", 21, 255}, + SourceLocation{"main", "/tmp", "main.c", 10, 511})); LR = GR->lookup(0x1200); ASSERT_THAT_EXPECTED(LR, Succeeded()); EXPECT_THAT(LR->Locations, - testing::ElementsAre(SourceLocation{"main", "/tmp", "main.c", 11})); + testing::ElementsAre(SourceLocation{"main", "/tmp", "main.c", 11, 512})); }