From 02a6c448c32c37aae834bc25e92db97bfac32524 Mon Sep 17 00:00:00 2001 From: Christopher Ferris Date: Mon, 11 Mar 2019 14:43:33 -0700 Subject: Add support for displaying soname in an apk. Changes: - Change GetSoname to always returns a std::string. - Added new unit tests for the soname printing. - Modify the GetElf() function to save the same elf when we see rosegment linkers that split the read-only and read-write across a map. This avoids creating multiple elf objects for each map. - Fixed a few offline unwind tests. Bug: 29218999 Test: Unit tests pass. Change-Id: Iad7c38b5c2957a8c5fd4ba94ebec335bafcad57d --- libunwindstack/ElfInterface.cpp | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'libunwindstack/ElfInterface.cpp') diff --git a/libunwindstack/ElfInterface.cpp b/libunwindstack/ElfInterface.cpp index c1b98d999..12efb9487 100644 --- a/libunwindstack/ElfInterface.cpp +++ b/libunwindstack/ElfInterface.cpp @@ -374,13 +374,12 @@ void ElfInterface::ReadSectionHeaders(const EhdrType& ehdr) { } template -bool ElfInterface::GetSonameWithTemplate(std::string* soname) { +std::string ElfInterface::GetSonameWithTemplate() { if (soname_type_ == SONAME_INVALID) { - return false; + return ""; } if (soname_type_ == SONAME_VALID) { - *soname = soname_; - return true; + return soname_; } soname_type_ = SONAME_INVALID; @@ -397,7 +396,7 @@ bool ElfInterface::GetSonameWithTemplate(std::string* soname) { if (!memory_->ReadFully(offset, &dyn, sizeof(dyn))) { last_error_.code = ERROR_MEMORY_INVALID; last_error_.address = offset; - return false; + return ""; } if (dyn.d_tag == DT_STRTAB) { @@ -416,17 +415,16 @@ bool ElfInterface::GetSonameWithTemplate(std::string* soname) { if (entry.first == strtab_addr) { soname_offset = entry.second + soname_offset; if (soname_offset >= entry.second + strtab_size) { - return false; + return ""; } if (!memory_->ReadString(soname_offset, &soname_)) { - return false; + return ""; } soname_type_ = SONAME_VALID; - *soname = soname_; - return true; + return soname_; } } - return false; + return ""; } template @@ -653,8 +651,8 @@ template void ElfInterface::ReadSectionHeaders(const Elf template std::string ElfInterface::ReadBuildID(); template std::string ElfInterface::ReadBuildID(); -template bool ElfInterface::GetSonameWithTemplate(std::string*); -template bool ElfInterface::GetSonameWithTemplate(std::string*); +template std::string ElfInterface::GetSonameWithTemplate(); +template std::string ElfInterface::GetSonameWithTemplate(); template bool ElfInterface::GetFunctionNameWithTemplate(uint64_t, std::string*, uint64_t*); -- cgit v1.2.3