英文:
Is there a way to save execution of ruby code to debug it using step by step replay later?
问题
我有一个在Ruby代码中难以复现的错误。通过不断运行我的测试套件,我大约每10-15分钟就会遇到一次。
我想要做的是逐步记录执行过程,一旦出现错误,就能继续进行调试,了解发生了什么事情。
我知道https://rr-project.org/,我曾经用它来调试C++中的类似问题。它基本上为您提供了一个完整的gdb界面,用于回放记录的内容。类似这样的工具将非常有用。
英文:
I have a rarely reproduced bug in ruby code. By running my test suite constantly I get it once every 10-15 minutes.
What I want to do is to have the execution recorded step by step and once it fails, go ahead and debug what happened.
I know about https://rr-project.org/ and I used it to debug such things in C++. It basically gives you a complete gdb interface into a recorded replay. Something along the same lines would be great.
答案1
得分: 1
有一个录制功能:
# intermittent.rb
需要 "debug"
# 弄清楚你的中断条件
binding.b do: "catch TypeError"
binding.b do: "record on"
# 这很慢 ^
class M
def m
var = rand(10)
var = "1" if rand(1000) == 666
var
end
end
循环 do
M.new.m + 1
end
从未真正使用过它,但你可以后退:
$ ruby ./intermittent.rb
停在 #0 断点 - 捕捉 "TypeError"
(rdbg) 后退一步
[重播] [6, 15] 在 ./intermittent.rb 中
[重播] 6|
[重播] 7| class M
[重播] 8| def m
[重播] 9| var = rand(10)
[重播] 10| var = "1" if rand(1000) == 666
[重播] => 11| var
[重播] 12| end
[重播] 13| end
[重播] 14|
[重播] 15| 循环 do
[重播] =>#0 M#m 在 ./intermittent.rb:11
[重播] #1 在 <main> 中的块 在 ./intermittent.rb:16
[重播] # 和 2 个框架 (使用 `bt' 命令查看所有框架)
(rdbg) 信息
[重播] %self = #<M:0x00007f946d07ef28>
[重播] var = "1"
(rdbg) 后退一步
(rdbg) 信息
[重播] %self = #<M:0x00007f946d07ef28>
[重播] var = 2
# 等等...
英文:
There is a recording functionality:
# intermittent.rb
require "debug"
# figure out your break condition
binding.b do: "catch TypeError"
binding.b do: "record on"
# this is slow ^
class M
def m
var = rand(10)
var = "1" if rand(1000) == 666
var
end
end
loop do
M.new.m + 1
end
Never really used it, but you can step back:
$ ruby ./intermittent.rb
Stop by #0 BP - Catch "TypeError"
(rdbg) step back
[replay] [6, 15] in ./intermittent.rb
[replay] 6|
[replay] 7| class M
[replay] 8| def m
[replay] 9| var = rand(10)
[replay] 10| var = "1" if rand(1000) == 666
[replay] => 11| var
[replay] 12| end
[replay] 13| end
[replay] 14|
[replay] 15| loop do
[replay] =>#0 M#m at ./intermittent.rb:11
[replay] #1 block in <main> at ./intermittent.rb:16
[replay] # and 2 frames (use `bt' command for all frames)
(rdbg) info
[replay] %self = #<M:0x00007f946d07ef28>
[replay] var = "1"
(rdbg) step back
(rdbg) info
[replay] %self = #<M:0x00007f946d07ef28>
[replay] var = 2
# etc...
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论