mirror of
https://gitee.com/openharmony/developtools_profiler
synced 2024-11-27 00:51:47 +00:00
commit
feb7ad8118
@ -112,6 +112,9 @@ public:
|
||||
#endif
|
||||
const bool loadSymboleWhenNeeded_ = true; // thie is a feature config
|
||||
void UpdateSymbols(std::string filename);
|
||||
// we don't know whether hap vma mapping is stand for a so
|
||||
// thus we need try to parse it first
|
||||
bool UpdateHapSymbols(std::shared_ptr<DfxMap> map);
|
||||
bool IsSymbolExist(const std::string& fileName);
|
||||
void DelSymbolFile(const std::string& fileName);
|
||||
void UpdateMaps(pid_t pid, pid_t tid);
|
||||
|
@ -136,7 +136,13 @@ const std::string SymbolsFile::FindSymbolFile(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto pathSplit = StringSplit(symboleFilePath, "!");
|
||||
if (pathSplit.size() > 1) {
|
||||
HLOGV("base name is: %s ", pathSplit.back().c_str());
|
||||
if (StringEndsWith(pathSplit[0], ".hap")) {
|
||||
foundPath = pathSplit[0];
|
||||
}
|
||||
}
|
||||
// only access the patch in onRecording_
|
||||
// in report mode we don't load any thing in runtime path
|
||||
if (foundPath.empty() and onRecording_) {
|
||||
@ -195,24 +201,33 @@ protected:
|
||||
if (StringEndsWith(elfPath, ".hap")) {
|
||||
elfFile_ = DfxElf::CreateFromHap(elfPath, map->prevMap, map->offset);
|
||||
map->elf = elfFile_;
|
||||
HLOGD("loaded map %s", elfPath.c_str());
|
||||
} else {
|
||||
elfFile_ = std::make_shared<DfxElf>(elfPath);
|
||||
HLOGD("loaded elf %s", elfPath.c_str());
|
||||
}
|
||||
}
|
||||
if (!elfFile_->IsValid()) {
|
||||
HLOGD("parser elf file failed.");
|
||||
|
||||
if (elfFile_ == nullptr) {
|
||||
HLOGE("Failed to create elf file for %s.", elfPath.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
auto ptloads = elfFile_->GetPtLoads();
|
||||
for (const auto &ptload : ptloads) {
|
||||
if (textExecVaddr_ != std::min(textExecVaddr_, ptload.second.tableVaddr)) {
|
||||
textExecVaddr_ = std::min(textExecVaddr_, ptload.second.tableVaddr);
|
||||
textExecVaddrFileOffset_ = ptload.second.offset;
|
||||
}
|
||||
if (!elfFile_->IsValid()) {
|
||||
HLOGE("parse elf file failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
HLOGD("loaded elf %s", elfPath.c_str());
|
||||
// update path for so in hap
|
||||
if (StringEndsWith(elfPath, ".hap")) {
|
||||
filePath_ = elfPath + "!" + elfFile_->GetElfName();
|
||||
HLOGD("update path for so in hap %s.", filePath_.c_str());
|
||||
map->name = filePath_;
|
||||
map->elf = elfFile_;
|
||||
map->prevMap->name = filePath_;
|
||||
map->prevMap->elf = elfFile_;
|
||||
}
|
||||
textExecVaddr_ = elfFile_->GetStartVaddr();
|
||||
textExecVaddrFileOffset_ = elfFile_->GetStartOffset();
|
||||
HLOGD("textExecVaddr_ 0x%016" PRIx64 " file offset 0x%016" PRIx64 "", textExecVaddr_,
|
||||
textExecVaddrFileOffset_);
|
||||
|
||||
@ -347,26 +362,23 @@ private:
|
||||
#ifdef HIPERF_DEBUG_TIME
|
||||
const auto startTime = steady_clock::now();
|
||||
#endif
|
||||
if (StringEndsWith(elfPath, ".hap") && map != nullptr) {
|
||||
elfFile_ = DfxElf::CreateFromHap(elfPath, map->prevMap, map->offset);
|
||||
map->elf = elfFile_;
|
||||
HLOGD("loaded map %s", elfPath.c_str());
|
||||
} else {
|
||||
elfFile_ = std::make_shared<DfxElf>(elfPath);
|
||||
HLOGD("loaded elf %s", elfPath.c_str());
|
||||
if (elfFile_ == nullptr) {
|
||||
if (StringEndsWith(elfPath, ".hap") && map != nullptr) {
|
||||
elfFile_ = DfxElf::CreateFromHap(elfPath, map->prevMap, map->offset);
|
||||
map->elf = elfFile_;
|
||||
HLOGD("loaded map %s", elfPath.c_str());
|
||||
} else {
|
||||
elfFile_ = std::make_shared<DfxElf>(elfPath);
|
||||
HLOGD("loaded elf %s", elfPath.c_str());
|
||||
}
|
||||
}
|
||||
if (!elfFile_->IsValid()) {
|
||||
|
||||
if (elfFile_ == nullptr || !elfFile_->IsValid()) {
|
||||
HLOGD("parser elf file failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
auto ptloads = elfFile_->GetPtLoads();
|
||||
for (const auto &ptload : ptloads) {
|
||||
if (textExecVaddr_ != std::min(textExecVaddr_, ptload.second.tableVaddr)) {
|
||||
textExecVaddr_ = std::min(textExecVaddr_, ptload.second.tableVaddr);
|
||||
textExecVaddrFileOffset_ = ptload.second.offset;
|
||||
}
|
||||
}
|
||||
textExecVaddr_ = elfFile_->GetStartVaddr();
|
||||
textExecVaddrFileOffset_ = elfFile_->GetStartOffset();
|
||||
HLOGD("textExecVaddr_ 0x%016" PRIx64 " file offset 0x%016" PRIx64 "", textExecVaddr_,
|
||||
textExecVaddrFileOffset_);
|
||||
|
||||
|
@ -293,6 +293,26 @@ void VirtualRuntime::UpdateSymbols(std::string fileName)
|
||||
#endif
|
||||
}
|
||||
|
||||
bool VirtualRuntime::UpdateHapSymbols(std::shared_ptr<DfxMap> map)
|
||||
{
|
||||
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;
|
||||
}
|
||||
// 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());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!loadSymboleWhenNeeded_) {
|
||||
symbolsFile->LoadSymbols(map);
|
||||
}
|
||||
symbolsFiles_[symbolsFile->filePath_] = (std::move(symbolsFile));
|
||||
return true;
|
||||
}
|
||||
|
||||
const DfxSymbol VirtualRuntime::GetKernelSymbol(uint64_t ip, const std::vector<std::shared_ptr<DfxMap>> &maps,
|
||||
const VirtualThread &thread)
|
||||
{
|
||||
@ -339,10 +359,9 @@ const DfxSymbol VirtualRuntime::GetUserSymbol(uint64_t ip, const VirtualThread &
|
||||
DfxSymbol vaddrSymbol(ip, thread.name_);
|
||||
auto [curMaps, itemIndex] = FindMap(ip);
|
||||
if (curMaps != nullptr) {
|
||||
auto symbolsFilesIter = symbolsFiles_.find(curMaps->name_);
|
||||
auto symbolsFilesIter = symbolsFiles_.find((curMaps->GetMaps())[itemIndex]->name);
|
||||
if (symbolsFilesIter != symbolsFiles_.end()) {
|
||||
auto symbolsFile = symbolsFilesIter->second.get();
|
||||
symbolsFile->LoadDebugInfo((curMaps->GetMaps())[itemIndex]);
|
||||
vaddrSymbol.fileVaddr_ =
|
||||
symbolsFile->GetVaddrInSymbols(ip, (curMaps->GetMaps())[itemIndex]->begin,
|
||||
(curMaps->GetMaps())[itemIndex]->offset);
|
||||
@ -500,6 +519,11 @@ void VirtualRuntime::HandleMapInfo(uint64_t begin, uint64_t length, uint32_t fla
|
||||
curMaps->soEnd_ = begin + length;
|
||||
std::shared_ptr<DfxMap> mapItem = std::make_shared<DfxMap>(begin, begin + length,
|
||||
offset, flags, curMaps->name_);
|
||||
if (mapItem->name.find(".hap") != std::string::npos && (mapItem->prots & PROT_EXEC)) {
|
||||
mapItem->prevMap = curMaps->GetMaps().back();
|
||||
HLOGD("update hap(%s) symbols", mapItem->name.c_str());
|
||||
UpdateHapSymbols(mapItem);
|
||||
}
|
||||
curMaps->AddMap(mapItem, false);
|
||||
}
|
||||
}
|
||||
|
@ -197,14 +197,12 @@ bool VirtualThread::ReadRoMemory(uint64_t vaddr, uint8_t *data, size_t size) con
|
||||
SymbolsFile *symbolsFile = FindSymbolsFileByMap((curMemMaps->GetMaps())[itemIndex]);
|
||||
if (symbolsFile != nullptr) {
|
||||
std::shared_ptr<DfxMap> map = (curMemMaps->GetMaps())[itemIndex];
|
||||
HLOGM("read vaddr from addr is 0x%" PRIx64 " at '%s'", vaddr - map->begin,
|
||||
curMemMaps->name_.c_str());
|
||||
HLOGM("read vaddr from addr is 0x%" PRIx64 " mapStart :0x%" PRIx64 " mapOffset :0x%" PRIx64 " at '%s'",
|
||||
vaddr - map->begin, map->begin, map->offset, map->name.c_str());
|
||||
map->elf = symbolsFile->GetElfFile();
|
||||
if (map->elf != nullptr) {
|
||||
auto fileOffset = map->FileOffsetFromAddr(vaddr);
|
||||
if (StringEndsWith(map->name, ".hap")) {
|
||||
fileOffset -= map->elf->GetBaseOffset();
|
||||
}
|
||||
fileOffset -= map->elf->GetBaseOffset();
|
||||
map->elf->Read(fileOffset, data, size);
|
||||
return true;
|
||||
}
|
||||
@ -230,18 +228,36 @@ bool VirtualThread::ParseMap(std::vector<std::shared_ptr<DfxMap>>& memMaps, bool
|
||||
}
|
||||
memMaps = dfxMaps->GetMaps();
|
||||
bool mapsAdded = !update;
|
||||
std::set<std::string> addSymbolFile;
|
||||
std::vector<std::shared_ptr<DfxMap>> tempMap;
|
||||
std::string tempMapName;
|
||||
std::shared_ptr<DfxMap> prevMap = nullptr;
|
||||
for (auto memMapItem : memMaps) {
|
||||
if (!update) {
|
||||
virtualruntime_->FillMapsCache(tempMapName, memMapItem);
|
||||
virtualruntime_->UpdateSymbols(memMapItem->name);
|
||||
bool updateNormalSymbol = true;
|
||||
if (memMapItem->name.find(".hap") != std::string::npos && (memMapItem->prots & PROT_EXEC)) {
|
||||
memMapItem->prevMap = prevMap;
|
||||
HLOGD("update hap(%s) symbols", memMapItem->name.c_str());
|
||||
updateNormalSymbol = !virtualruntime_->UpdateHapSymbols(memMapItem);
|
||||
}
|
||||
if (updateNormalSymbol) {
|
||||
virtualruntime_->UpdateSymbols(memMapItem->name);
|
||||
}
|
||||
prevMap = memMapItem;
|
||||
} else if (!virtualruntime_->IsSymbolExist(memMapItem->name)) {
|
||||
virtualruntime_->FillMapsCache(tempMapName, memMapItem);
|
||||
mapsAdded = true;
|
||||
tempMap.push_back(memMapItem);
|
||||
addSymbolFile.emplace(memMapItem->name);
|
||||
bool updateNormalSymbol = true;
|
||||
if (memMapItem->name.find(".hap") != std::string::npos && (memMapItem->prots & PROT_EXEC)) {
|
||||
memMapItem->prevMap = prevMap;
|
||||
HLOGD("update hap(%s) symbols", memMapItem->name.c_str());
|
||||
updateNormalSymbol = !virtualruntime_->UpdateHapSymbols(memMapItem);
|
||||
}
|
||||
if (updateNormalSymbol) {
|
||||
virtualruntime_->UpdateSymbols(memMapItem->name);
|
||||
}
|
||||
prevMap = memMapItem;
|
||||
}
|
||||
}
|
||||
|
||||
@ -260,11 +276,6 @@ bool VirtualThread::ParseMap(std::vector<std::shared_ptr<DfxMap>>& memMaps, bool
|
||||
}
|
||||
memMaps.insert(memMaps.end(), tempMap.begin(), tempMap.end());
|
||||
|
||||
for (const auto& it : addSymbolFile) {
|
||||
virtualruntime_->UpdateSymbols(it);
|
||||
HLOGD("add symbol file %s", it.c_str());
|
||||
}
|
||||
|
||||
if (mapsAdded) {
|
||||
HILOG_DEBUG(LOG_CORE, "maps changed and need sort");
|
||||
SortMaps();
|
||||
|
Loading…
Reference in New Issue
Block a user