`
skandhas
  • 浏览: 35053 次
  • 性别: Icon_minigender_1
  • 来自: 沈阳
社区版块
存档分类
最新评论

Ruby1.9的隐藏参数"--dump"

    博客分类:
  • Ruby
阅读更多

前几天,我的同事老高在看Ruby1.9.2源码的时候,发现Ruby1.9有一个隐藏参数:"--dump"(注意是两个减号). 下面具体说说这个参数:

 

1. --dump 参数

--dump 可以打印出ruby及指定脚本的相关信息,具体如下:

[version, copyright, usage, yydebug, syntax, parsetree , parsetree_with_comment, insns ]

其中有几项的内容我们已经熟悉,例如:version,copyright,usage. 不过这次我们感兴趣的是parsetree和insns的内容。

 

parsetree -- 打印指定脚本的Parse Tree

insns        -- 打印指定脚本的RubyVM(YARV)指令

 

2. 具体用法举例

假设有一个已经写好的脚本1.rb,存放在C盘。我们可以如下使用"--dump"参数:

ruby --dump parsetree c:\1.rb

 

3.测试结果

测试脚本:

class A
  def hello
    puts 'Hello'
  end
end

A.new.hello

打印RubyVM指令:ruby --dump insns c:\1.rb

输出

== disasm: <RubyVM::InstructionSequence:<main>@c:/1.rb>=================
0000 trace            1                                               (   1)
0002 putspecialobject 3
0004 putnil
0005 defineclass      :A, <class:A>, 0
0009 pop
0010 trace            1                                               (   7)
0012 getinlinecache   19, <ic:0>
0015 getconstant      :A
0017 setinlinecache   <ic:0>
0019 send             :new, 0, nil, 0, <ic:1>
0025 send             :hello, 0, nil, 0, <ic:2>
0031 leave
== disasm: <RubyVM::InstructionSequence:<class:A>@c:/1.rb>==============
0000 trace            2                                               (   1)
0002 trace            1                                               (   2)
0004 putspecialobject 1
0006 putspecialobject 2
0008 putobject        :hello
0010 putiseq          hello
0012 send             :"core#define_method", 3, nil, 0, <ic:0>
0018 trace            4                                               (   5)
0020 leave                                                            (   2)
== disasm: <RubyVM::InstructionSequence:hello@c:/1.rb>==================
0000 trace            8                                               (   2)
0002 trace            1                                               (   3)
0004 putnil
0005 putstring        "Hello"
0007 send             :puts, 1, nil, 8, <ic:0>
0013 trace            16                                              (   4)
0015 leave                                                            (   3)
 

 

打印ParseTree:ruby --dump parsetree c:\1.rb

输出:

###########################################################
## Do NOT use this node dump for any purpose other than  ##
## debug and research.  Compatibility is not guaranteed. ##
###########################################################

# @ NODE_SCOPE (line: 7)
# +- nd_tbl: (empty)
# +- nd_args:
# |   (null node)
# +- nd_body:
#     @ NODE_BLOCK (line: 1)
#     +- nd_head:
#     |   @ NODE_CLASS (line: 1)
#     |   +- nd_cpath:
#     |   |   @ NODE_COLON2 (line: 1)
#     |   |   +- nd_mid: :A
#     |   |   +- nd_head:
#     |   |       (null node)
#     |   +- nd_super:
#     |   |   (null node)
#     |   +- nd_body:
#     |       @ NODE_SCOPE (line: 5)
#     |       +- nd_tbl: (empty)
#     |       +- nd_args:
#     |       |   (null node)
#     |       +- nd_body:
#     |           @ NODE_DEFN (line: 2)
#     |           +- nd_mid: :hello
#     |           +- nd_defn:
#     |               @ NODE_SCOPE (line: 4)
#     |               +- nd_tbl: (empty)
#     |               +- nd_args:
#     |               |   @ NODE_ARGS (line: 2)
#     |               |   +- nd_frml: 0
#     |               |   +- nd_next:
#     |               |   |   @ NODE_ARGS_AUX (line: 2)
#     |               |   |   +- nd_rest: (null)
#     |               |   |   +- nd_body: (null)
#     |               |   |   +- nd_next:
#     |               |   |       (null node)
#     |               |   +- nd_opt:
#     |               |       (null node)
#     |               +- nd_body:
#     |                   @ NODE_FCALL (line: 3)
#     |                   +- nd_mid: :puts
#     |                   +- nd_args:
#     |                       @ NODE_ARRAY (line: 3)
#     |                       +- nd_alen: 1
#     |                       +- nd_head:
#     |                       |   @ NODE_STR (line: 3)
#     |                       |   +- nd_lit: "Hello"
#     |                       +- nd_next:
#     |                           (null node)
#     +- nd_next:
#         @ NODE_BLOCK (line: 7)
#         +- nd_head:
#         |   @ NODE_CALL (line: 7)
#         |   +- nd_mid: :hello
#         |   +- nd_recv:
#         |   |   @ NODE_CALL (line: 7)
#         |   |   +- nd_mid: :new
#         |   |   +- nd_recv:
#         |   |   |   @ NODE_CONST (line: 7)
#         |   |   |   +- nd_vid: :A
#         |   |   +- nd_args:
#         |   |       (null node)
#         |   +- nd_args:
#         |       (null node)
#         +- nd_next:
#             (null node)
 
1
1
分享到:
评论

相关推荐

    class-dump, class-dump-z.exe,class-dump-z win版本

    class-dump, class-dump-z.exe,class-dump-z win版本

    class-dump-z全平台版本(linux、iPhone、Windows)

    class-dump-z全平台版本(linux、iPhone、Windows)

    class-dump-3.5

    class-dump-3.5

    parallel-fastq-dump:并行fastq-dump包装器

    并行fastq转储并行fastq-dump包装器为什么和如何即使您已经拥有更快的资源(网络,IO,CPU),即使您已经下载了sra文件,NCBI ... 所有其他参数将直接传递给fastq-dump ,-- --gzip ,-- --split-files和过滤器按预

    class-dump-z.zip

    class-dump-z.zip资源包分享,支持win/linux/mac/iphone等,提供大家参考使用“使用class-dump-z分析支付宝app”,附链接:http://blog.csdn.net/yiyaaixuexi/article/details/18353423

    linux-ramdump-parser-v2.tar.gz

    2. 到linux-ramdump-parser-v2下 3. sudo ./ramdump-parser.sh Port_COM4 // Port_COM4中包含ramdump对应的vmlinux 4. 会生成out目录,在使用中,如果遇到问题,可以看out/dmesg_TZ.txt来看看log信息

    elasticsearch-dump-6.78.0.tar.gz

    Elasticsearch 数据导入/导出工具,可以用于 ES 的数据备份和迁移

    class-dump-z_0.2-0.tar.gz

    包括了class-dump的mac版,LINUX版,Windows版 具体用法: class-dump -H Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator2.1.sdk/System/Library/CoreServices/SpringBoard.app/...

    class-dump-z

    class-dump工具,针对iOS 导出头文件。

    class-dump-z_0.2-0

    class-dump变种,官方文件下载。支持:iPhone_armv6、linux_x86、mac_x86、win_x86

    elasticsearch-dump-6.79.0.tar.gz

    Elasticsearch 数据导入/导出工具,可以用于 ES 的数据备份和迁移

    class-dump ios9

    解决ios sdk9 无法class-dump导出framework头文件 也可以自己重新编译一份https://github.com/nygard/class-dump

    class-dump-z_0.2-0.tar

    (看到一哥们下载要5分。...class-dump -H Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator2.1.sdk/System/Library/CoreServices/SpringBoard.app/SpringBoard -o ~/Desktop/SpringBoard

    class-dump-3.3.3.dmg

    包括了class-dump的mac版,LINUX版,Windows版 具体用法: class-dump -H Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.1.sdk/System/Library/CoreServices/SpringBoard.app/...

    MemoryAnalyzer-1.9.1.20190826-linux.gtk.x86_64.zip

    配置jvm参数-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/home/mat/ java_pid1089.hprof 手工直接导,PID为进程号 jmap -dump:live,format=b,file= java_pid1089.hprof PID 然后,在linux解压后执行以下命令...

    gcov-dump-1.0.tar.gz

    该程序是从gcc-4.1.2源代码中抽取出来的与gcov-dump相关的文件组成的小项目。希望能对通过gcc覆盖率测试工具GCOV进行覆盖率测试相关工作的同行有些许的帮助。 gcov-dump是一个dump程序,输入是一个gcov的文件,或者....

    dump--txt互转

    dumptxt互转

    Advanced-Windows-Memory-Dump-Analysis-Public

    Advanced-Windows-Memory-Dump-Analysis-Public

    redis-check-dump.exe

    redis-check-dump.exe-

Global site tag (gtag.js) - Google Analytics