欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

OCLint自定义规则的调试方法

程序员文章站 2022-07-13 21:52:19
...

上一篇说到的如何自己写一个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.

我试着上面的回答做的一下发现可以,下面总结一下步骤:
OCLint自定义规则的调试方法

OCLint自定义规则的调试方法

图中的参数如下,测试代码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

下面来一张调试图证明一下可以调试:
OCLint自定义规则的调试方法

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

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

OCLint自定义规则的调试方法

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