简体   繁体   English

如何在 Ruby 2.0 中使用调试器?

[英]How to use the debugger with Ruby 2.0?

I know the debugger gem is not and never will be compatible with ruby 2.0 per " officially support ruby 2.X ".我知道调试器 gem 不是也永远不会与“ 正式支持 ruby​​ 2.X ”的 ruby​​ 2.0 兼容。

In the changelog of Ruby 2.0 is:在 Ruby 2.0 的更新日志中是:

Debug support调试支持

DTrace support, which enables run-time diagnosis in DTrace 支持,可在

production TracePoint, which is an improved tracing API生产 TracePoint,这是一个改进的跟踪 API

Is there something out of the box for debugging with Ruby 2.0?是否有开箱即用的 Ruby 2.0 调试功能? Can somebody explain this to me?有人可以向我解释一下吗?

The debugger gem can be used but it still has issues. 可以使用调试器gem,但它仍然存在问题。

Install byebug which was written for Ruby 2.0 debugging. 安装为Ruby 2.0调试编写的byebug

For breakpoints, use the byebug command in your code instead of debugger . 对于断点,请在代码中使用byebug命令而不是debugger

Version 1.4.0 of the debugger gem now installs without problems. 调试器gem的1.4.0版现在安装没有问题。 There are still some issues but this should be fixed soon. 仍有一些问题,但应尽快修复。

The debugger gem does not play well with Ruby 2. Instead, install the Byebug gem that is fully compatible with Ruby 2. 调试器gem与Ruby 2不兼容。相反,安装与Ruby 2完全兼容的Byebug gem。

Use pry : 使用

gem install pry  
gem install pry-debugger

See " Debugging Ruby With Pry ". 请参阅“ 使用Pry调试Ruby ”。

debug.rb (aka binding.break) debug.rb(又名 binding.break)

Consider using a new Ruby debugging tool called debug.rb .考虑使用名为debug.rb的新 Ruby 调试工具。

It supports syntax highlighting and many more out-of-the-box.它支持语法高亮和更多开箱即用的功能。

Also, it is worth mentioning that it is developed by the Ruby core team.此外,值得一提的是,它是由 Ruby 核心团队开发的。

Just place binding.break anywhere in your codebase.只需将binding.break放在代码库中的任何位置。

Here is an example:下面是一个例子:

binding.break 示例

Also, it is a default Rails debugger starting from version 7 .此外,它是从版本 7 开始默认 Rails 调试器

Notes:笔记:

  • Do not forget about require 'debug'不要忘记require 'debug'
  • q # quit command

Sources:资料来源:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM