简体   繁体   English

如何调试Ruby gem? (罗盘)

[英]How do I debug a Ruby gem? (Compass)

I am in the early stages of learning Ruby and want to learn how to debug a gem, but am having trouble finding learning resources around this. 我正处于学习Ruby的早期阶段,并且想学习如何调试gem,但是我很难找到学习资源。 A simple example would go a long way for me. 一个简单的例子对我来说有很长的路要走。

Is debugger the preferred debugger? 调试器是首选调试器吗? Where do I require it? 我在哪里需要它? How do I set breakpoints with it? 如何设置断点?

Note: I am making an educated guess that the debugging process may be different depending on the gem that needs debugging, so for reference I am particularly interested in debugging certain issues with Compass . 注意:我正在做出有根据的猜测,根据需要调试的gem,调试过程可能会有所不同,因此作为参考,我对使用Compass 调试某些问题特别感兴趣。

OK, figured this out on my own. 好吧,我自己想出来了。 Here were the steps I took.. 这是我采取的步骤..

I am running Ruby 1.9.3 (determined by running ruby -v ), so after testing ruby-debug and ruby-debug19 , I determined these debuggers were no longer maintained, or at least didn't work properly with my install of ruby1.9.3-p125. 我正在运行Ruby 1.9.3(通过运行ruby -v确定),所以在测试ruby-debugruby-debug19之后 ,我确定这些调试器不再被维护,或者至少在我安装ruby1时无法正常工作。 9.3-P125。 This lead me to debugger . 这导致我调试

The install instructions that worked were: 有效的安装说明是:

$ gem install debugger -- --with-ruby-include=PATH_TO_HEADERS

The PATH_TO_HEADERS on my machine, was simply the source location of ruby: 我机器上的PATH_TO_HEADERS只是ruby的源位置:

/Users/myusername/.rvm/src/ruby-1.9.3-p125/

Since I was particularly determined to debug the Compass compiler, I did the following: 由于我特别决定调试Compass编译器,所以我做了以下事情:

  1. Cloned the source: $ git clone git://github.com/chriseppstein/compass.git 克隆源: $ git clone git://github.com/chriseppstein/compass.git
  2. Checked existing compass version first $ compass -v which was 13.0 检查现有指南针版本的第一个$ compass -v是13.0
  3. Edited VERSION.yml and increased the patch number (to 13.1) so it didn't conflict with my existing install. 编辑了VERSION.yml并增加了补丁号(至13.1),因此它与我现有的安装没有冲突。
  4. Edited the .rb of the file I wanted to debug, which was lib/compass/compiler.rb and added this line at the top: require 'debugger'; debugger 编辑了我想要调试的文件的.rb,它是lib/compass/compiler.rb并在顶部添加了这行: require 'debugger'; debugger require 'debugger'; debugger
  5. Built the gem: gem build compass.gemspec 构建了gem: gem build compass.gemspec
  6. Installed the newly compiled gem: sudo gem install compass-0.13.2.058ead2.gem 安装新编译的gem: sudo gem install compass-0.13.2.058ead2.gem
  7. Compiled an existing compass based project that I was experiencing problems with, and started debugging. 编译了我遇到问题的现有基于罗盘的项目,并开始调试。
  8. When I was done debugging, I uninstalled the debugging version with sudo gem uninstall compass and chose the number corresponding to Compass 13.2. 当我完成调试时,我用sudo gem uninstall compass卸载了调试版本,并选择了与Compass 13.2相对应的编号。

Note about step 7: Since debugger has the same debugging commands as ruby-debug/ruby-debug19, I was able to follow existing tutorials around debugging steps.. 关于步骤7的注意事项:由于调试器具有与ruby-debug / ruby​​-debug19相同的调试命令,因此我能够按照现有的调试步骤进行调试。

If you have other debugger tutorials, pointers, tips, etc, please post them. 如果您有其他调试器教程,指针,提示等,请发布它们。

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

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