=encoding euc-jp =head1 NAME X X =begin original perldebug - Perl debugging =end original perldebug - Perl のデバッグ =head1 DESCRIPTION =begin original First of all, have you tried using the B<-w> switch? =end original まず最初に一言「もう B<-w> スイッチはお使いになりましたか。」 =begin original If you're new to the Perl debugger, you may prefer to read L, which is a tutorial introduction to the debugger. =end original もし Perl デバッガに慣れていないなら、デバッガに関するチュートリアルである L を読んだ方がいいかもしれません。 =head1 The Perl Debugger =begin original If you invoke Perl with the B<-d> switch, your script runs under the Perl source debugger. This works like an interactive Perl environment, prompting for debugger commands that let you examine source code, set breakpoints, get stack backtraces, change the values of variables, etc. This is so convenient that you often fire up the debugger all by itself just to test out Perl constructs interactively to see what they do. For example: X<-d> =end original Perl を B<-d> スイッチを付けて起動すれば、スクリプトは Perl ソースデバッガ 上で実行されることになります。 これは対話的な Perl 環境のように動作し、 ソースコードの表示、ブレークポイントの設定、スタックのバックトレース、 変数の値の変更、などを実行するデバッガコマンドを入力できます。 これはとても便利なので、単にやりたいことを対話的に試すために デバッガを起動するようになるでしょう。 例えば: X<-d> $ perl -d -e 42 =begin original In Perl, the debugger is not a separate program the way it usually is in the typical compiled environment. Instead, the B<-d> flag tells the compiler to insert source information into the parse trees it's about to hand off to the interpreter. That means your code must first compile correctly for the debugger to work on it. Then when the interpreter starts up, it preloads a special Perl library file containing the debugger. =end original しかし、Perl デバッガは典型的なコンパイルされた環境の様に独立した プログラムではありません。 その代わりに、 -d フラグによって、コンパイラがインタプリタに渡すパース木にソース情報を 埋め込むようにしています。これは、ソースがデバッガ上で動作できるためには、 一度正常にコンパイルできないといけないということです。 それからインタプリタが起動され、デバッガを含む 特別な Perl ライブラリをロードします。 =begin original The program will halt I the first run-time executable statement (but see below regarding compile-time statements) and ask you to enter a debugger command. Contrary to popular expectations, whenever the debugger halts and shows you a line of code, it always displays the line it's I to execute, rather than the one it has just executed. =end original プログラムは、最初の実行時実行文のI<直前>で停止し (ただし、以下コンパイル時実行文については後述します)、以下に示すいずれかの コマンドが入力されるのを待ちます。 よくある期待とは逆に、 デバッガが停止してある行のコードを表示しているときは、 直前に実行した行ではなく、常にI<今から実行する>行を表示します。 =begin original Any command not recognized by the debugger is directly executed (C'd) as Perl code in the current package. (The debugger uses the DB package for keeping its own state information.) =end original デバッガが認識できないコマンドは現在のパッケージ内で Perl のコードとして 実行(C)されます。 (デバッガは自分自身の状態を保存するために DB パッケージを使います。) =begin original Note that the said C is bound by an implicit scope. As a result any newly introduced lexical variable or any modified capture buffer content is lost after the eval. The debugger is a nice environment to learn Perl, but if you interactively experiment using material which should be in the same scope, stuff it in one line. =end original C は暗黙のスコープで区切られていることに注意してください。 結果として、新しく導入されたレキシカル変数や変更された捕捉バッファの内容は eval の後失われます。 デバッガは Perl を学ぶよい環境ですが、もし同じスコープ内であるべき ものを使って対話的に実験したい場合は、それを 1 行に書いてください。 =begin original For any text entered at the debugger prompt, leading and trailing whitespace is first stripped before further processing. If a debugger command coincides with some function in your own program, merely precede the function with something that doesn't look like a debugger command, such as a leading C<;> or perhaps a C<+>, or by wrapping it with parentheses or braces. =end original デバッガコマンドとして入力された文字列は、まず先頭と末尾の 空白が切り詰められます。 デバッガコマンドがプログラムの関数名と一致する場合、 関数名の前に C<;> や C<+> のような、デバッガコマンドに見えない文字を 付け加えるか、括弧でくくってください。 =head2 Calling the Debugger (デバッガを呼び出す) =begin original There are several ways to call the debugger: =end original デバッガを呼び出すにはいくつかの方法があります: =over 4 =item perl -d program_name =begin original On the given program identified by C. =end original C で識別されるプログラムに対して。 =item perl -d -e 0 =begin original Interactively supply an arbitrary C using C<-e>. =end original C<-e> を使って指定された任意の C を対話的に。 =item perl -d:ptkdb program_name =begin original Debug a given program via the C GUI. =end original C GUI 経由で与えられたプログラムをデバッグする。 =item perl -dt threaded_program_name =begin original Debug a given program using threads (experimental). =end original スレッドを使っているプログラムをデバッグする(実験的機能)。 =back =head2 Debugger Commands (デバッガコマンド) =begin original The interactive debugger understands the following commands: =end original 対話式のデバッガは以下のコマンドを理解します: =over 12 =item h X =begin original Prints out a summary help message =end original サマリヘルプメッセージを表示します。 =item h [command] =begin original Prints out a help message for the given debugger command. =end original 指定されたコマンドの説明を表示します。 =item h h =begin original The special argument of C produces the entire help page, which is quite long. =end original C という特別なコマンドは、かなり長い、ヘルプ全体を表示します。 =begin original If the output of the C command (or any command, for that matter) scrolls past your screen, precede the command with a leading pipe symbol so that it's run through your pager, as in =end original C コマンド(や他のコマンドでも)の出力で画面がスクロールしてしまう場合、 以下のようにコマンドの前にパイプ記号をつけるとページャーを呼び出します: DB> |h h =begin original You may change the pager which is used via C command. =end original 使用されるページャーは C コマンドで変更できます。 =item p expr X =begin original Same as C in the current package. In particular, because this is just Perl's own C function, this means that nested data structures and objects are not dumped, unlike with the C command. =end original 現在のパッケージでの C と同じです。 特に、これは Perl 自身の C 関数なので、 C コマンドと違って、ネストしたデータ構造やオブジェクトはダンプしません。 =begin original The C filehandle is opened to F, regardless of where STDOUT may be redirected to. =end original STDOUT がどこにリダイレクトされていても、 ファイルハンドル C は F に対して オープンされています。 =item x [maxdepth] expr X =begin original Evaluates its expression in list context and dumps out the result in a pretty-printed fashion. Nested data structures are printed out recursively, unlike the real C function in Perl. When dumping hashes, you'll probably prefer 'x \%h' rather than 'x %h'. See L if you'd like to do this yourself. =end original 式をリストコンテキストで評価し、結果を多少読みやすい形で表示します。 ネストしたデータは再帰的に表示します; これは Perl の実際の C 関数とは 異なります。 ハッシュをダンプするとき、おそらく 'x %h' より 'x \%h' を好むでしょう。 これを自分自身で行いたい場合は L を参照して下さい。 =begin original The output format is governed by multiple options described under L<"Configurable Options">. =end original 出力フォーマットは L<"Configurable Options"> に記された 様々なオプションの影響を受けます。 =begin original If the C is included, it must be a numeral I; the value is dumped only I levels deep, as if the C option had been temporarily set to I. =end original C が指定されている場合、それは数値 I でなければなりません; C オプションが一時的に I に設定されたかのように、 値は I レベルの深さでだけダンプされます。 =item V [pkg [vars]] X =begin original Display all (or some) variables in package (defaulting to C
) using a data pretty-printer (hashes show their keys and values so you see what's what, control characters are made printable, etc.). Make sure you don't put the type specifier (like C<$>) there, just the symbol names, like this: =end original package (デフォルトは C
) 内のすべて (または、一部) の 変数 (variable) をデータプリティプリンタを使って表示します (ハッシュは何が何か解るように、key と value を表示し、 コントロール文字は表示できる形にします)。 以下に示すように、symbol は名前だけを示し、(C<$> などの) 型識別子を 付けないようにしてください: V DB filename line =begin original Use C<~pattern> and C for positive and negative regexes. =end original 正と逆の正規表現のためには C<~pattern> と C を使ってください。 =begin original This is similar to calling the C command on each applicable var. =end original これは有効な変数のそれぞれについて C を呼び出すのと似ています。 =item X [vars] X =begin original Same as C. =end original C と同じです。 =item y [level [vars]] X =begin original Display all (or some) lexical variables (mnemonic: C variables) in the current scope or I scopes higher. You can limit the variables that you see with I which works exactly as it does for the C and C commands. Requires the C module version 0.08 or higher; will warn if this isn't installed. Output is pretty-printed in the same style as for C and the format is controlled by the same options. =end original 現在のスコープや、I だけ高いスコープの全て(またはいくつか)の レキシカル変数を表示します(記憶法: C 変数)。 C や C コマンドと全く同じように、I を制定することで 表示される変数を制限できます。 バージョン 0.08 以降の C モジュールが必要です; もしインストールされていなければ警告されます。 出力は C コマンドと同じスタイルにフォーマットされ、 このフォーマットは同じオプションで制御されます。 =item T X X X =begin original Produce a stack backtrace. See below for details on its output. =end original スタックのバックトレースを行います。出力についての詳細は後述します。 =item s [expr] X X =begin original Single step. Executes until the beginning of another statement, descending into subroutine calls. If an expression is supplied that includes function calls, it too will be single-stepped. =end original シングルステップ実行します。 サブルーチンをたどりながら、別の実行文の先頭に到達するまで実行します。 関数呼び出しを含む式が与えられた場合、これもシングルステップ実行します。 =item n [expr] X =begin original Next. Executes over subroutine calls, until the beginning of the next statement. If an expression is supplied that includes function calls, those functions will be executed with stops before each statement. =end original ネクスト。次の実行文の先頭に到達するまで、サブルーチンにまたがって実行します。 関数呼び出しを含む式が与えられた場合、 各行毎に停止しながら関数を実行します。 =item r X =begin original Continue until the return from the current subroutine. Dump the return value if the C option is set (default). =end original 現在のサブルーチンから戻るまで実行します。 C がセットされていれば(デフォルトではセットされています) 返り値をダンプします。 =item =begin original Repeat last C or C command. =end original 最後の C または C を繰り返します。 =item c [line|sub] X =begin original Continue, optionally inserting a one-time-only breakpoint at the specified line or subroutine. =end original 続きを実行します; オプションとして、1 回限りのブレークポイントを指定された 行またはサブルーチンに設定します。 =item l X =begin original List next window of lines. =end original 次の 1 画面分をリスト表示します。 =item l min+incr =begin original List C lines starting at C. =end original C から C 行をリスト表示します。 =item l min-max =begin original List lines C through C. C is synonymous to C<->. =end original C 行から C 行をリスト表示します。 C は C<-> と同じです。 =item l line =begin original List a single line. =end original 指定行をリスト表示します。 =item l subname =begin original List first window of lines from subroutine. I may be a variable that contains a code reference. =end original サブルーチンの最初の一画面分をリスト表示します。 I は コードリファレンスが入った変数でも構いません。 =item - X =begin original List previous window of lines. =end original 前の 1 画面分をリスト表示します。 =item v [line] X =begin original View a few lines of code around the current line. =end original 指定行付近の(数行のコードをリスト表示します。 =item . X =begin original Return the internal debugger pointer to the line last executed, and print out that line. =end original 最後に実行した行への内部デバッガポインタを返し、 その行を表示します。 =item f filename X =begin original Switch to viewing a different file or C statement. If I is not a full pathname found in the values of %INC, it is considered a regex. =end original 異なるファイルまたは C 行に表示を切り替えます。 もし I が %INC にあるフルパス名でなければ、 正規表現として扱われます。 =begin original Ced strings (when accessible) are considered to be filenames: C and C access the body of the 7th Ced string (in the order of execution). The bodies of the currently executed C and of Ced strings that define subroutines are saved and thus accessible. =end original C した文字列は(アクセス可能なら)ファイル名として扱われます: C と C は (実行した順で) 7 番目に C した 文字列の中身にアクセスします。 現在実行した C の中身と、サブルーチンを定義する C した 中身は保存されるので、アクセス可能です。 =item /pattern/ =begin original Search forwards for pattern (a Perl regex); final / is optional. The search is case-insensitive by default. =end original pattern を用いて Perl 正規表現による前方検索を行います; 最後の / は なくてもかまいません。 デフォルトでは検索は大文字小文字を区別しません。 =item ?pattern? =begin original Search backwards for pattern; final ? is optional. The search is case-insensitive by default. =end original pattern を用いて後方検索を行います; 最後の ? はなくてもかまいません。 デフォルトでは検索は大文字小文字を区別しません。 =item L [abw] X =begin original List (default all) actions, breakpoints and watch expressions =end original ブレークポイント、アクション、ウォッチ式を (デフォルトは全て)リストアップします。 =item S [[!]regex] X =begin original List subroutine names [not] matching the regex. =end original regex に一致する(または一致しない)サブルーチン名をリストアップします。 =item t [n] X =begin original Toggle trace mode (see also the C option). Optional argument is the maximum number of levels to trace below the current one; anything deeper than that will be silent. =end original トレースモードの on/off を切り替えます (C オプションも 参照して下さい)。 オプションの引数は現在のもの以下でトレースする最大レベル数です; これよりも深いものは沈黙します。 =item t [n] expr X =begin original Trace through execution of C. Optional first argument is the maximum number of levels to trace below the current one; anything deeper than that will be silent. See L for examples. =end original C の実行をトレースします。 オプションの引数は現在のもの以下でトレースする最大レベル数です; これよりも深いものは沈黙します。 例については L を 参照して下さい。 =item b X X =begin original Sets breakpoint on current line =end original 現在の位置にブレークポイントを設定します。 =item b [line] [condition] X X =begin original Set a breakpoint before the given line. If a condition is specified, it's evaluated each time the statement is reached: a breakpoint is taken only if the condition is true. Breakpoints may only be set on lines that begin an executable statement. Conditions don't use C: =end original 与えられた行の直前にブレークポイントを設定します。 condition が指定されると、その文にさしかかる度に評価されます: condition が 真となったときにだけブレークポイントが働きます。 ブレークポイントは、実行可能な文で始まる行にだけ、設定できます。 condition には C を使いません: b 237 $x > 30 b 237 ++$count237 < 11 b 33 /pattern/i =begin original If the line number is C<.>, sets a breakpoint on the current line: =end original 行番号が C<.> なら、現在行にブレークポイントを設定します: b . $n > 100 =item b [file]:[line] [condition] X X =begin original Set a breakpoint before the given line in a (possibly different) file. If a condition is specified, it's evaluated each time the statement is reached: a breakpoint is taken only if the condition is true. Breakpoints may only be set on lines that begin an executable statement. Conditions don't use C: =end original ブレークポイントを(おそらくは異なった)ファイルの指定された行に設定します。 condition が指定されると、その文にさしかかる度に評価されます: condition が 真となったときにだけブレークポイントが働きます。 ブレークポイントは、実行可能な文で始まる行にだけ、設定できます。 condition には C を使いません: b lib/MyModule.pm:237 $x > 30 b /usr/lib/perl5/site_perl/CGI.pm:100 ++$count100 < 11 =item b subname [condition] X X =begin original Set a breakpoint before the first line of the named subroutine. I may be a variable containing a code reference (in this case I is not supported). =end original サブルーチンの最初の実行可能文にブレークポイントを設定します。 I は コードリファレンスが入った変数でも構いません (この場合は I は非対応です)。 =item b postpone subname [condition] X X =begin original Set a breakpoint at first line of subroutine after it is compiled. =end original コンパイル後、サブルーチンの最初の行にブレークポイントをセットします。 =item b load filename X X =begin original Set a breakpoint before the first executed line of the I, which should be a full pathname found amongst the %INC values. =end original I の最初に実行される行の手前にブレークポイントをセットします; これは %INC の値に含まれるフルパス名であるべきです。 =item b compile subname X X =begin original Sets a breakpoint before the first statement executed after the specified subroutine is compiled. =end original 指定されたサブルーチンがコンパイルされた後、最初に実行される文の手前に ブレークポイントをセットします。 =item B line X X =begin original Delete a breakpoint from the specified I. =end original I で指定されたブレークポイントを削除します。 =item B * X X =begin original Delete all installed breakpoints. =end original すべてのブレークポイントを削除します。 =item disable [file]:[line] X X X =begin original Disable the breakpoint so it won't stop the execution of the program. Breakpoints are enabled by default and can be re-enabled using the C command. =end original ブレークポイントを向こうにして、プログラムの実行を止めないようにします。 ブレークポイントはデフォルトで有効で、C コマンドを使って 再有効化できます。 =item disable [line] X X X =begin original Disable the breakpoint so it won't stop the execution of the program. Breakpoints are enabled by default and can be re-enabled using the C command. =end original ブレークポイントを向こうにして、プログラムの実行を止めないようにします。 ブレークポイントはデフォルトで有効で、C コマンドを使って 再有効化できます。 =begin original This is done for a breakpoint in the current file. =end original これは現在のファイルのブレークポイントに対して行われます。 =item enable [file]:[line] X X X =begin original Enable the breakpoint so it will stop the execution of the program. =end original ブレークポイントを有効にして、プログラムの実行を止めるようにします。 =item enable [line] X X X =begin original Enable the breakpoint so it will stop the execution of the program. =end original ブレークポイントを有効にして、プログラムの実行を止めるようにします。 =begin original This is done for a breakpoint in the current file. =end original これは現在のファイルのブレークポイントに対して行われます。 =item a [line] command X =begin original Set an action to be done before the line is executed. If I is omitted, set an action on the line about to be executed. The sequence of steps taken by the debugger is =end original その行を実行する前に行うアクションを設定します。 I が省略されると、いままさに実行しようとしていた行に アクションを設定します。 デバッガが実行する処理の順番は以下の通りです。 =begin original 1. check for a breakpoint at this line 2. print the line if necessary (tracing) 3. do any actions associated with that line 4. prompt user if at a breakpoint or in single-step 5. evaluate line =end original 1. この行のブレークポイントをチェックします 2. 必要なら行を表示します(トレース) 3. この行に結び付けられたアクションを実行します 4. ブレークポイントやシングルステップの場合はユーザーに確認します 5. 行を評価します =begin original For example, this will print out $foo every time line 53 is passed: =end original 例えば、以下のコードは 53 行を通過する毎に $foo を表示します。 a 53 print "DB FOUND $foo\n" =item A line X =begin original Delete an action from the specified line. =end original 指定された行に設定されたアクションを削除します。 =item A * X =begin original Delete all installed actions. =end original 設定されたすべてのアクションを削除します。 =item w expr X =begin original Add a global watch-expression. Whenever a watched global changes the debugger will stop and display the old and new values. =end original グローバルなウォッチ式を追加します。 グローバルな変更が行われたときは、デバッガは停止して新旧の値を表示します。 =item W expr X =begin original Delete watch-expression =end original ウォッチ式を削除します。 =item W * X =begin original Delete all watch-expressions. =end original 全てのウォッチ式を削除します。 =item o X =begin original Display all options. =end original 全てのオプションを表示します。 =item o booloption ... X =begin original Set each listed Boolean option to the value C<1>. =end original リストされた各真偽値オプションの値を C<1> に設定します。 =item o anyoption? ... X =begin original Print out the value of one or more options. =end original 1 つ、あるいは複数のオプションの値を表示します。 =item o option=value ... X =begin original Set the value of one or more options. If the value has internal whitespace, it should be quoted. For example, you could set C to call B with those specific options. You may use either single or double quotes, but if you do, you must escape any embedded instances of same sort of quote you began with, as well as any escaping any escapes that immediately precede that quote but which are not meant to escape the quote itself. In other words, you follow single-quoting rules irrespective of the quote; eg: C or C. =end original 一つまたは複数のオプションをセットします。 値自身に空白を含む場合、クォートする必要があります。 例えば、B をオプション付きで呼び出す場合は C のようにします。 シングルクォートとダブルクォートのどちらでも使えますが、クォートする場合は、 クォート文字と同じ文字はエスケープする必要があります; そしてエスケープ文字自身もエスケープして、クォート文字を エスケープしているのではないことを示す必要があります。 言い換えると、クォートに関わりなく、シングルクォートルールに従います; 例えば: C や C =begin original For historical reasons, the C<=value> is optional, but defaults to 1 only where it is safe to do so--that is, mostly for Boolean options. It is always better to assign a specific value using C<=>. The C