xref: /aosp_15_r20/system/unwinding/libunwindstack/JitDebug.cpp (revision eb293b8f56ee8303637c5595cfcdeef8039e85c6)
1*eb293b8fSAndroid Build Coastguard Worker /*
2*eb293b8fSAndroid Build Coastguard Worker  * Copyright (C) 2017 The Android Open Source Project
3*eb293b8fSAndroid Build Coastguard Worker  *
4*eb293b8fSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*eb293b8fSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*eb293b8fSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*eb293b8fSAndroid Build Coastguard Worker  *
8*eb293b8fSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*eb293b8fSAndroid Build Coastguard Worker  *
10*eb293b8fSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*eb293b8fSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*eb293b8fSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*eb293b8fSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*eb293b8fSAndroid Build Coastguard Worker  * limitations under the License.
15*eb293b8fSAndroid Build Coastguard Worker  */
16*eb293b8fSAndroid Build Coastguard Worker 
17*eb293b8fSAndroid Build Coastguard Worker #include <unwindstack/JitDebug.h>
18*eb293b8fSAndroid Build Coastguard Worker 
19*eb293b8fSAndroid Build Coastguard Worker #include <unwindstack/Elf.h>
20*eb293b8fSAndroid Build Coastguard Worker 
21*eb293b8fSAndroid Build Coastguard Worker #include "GlobalDebugImpl.h"
22*eb293b8fSAndroid Build Coastguard Worker #include "MemoryBuffer.h"
23*eb293b8fSAndroid Build Coastguard Worker 
24*eb293b8fSAndroid Build Coastguard Worker namespace unwindstack {
25*eb293b8fSAndroid Build Coastguard Worker 
26*eb293b8fSAndroid Build Coastguard Worker template <>
Load(Maps *,std::shared_ptr<Memory> & memory,uint64_t addr,uint64_t size,std::shared_ptr<Elf> & elf)27*eb293b8fSAndroid Build Coastguard Worker bool GlobalDebugInterface<Elf>::Load(Maps*, std::shared_ptr<Memory>& memory, uint64_t addr,
28*eb293b8fSAndroid Build Coastguard Worker                                      uint64_t size, /*out*/ std::shared_ptr<Elf>& elf) {
29*eb293b8fSAndroid Build Coastguard Worker   std::shared_ptr<Memory> copy(new MemoryBuffer(size));
30*eb293b8fSAndroid Build Coastguard Worker   uint8_t* dst_ptr = copy->GetPtr(0);
31*eb293b8fSAndroid Build Coastguard Worker   if (dst_ptr == nullptr || !memory->ReadFully(addr, dst_ptr, size)) {
32*eb293b8fSAndroid Build Coastguard Worker     return false;
33*eb293b8fSAndroid Build Coastguard Worker   }
34*eb293b8fSAndroid Build Coastguard Worker   elf.reset(new Elf(copy));
35*eb293b8fSAndroid Build Coastguard Worker   return elf->Init() && elf->valid();
36*eb293b8fSAndroid Build Coastguard Worker }
37*eb293b8fSAndroid Build Coastguard Worker 
CreateJitDebug(ArchEnum arch,std::shared_ptr<Memory> & memory,std::vector<std::string> search_libs)38*eb293b8fSAndroid Build Coastguard Worker std::unique_ptr<JitDebug> CreateJitDebug(ArchEnum arch, std::shared_ptr<Memory>& memory,
39*eb293b8fSAndroid Build Coastguard Worker                                          std::vector<std::string> search_libs) {
40*eb293b8fSAndroid Build Coastguard Worker   return CreateGlobalDebugImpl<Elf>(arch, memory, search_libs, "__jit_debug_descriptor");
41*eb293b8fSAndroid Build Coastguard Worker }
42*eb293b8fSAndroid Build Coastguard Worker 
43*eb293b8fSAndroid Build Coastguard Worker }  // namespace unwindstack
44