使用byebug进行调试时,如何扩展堆栈?

编程入门 行业动态 更新时间:2024-10-11 07:25:31
本文介绍了使用byebug进行调试时,如何扩展堆栈?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我当前收到一个类似以下错误:

I'm currently getting an error that looks like this:

NoMethodError: undefined method `debug' for nil:NilClass /mnt/hgfs/Dropbox/Company/Project/lib/project/misc.rb:23:in `debug' /mnt/hgfs/Dropbox/Company/Project/lib/project/validation/google_geocoding_validation_engine.rb:49:in `block in compare_addresses' /mnt/hgfs/Dropbox/Company/Project/lib/project/validation/google_geocoding_validation_engine.rb:43:in `each' /mnt/hgfs/Dropbox/Company/Project/lib/project/validation/google_geocoding_validation_engine.rb:43:in `compare_addresses' /mnt/hgfs/Dropbox/Company/Project/lib/project/validation/google_geocoding_validation_engine.rb:32:in `valid?' /mnt/hgfs/Dropbox/Company/Project/specs/project/validation/google_geocoding_validation_engine_spec.rb:56:in `block (2 levels) in <module:Validation>' /home/tomas/ruby2/lib/ruby/2.0.0/minitest/unit.rb:1301:in `run'

我认为我会尝试使用 byebug 来找出为什么对象是nil因为它永远都不应该是nil.我将byebug放在错误行的正上方:

I figured I'd try using byebug to figure out why the object is nil since it's never supposed to be nil. I placed byebug just above the erroneous line:

def debug(&block) if @logger.nil? byebug end @logger.debug(@logger_name, &block) end

并运行测试.我掉到了byebug调试界面,可以确认该对象确实是nil.问题是我无法爬上堆栈:

And ran the tests. I was dropped to the byebug debugging interface and could confirm that the object was indeed nil. The problem is that I can't climb up the stack:

(byebug) up *** Adjusting would put us beyond the oldest (initial) frame. (byebug) down *** Adjusting would put us beyond the newest (innermost) frame. (byebug) backtrace --> #0 AddressKit::Misc::Logging.debug(block#Proc) at /mnt/hgfs/Dropbox/Kvantel/Address Kit/lib/addresskit/misc.rb:25 Warning: saved frames may be incomplete; compare with caller(0)

我为什么不能进入堆栈?这是byebug的问题,还是MiniTest的不兼容性?

Why can't I go up the stack? Is this an issue with byebug or perhaps an incompatibility with MiniTest?

推荐答案

Beebug的答案> = 1.5.0

在这种情况下打印并在调用栈中移动应该可以正常工作,而OP不会出现此问题.

Answer for byebug >= 1.5.0

Printing and moving around the callstack in situations like this one should just work and the OP wouldn't have this issue.

在调用Byebug.start之前,Bybug不会开始跟踪调用堆栈信息,而byebug命令在内部调用了Byebug.start.因此,当您收到调试提示时,仅保存了一个调用堆栈帧,这就是您收到该消息的原因:

Byebug won't start tracking down callstack information until Byebug.start is called, which is internally called by the byebug command. So by the time you get the debugging prompt, only one callstack frame has been saved, that's why you get that message:

Warning: saved frames may be incomplete; compare with caller(0)

这就是为什么您不能移动up或down的原因:只有一帧.

and that's why you can't move up or down: there's only one frame.

要正确地浏览堆栈,您需要通过将Byebug.start放到要开始跟踪调用堆栈信息的位置来将Byebug向上启动.例如,在google_geocoding_validation_engine_spec.rb中的第56行之前.如果您需要完整的堆栈信息,则可以通过运行byebug可执行文件从一开始就运行byebug:

To properly navigate the stack, you need to start Byebug higher up, by dropping Byebug.start wherever you want to start tracking down callstack info. For example, before line 56 in google_geocoding_validation_engine_spec.rb. If you want full stack information, you can run byebug from the outset, by running the byebug executable:

byebug rake

或者您正在运行规范.

如果仍有问题,请告诉我!

If you still have issues, please let me know!

希望这会有所帮助.

更多推荐

使用byebug进行调试时,如何扩展堆栈?

本文发布于:2023-11-29 05:54:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1645530.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:堆栈   byebug

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!