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 | |
Mathieu Chartier | 4345c46 | 2014-06-27 10:20:14 -0700 | [diff] [blame] | 26 | #include <map> |
Sebastien Hertz | 61b7f1b | 2013-11-15 15:59:30 +0100 | [diff] [blame] | 27 | #include <set> |
Elliott Hughes | 3bb8156 | 2011-10-21 18:52:59 -0700 | [diff] [blame] | 28 | #include <string> |
Sebastien Hertz | 4d25df3 | 2014-03-21 17:44:46 +0100 | [diff] [blame] | 29 | #include <vector> |
Elliott Hughes | 3bb8156 | 2011-10-21 18:52:59 -0700 | [diff] [blame] | 30 | |
Mathieu Chartier | e34fa1d | 2015-01-14 14:55:47 -0800 | [diff] [blame] | 31 | #include "gc_root.h" |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 32 | #include "jdwp/jdwp.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 33 | #include "jni.h" |
| 34 | #include "jvalue.h" |
Mathieu Chartier | 83c8ee0 | 2014-01-28 14:50:23 -0800 | [diff] [blame] | 35 | #include "object_callbacks.h" |
Jeff Hao | 920af3e | 2013-08-28 15:46:38 -0700 | [diff] [blame] | 36 | #include "thread_state.h" |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 37 | |
| 38 | namespace art { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 39 | namespace mirror { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 40 | class Class; |
| 41 | class Object; |
| 42 | class Throwable; |
| 43 | } // namespace mirror |
Hiroshi Yamauchi | b5a9e3d | 2014-06-09 12:11:20 -0700 | [diff] [blame] | 44 | class AllocRecord; |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 45 | class ArtField; |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 46 | class ArtMethod; |
Sebastien Hertz | 6995c60 | 2014-09-09 12:10:13 +0200 | [diff] [blame] | 47 | class ObjectRegistry; |
Sebastien Hertz | cbc5064 | 2015-06-01 17:33:12 +0200 | [diff] [blame^] | 48 | class ScopedObjectAccess; |
Sebastien Hertz | 6995c60 | 2014-09-09 12:10:13 +0200 | [diff] [blame] | 49 | class ScopedObjectAccessUnchecked; |
Sebastien Hertz | 8009f39 | 2014-09-01 17:07:11 +0200 | [diff] [blame] | 50 | class StackVisitor; |
Ian Rogers | 1b09b09 | 2012-08-20 15:35:52 -0700 | [diff] [blame] | 51 | class Thread; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 52 | |
| 53 | /* |
| 54 | * Invoke-during-breakpoint support. |
| 55 | */ |
| 56 | struct DebugInvokeReq { |
Sebastien Hertz | cbc5064 | 2015-06-01 17:33:12 +0200 | [diff] [blame^] | 57 | DebugInvokeReq(uint32_t invoke_request_id, JDWP::ObjectId invoke_thread_id, |
| 58 | mirror::Object* invoke_receiver, mirror::Class* invoke_class, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 59 | ArtMethod* invoke_method, uint32_t invoke_options, |
Sebastien Hertz | cbc5064 | 2015-06-01 17:33:12 +0200 | [diff] [blame^] | 60 | uint64_t args[], uint32_t args_count) |
| 61 | : request_id(invoke_request_id), thread_id(invoke_thread_id), receiver(invoke_receiver), |
| 62 | klass(invoke_class), method(invoke_method), arg_count(args_count), arg_values(args), |
| 63 | options(invoke_options), reply(JDWP::expandBufAlloc()) { |
Elliott Hughes | 475fc23 | 2011-10-25 15:00:35 -0700 | [diff] [blame] | 64 | } |
| 65 | |
Sebastien Hertz | cbc5064 | 2015-06-01 17:33:12 +0200 | [diff] [blame^] | 66 | ~DebugInvokeReq() { |
| 67 | JDWP::expandBufFree(reply); |
| 68 | } |
| 69 | |
| 70 | // Request |
| 71 | const uint32_t request_id; |
| 72 | const JDWP::ObjectId thread_id; |
| 73 | GcRoot<mirror::Object> receiver; // not used for ClassType.InvokeMethod. |
Sebastien Hertz | 1558b57 | 2015-02-25 15:05:59 +0100 | [diff] [blame] | 74 | GcRoot<mirror::Class> klass; |
Sebastien Hertz | cbc5064 | 2015-06-01 17:33:12 +0200 | [diff] [blame^] | 75 | ArtMethod* const method; |
Sebastien Hertz | 1558b57 | 2015-02-25 15:05:59 +0100 | [diff] [blame] | 76 | const uint32_t arg_count; |
Sebastien Hertz | cbc5064 | 2015-06-01 17:33:12 +0200 | [diff] [blame^] | 77 | std::unique_ptr<uint64_t[]> arg_values; // will be null if arg_count_ == 0. We take ownership |
| 78 | // of this array so we must delete it upon destruction. |
Sebastien Hertz | 1558b57 | 2015-02-25 15:05:59 +0100 | [diff] [blame] | 79 | const uint32_t options; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 80 | |
Sebastien Hertz | cbc5064 | 2015-06-01 17:33:12 +0200 | [diff] [blame^] | 81 | // Reply |
| 82 | JDWP::ExpandBuf* const reply; |
Sebastien Hertz | 61b7f1b | 2013-11-15 15:59:30 +0100 | [diff] [blame] | 83 | |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 84 | void VisitRoots(RootVisitor* visitor, const RootInfo& root_info) |
Mathieu Chartier | 3b05e9b | 2014-03-25 09:29:43 -0700 | [diff] [blame] | 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. |
Sebastien Hertz | 597c4f0 | 2015-01-26 17:37:14 +0100 | [diff] [blame] | 92 | class SingleStepControl { |
| 93 | public: |
| 94 | SingleStepControl(JDWP::JdwpStepSize step_size, JDWP::JdwpStepDepth step_depth, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 95 | int stack_depth, ArtMethod* method) |
Sebastien Hertz | 597c4f0 | 2015-01-26 17:37:14 +0100 | [diff] [blame] | 96 | : step_size_(step_size), step_depth_(step_depth), |
| 97 | stack_depth_(stack_depth), method_(method) { |
Sebastien Hertz | 61b7f1b | 2013-11-15 15:59:30 +0100 | [diff] [blame] | 98 | } |
| 99 | |
Sebastien Hertz | 597c4f0 | 2015-01-26 17:37:14 +0100 | [diff] [blame] | 100 | JDWP::JdwpStepSize GetStepSize() const { |
| 101 | return step_size_; |
| 102 | } |
Sebastien Hertz | 61b7f1b | 2013-11-15 15:59:30 +0100 | [diff] [blame] | 103 | |
Sebastien Hertz | 597c4f0 | 2015-01-26 17:37:14 +0100 | [diff] [blame] | 104 | JDWP::JdwpStepDepth GetStepDepth() const { |
| 105 | return step_depth_; |
| 106 | } |
| 107 | |
| 108 | int GetStackDepth() const { |
| 109 | return stack_depth_; |
| 110 | } |
| 111 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 112 | ArtMethod* GetMethod() const { |
| 113 | return method_; |
Sebastien Hertz | 597c4f0 | 2015-01-26 17:37:14 +0100 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | const std::set<uint32_t>& GetDexPcs() const { |
| 117 | return dex_pcs_; |
| 118 | } |
| 119 | |
Sebastien Hertz | 597c4f0 | 2015-01-26 17:37:14 +0100 | [diff] [blame] | 120 | void AddDexPc(uint32_t dex_pc); |
| 121 | |
| 122 | bool ContainsDexPc(uint32_t dex_pc) const; |
| 123 | |
| 124 | private: |
Sebastien Hertz | 61b7f1b | 2013-11-15 15:59:30 +0100 | [diff] [blame] | 125 | // See JdwpStepSize and JdwpStepDepth for details. |
Sebastien Hertz | 597c4f0 | 2015-01-26 17:37:14 +0100 | [diff] [blame] | 126 | const JDWP::JdwpStepSize step_size_; |
| 127 | const JDWP::JdwpStepDepth step_depth_; |
| 128 | |
| 129 | // The stack depth when this single-step was initiated. This is used to support SD_OVER and SD_OUT |
| 130 | // single-step depth. |
| 131 | const int stack_depth_; |
Sebastien Hertz | 61b7f1b | 2013-11-15 15:59:30 +0100 | [diff] [blame] | 132 | |
| 133 | // The location this single-step was initiated from. |
| 134 | // A single-step is initiated in a suspended thread. We save here the current method and the |
| 135 | // set of DEX pcs associated to the source line number where the suspension occurred. |
| 136 | // This is used to support SD_INTO and SD_OVER single-step depths so we detect when a single-step |
| 137 | // causes the execution of an instruction in a different method or at a different line number. |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 138 | ArtMethod* method_; |
| 139 | |
Sebastien Hertz | 597c4f0 | 2015-01-26 17:37:14 +0100 | [diff] [blame] | 140 | std::set<uint32_t> dex_pcs_; |
Sebastien Hertz | 61b7f1b | 2013-11-15 15:59:30 +0100 | [diff] [blame] | 141 | |
Sebastien Hertz | 61b7f1b | 2013-11-15 15:59:30 +0100 | [diff] [blame] | 142 | DISALLOW_COPY_AND_ASSIGN(SingleStepControl); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 143 | }; |
| 144 | |
Sebastien Hertz | 42cd43f | 2014-05-13 14:15:41 +0200 | [diff] [blame] | 145 | // TODO rename to InstrumentationRequest. |
Hiroshi Yamauchi | 0ec17d2 | 2014-07-07 13:07:08 -0700 | [diff] [blame] | 146 | class DeoptimizationRequest { |
| 147 | public: |
Sebastien Hertz | 4d25df3 | 2014-03-21 17:44:46 +0100 | [diff] [blame] | 148 | enum Kind { |
| 149 | kNothing, // no action. |
Sebastien Hertz | 42cd43f | 2014-05-13 14:15:41 +0200 | [diff] [blame] | 150 | kRegisterForEvent, // start listening for instrumentation event. |
| 151 | kUnregisterForEvent, // stop listening for instrumentation event. |
Sebastien Hertz | 4d25df3 | 2014-03-21 17:44:46 +0100 | [diff] [blame] | 152 | kFullDeoptimization, // deoptimize everything. |
| 153 | kFullUndeoptimization, // undeoptimize everything. |
| 154 | kSelectiveDeoptimization, // deoptimize one method. |
| 155 | kSelectiveUndeoptimization // undeoptimize one method. |
| 156 | }; |
| 157 | |
Hiroshi Yamauchi | 0ec17d2 | 2014-07-07 13:07:08 -0700 | [diff] [blame] | 158 | DeoptimizationRequest() : kind_(kNothing), instrumentation_event_(0), method_(nullptr) {} |
Sebastien Hertz | 4d25df3 | 2014-03-21 17:44:46 +0100 | [diff] [blame] | 159 | |
Hiroshi Yamauchi | 0ec17d2 | 2014-07-07 13:07:08 -0700 | [diff] [blame] | 160 | DeoptimizationRequest(const DeoptimizationRequest& other) |
| 161 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) |
| 162 | : kind_(other.kind_), instrumentation_event_(other.instrumentation_event_) { |
| 163 | // Create a new JNI global reference for the method. |
| 164 | SetMethod(other.Method()); |
| 165 | } |
Sebastien Hertz | 4d25df3 | 2014-03-21 17:44:46 +0100 | [diff] [blame] | 166 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 167 | ArtMethod* Method() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Hiroshi Yamauchi | 0ec17d2 | 2014-07-07 13:07:08 -0700 | [diff] [blame] | 168 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 169 | void SetMethod(ArtMethod* m) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Hiroshi Yamauchi | 0ec17d2 | 2014-07-07 13:07:08 -0700 | [diff] [blame] | 170 | |
| 171 | // Name 'Kind()' would collide with the above enum name. |
| 172 | Kind GetKind() const { |
| 173 | return kind_; |
| 174 | } |
| 175 | |
| 176 | void SetKind(Kind kind) { |
| 177 | kind_ = kind; |
| 178 | } |
| 179 | |
| 180 | uint32_t InstrumentationEvent() const { |
| 181 | return instrumentation_event_; |
| 182 | } |
| 183 | |
| 184 | void SetInstrumentationEvent(uint32_t instrumentation_event) { |
| 185 | instrumentation_event_ = instrumentation_event; |
| 186 | } |
| 187 | |
| 188 | private: |
| 189 | Kind kind_; |
Sebastien Hertz | 4d25df3 | 2014-03-21 17:44:46 +0100 | [diff] [blame] | 190 | |
Sebastien Hertz | 42cd43f | 2014-05-13 14:15:41 +0200 | [diff] [blame] | 191 | // TODO we could use a union to hold the instrumentation_event and the method since they |
| 192 | // respectively have sense only for kRegisterForEvent/kUnregisterForEvent and |
| 193 | // kSelectiveDeoptimization/kSelectiveUndeoptimization. |
| 194 | |
| 195 | // Event to start or stop listening to. Only for kRegisterForEvent and kUnregisterForEvent. |
Hiroshi Yamauchi | 0ec17d2 | 2014-07-07 13:07:08 -0700 | [diff] [blame] | 196 | uint32_t instrumentation_event_; |
Sebastien Hertz | 42cd43f | 2014-05-13 14:15:41 +0200 | [diff] [blame] | 197 | |
Sebastien Hertz | 4d25df3 | 2014-03-21 17:44:46 +0100 | [diff] [blame] | 198 | // Method for selective deoptimization. |
Hiroshi Yamauchi | 0ec17d2 | 2014-07-07 13:07:08 -0700 | [diff] [blame] | 199 | jmethodID method_; |
Sebastien Hertz | 4d25df3 | 2014-03-21 17:44:46 +0100 | [diff] [blame] | 200 | }; |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 201 | std::ostream& operator<<(std::ostream& os, const DeoptimizationRequest::Kind& rhs); |
Sebastien Hertz | 4d25df3 | 2014-03-21 17:44:46 +0100 | [diff] [blame] | 202 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 203 | class Dbg { |
Elliott Hughes | ff17f1f | 2012-01-24 18:12:29 -0800 | [diff] [blame] | 204 | public: |
Mathieu Chartier | 4345c46 | 2014-06-27 10:20:14 -0700 | [diff] [blame] | 205 | class TypeCache { |
| 206 | public: |
| 207 | // Returns a weak global for the input type. Deduplicates. |
Brian Carlstrom | 306db81 | 2014-09-05 13:01:41 -0700 | [diff] [blame] | 208 | jobject Add(mirror::Class* t) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_, |
| 209 | Locks::alloc_tracker_lock_); |
Mathieu Chartier | 4345c46 | 2014-06-27 10:20:14 -0700 | [diff] [blame] | 210 | // Clears the type cache and deletes all the weak global refs. |
Brian Carlstrom | 306db81 | 2014-09-05 13:01:41 -0700 | [diff] [blame] | 211 | void Clear() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_, |
| 212 | Locks::alloc_tracker_lock_); |
Mathieu Chartier | 4345c46 | 2014-06-27 10:20:14 -0700 | [diff] [blame] | 213 | |
| 214 | private: |
| 215 | std::multimap<int32_t, jobject> objects_; |
| 216 | }; |
| 217 | |
Elliott Hughes | 4ffd313 | 2011-10-24 12:06:42 -0700 | [diff] [blame] | 218 | static void SetJdwpAllowed(bool allowed); |
| 219 | |
Sebastien Hertz | b3b173b | 2015-02-06 09:16:32 +0100 | [diff] [blame] | 220 | static void StartJdwp(); |
Elliott Hughes | d1cc836 | 2011-10-24 16:58:50 -0700 | [diff] [blame] | 221 | static void StopJdwp(); |
| 222 | |
Elliott Hughes | 767a147 | 2011-10-26 18:49:02 -0700 | [diff] [blame] | 223 | // Invoked by the GC in case we need to keep DDMS informed. |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 224 | static void GcDidFinish() LOCKS_EXCLUDED(Locks::mutator_lock_); |
Elliott Hughes | 767a147 | 2011-10-26 18:49:02 -0700 | [diff] [blame] | 225 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 226 | // Return the DebugInvokeReq for the current thread. |
| 227 | static DebugInvokeReq* GetInvokeReq(); |
| 228 | |
Elliott Hughes | 475fc23 | 2011-10-25 15:00:35 -0700 | [diff] [blame] | 229 | static Thread* GetDebugThread(); |
| 230 | static void ClearWaitForEventThread(); |
| 231 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 232 | /* |
| 233 | * Enable/disable breakpoints and step modes. Used to provide a heads-up |
| 234 | * when the debugger attaches. |
| 235 | */ |
| 236 | static void Connected(); |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 237 | static void GoActive() |
Brian Carlstrom | 306db81 | 2014-09-05 13:01:41 -0700 | [diff] [blame] | 238 | LOCKS_EXCLUDED(Locks::breakpoint_lock_, Locks::deoptimization_lock_, Locks::mutator_lock_); |
| 239 | static void Disconnected() LOCKS_EXCLUDED(Locks::deoptimization_lock_, Locks::mutator_lock_); |
Sebastien Hertz | 4e5b208 | 2015-03-24 19:03:40 +0100 | [diff] [blame] | 240 | static void Dispose() { |
| 241 | gDisposed = true; |
| 242 | } |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 243 | |
Elliott Hughes | c0f0933 | 2012-03-26 13:27:06 -0700 | [diff] [blame] | 244 | // Returns true if we're actually debugging with a real debugger, false if it's |
| 245 | // just DDMS (or nothing at all). |
Daniel Mihalyi | eb07669 | 2014-08-22 17:33:31 +0200 | [diff] [blame] | 246 | static bool IsDebuggerActive() { |
| 247 | return gDebuggerActive; |
| 248 | } |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 249 | |
Sebastien Hertz | b3b173b | 2015-02-06 09:16:32 +0100 | [diff] [blame] | 250 | // Configures JDWP with parsed command-line options. |
| 251 | static void ConfigureJdwp(const JDWP::JdwpOptions& jdwp_options); |
| 252 | |
Elliott Hughes | c0f0933 | 2012-03-26 13:27:06 -0700 | [diff] [blame] | 253 | // Returns true if we had -Xrunjdwp or -agentlib:jdwp= on the command line. |
| 254 | static bool IsJdwpConfigured(); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 255 | |
Mathieu Chartier | d856545 | 2015-03-26 09:41:50 -0700 | [diff] [blame] | 256 | // Returns true if a method has any breakpoints. |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 257 | static bool MethodHasAnyBreakpoints(ArtMethod* method) |
Sebastien Hertz | 4e5b208 | 2015-03-24 19:03:40 +0100 | [diff] [blame] | 258 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) |
| 259 | LOCKS_EXCLUDED(Locks::breakpoint_lock_); |
Mathieu Chartier | d856545 | 2015-03-26 09:41:50 -0700 | [diff] [blame] | 260 | |
Sebastien Hertz | 4e5b208 | 2015-03-24 19:03:40 +0100 | [diff] [blame] | 261 | static bool IsDisposed() { |
| 262 | return gDisposed; |
| 263 | } |
Elliott Hughes | 8696433 | 2012-02-15 19:37:42 -0800 | [diff] [blame] | 264 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 265 | /* |
| 266 | * Time, in milliseconds, since the last debugger activity. Does not |
| 267 | * include DDMS activity. Returns -1 if there has been no activity. |
| 268 | * Returns 0 if we're in the middle of handling a debugger request. |
| 269 | */ |
| 270 | static int64_t LastDebuggerActivity(); |
| 271 | |
Sebastien Hertz | 253fa55 | 2014-10-14 17:27:15 +0200 | [diff] [blame] | 272 | static void UndoDebuggerSuspensions() |
| 273 | LOCKS_EXCLUDED(Locks::thread_list_lock_, |
| 274 | Locks::thread_suspend_count_lock_); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 275 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 276 | /* |
| 277 | * Class, Object, Array |
| 278 | */ |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 279 | static std::string GetClassName(JDWP::RefTypeId id) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 280 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Sebastien Hertz | 6995c60 | 2014-09-09 12:10:13 +0200 | [diff] [blame] | 281 | static std::string GetClassName(mirror::Class* klass) |
| 282 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | c0542af | 2014-09-03 16:16:56 -0700 | [diff] [blame] | 283 | static JDWP::JdwpError GetClassObject(JDWP::RefTypeId id, JDWP::ObjectId* class_object_id) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 284 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | c0542af | 2014-09-03 16:16:56 -0700 | [diff] [blame] | 285 | static JDWP::JdwpError GetSuperclass(JDWP::RefTypeId id, JDWP::RefTypeId* superclass_id) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 286 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 287 | static JDWP::JdwpError GetClassLoader(JDWP::RefTypeId id, JDWP::ExpandBuf* pReply) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 288 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 289 | static JDWP::JdwpError GetModifiers(JDWP::RefTypeId id, JDWP::ExpandBuf* pReply) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 290 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 88d6309 | 2013-01-09 09:55:54 -0800 | [diff] [blame] | 291 | static JDWP::JdwpError GetReflectedType(JDWP::RefTypeId class_id, JDWP::ExpandBuf* pReply) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 292 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | c0542af | 2014-09-03 16:16:56 -0700 | [diff] [blame] | 293 | static void GetClassList(std::vector<JDWP::RefTypeId>* classes) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 294 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 88d6309 | 2013-01-09 09:55:54 -0800 | [diff] [blame] | 295 | static JDWP::JdwpError GetClassInfo(JDWP::RefTypeId class_id, JDWP::JdwpTypeTag* pTypeTag, |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 296 | uint32_t* pStatus, std::string* pDescriptor) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 297 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | c0542af | 2014-09-03 16:16:56 -0700 | [diff] [blame] | 298 | static void FindLoadedClassBySignature(const char* descriptor, std::vector<JDWP::RefTypeId>* ids) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 299 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 64f574f | 2013-02-20 14:57:12 -0800 | [diff] [blame] | 300 | static JDWP::JdwpError GetReferenceType(JDWP::ObjectId object_id, JDWP::ExpandBuf* pReply) |
| 301 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | fc0e94b | 2013-09-23 23:51:32 -0700 | [diff] [blame] | 302 | static JDWP::JdwpError GetSignature(JDWP::RefTypeId ref_type_id, std::string* signature) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 303 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | c0542af | 2014-09-03 16:16:56 -0700 | [diff] [blame] | 304 | 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] | 305 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | c0542af | 2014-09-03 16:16:56 -0700 | [diff] [blame] | 306 | static JDWP::JdwpError GetObjectTag(JDWP::ObjectId object_id, uint8_t* tag) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 307 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | aed4be9 | 2011-12-02 16:16:23 -0800 | [diff] [blame] | 308 | static size_t GetTagWidth(JDWP::JdwpTag tag); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 309 | |
Ian Rogers | c0542af | 2014-09-03 16:16:56 -0700 | [diff] [blame] | 310 | static JDWP::JdwpError GetArrayLength(JDWP::ObjectId array_id, int32_t* length) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 311 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 88d6309 | 2013-01-09 09:55:54 -0800 | [diff] [blame] | 312 | static JDWP::JdwpError OutputArray(JDWP::ObjectId array_id, int offset, int count, |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 313 | JDWP::ExpandBuf* pReply) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 314 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 88d6309 | 2013-01-09 09:55:54 -0800 | [diff] [blame] | 315 | static JDWP::JdwpError SetArrayElements(JDWP::ObjectId array_id, int offset, int count, |
Ian Rogers | c0542af | 2014-09-03 16:16:56 -0700 | [diff] [blame] | 316 | JDWP::Request* request) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 317 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 318 | |
Sebastien Hertz | 2c3e77a | 2015-04-02 16:26:48 +0200 | [diff] [blame] | 319 | static JDWP::JdwpError CreateString(const std::string& str, JDWP::ObjectId* new_string_id) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 320 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Sebastien Hertz | 2c3e77a | 2015-04-02 16:26:48 +0200 | [diff] [blame] | 321 | static JDWP::JdwpError CreateObject(JDWP::RefTypeId class_id, JDWP::ObjectId* new_object_id) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 322 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 88d6309 | 2013-01-09 09:55:54 -0800 | [diff] [blame] | 323 | static JDWP::JdwpError CreateArrayObject(JDWP::RefTypeId array_class_id, uint32_t length, |
Sebastien Hertz | 2c3e77a | 2015-04-02 16:26:48 +0200 | [diff] [blame] | 324 | JDWP::ObjectId* new_array_id) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 325 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 326 | |
Sebastien Hertz | 6995c60 | 2014-09-09 12:10:13 +0200 | [diff] [blame] | 327 | // |
| 328 | // Event filtering. |
| 329 | // |
| 330 | static bool MatchThread(JDWP::ObjectId expected_thread_id, Thread* event_thread) |
| 331 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 332 | |
| 333 | static bool MatchLocation(const JDWP::JdwpLocation& expected_location, |
| 334 | const JDWP::EventLocation& event_location) |
| 335 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 336 | |
| 337 | static bool MatchType(mirror::Class* event_class, JDWP::RefTypeId class_id) |
| 338 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 339 | |
| 340 | static bool MatchField(JDWP::RefTypeId expected_type_id, JDWP::FieldId expected_field_id, |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 341 | ArtField* event_field) |
Sebastien Hertz | 6995c60 | 2014-09-09 12:10:13 +0200 | [diff] [blame] | 342 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 343 | |
| 344 | static bool MatchInstance(JDWP::ObjectId expected_instance_id, mirror::Object* event_instance) |
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 | |
Elliott Hughes | ec0f83d | 2013-01-15 16:54:08 -0800 | [diff] [blame] | 347 | // |
| 348 | // Monitors. |
| 349 | // |
| 350 | static JDWP::JdwpError GetMonitorInfo(JDWP::ObjectId object_id, JDWP::ExpandBuf* reply) |
| 351 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 352 | static JDWP::JdwpError GetOwnedMonitors(JDWP::ObjectId thread_id, |
Ian Rogers | c0542af | 2014-09-03 16:16:56 -0700 | [diff] [blame] | 353 | std::vector<JDWP::ObjectId>* monitors, |
| 354 | std::vector<uint32_t>* stack_depths) |
Sebastien Hertz | 52d131d | 2014-03-13 16:17:40 +0100 | [diff] [blame] | 355 | LOCKS_EXCLUDED(Locks::thread_list_lock_) |
Elliott Hughes | ec0f83d | 2013-01-15 16:54:08 -0800 | [diff] [blame] | 356 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Sebastien Hertz | 52d131d | 2014-03-13 16:17:40 +0100 | [diff] [blame] | 357 | static JDWP::JdwpError GetContendedMonitor(JDWP::ObjectId thread_id, |
Ian Rogers | c0542af | 2014-09-03 16:16:56 -0700 | [diff] [blame] | 358 | JDWP::ObjectId* contended_monitor) |
Sebastien Hertz | 52d131d | 2014-03-13 16:17:40 +0100 | [diff] [blame] | 359 | LOCKS_EXCLUDED(Locks::thread_list_lock_) |
Elliott Hughes | ec0f83d | 2013-01-15 16:54:08 -0800 | [diff] [blame] | 360 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 361 | |
| 362 | // |
| 363 | // Heap. |
| 364 | // |
| 365 | static JDWP::JdwpError GetInstanceCounts(const std::vector<JDWP::RefTypeId>& class_ids, |
Ian Rogers | c0542af | 2014-09-03 16:16:56 -0700 | [diff] [blame] | 366 | std::vector<uint64_t>* counts) |
Elliott Hughes | ec0f83d | 2013-01-15 16:54:08 -0800 | [diff] [blame] | 367 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 3b78c94 | 2013-01-15 17:35:41 -0800 | [diff] [blame] | 368 | static JDWP::JdwpError GetInstances(JDWP::RefTypeId class_id, int32_t max_count, |
Ian Rogers | c0542af | 2014-09-03 16:16:56 -0700 | [diff] [blame] | 369 | std::vector<JDWP::ObjectId>* instances) |
Elliott Hughes | 3b78c94 | 2013-01-15 17:35:41 -0800 | [diff] [blame] | 370 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 0cbaff5 | 2013-01-16 15:28:01 -0800 | [diff] [blame] | 371 | static JDWP::JdwpError GetReferringObjects(JDWP::ObjectId object_id, int32_t max_count, |
Ian Rogers | c0542af | 2014-09-03 16:16:56 -0700 | [diff] [blame] | 372 | std::vector<JDWP::ObjectId>* referring_objects) |
Elliott Hughes | 0cbaff5 | 2013-01-16 15:28:01 -0800 | [diff] [blame] | 373 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 64f574f | 2013-02-20 14:57:12 -0800 | [diff] [blame] | 374 | static JDWP::JdwpError DisableCollection(JDWP::ObjectId object_id) |
| 375 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 376 | static JDWP::JdwpError EnableCollection(JDWP::ObjectId object_id) |
| 377 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | c0542af | 2014-09-03 16:16:56 -0700 | [diff] [blame] | 378 | static JDWP::JdwpError IsCollected(JDWP::ObjectId object_id, bool* is_collected) |
Elliott Hughes | 64f574f | 2013-02-20 14:57:12 -0800 | [diff] [blame] | 379 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 380 | static void DisposeObject(JDWP::ObjectId object_id, uint32_t reference_count) |
| 381 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | ec0f83d | 2013-01-15 16:54:08 -0800 | [diff] [blame] | 382 | |
Elliott Hughes | 9777ba2 | 2013-01-17 09:04:19 -0800 | [diff] [blame] | 383 | // |
| 384 | // Methods and fields. |
| 385 | // |
Elliott Hughes | a96836a | 2013-01-17 12:27:49 -0800 | [diff] [blame] | 386 | static std::string GetMethodName(JDWP::MethodId method_id) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 387 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 88d6309 | 2013-01-09 09:55:54 -0800 | [diff] [blame] | 388 | static JDWP::JdwpError OutputDeclaredFields(JDWP::RefTypeId ref_type_id, bool with_generic, |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 389 | JDWP::ExpandBuf* pReply) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 390 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 88d6309 | 2013-01-09 09:55:54 -0800 | [diff] [blame] | 391 | static JDWP::JdwpError OutputDeclaredMethods(JDWP::RefTypeId ref_type_id, bool with_generic, |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 392 | JDWP::ExpandBuf* pReply) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 393 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 88d6309 | 2013-01-09 09:55:54 -0800 | [diff] [blame] | 394 | static JDWP::JdwpError OutputDeclaredInterfaces(JDWP::RefTypeId ref_type_id, |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 395 | JDWP::ExpandBuf* pReply) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 396 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 88d6309 | 2013-01-09 09:55:54 -0800 | [diff] [blame] | 397 | static void OutputLineTable(JDWP::RefTypeId ref_type_id, JDWP::MethodId method_id, |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 398 | JDWP::ExpandBuf* pReply) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 399 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 88d6309 | 2013-01-09 09:55:54 -0800 | [diff] [blame] | 400 | 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] | 401 | JDWP::ExpandBuf* pReply) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 402 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Jeff Hao | 579b024 | 2013-11-18 13:16:49 -0800 | [diff] [blame] | 403 | static void OutputMethodReturnValue(JDWP::MethodId method_id, const JValue* return_value, |
| 404 | JDWP::ExpandBuf* pReply) |
| 405 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Sebastien Hertz | 3f52eaf | 2014-04-04 17:50:18 +0200 | [diff] [blame] | 406 | static void OutputFieldValue(JDWP::FieldId field_id, const JValue* field_value, |
| 407 | JDWP::ExpandBuf* pReply) |
| 408 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 9777ba2 | 2013-01-17 09:04:19 -0800 | [diff] [blame] | 409 | static JDWP::JdwpError GetBytecodes(JDWP::RefTypeId class_id, JDWP::MethodId method_id, |
Ian Rogers | c0542af | 2014-09-03 16:16:56 -0700 | [diff] [blame] | 410 | std::vector<uint8_t>* bytecodes) |
Elliott Hughes | 9777ba2 | 2013-01-17 09:04:19 -0800 | [diff] [blame] | 411 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 412 | |
Elliott Hughes | a96836a | 2013-01-17 12:27:49 -0800 | [diff] [blame] | 413 | static std::string GetFieldName(JDWP::FieldId field_id) |
| 414 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 88d6309 | 2013-01-09 09:55:54 -0800 | [diff] [blame] | 415 | static JDWP::JdwpTag GetFieldBasicTag(JDWP::FieldId field_id) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 416 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 88d6309 | 2013-01-09 09:55:54 -0800 | [diff] [blame] | 417 | static JDWP::JdwpTag GetStaticFieldBasicTag(JDWP::FieldId field_id) |
Brian Carlstrom | f69863b | 2013-07-17 21:53:13 -0700 | [diff] [blame] | 418 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 88d6309 | 2013-01-09 09:55:54 -0800 | [diff] [blame] | 419 | static JDWP::JdwpError GetFieldValue(JDWP::ObjectId object_id, JDWP::FieldId field_id, |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 420 | JDWP::ExpandBuf* pReply) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 421 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 88d6309 | 2013-01-09 09:55:54 -0800 | [diff] [blame] | 422 | static JDWP::JdwpError SetFieldValue(JDWP::ObjectId object_id, JDWP::FieldId field_id, |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 423 | uint64_t value, int width) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 424 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 88d6309 | 2013-01-09 09:55:54 -0800 | [diff] [blame] | 425 | 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] | 426 | JDWP::ExpandBuf* pReply) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 427 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 88d6309 | 2013-01-09 09:55:54 -0800 | [diff] [blame] | 428 | 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] | 429 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 430 | |
Sebastien Hertz | b0b0b49 | 2014-09-15 11:27:27 +0200 | [diff] [blame] | 431 | static JDWP::JdwpError StringToUtf8(JDWP::ObjectId string_id, std::string* str) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 432 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Jeff Hao | 579b024 | 2013-11-18 13:16:49 -0800 | [diff] [blame] | 433 | static void OutputJValue(JDWP::JdwpTag tag, const JValue* return_value, JDWP::ExpandBuf* pReply) |
| 434 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 435 | |
| 436 | /* |
| 437 | * Thread, ThreadGroup, Frame |
| 438 | */ |
Ian Rogers | c0542af | 2014-09-03 16:16:56 -0700 | [diff] [blame] | 439 | static JDWP::JdwpError GetThreadName(JDWP::ObjectId thread_id, std::string* name) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 440 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) |
| 441 | LOCKS_EXCLUDED(Locks::thread_list_lock_); |
Sebastien Hertz | 52d131d | 2014-03-13 16:17:40 +0100 | [diff] [blame] | 442 | static JDWP::JdwpError GetThreadGroup(JDWP::ObjectId thread_id, JDWP::ExpandBuf* pReply) |
Sebastien Hertz | a06430c | 2014-09-15 19:21:30 +0200 | [diff] [blame] | 443 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) |
Sebastien Hertz | 52d131d | 2014-03-13 16:17:40 +0100 | [diff] [blame] | 444 | LOCKS_EXCLUDED(Locks::thread_list_lock_); |
Sebastien Hertz | a06430c | 2014-09-15 19:21:30 +0200 | [diff] [blame] | 445 | static JDWP::JdwpError GetThreadGroupName(JDWP::ObjectId thread_group_id, |
| 446 | JDWP::ExpandBuf* pReply) |
| 447 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 448 | static JDWP::JdwpError GetThreadGroupParent(JDWP::ObjectId thread_group_id, |
| 449 | JDWP::ExpandBuf* pReply) |
| 450 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 451 | static JDWP::JdwpError GetThreadGroupChildren(JDWP::ObjectId thread_group_id, |
| 452 | JDWP::ExpandBuf* pReply) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 453 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 454 | static JDWP::ObjectId GetSystemThreadGroupId() |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 455 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 456 | |
Jeff Hao | 920af3e | 2013-08-28 15:46:38 -0700 | [diff] [blame] | 457 | static JDWP::JdwpThreadStatus ToJdwpThreadStatus(ThreadState state); |
Sebastien Hertz | 52d131d | 2014-03-13 16:17:40 +0100 | [diff] [blame] | 458 | static JDWP::JdwpError GetThreadStatus(JDWP::ObjectId thread_id, |
| 459 | JDWP::JdwpThreadStatus* pThreadStatus, |
| 460 | JDWP::JdwpSuspendStatus* pSuspendStatus) |
| 461 | LOCKS_EXCLUDED(Locks::thread_list_lock_); |
| 462 | static JDWP::JdwpError GetThreadDebugSuspendCount(JDWP::ObjectId thread_id, |
| 463 | JDWP::ExpandBuf* pReply) |
| 464 | LOCKS_EXCLUDED(Locks::thread_list_lock_, |
| 465 | Locks::thread_suspend_count_lock_); |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 466 | // static void WaitForSuspend(JDWP::ObjectId thread_id); |
Elliott Hughes | caf7654 | 2012-06-28 16:08:22 -0700 | [diff] [blame] | 467 | |
Elliott Hughes | 026b146 | 2012-06-28 20:43:49 -0700 | [diff] [blame] | 468 | // 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] | 469 | // returns all threads. |
Sebastien Hertz | a06430c | 2014-09-15 19:21:30 +0200 | [diff] [blame] | 470 | static void GetThreads(mirror::Object* thread_group, std::vector<JDWP::ObjectId>* thread_ids) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 471 | LOCKS_EXCLUDED(Locks::thread_list_lock_) |
| 472 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | caf7654 | 2012-06-28 16:08:22 -0700 | [diff] [blame] | 473 | |
Ian Rogers | c0542af | 2014-09-03 16:16:56 -0700 | [diff] [blame] | 474 | static JDWP::JdwpError GetThreadFrameCount(JDWP::ObjectId thread_id, size_t* result) |
Sebastien Hertz | 52d131d | 2014-03-13 16:17:40 +0100 | [diff] [blame] | 475 | LOCKS_EXCLUDED(Locks::thread_list_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 476 | static JDWP::JdwpError GetThreadFrames(JDWP::ObjectId thread_id, size_t start_frame, |
| 477 | size_t frame_count, JDWP::ExpandBuf* buf) |
Sebastien Hertz | 52d131d | 2014-03-13 16:17:40 +0100 | [diff] [blame] | 478 | LOCKS_EXCLUDED(Locks::thread_list_lock_) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 479 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 480 | |
Sebastien Hertz | 6995c60 | 2014-09-09 12:10:13 +0200 | [diff] [blame] | 481 | static JDWP::ObjectId GetThreadSelfId() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 482 | static JDWP::ObjectId GetThreadId(Thread* thread) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 483 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 484 | static void SuspendVM() |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 485 | LOCKS_EXCLUDED(Locks::thread_list_lock_, |
| 486 | Locks::thread_suspend_count_lock_); |
Sebastien Hertz | 253fa55 | 2014-10-14 17:27:15 +0200 | [diff] [blame] | 487 | static void ResumeVM() |
| 488 | LOCKS_EXCLUDED(Locks::thread_list_lock_, |
| 489 | Locks::thread_suspend_count_lock_); |
Elliott Hughes | 88d6309 | 2013-01-09 09:55:54 -0800 | [diff] [blame] | 490 | static JDWP::JdwpError SuspendThread(JDWP::ObjectId thread_id, bool request_suspension = true) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 491 | LOCKS_EXCLUDED(Locks::mutator_lock_, |
| 492 | Locks::thread_list_lock_, |
| 493 | Locks::thread_suspend_count_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 494 | |
Elliott Hughes | 88d6309 | 2013-01-09 09:55:54 -0800 | [diff] [blame] | 495 | static void ResumeThread(JDWP::ObjectId thread_id) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 496 | LOCKS_EXCLUDED(Locks::thread_list_lock_, |
| 497 | Locks::thread_suspend_count_lock_) |
| 498 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 499 | static void SuspendSelf(); |
| 500 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 501 | static JDWP::JdwpError GetThisObject(JDWP::ObjectId thread_id, JDWP::FrameId frame_id, |
| 502 | JDWP::ObjectId* result) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 503 | LOCKS_EXCLUDED(Locks::thread_list_lock_, |
| 504 | Locks::thread_suspend_count_lock_) |
| 505 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Sebastien Hertz | 8009f39 | 2014-09-01 17:07:11 +0200 | [diff] [blame] | 506 | static JDWP::JdwpError GetLocalValues(JDWP::Request* request, JDWP::ExpandBuf* pReply) |
Sebastien Hertz | 52d131d | 2014-03-13 16:17:40 +0100 | [diff] [blame] | 507 | LOCKS_EXCLUDED(Locks::thread_list_lock_) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 508 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Sebastien Hertz | 8009f39 | 2014-09-01 17:07:11 +0200 | [diff] [blame] | 509 | static JDWP::JdwpError SetLocalValues(JDWP::Request* request) |
Sebastien Hertz | 52d131d | 2014-03-13 16:17:40 +0100 | [diff] [blame] | 510 | LOCKS_EXCLUDED(Locks::thread_list_lock_) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 511 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 512 | |
Sebastien Hertz | 52d131d | 2014-03-13 16:17:40 +0100 | [diff] [blame] | 513 | static JDWP::JdwpError Interrupt(JDWP::ObjectId thread_id) |
| 514 | LOCKS_EXCLUDED(Locks::thread_list_lock_); |
Elliott Hughes | f950170 | 2013-01-11 11:22:27 -0800 | [diff] [blame] | 515 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 516 | /* |
| 517 | * Debugger notification |
| 518 | */ |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 519 | enum EventFlag { |
Elliott Hughes | 8696433 | 2012-02-15 19:37:42 -0800 | [diff] [blame] | 520 | kBreakpoint = 0x01, |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 521 | kSingleStep = 0x02, |
| 522 | kMethodEntry = 0x04, |
| 523 | kMethodExit = 0x08, |
| 524 | }; |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 525 | static void PostFieldAccessEvent(ArtMethod* m, int dex_pc, mirror::Object* this_object, |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 526 | ArtField* f) |
Sebastien Hertz | 3f52eaf | 2014-04-04 17:50:18 +0200 | [diff] [blame] | 527 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 528 | static void PostFieldModificationEvent(ArtMethod* m, int dex_pc, |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 529 | mirror::Object* this_object, ArtField* f, |
Sebastien Hertz | 3f52eaf | 2014-04-04 17:50:18 +0200 | [diff] [blame] | 530 | const JValue* field_value) |
| 531 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Nicolas Geoffray | 14691c5 | 2015-03-05 10:40:17 +0000 | [diff] [blame] | 532 | static void PostException(mirror::Throwable* exception) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 533 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 534 | static void PostThreadStart(Thread* t) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 535 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 536 | static void PostThreadDeath(Thread* t) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 537 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 538 | static void PostClassPrepare(mirror::Class* c) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 539 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 540 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 541 | static void UpdateDebugger(Thread* thread, mirror::Object* this_object, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 542 | ArtMethod* method, uint32_t new_dex_pc, |
Sebastien Hertz | 8379b22 | 2014-02-24 17:38:15 +0100 | [diff] [blame] | 543 | int event_flags, const JValue* return_value) |
jeffhao | 09bfc6a | 2012-12-11 18:11:43 -0800 | [diff] [blame] | 544 | LOCKS_EXCLUDED(Locks::breakpoint_lock_) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 545 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 91bf6cd | 2012-02-14 17:27:48 -0800 | [diff] [blame] | 546 | |
Sebastien Hertz | f392879 | 2014-11-17 19:00:37 +0100 | [diff] [blame] | 547 | // Indicates whether we need deoptimization for debugging. |
| 548 | static bool RequiresDeoptimization(); |
| 549 | |
Sebastien Hertz | 4d25df3 | 2014-03-21 17:44:46 +0100 | [diff] [blame] | 550 | // Records deoptimization request in the queue. |
| 551 | static void RequestDeoptimization(const DeoptimizationRequest& req) |
Brian Carlstrom | 306db81 | 2014-09-05 13:01:41 -0700 | [diff] [blame] | 552 | LOCKS_EXCLUDED(Locks::deoptimization_lock_) |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 553 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 554 | |
Sebastien Hertz | 4d25df3 | 2014-03-21 17:44:46 +0100 | [diff] [blame] | 555 | // Manage deoptimization after updating JDWP events list. Suspends all threads, processes each |
| 556 | // request and finally resumes all threads. |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 557 | static void ManageDeoptimization() |
Brian Carlstrom | 306db81 | 2014-09-05 13:01:41 -0700 | [diff] [blame] | 558 | LOCKS_EXCLUDED(Locks::deoptimization_lock_) |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 559 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 560 | |
| 561 | // Breakpoints. |
Sebastien Hertz | 4d25df3 | 2014-03-21 17:44:46 +0100 | [diff] [blame] | 562 | static void WatchLocation(const JDWP::JdwpLocation* pLoc, DeoptimizationRequest* req) |
| 563 | LOCKS_EXCLUDED(Locks::breakpoint_lock_) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 564 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Sebastien Hertz | 4d25df3 | 2014-03-21 17:44:46 +0100 | [diff] [blame] | 565 | static void UnwatchLocation(const JDWP::JdwpLocation* pLoc, DeoptimizationRequest* req) |
| 566 | LOCKS_EXCLUDED(Locks::breakpoint_lock_) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 567 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 568 | |
Daniel Mihalyi | eb07669 | 2014-08-22 17:33:31 +0200 | [diff] [blame] | 569 | /* |
| 570 | * Forced interpreter checkers for single-step and continue support. |
| 571 | */ |
| 572 | |
| 573 | // Indicates whether we need to force the use of interpreter to invoke a method. |
| 574 | // This allows to single-step or continue into the called method. |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 575 | static bool IsForcedInterpreterNeededForCalling(Thread* thread, ArtMethod* m) |
Daniel Mihalyi | eb07669 | 2014-08-22 17:33:31 +0200 | [diff] [blame] | 576 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 577 | if (!IsDebuggerActive()) { |
| 578 | return false; |
| 579 | } |
| 580 | return IsForcedInterpreterNeededForCallingImpl(thread, m); |
| 581 | } |
| 582 | |
| 583 | // Indicates whether we need to force the use of interpreter entrypoint when calling a |
| 584 | // method through the resolution trampoline. This allows to single-step or continue into |
| 585 | // the called method. |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 586 | static bool IsForcedInterpreterNeededForResolution(Thread* thread, ArtMethod* m) |
Daniel Mihalyi | eb07669 | 2014-08-22 17:33:31 +0200 | [diff] [blame] | 587 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 588 | if (!IsDebuggerActive()) { |
| 589 | return false; |
| 590 | } |
| 591 | return IsForcedInterpreterNeededForResolutionImpl(thread, m); |
| 592 | } |
| 593 | |
| 594 | // Indicates whether we need to force the use of instrumentation entrypoint when calling |
| 595 | // a method through the resolution trampoline. This allows to deoptimize the stack for |
| 596 | // debugging when we returned from the called method. |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 597 | static bool IsForcedInstrumentationNeededForResolution(Thread* thread, ArtMethod* m) |
Daniel Mihalyi | eb07669 | 2014-08-22 17:33:31 +0200 | [diff] [blame] | 598 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 599 | if (!IsDebuggerActive()) { |
| 600 | return false; |
| 601 | } |
| 602 | return IsForcedInstrumentationNeededForResolutionImpl(thread, m); |
| 603 | } |
| 604 | |
| 605 | // Indicates whether we need to force the use of interpreter when returning from the |
| 606 | // interpreter into the runtime. This allows to deoptimize the stack and continue |
| 607 | // execution with interpreter for debugging. |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 608 | static bool IsForcedInterpreterNeededForUpcall(Thread* thread, ArtMethod* m) |
Daniel Mihalyi | eb07669 | 2014-08-22 17:33:31 +0200 | [diff] [blame] | 609 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 610 | if (!IsDebuggerActive()) { |
| 611 | return false; |
| 612 | } |
| 613 | return IsForcedInterpreterNeededForUpcallImpl(thread, m); |
| 614 | } |
| 615 | |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 616 | // Single-stepping. |
Elliott Hughes | 88d6309 | 2013-01-09 09:55:54 -0800 | [diff] [blame] | 617 | static JDWP::JdwpError ConfigureStep(JDWP::ObjectId thread_id, JDWP::JdwpStepSize size, |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 618 | JDWP::JdwpStepDepth depth) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 619 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Sebastien Hertz | 61b7f1b | 2013-11-15 15:59:30 +0100 | [diff] [blame] | 620 | static void UnconfigureStep(JDWP::ObjectId thread_id) |
Sebastien Hertz | 52d131d | 2014-03-13 16:17:40 +0100 | [diff] [blame] | 621 | LOCKS_EXCLUDED(Locks::thread_list_lock_) |
Sebastien Hertz | 61b7f1b | 2013-11-15 15:59:30 +0100 | [diff] [blame] | 622 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 623 | |
Sebastien Hertz | cbc5064 | 2015-06-01 17:33:12 +0200 | [diff] [blame^] | 624 | /* |
| 625 | * Invoke support |
| 626 | */ |
| 627 | |
| 628 | // Called by the JDWP thread to prepare invocation in the event thread (suspended on an event). |
| 629 | // If the information sent by the debugger is incorrect, it will send a reply with the |
| 630 | // appropriate error code. Otherwise, it will attach a DebugInvokeReq object to the event thread |
| 631 | // and resume it (and possibly other threads depending on the invoke options). |
| 632 | // Unlike other commands, the JDWP thread will not send the reply to the debugger (see |
| 633 | // JdwpState::ProcessRequest). The reply will be sent by the event thread itself after method |
| 634 | // invocation completes (see FinishInvokeMethod). This is required to allow the JDWP thread to |
| 635 | // process incoming commands from the debugger while the invocation is still in progress in the |
| 636 | // event thread, especially if it gets suspended by a debug event occurring in another thread. |
| 637 | static JDWP::JdwpError PrepareInvokeMethod(uint32_t request_id, JDWP::ObjectId thread_id, |
| 638 | JDWP::ObjectId object_id, JDWP::RefTypeId class_id, |
| 639 | JDWP::MethodId method_id, uint32_t arg_count, |
| 640 | uint64_t arg_values[], JDWP::JdwpTag* arg_types, |
| 641 | uint32_t options) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 642 | LOCKS_EXCLUDED(Locks::thread_list_lock_, |
| 643 | Locks::thread_suspend_count_lock_) |
| 644 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Sebastien Hertz | cbc5064 | 2015-06-01 17:33:12 +0200 | [diff] [blame^] | 645 | |
| 646 | // Called by the event thread to execute a method prepared by the JDWP thread in the given |
| 647 | // DebugInvokeReq object. Once the invocation completes, the event thread attaches a reply |
| 648 | // to that DebugInvokeReq object so it can be sent to the debugger only when the event thread |
| 649 | // is ready to suspend (see FinishInvokeMethod). |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 650 | static void ExecuteMethod(DebugInvokeReq* pReq); |
| 651 | |
Sebastien Hertz | cbc5064 | 2015-06-01 17:33:12 +0200 | [diff] [blame^] | 652 | // Called by the event thread to send the reply of the invoke (created in ExecuteMethod) |
| 653 | // before suspending itself. This is to ensure the thread is ready to suspend before the |
| 654 | // debugger receives the reply. |
| 655 | static void FinishInvokeMethod(DebugInvokeReq* pReq); |
| 656 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 657 | /* |
| 658 | * DDM support. |
| 659 | */ |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 660 | static void DdmSendThreadNotification(Thread* t, uint32_t type) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 661 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Sebastien Hertz | 52d131d | 2014-03-13 16:17:40 +0100 | [diff] [blame] | 662 | static void DdmSetThreadNotification(bool enable) |
| 663 | LOCKS_EXCLUDED(Locks::thread_list_lock_); |
Ian Rogers | c0542af | 2014-09-03 16:16:56 -0700 | [diff] [blame] | 664 | static bool DdmHandlePacket(JDWP::Request* request, uint8_t** pReplyBuf, int* pReplyLen); |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 665 | static void DdmConnected() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 666 | static void DdmDisconnected() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 667 | static void DdmSendChunk(uint32_t type, const std::vector<uint8_t>& bytes) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 668 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 669 | 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] | 670 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 671 | static void DdmSendChunkV(uint32_t type, const iovec* iov, int iov_count) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 672 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 767a147 | 2011-10-26 18:49:02 -0700 | [diff] [blame] | 673 | |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 674 | static void VisitRoots(RootVisitor* visitor) |
Mathieu Chartier | 3b05e9b | 2014-03-25 09:29:43 -0700 | [diff] [blame] | 675 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 676 | |
Elliott Hughes | 545a064 | 2011-11-08 19:10:03 -0800 | [diff] [blame] | 677 | /* |
| 678 | * Recent allocation tracking support. |
| 679 | */ |
Ian Rogers | 844506b | 2014-09-12 19:59:33 -0700 | [diff] [blame] | 680 | static void RecordAllocation(Thread* self, mirror::Class* type, size_t byte_count) |
Brian Carlstrom | 306db81 | 2014-09-05 13:01:41 -0700 | [diff] [blame] | 681 | LOCKS_EXCLUDED(Locks::alloc_tracker_lock_) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 682 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | 306db81 | 2014-09-05 13:01:41 -0700 | [diff] [blame] | 683 | static void SetAllocTrackingEnabled(bool enabled) LOCKS_EXCLUDED(Locks::alloc_tracker_lock_); |
Ian Rogers | 719d1a3 | 2014-03-06 12:13:39 -0800 | [diff] [blame] | 684 | static bool IsAllocTrackingEnabled() { |
| 685 | return recent_allocation_records_ != nullptr; |
| 686 | } |
Sebastien Hertz | 52d131d | 2014-03-13 16:17:40 +0100 | [diff] [blame] | 687 | static jbyteArray GetRecentAllocations() |
Brian Carlstrom | 306db81 | 2014-09-05 13:01:41 -0700 | [diff] [blame] | 688 | LOCKS_EXCLUDED(Locks::alloc_tracker_lock_) |
Sebastien Hertz | 52d131d | 2014-03-13 16:17:40 +0100 | [diff] [blame] | 689 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | 306db81 | 2014-09-05 13:01:41 -0700 | [diff] [blame] | 690 | static size_t HeadIndex() EXCLUSIVE_LOCKS_REQUIRED(Locks::alloc_tracker_lock_); |
| 691 | static void DumpRecentAllocations() LOCKS_EXCLUDED(Locks::alloc_tracker_lock_); |
Elliott Hughes | 545a064 | 2011-11-08 19:10:03 -0800 | [diff] [blame] | 692 | |
Elliott Hughes | 767a147 | 2011-10-26 18:49:02 -0700 | [diff] [blame] | 693 | enum HpifWhen { |
| 694 | HPIF_WHEN_NEVER = 0, |
| 695 | HPIF_WHEN_NOW = 1, |
| 696 | HPIF_WHEN_NEXT_GC = 2, |
| 697 | HPIF_WHEN_EVERY_GC = 3 |
| 698 | }; |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 699 | static int DdmHandleHpifChunk(HpifWhen when) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 700 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 767a147 | 2011-10-26 18:49:02 -0700 | [diff] [blame] | 701 | |
| 702 | enum HpsgWhen { |
| 703 | HPSG_WHEN_NEVER = 0, |
| 704 | HPSG_WHEN_EVERY_GC = 1, |
| 705 | }; |
| 706 | enum HpsgWhat { |
| 707 | HPSG_WHAT_MERGED_OBJECTS = 0, |
| 708 | HPSG_WHAT_DISTINCT_OBJECTS = 1, |
| 709 | }; |
| 710 | static bool DdmHandleHpsgNhsgChunk(HpsgWhen when, HpsgWhat what, bool native); |
| 711 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 712 | static void DdmSendHeapInfo(HpifWhen reason) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 713 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 714 | static void DdmSendHeapSegments(bool native) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 715 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 545a064 | 2011-11-08 19:10:03 -0800 | [diff] [blame] | 716 | |
Sebastien Hertz | 6995c60 | 2014-09-09 12:10:13 +0200 | [diff] [blame] | 717 | static ObjectRegistry* GetObjectRegistry() { |
| 718 | return gRegistry; |
| 719 | } |
| 720 | |
| 721 | static JDWP::JdwpTag TagFromObject(const ScopedObjectAccessUnchecked& soa, mirror::Object* o) |
| 722 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 723 | |
| 724 | static JDWP::JdwpTypeTag GetTypeTag(mirror::Class* klass) |
| 725 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 726 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 727 | static JDWP::FieldId ToFieldId(const ArtField* f) |
Sebastien Hertz | 6995c60 | 2014-09-09 12:10:13 +0200 | [diff] [blame] | 728 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 729 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 730 | static void SetJdwpLocation(JDWP::JdwpLocation* location, ArtMethod* m, uint32_t dex_pc) |
Sebastien Hertz | 6995c60 | 2014-09-09 12:10:13 +0200 | [diff] [blame] | 731 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 732 | |
Mathieu Chartier | ad466ad | 2015-01-08 16:28:08 -0800 | [diff] [blame] | 733 | static JDWP::JdwpState* GetJdwpState(); |
| 734 | |
Sebastien Hertz | 9d6bf69 | 2015-04-10 12:12:33 +0200 | [diff] [blame] | 735 | static uint32_t GetInstrumentationEvents() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 736 | return instrumentation_events_; |
| 737 | } |
| 738 | |
Elliott Hughes | 545a064 | 2011-11-08 19:10:03 -0800 | [diff] [blame] | 739 | private: |
Sebastien Hertz | cbc5064 | 2015-06-01 17:33:12 +0200 | [diff] [blame^] | 740 | static void ExecuteMethodWithoutPendingException(ScopedObjectAccess& soa, DebugInvokeReq* pReq) |
| 741 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 742 | |
| 743 | static void BuildInvokeReply(JDWP::ExpandBuf* pReply, uint32_t request_id, |
| 744 | JDWP::JdwpTag result_tag, uint64_t result_value, |
| 745 | JDWP::ObjectId exception) |
| 746 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 747 | |
Sebastien Hertz | 8009f39 | 2014-09-01 17:07:11 +0200 | [diff] [blame] | 748 | static JDWP::JdwpError GetLocalValue(const StackVisitor& visitor, |
| 749 | ScopedObjectAccessUnchecked& soa, int slot, |
| 750 | JDWP::JdwpTag tag, uint8_t* buf, size_t width) |
| 751 | LOCKS_EXCLUDED(Locks::thread_list_lock_) |
| 752 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 753 | static JDWP::JdwpError SetLocalValue(StackVisitor& visitor, int slot, JDWP::JdwpTag tag, |
| 754 | uint64_t value, size_t width) |
| 755 | LOCKS_EXCLUDED(Locks::thread_list_lock_) |
| 756 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 757 | |
Brian Carlstrom | 2d88862 | 2013-07-18 17:02:00 -0700 | [diff] [blame] | 758 | static void DdmBroadcast(bool connect) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 759 | static void PostThreadStartOrStop(Thread*, uint32_t) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 760 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | a215526 | 2011-11-16 16:26:58 -0800 | [diff] [blame] | 761 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 762 | static void PostLocationEvent(ArtMethod* method, int pcOffset, |
Sebastien Hertz | 8379b22 | 2014-02-24 17:38:15 +0100 | [diff] [blame] | 763 | mirror::Object* thisPtr, int eventFlags, |
| 764 | const JValue* return_value) |
| 765 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 766 | |
Sebastien Hertz | 4d25df3 | 2014-03-21 17:44:46 +0100 | [diff] [blame] | 767 | static void ProcessDeoptimizationRequest(const DeoptimizationRequest& request) |
| 768 | EXCLUSIVE_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 769 | |
Sebastien Hertz | 7ec2f1c | 2014-03-27 20:06:47 +0100 | [diff] [blame] | 770 | static void RequestDeoptimizationLocked(const DeoptimizationRequest& req) |
Brian Carlstrom | 306db81 | 2014-09-05 13:01:41 -0700 | [diff] [blame] | 771 | EXCLUSIVE_LOCKS_REQUIRED(Locks::deoptimization_lock_) |
Sebastien Hertz | 7ec2f1c | 2014-03-27 20:06:47 +0100 | [diff] [blame] | 772 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 773 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 774 | static bool IsForcedInterpreterNeededForCallingImpl(Thread* thread, ArtMethod* m) |
Daniel Mihalyi | eb07669 | 2014-08-22 17:33:31 +0200 | [diff] [blame] | 775 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 776 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 777 | static bool IsForcedInterpreterNeededForResolutionImpl(Thread* thread, ArtMethod* m) |
Daniel Mihalyi | eb07669 | 2014-08-22 17:33:31 +0200 | [diff] [blame] | 778 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 779 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 780 | static bool IsForcedInstrumentationNeededForResolutionImpl(Thread* thread, ArtMethod* m) |
Daniel Mihalyi | eb07669 | 2014-08-22 17:33:31 +0200 | [diff] [blame] | 781 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 782 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 783 | static bool IsForcedInterpreterNeededForUpcallImpl(Thread* thread, ArtMethod* m) |
Daniel Mihalyi | eb07669 | 2014-08-22 17:33:31 +0200 | [diff] [blame] | 784 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 785 | |
Brian Carlstrom | 306db81 | 2014-09-05 13:01:41 -0700 | [diff] [blame] | 786 | static AllocRecord* recent_allocation_records_ PT_GUARDED_BY(Locks::alloc_tracker_lock_); |
| 787 | static size_t alloc_record_max_ GUARDED_BY(Locks::alloc_tracker_lock_); |
| 788 | static size_t alloc_record_head_ GUARDED_BY(Locks::alloc_tracker_lock_); |
| 789 | static size_t alloc_record_count_ GUARDED_BY(Locks::alloc_tracker_lock_); |
Sebastien Hertz | 4d25df3 | 2014-03-21 17:44:46 +0100 | [diff] [blame] | 790 | |
Daniel Mihalyi | eb07669 | 2014-08-22 17:33:31 +0200 | [diff] [blame] | 791 | // Indicates whether the debugger is making requests. |
| 792 | static bool gDebuggerActive; |
| 793 | |
Sebastien Hertz | 4e5b208 | 2015-03-24 19:03:40 +0100 | [diff] [blame] | 794 | // Indicates whether we should drop the JDWP connection because the runtime stops or the |
| 795 | // debugger called VirtualMachine.Dispose. |
| 796 | static bool gDisposed; |
| 797 | |
Daniel Mihalyi | eb07669 | 2014-08-22 17:33:31 +0200 | [diff] [blame] | 798 | // The registry mapping objects to JDWP ids. |
Sebastien Hertz | 6995c60 | 2014-09-09 12:10:13 +0200 | [diff] [blame] | 799 | static ObjectRegistry* gRegistry; |
| 800 | |
Sebastien Hertz | 4d25df3 | 2014-03-21 17:44:46 +0100 | [diff] [blame] | 801 | // Deoptimization requests to be processed each time the event list is updated. This is used when |
| 802 | // registering and unregistering events so we do not deoptimize while holding the event list |
| 803 | // lock. |
Sebastien Hertz | 42cd43f | 2014-05-13 14:15:41 +0200 | [diff] [blame] | 804 | // TODO rename to instrumentation_requests. |
Brian Carlstrom | 306db81 | 2014-09-05 13:01:41 -0700 | [diff] [blame] | 805 | static std::vector<DeoptimizationRequest> deoptimization_requests_ GUARDED_BY(Locks::deoptimization_lock_); |
Sebastien Hertz | 4d25df3 | 2014-03-21 17:44:46 +0100 | [diff] [blame] | 806 | |
| 807 | // Count the number of events requiring full deoptimization. When the counter is > 0, everything |
| 808 | // is deoptimized, otherwise everything is undeoptimized. |
| 809 | // Note: we fully deoptimize on the first event only (when the counter is set to 1). We fully |
| 810 | // undeoptimize when the last event is unregistered (when the counter is set to 0). |
Brian Carlstrom | 306db81 | 2014-09-05 13:01:41 -0700 | [diff] [blame] | 811 | static size_t full_deoptimization_event_count_ GUARDED_BY(Locks::deoptimization_lock_); |
Sebastien Hertz | 4d25df3 | 2014-03-21 17:44:46 +0100 | [diff] [blame] | 812 | |
Sebastien Hertz | 42cd43f | 2014-05-13 14:15:41 +0200 | [diff] [blame] | 813 | static size_t* GetReferenceCounterForEvent(uint32_t instrumentation_event); |
| 814 | |
Mathieu Chartier | 4345c46 | 2014-06-27 10:20:14 -0700 | [diff] [blame] | 815 | // Weak global type cache, TODO improve this. |
Brian Carlstrom | 306db81 | 2014-09-05 13:01:41 -0700 | [diff] [blame] | 816 | static TypeCache type_cache_ GUARDED_BY(Locks::alloc_tracker_lock_); |
Mathieu Chartier | 4345c46 | 2014-06-27 10:20:14 -0700 | [diff] [blame] | 817 | |
Sebastien Hertz | 42cd43f | 2014-05-13 14:15:41 +0200 | [diff] [blame] | 818 | // Instrumentation event reference counters. |
| 819 | // TODO we could use an array instead of having all these dedicated counters. Instrumentation |
| 820 | // events are bits of a mask so we could convert them to array index. |
Brian Carlstrom | 306db81 | 2014-09-05 13:01:41 -0700 | [diff] [blame] | 821 | static size_t dex_pc_change_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_); |
| 822 | static size_t method_enter_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_); |
| 823 | static size_t method_exit_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_); |
| 824 | static size_t field_read_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_); |
| 825 | static size_t field_write_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_); |
| 826 | static size_t exception_catch_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_); |
Sebastien Hertz | 42cd43f | 2014-05-13 14:15:41 +0200 | [diff] [blame] | 827 | static uint32_t instrumentation_events_ GUARDED_BY(Locks::mutator_lock_); |
| 828 | |
Brian Carlstrom | 306db81 | 2014-09-05 13:01:41 -0700 | [diff] [blame] | 829 | friend class AllocRecord; // For type_cache_ with proper annotalysis. |
Ian Rogers | 719d1a3 | 2014-03-06 12:13:39 -0800 | [diff] [blame] | 830 | DISALLOW_COPY_AND_ASSIGN(Dbg); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 831 | }; |
| 832 | |
| 833 | #define CHUNK_TYPE(_name) \ |
Elliott Hughes | 8218847 | 2011-11-07 18:11:48 -0800 | [diff] [blame] | 834 | 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] | 835 | |
| 836 | } // namespace art |
| 837 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 838 | #endif // ART_RUNTIME_DEBUGGER_H_ |