node_debugger.cc 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Copyright (c) 2014 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #include "shell/browser/node_debugger.h"
  5. #include <memory>
  6. #include <string>
  7. #include <vector>
  8. #include "base/command_line.h"
  9. #include "base/logging.h"
  10. #include "base/strings/string_util.h"
  11. #include "base/strings/utf_string_conversions.h"
  12. #include "libplatform/libplatform.h"
  13. #include "shell/common/gin_helper/dictionary.h"
  14. #include "shell/common/node_includes.h"
  15. namespace electron {
  16. NodeDebugger::NodeDebugger(node::Environment* env) : env_(env) {}
  17. NodeDebugger::~NodeDebugger() = default;
  18. void NodeDebugger::Start() {
  19. auto* inspector = env_->inspector_agent();
  20. if (inspector == nullptr)
  21. return;
  22. // DebugOptions will already have been set by ProcessGlobalArgs,
  23. // so just pull the ones from there to pass to the InspectorAgent
  24. const auto debug_options = env_->options()->debug_options();
  25. if (inspector->Start("" /* path */, debug_options,
  26. std::make_shared<node::ExclusiveAccess<node::HostPort>>(
  27. debug_options.host_port),
  28. true /* is_main */))
  29. DCHECK(inspector->IsListening());
  30. v8::HandleScope handle_scope(env_->isolate());
  31. node::profiler::StartProfilers(env_);
  32. if (inspector->options().break_node_first_line) {
  33. inspector->PauseOnNextJavascriptStatement("Break at bootstrap");
  34. }
  35. }
  36. void NodeDebugger::Stop() {
  37. auto* inspector = env_->inspector_agent();
  38. if (inspector && inspector->IsListening()) {
  39. inspector->WaitForDisconnect();
  40. inspector->Stop();
  41. }
  42. }
  43. } // namespace electron