node_debugger.cc 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 <string>
  6. #include "base/command_line.h"
  7. #include "base/strings/utf_string_conversions.h"
  8. #include "libplatform/libplatform.h"
  9. #include "native_mate/dictionary.h"
  10. #include "atom/common/node_includes.h"
  11. namespace atom {
  12. NodeDebugger::NodeDebugger(node::Environment* env)
  13. : env_(env) {
  14. }
  15. NodeDebugger::~NodeDebugger() {
  16. }
  17. void NodeDebugger::Start(node::NodePlatform* platform) {
  18. auto inspector = env_->inspector_agent();
  19. if (inspector == nullptr)
  20. return;
  21. node::DebugOptions options;
  22. for (auto& arg : base::CommandLine::ForCurrentProcess()->argv()) {
  23. #if defined(OS_WIN)
  24. const std::string nice_arg = base::UTF16ToUTF8(arg);
  25. #else
  26. const std::string& nice_arg = arg;
  27. #endif
  28. // Stop handling arguments after a "--" to be consistent with Chromium
  29. if (nice_arg == "--")
  30. break;
  31. options.ParseOption("Electron", nice_arg);
  32. }
  33. if (options.inspector_enabled()) {
  34. // Set process._debugWaitConnect if --inspect-brk was specified to stop
  35. // the debugger on the first line
  36. if (options.wait_for_connect()) {
  37. mate::Dictionary process(env_->isolate(), env_->process_object());
  38. process.Set("_breakFirstLine", true);
  39. }
  40. inspector->Start(platform, nullptr, options);
  41. }
  42. }
  43. } // namespace atom