how to debug mruby (rubyconftw2014)
DESCRIPTION
slides for RubyConf Taiwan 2014TRANSCRIPT
![Page 1: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/1.jpg)
How to debug mrubyHow to debug mruby
RubyConf.tw 2014RubyConf.tw 2014Team YamanekkoTeam Yamanekko
Yurie Yamane / Masayoshi TakahashiYurie Yamane / Masayoshi Takahashi
![Page 2: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/2.jpg)
自我介紹Who are we?
![Page 3: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/3.jpg)
Who are we
●やまね ゆりえ (Yurie Yamane)●高橋征義 (Masayoshi Takahashi)●ちー (Chie)
![Page 4: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/4.jpg)
Team Yamanekko
Who are we
![Page 5: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/5.jpg)
http://mrb.h2so5.net/
![Page 6: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/6.jpg)
電子書出版社
http://tatsu-zine.com/
Tatsu-zine Publishing Inc.
![Page 7: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/7.jpg)
![Page 8: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/8.jpg)
![Page 9: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/9.jpg)
http://ruby-no-kai.org/
![Page 10: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/10.jpg)
http://rubykaigi.org/2014
![Page 11: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/11.jpg)
http://rubykaigi.org/2015
![Page 12: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/12.jpg)
CFP will be opened soon
公開徵求講者
![Page 13: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/13.jpg)
our talks
到現在的經歷
![Page 14: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/14.jpg)
Our talks
RubyConf.tw 2012
![Page 15: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/15.jpg)
Our talks
OSDC.tw 2013
![Page 16: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/16.jpg)
RubyConf 2013
https://www.flickr.com/photos/igaiga/10836637785/
![Page 17: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/17.jpg)
Demo
演示
![Page 18: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/18.jpg)
STM32F4的演示
Push Button
Push Button
Power ON
blinkingmode
tilt sensormode
![Page 19: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/19.jpg)
Our problem
我們的問題
![Page 20: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/20.jpg)
mruby core
*.rb (stdlib)
*.rb (your code)
C/C++libmruby.a
Bytecode(C String)
mrbgems
Bytecode(C String)
![Page 21: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/21.jpg)
mruby core
*.rb (stdlib)
*.rb (your code)
C/C++
mrbgems
Ruby
C
![Page 22: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/22.jpg)
mrb_led_toggle
![Page 23: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/23.jpg)
debugging in C → Eclipse+CDT
![Page 24: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/24.jpg)
debugging in Ruby → ???
![Page 25: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/25.jpg)
add breakpoint in C
● aaa● Bbb●
mrbc
breakpoint
mrbgems
C part inApplication
![Page 26: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/26.jpg)
add breakpoint in Ruby
● aaa● Bbb●
mrbc
breakpoint
![Page 27: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/27.jpg)
Today's Topic
今天的主題
![Page 28: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/28.jpg)
Debug
除錯
![Page 29: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/29.jpg)
https://www.flickr.com/photos/monkeymashbutton/7618269720/https://www.flickr.com/photos/monkeymashbutton/7618269720/
![Page 30: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/30.jpg)
CRuby的除錯
Debugging in CRuby
![Page 31: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/31.jpg)
Debugging in CRuby● p || printf● irb● ruby-debug || bybug
![Page 32: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/32.jpg)
Debugging in CRuby● p || printf● irb● ruby-debug || bybug
![Page 33: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/33.jpg)
mruby/src/vm.c
![Page 34: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/34.jpg)
STDIO is an option in mruby
![Page 35: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/35.jpg)
Debugging in CRuby
● p || printf● irb● ruby-debug || bybug
![Page 36: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/36.jpg)
![Page 37: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/37.jpg)
![Page 38: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/38.jpg)
Debugging in CRuby
● p || printf● irb● ruby-debug || bybug
![Page 39: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/39.jpg)
Debugging in CRuby
● p || printf● irb● ruby-debug || bybug
mruby has no debugger (yet)– 田中先生 will develop mruby debugger (in this year?)
![Page 40: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/40.jpg)
Issues in mruby
● embedding into C/C++ apps– mruby's code is just a part of application– We need to debug C/C++ code AND ruby code
● ruby-debug is only Ruby-level debugger– GDB && ruby-debug ??
![Page 41: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/41.jpg)
What we want to do● adding breakpoint in Ruby AND C● step over/into/return in Ruby AND C● show stacktrace in Ruby AND C● show variable in Ruby AND C
– it's different from ruby-debug
![Page 42: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/42.jpg)
We can do them in C level
https://www.sourceware.org/gdb/
![Page 43: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/43.jpg)
our solution
● “hybrid debugger”– C-level debugger + Ruby-level extension– Ruby debugger on GDB
![Page 44: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/44.jpg)
How to debug mrubyHow to debug mruby
RubyConf.tw 2014RubyConf.tw 2014Team YamanekkoTeam Yamanekko
Yurie Yamane / Masayoshi TakahashiYurie Yamane / Masayoshi Takahashi
make a debugger tomake a debugger to
![Page 45: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/45.jpg)
Our debugger status
● just started (not finished yet Orz)● We talk how it works, showing simple demo with gdb and Eclipse plugin
![Page 46: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/46.jpg)
m
http://ruby-hacking-guide.github.io/
![Page 47: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/47.jpg)
mrbc and mrubyVM
*.rb *.mrb mrubyVMmrbc
Compile
Ruby Bytecode
Execute
![Page 48: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/48.jpg)
mrbc and mrubyVM
*.rb *.mrb mrubyVMmrbc
Compile
Ruby Bytecode
Execute
mruby VM don't seeoriginal code in Ruby
![Page 49: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/49.jpg)
bytecode structure
● We made mruby bytecode parser– mrb_parser (v0.0.1)– http://rubygems.org/gems/mrb_parser– https://github.com/yamanekko/mrb_parser
![Page 50: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/50.jpg)
![Page 51: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/51.jpg)
bytecode structure
RITE Section (Header)
IREP Section
END Section
IREP Record
*.mrb
![Page 52: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/52.jpg)
http://commons.wikimedia.org/wiki/File:Dialog-warning-orange.svg
without -g option,mrbc doesn't generate mappings between line numbers of ruby souce code and bytecodes.
![Page 53: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/53.jpg)
mrbc and mrubyVM
*.rb *.mrb
Compile
RubyBytecode withdebug section
Executemrbc -g
mrbc mrubyVM
![Page 54: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/54.jpg)
bytecode structure
RITE Section(Header)
IREP Section
END Section
IREP Record
DEBUG SectionDEBUG Info
*.mrb
corresponding
![Page 55: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/55.jpg)
![Page 56: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/56.jpg)
bytecode structure
RITE Section
IREP Section
END Section
IREP Record
DEBUG SectionDEBUG Info
*.mrb
corresponding
![Page 57: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/57.jpg)
![Page 58: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/58.jpg)
![Page 59: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/59.jpg)
i=1+2
p i
![Page 60: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/60.jpg)
http://commons.wikimedia.org/wiki/File:Dialog-warning-orange.svg
number of byte code ≠line number of Ruby code
not 1 to 1 mapping
![Page 61: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/61.jpg)
mruby VM
![Page 62: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/62.jpg)
mruby VM
● src/vm.c● mrb_context_run()● ≒ case statements within loops
![Page 63: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/63.jpg)
mrb_context_run()
![Page 64: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/64.jpg)
![Page 65: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/65.jpg)
![Page 66: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/66.jpg)
![Page 67: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/67.jpg)
http://commons.wikimedia.org/wiki/File:Dialog-warning-orange.svg
You should defineENABLE_DEBUGin mrbconf.h
![Page 68: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/68.jpg)
ENABLE_DEBUG in mrbconf.h
![Page 69: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/69.jpg)
mrb_state has code_fetch_hook
![Page 70: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/70.jpg)
setting code_fetch_hook function
![Page 71: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/71.jpg)
![Page 72: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/72.jpg)
GDB demo
![Page 73: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/73.jpg)
Eclipse
![Page 74: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/74.jpg)
Eclipse + CDT
● CDT = C/C++ Development Tooling– support various toolchains– standard make build– source navigation– various source knowledge tools
![Page 75: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/75.jpg)
Eclipse + CDT meets mruby
Eclipse Platform
DSF-GDB
target application(+mruby)
GDB/MI
DSFCDT
mrubydebugger
![Page 76: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/76.jpg)
Demo
演示
![Page 77: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/77.jpg)
Conclusion
結語
![Page 78: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/78.jpg)
Conclusion●programming in mruby is fun●debugging in mruby is hard
●making debugger is harder than that
●Cool tool helps you and makes less hard
![Page 79: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/79.jpg)
TODO● step into/step over● show backtrace● show variables
![Page 80: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/80.jpg)
Kernel#local_variables
![Page 81: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/81.jpg)
![Page 82: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/82.jpg)
TODO● extending *.mrb
● adding LVAR section???
![Page 83: How to debug mruby (rubyconftw2014)](https://reader034.vdocuments.mx/reader034/viewer/2022042607/555218f2b4c90520548b4b04/html5/thumbnails/83.jpg)
Thanks!Happy mruby Hacking!
special thanks to: