Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1 | /* |
| 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 | * JDWP internal interfaces. |
| 18 | */ |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 19 | #ifndef ART_RUNTIME_JDWP_JDWP_PRIV_H_ |
| 20 | #define ART_RUNTIME_JDWP_JDWP_PRIV_H_ |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 21 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 22 | #include "debugger.h" |
| 23 | #include "jdwp/jdwp.h" |
| 24 | #include "jdwp/jdwp_event.h" |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 25 | |
| 26 | #include <pthread.h> |
| 27 | #include <sys/uio.h> |
| 28 | |
| 29 | /* |
| 30 | * JDWP constants. |
| 31 | */ |
| 32 | #define kJDWPHeaderLen 11 |
| 33 | #define kJDWPFlagReply 0x80 |
| 34 | |
Elliott Hughes | 7484741 | 2012-06-20 18:10:21 -0700 | [diff] [blame] | 35 | #define kMagicHandshake "JDWP-Handshake" |
| 36 | #define kMagicHandshakeLen (sizeof(kMagicHandshake)-1) |
| 37 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 38 | /* DDM support */ |
| 39 | #define kJDWPDdmCmdSet 199 /* 0xc7, or 'G'+128 */ |
| 40 | #define kJDWPDdmCmd 1 |
| 41 | |
| 42 | namespace art { |
| 43 | |
| 44 | namespace JDWP { |
| 45 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 46 | struct JdwpState; |
| 47 | |
Elliott Hughes | 5d10a87 | 2013-04-17 19:26:43 -0700 | [diff] [blame] | 48 | bool InitSocketTransport(JdwpState*, const JdwpOptions*); |
| 49 | bool InitAdbTransport(JdwpState*, const JdwpOptions*); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 50 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 51 | /* |
Elliott Hughes | 68a5e3c | 2013-04-17 17:13:35 -0700 | [diff] [blame] | 52 | * Base class for the adb and socket JdwpNetState implementations. |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 53 | */ |
| 54 | class JdwpNetStateBase { |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 55 | public: |
Brian Carlstrom | 93ba893 | 2013-07-17 21:31:49 -0700 | [diff] [blame] | 56 | explicit JdwpNetStateBase(JdwpState*); |
Elliott Hughes | 5d10a87 | 2013-04-17 19:26:43 -0700 | [diff] [blame] | 57 | virtual ~JdwpNetStateBase(); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 58 | |
Elliott Hughes | 5d10a87 | 2013-04-17 19:26:43 -0700 | [diff] [blame] | 59 | virtual bool Accept() = 0; |
| 60 | virtual bool Establish(const JdwpOptions*) = 0; |
| 61 | virtual void Shutdown() = 0; |
| 62 | virtual bool ProcessIncoming() = 0; |
Elliott Hughes | 68a5e3c | 2013-04-17 17:13:35 -0700 | [diff] [blame] | 63 | |
Elliott Hughes | cb69306 | 2013-02-21 09:48:08 -0800 | [diff] [blame] | 64 | void ConsumeBytes(size_t byte_count); |
Elliott Hughes | 68a5e3c | 2013-04-17 17:13:35 -0700 | [diff] [blame] | 65 | |
| 66 | bool IsConnected(); |
| 67 | |
| 68 | bool IsAwaitingHandshake(); |
Elliott Hughes | 68a5e3c | 2013-04-17 17:13:35 -0700 | [diff] [blame] | 69 | |
| 70 | void Close(); |
| 71 | |
Elliott Hughes | cb69306 | 2013-02-21 09:48:08 -0800 | [diff] [blame] | 72 | ssize_t WritePacket(ExpandBuf* pReply); |
Brian Carlstrom | f529352 | 2013-07-19 00:24:00 -0700 | [diff] [blame] | 73 | ssize_t WriteBufferedPacket(const std::vector<iovec>& iov); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 74 | |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 75 | int clientSock; // Active connection to debugger. |
Elliott Hughes | 5d10a87 | 2013-04-17 19:26:43 -0700 | [diff] [blame] | 76 | |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 77 | int wake_pipe_[2]; // Used to break out of select. |
Elliott Hughes | 5d10a87 | 2013-04-17 19:26:43 -0700 | [diff] [blame] | 78 | |
| 79 | uint8_t input_buffer_[8192]; |
| 80 | size_t input_count_; |
| 81 | |
| 82 | protected: |
| 83 | bool HaveFullPacket(); |
| 84 | |
| 85 | bool MakePipe(); |
| 86 | void WakePipe(); |
| 87 | |
| 88 | void SetAwaitingHandshake(bool new_state); |
| 89 | |
| 90 | JdwpState* state_; |
| 91 | |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 92 | private: |
| 93 | // Used to serialize writes to the socket. |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 94 | Mutex socket_lock_; |
Elliott Hughes | 68a5e3c | 2013-04-17 17:13:35 -0700 | [diff] [blame] | 95 | |
| 96 | // Are we waiting for the JDWP handshake? |
| 97 | bool awaiting_handshake_; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 98 | }; |
| 99 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 100 | } // namespace JDWP |
| 101 | |
| 102 | } // namespace art |
| 103 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 104 | #endif // ART_RUNTIME_JDWP_JDWP_PRIV_H_ |