LLDB  mainline
AdbClient.h
Go to the documentation of this file.
1 //===-- AdbClient.h ---------------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLDB_SOURCE_PLUGINS_PLATFORM_ANDROID_ADBCLIENT_H
10 #define LLDB_SOURCE_PLUGINS_PLATFORM_ANDROID_ADBCLIENT_H
11 
12 #include "lldb/Utility/Status.h"
13 #include <chrono>
14 #include <functional>
15 #include <list>
16 #include <memory>
17 #include <string>
18 #include <vector>
19 
20 namespace lldb_private {
21 
22 class FileSpec;
23 
24 namespace platform_android {
25 
26 class AdbClient {
27 public:
31  };
32 
33  using DeviceIDList = std::list<std::string>;
34 
35  class SyncService {
36  friend class AdbClient;
37 
38  public:
39  ~SyncService();
40 
41  Status PullFile(const FileSpec &remote_file, const FileSpec &local_file);
42 
43  Status PushFile(const FileSpec &local_file, const FileSpec &remote_file);
44 
45  Status Stat(const FileSpec &remote_file, uint32_t &mode, uint32_t &size,
46  uint32_t &mtime);
47 
48  bool IsConnected() const;
49 
50  private:
51  explicit SyncService(std::unique_ptr<Connection> &&conn);
52 
53  Status SendSyncRequest(const char *request_id, const uint32_t data_len,
54  const void *data);
55 
56  Status ReadSyncHeader(std::string &response_id, uint32_t &data_len);
57 
58  Status PullFileChunk(std::vector<char> &buffer, bool &eof);
59 
60  Status ReadAllBytes(void *buffer, size_t size);
61 
62  Status internalPullFile(const FileSpec &remote_file,
63  const FileSpec &local_file);
64 
65  Status internalPushFile(const FileSpec &local_file,
66  const FileSpec &remote_file);
67 
68  Status internalStat(const FileSpec &remote_file, uint32_t &mode,
69  uint32_t &size, uint32_t &mtime);
70 
71  Status executeCommand(const std::function<Status()> &cmd);
72 
73  std::unique_ptr<Connection> m_conn;
74  };
75 
76  static Status CreateByDeviceID(const std::string &device_id, AdbClient &adb);
77 
78  AdbClient();
79  explicit AdbClient(const std::string &device_id);
80 
81  ~AdbClient();
82 
83  const std::string &GetDeviceID() const;
84 
85  Status GetDevices(DeviceIDList &device_list);
86 
87  Status SetPortForwarding(const uint16_t local_port,
88  const uint16_t remote_port);
89 
90  Status SetPortForwarding(const uint16_t local_port,
91  llvm::StringRef remote_socket_name,
92  const UnixSocketNamespace socket_namespace);
93 
94  Status DeletePortForwarding(const uint16_t local_port);
95 
96  Status Shell(const char *command, std::chrono::milliseconds timeout,
97  std::string *output);
98 
99  Status ShellToFile(const char *command, std::chrono::milliseconds timeout,
100  const FileSpec &output_file_spec);
101 
102  std::unique_ptr<SyncService> GetSyncService(Status &error);
103 
105 
106 private:
107  Status Connect();
108 
109  void SetDeviceID(const std::string &device_id);
110 
111  Status SendMessage(const std::string &packet, const bool reconnect = true);
112 
113  Status SendDeviceMessage(const std::string &packet);
114 
115  Status ReadMessage(std::vector<char> &message);
116 
117  Status ReadMessageStream(std::vector<char> &message,
118  std::chrono::milliseconds timeout);
119 
120  Status GetResponseError(const char *response_id);
121 
123 
124  Status Sync();
125 
126  Status StartSync();
127 
128  Status internalShell(const char *command, std::chrono::milliseconds timeout,
129  std::vector<char> &output_buf);
130 
131  Status ReadAllBytes(void *buffer, size_t size);
132 
134  std::unique_ptr<Connection> m_conn;
135 };
136 
137 } // namespace platform_android
138 } // namespace lldb_private
139 
140 #endif // LLDB_SOURCE_PLUGINS_PLATFORM_ANDROID_ADBCLIENT_H
lldb_private::platform_android::AdbClient::SyncService::IsConnected
bool IsConnected() const
Definition: AdbClient.cpp:563
lldb_private::platform_android::AdbClient::ReadMessageStream
Status ReadMessageStream(std::vector< char > &message, std::chrono::milliseconds timeout)
Definition: AdbClient.cpp:261
lldb_private::platform_android::AdbClient::CreateByDeviceID
static Status CreateByDeviceID(const std::string &device_id, AdbClient &adb)
Definition: AdbClient.cpp:91
lldb_private::platform_android::AdbClient::internalShell
Status internalShell(const char *command, std::chrono::milliseconds timeout, std::vector< char > &output_buf)
Definition: AdbClient.cpp:349
lldb_private::platform_android::AdbClient::SyncService::m_conn
std::unique_ptr< Connection > m_conn
Definition: AdbClient.h:73
lldb_private::platform_android::AdbClient::ReadMessage
Status ReadMessage(std::vector< char > &message)
Definition: AdbClient.cpp:240
lldb_private::platform_android::AdbClient::SetDeviceID
void SetDeviceID(const std::string &device_id)
Definition: AdbClient.cpp:123
lldb_private::platform_android::AdbClient::StartSync
Status StartSync()
Definition: AdbClient.cpp:324
lldb_private::platform_android::AdbClient::SwitchDeviceTransport
Status SwitchDeviceTransport()
Definition: AdbClient.cpp:313
lldb_private::platform_android::AdbClient::ReadResponseStatus
Status ReadResponseStatus()
Definition: AdbClient.cpp:284
lldb_private::platform_android::AdbClient::SyncService::ReadAllBytes
Status ReadAllBytes(void *buffer, size_t size)
Definition: AdbClient.cpp:647
lldb_private::FileSpec
Definition: FileSpec.h:56
error
static llvm::raw_ostream & error(Stream &strm)
Definition: CommandReturnObject.cpp:17
lldb_private::platform_android::AdbClient::SyncService::PushFile
Status PushFile(const FileSpec &local_file, const FileSpec &remote_file)
Definition: AdbClient.cpp:549
lldb_private::platform_android::AdbClient::SyncService::SendSyncRequest
Status SendSyncRequest(const char *request_id, const uint32_t data_len, const void *data)
Definition: AdbClient.cpp:584
lldb_private::platform_android::AdbClient::~AdbClient
~AdbClient()
lldb_private::platform_android::AdbClient::GetDeviceID
const std::string & GetDeviceID() const
Definition: AdbClient.cpp:127
lldb_private::platform_android::AdbClient::DeviceIDList
std::list< std::string > DeviceIDList
Definition: AdbClient.h:33
lldb_private::platform_android::AdbClient::m_conn
std::unique_ptr< Connection > m_conn
Definition: AdbClient.h:134
lldb_private::platform_android::AdbClient::GetDevices
Status GetDevices(DeviceIDList &device_list)
Definition: AdbClient.cpp:142
lldb_private::platform_android::AdbClient::SyncService::Stat
Status Stat(const FileSpec &remote_file, uint32_t &mode, uint32_t &size, uint32_t &mtime)
Definition: AdbClient.cpp:556
lldb_private::platform_android::AdbClient::Connect
Status Connect()
Definition: AdbClient.cpp:129
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:40
lldb_private::platform_android::AdbClient::SyncService::SyncService
SyncService(std::unique_ptr< Connection > &&conn)
Definition: AdbClient.cpp:567
lldb_private::platform_android::AdbClient::SyncService::~SyncService
~SyncService()
lldb_private::platform_android::AdbClient::SyncService::ReadSyncHeader
Status ReadSyncHeader(std::string &response_id, uint32_t &data_len)
Definition: AdbClient.cpp:603
lldb_private::platform_android::AdbClient::Sync
Status Sync()
Definition: AdbClient.cpp:337
lldb_private::platform_android::AdbClient::SendDeviceMessage
Status SendDeviceMessage(const std::string &packet)
Definition: AdbClient.cpp:234
lldb_private::Status
Definition: Status.h:44
message
message(FATAL_ERROR "invalid libipt include path provided") endif() include_directories($
Definition: Plugins/Trace/intel-pt/CMakeLists.txt:6
uint32_t
lldb_private::platform_android::AdbClient::SyncService::internalStat
Status internalStat(const FileSpec &remote_file, uint32_t &mode, uint32_t &size, uint32_t &mtime)
Definition: AdbClient.cpp:508
lldb_private::platform_android::AdbClient
Definition: AdbClient.h:26
lldb_private::platform_android::AdbClient::UnixSocketNamespace
UnixSocketNamespace
Definition: AdbClient.h:28
lldb_private::platform_android::AdbClient::GetSyncService
std::unique_ptr< SyncService > GetSyncService(Status &error)
Definition: AdbClient.cpp:417
lldb_private::platform_android::AdbClient::GetResponseError
Status GetResponseError(const char *response_id)
Definition: AdbClient.cpp:300
lldb_private::platform_android::AdbClient::SyncService
Definition: AdbClient.h:35
lldb_private::platform_android::AdbClient::SetPortForwarding
Status SetPortForwarding(const uint16_t local_port, const uint16_t remote_port)
Definition: AdbClient.cpp:169
lldb_private::platform_android::AdbClient::SyncService::internalPushFile
Status internalPushFile(const FileSpec &local_file, const FileSpec &remote_file)
Definition: AdbClient.cpp:459
lldb_private::platform_android::AdbClient::SendMessage
Status SendMessage(const std::string &packet, const bool reconnect=true)
Definition: AdbClient.cpp:212
uint16_t
lldb_private::platform_android::AdbClient::SyncService::internalPullFile
Status internalPullFile(const FileSpec &remote_file, const FileSpec &local_file)
Definition: AdbClient.cpp:426
lldb_private::platform_android::AdbClient::SyncService::PullFileChunk
Status PullFileChunk(std::vector< char > &buffer, bool &eof)
Definition: AdbClient.cpp:618
Status.h
lldb_private::platform_android::AdbClient::AdbClient
AdbClient()
lldb_private::platform_android::AdbClient::SyncService::executeCommand
Status executeCommand(const std::function< Status()> &cmd)
Definition: AdbClient.cpp:571
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::platform_android::AdbClient::UnixSocketNamespaceAbstract
@ UnixSocketNamespaceAbstract
Definition: AdbClient.h:29
lldb_private::platform_android::AdbClient::ShellToFile
Status ShellToFile(const char *command, std::chrono::milliseconds timeout, const FileSpec &output_file_spec)
Definition: AdbClient.cpp:396
lldb_private::platform_android::AdbClient::SyncService::PullFile
Status PullFile(const FileSpec &remote_file, const FileSpec &local_file)
Definition: AdbClient.cpp:542
lldb_private::platform_android::AdbClient::UnixSocketNamespaceFileSystem
@ UnixSocketNamespaceFileSystem
Definition: AdbClient.h:30
lldb_private::platform_android::AdbClient::DeletePortForwarding
Status DeletePortForwarding(const uint16_t local_port)
Definition: AdbClient.cpp:201
lldb_private::platform_android::AdbClient::ReadAllBytes
Status ReadAllBytes(void *buffer, size_t size)
Definition: AdbClient.cpp:345
lldb_private::platform_android::AdbClient::m_device_id
std::string m_device_id
Definition: AdbClient.h:133
lldb_private::platform_android::AdbClient::Shell
Status Shell(const char *command, std::chrono::milliseconds timeout, std::string *output)
Definition: AdbClient.cpp:384