blob: 2282305ac2935956cccdad2067b0b2e0fe7ada09 [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 */
Brian Carlstromfc0e3212013-07-17 14:40:12 -070021#ifndef ART_RUNTIME_DEBUGGER_H_
22#define ART_RUNTIME_DEBUGGER_H_
Elliott Hughes872d4ec2011-10-21 17:07:15 -070023
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 {
Brian Carlstromea46f952013-07-30 01:26:50 -070035class ArtMethod;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080036class 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;
Ian Rogers62d6c772013-02-27 08:32:07 -080042class ThrowLocation;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070043
44/*
45 * Invoke-during-breakpoint support.
46 */
47struct DebugInvokeReq {
Elliott Hughes7b3cdfc2011-12-08 21:28:17 -080048 DebugInvokeReq()
Ian Rogers00f7d0e2012-07-19 15:28:27 -070049 : ready(false), invoke_needed_(false),
50 receiver_(NULL), thread_(NULL), class_(NULL), method_(NULL),
51 arg_count_(0), arg_values_(NULL), options_(0), error(JDWP::ERR_NONE),
52 result_tag(JDWP::JT_VOID), exception(0),
jeffhao9b5aa6f2012-12-18 11:47:11 -080053 lock_("a DebugInvokeReq lock", kBreakpointInvokeLock),
Ian Rogersc604d732012-10-14 16:09:54 -070054 cond_("a DebugInvokeReq condition variable", lock_) {
Elliott Hughes475fc232011-10-25 15:00:35 -070055 }
56
Elliott Hughes872d4ec2011-10-21 17:07:15 -070057 /* boolean; only set when we're in the tail end of an event handler */
58 bool ready;
59
60 /* boolean; set if the JDWP thread wants this thread to do work */
Elliott Hughesd07986f2011-12-06 18:27:45 -080061 bool invoke_needed_;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070062
63 /* request */
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080064 mirror::Object* receiver_; /* not used for ClassType.InvokeMethod */
65 mirror::Object* thread_;
66 mirror::Class* class_;
Brian Carlstromea46f952013-07-30 01:26:50 -070067 mirror::ArtMethod* method_;
Elliott Hughes45651fd2012-02-21 15:48:20 -080068 uint32_t arg_count_;
69 uint64_t* arg_values_; /* will be NULL if arg_count_ == 0 */
Elliott Hughesd07986f2011-12-06 18:27:45 -080070 uint32_t options_;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070071
72 /* result */
Elliott Hughes475fc232011-10-25 15:00:35 -070073 JDWP::JdwpError error;
Elliott Hughesd07986f2011-12-06 18:27:45 -080074 JDWP::JdwpTag result_tag;
Elliott Hughes475fc232011-10-25 15:00:35 -070075 JValue result_value;
76 JDWP::ObjectId exception;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070077
78 /* condition variable to wait on while the method executes */
Ian Rogersc604d732012-10-14 16:09:54 -070079 Mutex lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
80 ConditionVariable cond_ GUARDED_BY(lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -070081};
82
83class Dbg {
Elliott Hughesff17f1f2012-01-24 18:12:29 -080084 public:
Elliott Hughes3bb81562011-10-21 18:52:59 -070085 static bool ParseJdwpOptions(const std::string& options);
Elliott Hughes4ffd3132011-10-24 12:06:42 -070086 static void SetJdwpAllowed(bool allowed);
87
Elliott Hughesd1cc8362011-10-24 16:58:50 -070088 static void StartJdwp();
89 static void StopJdwp();
90
Elliott Hughes767a1472011-10-26 18:49:02 -070091 // Invoked by the GC in case we need to keep DDMS informed.
Ian Rogersb726dcb2012-09-05 08:57:23 -070092 static void GcDidFinish() LOCKS_EXCLUDED(Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -070093
Elliott Hughes872d4ec2011-10-21 17:07:15 -070094 // Return the DebugInvokeReq for the current thread.
95 static DebugInvokeReq* GetInvokeReq();
96
Elliott Hughes475fc232011-10-25 15:00:35 -070097 static Thread* GetDebugThread();
98 static void ClearWaitForEventThread();
99
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700100 /*
101 * Enable/disable breakpoints and step modes. Used to provide a heads-up
102 * when the debugger attaches.
103 */
104 static void Connected();
Ian Rogers62d6c772013-02-27 08:32:07 -0800105 static void GoActive() LOCKS_EXCLUDED(Locks::breakpoint_lock_, Locks::mutator_lock_);
106 static void Disconnected() LOCKS_EXCLUDED(Locks::mutator_lock_);
Elliott Hughes86964332012-02-15 19:37:42 -0800107 static void Disposed();
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700108
Elliott Hughesc0f09332012-03-26 13:27:06 -0700109 // Returns true if we're actually debugging with a real debugger, false if it's
110 // just DDMS (or nothing at all).
111 static bool IsDebuggerActive();
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700112
Elliott Hughesc0f09332012-03-26 13:27:06 -0700113 // Returns true if we had -Xrunjdwp or -agentlib:jdwp= on the command line.
114 static bool IsJdwpConfigured();
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700115
Elliott Hughes86964332012-02-15 19:37:42 -0800116 static bool IsDisposed();
117
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700118 /*
119 * Time, in milliseconds, since the last debugger activity. Does not
120 * include DDMS activity. Returns -1 if there has been no activity.
121 * Returns 0 if we're in the middle of handling a debugger request.
122 */
123 static int64_t LastDebuggerActivity();
124
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700125 static void UndoDebuggerSuspensions();
126
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700127 /*
128 * Class, Object, Array
129 */
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700130 static std::string GetClassName(JDWP::RefTypeId id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700131 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800132 static JDWP::JdwpError GetClassObject(JDWP::RefTypeId id, JDWP::ObjectId& class_object_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700133 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800134 static JDWP::JdwpError GetSuperclass(JDWP::RefTypeId id, JDWP::RefTypeId& superclass_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700135 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700136 static JDWP::JdwpError GetClassLoader(JDWP::RefTypeId 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 JDWP::JdwpError GetModifiers(JDWP::RefTypeId id, JDWP::ExpandBuf* pReply)
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 GetReflectedType(JDWP::RefTypeId class_id, JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700141 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700142 static void GetClassList(std::vector<JDWP::RefTypeId>& classes)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700143 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800144 static JDWP::JdwpError GetClassInfo(JDWP::RefTypeId class_id, JDWP::JdwpTypeTag* pTypeTag,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700145 uint32_t* pStatus, std::string* pDescriptor)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700146 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700147 static void FindLoadedClassBySignature(const char* descriptor, std::vector<JDWP::RefTypeId>& ids)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700148 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes64f574f2013-02-20 14:57:12 -0800149 static JDWP::JdwpError GetReferenceType(JDWP::ObjectId object_id, JDWP::ExpandBuf* pReply)
150 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800151 static JDWP::JdwpError GetSignature(JDWP::RefTypeId ref_type_id, std::string& signature)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700152 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800153 static JDWP::JdwpError GetSourceFile(JDWP::RefTypeId ref_type_id, std::string& source_file)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700154 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800155 static JDWP::JdwpError GetObjectTag(JDWP::ObjectId object_id, uint8_t& tag)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700156 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughesaed4be92011-12-02 16:16:23 -0800157 static size_t GetTagWidth(JDWP::JdwpTag tag);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700158
Elliott Hughes88d63092013-01-09 09:55:54 -0800159 static JDWP::JdwpError GetArrayLength(JDWP::ObjectId array_id, int& length)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700160 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800161 static JDWP::JdwpError OutputArray(JDWP::ObjectId array_id, int offset, int count,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700162 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700163 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800164 static JDWP::JdwpError SetArrayElements(JDWP::ObjectId array_id, int offset, int count,
Elliott Hughes4b9702c2013-02-20 18:13:24 -0800165 JDWP::Request& request)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700166 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700167
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700168 static JDWP::ObjectId CreateString(const std::string& str)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700169 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800170 static JDWP::JdwpError CreateObject(JDWP::RefTypeId class_id, JDWP::ObjectId& new_object)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700171 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800172 static JDWP::JdwpError CreateArrayObject(JDWP::RefTypeId array_class_id, uint32_t length,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700173 JDWP::ObjectId& new_array)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700174 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700175
Elliott Hughes88d63092013-01-09 09:55:54 -0800176 static bool MatchType(JDWP::RefTypeId instance_class_id, JDWP::RefTypeId class_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700177 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700178
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800179 //
180 // Monitors.
181 //
182 static JDWP::JdwpError GetMonitorInfo(JDWP::ObjectId object_id, JDWP::ExpandBuf* reply)
183 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
184 static JDWP::JdwpError GetOwnedMonitors(JDWP::ObjectId thread_id,
185 std::vector<JDWP::ObjectId>& monitors,
186 std::vector<uint32_t>& stack_depths)
187 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
188 static JDWP::JdwpError GetContendedMonitor(JDWP::ObjectId thread_id, JDWP::ObjectId& contended_monitor)
189 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
190
191 //
192 // Heap.
193 //
194 static JDWP::JdwpError GetInstanceCounts(const std::vector<JDWP::RefTypeId>& class_ids,
195 std::vector<uint64_t>& counts)
196 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes3b78c942013-01-15 17:35:41 -0800197 static JDWP::JdwpError GetInstances(JDWP::RefTypeId class_id, int32_t max_count,
198 std::vector<JDWP::ObjectId>& instances)
199 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes0cbaff52013-01-16 15:28:01 -0800200 static JDWP::JdwpError GetReferringObjects(JDWP::ObjectId object_id, int32_t max_count,
201 std::vector<JDWP::ObjectId>& referring_objects)
202 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes64f574f2013-02-20 14:57:12 -0800203 static JDWP::JdwpError DisableCollection(JDWP::ObjectId object_id)
204 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
205 static JDWP::JdwpError EnableCollection(JDWP::ObjectId object_id)
206 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
207 static JDWP::JdwpError IsCollected(JDWP::ObjectId object_id, bool& is_collected)
208 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
209 static void DisposeObject(JDWP::ObjectId object_id, uint32_t reference_count)
210 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800211
Elliott Hughes9777ba22013-01-17 09:04:19 -0800212 //
213 // Methods and fields.
214 //
Elliott Hughesa96836a2013-01-17 12:27:49 -0800215 static std::string GetMethodName(JDWP::MethodId method_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700216 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800217 static JDWP::JdwpError OutputDeclaredFields(JDWP::RefTypeId ref_type_id, bool with_generic,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700218 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700219 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800220 static JDWP::JdwpError OutputDeclaredMethods(JDWP::RefTypeId ref_type_id, bool with_generic,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700221 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700222 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800223 static JDWP::JdwpError OutputDeclaredInterfaces(JDWP::RefTypeId ref_type_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700224 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700225 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800226 static void OutputLineTable(JDWP::RefTypeId ref_type_id, JDWP::MethodId method_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700227 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700228 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800229 static void OutputVariableTable(JDWP::RefTypeId ref_type_id, JDWP::MethodId id, bool with_generic,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700230 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700231 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes9777ba22013-01-17 09:04:19 -0800232 static JDWP::JdwpError GetBytecodes(JDWP::RefTypeId class_id, JDWP::MethodId method_id,
233 std::vector<uint8_t>& bytecodes)
234 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700235
Elliott Hughesa96836a2013-01-17 12:27:49 -0800236 static std::string GetFieldName(JDWP::FieldId field_id)
237 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800238 static JDWP::JdwpTag GetFieldBasicTag(JDWP::FieldId field_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700239 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800240 static JDWP::JdwpTag GetStaticFieldBasicTag(JDWP::FieldId field_id)
Brian Carlstromf69863b2013-07-17 21:53:13 -0700241 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800242 static JDWP::JdwpError GetFieldValue(JDWP::ObjectId object_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700243 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700244 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800245 static JDWP::JdwpError SetFieldValue(JDWP::ObjectId object_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700246 uint64_t value, int width)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700247 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800248 static JDWP::JdwpError GetStaticFieldValue(JDWP::RefTypeId ref_type_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700249 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700250 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800251 static JDWP::JdwpError SetStaticFieldValue(JDWP::FieldId field_id, uint64_t value, int width)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700252 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700253
Elliott Hughes88d63092013-01-09 09:55:54 -0800254 static std::string StringToUtf8(JDWP::ObjectId string_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700255 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700256
257 /*
258 * Thread, ThreadGroup, Frame
259 */
Elliott Hughes88d63092013-01-09 09:55:54 -0800260 static JDWP::JdwpError GetThreadName(JDWP::ObjectId thread_id, std::string& name)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700261 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
262 LOCKS_EXCLUDED(Locks::thread_list_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800263 static JDWP::JdwpError GetThreadGroup(JDWP::ObjectId thread_id, JDWP::ExpandBuf* pReply);
264 static std::string GetThreadGroupName(JDWP::ObjectId thread_group_id);
265 static JDWP::ObjectId GetThreadGroupParent(JDWP::ObjectId thread_group_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700266 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700267 static JDWP::ObjectId GetSystemThreadGroupId()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700268 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700269 static JDWP::ObjectId GetMainThreadGroupId();
270
Elliott Hughes88d63092013-01-09 09:55:54 -0800271 static JDWP::JdwpError GetThreadStatus(JDWP::ObjectId thread_id, JDWP::JdwpThreadStatus* pThreadStatus, JDWP::JdwpSuspendStatus* pSuspendStatus);
272 static JDWP::JdwpError GetThreadDebugSuspendCount(JDWP::ObjectId thread_id, JDWP::ExpandBuf* pReply);
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700273 // static void WaitForSuspend(JDWP::ObjectId thread_id);
Elliott Hughescaf76542012-06-28 16:08:22 -0700274
Elliott Hughes026b1462012-06-28 20:43:49 -0700275 // Fills 'thread_ids' with the threads in the given thread group. If thread_group_id == 0,
Elliott Hughescaf76542012-06-28 16:08:22 -0700276 // returns all threads.
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700277 static void GetThreads(JDWP::ObjectId thread_group_id, std::vector<JDWP::ObjectId>& thread_ids)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700278 LOCKS_EXCLUDED(Locks::thread_list_lock_)
279 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughescaf76542012-06-28 16:08:22 -0700280 static void GetChildThreadGroups(JDWP::ObjectId thread_group_id, std::vector<JDWP::ObjectId>& child_thread_group_ids);
281
Elliott Hughes88d63092013-01-09 09:55:54 -0800282 static JDWP::JdwpError GetThreadFrameCount(JDWP::ObjectId thread_id, size_t& result);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700283 static JDWP::JdwpError GetThreadFrames(JDWP::ObjectId thread_id, size_t start_frame,
284 size_t frame_count, JDWP::ExpandBuf* buf)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700285 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700286
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700287 static JDWP::ObjectId GetThreadSelfId()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700288 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700289 static void SuspendVM()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700290 LOCKS_EXCLUDED(Locks::thread_list_lock_,
291 Locks::thread_suspend_count_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700292 static void ResumeVM();
Elliott Hughes88d63092013-01-09 09:55:54 -0800293 static JDWP::JdwpError SuspendThread(JDWP::ObjectId thread_id, bool request_suspension = true)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700294 LOCKS_EXCLUDED(Locks::mutator_lock_,
295 Locks::thread_list_lock_,
296 Locks::thread_suspend_count_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700297
Elliott Hughes88d63092013-01-09 09:55:54 -0800298 static void ResumeThread(JDWP::ObjectId thread_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700299 LOCKS_EXCLUDED(Locks::thread_list_lock_,
300 Locks::thread_suspend_count_lock_)
301 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700302 static void SuspendSelf();
303
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700304 static JDWP::JdwpError GetThisObject(JDWP::ObjectId thread_id, JDWP::FrameId frame_id,
305 JDWP::ObjectId* result)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700306 LOCKS_EXCLUDED(Locks::thread_list_lock_,
307 Locks::thread_suspend_count_lock_)
308 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800309 static void GetLocalValue(JDWP::ObjectId thread_id, JDWP::FrameId frame_id, int slot,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700310 JDWP::JdwpTag tag, uint8_t* buf, size_t expectedLen)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700311 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800312 static void SetLocalValue(JDWP::ObjectId thread_id, JDWP::FrameId frame_id, int slot,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700313 JDWP::JdwpTag tag, uint64_t value, size_t width)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700314 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700315
Elliott Hughesf9501702013-01-11 11:22:27 -0800316 static JDWP::JdwpError Interrupt(JDWP::ObjectId thread_id);
317
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700318 /*
319 * Debugger notification
320 */
321 enum {
Elliott Hughes86964332012-02-15 19:37:42 -0800322 kBreakpoint = 0x01,
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700323 kSingleStep = 0x02,
324 kMethodEntry = 0x04,
325 kMethodExit = 0x08,
326 };
Brian Carlstromea46f952013-07-30 01:26:50 -0700327 static void PostLocationEvent(const mirror::ArtMethod* method, int pcOffset,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800328 mirror::Object* thisPtr, int eventFlags)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700329 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers62d6c772013-02-27 08:32:07 -0800330 static void PostException(Thread* thread, const ThrowLocation& throw_location,
Brian Carlstromea46f952013-07-30 01:26:50 -0700331 mirror::ArtMethod* catch_method,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800332 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 Rogers62d6c772013-02-27 08:32:07 -0800341 static void UpdateDebugger(Thread* thread, mirror::Object* this_object,
Brian Carlstromea46f952013-07-30 01:26:50 -0700342 const mirror::ArtMethod* method, uint32_t new_dex_pc)
jeffhao09bfc6a2012-12-11 18:11:43 -0800343 LOCKS_EXCLUDED(Locks::breakpoint_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700344 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes91bf6cd2012-02-14 17:27:48 -0800345
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700346 static void WatchLocation(const JDWP::JdwpLocation* pLoc)
jeffhao09bfc6a2012-12-11 18:11:43 -0800347 LOCKS_EXCLUDED(Locks::breakpoint_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700348 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700349 static void UnwatchLocation(const JDWP::JdwpLocation* pLoc)
jeffhao09bfc6a2012-12-11 18:11:43 -0800350 LOCKS_EXCLUDED(Locks::breakpoint_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700351 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800352 static JDWP::JdwpError ConfigureStep(JDWP::ObjectId thread_id, JDWP::JdwpStepSize size,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700353 JDWP::JdwpStepDepth depth)
jeffhao09bfc6a2012-12-11 18:11:43 -0800354 LOCKS_EXCLUDED(Locks::breakpoint_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700355 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800356 static void UnconfigureStep(JDWP::ObjectId thread_id) LOCKS_EXCLUDED(Locks::breakpoint_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700357
Elliott Hughes88d63092013-01-09 09:55:54 -0800358 static JDWP::JdwpError InvokeMethod(JDWP::ObjectId thread_id, JDWP::ObjectId object_id,
359 JDWP::RefTypeId class_id, JDWP::MethodId method_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700360 uint32_t arg_count, uint64_t* arg_values,
361 JDWP::JdwpTag* arg_types, uint32_t options,
362 JDWP::JdwpTag* pResultTag, uint64_t* pResultValue,
363 JDWP::ObjectId* pExceptObj)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700364 LOCKS_EXCLUDED(Locks::thread_list_lock_,
365 Locks::thread_suspend_count_lock_)
366 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700367 static void ExecuteMethod(DebugInvokeReq* pReq);
368
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700369 /*
370 * DDM support.
371 */
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700372 static void DdmSendThreadNotification(Thread* t, uint32_t type)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700373 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes47fce012011-10-25 18:37:19 -0700374 static void DdmSetThreadNotification(bool enable);
Elliott Hughes4b9702c2013-02-20 18:13:24 -0800375 static bool DdmHandlePacket(JDWP::Request& request, uint8_t** pReplyBuf, int* pReplyLen);
Ian Rogersb726dcb2012-09-05 08:57:23 -0700376 static void DdmConnected() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
377 static void DdmDisconnected() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700378 static void DdmSendChunk(uint32_t type, const std::vector<uint8_t>& bytes)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700379 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700380 static void DdmSendChunk(uint32_t type, size_t len, const uint8_t* buf)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700381 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700382 static void DdmSendChunkV(uint32_t type, const iovec* iov, int iov_count)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700383 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -0700384
Elliott Hughes545a0642011-11-08 19:10:03 -0800385 /*
386 * Recent allocation tracking support.
387 */
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800388 static void RecordAllocation(mirror::Class* type, size_t byte_count)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700389 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes545a0642011-11-08 19:10:03 -0800390 static void SetAllocTrackingEnabled(bool enabled);
391 static inline bool IsAllocTrackingEnabled() { return recent_allocation_records_ != NULL; }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800392 static jbyteArray GetRecentAllocations() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes545a0642011-11-08 19:10:03 -0800393 static void DumpRecentAllocations();
394
Elliott Hughes767a1472011-10-26 18:49:02 -0700395 enum HpifWhen {
396 HPIF_WHEN_NEVER = 0,
397 HPIF_WHEN_NOW = 1,
398 HPIF_WHEN_NEXT_GC = 2,
399 HPIF_WHEN_EVERY_GC = 3
400 };
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700401 static int DdmHandleHpifChunk(HpifWhen when)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700402 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -0700403
404 enum HpsgWhen {
405 HPSG_WHEN_NEVER = 0,
406 HPSG_WHEN_EVERY_GC = 1,
407 };
408 enum HpsgWhat {
409 HPSG_WHAT_MERGED_OBJECTS = 0,
410 HPSG_WHAT_DISTINCT_OBJECTS = 1,
411 };
412 static bool DdmHandleHpsgNhsgChunk(HpsgWhen when, HpsgWhat what, bool native);
413
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700414 static void DdmSendHeapInfo(HpifWhen reason)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700415 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700416 static void DdmSendHeapSegments(bool native)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700417 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes545a0642011-11-08 19:10:03 -0800418
419 private:
Brian Carlstrom2d888622013-07-18 17:02:00 -0700420 static void DdmBroadcast(bool connect) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700421 static void PostThreadStartOrStop(Thread*, uint32_t)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700422 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughesa2155262011-11-16 16:26:58 -0800423
Elliott Hughes545a0642011-11-08 19:10:03 -0800424 static AllocRecord* recent_allocation_records_;
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700425};
426
427#define CHUNK_TYPE(_name) \
Elliott Hughes82188472011-11-07 18:11:48 -0800428 static_cast<uint32_t>((_name)[0] << 24 | (_name)[1] << 16 | (_name)[2] << 8 | (_name)[3])
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700429
430} // namespace art
431
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700432#endif // ART_RUNTIME_DEBUGGER_H_