1*795d594fSAndroid Build Coastguard Worker /* 2*795d594fSAndroid Build Coastguard Worker * Copyright (C) 2015 The Android Open Source Project 3*795d594fSAndroid Build Coastguard Worker * 4*795d594fSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*795d594fSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*795d594fSAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*795d594fSAndroid Build Coastguard Worker * 8*795d594fSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*795d594fSAndroid Build Coastguard Worker * 10*795d594fSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*795d594fSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*795d594fSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*795d594fSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*795d594fSAndroid Build Coastguard Worker * limitations under the License. 15*795d594fSAndroid Build Coastguard Worker */ 16*795d594fSAndroid Build Coastguard Worker 17*795d594fSAndroid Build Coastguard Worker #ifndef ART_RUNTIME_JIT_DEBUGGER_INTERFACE_H_ 18*795d594fSAndroid Build Coastguard Worker #define ART_RUNTIME_JIT_DEBUGGER_INTERFACE_H_ 19*795d594fSAndroid Build Coastguard Worker 20*795d594fSAndroid Build Coastguard Worker #include <functional> 21*795d594fSAndroid Build Coastguard Worker #include <inttypes.h> 22*795d594fSAndroid Build Coastguard Worker #include <vector> 23*795d594fSAndroid Build Coastguard Worker 24*795d594fSAndroid Build Coastguard Worker #include "arch/instruction_set_features.h" 25*795d594fSAndroid Build Coastguard Worker #include "base/array_ref.h" 26*795d594fSAndroid Build Coastguard Worker #include "base/locks.h" 27*795d594fSAndroid Build Coastguard Worker 28*795d594fSAndroid Build Coastguard Worker namespace art HIDDEN { 29*795d594fSAndroid Build Coastguard Worker 30*795d594fSAndroid Build Coastguard Worker class DexFile; 31*795d594fSAndroid Build Coastguard Worker class Mutex; 32*795d594fSAndroid Build Coastguard Worker class Thread; 33*795d594fSAndroid Build Coastguard Worker struct JITCodeEntry; 34*795d594fSAndroid Build Coastguard Worker 35*795d594fSAndroid Build Coastguard Worker // Must be called before zygote forks. 36*795d594fSAndroid Build Coastguard Worker // Used to ensure that zygote's mini-debug-info can be shared with apps. 37*795d594fSAndroid Build Coastguard Worker void NativeDebugInfoPreFork(); 38*795d594fSAndroid Build Coastguard Worker 39*795d594fSAndroid Build Coastguard Worker // Must be called after zygote forks. 40*795d594fSAndroid Build Coastguard Worker void NativeDebugInfoPostFork(); 41*795d594fSAndroid Build Coastguard Worker 42*795d594fSAndroid Build Coastguard Worker ArrayRef<const uint8_t> GetJITCodeEntrySymFile(const JITCodeEntry*); 43*795d594fSAndroid Build Coastguard Worker 44*795d594fSAndroid Build Coastguard Worker // Notify native tools (e.g. libunwind) that DEX file has been opened. 45*795d594fSAndroid Build Coastguard Worker void AddNativeDebugInfoForDex(Thread* self, const DexFile* dexfile); 46*795d594fSAndroid Build Coastguard Worker 47*795d594fSAndroid Build Coastguard Worker // Notify native tools (e.g. libunwind) that DEX file has been closed. 48*795d594fSAndroid Build Coastguard Worker void RemoveNativeDebugInfoForDex(Thread* self, const DexFile* dexfile); 49*795d594fSAndroid Build Coastguard Worker 50*795d594fSAndroid Build Coastguard Worker // Notify native tools (e.g. libunwind) that JIT has compiled a single new method. 51*795d594fSAndroid Build Coastguard Worker // The method will make copy of the passed ELF file (to shrink it to the minimum size). 52*795d594fSAndroid Build Coastguard Worker // If packing is allowed, the ELF file might be merged with others to save space 53*795d594fSAndroid Build Coastguard Worker // (however, this drops all ELF sections other than symbols names and unwinding info). 54*795d594fSAndroid Build Coastguard Worker void AddNativeDebugInfoForJit(const void* code_ptr, 55*795d594fSAndroid Build Coastguard Worker const std::vector<uint8_t>& symfile, 56*795d594fSAndroid Build Coastguard Worker bool allow_packing) 57*795d594fSAndroid Build Coastguard Worker REQUIRES_SHARED(Locks::jit_lock_); // Might need JIT code cache to allocate memory. 58*795d594fSAndroid Build Coastguard Worker 59*795d594fSAndroid Build Coastguard Worker // Notify native tools (e.g. libunwind) that JIT code has been garbage collected. 60*795d594fSAndroid Build Coastguard Worker // The actual removal might be lazy. Removal of address that was not added is no-op. 61*795d594fSAndroid Build Coastguard Worker void RemoveNativeDebugInfoForJit(const void* code_ptr); 62*795d594fSAndroid Build Coastguard Worker 63*795d594fSAndroid Build Coastguard Worker // Merge and compress entries to save space. 64*795d594fSAndroid Build Coastguard Worker void RepackNativeDebugInfoForJit() 65*795d594fSAndroid Build Coastguard Worker REQUIRES_SHARED(Locks::jit_lock_); // Might need JIT code cache to allocate memory. 66*795d594fSAndroid Build Coastguard Worker 67*795d594fSAndroid Build Coastguard Worker // Returns approximate memory used by debug info for JIT code. 68*795d594fSAndroid Build Coastguard Worker size_t GetJitMiniDebugInfoMemUsage() REQUIRES_SHARED(Locks::jit_lock_); 69*795d594fSAndroid Build Coastguard Worker 70*795d594fSAndroid Build Coastguard Worker // Get the lock which protects the native debug info. 71*795d594fSAndroid Build Coastguard Worker // Used only in tests to unwind while the JIT thread is running. 72*795d594fSAndroid Build Coastguard Worker // TODO: Unwinding should be race-free. Remove this. 73*795d594fSAndroid Build Coastguard Worker EXPORT Mutex* GetNativeDebugInfoLock(); 74*795d594fSAndroid Build Coastguard Worker 75*795d594fSAndroid Build Coastguard Worker // Call given callback for every non-zygote symbol. 76*795d594fSAndroid Build Coastguard Worker // The callback parameters are (address, size, name). 77*795d594fSAndroid Build Coastguard Worker void ForEachNativeDebugSymbol(std::function<void(const void*, size_t, const char*)> cb); 78*795d594fSAndroid Build Coastguard Worker 79*795d594fSAndroid Build Coastguard Worker } // namespace art 80*795d594fSAndroid Build Coastguard Worker 81*795d594fSAndroid Build Coastguard Worker #endif // ART_RUNTIME_JIT_DEBUGGER_INTERFACE_H_ 82