雑なメモ書き

気楽にいきます

rustでlldbを使用してdebug時にsourceを表示する

通常のケース

  • sourceがstep inしても出ない
(lldb) l
   1       fn main() {
   2           println!("Hello, world!");
   3       }
(lldb) b 1
Breakpoint 1: where = hello`hello::main::h339d18d0cfd709be + 16 at main.rs:2, address = 0x0000000000004150
(lldb) run
Process 30247 launched: './target/debug/hello' (x86_64)
Process 30247 stopped
* thread #1, name = 'hello', stop reason = breakpoint 1.1
    frame #0: 0x0000555555558150 hello`hello::main::h339d18d0cfd709be at main.rs:2
   1      fn main() {
-> 2         println!("Hello, world!");
   3      }
(lldb) s
Process 30247 stopped
* thread #1, name = 'hello', stop reason = step in
    frame #0: 0x000055555555802a hello`core::fmt::Arguments::new_v1::h25473df8595fb893(pieces=&["Hello, world!
"], args=&[]) at mod.rs:317
(lldb) s
Process 30247 stopped
* thread #1, name = 'hello', stop reason = step in
    frame #0: 0x0000555555558033 hello`core::fmt::Arguments::new_v1::h25473df8595fb893(pieces=&["Hello, world!
"], args=&[]) at mod.rs:318
(lldb) 

前回と同じでlldbを起動時にデータを渡せば問題はない

#!/bin/sh

TARGET_PATH=$1
DEBUG_SRC=`strings $TARGET_PATH  | grep -o '^/rustc/[^/]\+/' | uniq`
TMPLLDBINIT=`mktemp -d`
echo "settings set target.source-map $DEBUG_SRC $HOME/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/" >> $TMPLLDBINIT/.lldbinit
rust-lldb -s $TMPLLDBINIT/.lldbinit $TARGET_PATH

このようにstepinできる

* thread #1, name = 'hello', stop reason = breakpoint 1.1
    frame #0: 0x0000555555558150 hello`hello::main::h339d18d0cfd709be at main.rs:2
   1       fn main() {
-> 2          println!("Hello, world!");
   3       }
(lldb) s
Process 30094 stopped
* thread #1, name = 'hello', stop reason = step in
    frame #0: 0x000055555555802a hello`core::fmt::Arguments::new_v1::h25473df8595fb893(pieces=&["Hello, world!
"], args=&[]) at mod.rs:317
   314        pub fn new_v1(pieces: &'a [&'a str],
   315                      args: &'a [ArgumentV1<'a>]) -> Arguments<'a> {
   316            Arguments {
-> 317                 pieces,
   318                fmt: None,
   319                args,
   320            }