| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent aa32bd0 commit 54cd7df
13 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -548,10 +548,6 @@ void Agent::Connect(InspectorSessionDelegate* delegate) { | |||
| 548 | 548 | client_->connectFrontend(delegate); | |
| 549 | 549 | } | |
| 550 | 550 | ||
| 551 | - bool Agent::IsConnected() { | ||
| 552 | - return io_ && io_->IsConnected(); | ||
| 553 | - } | ||
| 554 | - | ||
| 555 | 551 | void Agent::WaitForDisconnect() { | |
| 556 | 552 | CHECK_NE(client_, nullptr); | |
| 557 | 553 | client_->contextDestroyed(parent_env_->context()); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -48,7 +48,6 @@ class Agent { | |||
| 48 | 48 | bool IsStarted() { return !!client_; } | |
| 49 | 49 | ||
| 50 | 50 | // IO thread started, and client connected | |
| 51 | - bool IsConnected(); | ||
| 52 | 51 | bool IsWaitingForConnect(); | |
| 53 | 52 | ||
| 54 | 53 | void WaitForDisconnect(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -136,7 +136,7 @@ class InspectorIoDelegate: public node::inspector::SocketServerDelegate { | |||
| 136 | 136 | const std::string& script_name, bool wait); | |
| 137 | 137 | // Calls PostIncomingMessage() with appropriate InspectorAction: | |
| 138 | 138 | // kStartSession | |
| 139 | - bool StartSession(int session_id, const std::string& target_id) override; | ||
| 139 | + void StartSession(int session_id, const std::string& target_id) override; | ||
| 140 | 140 | // kSendMessage | |
| 141 | 141 | void MessageReceived(int session_id, const std::string& message) override; | |
| 142 | 142 | // kEndSession | |
@@ -145,19 +145,22 @@ class InspectorIoDelegate: public node::inspector::SocketServerDelegate { | |||
| 145 | 145 | std::vector<std::string> GetTargetIds() override; | |
| 146 | 146 | std::string GetTargetTitle(const std::string& id) override; | |
| 147 | 147 | std::string GetTargetUrl(const std::string& id) override; | |
| 148 | - bool IsConnected() { return connected_; } | ||
| 149 | 148 | void ServerDone() override { | |
| 150 | 149 | io_->ServerDone(); | |
| 151 | 150 | } | |
| 152 | 151 | ||
| 152 | + void AssignTransport(InspectorSocketServer* server) { | ||
| 153 | + server_ = server; | ||
| 154 | + } | ||
| 155 | + | ||
| 153 | 156 | private: | |
| 154 | 157 | InspectorIo* io_; | |
| 155 | - bool connected_; | ||
| 156 | 158 | int session_id_; | |
| 157 | 159 | const std::string script_name_; | |
| 158 | 160 | const std::string script_path_; | |
| 159 | 161 | const std::string target_id_; | |
| 160 | 162 | bool waiting_; | |
| 163 | + InspectorSocketServer* server_; | ||
| 161 | 164 | }; | |
| 162 | 165 | ||
| 163 | 166 | void InterruptCallback(v8::Isolate*, void* agent) { | |
@@ -226,10 +229,6 @@ void InspectorIo::Stop() { | |||
| 226 | 229 | DispatchMessages(); | |
| 227 | 230 | } | |
| 228 | 231 | ||
| 229 | - bool InspectorIo::IsConnected() { | ||
| 230 | - return delegate_ != nullptr && delegate_->IsConnected(); | ||
| 231 | - } | ||
| 232 | - | ||
| 233 | 232 | bool InspectorIo::IsStarted() { | |
| 234 | 233 | return platform_ != nullptr; | |
| 235 | 234 | } | |
@@ -264,6 +263,7 @@ void InspectorIo::IoThreadAsyncCb(uv_async_t* async) { | |||
| 264 | 263 | MessageQueue<TransportAction> outgoing_message_queue; | |
| 265 | 264 | io->SwapBehindLock(&io->outgoing_message_queue_, &outgoing_message_queue); | |
| 266 | 265 | for (const auto& outgoing : outgoing_message_queue) { | |
| 266 | + int session_id = std::get<1>(outgoing); | ||
| 267 | 267 | switch (std::get<0>(outgoing)) { | |
| 268 | 268 | case TransportAction::kKill: | |
| 269 | 269 | transport->TerminateConnections(); | |
@@ -272,8 +272,14 @@ void InspectorIo::IoThreadAsyncCb(uv_async_t* async) { | |||
| 272 | 272 | transport->Stop(nullptr); | |
| 273 | 273 | break; | |
| 274 | 274 | case TransportAction::kSendMessage: | |
| 275 | - std::string message = StringViewToUtf8(std::get<2>(outgoing)->string()); | ||
| 276 | - transport->Send(std::get<1>(outgoing), message); | ||
| 275 | + transport->Send(session_id, | ||
| 276 | + StringViewToUtf8(std::get<2>(outgoing)->string())); | ||
| 277 | + break; | ||
| 278 | + case TransportAction::kAcceptSession: | ||
| 279 | + transport->AcceptSession(session_id); | ||
| 280 | + break; | ||
| 281 | + case TransportAction::kDeclineSession: | ||
| 282 | + transport->DeclineSession(session_id); | ||
| 277 | 283 | break; | |
| 278 | 284 | } | |
| 279 | 285 | } | |
@@ -293,6 +299,7 @@ void InspectorIo::ThreadMain() { | |||
| 293 | 299 | wait_for_connect_); | |
| 294 | 300 | delegate_ = &delegate; | |
| 295 | 301 | Transport server(&delegate, &loop, options_.host_name(), options_.port()); | |
| 302 | + delegate.AssignTransport(&server); | ||
| 296 | 303 | TransportAndIo<Transport> queue_transport(&server, this); | |
| 297 | 304 | thread_req_.data = &queue_transport; | |
| 298 | 305 | if (!server.Start()) { | |
@@ -308,6 +315,7 @@ void InspectorIo::ThreadMain() { | |||
| 308 | 315 | uv_run(&loop, UV_RUN_DEFAULT); | |
| 309 | 316 | thread_req_.data = nullptr; | |
| 310 | 317 | CHECK_EQ(uv_loop_close(&loop), 0); | |
| 318 | + delegate.AssignTransport(nullptr); | ||
| 311 | 319 | delegate_ = nullptr; | |
| 312 | 320 | } | |
| 313 | 321 | ||
@@ -358,6 +366,21 @@ void InspectorIo::NotifyMessageReceived() { | |||
| 358 | 366 | incoming_message_cond_.Broadcast(scoped_lock); | |
| 359 | 367 | } | |
| 360 | 368 | ||
| 369 | + TransportAction InspectorIo::Attach(int session_id) { | ||
| 370 | + Agent* agent = parent_env_->inspector_agent(); | ||
| 371 | + if (agent->delegate() != nullptr) | ||
| 372 | + return TransportAction::kDeclineSession; | ||
| 373 | + | ||
| 374 | + CHECK_EQ(session_delegate_, nullptr); | ||
| 375 | + session_id_ = session_id; | ||
| 376 | + state_ = State::kConnected; | ||
| 377 | + fprintf(stderr, "Debugger attached.\n"); | ||
| 378 | + session_delegate_ = std::unique_ptr<InspectorSessionDelegate>( | ||
| 379 | + new IoSessionDelegate(this)); | ||
| 380 | + agent->Connect(session_delegate_.get()); | ||
| 381 | + return TransportAction::kAcceptSession; | ||
| 382 | + } | ||
| 383 | + | ||
| 361 | 384 | void InspectorIo::DispatchMessages() { | |
| 362 | 385 | // This function can be reentered if there was an incoming message while | |
| 363 | 386 | // V8 was processing another inspector request (e.g. if the user is | |
@@ -375,16 +398,14 @@ void InspectorIo::DispatchMessages() { | |||
| 375 | 398 | MessageQueue<InspectorAction>::value_type task; | |
| 376 | 399 | std::swap(dispatching_message_queue_.front(), task); | |
| 377 | 400 | dispatching_message_queue_.pop_front(); | |
| 401 | + int id = std::get<1>(task); | ||
| 378 | 402 | StringView message = std::get<2>(task)->string(); | |
| 379 | 403 | switch (std::get<0>(task)) { | |
| 380 | 404 | case InspectorAction::kStartSession: | |
| 381 | - CHECK_EQ(session_delegate_, nullptr); | ||
| 382 | - session_id_ = std::get<1>(task); | ||
| 383 | - state_ = State::kConnected; | ||
| 384 | - fprintf(stderr, "Debugger attached.\n"); | ||
| 385 | - session_delegate_ = std::unique_ptr<InspectorSessionDelegate>( | ||
| 386 | - new IoSessionDelegate(this)); | ||
| 387 | - parent_env_->inspector_agent()->Connect(session_delegate_.get()); | ||
| 405 | + Write(Attach(id), id, StringView()); | ||
| 406 | + break; | ||
| 407 | + case InspectorAction::kStartSessionUnconditionally: | ||
| 408 | + Attach(id); | ||
| 388 | 409 | break; | |
| 389 | 410 | case InspectorAction::kEndSession: | |
| 390 | 411 | CHECK_NE(session_delegate_, nullptr); | |
@@ -428,22 +449,23 @@ InspectorIoDelegate::InspectorIoDelegate(InspectorIo* io, | |||
| 428 | 449 | const std::string& script_name, | |
| 429 | 450 | bool wait) | |
| 430 | 451 | : io_(io), | |
| 431 | - connected_(false), | ||
| 432 | 452 | session_id_(0), | |
| 433 | 453 | script_name_(script_name), | |
| 434 | 454 | script_path_(script_path), | |
| 435 | 455 | target_id_(GenerateID()), | |
| 436 | - waiting_(wait) { } | ||
| 456 | + waiting_(wait), | ||
| 457 | + server_(nullptr) { } | ||
| 437 | 458 | ||
| 438 | 459 | ||
| 439 | - bool InspectorIoDelegate::StartSession(int session_id, | ||
| 460 | + void InspectorIoDelegate::StartSession(int session_id, | ||
| 440 | 461 | const std::string& target_id) { | |
| 441 | - if (connected_) | ||
| 442 | - return false; | ||
| 443 | - connected_ = true; | ||
| 444 | - session_id_++; | ||
| 445 | - io_->PostIncomingMessage(InspectorAction::kStartSession, session_id, ""); | ||
| 446 | - return true; | ||
| 462 | + session_id_ = session_id; | ||
| 463 | + InspectorAction action = InspectorAction::kStartSession; | ||
| 464 | + if (waiting_) { | ||
| 465 | + action = InspectorAction::kStartSessionUnconditionally; | ||
| 466 | + server_->AcceptSession(session_id); | ||
| 467 | + } | ||
| 468 | + io_->PostIncomingMessage(action, session_id, ""); | ||
| 447 | 469 | } | |
| 448 | 470 | ||
| 449 | 471 | void InspectorIoDelegate::MessageReceived(int session_id, | |
@@ -464,7 +486,6 @@ void InspectorIoDelegate::MessageReceived(int session_id, | |||
| 464 | 486 | } | |
| 465 | 487 | ||
| 466 | 488 | void InspectorIoDelegate::EndSession(int session_id) { | |
| 467 | - connected_ = false; | ||
| 468 | 489 | io_->PostIncomingMessage(InspectorAction::kEndSession, session_id, ""); | |
| 469 | 490 | } | |
| 470 | 491 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -36,6 +36,7 @@ class InspectorIoDelegate; | |||
| 36 | 36 | ||
| 37 | 37 | enum class InspectorAction { | |
| 38 | 38 | kStartSession, | |
| 39 | + kStartSessionUnconditionally, // First attach with --inspect-brk | ||
| 39 | 40 | kEndSession, | |
| 40 | 41 | kSendMessage | |
| 41 | 42 | }; | |
@@ -44,7 +45,9 @@ enum class InspectorAction { | |||
| 44 | 45 | enum class TransportAction { | |
| 45 | 46 | kKill, | |
| 46 | 47 | kSendMessage, | |
| 47 | - kStop | ||
| 48 | + kStop, | ||
| 49 | + kAcceptSession, | ||
| 50 | + kDeclineSession | ||
| 48 | 51 | }; | |
| 49 | 52 | ||
| 50 | 53 | class InspectorIo { | |
@@ -61,7 +64,6 @@ class InspectorIo { | |||
| 61 | 64 | void Stop(); | |
| 62 | 65 | ||
| 63 | 66 | bool IsStarted(); | |
| 64 | - bool IsConnected(); | ||
| 65 | 67 | ||
| 66 | 68 | void WaitForDisconnect(); | |
| 67 | 69 | // Called from thread to queue an incoming message and trigger | |
@@ -124,6 +126,8 @@ class InspectorIo { | |||
| 124 | 126 | void WaitForFrontendMessageWhilePaused(); | |
| 125 | 127 | // Broadcast incoming_message_cond_ | |
| 126 | 128 | void NotifyMessageReceived(); | |
| 129 | + // Attach session to an inspector. Either kAcceptSession or kDeclineSession | ||
| 130 | + TransportAction Attach(int session_id); | ||
| 127 | 131 | ||
| 128 | 132 | const DebugOptions options_; | |
| 129 | 133 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments