blob: 3c2898b8ac8e071c07e473bd431881f4726a7824 [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#include "debugger_interface.h"
18
19namespace art {
20
21// -------------------------------------------------------------------
22// Binary GDB JIT Interface as described in
23// http://sourceware.org/gdb/onlinedocs/gdb/Declarations.html
24// -------------------------------------------------------------------
25extern "C" {
26 typedef enum {
27 JIT_NOACTION = 0,
28 JIT_REGISTER_FN,
29 JIT_UNREGISTER_FN
30 } JITAction;
31
32 struct JITCodeEntry {
33 JITCodeEntry* next_;
34 JITCodeEntry* prev_;
35 const uint8_t *symfile_addr_;
36 uint64_t symfile_size_;
37 };
38
39 struct JITDescriptor {
40 uint32_t version_;
41 uint32_t action_flag_;
42 JITCodeEntry* relevant_entry_;
43 JITCodeEntry* first_entry_;
44 };
45
46 // GDB will place breakpoint into this function.
47 // To prevent GCC from inlining or removing it we place noinline attribute
48 // and inline assembler statement inside.
49 void __attribute__((noinline)) __jit_debug_register_code();
50 void __attribute__((noinline)) __jit_debug_register_code() {
51 __asm__("");
52 }
53
54 // GDB will inspect contents of this descriptor.
55 // Static initialization is necessary to prevent GDB from seeing
56 // uninitialized descriptor.
57 JITDescriptor __jit_debug_descriptor = { 1, JIT_NOACTION, nullptr, nullptr };
58}
59
60JITCodeEntry* CreateJITCodeEntry(const uint8_t *symfile_addr, uintptr_t symfile_size) {
61 JITCodeEntry* entry = new JITCodeEntry;
62 entry->symfile_addr_ = symfile_addr;
63 entry->symfile_size_ = symfile_size;
64 entry->prev_ = nullptr;
65
66 // TODO: Do we need a lock here?
67 entry->next_ = __jit_debug_descriptor.first_entry_;
68 if (entry->next_ != nullptr) {
69 entry->next_->prev_ = entry;
70 }
71 __jit_debug_descriptor.first_entry_ = entry;
72 __jit_debug_descriptor.relevant_entry_ = entry;
73
74 __jit_debug_descriptor.action_flag_ = JIT_REGISTER_FN;
75 __jit_debug_register_code();
76 return entry;
77}
78
79void DeleteJITCodeEntry(JITCodeEntry* entry) {
80 // TODO: Do we need a lock here?
81 if (entry->prev_ != nullptr) {
82 entry->prev_->next_ = entry->next_;
83 } else {
84 __jit_debug_descriptor.first_entry_ = entry->next_;
85 }
86
87 if (entry->next_ != nullptr) {
88 entry->next_->prev_ = entry->prev_;
89 }
90
91 __jit_debug_descriptor.relevant_entry_ = entry;
92 __jit_debug_descriptor.action_flag_ = JIT_UNREGISTER_FN;
93 __jit_debug_register_code();
94 delete entry;
95}
96
97} // namespace art