美文网首页
iOS调试——Chisel

iOS调试——Chisel

作者: coderanger | 来源:发表于2017-04-21 13:43 被阅读0次

    Chisel是facebook开源的辅助xcode进行iOS开发调试的工具,包含一系列更加有用的lldb命令,而且Chisel还支持添加本地以及自定义命令。本文从工具介绍开始,带大家认识并使用这一强大工具。

    Chisel 简介

    github地址

    安装

    直接按照官方文档进行:

    1. 安装Homebrew
    ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
    
    1. 安装Chisel
    brew update
    brew install chisel
    
    1. 更新.lldbinit
      .lldbinit文件是lldb启动之前加载的文件,用于lldb的初始化,每次lldb启动都会加载。安装chisel成功之后,终端会打印如下提示,按照提示,将启动chisel的命令复制到.lldbinit文件中。


      chisel安装.png

      我是通过如下命令直接将上面的命令写入文件中(>>表示追加到文件尾,如果你已经添加过则无需再次添加)

    echo command script import /usr/local/opt/chisel/libexec/fblldb.py >> ~/.lldbinit
    
    1. 重启xcode并check
      check方法有两种,第一种是打开终端依次输入:llbd<enter>,help<enter>;第二种方法是打开xcode,打断点并执行到断点处,输入help命令。滚动help的结果,当找到Current user-defined commands:一行,即表示安装成功。


      chisel安装check.png

    Chisel常用命令简介

    • pmethods
      print the class and instance methods of a class.

    • pclass
      Print the inheritance starting from an instance of any class.

    • poobjc
      Print the expression result, with the expression run in an ObjC++ context. (Shortcut for "expression -O -l ObjC++ -- " ).

    • pviews
      Print the recursion description of <aView>.

    • pcells
      Print the visible cells of the highest table view in the hierarchy.

    • pblock
      Print the block`s implementation address and signature.

    • mask
      Add a transparent rectangle to the window to reveal a possibly obscured or hidden view or layer's bounds

    • border
      Draws a border around <viewOrLayer>. Color and width can be optionally provided. Additionally depth can be provided in order to recursively border subviews.

    • show
      Show a view or layer.

    添加本地及自定义命令

    参考官方文档,这里整理出基本步骤如下:

    1. 开发命令脚本
      官方文档提供了一个example(源码贴在下面方便大家阅读)
    2. 更新.lldbinit
      同Chisel安装完成后的步骤一样,需要将初始化的命令同步到.lldbinit文件中。
    3. check命令
      同check Chisel是否安装成功的方法一样。
    #!/usr/bin/python
    # Example file with custom commands, located at /magical/commands/example.py
    
    import lldb
    import fblldbbase as fb
    
    def lldbcommands():
      return [ PrintKeyWindowLevel() ]
      
    class PrintKeyWindowLevel(fb.FBCommand):
      def name(self):
        return 'pkeywinlevel'
        
      def description(self):
        return 'An incredibly contrived command that prints the window level of the key window.'
        
      def run(self, arguments, options):
        # It's a good habit to explicitly cast the type of all return
        # values and arguments. LLDB can't always find them on its own.
        lldb.debugger.HandleCommand('p (CGFloat)[(id)[(id)[UIApplication sharedApplication] keyWindow] windowLevel]')
    

    最后,Enjoy yourself!

    相关文章

      网友评论

          本文标题:iOS调试——Chisel

          本文链接:https://www.haomeiwen.com/subject/vgxqattx.html