rustでデバッグ
rust-lldb
例えばopen_fileというプログラムを作っていたら、rust-lldbが使える。
rust-lldb ./target/debug/open_file
コマンド入力待ちになるのでここでコマンドを打つ。
(lldb) command source -s 0 '/tmp/rust-lldb-commands.ezgyPg' Executing commands in '/tmp/rust-lldb-commands.ezgyPg'. (lldb) command script import "/Users/byoma/.multirust/toolchains/stable-x86_64-apple-darwin/lib/rustlib/etc/lldb_rust_formatters.py" (lldb) type summary add --no-value --python-function lldb_rust_formatters.print_val -x ".*" --category Rust (lldb) type category enable Rust (lldb) target create "./target/debug/open_file" Current executable set to './target/debug/open_file' (x86_64). (lldb)
help
コマンドでコマンドのリストなど使い方が分かる。
breakpointを張る
関数名でbreakpoitを張れる
(lldb) breakpoint set --name read_file
breakpointまで実行
(lldb) run
stepでいわゆるstep in nextでstep overになる
変数の中身を確認
frameコマンドで現在のthreadに対してコマンドが実行出来るっぽい。 frameはfrで略せる。
(lldb) fr v path
これでpathの変数になにが入っているか分かる。
というわけで
これで簡単なdebugは出来そう。あとはprintln!
などで単純に出力するのもよさそう。
よくわからないこと
- lldbがどんな仕組みか分からない