blob: c03adeadd81088436a7ce3dd8b12243969351edd [file] [log] [blame]
Elliott Hughes872d4ec2011-10-21 17:07:15 -07001/*
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 Hughes3bb81562011-10-21 18:52:59 -070026#include <string>
27
Elliott Hughes872d4ec2011-10-21 17:07:15 -070028#include "jdwp/jdwp.h"
Elliott Hughes3bb81562011-10-21 18:52:59 -070029#include "object.h"
Elliott Hughes872d4ec2011-10-21 17:07:15 -070030
31namespace art {
32
Elliott Hughes545a0642011-11-08 19:10:03 -080033struct AllocRecord;
Ian Rogers1b09b092012-08-20 15:35:52 -070034class Thread;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070035
36/*
37 * Invoke-during-breakpoint support.
38 */
39struct DebugInvokeReq {
Elliott Hughes7b3cdfc2011-12-08 21:28:17 -080040 DebugInvokeReq()
Ian Rogers00f7d0e2012-07-19 15:28:27 -070041 : ready(false), invoke_needed_(false),
42 receiver_(NULL), thread_(NULL), class_(NULL), method_(NULL),
43 arg_count_(0), arg_values_(NULL), options_(0), error(JDWP::ERR_NONE),
44 result_tag(JDWP::JT_VOID), exception(0),
jeffhao9b5aa6f2012-12-18 11:47:11 -080045 lock_("a DebugInvokeReq lock", kBreakpointInvokeLock),
Ian Rogersc604d732012-10-14 16:09:54 -070046 cond_("a DebugInvokeReq condition variable", lock_) {
Elliott Hughes475fc232011-10-25 15:00:35 -070047 }
48
Elliott Hughes872d4ec2011-10-21 17:07:15 -070049 /* boolean; only set when we're in the tail end of an event handler */
50 bool ready;
51
52 /* boolean; set if the JDWP thread wants this thread to do work */
Elliott Hughesd07986f2011-12-06 18:27:45 -080053 bool invoke_needed_;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070054
55 /* request */
Elliott Hughesd07986f2011-12-06 18:27:45 -080056 Object* receiver_; /* not used for ClassType.InvokeMethod */
57 Object* thread_;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070058 Class* class_;
Mathieu Chartier66f19252012-09-18 08:57:04 -070059 AbstractMethod* method_;
Elliott Hughes45651fd2012-02-21 15:48:20 -080060 uint32_t arg_count_;
61 uint64_t* arg_values_; /* will be NULL if arg_count_ == 0 */
Elliott Hughesd07986f2011-12-06 18:27:45 -080062 uint32_t options_;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070063
64 /* result */
Elliott Hughes475fc232011-10-25 15:00:35 -070065 JDWP::JdwpError error;
Elliott Hughesd07986f2011-12-06 18:27:45 -080066 JDWP::JdwpTag result_tag;
Elliott Hughes475fc232011-10-25 15:00:35 -070067 JValue result_value;
68 JDWP::ObjectId exception;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070069
70 /* condition variable to wait on while the method executes */
Ian Rogersc604d732012-10-14 16:09:54 -070071 Mutex lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
72 ConditionVariable cond_ GUARDED_BY(lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -070073};
74
75class Dbg {
Elliott Hughesff17f1f2012-01-24 18:12:29 -080076 public:
Elliott Hughes3bb81562011-10-21 18:52:59 -070077 static bool ParseJdwpOptions(const std::string& options);
Elliott Hughes4ffd3132011-10-24 12:06:42 -070078 static void SetJdwpAllowed(bool allowed);
79
Elliott Hughesd1cc8362011-10-24 16:58:50 -070080 static void StartJdwp();
81 static void StopJdwp();
82
Elliott Hughes767a1472011-10-26 18:49:02 -070083 // Invoked by the GC in case we need to keep DDMS informed.
Ian Rogersb726dcb2012-09-05 08:57:23 -070084 static void GcDidFinish() LOCKS_EXCLUDED(Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -070085
Elliott Hughes872d4ec2011-10-21 17:07:15 -070086 // Return the DebugInvokeReq for the current thread.
87 static DebugInvokeReq* GetInvokeReq();
88
Elliott Hughes475fc232011-10-25 15:00:35 -070089 static Thread* GetDebugThread();
90 static void ClearWaitForEventThread();
91
Elliott Hughes872d4ec2011-10-21 17:07:15 -070092 /*
93 * Enable/disable breakpoints and step modes. Used to provide a heads-up
94 * when the debugger attaches.
95 */
96 static void Connected();
jeffhao09bfc6a2012-12-11 18:11:43 -080097 static void GoActive() LOCKS_EXCLUDED(Locks::breakpoint_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -070098 static void Disconnected();
Elliott Hughes86964332012-02-15 19:37:42 -080099 static void Disposed();
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700100
Elliott Hughesc0f09332012-03-26 13:27:06 -0700101 // Returns true if we're actually debugging with a real debugger, false if it's
102 // just DDMS (or nothing at all).
103 static bool IsDebuggerActive();
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700104
Elliott Hughesc0f09332012-03-26 13:27:06 -0700105 // Returns true if we had -Xrunjdwp or -agentlib:jdwp= on the command line.
106 static bool IsJdwpConfigured();
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700107
Elliott Hughes86964332012-02-15 19:37:42 -0800108 static bool IsDisposed();
109
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700110 /*
111 * Time, in milliseconds, since the last debugger activity. Does not
112 * include DDMS activity. Returns -1 if there has been no activity.
113 * Returns 0 if we're in the middle of handling a debugger request.
114 */
115 static int64_t LastDebuggerActivity();
116
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700117 static void UndoDebuggerSuspensions();
118
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700119 static void Exit(int status);
120
Elliott Hughesbfe487b2011-10-26 15:48:55 -0700121 static void VisitRoots(Heap::RootVisitor* visitor, void* arg);
122
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700123 /*
124 * Class, Object, Array
125 */
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700126 static std::string GetClassName(JDWP::RefTypeId id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700127 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800128 static JDWP::JdwpError GetClassObject(JDWP::RefTypeId id, JDWP::ObjectId& class_object_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700129 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800130 static JDWP::JdwpError GetSuperclass(JDWP::RefTypeId id, JDWP::RefTypeId& superclass_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700131 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700132 static JDWP::JdwpError GetClassLoader(JDWP::RefTypeId id, JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700133 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700134 static JDWP::JdwpError GetModifiers(JDWP::RefTypeId id, JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700135 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800136 static JDWP::JdwpError GetReflectedType(JDWP::RefTypeId class_id, JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700137 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700138 static void GetClassList(std::vector<JDWP::RefTypeId>& classes)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700139 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800140 static JDWP::JdwpError GetClassInfo(JDWP::RefTypeId class_id, JDWP::JdwpTypeTag* pTypeTag,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700141 uint32_t* pStatus, std::string* pDescriptor)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700142 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700143 static void FindLoadedClassBySignature(const char* descriptor, std::vector<JDWP::RefTypeId>& ids)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700144 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800145 static JDWP::JdwpError GetReferenceType(JDWP::ObjectId object_id, JDWP::ExpandBuf* pReply);
146 static JDWP::JdwpError GetSignature(JDWP::RefTypeId ref_type_id, std::string& signature)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700147 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800148 static JDWP::JdwpError GetSourceFile(JDWP::RefTypeId ref_type_id, std::string& source_file)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700149 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800150 static JDWP::JdwpError GetObjectTag(JDWP::ObjectId object_id, uint8_t& tag)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700151 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughesaed4be92011-12-02 16:16:23 -0800152 static size_t GetTagWidth(JDWP::JdwpTag tag);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700153
Elliott Hughes88d63092013-01-09 09:55:54 -0800154 static JDWP::JdwpError GetArrayLength(JDWP::ObjectId array_id, int& length)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700155 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800156 static JDWP::JdwpError OutputArray(JDWP::ObjectId array_id, int offset, int count,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700157 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700158 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800159 static JDWP::JdwpError SetArrayElements(JDWP::ObjectId array_id, int offset, int count,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700160 const uint8_t* buf)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700161 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700162
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700163 static JDWP::ObjectId CreateString(const std::string& str)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700164 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800165 static JDWP::JdwpError CreateObject(JDWP::RefTypeId class_id, JDWP::ObjectId& new_object)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700166 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800167 static JDWP::JdwpError CreateArrayObject(JDWP::RefTypeId array_class_id, uint32_t length,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700168 JDWP::ObjectId& new_array)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700169 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700170
Elliott Hughes88d63092013-01-09 09:55:54 -0800171 static bool MatchType(JDWP::RefTypeId instance_class_id, JDWP::RefTypeId class_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700172 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700173
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800174 //
175 // Monitors.
176 //
177 static JDWP::JdwpError GetMonitorInfo(JDWP::ObjectId object_id, JDWP::ExpandBuf* reply)
178 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
179 static JDWP::JdwpError GetOwnedMonitors(JDWP::ObjectId thread_id,
180 std::vector<JDWP::ObjectId>& monitors,
181 std::vector<uint32_t>& stack_depths)
182 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
183 static JDWP::JdwpError GetContendedMonitor(JDWP::ObjectId thread_id, JDWP::ObjectId& contended_monitor)
184 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
185
186 //
187 // Heap.
188 //
189 static JDWP::JdwpError GetInstanceCounts(const std::vector<JDWP::RefTypeId>& class_ids,
190 std::vector<uint64_t>& counts)
191 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes3b78c942013-01-15 17:35:41 -0800192 static JDWP::JdwpError GetInstances(JDWP::RefTypeId class_id, int32_t max_count,
193 std::vector<JDWP::ObjectId>& instances)
194 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes0cbaff52013-01-16 15:28:01 -0800195 static JDWP::JdwpError GetReferringObjects(JDWP::ObjectId object_id, int32_t max_count,
196 std::vector<JDWP::ObjectId>& referring_objects)
197 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800198
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700199 /*
200 * Method and Field
201 */
Elliott Hughes88d63092013-01-09 09:55:54 -0800202 static std::string GetMethodName(JDWP::RefTypeId ref_type_id, JDWP::MethodId id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700203 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800204 static JDWP::JdwpError OutputDeclaredFields(JDWP::RefTypeId ref_type_id, bool with_generic,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700205 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700206 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800207 static JDWP::JdwpError OutputDeclaredMethods(JDWP::RefTypeId ref_type_id, bool with_generic,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700208 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700209 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800210 static JDWP::JdwpError OutputDeclaredInterfaces(JDWP::RefTypeId ref_type_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700211 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700212 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800213 static void OutputLineTable(JDWP::RefTypeId ref_type_id, JDWP::MethodId method_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700214 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700215 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800216 static void OutputVariableTable(JDWP::RefTypeId ref_type_id, JDWP::MethodId id, bool with_generic,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700217 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700218 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700219
Elliott Hughes88d63092013-01-09 09:55:54 -0800220 static JDWP::JdwpTag GetFieldBasicTag(JDWP::FieldId field_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700221 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800222 static JDWP::JdwpTag GetStaticFieldBasicTag(JDWP::FieldId field_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700223 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);;
Elliott Hughes88d63092013-01-09 09:55:54 -0800224 static JDWP::JdwpError GetFieldValue(JDWP::ObjectId object_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700225 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700226 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800227 static JDWP::JdwpError SetFieldValue(JDWP::ObjectId object_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700228 uint64_t value, int width)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700229 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800230 static JDWP::JdwpError GetStaticFieldValue(JDWP::RefTypeId ref_type_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700231 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700232 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800233 static JDWP::JdwpError SetStaticFieldValue(JDWP::FieldId field_id, uint64_t value, int width)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700234 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700235
Elliott Hughes88d63092013-01-09 09:55:54 -0800236 static std::string StringToUtf8(JDWP::ObjectId string_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700237 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700238
239 /*
240 * Thread, ThreadGroup, Frame
241 */
Elliott Hughes88d63092013-01-09 09:55:54 -0800242 static JDWP::JdwpError GetThreadName(JDWP::ObjectId thread_id, std::string& name)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700243 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
244 LOCKS_EXCLUDED(Locks::thread_list_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800245 static JDWP::JdwpError GetThreadGroup(JDWP::ObjectId thread_id, JDWP::ExpandBuf* pReply);
246 static std::string GetThreadGroupName(JDWP::ObjectId thread_group_id);
247 static JDWP::ObjectId GetThreadGroupParent(JDWP::ObjectId thread_group_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700248 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700249 static JDWP::ObjectId GetSystemThreadGroupId()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700250 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700251 static JDWP::ObjectId GetMainThreadGroupId();
252
Elliott Hughes88d63092013-01-09 09:55:54 -0800253 static JDWP::JdwpError GetThreadStatus(JDWP::ObjectId thread_id, JDWP::JdwpThreadStatus* pThreadStatus, JDWP::JdwpSuspendStatus* pSuspendStatus);
254 static JDWP::JdwpError GetThreadDebugSuspendCount(JDWP::ObjectId thread_id, JDWP::ExpandBuf* pReply);
Elliott Hughes88d63092013-01-09 09:55:54 -0800255 //static void WaitForSuspend(JDWP::ObjectId thread_id);
Elliott Hughescaf76542012-06-28 16:08:22 -0700256
Elliott Hughes026b1462012-06-28 20:43:49 -0700257 // Fills 'thread_ids' with the threads in the given thread group. If thread_group_id == 0,
Elliott Hughescaf76542012-06-28 16:08:22 -0700258 // returns all threads.
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700259 static void GetThreads(JDWP::ObjectId thread_group_id, std::vector<JDWP::ObjectId>& thread_ids)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700260 LOCKS_EXCLUDED(Locks::thread_list_lock_)
261 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughescaf76542012-06-28 16:08:22 -0700262 static void GetChildThreadGroups(JDWP::ObjectId thread_group_id, std::vector<JDWP::ObjectId>& child_thread_group_ids);
263
Elliott Hughes88d63092013-01-09 09:55:54 -0800264 static JDWP::JdwpError GetThreadFrameCount(JDWP::ObjectId thread_id, size_t& result);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700265 static JDWP::JdwpError GetThreadFrames(JDWP::ObjectId thread_id, size_t start_frame,
266 size_t frame_count, JDWP::ExpandBuf* buf)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700267 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700268
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700269 static JDWP::ObjectId GetThreadSelfId()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700270 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700271 static void SuspendVM()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700272 LOCKS_EXCLUDED(Locks::thread_list_lock_,
273 Locks::thread_suspend_count_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700274 static void ResumeVM();
Elliott Hughes88d63092013-01-09 09:55:54 -0800275 static JDWP::JdwpError SuspendThread(JDWP::ObjectId thread_id, bool request_suspension = true)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700276 LOCKS_EXCLUDED(Locks::mutator_lock_,
277 Locks::thread_list_lock_,
278 Locks::thread_suspend_count_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700279
Elliott Hughes88d63092013-01-09 09:55:54 -0800280 static void ResumeThread(JDWP::ObjectId thread_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700281 LOCKS_EXCLUDED(Locks::thread_list_lock_,
282 Locks::thread_suspend_count_lock_)
283 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700284 static void SuspendSelf();
285
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700286 static JDWP::JdwpError GetThisObject(JDWP::ObjectId thread_id, JDWP::FrameId frame_id,
287 JDWP::ObjectId* result)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700288 LOCKS_EXCLUDED(Locks::thread_list_lock_,
289 Locks::thread_suspend_count_lock_)
290 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800291 static void GetLocalValue(JDWP::ObjectId thread_id, JDWP::FrameId frame_id, int slot,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700292 JDWP::JdwpTag tag, uint8_t* buf, size_t expectedLen)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700293 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800294 static void SetLocalValue(JDWP::ObjectId thread_id, JDWP::FrameId frame_id, int slot,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700295 JDWP::JdwpTag tag, uint64_t value, size_t width)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700296 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700297
Elliott Hughesf9501702013-01-11 11:22:27 -0800298 static JDWP::JdwpError Interrupt(JDWP::ObjectId thread_id);
299
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700300 /*
301 * Debugger notification
302 */
303 enum {
Elliott Hughes86964332012-02-15 19:37:42 -0800304 kBreakpoint = 0x01,
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700305 kSingleStep = 0x02,
306 kMethodEntry = 0x04,
307 kMethodExit = 0x08,
308 };
Mathieu Chartier66f19252012-09-18 08:57:04 -0700309 static void PostLocationEvent(const AbstractMethod* method, int pcOffset, Object* thisPtr, int eventFlags)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700310 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier66f19252012-09-18 08:57:04 -0700311 static void PostException(Thread* thread, JDWP::FrameId throw_frame_id, AbstractMethod* throw_method,
312 uint32_t throw_dex_pc, AbstractMethod* catch_method, uint32_t catch_dex_pc,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700313 Throwable* exception)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700314 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700315 static void PostThreadStart(Thread* t)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700316 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700317 static void PostThreadDeath(Thread* t)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700318 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700319 static void PostClassPrepare(Class* c)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700320 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700321
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700322 static void UpdateDebugger(int32_t dex_pc, Thread* self)
jeffhao09bfc6a2012-12-11 18:11:43 -0800323 LOCKS_EXCLUDED(Locks::breakpoint_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700324 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes91bf6cd2012-02-14 17:27:48 -0800325
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700326 static void WatchLocation(const JDWP::JdwpLocation* pLoc)
jeffhao09bfc6a2012-12-11 18:11:43 -0800327 LOCKS_EXCLUDED(Locks::breakpoint_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700328 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700329 static void UnwatchLocation(const JDWP::JdwpLocation* pLoc)
jeffhao09bfc6a2012-12-11 18:11:43 -0800330 LOCKS_EXCLUDED(Locks::breakpoint_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700331 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800332 static JDWP::JdwpError ConfigureStep(JDWP::ObjectId thread_id, JDWP::JdwpStepSize size,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700333 JDWP::JdwpStepDepth depth)
jeffhao09bfc6a2012-12-11 18:11:43 -0800334 LOCKS_EXCLUDED(Locks::breakpoint_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700335 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800336 static void UnconfigureStep(JDWP::ObjectId thread_id) LOCKS_EXCLUDED(Locks::breakpoint_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700337
Elliott Hughes88d63092013-01-09 09:55:54 -0800338 static JDWP::JdwpError InvokeMethod(JDWP::ObjectId thread_id, JDWP::ObjectId object_id,
339 JDWP::RefTypeId class_id, JDWP::MethodId method_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700340 uint32_t arg_count, uint64_t* arg_values,
341 JDWP::JdwpTag* arg_types, uint32_t options,
342 JDWP::JdwpTag* pResultTag, uint64_t* pResultValue,
343 JDWP::ObjectId* pExceptObj)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700344 LOCKS_EXCLUDED(Locks::thread_list_lock_,
345 Locks::thread_suspend_count_lock_)
346 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700347 static void ExecuteMethod(DebugInvokeReq* pReq);
348
349 /* perform "late registration" of an object ID */
350 static void RegisterObjectId(JDWP::ObjectId id);
351
352 /*
353 * DDM support.
354 */
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700355 static void DdmSendThreadNotification(Thread* t, uint32_t type)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700356 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes47fce012011-10-25 18:37:19 -0700357 static void DdmSetThreadNotification(bool enable);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700358 static bool DdmHandlePacket(const uint8_t* buf, int dataLen, uint8_t** pReplyBuf, int* pReplyLen);
Ian Rogersb726dcb2012-09-05 08:57:23 -0700359 static void DdmConnected() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
360 static void DdmDisconnected() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700361 static void DdmSendChunk(uint32_t type, const std::vector<uint8_t>& bytes)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700362 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700363 static void DdmSendChunk(uint32_t type, size_t len, const uint8_t* buf)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700364 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700365 static void DdmSendChunkV(uint32_t type, const iovec* iov, int iov_count)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700366 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -0700367
Elliott Hughes545a0642011-11-08 19:10:03 -0800368 /*
369 * Recent allocation tracking support.
370 */
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700371 static void RecordAllocation(Class* type, size_t byte_count)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700372 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes545a0642011-11-08 19:10:03 -0800373 static void SetAllocTrackingEnabled(bool enabled);
374 static inline bool IsAllocTrackingEnabled() { return recent_allocation_records_ != NULL; }
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700375 static jbyteArray GetRecentAllocations()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700376 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes545a0642011-11-08 19:10:03 -0800377 static void DumpRecentAllocations();
378
Elliott Hughes767a1472011-10-26 18:49:02 -0700379 enum HpifWhen {
380 HPIF_WHEN_NEVER = 0,
381 HPIF_WHEN_NOW = 1,
382 HPIF_WHEN_NEXT_GC = 2,
383 HPIF_WHEN_EVERY_GC = 3
384 };
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700385 static int DdmHandleHpifChunk(HpifWhen when)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700386 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -0700387
388 enum HpsgWhen {
389 HPSG_WHEN_NEVER = 0,
390 HPSG_WHEN_EVERY_GC = 1,
391 };
392 enum HpsgWhat {
393 HPSG_WHAT_MERGED_OBJECTS = 0,
394 HPSG_WHAT_DISTINCT_OBJECTS = 1,
395 };
396 static bool DdmHandleHpsgNhsgChunk(HpsgWhen when, HpsgWhat what, bool native);
397
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700398 static void DdmSendHeapInfo(HpifWhen reason)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700399 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700400 static void DdmSendHeapSegments(bool native)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700401 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes545a0642011-11-08 19:10:03 -0800402
403 private:
Ian Rogersb726dcb2012-09-05 08:57:23 -0700404 static void DdmBroadcast(bool) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700405 static void PostThreadStartOrStop(Thread*, uint32_t)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700406 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughesa2155262011-11-16 16:26:58 -0800407
Elliott Hughes545a0642011-11-08 19:10:03 -0800408 static AllocRecord* recent_allocation_records_;
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700409};
410
411#define CHUNK_TYPE(_name) \
Elliott Hughes82188472011-11-07 18:11:48 -0800412 static_cast<uint32_t>((_name)[0] << 24 | (_name)[1] << 16 | (_name)[2] << 8 | (_name)[3])
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700413
414} // namespace art
415
416#endif // ART_DEBUGGER_H_