blob: 62288de8cf94a026ec599ab10a19a21c1aeb37cd [file] [log] [blame]
David Srbecky67feb172015-12-17 19:57:44 +00001/*
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
David Srbecky8fc2f952019-07-31 18:40:09 +010020#include <functional>
David Srbecky67feb172015-12-17 19:57:44 +000021#include <inttypes.h>
Vladimir Marko93205e32016-04-13 11:59:46 +010022#include <vector>
David Srbecky67feb172015-12-17 19:57:44 +000023
David Srbecky0b21e412018-12-05 13:24:06 +000024#include "arch/instruction_set_features.h"
David Srbecky53eb07f2019-02-12 16:34:55 +000025#include "base/array_ref.h"
Andreas Gampe7fbc4a52018-11-28 08:26:47 -080026#include "base/locks.h"
David Srbeckyc684f332018-01-19 17:38:06 +000027
David Srbecky67feb172015-12-17 19:57:44 +000028namespace art {
29
David Srbeckyafc60cd2018-12-05 11:59:31 +000030class DexFile;
David Srbecky1ed45152019-04-09 18:10:26 +010031class Mutex;
David Srbeckyafc60cd2018-12-05 11:59:31 +000032class Thread;
David Srbecky8fc2f952019-07-31 18:40:09 +010033struct JITCodeEntry;
David Srbeckyafc60cd2018-12-05 11:59:31 +000034
David Srbecky1550a662019-08-14 17:16:46 +010035// Must be called before zygote forks.
36// Used to ensure that zygote's mini-debug-info can be shared with apps.
37void NativeDebugInfoPreFork();
38
39// Must be called after zygote forks.
40void NativeDebugInfoPostFork();
41
David Srbeckye09b87e2019-08-19 21:31:31 +010042ArrayRef<const uint8_t> GetJITCodeEntrySymFile(const JITCodeEntry*);
David Srbecky0b21e412018-12-05 13:24:06 +000043
David Srbeckyfb3de3d2018-01-29 16:11:49 +000044// Notify native tools (e.g. libunwind) that DEX file has been opened.
David Srbecky0b21e412018-12-05 13:24:06 +000045void AddNativeDebugInfoForDex(Thread* self, const DexFile* dexfile);
David Srbeckyfb3de3d2018-01-29 16:11:49 +000046
47// Notify native tools (e.g. libunwind) that DEX file has been closed.
David Srbecky0b21e412018-12-05 13:24:06 +000048void RemoveNativeDebugInfoForDex(Thread* self, const DexFile* dexfile);
David Srbeckyc684f332018-01-19 17:38:06 +000049
David Srbecky8fc2f952019-07-31 18:40:09 +010050// Notify native tools (e.g. libunwind) that JIT has compiled a single new method.
David Srbecky440a9b32018-02-15 17:47:29 +000051// The method will make copy of the passed ELF file (to shrink it to the minimum size).
David Srbecky8fc2f952019-07-31 18:40:09 +010052// 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).
54void AddNativeDebugInfoForJit(const void* code_ptr,
David Srbecky0b21e412018-12-05 13:24:06 +000055 const std::vector<uint8_t>& symfile,
David Srbecky9ac8e432019-08-13 13:16:13 +010056 bool allow_packing)
57 REQUIRES_SHARED(Locks::jit_lock_); // Might need JIT code cache to allocate memory.
David Srbecky67feb172015-12-17 19:57:44 +000058
David Srbeckyafc60cd2018-12-05 11:59:31 +000059// Notify native tools (e.g. libunwind) that JIT code has been garbage collected.
David Srbecky30fd8512020-02-20 20:27:58 +000060// The actual removal might be lazy. Removal of address that was not added is no-op.
61void RemoveNativeDebugInfoForJit(const void* code_ptr);
62
63// Merge and compress entries to save space.
64void RepackNativeDebugInfoForJit()
David Srbecky9ac8e432019-08-13 13:16:13 +010065 REQUIRES_SHARED(Locks::jit_lock_); // Might need JIT code cache to allocate memory.
David Srbeckyc684f332018-01-19 17:38:06 +000066
David Srbeckyafc60cd2018-12-05 11:59:31 +000067// Returns approximate memory used by debug info for JIT code.
David Srbecky1550a662019-08-14 17:16:46 +010068size_t GetJitMiniDebugInfoMemUsage() REQUIRES_SHARED(Locks::jit_lock_);
David Srbecky5cc349f2015-12-18 15:04:48 +000069
David Srbecky1ed45152019-04-09 18:10:26 +010070// 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.
73Mutex* GetNativeDebugInfoLock();
74
David Srbecky1f947b42020-12-08 16:08:04 +000075// Call given callback for every non-zygote symbol.
76// The callback parameters are (address, size, name).
David Srbecky41617b12020-03-18 21:19:06 +000077void ForEachNativeDebugSymbol(std::function<void(const void*, size_t, const char*)> cb);
78
David Srbecky67feb172015-12-17 19:57:44 +000079} // namespace art
80
81#endif // ART_RUNTIME_JIT_DEBUGGER_INTERFACE_H_