1 /* 2 * Copyright (C) 2015 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 #ifndef ART_RUNTIME_JIT_DEBUGGER_INTERFACE_H_ 18 #define ART_RUNTIME_JIT_DEBUGGER_INTERFACE_H_ 19 20 #include <functional> 21 #include <inttypes.h> 22 #include <vector> 23 24 #include "arch/instruction_set_features.h" 25 #include "base/array_ref.h" 26 #include "base/locks.h" 27 28 namespace art { 29 30 class DexFile; 31 class Mutex; 32 class Thread; 33 struct JITCodeEntry; 34 35 // Must be called before zygote forks. 36 // Used to ensure that zygote's mini-debug-info can be shared with apps. 37 void NativeDebugInfoPreFork(); 38 39 // Must be called after zygote forks. 40 void NativeDebugInfoPostFork(); 41 42 ArrayRef<const uint8_t> GetJITCodeEntrySymFile(const JITCodeEntry*); 43 44 // Notify native tools (e.g. libunwind) that DEX file has been opened. 45 void AddNativeDebugInfoForDex(Thread* self, const DexFile* dexfile); 46 47 // Notify native tools (e.g. libunwind) that DEX file has been closed. 48 void RemoveNativeDebugInfoForDex(Thread* self, const DexFile* dexfile); 49 50 // Notify native tools (e.g. libunwind) that JIT has compiled a single new method. 51 // The method will make copy of the passed ELF file (to shrink it to the minimum size). 52 // If packing is allowed, the ELF file might be merged with others to save space 53 // (however, this drops all ELF sections other than symbols names and unwinding info). 54 void AddNativeDebugInfoForJit(const void* code_ptr, 55 const std::vector<uint8_t>& symfile, 56 bool allow_packing) 57 REQUIRES_SHARED(Locks::jit_lock_); // Might need JIT code cache to allocate memory. 58 59 // Notify native tools (e.g. libunwind) that JIT code has been garbage collected. 60 // The actual removal might be lazy. Removal of address that was not added is no-op. 61 void RemoveNativeDebugInfoForJit(const void* code_ptr); 62 63 // Merge and compress entries to save space. 64 void RepackNativeDebugInfoForJit() 65 REQUIRES_SHARED(Locks::jit_lock_); // Might need JIT code cache to allocate memory. 66 67 // Returns approximate memory used by debug info for JIT code. 68 size_t GetJitMiniDebugInfoMemUsage() REQUIRES_SHARED(Locks::jit_lock_); 69 70 // Get the lock which protects the native debug info. 71 // Used only in tests to unwind while the JIT thread is running. 72 // TODO: Unwinding should be race-free. Remove this. 73 Mutex* GetNativeDebugInfoLock(); 74 75 // Call given callback for every non-zygote symbol. 76 // The callback parameters are (address, size, name). 77 void ForEachNativeDebugSymbol(std::function<void(const void*, size_t, const char*)> cb); 78 79 } // namespace art 80 81 #endif // ART_RUNTIME_JIT_DEBUGGER_INTERFACE_H_ 82