2010-05-04 42 views
5

从触发断点的时候我就会知道这一点。它看起来像堆栈帧没有得到保存,所以我不能退后通过调用堆栈 - 一个真正的痛苦。看下面的例子为什么ruby-debug会说'保存的帧可能不完整'

--> #0 BatchProcess.add_failure_record(row_id#Fixnum, test#Struct::Test, message#String,...) 
     at line server/processes/batch.rb:309 
Warning: saved frames may be incomplete; compare with caller(0). 
(rdb:1) pp caller 
["./server/processes/batch.rb:309:in `run_tests'", 
"./server/processes/common/generic_process.rb:219:in `each'", 
"./server/processes/common/generic_process.rb:219:in `run_tests'", 
"./server/processes/common/generic_process.rb:271:in `run_plan'", 
"./server/processes/common/corrections.rb:19:in `each_with_index'", 
"./server/processes/common/generic_process.rb:266:in `each'", 
"./server/processes/common/generic_process.rb:266:in `each_with_index'", 
"./server/processes/common/generic_process.rb:266:in `run_plan'", 
"./server/processes/batch.rb:202:in `run_engine'", 
"/usr/lib/ruby/1.8/benchmark.rb:293:in `measure'", 
"./server/processes/batch.rb:201:in `run_engine'", 
"./server/processes/common/generic_process.rb:88:in `run_dataset'", 
"./server/processes/batch.rb:210:in `run_dataset'", 
"/usr/lib/ruby/1.8/benchmark.rb:293:in `measure'", 
"./server/processes/batch.rb:209:in `run_dataset'", 
"./server/processes/common/generic_process.rb:159:in `run'", 
"./server/processes/common/generic_process.rb:158:in `each'", 
"./server/processes/common/generic_process.rb:158:in `run'", 
"./server/processes/batch.rb:350:in `run'", 
"/usr/lib/ruby/1.8/benchmark.rb:293:in `measure'", 
"./server/processes/batch.rb:349:in `run'", 
"server/processes/test_runs/run_tests.rb:55:in `run_one_process'", 
"server/processes/test_runs/run_tests.rb:81"] 

有关如何阻止这种情况发生的任何想法?

回答

7

这意味着由Ruby的调用方()函数报告的调用堆栈与调试器作为调用堆栈记录的内容不匹配。

如果在调用堆栈中有多个帧的情况下激活了调试器跟踪,则会发生这种情况。它也可能发生在ruby-debug错误的地方,它不能正确跟踪。一种“补救措施”是将其放在主文件中的文件的开头: 要求'ruby-debug'; Debugger.start

但是,这样做的缺点是从程序开始就会增加一些额外的开销。

在您的Ruby代码的某处,您必须告诉Ruby开始跟踪调用和返回。通常这是通过Debugger.start和Debugger.stop或Debugger.start {}的组合完成的。如果你是从一个框架运行的话,这些命令会在你的某个地方发布,所以在正确的地方发布的责任取决于添加了这个代码的程序员。

最后,下了线,我会改变的消息是一个小更明确:

Warning: saved frames may be incomplete; 
compare debugger backtrace (bt) with Ruby caller(0). 
+0

感谢洛基。下次发生这种情况时,我会尝试使用Debugger.start解决方法 – 2010-05-07 12:41:32

+0

我再次遇到这个问题,并且解决方案正常工作。满分给你! – 2010-05-10 12:42:22

+0

我不确定这个新消息是否也是有用的。也许最好是让它包含“请考虑调用”require“ruby-debug”\ n Debugger.start在程序开始处。“ – Smar 2013-10-18 09:56:53