Merge "Add GetPrintableBuildID()."

am: 49047d711b

Change-Id: If23b529363e07473a498896ef493565f7a4cecb5
This commit is contained in:
Christopher Ferris 2019-01-25 23:09:38 -08:00 committed by android-build-merger
commit 8bd4aa963a
3 changed files with 21 additions and 0 deletions

View file

@ -22,6 +22,8 @@
#include <mutex>
#include <string>
#include <android-base/stringprintf.h>
#include <unwindstack/Elf.h>
#include <unwindstack/MapInfo.h>
#include <unwindstack/Maps.h>
@ -311,4 +313,16 @@ std::string MapInfo::GetBuildID() {
return *reinterpret_cast<std::string*>(id);
}
std::string MapInfo::GetPrintableBuildID() {
std::string raw_build_id = GetBuildID();
if (raw_build_id.empty()) {
return "";
}
std::string printable_build_id;
for (const char& c : raw_build_id) {
printable_build_id += android::base::StringPrintf("%02x", c);
}
return printable_build_id;
}
} // namespace unwindstack

View file

@ -84,8 +84,12 @@ struct MapInfo {
bool GetFunctionName(uint64_t addr, std::string* name, uint64_t* func_offset);
// Returns the raw build id read from the elf data.
std::string GetBuildID();
// Returns the printable version of the build id (hex dump of raw data).
std::string GetPrintableBuildID();
private:
MapInfo(const MapInfo&) = delete;
void operator=(const MapInfo&) = delete;

View file

@ -67,6 +67,7 @@ TEST_F(MapInfoGetBuildIDTest, no_elf_and_no_valid_elf_in_memory) {
MapInfo info(nullptr, 0x1000, 0x2000, 0, PROT_READ, "");
EXPECT_EQ("", info.GetBuildID());
EXPECT_EQ("", info.GetPrintableBuildID());
}
TEST_F(MapInfoGetBuildIDTest, from_elf) {
@ -74,6 +75,7 @@ TEST_F(MapInfoGetBuildIDTest, from_elf) {
elf_interface_->FakeSetBuildID("FAKE_BUILD_ID");
EXPECT_EQ("FAKE_BUILD_ID", map_info_->GetBuildID());
EXPECT_EQ("46414b455f4255494c445f4944", map_info_->GetPrintableBuildID());
}
void MapInfoGetBuildIDTest::MultipleThreadTest(std::string expected_build_id) {
@ -172,6 +174,7 @@ TEST_F(MapInfoGetBuildIDTest, from_memory) {
InitElfData(tf_->fd);
EXPECT_EQ("ELF_BUILDID", map_info_->GetBuildID());
EXPECT_EQ("454c465f4255494c444944", map_info_->GetPrintableBuildID());
}
TEST_F(MapInfoGetBuildIDTest, multiple_thread_elf_exists_in_memory) {