solana documentaiton-developing-Debugging

Solana programs run on-chain, so debugging them in the wild can be challenging. To make debugging programs easier, developers can write unit tests that directly test their program's execution via the Solana runtime, or run a local cluster that will allow RPC clients to interact with their program.
ソラナプログラムはオンチェーンで実行されるため、実際にデバッグを行うのが困難な場合があります。プログラムのデバッグを容易にするために、開発者はソラナランタイムを介してプログラムの実行を直接テストするユニットテストを書いたり、RPCクライアントがプログラムと対話できるようにするローカルクラスタを実行することができます。

Running unit tests(ユニットテストを走らせよう)

Testing with Rust
Testing with C

Logging(ログ)

During program execution both the runtime and the program log status and error messages.
プログラムの実行中、ランタイムとプログラムの両方がステータスとエラーメッセージをログに記録します。

For information about how to log from a program see the language specific documentation:
プログラムからのログのとり方については、下記の言語別ドキュメントを参照してください。

Logging from a Rust program
Logging from a C program

When running a local cluster the logs are written to stdout as long as they are enabled via the RUST_LOG log mask. From the perspective of program development it is helpful to focus on just the runtime and program logs and not the rest of the cluster logs. To focus in on program specific information the following log mask is recommended:
ローカルクラスタを実行している場合、"RUST_LOG"ログマスクで有効にしている限り、ログは標準出力に書き込まれます。プロ恨む開発の観点からは、ランタイムとプログラムのログだけに注目し、残りのクラスタログには注目しないことが有用です。プログラム固有の情報に焦点を当てるには、以下のログマスクが推奨されます。

export RUST_LOG=solana_runtime::system_instruction_processor=trace,solana_runtime::message_processor=info,solana_bpf_loader=debug,solana_rbpf=debug

Log messages coming directly from the program (not the runtime) will be displayed in the form:
(ランタイムではなく)プログラムから直接送られてくるメッセージは、フォームに表示されます。

Program log: <user defined message>

Error Handling(エラー処理)

The amount of information that can be communicated via a transaction error is limited but there are many points of possible failures. The following are possible failure points and information about what errors to expect and where to get more information:
トランザクションエラーで伝えられる情報量は限られていますが、失敗する可能性のあるポイントはたくさんあります。以下に、想定される失敗点と、どのようなエラーが発生するのか、またどこで情報を得ることが出来すのかを示します。

・The BPF loader may fail to parse the program, this should not happen since the loader has already finalized the program's account data.
InstructionError::InvalidAccountData will be returned as part of the transaction error.
The BPF loader may fail to setup the program's execution environment
BPFローダがプログラムの解析に失敗する可能性がありますが、ローダは既にプログラムのアカウントデータを確定しているため、このようなことは起こらないと思います。"InstructionError::InvalidAccountData"がトランザクションエラーの一部として返されます。
BPFローダはプログラムの実行環境のセットアップに失敗することがあります。

○InstructionError::Custom(0x0b9f_0001) will be returned as part of the transaction error. "0x0b9f_0001" is the hexadecimal representation of VirtualMachineCreationFailed.
トランザクションのエラーとして、"InstructionError::Custom(0x0b9f_0001)"が返されます。"0x0b9f_000"は、"VirtualMachineCreationFailed"の16進数表現です。

・The BPF loader may have detected a fatal error during program executions (things like panics, memory violations, system call errors, etc...)
プログラム実行中にBPFローダが致命的なエラーを検出した可能性があります。(パニック、メモリ違反、システムコールエラーなど)

○InstructionError::Custom(0x0b9f_0002) will be returned as part of the transaction error. "0x0b9f_0002" is the hexadecimal representation of VirtualMachineFailedToRunProgram.
トランザクションのエラーの一部として、"InstructionError::Custom(0x0b9f_0002)"が返されます。"0x0b9f_0002"は、"VirtualMachineFailedToRunProgram"の16進数表現です。

・The program itself may return an error
プログラム自体がエラーを帰す場合があります。

○InstructionError::Custom(<user defined value>) will be returned. The "user defined value" must not conflict with any of the builtin runtime program errors. Programs typically use enumeration types to define error codes starting at zero so they won't conflict.
In the case of VirtualMachineFailedToRunProgram errors, more information about the specifics of what failed are written to the program's execution logs.
"InstructionError::Custom(<user defined value>)"が返されます。ユーザー定義値は、組み込みのランタイムプログラムエラーと競合してはいけません。プログラムは通常、列挙型を使用して、ゼロから始まるエラーコードを定義し、競合しないようにします。この場合は、"ユーザー定義値"が返されますが、「ユーザー定義値」が返されない場合は、"ユーザー定義値"が返されます。

For example, an access violation involving the stack will look something like this:
例えば、スタックを含むアクセス違反は次のようになります。

BPF program 4uQeVj5tqViQh7yWWGStvkEG1Zmhx6uasJtWCJziofM failed: out of bounds memory store (insn #615 ), addr 0x200001e38/8

Monitoring Compute Budget Consumption
予算消費量の計算のモニタリング

The program can log the remaining number of compute units it will be allowed before program execution is halted. Programs can use these logs to wrap operations they wish to profile.
プログラムは、プログラムの実行を停止する前に許可される計算単位の残りの数をログに記録することが出来ます。プログラムは、これらのログを使用して、プロファイリングしたい操作をラップすることが出来ます。

Log the remaining compute units from a Rust program
Log the remaining compute units from a C program

See compute budget for more information.
詳細は"compute budget "を参照してください。

ELF Dump(ELFダンプ)

The BPF shared object internals can be dumped to a text file to gain more insight into a program's composition and what it may be doing at runtime.
BPFの共有オブジェクト内部をテキストファイルにダンプすることで、プログラムの構成や実行時に何をしているのかをより深く知ることができます。

Create a dump file of a Rust program
Create a dump file of a C program

Instruction Tracing(インストラクショントレース)

During execution the runtime BPF interpreter can be configured to log a trace message for each BPF instruction executed. This can be very helpful for things like pin-pointing the runtime context leading up to a memory access violation.
実行中、ランタイムBPFインタプリタは、BPF命令の実行ごとにトレースメッセージをログに記録するように設定することが出来ます。これは、メモリアクセス違反に至るまでのランタイム文脈をピンポイントで特定するなど、非常に有用です。

The trace logs together with the ELF dump can provide a lot of insight (though the traces produce a lot of information).
ELFダンプと一緒にトレースログから多くの情報を得ることが出来ます。(ただし、トレースは多くの情報を生成します)

To turn on BPF interpreter trace messages in a local cluster configure the solana_rbpf level in RUST_LOG to trace. For example:
ローカルクラスタでBPFインタプリタのトレースメッセージを有効にするには、"RUST_LOG "の" solana_rbpf"レベルを"trace"に設定します。例えば以下のようになります。

export RUST_LOG=solana_rbpf=trace

この記事が気に入ったらサポートをしてみませんか?