Upload
yamanekko
View
488
Download
6
Embed Size (px)
DESCRIPTION
slides for RubyConf Taiwan 2014
Citation preview
How to debug mrubyHow to debug mruby
RubyConf.tw 2014RubyConf.tw 2014Team YamanekkoTeam Yamanekko
Yurie Yamane / Masayoshi TakahashiYurie Yamane / Masayoshi Takahashi
自我介紹Who are we?
Who are we
●やまね ゆりえ (Yurie Yamane)●高橋征義 (Masayoshi Takahashi)●ちー (Chie)
Team Yamanekko
Who are we
http://mrb.h2so5.net/
電子書出版社
http://tatsu-zine.com/
Tatsu-zine Publishing Inc.
http://ruby-no-kai.org/
http://rubykaigi.org/2014
http://rubykaigi.org/2015
CFP will be opened soon
公開徵求講者
our talks
到現在的經歷
Our talks
RubyConf.tw 2012
Our talks
OSDC.tw 2013
RubyConf 2013
https://www.flickr.com/photos/igaiga/10836637785/
Demo
演示
STM32F4的演示
Push Button
Push Button
Power ON
blinkingmode
tilt sensormode
Our problem
我們的問題
mruby core
*.rb (stdlib)
*.rb (your code)
C/C++libmruby.a
Bytecode(C String)
mrbgems
Bytecode(C String)
mruby core
*.rb (stdlib)
*.rb (your code)
C/C++
mrbgems
Ruby
C
mrb_led_toggle
debugging in C → Eclipse+CDT
debugging in Ruby → ???
add breakpoint in C
● aaa● Bbb●
mrbc
breakpoint
mrbgems
C part inApplication
add breakpoint in Ruby
● aaa● Bbb●
mrbc
breakpoint
Today's Topic
今天的主題
Debug
除錯
https://www.flickr.com/photos/monkeymashbutton/7618269720/https://www.flickr.com/photos/monkeymashbutton/7618269720/
CRuby的除錯
Debugging in CRuby
Debugging in CRuby● p || printf● irb● ruby-debug || bybug
Debugging in CRuby● p || printf● irb● ruby-debug || bybug
mruby/src/vm.c
STDIO is an option in mruby
Debugging in CRuby
● p || printf● irb● ruby-debug || bybug
Debugging in CRuby
● p || printf● irb● ruby-debug || bybug
Debugging in CRuby
● p || printf● irb● ruby-debug || bybug
mruby has no debugger (yet)– 田中先生 will develop mruby debugger (in this year?)
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 ??
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
We can do them in C level
https://www.sourceware.org/gdb/
our solution
● “hybrid debugger”– C-level debugger + Ruby-level extension– Ruby debugger on GDB
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
Our debugger status
● just started (not finished yet Orz)● We talk how it works, showing simple demo with gdb and Eclipse plugin
m
http://ruby-hacking-guide.github.io/
mrbc and mrubyVM
*.rb *.mrb mrubyVMmrbc
Compile
Ruby Bytecode
Execute
mrbc and mrubyVM
*.rb *.mrb mrubyVMmrbc
Compile
Ruby Bytecode
Execute
mruby VM don't seeoriginal code in Ruby
bytecode structure
● We made mruby bytecode parser– mrb_parser (v0.0.1)– http://rubygems.org/gems/mrb_parser– https://github.com/yamanekko/mrb_parser
bytecode structure
RITE Section (Header)
IREP Section
END Section
IREP Record
*.mrb
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.
mrbc and mrubyVM
*.rb *.mrb
Compile
RubyBytecode withdebug section
Executemrbc -g
mrbc mrubyVM
bytecode structure
RITE Section(Header)
IREP Section
END Section
IREP Record
DEBUG SectionDEBUG Info
*.mrb
corresponding
bytecode structure
RITE Section
IREP Section
END Section
IREP Record
DEBUG SectionDEBUG Info
*.mrb
corresponding
i=1+2
p i
http://commons.wikimedia.org/wiki/File:Dialog-warning-orange.svg
number of byte code ≠line number of Ruby code
not 1 to 1 mapping
mruby VM
mruby VM
● src/vm.c● mrb_context_run()● ≒ case statements within loops
mrb_context_run()
http://commons.wikimedia.org/wiki/File:Dialog-warning-orange.svg
You should defineENABLE_DEBUGin mrbconf.h
ENABLE_DEBUG in mrbconf.h
mrb_state has code_fetch_hook
setting code_fetch_hook function
GDB demo
Eclipse
Eclipse + CDT
● CDT = C/C++ Development Tooling– support various toolchains– standard make build– source navigation– various source knowledge tools
Eclipse + CDT meets mruby
Eclipse Platform
DSF-GDB
target application(+mruby)
GDB/MI
DSFCDT
mrubydebugger
Demo
演示
Conclusion
結語
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
TODO● step into/step over● show backtrace● show variables
Kernel#local_variables
TODO● extending *.mrb
● adding LVAR section???
Thanks!Happy mruby Hacking!
special thanks to: