ライブラリクレートのビルドとデバッグ
標準ライブラリは同じビルドシステムでビルドされるため、rustc-dev-guide の手順のほとんどは 標準ライブラリにも適用されます。そのため、先に読むことをおすすめします。
alloc と core の println デバッグ
alloc と core ではロギングや IO API が利用できないため、コンパイラの他の部分向けのアドバイスは
ここでは適用できません。
代わりに、テストすべきコードを通常のクレートに抽出してそこでデバッグ文を追加するか、 POSIX システムでは次のハックを使用できます。
#![allow(unused)]
fn main() {
extern "C" {
fn dprintf(fd: i32, s: *const u8, ...);
}
macro_rules! dbg_printf {
($s:expr) => {
unsafe { dprintf(2, "%s\0".as_ptr(), $s as *const u8); }
}
}
fn function_to_debug() {
let dbg_str = format!("debug: {}\n\0", "hello world");
dbg_printf!(dbg_str.as_bytes().as_ptr());
}
}
その後、デバッグ対象のコードを実行するテストを実行し、次のようにしてエラー出力を表示できます。
./x.py test library/alloc --test-args <test_name> --test-args --nocapture