SlideShare a Scribd company logo
1 of 25
Download to read offline
Hacking Ruby
    with
   Python
     @tyamadajp
光ある所、影があり

コードある所、闇がある
闇の名は、バグ。

そしてバグを殺す者、
Ruby Debugger
~僕と契約して闇デバッガになろうよ!~
みなさんオススメのデバッガは?
0. p+?            (?!)
1. debug.rb?      (旧型)
2. ruby-debug? (普通)
3. rb-trepanning? (新型)
4. others?

#ベースの機能を生かした
# JRuby, Rubinius 用のとかも
#ありますよね
デバッガのいい所
・どこまでも覗ける
・動いている状態を覗ける
・あろうことか、手まで出せる

「言語仕様?そんなの関係ねぇ!」

「もし闇の住人がデバッガーの
       解説ページを読んだら」
さて今宵のデバッガは・・・
さて今宵のデバッガは・・・




  GDB
さて今宵のデバッガは・・・


   The
   GNU
   Debugger
さて今宵のデバッガは・・・




… の Python 拡張
さて今宵のデバッガは・・・




 GDB/Python
       明日の Ruby のために、
       今夜は Python
なにそれこわい
こわくないよ!> GDB/Python
1. GDB を 100% API control
 → ブレークポイントの操作とか

2. GDB そのものも拡張
 →新コマンド追加 / (gdb)...
 →簡易関数の追加 / $func(...)
 → print ハイジャック / pretty printer
こんな感じ(実装例)
(gdb) p self
$299 = (struct RTypedData *) 0x64b2c0,
   type=iseq ($300), data=0x731ee0 ($301)

(gdb) pp self
$302 = (struct RTypedData *) 0x64b2c0,
   type=iseq ($303), data=0x731ee0 ($304)
$305 = (const rb_data_type_t *) 0x7ffff7dbe780
$306 = (rb_iseq_t *) 0x731ee0, <compiled>:3,
   type=ISEQ_TYPE_TOP



      ・・・まあ色々デコードしてくれます
それ $RUBY/.gdbinit でできるよ?
ええ、あるのですが・・・
・主力は内蔵 eval や dump 関数?
・なので展開能力が控えめ ( ぬるぽ避け? )
  (gdb) rp recv
  T_CLASS: $1156 = (struct RClass *) 0x655310


      →ソース読解の道具が欲しかった
      →自分でデコードするのがよい練習
ぬるぽを恐れず何でも展開
(gdb) pp recv
$1158 = (struct RClass *) 0x655310 [Time]
dump: {basic = {flags = 2, klass = 6640360},
 ptr=0x6e4e20, m_tbl=0x6e4e40, iv_index_tbl=0x0}
m_tbl: +, -, <=>, _dump, asctime, ctime, …

(gdb) pp ruby_current_thread->cfp->iseq 2
$1072 = (rb_iseq_t *) 0x75c9c0, MAIN,
   /home/tai/tarai.rb:1(p=0x70a260/$1073,
                         l=0x70a260/$1074)
line#0003:               VALUE ラップもの、 ID 、
      $1075 putstring NODE 、 rb_iseq_t 、 rb_vm_t...
                         自動で型判定し p or pp で
      $1076 getclassvariable
      …                  中身を徹底表示
GDB script ではダメですか?
・ まともな制御構文がない
 → if else if else if else end end end
・ スコープ概念が(ほとんど)ない
・ 遅い。当人比で最大 100+ 倍以上

・ 限りなく貧弱なデータ操作機能とライブラリ

     「 GDB script がやられたか・・・」
     「所詮あやつは言語以前の存在」
GDB Python API - basic
import gdb
# vmは gdb.Value オブジェクトだが rb_vm_t* の型を保持
vm = gdb.parse_and_eval(“ruby_current_vm”)

# これも gdb.Value オブジェクトだが、 rb_thread_t* の型を維持
th = vm['running_thread']
# いわゆる構造体ダンプ :(gdb) p *ruby_current_vm
print(vm.dereference())
# ポインタ演算したいときには char* にしたり
pointer_op(th.cast(gdb.lookup_type(“char”).pointer()))

# CLI 側で参照できるよう $ や $N に戻したりもできる
gdb.execute(“p (%s)%ld” % (th.type, long(th)))
gdb.execute(“set $foo = %ld” % long(th))
GDB Command – extending gdb
import gdb
class HelloCommand(gdb.Command):
   """Sample GDB command in Python"""
   def __init__(self):
      super(self.__class__, self).__init__(
          "hello-cmd", gdb.COMMAND_OBSCURE)
  def invoke(self, arg, from_tty):
     args = gdb.string_to_argv(arg)
     print("arg is [%s]" % ", ".join(args))
HelloCommand()
                                   拡張1つにクラスを1つ

※ ロードは (gdb) python execfile(“hello.py”) などで
GDB Command – easy way
import gdb
@gdbcommand(“hello-cmd“)
def hello(*args):
   """
   Sample GDB command in Python
   Usage: hello-cmd args
   """
   print("arg is [%s]" % ", ".join(args))




                                     バイト数 50% カット!
GDB Command – easy way, impl
def gdbcommand(*args):
   """Turns decorated function into GDB command"""
   opts = [args[0], gdb.COMMAND_OBSCURE] #FIXME

  def wrap(func):
     name = opts[0] or func.func_name
     def init(self):
        super(self.__class__, self).__init__(name, *opts[1:])
     def invoke(self, arg, from_tty):
        func(*gdb.string_to_argv(arg))
     type("", (gdb.Command,), {
        '__doc__': func.__doc__, '__init__': init, 'invoke': invoke,
     })()
     return func
  return wrap                           デコレータ、 Ruby にも
                                       本気で欲しくなったり
  ※ スライドに収めるため機能とコードをカットしています。バグってたらごめんなさい
GDB Pretty Printer
class HelloPrinter(object):
   """Print (hello_t *) type"""
   def __init__(self, val): self.val = val

   # 表示する文字列又は gdb.Value を返す。後者の場合は
   # 再度 pretty-printing 処理が試みられる。以下はダミー。
   def to_string(self): return "hogehoge"
   # 表示ヒント。 "array", "map", "string" のいずれかを返す
   def display_hint(self): return "string"
# カスタムプリンタが反応できるようチェッカを登録
def ckval(gv):
   if gv.type == gdb.lookup_type("hello_t").pointer():
      return HelloPrinter(gv)
   return None                    print 以外にも、あらゆる
gdb.pretty_printers.append(ckval) 表示処理に適用される
おまけ: Ruby と Python の狂演
$ rlwrap gdb -q -readnow --args ./ruby1.9.1 tarai.rb
(gdb) b vm_exec
(gdb) run
(gdb) python sys.argv = [“gdb”] # GDB 側の漏れ対応
(gdb) python execfile("/usr/bin/ipython")
IPython 0.10.2 -- An enhanced Interactive Python.
In [1]: from gdb import *
In [2]: vm = parse_and_eval("ruby_current_vm")
In [3]: vm
Out[3]: <gdb.Value object at 0x207bb70>
In [4]: p vm['main_thread'].type
struct rb_thread_struct *


  補完処理が壊れたり、単に GDB/Python スクリプト
  書くよりバグ率高いですが、変態的な可能性を感じる
おまけ: gdb.rb – GDB/Ruby in Py*
https://github.com/tmm1/gdb.rb

 「 gdb hooks for MRI/REE (and some for YARV) 」

(gdb) b vm_exec if $interactive == 0
(gdb) run
(gdb) set $interactive = 1 #自己呼び出しのブロック防止
(gdb) python execfile("ruby-gdb.py")
(gdb) ruby eval Thread.list
[#<Thread:0x00000000650cc0 run>]
(gdb) ruby objects
  HEAPS      24
  SLOTS    9816            実は金曜日に発見して
  LIVE     2717 (27.68%)   かなりへこんだ。
  FREE     7099 (72.32%)   Ruby 内部の機能をフルに
                          使って自分自身をデバッグ
 complex     1 (0.04%)
 bignum      2 (0.07%)
まとめ
1. Ruby のデバッグ・学習に使ってみた
2. GDB/Python は強力なツール
3.正直わけがわからないよ!

「明日の Ruby のために、今夜は Python 」


参考文献:
・ sourceware.org/gdb/onlinedocs/gdb/Python-API.html
・ sourceware.org/gdb/wiki/PythonGdbTutorial
・ gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/python/

More Related Content

What's hot

GCをみればRTSが見えてくる、かも。。。
GCをみればRTSが見えてくる、かも。。。GCをみればRTSが見えてくる、かも。。。
GCをみればRTSが見えてくる、かも。。。dec9ue
 
リテラル文字列型までの道
リテラル文字列型までの道リテラル文字列型までの道
リテラル文字列型までの道Satoshi Sato
 
Boost.勉強会#19東京 Effective Modern C++とC++ Core Guidelines
Boost.勉強会#19東京 Effective Modern C++とC++ Core GuidelinesBoost.勉強会#19東京 Effective Modern C++とC++ Core Guidelines
Boost.勉強会#19東京 Effective Modern C++とC++ Core GuidelinesShintarou Okada
 
組み込みでこそC++を使う10の理由
組み込みでこそC++を使う10の理由組み込みでこそC++を使う10の理由
組み込みでこそC++を使う10の理由kikairoya
 
Quine・難解プログラミングについて
Quine・難解プログラミングについてQuine・難解プログラミングについて
Quine・難解プログラミングについてmametter
 
不遇の標準ライブラリ - valarray
不遇の標準ライブラリ - valarray不遇の標準ライブラリ - valarray
不遇の標準ライブラリ - valarrayRyosuke839
 
クロージャデザインパターン
クロージャデザインパターンクロージャデザインパターン
クロージャデザインパターンMoriharu Ohzu
 
Rubyの拡張をCrystalで書いてみる
Rubyの拡張をCrystalで書いてみるRubyの拡張をCrystalで書いてみる
Rubyの拡張をCrystalで書いてみる5t111111
 
Groovyで学ぶプロセス代数 #jjug
Groovyで学ぶプロセス代数 #jjugGroovyで学ぶプロセス代数 #jjug
Groovyで学ぶプロセス代数 #jjugkyon mm
 
Application Developer Festival 2015 LT
Application Developer Festival 2015 LTApplication Developer Festival 2015 LT
Application Developer Festival 2015 LTJunpei Matsuda
 
AngularJS+TypeScript - AngularJS 1周年記念勉強会
AngularJS+TypeScript - AngularJS 1周年記念勉強会AngularJS+TypeScript - AngularJS 1周年記念勉強会
AngularJS+TypeScript - AngularJS 1周年記念勉強会Masahiro Wakame
 
Python physicalcomputing
Python physicalcomputingPython physicalcomputing
Python physicalcomputingNoboru Irieda
 
#027 tddのさわり
#027 tddのさわり#027 tddのさわり
#027 tddのさわり森下 智裕
 
Write good parser in perl
Write good parser in perlWrite good parser in perl
Write good parser in perlJiro Nishiguchi
 
第2回勉強会スライド
第2回勉強会スライド第2回勉強会スライド
第2回勉強会スライドkoturn 0;
 
これからのJSの話をしよう ~jQueryで作るTwitterアプリ~ (Gunma.web #2 2010/10/9)
これからのJSの話をしよう ~jQueryで作るTwitterアプリ~ (Gunma.web #2 2010/10/9)これからのJSの話をしよう ~jQueryで作るTwitterアプリ~ (Gunma.web #2 2010/10/9)
これからのJSの話をしよう ~jQueryで作るTwitterアプリ~ (Gunma.web #2 2010/10/9)parrotstudio
 
第1回勉強会スライド
第1回勉強会スライド第1回勉強会スライド
第1回勉強会スライドkoturn 0;
 

What's hot (19)

GCをみればRTSが見えてくる、かも。。。
GCをみればRTSが見えてくる、かも。。。GCをみればRTSが見えてくる、かも。。。
GCをみればRTSが見えてくる、かも。。。
 
リテラル文字列型までの道
リテラル文字列型までの道リテラル文字列型までの道
リテラル文字列型までの道
 
Boost.勉強会#19東京 Effective Modern C++とC++ Core Guidelines
Boost.勉強会#19東京 Effective Modern C++とC++ Core GuidelinesBoost.勉強会#19東京 Effective Modern C++とC++ Core Guidelines
Boost.勉強会#19東京 Effective Modern C++とC++ Core Guidelines
 
組み込みでこそC++を使う10の理由
組み込みでこそC++を使う10の理由組み込みでこそC++を使う10の理由
組み込みでこそC++を使う10の理由
 
Q planet
Q planetQ planet
Q planet
 
Quine・難解プログラミングについて
Quine・難解プログラミングについてQuine・難解プログラミングについて
Quine・難解プログラミングについて
 
不遇の標準ライブラリ - valarray
不遇の標準ライブラリ - valarray不遇の標準ライブラリ - valarray
不遇の標準ライブラリ - valarray
 
クロージャデザインパターン
クロージャデザインパターンクロージャデザインパターン
クロージャデザインパターン
 
Rubyの拡張をCrystalで書いてみる
Rubyの拡張をCrystalで書いてみるRubyの拡張をCrystalで書いてみる
Rubyの拡張をCrystalで書いてみる
 
Groovyで学ぶプロセス代数 #jjug
Groovyで学ぶプロセス代数 #jjugGroovyで学ぶプロセス代数 #jjug
Groovyで学ぶプロセス代数 #jjug
 
Application Developer Festival 2015 LT
Application Developer Festival 2015 LTApplication Developer Festival 2015 LT
Application Developer Festival 2015 LT
 
AngularJS+TypeScript - AngularJS 1周年記念勉強会
AngularJS+TypeScript - AngularJS 1周年記念勉強会AngularJS+TypeScript - AngularJS 1周年記念勉強会
AngularJS+TypeScript - AngularJS 1周年記念勉強会
 
Python physicalcomputing
Python physicalcomputingPython physicalcomputing
Python physicalcomputing
 
#027 tddのさわり
#027 tddのさわり#027 tddのさわり
#027 tddのさわり
 
Dsl&Builder
Dsl&BuilderDsl&Builder
Dsl&Builder
 
Write good parser in perl
Write good parser in perlWrite good parser in perl
Write good parser in perl
 
第2回勉強会スライド
第2回勉強会スライド第2回勉強会スライド
第2回勉強会スライド
 
これからのJSの話をしよう ~jQueryで作るTwitterアプリ~ (Gunma.web #2 2010/10/9)
これからのJSの話をしよう ~jQueryで作るTwitterアプリ~ (Gunma.web #2 2010/10/9)これからのJSの話をしよう ~jQueryで作るTwitterアプリ~ (Gunma.web #2 2010/10/9)
これからのJSの話をしよう ~jQueryで作るTwitterアプリ~ (Gunma.web #2 2010/10/9)
 
第1回勉強会スライド
第1回勉強会スライド第1回勉強会スライド
第1回勉強会スライド
 

Viewers also liked

Use Promise, Future and some functional programing stuff without being a math...
Use Promise, Future and some functional programing stuff without being a math...Use Promise, Future and some functional programing stuff without being a math...
Use Promise, Future and some functional programing stuff without being a math...Quentin Adam
 
preventing sqli and xss by ravi rajput in owasp meet ahmedabad
preventing sqli and xss by ravi rajput in owasp meet ahmedabadpreventing sqli and xss by ravi rajput in owasp meet ahmedabad
preventing sqli and xss by ravi rajput in owasp meet ahmedabadRavi Rajput
 
Micro c lab3(ssd)
Micro c lab3(ssd)Micro c lab3(ssd)
Micro c lab3(ssd)Mashood
 
Introduction To Django
Introduction To DjangoIntroduction To Django
Introduction To DjangoJay Graves
 
Defcon 21 - Fear the Evil FOCA: mitm attacks using IPv6
Defcon 21 - Fear the Evil FOCA: mitm attacks using IPv6Defcon 21 - Fear the Evil FOCA: mitm attacks using IPv6
Defcon 21 - Fear the Evil FOCA: mitm attacks using IPv6Chema Alonso
 
Building a Dynamic Website Using Django
Building a Dynamic Website Using DjangoBuilding a Dynamic Website Using Django
Building a Dynamic Website Using DjangoNathan Eror
 
Easy selenium test automation on python
Easy selenium test automation on pythonEasy selenium test automation on python
Easy selenium test automation on pythonMykhailo Poliarush
 
Selenium Tips & Tricks, presented at the Tel Aviv Selenium Meetup
Selenium Tips & Tricks, presented at the Tel Aviv Selenium MeetupSelenium Tips & Tricks, presented at the Tel Aviv Selenium Meetup
Selenium Tips & Tricks, presented at the Tel Aviv Selenium MeetupDave Haeffner
 
Practical Tips & Tricks for Selenium Test Automation
Practical Tips & Tricks for Selenium Test AutomationPractical Tips & Tricks for Selenium Test Automation
Practical Tips & Tricks for Selenium Test AutomationSauce Labs
 
Python in Computer Vision
Python in Computer VisionPython in Computer Vision
Python in Computer VisionBrian Thorne
 
X-XSS-Nightmare: 1; mode=attack XSS Attacks Exploiting XSS Filter
X-XSS-Nightmare: 1; mode=attack XSS Attacks Exploiting XSS FilterX-XSS-Nightmare: 1; mode=attack XSS Attacks Exploiting XSS Filter
X-XSS-Nightmare: 1; mode=attack XSS Attacks Exploiting XSS FilterMasato Kinugawa
 
Django for Beginners
Django for BeginnersDjango for Beginners
Django for BeginnersJason Davies
 
Cross Site Scripting ( XSS)
Cross Site Scripting ( XSS)Cross Site Scripting ( XSS)
Cross Site Scripting ( XSS)Amit Tyagi
 
Object-oriented Programming in Python
Object-oriented Programming in PythonObject-oriented Programming in Python
Object-oriented Programming in PythonJuan-Manuel Gimeno
 

Viewers also liked (20)

Use Promise, Future and some functional programing stuff without being a math...
Use Promise, Future and some functional programing stuff without being a math...Use Promise, Future and some functional programing stuff without being a math...
Use Promise, Future and some functional programing stuff without being a math...
 
Middle man
Middle manMiddle man
Middle man
 
Django Testing
Django TestingDjango Testing
Django Testing
 
preventing sqli and xss by ravi rajput in owasp meet ahmedabad
preventing sqli and xss by ravi rajput in owasp meet ahmedabadpreventing sqli and xss by ravi rajput in owasp meet ahmedabad
preventing sqli and xss by ravi rajput in owasp meet ahmedabad
 
Micro c lab3(ssd)
Micro c lab3(ssd)Micro c lab3(ssd)
Micro c lab3(ssd)
 
Code 8051
Code 8051Code 8051
Code 8051
 
Introduction To Django
Introduction To DjangoIntroduction To Django
Introduction To Django
 
Hacking y python: Hacking de redes con Python
Hacking y python: Hacking de redes con PythonHacking y python: Hacking de redes con Python
Hacking y python: Hacking de redes con Python
 
Defcon 21 - Fear the Evil FOCA: mitm attacks using IPv6
Defcon 21 - Fear the Evil FOCA: mitm attacks using IPv6Defcon 21 - Fear the Evil FOCA: mitm attacks using IPv6
Defcon 21 - Fear the Evil FOCA: mitm attacks using IPv6
 
Building a Dynamic Website Using Django
Building a Dynamic Website Using DjangoBuilding a Dynamic Website Using Django
Building a Dynamic Website Using Django
 
Easy selenium test automation on python
Easy selenium test automation on pythonEasy selenium test automation on python
Easy selenium test automation on python
 
Selenium Tips & Tricks, presented at the Tel Aviv Selenium Meetup
Selenium Tips & Tricks, presented at the Tel Aviv Selenium MeetupSelenium Tips & Tricks, presented at the Tel Aviv Selenium Meetup
Selenium Tips & Tricks, presented at the Tel Aviv Selenium Meetup
 
Practical Tips & Tricks for Selenium Test Automation
Practical Tips & Tricks for Selenium Test AutomationPractical Tips & Tricks for Selenium Test Automation
Practical Tips & Tricks for Selenium Test Automation
 
Python in Computer Vision
Python in Computer VisionPython in Computer Vision
Python in Computer Vision
 
X-XSS-Nightmare: 1; mode=attack XSS Attacks Exploiting XSS Filter
X-XSS-Nightmare: 1; mode=attack XSS Attacks Exploiting XSS FilterX-XSS-Nightmare: 1; mode=attack XSS Attacks Exploiting XSS Filter
X-XSS-Nightmare: 1; mode=attack XSS Attacks Exploiting XSS Filter
 
Ethical hacking with Python tools
Ethical hacking with Python toolsEthical hacking with Python tools
Ethical hacking with Python tools
 
DHCP Snooping
DHCP SnoopingDHCP Snooping
DHCP Snooping
 
Django for Beginners
Django for BeginnersDjango for Beginners
Django for Beginners
 
Cross Site Scripting ( XSS)
Cross Site Scripting ( XSS)Cross Site Scripting ( XSS)
Cross Site Scripting ( XSS)
 
Object-oriented Programming in Python
Object-oriented Programming in PythonObject-oriented Programming in Python
Object-oriented Programming in Python
 

Similar to Hacking Ruby with Python

Groovyで楽にSQLを実行してみよう
Groovyで楽にSQLを実行してみようGroovyで楽にSQLを実行してみよう
Groovyで楽にSQLを実行してみようAkira Shimosako
 
ソフトウェア工学2023 10 デバッグ
ソフトウェア工学2023 10 デバッグソフトウェア工学2023 10 デバッグ
ソフトウェア工学2023 10 デバッグToru Tamaki
 
Debug Hacks at Security and Programming camp 2011
Debug Hacks at Security and Programming camp 2011 Debug Hacks at Security and Programming camp 2011
Debug Hacks at Security and Programming camp 2011 Hiro Yoshioka
 
Getting Started GraalVM / GraalVM超入門 #jjug_ccc #ccc_c2
Getting Started GraalVM / GraalVM超入門 #jjug_ccc #ccc_c2Getting Started GraalVM / GraalVM超入門 #jjug_ccc #ccc_c2
Getting Started GraalVM / GraalVM超入門 #jjug_ccc #ccc_c2tamtam180
 
Getting Started GraalVM (再アップロード)
Getting Started GraalVM (再アップロード)Getting Started GraalVM (再アップロード)
Getting Started GraalVM (再アップロード)tamtam180
 
Programming camp 2010 debug hacks
Programming camp 2010 debug hacksProgramming camp 2010 debug hacks
Programming camp 2010 debug hacksHiro Yoshioka
 
PF部第19回資料 poor man's JTAG
PF部第19回資料 poor man's JTAGPF部第19回資料 poor man's JTAG
PF部第19回資料 poor man's JTAGdaye001
 
こんにちはGroovy
こんにちはGroovyこんにちはGroovy
こんにちはGroovyirof N
 
関東GPGPU勉強会 LLVM meets GPU
関東GPGPU勉強会 LLVM meets GPU関東GPGPU勉強会 LLVM meets GPU
関東GPGPU勉強会 LLVM meets GPUTakuro Iizuka
 
20130626 kawasaki.rb NKT77
20130626 kawasaki.rb NKT7720130626 kawasaki.rb NKT77
20130626 kawasaki.rb NKT77nkt77
 
Inside frogc in Dart
Inside frogc in DartInside frogc in Dart
Inside frogc in DartGoro Fuji
 
第8回KPF発表資料
第8回KPF発表資料第8回KPF発表資料
第8回KPF発表資料cryks
 
node-gypを使ったネイティブモジュールの作成
node-gypを使ったネイティブモジュールの作成node-gypを使ったネイティブモジュールの作成
node-gypを使ったネイティブモジュールの作成shigeki_ohtsu
 
Rubinius Under a Microscope
Rubinius Under a MicroscopeRubinius Under a Microscope
Rubinius Under a Microscope高広 内山
 
メタメタプログラミングRuby
メタメタプログラミングRubyメタメタプログラミングRuby
メタメタプログラミングRubyemasaka
 
20130626 kawasaki.rb NKT77
20130626 kawasaki.rb NKT7720130626 kawasaki.rb NKT77
20130626 kawasaki.rb NKT77nkt77
 
怠惰なRubyistへの道 fukuoka rubykaigi01
怠惰なRubyistへの道 fukuoka rubykaigi01怠惰なRubyistへの道 fukuoka rubykaigi01
怠惰なRubyistへの道 fukuoka rubykaigi01nagachika t
 

Similar to Hacking Ruby with Python (20)

Groovyで楽にSQLを実行してみよう
Groovyで楽にSQLを実行してみようGroovyで楽にSQLを実行してみよう
Groovyで楽にSQLを実行してみよう
 
ソフトウェア工学2023 10 デバッグ
ソフトウェア工学2023 10 デバッグソフトウェア工学2023 10 デバッグ
ソフトウェア工学2023 10 デバッグ
 
Debug Hacks at Security and Programming camp 2011
Debug Hacks at Security and Programming camp 2011 Debug Hacks at Security and Programming camp 2011
Debug Hacks at Security and Programming camp 2011
 
Getting Started GraalVM / GraalVM超入門 #jjug_ccc #ccc_c2
Getting Started GraalVM / GraalVM超入門 #jjug_ccc #ccc_c2Getting Started GraalVM / GraalVM超入門 #jjug_ccc #ccc_c2
Getting Started GraalVM / GraalVM超入門 #jjug_ccc #ccc_c2
 
Getting Started GraalVM (再アップロード)
Getting Started GraalVM (再アップロード)Getting Started GraalVM (再アップロード)
Getting Started GraalVM (再アップロード)
 
詳解! Decimal
詳解! Decimal詳解! Decimal
詳解! Decimal
 
Programming camp 2010 debug hacks
Programming camp 2010 debug hacksProgramming camp 2010 debug hacks
Programming camp 2010 debug hacks
 
PF部第19回資料 poor man's JTAG
PF部第19回資料 poor man's JTAGPF部第19回資料 poor man's JTAG
PF部第19回資料 poor man's JTAG
 
こんにちはGroovy
こんにちはGroovyこんにちはGroovy
こんにちはGroovy
 
関東GPGPU勉強会 LLVM meets GPU
関東GPGPU勉強会 LLVM meets GPU関東GPGPU勉強会 LLVM meets GPU
関東GPGPU勉強会 LLVM meets GPU
 
20130626 kawasaki.rb NKT77
20130626 kawasaki.rb NKT7720130626 kawasaki.rb NKT77
20130626 kawasaki.rb NKT77
 
Rubyによる本気のGC
Rubyによる本気のGCRubyによる本気のGC
Rubyによる本気のGC
 
Inside frogc in Dart
Inside frogc in DartInside frogc in Dart
Inside frogc in Dart
 
20130819 jjugnslt
20130819 jjugnslt20130819 jjugnslt
20130819 jjugnslt
 
第8回KPF発表資料
第8回KPF発表資料第8回KPF発表資料
第8回KPF発表資料
 
node-gypを使ったネイティブモジュールの作成
node-gypを使ったネイティブモジュールの作成node-gypを使ったネイティブモジュールの作成
node-gypを使ったネイティブモジュールの作成
 
Rubinius Under a Microscope
Rubinius Under a MicroscopeRubinius Under a Microscope
Rubinius Under a Microscope
 
メタメタプログラミングRuby
メタメタプログラミングRubyメタメタプログラミングRuby
メタメタプログラミングRuby
 
20130626 kawasaki.rb NKT77
20130626 kawasaki.rb NKT7720130626 kawasaki.rb NKT77
20130626 kawasaki.rb NKT77
 
怠惰なRubyistへの道 fukuoka rubykaigi01
怠惰なRubyistへの道 fukuoka rubykaigi01怠惰なRubyistへの道 fukuoka rubykaigi01
怠惰なRubyistへの道 fukuoka rubykaigi01
 

More from Taisuke Yamada

ウェブパフォーマンス計測の落とし穴
ウェブパフォーマンス計測の落とし穴ウェブパフォーマンス計測の落とし穴
ウェブパフォーマンス計測の落とし穴Taisuke Yamada
 
DIY Akamai Globe in 50 Minutes
DIY Akamai Globe in 50 MinutesDIY Akamai Globe in 50 Minutes
DIY Akamai Globe in 50 MinutesTaisuke Yamada
 
ウェブサイト最適化101 - 正しく測ろうあなたのサイト -
ウェブサイト最適化101 - 正しく測ろうあなたのサイト -ウェブサイト最適化101 - 正しく測ろうあなたのサイト -
ウェブサイト最適化101 - 正しく測ろうあなたのサイト -Taisuke Yamada
 
Quick QUIC Technical Update (2017)
Quick QUIC Technical Update (2017)Quick QUIC Technical Update (2017)
Quick QUIC Technical Update (2017)Taisuke Yamada
 
IoT Deep Dive - Be an IoT Developer for an Hour
IoT Deep Dive - Be an IoT Developer for an HourIoT Deep Dive - Be an IoT Developer for an Hour
IoT Deep Dive - Be an IoT Developer for an HourTaisuke Yamada
 
Pythonではじめるソフトウェア無線
Pythonではじめるソフトウェア無線Pythonではじめるソフトウェア無線
Pythonではじめるソフトウェア無線Taisuke Yamada
 
Getting Started with SDR in Python
Getting Started with SDR in PythonGetting Started with SDR in Python
Getting Started with SDR in PythonTaisuke Yamada
 
VSCode Remoteでも画像コピペがしたいです!
VSCode Remoteでも画像コピペがしたいです!VSCode Remoteでも画像コピペがしたいです!
VSCode Remoteでも画像コピペがしたいです!Taisuke Yamada
 
Infinite Debian - Platform for mass-producing system every second
Infinite Debian - Platform for mass-producing system every secondInfinite Debian - Platform for mass-producing system every second
Infinite Debian - Platform for mass-producing system every secondTaisuke Yamada
 
Invitation to Kernel Parameter and Code Exploration
Invitation to Kernel Parameter and Code ExplorationInvitation to Kernel Parameter and Code Exploration
Invitation to Kernel Parameter and Code ExplorationTaisuke Yamada
 
Charity Items from Debian JP Project
Charity Items from Debian JP ProjectCharity Items from Debian JP Project
Charity Items from Debian JP ProjectTaisuke Yamada
 
mod_auth_ticket - Bringing Single-Sign-On to lighttpd
mod_auth_ticket - Bringing Single-Sign-On to lighttpdmod_auth_ticket - Bringing Single-Sign-On to lighttpd
mod_auth_ticket - Bringing Single-Sign-On to lighttpdTaisuke Yamada
 
Introduction to Initramfs - Initramfs-tools and Dracut
Introduction to Initramfs - Initramfs-tools and DracutIntroduction to Initramfs - Initramfs-tools and Dracut
Introduction to Initramfs - Initramfs-tools and DracutTaisuke Yamada
 
Hadoop book-2nd-ch3-update
Hadoop book-2nd-ch3-updateHadoop book-2nd-ch3-update
Hadoop book-2nd-ch3-updateTaisuke Yamada
 
The CAcert Project - An Invitation to CAcert ATE in OSC/Tokyo 2011 (EN)
The CAcert Project - An Invitation to CAcert ATE in OSC/Tokyo 2011 (EN)The CAcert Project - An Invitation to CAcert ATE in OSC/Tokyo 2011 (EN)
The CAcert Project - An Invitation to CAcert ATE in OSC/Tokyo 2011 (EN)Taisuke Yamada
 
The CAcert Project - An Invitation to CAcert ATE at OSC/Tokyo 2011 (JP)
The CAcert Project - An Invitation to CAcert ATE at OSC/Tokyo 2011 (JP)The CAcert Project - An Invitation to CAcert ATE at OSC/Tokyo 2011 (JP)
The CAcert Project - An Invitation to CAcert ATE at OSC/Tokyo 2011 (JP)Taisuke Yamada
 
201012 cacert-at-tokyodebian
201012 cacert-at-tokyodebian201012 cacert-at-tokyodebian
201012 cacert-at-tokyodebianTaisuke Yamada
 
Nilfs usage-report-and-comparison-at-tokyodebian
Nilfs usage-report-and-comparison-at-tokyodebianNilfs usage-report-and-comparison-at-tokyodebian
Nilfs usage-report-and-comparison-at-tokyodebianTaisuke Yamada
 
Casual Web-browsing with gPXE and SYSLINUX
Casual Web-browsing with gPXE and SYSLINUXCasual Web-browsing with gPXE and SYSLINUX
Casual Web-browsing with gPXE and SYSLINUXTaisuke Yamada
 

More from Taisuke Yamada (20)

ウェブパフォーマンス計測の落とし穴
ウェブパフォーマンス計測の落とし穴ウェブパフォーマンス計測の落とし穴
ウェブパフォーマンス計測の落とし穴
 
DIY Akamai Globe in 50 Minutes
DIY Akamai Globe in 50 MinutesDIY Akamai Globe in 50 Minutes
DIY Akamai Globe in 50 Minutes
 
ウェブサイト最適化101 - 正しく測ろうあなたのサイト -
ウェブサイト最適化101 - 正しく測ろうあなたのサイト -ウェブサイト最適化101 - 正しく測ろうあなたのサイト -
ウェブサイト最適化101 - 正しく測ろうあなたのサイト -
 
Quick QUIC Technical Update (2017)
Quick QUIC Technical Update (2017)Quick QUIC Technical Update (2017)
Quick QUIC Technical Update (2017)
 
IoT Deep Dive - Be an IoT Developer for an Hour
IoT Deep Dive - Be an IoT Developer for an HourIoT Deep Dive - Be an IoT Developer for an Hour
IoT Deep Dive - Be an IoT Developer for an Hour
 
Pythonではじめるソフトウェア無線
Pythonではじめるソフトウェア無線Pythonではじめるソフトウェア無線
Pythonではじめるソフトウェア無線
 
Getting Started with SDR in Python
Getting Started with SDR in PythonGetting Started with SDR in Python
Getting Started with SDR in Python
 
VSCode Remoteでも画像コピペがしたいです!
VSCode Remoteでも画像コピペがしたいです!VSCode Remoteでも画像コピペがしたいです!
VSCode Remoteでも画像コピペがしたいです!
 
InfiniBand on Debian
InfiniBand on DebianInfiniBand on Debian
InfiniBand on Debian
 
Infinite Debian - Platform for mass-producing system every second
Infinite Debian - Platform for mass-producing system every secondInfinite Debian - Platform for mass-producing system every second
Infinite Debian - Platform for mass-producing system every second
 
Invitation to Kernel Parameter and Code Exploration
Invitation to Kernel Parameter and Code ExplorationInvitation to Kernel Parameter and Code Exploration
Invitation to Kernel Parameter and Code Exploration
 
Charity Items from Debian JP Project
Charity Items from Debian JP ProjectCharity Items from Debian JP Project
Charity Items from Debian JP Project
 
mod_auth_ticket - Bringing Single-Sign-On to lighttpd
mod_auth_ticket - Bringing Single-Sign-On to lighttpdmod_auth_ticket - Bringing Single-Sign-On to lighttpd
mod_auth_ticket - Bringing Single-Sign-On to lighttpd
 
Introduction to Initramfs - Initramfs-tools and Dracut
Introduction to Initramfs - Initramfs-tools and DracutIntroduction to Initramfs - Initramfs-tools and Dracut
Introduction to Initramfs - Initramfs-tools and Dracut
 
Hadoop book-2nd-ch3-update
Hadoop book-2nd-ch3-updateHadoop book-2nd-ch3-update
Hadoop book-2nd-ch3-update
 
The CAcert Project - An Invitation to CAcert ATE in OSC/Tokyo 2011 (EN)
The CAcert Project - An Invitation to CAcert ATE in OSC/Tokyo 2011 (EN)The CAcert Project - An Invitation to CAcert ATE in OSC/Tokyo 2011 (EN)
The CAcert Project - An Invitation to CAcert ATE in OSC/Tokyo 2011 (EN)
 
The CAcert Project - An Invitation to CAcert ATE at OSC/Tokyo 2011 (JP)
The CAcert Project - An Invitation to CAcert ATE at OSC/Tokyo 2011 (JP)The CAcert Project - An Invitation to CAcert ATE at OSC/Tokyo 2011 (JP)
The CAcert Project - An Invitation to CAcert ATE at OSC/Tokyo 2011 (JP)
 
201012 cacert-at-tokyodebian
201012 cacert-at-tokyodebian201012 cacert-at-tokyodebian
201012 cacert-at-tokyodebian
 
Nilfs usage-report-and-comparison-at-tokyodebian
Nilfs usage-report-and-comparison-at-tokyodebianNilfs usage-report-and-comparison-at-tokyodebian
Nilfs usage-report-and-comparison-at-tokyodebian
 
Casual Web-browsing with gPXE and SYSLINUX
Casual Web-browsing with gPXE and SYSLINUXCasual Web-browsing with gPXE and SYSLINUX
Casual Web-browsing with gPXE and SYSLINUX
 

Recently uploaded

情報処理学会86回全国大会_Generic OAMをDeep Learning技術によって実現するための課題と解決方法
情報処理学会86回全国大会_Generic OAMをDeep Learning技術によって実現するための課題と解決方法情報処理学会86回全国大会_Generic OAMをDeep Learning技術によって実現するための課題と解決方法
情報処理学会86回全国大会_Generic OAMをDeep Learning技術によって実現するための課題と解決方法ssuser370dd7
 
TaketoFujikawa_台本中の動作表現に基づくアニメーション原画システムの提案_SIGEC71.pdf
TaketoFujikawa_台本中の動作表現に基づくアニメーション原画システムの提案_SIGEC71.pdfTaketoFujikawa_台本中の動作表現に基づくアニメーション原画システムの提案_SIGEC71.pdf
TaketoFujikawa_台本中の動作表現に基づくアニメーション原画システムの提案_SIGEC71.pdfMatsushita Laboratory
 
持続可能なDrupal Meetupのコツ - Drupal Meetup Tokyoの知見
持続可能なDrupal Meetupのコツ - Drupal Meetup Tokyoの知見持続可能なDrupal Meetupのコツ - Drupal Meetup Tokyoの知見
持続可能なDrupal Meetupのコツ - Drupal Meetup Tokyoの知見Shumpei Kishi
 
2024 01 Virtual_Counselor
2024 01 Virtual_Counselor 2024 01 Virtual_Counselor
2024 01 Virtual_Counselor arts yokohama
 
2024 02 Nihon-Tanken ~Towards a More Inclusive Japan~
2024 02 Nihon-Tanken ~Towards a More Inclusive Japan~2024 02 Nihon-Tanken ~Towards a More Inclusive Japan~
2024 02 Nihon-Tanken ~Towards a More Inclusive Japan~arts yokohama
 
20240326_IoTLT_vol109_kitazaki_v1___.pdf
20240326_IoTLT_vol109_kitazaki_v1___.pdf20240326_IoTLT_vol109_kitazaki_v1___.pdf
20240326_IoTLT_vol109_kitazaki_v1___.pdfAyachika Kitazaki
 
「今からでも間に合う」GPTsによる 活用LT会 - 人とAIが協調するHumani-in-the-Loopへ
「今からでも間に合う」GPTsによる 活用LT会 - 人とAIが協調するHumani-in-the-Loopへ「今からでも間に合う」GPTsによる 活用LT会 - 人とAIが協調するHumani-in-the-Loopへ
「今からでも間に合う」GPTsによる 活用LT会 - 人とAIが協調するHumani-in-the-LoopへTetsuya Nihonmatsu
 
IFIP IP3での資格制度を対象とする国際認定(IPSJ86全国大会シンポジウム)
IFIP IP3での資格制度を対象とする国際認定(IPSJ86全国大会シンポジウム)IFIP IP3での資格制度を対象とする国際認定(IPSJ86全国大会シンポジウム)
IFIP IP3での資格制度を対象とする国際認定(IPSJ86全国大会シンポジウム)ssuser539845
 
ARスタートアップOnePlanetの Apple Vision Proへの情熱と挑戦
ARスタートアップOnePlanetの Apple Vision Proへの情熱と挑戦ARスタートアップOnePlanetの Apple Vision Proへの情熱と挑戦
ARスタートアップOnePlanetの Apple Vision Proへの情熱と挑戦Sadao Tokuyama
 

Recently uploaded (12)

情報処理学会86回全国大会_Generic OAMをDeep Learning技術によって実現するための課題と解決方法
情報処理学会86回全国大会_Generic OAMをDeep Learning技術によって実現するための課題と解決方法情報処理学会86回全国大会_Generic OAMをDeep Learning技術によって実現するための課題と解決方法
情報処理学会86回全国大会_Generic OAMをDeep Learning技術によって実現するための課題と解決方法
 
TaketoFujikawa_台本中の動作表現に基づくアニメーション原画システムの提案_SIGEC71.pdf
TaketoFujikawa_台本中の動作表現に基づくアニメーション原画システムの提案_SIGEC71.pdfTaketoFujikawa_台本中の動作表現に基づくアニメーション原画システムの提案_SIGEC71.pdf
TaketoFujikawa_台本中の動作表現に基づくアニメーション原画システムの提案_SIGEC71.pdf
 
持続可能なDrupal Meetupのコツ - Drupal Meetup Tokyoの知見
持続可能なDrupal Meetupのコツ - Drupal Meetup Tokyoの知見持続可能なDrupal Meetupのコツ - Drupal Meetup Tokyoの知見
持続可能なDrupal Meetupのコツ - Drupal Meetup Tokyoの知見
 
2024 01 Virtual_Counselor
2024 01 Virtual_Counselor 2024 01 Virtual_Counselor
2024 01 Virtual_Counselor
 
What is the world where you can make your own semiconductors?
What is the world where you can make your own semiconductors?What is the world where you can make your own semiconductors?
What is the world where you can make your own semiconductors?
 
2024 02 Nihon-Tanken ~Towards a More Inclusive Japan~
2024 02 Nihon-Tanken ~Towards a More Inclusive Japan~2024 02 Nihon-Tanken ~Towards a More Inclusive Japan~
2024 02 Nihon-Tanken ~Towards a More Inclusive Japan~
 
20240326_IoTLT_vol109_kitazaki_v1___.pdf
20240326_IoTLT_vol109_kitazaki_v1___.pdf20240326_IoTLT_vol109_kitazaki_v1___.pdf
20240326_IoTLT_vol109_kitazaki_v1___.pdf
 
「今からでも間に合う」GPTsによる 活用LT会 - 人とAIが協調するHumani-in-the-Loopへ
「今からでも間に合う」GPTsによる 活用LT会 - 人とAIが協調するHumani-in-the-Loopへ「今からでも間に合う」GPTsによる 活用LT会 - 人とAIが協調するHumani-in-the-Loopへ
「今からでも間に合う」GPTsによる 活用LT会 - 人とAIが協調するHumani-in-the-Loopへ
 
2024 04 minnanoito
2024 04 minnanoito2024 04 minnanoito
2024 04 minnanoito
 
IFIP IP3での資格制度を対象とする国際認定(IPSJ86全国大会シンポジウム)
IFIP IP3での資格制度を対象とする国際認定(IPSJ86全国大会シンポジウム)IFIP IP3での資格制度を対象とする国際認定(IPSJ86全国大会シンポジウム)
IFIP IP3での資格制度を対象とする国際認定(IPSJ86全国大会シンポジウム)
 
ARスタートアップOnePlanetの Apple Vision Proへの情熱と挑戦
ARスタートアップOnePlanetの Apple Vision Proへの情熱と挑戦ARスタートアップOnePlanetの Apple Vision Proへの情熱と挑戦
ARスタートアップOnePlanetの Apple Vision Proへの情熱と挑戦
 
2024 03 CTEA
2024 03 CTEA2024 03 CTEA
2024 03 CTEA
 

Hacking Ruby with Python

  • 1. Hacking Ruby with Python @tyamadajp
  • 5. みなさんオススメのデバッガは? 0. p+? (?!) 1. debug.rb? (旧型) 2. ruby-debug? (普通) 3. rb-trepanning? (新型) 4. others? #ベースの機能を生かした # JRuby, Rubinius 用のとかも #ありますよね
  • 11. さて今宵のデバッガは・・・ GDB/Python 明日の Ruby のために、 今夜は Python
  • 13. こわくないよ!> GDB/Python 1. GDB を 100% API control → ブレークポイントの操作とか 2. GDB そのものも拡張  →新コマンド追加 / (gdb)...  →簡易関数の追加 / $func(...)  → print ハイジャック / pretty printer
  • 14. こんな感じ(実装例) (gdb) p self $299 = (struct RTypedData *) 0x64b2c0, type=iseq ($300), data=0x731ee0 ($301) (gdb) pp self $302 = (struct RTypedData *) 0x64b2c0, type=iseq ($303), data=0x731ee0 ($304) $305 = (const rb_data_type_t *) 0x7ffff7dbe780 $306 = (rb_iseq_t *) 0x731ee0, <compiled>:3, type=ISEQ_TYPE_TOP ・・・まあ色々デコードしてくれます
  • 15. それ $RUBY/.gdbinit でできるよ? ええ、あるのですが・・・ ・主力は内蔵 eval や dump 関数? ・なので展開能力が控えめ ( ぬるぽ避け? )   (gdb) rp recv   T_CLASS: $1156 = (struct RClass *) 0x655310       →ソース読解の道具が欲しかった       →自分でデコードするのがよい練習
  • 16. ぬるぽを恐れず何でも展開 (gdb) pp recv $1158 = (struct RClass *) 0x655310 [Time] dump: {basic = {flags = 2, klass = 6640360}, ptr=0x6e4e20, m_tbl=0x6e4e40, iv_index_tbl=0x0} m_tbl: +, -, <=>, _dump, asctime, ctime, … (gdb) pp ruby_current_thread->cfp->iseq 2 $1072 = (rb_iseq_t *) 0x75c9c0, MAIN, /home/tai/tarai.rb:1(p=0x70a260/$1073, l=0x70a260/$1074) line#0003: VALUE ラップもの、 ID 、 $1075 putstring NODE 、 rb_iseq_t 、 rb_vm_t... 自動で型判定し p or pp で $1076 getclassvariable … 中身を徹底表示
  • 17. GDB script ではダメですか? ・ まともな制御構文がない  → if else if else if else end end end ・ スコープ概念が(ほとんど)ない ・ 遅い。当人比で最大 100+ 倍以上 ・ 限りなく貧弱なデータ操作機能とライブラリ      「 GDB script がやられたか・・・」      「所詮あやつは言語以前の存在」
  • 18. GDB Python API - basic import gdb # vmは gdb.Value オブジェクトだが rb_vm_t* の型を保持 vm = gdb.parse_and_eval(“ruby_current_vm”) # これも gdb.Value オブジェクトだが、 rb_thread_t* の型を維持 th = vm['running_thread'] # いわゆる構造体ダンプ :(gdb) p *ruby_current_vm print(vm.dereference()) # ポインタ演算したいときには char* にしたり pointer_op(th.cast(gdb.lookup_type(“char”).pointer())) # CLI 側で参照できるよう $ や $N に戻したりもできる gdb.execute(“p (%s)%ld” % (th.type, long(th))) gdb.execute(“set $foo = %ld” % long(th))
  • 19. GDB Command – extending gdb import gdb class HelloCommand(gdb.Command): """Sample GDB command in Python""" def __init__(self): super(self.__class__, self).__init__( "hello-cmd", gdb.COMMAND_OBSCURE) def invoke(self, arg, from_tty): args = gdb.string_to_argv(arg) print("arg is [%s]" % ", ".join(args)) HelloCommand() 拡張1つにクラスを1つ ※ ロードは (gdb) python execfile(“hello.py”) などで
  • 20. GDB Command – easy way import gdb @gdbcommand(“hello-cmd“) def hello(*args): """ Sample GDB command in Python Usage: hello-cmd args """ print("arg is [%s]" % ", ".join(args)) バイト数 50% カット!
  • 21. GDB Command – easy way, impl def gdbcommand(*args): """Turns decorated function into GDB command""" opts = [args[0], gdb.COMMAND_OBSCURE] #FIXME def wrap(func): name = opts[0] or func.func_name def init(self): super(self.__class__, self).__init__(name, *opts[1:]) def invoke(self, arg, from_tty): func(*gdb.string_to_argv(arg)) type("", (gdb.Command,), { '__doc__': func.__doc__, '__init__': init, 'invoke': invoke, })() return func return wrap デコレータ、 Ruby にも 本気で欲しくなったり ※ スライドに収めるため機能とコードをカットしています。バグってたらごめんなさい
  • 22. GDB Pretty Printer class HelloPrinter(object): """Print (hello_t *) type""" def __init__(self, val): self.val = val # 表示する文字列又は gdb.Value を返す。後者の場合は # 再度 pretty-printing 処理が試みられる。以下はダミー。 def to_string(self): return "hogehoge" # 表示ヒント。 "array", "map", "string" のいずれかを返す def display_hint(self): return "string" # カスタムプリンタが反応できるようチェッカを登録 def ckval(gv): if gv.type == gdb.lookup_type("hello_t").pointer(): return HelloPrinter(gv) return None print 以外にも、あらゆる gdb.pretty_printers.append(ckval) 表示処理に適用される
  • 23. おまけ: Ruby と Python の狂演 $ rlwrap gdb -q -readnow --args ./ruby1.9.1 tarai.rb (gdb) b vm_exec (gdb) run (gdb) python sys.argv = [“gdb”] # GDB 側の漏れ対応 (gdb) python execfile("/usr/bin/ipython") IPython 0.10.2 -- An enhanced Interactive Python. In [1]: from gdb import * In [2]: vm = parse_and_eval("ruby_current_vm") In [3]: vm Out[3]: <gdb.Value object at 0x207bb70> In [4]: p vm['main_thread'].type struct rb_thread_struct * 補完処理が壊れたり、単に GDB/Python スクリプト 書くよりバグ率高いですが、変態的な可能性を感じる
  • 24. おまけ: gdb.rb – GDB/Ruby in Py* https://github.com/tmm1/gdb.rb  「 gdb hooks for MRI/REE (and some for YARV) 」 (gdb) b vm_exec if $interactive == 0 (gdb) run (gdb) set $interactive = 1 #自己呼び出しのブロック防止 (gdb) python execfile("ruby-gdb.py") (gdb) ruby eval Thread.list [#<Thread:0x00000000650cc0 run>] (gdb) ruby objects HEAPS 24 SLOTS 9816 実は金曜日に発見して LIVE 2717 (27.68%) かなりへこんだ。 FREE 7099 (72.32%) Ruby 内部の機能をフルに 使って自分自身をデバッグ complex 1 (0.04%) bignum 2 (0.07%)
  • 25. まとめ 1. Ruby のデバッグ・学習に使ってみた 2. GDB/Python は強力なツール 3.正直わけがわからないよ! 「明日の Ruby のために、今夜は Python 」 参考文献: ・ sourceware.org/gdb/onlinedocs/gdb/Python-API.html ・ sourceware.org/gdb/wiki/PythonGdbTutorial ・ gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/python/