node_debugger.cc 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 "atom/browser/node_debugger.h"
  5. #include "base/command_line.h"
  6. #include "base/strings/utf_string_conversions.h"
  7. #include "libplatform/libplatform.h"
  8. #include "native_mate/dictionary.h"
  9. #include "atom/common/node_includes.h"
  10. namespace atom {
  11. NodeDebugger::NodeDebugger(node::Environment* env) : env_(env) {}
  12. NodeDebugger::~NodeDebugger() {}
  13. void NodeDebugger::Start(node::MultiIsolatePlatform* platform) {
  14. auto* inspector = env_->inspector_agent();
  15. if (inspector == nullptr)
  16. return;
  17. node::DebugOptions options;
  18. for (auto& arg : base::CommandLine::ForCurrentProcess()->argv()) {
  19. #if defined(OS_WIN)
  20. options.ParseOption("Electron", base::UTF16ToUTF8(arg));
  21. #else
  22. options.ParseOption("Electron", arg);
  23. #endif
  24. }
  25. // Set process._debugWaitConnect if --inspect-brk was specified to stop
  26. // the debugger on the first line
  27. if (options.wait_for_connect()) {
  28. mate::Dictionary process(env_->isolate(), env_->process_object());
  29. process.Set("_breakFirstLine", true);
  30. }
  31. inspector->Start(static_cast<node::NodePlatform*>(platform), nullptr,
  32. options);
  33. DCHECK(env_->inspector_agent()->IsStarted());
  34. }
  35. } // namespace atom