Add caching of build id in MapInfo object.
Change the GetBuildID function to return a std::string.
Added benchmark to check how long it takes to get the build id from
a file versus an elf object.
Added a way to get an elf without passing in a valid process_memory and
added tests for this.
Test: New unit tests.
Change-Id: I3029019767e0181c758d611fe635bc1bf72d6e8e
diff --git a/libunwindstack/Elf.cpp b/libunwindstack/Elf.cpp
index 5b586a2..2f5eed9 100644
--- a/libunwindstack/Elf.cpp
+++ b/libunwindstack/Elf.cpp
@@ -140,8 +140,11 @@
return true;
}
-bool Elf::GetBuildID(std::string* build_id) {
- return valid_ && interface_->GetBuildID(build_id);
+std::string Elf::GetBuildID() {
+ if (!valid_) {
+ return "";
+ }
+ return interface_->GetBuildID();
}
void Elf::GetLastError(ErrorData* data) {
@@ -384,4 +387,22 @@
return false;
}
+std::string Elf::GetBuildID(Memory* memory) {
+ if (!IsValidElf(memory)) {
+ return "";
+ }
+
+ uint8_t class_type;
+ if (!memory->Read(EI_CLASS, &class_type, 1)) {
+ return "";
+ }
+
+ if (class_type == ELFCLASS32) {
+ return ElfInterface::ReadBuildIDFromMemory<Elf32_Ehdr, Elf32_Shdr, Elf32_Nhdr>(memory);
+ } else if (class_type == ELFCLASS64) {
+ return ElfInterface::ReadBuildIDFromMemory<Elf64_Ehdr, Elf64_Shdr, Elf64_Nhdr>(memory);
+ }
+ return "";
+}
+
} // namespace unwindstack