Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 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 | /* |
| 18 | * Dalvik-specific side of debugger support. (The JDWP code is intended to |
| 19 | * be relatively generic.) |
| 20 | */ |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 21 | #ifndef ART_RUNTIME_DEBUGGER_H_ |
| 22 | #define ART_RUNTIME_DEBUGGER_H_ |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 23 | |
| 24 | #include <pthread.h> |
| 25 | |
Sebastien Hertz | 61b7f1b | 2013-11-15 15:59:30 +0100 | [diff] [blame] | 26 | #include <set> |
Elliott Hughes | 3bb8156 | 2011-10-21 18:52:59 -0700 | [diff] [blame] | 27 | #include <string> |
| 28 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 29 | #include "jdwp/jdwp.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 30 | #include "jni.h" |
| 31 | #include "jvalue.h" |
Mathieu Chartier | 83c8ee0 | 2014-01-28 14:50:23 -0800 | [diff] [blame] | 32 | #include "object_callbacks.h" |
Jeff Hao | 920af3e | 2013-08-28 15:46:38 -0700 | [diff] [blame] | 33 | #include "thread_state.h" |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 34 | |
| 35 | namespace art { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 36 | namespace mirror { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 37 | class ArtMethod; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 38 | class Class; |
| 39 | class Object; |
| 40 | class Throwable; |
| 41 | } // namespace mirror |
Elliott Hughes | 545a064 | 2011-11-08 19:10:03 -0800 | [diff] [blame] | 42 | struct AllocRecord; |
Ian Rogers | 1b09b09 | 2012-08-20 15:35:52 -0700 | [diff] [blame] | 43 | class Thread; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 44 | class ThrowLocation; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 45 | |
| 46 | /* |
| 47 | * Invoke-during-breakpoint support. |
| 48 | */ |
| 49 | struct DebugInvokeReq { |
Elliott Hughes | 7b3cdfc | 2011-12-08 21:28:17 -0800 | [diff] [blame] | 50 | DebugInvokeReq() |
Sebastien Hertz | d38667a | 2013-11-25 15:43:54 +0100 | [diff] [blame] | 51 | : ready(false), invoke_needed(false), |
| 52 | receiver(NULL), thread(NULL), klass(NULL), method(NULL), |
| 53 | arg_count(0), arg_values(NULL), options(0), error(JDWP::ERR_NONE), |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 54 | result_tag(JDWP::JT_VOID), exception(0), |
Sebastien Hertz | d38667a | 2013-11-25 15:43:54 +0100 | [diff] [blame] | 55 | lock("a DebugInvokeReq lock", kBreakpointInvokeLock), |
| 56 | cond("a DebugInvokeReq condition variable", lock) { |
Elliott Hughes | 475fc23 | 2011-10-25 15:00:35 -0700 | [diff] [blame] | 57 | } |
| 58 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 59 | /* boolean; only set when we're in the tail end of an event handler */ |
| 60 | bool ready; |
| 61 | |
| 62 | /* boolean; set if the JDWP thread wants this thread to do work */ |
Sebastien Hertz | d38667a | 2013-11-25 15:43:54 +0100 | [diff] [blame] | 63 | bool invoke_needed; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 64 | |
| 65 | /* request */ |
Sebastien Hertz | d38667a | 2013-11-25 15:43:54 +0100 | [diff] [blame] | 66 | mirror::Object* receiver; /* not used for ClassType.InvokeMethod */ |
| 67 | mirror::Object* thread; |
| 68 | mirror::Class* klass; |
| 69 | mirror::ArtMethod* method; |
| 70 | uint32_t arg_count; |
| 71 | uint64_t* arg_values; /* will be NULL if arg_count_ == 0 */ |
| 72 | uint32_t options; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 73 | |
| 74 | /* result */ |
Elliott Hughes | 475fc23 | 2011-10-25 15:00:35 -0700 | [diff] [blame] | 75 | JDWP::JdwpError error; |
Elliott Hughes | d07986f | 2011-12-06 18:27:45 -0800 | [diff] [blame] | 76 | JDWP::JdwpTag result_tag; |
Elliott Hughes | 475fc23 | 2011-10-25 15:00:35 -0700 | [diff] [blame] | 77 | JValue result_value; |
| 78 | JDWP::ObjectId exception; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 79 | |
| 80 | /* condition variable to wait on while the method executes */ |
Sebastien Hertz | d38667a | 2013-11-25 15:43:54 +0100 | [diff] [blame] | 81 | Mutex lock DEFAULT_MUTEX_ACQUIRED_AFTER; |
| 82 | ConditionVariable cond GUARDED_BY(lock); |
Sebastien Hertz | 61b7f1b | 2013-11-15 15:59:30 +0100 | [diff] [blame] | 83 | |
Mathieu Chartier | 3b05e9b | 2014-03-25 09:29:43 -0700 | [diff] [blame] | 84 | void VisitRoots(RootCallback* callback, void* arg, uint32_t tid, RootType root_type) |
| 85 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 86 | |
Sebastien Hertz | 61b7f1b | 2013-11-15 15:59:30 +0100 | [diff] [blame] | 87 | private: |
| 88 | DISALLOW_COPY_AND_ASSIGN(DebugInvokeReq); |
| 89 | }; |
| 90 | |
| 91 | // Thread local data-structure that holds fields for controlling single-stepping. |
| 92 | struct SingleStepControl { |
| 93 | SingleStepControl() |
| 94 | : is_active(false), step_size(JDWP::SS_MIN), step_depth(JDWP::SD_INTO), |
| 95 | method(nullptr), stack_depth(0) { |
| 96 | } |
| 97 | |
| 98 | // Are we single-stepping right now? |
| 99 | bool is_active; |
| 100 | |
| 101 | // See JdwpStepSize and JdwpStepDepth for details. |
| 102 | JDWP::JdwpStepSize step_size; |
| 103 | JDWP::JdwpStepDepth step_depth; |
| 104 | |
| 105 | // The location this single-step was initiated from. |
| 106 | // A single-step is initiated in a suspended thread. We save here the current method and the |
| 107 | // set of DEX pcs associated to the source line number where the suspension occurred. |
| 108 | // This is used to support SD_INTO and SD_OVER single-step depths so we detect when a single-step |
| 109 | // causes the execution of an instruction in a different method or at a different line number. |
| 110 | mirror::ArtMethod* method; |
| 111 | std::set<uint32_t> dex_pcs; |
| 112 | |
| 113 | // The stack depth when this single-step was initiated. This is used to support SD_OVER and SD_OUT |
| 114 | // single-step depth. |
| 115 | int stack_depth; |
| 116 | |
Mathieu Chartier | 3b05e9b | 2014-03-25 09:29:43 -0700 | [diff] [blame] | 117 | void VisitRoots(RootCallback* callback, void* arg, uint32_t tid, RootType root_type) |
| 118 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 119 | |
Sebastien Hertz | 61b7f1b | 2013-11-15 15:59:30 +0100 | [diff] [blame] | 120 | private: |
| 121 | DISALLOW_COPY_AND_ASSIGN(SingleStepControl); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 122 | }; |
| 123 | |
| 124 | class Dbg { |
Elliott Hughes | ff17f1f | 2012-01-24 18:12:29 -0800 | [diff] [blame] | 125 | public: |
Elliott Hughes | 3bb8156 | 2011-10-21 18:52:59 -0700 | [diff] [blame] | 126 | static bool ParseJdwpOptions(const std::string& options); |
Elliott Hughes | 4ffd313 | 2011-10-24 12:06:42 -0700 | [diff] [blame] | 127 | static void SetJdwpAllowed(bool allowed); |
| 128 | |
Elliott Hughes | d1cc836 | 2011-10-24 16:58:50 -0700 | [diff] [blame] | 129 | static void StartJdwp(); |
| 130 | static void StopJdwp(); |
| 131 | |
Elliott Hughes | 767a147 | 2011-10-26 18:49:02 -0700 | [diff] [blame] | 132 | // Invoked by the GC in case we need to keep DDMS informed. |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 133 | static void GcDidFinish() LOCKS_EXCLUDED(Locks::mutator_lock_); |
Elliott Hughes | 767a147 | 2011-10-26 18:49:02 -0700 | [diff] [blame] | 134 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 135 | // Return the DebugInvokeReq for the current thread. |
| 136 | static DebugInvokeReq* GetInvokeReq(); |
| 137 | |
Elliott Hughes | 475fc23 | 2011-10-25 15:00:35 -0700 | [diff] [blame] | 138 | static Thread* GetDebugThread(); |
| 139 | static void ClearWaitForEventThread(); |
| 140 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 141 | /* |
| 142 | * Enable/disable breakpoints and step modes. Used to provide a heads-up |
| 143 | * when the debugger attaches. |
| 144 | */ |
| 145 | static void Connected(); |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 146 | static void GoActive() |
| 147 | LOCKS_EXCLUDED(Locks::breakpoint_lock_, Locks::deoptimization_lock_, Locks::mutator_lock_); |
| 148 | static void Disconnected() LOCKS_EXCLUDED(Locks::deoptimization_lock_, Locks::mutator_lock_); |
Elliott Hughes | 8696433 | 2012-02-15 19:37:42 -0800 | [diff] [blame] | 149 | static void Disposed(); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 150 | |
Elliott Hughes | c0f0933 | 2012-03-26 13:27:06 -0700 | [diff] [blame] | 151 | // Returns true if we're actually debugging with a real debugger, false if it's |
| 152 | // just DDMS (or nothing at all). |
| 153 | static bool IsDebuggerActive(); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 154 | |
Elliott Hughes | c0f0933 | 2012-03-26 13:27:06 -0700 | [diff] [blame] | 155 | // Returns true if we had -Xrunjdwp or -agentlib:jdwp= on the command line. |
| 156 | static bool IsJdwpConfigured(); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 157 | |
Elliott Hughes | 8696433 | 2012-02-15 19:37:42 -0800 | [diff] [blame] | 158 | static bool IsDisposed(); |
| 159 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 160 | /* |
| 161 | * Time, in milliseconds, since the last debugger activity. Does not |
| 162 | * include DDMS activity. Returns -1 if there has been no activity. |
| 163 | * Returns 0 if we're in the middle of handling a debugger request. |
| 164 | */ |
| 165 | static int64_t LastDebuggerActivity(); |
| 166 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 167 | static void UndoDebuggerSuspensions(); |
| 168 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 169 | /* |
| 170 | * Class, Object, Array |
| 171 | */ |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 172 | static std::string GetClassName(JDWP::RefTypeId id) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 173 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 88d6309 | 2013-01-09 09:55:54 -0800 | [diff] [blame] | 174 | static JDWP::JdwpError GetClassObject(JDWP::RefTypeId id, JDWP::ObjectId& class_object_id) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 175 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 88d6309 | 2013-01-09 09:55:54 -0800 | [diff] [blame] | 176 | static JDWP::JdwpError GetSuperclass(JDWP::RefTypeId id, JDWP::RefTypeId& superclass_id) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 177 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 178 | static JDWP::JdwpError GetClassLoader(JDWP::RefTypeId id, JDWP::ExpandBuf* pReply) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 179 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 180 | static JDWP::JdwpError GetModifiers(JDWP::RefTypeId id, JDWP::ExpandBuf* pReply) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 181 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 88d6309 | 2013-01-09 09:55:54 -0800 | [diff] [blame] | 182 | static JDWP::JdwpError GetReflectedType(JDWP::RefTypeId class_id, JDWP::ExpandBuf* pReply) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 183 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 184 | static void GetClassList(std::vector<JDWP::RefTypeId>& classes) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 185 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 88d6309 | 2013-01-09 09:55:54 -0800 | [diff] [blame] | 186 | static JDWP::JdwpError GetClassInfo(JDWP::RefTypeId class_id, JDWP::JdwpTypeTag* pTypeTag, |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 187 | uint32_t* pStatus, std::string* pDescriptor) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 188 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 189 | static void FindLoadedClassBySignature(const char* descriptor, std::vector<JDWP::RefTypeId>& ids) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 190 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 64f574f | 2013-02-20 14:57:12 -0800 | [diff] [blame] | 191 | static JDWP::JdwpError GetReferenceType(JDWP::ObjectId object_id, JDWP::ExpandBuf* pReply) |
| 192 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | fc0e94b | 2013-09-23 23:51:32 -0700 | [diff] [blame] | 193 | static JDWP::JdwpError GetSignature(JDWP::RefTypeId ref_type_id, std::string* signature) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 194 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 88d6309 | 2013-01-09 09:55:54 -0800 | [diff] [blame] | 195 | static JDWP::JdwpError GetSourceFile(JDWP::RefTypeId ref_type_id, std::string& source_file) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 196 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 88d6309 | 2013-01-09 09:55:54 -0800 | [diff] [blame] | 197 | static JDWP::JdwpError GetObjectTag(JDWP::ObjectId object_id, uint8_t& tag) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 198 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | aed4be9 | 2011-12-02 16:16:23 -0800 | [diff] [blame] | 199 | static size_t GetTagWidth(JDWP::JdwpTag tag); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 200 | |
Elliott Hughes | 88d6309 | 2013-01-09 09:55:54 -0800 | [diff] [blame] | 201 | static JDWP::JdwpError GetArrayLength(JDWP::ObjectId array_id, int& length) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 202 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 88d6309 | 2013-01-09 09:55:54 -0800 | [diff] [blame] | 203 | static JDWP::JdwpError OutputArray(JDWP::ObjectId array_id, int offset, int count, |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 204 | JDWP::ExpandBuf* pReply) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 205 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 88d6309 | 2013-01-09 09:55:54 -0800 | [diff] [blame] | 206 | static JDWP::JdwpError SetArrayElements(JDWP::ObjectId array_id, int offset, int count, |
Elliott Hughes | 4b9702c | 2013-02-20 18:13:24 -0800 | [diff] [blame] | 207 | JDWP::Request& request) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 208 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 209 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 210 | static JDWP::ObjectId CreateString(const std::string& str) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 211 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 88d6309 | 2013-01-09 09:55:54 -0800 | [diff] [blame] | 212 | static JDWP::JdwpError CreateObject(JDWP::RefTypeId class_id, JDWP::ObjectId& new_object) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 213 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 88d6309 | 2013-01-09 09:55:54 -0800 | [diff] [blame] | 214 | static JDWP::JdwpError CreateArrayObject(JDWP::RefTypeId array_class_id, uint32_t length, |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 215 | JDWP::ObjectId& new_array) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 216 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 217 | |
Elliott Hughes | 88d6309 | 2013-01-09 09:55:54 -0800 | [diff] [blame] | 218 | static bool MatchType(JDWP::RefTypeId instance_class_id, JDWP::RefTypeId class_id) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 219 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 220 | |
Elliott Hughes | ec0f83d | 2013-01-15 16:54:08 -0800 | [diff] [blame] | 221 | // |
| 222 | // Monitors. |
| 223 | // |
| 224 | static JDWP::JdwpError GetMonitorInfo(JDWP::ObjectId object_id, JDWP::ExpandBuf* reply) |
| 225 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 226 | static JDWP::JdwpError GetOwnedMonitors(JDWP::ObjectId thread_id, |
| 227 | std::vector<JDWP::ObjectId>& monitors, |
| 228 | std::vector<uint32_t>& stack_depths) |
Sebastien Hertz | 52d131d | 2014-03-13 16:17:40 +0100 | [diff] [blame] | 229 | LOCKS_EXCLUDED(Locks::thread_list_lock_) |
Elliott Hughes | ec0f83d | 2013-01-15 16:54:08 -0800 | [diff] [blame] | 230 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Sebastien Hertz | 52d131d | 2014-03-13 16:17:40 +0100 | [diff] [blame] | 231 | static JDWP::JdwpError GetContendedMonitor(JDWP::ObjectId thread_id, |
| 232 | JDWP::ObjectId& contended_monitor) |
| 233 | LOCKS_EXCLUDED(Locks::thread_list_lock_) |
Elliott Hughes | ec0f83d | 2013-01-15 16:54:08 -0800 | [diff] [blame] | 234 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 235 | |
| 236 | // |
| 237 | // Heap. |
| 238 | // |
| 239 | static JDWP::JdwpError GetInstanceCounts(const std::vector<JDWP::RefTypeId>& class_ids, |
| 240 | std::vector<uint64_t>& counts) |
| 241 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 3b78c94 | 2013-01-15 17:35:41 -0800 | [diff] [blame] | 242 | static JDWP::JdwpError GetInstances(JDWP::RefTypeId class_id, int32_t max_count, |
| 243 | std::vector<JDWP::ObjectId>& instances) |
| 244 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 0cbaff5 | 2013-01-16 15:28:01 -0800 | [diff] [blame] | 245 | static JDWP::JdwpError GetReferringObjects(JDWP::ObjectId object_id, int32_t max_count, |
| 246 | std::vector<JDWP::ObjectId>& referring_objects) |
| 247 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 64f574f | 2013-02-20 14:57:12 -0800 | [diff] [blame] | 248 | static JDWP::JdwpError DisableCollection(JDWP::ObjectId object_id) |
| 249 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 250 | static JDWP::JdwpError EnableCollection(JDWP::ObjectId object_id) |
| 251 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 252 | static JDWP::JdwpError IsCollected(JDWP::ObjectId object_id, bool& is_collected) |
| 253 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 254 | static void DisposeObject(JDWP::ObjectId object_id, uint32_t reference_count) |
| 255 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | ec0f83d | 2013-01-15 16:54:08 -0800 | [diff] [blame] | 256 | |
Elliott Hughes | 9777ba2 | 2013-01-17 09:04:19 -0800 | [diff] [blame] | 257 | // |
| 258 | // Methods and fields. |
| 259 | // |
Elliott Hughes | a96836a | 2013-01-17 12:27:49 -0800 | [diff] [blame] | 260 | static std::string GetMethodName(JDWP::MethodId method_id) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 261 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 88d6309 | 2013-01-09 09:55:54 -0800 | [diff] [blame] | 262 | static JDWP::JdwpError OutputDeclaredFields(JDWP::RefTypeId ref_type_id, bool with_generic, |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 263 | JDWP::ExpandBuf* pReply) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 264 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 88d6309 | 2013-01-09 09:55:54 -0800 | [diff] [blame] | 265 | static JDWP::JdwpError OutputDeclaredMethods(JDWP::RefTypeId ref_type_id, bool with_generic, |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 266 | JDWP::ExpandBuf* pReply) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 267 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 88d6309 | 2013-01-09 09:55:54 -0800 | [diff] [blame] | 268 | static JDWP::JdwpError OutputDeclaredInterfaces(JDWP::RefTypeId ref_type_id, |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 269 | JDWP::ExpandBuf* pReply) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 270 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 88d6309 | 2013-01-09 09:55:54 -0800 | [diff] [blame] | 271 | static void OutputLineTable(JDWP::RefTypeId ref_type_id, JDWP::MethodId method_id, |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 272 | JDWP::ExpandBuf* pReply) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 273 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 88d6309 | 2013-01-09 09:55:54 -0800 | [diff] [blame] | 274 | static void OutputVariableTable(JDWP::RefTypeId ref_type_id, JDWP::MethodId id, bool with_generic, |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 275 | JDWP::ExpandBuf* pReply) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 276 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Jeff Hao | 579b024 | 2013-11-18 13:16:49 -0800 | [diff] [blame] | 277 | static void OutputMethodReturnValue(JDWP::MethodId method_id, const JValue* return_value, |
| 278 | JDWP::ExpandBuf* pReply) |
| 279 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 9777ba2 | 2013-01-17 09:04:19 -0800 | [diff] [blame] | 280 | static JDWP::JdwpError GetBytecodes(JDWP::RefTypeId class_id, JDWP::MethodId method_id, |
| 281 | std::vector<uint8_t>& bytecodes) |
| 282 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 283 | |
Elliott Hughes | a96836a | 2013-01-17 12:27:49 -0800 | [diff] [blame] | 284 | static std::string GetFieldName(JDWP::FieldId field_id) |
| 285 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 88d6309 | 2013-01-09 09:55:54 -0800 | [diff] [blame] | 286 | static JDWP::JdwpTag GetFieldBasicTag(JDWP::FieldId field_id) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 287 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 88d6309 | 2013-01-09 09:55:54 -0800 | [diff] [blame] | 288 | static JDWP::JdwpTag GetStaticFieldBasicTag(JDWP::FieldId field_id) |
Brian Carlstrom | f69863b | 2013-07-17 21:53:13 -0700 | [diff] [blame] | 289 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 88d6309 | 2013-01-09 09:55:54 -0800 | [diff] [blame] | 290 | static JDWP::JdwpError GetFieldValue(JDWP::ObjectId object_id, JDWP::FieldId field_id, |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 291 | JDWP::ExpandBuf* pReply) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 292 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 88d6309 | 2013-01-09 09:55:54 -0800 | [diff] [blame] | 293 | static JDWP::JdwpError SetFieldValue(JDWP::ObjectId object_id, JDWP::FieldId field_id, |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 294 | uint64_t value, int width) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 295 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 88d6309 | 2013-01-09 09:55:54 -0800 | [diff] [blame] | 296 | static JDWP::JdwpError GetStaticFieldValue(JDWP::RefTypeId ref_type_id, JDWP::FieldId field_id, |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 297 | JDWP::ExpandBuf* pReply) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 298 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 88d6309 | 2013-01-09 09:55:54 -0800 | [diff] [blame] | 299 | static JDWP::JdwpError SetStaticFieldValue(JDWP::FieldId field_id, uint64_t value, int width) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 300 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 301 | |
Elliott Hughes | 88d6309 | 2013-01-09 09:55:54 -0800 | [diff] [blame] | 302 | static std::string StringToUtf8(JDWP::ObjectId string_id) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 303 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Jeff Hao | 579b024 | 2013-11-18 13:16:49 -0800 | [diff] [blame] | 304 | static void OutputJValue(JDWP::JdwpTag tag, const JValue* return_value, JDWP::ExpandBuf* pReply) |
| 305 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 306 | |
| 307 | /* |
| 308 | * Thread, ThreadGroup, Frame |
| 309 | */ |
Elliott Hughes | 88d6309 | 2013-01-09 09:55:54 -0800 | [diff] [blame] | 310 | static JDWP::JdwpError GetThreadName(JDWP::ObjectId thread_id, std::string& name) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 311 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) |
| 312 | LOCKS_EXCLUDED(Locks::thread_list_lock_); |
Sebastien Hertz | 52d131d | 2014-03-13 16:17:40 +0100 | [diff] [blame] | 313 | static JDWP::JdwpError GetThreadGroup(JDWP::ObjectId thread_id, JDWP::ExpandBuf* pReply) |
| 314 | LOCKS_EXCLUDED(Locks::thread_list_lock_); |
Elliott Hughes | 88d6309 | 2013-01-09 09:55:54 -0800 | [diff] [blame] | 315 | static std::string GetThreadGroupName(JDWP::ObjectId thread_group_id); |
| 316 | static JDWP::ObjectId GetThreadGroupParent(JDWP::ObjectId thread_group_id) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 317 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 318 | static JDWP::ObjectId GetSystemThreadGroupId() |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 319 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 320 | static JDWP::ObjectId GetMainThreadGroupId(); |
| 321 | |
Jeff Hao | 920af3e | 2013-08-28 15:46:38 -0700 | [diff] [blame] | 322 | static JDWP::JdwpThreadStatus ToJdwpThreadStatus(ThreadState state); |
Sebastien Hertz | 52d131d | 2014-03-13 16:17:40 +0100 | [diff] [blame] | 323 | static JDWP::JdwpError GetThreadStatus(JDWP::ObjectId thread_id, |
| 324 | JDWP::JdwpThreadStatus* pThreadStatus, |
| 325 | JDWP::JdwpSuspendStatus* pSuspendStatus) |
| 326 | LOCKS_EXCLUDED(Locks::thread_list_lock_); |
| 327 | static JDWP::JdwpError GetThreadDebugSuspendCount(JDWP::ObjectId thread_id, |
| 328 | JDWP::ExpandBuf* pReply) |
| 329 | LOCKS_EXCLUDED(Locks::thread_list_lock_, |
| 330 | Locks::thread_suspend_count_lock_); |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 331 | // static void WaitForSuspend(JDWP::ObjectId thread_id); |
Elliott Hughes | caf7654 | 2012-06-28 16:08:22 -0700 | [diff] [blame] | 332 | |
Elliott Hughes | 026b146 | 2012-06-28 20:43:49 -0700 | [diff] [blame] | 333 | // Fills 'thread_ids' with the threads in the given thread group. If thread_group_id == 0, |
Elliott Hughes | caf7654 | 2012-06-28 16:08:22 -0700 | [diff] [blame] | 334 | // returns all threads. |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 335 | static void GetThreads(JDWP::ObjectId thread_group_id, std::vector<JDWP::ObjectId>& thread_ids) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 336 | LOCKS_EXCLUDED(Locks::thread_list_lock_) |
| 337 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | caf7654 | 2012-06-28 16:08:22 -0700 | [diff] [blame] | 338 | static void GetChildThreadGroups(JDWP::ObjectId thread_group_id, std::vector<JDWP::ObjectId>& child_thread_group_ids); |
| 339 | |
Sebastien Hertz | 52d131d | 2014-03-13 16:17:40 +0100 | [diff] [blame] | 340 | static JDWP::JdwpError GetThreadFrameCount(JDWP::ObjectId thread_id, size_t& result) |
| 341 | LOCKS_EXCLUDED(Locks::thread_list_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 342 | static JDWP::JdwpError GetThreadFrames(JDWP::ObjectId thread_id, size_t start_frame, |
| 343 | size_t frame_count, JDWP::ExpandBuf* buf) |
Sebastien Hertz | 52d131d | 2014-03-13 16:17:40 +0100 | [diff] [blame] | 344 | LOCKS_EXCLUDED(Locks::thread_list_lock_) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 345 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 346 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 347 | static JDWP::ObjectId GetThreadSelfId() |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 348 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 349 | static void SuspendVM() |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 350 | LOCKS_EXCLUDED(Locks::thread_list_lock_, |
| 351 | Locks::thread_suspend_count_lock_); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 352 | static void ResumeVM(); |
Elliott Hughes | 88d6309 | 2013-01-09 09:55:54 -0800 | [diff] [blame] | 353 | static JDWP::JdwpError SuspendThread(JDWP::ObjectId thread_id, bool request_suspension = true) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 354 | LOCKS_EXCLUDED(Locks::mutator_lock_, |
| 355 | Locks::thread_list_lock_, |
| 356 | Locks::thread_suspend_count_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 357 | |
Elliott Hughes | 88d6309 | 2013-01-09 09:55:54 -0800 | [diff] [blame] | 358 | static void ResumeThread(JDWP::ObjectId thread_id) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 359 | LOCKS_EXCLUDED(Locks::thread_list_lock_, |
| 360 | Locks::thread_suspend_count_lock_) |
| 361 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 362 | static void SuspendSelf(); |
| 363 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 364 | static JDWP::JdwpError GetThisObject(JDWP::ObjectId thread_id, JDWP::FrameId frame_id, |
| 365 | JDWP::ObjectId* result) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 366 | LOCKS_EXCLUDED(Locks::thread_list_lock_, |
| 367 | Locks::thread_suspend_count_lock_) |
| 368 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Sebastien Hertz | cb19ebf | 2014-03-11 15:26:35 +0100 | [diff] [blame] | 369 | static JDWP::JdwpError GetLocalValue(JDWP::ObjectId thread_id, JDWP::FrameId frame_id, int slot, |
| 370 | JDWP::JdwpTag tag, uint8_t* buf, size_t expectedLen) |
Sebastien Hertz | 52d131d | 2014-03-13 16:17:40 +0100 | [diff] [blame] | 371 | LOCKS_EXCLUDED(Locks::thread_list_lock_) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 372 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Sebastien Hertz | cb19ebf | 2014-03-11 15:26:35 +0100 | [diff] [blame] | 373 | static JDWP::JdwpError SetLocalValue(JDWP::ObjectId thread_id, JDWP::FrameId frame_id, int slot, |
| 374 | JDWP::JdwpTag tag, uint64_t value, size_t width) |
Sebastien Hertz | 52d131d | 2014-03-13 16:17:40 +0100 | [diff] [blame] | 375 | LOCKS_EXCLUDED(Locks::thread_list_lock_) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 376 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 377 | |
Sebastien Hertz | 52d131d | 2014-03-13 16:17:40 +0100 | [diff] [blame] | 378 | static JDWP::JdwpError Interrupt(JDWP::ObjectId thread_id) |
| 379 | LOCKS_EXCLUDED(Locks::thread_list_lock_); |
Elliott Hughes | f950170 | 2013-01-11 11:22:27 -0800 | [diff] [blame] | 380 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 381 | /* |
| 382 | * Debugger notification |
| 383 | */ |
| 384 | enum { |
Elliott Hughes | 8696433 | 2012-02-15 19:37:42 -0800 | [diff] [blame] | 385 | kBreakpoint = 0x01, |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 386 | kSingleStep = 0x02, |
| 387 | kMethodEntry = 0x04, |
| 388 | kMethodExit = 0x08, |
| 389 | }; |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 390 | static void PostLocationEvent(mirror::ArtMethod* method, int pcOffset, |
Jeff Hao | 579b024 | 2013-11-18 13:16:49 -0800 | [diff] [blame] | 391 | mirror::Object* thisPtr, int eventFlags, |
| 392 | const JValue* return_value) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 393 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 394 | static void PostException(Thread* thread, const ThrowLocation& throw_location, |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 395 | mirror::ArtMethod* catch_method, |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 396 | uint32_t catch_dex_pc, mirror::Throwable* exception) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 397 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 398 | static void PostThreadStart(Thread* t) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 399 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 400 | static void PostThreadDeath(Thread* t) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 401 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 402 | static void PostClassPrepare(mirror::Class* c) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 403 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 404 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 405 | static void UpdateDebugger(Thread* thread, mirror::Object* this_object, |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 406 | mirror::ArtMethod* method, uint32_t new_dex_pc) |
jeffhao | 09bfc6a | 2012-12-11 18:11:43 -0800 | [diff] [blame] | 407 | LOCKS_EXCLUDED(Locks::breakpoint_lock_) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 408 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 91bf6cd | 2012-02-14 17:27:48 -0800 | [diff] [blame] | 409 | |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 410 | // Full Deoptimization control. Only used for method entry/exit and single-stepping. |
| 411 | static void EnableFullDeoptimization() |
| 412 | LOCKS_EXCLUDED(Locks::deoptimization_lock_) |
| 413 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 414 | static void DisableFullDeoptimization() |
Ian Rogers | 719d1a3 | 2014-03-06 12:13:39 -0800 | [diff] [blame] | 415 | LOCKS_EXCLUDED(Locks::deoptimization_lock_) |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 416 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 417 | |
| 418 | // Manage deoptimization after updating JDWP events list. This must be done while all mutator |
| 419 | // threads are suspended. |
| 420 | static void ManageDeoptimization() |
| 421 | LOCKS_EXCLUDED(Locks::deoptimization_lock_) |
| 422 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 423 | |
| 424 | // Breakpoints. |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 425 | static void WatchLocation(const JDWP::JdwpLocation* pLoc) |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 426 | LOCKS_EXCLUDED(Locks::breakpoint_lock_, Locks::deoptimization_lock_) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 427 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 428 | static void UnwatchLocation(const JDWP::JdwpLocation* pLoc) |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 429 | LOCKS_EXCLUDED(Locks::breakpoint_lock_, Locks::deoptimization_lock_) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 430 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 431 | |
| 432 | // Single-stepping. |
Elliott Hughes | 88d6309 | 2013-01-09 09:55:54 -0800 | [diff] [blame] | 433 | static JDWP::JdwpError ConfigureStep(JDWP::ObjectId thread_id, JDWP::JdwpStepSize size, |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 434 | JDWP::JdwpStepDepth depth) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 435 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Sebastien Hertz | 61b7f1b | 2013-11-15 15:59:30 +0100 | [diff] [blame] | 436 | static void UnconfigureStep(JDWP::ObjectId thread_id) |
Sebastien Hertz | 52d131d | 2014-03-13 16:17:40 +0100 | [diff] [blame] | 437 | LOCKS_EXCLUDED(Locks::thread_list_lock_) |
Sebastien Hertz | 61b7f1b | 2013-11-15 15:59:30 +0100 | [diff] [blame] | 438 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 439 | |
Elliott Hughes | 88d6309 | 2013-01-09 09:55:54 -0800 | [diff] [blame] | 440 | static JDWP::JdwpError InvokeMethod(JDWP::ObjectId thread_id, JDWP::ObjectId object_id, |
| 441 | JDWP::RefTypeId class_id, JDWP::MethodId method_id, |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 442 | uint32_t arg_count, uint64_t* arg_values, |
| 443 | JDWP::JdwpTag* arg_types, uint32_t options, |
| 444 | JDWP::JdwpTag* pResultTag, uint64_t* pResultValue, |
| 445 | JDWP::ObjectId* pExceptObj) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 446 | LOCKS_EXCLUDED(Locks::thread_list_lock_, |
| 447 | Locks::thread_suspend_count_lock_) |
| 448 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 449 | static void ExecuteMethod(DebugInvokeReq* pReq); |
| 450 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 451 | /* |
| 452 | * DDM support. |
| 453 | */ |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 454 | static void DdmSendThreadNotification(Thread* t, uint32_t type) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 455 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Sebastien Hertz | 52d131d | 2014-03-13 16:17:40 +0100 | [diff] [blame] | 456 | static void DdmSetThreadNotification(bool enable) |
| 457 | LOCKS_EXCLUDED(Locks::thread_list_lock_); |
Elliott Hughes | 4b9702c | 2013-02-20 18:13:24 -0800 | [diff] [blame] | 458 | static bool DdmHandlePacket(JDWP::Request& request, uint8_t** pReplyBuf, int* pReplyLen); |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 459 | static void DdmConnected() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 460 | static void DdmDisconnected() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 461 | static void DdmSendChunk(uint32_t type, const std::vector<uint8_t>& bytes) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 462 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 463 | static void DdmSendChunk(uint32_t type, size_t len, const uint8_t* buf) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 464 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 465 | static void DdmSendChunkV(uint32_t type, const iovec* iov, int iov_count) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 466 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 767a147 | 2011-10-26 18:49:02 -0700 | [diff] [blame] | 467 | |
Mathieu Chartier | 3b05e9b | 2014-03-25 09:29:43 -0700 | [diff] [blame] | 468 | static void VisitRoots(RootCallback* callback, void* arg) |
| 469 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 470 | |
Elliott Hughes | 545a064 | 2011-11-08 19:10:03 -0800 | [diff] [blame] | 471 | /* |
| 472 | * Recent allocation tracking support. |
| 473 | */ |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 474 | static void RecordAllocation(mirror::Class* type, size_t byte_count) |
Sebastien Hertz | 52d131d | 2014-03-13 16:17:40 +0100 | [diff] [blame] | 475 | LOCKS_EXCLUDED(alloc_tracker_lock_) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 476 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Sebastien Hertz | 52d131d | 2014-03-13 16:17:40 +0100 | [diff] [blame] | 477 | static void SetAllocTrackingEnabled(bool enabled) LOCKS_EXCLUDED(alloc_tracker_lock_); |
Ian Rogers | 719d1a3 | 2014-03-06 12:13:39 -0800 | [diff] [blame] | 478 | static bool IsAllocTrackingEnabled() { |
| 479 | return recent_allocation_records_ != nullptr; |
| 480 | } |
Sebastien Hertz | 52d131d | 2014-03-13 16:17:40 +0100 | [diff] [blame] | 481 | static jbyteArray GetRecentAllocations() |
| 482 | LOCKS_EXCLUDED(alloc_tracker_lock_) |
| 483 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 719d1a3 | 2014-03-06 12:13:39 -0800 | [diff] [blame] | 484 | static size_t HeadIndex() EXCLUSIVE_LOCKS_REQUIRED(alloc_tracker_lock_); |
Sebastien Hertz | 52d131d | 2014-03-13 16:17:40 +0100 | [diff] [blame] | 485 | static void DumpRecentAllocations() LOCKS_EXCLUDED(alloc_tracker_lock_); |
Elliott Hughes | 545a064 | 2011-11-08 19:10:03 -0800 | [diff] [blame] | 486 | |
Mathieu Chartier | 412c7fc | 2014-02-07 12:18:39 -0800 | [diff] [blame] | 487 | // Updates the stored direct object pointers (called from SweepSystemWeaks). |
Mathieu Chartier | 83c8ee0 | 2014-01-28 14:50:23 -0800 | [diff] [blame] | 488 | static void UpdateObjectPointers(IsMarkedCallback* callback, void* arg) |
Sebastien Hertz | 52d131d | 2014-03-13 16:17:40 +0100 | [diff] [blame] | 489 | LOCKS_EXCLUDED(alloc_tracker_lock_) |
Mathieu Chartier | 412c7fc | 2014-02-07 12:18:39 -0800 | [diff] [blame] | 490 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 491 | |
Elliott Hughes | 767a147 | 2011-10-26 18:49:02 -0700 | [diff] [blame] | 492 | enum HpifWhen { |
| 493 | HPIF_WHEN_NEVER = 0, |
| 494 | HPIF_WHEN_NOW = 1, |
| 495 | HPIF_WHEN_NEXT_GC = 2, |
| 496 | HPIF_WHEN_EVERY_GC = 3 |
| 497 | }; |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 498 | static int DdmHandleHpifChunk(HpifWhen when) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 499 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 767a147 | 2011-10-26 18:49:02 -0700 | [diff] [blame] | 500 | |
| 501 | enum HpsgWhen { |
| 502 | HPSG_WHEN_NEVER = 0, |
| 503 | HPSG_WHEN_EVERY_GC = 1, |
| 504 | }; |
| 505 | enum HpsgWhat { |
| 506 | HPSG_WHAT_MERGED_OBJECTS = 0, |
| 507 | HPSG_WHAT_DISTINCT_OBJECTS = 1, |
| 508 | }; |
| 509 | static bool DdmHandleHpsgNhsgChunk(HpsgWhen when, HpsgWhat what, bool native); |
| 510 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 511 | static void DdmSendHeapInfo(HpifWhen reason) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 512 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 513 | static void DdmSendHeapSegments(bool native) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 514 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 545a064 | 2011-11-08 19:10:03 -0800 | [diff] [blame] | 515 | |
Mathieu Chartier | 412c7fc | 2014-02-07 12:18:39 -0800 | [diff] [blame] | 516 | static void AllowNewObjectRegistryObjects() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 517 | static void DisallowNewObjectRegistryObjects() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 518 | |
Elliott Hughes | 545a064 | 2011-11-08 19:10:03 -0800 | [diff] [blame] | 519 | private: |
Brian Carlstrom | 2d88862 | 2013-07-18 17:02:00 -0700 | [diff] [blame] | 520 | static void DdmBroadcast(bool connect) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 521 | static void PostThreadStartOrStop(Thread*, uint32_t) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 522 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | a215526 | 2011-11-16 16:26:58 -0800 | [diff] [blame] | 523 | |
Ian Rogers | 719d1a3 | 2014-03-06 12:13:39 -0800 | [diff] [blame] | 524 | static Mutex* alloc_tracker_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER; |
| 525 | |
| 526 | static AllocRecord* recent_allocation_records_ PT_GUARDED_BY(alloc_tracker_lock_); |
| 527 | static size_t alloc_record_max_ GUARDED_BY(alloc_tracker_lock_); |
| 528 | static size_t alloc_record_head_ GUARDED_BY(alloc_tracker_lock_); |
| 529 | static size_t alloc_record_count_ GUARDED_BY(alloc_tracker_lock_); |
| 530 | |
| 531 | DISALLOW_COPY_AND_ASSIGN(Dbg); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 532 | }; |
| 533 | |
| 534 | #define CHUNK_TYPE(_name) \ |
Elliott Hughes | 8218847 | 2011-11-07 18:11:48 -0800 | [diff] [blame] | 535 | static_cast<uint32_t>((_name)[0] << 24 | (_name)[1] << 16 | (_name)[2] << 8 | (_name)[3]) |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 536 | |
| 537 | } // namespace art |
| 538 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 539 | #endif // ART_RUNTIME_DEBUGGER_H_ |