summaryrefslogtreecommitdiff
path: root/libunwindstack/include/unwindstack
diff options
context:
space:
mode:
authorChristopher Ferris <cferris@google.com>2018-01-25 12:15:56 -0800
committerChristopher Ferris <cferris@google.com>2018-01-25 17:11:33 -0800
commita96466cb2985362311b93c1b140701eecfd44e25 (patch)
treed093691f9ed80eb367c6041a3d4c73200d2d4df2 /libunwindstack/include/unwindstack
parent5da6b7c58b3d9e44c27b81a24a687dcf807ccaaa (diff)
downloadunwinding-a96466cb2985362311b93c1b140701eecfd44e25.tar.gz
Add a global elf cache.
Bug: 65682279 Test: Ran new unit tests. Change-Id: I19c64614b2b11a27f58204d4cc34913c02e04c36
Diffstat (limited to 'libunwindstack/include/unwindstack')
-rw-r--r--libunwindstack/include/unwindstack/Elf.h13
-rw-r--r--libunwindstack/include/unwindstack/MapInfo.h5
2 files changed, 16 insertions, 2 deletions
diff --git a/libunwindstack/include/unwindstack/Elf.h b/libunwindstack/include/unwindstack/Elf.h
index e562d6d..a874709 100644
--- a/libunwindstack/include/unwindstack/Elf.h
+++ b/libunwindstack/include/unwindstack/Elf.h
@@ -22,6 +22,7 @@
#include <memory>
#include <mutex>
#include <string>
+#include <unordered_map>
#include <unwindstack/ElfInterface.h>
#include <unwindstack/Memory.h>
@@ -96,6 +97,14 @@ class Elf {
static uint64_t GetLoadBias(Memory* memory);
+ static void SetCachingEnabled(bool enable);
+ static bool CachingEnabled() { return cache_enabled_; }
+
+ static void CacheLock();
+ static void CacheUnlock();
+ static void CacheAdd(MapInfo* info);
+ static bool CacheGet(const std::string& name, std::shared_ptr<Elf>* elf);
+
protected:
bool valid_ = false;
uint64_t load_bias_ = 0;
@@ -109,6 +118,10 @@ class Elf {
std::unique_ptr<Memory> gnu_debugdata_memory_;
std::unique_ptr<ElfInterface> gnu_debugdata_interface_;
+
+ static bool cache_enabled_;
+ static std::unordered_map<std::string, std::shared_ptr<Elf>>* cache_;
+ static std::mutex* cache_lock_;
};
} // namespace unwindstack
diff --git a/libunwindstack/include/unwindstack/MapInfo.h b/libunwindstack/include/unwindstack/MapInfo.h
index 22e48f7..a57fe68 100644
--- a/libunwindstack/include/unwindstack/MapInfo.h
+++ b/libunwindstack/include/unwindstack/MapInfo.h
@@ -20,6 +20,7 @@
#include <stdint.h>
#include <atomic>
+#include <memory>
#include <mutex>
#include <string>
@@ -40,14 +41,14 @@ struct MapInfo {
flags(flags),
name(name),
load_bias(static_cast<uint64_t>(-1)) {}
- ~MapInfo() { delete elf; }
+ ~MapInfo() = default;
uint64_t start = 0;
uint64_t end = 0;
uint64_t offset = 0;
uint16_t flags = 0;
std::string name;
- Elf* elf = nullptr;
+ std::shared_ptr<Elf> elf;
// This value is only non-zero if the offset is non-zero but there is
// no elf signature found at that offset. This indicates that the
// entire file is represented by the Memory object returned by CreateMemory,