blob: 4e6aadac1a4cac3d840493662361227a99eb6ab6 [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 * JDWP internal interfaces.
18 */
Brian Carlstromfc0e3212013-07-17 14:40:12 -070019#ifndef ART_RUNTIME_JDWP_JDWP_PRIV_H_
20#define ART_RUNTIME_JDWP_JDWP_PRIV_H_
Elliott Hughes872d4ec2011-10-21 17:07:15 -070021
Elliott Hughes872d4ec2011-10-21 17:07:15 -070022#include "debugger.h"
23#include "jdwp/jdwp.h"
24#include "jdwp/jdwp_event.h"
Elliott Hughes872d4ec2011-10-21 17:07:15 -070025
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 Hughes74847412012-06-20 18:10:21 -070035#define kMagicHandshake "JDWP-Handshake"
36#define kMagicHandshakeLen (sizeof(kMagicHandshake)-1)
37
Elliott Hughes872d4ec2011-10-21 17:07:15 -070038/* DDM support */
39#define kJDWPDdmCmdSet 199 /* 0xc7, or 'G'+128 */
40#define kJDWPDdmCmd 1
41
42namespace art {
43
44namespace JDWP {
45
Elliott Hughes872d4ec2011-10-21 17:07:15 -070046struct JdwpState;
47
Elliott Hughes5d10a872013-04-17 19:26:43 -070048bool InitSocketTransport(JdwpState*, const JdwpOptions*);
49bool InitAdbTransport(JdwpState*, const JdwpOptions*);
Elliott Hughes872d4ec2011-10-21 17:07:15 -070050
Elliott Hughes872d4ec2011-10-21 17:07:15 -070051/*
Elliott Hughes68a5e3c2013-04-17 17:13:35 -070052 * Base class for the adb and socket JdwpNetState implementations.
Elliott Hughes872d4ec2011-10-21 17:07:15 -070053 */
54class JdwpNetStateBase {
Elliott Hughesf8349362012-06-18 15:00:06 -070055 public:
Brian Carlstrom93ba8932013-07-17 21:31:49 -070056 explicit JdwpNetStateBase(JdwpState*);
Elliott Hughes5d10a872013-04-17 19:26:43 -070057 virtual ~JdwpNetStateBase();
Elliott Hughes872d4ec2011-10-21 17:07:15 -070058
Elliott Hughes5d10a872013-04-17 19:26:43 -070059 virtual bool Accept() = 0;
60 virtual bool Establish(const JdwpOptions*) = 0;
61 virtual void Shutdown() = 0;
62 virtual bool ProcessIncoming() = 0;
Elliott Hughes68a5e3c2013-04-17 17:13:35 -070063
Elliott Hughescb693062013-02-21 09:48:08 -080064 void ConsumeBytes(size_t byte_count);
Elliott Hughes68a5e3c2013-04-17 17:13:35 -070065
66 bool IsConnected();
67
68 bool IsAwaitingHandshake();
Elliott Hughes68a5e3c2013-04-17 17:13:35 -070069
70 void Close();
71
Elliott Hughescb693062013-02-21 09:48:08 -080072 ssize_t WritePacket(ExpandBuf* pReply);
Brian Carlstromf5293522013-07-19 00:24:00 -070073 ssize_t WriteBufferedPacket(const std::vector<iovec>& iov);
Elliott Hughes872d4ec2011-10-21 17:07:15 -070074
Brian Carlstrom7934ac22013-07-26 10:54:15 -070075 int clientSock; // Active connection to debugger.
Elliott Hughes5d10a872013-04-17 19:26:43 -070076
Brian Carlstrom7934ac22013-07-26 10:54:15 -070077 int wake_pipe_[2]; // Used to break out of select.
Elliott Hughes5d10a872013-04-17 19:26:43 -070078
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 Hughesf8349362012-06-18 15:00:06 -070092 private:
93 // Used to serialize writes to the socket.
Elliott Hughes872d4ec2011-10-21 17:07:15 -070094 Mutex socket_lock_;
Elliott Hughes68a5e3c2013-04-17 17:13:35 -070095
96 // Are we waiting for the JDWP handshake?
97 bool awaiting_handshake_;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070098};
99
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700100} // namespace JDWP
101
102} // namespace art
103
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700104#endif // ART_RUNTIME_JDWP_JDWP_PRIV_H_