yhara.jp

Recent Posts

LLDBチートシート

Tech

起動

lldb ./a.out

-oを付けると起動と同時にコマンドを打てる

lldb -o run -o bt a.sk.out

バックトレースを表示する

(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
  * frame #0: 0x000000010016cb64 a.debug.out`user_main + 152
    frame #1: 0x000000010016cbd4 a.debug.out`main + 16
    frame #2: 0x000000010044908c dyld`start + 520

現在のフレームのアセンブリを表示する

(lldb) di
a.debug.out`user_main:           
    0x10016cacc <+0>:   sub    sp, sp, #0x60             ; =0x60 
    0x10016cad0 <+4>:   stp    x29, x30, [sp, #0x50]
    0x10016cad4 <+8>:   mov    w8, #0x8                         
...

レジスタの値を見る

(lldb) register read  または、re r
General Purpose Registers:
       rax = 0x00000001004711b0
       rbx = 0x0000000000000000
       rcx = 0x0000000100472e40
       rdx = 0x0000000100475ba0
       rdi = 0x000000000000000f
       rsi = 0x00000001004711b0
       rbp = 0x00007ffeefbfeee0
       rsp = 0x00007ffeefbfee50
        r8 = 0x0000000100165060  a.debug.out`shiika_vtable_String
        r9 = 0x0000000100164e01  a.debug.out`shiika_vtable_Fn4 + 193
       r10 = 0x00000001001483a8  a.debug.out`str.1 + 2648
       r11 = 0xfffffffffffffff0
       r12 = 0x0000000000000000
       r13 = 0x0000000000000000
       r14 = 0x0000000000000000
       r15 = 0x0000000000000000
       rip = 0x0000000100122db1  a.debug.out`lambda_1_in_toplevel + 65
    rflags = 0x0000000000000206
        cs = 0x000000000000002b
        fs = 0x0000000000000000
        gs = 0x0000000000000000

re r --allで全部のレジスタ。

メモリの値を見る

rspが0x00007ffeefbfee50だとして、そこから先を見てみる

(lldb) memory read --size 8 --format x --count 4 0x00007ffeefbfee50
0x7ffeefbfee50: 0x00007ffeefbfef28 0x000000000000000f
0x7ffeefbfee60: 0x00000001004711b0 0x00000001000343fd

8バイトずつ、16進数で4個取り出した。それぞれrsp+0x0, rsp+0x8, rsp+0x10, rsp+0x18ということ。

ブレークポイントを設定する

LLVM function名で設定できる。例えばdefine void @user_main() {なら、

(lldb) b user_main

その他のコマンド

以下に詳しい。GDBでの対応するコマンドもわかる。

More posts

Posts

(more...)

Articles

(more...)

Category

Ads

About

About the author