How to debug mrubyHow to debug mruby
RubyConf.tw 2014RubyConf.tw 2014
Team YamanekkoTeam Yamanekko
Yurie Yamane / Masayosh...
自我介紹
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
blinking
mode
tilt sensor
mode
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 in
Application
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 debugge...
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...
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...
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 2014
Team YamanekkoTeam Yamanekko
Yurie Yamane / Masayosh...
Our debugger status
●
just started (not finished yet Orz)
●
We talk how it works, showing
simple demo with gdb and Eclipse...
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 see
original code in Ruby
bytecode structure
●
We made mruby bytecode parser
–
mrb_parser (v0.0.1)
–
http://rubygems.org/gems/mrb_parser
–
https://g...
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...
mrbc and mrubyVM
*.rb *.mrb
Compile
Ruby
Bytecode with
debug section
Execute
mrbc -g
mrbc mrubyVM
bytecode structure
RITE Section(Header)
IREP Section
END Section
IREP Record
DEBUG Section
DEBUG Info
*.mrb
corresponding
bytecode structure
RITE Section
IREP Section
END Section
IREP Record
DEBUG Section
DEBUG 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...
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 define
ENABLE_DEBUG
in 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
–
v...
Eclipse + CDT meets mruby
Eclipse Platform
DSF-GDB
target application
(+mruby)
GDB/MI
DSF
CDT
mrubydebugger
Demo
演示
Conclusion
結語
Conclusion
●
programming in mruby is fun
●
debugging in mruby is hard
●
making debugger is harder than
that
●
Cool tool he...
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:
How to debug mruby (rubyconftw2014)
How to debug mruby (rubyconftw2014)
How to debug mruby (rubyconftw2014)
How to debug mruby (rubyconftw2014)
How to debug mruby (rubyconftw2014)
How to debug mruby (rubyconftw2014)
How to debug mruby (rubyconftw2014)
How to debug mruby (rubyconftw2014)
How to debug mruby (rubyconftw2014)
How to debug mruby (rubyconftw2014)
How to debug mruby (rubyconftw2014)
How to debug mruby (rubyconftw2014)
How to debug mruby (rubyconftw2014)
Upcoming SlideShare
Loading in …5
×

How to debug mruby (rubyconftw2014)

761
-1

Published on

slides for RubyConf Taiwan 2014

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
761
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
6
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

How to debug mruby (rubyconftw2014)

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

    Clipping is a handy way to collect important slides you want to go back to later.

×