node_debugger.cc 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 <memory>
  6. #include <string>
  7. #include <vector>
  8. #include "base/command_line.h"
  9. #include "base/logging.h"
  10. #include "base/strings/utf_string_conversions.h"
  11. #include "libplatform/libplatform.h"
  12. #include "native_mate/dictionary.h"
  13. #include "atom/common/node_includes.h"
  14. namespace atom {
  15. NodeDebugger::NodeDebugger(node::Environment* env) : env_(env) {}
  16. NodeDebugger::~NodeDebugger() {}
  17. void NodeDebugger::Start() {
  18. auto* inspector = env_->inspector_agent();
  19. if (inspector == nullptr)
  20. return;
  21. std::vector<std::string> args;
  22. for (auto& arg : base::CommandLine::ForCurrentProcess()->argv()) {
  23. #if defined(OS_WIN)
  24. args.push_back(base::UTF16ToUTF8(arg));
  25. #else
  26. args.push_back(arg);
  27. #endif
  28. }
  29. auto options = std::make_shared<node::DebugOptions>();
  30. std::vector<std::string> exec_args;
  31. std::vector<std::string> v8_args;
  32. std::string error;
  33. node::options_parser::DebugOptionsParser::instance.Parse(
  34. &args, &exec_args, &v8_args, options.get(),
  35. node::options_parser::kDisallowedInEnvironment, &error);
  36. if (!error.empty()) {
  37. // TODO(jeremy): what's the appropriate behaviour here?
  38. LOG(ERROR) << "Error parsing node options: " << error;
  39. }
  40. // Set process._debugWaitConnect if --inspect-brk was specified to stop
  41. // the debugger on the first line
  42. if (options->wait_for_connect()) {
  43. mate::Dictionary process(env_->isolate(), env_->process_object());
  44. process.Set("_breakFirstLine", true);
  45. }
  46. const char* path = "";
  47. inspector->Start(path, options);
  48. // FIXME
  49. // DCHECK(env_->inspector_agent()->IsListening());
  50. }
  51. } // namespace atom