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 | */ |
| 21 | #ifndef ART_DEBUGGER_H_ |
| 22 | #define ART_DEBUGGER_H_ |
| 23 | |
| 24 | #include <pthread.h> |
| 25 | |
Elliott Hughes | 3bb8156 | 2011-10-21 18:52:59 -0700 | [diff] [blame] | 26 | #include <string> |
| 27 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 28 | #include "jdwp/jdwp.h" |
Elliott Hughes | 3bb8156 | 2011-10-21 18:52:59 -0700 | [diff] [blame] | 29 | #include "object.h" |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 30 | |
| 31 | namespace art { |
| 32 | |
Elliott Hughes | 545a064 | 2011-11-08 19:10:03 -0800 | [diff] [blame] | 33 | struct AllocRecord; |
Ian Rogers | 1b09b09 | 2012-08-20 15:35:52 -0700 | [diff] [blame] | 34 | class Thread; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 35 | |
| 36 | /* |
| 37 | * Invoke-during-breakpoint support. |
| 38 | */ |
| 39 | struct DebugInvokeReq { |
Elliott Hughes | 7b3cdfc | 2011-12-08 21:28:17 -0800 | [diff] [blame] | 40 | DebugInvokeReq() |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 41 | : ready(false), invoke_needed_(false), |
| 42 | receiver_(NULL), thread_(NULL), class_(NULL), method_(NULL), |
| 43 | arg_count_(0), arg_values_(NULL), options_(0), error(JDWP::ERR_NONE), |
| 44 | result_tag(JDWP::JT_VOID), exception(0), |
Elliott Hughes | 7b3cdfc | 2011-12-08 21:28:17 -0800 | [diff] [blame] | 45 | lock_("a DebugInvokeReq lock"), |
Ian Rogers | c604d73 | 2012-10-14 16:09:54 -0700 | [diff] [blame] | 46 | cond_("a DebugInvokeReq condition variable", lock_) { |
Elliott Hughes | 475fc23 | 2011-10-25 15:00:35 -0700 | [diff] [blame] | 47 | } |
| 48 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 49 | /* boolean; only set when we're in the tail end of an event handler */ |
| 50 | bool ready; |
| 51 | |
| 52 | /* boolean; set if the JDWP thread wants this thread to do work */ |
Elliott Hughes | d07986f | 2011-12-06 18:27:45 -0800 | [diff] [blame] | 53 | bool invoke_needed_; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 54 | |
| 55 | /* request */ |
Elliott Hughes | d07986f | 2011-12-06 18:27:45 -0800 | [diff] [blame] | 56 | Object* receiver_; /* not used for ClassType.InvokeMethod */ |
| 57 | Object* thread_; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 58 | Class* class_; |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 59 | AbstractMethod* method_; |
Elliott Hughes | 45651fd | 2012-02-21 15:48:20 -0800 | [diff] [blame] | 60 | uint32_t arg_count_; |
| 61 | uint64_t* arg_values_; /* will be NULL if arg_count_ == 0 */ |
Elliott Hughes | d07986f | 2011-12-06 18:27:45 -0800 | [diff] [blame] | 62 | uint32_t options_; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 63 | |
| 64 | /* result */ |
Elliott Hughes | 475fc23 | 2011-10-25 15:00:35 -0700 | [diff] [blame] | 65 | JDWP::JdwpError error; |
Elliott Hughes | d07986f | 2011-12-06 18:27:45 -0800 | [diff] [blame] | 66 | JDWP::JdwpTag result_tag; |
Elliott Hughes | 475fc23 | 2011-10-25 15:00:35 -0700 | [diff] [blame] | 67 | JValue result_value; |
| 68 | JDWP::ObjectId exception; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 69 | |
| 70 | /* condition variable to wait on while the method executes */ |
Ian Rogers | c604d73 | 2012-10-14 16:09:54 -0700 | [diff] [blame] | 71 | Mutex lock_ DEFAULT_MUTEX_ACQUIRED_AFTER; |
| 72 | ConditionVariable cond_ GUARDED_BY(lock_); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 73 | }; |
| 74 | |
| 75 | class Dbg { |
Elliott Hughes | ff17f1f | 2012-01-24 18:12:29 -0800 | [diff] [blame] | 76 | public: |
Elliott Hughes | 3bb8156 | 2011-10-21 18:52:59 -0700 | [diff] [blame] | 77 | static bool ParseJdwpOptions(const std::string& options); |
Elliott Hughes | 4ffd313 | 2011-10-24 12:06:42 -0700 | [diff] [blame] | 78 | static void SetJdwpAllowed(bool allowed); |
| 79 | |
Elliott Hughes | d1cc836 | 2011-10-24 16:58:50 -0700 | [diff] [blame] | 80 | static void StartJdwp(); |
| 81 | static void StopJdwp(); |
| 82 | |
Elliott Hughes | 767a147 | 2011-10-26 18:49:02 -0700 | [diff] [blame] | 83 | // Invoked by the GC in case we need to keep DDMS informed. |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 84 | static void GcDidFinish() LOCKS_EXCLUDED(Locks::mutator_lock_); |
Elliott Hughes | 767a147 | 2011-10-26 18:49:02 -0700 | [diff] [blame] | 85 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 86 | // Return the DebugInvokeReq for the current thread. |
| 87 | static DebugInvokeReq* GetInvokeReq(); |
| 88 | |
Elliott Hughes | 475fc23 | 2011-10-25 15:00:35 -0700 | [diff] [blame] | 89 | static Thread* GetDebugThread(); |
| 90 | static void ClearWaitForEventThread(); |
| 91 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 92 | /* |
| 93 | * Enable/disable breakpoints and step modes. Used to provide a heads-up |
| 94 | * when the debugger attaches. |
| 95 | */ |
| 96 | static void Connected(); |
Elliott Hughes | a215526 | 2011-11-16 16:26:58 -0800 | [diff] [blame] | 97 | static void GoActive(); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 98 | static void Disconnected(); |
Elliott Hughes | 8696433 | 2012-02-15 19:37:42 -0800 | [diff] [blame] | 99 | static void Disposed(); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 100 | |
Elliott Hughes | c0f0933 | 2012-03-26 13:27:06 -0700 | [diff] [blame] | 101 | // Returns true if we're actually debugging with a real debugger, false if it's |
| 102 | // just DDMS (or nothing at all). |
| 103 | static bool IsDebuggerActive(); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 104 | |
Elliott Hughes | c0f0933 | 2012-03-26 13:27:06 -0700 | [diff] [blame] | 105 | // Returns true if we had -Xrunjdwp or -agentlib:jdwp= on the command line. |
| 106 | static bool IsJdwpConfigured(); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 107 | |
Elliott Hughes | 8696433 | 2012-02-15 19:37:42 -0800 | [diff] [blame] | 108 | static bool IsDisposed(); |
| 109 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 110 | /* |
| 111 | * Time, in milliseconds, since the last debugger activity. Does not |
| 112 | * include DDMS activity. Returns -1 if there has been no activity. |
| 113 | * Returns 0 if we're in the middle of handling a debugger request. |
| 114 | */ |
| 115 | static int64_t LastDebuggerActivity(); |
| 116 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 117 | static void UndoDebuggerSuspensions(); |
| 118 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 119 | static void Exit(int status); |
| 120 | |
Elliott Hughes | bfe487b | 2011-10-26 15:48:55 -0700 | [diff] [blame] | 121 | static void VisitRoots(Heap::RootVisitor* visitor, void* arg); |
| 122 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 123 | /* |
| 124 | * Class, Object, Array |
| 125 | */ |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 126 | static std::string GetClassName(JDWP::RefTypeId id) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 127 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 128 | static JDWP::JdwpError GetClassObject(JDWP::RefTypeId id, JDWP::ObjectId& classObjectId) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 129 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 130 | static JDWP::JdwpError GetSuperclass(JDWP::RefTypeId id, JDWP::RefTypeId& superclassId) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 131 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 132 | static JDWP::JdwpError GetClassLoader(JDWP::RefTypeId id, JDWP::ExpandBuf* pReply) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 133 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 134 | static JDWP::JdwpError GetModifiers(JDWP::RefTypeId id, JDWP::ExpandBuf* pReply) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 135 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 136 | static JDWP::JdwpError GetReflectedType(JDWP::RefTypeId classId, JDWP::ExpandBuf* pReply) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 137 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 138 | static void GetClassList(std::vector<JDWP::RefTypeId>& classes) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 139 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 140 | static JDWP::JdwpError GetClassInfo(JDWP::RefTypeId classId, JDWP::JdwpTypeTag* pTypeTag, |
| 141 | uint32_t* pStatus, std::string* pDescriptor) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 142 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 143 | static void FindLoadedClassBySignature(const char* descriptor, std::vector<JDWP::RefTypeId>& ids) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 144 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 2435a57 | 2012-02-17 16:07:41 -0800 | [diff] [blame] | 145 | static JDWP::JdwpError GetReferenceType(JDWP::ObjectId objectId, JDWP::ExpandBuf* pReply); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 146 | static JDWP::JdwpError GetSignature(JDWP::RefTypeId refTypeId, std::string& signature) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 147 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 148 | static JDWP::JdwpError GetSourceFile(JDWP::RefTypeId refTypeId, std::string& source_file) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 149 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 150 | static JDWP::JdwpError GetObjectTag(JDWP::ObjectId objectId, uint8_t& tag) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 151 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | aed4be9 | 2011-12-02 16:16:23 -0800 | [diff] [blame] | 152 | static size_t GetTagWidth(JDWP::JdwpTag tag); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 153 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 154 | static JDWP::JdwpError GetArrayLength(JDWP::ObjectId arrayId, int& length) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 155 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 156 | static JDWP::JdwpError OutputArray(JDWP::ObjectId arrayId, int firstIndex, int count, |
| 157 | JDWP::ExpandBuf* pReply) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 158 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 159 | static JDWP::JdwpError SetArrayElements(JDWP::ObjectId arrayId, int firstIndex, int count, |
| 160 | const uint8_t* buf) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 161 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 162 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 163 | static JDWP::ObjectId CreateString(const std::string& str) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 164 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 165 | static JDWP::JdwpError CreateObject(JDWP::RefTypeId classId, JDWP::ObjectId& new_object) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 166 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 167 | static JDWP::JdwpError CreateArrayObject(JDWP::RefTypeId arrayTypeId, uint32_t length, |
| 168 | JDWP::ObjectId& new_array) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 169 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 170 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 171 | static bool MatchType(JDWP::RefTypeId instClassId, JDWP::RefTypeId classId) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 172 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 173 | |
| 174 | /* |
| 175 | * Method and Field |
| 176 | */ |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 177 | static std::string GetMethodName(JDWP::RefTypeId refTypeId, JDWP::MethodId id) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 178 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 179 | static JDWP::JdwpError OutputDeclaredFields(JDWP::RefTypeId refTypeId, bool withGeneric, |
| 180 | JDWP::ExpandBuf* pReply) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 181 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 182 | static JDWP::JdwpError OutputDeclaredMethods(JDWP::RefTypeId refTypeId, bool withGeneric, |
| 183 | JDWP::ExpandBuf* pReply) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 184 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 185 | static JDWP::JdwpError OutputDeclaredInterfaces(JDWP::RefTypeId refTypeId, |
| 186 | JDWP::ExpandBuf* pReply) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 187 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 188 | static void OutputLineTable(JDWP::RefTypeId refTypeId, JDWP::MethodId methodId, |
| 189 | JDWP::ExpandBuf* pReply) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 190 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 191 | static void OutputVariableTable(JDWP::RefTypeId refTypeId, JDWP::MethodId id, bool withGeneric, |
| 192 | JDWP::ExpandBuf* pReply) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 193 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 194 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 195 | static JDWP::JdwpTag GetFieldBasicTag(JDWP::FieldId fieldId) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 196 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 197 | static JDWP::JdwpTag GetStaticFieldBasicTag(JDWP::FieldId fieldId) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 198 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);; |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 199 | static JDWP::JdwpError GetFieldValue(JDWP::ObjectId objectId, JDWP::FieldId fieldId, |
| 200 | JDWP::ExpandBuf* pReply) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 201 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 202 | static JDWP::JdwpError SetFieldValue(JDWP::ObjectId objectId, JDWP::FieldId fieldId, |
| 203 | uint64_t value, int width) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 204 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 205 | static JDWP::JdwpError GetStaticFieldValue(JDWP::RefTypeId refTypeId, JDWP::FieldId fieldId, |
| 206 | JDWP::ExpandBuf* pReply) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 207 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 208 | static JDWP::JdwpError SetStaticFieldValue(JDWP::FieldId fieldId, uint64_t value, int width) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 209 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 210 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 211 | static std::string StringToUtf8(JDWP::ObjectId strId) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 212 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 213 | |
| 214 | /* |
| 215 | * Thread, ThreadGroup, Frame |
| 216 | */ |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 217 | static bool GetThreadName(JDWP::ObjectId threadId, std::string& name) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 218 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) |
| 219 | LOCKS_EXCLUDED(Locks::thread_list_lock_); |
Elliott Hughes | 2435a57 | 2012-02-17 16:07:41 -0800 | [diff] [blame] | 220 | static JDWP::JdwpError GetThreadGroup(JDWP::ObjectId threadId, JDWP::ExpandBuf* pReply); |
Elliott Hughes | 499c513 | 2011-11-17 14:55:11 -0800 | [diff] [blame] | 221 | static std::string GetThreadGroupName(JDWP::ObjectId threadGroupId); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 222 | static JDWP::ObjectId GetThreadGroupParent(JDWP::ObjectId threadGroupId) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 223 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 224 | static JDWP::ObjectId GetSystemThreadGroupId() |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 225 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 226 | static JDWP::ObjectId GetMainThreadGroupId(); |
| 227 | |
Elliott Hughes | 3d30d9b | 2011-12-07 17:35:48 -0800 | [diff] [blame] | 228 | static bool GetThreadStatus(JDWP::ObjectId threadId, JDWP::JdwpThreadStatus* pThreadStatus, JDWP::JdwpSuspendStatus* pSuspendStatus); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 229 | static JDWP::JdwpError GetThreadDebugSuspendCount(JDWP::ObjectId threadId, JDWP::ExpandBuf* pReply); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 230 | static bool ThreadExists(JDWP::ObjectId threadId); |
| 231 | static bool IsSuspended(JDWP::ObjectId threadId); |
| 232 | //static void WaitForSuspend(JDWP::ObjectId threadId); |
Elliott Hughes | caf7654 | 2012-06-28 16:08:22 -0700 | [diff] [blame] | 233 | |
Elliott Hughes | 026b146 | 2012-06-28 20:43:49 -0700 | [diff] [blame] | 234 | // 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] | 235 | // returns all threads. |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 236 | static void GetThreads(JDWP::ObjectId thread_group_id, std::vector<JDWP::ObjectId>& thread_ids) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 237 | LOCKS_EXCLUDED(Locks::thread_list_lock_) |
| 238 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | caf7654 | 2012-06-28 16:08:22 -0700 | [diff] [blame] | 239 | static void GetChildThreadGroups(JDWP::ObjectId thread_group_id, std::vector<JDWP::ObjectId>& child_thread_group_ids); |
| 240 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 241 | static int GetThreadFrameCount(JDWP::ObjectId threadId); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 242 | static JDWP::JdwpError GetThreadFrames(JDWP::ObjectId thread_id, size_t start_frame, |
| 243 | size_t frame_count, JDWP::ExpandBuf* buf) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 244 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 245 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 246 | static JDWP::ObjectId GetThreadSelfId() |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 247 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 248 | static void SuspendVM() |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 249 | LOCKS_EXCLUDED(Locks::thread_list_lock_, |
| 250 | Locks::thread_suspend_count_lock_); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 251 | static void ResumeVM(); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 252 | static JDWP::JdwpError SuspendThread(JDWP::ObjectId threadId, bool request_suspension = true) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 253 | LOCKS_EXCLUDED(Locks::mutator_lock_, |
| 254 | Locks::thread_list_lock_, |
| 255 | Locks::thread_suspend_count_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 256 | |
| 257 | static void ResumeThread(JDWP::ObjectId threadId) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 258 | LOCKS_EXCLUDED(Locks::thread_list_lock_, |
| 259 | Locks::thread_suspend_count_lock_) |
| 260 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 261 | static void SuspendSelf(); |
| 262 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 263 | static JDWP::JdwpError GetThisObject(JDWP::ObjectId thread_id, JDWP::FrameId frame_id, |
| 264 | JDWP::ObjectId* result) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 265 | LOCKS_EXCLUDED(Locks::thread_list_lock_, |
| 266 | Locks::thread_suspend_count_lock_) |
| 267 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 268 | static void GetLocalValue(JDWP::ObjectId threadId, JDWP::FrameId frameId, int slot, |
| 269 | JDWP::JdwpTag tag, uint8_t* buf, size_t expectedLen) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 270 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 271 | static void SetLocalValue(JDWP::ObjectId threadId, JDWP::FrameId frameId, int slot, |
| 272 | JDWP::JdwpTag tag, uint64_t value, size_t width) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 273 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 274 | |
| 275 | /* |
| 276 | * Debugger notification |
| 277 | */ |
| 278 | enum { |
Elliott Hughes | 8696433 | 2012-02-15 19:37:42 -0800 | [diff] [blame] | 279 | kBreakpoint = 0x01, |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 280 | kSingleStep = 0x02, |
| 281 | kMethodEntry = 0x04, |
| 282 | kMethodExit = 0x08, |
| 283 | }; |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 284 | static void PostLocationEvent(const AbstractMethod* method, int pcOffset, Object* thisPtr, int eventFlags) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 285 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 286 | static void PostException(Thread* thread, JDWP::FrameId throw_frame_id, AbstractMethod* throw_method, |
| 287 | uint32_t throw_dex_pc, AbstractMethod* catch_method, uint32_t catch_dex_pc, |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 288 | Throwable* exception) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 289 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 290 | static void PostThreadStart(Thread* t) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 291 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 292 | static void PostThreadDeath(Thread* t) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 293 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 294 | static void PostClassPrepare(Class* c) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 295 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 296 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 297 | static void UpdateDebugger(int32_t dex_pc, Thread* self) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 298 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 91bf6cd | 2012-02-14 17:27:48 -0800 | [diff] [blame] | 299 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 300 | static void WatchLocation(const JDWP::JdwpLocation* pLoc) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 301 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 302 | static void UnwatchLocation(const JDWP::JdwpLocation* pLoc) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 303 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 304 | static JDWP::JdwpError ConfigureStep(JDWP::ObjectId threadId, JDWP::JdwpStepSize size, |
| 305 | JDWP::JdwpStepDepth depth) |
| 306 | LOCKS_EXCLUDED(gBreakpointsLock) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 307 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 308 | static void UnconfigureStep(JDWP::ObjectId threadId); |
| 309 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 310 | static JDWP::JdwpError InvokeMethod(JDWP::ObjectId threadId, JDWP::ObjectId objectId, |
| 311 | JDWP::RefTypeId classId, JDWP::MethodId methodId, |
| 312 | uint32_t arg_count, uint64_t* arg_values, |
| 313 | JDWP::JdwpTag* arg_types, uint32_t options, |
| 314 | JDWP::JdwpTag* pResultTag, uint64_t* pResultValue, |
| 315 | JDWP::ObjectId* pExceptObj) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 316 | LOCKS_EXCLUDED(Locks::thread_list_lock_, |
| 317 | Locks::thread_suspend_count_lock_) |
| 318 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 319 | static void ExecuteMethod(DebugInvokeReq* pReq); |
| 320 | |
| 321 | /* perform "late registration" of an object ID */ |
| 322 | static void RegisterObjectId(JDWP::ObjectId id); |
| 323 | |
| 324 | /* |
| 325 | * DDM support. |
| 326 | */ |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 327 | static void DdmSendThreadNotification(Thread* t, uint32_t type) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 328 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 47fce01 | 2011-10-25 18:37:19 -0700 | [diff] [blame] | 329 | static void DdmSetThreadNotification(bool enable); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 330 | static bool DdmHandlePacket(const uint8_t* buf, int dataLen, uint8_t** pReplyBuf, int* pReplyLen); |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 331 | static void DdmConnected() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 332 | static void DdmDisconnected() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 333 | static void DdmSendChunk(uint32_t type, const std::vector<uint8_t>& bytes) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 334 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 335 | 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] | 336 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 337 | static void DdmSendChunkV(uint32_t type, const iovec* iov, int iov_count) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 338 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 767a147 | 2011-10-26 18:49:02 -0700 | [diff] [blame] | 339 | |
Elliott Hughes | 545a064 | 2011-11-08 19:10:03 -0800 | [diff] [blame] | 340 | /* |
| 341 | * Recent allocation tracking support. |
| 342 | */ |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 343 | static void RecordAllocation(Class* type, size_t byte_count) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 344 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 545a064 | 2011-11-08 19:10:03 -0800 | [diff] [blame] | 345 | static void SetAllocTrackingEnabled(bool enabled); |
| 346 | static inline bool IsAllocTrackingEnabled() { return recent_allocation_records_ != NULL; } |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 347 | static jbyteArray GetRecentAllocations() |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 348 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 545a064 | 2011-11-08 19:10:03 -0800 | [diff] [blame] | 349 | static void DumpRecentAllocations(); |
| 350 | |
Elliott Hughes | 767a147 | 2011-10-26 18:49:02 -0700 | [diff] [blame] | 351 | enum HpifWhen { |
| 352 | HPIF_WHEN_NEVER = 0, |
| 353 | HPIF_WHEN_NOW = 1, |
| 354 | HPIF_WHEN_NEXT_GC = 2, |
| 355 | HPIF_WHEN_EVERY_GC = 3 |
| 356 | }; |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 357 | static int DdmHandleHpifChunk(HpifWhen when) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 358 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 767a147 | 2011-10-26 18:49:02 -0700 | [diff] [blame] | 359 | |
| 360 | enum HpsgWhen { |
| 361 | HPSG_WHEN_NEVER = 0, |
| 362 | HPSG_WHEN_EVERY_GC = 1, |
| 363 | }; |
| 364 | enum HpsgWhat { |
| 365 | HPSG_WHAT_MERGED_OBJECTS = 0, |
| 366 | HPSG_WHAT_DISTINCT_OBJECTS = 1, |
| 367 | }; |
| 368 | static bool DdmHandleHpsgNhsgChunk(HpsgWhen when, HpsgWhat what, bool native); |
| 369 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 370 | static void DdmSendHeapInfo(HpifWhen reason) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 371 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 372 | static void DdmSendHeapSegments(bool native) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 373 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 545a064 | 2011-11-08 19:10:03 -0800 | [diff] [blame] | 374 | |
| 375 | private: |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 376 | static void DdmBroadcast(bool) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 377 | static void PostThreadStartOrStop(Thread*, uint32_t) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 378 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | a215526 | 2011-11-16 16:26:58 -0800 | [diff] [blame] | 379 | |
Elliott Hughes | 545a064 | 2011-11-08 19:10:03 -0800 | [diff] [blame] | 380 | static AllocRecord* recent_allocation_records_; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 381 | }; |
| 382 | |
| 383 | #define CHUNK_TYPE(_name) \ |
Elliott Hughes | 8218847 | 2011-11-07 18:11:48 -0800 | [diff] [blame] | 384 | 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] | 385 | |
| 386 | } // namespace art |
| 387 | |
| 388 | #endif // ART_DEBUGGER_H_ |