| Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright (C) 2016 The Android Open Source Project | 
|  | 3 | * | 
|  | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 5 | * you may not use this file except in compliance with the License. | 
|  | 6 | * You may obtain a copy of the License at | 
|  | 7 | * | 
|  | 8 | *      http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 9 | * | 
|  | 10 | * Unless required by applicable law or agreed to in writing, software | 
|  | 11 | * distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 13 | * See the License for the specific language governing permissions and | 
|  | 14 | * limitations under the License. | 
|  | 15 | */ | 
|  | 16 |  | 
|  | 17 | #include <elf.h> | 
|  | 18 | #include <string.h> | 
|  | 19 |  | 
|  | 20 | #include <memory> | 
| Christopher Ferris | be788d8 | 2017-11-27 14:50:38 -0800 | [diff] [blame] | 21 | #include <mutex> | 
| Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 22 | #include <string> | 
|  | 23 |  | 
|  | 24 | #define LOG_TAG "unwind" | 
|  | 25 | #include <log/log.h> | 
|  | 26 |  | 
| Christopher Ferris | d226a51 | 2017-07-14 10:37:19 -0700 | [diff] [blame] | 27 | #include <unwindstack/Elf.h> | 
|  | 28 | #include <unwindstack/ElfInterface.h> | 
|  | 29 | #include <unwindstack/MapInfo.h> | 
|  | 30 | #include <unwindstack/Memory.h> | 
|  | 31 | #include <unwindstack/Regs.h> | 
|  | 32 |  | 
| Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 33 | #include "ElfInterfaceArm.h" | 
| Christopher Ferris | d226a51 | 2017-07-14 10:37:19 -0700 | [diff] [blame] | 34 | #include "Symbols.h" | 
|  | 35 |  | 
|  | 36 | namespace unwindstack { | 
| Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 37 |  | 
| Christopher Ferris | 0b79ae1 | 2018-01-25 12:15:56 -0800 | [diff] [blame] | 38 | bool Elf::cache_enabled_; | 
|  | 39 | std::unordered_map<std::string, std::shared_ptr<Elf>>* Elf::cache_; | 
|  | 40 | std::mutex* Elf::cache_lock_; | 
|  | 41 |  | 
| Christopher Ferris | e69f470 | 2017-10-19 16:08:58 -0700 | [diff] [blame] | 42 | bool Elf::Init(bool init_gnu_debugdata) { | 
|  | 43 | load_bias_ = 0; | 
| Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 44 | if (!memory_) { | 
|  | 45 | return false; | 
|  | 46 | } | 
|  | 47 |  | 
|  | 48 | interface_.reset(CreateInterfaceFromMemory(memory_.get())); | 
|  | 49 | if (!interface_) { | 
|  | 50 | return false; | 
|  | 51 | } | 
|  | 52 |  | 
| Christopher Ferris | e69f470 | 2017-10-19 16:08:58 -0700 | [diff] [blame] | 53 | valid_ = interface_->Init(&load_bias_); | 
| Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 54 | if (valid_) { | 
|  | 55 | interface_->InitHeaders(); | 
| Christopher Ferris | e69f470 | 2017-10-19 16:08:58 -0700 | [diff] [blame] | 56 | if (init_gnu_debugdata) { | 
|  | 57 | InitGnuDebugdata(); | 
|  | 58 | } else { | 
|  | 59 | gnu_debugdata_interface_.reset(nullptr); | 
|  | 60 | } | 
| Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 61 | } else { | 
|  | 62 | interface_.reset(nullptr); | 
|  | 63 | } | 
|  | 64 | return valid_; | 
|  | 65 | } | 
|  | 66 |  | 
| Christopher Ferris | bae69f1 | 2017-06-28 14:51:54 -0700 | [diff] [blame] | 67 | // It is expensive to initialize the .gnu_debugdata section. Provide a method | 
|  | 68 | // to initialize this data separately. | 
|  | 69 | void Elf::InitGnuDebugdata() { | 
|  | 70 | if (!valid_ || interface_->gnu_debugdata_offset() == 0) { | 
|  | 71 | return; | 
|  | 72 | } | 
|  | 73 |  | 
|  | 74 | gnu_debugdata_memory_.reset(interface_->CreateGnuDebugdataMemory()); | 
|  | 75 | gnu_debugdata_interface_.reset(CreateInterfaceFromMemory(gnu_debugdata_memory_.get())); | 
|  | 76 | ElfInterface* gnu = gnu_debugdata_interface_.get(); | 
|  | 77 | if (gnu == nullptr) { | 
|  | 78 | return; | 
|  | 79 | } | 
| Christopher Ferris | e69f470 | 2017-10-19 16:08:58 -0700 | [diff] [blame] | 80 |  | 
|  | 81 | // Ignore the load_bias from the compressed section, the correct load bias | 
|  | 82 | // is in the uncompressed data. | 
|  | 83 | uint64_t load_bias; | 
|  | 84 | if (gnu->Init(&load_bias)) { | 
| Christopher Ferris | bae69f1 | 2017-06-28 14:51:54 -0700 | [diff] [blame] | 85 | gnu->InitHeaders(); | 
| Christopher Ferris | e7b6624 | 2017-12-15 11:17:45 -0800 | [diff] [blame] | 86 | interface_->SetGnuDebugdataInterface(gnu); | 
| Christopher Ferris | bae69f1 | 2017-06-28 14:51:54 -0700 | [diff] [blame] | 87 | } else { | 
|  | 88 | // Free all of the memory associated with the gnu_debugdata section. | 
|  | 89 | gnu_debugdata_memory_.reset(nullptr); | 
|  | 90 | gnu_debugdata_interface_.reset(nullptr); | 
|  | 91 | } | 
|  | 92 | } | 
|  | 93 |  | 
| Christopher Ferris | d226a51 | 2017-07-14 10:37:19 -0700 | [diff] [blame] | 94 | bool Elf::GetSoname(std::string* name) { | 
| Christopher Ferris | be788d8 | 2017-11-27 14:50:38 -0800 | [diff] [blame] | 95 | std::lock_guard<std::mutex> guard(lock_); | 
| Christopher Ferris | d226a51 | 2017-07-14 10:37:19 -0700 | [diff] [blame] | 96 | return valid_ && interface_->GetSoname(name); | 
|  | 97 | } | 
|  | 98 |  | 
|  | 99 | uint64_t Elf::GetRelPc(uint64_t pc, const MapInfo* map_info) { | 
| Christopher Ferris | e69f470 | 2017-10-19 16:08:58 -0700 | [diff] [blame] | 100 | return pc - map_info->start + load_bias_ + map_info->elf_offset; | 
| Christopher Ferris | d226a51 | 2017-07-14 10:37:19 -0700 | [diff] [blame] | 101 | } | 
|  | 102 |  | 
|  | 103 | bool Elf::GetFunctionName(uint64_t addr, std::string* name, uint64_t* func_offset) { | 
| Christopher Ferris | be788d8 | 2017-11-27 14:50:38 -0800 | [diff] [blame] | 104 | std::lock_guard<std::mutex> guard(lock_); | 
| Christopher Ferris | e69f470 | 2017-10-19 16:08:58 -0700 | [diff] [blame] | 105 | return valid_ && (interface_->GetFunctionName(addr, load_bias_, name, func_offset) || | 
|  | 106 | (gnu_debugdata_interface_ && gnu_debugdata_interface_->GetFunctionName( | 
|  | 107 | addr, load_bias_, name, func_offset))); | 
| Christopher Ferris | d226a51 | 2017-07-14 10:37:19 -0700 | [diff] [blame] | 108 | } | 
|  | 109 |  | 
| Christopher Ferris | 150db12 | 2017-12-20 18:49:01 -0800 | [diff] [blame] | 110 | bool Elf::GetGlobalVariable(const std::string& name, uint64_t* memory_address) { | 
|  | 111 | if (!valid_) { | 
|  | 112 | return false; | 
|  | 113 | } | 
|  | 114 |  | 
|  | 115 | if (!interface_->GetGlobalVariable(name, memory_address) && | 
|  | 116 | (gnu_debugdata_interface_ == nullptr || | 
|  | 117 | !gnu_debugdata_interface_->GetGlobalVariable(name, memory_address))) { | 
|  | 118 | return false; | 
|  | 119 | } | 
|  | 120 |  | 
|  | 121 | // Adjust by the load bias. | 
|  | 122 | if (*memory_address < load_bias_) { | 
|  | 123 | return false; | 
|  | 124 | } | 
|  | 125 |  | 
|  | 126 | *memory_address -= load_bias_; | 
|  | 127 |  | 
|  | 128 | // If this winds up in the dynamic section, then we might need to adjust | 
|  | 129 | // the address. | 
|  | 130 | uint64_t dynamic_end = interface_->dynamic_vaddr() + interface_->dynamic_size(); | 
|  | 131 | if (*memory_address >= interface_->dynamic_vaddr() && *memory_address < dynamic_end) { | 
|  | 132 | if (interface_->dynamic_vaddr() > interface_->dynamic_offset()) { | 
|  | 133 | *memory_address -= interface_->dynamic_vaddr() - interface_->dynamic_offset(); | 
|  | 134 | } else { | 
|  | 135 | *memory_address += interface_->dynamic_offset() - interface_->dynamic_vaddr(); | 
|  | 136 | } | 
|  | 137 | } | 
|  | 138 | return true; | 
|  | 139 | } | 
|  | 140 |  | 
| Christopher Ferris | 2fcf4cf | 2018-01-23 17:52:23 -0800 | [diff] [blame] | 141 | void Elf::GetLastError(ErrorData* data) { | 
|  | 142 | if (valid_) { | 
|  | 143 | *data = interface_->last_error(); | 
|  | 144 | } | 
|  | 145 | } | 
|  | 146 |  | 
|  | 147 | ErrorCode Elf::GetLastErrorCode() { | 
|  | 148 | if (valid_) { | 
|  | 149 | return interface_->LastErrorCode(); | 
|  | 150 | } | 
|  | 151 | return ERROR_NONE; | 
|  | 152 | } | 
|  | 153 |  | 
|  | 154 | uint64_t Elf::GetLastErrorAddress() { | 
|  | 155 | if (valid_) { | 
|  | 156 | return interface_->LastErrorAddress(); | 
|  | 157 | } | 
|  | 158 | return 0; | 
|  | 159 | } | 
|  | 160 |  | 
| Christopher Ferris | e69f470 | 2017-10-19 16:08:58 -0700 | [diff] [blame] | 161 | // The relative pc is always relative to the start of the map from which it comes. | 
| Christopher Ferris | c3d79f7 | 2017-11-28 19:14:54 -0800 | [diff] [blame] | 162 | bool Elf::Step(uint64_t rel_pc, uint64_t adjusted_rel_pc, uint64_t elf_offset, Regs* regs, | 
|  | 163 | Memory* process_memory, bool* finished) { | 
| Christopher Ferris | b9de87f | 2017-09-20 13:37:24 -0700 | [diff] [blame] | 164 | if (!valid_) { | 
|  | 165 | return false; | 
|  | 166 | } | 
| Christopher Ferris | e69f470 | 2017-10-19 16:08:58 -0700 | [diff] [blame] | 167 |  | 
|  | 168 | // The relative pc expectd by StepIfSignalHandler is relative to the start of the elf. | 
|  | 169 | if (regs->StepIfSignalHandler(rel_pc + elf_offset, this, process_memory)) { | 
| Christopher Ferris | b9de87f | 2017-09-20 13:37:24 -0700 | [diff] [blame] | 170 | *finished = false; | 
|  | 171 | return true; | 
|  | 172 | } | 
| Christopher Ferris | e69f470 | 2017-10-19 16:08:58 -0700 | [diff] [blame] | 173 |  | 
| Christopher Ferris | be788d8 | 2017-11-27 14:50:38 -0800 | [diff] [blame] | 174 | // Lock during the step which can update information in the object. | 
|  | 175 | std::lock_guard<std::mutex> guard(lock_); | 
| Christopher Ferris | e7b6624 | 2017-12-15 11:17:45 -0800 | [diff] [blame] | 176 | return interface_->Step(adjusted_rel_pc, load_bias_, regs, process_memory, finished); | 
| Christopher Ferris | d226a51 | 2017-07-14 10:37:19 -0700 | [diff] [blame] | 177 | } | 
|  | 178 |  | 
| Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 179 | bool Elf::IsValidElf(Memory* memory) { | 
|  | 180 | if (memory == nullptr) { | 
|  | 181 | return false; | 
|  | 182 | } | 
|  | 183 |  | 
|  | 184 | // Verify that this is a valid elf file. | 
|  | 185 | uint8_t e_ident[SELFMAG + 1]; | 
| Josh Gao | ef35aa5 | 2017-10-18 11:44:51 -0700 | [diff] [blame] | 186 | if (!memory->ReadFully(0, e_ident, SELFMAG)) { | 
| Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 187 | return false; | 
|  | 188 | } | 
|  | 189 |  | 
|  | 190 | if (memcmp(e_ident, ELFMAG, SELFMAG) != 0) { | 
|  | 191 | return false; | 
|  | 192 | } | 
|  | 193 | return true; | 
|  | 194 | } | 
|  | 195 |  | 
| Christopher Ferris | 3f805ac | 2017-08-30 13:15:19 -0700 | [diff] [blame] | 196 | void Elf::GetInfo(Memory* memory, bool* valid, uint64_t* size) { | 
|  | 197 | if (!IsValidElf(memory)) { | 
|  | 198 | *valid = false; | 
|  | 199 | return; | 
|  | 200 | } | 
|  | 201 | *size = 0; | 
|  | 202 | *valid = true; | 
|  | 203 |  | 
|  | 204 | // Now read the section header information. | 
|  | 205 | uint8_t class_type; | 
| Josh Gao | ef35aa5 | 2017-10-18 11:44:51 -0700 | [diff] [blame] | 206 | if (!memory->ReadFully(EI_CLASS, &class_type, 1)) { | 
| Christopher Ferris | 3f805ac | 2017-08-30 13:15:19 -0700 | [diff] [blame] | 207 | return; | 
|  | 208 | } | 
|  | 209 | if (class_type == ELFCLASS32) { | 
|  | 210 | ElfInterface32::GetMaxSize(memory, size); | 
|  | 211 | } else if (class_type == ELFCLASS64) { | 
|  | 212 | ElfInterface64::GetMaxSize(memory, size); | 
|  | 213 | } else { | 
|  | 214 | *valid = false; | 
|  | 215 | } | 
|  | 216 | } | 
|  | 217 |  | 
| Christopher Ferris | 150db12 | 2017-12-20 18:49:01 -0800 | [diff] [blame] | 218 | bool Elf::IsValidPc(uint64_t pc) { | 
|  | 219 | if (!valid_ || pc < load_bias_) { | 
|  | 220 | return false; | 
|  | 221 | } | 
|  | 222 | pc -= load_bias_; | 
|  | 223 |  | 
|  | 224 | if (interface_->IsValidPc(pc)) { | 
|  | 225 | return true; | 
|  | 226 | } | 
|  | 227 |  | 
|  | 228 | if (gnu_debugdata_interface_ != nullptr && gnu_debugdata_interface_->IsValidPc(pc)) { | 
|  | 229 | return true; | 
|  | 230 | } | 
|  | 231 |  | 
|  | 232 | return false; | 
|  | 233 | } | 
|  | 234 |  | 
| Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 235 | ElfInterface* Elf::CreateInterfaceFromMemory(Memory* memory) { | 
|  | 236 | if (!IsValidElf(memory)) { | 
|  | 237 | return nullptr; | 
|  | 238 | } | 
|  | 239 |  | 
|  | 240 | std::unique_ptr<ElfInterface> interface; | 
| Josh Gao | ef35aa5 | 2017-10-18 11:44:51 -0700 | [diff] [blame] | 241 | if (!memory->ReadFully(EI_CLASS, &class_type_, 1)) { | 
| Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 242 | return nullptr; | 
|  | 243 | } | 
|  | 244 | if (class_type_ == ELFCLASS32) { | 
|  | 245 | Elf32_Half e_machine; | 
| Josh Gao | ef35aa5 | 2017-10-18 11:44:51 -0700 | [diff] [blame] | 246 | if (!memory->ReadFully(EI_NIDENT + sizeof(Elf32_Half), &e_machine, sizeof(e_machine))) { | 
| Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 247 | return nullptr; | 
|  | 248 | } | 
|  | 249 |  | 
| Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 250 | machine_type_ = e_machine; | 
|  | 251 | if (e_machine == EM_ARM) { | 
| Christopher Ferris | d06001d | 2017-11-30 18:56:01 -0800 | [diff] [blame] | 252 | arch_ = ARCH_ARM; | 
| Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 253 | interface.reset(new ElfInterfaceArm(memory)); | 
| Christopher Ferris | a019665 | 2017-07-18 16:09:20 -0700 | [diff] [blame] | 254 | } else if (e_machine == EM_386) { | 
| Christopher Ferris | d06001d | 2017-11-30 18:56:01 -0800 | [diff] [blame] | 255 | arch_ = ARCH_X86; | 
| Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 256 | interface.reset(new ElfInterface32(memory)); | 
| Douglas Leung | 61b1a1a | 2017-11-08 10:53:53 +0100 | [diff] [blame] | 257 | } else if (e_machine == EM_MIPS) { | 
|  | 258 | arch_ = ARCH_MIPS; | 
|  | 259 | interface.reset(new ElfInterface32(memory)); | 
| Christopher Ferris | a019665 | 2017-07-18 16:09:20 -0700 | [diff] [blame] | 260 | } else { | 
| Christopher Ferris | d06001d | 2017-11-30 18:56:01 -0800 | [diff] [blame] | 261 | // Unsupported. | 
| Douglas Leung | 61b1a1a | 2017-11-08 10:53:53 +0100 | [diff] [blame] | 262 | ALOGI("32 bit elf that is neither arm nor x86 nor mips: e_machine = %d\n", e_machine); | 
| Christopher Ferris | a019665 | 2017-07-18 16:09:20 -0700 | [diff] [blame] | 263 | return nullptr; | 
| Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 264 | } | 
|  | 265 | } else if (class_type_ == ELFCLASS64) { | 
|  | 266 | Elf64_Half e_machine; | 
| Josh Gao | ef35aa5 | 2017-10-18 11:44:51 -0700 | [diff] [blame] | 267 | if (!memory->ReadFully(EI_NIDENT + sizeof(Elf64_Half), &e_machine, sizeof(e_machine))) { | 
| Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 268 | return nullptr; | 
|  | 269 | } | 
| Christopher Ferris | d06001d | 2017-11-30 18:56:01 -0800 | [diff] [blame] | 270 |  | 
|  | 271 | machine_type_ = e_machine; | 
|  | 272 | if (e_machine == EM_AARCH64) { | 
|  | 273 | arch_ = ARCH_ARM64; | 
|  | 274 | } else if (e_machine == EM_X86_64) { | 
|  | 275 | arch_ = ARCH_X86_64; | 
| Douglas Leung | 61b1a1a | 2017-11-08 10:53:53 +0100 | [diff] [blame] | 276 | } else if (e_machine == EM_MIPS) { | 
|  | 277 | arch_ = ARCH_MIPS64; | 
| Christopher Ferris | d06001d | 2017-11-30 18:56:01 -0800 | [diff] [blame] | 278 | } else { | 
| Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 279 | // Unsupported. | 
| Douglas Leung | 61b1a1a | 2017-11-08 10:53:53 +0100 | [diff] [blame] | 280 | ALOGI("64 bit elf that is neither aarch64 nor x86_64 nor mips64: e_machine = %d\n", | 
|  | 281 | e_machine); | 
| Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 282 | return nullptr; | 
|  | 283 | } | 
| Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 284 | interface.reset(new ElfInterface64(memory)); | 
|  | 285 | } | 
|  | 286 |  | 
|  | 287 | return interface.release(); | 
|  | 288 | } | 
| Christopher Ferris | d226a51 | 2017-07-14 10:37:19 -0700 | [diff] [blame] | 289 |  | 
| Christopher Ferris | b7de5f5 | 2017-12-01 21:37:37 -0800 | [diff] [blame] | 290 | uint64_t Elf::GetLoadBias(Memory* memory) { | 
|  | 291 | if (!IsValidElf(memory)) { | 
|  | 292 | return 0; | 
|  | 293 | } | 
|  | 294 |  | 
|  | 295 | uint8_t class_type; | 
|  | 296 | if (!memory->Read(EI_CLASS, &class_type, 1)) { | 
|  | 297 | return 0; | 
|  | 298 | } | 
|  | 299 |  | 
|  | 300 | if (class_type == ELFCLASS32) { | 
|  | 301 | return ElfInterface::GetLoadBias<Elf32_Ehdr, Elf32_Phdr>(memory); | 
|  | 302 | } else if (class_type == ELFCLASS64) { | 
|  | 303 | return ElfInterface::GetLoadBias<Elf64_Ehdr, Elf64_Phdr>(memory); | 
|  | 304 | } | 
|  | 305 | return 0; | 
|  | 306 | } | 
|  | 307 |  | 
| Christopher Ferris | 0b79ae1 | 2018-01-25 12:15:56 -0800 | [diff] [blame] | 308 | void Elf::SetCachingEnabled(bool enable) { | 
|  | 309 | if (!cache_enabled_ && enable) { | 
|  | 310 | cache_enabled_ = true; | 
|  | 311 | cache_ = new std::unordered_map<std::string, std::shared_ptr<Elf>>; | 
|  | 312 | cache_lock_ = new std::mutex; | 
|  | 313 | } else if (cache_enabled_ && !enable) { | 
|  | 314 | cache_enabled_ = false; | 
|  | 315 | delete cache_; | 
|  | 316 | delete cache_lock_; | 
|  | 317 | } | 
|  | 318 | } | 
|  | 319 |  | 
|  | 320 | void Elf::CacheLock() { | 
|  | 321 | cache_lock_->lock(); | 
|  | 322 | } | 
|  | 323 |  | 
|  | 324 | void Elf::CacheUnlock() { | 
|  | 325 | cache_lock_->unlock(); | 
|  | 326 | } | 
|  | 327 |  | 
|  | 328 | void Elf::CacheAdd(MapInfo* info) { | 
|  | 329 | if (info->offset == 0) { | 
|  | 330 | (*cache_)[info->name] = info->elf; | 
|  | 331 | } else { | 
|  | 332 | std::string name(info->name + ':' + std::to_string(info->offset)); | 
|  | 333 | (*cache_)[name] = info->elf; | 
|  | 334 | } | 
|  | 335 | } | 
|  | 336 |  | 
|  | 337 | bool Elf::CacheGet(const std::string& name, std::shared_ptr<Elf>* elf) { | 
|  | 338 | auto entry = cache_->find(name); | 
|  | 339 | if (entry != cache_->end()) { | 
|  | 340 | *elf = entry->second; | 
|  | 341 | return true; | 
|  | 342 | } | 
|  | 343 | return false; | 
|  | 344 | } | 
|  | 345 |  | 
| Christopher Ferris | d226a51 | 2017-07-14 10:37:19 -0700 | [diff] [blame] | 346 | }  // namespace unwindstack |