iOS调试——Chisel

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!

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • [转]浅谈LLDB调试器文章来源于:http://www.cocoachina.com/ios/20150126/...
    loveobjc阅读 7,493评论 2 6
  • Chisel 调试工具,Facebook开源的一款lldb调试工具-->GitHub 安装Chisel 1.安装h...
    黄二瓜阅读 3,375评论 1 1
  • 马上就要国庆了,提前祝大家国庆快乐!! 前两天在gitHub上面发现了一个调试的三方框架,Chisel,由face...
    小明的知识库阅读 4,587评论 0 51
  • LLDB的Xcode默认的调试器,它与LLVM编译器一起,带给我们更丰富的流程控制和数据检测的调试功能。平时用Xc...
    CoderSC阅读 5,269评论 0 2
  • 1.顺便问一下,你们互相认识吗? 미안하지만 서로 아는 사이입니까? 2. 我很愿意为你引见我的朋友。 저의 친...
    韩语小助手阅读 3,012评论 0 3

友情链接更多精彩内容