Skip to content

Commit 801f6f1

Browse files
author
Zev Blut
committed
Adding transcripts for dbgr videos.
1 parent 1fd6c03 commit 801f6f1

File tree

3 files changed

+151
-0
lines changed

3 files changed

+151
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
## これは何?
2+
RubyKaigi2010 向け[[解説資料動画パート1|RubyKaigi2010-emacs-rdebug.ogv]]の概要の和訳です
3+
The following is a rough transcript of the [[first part of a short video presentation|RubyKaigi2010-emacs-rdebug.ogv]] at Ruby Kaigi 2010
4+
5+
## Transcript
6+
Emacs 上で動く Ruby デバッガはいくつも存在します。その中から、私の独断と偏見でベストだと思うものをいくつか取り上げます。
7+
There are a number of Emacs debugger interfaces for Ruby. I'll mention couple of them that in my biased opinion are the best.
8+
9+
最初に、ruby-debug を紹介します。私はこれが最も洗練されていると思います。利用するためには、Gentoo Linux を使っている人以外は、ソースからインストールする必要があるでしょう。インストール手順は[[ここ|http://bashdb.sf.net/ruby-debug/rdebug-emacs.html#Installation]]に書かれています。
10+
The first works only for the debugger ruby-debug. I think it is the most sophisticated. Unless you are using a Gentoo Linux distribution, you will have to install this from the source. Installation instructions are [[here|http://bashdb.sf.net/ruby-debug/rdebug-emacs.html#Installation]].
11+
12+
インストールが終わったら、`M-x load-library rdebug` でロードします。
13+
To load the Emacs code after the Emacs package has been installed: `M-x load-library rdebug`
14+
15+
"rdebug" というコマンドが使えるようになっています。ここからは、サンプルプログラムを一からデバッグしていきます。まずは `M-x rdebug` から。
16+
And now I have a command called "rdebug". I will use that to debug a sample program from the beginning. `M-x rdebug`
17+
18+
Debian ディストリビューションには、別の「rdebug」Emacs Lisp が存在します。パッケージ名「emacs-goodies」のものがそうです。プロンプトに `--emacs` と表示されていれば、正しいものを使っています。
19+
There is another Emacs rdebug Lisp command that comes in the Debian distribution under the package name *emacs-goodies*. You know you have the right one if you see `--emacs` in the prompt.
20+
21+
`M-x rdebug --emacs 3 gcd.rb 3 5`
22+
23+
画面上段には、デバッガのコマンドラインとローカル変数の一覧が表示されています。中段にはソースコードと出力が。ソースコード枠の端には、矢印が表示されています。これは、今から実行しようとしている文を指しています。
24+
The top-most panel of windows is split between the debugger command line and local variables. The middle panel is split between the source code and output. There is an arrow in the fringe area of the source-code window to show you the statement you are about to run.
25+
26+
ここで Debugger メニューを見てみましょう。`[Stack of windows]``[Rocky II]` など、違った枠レイアウトが選べることが分かります。
27+
Check out the Debugger menu and the Window Layout section of that. You will see alternative window formats such as `[Stack of windows]` or `[Rocky II]`
28+
29+
`frame 0` で画面をリフレッシュします。
30+
To refresh the display `frame 0`
31+
32+
1ステップ進めてみましょう。ソースコード枠とコールスタック枠が更新されるでしょう。現時点では gcd.rb の4行目にいます。
33+
Let me step a statement and you will see the location in both the source code and the call stack windows updated. Right now we are at line 4 in file gcd.rb
34+
35+
`step`
36+
37+
コールスタック枠は、いま18行目にいるとの表示に変わり、ソースコート枠の矢印は現在位置に移動しました。
38+
Note that the call-stack windows show that we are now at line 18 and the source code fringe arrow has been updated.
39+
40+
"next" コマンドを使って現在行をステップオーバーしてみましょう。現状だと nil になっている変数 a と b の値が更新されます。
41+
Let me step over the entire line shown here using the command "next" and you will see that the values of "a" and "b" updated. Right now the values are nil.
42+
43+
コマンドライン枠でコマンドを使う代わりに、ソースコード枠の方で操作することもできます。単一キーストロークだけでデバッガコマンドを実行できるマイナーモードがあります。rdebug-short-key-mode というのがそれです。実際にやってみましょう。
44+
Instead of running commands in a commmand-line window, you can run commands inside the source-code window. There is minor mode that allows single key-strokes to run debugger commands. This is called rdebug-short-key-mode. Let me show that.
45+
46+
`M-x rdebug-short-key-mode`
47+
48+
"ShortKeys" という表示が出たことと、ファイルのバッファがリードオンリーになっているのがポイントです。
49+
Notice the "ShortKeys" indicator and also notice the file is now read only. [points to %%].
50+
51+
この状態でスペースキーを叩くとステップ実行できます。一番下には実際に実行されたコマンドが表示されています。
52+
Now when I hit the space bar, I step a statement. And down in the bottom message area I see the debugger command that was run.
53+
54+
コールスタック枠には2行表示されています。一つはいま実行している gcd メソッドの、もう一つは gcd を呼び出している箇所のものです。
55+
Notice the call-stack window now has two entries: an entry to reflect that I am in the gcd method and an entry for the place where I called gcd.
56+
57+
ブレークポイントを置くには、b をタイプします。デフォルト状態では有効になりますが、t をタイプすると無効になります。再び t をタイプすると有効に戻ります。
58+
To set a breakpoint I type "b". Breakpoints are enabled by default but to toggle the breakpoint from enabled to disabled I type "t". Type "t" again and the breakpoint is enabled.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
いまお見せした rdebug Emacs インターフェースは、"Grand Unified Debugger" (gud.el) というものを利用しています。しかし、 GUD には問題も多くて、しょっちゅう悩まされていました。そこで、 Emacs デバッガのインターフェースを一から作りなおしてみることにしたというわけです。このインターフェース上では、私の関わっている Ruby デバッガも動きますし、それ以外のいろんなデバッガも動かすことができます。
2+
Underneath, the rdebug Emacs interface I just showed you uses the "Grand Unified Debugger", or gud.el. But GUD has a number of issues that I kept running into. So I am rewriting the Emacs debugger interface from scratch. It accomodates the Ruby debuggers I'm involved with as well as a number of other debuggers.
3+
4+
[[ここ|http://wiki.github.com/rocky/emacs-dbgr/how-to-install]] にインストール手順が書かれています。
5+
Shown [[here|http://wiki.github.com/rocky/emacs-dbgr/how-to-install]] is the link which describes how to install the Emacs code.
6+
7+
インストールが終わって、ロードするには次のようにします:
8+
To load the Emacs code after the Emacs package has been installed:
9+
10+
`M-x load-library dbgr`
11+
12+
この状態で、「dbgr-」で始まる名前のいくつかのコマンドが使えるようになっています。たとえば「dbgr-rdebug」など。一部、「dbgr-」で始まらないものもあります。
13+
There are now several commands that have been added that all start `dbgr-`, such as `dbgr-rdebug`. There also are a few commands to invoke some of the debuggers which don't start `dbgr-`.
14+
15+
このデモでは、[[Ruby 1.9 debugger|http://github.com/rocky/rbdbgr]] を使ってみます。私がいま開発中のものです。別のデバッガでも操作は同様です。これを使って Ruby プログラムをデバッグするには、`rbdbgr` を使います。
16+
For demonstration, I'll use a new [[Ruby 1.9 debugger|http://github.com/rocky/rbdbgr]] that I've been working on. However the operation for the other debuggers is the same. To debug a Ruby program from the start, you can use the command `rbdbgr`
17+
18+
`M-x rbdbgr gcd.rb 3 5`
19+
20+
起動にあたって、過去の履歴を探します。何をしようとしているのが表示されます。
21+
For the invocation that is suggested, the rbdbgr command searches the invocation history and that is what is going on here.
22+
23+
2つの枠が表示されています。上側がデバッガコマンド枠、下側がソースコード枠です。枠の配置は rdebug のものほど凄くはないです。以前と同様に、ソースコード枠の端には現在実行中の位置を示す矢印が置かれています。
24+
I now have two windows, a debugger command window on top and the source-code window on bottom. The window layout here is not as advanced as it is in the custom interface for rdebug. As before, there is an arrow in the fringe area of the source-code window to show you the statement you are about to run.
25+
26+
`step+`
27+
28+
rdebug との違いは、一つ前にいた行の矢印が薄くなっているところです。
29+
Notice, in contrast to the rdebug interface, that the fringe arrow at the previous location has now faded a little bit. A "step over", or "next"
30+
31+
`next`
32+
33+
矢印が薄くなる効果は3段階まであります。ソースコード枠の方でも同様。Meta-↑で一つ前のポイントへ戻れます。Meta-↓で逆方向へ。
34+
and you see three levels of shading in the command window. That is also true in the source-code window. To see this, I type Meta-up arrow which adjusts the positions in both windows to the previous spots. And Meta-down arrow goes the other direction. [repeat] up ... down.
35+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
ここまででは、デバッガを外から使う方法を紹介しました。しかし、Ruby の場合だと、デバッガは実行中のプログラムの中から呼び出すこともできます。そのような場合に Emacs インターフェースでデバッグする方法をお見せします。
2+
Previously, I have been running the debugger from the outset. However in Ruby, the debugger is not often run initally. Instead it is called from inside a running program. Let me show briefly how use the Emacs interface in this situation.
3+
4+
プログラムはこのような感じです。Ruby 1.9 のデバッガを呼び出すように変更してあります。
5+
Here is a program where I have added a call to the Ruby 1.9 debugger.
6+
```ruby
7+
#!/usr/bin/env ruby
8+
require 'rbdbgr'
9+
10+
# GCD. We assume positive numbers
11+
def gcd(a, b)
12+
Debugger.new.debugger # Call debugger here!
13+
14+
# Make: a <= b
15+
if a > b
16+
a, b = [b, a]
17+
end
18+
19+
return nil if a <= 0
20+
21+
if a == 1 or b-a == 0
22+
return a
23+
end
24+
return gcd(b-a, a)
25+
end
26+
27+
a, b = ARGV[0..1].map {|arg| arg.to_i}
28+
puts "The GCD of %d and %d is %d" % [a, b, gcd(a, b)]
29+
```
30+
31+
通常のシェル上で、
32+
Now I go into a normal comint shell
33+
34+
`M-x shell`
35+
36+
このプログラムを走らせてみると、
37+
And when I run the program
38+
39+
`ruby gcd-dbgcall.rb 3 5`
40+
41+
デバッガが起動した状態になります。
42+
I am now in the debugger.
43+
44+
しかし、Emacs は現在のシェル上でデバッガが起動していることを知りません。なので、 dbgr-track-mode を使って伝えてやります。
45+
But Emacs doesn't know that this shell is inside a particular debugger. So to tell Emacs this, use dbgr-track-mode
46+
47+
`M-x dbgr-track-mode`
48+
49+
デバッガの名前を訊かれます。使えるものは [[いくつかの|http://github.com/rbdbgr]] [[Ruby デバッガ|http://bashdb.sourceforge.net/ruby-debug/home-page.html]]とか、 [[いくつかの|http://code.google.com/p/pydbgr/]] [[Python デバッガ|bashdb.sf.net/pydb]]、それに gdb や [[いくつかの|http://bashdb.sf.net] [POSIX シェルのhttp://github.com/rocky/kshdb] [[デバッガ|http://github.com/rocky/zshdb]] などです。後から別のものに変更することもできます。ここでは rbdbgr を使います。
50+
You are prompted for the name of a debugger. The debugger names you could list here include a [[couple of|http://github.com/rbdbgr]] [[Ruby debuggers|http://bashdb.sourceforge.net/ruby-debug/home-page.html]], a [[couple of|http://code.google.com/p/pydbgr/]] [[Python debuggers|bashdb.sf.net/pydb]], gdb, or [[some|http://bashdb.sf.net] [POSIX shell|http://github.com/rocky/kshdb] [[debuggers|http://github.com/rocky/zshdb]]. And you can switch from one to the another afterwards. I will use rbdbgr
51+
52+
`rbdbgr`
53+
54+
モードラインにデバッガの名前が出ている点に注目してください。
55+
Note the mode line now has the name of the debugger.
56+
57+
`frame 0` で画面をリフレッシュします。
58+
And use `frame 0` to refresh the display.

0 commit comments

Comments
 (0)