Skip to content

Instantly share code, notes, and snippets.

Google Summer of Code 2021: Tests for debugger

Background and Motivation

Current lib/debug.rb is no longer being maintained and it is not appropriate for current Ruby features. Koichi Sasada started writing new lib/debug.rb (hereinafter referred to as the new debugger) to replace it(For more information, see this article). However, it was hard to write test for it because the test framework have to test the new debugger without interrupting debugger process. That's why we worked on developping the test framework for the new debugger as the part of GSoC 2021 project.

Project Goal

Main goal

Socket.tcp_server_sockets "127.0.0.1", 9229 do |socks|
Socket.accept_loop(socks) do |sock, client|
while l = sock.gets
p l
case l
when /^GET \/json\/version HTTP\/1.1/
sock.print "HTTP/1.0 200 OK\r\nContent-Type: application/json; charset=UTF-8\r\nCache-Control: no-cache\r\nContent-Length: 64\r\n\r\n{\n \"Browser\": \"node.js/v17.0.1\",\n \"Protocol-Version\": \"1.1\"\n} "
when /^GET \/json HTTP\/1.1/
sock.print "HTTP/1.0 200 OK\r\nContent-Type: application/json; charset=UTF-8\r\nCache-Control: no-cache\r\nContent-Length: 660\r\n\r\n[ {\n \"description\": \"node.js instance\",\n \"devtoolsFrontendUrl\": \"devtools://devtools/bundled/js_app.html?experiments=true&v8only=true&ws=127.0.0.1:9229/5e7fe95a-33c8-4035-a11a-de9f5845840a\",\n \"devtoolsFrontendUrlCompat\": \"devtools://devtools/bundled/inspector.html?experiments=true&v8only=true&ws=127.0.0.1:9229/5e7fe95a-33c8-4035-a11a-de9f5845840a\",\n \"faviconUrl\": \"https://nodejs.org/static/images/favicons/favic

Ruby アソシエーション開発助成金2021中間報告: “debug.gem”の利用体験・開発効率の改善

取り組んだこと

 前期では、本プロジェクトのゴールである Chrome でのデバッグ機能を実現する CDP サーバーと、CDPサーバー と DAPサーバー(VS Code でのデバッグ機能を実現するサーバー) のテストフレームワークの開発を中心に取り組んだ。

 CDP サーバーの開発については本プロジェクト開始前にプロトタイプとして導入されていたものを改善する形で主にバグ修正や Chrome DevTools 上の UI として提供されている機能をサポートしていった。 バグ修正については手元の環境で Chrome を用いてデバッグ機能を行いそれを元に見つかったバグを中心に修正を行っていった。提供されている機能のサポートについては、例外で止まる機能やブレークポイントなしでスクリプト実行を強制する機能などを実装した。他にもデバッガー起動時に Chrome を自動で開いて Chrome DevTools とデバッガーの接続を自動で行う機能や Chrome のコンソールで式評価をした際に標準出力に出力されるものをターミナルではなくコンソール上に出力されるものを開発した。

 テストフレームワーク開発についてはプロトタイプとしていくつかのものを Pull Request として作りながらメンテナンス性や可読性の高いものを考えていった。現在 DAP サーバーのテストフレームワークがプロトタイプとしてマージされている。

Ruby アソシエーション開発助成金2021最終報告: “debug.gem”の利用体験・開発効率の改善

取り組んだこと

 前後期で一貫して取り組んだことは Chrome でのデバッグ機能の実装を通した利用体験・フレームワーク開発による開発効率の改善である。

 前期では、Chrome を使ったデバッグを問題なくできるところを目指し、外部ツール(Chrome、VSCode) とのインターフェースをテストするフレームワーク導入に向けて実装していった。後期では、Chrome DevTools の強みを活かしたリッチな体験、 プロトタイプを通して得られた知見をもとによりよいフレームワーク開発による開発効率の向上を目標に取り組んだ。

Chrome のデバッグ機能について

@ono-max
ono-max / sample.rb
Last active September 26, 2022 23:25
module REXMLInspector
def to_obj_inspector kw
[
{
type: :tree,
data: get_tree(self)
}
]
end
require 'json'
module REXMLInspector
def to_rdbg_mimebundle kw
json = JSON.generate {
type: :tree,
data: get_tree(self)
}
[
{
"application/json" => json
@ono-max
ono-max / api.rb
Last active October 3, 2022 14:03
# pattern1
def to_rdbg_mimebundle kw
format = {
"application/rdbg+json" => json
}
format, {}
end
# pattern2
def to_rdbg_mimebundle kw
require 'webrick'
require 'json'
binding = TOPLEVEL_BINDING.dup
srv = WEBrick::HTTPServer.new({:BindAddress => '127.0.0.1',
:Port => 8080})
srv.mount_proc('/') {|req, res|
body = JSON.parse req.body
expr = body['expression']
result = binding.eval(expr)
puts result

2万件

トレースなし 0.006363000255078077 0.006033000070601702 0.004674999974668026 0.007385000120848417 0.006134000141173601
配列2つ 1.2077299999073148 1.2094470001757145 1.2031790004111826 1.2191599998623133 1.1907759997993708
配列一つ(shift) 1.1787890000268817 1.2063179998658597 1.194932000245899 1.1878820001147687 1.1984939998947084
リングバッファ 1.208700000308454 1.210185999982059 1.2016769996844232 1.2195199998095632 1.2273840000852942
  1. ブロックのみ
@tracer = TracePoint.new(:a_call, :a_return, :line){|tp|
end
  1. skip? メソッド()を追加
@tracer = TracePoint.new(:a_call, :a_return, :line){|tp|