読者です 読者をやめる 読者になる 読者になる

CubicLouve

Spring_MTの技術ブログです。https://github.com/SpringMT (http://spring-mt.tumblr.com/ からの移転)

lldbでrubyのデバッグ初級編

c lldb

スーパールーキーに教わってたことのメモ

putsメソッドrb_f_putsを呼んでいるので、そこでbreakpoitを仕込んでbacktrace取る。

% lldb `rbenv which ruby`
(lldb) target create "/opt/boxen/rbenv/versions/2.1.2/bin/ruby"
Current executable set to '/opt/boxen/rbenv/versions/2.1.2/bin/ruby' (x86_64).
(lldb) b rb_f_puts
Breakpoint 1: where = ruby`rb_f_puts, address = 0x0000000100069f60
(lldb) r -e 'puts 1'
Process 31982 launched: '/opt/boxen/rbenv/versions/2.1.2/bin/ruby' (x86_64)
Process 31982 stopped
* thread #1: tid = 0x12faced, 0x0000000100069f60 ruby`rb_f_puts, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
    frame #0: 0x0000000100069f60 ruby`rb_f_puts
ruby`rb_f_puts:
-> 0x100069f60:  pushq  %rbp
   0x100069f61:  movq   %rsp, %rbp
   0x100069f64:  pushq  %r15
   0x100069f66:  pushq  %r14
(lldb) bt
* thread #1: tid = 0x12faced, 0x0000000100069f60 ruby`rb_f_puts, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
  * frame #0: 0x0000000100069f60 ruby`rb_f_puts
    frame #1: 0x000000010016d07b ruby`vm_call_cfunc + 987
    frame #2: 0x000000010016c9cb ruby`vm_call_method + 843
    frame #3: 0x000000010015610c ruby`vm_exec_core + 10156
    frame #4: 0x000000010016334f ruby`vm_exec + 127
    frame #5: 0x0000000100164238 ruby`rb_iseq_eval_main + 392
    frame #6: 0x000000010003ebb4 ruby`ruby_exec_internal + 148
    frame #7: 0x000000010003eade ruby`ruby_run_node + 78
    frame #8: 0x0000000100000d5f ruby`main + 79
    frame #9: 0x00007fff8cb225fd libdyld.dylib`start + 1
    frame #10: 0x00007fff8cb225fd libdyld.dylib`start + 1
(lldb) finish
1
Process 31982 stopped
* thread #1: tid = 0x12faced, 0x000000010016d07b ruby`vm_call_cfunc + 987, queue = 'com.apple.main-thread', stop reason = step out
    frame #0: 0x000000010016d07b ruby`vm_call_cfunc + 987
ruby`vm_call_cfunc + 987:
-> 0x10016d07b:  movq   %rax, %r12
   0x10016d07e:  movq   0x20(%r13), %rax
   0x10016d082:  addq   $0x50, %rax
   0x10016d086:  cmpq   %rbx, %rax