fix symboling elf in hap

Signed-off-by: yuyanqinghw <yuyanqing539@huawei.com>
This commit is contained in:
yuyanqinghw 2024-08-07 11:38:36 +08:00
parent 7f486093ab
commit 17ec05bd21
4 changed files with 17 additions and 5 deletions

View File

@ -26,8 +26,8 @@
"c_utils",
"bundle_framework",
"faultloggerd",
"init",
"ability_base"
"init",
"ability_base"
],
"third_party": [
"zlib",

View File

@ -481,6 +481,7 @@ bool PerfFileWriter::AddSymbolsFeature(
HLOGV("add feature symbolsFiles %zu", symbolsFiles.size());
std::vector<SymbolFileStruct> symbolFileStructs {};
for (auto &symbolsFile : symbolsFiles) {
HLOGV("add feature symbolsFile %s", symbolsFile->filePath_.c_str());
if (symbolsFile->SymbolsLoaded()) {
auto &symbolsFileStruct = symbolFileStructs.emplace_back();
symbolsFile->ExportSymbolToFileFormat(symbolsFileStruct);

View File

@ -410,6 +410,9 @@ private:
AdjustSymbols();
HLOGD("%zu symbols loadded from elf '%s'.", symbols_.size(), elfPath.c_str());
for (auto& symbol: symbols_) {
HLOGD("symbol %s", symbol.ToDebugString().c_str());
}
if (buildId_.empty()) {
HLOGD("buildId not found from elf '%s'.", elfPath.c_str());
// don't failed. some time the lib have not got the build id
@ -934,6 +937,11 @@ public:
}
hapExtracted_ = true;
HLOGD("the symbol file is %s.", filePath_.c_str());
if (StringEndsWith(filePath_, ".hap") && map_->IsMapExec()) {
HLOGD("map is exec not abc file , the symbol file is:%s", map_->name.c_str());
return false;
}
if (StringEndsWith(filePath_, ".hap") || StringEndsWith(filePath_, ".hsp")) {
dfxExtractor_ = std::make_unique<DfxExtractor>(filePath_);
if (!dfxExtractor_->GetHapAbcInfo(loadOffSet_, abcDataPtr_, abcDataSize_)) {
@ -979,10 +987,10 @@ public:
bool LoadDebugInfo(std::shared_ptr<DfxMap> map, const std::string &symbolFilePath) override
{
HLOGD("map ptr:%p, map name:%s", map.get(), map->name.c_str());
if (debugInfoLoaded_) {
return true;
}
debugInfoLoaded_ = true;
if (!onRecording_) {
return true;
}
@ -990,13 +998,14 @@ public:
if (!IsHapAbc()) {
ElfFileSymbols::LoadDebugInfo(map, "");
}
debugInfoLoaded_ = true;
debugInfoLoadResult_ = true;
return true;
}
bool LoadSymbols(std::shared_ptr<DfxMap> map, const std::string &symbolFilePath) override
{
HLOGD("map ptr:%p, map name:%s", map.get(), map->name.c_str());
if (symbolsLoaded_ || !onRecording_) {
return true;
}

View File

@ -189,12 +189,14 @@ bool VirtualRuntime::UpdateHapSymbols(std::shared_ptr<DfxMap> map)
if (map == nullptr) {
return false;
}
HLOGV("hap name:%s", map->name.c_str());
// found it by name
auto symbolsFile = SymbolsFile::CreateSymbolsFile(map->name);
if (symbolsFile == nullptr) {
HLOGV("Failed to load CreateSymbolsFile for exec section in hap(%s)", map->name.c_str());
return false;
}
symbolsFile->SetMapsInfo(map);
// update maps name if load debuginfo successfully
if (!symbolsFile->LoadDebugInfo(map)) {
HLOGV("Failed to load debuginfo for exec section in hap(%s)", map->name.c_str());
@ -885,7 +887,7 @@ void VirtualRuntime::UpdateSymbols(std::shared_ptr<DfxMap> map, pid_t pid)
for (size_t i = 0; i < symbolsFiles_.size(); ++i) {
if (symbolsFiles_[i]->filePath_ == map->name) {
map->symbolFileIndex = static_cast<int32_t>(i);
HLOGV("already have '%s'", map->name.c_str());
HLOGV("already have '%s', symbol index:%zu", map->name.c_str(), i);
return;
}
}