blob: c8f3cecd7d63a2b61566206fd50b05fcd727ffa4 [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#include "debugger.h"
18
Elliott Hughes3bb81562011-10-21 18:52:59 -070019#include <sys/uio.h>
20
Elliott Hughes872d4ec2011-10-21 17:07:15 -070021namespace art {
22
Elliott Hughes3bb81562011-10-21 18:52:59 -070023// Was there a -Xrunjdwp or -agent argument on the command-line?
24static bool gJdwpConfigured = false;
25
26// Broken-down JDWP options. (Only valid if gJdwpConfigured is true.)
27static JDWP::JdwpTransportType gJdwpTransport;
28static bool gJdwpServer;
29static bool gJdwpSuspend;
30static std::string gJdwpHost;
31static int gJdwpPort;
32
33// Runtime JDWP state.
34static JDWP::JdwpState* gJdwpState = NULL;
35static bool gDebuggerConnected; // debugger or DDMS is connected.
36static bool gDebuggerActive; // debugger is making requests.
37
38/*
39 * Handle one of the JDWP name/value pairs.
40 *
41 * JDWP options are:
42 * help: if specified, show help message and bail
43 * transport: may be dt_socket or dt_shmem
44 * address: for dt_socket, "host:port", or just "port" when listening
45 * server: if "y", wait for debugger to attach; if "n", attach to debugger
46 * timeout: how long to wait for debugger to connect / listen
47 *
48 * Useful with server=n (these aren't supported yet):
49 * onthrow=<exception-name>: connect to debugger when exception thrown
50 * onuncaught=y|n: connect to debugger when uncaught exception thrown
51 * launch=<command-line>: launch the debugger itself
52 *
53 * The "transport" option is required, as is "address" if server=n.
54 */
55static bool ParseJdwpOption(const std::string& name, const std::string& value) {
56 if (name == "transport") {
57 if (value == "dt_socket") {
58 gJdwpTransport = JDWP::kJdwpTransportSocket;
59 } else if (value == "dt_android_adb") {
60 gJdwpTransport = JDWP::kJdwpTransportAndroidAdb;
61 } else {
62 LOG(ERROR) << "JDWP transport not supported: " << value;
63 return false;
64 }
65 } else if (name == "server") {
66 if (value == "n") {
67 gJdwpServer = false;
68 } else if (value == "y") {
69 gJdwpServer = true;
70 } else {
71 LOG(ERROR) << "JDWP option 'server' must be 'y' or 'n'";
72 return false;
73 }
74 } else if (name == "suspend") {
75 if (value == "n") {
76 gJdwpSuspend = false;
77 } else if (value == "y") {
78 gJdwpSuspend = true;
79 } else {
80 LOG(ERROR) << "JDWP option 'suspend' must be 'y' or 'n'";
81 return false;
82 }
83 } else if (name == "address") {
84 /* this is either <port> or <host>:<port> */
85 std::string port_string;
86 gJdwpHost.clear();
87 std::string::size_type colon = value.find(':');
88 if (colon != std::string::npos) {
89 gJdwpHost = value.substr(0, colon);
90 port_string = value.substr(colon + 1);
91 } else {
92 port_string = value;
93 }
94 if (port_string.empty()) {
95 LOG(ERROR) << "JDWP address missing port: " << value;
96 return false;
97 }
98 char* end;
99 long port = strtol(port_string.c_str(), &end, 10);
100 if (*end != '\0') {
101 LOG(ERROR) << "JDWP address has junk in port field: " << value;
102 return false;
103 }
104 gJdwpPort = port;
105 } else if (name == "launch" || name == "onthrow" || name == "oncaught" || name == "timeout") {
106 /* valid but unsupported */
107 LOG(INFO) << "Ignoring JDWP option '" << name << "'='" << value << "'";
108 } else {
109 LOG(INFO) << "Ignoring unrecognized JDWP option '" << name << "'='" << value << "'";
110 }
111
112 return true;
113}
114
115/*
116 * Parse the latter half of a -Xrunjdwp/-agentlib:jdwp= string, e.g.:
117 * "transport=dt_socket,address=8000,server=y,suspend=n"
118 */
119bool Dbg::ParseJdwpOptions(const std::string& options) {
120 std::vector<std::string> pairs;
121 Split(options, ',', pairs);
122
123 for (size_t i = 0; i < pairs.size(); ++i) {
124 std::string::size_type equals = pairs[i].find('=');
125 if (equals == std::string::npos) {
126 LOG(ERROR) << "Can't parse JDWP option '" << pairs[i] << "' in '" << options << "'";
127 return false;
128 }
129 ParseJdwpOption(pairs[i].substr(0, equals), pairs[i].substr(equals + 1));
130 }
131
132 if (gJdwpTransport == JDWP::kJdwpTransportUnknown) {
133 LOG(ERROR) << "Must specify JDWP transport: " << options;
134 }
135 if (!gJdwpServer && (gJdwpHost.empty() || gJdwpPort == 0)) {
136 LOG(ERROR) << "Must specify JDWP host and port when server=n: " << options;
137 return false;
138 }
139
140 gJdwpConfigured = true;
141 return true;
142}
143
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700144bool Dbg::DebuggerStartup() {
145 UNIMPLEMENTED(FATAL);
146 return false;
147}
148
149void Dbg::DebuggerShutdown() {
150 UNIMPLEMENTED(FATAL);
151}
152
153DebugInvokeReq* Dbg::GetInvokeReq() {
154 UNIMPLEMENTED(FATAL);
155 return NULL;
156}
157
158void Dbg::Connected() {
Elliott Hughes3bb81562011-10-21 18:52:59 -0700159 CHECK(!gDebuggerConnected);
160 LOG(VERBOSE) << "JDWP has attached";
161 gDebuggerConnected = true;
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700162}
163
164void Dbg::Active() {
165 UNIMPLEMENTED(FATAL);
166}
167
168void Dbg::Disconnected() {
169 UNIMPLEMENTED(FATAL);
170}
171
172bool Dbg::IsDebuggerConnected() {
Elliott Hughes3bb81562011-10-21 18:52:59 -0700173 return gDebuggerActive;
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700174}
175
176bool Dbg::IsDebuggingEnabled() {
Elliott Hughes3bb81562011-10-21 18:52:59 -0700177 return gJdwpConfigured;
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700178}
179
180int64_t Dbg::LastDebuggerActivity() {
181 UNIMPLEMENTED(WARNING);
182 return -1;
183}
184
185int Dbg::ThreadRunning() {
186 UNIMPLEMENTED(FATAL);
187 return 0;
188}
189
190int Dbg::ThreadWaiting() {
191 UNIMPLEMENTED(FATAL);
192 return 0;
193}
194
195int Dbg::ThreadContinuing(int status) {
196 UNIMPLEMENTED(FATAL);
197 return 0;
198}
199
200void Dbg::UndoDebuggerSuspensions() {
201 UNIMPLEMENTED(FATAL);
202}
203
204void Dbg::Exit(int status) {
205 UNIMPLEMENTED(FATAL);
206}
207
208const char* Dbg::GetClassDescriptor(JDWP::RefTypeId id) {
209 UNIMPLEMENTED(FATAL);
210 return NULL;
211}
212
213JDWP::ObjectId Dbg::GetClassObject(JDWP::RefTypeId id) {
214 UNIMPLEMENTED(FATAL);
215 return 0;
216}
217
218JDWP::RefTypeId Dbg::GetSuperclass(JDWP::RefTypeId id) {
219 UNIMPLEMENTED(FATAL);
220 return 0;
221}
222
223JDWP::ObjectId Dbg::GetClassLoader(JDWP::RefTypeId id) {
224 UNIMPLEMENTED(FATAL);
225 return 0;
226}
227
228uint32_t Dbg::GetAccessFlags(JDWP::RefTypeId id) {
229 UNIMPLEMENTED(FATAL);
230 return 0;
231}
232
233bool Dbg::IsInterface(JDWP::RefTypeId id) {
234 UNIMPLEMENTED(FATAL);
235 return false;
236}
237
238void Dbg::GetClassList(uint32_t* pNumClasses, JDWP::RefTypeId** pClassRefBuf) {
239 UNIMPLEMENTED(FATAL);
240}
241
242void Dbg::GetVisibleClassList(JDWP::ObjectId classLoaderId, uint32_t* pNumClasses, JDWP::RefTypeId** pClassRefBuf) {
243 UNIMPLEMENTED(FATAL);
244}
245
246void Dbg::GetClassInfo(JDWP::RefTypeId classId, uint8_t* pTypeTag, uint32_t* pStatus, const char** pSignature) {
247 UNIMPLEMENTED(FATAL);
248}
249
250bool Dbg::FindLoadedClassBySignature(const char* classDescriptor, JDWP::RefTypeId* pRefTypeId) {
251 UNIMPLEMENTED(FATAL);
252 return false;
253}
254
255void Dbg::GetObjectType(JDWP::ObjectId objectId, uint8_t* pRefTypeTag, JDWP::RefTypeId* pRefTypeId) {
256 UNIMPLEMENTED(FATAL);
257}
258
259uint8_t Dbg::GetClassObjectType(JDWP::RefTypeId refTypeId) {
260 UNIMPLEMENTED(FATAL);
261 return 0;
262}
263
264const char* Dbg::GetSignature(JDWP::RefTypeId refTypeId) {
265 UNIMPLEMENTED(FATAL);
266 return NULL;
267}
268
269const char* Dbg::GetSourceFile(JDWP::RefTypeId refTypeId) {
270 UNIMPLEMENTED(FATAL);
271 return NULL;
272}
273
274const char* Dbg::GetObjectTypeName(JDWP::ObjectId objectId) {
275 UNIMPLEMENTED(FATAL);
276 return NULL;
277}
278
279uint8_t Dbg::GetObjectTag(JDWP::ObjectId objectId) {
280 UNIMPLEMENTED(FATAL);
281 return 0;
282}
283
284int Dbg::GetTagWidth(int tag) {
285 UNIMPLEMENTED(FATAL);
286 return 0;
287}
288
289int Dbg::GetArrayLength(JDWP::ObjectId arrayId) {
290 UNIMPLEMENTED(FATAL);
291 return 0;
292}
293
294uint8_t Dbg::GetArrayElementTag(JDWP::ObjectId arrayId) {
295 UNIMPLEMENTED(FATAL);
296 return 0;
297}
298
299bool Dbg::OutputArray(JDWP::ObjectId arrayId, int firstIndex, int count, JDWP::ExpandBuf* pReply) {
300 UNIMPLEMENTED(FATAL);
301 return false;
302}
303
304bool Dbg::SetArrayElements(JDWP::ObjectId arrayId, int firstIndex, int count, const uint8_t* buf) {
305 UNIMPLEMENTED(FATAL);
306 return false;
307}
308
309JDWP::ObjectId Dbg::CreateString(const char* str) {
310 UNIMPLEMENTED(FATAL);
311 return 0;
312}
313
314JDWP::ObjectId Dbg::CreateObject(JDWP::RefTypeId classId) {
315 UNIMPLEMENTED(FATAL);
316 return 0;
317}
318
319JDWP::ObjectId Dbg::CreateArrayObject(JDWP::RefTypeId arrayTypeId, uint32_t length) {
320 UNIMPLEMENTED(FATAL);
321 return 0;
322}
323
324bool Dbg::MatchType(JDWP::RefTypeId instClassId, JDWP::RefTypeId classId) {
325 UNIMPLEMENTED(FATAL);
326 return false;
327}
328
329const char* Dbg::GetMethodName(JDWP::RefTypeId refTypeId, JDWP::MethodId id) {
330 UNIMPLEMENTED(FATAL);
331 return NULL;
332}
333
334void Dbg::OutputAllFields(JDWP::RefTypeId refTypeId, bool withGeneric, JDWP::ExpandBuf* pReply) {
335 UNIMPLEMENTED(FATAL);
336}
337
338void Dbg::OutputAllMethods(JDWP::RefTypeId refTypeId, bool withGeneric, JDWP::ExpandBuf* pReply) {
339 UNIMPLEMENTED(FATAL);
340}
341
342void Dbg::OutputAllInterfaces(JDWP::RefTypeId refTypeId, JDWP::ExpandBuf* pReply) {
343 UNIMPLEMENTED(FATAL);
344}
345
346void Dbg::OutputLineTable(JDWP::RefTypeId refTypeId, JDWP::MethodId methodId, JDWP::ExpandBuf* pReply) {
347 UNIMPLEMENTED(FATAL);
348}
349
350void Dbg::OutputVariableTable(JDWP::RefTypeId refTypeId, JDWP::MethodId id, bool withGeneric, JDWP::ExpandBuf* pReply) {
351 UNIMPLEMENTED(FATAL);
352}
353
354uint8_t Dbg::GetFieldBasicTag(JDWP::ObjectId objId, JDWP::FieldId fieldId) {
355 UNIMPLEMENTED(FATAL);
356 return 0;
357}
358
359uint8_t Dbg::GetStaticFieldBasicTag(JDWP::RefTypeId refTypeId, JDWP::FieldId fieldId) {
360 UNIMPLEMENTED(FATAL);
361 return 0;
362}
363
364void Dbg::GetFieldValue(JDWP::ObjectId objectId, JDWP::FieldId fieldId, JDWP::ExpandBuf* pReply) {
365 UNIMPLEMENTED(FATAL);
366}
367
368void Dbg::SetFieldValue(JDWP::ObjectId objectId, JDWP::FieldId fieldId, uint64_t value, int width) {
369 UNIMPLEMENTED(FATAL);
370}
371
372void Dbg::GetStaticFieldValue(JDWP::RefTypeId refTypeId, JDWP::FieldId fieldId, JDWP::ExpandBuf* pReply) {
373 UNIMPLEMENTED(FATAL);
374}
375
376void Dbg::SetStaticFieldValue(JDWP::RefTypeId refTypeId, JDWP::FieldId fieldId, uint64_t rawValue, int width) {
377 UNIMPLEMENTED(FATAL);
378}
379
380char* Dbg::StringToUtf8(JDWP::ObjectId strId) {
381 UNIMPLEMENTED(FATAL);
382 return NULL;
383}
384
385char* Dbg::GetThreadName(JDWP::ObjectId threadId) {
386 UNIMPLEMENTED(FATAL);
387 return NULL;
388}
389
390JDWP::ObjectId Dbg::GetThreadGroup(JDWP::ObjectId threadId) {
391 UNIMPLEMENTED(FATAL);
392 return 0;
393}
394
395char* Dbg::GetThreadGroupName(JDWP::ObjectId threadGroupId) {
396 UNIMPLEMENTED(FATAL);
397 return NULL;
398}
399
400JDWP::ObjectId Dbg::GetThreadGroupParent(JDWP::ObjectId threadGroupId) {
401 UNIMPLEMENTED(FATAL);
402 return 0;
403}
404
405JDWP::ObjectId Dbg::GetSystemThreadGroupId() {
406 UNIMPLEMENTED(FATAL);
407 return 0;
408}
409
410JDWP::ObjectId Dbg::GetMainThreadGroupId() {
411 UNIMPLEMENTED(FATAL);
412 return 0;
413}
414
415bool Dbg::GetThreadStatus(JDWP::ObjectId threadId, uint32_t* threadStatus, uint32_t* suspendStatus) {
416 UNIMPLEMENTED(FATAL);
417 return false;
418}
419
420uint32_t Dbg::GetThreadSuspendCount(JDWP::ObjectId threadId) {
421 UNIMPLEMENTED(FATAL);
422 return 0;
423}
424
425bool Dbg::ThreadExists(JDWP::ObjectId threadId) {
426 UNIMPLEMENTED(FATAL);
427 return false;
428}
429
430bool Dbg::IsSuspended(JDWP::ObjectId threadId) {
431 UNIMPLEMENTED(FATAL);
432 return false;
433}
434
435//void Dbg::WaitForSuspend(JDWP::ObjectId threadId);
436
437void Dbg::GetThreadGroupThreads(JDWP::ObjectId threadGroupId, JDWP::ObjectId** ppThreadIds, uint32_t* pThreadCount) {
438 UNIMPLEMENTED(FATAL);
439}
440
441void Dbg::GetAllThreads(JDWP::ObjectId** ppThreadIds, uint32_t* pThreadCount) {
442 UNIMPLEMENTED(FATAL);
443}
444
445int Dbg::GetThreadFrameCount(JDWP::ObjectId threadId) {
446 UNIMPLEMENTED(FATAL);
447 return 0;
448}
449
450bool Dbg::GetThreadFrame(JDWP::ObjectId threadId, int num, JDWP::FrameId* pFrameId, JDWP::JdwpLocation* pLoc) {
451 UNIMPLEMENTED(FATAL);
452 return false;
453}
454
455JDWP::ObjectId Dbg::GetThreadSelfId() {
456 UNIMPLEMENTED(FATAL);
457 return 0;
458}
459
460void Dbg::SuspendVM(bool isEvent) {
461 UNIMPLEMENTED(FATAL);
462}
463
464void Dbg::ResumeVM() {
465 UNIMPLEMENTED(FATAL);
466}
467
468void Dbg::SuspendThread(JDWP::ObjectId threadId) {
469 UNIMPLEMENTED(FATAL);
470}
471
472void Dbg::ResumeThread(JDWP::ObjectId threadId) {
473 UNIMPLEMENTED(FATAL);
474}
475
476void Dbg::SuspendSelf() {
477 UNIMPLEMENTED(FATAL);
478}
479
480bool Dbg::GetThisObject(JDWP::ObjectId threadId, JDWP::FrameId frameId, JDWP::ObjectId* pThisId) {
481 UNIMPLEMENTED(FATAL);
482 return false;
483}
484
485void Dbg::GetLocalValue(JDWP::ObjectId threadId, JDWP::FrameId frameId, int slot, uint8_t tag, uint8_t* buf, int expectedLen) {
486 UNIMPLEMENTED(FATAL);
487}
488
489void Dbg::SetLocalValue(JDWP::ObjectId threadId, JDWP::FrameId frameId, int slot, uint8_t tag, uint64_t value, int width) {
490 UNIMPLEMENTED(FATAL);
491}
492
493void Dbg::PostLocationEvent(const Method* method, int pcOffset, Object* thisPtr, int eventFlags) {
494 UNIMPLEMENTED(FATAL);
495}
496
497void Dbg::PostException(void* throwFp, int throwRelPc, void* catchFp, int catchRelPc, Object* exception) {
498 UNIMPLEMENTED(FATAL);
499}
500
501void Dbg::PostThreadStart(Thread* t) {
Elliott Hughes3bb81562011-10-21 18:52:59 -0700502 if (!gDebuggerConnected) {
503 return;
504 }
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700505 UNIMPLEMENTED(WARNING);
506}
507
508void Dbg::PostThreadDeath(Thread* t) {
Elliott Hughes3bb81562011-10-21 18:52:59 -0700509 if (!gDebuggerConnected) {
510 return;
511 }
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700512 UNIMPLEMENTED(WARNING);
513}
514
515void Dbg::PostClassPrepare(Class* c) {
516 UNIMPLEMENTED(FATAL);
517}
518
519bool Dbg::WatchLocation(const JDWP::JdwpLocation* pLoc) {
520 UNIMPLEMENTED(FATAL);
521 return false;
522}
523
524void Dbg::UnwatchLocation(const JDWP::JdwpLocation* pLoc) {
525 UNIMPLEMENTED(FATAL);
526}
527
528bool Dbg::ConfigureStep(JDWP::ObjectId threadId, JDWP::JdwpStepSize size, JDWP::JdwpStepDepth depth) {
529 UNIMPLEMENTED(FATAL);
530 return false;
531}
532
533void Dbg::UnconfigureStep(JDWP::ObjectId threadId) {
534 UNIMPLEMENTED(FATAL);
535}
536
537JDWP::JdwpError Dbg::InvokeMethod(JDWP::ObjectId threadId, JDWP::ObjectId objectId, JDWP::RefTypeId classId, JDWP::MethodId methodId, uint32_t numArgs, uint64_t* argArray, uint32_t options, uint8_t* pResultTag, uint64_t* pResultValue, JDWP::ObjectId* pExceptObj) {
538 UNIMPLEMENTED(FATAL);
539 return JDWP::ERR_NONE;
540}
541
542void Dbg::ExecuteMethod(DebugInvokeReq* pReq) {
543 UNIMPLEMENTED(FATAL);
544}
545
546void Dbg::RegisterObjectId(JDWP::ObjectId id) {
547 UNIMPLEMENTED(FATAL);
548}
549
550bool Dbg::DdmHandlePacket(const uint8_t* buf, int dataLen, uint8_t** pReplyBuf, int* pReplyLen) {
551 UNIMPLEMENTED(FATAL);
552 return false;
553}
554
555void Dbg::DdmConnected() {
556 UNIMPLEMENTED(FATAL);
557}
558
559void Dbg::DdmDisconnected() {
560 UNIMPLEMENTED(FATAL);
561}
562
Elliott Hughes3bb81562011-10-21 18:52:59 -0700563void Dbg::DdmSendChunk(int type, size_t byte_count, const uint8_t* buf) {
564 CHECK(buf != NULL);
565 iovec vec[1];
566 vec[0].iov_base = reinterpret_cast<void*>(const_cast<uint8_t*>(buf));
567 vec[0].iov_len = byte_count;
568 Dbg::DdmSendChunkV(type, vec, 1);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700569}
570
571void Dbg::DdmSendChunkV(int type, const struct iovec* iov, int iovcnt) {
Elliott Hughes3bb81562011-10-21 18:52:59 -0700572 if (gJdwpState == NULL) {
573 LOG(VERBOSE) << "Debugger thread not active, ignoring DDM send: " << type;
574 } else {
575 JDWP::DdmSendChunkV(gJdwpState, type, iov, iovcnt);
576 }
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700577}
578
579} // namespace art