debugger.h revision 767a147529da3ee8240f3ce4cd3af22ae454be64
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
33872d4ec7225444d9400d30f9027247deb91012fdElliott Hughesstruct Thread;
34872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes
35872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes/*
36872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes * Invoke-during-breakpoint support.
37872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes */
38872d4ec7225444d9400d30f9027247deb91012fdElliott Hughesstruct DebugInvokeReq {
39475fc23a4a7f35d1be87ea0b06c80df317a720acElliott Hughes  DebugInvokeReq() : lock_("a DebugInvokeReq lock"), cond_("a DebugInvokeReq condition variable") {
40475fc23a4a7f35d1be87ea0b06c80df317a720acElliott Hughes  }
41475fc23a4a7f35d1be87ea0b06c80df317a720acElliott Hughes
42872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  /* boolean; only set when we're in the tail end of an event handler */
43872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  bool ready;
44872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes
45872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  /* boolean; set if the JDWP thread wants this thread to do work */
46475fc23a4a7f35d1be87ea0b06c80df317a720acElliott Hughes  bool invoke_needed;
47872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes
48872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  /* request */
49872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  Object* obj;        /* not used for ClassType.InvokeMethod */
50872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  Object* thread;
51872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  Class* class_;
52872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  Method* method;
53475fc23a4a7f35d1be87ea0b06c80df317a720acElliott Hughes  uint32_t num_args;
54475fc23a4a7f35d1be87ea0b06c80df317a720acElliott Hughes  uint64_t* arg_array;   /* will be NULL if numArgs==0 */
55872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  uint32_t options;
56872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes
57872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  /* result */
58475fc23a4a7f35d1be87ea0b06c80df317a720acElliott Hughes  JDWP::JdwpError error;
59475fc23a4a7f35d1be87ea0b06c80df317a720acElliott Hughes  uint8_t result_tag;
60475fc23a4a7f35d1be87ea0b06c80df317a720acElliott Hughes  JValue result_value;
61475fc23a4a7f35d1be87ea0b06c80df317a720acElliott Hughes  JDWP::ObjectId exception;
62872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes
63872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  /* condition variable to wait on while the method executes */
64872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  Mutex lock_;
65872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  ConditionVariable cond_;
66872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes};
67872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes
68872d4ec7225444d9400d30f9027247deb91012fdElliott Hughesclass Dbg {
69872d4ec7225444d9400d30f9027247deb91012fdElliott Hughespublic:
703bb81563481d02b5a6349b8ed918392454e761d8Elliott Hughes  static bool ParseJdwpOptions(const std::string& options);
714ffd31315bc0d00ec278e85feed15985de5ac3dcElliott Hughes  static void SetJdwpAllowed(bool allowed);
724ffd31315bc0d00ec278e85feed15985de5ac3dcElliott Hughes
73d1cc8363d4f4bbac7568b1d02a5ca481cd10830fElliott Hughes  static void StartJdwp();
74d1cc8363d4f4bbac7568b1d02a5ca481cd10830fElliott Hughes  static void StopJdwp();
75d1cc8363d4f4bbac7568b1d02a5ca481cd10830fElliott Hughes
76767a147529da3ee8240f3ce4cd3af22ae454be64Elliott Hughes  // Invoked by the GC in case we need to keep DDMS informed.
77767a147529da3ee8240f3ce4cd3af22ae454be64Elliott Hughes  static void GcDidFinish();
78767a147529da3ee8240f3ce4cd3af22ae454be64Elliott Hughes
79872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  // Return the DebugInvokeReq for the current thread.
80872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static DebugInvokeReq* GetInvokeReq();
81872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes
82475fc23a4a7f35d1be87ea0b06c80df317a720acElliott Hughes  static Thread* GetDebugThread();
83475fc23a4a7f35d1be87ea0b06c80df317a720acElliott Hughes  static void ClearWaitForEventThread();
84475fc23a4a7f35d1be87ea0b06c80df317a720acElliott Hughes
85872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  /*
86872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes   * Enable/disable breakpoints and step modes.  Used to provide a heads-up
87872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes   * when the debugger attaches.
88872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes   */
89872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static void Connected();
90872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static void Active();
91872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static void Disconnected();
92872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes
93872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  /*
94872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes   * Returns "true" if a debugger is connected.  Returns "false" if it's
95872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes   * just DDM.
96872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes   */
97872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static bool IsDebuggerConnected();
98872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes
99872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static bool IsDebuggingEnabled();
100872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes
101872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  /*
102872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes   * Time, in milliseconds, since the last debugger activity.  Does not
103872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes   * include DDMS activity.  Returns -1 if there has been no activity.
104872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes   * Returns 0 if we're in the middle of handling a debugger request.
105872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes   */
106872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static int64_t LastDebuggerActivity();
107872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes
108872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  /*
109872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes   * Block/allow GC depending on what we're doing.  These return the old
110872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes   * status, which can be fed to ThreadContinuing() to restore the previous
111872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes   * mode.
112872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes   */
113872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static int ThreadRunning();
114872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static int ThreadWaiting();
115872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static int ThreadContinuing(int status);
116872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes
117872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static void UndoDebuggerSuspensions();
118872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes
119872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  // The debugger wants the VM to exit.
120872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static void Exit(int status);
121872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes
122bfe487be25652c5456236661b9d9c3579d2296c1Elliott Hughes  static void VisitRoots(Heap::RootVisitor* visitor, void* arg);
123bfe487be25652c5456236661b9d9c3579d2296c1Elliott Hughes
124872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  /*
125872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes   * Class, Object, Array
126872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes   */
127872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static const char* GetClassDescriptor(JDWP::RefTypeId id);
128872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static JDWP::ObjectId GetClassObject(JDWP::RefTypeId id);
129872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static JDWP::RefTypeId GetSuperclass(JDWP::RefTypeId id);
130872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static JDWP::ObjectId GetClassLoader(JDWP::RefTypeId id);
131872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static uint32_t GetAccessFlags(JDWP::RefTypeId id);
132872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static bool IsInterface(JDWP::RefTypeId id);
133872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static void GetClassList(uint32_t* pNumClasses, JDWP::RefTypeId** pClassRefBuf);
134872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static void GetVisibleClassList(JDWP::ObjectId classLoaderId, uint32_t* pNumClasses, JDWP::RefTypeId** pClassRefBuf);
135872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static void GetClassInfo(JDWP::RefTypeId classId, uint8_t* pTypeTag, uint32_t* pStatus, const char** pSignature);
136872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static bool FindLoadedClassBySignature(const char* classDescriptor, JDWP::RefTypeId* pRefTypeId);
137872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static void GetObjectType(JDWP::ObjectId objectId, uint8_t* pRefTypeTag, JDWP::RefTypeId* pRefTypeId);
138872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static uint8_t GetClassObjectType(JDWP::RefTypeId refTypeId);
139872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static const char* GetSignature(JDWP::RefTypeId refTypeId);
140872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static const char* GetSourceFile(JDWP::RefTypeId refTypeId);
141872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static const char* GetObjectTypeName(JDWP::ObjectId objectId);
142872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static uint8_t GetObjectTag(JDWP::ObjectId objectId);
143872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static int GetTagWidth(int tag);
144872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes
145872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static int GetArrayLength(JDWP::ObjectId arrayId);
146872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static uint8_t GetArrayElementTag(JDWP::ObjectId arrayId);
147872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static bool OutputArray(JDWP::ObjectId arrayId, int firstIndex, int count, JDWP::ExpandBuf* pReply);
148872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static bool SetArrayElements(JDWP::ObjectId arrayId, int firstIndex, int count, const uint8_t* buf);
149872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes
150872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static JDWP::ObjectId CreateString(const char* str);
151872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static JDWP::ObjectId CreateObject(JDWP::RefTypeId classId);
152872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static JDWP::ObjectId CreateArrayObject(JDWP::RefTypeId arrayTypeId, uint32_t length);
153872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes
154872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static bool MatchType(JDWP::RefTypeId instClassId, JDWP::RefTypeId classId);
155872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes
156872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  /*
157872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes   * Method and Field
158872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes   */
159872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static const char* GetMethodName(JDWP::RefTypeId refTypeId, JDWP::MethodId id);
160872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static void OutputAllFields(JDWP::RefTypeId refTypeId, bool withGeneric, JDWP::ExpandBuf* pReply);
161872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static void OutputAllMethods(JDWP::RefTypeId refTypeId, bool withGeneric, JDWP::ExpandBuf* pReply);
162872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static void OutputAllInterfaces(JDWP::RefTypeId refTypeId, JDWP::ExpandBuf* pReply);
163872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static void OutputLineTable(JDWP::RefTypeId refTypeId, JDWP::MethodId methodId, JDWP::ExpandBuf* pReply);
164872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static void OutputVariableTable(JDWP::RefTypeId refTypeId, JDWP::MethodId id, bool withGeneric, JDWP::ExpandBuf* pReply);
165872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes
166872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static uint8_t GetFieldBasicTag(JDWP::ObjectId objId, JDWP::FieldId fieldId);
167872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static uint8_t GetStaticFieldBasicTag(JDWP::RefTypeId refTypeId, JDWP::FieldId fieldId);
168872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static void GetFieldValue(JDWP::ObjectId objectId, JDWP::FieldId fieldId, JDWP::ExpandBuf* pReply);
169872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static void SetFieldValue(JDWP::ObjectId objectId, JDWP::FieldId fieldId, uint64_t value, int width);
170872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static void GetStaticFieldValue(JDWP::RefTypeId refTypeId, JDWP::FieldId fieldId, JDWP::ExpandBuf* pReply);
171872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static void SetStaticFieldValue(JDWP::RefTypeId refTypeId, JDWP::FieldId fieldId, uint64_t rawValue, int width);
172872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes
173872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static char* StringToUtf8(JDWP::ObjectId strId);
174872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes
175872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  /*
176872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes   * Thread, ThreadGroup, Frame
177872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes   */
178872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static char* GetThreadName(JDWP::ObjectId threadId);
179872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static JDWP::ObjectId GetThreadGroup(JDWP::ObjectId threadId);
180872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static char* GetThreadGroupName(JDWP::ObjectId threadGroupId);
181872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static JDWP::ObjectId GetThreadGroupParent(JDWP::ObjectId threadGroupId);
182872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static JDWP::ObjectId GetSystemThreadGroupId();
183872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static JDWP::ObjectId GetMainThreadGroupId();
184872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes
185872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static bool GetThreadStatus(JDWP::ObjectId threadId, uint32_t* threadStatus, uint32_t* suspendStatus);
186872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static uint32_t GetThreadSuspendCount(JDWP::ObjectId threadId);
187872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static bool ThreadExists(JDWP::ObjectId threadId);
188872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static bool IsSuspended(JDWP::ObjectId threadId);
189872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  //static void WaitForSuspend(JDWP::ObjectId threadId);
190872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static void GetThreadGroupThreads(JDWP::ObjectId threadGroupId, JDWP::ObjectId** ppThreadIds, uint32_t* pThreadCount);
191872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static void GetAllThreads(JDWP::ObjectId** ppThreadIds, uint32_t* pThreadCount);
192872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static int GetThreadFrameCount(JDWP::ObjectId threadId);
193872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static bool GetThreadFrame(JDWP::ObjectId threadId, int num, JDWP::FrameId* pFrameId, JDWP::JdwpLocation* pLoc);
194872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes
195872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static JDWP::ObjectId GetThreadSelfId();
196475fc23a4a7f35d1be87ea0b06c80df317a720acElliott Hughes  static void SuspendVM();
197872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static void ResumeVM();
198872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static void SuspendThread(JDWP::ObjectId threadId);
199872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static void ResumeThread(JDWP::ObjectId threadId);
200872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static void SuspendSelf();
201872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes
202872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static bool GetThisObject(JDWP::ObjectId threadId, JDWP::FrameId frameId, JDWP::ObjectId* pThisId);
203872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static void GetLocalValue(JDWP::ObjectId threadId, JDWP::FrameId frameId, int slot, uint8_t tag, uint8_t* buf, int expectedLen);
204872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static void SetLocalValue(JDWP::ObjectId threadId, JDWP::FrameId frameId, int slot, uint8_t tag, uint64_t value, int width);
205872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes
206872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  /*
207872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes   * Debugger notification
208872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes   */
209872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  enum {
210872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes    kBreakPoint     = 0x01,
211872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes    kSingleStep     = 0x02,
212872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes    kMethodEntry    = 0x04,
213872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes    kMethodExit     = 0x08,
214872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  };
215872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static void PostLocationEvent(const Method* method, int pcOffset, Object* thisPtr, int eventFlags);
216872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static void PostException(void* throwFp, int throwRelPc, void* catchFp, int catchRelPc, Object* exception);
217872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static void PostThreadStart(Thread* t);
218872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static void PostThreadDeath(Thread* t);
219872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static void PostClassPrepare(Class* c);
220872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes
221872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static bool WatchLocation(const JDWP::JdwpLocation* pLoc);
222872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static void UnwatchLocation(const JDWP::JdwpLocation* pLoc);
223872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static bool ConfigureStep(JDWP::ObjectId threadId, JDWP::JdwpStepSize size, JDWP::JdwpStepDepth depth);
224872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static void UnconfigureStep(JDWP::ObjectId threadId);
225872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes
226872d4ec7225444d9400d30f9027247deb91012fdElliott 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, uint8_t* pResultTag, uint64_t* pResultValue, JDWP::ObjectId* pExceptObj);
227872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static void ExecuteMethod(DebugInvokeReq* pReq);
228872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes
229872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  /* perform "late registration" of an object ID */
230872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static void RegisterObjectId(JDWP::ObjectId id);
231872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes
232872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  /*
233872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes   * DDM support.
234872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes   */
23547fce01c0f27dba716fa6b97242562fbc5c26eeaElliott Hughes  static void DdmSetThreadNotification(bool enable);
236872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static bool DdmHandlePacket(const uint8_t* buf, int dataLen, uint8_t** pReplyBuf, int* pReplyLen);
237872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static void DdmConnected();
238872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static void DdmDisconnected();
239872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static void DdmSendChunk(int type, size_t len, const uint8_t* buf);
240872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static void DdmSendChunkV(int type, const struct iovec* iov, int iovcnt);
241767a147529da3ee8240f3ce4cd3af22ae454be64Elliott Hughes
242767a147529da3ee8240f3ce4cd3af22ae454be64Elliott Hughes  enum HpifWhen {
243767a147529da3ee8240f3ce4cd3af22ae454be64Elliott Hughes    HPIF_WHEN_NEVER = 0,
244767a147529da3ee8240f3ce4cd3af22ae454be64Elliott Hughes    HPIF_WHEN_NOW = 1,
245767a147529da3ee8240f3ce4cd3af22ae454be64Elliott Hughes    HPIF_WHEN_NEXT_GC = 2,
246767a147529da3ee8240f3ce4cd3af22ae454be64Elliott Hughes    HPIF_WHEN_EVERY_GC = 3
247767a147529da3ee8240f3ce4cd3af22ae454be64Elliott Hughes  };
248767a147529da3ee8240f3ce4cd3af22ae454be64Elliott Hughes  static int DdmHandleHpifChunk(HpifWhen when);
249767a147529da3ee8240f3ce4cd3af22ae454be64Elliott Hughes
250767a147529da3ee8240f3ce4cd3af22ae454be64Elliott Hughes  enum HpsgWhen {
251767a147529da3ee8240f3ce4cd3af22ae454be64Elliott Hughes    HPSG_WHEN_NEVER = 0,
252767a147529da3ee8240f3ce4cd3af22ae454be64Elliott Hughes    HPSG_WHEN_EVERY_GC = 1,
253767a147529da3ee8240f3ce4cd3af22ae454be64Elliott Hughes  };
254767a147529da3ee8240f3ce4cd3af22ae454be64Elliott Hughes  enum HpsgWhat {
255767a147529da3ee8240f3ce4cd3af22ae454be64Elliott Hughes    HPSG_WHAT_MERGED_OBJECTS = 0,
256767a147529da3ee8240f3ce4cd3af22ae454be64Elliott Hughes    HPSG_WHAT_DISTINCT_OBJECTS = 1,
257767a147529da3ee8240f3ce4cd3af22ae454be64Elliott Hughes  };
258767a147529da3ee8240f3ce4cd3af22ae454be64Elliott Hughes  static bool DdmHandleHpsgNhsgChunk(HpsgWhen when, HpsgWhat what, bool native);
259767a147529da3ee8240f3ce4cd3af22ae454be64Elliott Hughes
260767a147529da3ee8240f3ce4cd3af22ae454be64Elliott Hughes  static void DdmSendHeapInfo(HpifWhen reason, bool shouldLock);
261767a147529da3ee8240f3ce4cd3af22ae454be64Elliott Hughes  static void DdmSendHeapSegments(bool shouldLock, bool native);
262872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes};
263872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes
264872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes#define CHUNK_TYPE(_name) \
265872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes    ((_name)[0] << 24 | (_name)[1] << 16 | (_name)[2] << 8 | (_name)[3])
266872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes
267872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes}  // namespace art
268872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes
269872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes#endif  // ART_DEBUGGER_H_
270