inferTraceBugs 命令
查看看详细错误详细信息,一般我们可能直接去源码文件去看这些文件,但是infer也为我们提供inferTraceBugs命令来查看.
命令详细说明:
localhost:ios_hello wuxian$ inferTraceBugs --help
usage: inferTraceBugs [-h] [-o <directory>] [--only-show] [--no-source]
[--select N] [--max-level N]
Explore the error traces in Infer reports.
optional arguments:
-h, --help show this help message and exit
-o <directory>, --out <directory>
Set the Infer results directory
--only-show Show the list of reports and exit
--no-source Do not print code excerpts
--select N Select bug number N. If omitted, prompts you for
input.
--max-level N Level of nested procedure calls to show. Can be "max",
in which case all levels are shown. If omitted,
prompts you for input
inferTraceBugs命令定位某个问题的具体信息,你可以通过上面的参数直接定位,也可以缺省然后通过提示一步一步进入详细信息界面.
我们采用缺省的方式(inferTraceBugs)一步一步了解该命令的使用方式
执行该命令,首先列举出所有的问题信息
localhost:ios_hello wuxian$ inferTraceBugs
0. /Users/wuxian/Downloads/infer-osx-v0.1.0/infer/examples/ios_hello/HelloWorldApp/AppDelegate.m:20: error: MEMORY_LEAK
memory dynamically allocated to shadowPath by call to CGPathCreateWithRect() at line 20, column 28 is not reachable after line 20, column 5
1. /Users/wuxian/Downloads/infer-osx-v0.1.0/infer/examples/ios_hello/HelloWorldApp/AppDelegate.m:25: error: RESOURCE_LEAK
resource acquired to fp by call to fopen() at line 25, column 8 is not released after line 25, column 5
2. /Users/wuxian/Downloads/infer-osx-v0.1.0/infer/examples/ios_hello/HelloWorldApp/AppDelegate.m:29: warning: PARAMETER_NOT_NULL_CHECKED
Parameter callback is not checked for null, there could be a null pointer dereference: pointer callback could be null and is dereferenced at line 29, column 5
3. /Users/wuxian/Downloads/infer-osx-v0.1.0/infer/examples/ios_hello/HelloWorldApp/AppDelegate.m:34: error: NULL_DEREFERENCE
pointer str last assigned on line 33 could be null and is dereferenced at line 34, column 12
4. /Users/wuxian/Downloads/infer-osx-v0.1.0/infer/examples/ios_hello/HelloWorldApp/AppDelegate.m:39: error: PREMATURE_NIL_TERMINATION_ARGUMENT
pointer str last assigned on line 38 could be nil which results in a call to arrayWithObjects: with 1 arguments instead of 3 (nil indicates that the last argument of this variadic method has been reached) at line 39, column 12
5. /Users/wuxian/Downloads/infer-osx-v0.1.0/infer/examples/ios_hello/HelloWorldApp/Hello.m:20: error: NULL_DEREFERENCE
pointer hello last assigned on line 19 could be null and is dereferenced at line 20, column 12
6. /Users/wuxian/Downloads/infer-osx-v0.1.0/infer/examples/ios_hello/HelloWorldApp/Hello.m:25: warning: IVAR_NOT_NULL_CHECKED
Instance variable hello -> _hello is not checked for null, there could be a null pointer dereference: pointer ret_hello last assigned on line 24 could be null and is dereferenced at line 25, column 12
7. /Users/wuxian/Downloads/infer-osx-v0.1.0/infer/examples/ios_hello/HelloWorldApp/Hello.m:30: warning: PARAMETER_NOT_NULL_CHECKED
Parameter hello is not checked for null, there could be a null pointer dereference: pointer ret_hello last assigned on line 29 could be null and is dereferenced at line 30, column 12
–select
上面的信息显示完成后,会有一个交互行,需要你输入数字,这个数字是上面列举的问题的序号,你不能输入超过列举问题序号的范围,这个交互行就是没有设置–select 参数出现的。
Choose report to display (default=0):
我们输入正确的数字(本例是0-7为有效值),比如:0
Choose report to display (default=0): 0
然后又有一个提示行
–max-level
设置嵌套调用的等级,暂不知道这个参数实际影响,因为我尝试不同的值,结果都一样。
Choose maximum level of nested procedures calls (default=max): max
然后infer会为我们显示这条问题的详细信息:
/Users/wuxian/Downloads/infer-osx-v0.1.0/infer/examples/ios_hello/HelloWorldApp/AppDelegate.m:20: error: MEMORY_LEAK
memory dynamically allocated to shadowPath by call to CGPathCreateWithRect() at line 20, column 28 is not reachable after line 20, column 5
Showing all 2 steps of the trace
/Users/wuxian/Downloads/infer-osx-v0.1.0/infer/examples/ios_hello/HelloWorldApp/AppDelegate.m:19: start of procedure memory_leak_bug
17 @implementation AppDelegate
18
19 > -(void) memory_leak_bug {
20 CGPathRef shadowPath = CGPathCreateWithRect(self.inputView.bounds, NULL);
21 }
/Users/wuxian/Downloads/infer-osx-v0.1.0/infer/examples/ios_hello/HelloWorldApp/AppDelegate.m:20:
18
19 -(void) memory_leak_bug {
20 > CGPathRef shadowPath = CGPathCreateWithRect(self.inputView.bounds, NULL);
21 }
22
上面的交互方式等同于