1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 20:51:52 +01:00

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
This commit is contained in:
Greg Clayton 2020-02-15 21:28:36 -08:00
parent 8c7beab605
commit 76f7457508
4 changed files with 27 additions and 21 deletions

View File

@ -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);

View File

@ -223,6 +223,7 @@ llvm::Expected<LookupResult> 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<LookupResult> 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;

View File

@ -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;

View File

@ -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}));
}