Oracle® Developer Studio 12.5:代码分析器用户指南

退出打印视图

更新时间: 2016 年 6 月
 
 

为问题设置标签

下节介绍使用标签对您的问题进行排序和显示的典型工作流。

如何为问题设置标签

  1. 使用 –-showhash 选项显示与问题关联的散列。
  2. 确定要为其设置标签的问题及其散列字符串。
  3. 为二进制文件创建 labels 子目录。

    例如,如果您的二进制文件为 a.out,请创建 a.out.analyze/labels

  4. 在以下三个文件中放入要设置标签的问题的 (hash, label) 对。
    • a.out.analyze/labels/static_report_labels

    • a.out.analyze/labels/dynamic_report_labels

    • a.out.analyze/labels/coverage_report_labels

    每个目录将分别包含静态、动态和覆盖报告中的问题。标签文件的格式为 hash-name:label-name:comment

    下面是一个标签文件示例:

    $ cat codean.analyze/labels/dynamic_report_labels 
        54f3a6f0160dceb58156be03d07090a2:false_positive:bug 12345678 has been filed
        3b7ee9d573847e2dbf80652b7a89026e:false_positive
        6c575302146d147f5f1d2d2e6e1710a5:false_positive

    使用 codean 处理 a.out 的报告时,如果某个问题存在匹配标签,缺省情况下标签名称将作为附加信息显示在该问题的后面。

如何使用标签显示或隐藏问题

  1. 要显示某个问题,请使用 –-showlabel 选项。

    例如,如果只想看到误报:

    % codean --showlabel false_positive a.out
  2. 要隐藏某个问题,请使用 –-hidelabel 选项。

    例如,如果要隐藏标签为 wont_be_fixed 的问题:

    % codean --hidelabel wont_be_fixed a.out

如何查找特定散列

  1. 要查明标签文件中的特定散列是否过期,请使用 –-findhash hash-string 告知 codean 仅显示与该散列相匹配的问题。
  2. 要查找多个散列,请列出 hash-strings(用冒号 (:) 隔开)。例如:
    % codean --findhash 54f3a6f0160dceb58156be03d07090a2:3b7ee9d573847e2dbf80652b7a89026e a.out
示例 2  使用其他标签

下面是一个使用其他标签的示例:

 $ cat t.c
#include <stdlib.h>

int main()
{
int *p = (int *)malloc(sizeof(int));
int i = *p;
free(p);
return i;
}

$ cc -g t.c
$ discover -a -o a.out.disc a.out
$ ./a.out.disc

$ codean -d --showhash a.out
DYNAMIC report of a.out:
ERROR 1 (UMR): accessing uninitialized data in "*p" at address 0x1001208e0 (4 bytes) on the heap:
hash: 79b6e1b242a057deec8762328b6860e6
main() + 0xac <t.c : 6>
3: int main()
4: {
5: int *p = (int *)malloc(sizeof(int));
6:=> int i = *p;
7: free(p);
_start() + 0x108
was allocated at (4 bytes):
main() + 0x20 <t.c : 5>
1: #include <stdlib.h>
3: int main()
4: {
5:=> int *p = (int *)malloc(sizeof(int));
6: int i = *p;
_start() + 0x108
DISCOVER SUMMARY for a.out: 1 non-leak issues, 0 leak issues
unique errors : 1 (1 total)
unique warnings : 0 (0 total)
unique leaks : 0 (0 blocks, 0 bytes)
unique possible leaks : 0 (0 blocks, 0 bytes)

$ cat a.out.analyze/labels/dynamic_report_labels
79b6e1b242a057deec8762328b6860e6:verified:I have verified that this is a bug.

$ codean -d a.out
DYNAMIC report of a.out:
ERROR 1 (UMR): accessing uninitialized data in "*p" at address 0x1001208e0 (4 bytes) on the heap:
label: verified "I have verified that this is a bug."
main() + 0xac <t.c : 6>
3: int main()
4: {
5: int *p = (int *)malloc(sizeof(int));
6:=> int i = *p;
7: free(p);
_start() + 0x108
was allocated at (4 bytes):
main() + 0x20 <t.c : 5>
1: #include <stdlib.h>
3: int main()
4: {
5:=> int *p = (int *)malloc(sizeof(int));
6: int i = *p;
_start() + 0x108
DISCOVER SUMMARY for a.out: 1 non-leak issues, 0 leak issues
unique errors : 1 (1 total)
unique warnings : 0 (0 total)
unique leaks : 0 (0 blocks, 0 bytes)
unique possible leaks : 0 (0 blocks, 0 bytes)

$ codean -d --showlabel verified a.out
DYNAMIC report of a.out:
ERROR 1 (UMR): accessing uninitialized data in "*p" at address 0x1001208e0 (4 bytes) on the heap:
label: verified "I have verified that this is a bug."
main() + 0xac <t.c : 6>
3: int main()
4: {
5: int *p = (int *)malloc(sizeof(int));
6:=> int i = *p;
7: free(p);
_start() + 0x108
was allocated at (4 bytes):
main() + 0x20 <t.c : 5>
1: #include <stdlib.h>
3: int main()
4: {
5:=> int *p = (int *)malloc(sizeof(int));
6: int i = *p;
_start() + 0x108
DISCOVER SUMMARY for a.out: 1 non-leak issues, 0 leak issues
unique errors : 1 (1 total)
unique warnings : 0 (0 total)
unique leaks : 0 (0 blocks, 0 bytes)
unique possible leaks : 0 (0 blocks, 0 bytes)

$ codean -d --hidelabel verified a.out
DYNAMIC report of a.out:
DISCOVER SUMMARY for a.out: 0 issues found (1 issues suppressed)