OCLint自定义规则的调试方法

上一篇说到的如何自己写一个OCLint规则,但是没有提到调试的方法。用C++写程序如果没有调试方法那简直是噩梦,所以这里说一下如何调试。
其实如何在Xcode上调试OClint自定义规则,就是如何在Xcode上调试dylib的问题。
这个问题Google一下就知道了,比如搜索“How to debug dylib with Xcode?”这里有一个靠谱的回答“点击这里

I faced the same problem and no one of the previous answer worked for my case so I share my solution (for Xcode):
If you need to debug a c/c++ dylib which is loaded by an external (executable) program:
First be sure that your dylib is build with the same architecture as your external program.
Then Go to --> Product —>Scheme—>Edit scheme
Got to Tab Run(Debug) and check "Debug Executable" , then select into the dropdown button your external program as executable. Then check "Launch Automatically"
Additionally if you program needs extra argument you can add it into the "Arguments" tab.
Finally you set some breakpoints to your c source file and finally click run.

我试着上面的回答做的一下发现可以,下面总结一下步骤:
这里写图片描述

这里写图片描述

图中的参数如下,测试代码debug.m放到OCLint执行程序的地方(比较蛋疼,不知有没有更好的方式),要自己配置自己的目录:

-R=/Users/David/code/learn-iOS/oclint/oclint-xcoderules/rules.dl/Debug  /Users/David/code/learn-iOS/oclint/oclint-xcoderules/debug.m -- -x objective-c

下面来一张调试图证明一下可以调试:
这里写图片描述

好啦,希望能够帮到大家
有问题可以回复我,或邮件给我。祝大家天天没bug

回复中有人问oclintexe是什么,在上文中写的是“可以执行的oclint程序”,不好意思,没有描述清楚,这其实是说就是oclint。至于为什么文中写成了oclintexe,是因为当时我的电脑编译生成的oclint没有执行权限,我就复制了一份oclint,重命名为oclintexe。如下图,这个realse目录就是编译oclint后的生成的,我把oclint-0.13 复制并重命名为oclintexe,而且加了可执行权限(给大家造成困扰很抱歉)

这里写图片描述

有小伙伴问我要源码,文中涉及的代码部分(包括上一篇oclint 文章),其实是oclint github上仓库的代码,还有就是一些自己写的帮助大家进行编译调试的脚本,这些脚本文中都有列出。
再者就是脚手架自动生成的代码,生成方法和步骤文中都有具体说明。
完整demo“检测block中是否有self”源码,如果大家需要,可以到我的github上去下载。顺便欢求个星星,嘿嘿,商业互吹~

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 8
    评论
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值