blob: acbb2c6ae883d7d34610b17beb06c7cc756f5253 [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
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +010026#include <set>
Elliott Hughes3bb81562011-10-21 18:52:59 -070027#include <string>
28
Elliott Hughes872d4ec2011-10-21 17:07:15 -070029#include "jdwp/jdwp.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080030#include "jni.h"
31#include "jvalue.h"
32#include "root_visitor.h"
Jeff Hao920af3e2013-08-28 15:46:38 -070033#include "thread_state.h"
Elliott Hughes872d4ec2011-10-21 17:07:15 -070034
35namespace art {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080036namespace mirror {
Brian Carlstromea46f952013-07-30 01:26:50 -070037class ArtMethod;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080038class Class;
39class Object;
40class Throwable;
41} // namespace mirror
Elliott Hughes545a0642011-11-08 19:10:03 -080042struct AllocRecord;
Ian Rogers1b09b092012-08-20 15:35:52 -070043class Thread;
Ian Rogers62d6c772013-02-27 08:32:07 -080044class ThrowLocation;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070045
46/*
47 * Invoke-during-breakpoint support.
48 */
49struct DebugInvokeReq {
Elliott Hughes7b3cdfc2011-12-08 21:28:17 -080050 DebugInvokeReq()
Sebastien Hertzd38667a2013-11-25 15:43:54 +010051 : ready(false), invoke_needed(false),
52 receiver(NULL), thread(NULL), klass(NULL), method(NULL),
53 arg_count(0), arg_values(NULL), options(0), error(JDWP::ERR_NONE),
Ian Rogers00f7d0e2012-07-19 15:28:27 -070054 result_tag(JDWP::JT_VOID), exception(0),
Sebastien Hertzd38667a2013-11-25 15:43:54 +010055 lock("a DebugInvokeReq lock", kBreakpointInvokeLock),
56 cond("a DebugInvokeReq condition variable", lock) {
Elliott Hughes475fc232011-10-25 15:00:35 -070057 }
58
Elliott Hughes872d4ec2011-10-21 17:07:15 -070059 /* boolean; only set when we're in the tail end of an event handler */
60 bool ready;
61
62 /* boolean; set if the JDWP thread wants this thread to do work */
Sebastien Hertzd38667a2013-11-25 15:43:54 +010063 bool invoke_needed;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070064
65 /* request */
Sebastien Hertzd38667a2013-11-25 15:43:54 +010066 mirror::Object* receiver; /* not used for ClassType.InvokeMethod */
67 mirror::Object* thread;
68 mirror::Class* klass;
69 mirror::ArtMethod* method;
70 uint32_t arg_count;
71 uint64_t* arg_values; /* will be NULL if arg_count_ == 0 */
72 uint32_t options;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070073
74 /* result */
Elliott Hughes475fc232011-10-25 15:00:35 -070075 JDWP::JdwpError error;
Elliott Hughesd07986f2011-12-06 18:27:45 -080076 JDWP::JdwpTag result_tag;
Elliott Hughes475fc232011-10-25 15:00:35 -070077 JValue result_value;
78 JDWP::ObjectId exception;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070079
80 /* condition variable to wait on while the method executes */
Sebastien Hertzd38667a2013-11-25 15:43:54 +010081 Mutex lock DEFAULT_MUTEX_ACQUIRED_AFTER;
82 ConditionVariable cond GUARDED_BY(lock);
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +010083
84 private:
85 DISALLOW_COPY_AND_ASSIGN(DebugInvokeReq);
86};
87
88// Thread local data-structure that holds fields for controlling single-stepping.
89struct SingleStepControl {
90 SingleStepControl()
91 : is_active(false), step_size(JDWP::SS_MIN), step_depth(JDWP::SD_INTO),
92 method(nullptr), stack_depth(0) {
93 }
94
95 // Are we single-stepping right now?
96 bool is_active;
97
98 // See JdwpStepSize and JdwpStepDepth for details.
99 JDWP::JdwpStepSize step_size;
100 JDWP::JdwpStepDepth step_depth;
101
102 // The location this single-step was initiated from.
103 // A single-step is initiated in a suspended thread. We save here the current method and the
104 // set of DEX pcs associated to the source line number where the suspension occurred.
105 // This is used to support SD_INTO and SD_OVER single-step depths so we detect when a single-step
106 // causes the execution of an instruction in a different method or at a different line number.
107 mirror::ArtMethod* method;
108 std::set<uint32_t> dex_pcs;
109
110 // The stack depth when this single-step was initiated. This is used to support SD_OVER and SD_OUT
111 // single-step depth.
112 int stack_depth;
113
114 private:
115 DISALLOW_COPY_AND_ASSIGN(SingleStepControl);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700116};
117
118class Dbg {
Elliott Hughesff17f1f2012-01-24 18:12:29 -0800119 public:
Elliott Hughes3bb81562011-10-21 18:52:59 -0700120 static bool ParseJdwpOptions(const std::string& options);
Elliott Hughes4ffd3132011-10-24 12:06:42 -0700121 static void SetJdwpAllowed(bool allowed);
122
Elliott Hughesd1cc8362011-10-24 16:58:50 -0700123 static void StartJdwp();
124 static void StopJdwp();
125
Elliott Hughes767a1472011-10-26 18:49:02 -0700126 // Invoked by the GC in case we need to keep DDMS informed.
Ian Rogersb726dcb2012-09-05 08:57:23 -0700127 static void GcDidFinish() LOCKS_EXCLUDED(Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -0700128
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700129 // Return the DebugInvokeReq for the current thread.
130 static DebugInvokeReq* GetInvokeReq();
131
Elliott Hughes475fc232011-10-25 15:00:35 -0700132 static Thread* GetDebugThread();
133 static void ClearWaitForEventThread();
134
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700135 /*
136 * Enable/disable breakpoints and step modes. Used to provide a heads-up
137 * when the debugger attaches.
138 */
139 static void Connected();
Ian Rogers62d6c772013-02-27 08:32:07 -0800140 static void GoActive() LOCKS_EXCLUDED(Locks::breakpoint_lock_, Locks::mutator_lock_);
141 static void Disconnected() LOCKS_EXCLUDED(Locks::mutator_lock_);
Elliott Hughes86964332012-02-15 19:37:42 -0800142 static void Disposed();
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700143
Elliott Hughesc0f09332012-03-26 13:27:06 -0700144 // Returns true if we're actually debugging with a real debugger, false if it's
145 // just DDMS (or nothing at all).
146 static bool IsDebuggerActive();
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700147
Elliott Hughesc0f09332012-03-26 13:27:06 -0700148 // Returns true if we had -Xrunjdwp or -agentlib:jdwp= on the command line.
149 static bool IsJdwpConfigured();
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700150
Elliott Hughes86964332012-02-15 19:37:42 -0800151 static bool IsDisposed();
152
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700153 /*
154 * Time, in milliseconds, since the last debugger activity. Does not
155 * include DDMS activity. Returns -1 if there has been no activity.
156 * Returns 0 if we're in the middle of handling a debugger request.
157 */
158 static int64_t LastDebuggerActivity();
159
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700160 static void UndoDebuggerSuspensions();
161
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700162 /*
163 * Class, Object, Array
164 */
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700165 static std::string GetClassName(JDWP::RefTypeId id)
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 GetClassObject(JDWP::RefTypeId id, JDWP::ObjectId& class_object_id)
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 GetSuperclass(JDWP::RefTypeId id, JDWP::RefTypeId& superclass_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700170 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700171 static JDWP::JdwpError GetClassLoader(JDWP::RefTypeId id, JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700172 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700173 static JDWP::JdwpError GetModifiers(JDWP::RefTypeId id, JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700174 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800175 static JDWP::JdwpError GetReflectedType(JDWP::RefTypeId class_id, JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700176 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700177 static void GetClassList(std::vector<JDWP::RefTypeId>& classes)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700178 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800179 static JDWP::JdwpError GetClassInfo(JDWP::RefTypeId class_id, JDWP::JdwpTypeTag* pTypeTag,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700180 uint32_t* pStatus, std::string* pDescriptor)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700181 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700182 static void FindLoadedClassBySignature(const char* descriptor, std::vector<JDWP::RefTypeId>& ids)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700183 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes64f574f2013-02-20 14:57:12 -0800184 static JDWP::JdwpError GetReferenceType(JDWP::ObjectId object_id, JDWP::ExpandBuf* pReply)
185 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersfc0e94b2013-09-23 23:51:32 -0700186 static JDWP::JdwpError GetSignature(JDWP::RefTypeId ref_type_id, std::string* signature)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700187 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800188 static JDWP::JdwpError GetSourceFile(JDWP::RefTypeId ref_type_id, std::string& source_file)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700189 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800190 static JDWP::JdwpError GetObjectTag(JDWP::ObjectId object_id, uint8_t& tag)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700191 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughesaed4be92011-12-02 16:16:23 -0800192 static size_t GetTagWidth(JDWP::JdwpTag tag);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700193
Elliott Hughes88d63092013-01-09 09:55:54 -0800194 static JDWP::JdwpError GetArrayLength(JDWP::ObjectId array_id, int& length)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700195 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800196 static JDWP::JdwpError OutputArray(JDWP::ObjectId array_id, int offset, int count,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700197 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700198 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800199 static JDWP::JdwpError SetArrayElements(JDWP::ObjectId array_id, int offset, int count,
Elliott Hughes4b9702c2013-02-20 18:13:24 -0800200 JDWP::Request& request)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700201 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700202
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700203 static JDWP::ObjectId CreateString(const std::string& str)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700204 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800205 static JDWP::JdwpError CreateObject(JDWP::RefTypeId class_id, JDWP::ObjectId& new_object)
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 CreateArrayObject(JDWP::RefTypeId array_class_id, uint32_t length,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700208 JDWP::ObjectId& new_array)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700209 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700210
Elliott Hughes88d63092013-01-09 09:55:54 -0800211 static bool MatchType(JDWP::RefTypeId instance_class_id, JDWP::RefTypeId class_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700212 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700213
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800214 //
215 // Monitors.
216 //
217 static JDWP::JdwpError GetMonitorInfo(JDWP::ObjectId object_id, JDWP::ExpandBuf* reply)
218 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
219 static JDWP::JdwpError GetOwnedMonitors(JDWP::ObjectId thread_id,
220 std::vector<JDWP::ObjectId>& monitors,
221 std::vector<uint32_t>& stack_depths)
222 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
223 static JDWP::JdwpError GetContendedMonitor(JDWP::ObjectId thread_id, JDWP::ObjectId& contended_monitor)
224 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
225
226 //
227 // Heap.
228 //
229 static JDWP::JdwpError GetInstanceCounts(const std::vector<JDWP::RefTypeId>& class_ids,
230 std::vector<uint64_t>& counts)
231 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes3b78c942013-01-15 17:35:41 -0800232 static JDWP::JdwpError GetInstances(JDWP::RefTypeId class_id, int32_t max_count,
233 std::vector<JDWP::ObjectId>& instances)
234 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes0cbaff52013-01-16 15:28:01 -0800235 static JDWP::JdwpError GetReferringObjects(JDWP::ObjectId object_id, int32_t max_count,
236 std::vector<JDWP::ObjectId>& referring_objects)
237 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes64f574f2013-02-20 14:57:12 -0800238 static JDWP::JdwpError DisableCollection(JDWP::ObjectId object_id)
239 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
240 static JDWP::JdwpError EnableCollection(JDWP::ObjectId object_id)
241 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
242 static JDWP::JdwpError IsCollected(JDWP::ObjectId object_id, bool& is_collected)
243 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
244 static void DisposeObject(JDWP::ObjectId object_id, uint32_t reference_count)
245 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800246
Elliott Hughes9777ba22013-01-17 09:04:19 -0800247 //
248 // Methods and fields.
249 //
Elliott Hughesa96836a2013-01-17 12:27:49 -0800250 static std::string GetMethodName(JDWP::MethodId method_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700251 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800252 static JDWP::JdwpError OutputDeclaredFields(JDWP::RefTypeId ref_type_id, bool with_generic,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700253 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700254 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800255 static JDWP::JdwpError OutputDeclaredMethods(JDWP::RefTypeId ref_type_id, bool with_generic,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700256 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700257 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800258 static JDWP::JdwpError OutputDeclaredInterfaces(JDWP::RefTypeId ref_type_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700259 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700260 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800261 static void OutputLineTable(JDWP::RefTypeId ref_type_id, JDWP::MethodId method_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700262 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700263 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800264 static void OutputVariableTable(JDWP::RefTypeId ref_type_id, JDWP::MethodId id, bool with_generic,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700265 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700266 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Jeff Hao579b0242013-11-18 13:16:49 -0800267 static void OutputMethodReturnValue(JDWP::MethodId method_id, const JValue* return_value,
268 JDWP::ExpandBuf* pReply)
269 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes9777ba22013-01-17 09:04:19 -0800270 static JDWP::JdwpError GetBytecodes(JDWP::RefTypeId class_id, JDWP::MethodId method_id,
271 std::vector<uint8_t>& bytecodes)
272 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700273
Elliott Hughesa96836a2013-01-17 12:27:49 -0800274 static std::string GetFieldName(JDWP::FieldId field_id)
275 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800276 static JDWP::JdwpTag GetFieldBasicTag(JDWP::FieldId field_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700277 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800278 static JDWP::JdwpTag GetStaticFieldBasicTag(JDWP::FieldId field_id)
Brian Carlstromf69863b2013-07-17 21:53:13 -0700279 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800280 static JDWP::JdwpError GetFieldValue(JDWP::ObjectId object_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700281 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700282 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800283 static JDWP::JdwpError SetFieldValue(JDWP::ObjectId object_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700284 uint64_t value, int width)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700285 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800286 static JDWP::JdwpError GetStaticFieldValue(JDWP::RefTypeId ref_type_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700287 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700288 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800289 static JDWP::JdwpError SetStaticFieldValue(JDWP::FieldId field_id, uint64_t value, int width)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700290 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700291
Elliott Hughes88d63092013-01-09 09:55:54 -0800292 static std::string StringToUtf8(JDWP::ObjectId string_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700293 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Jeff Hao579b0242013-11-18 13:16:49 -0800294 static void OutputJValue(JDWP::JdwpTag tag, const JValue* return_value, JDWP::ExpandBuf* pReply)
295 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700296
297 /*
298 * Thread, ThreadGroup, Frame
299 */
Elliott Hughes88d63092013-01-09 09:55:54 -0800300 static JDWP::JdwpError GetThreadName(JDWP::ObjectId thread_id, std::string& name)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700301 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
302 LOCKS_EXCLUDED(Locks::thread_list_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800303 static JDWP::JdwpError GetThreadGroup(JDWP::ObjectId thread_id, JDWP::ExpandBuf* pReply);
304 static std::string GetThreadGroupName(JDWP::ObjectId thread_group_id);
305 static JDWP::ObjectId GetThreadGroupParent(JDWP::ObjectId thread_group_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700306 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700307 static JDWP::ObjectId GetSystemThreadGroupId()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700308 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700309 static JDWP::ObjectId GetMainThreadGroupId();
310
Jeff Hao920af3e2013-08-28 15:46:38 -0700311 static JDWP::JdwpThreadStatus ToJdwpThreadStatus(ThreadState state);
Elliott Hughes88d63092013-01-09 09:55:54 -0800312 static JDWP::JdwpError GetThreadStatus(JDWP::ObjectId thread_id, JDWP::JdwpThreadStatus* pThreadStatus, JDWP::JdwpSuspendStatus* pSuspendStatus);
313 static JDWP::JdwpError GetThreadDebugSuspendCount(JDWP::ObjectId thread_id, JDWP::ExpandBuf* pReply);
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700314 // static void WaitForSuspend(JDWP::ObjectId thread_id);
Elliott Hughescaf76542012-06-28 16:08:22 -0700315
Elliott Hughes026b1462012-06-28 20:43:49 -0700316 // Fills 'thread_ids' with the threads in the given thread group. If thread_group_id == 0,
Elliott Hughescaf76542012-06-28 16:08:22 -0700317 // returns all threads.
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700318 static void GetThreads(JDWP::ObjectId thread_group_id, std::vector<JDWP::ObjectId>& thread_ids)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700319 LOCKS_EXCLUDED(Locks::thread_list_lock_)
320 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughescaf76542012-06-28 16:08:22 -0700321 static void GetChildThreadGroups(JDWP::ObjectId thread_group_id, std::vector<JDWP::ObjectId>& child_thread_group_ids);
322
Elliott Hughes88d63092013-01-09 09:55:54 -0800323 static JDWP::JdwpError GetThreadFrameCount(JDWP::ObjectId thread_id, size_t& result);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700324 static JDWP::JdwpError GetThreadFrames(JDWP::ObjectId thread_id, size_t start_frame,
325 size_t frame_count, JDWP::ExpandBuf* buf)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700326 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700327
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700328 static JDWP::ObjectId GetThreadSelfId()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700329 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700330 static void SuspendVM()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700331 LOCKS_EXCLUDED(Locks::thread_list_lock_,
332 Locks::thread_suspend_count_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700333 static void ResumeVM();
Elliott Hughes88d63092013-01-09 09:55:54 -0800334 static JDWP::JdwpError SuspendThread(JDWP::ObjectId thread_id, bool request_suspension = true)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700335 LOCKS_EXCLUDED(Locks::mutator_lock_,
336 Locks::thread_list_lock_,
337 Locks::thread_suspend_count_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700338
Elliott Hughes88d63092013-01-09 09:55:54 -0800339 static void ResumeThread(JDWP::ObjectId thread_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700340 LOCKS_EXCLUDED(Locks::thread_list_lock_,
341 Locks::thread_suspend_count_lock_)
342 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700343 static void SuspendSelf();
344
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700345 static JDWP::JdwpError GetThisObject(JDWP::ObjectId thread_id, JDWP::FrameId frame_id,
346 JDWP::ObjectId* result)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700347 LOCKS_EXCLUDED(Locks::thread_list_lock_,
348 Locks::thread_suspend_count_lock_)
349 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800350 static void GetLocalValue(JDWP::ObjectId thread_id, JDWP::FrameId frame_id, int slot,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700351 JDWP::JdwpTag tag, uint8_t* buf, size_t expectedLen)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700352 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800353 static void SetLocalValue(JDWP::ObjectId thread_id, JDWP::FrameId frame_id, int slot,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700354 JDWP::JdwpTag tag, uint64_t value, size_t width)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700355 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700356
Elliott Hughesf9501702013-01-11 11:22:27 -0800357 static JDWP::JdwpError Interrupt(JDWP::ObjectId thread_id);
358
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700359 /*
360 * Debugger notification
361 */
362 enum {
Elliott Hughes86964332012-02-15 19:37:42 -0800363 kBreakpoint = 0x01,
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700364 kSingleStep = 0x02,
365 kMethodEntry = 0x04,
366 kMethodExit = 0x08,
367 };
Brian Carlstromea46f952013-07-30 01:26:50 -0700368 static void PostLocationEvent(const mirror::ArtMethod* method, int pcOffset,
Jeff Hao579b0242013-11-18 13:16:49 -0800369 mirror::Object* thisPtr, int eventFlags,
370 const JValue* return_value)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700371 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers62d6c772013-02-27 08:32:07 -0800372 static void PostException(Thread* thread, const ThrowLocation& throw_location,
Brian Carlstromea46f952013-07-30 01:26:50 -0700373 mirror::ArtMethod* catch_method,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800374 uint32_t catch_dex_pc, mirror::Throwable* exception)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700375 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700376 static void PostThreadStart(Thread* t)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700377 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700378 static void PostThreadDeath(Thread* t)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700379 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800380 static void PostClassPrepare(mirror::Class* c)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700381 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700382
Ian Rogers62d6c772013-02-27 08:32:07 -0800383 static void UpdateDebugger(Thread* thread, mirror::Object* this_object,
Brian Carlstromea46f952013-07-30 01:26:50 -0700384 const mirror::ArtMethod* method, uint32_t new_dex_pc)
jeffhao09bfc6a2012-12-11 18:11:43 -0800385 LOCKS_EXCLUDED(Locks::breakpoint_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700386 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes91bf6cd2012-02-14 17:27:48 -0800387
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700388 static void WatchLocation(const JDWP::JdwpLocation* pLoc)
jeffhao09bfc6a2012-12-11 18:11:43 -0800389 LOCKS_EXCLUDED(Locks::breakpoint_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700390 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700391 static void UnwatchLocation(const JDWP::JdwpLocation* pLoc)
jeffhao09bfc6a2012-12-11 18:11:43 -0800392 LOCKS_EXCLUDED(Locks::breakpoint_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700393 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800394 static JDWP::JdwpError ConfigureStep(JDWP::ObjectId thread_id, JDWP::JdwpStepSize size,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700395 JDWP::JdwpStepDepth depth)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700396 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100397 static void UnconfigureStep(JDWP::ObjectId thread_id)
398 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700399
Elliott Hughes88d63092013-01-09 09:55:54 -0800400 static JDWP::JdwpError InvokeMethod(JDWP::ObjectId thread_id, JDWP::ObjectId object_id,
401 JDWP::RefTypeId class_id, JDWP::MethodId method_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700402 uint32_t arg_count, uint64_t* arg_values,
403 JDWP::JdwpTag* arg_types, uint32_t options,
404 JDWP::JdwpTag* pResultTag, uint64_t* pResultValue,
405 JDWP::ObjectId* pExceptObj)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700406 LOCKS_EXCLUDED(Locks::thread_list_lock_,
407 Locks::thread_suspend_count_lock_)
408 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700409 static void ExecuteMethod(DebugInvokeReq* pReq);
410
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700411 /*
412 * DDM support.
413 */
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700414 static void DdmSendThreadNotification(Thread* t, uint32_t type)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700415 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes47fce012011-10-25 18:37:19 -0700416 static void DdmSetThreadNotification(bool enable);
Elliott Hughes4b9702c2013-02-20 18:13:24 -0800417 static bool DdmHandlePacket(JDWP::Request& request, uint8_t** pReplyBuf, int* pReplyLen);
Ian Rogersb726dcb2012-09-05 08:57:23 -0700418 static void DdmConnected() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
419 static void DdmDisconnected() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700420 static void DdmSendChunk(uint32_t type, const std::vector<uint8_t>& bytes)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700421 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700422 static void DdmSendChunk(uint32_t type, size_t len, const uint8_t* buf)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700423 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700424 static void DdmSendChunkV(uint32_t type, const iovec* iov, int iov_count)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700425 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -0700426
Elliott Hughes545a0642011-11-08 19:10:03 -0800427 /*
428 * Recent allocation tracking support.
429 */
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800430 static void RecordAllocation(mirror::Class* type, size_t byte_count)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700431 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes545a0642011-11-08 19:10:03 -0800432 static void SetAllocTrackingEnabled(bool enabled);
433 static inline bool IsAllocTrackingEnabled() { return recent_allocation_records_ != NULL; }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800434 static jbyteArray GetRecentAllocations() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes545a0642011-11-08 19:10:03 -0800435 static void DumpRecentAllocations();
436
Elliott Hughes767a1472011-10-26 18:49:02 -0700437 enum HpifWhen {
438 HPIF_WHEN_NEVER = 0,
439 HPIF_WHEN_NOW = 1,
440 HPIF_WHEN_NEXT_GC = 2,
441 HPIF_WHEN_EVERY_GC = 3
442 };
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700443 static int DdmHandleHpifChunk(HpifWhen when)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700444 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -0700445
446 enum HpsgWhen {
447 HPSG_WHEN_NEVER = 0,
448 HPSG_WHEN_EVERY_GC = 1,
449 };
450 enum HpsgWhat {
451 HPSG_WHAT_MERGED_OBJECTS = 0,
452 HPSG_WHAT_DISTINCT_OBJECTS = 1,
453 };
454 static bool DdmHandleHpsgNhsgChunk(HpsgWhen when, HpsgWhat what, bool native);
455
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700456 static void DdmSendHeapInfo(HpifWhen reason)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700457 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700458 static void DdmSendHeapSegments(bool native)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700459 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes545a0642011-11-08 19:10:03 -0800460
461 private:
Brian Carlstrom2d888622013-07-18 17:02:00 -0700462 static void DdmBroadcast(bool connect) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700463 static void PostThreadStartOrStop(Thread*, uint32_t)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700464 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughesa2155262011-11-16 16:26:58 -0800465
Elliott Hughes545a0642011-11-08 19:10:03 -0800466 static AllocRecord* recent_allocation_records_;
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700467};
468
469#define CHUNK_TYPE(_name) \
Elliott Hughes82188472011-11-07 18:11:48 -0800470 static_cast<uint32_t>((_name)[0] << 24 | (_name)[1] << 16 | (_name)[2] << 8 | (_name)[3])
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700471
472} // namespace art
473
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700474#endif // ART_RUNTIME_DEBUGGER_H_