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 | #include "debugger.h" |
| 18 | |
Elliott Hughes | 3bb8156 | 2011-10-21 18:52:59 -0700 | [diff] [blame] | 19 | #include <sys/uio.h> |
| 20 | |
Elliott Hughes | f6a1e1e | 2011-10-25 16:28:04 -0700 | [diff] [blame] | 21 | #include "ScopedPrimitiveArray.h" |
Elliott Hughes | 47fce01 | 2011-10-25 18:37:19 -0700 | [diff] [blame^] | 22 | #include "stack_indirect_reference_table.h" |
Elliott Hughes | 475fc23 | 2011-10-25 15:00:35 -0700 | [diff] [blame] | 23 | #include "thread_list.h" |
| 24 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 25 | namespace art { |
| 26 | |
Elliott Hughes | 475fc23 | 2011-10-25 15:00:35 -0700 | [diff] [blame] | 27 | class ObjectRegistry { |
| 28 | public: |
| 29 | ObjectRegistry() : lock_("ObjectRegistry lock") { |
| 30 | } |
| 31 | |
| 32 | JDWP::ObjectId Add(Object* o) { |
| 33 | if (o == NULL) { |
| 34 | return 0; |
| 35 | } |
| 36 | JDWP::ObjectId id = static_cast<JDWP::ObjectId>(reinterpret_cast<uintptr_t>(o)); |
| 37 | MutexLock mu(lock_); |
| 38 | map_[id] = o; |
| 39 | return id; |
| 40 | } |
| 41 | |
| 42 | bool Contains(JDWP::ObjectId id) { |
| 43 | MutexLock mu(lock_); |
| 44 | return map_.find(id) != map_.end(); |
| 45 | } |
| 46 | |
| 47 | private: |
| 48 | Mutex lock_; |
| 49 | std::map<JDWP::ObjectId, Object*> map_; |
| 50 | }; |
| 51 | |
Elliott Hughes | 4ffd313 | 2011-10-24 12:06:42 -0700 | [diff] [blame] | 52 | // JDWP is allowed unless the Zygote forbids it. |
| 53 | static bool gJdwpAllowed = true; |
| 54 | |
Elliott Hughes | 3bb8156 | 2011-10-21 18:52:59 -0700 | [diff] [blame] | 55 | // Was there a -Xrunjdwp or -agent argument on the command-line? |
| 56 | static bool gJdwpConfigured = false; |
| 57 | |
| 58 | // Broken-down JDWP options. (Only valid if gJdwpConfigured is true.) |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 59 | static JDWP::JdwpOptions gJdwpOptions; |
Elliott Hughes | 3bb8156 | 2011-10-21 18:52:59 -0700 | [diff] [blame] | 60 | |
| 61 | // Runtime JDWP state. |
| 62 | static JDWP::JdwpState* gJdwpState = NULL; |
| 63 | static bool gDebuggerConnected; // debugger or DDMS is connected. |
| 64 | static bool gDebuggerActive; // debugger is making requests. |
| 65 | |
Elliott Hughes | 47fce01 | 2011-10-25 18:37:19 -0700 | [diff] [blame^] | 66 | static bool gDdmThreadNotification = false; |
| 67 | |
Elliott Hughes | 475fc23 | 2011-10-25 15:00:35 -0700 | [diff] [blame] | 68 | static ObjectRegistry* gRegistry = NULL; |
| 69 | |
Elliott Hughes | 3bb8156 | 2011-10-21 18:52:59 -0700 | [diff] [blame] | 70 | /* |
| 71 | * Handle one of the JDWP name/value pairs. |
| 72 | * |
| 73 | * JDWP options are: |
| 74 | * help: if specified, show help message and bail |
| 75 | * transport: may be dt_socket or dt_shmem |
| 76 | * address: for dt_socket, "host:port", or just "port" when listening |
| 77 | * server: if "y", wait for debugger to attach; if "n", attach to debugger |
| 78 | * timeout: how long to wait for debugger to connect / listen |
| 79 | * |
| 80 | * Useful with server=n (these aren't supported yet): |
| 81 | * onthrow=<exception-name>: connect to debugger when exception thrown |
| 82 | * onuncaught=y|n: connect to debugger when uncaught exception thrown |
| 83 | * launch=<command-line>: launch the debugger itself |
| 84 | * |
| 85 | * The "transport" option is required, as is "address" if server=n. |
| 86 | */ |
| 87 | static bool ParseJdwpOption(const std::string& name, const std::string& value) { |
| 88 | if (name == "transport") { |
| 89 | if (value == "dt_socket") { |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 90 | gJdwpOptions.transport = JDWP::kJdwpTransportSocket; |
Elliott Hughes | 3bb8156 | 2011-10-21 18:52:59 -0700 | [diff] [blame] | 91 | } else if (value == "dt_android_adb") { |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 92 | gJdwpOptions.transport = JDWP::kJdwpTransportAndroidAdb; |
Elliott Hughes | 3bb8156 | 2011-10-21 18:52:59 -0700 | [diff] [blame] | 93 | } else { |
| 94 | LOG(ERROR) << "JDWP transport not supported: " << value; |
| 95 | return false; |
| 96 | } |
| 97 | } else if (name == "server") { |
| 98 | if (value == "n") { |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 99 | gJdwpOptions.server = false; |
Elliott Hughes | 3bb8156 | 2011-10-21 18:52:59 -0700 | [diff] [blame] | 100 | } else if (value == "y") { |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 101 | gJdwpOptions.server = true; |
Elliott Hughes | 3bb8156 | 2011-10-21 18:52:59 -0700 | [diff] [blame] | 102 | } else { |
| 103 | LOG(ERROR) << "JDWP option 'server' must be 'y' or 'n'"; |
| 104 | return false; |
| 105 | } |
| 106 | } else if (name == "suspend") { |
| 107 | if (value == "n") { |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 108 | gJdwpOptions.suspend = false; |
Elliott Hughes | 3bb8156 | 2011-10-21 18:52:59 -0700 | [diff] [blame] | 109 | } else if (value == "y") { |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 110 | gJdwpOptions.suspend = true; |
Elliott Hughes | 3bb8156 | 2011-10-21 18:52:59 -0700 | [diff] [blame] | 111 | } else { |
| 112 | LOG(ERROR) << "JDWP option 'suspend' must be 'y' or 'n'"; |
| 113 | return false; |
| 114 | } |
| 115 | } else if (name == "address") { |
| 116 | /* this is either <port> or <host>:<port> */ |
| 117 | std::string port_string; |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 118 | gJdwpOptions.host.clear(); |
Elliott Hughes | 3bb8156 | 2011-10-21 18:52:59 -0700 | [diff] [blame] | 119 | std::string::size_type colon = value.find(':'); |
| 120 | if (colon != std::string::npos) { |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 121 | gJdwpOptions.host = value.substr(0, colon); |
Elliott Hughes | 3bb8156 | 2011-10-21 18:52:59 -0700 | [diff] [blame] | 122 | port_string = value.substr(colon + 1); |
| 123 | } else { |
| 124 | port_string = value; |
| 125 | } |
| 126 | if (port_string.empty()) { |
| 127 | LOG(ERROR) << "JDWP address missing port: " << value; |
| 128 | return false; |
| 129 | } |
| 130 | char* end; |
| 131 | long port = strtol(port_string.c_str(), &end, 10); |
| 132 | if (*end != '\0') { |
| 133 | LOG(ERROR) << "JDWP address has junk in port field: " << value; |
| 134 | return false; |
| 135 | } |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 136 | gJdwpOptions.port = port; |
Elliott Hughes | 3bb8156 | 2011-10-21 18:52:59 -0700 | [diff] [blame] | 137 | } else if (name == "launch" || name == "onthrow" || name == "oncaught" || name == "timeout") { |
| 138 | /* valid but unsupported */ |
| 139 | LOG(INFO) << "Ignoring JDWP option '" << name << "'='" << value << "'"; |
| 140 | } else { |
| 141 | LOG(INFO) << "Ignoring unrecognized JDWP option '" << name << "'='" << value << "'"; |
| 142 | } |
| 143 | |
| 144 | return true; |
| 145 | } |
| 146 | |
| 147 | /* |
| 148 | * Parse the latter half of a -Xrunjdwp/-agentlib:jdwp= string, e.g.: |
| 149 | * "transport=dt_socket,address=8000,server=y,suspend=n" |
| 150 | */ |
| 151 | bool Dbg::ParseJdwpOptions(const std::string& options) { |
Elliott Hughes | 47fce01 | 2011-10-25 18:37:19 -0700 | [diff] [blame^] | 152 | LOG(VERBOSE) << "ParseJdwpOptions: " << options; |
| 153 | |
Elliott Hughes | 3bb8156 | 2011-10-21 18:52:59 -0700 | [diff] [blame] | 154 | std::vector<std::string> pairs; |
| 155 | Split(options, ',', pairs); |
| 156 | |
| 157 | for (size_t i = 0; i < pairs.size(); ++i) { |
| 158 | std::string::size_type equals = pairs[i].find('='); |
| 159 | if (equals == std::string::npos) { |
| 160 | LOG(ERROR) << "Can't parse JDWP option '" << pairs[i] << "' in '" << options << "'"; |
| 161 | return false; |
| 162 | } |
| 163 | ParseJdwpOption(pairs[i].substr(0, equals), pairs[i].substr(equals + 1)); |
| 164 | } |
| 165 | |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 166 | if (gJdwpOptions.transport == JDWP::kJdwpTransportUnknown) { |
Elliott Hughes | 3bb8156 | 2011-10-21 18:52:59 -0700 | [diff] [blame] | 167 | LOG(ERROR) << "Must specify JDWP transport: " << options; |
| 168 | } |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 169 | if (!gJdwpOptions.server && (gJdwpOptions.host.empty() || gJdwpOptions.port == 0)) { |
Elliott Hughes | 3bb8156 | 2011-10-21 18:52:59 -0700 | [diff] [blame] | 170 | LOG(ERROR) << "Must specify JDWP host and port when server=n: " << options; |
| 171 | return false; |
| 172 | } |
| 173 | |
| 174 | gJdwpConfigured = true; |
| 175 | return true; |
| 176 | } |
| 177 | |
Elliott Hughes | d1cc836 | 2011-10-24 16:58:50 -0700 | [diff] [blame] | 178 | void Dbg::StartJdwp() { |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 179 | if (!gJdwpAllowed || !gJdwpConfigured) { |
| 180 | // No JDWP for you! |
| 181 | return; |
| 182 | } |
| 183 | |
Elliott Hughes | 475fc23 | 2011-10-25 15:00:35 -0700 | [diff] [blame] | 184 | CHECK(gRegistry == NULL); |
| 185 | gRegistry = new ObjectRegistry; |
| 186 | |
Elliott Hughes | d1cc836 | 2011-10-24 16:58:50 -0700 | [diff] [blame] | 187 | // Init JDWP if the debugger is enabled. This may connect out to a |
| 188 | // debugger, passively listen for a debugger, or block waiting for a |
| 189 | // debugger. |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 190 | gJdwpState = JDWP::JdwpState::Create(&gJdwpOptions); |
| 191 | if (gJdwpState == NULL) { |
| 192 | LOG(WARNING) << "debugger thread failed to initialize"; |
Elliott Hughes | 475fc23 | 2011-10-25 15:00:35 -0700 | [diff] [blame] | 193 | return; |
Elliott Hughes | d1cc836 | 2011-10-24 16:58:50 -0700 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | // If a debugger has already attached, send the "welcome" message. |
| 197 | // This may cause us to suspend all threads. |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 198 | if (gJdwpState->IsActive()) { |
Elliott Hughes | d1cc836 | 2011-10-24 16:58:50 -0700 | [diff] [blame] | 199 | //ScopedThreadStateChange(Thread::Current(), Thread::kRunnable); |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 200 | if (!gJdwpState->PostVMStart()) { |
Elliott Hughes | d1cc836 | 2011-10-24 16:58:50 -0700 | [diff] [blame] | 201 | LOG(WARNING) << "failed to post 'start' message to debugger"; |
| 202 | } |
| 203 | } |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 204 | } |
| 205 | |
Elliott Hughes | d1cc836 | 2011-10-24 16:58:50 -0700 | [diff] [blame] | 206 | void Dbg::StopJdwp() { |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 207 | delete gJdwpState; |
Elliott Hughes | 475fc23 | 2011-10-25 15:00:35 -0700 | [diff] [blame] | 208 | delete gRegistry; |
| 209 | gRegistry = NULL; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 210 | } |
| 211 | |
Elliott Hughes | 4ffd313 | 2011-10-24 12:06:42 -0700 | [diff] [blame] | 212 | void Dbg::SetJdwpAllowed(bool allowed) { |
| 213 | gJdwpAllowed = allowed; |
| 214 | } |
| 215 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 216 | DebugInvokeReq* Dbg::GetInvokeReq() { |
Elliott Hughes | 475fc23 | 2011-10-25 15:00:35 -0700 | [diff] [blame] | 217 | return Thread::Current()->GetInvokeReq(); |
| 218 | } |
| 219 | |
| 220 | Thread* Dbg::GetDebugThread() { |
| 221 | return (gJdwpState != NULL) ? gJdwpState->GetDebugThread() : NULL; |
| 222 | } |
| 223 | |
| 224 | void Dbg::ClearWaitForEventThread() { |
| 225 | gJdwpState->ClearWaitForEventThread(); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | void Dbg::Connected() { |
Elliott Hughes | 3bb8156 | 2011-10-21 18:52:59 -0700 | [diff] [blame] | 229 | CHECK(!gDebuggerConnected); |
| 230 | LOG(VERBOSE) << "JDWP has attached"; |
| 231 | gDebuggerConnected = true; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | void Dbg::Active() { |
| 235 | UNIMPLEMENTED(FATAL); |
| 236 | } |
| 237 | |
| 238 | void Dbg::Disconnected() { |
| 239 | UNIMPLEMENTED(FATAL); |
| 240 | } |
| 241 | |
| 242 | bool Dbg::IsDebuggerConnected() { |
Elliott Hughes | 3bb8156 | 2011-10-21 18:52:59 -0700 | [diff] [blame] | 243 | return gDebuggerActive; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | bool Dbg::IsDebuggingEnabled() { |
Elliott Hughes | 3bb8156 | 2011-10-21 18:52:59 -0700 | [diff] [blame] | 247 | return gJdwpConfigured; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | int64_t Dbg::LastDebuggerActivity() { |
| 251 | UNIMPLEMENTED(WARNING); |
| 252 | return -1; |
| 253 | } |
| 254 | |
| 255 | int Dbg::ThreadRunning() { |
Elliott Hughes | d1cc836 | 2011-10-24 16:58:50 -0700 | [diff] [blame] | 256 | return static_cast<int>(Thread::Current()->SetState(Thread::kRunnable)); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | int Dbg::ThreadWaiting() { |
Elliott Hughes | d1cc836 | 2011-10-24 16:58:50 -0700 | [diff] [blame] | 260 | return static_cast<int>(Thread::Current()->SetState(Thread::kVmWait)); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 261 | } |
| 262 | |
Elliott Hughes | 6ba581a | 2011-10-25 11:45:35 -0700 | [diff] [blame] | 263 | int Dbg::ThreadContinuing(int new_state) { |
| 264 | return static_cast<int>(Thread::Current()->SetState(static_cast<Thread::State>(new_state))); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | void Dbg::UndoDebuggerSuspensions() { |
| 268 | UNIMPLEMENTED(FATAL); |
| 269 | } |
| 270 | |
| 271 | void Dbg::Exit(int status) { |
| 272 | UNIMPLEMENTED(FATAL); |
| 273 | } |
| 274 | |
| 275 | const char* Dbg::GetClassDescriptor(JDWP::RefTypeId id) { |
| 276 | UNIMPLEMENTED(FATAL); |
| 277 | return NULL; |
| 278 | } |
| 279 | |
| 280 | JDWP::ObjectId Dbg::GetClassObject(JDWP::RefTypeId id) { |
| 281 | UNIMPLEMENTED(FATAL); |
| 282 | return 0; |
| 283 | } |
| 284 | |
| 285 | JDWP::RefTypeId Dbg::GetSuperclass(JDWP::RefTypeId id) { |
| 286 | UNIMPLEMENTED(FATAL); |
| 287 | return 0; |
| 288 | } |
| 289 | |
| 290 | JDWP::ObjectId Dbg::GetClassLoader(JDWP::RefTypeId id) { |
| 291 | UNIMPLEMENTED(FATAL); |
| 292 | return 0; |
| 293 | } |
| 294 | |
| 295 | uint32_t Dbg::GetAccessFlags(JDWP::RefTypeId id) { |
| 296 | UNIMPLEMENTED(FATAL); |
| 297 | return 0; |
| 298 | } |
| 299 | |
| 300 | bool Dbg::IsInterface(JDWP::RefTypeId id) { |
| 301 | UNIMPLEMENTED(FATAL); |
| 302 | return false; |
| 303 | } |
| 304 | |
| 305 | void Dbg::GetClassList(uint32_t* pNumClasses, JDWP::RefTypeId** pClassRefBuf) { |
| 306 | UNIMPLEMENTED(FATAL); |
| 307 | } |
| 308 | |
| 309 | void Dbg::GetVisibleClassList(JDWP::ObjectId classLoaderId, uint32_t* pNumClasses, JDWP::RefTypeId** pClassRefBuf) { |
| 310 | UNIMPLEMENTED(FATAL); |
| 311 | } |
| 312 | |
| 313 | void Dbg::GetClassInfo(JDWP::RefTypeId classId, uint8_t* pTypeTag, uint32_t* pStatus, const char** pSignature) { |
| 314 | UNIMPLEMENTED(FATAL); |
| 315 | } |
| 316 | |
| 317 | bool Dbg::FindLoadedClassBySignature(const char* classDescriptor, JDWP::RefTypeId* pRefTypeId) { |
| 318 | UNIMPLEMENTED(FATAL); |
| 319 | return false; |
| 320 | } |
| 321 | |
| 322 | void Dbg::GetObjectType(JDWP::ObjectId objectId, uint8_t* pRefTypeTag, JDWP::RefTypeId* pRefTypeId) { |
| 323 | UNIMPLEMENTED(FATAL); |
| 324 | } |
| 325 | |
| 326 | uint8_t Dbg::GetClassObjectType(JDWP::RefTypeId refTypeId) { |
| 327 | UNIMPLEMENTED(FATAL); |
| 328 | return 0; |
| 329 | } |
| 330 | |
| 331 | const char* Dbg::GetSignature(JDWP::RefTypeId refTypeId) { |
| 332 | UNIMPLEMENTED(FATAL); |
| 333 | return NULL; |
| 334 | } |
| 335 | |
| 336 | const char* Dbg::GetSourceFile(JDWP::RefTypeId refTypeId) { |
| 337 | UNIMPLEMENTED(FATAL); |
| 338 | return NULL; |
| 339 | } |
| 340 | |
| 341 | const char* Dbg::GetObjectTypeName(JDWP::ObjectId objectId) { |
| 342 | UNIMPLEMENTED(FATAL); |
| 343 | return NULL; |
| 344 | } |
| 345 | |
| 346 | uint8_t Dbg::GetObjectTag(JDWP::ObjectId objectId) { |
| 347 | UNIMPLEMENTED(FATAL); |
| 348 | return 0; |
| 349 | } |
| 350 | |
| 351 | int Dbg::GetTagWidth(int tag) { |
| 352 | UNIMPLEMENTED(FATAL); |
| 353 | return 0; |
| 354 | } |
| 355 | |
| 356 | int Dbg::GetArrayLength(JDWP::ObjectId arrayId) { |
| 357 | UNIMPLEMENTED(FATAL); |
| 358 | return 0; |
| 359 | } |
| 360 | |
| 361 | uint8_t Dbg::GetArrayElementTag(JDWP::ObjectId arrayId) { |
| 362 | UNIMPLEMENTED(FATAL); |
| 363 | return 0; |
| 364 | } |
| 365 | |
| 366 | bool Dbg::OutputArray(JDWP::ObjectId arrayId, int firstIndex, int count, JDWP::ExpandBuf* pReply) { |
| 367 | UNIMPLEMENTED(FATAL); |
| 368 | return false; |
| 369 | } |
| 370 | |
| 371 | bool Dbg::SetArrayElements(JDWP::ObjectId arrayId, int firstIndex, int count, const uint8_t* buf) { |
| 372 | UNIMPLEMENTED(FATAL); |
| 373 | return false; |
| 374 | } |
| 375 | |
| 376 | JDWP::ObjectId Dbg::CreateString(const char* str) { |
| 377 | UNIMPLEMENTED(FATAL); |
| 378 | return 0; |
| 379 | } |
| 380 | |
| 381 | JDWP::ObjectId Dbg::CreateObject(JDWP::RefTypeId classId) { |
| 382 | UNIMPLEMENTED(FATAL); |
| 383 | return 0; |
| 384 | } |
| 385 | |
| 386 | JDWP::ObjectId Dbg::CreateArrayObject(JDWP::RefTypeId arrayTypeId, uint32_t length) { |
| 387 | UNIMPLEMENTED(FATAL); |
| 388 | return 0; |
| 389 | } |
| 390 | |
| 391 | bool Dbg::MatchType(JDWP::RefTypeId instClassId, JDWP::RefTypeId classId) { |
| 392 | UNIMPLEMENTED(FATAL); |
| 393 | return false; |
| 394 | } |
| 395 | |
| 396 | const char* Dbg::GetMethodName(JDWP::RefTypeId refTypeId, JDWP::MethodId id) { |
| 397 | UNIMPLEMENTED(FATAL); |
| 398 | return NULL; |
| 399 | } |
| 400 | |
| 401 | void Dbg::OutputAllFields(JDWP::RefTypeId refTypeId, bool withGeneric, JDWP::ExpandBuf* pReply) { |
| 402 | UNIMPLEMENTED(FATAL); |
| 403 | } |
| 404 | |
| 405 | void Dbg::OutputAllMethods(JDWP::RefTypeId refTypeId, bool withGeneric, JDWP::ExpandBuf* pReply) { |
| 406 | UNIMPLEMENTED(FATAL); |
| 407 | } |
| 408 | |
| 409 | void Dbg::OutputAllInterfaces(JDWP::RefTypeId refTypeId, JDWP::ExpandBuf* pReply) { |
| 410 | UNIMPLEMENTED(FATAL); |
| 411 | } |
| 412 | |
| 413 | void Dbg::OutputLineTable(JDWP::RefTypeId refTypeId, JDWP::MethodId methodId, JDWP::ExpandBuf* pReply) { |
| 414 | UNIMPLEMENTED(FATAL); |
| 415 | } |
| 416 | |
| 417 | void Dbg::OutputVariableTable(JDWP::RefTypeId refTypeId, JDWP::MethodId id, bool withGeneric, JDWP::ExpandBuf* pReply) { |
| 418 | UNIMPLEMENTED(FATAL); |
| 419 | } |
| 420 | |
| 421 | uint8_t Dbg::GetFieldBasicTag(JDWP::ObjectId objId, JDWP::FieldId fieldId) { |
| 422 | UNIMPLEMENTED(FATAL); |
| 423 | return 0; |
| 424 | } |
| 425 | |
| 426 | uint8_t Dbg::GetStaticFieldBasicTag(JDWP::RefTypeId refTypeId, JDWP::FieldId fieldId) { |
| 427 | UNIMPLEMENTED(FATAL); |
| 428 | return 0; |
| 429 | } |
| 430 | |
| 431 | void Dbg::GetFieldValue(JDWP::ObjectId objectId, JDWP::FieldId fieldId, JDWP::ExpandBuf* pReply) { |
| 432 | UNIMPLEMENTED(FATAL); |
| 433 | } |
| 434 | |
| 435 | void Dbg::SetFieldValue(JDWP::ObjectId objectId, JDWP::FieldId fieldId, uint64_t value, int width) { |
| 436 | UNIMPLEMENTED(FATAL); |
| 437 | } |
| 438 | |
| 439 | void Dbg::GetStaticFieldValue(JDWP::RefTypeId refTypeId, JDWP::FieldId fieldId, JDWP::ExpandBuf* pReply) { |
| 440 | UNIMPLEMENTED(FATAL); |
| 441 | } |
| 442 | |
| 443 | void Dbg::SetStaticFieldValue(JDWP::RefTypeId refTypeId, JDWP::FieldId fieldId, uint64_t rawValue, int width) { |
| 444 | UNIMPLEMENTED(FATAL); |
| 445 | } |
| 446 | |
| 447 | char* Dbg::StringToUtf8(JDWP::ObjectId strId) { |
| 448 | UNIMPLEMENTED(FATAL); |
| 449 | return NULL; |
| 450 | } |
| 451 | |
| 452 | char* Dbg::GetThreadName(JDWP::ObjectId threadId) { |
| 453 | UNIMPLEMENTED(FATAL); |
| 454 | return NULL; |
| 455 | } |
| 456 | |
| 457 | JDWP::ObjectId Dbg::GetThreadGroup(JDWP::ObjectId threadId) { |
| 458 | UNIMPLEMENTED(FATAL); |
| 459 | return 0; |
| 460 | } |
| 461 | |
| 462 | char* Dbg::GetThreadGroupName(JDWP::ObjectId threadGroupId) { |
| 463 | UNIMPLEMENTED(FATAL); |
| 464 | return NULL; |
| 465 | } |
| 466 | |
| 467 | JDWP::ObjectId Dbg::GetThreadGroupParent(JDWP::ObjectId threadGroupId) { |
| 468 | UNIMPLEMENTED(FATAL); |
| 469 | return 0; |
| 470 | } |
| 471 | |
| 472 | JDWP::ObjectId Dbg::GetSystemThreadGroupId() { |
| 473 | UNIMPLEMENTED(FATAL); |
| 474 | return 0; |
| 475 | } |
| 476 | |
| 477 | JDWP::ObjectId Dbg::GetMainThreadGroupId() { |
| 478 | UNIMPLEMENTED(FATAL); |
| 479 | return 0; |
| 480 | } |
| 481 | |
| 482 | bool Dbg::GetThreadStatus(JDWP::ObjectId threadId, uint32_t* threadStatus, uint32_t* suspendStatus) { |
| 483 | UNIMPLEMENTED(FATAL); |
| 484 | return false; |
| 485 | } |
| 486 | |
| 487 | uint32_t Dbg::GetThreadSuspendCount(JDWP::ObjectId threadId) { |
| 488 | UNIMPLEMENTED(FATAL); |
| 489 | return 0; |
| 490 | } |
| 491 | |
| 492 | bool Dbg::ThreadExists(JDWP::ObjectId threadId) { |
| 493 | UNIMPLEMENTED(FATAL); |
| 494 | return false; |
| 495 | } |
| 496 | |
| 497 | bool Dbg::IsSuspended(JDWP::ObjectId threadId) { |
| 498 | UNIMPLEMENTED(FATAL); |
| 499 | return false; |
| 500 | } |
| 501 | |
| 502 | //void Dbg::WaitForSuspend(JDWP::ObjectId threadId); |
| 503 | |
| 504 | void Dbg::GetThreadGroupThreads(JDWP::ObjectId threadGroupId, JDWP::ObjectId** ppThreadIds, uint32_t* pThreadCount) { |
| 505 | UNIMPLEMENTED(FATAL); |
| 506 | } |
| 507 | |
| 508 | void Dbg::GetAllThreads(JDWP::ObjectId** ppThreadIds, uint32_t* pThreadCount) { |
| 509 | UNIMPLEMENTED(FATAL); |
| 510 | } |
| 511 | |
| 512 | int Dbg::GetThreadFrameCount(JDWP::ObjectId threadId) { |
| 513 | UNIMPLEMENTED(FATAL); |
| 514 | return 0; |
| 515 | } |
| 516 | |
| 517 | bool Dbg::GetThreadFrame(JDWP::ObjectId threadId, int num, JDWP::FrameId* pFrameId, JDWP::JdwpLocation* pLoc) { |
| 518 | UNIMPLEMENTED(FATAL); |
| 519 | return false; |
| 520 | } |
| 521 | |
| 522 | JDWP::ObjectId Dbg::GetThreadSelfId() { |
Elliott Hughes | 475fc23 | 2011-10-25 15:00:35 -0700 | [diff] [blame] | 523 | return gRegistry->Add(Thread::Current()->GetPeer()); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 524 | } |
| 525 | |
Elliott Hughes | 475fc23 | 2011-10-25 15:00:35 -0700 | [diff] [blame] | 526 | void Dbg::SuspendVM() { |
| 527 | Runtime::Current()->GetThreadList()->SuspendAll(true); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 528 | } |
| 529 | |
| 530 | void Dbg::ResumeVM() { |
Elliott Hughes | 475fc23 | 2011-10-25 15:00:35 -0700 | [diff] [blame] | 531 | Runtime::Current()->GetThreadList()->ResumeAll(true); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | void Dbg::SuspendThread(JDWP::ObjectId threadId) { |
| 535 | UNIMPLEMENTED(FATAL); |
| 536 | } |
| 537 | |
| 538 | void Dbg::ResumeThread(JDWP::ObjectId threadId) { |
| 539 | UNIMPLEMENTED(FATAL); |
| 540 | } |
| 541 | |
| 542 | void Dbg::SuspendSelf() { |
Elliott Hughes | 475fc23 | 2011-10-25 15:00:35 -0700 | [diff] [blame] | 543 | Runtime::Current()->GetThreadList()->SuspendSelfForDebugger(); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | bool Dbg::GetThisObject(JDWP::ObjectId threadId, JDWP::FrameId frameId, JDWP::ObjectId* pThisId) { |
| 547 | UNIMPLEMENTED(FATAL); |
| 548 | return false; |
| 549 | } |
| 550 | |
| 551 | void Dbg::GetLocalValue(JDWP::ObjectId threadId, JDWP::FrameId frameId, int slot, uint8_t tag, uint8_t* buf, int expectedLen) { |
| 552 | UNIMPLEMENTED(FATAL); |
| 553 | } |
| 554 | |
| 555 | void Dbg::SetLocalValue(JDWP::ObjectId threadId, JDWP::FrameId frameId, int slot, uint8_t tag, uint64_t value, int width) { |
| 556 | UNIMPLEMENTED(FATAL); |
| 557 | } |
| 558 | |
| 559 | void Dbg::PostLocationEvent(const Method* method, int pcOffset, Object* thisPtr, int eventFlags) { |
| 560 | UNIMPLEMENTED(FATAL); |
| 561 | } |
| 562 | |
| 563 | void Dbg::PostException(void* throwFp, int throwRelPc, void* catchFp, int catchRelPc, Object* exception) { |
| 564 | UNIMPLEMENTED(FATAL); |
| 565 | } |
| 566 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 567 | void Dbg::PostClassPrepare(Class* c) { |
| 568 | UNIMPLEMENTED(FATAL); |
| 569 | } |
| 570 | |
| 571 | bool Dbg::WatchLocation(const JDWP::JdwpLocation* pLoc) { |
| 572 | UNIMPLEMENTED(FATAL); |
| 573 | return false; |
| 574 | } |
| 575 | |
| 576 | void Dbg::UnwatchLocation(const JDWP::JdwpLocation* pLoc) { |
| 577 | UNIMPLEMENTED(FATAL); |
| 578 | } |
| 579 | |
| 580 | bool Dbg::ConfigureStep(JDWP::ObjectId threadId, JDWP::JdwpStepSize size, JDWP::JdwpStepDepth depth) { |
| 581 | UNIMPLEMENTED(FATAL); |
| 582 | return false; |
| 583 | } |
| 584 | |
| 585 | void Dbg::UnconfigureStep(JDWP::ObjectId threadId) { |
| 586 | UNIMPLEMENTED(FATAL); |
| 587 | } |
| 588 | |
| 589 | JDWP::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) { |
| 590 | UNIMPLEMENTED(FATAL); |
| 591 | return JDWP::ERR_NONE; |
| 592 | } |
| 593 | |
| 594 | void Dbg::ExecuteMethod(DebugInvokeReq* pReq) { |
| 595 | UNIMPLEMENTED(FATAL); |
| 596 | } |
| 597 | |
| 598 | void Dbg::RegisterObjectId(JDWP::ObjectId id) { |
| 599 | UNIMPLEMENTED(FATAL); |
| 600 | } |
| 601 | |
Elliott Hughes | f6a1e1e | 2011-10-25 16:28:04 -0700 | [diff] [blame] | 602 | /* |
| 603 | * "buf" contains a full JDWP packet, possibly with multiple chunks. We |
| 604 | * need to process each, accumulate the replies, and ship the whole thing |
| 605 | * back. |
| 606 | * |
| 607 | * Returns "true" if we have a reply. The reply buffer is newly allocated, |
| 608 | * and includes the chunk type/length, followed by the data. |
| 609 | * |
| 610 | * TODO: we currently assume that the request and reply include a single |
| 611 | * chunk. If this becomes inconvenient we will need to adapt. |
| 612 | */ |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 613 | bool Dbg::DdmHandlePacket(const uint8_t* buf, int dataLen, uint8_t** pReplyBuf, int* pReplyLen) { |
Elliott Hughes | f6a1e1e | 2011-10-25 16:28:04 -0700 | [diff] [blame] | 614 | CHECK_GE(dataLen, 0); |
| 615 | |
| 616 | Thread* self = Thread::Current(); |
| 617 | JNIEnv* env = self->GetJniEnv(); |
| 618 | |
| 619 | static jclass Chunk_class = env->FindClass("org/apache/harmony/dalvik/ddmc/Chunk"); |
| 620 | static jclass DdmServer_class = env->FindClass("org/apache/harmony/dalvik/ddmc/DdmServer"); |
| 621 | static jmethodID dispatch_mid = env->GetStaticMethodID(DdmServer_class, "dispatch", |
| 622 | "(I[BII)Lorg/apache/harmony/dalvik/ddmc/Chunk;"); |
| 623 | static jfieldID data_fid = env->GetFieldID(Chunk_class, "data", "[B"); |
| 624 | static jfieldID length_fid = env->GetFieldID(Chunk_class, "length", "I"); |
| 625 | static jfieldID offset_fid = env->GetFieldID(Chunk_class, "offset", "I"); |
| 626 | static jfieldID type_fid = env->GetFieldID(Chunk_class, "type", "I"); |
| 627 | |
| 628 | // Create a byte[] corresponding to 'buf'. |
| 629 | jbyteArray dataArray = env->NewByteArray(dataLen); |
| 630 | if (dataArray == NULL) { |
| 631 | LOG(WARNING) << "byte[] allocation failed: " << dataLen; |
| 632 | env->ExceptionClear(); |
| 633 | return false; |
| 634 | } |
| 635 | env->SetByteArrayRegion(dataArray, 0, dataLen, reinterpret_cast<const jbyte*>(buf)); |
| 636 | |
| 637 | const int kChunkHdrLen = 8; |
| 638 | |
| 639 | // Run through and find all chunks. [Currently just find the first.] |
| 640 | ScopedByteArrayRO contents(env, dataArray); |
| 641 | jint type = JDWP::get4BE(reinterpret_cast<const uint8_t*>(&contents[0])); |
| 642 | jint length = JDWP::get4BE(reinterpret_cast<const uint8_t*>(&contents[4])); |
| 643 | jint offset = kChunkHdrLen; |
| 644 | if (offset + length > dataLen) { |
| 645 | LOG(WARNING) << StringPrintf("bad chunk found (len=%u pktLen=%d)", length, dataLen); |
| 646 | return false; |
| 647 | } |
| 648 | |
| 649 | // Call "private static Chunk dispatch(int type, byte[] data, int offset, int length)". |
| 650 | jobject chunk = env->CallStaticObjectMethod(DdmServer_class, dispatch_mid, type, dataArray, offset, length); |
| 651 | if (env->ExceptionCheck()) { |
| 652 | LOG(INFO) << StringPrintf("Exception thrown by dispatcher for 0x%08x", type); |
| 653 | env->ExceptionDescribe(); |
| 654 | env->ExceptionClear(); |
| 655 | return false; |
| 656 | } |
| 657 | |
| 658 | if (chunk == NULL) { |
| 659 | return false; |
| 660 | } |
| 661 | |
| 662 | /* |
| 663 | * Pull the pieces out of the chunk. We copy the results into a |
| 664 | * newly-allocated buffer that the caller can free. We don't want to |
| 665 | * continue using the Chunk object because nothing has a reference to it. |
| 666 | * |
| 667 | * We could avoid this by returning type/data/offset/length and having |
| 668 | * the caller be aware of the object lifetime issues, but that |
| 669 | * integrates the JDWP code more tightly into the VM, and doesn't work |
| 670 | * if we have responses for multiple chunks. |
| 671 | * |
| 672 | * So we're pretty much stuck with copying data around multiple times. |
| 673 | */ |
| 674 | jbyteArray replyData = reinterpret_cast<jbyteArray>(env->GetObjectField(chunk, data_fid)); |
| 675 | length = env->GetIntField(chunk, length_fid); |
| 676 | offset = env->GetIntField(chunk, offset_fid); |
| 677 | type = env->GetIntField(chunk, type_fid); |
| 678 | |
| 679 | LOG(VERBOSE) << StringPrintf("DDM reply: type=0x%08x data=%p offset=%d length=%d", type, replyData, offset, length); |
| 680 | if (length == 0 || replyData == NULL) { |
| 681 | return false; |
| 682 | } |
| 683 | |
| 684 | jsize replyLength = env->GetArrayLength(replyData); |
| 685 | if (offset + length > replyLength) { |
| 686 | LOG(WARNING) << StringPrintf("chunk off=%d len=%d exceeds reply array len %d", offset, length, replyLength); |
| 687 | return false; |
| 688 | } |
| 689 | |
| 690 | uint8_t* reply = new uint8_t[length + kChunkHdrLen]; |
| 691 | if (reply == NULL) { |
| 692 | LOG(WARNING) << "malloc failed: " << (length + kChunkHdrLen); |
| 693 | return false; |
| 694 | } |
| 695 | JDWP::set4BE(reply + 0, type); |
| 696 | JDWP::set4BE(reply + 4, length); |
| 697 | env->GetByteArrayRegion(replyData, offset, length, reinterpret_cast<jbyte*>(reply + kChunkHdrLen)); |
| 698 | |
| 699 | *pReplyBuf = reply; |
| 700 | *pReplyLen = length + kChunkHdrLen; |
| 701 | |
| 702 | LOG(VERBOSE) << StringPrintf("dvmHandleDdm returning type=%.4s buf=%p len=%d", (char*) reply, reply, length); |
| 703 | return true; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 704 | } |
| 705 | |
Elliott Hughes | 47fce01 | 2011-10-25 18:37:19 -0700 | [diff] [blame^] | 706 | void DdmBroadcast(bool connect) { |
| 707 | LOG(VERBOSE) << "Broadcasting DDM " << (connect ? "connect" : "disconnect") << "..."; |
| 708 | |
| 709 | Thread* self = Thread::Current(); |
| 710 | if (self->GetState() != Thread::kRunnable) { |
| 711 | LOG(ERROR) << "DDM broadcast in thread state " << self->GetState(); |
| 712 | /* try anyway? */ |
| 713 | } |
| 714 | |
| 715 | JNIEnv* env = self->GetJniEnv(); |
| 716 | static jclass DdmServer_class = env->FindClass("org/apache/harmony/dalvik/ddmc/DdmServer"); |
| 717 | static jmethodID broadcast_mid = env->GetStaticMethodID(DdmServer_class, "broadcast", "(I)V"); |
| 718 | jint event = connect ? 1 /*DdmServer.CONNECTED*/ : 2 /*DdmServer.DISCONNECTED*/; |
| 719 | env->CallStaticVoidMethod(DdmServer_class, broadcast_mid, event); |
| 720 | if (env->ExceptionCheck()) { |
| 721 | LOG(ERROR) << "DdmServer.broadcast " << event << " failed"; |
| 722 | env->ExceptionDescribe(); |
| 723 | env->ExceptionClear(); |
| 724 | } |
| 725 | } |
| 726 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 727 | void Dbg::DdmConnected() { |
Elliott Hughes | 47fce01 | 2011-10-25 18:37:19 -0700 | [diff] [blame^] | 728 | DdmBroadcast(true); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 729 | } |
| 730 | |
| 731 | void Dbg::DdmDisconnected() { |
Elliott Hughes | 47fce01 | 2011-10-25 18:37:19 -0700 | [diff] [blame^] | 732 | DdmBroadcast(false); |
| 733 | gDdmThreadNotification = false; |
| 734 | } |
| 735 | |
| 736 | /* |
| 737 | * Send a notification when a thread starts or stops. |
| 738 | * |
| 739 | * Because we broadcast the full set of threads when the notifications are |
| 740 | * first enabled, it's possible for "thread" to be actively executing. |
| 741 | */ |
| 742 | void DdmSendThreadNotification(Thread* t, bool started) { |
| 743 | if (!gDdmThreadNotification) { |
| 744 | return; |
| 745 | } |
| 746 | |
| 747 | if (started) { |
| 748 | SirtRef<String> name(t->GetName()); |
| 749 | size_t char_count = (name.get() != NULL) ? name->GetLength() : 0; |
| 750 | |
| 751 | size_t byte_count = char_count*2 + sizeof(uint32_t)*2; |
| 752 | std::vector<uint8_t> buf(byte_count); |
| 753 | JDWP::set4BE(&buf[0], t->GetThinLockId()); |
| 754 | JDWP::set4BE(&buf[4], char_count); |
| 755 | if (char_count > 0) { |
| 756 | // Copy the UTF-16 string, transforming to big-endian. |
| 757 | const jchar* src = name->GetCharArray()->GetData(); |
| 758 | jchar* dst = reinterpret_cast<jchar*>(&buf[8]); |
| 759 | while (char_count--) { |
| 760 | JDWP::set2BE(reinterpret_cast<uint8_t*>(dst++), *src++); |
| 761 | } |
| 762 | } |
| 763 | Dbg::DdmSendChunk(CHUNK_TYPE("THCR"), buf.size(), &buf[0]); |
| 764 | } else { |
| 765 | uint8_t buf[4]; |
| 766 | JDWP::set4BE(&buf[0], t->GetThinLockId()); |
| 767 | Dbg::DdmSendChunk(CHUNK_TYPE("THDE"), 4, buf); |
| 768 | } |
| 769 | } |
| 770 | |
| 771 | void DdmSendThreadStartCallback(Thread* t) { |
| 772 | DdmSendThreadNotification(t, true); |
| 773 | } |
| 774 | |
| 775 | void Dbg::DdmSetThreadNotification(bool enable) { |
| 776 | // We lock the thread list to avoid sending duplicate events or missing |
| 777 | // a thread change. We should be okay holding this lock while sending |
| 778 | // the messages out. (We have to hold it while accessing a live thread.) |
| 779 | ThreadListLock lock; |
| 780 | |
| 781 | gDdmThreadNotification = enable; |
| 782 | if (enable) { |
| 783 | Runtime::Current()->GetThreadList()->ForEach(DdmSendThreadStartCallback); |
| 784 | } |
| 785 | } |
| 786 | |
| 787 | void PostThreadStartOrStop(Thread* t, bool is_start) { |
| 788 | if (gDebuggerActive) { |
| 789 | JDWP::ObjectId id = gRegistry->Add(t->GetPeer()); |
| 790 | gJdwpState->PostThreadChange(id, is_start); |
| 791 | } |
| 792 | DdmSendThreadNotification(t, is_start); |
| 793 | } |
| 794 | |
| 795 | void Dbg::PostThreadStart(Thread* t) { |
| 796 | PostThreadStartOrStop(t, true); |
| 797 | } |
| 798 | |
| 799 | void Dbg::PostThreadDeath(Thread* t) { |
| 800 | PostThreadStartOrStop(t, false); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 801 | } |
| 802 | |
Elliott Hughes | 3bb8156 | 2011-10-21 18:52:59 -0700 | [diff] [blame] | 803 | void Dbg::DdmSendChunk(int type, size_t byte_count, const uint8_t* buf) { |
| 804 | CHECK(buf != NULL); |
| 805 | iovec vec[1]; |
| 806 | vec[0].iov_base = reinterpret_cast<void*>(const_cast<uint8_t*>(buf)); |
| 807 | vec[0].iov_len = byte_count; |
| 808 | Dbg::DdmSendChunkV(type, vec, 1); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 809 | } |
| 810 | |
| 811 | void Dbg::DdmSendChunkV(int type, const struct iovec* iov, int iovcnt) { |
Elliott Hughes | 3bb8156 | 2011-10-21 18:52:59 -0700 | [diff] [blame] | 812 | if (gJdwpState == NULL) { |
| 813 | LOG(VERBOSE) << "Debugger thread not active, ignoring DDM send: " << type; |
| 814 | } else { |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 815 | gJdwpState->DdmSendChunkV(type, iov, iovcnt); |
Elliott Hughes | 3bb8156 | 2011-10-21 18:52:59 -0700 | [diff] [blame] | 816 | } |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 817 | } |
| 818 | |
| 819 | } // namespace art |