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