Xdebug を使用すると、パラメータや戻り値を含むすべての関数呼び出しをさまざまな形式のファイルに記録できます。
これらのいわゆる「関数トレース」機能は、新しいアプリケーションに直面したり、プログラムが実行中に何をしているかを把握したい場合に役立ちます。関数トレースでは、戻り値だけでなく、関数またはメソッドによって渡された変数の値もオプションで表示できます。これら 2 つの要素の追跡は、デフォルトでは有効になっていません。
出力形式
出力形式は 3 つあります。 1 つは人間が読める追跡情報を持ち、もう 1 つはコンピューター プログラムによる解析に適しており、最後は HTML を使用して追跡情報をフォーマットします。 xdebug_trace_format 設定を使用すると、これら 2 つの不適切な形式を切り替えることができます。トレース ファイルに書き込む情報を制御する設定もあります。たとえば、変数 (xdebug.collect_params) と戻り値 (xdebug.collect_return) を設定します。次の例は、人間が判読できる関数トレース情報のさまざまな設定の影響を示しています。
スクリプト<span style="color: #000000;">php </span><span style="color: #800080;">$str</span> = "Xdebug"<span style="color: #000000;">; </span><span style="color: #0000ff;">function</span> ret_ord( <span style="color: #800080;">$c</span><span style="color: #000000;"> ) { </span><span style="color: #0000ff;">return</span> <span style="color: #008080;">ord</span>( <span style="color: #800080;">$c</span><span style="color: #000000;"> ); } </span><span style="color: #0000ff;">foreach</span> ( <span style="color: #008080;">str_split</span>( <span style="color: #800080;">$str</span> ) <span style="color: #0000ff;">as</span> <span style="color: #800080;">$char</span><span style="color: #000000;"> ) { </span><span style="color: #0000ff;">echo</span> <span style="color: #800080;">$char</span>, ": ", ret_ord( <span style="color: #800080;">$char</span> ), "\n"<span style="color: #000000;">; } </span>?>
The Results
以下由xdebug.collect_params设置不同值时的结果。当不在web环境下,2值不包含鼠标提示。
默认值:
TRACE START [2007-05-06 14:37:06]
0.0003 114112 -> {main}() ../trace.php:0
0.0004 114272 -> str_split() ../trace.php:8
0.0153 117424 -> ret_ord() ../trace.php:10
0.0165 117584 -> ord() ../trace.php:5
0.0166 117584 -> ret_ord() ../trace.php:10
0.0167 117584 -> ord() ../trace.php:5
0.0168 117584 -> ret_ord() ../trace.php:10
0.0168 117584 -> ord() ../trace.php:5
0.0170 117584 -> ret_ord() ../trace.php:10
0.0170 117584 -> ord() ../trace.php:5
0.0172 117584 -> ret_ord() ../trace.php:10
0.0172 117584 -> ord() ../trace.php:5
0.0173 117584 -> ret_ord() ../trace.php:10
0.0174 117584 -> ord() ../trace.php:5
0.0177 41152
TRACE END [2007-05-06 14:37:07]
Collect_params=1:
TRACE START [2007-05-06 14:37:11]
0.0003 114112 -> {main}() ../trace.php:0
0.0004 114272 -> str_split(string(6)) ../trace.php:8
0.0007 117424 -> ret_ord(string(1)) ../trace.php:10
0.0007 117584 -> ord(string(1)) ../trace.php:5
0.0009 117584 -> ret_ord(string(1)) ../trace.php:10
0.0009 117584 -> ord(string(1)) ../trace.php:5
0.0010 117584 -> ret_ord(string(1)) ../trace.php:10
0.0011 117584 -> ord(string(1)) ../trace.php:5
0.0012 117584 -> ret_ord(string(1)) ../trace.php:10
0.0013 117584 -> ord(string(1)) ../trace.php:5
0.0014 117584 -> ret_ord(string(1)) ../trace.php:10
0.0014 117584 -> ord(string(1)) ../trace.php:5
0.0016 117584 -> ret_ord(string(1)) ../trace.php:10
0.0016 117584 -> ord(string(1)) ../trace.php:5
0.0019 41152
TRACE END [2007-05-06 14:37:11]
Collect_params=3:
TRACE START [2007-05-06 14:37:13]
0.0003 114112 -> {main}() ../trace.php:0
0.0004 114272 -> str_split('Xdebug') ../trace.php:8
0.0007 117424 -> ret_ord('X') ../trace.php:10
0.0007 117584 -> ord('X') ../trace.php:5
0.0009 117584 -> ret_ord('d') ../trace.php:10
0.0009 117584 -> ord('d') ../trace.php:5
0.0010 117584 -> ret_ord('e') ../trace.php:10
0.0011 117584 -> ord('e') ../trace.php:5
0.0012 117584 -> ret_ord('b') ../trace.php:10
0.0013 117584 -> ord('b') ../trace.php:5
0.0014 117584 -> ret_ord('u') ../trace.php:10
0.0014 117584 -> ord('u') ../trace.php:5
0.0016 117584 -> ret_ord('g') ../trace.php:10
0.0016 117584 -> ord('g') ../trace.php:5
0.0019 41152
TRACE END [2007-05-06 14:37:13]
Collect_params=4:
TRACE START [2007-05-06 14:37:16]
0.0003 114112 -> {main}() ../trace.php:0
0.0004 114272 -> str_split('Xdebug') ../trace.php:8
0.0007 117424 -> ret_ord($c = 'X') ../trace.php:10
0.0007 117584 -> ord('X') ../trace.php:5
0.0009 117584 -> ret_ord($c = 'd') ../trace.php:10
0.0009 117584 -> ord('d') ../trace.php:5
0.0010 117584 -> ret_ord($c = 'e') ../trace.php:10
0.0011 117584 -> ord('e') ../trace.php:5
0.0012 117584 -> ret_ord($c = 'b') ../trace.php:10
0.0013 117584 -> ord('b') ../trace.php:5
0.0014 117584 -> ret_ord($c = 'u') ../trace.php:10
0.0014 117584 -> ord('u') ../trace.php:5
0.0016 117584 -> ret_ord($c = 'g') ../trace.php:10
0.0016 117584 -> ord('g') ../trace.php:5
0.0019 41152
TRACE END [2007-05-06 14:37:16]
除了xdebug.collet_params设置还有另一些设置影响跟踪文件的输出效果。“show_mem_delta=1”可以显示内存使用量在两个不同列中。
TRACE START [2007-05-06 14:37:26]
0.0003 114112 +114112 -> {main}() ../trace.php:0
0.0004 114272 +160 -> str_split('Xdebug') ../trace.php:8
0.0007 117424 +3152 -> ret_ord($c = 'X') ../trace.php:10
0.0007 117584 +160 -> ord('X') ../trace.php:5
0.0009 117584 +0 -> ret_ord($c = 'd') ../trace.php:10
0.0009 117584 +0 -> ord('d') ../trace.php:5
0.0011 117584 +0 -> ret_ord($c = 'e') ../trace.php:10
0.0011 117584 +0 -> ord('e') ../trace.php:5
0.0013 117584 +0 -> ret_ord($c = 'b') ../trace.php:10
0.0013 117584 +0 -> ord('b') ../trace.php:5
0.0014 117584 +0 -> ret_ord($c = 'u') ../trace.php:10
0.0015 117584 +0 -> ord('u') ../trace.php:5
0.0016 117584 +0 -> ret_ord($c = 'g') ../trace.php:10
0.0017 117584 +0 -> ord('g') ../trace.php:5
0.0019 41152
TRACE END [2007-05-06 14:37:26]
“collect_return=1”显示被调用函数的返回值:
TRACE START [2007-05-06 14:37:35]
0.0003 114112 -> {main}() ../trace.php:0
0.0004 114272 -> str_split('Xdebug') ../trace.php:8
>=> array (0 => 'X', 1 => 'd', 2 => 'e', 3 => 'b', 4 => 'u', 5 => 'g')
0.0007 117424 -> ret_ord($c = 'X') ../trace.php:10
0.0007 117584 -> ord('X') ../trace.php:5
>=> 88
>=> 88
0.0009 117584 -> ret_ord($c = 'd') ../trace.php:10
0.0009 117584 -> ord('d') ../trace.php:5
>=> 100
>=> 100
0.0011 117584 -> ret_ord($c = 'e') ../trace.php:10
0.0011 117584 -> ord('e') ../trace.php:5
>=> 101
>=> 101
0.0013 117584 -> ret_ord($c = 'b') ../trace.php:10
0.0013 117584 -> ord('b') ../trace.php:5
>=> 98
>=> 98
0.0015 117584 -> ret_ord($c = 'u') ../trace.php:10
0.0016 117584 -> ord('u') ../trace.php:5
>=> 117
>=> 117
0.0017 117584 -> ret_ord($c = 'g') ../trace.php:10
0.0018 117584 -> ord('g') ../trace.php:5
>=> 103
>=> 103
>=> 1
0.0021 41152
TRACE END [2007-05-06 14:37:35]
“collect_assignments=1”显示变量赋予,详见xdebug.collect_assignments设置。
“xdebug.trace_format”设置改变输出格式让解析更容易但反而让人更难理解。这对于用第三方工具解析跟踪文件最有用处。
Version: 2.0.0RC4-dev
TRACE START [2007-05-06 18:29:01]
1 0 0 0.010870 114112 {main} 1 ../trace.php 0
2 1 0 0.032009 114272 str_split 0 ../trace.php 8
2 1 1 0.032073 116632
2 2 0 0.033505 117424 ret_ord 1 ../trace.php 10
3 3 0 0.033531 117584 ord 0 ../trace.php 5
3 3 1 0.033551 117584
2 2 1 0.033567 117584
2 4 0 0.033718 117584 ret_ord 1 ../trace.php 10
3 5 0 0.033740 117584 ord 0 ../trace.php 5
3 5 1 0.033758 117584
2 4 1 0.033770 117584
2 6 0 0.033914 117584 ret_ord 1 ../trace.php 10
3 7 0 0.033936 117584 ord 0 ../trace.php 5
3 7 1 0.033953 117584
2 6 1 0.033965 117584
2 8 0 0.034108 117584 ret_ord 1 ../trace.php 10
3 9 0 0.034130 117584 ord 0 ../trace.php 5
3 9 1 0.034147 117584
2 8 1 0.034160 117584
2 10 0 0.034302 117584 ret_ord 1 ../trace.php 10
3 11 0 0.034325 117584 ord 0 ../trace.php 5
3 11 1 0.034342 117584
2 10 1 0.034354 117584
2 12 0 0.034497 117584 ret_ord 1 ../trace.php 10
3 13 0 0.034519 117584 ord 0 ../trace.php 5
3 13 1 0.034536 117584
2 12 1 0.034549 117584
1 0 1 0.034636 117584
TRACE END [2007-05-06 18:29:01]
VIM 语法文件
Xdebug 携带一个VIM语法文件能对跟踪文件的语法提亮,该语法文件名:xt.vim。 为了使VIM识别新格式,你需这么做:
- 复制xt.vim文件到 ~/.vim/syntax
- 编辑或创建 ~/.vim/filetype.vim 文件,并添加以下代码:
augroup filetypedetect
au BufNewFile,BufRead *.xt setf xt
augroup END
做完这些后,打开的跟踪文件就会类似这样:
<strong>TRACE START</strong> <strong>[2007-05-15 20:06:02]</strong>
0.0003 115208 <strong>-></strong> <strong>{main}()</strong> ../trace.php<strong>:0</strong>
0.0004 115368 <strong>-></strong> <strong>str_split() </strong>../trace.php<strong>:8</strong>
0.0006 118520 <strong>-></strong> <strong>ret_ord() </strong>../trace.php<strong>:10</strong>
0.0007 118680 <strong>-></strong> <strong>ord() </strong>../trace.php<strong>:5</strong>
0.0008 118680 <strong>-></strong> <strong>ret_ord() </strong>../trace.php<strong>:10</strong>
0.0009 118680 <strong>-></strong> <strong>ord() </strong>../trace.php<strong>:5</strong>
0.0010 118680 <strong>-></strong> <strong>ret_ord() </strong>../trace.php<strong>:10</strong>
0.0010 118680 <strong>-></strong> <strong>ord() </strong>../trace.php<strong>:5</strong>
0.0012 118680 <strong>-></strong> <strong>ret_ord() </strong>../trace.php<strong>:10</strong>
0.0012 118680 <strong>-></strong> <strong>ord() </strong>../trace.php<strong>:5</strong>
0.0014 118680 <strong>-></strong> <strong>ret_ord() </strong>../trace.php<strong>:10</strong>
0.0014 118680 <strong>-></strong> <strong>ord() </strong>../trace.php<strong>:5</strong>
0.0016 118680 <strong>-></strong> <strong>ret_ord() </strong>../trace.php<strong>:10</strong>
0.0016 118680 <strong>-></strong> <strong>ord() </strong>../trace.php<strong>:5</strong>
0.0019 54880
<strong>TRACE END</strong> <strong>[2007-05-15 20:06:02]<br></strong>
相关设置:
xdebug.auto_trace
类型: boolean, 默认值: 0
打开此设置时,脚本在运行前函数调用追踪将开启。这将可能追踪auto_prepend_file设置的代码文件。
xdebug.collect_assignments
类型: boolean, 默认值: 0, 始于 Xdebug > 2.1
用于控制xdebug是否添加变量赋予到函数追踪当中。
xdebug.collect_includes
类型: boolean, 默认值: 1
include()、include_once()、require()、または require_once() によって参照されるファイル名を xdebug がトレース ファイルに書き込むかどうかを制御するために使用されます。
xdebug.collect_params
タイプ: 整数、デフォルト値: 0
デフォルトが 0 の場合、この設定は、関数トレースまたはスタック トレースに関係なく、呼び出し関数のパラメーターを収集するように xdebug を制御します。
デフォルト値の 0 は、大規模なスクリプトが大量のメモリを消費することを考慮して、大規模なスクリプトに対しては実行されません。この設定を安全にオンにすることができますが、多数の関数呼び出しや引数として渡される大規模なデータ構造など、スクリプトの問題が発生することが予想されます。 Xdebug2 はメモリには保存せず、ディスクにのみ保存するため、メモリ使用量の増加という問題は発生しません。これには、十分なディスク使用量が必要です。
この設定には 4 つの設定値があります。それぞれが異なる情報を提示します。次の表に、さまざまな設定値の情報を示します。
|
表示される引数情報
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
0 |
なし。 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1
|
変数要素の値の型と値を表示します。 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2 |
変数要素の値のタイプと値を表示し、マウス プロンプトに完全な情報が表示されます。 (マウスプロンプトは CLI モードには存在しません) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3
|
変数の完全な内容 (内容は次の設定によって制限されます: xdebug.var_display_max_children、xdebug.var_display_max_data、および xdebug.var_display_max_ Depth。)
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4 |
変数の完全な内容と名前。 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5
|
PHP は変数の内容を名前なしでシリアル化します。 (2.3 バージョンの新機能) |
值 |
描述 |
0 |
显示人类可读性排版式文件:时间点,内存量,内存增量(如果xdebug.show_mem_delta 开启), 层级, 函数名, 函数参数 (如果 xdebug.collect_params 开启),文件名和行号。 |
1 |
用两种不同记录编写记算机可读格式文件。其记录不同在于一个插入堆栈边框,一个移除堆栈边框。以下表格列出记录中每个栏位区别。 |
2 |
使用HTML写成跟踪文件。 |
値 |
説明 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
0 |
人間が読める形式のファイルを表示: 時点、メモリ量、メモリ デルタ (xdebug.show_mem_delta がオンの場合)、レベル、関数名、関数パラメータ (xdebug.collect_params がオンの場合)、ファイル名および行番号。 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1 |
2 つの異なるレコードを使用して、コンピューター可読形式のファイルを作成します。レコードの違いは、一方はスタック境界を挿入し、もう一方はスタック境界を削除することです。次の表に、レコード内の各フィールドの違いを示します。 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2 |
HTML を使用して追跡ファイルを作成します。 |
レコードの種類
|
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 - ... |
||||||||||||||||||||||||||||||||||||||||||||||||||||
エントリー |
レベル | 関数# | 常に '0' | タイムインデックス | メモリ使用量 | 関数名 | ユーザー定義 (1) または内部関数 (0) | インクルード/必須ファイルの名前 | ファイル名 | 行番号 | いいえ。パラメータ | パラメータ (フィールド 11 で指定した数) - タブ区切り | ||||||||||||||||||||||||||||||||||||||||||||||||||||
終了 |
レベル | 関数# | 常に「1」 | タイムインデックス | メモリ使用量 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
戻る |
レベル | 関数# | 常に「R」 | 戻り値 |
|
意味 |
形式の例 |
ファイルの例 |
||||||||||||||||||||||||||||||||||||||||||||||||
%c |
現在の作業パスの Crc32 検証値 | トレース.%c | trace.1258863198.xt | ||||||||||||||||||||||||||||||||||||||||||||||||
%p |
プロセス識別子 | トレース.%p | trace.5174.xt | ||||||||||||||||||||||||||||||||||||||||||||||||
%r |
乱数 | トレース.%r | trace.072db0.xt | ||||||||||||||||||||||||||||||||||||||||||||||||
%s |
スクリプト名 2 | cachegrind.out.%s | cachegrind.out._home_httpd_html_test_xdebug_test_php | ||||||||||||||||||||||||||||||||||||||||||||||||
%t |
制限時間 (秒) | トレース.%t | trace.1179434742.xt | ||||||||||||||||||||||||||||||||||||||||||||||||
%u |
タイムカットオフ (マイクロ秒) | トレース.%u | trace.1179434749_642382.xt | ||||||||||||||||||||||||||||||||||||||||||||||||
%H |
$_SERVER['HTTP_HOST'] | トレース.%H | trace.kossu.xt | ||||||||||||||||||||||||||||||||||||||||||||||||
%R |
$_SERVER['REQUEST_URI'] | トレース.%R | trace._test_xdebug_test_php_var=1_var2=2.xt | ||||||||||||||||||||||||||||||||||||||||||||||||
%U |
$_SERVER['UNIQUE_ID'] 3 | トレース.%U | トレース.TRX4n38AAAEAAB9gBFkAAAAB.xt | ||||||||||||||||||||||||||||||||||||||||||||||||
%S |
session_id (ソース $_COOKIE、設定されている場合) | トレース.%S | trace.c70c1ec2375af58f74b390bbdd2a679d.xt | ||||||||||||||||||||||||||||||||||||||||||||||||
%% |
リテラル % | トレース.%% | トレース.%%.xt |

ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

AI Hentai Generator
AIヘンタイを無料で生成します。

人気の記事

ホットツール

ZendStudio 13.5.1 Mac
強力な PHP 統合開発環境

ゼンドスタジオ 13.0.1
強力な PHP 統合開発環境

EditPlus 中国語クラック版
サイズが小さく、構文の強調表示、コード プロンプト機能はサポートされていません

Safe Exam Browser
Safe Exam Browser は、オンライン試験を安全に受験するための安全なブラウザ環境です。このソフトウェアは、あらゆるコンピュータを安全なワークステーションに変えます。あらゆるユーティリティへのアクセスを制御し、学生が無許可のリソースを使用するのを防ぎます。

ドリームウィーバー CS6
ビジュアル Web 開発ツール
