Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8bd4aa96 authored by Christopher Ferris's avatar Christopher Ferris Committed by android-build-merger
Browse files

Merge "Add GetPrintableBuildID()."

am: 49047d71

Change-Id: If23b529363e07473a498896ef493565f7a4cecb5
parents 9a96618c 49047d71
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -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
+4 −0
Original line number Diff line number Diff line
@@ -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;
+3 −0
Original line number Diff line number Diff line
@@ -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) {