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; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 34 | struct Thread; |
| 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() |
| 41 | : invoke_needed_(false), |
| 42 | lock_("a DebugInvokeReq lock"), |
| 43 | cond_("a DebugInvokeReq condition variable") { |
Elliott Hughes | 475fc23 | 2011-10-25 15:00:35 -0700 | [diff] [blame] | 44 | } |
| 45 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 46 | /* boolean; only set when we're in the tail end of an event handler */ |
| 47 | bool ready; |
| 48 | |
| 49 | /* boolean; set if the JDWP thread wants this thread to do work */ |
Elliott Hughes | d07986f | 2011-12-06 18:27:45 -0800 | [diff] [blame] | 50 | bool invoke_needed_; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 51 | |
| 52 | /* request */ |
Elliott Hughes | d07986f | 2011-12-06 18:27:45 -0800 | [diff] [blame] | 53 | Object* receiver_; /* not used for ClassType.InvokeMethod */ |
| 54 | Object* thread_; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 55 | Class* class_; |
Elliott Hughes | d07986f | 2011-12-06 18:27:45 -0800 | [diff] [blame] | 56 | Method* method_; |
Elliott Hughes | 45651fd | 2012-02-21 15:48:20 -0800 | [diff] [blame] | 57 | uint32_t arg_count_; |
| 58 | uint64_t* arg_values_; /* will be NULL if arg_count_ == 0 */ |
Elliott Hughes | d07986f | 2011-12-06 18:27:45 -0800 | [diff] [blame] | 59 | uint32_t options_; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 60 | |
| 61 | /* result */ |
Elliott Hughes | 475fc23 | 2011-10-25 15:00:35 -0700 | [diff] [blame] | 62 | JDWP::JdwpError error; |
Elliott Hughes | d07986f | 2011-12-06 18:27:45 -0800 | [diff] [blame] | 63 | JDWP::JdwpTag result_tag; |
Elliott Hughes | 475fc23 | 2011-10-25 15:00:35 -0700 | [diff] [blame] | 64 | JValue result_value; |
| 65 | JDWP::ObjectId exception; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 66 | |
| 67 | /* condition variable to wait on while the method executes */ |
| 68 | Mutex lock_; |
| 69 | ConditionVariable cond_; |
| 70 | }; |
| 71 | |
| 72 | class Dbg { |
Elliott Hughes | ff17f1f | 2012-01-24 18:12:29 -0800 | [diff] [blame] | 73 | public: |
Elliott Hughes | 3bb8156 | 2011-10-21 18:52:59 -0700 | [diff] [blame] | 74 | static bool ParseJdwpOptions(const std::string& options); |
Elliott Hughes | 4ffd313 | 2011-10-24 12:06:42 -0700 | [diff] [blame] | 75 | static void SetJdwpAllowed(bool allowed); |
| 76 | |
Elliott Hughes | d1cc836 | 2011-10-24 16:58:50 -0700 | [diff] [blame] | 77 | static void StartJdwp(); |
| 78 | static void StopJdwp(); |
| 79 | |
Elliott Hughes | 767a147 | 2011-10-26 18:49:02 -0700 | [diff] [blame] | 80 | // Invoked by the GC in case we need to keep DDMS informed. |
| 81 | static void GcDidFinish(); |
| 82 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 83 | // Return the DebugInvokeReq for the current thread. |
| 84 | static DebugInvokeReq* GetInvokeReq(); |
| 85 | |
Elliott Hughes | 475fc23 | 2011-10-25 15:00:35 -0700 | [diff] [blame] | 86 | static Thread* GetDebugThread(); |
| 87 | static void ClearWaitForEventThread(); |
| 88 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 89 | /* |
| 90 | * Enable/disable breakpoints and step modes. Used to provide a heads-up |
| 91 | * when the debugger attaches. |
| 92 | */ |
| 93 | static void Connected(); |
Elliott Hughes | a215526 | 2011-11-16 16:26:58 -0800 | [diff] [blame] | 94 | static void GoActive(); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 95 | static void Disconnected(); |
Elliott Hughes | 8696433 | 2012-02-15 19:37:42 -0800 | [diff] [blame] | 96 | static void Disposed(); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 97 | |
Elliott Hughes | c0f0933 | 2012-03-26 13:27:06 -0700 | [diff] [blame] | 98 | // Returns true if we're actually debugging with a real debugger, false if it's |
| 99 | // just DDMS (or nothing at all). |
| 100 | static bool IsDebuggerActive(); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 101 | |
Elliott Hughes | c0f0933 | 2012-03-26 13:27:06 -0700 | [diff] [blame] | 102 | // Returns true if we had -Xrunjdwp or -agentlib:jdwp= on the command line. |
| 103 | static bool IsJdwpConfigured(); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 104 | |
Elliott Hughes | 8696433 | 2012-02-15 19:37:42 -0800 | [diff] [blame] | 105 | static bool IsDisposed(); |
| 106 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 107 | /* |
| 108 | * Time, in milliseconds, since the last debugger activity. Does not |
| 109 | * include DDMS activity. Returns -1 if there has been no activity. |
| 110 | * Returns 0 if we're in the middle of handling a debugger request. |
| 111 | */ |
| 112 | static int64_t LastDebuggerActivity(); |
| 113 | |
| 114 | /* |
| 115 | * Block/allow GC depending on what we're doing. These return the old |
| 116 | * status, which can be fed to ThreadContinuing() to restore the previous |
| 117 | * mode. |
| 118 | */ |
| 119 | static int ThreadRunning(); |
| 120 | static int ThreadWaiting(); |
| 121 | static int ThreadContinuing(int status); |
| 122 | |
| 123 | static void UndoDebuggerSuspensions(); |
| 124 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 125 | static void Exit(int status); |
| 126 | |
Elliott Hughes | bfe487b | 2011-10-26 15:48:55 -0700 | [diff] [blame] | 127 | static void VisitRoots(Heap::RootVisitor* visitor, void* arg); |
| 128 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 129 | /* |
| 130 | * Class, Object, Array |
| 131 | */ |
Elliott Hughes | c308a5d | 2012-02-16 17:12:06 -0800 | [diff] [blame] | 132 | static std::string GetClassName(JDWP::RefTypeId id); |
Elliott Hughes | 436e372 | 2012-02-17 20:01:47 -0800 | [diff] [blame] | 133 | static JDWP::JdwpError GetClassObject(JDWP::RefTypeId id, JDWP::ObjectId& classObjectId); |
Elliott Hughes | 3d1ca6d | 2012-02-13 15:43:19 -0800 | [diff] [blame] | 134 | static JDWP::JdwpError GetSuperclass(JDWP::RefTypeId id, JDWP::RefTypeId& superclassId); |
Elliott Hughes | 436e372 | 2012-02-17 20:01:47 -0800 | [diff] [blame] | 135 | static JDWP::JdwpError GetClassLoader(JDWP::RefTypeId id, JDWP::ExpandBuf* pReply); |
| 136 | static JDWP::JdwpError GetModifiers(JDWP::RefTypeId id, JDWP::ExpandBuf* pReply); |
| 137 | static JDWP::JdwpError GetReflectedType(JDWP::RefTypeId classId, JDWP::ExpandBuf* pReply); |
Elliott Hughes | 7b3cdfc | 2011-12-08 21:28:17 -0800 | [diff] [blame] | 138 | static void GetClassList(std::vector<JDWP::RefTypeId>& classes); |
Elliott Hughes | 436e372 | 2012-02-17 20:01:47 -0800 | [diff] [blame] | 139 | static JDWP::JdwpError GetClassInfo(JDWP::RefTypeId classId, JDWP::JdwpTypeTag* pTypeTag, uint32_t* pStatus, std::string* pDescriptor); |
Elliott Hughes | c3b77c7 | 2011-12-15 20:56:48 -0800 | [diff] [blame] | 140 | static void FindLoadedClassBySignature(const char* descriptor, std::vector<JDWP::RefTypeId>& ids); |
Elliott Hughes | 2435a57 | 2012-02-17 16:07:41 -0800 | [diff] [blame] | 141 | static JDWP::JdwpError GetReferenceType(JDWP::ObjectId objectId, JDWP::ExpandBuf* pReply); |
Elliott Hughes | 1fe7afb | 2012-02-13 17:23:03 -0800 | [diff] [blame] | 142 | static JDWP::JdwpError GetSignature(JDWP::RefTypeId refTypeId, std::string& signature); |
Elliott Hughes | 436e372 | 2012-02-17 20:01:47 -0800 | [diff] [blame] | 143 | static JDWP::JdwpError GetSourceFile(JDWP::RefTypeId refTypeId, std::string& source_file); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 144 | static uint8_t GetObjectTag(JDWP::ObjectId objectId); |
Elliott Hughes | aed4be9 | 2011-12-02 16:16:23 -0800 | [diff] [blame] | 145 | static size_t GetTagWidth(JDWP::JdwpTag tag); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 146 | |
Elliott Hughes | 3d1ca6d | 2012-02-13 15:43:19 -0800 | [diff] [blame] | 147 | static JDWP::JdwpError GetArrayLength(JDWP::ObjectId arrayId, int& length); |
| 148 | static JDWP::JdwpError OutputArray(JDWP::ObjectId arrayId, int firstIndex, int count, JDWP::ExpandBuf* pReply); |
| 149 | static JDWP::JdwpError SetArrayElements(JDWP::ObjectId arrayId, int firstIndex, int count, const uint8_t* buf); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 150 | |
Elliott Hughes | 7b3cdfc | 2011-12-08 21:28:17 -0800 | [diff] [blame] | 151 | static JDWP::ObjectId CreateString(const std::string& str); |
Elliott Hughes | 436e372 | 2012-02-17 20:01:47 -0800 | [diff] [blame] | 152 | static JDWP::JdwpError CreateObject(JDWP::RefTypeId classId, JDWP::ObjectId& new_object); |
| 153 | static JDWP::JdwpError CreateArrayObject(JDWP::RefTypeId arrayTypeId, uint32_t length, JDWP::ObjectId& new_array); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 154 | |
| 155 | static bool MatchType(JDWP::RefTypeId instClassId, JDWP::RefTypeId classId); |
| 156 | |
| 157 | /* |
| 158 | * Method and Field |
| 159 | */ |
Elliott Hughes | 03181a8 | 2011-11-17 17:22:21 -0800 | [diff] [blame] | 160 | static std::string GetMethodName(JDWP::RefTypeId refTypeId, JDWP::MethodId id); |
Elliott Hughes | 436e372 | 2012-02-17 20:01:47 -0800 | [diff] [blame] | 161 | static JDWP::JdwpError OutputDeclaredFields(JDWP::RefTypeId refTypeId, bool withGeneric, JDWP::ExpandBuf* pReply); |
| 162 | static JDWP::JdwpError OutputDeclaredMethods(JDWP::RefTypeId refTypeId, bool withGeneric, JDWP::ExpandBuf* pReply); |
| 163 | static JDWP::JdwpError OutputDeclaredInterfaces(JDWP::RefTypeId refTypeId, JDWP::ExpandBuf* pReply); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 164 | static void OutputLineTable(JDWP::RefTypeId refTypeId, JDWP::MethodId methodId, JDWP::ExpandBuf* pReply); |
| 165 | static void OutputVariableTable(JDWP::RefTypeId refTypeId, JDWP::MethodId id, bool withGeneric, JDWP::ExpandBuf* pReply); |
| 166 | |
Elliott Hughes | aed4be9 | 2011-12-02 16:16:23 -0800 | [diff] [blame] | 167 | static JDWP::JdwpTag GetFieldBasicTag(JDWP::FieldId fieldId); |
| 168 | static JDWP::JdwpTag GetStaticFieldBasicTag(JDWP::FieldId fieldId); |
Elliott Hughes | 3f4d58f | 2012-02-18 20:05:37 -0800 | [diff] [blame] | 169 | static JDWP::JdwpError GetFieldValue(JDWP::ObjectId objectId, JDWP::FieldId fieldId, JDWP::ExpandBuf* pReply); |
Elliott Hughes | 3d1ca6d | 2012-02-13 15:43:19 -0800 | [diff] [blame] | 170 | static JDWP::JdwpError SetFieldValue(JDWP::ObjectId objectId, JDWP::FieldId fieldId, uint64_t value, int width); |
Elliott Hughes | 0cf7433 | 2012-02-23 23:14:00 -0800 | [diff] [blame] | 171 | static JDWP::JdwpError GetStaticFieldValue(JDWP::RefTypeId refTypeId, JDWP::FieldId fieldId, JDWP::ExpandBuf* pReply); |
Elliott Hughes | 3d1ca6d | 2012-02-13 15:43:19 -0800 | [diff] [blame] | 172 | static JDWP::JdwpError SetStaticFieldValue(JDWP::FieldId fieldId, uint64_t value, int width); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 173 | |
Elliott Hughes | 68fdbd0 | 2011-11-29 19:22:47 -0800 | [diff] [blame] | 174 | static std::string StringToUtf8(JDWP::ObjectId strId); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 175 | |
| 176 | /* |
| 177 | * Thread, ThreadGroup, Frame |
| 178 | */ |
Elliott Hughes | a2e54f6 | 2011-11-17 13:01:30 -0800 | [diff] [blame] | 179 | static bool GetThreadName(JDWP::ObjectId threadId, std::string& name); |
Elliott Hughes | 2435a57 | 2012-02-17 16:07:41 -0800 | [diff] [blame] | 180 | static JDWP::JdwpError GetThreadGroup(JDWP::ObjectId threadId, JDWP::ExpandBuf* pReply); |
Elliott Hughes | 499c513 | 2011-11-17 14:55:11 -0800 | [diff] [blame] | 181 | static std::string GetThreadGroupName(JDWP::ObjectId threadGroupId); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 182 | static JDWP::ObjectId GetThreadGroupParent(JDWP::ObjectId threadGroupId); |
| 183 | static JDWP::ObjectId GetSystemThreadGroupId(); |
| 184 | static JDWP::ObjectId GetMainThreadGroupId(); |
| 185 | |
Elliott Hughes | 3d30d9b | 2011-12-07 17:35:48 -0800 | [diff] [blame] | 186 | static bool GetThreadStatus(JDWP::ObjectId threadId, JDWP::JdwpThreadStatus* pThreadStatus, JDWP::JdwpSuspendStatus* pSuspendStatus); |
Elliott Hughes | 2435a57 | 2012-02-17 16:07:41 -0800 | [diff] [blame] | 187 | static JDWP::JdwpError GetThreadSuspendCount(JDWP::ObjectId threadId, JDWP::ExpandBuf* pReply); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 188 | static bool ThreadExists(JDWP::ObjectId threadId); |
| 189 | static bool IsSuspended(JDWP::ObjectId threadId); |
| 190 | //static void WaitForSuspend(JDWP::ObjectId threadId); |
| 191 | static void GetThreadGroupThreads(JDWP::ObjectId threadGroupId, JDWP::ObjectId** ppThreadIds, uint32_t* pThreadCount); |
| 192 | static void GetAllThreads(JDWP::ObjectId** ppThreadIds, uint32_t* pThreadCount); |
| 193 | static int GetThreadFrameCount(JDWP::ObjectId threadId); |
Elliott Hughes | 530fa00 | 2012-03-12 11:44:49 -0700 | [diff] [blame] | 194 | static void GetThreadFrame(JDWP::ObjectId threadId, int num, JDWP::FrameId* pFrameId, JDWP::JdwpLocation* pLoc); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 195 | |
| 196 | static JDWP::ObjectId GetThreadSelfId(); |
Elliott Hughes | 475fc23 | 2011-10-25 15:00:35 -0700 | [diff] [blame] | 197 | static void SuspendVM(); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 198 | static void ResumeVM(); |
| 199 | static void SuspendThread(JDWP::ObjectId threadId); |
| 200 | static void ResumeThread(JDWP::ObjectId threadId); |
| 201 | static void SuspendSelf(); |
| 202 | |
Elliott Hughes | 91bf6cd | 2012-02-14 17:27:48 -0800 | [diff] [blame] | 203 | static void GetThisObject(JDWP::FrameId frameId, JDWP::ObjectId* pThisId); |
Elliott Hughes | dbb4079 | 2011-11-18 17:05:22 -0800 | [diff] [blame] | 204 | static void GetLocalValue(JDWP::ObjectId threadId, JDWP::FrameId frameId, int slot, JDWP::JdwpTag tag, uint8_t* buf, size_t expectedLen); |
| 205 | static void SetLocalValue(JDWP::ObjectId threadId, JDWP::FrameId frameId, int slot, JDWP::JdwpTag tag, uint64_t value, size_t width); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 206 | |
| 207 | /* |
| 208 | * Debugger notification |
| 209 | */ |
| 210 | enum { |
Elliott Hughes | 8696433 | 2012-02-15 19:37:42 -0800 | [diff] [blame] | 211 | kBreakpoint = 0x01, |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 212 | kSingleStep = 0x02, |
| 213 | kMethodEntry = 0x04, |
| 214 | kMethodExit = 0x08, |
| 215 | }; |
| 216 | static void PostLocationEvent(const Method* method, int pcOffset, Object* thisPtr, int eventFlags); |
Elliott Hughes | d07986f | 2011-12-06 18:27:45 -0800 | [diff] [blame] | 217 | static void PostException(Method** sp, Method* throwMethod, uintptr_t throwNativePc, Method* catchMethod, uintptr_t catchNativePc, Object* exception); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 218 | static void PostThreadStart(Thread* t); |
| 219 | static void PostThreadDeath(Thread* t); |
| 220 | static void PostClassPrepare(Class* c); |
| 221 | |
Elliott Hughes | 91bf6cd | 2012-02-14 17:27:48 -0800 | [diff] [blame] | 222 | static void UpdateDebugger(int32_t dex_pc, Thread* self, Method** sp); |
| 223 | |
Elliott Hughes | 8696433 | 2012-02-15 19:37:42 -0800 | [diff] [blame] | 224 | static void WatchLocation(const JDWP::JdwpLocation* pLoc); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 225 | static void UnwatchLocation(const JDWP::JdwpLocation* pLoc); |
Elliott Hughes | 2435a57 | 2012-02-17 16:07:41 -0800 | [diff] [blame] | 226 | static JDWP::JdwpError ConfigureStep(JDWP::ObjectId threadId, JDWP::JdwpStepSize size, JDWP::JdwpStepDepth depth); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 227 | static void UnconfigureStep(JDWP::ObjectId threadId); |
| 228 | |
Elliott Hughes | 45651fd | 2012-02-21 15:48:20 -0800 | [diff] [blame] | 229 | static JDWP::JdwpError InvokeMethod(JDWP::ObjectId threadId, JDWP::ObjectId objectId, JDWP::RefTypeId classId, JDWP::MethodId methodId, uint32_t arg_count, uint64_t* arg_values, JDWP::JdwpTag* arg_types, uint32_t options, JDWP::JdwpTag* pResultTag, uint64_t* pResultValue, JDWP::ObjectId* pExceptObj); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 230 | static void ExecuteMethod(DebugInvokeReq* pReq); |
| 231 | |
| 232 | /* perform "late registration" of an object ID */ |
| 233 | static void RegisterObjectId(JDWP::ObjectId id); |
| 234 | |
| 235 | /* |
| 236 | * DDM support. |
| 237 | */ |
Elliott Hughes | 8218847 | 2011-11-07 18:11:48 -0800 | [diff] [blame] | 238 | static void DdmSendThreadNotification(Thread* t, uint32_t type); |
Elliott Hughes | 47fce01 | 2011-10-25 18:37:19 -0700 | [diff] [blame] | 239 | static void DdmSetThreadNotification(bool enable); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 240 | static bool DdmHandlePacket(const uint8_t* buf, int dataLen, uint8_t** pReplyBuf, int* pReplyLen); |
| 241 | static void DdmConnected(); |
| 242 | static void DdmDisconnected(); |
Elliott Hughes | 21f32d7 | 2011-11-09 17:44:13 -0800 | [diff] [blame] | 243 | static void DdmSendChunk(uint32_t type, const std::vector<uint8_t>& bytes); |
Elliott Hughes | 8218847 | 2011-11-07 18:11:48 -0800 | [diff] [blame] | 244 | static void DdmSendChunk(uint32_t type, size_t len, const uint8_t* buf); |
Elliott Hughes | cccd84f | 2011-12-05 16:51:54 -0800 | [diff] [blame] | 245 | static void DdmSendChunkV(uint32_t type, const struct iovec* iov, int iov_count); |
Elliott Hughes | 767a147 | 2011-10-26 18:49:02 -0700 | [diff] [blame] | 246 | |
Elliott Hughes | 545a064 | 2011-11-08 19:10:03 -0800 | [diff] [blame] | 247 | /* |
| 248 | * Recent allocation tracking support. |
| 249 | */ |
| 250 | static void RecordAllocation(Class* type, size_t byte_count); |
| 251 | static void SetAllocTrackingEnabled(bool enabled); |
| 252 | static inline bool IsAllocTrackingEnabled() { return recent_allocation_records_ != NULL; } |
| 253 | static jbyteArray GetRecentAllocations(); |
| 254 | static void DumpRecentAllocations(); |
| 255 | |
Elliott Hughes | 767a147 | 2011-10-26 18:49:02 -0700 | [diff] [blame] | 256 | enum HpifWhen { |
| 257 | HPIF_WHEN_NEVER = 0, |
| 258 | HPIF_WHEN_NOW = 1, |
| 259 | HPIF_WHEN_NEXT_GC = 2, |
| 260 | HPIF_WHEN_EVERY_GC = 3 |
| 261 | }; |
| 262 | static int DdmHandleHpifChunk(HpifWhen when); |
| 263 | |
| 264 | enum HpsgWhen { |
| 265 | HPSG_WHEN_NEVER = 0, |
| 266 | HPSG_WHEN_EVERY_GC = 1, |
| 267 | }; |
| 268 | enum HpsgWhat { |
| 269 | HPSG_WHAT_MERGED_OBJECTS = 0, |
| 270 | HPSG_WHAT_DISTINCT_OBJECTS = 1, |
| 271 | }; |
| 272 | static bool DdmHandleHpsgNhsgChunk(HpsgWhen when, HpsgWhat what, bool native); |
| 273 | |
Elliott Hughes | 7162ad9 | 2011-10-27 14:08:42 -0700 | [diff] [blame] | 274 | static void DdmSendHeapInfo(HpifWhen reason); |
Elliott Hughes | 6a5bd49 | 2011-10-28 14:33:57 -0700 | [diff] [blame] | 275 | static void DdmSendHeapSegments(bool native); |
Elliott Hughes | 545a064 | 2011-11-08 19:10:03 -0800 | [diff] [blame] | 276 | |
| 277 | private: |
Elliott Hughes | a215526 | 2011-11-16 16:26:58 -0800 | [diff] [blame] | 278 | static void DdmBroadcast(bool); |
| 279 | static void GetThreadGroupThreadsImpl(Object*, JDWP::ObjectId**, uint32_t*); |
| 280 | static void PostThreadStartOrStop(Thread*, uint32_t); |
| 281 | |
Elliott Hughes | 545a064 | 2011-11-08 19:10:03 -0800 | [diff] [blame] | 282 | static AllocRecord* recent_allocation_records_; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 283 | }; |
| 284 | |
| 285 | #define CHUNK_TYPE(_name) \ |
Elliott Hughes | 8218847 | 2011-11-07 18:11:48 -0800 | [diff] [blame] | 286 | 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] | 287 | |
| 288 | } // namespace art |
| 289 | |
| 290 | #endif // ART_DEBUGGER_H_ |