blob: 321bcf1bf5dbe4db5daa68d13e65324e8bd7c1e5 [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"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080029#include "jni.h"
30#include "jvalue.h"
31#include "root_visitor.h"
Elliott Hughes872d4ec2011-10-21 17:07:15 -070032
33namespace art {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080034namespace mirror {
35class AbstractMethod;
36class Class;
37class Object;
38class Throwable;
39} // namespace mirror
Elliott Hughes545a0642011-11-08 19:10:03 -080040struct AllocRecord;
Ian Rogers1b09b092012-08-20 15:35:52 -070041class Thread;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070042
43/*
44 * Invoke-during-breakpoint support.
45 */
46struct DebugInvokeReq {
Elliott Hughes7b3cdfc2011-12-08 21:28:17 -080047 DebugInvokeReq()
Ian Rogers00f7d0e2012-07-19 15:28:27 -070048 : ready(false), invoke_needed_(false),
49 receiver_(NULL), thread_(NULL), class_(NULL), method_(NULL),
50 arg_count_(0), arg_values_(NULL), options_(0), error(JDWP::ERR_NONE),
51 result_tag(JDWP::JT_VOID), exception(0),
jeffhao9b5aa6f2012-12-18 11:47:11 -080052 lock_("a DebugInvokeReq lock", kBreakpointInvokeLock),
Ian Rogersc604d732012-10-14 16:09:54 -070053 cond_("a DebugInvokeReq condition variable", lock_) {
Elliott Hughes475fc232011-10-25 15:00:35 -070054 }
55
Elliott Hughes872d4ec2011-10-21 17:07:15 -070056 /* boolean; only set when we're in the tail end of an event handler */
57 bool ready;
58
59 /* boolean; set if the JDWP thread wants this thread to do work */
Elliott Hughesd07986f2011-12-06 18:27:45 -080060 bool invoke_needed_;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070061
62 /* request */
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080063 mirror::Object* receiver_; /* not used for ClassType.InvokeMethod */
64 mirror::Object* thread_;
65 mirror::Class* class_;
66 mirror::AbstractMethod* method_;
Elliott Hughes45651fd2012-02-21 15:48:20 -080067 uint32_t arg_count_;
68 uint64_t* arg_values_; /* will be NULL if arg_count_ == 0 */
Elliott Hughesd07986f2011-12-06 18:27:45 -080069 uint32_t options_;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070070
71 /* result */
Elliott Hughes475fc232011-10-25 15:00:35 -070072 JDWP::JdwpError error;
Elliott Hughesd07986f2011-12-06 18:27:45 -080073 JDWP::JdwpTag result_tag;
Elliott Hughes475fc232011-10-25 15:00:35 -070074 JValue result_value;
75 JDWP::ObjectId exception;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070076
77 /* condition variable to wait on while the method executes */
Ian Rogersc604d732012-10-14 16:09:54 -070078 Mutex lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
79 ConditionVariable cond_ GUARDED_BY(lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -070080};
81
82class Dbg {
Elliott Hughesff17f1f2012-01-24 18:12:29 -080083 public:
Elliott Hughes3bb81562011-10-21 18:52:59 -070084 static bool ParseJdwpOptions(const std::string& options);
Elliott Hughes4ffd3132011-10-24 12:06:42 -070085 static void SetJdwpAllowed(bool allowed);
86
Elliott Hughesd1cc8362011-10-24 16:58:50 -070087 static void StartJdwp();
88 static void StopJdwp();
89
Elliott Hughes767a1472011-10-26 18:49:02 -070090 // Invoked by the GC in case we need to keep DDMS informed.
Ian Rogersb726dcb2012-09-05 08:57:23 -070091 static void GcDidFinish() LOCKS_EXCLUDED(Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -070092
Elliott Hughes872d4ec2011-10-21 17:07:15 -070093 // Return the DebugInvokeReq for the current thread.
94 static DebugInvokeReq* GetInvokeReq();
95
Elliott Hughes475fc232011-10-25 15:00:35 -070096 static Thread* GetDebugThread();
97 static void ClearWaitForEventThread();
98
Elliott Hughes872d4ec2011-10-21 17:07:15 -070099 /*
100 * Enable/disable breakpoints and step modes. Used to provide a heads-up
101 * when the debugger attaches.
102 */
103 static void Connected();
jeffhao09bfc6a2012-12-11 18:11:43 -0800104 static void GoActive() LOCKS_EXCLUDED(Locks::breakpoint_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700105 static void Disconnected();
Elliott Hughes86964332012-02-15 19:37:42 -0800106 static void Disposed();
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700107
Elliott Hughesc0f09332012-03-26 13:27:06 -0700108 // Returns true if we're actually debugging with a real debugger, false if it's
109 // just DDMS (or nothing at all).
110 static bool IsDebuggerActive();
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700111
Elliott Hughesc0f09332012-03-26 13:27:06 -0700112 // Returns true if we had -Xrunjdwp or -agentlib:jdwp= on the command line.
113 static bool IsJdwpConfigured();
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700114
Elliott Hughes86964332012-02-15 19:37:42 -0800115 static bool IsDisposed();
116
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700117 /*
118 * Time, in milliseconds, since the last debugger activity. Does not
119 * include DDMS activity. Returns -1 if there has been no activity.
120 * Returns 0 if we're in the middle of handling a debugger request.
121 */
122 static int64_t LastDebuggerActivity();
123
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700124 static void UndoDebuggerSuspensions();
125
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700126 /*
127 * Class, Object, Array
128 */
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700129 static std::string GetClassName(JDWP::RefTypeId id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700130 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800131 static JDWP::JdwpError GetClassObject(JDWP::RefTypeId id, JDWP::ObjectId& class_object_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700132 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800133 static JDWP::JdwpError GetSuperclass(JDWP::RefTypeId id, JDWP::RefTypeId& superclass_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700134 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700135 static JDWP::JdwpError GetClassLoader(JDWP::RefTypeId id, JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700136 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700137 static JDWP::JdwpError GetModifiers(JDWP::RefTypeId id, JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700138 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800139 static JDWP::JdwpError GetReflectedType(JDWP::RefTypeId class_id, JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700140 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700141 static void GetClassList(std::vector<JDWP::RefTypeId>& classes)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700142 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800143 static JDWP::JdwpError GetClassInfo(JDWP::RefTypeId class_id, JDWP::JdwpTypeTag* pTypeTag,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700144 uint32_t* pStatus, std::string* pDescriptor)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700145 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700146 static void FindLoadedClassBySignature(const char* descriptor, std::vector<JDWP::RefTypeId>& ids)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700147 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes64f574f2013-02-20 14:57:12 -0800148 static JDWP::JdwpError GetReferenceType(JDWP::ObjectId object_id, JDWP::ExpandBuf* pReply)
149 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800150 static JDWP::JdwpError GetSignature(JDWP::RefTypeId ref_type_id, std::string& signature)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700151 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800152 static JDWP::JdwpError GetSourceFile(JDWP::RefTypeId ref_type_id, std::string& source_file)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700153 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800154 static JDWP::JdwpError GetObjectTag(JDWP::ObjectId object_id, uint8_t& tag)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700155 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughesaed4be92011-12-02 16:16:23 -0800156 static size_t GetTagWidth(JDWP::JdwpTag tag);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700157
Elliott Hughes88d63092013-01-09 09:55:54 -0800158 static JDWP::JdwpError GetArrayLength(JDWP::ObjectId array_id, int& length)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700159 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800160 static JDWP::JdwpError OutputArray(JDWP::ObjectId array_id, int offset, int count,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700161 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700162 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800163 static JDWP::JdwpError SetArrayElements(JDWP::ObjectId array_id, int offset, int count,
Elliott Hughes4b9702c2013-02-20 18:13:24 -0800164 JDWP::Request& request)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700165 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700166
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700167 static JDWP::ObjectId CreateString(const std::string& str)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700168 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800169 static JDWP::JdwpError CreateObject(JDWP::RefTypeId class_id, JDWP::ObjectId& new_object)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700170 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800171 static JDWP::JdwpError CreateArrayObject(JDWP::RefTypeId array_class_id, uint32_t length,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700172 JDWP::ObjectId& new_array)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700173 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700174
Elliott Hughes88d63092013-01-09 09:55:54 -0800175 static bool MatchType(JDWP::RefTypeId instance_class_id, JDWP::RefTypeId class_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700176 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700177
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800178 //
179 // Monitors.
180 //
181 static JDWP::JdwpError GetMonitorInfo(JDWP::ObjectId object_id, JDWP::ExpandBuf* reply)
182 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
183 static JDWP::JdwpError GetOwnedMonitors(JDWP::ObjectId thread_id,
184 std::vector<JDWP::ObjectId>& monitors,
185 std::vector<uint32_t>& stack_depths)
186 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
187 static JDWP::JdwpError GetContendedMonitor(JDWP::ObjectId thread_id, JDWP::ObjectId& contended_monitor)
188 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
189
190 //
191 // Heap.
192 //
193 static JDWP::JdwpError GetInstanceCounts(const std::vector<JDWP::RefTypeId>& class_ids,
194 std::vector<uint64_t>& counts)
195 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes3b78c942013-01-15 17:35:41 -0800196 static JDWP::JdwpError GetInstances(JDWP::RefTypeId class_id, int32_t max_count,
197 std::vector<JDWP::ObjectId>& instances)
198 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes0cbaff52013-01-16 15:28:01 -0800199 static JDWP::JdwpError GetReferringObjects(JDWP::ObjectId object_id, int32_t max_count,
200 std::vector<JDWP::ObjectId>& referring_objects)
201 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes64f574f2013-02-20 14:57:12 -0800202 static JDWP::JdwpError DisableCollection(JDWP::ObjectId object_id)
203 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
204 static JDWP::JdwpError EnableCollection(JDWP::ObjectId object_id)
205 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
206 static JDWP::JdwpError IsCollected(JDWP::ObjectId object_id, bool& is_collected)
207 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
208 static void DisposeObject(JDWP::ObjectId object_id, uint32_t reference_count)
209 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800210
Elliott Hughes9777ba22013-01-17 09:04:19 -0800211 //
212 // Methods and fields.
213 //
Elliott Hughesa96836a2013-01-17 12:27:49 -0800214 static std::string GetMethodName(JDWP::MethodId method_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700215 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800216 static JDWP::JdwpError OutputDeclaredFields(JDWP::RefTypeId ref_type_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 Hughes88d63092013-01-09 09:55:54 -0800219 static JDWP::JdwpError OutputDeclaredMethods(JDWP::RefTypeId ref_type_id, bool with_generic,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700220 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700221 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800222 static JDWP::JdwpError OutputDeclaredInterfaces(JDWP::RefTypeId ref_type_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700223 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700224 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800225 static void OutputLineTable(JDWP::RefTypeId ref_type_id, JDWP::MethodId method_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700226 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700227 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800228 static void OutputVariableTable(JDWP::RefTypeId ref_type_id, JDWP::MethodId id, bool with_generic,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700229 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700230 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes9777ba22013-01-17 09:04:19 -0800231 static JDWP::JdwpError GetBytecodes(JDWP::RefTypeId class_id, JDWP::MethodId method_id,
232 std::vector<uint8_t>& bytecodes)
233 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700234
Elliott Hughesa96836a2013-01-17 12:27:49 -0800235 static std::string GetFieldName(JDWP::FieldId field_id)
236 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800237 static JDWP::JdwpTag GetFieldBasicTag(JDWP::FieldId field_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700238 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800239 static JDWP::JdwpTag GetStaticFieldBasicTag(JDWP::FieldId field_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700240 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);;
Elliott Hughes88d63092013-01-09 09:55:54 -0800241 static JDWP::JdwpError GetFieldValue(JDWP::ObjectId object_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700242 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700243 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800244 static JDWP::JdwpError SetFieldValue(JDWP::ObjectId object_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700245 uint64_t value, int width)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700246 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800247 static JDWP::JdwpError GetStaticFieldValue(JDWP::RefTypeId ref_type_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700248 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700249 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800250 static JDWP::JdwpError SetStaticFieldValue(JDWP::FieldId field_id, uint64_t value, int width)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700251 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700252
Elliott Hughes88d63092013-01-09 09:55:54 -0800253 static std::string StringToUtf8(JDWP::ObjectId string_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700254 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700255
256 /*
257 * Thread, ThreadGroup, Frame
258 */
Elliott Hughes88d63092013-01-09 09:55:54 -0800259 static JDWP::JdwpError GetThreadName(JDWP::ObjectId thread_id, std::string& name)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700260 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
261 LOCKS_EXCLUDED(Locks::thread_list_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800262 static JDWP::JdwpError GetThreadGroup(JDWP::ObjectId thread_id, JDWP::ExpandBuf* pReply);
263 static std::string GetThreadGroupName(JDWP::ObjectId thread_group_id);
264 static JDWP::ObjectId GetThreadGroupParent(JDWP::ObjectId thread_group_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700265 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700266 static JDWP::ObjectId GetSystemThreadGroupId()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700267 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700268 static JDWP::ObjectId GetMainThreadGroupId();
269
Elliott Hughes88d63092013-01-09 09:55:54 -0800270 static JDWP::JdwpError GetThreadStatus(JDWP::ObjectId thread_id, JDWP::JdwpThreadStatus* pThreadStatus, JDWP::JdwpSuspendStatus* pSuspendStatus);
271 static JDWP::JdwpError GetThreadDebugSuspendCount(JDWP::ObjectId thread_id, JDWP::ExpandBuf* pReply);
Elliott Hughes88d63092013-01-09 09:55:54 -0800272 //static void WaitForSuspend(JDWP::ObjectId thread_id);
Elliott Hughescaf76542012-06-28 16:08:22 -0700273
Elliott Hughes026b1462012-06-28 20:43:49 -0700274 // Fills 'thread_ids' with the threads in the given thread group. If thread_group_id == 0,
Elliott Hughescaf76542012-06-28 16:08:22 -0700275 // returns all threads.
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700276 static void GetThreads(JDWP::ObjectId thread_group_id, std::vector<JDWP::ObjectId>& thread_ids)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700277 LOCKS_EXCLUDED(Locks::thread_list_lock_)
278 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughescaf76542012-06-28 16:08:22 -0700279 static void GetChildThreadGroups(JDWP::ObjectId thread_group_id, std::vector<JDWP::ObjectId>& child_thread_group_ids);
280
Elliott Hughes88d63092013-01-09 09:55:54 -0800281 static JDWP::JdwpError GetThreadFrameCount(JDWP::ObjectId thread_id, size_t& result);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700282 static JDWP::JdwpError GetThreadFrames(JDWP::ObjectId thread_id, size_t start_frame,
283 size_t frame_count, JDWP::ExpandBuf* buf)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700284 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700285
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700286 static JDWP::ObjectId GetThreadSelfId()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700287 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700288 static void SuspendVM()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700289 LOCKS_EXCLUDED(Locks::thread_list_lock_,
290 Locks::thread_suspend_count_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700291 static void ResumeVM();
Elliott Hughes88d63092013-01-09 09:55:54 -0800292 static JDWP::JdwpError SuspendThread(JDWP::ObjectId thread_id, bool request_suspension = true)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700293 LOCKS_EXCLUDED(Locks::mutator_lock_,
294 Locks::thread_list_lock_,
295 Locks::thread_suspend_count_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700296
Elliott Hughes88d63092013-01-09 09:55:54 -0800297 static void ResumeThread(JDWP::ObjectId thread_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700298 LOCKS_EXCLUDED(Locks::thread_list_lock_,
299 Locks::thread_suspend_count_lock_)
300 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700301 static void SuspendSelf();
302
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700303 static JDWP::JdwpError GetThisObject(JDWP::ObjectId thread_id, JDWP::FrameId frame_id,
304 JDWP::ObjectId* result)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700305 LOCKS_EXCLUDED(Locks::thread_list_lock_,
306 Locks::thread_suspend_count_lock_)
307 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800308 static void GetLocalValue(JDWP::ObjectId thread_id, JDWP::FrameId frame_id, int slot,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700309 JDWP::JdwpTag tag, uint8_t* buf, size_t expectedLen)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700310 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800311 static void SetLocalValue(JDWP::ObjectId thread_id, JDWP::FrameId frame_id, int slot,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700312 JDWP::JdwpTag tag, uint64_t value, size_t width)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700313 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700314
Elliott Hughesf9501702013-01-11 11:22:27 -0800315 static JDWP::JdwpError Interrupt(JDWP::ObjectId thread_id);
316
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700317 /*
318 * Debugger notification
319 */
320 enum {
Elliott Hughes86964332012-02-15 19:37:42 -0800321 kBreakpoint = 0x01,
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700322 kSingleStep = 0x02,
323 kMethodEntry = 0x04,
324 kMethodExit = 0x08,
325 };
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800326 static void PostLocationEvent(const mirror::AbstractMethod* method, int pcOffset,
327 mirror::Object* thisPtr, int eventFlags)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700328 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800329 static void PostException(Thread* thread, JDWP::FrameId throw_frame_id,
330 mirror::AbstractMethod* throw_method,
331 uint32_t throw_dex_pc, mirror::AbstractMethod* catch_method,
332 uint32_t catch_dex_pc, mirror::Throwable* exception)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700333 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700334 static void PostThreadStart(Thread* t)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700335 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700336 static void PostThreadDeath(Thread* t)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700337 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800338 static void PostClassPrepare(mirror::Class* c)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700339 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700340
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700341 static void UpdateDebugger(int32_t dex_pc, Thread* self)
jeffhao09bfc6a2012-12-11 18:11:43 -0800342 LOCKS_EXCLUDED(Locks::breakpoint_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700343 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes91bf6cd2012-02-14 17:27:48 -0800344
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700345 static void WatchLocation(const JDWP::JdwpLocation* pLoc)
jeffhao09bfc6a2012-12-11 18:11:43 -0800346 LOCKS_EXCLUDED(Locks::breakpoint_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700347 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700348 static void UnwatchLocation(const JDWP::JdwpLocation* pLoc)
jeffhao09bfc6a2012-12-11 18:11:43 -0800349 LOCKS_EXCLUDED(Locks::breakpoint_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700350 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800351 static JDWP::JdwpError ConfigureStep(JDWP::ObjectId thread_id, JDWP::JdwpStepSize size,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700352 JDWP::JdwpStepDepth depth)
jeffhao09bfc6a2012-12-11 18:11:43 -0800353 LOCKS_EXCLUDED(Locks::breakpoint_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700354 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800355 static void UnconfigureStep(JDWP::ObjectId thread_id) LOCKS_EXCLUDED(Locks::breakpoint_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700356
Elliott Hughes88d63092013-01-09 09:55:54 -0800357 static JDWP::JdwpError InvokeMethod(JDWP::ObjectId thread_id, JDWP::ObjectId object_id,
358 JDWP::RefTypeId class_id, JDWP::MethodId method_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700359 uint32_t arg_count, uint64_t* arg_values,
360 JDWP::JdwpTag* arg_types, uint32_t options,
361 JDWP::JdwpTag* pResultTag, uint64_t* pResultValue,
362 JDWP::ObjectId* pExceptObj)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700363 LOCKS_EXCLUDED(Locks::thread_list_lock_,
364 Locks::thread_suspend_count_lock_)
365 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700366 static void ExecuteMethod(DebugInvokeReq* pReq);
367
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700368 /*
369 * DDM support.
370 */
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700371 static void DdmSendThreadNotification(Thread* t, uint32_t type)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700372 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes47fce012011-10-25 18:37:19 -0700373 static void DdmSetThreadNotification(bool enable);
Elliott Hughes4b9702c2013-02-20 18:13:24 -0800374 static bool DdmHandlePacket(JDWP::Request& request, uint8_t** pReplyBuf, int* pReplyLen);
Ian Rogersb726dcb2012-09-05 08:57:23 -0700375 static void DdmConnected() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
376 static void DdmDisconnected() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700377 static void DdmSendChunk(uint32_t type, const std::vector<uint8_t>& bytes)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700378 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700379 static void DdmSendChunk(uint32_t type, size_t len, const uint8_t* buf)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700380 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700381 static void DdmSendChunkV(uint32_t type, const iovec* iov, int iov_count)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700382 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -0700383
Elliott Hughes545a0642011-11-08 19:10:03 -0800384 /*
385 * Recent allocation tracking support.
386 */
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800387 static void RecordAllocation(mirror::Class* type, size_t byte_count)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700388 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes545a0642011-11-08 19:10:03 -0800389 static void SetAllocTrackingEnabled(bool enabled);
390 static inline bool IsAllocTrackingEnabled() { return recent_allocation_records_ != NULL; }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800391 static jbyteArray GetRecentAllocations() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes545a0642011-11-08 19:10:03 -0800392 static void DumpRecentAllocations();
393
Elliott Hughes767a1472011-10-26 18:49:02 -0700394 enum HpifWhen {
395 HPIF_WHEN_NEVER = 0,
396 HPIF_WHEN_NOW = 1,
397 HPIF_WHEN_NEXT_GC = 2,
398 HPIF_WHEN_EVERY_GC = 3
399 };
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700400 static int DdmHandleHpifChunk(HpifWhen when)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700401 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -0700402
403 enum HpsgWhen {
404 HPSG_WHEN_NEVER = 0,
405 HPSG_WHEN_EVERY_GC = 1,
406 };
407 enum HpsgWhat {
408 HPSG_WHAT_MERGED_OBJECTS = 0,
409 HPSG_WHAT_DISTINCT_OBJECTS = 1,
410 };
411 static bool DdmHandleHpsgNhsgChunk(HpsgWhen when, HpsgWhat what, bool native);
412
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700413 static void DdmSendHeapInfo(HpifWhen reason)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700414 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700415 static void DdmSendHeapSegments(bool native)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700416 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes545a0642011-11-08 19:10:03 -0800417
418 private:
Ian Rogersb726dcb2012-09-05 08:57:23 -0700419 static void DdmBroadcast(bool) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700420 static void PostThreadStartOrStop(Thread*, uint32_t)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700421 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughesa2155262011-11-16 16:26:58 -0800422
Elliott Hughes545a0642011-11-08 19:10:03 -0800423 static AllocRecord* recent_allocation_records_;
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700424};
425
426#define CHUNK_TYPE(_name) \
Elliott Hughes82188472011-11-07 18:11:48 -0800427 static_cast<uint32_t>((_name)[0] << 24 | (_name)[1] << 16 | (_name)[2] << 8 | (_name)[3])
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700428
429} // namespace art
430
431#endif // ART_DEBUGGER_H_