summaryrefslogtreecommitdiffstats
path: root/libunwindstack
diff options
context:
space:
mode:
authorChristopher Ferris <cferris@google.com>2019-01-26 07:03:35 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2019-01-26 07:03:35 +0000
commit49047d711be157376b50a0d23e14c496653a234b (patch)
tree34a6603ba9bec0ff91073e17636a2c3ec94db72a /libunwindstack
parented7ca8bb1499bfa6ae2ed00fa5f19239d2b998f1 (diff)
parentb1c9c20eb270e54de95000d8923813c6a44fe467 (diff)
downloadsystem_core-49047d711be157376b50a0d23e14c496653a234b.tar.gz
system_core-49047d711be157376b50a0d23e14c496653a234b.tar.bz2
system_core-49047d711be157376b50a0d23e14c496653a234b.zip
Merge "Add GetPrintableBuildID()."
Diffstat (limited to 'libunwindstack')
-rw-r--r--libunwindstack/MapInfo.cpp14
-rw-r--r--libunwindstack/include/unwindstack/MapInfo.h4
-rw-r--r--libunwindstack/tests/MapInfoGetBuildIDTest.cpp3
3 files changed, 21 insertions, 0 deletions
diff --git a/libunwindstack/MapInfo.cpp b/libunwindstack/MapInfo.cpp
index f3199711b..9e6bcd4e3 100644
--- a/libunwindstack/MapInfo.cpp
+++ b/libunwindstack/MapInfo.cpp
@@ -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
diff --git a/libunwindstack/include/unwindstack/MapInfo.h b/libunwindstack/include/unwindstack/MapInfo.h
index 5143ff1f5..e938986d8 100644
--- a/libunwindstack/include/unwindstack/MapInfo.h
+++ b/libunwindstack/include/unwindstack/MapInfo.h
@@ -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;
diff --git a/libunwindstack/tests/MapInfoGetBuildIDTest.cpp b/libunwindstack/tests/MapInfoGetBuildIDTest.cpp
index 3b89c5961..ea9befcda 100644
--- a/libunwindstack/tests/MapInfoGetBuildIDTest.cpp
+++ b/libunwindstack/tests/MapInfoGetBuildIDTest.cpp
@@ -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) {