debugger.h revision 7b3cdfcca472b779cf8745fb8460935e56229f11
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 {
407b3cdfcca472b779cf8745fb8460935e56229f11Elliott Hughes  DebugInvokeReq()
417b3cdfcca472b779cf8745fb8460935e56229f11Elliott Hughes      : invoke_needed_(false),
427b3cdfcca472b779cf8745fb8460935e56229f11Elliott Hughes        lock_("a DebugInvokeReq lock"),
437b3cdfcca472b779cf8745fb8460935e56229f11Elliott Hughes        cond_("a DebugInvokeReq condition variable") {
44475fc23a4a7f35d1be87ea0b06c80df317a720acElliott Hughes  }
45475fc23a4a7f35d1be87ea0b06c80df317a720acElliott Hughes
46872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  /* boolean; only set when we're in the tail end of an event handler */
47872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  bool ready;
48872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes
49872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  /* boolean; set if the JDWP thread wants this thread to do work */
50d07986fad0d08cdf05505cf9230714a2cf0dd9aeElliott Hughes  bool invoke_needed_;
51872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes
52872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  /* request */
53d07986fad0d08cdf05505cf9230714a2cf0dd9aeElliott Hughes  Object* receiver_;      /* not used for ClassType.InvokeMethod */
54d07986fad0d08cdf05505cf9230714a2cf0dd9aeElliott Hughes  Object* thread_;
55872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  Class* class_;
56d07986fad0d08cdf05505cf9230714a2cf0dd9aeElliott Hughes  Method* method_;
57d07986fad0d08cdf05505cf9230714a2cf0dd9aeElliott Hughes  uint32_t num_args_;
58d07986fad0d08cdf05505cf9230714a2cf0dd9aeElliott Hughes  uint64_t* arg_array_;   /* will be NULL if numArgs==0 */
59d07986fad0d08cdf05505cf9230714a2cf0dd9aeElliott Hughes  uint32_t options_;
60872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes
61872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  /* result */
62475fc23a4a7f35d1be87ea0b06c80df317a720acElliott Hughes  JDWP::JdwpError error;
63d07986fad0d08cdf05505cf9230714a2cf0dd9aeElliott Hughes  JDWP::JdwpTag result_tag;
64475fc23a4a7f35d1be87ea0b06c80df317a720acElliott Hughes  JValue result_value;
65475fc23a4a7f35d1be87ea0b06c80df317a720acElliott Hughes  JDWP::ObjectId exception;
66872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes
67872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  /* condition variable to wait on while the method executes */
68872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  Mutex lock_;
69872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  ConditionVariable cond_;
70872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes};
71872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes
72872d4ec7225444d9400d30f9027247deb91012fdElliott Hughesclass Dbg {
73872d4ec7225444d9400d30f9027247deb91012fdElliott Hughespublic:
743bb81563481d02b5a6349b8ed918392454e761d8Elliott Hughes  static bool ParseJdwpOptions(const std::string& options);
754ffd31315bc0d00ec278e85feed15985de5ac3dcElliott Hughes  static void SetJdwpAllowed(bool allowed);
764ffd31315bc0d00ec278e85feed15985de5ac3dcElliott Hughes
77d1cc8363d4f4bbac7568b1d02a5ca481cd10830fElliott Hughes  static void StartJdwp();
78d1cc8363d4f4bbac7568b1d02a5ca481cd10830fElliott Hughes  static void StopJdwp();
79d1cc8363d4f4bbac7568b1d02a5ca481cd10830fElliott Hughes
80767a147529da3ee8240f3ce4cd3af22ae454be64Elliott Hughes  // Invoked by the GC in case we need to keep DDMS informed.
81767a147529da3ee8240f3ce4cd3af22ae454be64Elliott Hughes  static void GcDidFinish();
82767a147529da3ee8240f3ce4cd3af22ae454be64Elliott Hughes
83872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  // Return the DebugInvokeReq for the current thread.
84872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static DebugInvokeReq* GetInvokeReq();
85872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes
86475fc23a4a7f35d1be87ea0b06c80df317a720acElliott Hughes  static Thread* GetDebugThread();
87475fc23a4a7f35d1be87ea0b06c80df317a720acElliott Hughes  static void ClearWaitForEventThread();
88475fc23a4a7f35d1be87ea0b06c80df317a720acElliott Hughes
89872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  /*
90872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes   * Enable/disable breakpoints and step modes.  Used to provide a heads-up
91872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes   * when the debugger attaches.
92872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes   */
93872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static void Connected();
94a215526d5c789cbef0f81a1f9aba22541a841ccaElliott Hughes  static void GoActive();
95872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static void Disconnected();
96872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes
97872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  /*
98872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes   * Returns "true" if a debugger is connected.  Returns "false" if it's
99872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes   * just DDM.
100872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes   */
101872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static bool IsDebuggerConnected();
102872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes
103872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static bool IsDebuggingEnabled();
104872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes
105872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  /*
106872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes   * Time, in milliseconds, since the last debugger activity.  Does not
107872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes   * include DDMS activity.  Returns -1 if there has been no activity.
108872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes   * Returns 0 if we're in the middle of handling a debugger request.
109872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes   */
110872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static int64_t LastDebuggerActivity();
111872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes
112872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  /*
113872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes   * Block/allow GC depending on what we're doing.  These return the old
114872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes   * status, which can be fed to ThreadContinuing() to restore the previous
115872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes   * mode.
116872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes   */
117872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static int ThreadRunning();
118872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static int ThreadWaiting();
119872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static int ThreadContinuing(int status);
120872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes
121872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static void UndoDebuggerSuspensions();
122872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes
123872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  // The debugger wants the VM to exit.
124872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static void Exit(int status);
125872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes
126bfe487be25652c5456236661b9d9c3579d2296c1Elliott Hughes  static void VisitRoots(Heap::RootVisitor* visitor, void* arg);
127bfe487be25652c5456236661b9d9c3579d2296c1Elliott Hughes
128872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  /*
129872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes   * Class, Object, Array
130872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes   */
131a215526d5c789cbef0f81a1f9aba22541a841ccaElliott Hughes  static std::string GetClassDescriptor(JDWP::RefTypeId id);
1327b3cdfcca472b779cf8745fb8460935e56229f11Elliott Hughes  static bool GetClassObject(JDWP::RefTypeId id, JDWP::ObjectId& classObjectId);
1337b3cdfcca472b779cf8745fb8460935e56229f11Elliott Hughes  static bool GetSuperclass(JDWP::RefTypeId id, JDWP::RefTypeId& superclassId);
134872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static JDWP::ObjectId GetClassLoader(JDWP::RefTypeId id);
1357b3cdfcca472b779cf8745fb8460935e56229f11Elliott Hughes  static bool GetAccessFlags(JDWP::RefTypeId id, uint32_t& access_flags);
1367b3cdfcca472b779cf8745fb8460935e56229f11Elliott Hughes  static bool IsInterface(JDWP::RefTypeId classId, bool& is_interface);
1377b3cdfcca472b779cf8745fb8460935e56229f11Elliott Hughes  static void GetClassList(std::vector<JDWP::RefTypeId>& classes);
138872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static void GetVisibleClassList(JDWP::ObjectId classLoaderId, uint32_t* pNumClasses, JDWP::RefTypeId** pClassRefBuf);
1397b3cdfcca472b779cf8745fb8460935e56229f11Elliott Hughes  static bool GetClassInfo(JDWP::RefTypeId classId, JDWP::JdwpTypeTag* pTypeTag, uint32_t* pStatus, std::string* pDescriptor);
1407b3cdfcca472b779cf8745fb8460935e56229f11Elliott Hughes  static void FindLoadedClassBySignature(const std::string& descriptor, std::vector<JDWP::RefTypeId>& ids);
1416fa602d614d418f38afebb4d44f42e7dc0b4bd94Elliott Hughes  static void GetObjectType(JDWP::ObjectId objectId, JDWP::JdwpTypeTag* pRefTypeTag, JDWP::RefTypeId* pRefTypeId);
142872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static uint8_t GetClassObjectType(JDWP::RefTypeId refTypeId);
1437b3cdfcca472b779cf8745fb8460935e56229f11Elliott Hughes  static bool GetSignature(JDWP::RefTypeId refTypeId, std::string& signature);
14403181a828cd493545b278e0aa4f150fdaf1e3325Elliott Hughes  static bool GetSourceFile(JDWP::RefTypeId refTypeId, std::string& source_file);
145872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static uint8_t GetObjectTag(JDWP::ObjectId objectId);
146aed4be94da51b4fbb54c728151f0daf11535f6abElliott Hughes  static size_t GetTagWidth(JDWP::JdwpTag tag);
147872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes
148872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static int GetArrayLength(JDWP::ObjectId arrayId);
149872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static uint8_t GetArrayElementTag(JDWP::ObjectId arrayId);
150872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static bool OutputArray(JDWP::ObjectId arrayId, int firstIndex, int count, JDWP::ExpandBuf* pReply);
151872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static bool SetArrayElements(JDWP::ObjectId arrayId, int firstIndex, int count, const uint8_t* buf);
152872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes
1537b3cdfcca472b779cf8745fb8460935e56229f11Elliott Hughes  static JDWP::ObjectId CreateString(const std::string& str);
1547b3cdfcca472b779cf8745fb8460935e56229f11Elliott Hughes  static bool CreateObject(JDWP::RefTypeId classId, JDWP::ObjectId& new_object);
1557b3cdfcca472b779cf8745fb8460935e56229f11Elliott Hughes  static bool CreateArrayObject(JDWP::RefTypeId arrayTypeId, uint32_t length, JDWP::ObjectId& new_array);
156872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes
157872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static bool MatchType(JDWP::RefTypeId instClassId, JDWP::RefTypeId classId);
158872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes
159872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  /*
160872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes   * Method and Field
161872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes   */
16203181a828cd493545b278e0aa4f150fdaf1e3325Elliott Hughes  static std::string GetMethodName(JDWP::RefTypeId refTypeId, JDWP::MethodId id);
1637b3cdfcca472b779cf8745fb8460935e56229f11Elliott Hughes  static bool OutputDeclaredFields(JDWP::RefTypeId refTypeId, bool withGeneric, JDWP::ExpandBuf* pReply);
1647b3cdfcca472b779cf8745fb8460935e56229f11Elliott Hughes  static bool OutputDeclaredMethods(JDWP::RefTypeId refTypeId, bool withGeneric, JDWP::ExpandBuf* pReply);
1657b3cdfcca472b779cf8745fb8460935e56229f11Elliott Hughes  static bool OutputDeclaredInterfaces(JDWP::RefTypeId refTypeId, JDWP::ExpandBuf* pReply);
166872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static void OutputLineTable(JDWP::RefTypeId refTypeId, JDWP::MethodId methodId, JDWP::ExpandBuf* pReply);
167872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static void OutputVariableTable(JDWP::RefTypeId refTypeId, JDWP::MethodId id, bool withGeneric, JDWP::ExpandBuf* pReply);
168872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes
169aed4be94da51b4fbb54c728151f0daf11535f6abElliott Hughes  static JDWP::JdwpTag GetFieldBasicTag(JDWP::FieldId fieldId);
170aed4be94da51b4fbb54c728151f0daf11535f6abElliott Hughes  static JDWP::JdwpTag GetStaticFieldBasicTag(JDWP::FieldId fieldId);
171872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static void GetFieldValue(JDWP::ObjectId objectId, JDWP::FieldId fieldId, JDWP::ExpandBuf* pReply);
172872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static void SetFieldValue(JDWP::ObjectId objectId, JDWP::FieldId fieldId, uint64_t value, int width);
1736fa602d614d418f38afebb4d44f42e7dc0b4bd94Elliott Hughes  static void GetStaticFieldValue(JDWP::FieldId fieldId, JDWP::ExpandBuf* pReply);
1746fa602d614d418f38afebb4d44f42e7dc0b4bd94Elliott Hughes  static void SetStaticFieldValue(JDWP::FieldId fieldId, uint64_t value, int width);
175872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes
17668fdbd07fc2b8856905e06f3cc945b046c3bfcd3Elliott Hughes  static std::string StringToUtf8(JDWP::ObjectId strId);
177872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes
178872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  /*
179872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes   * Thread, ThreadGroup, Frame
180872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes   */
181a2e54f61453a2072181d5dd7aa2d5e845f5b53f6Elliott Hughes  static bool GetThreadName(JDWP::ObjectId threadId, std::string& name);
182872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static JDWP::ObjectId GetThreadGroup(JDWP::ObjectId threadId);
183499c5133d361e7c659fc38e5ccfeb1280a7996f5Elliott Hughes  static std::string GetThreadGroupName(JDWP::ObjectId threadGroupId);
184872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static JDWP::ObjectId GetThreadGroupParent(JDWP::ObjectId threadGroupId);
185872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static JDWP::ObjectId GetSystemThreadGroupId();
186872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static JDWP::ObjectId GetMainThreadGroupId();
187872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes
1883d30d9b09c16542d41554aad9f46ec9109ba5cb5Elliott Hughes  static bool GetThreadStatus(JDWP::ObjectId threadId, JDWP::JdwpThreadStatus* pThreadStatus, JDWP::JdwpSuspendStatus* pSuspendStatus);
189872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static uint32_t GetThreadSuspendCount(JDWP::ObjectId threadId);
190872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static bool ThreadExists(JDWP::ObjectId threadId);
191872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static bool IsSuspended(JDWP::ObjectId threadId);
192872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  //static void WaitForSuspend(JDWP::ObjectId threadId);
193872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static void GetThreadGroupThreads(JDWP::ObjectId threadGroupId, JDWP::ObjectId** ppThreadIds, uint32_t* pThreadCount);
194872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static void GetAllThreads(JDWP::ObjectId** ppThreadIds, uint32_t* pThreadCount);
195872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static int GetThreadFrameCount(JDWP::ObjectId threadId);
196872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static bool GetThreadFrame(JDWP::ObjectId threadId, int num, JDWP::FrameId* pFrameId, JDWP::JdwpLocation* pLoc);
197872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes
198872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static JDWP::ObjectId GetThreadSelfId();
199475fc23a4a7f35d1be87ea0b06c80df317a720acElliott Hughes  static void SuspendVM();
200872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static void ResumeVM();
201872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static void SuspendThread(JDWP::ObjectId threadId);
202872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static void ResumeThread(JDWP::ObjectId threadId);
203872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static void SuspendSelf();
204872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes
205d07986fad0d08cdf05505cf9230714a2cf0dd9aeElliott Hughes  static bool GetThisObject(JDWP::FrameId frameId, JDWP::ObjectId* pThisId);
206dbb4079eb1e7d7738c81a97c8dd2550885c1093aElliott Hughes  static void GetLocalValue(JDWP::ObjectId threadId, JDWP::FrameId frameId, int slot, JDWP::JdwpTag tag, uint8_t* buf, size_t expectedLen);
207dbb4079eb1e7d7738c81a97c8dd2550885c1093aElliott Hughes  static void SetLocalValue(JDWP::ObjectId threadId, JDWP::FrameId frameId, int slot, JDWP::JdwpTag tag, uint64_t value, size_t width);
208872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes
209872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  /*
210872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes   * Debugger notification
211872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes   */
212872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  enum {
213872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes    kBreakPoint     = 0x01,
214872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes    kSingleStep     = 0x02,
215872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes    kMethodEntry    = 0x04,
216872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes    kMethodExit     = 0x08,
217872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  };
218872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static void PostLocationEvent(const Method* method, int pcOffset, Object* thisPtr, int eventFlags);
219d07986fad0d08cdf05505cf9230714a2cf0dd9aeElliott Hughes  static void PostException(Method** sp, Method* throwMethod, uintptr_t throwNativePc, Method* catchMethod, uintptr_t catchNativePc, Object* exception);
220872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static void PostThreadStart(Thread* t);
221872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static void PostThreadDeath(Thread* t);
222872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static void PostClassPrepare(Class* c);
223872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes
224872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static bool WatchLocation(const JDWP::JdwpLocation* pLoc);
225872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static void UnwatchLocation(const JDWP::JdwpLocation* pLoc);
226872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static bool ConfigureStep(JDWP::ObjectId threadId, JDWP::JdwpStepSize size, JDWP::JdwpStepDepth depth);
227872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static void UnconfigureStep(JDWP::ObjectId threadId);
228872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes
229aed4be94da51b4fbb54c728151f0daf11535f6abElliott 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);
230872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static void ExecuteMethod(DebugInvokeReq* pReq);
231872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes
232872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  /* perform "late registration" of an object ID */
233872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static void RegisterObjectId(JDWP::ObjectId id);
234872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes
235872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  /*
236872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes   * DDM support.
237872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes   */
2388218847294600bbfcdc041a46c2b579b6e70cf3bElliott Hughes  static void DdmSendThreadNotification(Thread* t, uint32_t type);
23947fce01c0f27dba716fa6b97242562fbc5c26eeaElliott Hughes  static void DdmSetThreadNotification(bool enable);
240872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static bool DdmHandlePacket(const uint8_t* buf, int dataLen, uint8_t** pReplyBuf, int* pReplyLen);
241872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static void DdmConnected();
242872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes  static void DdmDisconnected();
24321f32d704a21bcd67d7b87b149b6314ff92946cbElliott Hughes  static void DdmSendChunk(uint32_t type, const std::vector<uint8_t>& bytes);
2448218847294600bbfcdc041a46c2b579b6e70cf3bElliott Hughes  static void DdmSendChunk(uint32_t type, size_t len, const uint8_t* buf);
245cccd84f1f972f1a260c3be418c8388a5d30cf59eElliott Hughes  static void DdmSendChunkV(uint32_t type, const struct iovec* iov, int iov_count);
246767a147529da3ee8240f3ce4cd3af22ae454be64Elliott Hughes
247545a064aca775ba801790fced3d713d8a87bfc61Elliott Hughes  /*
248545a064aca775ba801790fced3d713d8a87bfc61Elliott Hughes   * Recent allocation tracking support.
249545a064aca775ba801790fced3d713d8a87bfc61Elliott Hughes   */
250545a064aca775ba801790fced3d713d8a87bfc61Elliott Hughes  static void RecordAllocation(Class* type, size_t byte_count);
251545a064aca775ba801790fced3d713d8a87bfc61Elliott Hughes  static void SetAllocTrackingEnabled(bool enabled);
252545a064aca775ba801790fced3d713d8a87bfc61Elliott Hughes  static inline bool IsAllocTrackingEnabled() { return recent_allocation_records_ != NULL; }
253545a064aca775ba801790fced3d713d8a87bfc61Elliott Hughes  static jbyteArray GetRecentAllocations();
254545a064aca775ba801790fced3d713d8a87bfc61Elliott Hughes  static void DumpRecentAllocations();
255545a064aca775ba801790fced3d713d8a87bfc61Elliott Hughes
256767a147529da3ee8240f3ce4cd3af22ae454be64Elliott Hughes  enum HpifWhen {
257767a147529da3ee8240f3ce4cd3af22ae454be64Elliott Hughes    HPIF_WHEN_NEVER = 0,
258767a147529da3ee8240f3ce4cd3af22ae454be64Elliott Hughes    HPIF_WHEN_NOW = 1,
259767a147529da3ee8240f3ce4cd3af22ae454be64Elliott Hughes    HPIF_WHEN_NEXT_GC = 2,
260767a147529da3ee8240f3ce4cd3af22ae454be64Elliott Hughes    HPIF_WHEN_EVERY_GC = 3
261767a147529da3ee8240f3ce4cd3af22ae454be64Elliott Hughes  };
262767a147529da3ee8240f3ce4cd3af22ae454be64Elliott Hughes  static int DdmHandleHpifChunk(HpifWhen when);
263767a147529da3ee8240f3ce4cd3af22ae454be64Elliott Hughes
264767a147529da3ee8240f3ce4cd3af22ae454be64Elliott Hughes  enum HpsgWhen {
265767a147529da3ee8240f3ce4cd3af22ae454be64Elliott Hughes    HPSG_WHEN_NEVER = 0,
266767a147529da3ee8240f3ce4cd3af22ae454be64Elliott Hughes    HPSG_WHEN_EVERY_GC = 1,
267767a147529da3ee8240f3ce4cd3af22ae454be64Elliott Hughes  };
268767a147529da3ee8240f3ce4cd3af22ae454be64Elliott Hughes  enum HpsgWhat {
269767a147529da3ee8240f3ce4cd3af22ae454be64Elliott Hughes    HPSG_WHAT_MERGED_OBJECTS = 0,
270767a147529da3ee8240f3ce4cd3af22ae454be64Elliott Hughes    HPSG_WHAT_DISTINCT_OBJECTS = 1,
271767a147529da3ee8240f3ce4cd3af22ae454be64Elliott Hughes  };
272767a147529da3ee8240f3ce4cd3af22ae454be64Elliott Hughes  static bool DdmHandleHpsgNhsgChunk(HpsgWhen when, HpsgWhat what, bool native);
273767a147529da3ee8240f3ce4cd3af22ae454be64Elliott Hughes
2747162ad937f5f6bec32bf78d4675ff65cd6d1a233Elliott Hughes  static void DdmSendHeapInfo(HpifWhen reason);
2756a5bd495ff2f614f1495f652c86f3902d3bde537Elliott Hughes  static void DdmSendHeapSegments(bool native);
276545a064aca775ba801790fced3d713d8a87bfc61Elliott Hughes
277545a064aca775ba801790fced3d713d8a87bfc61Elliott Hughes private:
278a215526d5c789cbef0f81a1f9aba22541a841ccaElliott Hughes  static void DdmBroadcast(bool);
279a215526d5c789cbef0f81a1f9aba22541a841ccaElliott Hughes  static void GetThreadGroupThreadsImpl(Object*, JDWP::ObjectId**, uint32_t*);
280a215526d5c789cbef0f81a1f9aba22541a841ccaElliott Hughes  static void PostThreadStartOrStop(Thread*, uint32_t);
281a215526d5c789cbef0f81a1f9aba22541a841ccaElliott Hughes
282545a064aca775ba801790fced3d713d8a87bfc61Elliott Hughes  static AllocRecord* recent_allocation_records_;
283872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes};
284872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes
285872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes#define CHUNK_TYPE(_name) \
2868218847294600bbfcdc041a46c2b579b6e70cf3bElliott Hughes    static_cast<uint32_t>((_name)[0] << 24 | (_name)[1] << 16 | (_name)[2] << 8 | (_name)[3])
287872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes
288872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes}  // namespace art
289872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes
290872d4ec7225444d9400d30f9027247deb91012fdElliott Hughes#endif  // ART_DEBUGGER_H_
291