| Dan Albert | db6fe64 | 2015-03-19 15:21:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 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 | |
| Josh Gao | fa3605a | 2020-03-16 11:30:09 -0700 | [diff] [blame] | 17 | #if !defined(__ANDROID_RECOVERY__) |
| Yabin Cui | 19bec5b | 2015-09-22 15:52:57 -0700 | [diff] [blame] | 18 | #define TRACE_TAG JDWP |
| Dan Albert | db6fe64 | 2015-03-19 15:21:08 -0700 | [diff] [blame] | 19 | |
| The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 20 | #include "sysdeps.h" |
| Dan Albert | db6fe64 | 2015-03-19 15:21:08 -0700 | [diff] [blame] | 21 | |
| The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 22 | #include <errno.h> |
| Shukang Zhou | 420ad55 | 2020-02-13 17:01:39 -0800 | [diff] [blame] | 23 | #include <inttypes.h> |
| The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 24 | #include <stdio.h> |
| Elliott Hughes | 43df109 | 2015-07-23 17:12:58 -0700 | [diff] [blame] | 25 | #include <stdlib.h> |
| The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 26 | #include <string.h> |
| Josh Gao | 9eaf33c | 2016-05-13 15:28:34 -0700 | [diff] [blame] | 27 | #include <sys/socket.h> |
| 28 | #include <sys/un.h> |
| Teddie Stenvi | f56e7f5 | 2010-02-15 12:20:44 +0100 | [diff] [blame] | 29 | #include <unistd.h> |
| The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 30 | |
| Josh Gao | 9eaf33c | 2016-05-13 15:28:34 -0700 | [diff] [blame] | 31 | #include <list> |
| 32 | #include <memory> |
| Josh Gao | eb5e605 | 2019-06-19 14:14:57 -0700 | [diff] [blame] | 33 | #include <thread> |
| Josh Gao | 9eaf33c | 2016-05-13 15:28:34 -0700 | [diff] [blame] | 34 | #include <vector> |
| 35 | |
| Josh Gao | eb5e605 | 2019-06-19 14:14:57 -0700 | [diff] [blame] | 36 | #include <adbconnection/server.h> |
| Josh Gao | 2d83b54 | 2019-01-10 14:29:29 -0800 | [diff] [blame] | 37 | #include <android-base/cmsg.h> |
| Fabien Sanglard | 5d4eaef | 2024-12-18 14:56:14 -0800 | [diff] [blame] | 38 | #include <android-base/file.h> |
| Josh Gao | eb5e605 | 2019-06-19 14:14:57 -0700 | [diff] [blame] | 39 | #include <android-base/unique_fd.h> |
| Fabien Sanglard | 5d4eaef | 2024-12-18 14:56:14 -0800 | [diff] [blame] | 40 | #include <processgroup/processgroup.h> |
| Josh Gao | 2d83b54 | 2019-01-10 14:29:29 -0800 | [diff] [blame] | 41 | |
| Dan Albert | db6fe64 | 2015-03-19 15:21:08 -0700 | [diff] [blame] | 42 | #include "adb.h" |
| Josh Gao | 9eaf33c | 2016-05-13 15:28:34 -0700 | [diff] [blame] | 43 | #include "adb_io.h" |
| Josh Gao | ea7457b | 2016-08-30 15:39:25 -0700 | [diff] [blame] | 44 | #include "adb_unique_fd.h" |
| Yabin Cui | 5fc2231 | 2015-10-06 15:10:05 -0700 | [diff] [blame] | 45 | #include "adb_utils.h" |
| Shukang Zhou | 420ad55 | 2020-02-13 17:01:39 -0800 | [diff] [blame] | 46 | #include "app_processes.pb.h" |
| Dan Albert | db6fe64 | 2015-03-19 15:21:08 -0700 | [diff] [blame] | 47 | |
| Josh Gao | eb5e605 | 2019-06-19 14:14:57 -0700 | [diff] [blame] | 48 | using android::base::borrowed_fd; |
| 49 | using android::base::unique_fd; |
| 50 | |
| The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 51 | /* here's how these things work. |
| 52 | |
| 53 | when adbd starts, it creates a unix server socket |
| Josh Gao | 9eaf33c | 2016-05-13 15:28:34 -0700 | [diff] [blame] | 54 | named @jdwp-control (@ is a shortcut for "first byte is zero" |
| The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 55 | to use the private namespace instead of the file system) |
| 56 | |
| 57 | when a new JDWP daemon thread starts in a new VM process, it creates |
| Josh Gao | 9eaf33c | 2016-05-13 15:28:34 -0700 | [diff] [blame] | 58 | a connection to @jdwp-control to announce its availability. |
| The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 59 | |
| 60 | |
| Josh Gao | 9eaf33c | 2016-05-13 15:28:34 -0700 | [diff] [blame] | 61 | JDWP thread @jdwp-control |
| The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 62 | | | |
| 63 | |-------------------------------> | |
| 64 | | hello I'm in process <pid> | |
| 65 | | | |
| 66 | | | |
| 67 | |
| 68 | the connection is kept alive. it will be closed automatically if |
| 69 | the JDWP process terminates (this allows adbd to detect dead |
| 70 | processes). |
| 71 | |
| 72 | adbd thus maintains a list of "active" JDWP processes. it can send |
| 73 | its content to clients through the "device:debug-ports" service, |
| 74 | or even updates through the "device:track-debug-ports" service. |
| 75 | |
| 76 | when a debugger wants to connect, it simply runs the command |
| 77 | equivalent to "adb forward tcp:<hostport> jdwp:<pid>" |
| 78 | |
| 79 | "jdwp:<pid>" is a new forward destination format used to target |
| 80 | a given JDWP process on the device. when sutch a request arrives, |
| 81 | adbd does the following: |
| 82 | |
| 83 | - first, it calls socketpair() to create a pair of equivalent |
| 84 | sockets. |
| 85 | |
| 86 | - it attaches the first socket in the pair to a local socket |
| 87 | which is itself attached to the transport's remote socket: |
| 88 | |
| 89 | |
| 90 | - it sends the file descriptor of the second socket directly |
| 91 | to the JDWP process with the help of sendmsg() |
| 92 | |
| 93 | |
| Josh Gao | 9eaf33c | 2016-05-13 15:28:34 -0700 | [diff] [blame] | 94 | JDWP thread @jdwp-control |
| The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 95 | | | |
| 96 | | <----------------------| |
| 97 | | OK, try this file descriptor | |
| 98 | | | |
| 99 | | | |
| 100 | |
| 101 | then, the JDWP thread uses this new socket descriptor as its |
| 102 | pass-through connection to the debugger (and receives the |
| 103 | JDWP-Handshake message, answers to it, etc...) |
| 104 | |
| 105 | this gives the following graphics: |
| 106 | ____________________________________ |
| 107 | | | |
| 108 | | ADB Server (host) | |
| 109 | | | |
| 110 | Debugger <---> LocalSocket <----> RemoteSocket | |
| 111 | | ^^ | |
| 112 | |___________________________||_______| |
| 113 | || |
| 114 | Transport || |
| 115 | (TCP for emulator - USB for device) || |
| 116 | || |
| 117 | ___________________________||_______ |
| 118 | | || | |
| 119 | | ADBD (device) || | |
| 120 | | VV | |
| 121 | JDWP <======> LocalSocket <----> RemoteSocket | |
| 122 | | | |
| 123 | |____________________________________| |
| 124 | |
| 125 | due to the way adb works, this doesn't need a special socket |
| 126 | type or fancy handling of socket termination if either the debugger |
| 127 | or the JDWP process closes the connection. |
| 128 | |
| 129 | THIS IS THE SIMPLEST IMPLEMENTATION I COULD FIND, IF YOU HAPPEN |
| 130 | TO HAVE A BETTER IDEA, LET ME KNOW - Digit |
| 131 | |
| 132 | **********************************************************************/ |
| 133 | |
| 134 | /** JDWP PID List Support Code |
| 135 | ** for each JDWP process, we record its pid and its connected socket |
| 136 | **/ |
| 137 | |
| Shukang Zhou | 420ad55 | 2020-02-13 17:01:39 -0800 | [diff] [blame] | 138 | enum class TrackerKind { |
| 139 | kJdwp, |
| 140 | kApp, |
| 141 | }; |
| 142 | |
| Josh Gao | 9eaf33c | 2016-05-13 15:28:34 -0700 | [diff] [blame] | 143 | static void jdwp_process_event(int socket, unsigned events, void* _proc); |
| Elliott Hughes | a8ab5ce | 2024-06-28 12:10:09 +0000 | [diff] [blame] | 144 | static void jdwp_process_list_updated(); |
| 145 | static void app_process_list_updated(); |
| The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 146 | |
| Josh Gao | 9eaf33c | 2016-05-13 15:28:34 -0700 | [diff] [blame] | 147 | struct JdwpProcess; |
| Josh Gao | 361148b | 2018-01-02 12:01:43 -0800 | [diff] [blame] | 148 | static auto& _jdwp_list = *new std::list<std::unique_ptr<JdwpProcess>>(); |
| The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 149 | |
| The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 150 | struct JdwpProcess { |
| Shukang Zhou | 420ad55 | 2020-02-13 17:01:39 -0800 | [diff] [blame] | 151 | JdwpProcess(unique_fd socket, ProcessInfo process) { |
| 152 | CHECK(process.pid != 0); |
| Josh Gao | eb5e605 | 2019-06-19 14:14:57 -0700 | [diff] [blame] | 153 | |
| Josh Gao | 9eaf33c | 2016-05-13 15:28:34 -0700 | [diff] [blame] | 154 | this->socket = socket; |
| Shukang Zhou | 420ad55 | 2020-02-13 17:01:39 -0800 | [diff] [blame] | 155 | this->process = process; |
| Josh Gao | eb5e605 | 2019-06-19 14:14:57 -0700 | [diff] [blame] | 156 | this->fde = fdevent_create(socket.release(), jdwp_process_event, this); |
| Fabien Sanglard | 15335e0 | 2024-03-05 21:33:44 +0000 | [diff] [blame] | 157 | fdevent_set(this->fde, FDE_READ); |
| The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 158 | |
| Josh Gao | 9eaf33c | 2016-05-13 15:28:34 -0700 | [diff] [blame] | 159 | if (!this->fde) { |
| Elliott Hughes | e64126b | 2018-10-19 13:59:44 -0700 | [diff] [blame] | 160 | LOG(FATAL) << "could not create fdevent for new JDWP process"; |
| Josh Gao | 9eaf33c | 2016-05-13 15:28:34 -0700 | [diff] [blame] | 161 | } |
| Josh Gao | 9eaf33c | 2016-05-13 15:28:34 -0700 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | ~JdwpProcess() { |
| 165 | if (this->socket >= 0) { |
| 166 | adb_shutdown(this->socket); |
| Josh Gao | 9eaf33c | 2016-05-13 15:28:34 -0700 | [diff] [blame] | 167 | this->socket = -1; |
| 168 | } |
| 169 | |
| 170 | if (this->fde) { |
| 171 | fdevent_destroy(this->fde); |
| 172 | this->fde = nullptr; |
| 173 | } |
| 174 | |
| 175 | out_fds.clear(); |
| 176 | } |
| 177 | |
| 178 | void RemoveFromList() { |
| Josh Gao | 9eaf33c | 2016-05-13 15:28:34 -0700 | [diff] [blame] | 179 | auto pred = [this](const auto& proc) { return proc.get() == this; }; |
| 180 | _jdwp_list.remove_if(pred); |
| 181 | } |
| 182 | |
| Josh Gao | eb5e605 | 2019-06-19 14:14:57 -0700 | [diff] [blame] | 183 | borrowed_fd socket = -1; |
| Shukang Zhou | 420ad55 | 2020-02-13 17:01:39 -0800 | [diff] [blame] | 184 | ProcessInfo process; |
| Josh Gao | 9eaf33c | 2016-05-13 15:28:34 -0700 | [diff] [blame] | 185 | fdevent* fde = nullptr; |
| 186 | |
| Fabien Sanglard | b7452ff | 2023-11-02 15:08:50 -0700 | [diff] [blame] | 187 | // When a jdwp:<PID> request arrives, we create a socketpair and immediately |
| 188 | // return one end to the requester. The other end is "staged" in this queue. |
| 189 | // The next time @jdwp-control becomes FDE_WRITE, we send the back() fd (it is |
| 190 | // received on the other end of @jdwp-control by ART) and pop it. This queue |
| 191 | // should almost always be empty if ART reads() from @jdwp-control properly. |
| Josh Gao | 9eaf33c | 2016-05-13 15:28:34 -0700 | [diff] [blame] | 192 | std::vector<unique_fd> out_fds; |
| The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 193 | }; |
| 194 | |
| Shukang Zhou | 420ad55 | 2020-02-13 17:01:39 -0800 | [diff] [blame] | 195 | // Populate the list of processes for "track-jdwp" service. |
| Josh Gao | 9eaf33c | 2016-05-13 15:28:34 -0700 | [diff] [blame] | 196 | static size_t jdwp_process_list(char* buffer, size_t bufferlen) { |
| 197 | std::string temp; |
| The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 198 | |
| Josh Gao | 9eaf33c | 2016-05-13 15:28:34 -0700 | [diff] [blame] | 199 | for (auto& proc : _jdwp_list) { |
| Shukang Zhou | 420ad55 | 2020-02-13 17:01:39 -0800 | [diff] [blame] | 200 | if (!proc->process.debuggable) continue; |
| 201 | std::string next = std::to_string(proc->process.pid) + "\n"; |
| Josh Gao | 9eaf33c | 2016-05-13 15:28:34 -0700 | [diff] [blame] | 202 | if (temp.length() + next.length() > bufferlen) { |
| 203 | D("truncating JDWP process list (max len = %zu)", bufferlen); |
| The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 204 | break; |
| The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 205 | } |
| Josh Gao | 9eaf33c | 2016-05-13 15:28:34 -0700 | [diff] [blame] | 206 | temp.append(next); |
| The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 207 | } |
| Josh Gao | 9eaf33c | 2016-05-13 15:28:34 -0700 | [diff] [blame] | 208 | |
| 209 | memcpy(buffer, temp.data(), temp.length()); |
| 210 | return temp.length(); |
| The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 211 | } |
| 212 | |
| Shukang Zhou | 420ad55 | 2020-02-13 17:01:39 -0800 | [diff] [blame] | 213 | // Populate the list of processes for "track-app" service. |
| 214 | // The list is a protobuf message in the binary format for efficiency. |
| 215 | static size_t app_process_list(char* buffer, size_t bufferlen) { |
| 216 | adb::proto::AppProcesses output; // result that's guaranteed to fit in the given buffer |
| 217 | adb::proto::AppProcesses temp; // temporary result that may be longer than the given buffer |
| 218 | std::string serialized_message; |
| 219 | |
| 220 | for (auto& proc : _jdwp_list) { |
| 221 | if (!proc->process.debuggable && !proc->process.profileable) continue; |
| 222 | auto* entry = temp.add_process(); |
| Yi Kong | aa8bdb1 | 2024-08-12 18:10:54 +0800 | [diff] [blame] | 223 | *entry = proc->process.toProtobuf(); |
| Shukang Zhou | 420ad55 | 2020-02-13 17:01:39 -0800 | [diff] [blame] | 224 | temp.SerializeToString(&serialized_message); |
| 225 | if (serialized_message.size() > bufferlen) { |
| 226 | D("truncating app process list (max len = %zu)", bufferlen); |
| 227 | break; |
| 228 | } |
| 229 | output = temp; |
| 230 | } |
| 231 | output.SerializeToString(&serialized_message); |
| 232 | memcpy(buffer, serialized_message.data(), serialized_message.length()); |
| 233 | return serialized_message.length(); |
| 234 | } |
| 235 | |
| 236 | // Populate the list of processes for either "track-jdwp" or "track-app" services, |
| 237 | // depending on the given kind. |
| 238 | static size_t process_list(TrackerKind kind, char* buffer, size_t bufferlen) { |
| 239 | switch (kind) { |
| 240 | case TrackerKind::kJdwp: |
| 241 | return jdwp_process_list(buffer, bufferlen); |
| 242 | case TrackerKind::kApp: |
| 243 | return app_process_list(buffer, bufferlen); |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | static size_t process_list_msg(TrackerKind kind, char* buffer, size_t bufferlen) { |
| Josh Gao | 9eaf33c | 2016-05-13 15:28:34 -0700 | [diff] [blame] | 248 | // Message is length-prefixed with 4 hex digits in ASCII. |
| 249 | static constexpr size_t header_len = 4; |
| 250 | if (bufferlen < header_len) { |
| Elliott Hughes | e64126b | 2018-10-19 13:59:44 -0700 | [diff] [blame] | 251 | LOG(FATAL) << "invalid JDWP process list buffer size: " << bufferlen; |
| The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 252 | } |
| 253 | |
| Josh Gao | 9eaf33c | 2016-05-13 15:28:34 -0700 | [diff] [blame] | 254 | char head[header_len + 1]; |
| Shukang Zhou | 420ad55 | 2020-02-13 17:01:39 -0800 | [diff] [blame] | 255 | size_t len = process_list(kind, buffer + header_len, bufferlen - header_len); |
| Josh Gao | 9eaf33c | 2016-05-13 15:28:34 -0700 | [diff] [blame] | 256 | snprintf(head, sizeof head, "%04zx", len); |
| 257 | memcpy(buffer, head, header_len); |
| 258 | return len + header_len; |
| The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 259 | } |
| 260 | |
| Josh Gao | 9eaf33c | 2016-05-13 15:28:34 -0700 | [diff] [blame] | 261 | static void jdwp_process_event(int socket, unsigned events, void* _proc) { |
| 262 | JdwpProcess* proc = reinterpret_cast<JdwpProcess*>(_proc); |
| Josh Gao | eb5e605 | 2019-06-19 14:14:57 -0700 | [diff] [blame] | 263 | CHECK_EQ(socket, proc->socket.get()); |
| The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 264 | |
| 265 | if (events & FDE_READ) { |
| Fabien Sanglard | 15335e0 | 2024-03-05 21:33:44 +0000 | [diff] [blame] | 266 | auto process_info = readProcessInfoFromSocket(socket); |
| 267 | |
| 268 | // Unable to get a process info, the remote app process either died or errored |
| 269 | if (!process_info) { |
| 270 | goto CloseProcess; |
| 271 | } |
| 272 | |
| Fabien Sanglard | bef3d19 | 2024-12-12 17:47:35 -0800 | [diff] [blame] | 273 | VLOG(JDWP) << "Received JDWP Process info for pid=" << process_info->pid; |
| Fabien Sanglard | 15335e0 | 2024-03-05 21:33:44 +0000 | [diff] [blame] | 274 | proc->process = std::move(*process_info); |
| 275 | jdwp_process_list_updated(); |
| 276 | app_process_list_updated(); |
| The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | if (events & FDE_WRITE) { |
| Josh Gao | 9eaf33c | 2016-05-13 15:28:34 -0700 | [diff] [blame] | 280 | D("trying to send fd to JDWP process (count = %zu)", proc->out_fds.size()); |
| Josh Gao | cc1dcc8 | 2018-10-05 17:09:41 -0700 | [diff] [blame] | 281 | CHECK(!proc->out_fds.empty()); |
| The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 282 | |
| Josh Gao | cc1dcc8 | 2018-10-05 17:09:41 -0700 | [diff] [blame] | 283 | int fd = proc->out_fds.back().get(); |
| Josh Gao | 2d83b54 | 2019-01-10 14:29:29 -0800 | [diff] [blame] | 284 | if (android::base::SendFileDescriptors(socket, "", 1, fd) != 1) { |
| Shukang Zhou | 420ad55 | 2020-02-13 17:01:39 -0800 | [diff] [blame] | 285 | D("sending new file descriptor to JDWP %" PRId64 " failed: %s", proc->process.pid, |
| 286 | strerror(errno)); |
| Josh Gao | cc1dcc8 | 2018-10-05 17:09:41 -0700 | [diff] [blame] | 287 | goto CloseProcess; |
| 288 | } |
| The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 289 | |
| Shukang Zhou | 420ad55 | 2020-02-13 17:01:39 -0800 | [diff] [blame] | 290 | D("sent file descriptor %d to JDWP process %" PRId64, fd, proc->process.pid); |
| Josh Gao | 9eaf33c | 2016-05-13 15:28:34 -0700 | [diff] [blame] | 291 | |
| Josh Gao | cc1dcc8 | 2018-10-05 17:09:41 -0700 | [diff] [blame] | 292 | proc->out_fds.pop_back(); |
| 293 | if (proc->out_fds.empty()) { |
| Fabien Sanglard | bef3d19 | 2024-12-12 17:47:35 -0800 | [diff] [blame] | 294 | VLOG(JDWP) << "Removing FDE_WRITE"; |
| Josh Gao | cc1dcc8 | 2018-10-05 17:09:41 -0700 | [diff] [blame] | 295 | fdevent_del(proc->fde, FDE_WRITE); |
| The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 296 | } |
| 297 | } |
| Josh Gao | 9eaf33c | 2016-05-13 15:28:34 -0700 | [diff] [blame] | 298 | |
| 299 | return; |
| 300 | |
| 301 | CloseProcess: |
| Fabien Sanglard | bef3d19 | 2024-12-12 17:47:35 -0800 | [diff] [blame] | 302 | VLOG(JDWP) << "Process " << proc->process.pid << " has disconnected"; |
| Shukang Zhou | 420ad55 | 2020-02-13 17:01:39 -0800 | [diff] [blame] | 303 | bool debuggable = proc->process.debuggable; |
| 304 | bool profileable = proc->process.profileable; |
| Josh Gao | 9eaf33c | 2016-05-13 15:28:34 -0700 | [diff] [blame] | 305 | proc->RemoveFromList(); |
| Shukang Zhou | 420ad55 | 2020-02-13 17:01:39 -0800 | [diff] [blame] | 306 | if (debuggable) jdwp_process_list_updated(); |
| 307 | if (debuggable || profileable) app_process_list_updated(); |
| The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 308 | } |
| 309 | |
| Fabien Sanglard | 5d4eaef | 2024-12-18 14:56:14 -0800 | [diff] [blame] | 310 | static bool is_process_in_freezer(const ProcessInfo& info) { |
| 311 | // Check "/sys/fs/cgroup/apps/uid_{}/pid_{}/cgroup.freeze". Since "apps" is configurable, |
| 312 | // use libprocessgroup to make sure we always have the right path. |
| 313 | std::string path; |
| 314 | if (!CgroupGetAttributePathForProcess("FreezerState", info.uid, info.pid, path)) { |
| 315 | VLOG(JDWP) << std::format("Failed to build frozen path of '{}' (got '{}')", info.pid, path); |
| 316 | return false; |
| 317 | } |
| 318 | |
| 319 | std::string content; |
| 320 | if (!android::base::ReadFileToString(path, &content)) { |
| 321 | VLOG(JDWP) << std::format("Failed to read ({})", path); |
| 322 | return false; |
| 323 | } |
| 324 | |
| 325 | bool is_frozen = content == "1\n"; |
| 326 | VLOG(JDWP) << std::format("Checking if pid {} is frozen at '{}' = '{}'", info.pid, path, |
| 327 | content); |
| 328 | |
| 329 | if (is_frozen) { |
| 330 | LOG(WARNING) << std::format("According to '{}'(='{}'), pid {} is frozen", path, content, |
| 331 | info.pid); |
| 332 | } |
| 333 | return is_frozen; |
| 334 | } |
| 335 | |
| 336 | static unique_fd send_socket_to_process(JdwpProcess& proc) { |
| 337 | // Process in the cached apps freezer don't get scheduled. |
| 338 | // Returning a socket will hang the debugger and leak a fd until the app is taken |
| 339 | // out of the freezer. Fail instead. |
| 340 | if (is_process_in_freezer(proc.process)) { |
| 341 | ProcessInfo& info = proc.process; |
| 342 | LOG(WARNING) << std::format("Process {} ({}) is frozen. Denying JDWP connection", info.pid, |
| 343 | info.process_name); |
| 344 | return unique_fd{}; |
| 345 | } |
| 346 | |
| 347 | int fds[2]; |
| 348 | if (adb_socketpair(fds) < 0) { |
| 349 | LOG(WARNING) << std::format("{}: socket pair creation failed: {}", __FUNCTION__, |
| 350 | strerror(errno)); |
| 351 | return unique_fd{}; |
| 352 | } |
| 353 | |
| 354 | VLOG(JDWP) << std::format("socketpair: ({},{})", fds[0], fds[1]); |
| 355 | proc.out_fds.emplace_back(fds[1]); |
| 356 | if (proc.out_fds.size() == 1) { |
| 357 | fdevent_add(proc.fde, FDE_WRITE); |
| 358 | } |
| 359 | |
| 360 | return unique_fd{fds[0]}; |
| 361 | } |
| 362 | |
| Fabien Sanglard | 5f42cc7 | 2025-01-21 14:48:35 -0800 | [diff] [blame] | 363 | unique_fd create_jdwp_connection_fd(pid_t pid) { |
| Fabien Sanglard | 5d4eaef | 2024-12-18 14:56:14 -0800 | [diff] [blame] | 364 | VLOG(JDWP) << std::format("looking for pid {} in JDWP process list", pid); |
| Josh Gao | 9eaf33c | 2016-05-13 15:28:34 -0700 | [diff] [blame] | 365 | |
| 366 | for (auto& proc : _jdwp_list) { |
| Shukang Zhou | 420ad55 | 2020-02-13 17:01:39 -0800 | [diff] [blame] | 367 | // Don't allow JDWP connection to a non-debuggable process. |
| Fabien Sanglard | 5d4eaef | 2024-12-18 14:56:14 -0800 | [diff] [blame] | 368 | if (!proc->process.debuggable) { |
| 369 | continue; |
| The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 370 | } |
| Fabien Sanglard | 5d4eaef | 2024-12-18 14:56:14 -0800 | [diff] [blame] | 371 | |
| Fabien Sanglard | 5f42cc7 | 2025-01-21 14:48:35 -0800 | [diff] [blame] | 372 | if (static_cast<pid_t>(proc->process.pid) != pid) { |
| Fabien Sanglard | 5d4eaef | 2024-12-18 14:56:14 -0800 | [diff] [blame] | 373 | continue; |
| 374 | } |
| 375 | |
| 376 | return send_socket_to_process(*proc); |
| The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 377 | } |
| Fabien Sanglard | 5d4eaef | 2024-12-18 14:56:14 -0800 | [diff] [blame] | 378 | LOG(WARNING) << std::format("search for pid {} failed !!", pid); |
| Josh Gao | 5607e92 | 2018-07-25 18:15:52 -0700 | [diff] [blame] | 379 | return unique_fd{}; |
| The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 380 | } |
| 381 | |
| The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 382 | /** "jdwp" local service implementation |
| 383 | ** this simply returns the list of known JDWP process pids |
| 384 | **/ |
| 385 | |
| Josh Gao | 9eaf33c | 2016-05-13 15:28:34 -0700 | [diff] [blame] | 386 | struct JdwpSocket : public asocket { |
| Josh Gao | 5cb76ce | 2018-02-12 17:24:00 -0800 | [diff] [blame] | 387 | bool pass = false; |
| Elliott Hughes | fe7ff81 | 2015-04-17 09:47:42 -0700 | [diff] [blame] | 388 | }; |
| The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 389 | |
| Josh Gao | 9eaf33c | 2016-05-13 15:28:34 -0700 | [diff] [blame] | 390 | static void jdwp_socket_close(asocket* s) { |
| 391 | D("LS(%d): closing jdwp socket", s->id); |
| 392 | |
| 393 | if (s->peer) { |
| 394 | D("LS(%d) peer->close()ing peer->id=%d peer->fd=%d", s->id, s->peer->id, s->peer->fd); |
| 395 | s->peer->peer = nullptr; |
| 396 | s->peer->close(s->peer); |
| 397 | s->peer = nullptr; |
| 398 | } |
| The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 399 | |
| 400 | remove_socket(s); |
| Josh Gao | 5cb76ce | 2018-02-12 17:24:00 -0800 | [diff] [blame] | 401 | delete s; |
| The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 402 | } |
| 403 | |
| Josh Gao | cd2a529 | 2018-03-07 16:52:28 -0800 | [diff] [blame] | 404 | static int jdwp_socket_enqueue(asocket* s, apacket::payload_type) { |
| The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 405 | /* you can't write to this asocket */ |
| Josh Gao | 9eaf33c | 2016-05-13 15:28:34 -0700 | [diff] [blame] | 406 | D("LS(%d): JDWP socket received data?", s->id); |
| The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 407 | s->peer->close(s->peer); |
| 408 | return -1; |
| 409 | } |
| 410 | |
| Josh Gao | 9eaf33c | 2016-05-13 15:28:34 -0700 | [diff] [blame] | 411 | static void jdwp_socket_ready(asocket* s) { |
| 412 | JdwpSocket* jdwp = (JdwpSocket*)s; |
| 413 | asocket* peer = jdwp->peer; |
| The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 414 | |
| Josh Gao | 9eaf33c | 2016-05-13 15:28:34 -0700 | [diff] [blame] | 415 | /* on the first call, send the list of pids, |
| 416 | * on the second one, close the connection |
| 417 | */ |
| 418 | if (!jdwp->pass) { |
| Josh Gao | cd2a529 | 2018-03-07 16:52:28 -0800 | [diff] [blame] | 419 | apacket::payload_type data; |
| Josh Gao | a7d9d71 | 2018-02-01 13:17:50 -0800 | [diff] [blame] | 420 | data.resize(s->get_max_payload()); |
| 421 | size_t len = jdwp_process_list(&data[0], data.size()); |
| 422 | data.resize(len); |
| 423 | peer->enqueue(peer, std::move(data)); |
| Josh Gao | 9eaf33c | 2016-05-13 15:28:34 -0700 | [diff] [blame] | 424 | jdwp->pass = true; |
| 425 | } else { |
| The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 426 | peer->close(peer); |
| 427 | } |
| 428 | } |
| 429 | |
| Elliott Hughes | a8ab5ce | 2024-06-28 12:10:09 +0000 | [diff] [blame] | 430 | asocket* create_jdwp_service_socket() { |
| Josh Gao | 5cb76ce | 2018-02-12 17:24:00 -0800 | [diff] [blame] | 431 | JdwpSocket* s = new JdwpSocket(); |
| The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 432 | |
| Josh Gao | 9eaf33c | 2016-05-13 15:28:34 -0700 | [diff] [blame] | 433 | if (!s) { |
| Elliott Hughes | e64126b | 2018-10-19 13:59:44 -0700 | [diff] [blame] | 434 | LOG(FATAL) << "failed to allocate JdwpSocket"; |
| Josh Gao | 9eaf33c | 2016-05-13 15:28:34 -0700 | [diff] [blame] | 435 | } |
| The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 436 | |
| Josh Gao | 9eaf33c | 2016-05-13 15:28:34 -0700 | [diff] [blame] | 437 | install_local_socket(s); |
| The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 438 | |
| Josh Gao | 9eaf33c | 2016-05-13 15:28:34 -0700 | [diff] [blame] | 439 | s->ready = jdwp_socket_ready; |
| 440 | s->enqueue = jdwp_socket_enqueue; |
| 441 | s->close = jdwp_socket_close; |
| 442 | s->pass = false; |
| The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 443 | |
| Josh Gao | 9eaf33c | 2016-05-13 15:28:34 -0700 | [diff] [blame] | 444 | return s; |
| The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | /** "track-jdwp" local service implementation |
| 448 | ** this periodically sends the list of known JDWP process pids |
| 449 | ** to the client... |
| 450 | **/ |
| 451 | |
| Josh Gao | 9eaf33c | 2016-05-13 15:28:34 -0700 | [diff] [blame] | 452 | struct JdwpTracker : public asocket { |
| Shukang Zhou | 420ad55 | 2020-02-13 17:01:39 -0800 | [diff] [blame] | 453 | TrackerKind kind; |
| Josh Gao | 9eaf33c | 2016-05-13 15:28:34 -0700 | [diff] [blame] | 454 | bool need_initial; |
| Shukang Zhou | 420ad55 | 2020-02-13 17:01:39 -0800 | [diff] [blame] | 455 | |
| 456 | explicit JdwpTracker(TrackerKind k, bool initial) : kind(k), need_initial(initial) {} |
| The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 457 | }; |
| 458 | |
| Josh Gao | 361148b | 2018-01-02 12:01:43 -0800 | [diff] [blame] | 459 | static auto& _jdwp_trackers = *new std::vector<std::unique_ptr<JdwpTracker>>(); |
| The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 460 | |
| Shukang Zhou | 420ad55 | 2020-02-13 17:01:39 -0800 | [diff] [blame] | 461 | static void process_list_updated(TrackerKind kind) { |
| Fabien Sanglard | 2e9756a | 2024-03-28 23:22:59 +0000 | [diff] [blame] | 462 | // Find out the max payload we can output. |
| 463 | // We start with the max the protocol can handle (hex4). |
| 464 | size_t maxPayload = UINT16_MAX; |
| 465 | for (auto& t : _jdwp_trackers) { |
| 466 | maxPayload = std::min(maxPayload, t->get_max_payload()); |
| 467 | } |
| 468 | |
| Josh Gao | a7d9d71 | 2018-02-01 13:17:50 -0800 | [diff] [blame] | 469 | std::string data; |
| Fabien Sanglard | 2e9756a | 2024-03-28 23:22:59 +0000 | [diff] [blame] | 470 | data.resize(maxPayload); |
| Shukang Zhou | 420ad55 | 2020-02-13 17:01:39 -0800 | [diff] [blame] | 471 | data.resize(process_list_msg(kind, &data[0], data.size())); |
| The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 472 | |
| Josh Gao | 9eaf33c | 2016-05-13 15:28:34 -0700 | [diff] [blame] | 473 | for (auto& t : _jdwp_trackers) { |
| Shukang Zhou | 420ad55 | 2020-02-13 17:01:39 -0800 | [diff] [blame] | 474 | if (t->kind == kind && t->peer) { |
| Josh Gao | 9eaf33c | 2016-05-13 15:28:34 -0700 | [diff] [blame] | 475 | // The tracker might not have been connected yet. |
| Josh Gao | cd2a529 | 2018-03-07 16:52:28 -0800 | [diff] [blame] | 476 | apacket::payload_type payload(data.begin(), data.end()); |
| 477 | t->peer->enqueue(t->peer, std::move(payload)); |
| Josh Gao | 9eaf33c | 2016-05-13 15:28:34 -0700 | [diff] [blame] | 478 | } |
| The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 479 | } |
| 480 | } |
| 481 | |
| Elliott Hughes | a8ab5ce | 2024-06-28 12:10:09 +0000 | [diff] [blame] | 482 | static void jdwp_process_list_updated() { |
| Shukang Zhou | 420ad55 | 2020-02-13 17:01:39 -0800 | [diff] [blame] | 483 | process_list_updated(TrackerKind::kJdwp); |
| 484 | } |
| 485 | |
| Elliott Hughes | a8ab5ce | 2024-06-28 12:10:09 +0000 | [diff] [blame] | 486 | static void app_process_list_updated() { |
| Shukang Zhou | 420ad55 | 2020-02-13 17:01:39 -0800 | [diff] [blame] | 487 | process_list_updated(TrackerKind::kApp); |
| 488 | } |
| 489 | |
| Josh Gao | 9eaf33c | 2016-05-13 15:28:34 -0700 | [diff] [blame] | 490 | static void jdwp_tracker_close(asocket* s) { |
| 491 | D("LS(%d): destroying jdwp tracker service", s->id); |
| The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 492 | |
| Josh Gao | 9eaf33c | 2016-05-13 15:28:34 -0700 | [diff] [blame] | 493 | if (s->peer) { |
| 494 | D("LS(%d) peer->close()ing peer->id=%d peer->fd=%d", s->id, s->peer->id, s->peer->fd); |
| 495 | s->peer->peer = nullptr; |
| 496 | s->peer->close(s->peer); |
| 497 | s->peer = nullptr; |
| The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | remove_socket(s); |
| 501 | |
| Josh Gao | 9eaf33c | 2016-05-13 15:28:34 -0700 | [diff] [blame] | 502 | auto pred = [s](const auto& tracker) { return tracker.get() == s; }; |
| Josh Gao | eea5fea | 2017-03-10 11:19:48 -0800 | [diff] [blame] | 503 | _jdwp_trackers.erase(std::remove_if(_jdwp_trackers.begin(), _jdwp_trackers.end(), pred), |
| 504 | _jdwp_trackers.end()); |
| The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 505 | } |
| 506 | |
| Josh Gao | 9eaf33c | 2016-05-13 15:28:34 -0700 | [diff] [blame] | 507 | static void jdwp_tracker_ready(asocket* s) { |
| 508 | JdwpTracker* t = (JdwpTracker*)s; |
| The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 509 | |
| Josh Gao | 9eaf33c | 2016-05-13 15:28:34 -0700 | [diff] [blame] | 510 | if (t->need_initial) { |
| Josh Gao | cd2a529 | 2018-03-07 16:52:28 -0800 | [diff] [blame] | 511 | apacket::payload_type data; |
| Josh Gao | a7d9d71 | 2018-02-01 13:17:50 -0800 | [diff] [blame] | 512 | data.resize(s->get_max_payload()); |
| Shukang Zhou | 420ad55 | 2020-02-13 17:01:39 -0800 | [diff] [blame] | 513 | data.resize(process_list_msg(t->kind, &data[0], data.size())); |
| Josh Gao | 9eaf33c | 2016-05-13 15:28:34 -0700 | [diff] [blame] | 514 | t->need_initial = false; |
| Josh Gao | a7d9d71 | 2018-02-01 13:17:50 -0800 | [diff] [blame] | 515 | s->peer->enqueue(s->peer, std::move(data)); |
| The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 516 | } |
| 517 | } |
| 518 | |
| Josh Gao | cd2a529 | 2018-03-07 16:52:28 -0800 | [diff] [blame] | 519 | static int jdwp_tracker_enqueue(asocket* s, apacket::payload_type) { |
| The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 520 | /* you can't write to this socket */ |
| Josh Gao | 9eaf33c | 2016-05-13 15:28:34 -0700 | [diff] [blame] | 521 | D("LS(%d): JDWP tracker received data?", s->id); |
| The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 522 | s->peer->close(s->peer); |
| 523 | return -1; |
| 524 | } |
| 525 | |
| Josh Gao | fa3605a | 2020-03-16 11:30:09 -0700 | [diff] [blame] | 526 | static asocket* create_process_tracker_service_socket(TrackerKind kind) { |
| Shaju Mathew | 237944f | 2023-06-01 18:03:03 -0700 | [diff] [blame] | 527 | std::unique_ptr<JdwpTracker> t = std::make_unique<JdwpTracker>(kind, true); |
| Josh Gao | 9eaf33c | 2016-05-13 15:28:34 -0700 | [diff] [blame] | 528 | if (!t) { |
| Elliott Hughes | e64126b | 2018-10-19 13:59:44 -0700 | [diff] [blame] | 529 | LOG(FATAL) << "failed to allocate JdwpTracker"; |
| Josh Gao | 9eaf33c | 2016-05-13 15:28:34 -0700 | [diff] [blame] | 530 | } |
| The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 531 | |
| Shaju Mathew | 237944f | 2023-06-01 18:03:03 -0700 | [diff] [blame] | 532 | /* Object layout (with an inheritance hierarchy) varies across arch (e.g |
| 533 | * armv7a/Android TV vs aarch64), so no assumptions can be made about |
| 534 | * accessing fields based on offsets (e.g memset(t.get(), 0, sizeof(asocket)) |
| 535 | * might clobber an unintended memory location). |
| 536 | */ |
| The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 537 | |
| Josh Gao | 9eaf33c | 2016-05-13 15:28:34 -0700 | [diff] [blame] | 538 | install_local_socket(t.get()); |
| 539 | D("LS(%d): created new jdwp tracker service", t->id); |
| The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 540 | |
| Josh Gao | 9eaf33c | 2016-05-13 15:28:34 -0700 | [diff] [blame] | 541 | t->ready = jdwp_tracker_ready; |
| 542 | t->enqueue = jdwp_tracker_enqueue; |
| 543 | t->close = jdwp_tracker_close; |
| The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 544 | |
| Josh Gao | 9eaf33c | 2016-05-13 15:28:34 -0700 | [diff] [blame] | 545 | asocket* result = t.get(); |
| The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 546 | |
| Josh Gao | 9eaf33c | 2016-05-13 15:28:34 -0700 | [diff] [blame] | 547 | _jdwp_trackers.emplace_back(std::move(t)); |
| The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 548 | |
| Josh Gao | 9eaf33c | 2016-05-13 15:28:34 -0700 | [diff] [blame] | 549 | return result; |
| The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 550 | } |
| 551 | |
| Shukang Zhou | 420ad55 | 2020-02-13 17:01:39 -0800 | [diff] [blame] | 552 | asocket* create_jdwp_tracker_service_socket() { |
| 553 | return create_process_tracker_service_socket(TrackerKind::kJdwp); |
| 554 | } |
| 555 | |
| 556 | asocket* create_app_tracker_service_socket() { |
| 557 | return create_process_tracker_service_socket(TrackerKind::kApp); |
| 558 | } |
| 559 | |
| Elliott Hughes | a8ab5ce | 2024-06-28 12:10:09 +0000 | [diff] [blame] | 560 | int init_jdwp() { |
| Josh Gao | eb5e605 | 2019-06-19 14:14:57 -0700 | [diff] [blame] | 561 | std::thread([]() { |
| 562 | adb_thread_setname("jdwp control"); |
| Shukang Zhou | 420ad55 | 2020-02-13 17:01:39 -0800 | [diff] [blame] | 563 | adbconnection_listen([](int fd, ProcessInfo process) { |
| 564 | LOG(INFO) << "jdwp connection from " << process.pid; |
| Shaju Mathew | 705fa1c | 2022-12-31 19:36:54 -0800 | [diff] [blame] | 565 | fdevent_run_on_looper([fd, process] { |
| Josh Gao | eb5e605 | 2019-06-19 14:14:57 -0700 | [diff] [blame] | 566 | unique_fd ufd(fd); |
| Shukang Zhou | 420ad55 | 2020-02-13 17:01:39 -0800 | [diff] [blame] | 567 | auto proc = std::make_unique<JdwpProcess>(std::move(ufd), process); |
| Josh Gao | eb5e605 | 2019-06-19 14:14:57 -0700 | [diff] [blame] | 568 | if (!proc) { |
| 569 | LOG(FATAL) << "failed to allocate JdwpProcess"; |
| 570 | } |
| 571 | _jdwp_list.emplace_back(std::move(proc)); |
| Shukang Zhou | 420ad55 | 2020-02-13 17:01:39 -0800 | [diff] [blame] | 572 | if (process.debuggable) jdwp_process_list_updated(); |
| 573 | if (process.debuggable || process.profileable) app_process_list_updated(); |
| Josh Gao | eb5e605 | 2019-06-19 14:14:57 -0700 | [diff] [blame] | 574 | }); |
| 575 | }); |
| 576 | }).detach(); |
| 577 | return 0; |
| The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 578 | } |
| 579 | |
| Josh Gao | fa3605a | 2020-03-16 11:30:09 -0700 | [diff] [blame] | 580 | #else // !defined(__ANDROID_RECOVERY) |
| 581 | #include "adb.h" |
| 582 | |
| Elliott Hughes | a8ab5ce | 2024-06-28 12:10:09 +0000 | [diff] [blame] | 583 | asocket* create_jdwp_service_socket() { |
| Josh Gao | fa3605a | 2020-03-16 11:30:09 -0700 | [diff] [blame] | 584 | return nullptr; |
| 585 | } |
| 586 | |
| Fabien Sanglard | 5f42cc7 | 2025-01-21 14:48:35 -0800 | [diff] [blame] | 587 | unique_fd create_jdwp_connection_fd(pid_t pid) { |
| Josh Gao | fa3605a | 2020-03-16 11:30:09 -0700 | [diff] [blame] | 588 | return {}; |
| 589 | } |
| 590 | |
| 591 | asocket* create_app_tracker_service_socket() { |
| 592 | return nullptr; |
| 593 | } |
| 594 | |
| 595 | asocket* create_jdwp_tracker_service_socket() { |
| 596 | return nullptr; |
| 597 | } |
| 598 | |
| 599 | int init_jdwp() { |
| 600 | return 0; |
| 601 | } |
| 602 | |
| 603 | #endif /* defined(__ANDROID_RECOVERY__) */ |