Oracle® Developer Studio 12.5: コードアナライザユーザーズガイド

印刷ビューの終了

更新: 2016 年 6 月
 
 

テストスイートでの codean の使用

–-union を使用すると、codean で複数の動的レポートを処理できます。これを使用すると、テストスイートでの discover の実行結果の表示、保存、新しい問題の表示、または修正された問題の表示を行うことができます。次の例は、discover および codean -–union の使用方法を示しています。

discover を使用したテストスイートでのバイナリの準備

  1. discover を使用して a.out に計測機構を組み込みます。
  2. Analytics 出力を選択します: discover -a a.out

    これにより、a.out.analyze/dynamic/ の下にある既存の動的レポートがすべて削除されます。

  3. テストスイートに対して計測機構付きバイナリを実行します。

    デフォルトでは、各実行の結果が別のファイルに保存され、latest レポートが最新のレポートへのシンボリックリンクになります。たとえば、a.out を 5 回実行したあとの a.out.analyze/dynamic/ ディレクトリは次のようになります。

    $ ls -l a.out.analyze/dynamic/
    total 11
    lrwxrwxrwx 1 demoUser demo 18 May 1 15:14 latest -> ./latest.AAAvCaWri
    -rwxrwxrwx 1 demoUser demo 588 Apr 30 10:05 latest.AAACRaOId
    -rwxrwxrwx 1 demoUser demo 587 Apr 15 15:03 latest.AAAQcayId
    -rwxrwxrwx 1 demoUser demo 587 Apr 30 10:05 latest.AAAe5aWId
    -rwxrwxrwx 1 demoUser demo 587 Apr 15 15:03 latest.AAAlCaGId
    -rwxrwxrwx 1 demoUser demo 587 May 1 15:14 latest.AAAvCaWri 

    discover によるレポートの準備が完了したら、codean を使用して a.out.analyze/dynamic/ の下にあるすべての動的レポートを処理できます。

テストスイートでのレポートの表示

個々のレポートを表示するには:

% codean --union -d a.out

codean コマンドは、a.out.analyze/dynamic の下にある個々の動的レポートをすべてアルファベット順に処理します。これによってテキスト出力のみが生成されます (つまり、標準の codean の実行とは異なり、Analytics 出力や HTML 出力が合わせて生成されることはありません)。同じ問題については、どのレポートが存在していても、最初に出現したときにのみ問題の詳細が表示されます。それ以降に出現した場合、codean は次のような限られた情報のみを表示します。

LEAK 1: repeated, 1 blocks, 4 bytes
ERROR 1: repeated 1 time 

discover 情報は詳細レポートの最後に一度だけ表示され、テストスイーツ全体での問題の総数がまとめられています。codean の完全な出力の例は次のとおりです。

$ codean --union -d a.out

Displaying dynamic report of a.out.analyze/dynamic/latest.AAACRaOId:

ERROR 1 (UMR): accessing uninitialized data in "*i" at address 0x8090010 (4 bytes) on the heap at:
main() + 0xe1 <hello.c : 10>
5: {
6: int *i = malloc(sizeof(int));
8: int j = 0;
10:=> j = *i;
12: return 0;
_start() + 0x71
was allocated at (4 bytes):
main() + 0x5e <hello.c : 6>
2: #include <stdio.h>
4: int main()
5: {
6:=> int *i = malloc(sizeof(int));
8: int j = 0;
_start() + 0x71

Displaying dynamic report of a.out.analyze/dynamic/latest.AAAQcayId:

LEAK 1: 1 allocation with total size of 4 bytes
main() + 0x5e <hello.c : 6>
2: #include <stdio.h>
4: int main()
5: {
6:=> int *i = malloc(sizeof(int));
8: int j = 0;
_start() + 0x71
ERROR 1: repeated 1 time

Displaying dynamic report of a.out.analyze/dynamic/latest.AAAe5aWId:

LEAK 1: repeated, 1 blocks, 4 bytes
ERROR 1: repeated 1 time

Displaying dynamic report of a.out.analyze/dynamic/latest.AAAlCaGId:

LEAK 1: repeated, 1 blocks, 4 bytes
ERROR 1: repeated 1 time

Displaying dynamic report of a.out.analyze/dynamic/latest.AAAvCaWri:

LEAK 1: repeated, 1 blocks, 4 bytes
ERROR 1: repeated 1 time

DISCOVER SUMMARY for a.out: 1 non-leak issues, 1 leak issues
unique errors : 1 (5 total)
unique warnings : 0 (0 total)
unique leaks : 1 (4 blocks, 16 bytes)
unique possible leaks : 0 (0 blocks, 0 bytes) 

明らかなリークと可能性のあるリークの扱い方が異なることに注意してください。標準の codean を実行している場合、リークが明らかなリークまたは可能性のあるリークのどちらであるかは、Analytics レポートの信頼値に完全に依存しています。しかし、「テストスイート」の codean を実行している場合、動的レポートのどれかで明らかなリークと判断されたリークは、レポートの信頼値に関係なく、残りのレポートでも明らかなリークと見なされます。次の「テストスイート」の codean と標準の codean のレポートで、LEAK 1 がどのように表示されるかを確認してください。

 $ codean --union -d a.out

Displaying dynamic report of a.out.analyze/dynamic/latest.AAACRaOId:
...

Displaying dynamic report of a.out.analyze/dynamic/latest.AAAQcayId:

LEAK 1: 1 allocation with total size of 4 bytes
main() + 0x5e <hello.c : 6>
2: #include <stdio.h>
4: int main()
5: {
6:=> int *i = malloc(sizeof(int));
8: int j = 0;
_start() + 0x71
...

Displaying dynamic report of a.out.analyze/dynamic/latest.AAAe5aWId:

LEAK 1: repeated, 1 blocks, 4 bytes
...

Displaying dynamic report of a.out.analyze/dynamic/latest.AAAlCaGId:

LEAK 1: repeated, 1 blocks, 4 bytes
...

Displaying dynamic report of a.out.analyze/dynamic/latest.AAAvCaWri:

LEAK 1: repeated, 1 blocks, 4 bytes
...

DISCOVER SUMMARY for a.out: 1 non-leak issues, 1 leak issues
unique errors : 1 (5 total)
unique warnings : 0 (0 total)
unique leaks : 1 (4 blocks, 16 bytes)
unique possible leaks : 0 (0 blocks, 0 bytes)

tests$ codean -d a.out
DYNAMIC report of a.out:
...
LEAK (Possible leak) 1: 1 allocation with total size of 4 bytes
main() + 0x5e <hello.c : 6>
2: #include <stdio.h>
4: int main()
5: {
6:=> int *i = malloc(sizeof(int));
8: int j = 0;
_start() + 0x71
DISCOVER SUMMARY for a.out: 1 non-leak issues, 1 leak issues
unique errors : 1 (1 total)
unique warnings : 0 (0 total)
unique leaks : 0 (0 blocks, 0 bytes)
unique possible leaks : 1 (1 blocks, 4 bytes) 

テストスイートでのレポートの保存

テストスイートでレポートを保存するには:

% codean --save --union -d --tag run1 a.out

a.out.analyze/dynamic/ の下にある各動的レポートは、別のファイルに保存されます。

$ ls -l a.out.analyze/history/run1/
total 15
lrwxrwxrwx 1 demoUser demo 26 Sep 30 11:09 dynamic -> ./dynamic.latest.AAACRaOId
-rw-r--r-- 1 demoUser demo 674 Sep 30 11:09 dynamic.latest.AAACRaOId
-rw-r--r-- 1 demoUser demo 847 Sep 30 11:09 dynamic.latest.AAAQcayId
-rw-r--r-- 1 demoUser demo 847 Sep 30 11:09 dynamic.latest.AAAe5aWId
-rw-r--r-- 1 demoUser demo 847 Sep 30 11:09 dynamic.latest.AAAlCaGId
-rw-r--r-- 1 demoUser demo 847 Sep 30 11:09 dynamic.latest.AAAvCaWri 

テストスイートでのレポートの比較

テストスイートでレポートを比較するには:

% codean --whatisnew --union -d --tag run1 a.out
% codean --whatisfixed --union -d --tag run1 a.out

codean コマンドは、現在 a.out.analyze/dynamic/ の下にあるすべての動的レポートの新しい問題と修正された問題を 1 セットで表示し、a.out.analyze/history/run1/ の下にある保存されたすべての動的なレポートを 1 セットで表示します。次に出力例を示します。


注 -  可能性のあるリークと明らかなリークの扱い方は、テストスイートでのレポートの表示での説明と同じです。
$ codean --whatisnew --union -d --tag run1 a.out
DYNAMIC report of a.out showing new issues:
New issues in a.out.analyze/dynamic/latest.AAARTaOxS:
ERROR 1 (ABR): reading memory beyond array bounds at address 0xfeffdef8 (4 bytes) on the stack at:
main() + 0x68 <hello.c : 11>
6: // int *i = malloc(sizeof(int));
7: int i[30];
9: int j = 0;
11:=> j = i[35];
13: return 0;
_start() + 0x71
New issues in a.out.analyze/dynamic/latest.AAATDaGxS:
ERROR 1 is a new, but repeated error. It was first seen as ERROR 1 in latest.AAARTaOxS.
New issues in a.out.analyze/dynamic/latest.AAArca4wS:
ERROR 1 is a new, but repeated error. It was first seen as ERROR 1 in latest.AAARTaOxS.

DISCOVER SUMMARY for a.out: 1 new non-leak issues, 0 new leak issues
new unique errors : 1 (3 total)
new unique warnings : 0 (0 total)
new unique leaks : 0 (0 blocks, 0 bytes)
new unique possible leaks : 0 (0 blocks, 0 bytes)

tests$ codean --whatisfixed --union -d --tag run1 a.out
DYNAMIC report of a.out showing fixed issues:
Fixed issues in a.out.analyze/history/run1/dynamic.latest.AAACRaOId:
ERROR 1 (UMR): accessing uninitialized data in "*i" at address 0x8090010 (4 bytes) on the heap at:
(Warning: Source files have changed. Source code shown below may not be accurate.)
main() + 0xe1 <hello.c : 10>
6: // int *i = malloc(sizeof(int));
7: int i[30];
9: int j = 0;
11: j = i[35];
_start() + 0x71
was allocated at (4 bytes):
main() + 0x5e <hello.c : 6>
2: #include <stdio.h>
4: int main()
5: {
6:=> // int *i = malloc(sizeof(int));
7: int i[30];
_start() + 0x71
Fixed issues in a.out.analyze/history/run1/dynamic.latest.AAAQcayId:
ERROR 1 is a fixed, but repeated error. It was first seen as ERROR 1 in dynamic.latest.AAACRaOId.
LEAK 1: 1 allocation with total size of 4 bytes
(Warning: Source files have changed. Source code shown below may not be accurate.)
main() + 0x5e <hello.c : 6>
2: #include <stdio.h>
4: int main()
5: {
6:=> // int *i = malloc(sizeof(int));
7: int i[30];
_start() + 0x71
Fixed issues in a.out.analyze/history/run1/dynamic.latest.AAAe5aWId:
ERROR 1 is a fixed, but repeated error. It was first seen as ERROR 1 in dynamic.latest.AAACRaOId.
LEAK 1 is a fixed, but repeated leak. It was first seen as LEAK 1 in dynamic.latest.AAAQcayId.
Fixed issues in a.out.analyze/history/run1/dynamic.latest.AAAlCaGId:
ERROR 1 is a fixed, but repeated error. It was first seen as ERROR 1 in dynamic.latest.AAACRaOId.
LEAK 1 is a fixed, but repeated leak. It was first seen as LEAK 1 in dynamic.latest.AAAQcayId.
Fixed issues in a.out.analyze/history/run1/dynamic.latest.AAAvCaWri:
ERROR 1 is a fixed, but repeated error. It was first seen as ERROR 1 in dynamic.latest.AAACRaOId.
LEAK 1 is a fixed, but repeated leak. It was first seen as LEAK 1 in dynamic.latest.AAAQcayId.

DISCOVER SUMMARY for a.out: 1 fixed non-leak issues, 1 fixed leak issues
fixed unique errors : 1 (5 total)
fixed unique warnings : 0 (0 total)
fixed unique leaks : 1 (4 blocks, 16 bytes)
fixed unique possible leaks : 0 (0 blocks, 0 bytes)