Commit 8feeb7e4 authored by Matt Ma's avatar Matt Ma Committed by Facebook Github Bot

Prefer linkage name to name for inline function frames.

Summary: Linkage name (DW_AT_linkage_name) contains more information than the identifier name (DW_AT_name).

Reviewed By: luciang

Differential Revision: D19437477

fbshipit-source-id: 1755a71678cbe9e90ba7bc085e4c46b7784c273e
parent 1c998314
......@@ -538,30 +538,35 @@ bool Dwarf::findLocation(
inlineLocIter++, inlineFrameIter++) {
inlineFrameIter->location.line = callerLine;
callerLine = inlineLocIter->line;
folly::Optional<folly::StringPiece> linkageName;
folly::Optional<folly::StringPiece> name;
folly::Optional<uint64_t> file;
forEachAttribute(
cu, inlineLocIter->die, [&](const detail::Attribute& attr) {
switch (attr.spec.name) {
case DW_AT_linkage_name:
linkageName = boost::get<folly::StringPiece>(attr.attrValue);
break;
case DW_AT_name:
name = boost::get<StringPiece>(attr.attrValue);
name = boost::get<folly::StringPiece>(attr.attrValue);
break;
case DW_AT_decl_file:
file = boost::get<uint64_t>(attr.attrValue);
break;
}
return !file.has_value() || !name.has_value();
return !file || !name || !linkageName;
});
if (!name.has_value() || !file.has_value()) {
if (!(name || linkageName) || !file) {
break;
}
inlineFrameIter->found = true;
inlineFrameIter->addr = address;
inlineFrameIter->name = name.value().data();
inlineFrameIter->name =
linkageName ? linkageName.value().data() : name.value().data();
inlineFrameIter->location.hasFileAndLine = true;
inlineFrameIter->location.name = name.value();
inlineFrameIter->location.name =
linkageName ? linkageName.value() : name.value();
inlineFrameIter->location.file = lineVM.getFullFileName(file.value());
}
locationInfo.line = callerLine;
......@@ -656,7 +661,7 @@ detail::Die Dwarf::findDefinitionDie(
return true;
});
if (!offset.hasValue()) {
if (!offset) {
return die;
}
return getDieAtOffset(cu, cu.offset + offset.value());
......
......@@ -159,12 +159,15 @@ void verifyStackTrace(
const std::string& barName,
size_t barLine) {
EXPECT_TRUE(frames.frameCount == 14 || frames.frameCount == 15);
EXPECT_EQ("inlineFoo<100>", std::string(frames.frames[5].name));
EXPECT_EQ(
"void folly::symbolizer::test::(anonymous namespace)::inlineFoo<100ul>("
"folly::symbolizer::FrameArray<100ul>&)",
std::string(folly::demangle(frames.frames[5].name)));
EXPECT_EQ(
"folly/experimental/symbolizer/test/SymbolizerTest.cpp",
std::string(frames.frames[5].location.file.toString()));
EXPECT_EQ(kQsortCallLineNo, frames.frames[5].location.line);
EXPECT_EQ(barName, std::string(frames.frames[6].name));
EXPECT_EQ(barName, std::string(folly::demangle(frames.frames[6].name)));
EXPECT_EQ(
"folly/experimental/symbolizer/test/SymbolizerTest.cpp",
std::string(frames.frames[6].location.file.toString()));
......@@ -213,14 +216,13 @@ TEST(SymbolizerTest, InlineFunctionBasic) {
// clang-format off
// Expected full stack trace with @mode/dev. The last frame is missing in opt
// mode.
// Frame: _ZN5folly10symbolizer13getStackTraceEPmm
// Frame: getStackTrace<100>
// Frame: _ZN5folly10symbolizer13getStackTraceILm100EEEbRNS0_10FrameArrayIXT_EEE
// Frame: _ZN5folly10symbolizer4test10comparatorILm100EEEiPKvS4_
// Frame: msort_with_tmp.part.0
// Frame: __GI___qsort_r
// Frame: inlineFoo<100>
// Frame: inlineBar<100>
// Frame: _ZN5folly10symbolizer4test43SymbolizerTest_InlineFunctionWithCache_Test8TestBodyEv
// Frame: _ZN5folly10symbolizer4test12_GLOBAL__N_19inlineFooILm100EEEvRNS0_10FrameArrayIXT_EEE
// Frame: _ZN5folly10symbolizer4test12_GLOBAL__N_19inlineBarILm100EEEvRNS0_10FrameArrayIXT_EEE
// Frame: _ZN5folly10symbolizer4test39SymbolizerTest_InlineFunctionBasic_Test8TestBodyEv
// Frame: _ZN7testing8internal35HandleExceptionsInMethodIfSupportedINS_4TestEvEET0_PT_MS4_FS3_vEPKc
// Frame: _ZN7testing4Test3RunEv
// Frame: _ZN7testing8TestInfo3RunEv
......@@ -229,7 +231,11 @@ TEST(SymbolizerTest, InlineFunctionBasic) {
// Frame: _ZN7testing8UnitTest3RunEv
// Frame: _Z13RUN_ALL_TESTSv
// clang-format on
verifyStackTrace(frames, "inlineBar<100>", kFooCallByStandaloneBarLineNo);
verifyStackTrace(
frames,
"void folly::symbolizer::test::(anonymous namespace)::inlineBar<100ul>("
"folly::symbolizer::FrameArray<100ul>&)",
kFooCallByStandaloneBarLineNo);
FrameArray<100> frames2;
inlineBar<100>(frames2);
......@@ -246,7 +252,11 @@ TEST(SymbolizerTest, InlineClassMemberFunction) {
obj.inlineBar(frames);
symbolizer.symbolize(frames);
verifyStackTrace(frames, "inlineBar", kFooCallByClassBarLineNo);
verifyStackTrace(
frames,
"folly::symbolizer::test::ClassWithInlineFunctions::inlineBar("
"folly::symbolizer::FrameArray<100ul>&) const",
kFooCallByClassBarLineNo);
}
TEST(SymbolizerTest, StaticInlineClassMemberFunction) {
......@@ -256,7 +266,11 @@ TEST(SymbolizerTest, StaticInlineClassMemberFunction) {
ClassWithInlineFunctions::staticInlineBar(frames);
symbolizer.symbolize(frames);
verifyStackTrace(frames, "staticInlineBar", kFooCallByClassStaticBarLineNo);
verifyStackTrace(
frames,
"folly::symbolizer::test::ClassWithInlineFunctions::staticInlineBar("
"folly::symbolizer::FrameArray<100ul>&)",
kFooCallByClassStaticBarLineNo);
}
// No inline frames should be filled because of no extra frames.
......@@ -281,7 +295,11 @@ TEST(SymbolizerTest, InlineFunctionWithCache) {
inlineBar<100>(frames);
symbolizer.symbolize(frames);
verifyStackTrace(frames, "inlineBar<100>", kFooCallByStandaloneBarLineNo);
verifyStackTrace(
frames,
"void folly::symbolizer::test::(anonymous namespace)::inlineBar<100ul>("
"folly::symbolizer::FrameArray<100ul>&)",
kFooCallByStandaloneBarLineNo);
FrameArray<100> frames2;
inlineBar<100>(frames2);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment