debugger.h revision aed4be94da51b4fbb54c728151f0daf11535f6ab
1872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes/* 2872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes * Copyright (C) 2008 The Android Open Source Project 3872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes * 4872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes * Licensed under the Apache License, Version 2.0 (the "License"); 5872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes * you may not use this file except in compliance with the License. 6872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes * You may obtain a copy of the License at 7872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes * 8872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes * http://www.apache.org/licenses/LICENSE-2.0 9872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes * 10872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes * Unless required by applicable law or agreed to in writing, software 11872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes * distributed under the License is distributed on an "AS IS" BASIS, 12872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes * See the License for the specific language governing permissions and 14872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes * limitations under the License. 15872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes */ 16872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes 17872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes/* 18872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes * Dalvik-specific side of debugger support. (The JDWP code is intended to 19872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes * be relatively generic.) 20872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes */ 21872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes#ifndef ART_DEBUGGER_H_ 22872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes#define ART_DEBUGGER_H_ 23872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes 24872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes#include <pthread.h> 25872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes 263bb81563481d02b5a6349b8ed918392454e761d8Elliott Hughes#include <string> 273bb81563481d02b5a6349b8ed918392454e761d8Elliott Hughes 28872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes#include "jdwp/jdwp.h" 293bb81563481d02b5a6349b8ed918392454e761d8Elliott Hughes#include "object.h" 30872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes 31872d4ec7225444d9400d30f9027247deb91012fdElliott Hughesnamespace art { 32872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes 33545a064aca775ba801790fced3d713d8a87bfc61Elliott Hughesstruct AllocRecord; 34872d4ec7225444d9400d30f9027247deb91012fdElliott Hughesstruct Thread; 35872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes 36872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes/* 37872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes * Invoke-during-breakpoint support. 38872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes */ 39872d4ec7225444d9400d30f9027247deb91012fdElliott Hughesstruct DebugInvokeReq { 40475fc23a4a7f35d1be87ea0b06c80df317a720acElliott Hughes DebugInvokeReq() : lock_("a DebugInvokeReq lock"), cond_("a DebugInvokeReq condition variable") { 41475fc23a4a7f35d1be87ea0b06c80df317a720acElliott Hughes } 42475fc23a4a7f35d1be87ea0b06c80df317a720acElliott Hughes 43872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes /* boolean; only set when we're in the tail end of an event handler */ 44872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes bool ready; 45872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes 46872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes /* boolean; set if the JDWP thread wants this thread to do work */ 47475fc23a4a7f35d1be87ea0b06c80df317a720acElliott Hughes bool invoke_needed; 48872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes 49872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes /* request */ 50872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes Object* obj; /* not used for ClassType.InvokeMethod */ 51872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes Object* thread; 52872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes Class* class_; 53872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes Method* method; 54475fc23a4a7f35d1be87ea0b06c80df317a720acElliott Hughes uint32_t num_args; 55475fc23a4a7f35d1be87ea0b06c80df317a720acElliott Hughes uint64_t* arg_array; /* will be NULL if numArgs==0 */ 56872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes uint32_t options; 57872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes 58872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes /* result */ 59475fc23a4a7f35d1be87ea0b06c80df317a720acElliott Hughes JDWP::JdwpError error; 60475fc23a4a7f35d1be87ea0b06c80df317a720acElliott Hughes uint8_t result_tag; 61475fc23a4a7f35d1be87ea0b06c80df317a720acElliott Hughes JValue result_value; 62475fc23a4a7f35d1be87ea0b06c80df317a720acElliott Hughes JDWP::ObjectId exception; 63872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes 64872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes /* condition variable to wait on while the method executes */ 65872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes Mutex lock_; 66872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes ConditionVariable cond_; 67872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes}; 68872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes 69872d4ec7225444d9400d30f9027247deb91012fdElliott Hughesclass Dbg { 70872d4ec7225444d9400d30f9027247deb91012fdElliott Hughespublic: 713bb81563481d02b5a6349b8ed918392454e761d8Elliott Hughes static bool ParseJdwpOptions(const std::string& options); 724ffd31315bc0d00ec278e85feed15985de5ac3dcElliott Hughes static void SetJdwpAllowed(bool allowed); 734ffd31315bc0d00ec278e85feed15985de5ac3dcElliott Hughes 74d1cc8363d4f4bbac7568b1d02a5ca481cd10830fElliott Hughes static void StartJdwp(); 75d1cc8363d4f4bbac7568b1d02a5ca481cd10830fElliott Hughes static void StopJdwp(); 76d1cc8363d4f4bbac7568b1d02a5ca481cd10830fElliott Hughes 77767a147529da3ee8240f3ce4cd3af22ae454be64Elliott Hughes // Invoked by the GC in case we need to keep DDMS informed. 78767a147529da3ee8240f3ce4cd3af22ae454be64Elliott Hughes static void GcDidFinish(); 79767a147529da3ee8240f3ce4cd3af22ae454be64Elliott Hughes 80872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes // Return the DebugInvokeReq for the current thread. 81872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static DebugInvokeReq* GetInvokeReq(); 82872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes 83475fc23a4a7f35d1be87ea0b06c80df317a720acElliott Hughes static Thread* GetDebugThread(); 84475fc23a4a7f35d1be87ea0b06c80df317a720acElliott Hughes static void ClearWaitForEventThread(); 85475fc23a4a7f35d1be87ea0b06c80df317a720acElliott Hughes 86872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes /* 87872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes * Enable/disable breakpoints and step modes. Used to provide a heads-up 88872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes * when the debugger attaches. 89872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes */ 90872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static void Connected(); 91a215526d5c789cbef0f81a1f9aba22541a841ccaElliott Hughes static void GoActive(); 92872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static void Disconnected(); 93872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes 94872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes /* 95872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes * Returns "true" if a debugger is connected. Returns "false" if it's 96872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes * just DDM. 97872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes */ 98872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static bool IsDebuggerConnected(); 99872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes 100872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static bool IsDebuggingEnabled(); 101872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes 102872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes /* 103872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes * Time, in milliseconds, since the last debugger activity. Does not 104872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes * include DDMS activity. Returns -1 if there has been no activity. 105872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes * Returns 0 if we're in the middle of handling a debugger request. 106872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes */ 107872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static int64_t LastDebuggerActivity(); 108872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes 109872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes /* 110872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes * Block/allow GC depending on what we're doing. These return the old 111872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes * status, which can be fed to ThreadContinuing() to restore the previous 112872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes * mode. 113872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes */ 114872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static int ThreadRunning(); 115872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static int ThreadWaiting(); 116872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static int ThreadContinuing(int status); 117872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes 118872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static void UndoDebuggerSuspensions(); 119872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes 120872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes // The debugger wants the VM to exit. 121872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static void Exit(int status); 122872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes 123bfe487be25652c5456236661b9d9c3579d2296c1Elliott Hughes static void VisitRoots(Heap::RootVisitor* visitor, void* arg); 124bfe487be25652c5456236661b9d9c3579d2296c1Elliott Hughes 125872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes /* 126872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes * Class, Object, Array 127872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes */ 128a215526d5c789cbef0f81a1f9aba22541a841ccaElliott Hughes static std::string GetClassDescriptor(JDWP::RefTypeId id); 129872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static JDWP::ObjectId GetClassObject(JDWP::RefTypeId id); 130872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static JDWP::RefTypeId GetSuperclass(JDWP::RefTypeId id); 131872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static JDWP::ObjectId GetClassLoader(JDWP::RefTypeId id); 132872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static uint32_t GetAccessFlags(JDWP::RefTypeId id); 133872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static bool IsInterface(JDWP::RefTypeId id); 134872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static void GetClassList(uint32_t* pNumClasses, JDWP::RefTypeId** pClassRefBuf); 135872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static void GetVisibleClassList(JDWP::ObjectId classLoaderId, uint32_t* pNumClasses, JDWP::RefTypeId** pClassRefBuf); 136a215526d5c789cbef0f81a1f9aba22541a841ccaElliott Hughes static void GetClassInfo(JDWP::RefTypeId classId, uint8_t* pTypeTag, uint32_t* pStatus, std::string* pDescriptor); 137872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static bool FindLoadedClassBySignature(const char* classDescriptor, JDWP::RefTypeId* pRefTypeId); 138872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static void GetObjectType(JDWP::ObjectId objectId, uint8_t* pRefTypeTag, JDWP::RefTypeId* pRefTypeId); 139872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static uint8_t GetClassObjectType(JDWP::RefTypeId refTypeId); 140a2e54f61453a2072181d5dd7aa2d5e845f5b53f6Elliott Hughes static std::string GetSignature(JDWP::RefTypeId refTypeId); 14103181a828cd493545b278e0aa4f150fdaf1e3325Elliott Hughes static bool GetSourceFile(JDWP::RefTypeId refTypeId, std::string& source_file); 142872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static const char* GetObjectTypeName(JDWP::ObjectId objectId); 143872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static uint8_t GetObjectTag(JDWP::ObjectId objectId); 144aed4be94da51b4fbb54c728151f0daf11535f6abElliott Hughes static size_t GetTagWidth(JDWP::JdwpTag tag); 145872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes 146872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static int GetArrayLength(JDWP::ObjectId arrayId); 147872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static uint8_t GetArrayElementTag(JDWP::ObjectId arrayId); 148872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static bool OutputArray(JDWP::ObjectId arrayId, int firstIndex, int count, JDWP::ExpandBuf* pReply); 149872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static bool SetArrayElements(JDWP::ObjectId arrayId, int firstIndex, int count, const uint8_t* buf); 150872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes 151872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static JDWP::ObjectId CreateString(const char* str); 152872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static JDWP::ObjectId CreateObject(JDWP::RefTypeId classId); 153872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static JDWP::ObjectId CreateArrayObject(JDWP::RefTypeId arrayTypeId, uint32_t length); 154872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes 155872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static bool MatchType(JDWP::RefTypeId instClassId, JDWP::RefTypeId classId); 156872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes 157872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes /* 158872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes * Method and Field 159872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes */ 16003181a828cd493545b278e0aa4f150fdaf1e3325Elliott Hughes static std::string GetMethodName(JDWP::RefTypeId refTypeId, JDWP::MethodId id); 161a2e54f61453a2072181d5dd7aa2d5e845f5b53f6Elliott Hughes static void OutputDeclaredFields(JDWP::RefTypeId refTypeId, bool withGeneric, JDWP::ExpandBuf* pReply); 162a2e54f61453a2072181d5dd7aa2d5e845f5b53f6Elliott Hughes static void OutputDeclaredMethods(JDWP::RefTypeId refTypeId, bool withGeneric, JDWP::ExpandBuf* pReply); 163a2e54f61453a2072181d5dd7aa2d5e845f5b53f6Elliott Hughes static void OutputDeclaredInterfaces(JDWP::RefTypeId refTypeId, JDWP::ExpandBuf* pReply); 164872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static void OutputLineTable(JDWP::RefTypeId refTypeId, JDWP::MethodId methodId, JDWP::ExpandBuf* pReply); 165872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static void OutputVariableTable(JDWP::RefTypeId refTypeId, JDWP::MethodId id, bool withGeneric, JDWP::ExpandBuf* pReply); 166872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes 167aed4be94da51b4fbb54c728151f0daf11535f6abElliott Hughes static JDWP::JdwpTag GetFieldBasicTag(JDWP::FieldId fieldId); 168aed4be94da51b4fbb54c728151f0daf11535f6abElliott Hughes static JDWP::JdwpTag GetStaticFieldBasicTag(JDWP::FieldId fieldId); 169872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static void GetFieldValue(JDWP::ObjectId objectId, JDWP::FieldId fieldId, JDWP::ExpandBuf* pReply); 170872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static void SetFieldValue(JDWP::ObjectId objectId, JDWP::FieldId fieldId, uint64_t value, int width); 171872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static void GetStaticFieldValue(JDWP::RefTypeId refTypeId, JDWP::FieldId fieldId, JDWP::ExpandBuf* pReply); 172872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static void SetStaticFieldValue(JDWP::RefTypeId refTypeId, JDWP::FieldId fieldId, uint64_t rawValue, int width); 173872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes 17468fdbd07fc2b8856905e06f3cc945b046c3bfcd3Elliott Hughes static std::string StringToUtf8(JDWP::ObjectId strId); 175872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes 176872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes /* 177872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes * Thread, ThreadGroup, Frame 178872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes */ 179a2e54f61453a2072181d5dd7aa2d5e845f5b53f6Elliott Hughes static bool GetThreadName(JDWP::ObjectId threadId, std::string& name); 180872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static JDWP::ObjectId GetThreadGroup(JDWP::ObjectId threadId); 181499c5133d361e7c659fc38e5ccfeb1280a7996f5Elliott Hughes static std::string GetThreadGroupName(JDWP::ObjectId threadGroupId); 182872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static JDWP::ObjectId GetThreadGroupParent(JDWP::ObjectId threadGroupId); 183872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static JDWP::ObjectId GetSystemThreadGroupId(); 184872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static JDWP::ObjectId GetMainThreadGroupId(); 185872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes 186872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static bool GetThreadStatus(JDWP::ObjectId threadId, uint32_t* threadStatus, uint32_t* suspendStatus); 187872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static uint32_t GetThreadSuspendCount(JDWP::ObjectId threadId); 188872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static bool ThreadExists(JDWP::ObjectId threadId); 189872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static bool IsSuspended(JDWP::ObjectId threadId); 190872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes //static void WaitForSuspend(JDWP::ObjectId threadId); 191872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static void GetThreadGroupThreads(JDWP::ObjectId threadGroupId, JDWP::ObjectId** ppThreadIds, uint32_t* pThreadCount); 192872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static void GetAllThreads(JDWP::ObjectId** ppThreadIds, uint32_t* pThreadCount); 193872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static int GetThreadFrameCount(JDWP::ObjectId threadId); 194872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static bool GetThreadFrame(JDWP::ObjectId threadId, int num, JDWP::FrameId* pFrameId, JDWP::JdwpLocation* pLoc); 195872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes 196872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static JDWP::ObjectId GetThreadSelfId(); 197475fc23a4a7f35d1be87ea0b06c80df317a720acElliott Hughes static void SuspendVM(); 198872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static void ResumeVM(); 199872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static void SuspendThread(JDWP::ObjectId threadId); 200872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static void ResumeThread(JDWP::ObjectId threadId); 201872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static void SuspendSelf(); 202872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes 203872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static bool GetThisObject(JDWP::ObjectId threadId, JDWP::FrameId frameId, JDWP::ObjectId* pThisId); 204dbb4079eb1e7d7738c81a97c8dd2550885c1093aElliott Hughes static void GetLocalValue(JDWP::ObjectId threadId, JDWP::FrameId frameId, int slot, JDWP::JdwpTag tag, uint8_t* buf, size_t expectedLen); 205dbb4079eb1e7d7738c81a97c8dd2550885c1093aElliott Hughes static void SetLocalValue(JDWP::ObjectId threadId, JDWP::FrameId frameId, int slot, JDWP::JdwpTag tag, uint64_t value, size_t width); 206872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes 207872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes /* 208872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes * Debugger notification 209872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes */ 210872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes enum { 211872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes kBreakPoint = 0x01, 212872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes kSingleStep = 0x02, 213872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes kMethodEntry = 0x04, 214872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes kMethodExit = 0x08, 215872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes }; 216872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static void PostLocationEvent(const Method* method, int pcOffset, Object* thisPtr, int eventFlags); 217872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static void PostException(void* throwFp, int throwRelPc, void* catchFp, int catchRelPc, Object* exception); 218872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static void PostThreadStart(Thread* t); 219872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static void PostThreadDeath(Thread* t); 220872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static void PostClassPrepare(Class* c); 221872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes 222872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static bool WatchLocation(const JDWP::JdwpLocation* pLoc); 223872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static void UnwatchLocation(const JDWP::JdwpLocation* pLoc); 224872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static bool ConfigureStep(JDWP::ObjectId threadId, JDWP::JdwpStepSize size, JDWP::JdwpStepDepth depth); 225872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static void UnconfigureStep(JDWP::ObjectId threadId); 226872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes 227aed4be94da51b4fbb54c728151f0daf11535f6abElliott Hughes static JDWP::JdwpError InvokeMethod(JDWP::ObjectId threadId, JDWP::ObjectId objectId, JDWP::RefTypeId classId, JDWP::MethodId methodId, uint32_t numArgs, uint64_t* argArray, uint32_t options, JDWP::JdwpTag* pResultTag, uint64_t* pResultValue, JDWP::ObjectId* pExceptObj); 228872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static void ExecuteMethod(DebugInvokeReq* pReq); 229872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes 230872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes /* perform "late registration" of an object ID */ 231872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static void RegisterObjectId(JDWP::ObjectId id); 232872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes 233872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes /* 234872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes * DDM support. 235872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes */ 2368218847294600bbfcdc041a46c2b579b6e70cf3bElliott Hughes static void DdmSendThreadNotification(Thread* t, uint32_t type); 23747fce01c0f27dba716fa6b97242562fbc5c26eeaElliott Hughes static void DdmSetThreadNotification(bool enable); 238872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static bool DdmHandlePacket(const uint8_t* buf, int dataLen, uint8_t** pReplyBuf, int* pReplyLen); 239872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static void DdmConnected(); 240872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes static void DdmDisconnected(); 24121f32d704a21bcd67d7b87b149b6314ff92946cbElliott Hughes static void DdmSendChunk(uint32_t type, const std::vector<uint8_t>& bytes); 2428218847294600bbfcdc041a46c2b579b6e70cf3bElliott Hughes static void DdmSendChunk(uint32_t type, size_t len, const uint8_t* buf); 2438218847294600bbfcdc041a46c2b579b6e70cf3bElliott Hughes static void DdmSendChunkV(uint32_t type, const struct iovec* iov, int iovcnt); 244767a147529da3ee8240f3ce4cd3af22ae454be64Elliott Hughes 245545a064aca775ba801790fced3d713d8a87bfc61Elliott Hughes /* 246545a064aca775ba801790fced3d713d8a87bfc61Elliott Hughes * Recent allocation tracking support. 247545a064aca775ba801790fced3d713d8a87bfc61Elliott Hughes */ 248545a064aca775ba801790fced3d713d8a87bfc61Elliott Hughes static void RecordAllocation(Class* type, size_t byte_count); 249545a064aca775ba801790fced3d713d8a87bfc61Elliott Hughes static void SetAllocTrackingEnabled(bool enabled); 250545a064aca775ba801790fced3d713d8a87bfc61Elliott Hughes static inline bool IsAllocTrackingEnabled() { return recent_allocation_records_ != NULL; } 251545a064aca775ba801790fced3d713d8a87bfc61Elliott Hughes static jbyteArray GetRecentAllocations(); 252545a064aca775ba801790fced3d713d8a87bfc61Elliott Hughes static void DumpRecentAllocations(); 253545a064aca775ba801790fced3d713d8a87bfc61Elliott Hughes 254767a147529da3ee8240f3ce4cd3af22ae454be64Elliott Hughes enum HpifWhen { 255767a147529da3ee8240f3ce4cd3af22ae454be64Elliott Hughes HPIF_WHEN_NEVER = 0, 256767a147529da3ee8240f3ce4cd3af22ae454be64Elliott Hughes HPIF_WHEN_NOW = 1, 257767a147529da3ee8240f3ce4cd3af22ae454be64Elliott Hughes HPIF_WHEN_NEXT_GC = 2, 258767a147529da3ee8240f3ce4cd3af22ae454be64Elliott Hughes HPIF_WHEN_EVERY_GC = 3 259767a147529da3ee8240f3ce4cd3af22ae454be64Elliott Hughes }; 260767a147529da3ee8240f3ce4cd3af22ae454be64Elliott Hughes static int DdmHandleHpifChunk(HpifWhen when); 261767a147529da3ee8240f3ce4cd3af22ae454be64Elliott Hughes 262767a147529da3ee8240f3ce4cd3af22ae454be64Elliott Hughes enum HpsgWhen { 263767a147529da3ee8240f3ce4cd3af22ae454be64Elliott Hughes HPSG_WHEN_NEVER = 0, 264767a147529da3ee8240f3ce4cd3af22ae454be64Elliott Hughes HPSG_WHEN_EVERY_GC = 1, 265767a147529da3ee8240f3ce4cd3af22ae454be64Elliott Hughes }; 266767a147529da3ee8240f3ce4cd3af22ae454be64Elliott Hughes enum HpsgWhat { 267767a147529da3ee8240f3ce4cd3af22ae454be64Elliott Hughes HPSG_WHAT_MERGED_OBJECTS = 0, 268767a147529da3ee8240f3ce4cd3af22ae454be64Elliott Hughes HPSG_WHAT_DISTINCT_OBJECTS = 1, 269767a147529da3ee8240f3ce4cd3af22ae454be64Elliott Hughes }; 270767a147529da3ee8240f3ce4cd3af22ae454be64Elliott Hughes static bool DdmHandleHpsgNhsgChunk(HpsgWhen when, HpsgWhat what, bool native); 271767a147529da3ee8240f3ce4cd3af22ae454be64Elliott Hughes 2727162ad937f5f6bec32bf78d4675ff65cd6d1a233Elliott Hughes static void DdmSendHeapInfo(HpifWhen reason); 2736a5bd495ff2f614f1495f652c86f3902d3bde537Elliott Hughes static void DdmSendHeapSegments(bool native); 274545a064aca775ba801790fced3d713d8a87bfc61Elliott Hughes 275545a064aca775ba801790fced3d713d8a87bfc61Elliott Hughes private: 276a215526d5c789cbef0f81a1f9aba22541a841ccaElliott Hughes static void DdmBroadcast(bool); 277a215526d5c789cbef0f81a1f9aba22541a841ccaElliott Hughes static void GetThreadGroupThreadsImpl(Object*, JDWP::ObjectId**, uint32_t*); 278a215526d5c789cbef0f81a1f9aba22541a841ccaElliott Hughes static void PostThreadStartOrStop(Thread*, uint32_t); 279a215526d5c789cbef0f81a1f9aba22541a841ccaElliott Hughes 280545a064aca775ba801790fced3d713d8a87bfc61Elliott Hughes static AllocRecord* recent_allocation_records_; 281872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes}; 282872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes 283872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes#define CHUNK_TYPE(_name) \ 2848218847294600bbfcdc041a46c2b579b6e70cf3bElliott Hughes static_cast<uint32_t>((_name)[0] << 24 | (_name)[1] << 16 | (_name)[2] << 8 | (_name)[3]) 285872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes 286872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes} // namespace art 287872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes 288872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes#endif // ART_DEBUGGER_H_ 289