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