JP2004145381A - Static analysis system for source program - Google Patents
Static analysis system for source program Download PDFInfo
- Publication number
- JP2004145381A JP2004145381A JP2002306063A JP2002306063A JP2004145381A JP 2004145381 A JP2004145381 A JP 2004145381A JP 2002306063 A JP2002306063 A JP 2002306063A JP 2002306063 A JP2002306063 A JP 2002306063A JP 2004145381 A JP2004145381 A JP 2004145381A
- Authority
- JP
- Japan
- Prior art keywords
- source program
- resource
- rule file
- analysis
- release
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Granted
Links
Images
Landscapes
- Debugging And Monitoring (AREA)
- Stored Programmes (AREA)
Abstract
Description
【0001】
【発明の属する技術分野】
本発明は、ソースプログラムの静的解析装置に係り、特に、ソースプログラムを静的に解析し、不良をソースプログラム製作段階で検出可能としたソースプログラムの静的解析装置に関する。
【0002】
【従来の技術】
一般に、従来技術によるソースプログラムの静的解析装置は、静的解析装置が有する入力手段により入力されたソースプログラムを解析して構文上の誤りを検出し、静的解析装置が有する出力手段により解析結果を出力するというものである。
【0003】
また、他の従来技術によるソースプログラムの静的解析装置に関する技術として、例えば、特許文献1等に記載された技術が知られている。この従来技術は、パターン化したチェック項目毎にソースプログラムの定義情報を格納しておき、チェック項目に基づいて分割したソースプログラムの処理を定義情報と比較し、定義情報の扱いが正しいか否か解析するというものである。
【0004】
【特許文献1】
特開平8−69380号公報
【0005】
【発明が解決しようとする課題】
前述した従来技術は、ソースプログラムを事前に用意したチェック項目と比較し、ソースプログラムの構文上の誤りを指摘するに止まり、ソースプログラムの動作時に実行される処理の順序の誤りを指摘することができないという問題点を有している。また、前述の従来技術は、解析の対象が1つのファイルであり、複数ファイルに亘るソースプログラムのチェックを行うことができないという問題点を有している。
【0006】
従来、ソースプログラムの動作時における処理の流れを解析するためには、動的解析装置が用いられている。しかし、動的解析装置を使用するためには、プログラムの実行環境と全条件分岐に対応するテストデータとを用意する時間と手間とが掛かってしまう。
【0007】
本発明の目的は、前述した従来技術の問題点を解決し、プログラムの実行環境とテストデータとを用意することなく、ソースプログラムの動作時に変化する情報と処理とを解析し、解析結果を出力することを可能とした、また、複数ファイルに渡って解析を行うことを可能にしたソースプログラムの静的解析装置を提供することにある。
【0008】
【課題を解決するための手段】
本発明によれば前記目的は、ソースプログラムを静的に解析しその解析結果を出力するソースプログラムの静的解析装置において、複数の前記ソースプログラムを入力可能な入力手段と、リソースの確保と解放との対応及び前記リソースの占有と占有解除との対応をチェックするルールを記述したルールファイルに基づいて前記入力手段により入力された前記ソースプログラムを解析する構造解析手段と、前記構造解析手段の解析結果を出力する出力手段とを備えることにより達成される。
【0009】
また、前記目的は、前記構造解析手段が、前記入力手段により入力された前記ソースプログラムの処理の流れを制御構造ツリーに展開する制御構造ツリー作成手段を含むことにより達成される。
【0010】
また、前記目的は、前記構造解析手段が、前記ルールファイルを参照して前記制御構造ツリーから前記リソースの確保と解放との処理手順を前記リソースの使用を管理するリソース使用管理テーブルに書き込み、前記リソースの確保と解放との処理順序をチェックすることにより達成される。
【0011】
さらに、前記目的は、前記構造解析手段が、前記ルールファイルを参照して前記制御構造ツリーから前記リソースの占有と占有解除との処理手順を前記リソースの使用を管理するリソース使用管理テーブルに書き込み、前記リソースの占有と占有解除との処理順序をチェックすることにより達成される。
【0012】
前述において、構造解析手段は、1つのソースプログラムを最後まで読み込むと、引き続き指定されたソースプログラムを読み込み、この間リソース使用管理テーブルの情報を保持し、複数のファイルに亘るリソースの確保と解放のチェックを行うことが可能である。
【0013】
本発明は、前述したような手段を有することにより、ソースプログラムの動作中に変化する情報と処理とを、ソースプログラムを動作させることなく解析することができる。そのため、ソースプログラムの実行環境を用意する必要なく、従来の動的解析装置の機能の一部を実現することができる。
【0014】
また、本発明は、ソースプログラムの開発段階で誤りを検出し、ソースプログラム製作者に通知することにより、ソースプログラム製作段階での不良を削減することができる。
【0015】
【発明の実施の形態】
以下、本発明によるソースプログラムの静的解析装置の実施形態を図面により詳細に説明する。
【0016】
図1は本発明の一実施形態によるソースプログラムの静的解析装置の構成を示すブロック図である。図1において、10はソースプログラム、11は静的解析装置、12は解析結果、110は制御構造ツリー作成部、111は制御構造ツリー、112は構造解析部、113は解析結果バッファ、114は解析結果編集部、115は解析結果出力部、116はルールファイル蓄積部、117はルールファイル編集部、118はリソース使用管理テーブルである。
【0017】
本発明の実施形態による静的解析装置11は、制御構造ツリー作成部110、制御構造ツリー111、構造解析部112、解析結果バッファ113、解析結果編集部114、解析結果出力部115、ルールファイル蓄積部116、チェックすべき関数の変更、追加等のルールファイルの編集を行うルールファイル編集部117、メモリ、ファイル、通信用ソケット等のリソース使用管理テーブル118を備えて構成される。そして、静的解析装置11は、ソースプログラム10を読み込み、制御構造解析ツリー作成部110においてソースプログラム10を制御構造ツリー111に展開する。構造解析部112は、ルールファイル蓄積部116に蓄積されたファイル内容に基づいて制御構造ツリー111を解析し、ルールファイル蓄積部116から作成されるリソース使用管理テーブル118と解析結果バッファ113とに対して、逐次解析結果を出力する。解析結果編集部114は、解析結果バッファ113の解析結果を編集し出力形式のエラーメッセージを作成する。解析結果出力部115は、解析結果編集部114から解析結果を受け取り、解析結果を解析結果12として出力する。
【0018】
図2は本発明の実施形態による静的解析装置11での処理動作の概要を説明するフローチャートであり、次に、これについて説明する。
【0019】
(1)まず、静的解析装置11は、ソースプログラム10を読み込む。このとき、ソースプログラム10に複数のファイルが指定された場合、続けて次のファイルを読み込む。静的解析装置11が解析可能なソースプログラム10は、C言語やVisual C++やJava(登録商標)等であり、各言語に対応する静的解析装置11を用意することにより、それぞれの言語の解析が可能となる(ステップS1)。
【0020】
(2)次に、静的解析装置11は、制御構造ツリー作成部110に、制御構造ツリー111を作成させる。この制御構造ツリー作成の詳細な処理については、図3、図4を参照して後述する(ステップS2)。
【0021】
(3)制御構造ツリー111の作成後、静的解析装置11は、ルールファイル蓄積部116内のルールファイルを読み込む。ルールファイル蓄積部116には、静的解析装置11がチェックするリソースの確保/解放関数の組とリソース確保の成功/失敗時の確認手段と、リソースの占有/占有解除関数の組とリソース占有の成功/失敗時の確認手段とが定義されている。ルールファイル蓄積部116のルールファイルの記述形式については、図9を参照して後述する(ステップS3)。
【0022】
(4)次に、静的解析装置11は、ルールファイル蓄積部116内のルールファイルを元に、リソース使用管理テーブル118を作成する。リソース使用管理テーブル118は、ルールファイル蓄積部116に定義されたリソース確保/解放、占有/占有解除関数名を抜き出して作成される。リソース使用管理テーブル118の構造については、図10を参照して後述する(ステップS4)。
【0023】
(5)リソース使用管理テーブル118の作成後、静的解析装置11内の構造解析部112は、ルールファイル蓄積部116内のルールファイルに基づいて制御構造ツリー111を解析する。この制御構造ツリー111の解析の詳細な処理については、図5、図6を参照して後述する(ステップS5)。
【0024】
(6)静的解析装置11は、構造解析部112による解析結果を一旦解析結果バッファに蓄積した後、編集処理を行って、エラーがあれば、エラーメッセージを作成する。解析結果編集部114は、リソース使用管理テーブル118の内容と解析結果バッファ113に蓄積された解析結果とを組み合わせ、解析結果出力部115に出力する(ステップS6)。
【0025】
(7)その後、静的解析装置11は、ソースプログラム10の解析結果12を出力する。解析結果12の出力形式と出力例とについては、図11を参照して後述する(ステップS7)。
【0026】
図3は前述のステップS2での制御構造ツリー作成部110の制御構造ツリー作成処理を説明するフローチャートであり、次に、これについて説明する。
【0027】
(1)制御構造ツリー作成の処理が開始されると、まず、ソースプログラム10が終了するまで処理を繰り返すことを設定し、ソースプログラム10から1命令を読み込む(ステップS21、S22)。
【0028】
(2)ステップS22で読み込んだ1命令が条件分岐命令であるか否かの判定を行い、条件分岐命令でない場合、その1命令の行を制御構造ツリーに書き込む(ステップS23、S25)。
【0029】
(3)ステップS23の判定で、読み込んだ1命令が条件分岐命令であった場合、ツリー分岐処理を行う(ステップS24)。
【0030】
図4は前述したステップS24でのツリー分岐処理を説明するフローチャートであり、次に、これについて説明する。
【0031】
(1)ツリー分岐処理が開始されると、初めに新たなツリーの枝を作成し、その枝に対し分岐が終了するまで処理を繰り返すことを設定する(ステップS241、S242)。
【0032】
(2)ファイルから1命令を読み込み、その1命令が条件分岐命令であるか否かを判定する。この判定で、読み込んだ1命令が条件分岐命令でなかった場合、その命令を制御構造ツリーに書き込む(ステップS243、S244、S246)。(3)ステップS244の判定で、読み込んだ1命令が条件分岐命令であった場合、再び、ツリー分岐処理を呼び、その命令についてステップS241からの処理を続ける。そして、ツリー分岐処理が終了したら、図3のステップS21に戻って処理を続ける(ステップS245)。
【0033】
図5は図2のステップS5での構造解析部112による構造解析処理を説明するフローチャートであり、次に、これについて説明する。
【0034】
(1)まず、リソース使用管理テーブル118に出力された関数の行数をクリアし、制御構造ツリー111を1つ読み込み、制御構造ツリー終了まで解析処理を繰り返すことを設定する(ステップS51、S52)。
【0035】
(2)読み込んだ制御構造ツリーの解析処理を実行する。この解析処理の詳細については、図6を参照して後述する(ステップS53)。
【0036】
(3)未解析の制御構造ツリーが存在するか否かを判定し、存在する場合、ステップS51からの処理に戻って処理を繰り返し、未解析の制御構造ツリーが存在しなかった場合、構造解析処理を終了する(ステップS54)。
【0037】
図6は前述したステップS53での制御構造ツリーの解析処理を説明するフローチャートであり、次に、これについて説明する。
【0038】
(1)読み込んだ制御構造ツリー111に関数が含まれていた場合、その関数がルールファイル蓄積部116に記載されたリソース確保/占有関数と一致するか否かの判定を行い、一致する場合、リソース使用管理テーブル118に検出したリソース確保/占有関数の行数を出力する(ステップS531、S532)。
【0039】
(2)次に、リソース確保/占有関数の直後に、ルールファイル蓄積部116の定義通りにリソース確保/占有の確認をしているか否かの判定を行い、確認がなされている場合、ステップS531からの処理に戻って処理を繰り返す(ステップS533)。
【0040】
(4)ステップS533の判定で、ルールファイル蓄積部116の定義通りにリソース確保/占有の確認がなされていなかった場合、解析結果バッファ113にリソース確保/占有の確認をしていないというエラーを出力し、ステップS531からの処理に戻って処理を繰り返す(ステップS534)。
【0041】
(5)ステップS531の判定で、制御構造ツリー111に含まれていた関数がルールファイル蓄積部116に記載されたリソース確保/占有関数と一致しなかった場合、その関数がルールファイル蓄積部116に記載されたリソース解放/占有解除関数と一致するか否かを判定し、一致しない場合、制御構造ツリー解析処理を終了する(ステップS535)。
【0042】
(6)ステップS535の判定で、関数がルールファイル蓄積部116に記載されたリソース解放/占有解除関数と一致した場合、リソース使用管理テーブル118に検出したリソース解放/占有解除関数の行数を出力し、リソース使用管理テーブル118を参照して、リソースの確保/解放、占有/占有解除関数の使用がルールファイル蓄積部116の定義と一致するか否か判定する(ステップS536、S537)。
【0043】
(7)ステップS537の判定で、リソースの確保/解放、占有/占有解除関数の使用がルールファイル蓄積部116の定義と一致した場合、制御構造ツリー解析処理を終了し、一致しなかった場合、解析結果バッファ113にエラー情報を出力し、制御構造ツリー解析処理を終了する。処理終了後、図5の処理に戻る(ステップS538)。
【0044】
図5、図6により説明した構造解析の処理は、リソースの実体を必要とすることなく、リソース使用管理テーブル118で管理されているメモリ、ファイル、通信用ソケット等のリソースの情報を使用して行うことができる。また、ソースプログラムの任意の範囲についての構造解析を行うことができる。
【0045】
次に、前述までに説明した本発明の実施形態による解析装置での処理をソースプログラムの例を用いて具体的に説明する。
【0046】
図7はC言語によるソースプログラム10の記述例の一部とこれにより生成した制御構造ツリーの例を説明する図である。
【0047】
図7(a)に示すC言語によるソースプログラム10の記述例は、条件分岐命令“if”と“else”とが存在する。ここで、“else”は“if”の補集合を示し、図3のステップS24におけるツリー分岐処理において“if”を用いた条件式に置換され、図7(b)に示すようなツリーへ展開される。制御構造ツリー111は、ツリーの最上部から最下部までのルートを網羅して生成され、図7(b)に示すツリーは、図7(c)及び図7(d)に示す2つの制御構造ツリー111に生成される。
【0048】
図8はC言語によるソースプログラム10の他の記述例の一部とこれにより生成した制御構造ツリーの例を説明する図である。
【0049】
図8(a)に示すC言語によるソースプログラムの例の3行目、4行目は、図7(a)に示した“処理A”に、7行目、8行目は、図7(a)に示した“処理B”に相当する。制御構造ツリー作成部110において、図8(a)に示すプログラムは、図8(b)に示されるツリーへ展開され、このツリーから図8(c)、図8(d)、図8(e)に示すような制御構造ツリー111が生成される。
【0050】
図9はルールファイル蓄積部116のルールファイルの記述形式を示す図である。ルールファイルにおいて、記号“|”は、複数の値を定義するときの区切り文字として用いられる。リソース確保/占有関数の成功/失敗時の返り値が存在しない場合の返り値は“−”となり、成功時と失敗時の返り値が両方共“−”の場合、リソース確保/占有関数の成功/失敗の判定を行わない。また、リソース確保/占有関数に対するリソース解放/占有解除関数が存在しない場合、リソース解放/占有解除関数名は空欄となる。
【0051】
図9(a)に示すように、ルールファイルは、“リソース確保関数”と“リソース開放関数”との間に、“リソース確保成功時の返り値”、“リソース確保失敗時の返り値”を有する行と、“リソース占有関数”と“リソース占有解除関数”との間に、“リソース占有成功時の返り値”、“リソース占有失敗時の返り値”を有する行とにより構成される。
【0052】
図9(a)に対応するルールファイルの具体的な記述例を図9(b)に示している。この図9(b)において、リソース確保関数が“関数A”であり、それに対するリソース解放関数が“関数B”であると定義している。また、リソース占有関数が“関数C”であり、それ対するリソース占有解除関数が“関数D”であると定義している。そして、関数Aによるリソース確保の成功時には“1”、失敗時には“0”または“NULL”が返り、関数Cによるリソース占有の成功時の返り値はなく、失敗時には“−1”または“0”が返ることを示している。
【0053】
図10は図9により説明したルールファイル蓄積部116のルールファイルから作成されたリソース使用管理テーブル118の例を示す図であり、次に、これについて説明する。
【0054】
図10(a)〜図10(c)に示すように、リソース使用管理テーブル118には、“関数A”、“関数B”、“関数C”、“関数D”が出力されている。構造解析部112は、制御構造ツリー111からこれらの関数を検出したとき、その何行目かを示す行数がリソース使用管理テーブル118に出力されている。
【0055】
次に、図8(a)に例示したソースプログラムから作成した制御構造ツリーの解析処理についてを具体的に説明する。まず、図8(c)に示す制御構造ツリーの解析処理の手順を説明する。
【0056】
図8(c)に示す制御構造ツリーの1行目から“関数A”を検出し、リソース使用管理テーブル118の“関数A”の行に“1”を出力する。ここで“関数A”の返り値を“x”としている。
2行目から条件分岐命令“if”を検出し、新たなツリーの枝を作成する。ここで、“x==0”は、関数Aのリソース確保失敗時の判定を示す。
3行目からの出力命令“printf”は、ルールファイル蓄積部116に定義されていないため、次に進む。
4行目から関数終了命令“exit”により、関数を終了する。5行目は実行されない。
【0057】
次に、図8(d)に示す制御構造ツリーの解析処理の手順を説明する。
【0058】
1行目から“関数A”を検出し、リソース使用管理テーブル118の“関数A”の行に“1”を出力する。
6行目から条件分岐命令“else if”を検出し、新たなツリーの枝を作成する。ここで、“x==1”は、関数Aのリソース確保成功時の判定を示す。
【0059】
7行目からの出力命令“printf”は、ルールファイル蓄積部116に定義されていないため、次に進む。
8行目から“関数B”を検出し、リソース使用管理テーブル118の“関数B”の行に“8”を出力する。この“関数B”は、1行目の“関数A”に対応し、ルールファイル蓄積部116の定義と一致する。
10行目から“関数B”を検出し、リソース使用管理テーブル118の“関数B”の行に“10”を出力する。すでに、8行目に“関数B”が存在するため、ルールファイル蓄積部116の定義と一致しない。解析結果バッファに、検出したエラー情報と関数Bの行数“10”を出力する。
【0060】
前述した図10(b)、図10(c)に示すリソース管理テーブルは、それぞれ、図8(c)及び図8(d)に示す制御構造ツリー111を構造解析部112において解析した後のリソース使用管理テーブル118を示し、“関数A”及び“関数B”を呼び出した行数がそれぞれ出力されている。
【0061】
図11は図8に示すソースプログラムの解析結果12の出力形式と出力例とを示す図である。
【0062】
図11に示すように、解析結果12としては、解析対象となったプログラム名と関数名、エラー検出行数、解析結果(エラー)メッセージが出力される。図示例では、プログラム名として“ソースプログラムA”が出力され、解析結果(エラー)メッセージとして、「リソース開放関数に対応するリソース確保関数がありません」が出力されている。
【0063】
図12はソースプログラム10のさらに他の例と作成された制御構造ツリーの例を示す図である。この図に示すプログラムは、関数をまたいでリソースの確保/解放関数が実行される場合の例である。また、このプログラムは、複数のファイルに亘るソースプログラムの場合もある。すなわち、本発明の静的解析装置は、複数関数間の解析も可能なものである。この場合、図12(a)における関数X、Y、Zのそれぞれに続く部分がそれぞれ異なるファイルに記述されている。図12の示すソースプログラムのルールファイル蓄積部116のルールファイルは図9(b)に示したものと同一であるとする。
【0064】
図12(a)に示すプログラムは、“関数X”によりリソース確保関数“関数A”を実行した後、条件分岐命令“if”によってリソースの確保が成功したときに“関数Y”を、失敗した時に“関数Z”を呼び出すというものである。
【0065】
図12(b)及び図12(c)は、図12(a)に示すプログラムの制御構造ツリー111を示している。“関数Y”及び“関数Z”は、制御構造ツリー111の作成時に“関数X”へ展開されている。図12(b)では、“関数B”が“関数A”で確保されたリソースを解放しているか否か判断し、同じリソースを解放している場合、エラー無く解析を終了する。しかし、“関数B”の解放するリソースが“関数A”が確保したリソースと異なり、リソースが解放されずに“関数X”が終了する場合、解析結果バッファ113に“関数A”の確保したリソースが解放されないエラーと“関数B”の解放するリソースが存在しないエラーとを出力する。図12(c)は、“関数A”でリソースの確保が失敗したとき、“関数X”を終了する。このとき、“関数X”はエラーを検出しない。
【0066】
前述した本発明の実施形態によるソースプログラムの静的解析装置によれば、複数関数間のリソースの確保と解放との対応、及び、リソースの占有と占有解除との対応をチェックすることができ、同様にして、複数ファイル間の関数のリソース確保/解放の対応及びリソース占有/占有解除の対応をチェックすることもできる。
【0067】
前述した本発明の実施形態による各処理は、処理プログラムとして構成することができ、この処理プログラムは、HD、DAT、FD、MO、DVD−ROM、CD−ROM等の記録媒体に格納して提供することができる。
【0068】
【発明の効果】
以上説明したように本発明によれば、ソースプログラムを実行することなく、動作時に変化する情報と処理とを解析することができ、従来の動的解析装置に必要なプログラムを実行させる環境とそれを構築する時間とを不要とすることができる。
【0069】
また、本発明は、ソースプログラムの解析に使用するパターンファイルが異なる静的解析装置においても使用可能であるため、解析の対象を容易に決定することができ、プログラムの改訂時に自由に対応できる。
【0070】
さらに、本発明によれば、ソースプログラムのコーディング時にテストを行うことができるため、ソースプログラムの品質を向上させることができ、開発の初期段階で不良を検出し、後工程で発生する修正のコストと時間とを最小限に止めることができる。
【図面の簡単な説明】
【図1】本発明の一実施形態によるソースプログラムの静的解析装置の構成を示すブロック図である。
【図2】本発明の実施形態による静的解析装置での処理動作の概要を説明するフローチャートである。
【図3】制御構造ツリー作成部での制御構造ツリー作成処理を説明するフローチャートである。
【図4】図3のフローにおけるツリー分岐処理を説明するフローチャートである。
【図5】構造解析部112による構造解析処理を説明するフローチャートである。
【図6】図5のフローにおける制御構造ツリーの解析処理を説明するフローチャートである。
【図7】C言語によるソースプログラムの記述例の一部とこれにより生成した制御構造ツリーの例を説明する図である。
【図8】C言語によるソースプログラムの他の記述例の一部とこれにより生成した制御構造ツリーの例を説明する図である。
【図9】ルールファイル蓄積部のルールファイルの記述形式を示す図である。
【図10】図9により説明したルールファイル蓄積部のルールファイルから作成されたリソース使用管理テーブルの例を示す図である。
【図11】図8に示すソースプログラムの解析結果の出力形式と出力例を示す図である。
【図12】関数をまたいでリソースの確保/解放関数が実行されるソースプログラムの例と作成された制御構造ツリーの例を示す図である。
【符号の説明】
10 ソースプログラム
11 静的解析装置
12 解析結果
110 制御構造ツリー作成部
111 制御構造ツリー
112 構造解析部
113 解析結果バッファ
114 解析結果編集部
115 解析結果出力部
116 ルールファイル蓄積部
117 ルールファイル編集部
118 リソース使用管理テーブル[0001]
TECHNICAL FIELD OF THE INVENTION
The present invention relates to a static analysis device for a source program, and more particularly to a static analysis device for a source program that statically analyzes a source program and can detect a defect in a source program production stage.
[0002]
[Prior art]
Generally, a static analyzer of a source program according to the related art analyzes a source program input by an input unit of the static analyzer to detect a syntax error, and analyzes the syntax by an output unit of the static analyzer. Output the result.
[0003]
Further, as a technique relating to a source program static analysis apparatus according to another conventional technique, for example, a technique described in
[0004]
[Patent Document 1]
JP-A-8-69380 [0005]
[Problems to be solved by the invention]
According to the above-described prior art, the source program is compared with check items prepared in advance, and only the syntax error of the source program is pointed out. There is a problem that it cannot be done. Further, the above-described conventional technique has a problem that the analysis target is a single file, and it is not possible to check a source program over a plurality of files.
[0006]
2. Description of the Related Art Conventionally, a dynamic analyzer has been used to analyze the flow of processing during the operation of a source program. However, in order to use the dynamic analysis device, it takes time and effort to prepare the program execution environment and test data corresponding to all conditional branches.
[0007]
SUMMARY OF THE INVENTION An object of the present invention is to solve the above-described problems of the related art, analyze information and processing that change during the operation of a source program without preparing a program execution environment and test data, and output an analysis result. Another object of the present invention is to provide a static analysis device for a source program capable of performing analysis over a plurality of files.
[0008]
[Means for Solving the Problems]
According to the present invention, an object of the present invention is to provide a static analysis apparatus for a source program that statically analyzes a source program and outputs an analysis result, an input unit capable of inputting a plurality of the source programs, and securing and releasing resources. Analysis means for analyzing the source program input by the input means on the basis of a rule file describing a rule for checking the correspondence between the resource program and the resource occupancy and the release of the occupation, and analysis by the structure analysis means Output means for outputting a result.
[0009]
Further, the above object is achieved when the structure analyzing means includes a control structure tree creating means for expanding a processing flow of the source program input by the input means into a control structure tree.
[0010]
Also, the object is that the structure analysis means refers to the rule file and writes a processing procedure of securing and releasing the resource from the control structure tree to a resource use management table for managing use of the resource, This is achieved by checking the processing order of securing and releasing resources.
[0011]
Further, the object is that the structure analysis means refers to the rule file, writes a processing procedure of occupation and release of the resource from the control structure tree to a resource use management table for managing use of the resource, This is achieved by checking the processing order of occupation and release of the resource.
[0012]
In the above description, when the structure analysis means reads one source program to the end, the structure analysis means continuously reads the specified source program, keeps information of the resource use management table during this time, and checks for securing and releasing resources over a plurality of files. It is possible to do.
[0013]
According to the present invention, by having the above-described means, it is possible to analyze information and processing that change during the operation of the source program without operating the source program. Therefore, it is possible to realize a part of the functions of the conventional dynamic analyzer without having to prepare an execution environment for the source program.
[0014]
Further, according to the present invention, an error can be detected in a source program development stage by detecting an error in a source program development stage and notifying the error to a source program creator.
[0015]
BEST MODE FOR CARRYING OUT THE INVENTION
Hereinafter, an embodiment of a static analysis device for a source program according to the present invention will be described in detail with reference to the drawings.
[0016]
FIG. 1 is a block diagram showing the configuration of a source program static analysis device according to an embodiment of the present invention. In FIG. 1,
[0017]
The
[0018]
FIG. 2 is a flowchart for explaining the outline of the processing operation in the
[0019]
(1) First, the
[0020]
(2) Next, the
[0021]
(3) After creating the control structure tree 111, the
[0022]
(4) Next, the
[0023]
(5) After creating the resource use management table 118, the structure analysis unit 112 in the
[0024]
(6) The
[0025]
(7) Thereafter, the
[0026]
FIG. 3 is a flowchart for explaining the control structure tree creation processing of the control structure
[0027]
(1) When the process of creating a control structure tree is started, first, it is set to repeat the process until the
[0028]
(2) It is determined whether or not the one instruction read in step S22 is a conditional branch instruction. If the instruction is not a conditional branch instruction, the row of the one instruction is written in the control structure tree (steps S23 and S25).
[0029]
(3) If it is determined in step S23 that the read one instruction is a conditional branch instruction, tree branch processing is performed (step S24).
[0030]
FIG. 4 is a flowchart for explaining the tree branching process in step S24 described above. Next, this will be described.
[0031]
(1) When the tree branching process is started, a new branch of the tree is created first, and the process is set to be repeated until the branch ends for that branch (steps S241 and S242).
[0032]
(2) One instruction is read from the file, and it is determined whether the one instruction is a conditional branch instruction. If the read one instruction is not a conditional branch instruction in this determination, the instruction is written in the control structure tree (steps S243, S244, S246). (3) If it is determined in step S244 that the read one instruction is a conditional branch instruction, tree branch processing is called again, and the processing from step S241 is continued for the instruction. When the tree branching process is completed, the process returns to step S21 in FIG. 3 to continue the process (step S245).
[0033]
FIG. 5 is a flowchart for explaining the structure analysis processing by the structure analysis unit 112 in step S5 in FIG. 2. Next, this will be described.
[0034]
(1) First, the number of function lines output to the resource use management table 118 is cleared, one control structure tree 111 is read, and analysis processing is repeated until the control structure tree ends (steps S51 and S52). .
[0035]
(2) Execute analysis processing of the read control structure tree. Details of this analysis processing will be described later with reference to FIG. 6 (step S53).
[0036]
(3) It is determined whether or not there is an unanalyzed control structure tree, and if so, the process returns to step S51 and repeats the process. If there is no unanalyzed control structure tree, the structure analysis is performed. The process ends (step S54).
[0037]
FIG. 6 is a flowchart for explaining the analysis process of the control structure tree in step S53 described above. Next, this will be described.
[0038]
(1) When a function is included in the read control structure tree 111, it is determined whether or not the function matches the resource reservation / occupation function described in the rule
[0039]
(2) Next, immediately after the resource securing / occupying function, it is determined whether or not the resource securing / occupying is confirmed as defined by the rule
[0040]
(4) If it is determined in step S533 that the resource reservation / occupation has not been confirmed as defined by the rule
[0041]
(5) If it is determined in step S531 that the function included in the control structure tree 111 does not match the resource reservation / occupation function described in the rule
[0042]
(6) If the function matches the resource release / dedicated release function described in the rule
[0043]
(7) If it is determined in step S537 that the use of the resource reservation / release and occupancy / release of the occupancy matches the definition of the rule
[0044]
The structure analysis processing described with reference to FIGS. 5 and 6 does not require the entity of the resource and uses information of resources such as a memory, a file, and a communication socket managed by the resource use management table 118. It can be carried out. Further, it is possible to perform a structural analysis on an arbitrary range of the source program.
[0045]
Next, the processing in the analyzer according to the embodiment of the present invention described above will be specifically described using an example of a source program.
[0046]
FIG. 7 is a diagram illustrating a part of a description example of the
[0047]
The description example of the
[0048]
FIG. 8 is a diagram illustrating a part of another description example of the
[0049]
The third and fourth lines of the example of the source program in the C language shown in FIG. 8A correspond to “processing A” shown in FIG. 7A, and the seventh and eighth lines correspond to FIG. This corresponds to “process B” shown in a). In the control structure
[0050]
FIG. 9 is a diagram showing a description format of a rule file in the rule
[0051]
As shown in FIG. 9A, the rule file includes a “return value when resource reservation succeeds” and a “return value when resource reservation fails” between the “resource reservation function” and the “resource release function”. And a row having a “return value when resource occupation succeeds” and a “return value when resource occupation fails” between the “resource occupancy function” and the “resource occupancy release function”.
[0052]
FIG. 9B shows a specific description example of the rule file corresponding to FIG. 9A. In FIG. 9B, it is defined that the resource securing function is “function A” and the resource releasing function is “function B”. Further, it is defined that the resource occupancy function is "function C" and the resource occupancy release function is "function D". When the resource A is successfully allocated by the function A, “1” is returned. When the resource A is unsuccessful, “0” or “NULL” is returned. Is returned.
[0053]
FIG. 10 is a diagram showing an example of the resource use management table 118 created from the rule file of the rule
[0054]
As shown in FIGS. 10A to 10C, “function A”, “function B”, “function C”, and “function D” are output to the resource use management table 118. When the structure analysis unit 112 detects these functions from the control structure tree 111, the number of lines indicating the number of the lines is output to the resource use management table 118.
[0055]
Next, the process of analyzing the control structure tree created from the source program illustrated in FIG. 8A will be specifically described. First, the procedure of the control structure tree analysis processing shown in FIG. 8C will be described.
[0056]
“Function A” is detected from the first line of the control structure tree shown in FIG. 8C, and “1” is output to the line of “Function A” in the resource use management table 118. Here, the return value of “function A” is “x”.
The conditional branch instruction “if” is detected from the second line, and a new tree branch is created. Here, “x == 0” indicates a determination at the time of failure in securing resources of the function A.
Since the output instruction “printf” from the third line is not defined in the rule
The function is terminated from the fourth line by a function termination instruction “exit”. The fifth line is not executed.
[0057]
Next, the procedure of the control structure tree analysis processing shown in FIG. 8D will be described.
[0058]
"Function A" is detected from the first line, and "1" is output to the line of "function A" in the resource use management table 118.
The conditional branch instruction “else if” is detected from the sixth line, and a new tree branch is created. Here, “x == 1” indicates a determination at the time of successful resource securing of the function A.
[0059]
Since the output instruction “printf” from the seventh line is not defined in the rule
"Function B" is detected from the eighth line, and "8" is output to the line of "function B" in the resource use management table 118. This “function B” corresponds to “function A” on the first line, and matches the definition of the rule
“Function B” is detected from the tenth line, and “10” is output to the “function B” line of the resource use management table 118. Since “function B” already exists in the eighth line, it does not match the definition in the rule
[0060]
The resource management tables shown in FIGS. 10B and 10C described above are obtained by analyzing the control structure tree 111 shown in FIGS. 8C and 8D by the structure analysis unit 112, respectively. The usage management table 118 is shown, and the number of lines that called “function A” and “function B” are output.
[0061]
FIG. 11 is a diagram showing an output format and an output example of the
[0062]
As shown in FIG. 11, as the
[0063]
FIG. 12 is a diagram showing still another example of the
[0064]
The program shown in FIG. 12A executes the resource securing function “function A” by the “function X” and then fails the “function Y” when the resource securing by the conditional branch instruction “if” succeeds. Sometimes, "function Z" is called.
[0065]
FIGS. 12B and 12C show a control structure tree 111 of the program shown in FIG. 12A. “Function Y” and “Function Z” are expanded to “Function X” when the control structure tree 111 is created. In FIG. 12B, it is determined whether “function B” has released the resources secured by “function A”, and if the same resources have been released, the analysis ends without error. However, when the resource released by “function B” is different from the resource reserved by “function A” and “function X” ends without releasing the resource, the resource reserved by “function A” is stored in the analysis result buffer 113. Is output and the error that the resource to be released by “function B” does not exist is output. In FIG. 12 (c), when securing of resources by “function A” fails, “function X” ends. At this time, “function X” does not detect an error.
[0066]
According to the source program static analysis device according to the embodiment of the present invention described above, it is possible to check the correspondence between securing and releasing resources among a plurality of functions and the correspondence between occupation and release of resources, Similarly, it is also possible to check the correspondence between the resource reservation / release and the resource occupation / release of the function between the plurality of files.
[0067]
Each processing according to the above-described embodiment of the present invention can be configured as a processing program, and the processing program is provided by being stored in a recording medium such as an HD, a DAT, an FD, an MO, a DVD-ROM, and a CD-ROM. can do.
[0068]
【The invention's effect】
As described above, according to the present invention, it is possible to analyze information and processes that change during operation without executing a source program. The time to build and the time can be eliminated.
[0069]
Further, since the present invention can be used in a static analysis device that uses a different pattern file for analyzing a source program, the analysis target can be easily determined, and the program can be freely responded to when the program is revised.
[0070]
Further, according to the present invention, a test can be performed at the time of coding a source program, so that the quality of the source program can be improved, a defect can be detected in an early stage of development, and a cost of a correction generated in a later process can be improved. And time can be kept to a minimum.
[Brief description of the drawings]
FIG. 1 is a block diagram showing a configuration of a source program static analysis device according to an embodiment of the present invention.
FIG. 2 is a flowchart illustrating an outline of a processing operation in the static analysis device according to the embodiment of the present invention.
FIG. 3 is a flowchart illustrating a control structure tree creation process in a control structure tree creation unit.
FIG. 4 is a flowchart illustrating a tree branching process in the flow of FIG. 3;
FIG. 5 is a flowchart illustrating a structure analysis process performed by a structure analysis unit 112;
FIG. 6 is a flowchart illustrating a control structure tree analysis process in the flow of FIG. 5;
FIG. 7 is a diagram illustrating a part of a description example of a source program in C language and an example of a control structure tree generated thereby.
FIG. 8 is a diagram illustrating a part of another description example of a source program in the C language and an example of a control structure tree generated thereby.
FIG. 9 is a diagram illustrating a description format of a rule file in a rule file storage unit.
FIG. 10 is a diagram illustrating an example of a resource use management table created from a rule file of a rule file storage unit described with reference to FIG. 9;
11 is a diagram showing an output format and an output example of an analysis result of the source program shown in FIG. 8;
FIG. 12 is a diagram showing an example of a source program in which a resource securing / release function is executed across functions and an example of a created control structure tree.
[Explanation of symbols]
Claims (14)
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
JP2002306063A JP4257096B2 (en) | 2002-10-21 | 2002-10-21 | Static analysis device for source program |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
JP2002306063A JP4257096B2 (en) | 2002-10-21 | 2002-10-21 | Static analysis device for source program |
Publications (2)
Publication Number | Publication Date |
---|---|
JP2004145381A true JP2004145381A (en) | 2004-05-20 |
JP4257096B2 JP4257096B2 (en) | 2009-04-22 |
Family
ID=32452967
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
JP2002306063A Expired - Fee Related JP4257096B2 (en) | 2002-10-21 | 2002-10-21 | Static analysis device for source program |
Country Status (1)
Country | Link |
---|---|
JP (1) | JP4257096B2 (en) |
Cited By (9)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
KR100692172B1 (en) | 2005-03-30 | 2007-03-12 | 아이티플러스 주식회사 | Universal string analyzer and method thereof |
WO2007072652A1 (en) * | 2005-12-22 | 2007-06-28 | Syunichi Niihara | Program processing pattern automatic analysis processing device |
JP2008226208A (en) * | 2007-03-16 | 2008-09-25 | Hitachi Information Systems Ltd | Program verification method, system and program |
US8166451B2 (en) | 2006-12-18 | 2012-04-24 | International Business Machines Corporation | Simultaneous static analysis on disparate resource types |
CN102968367A (en) * | 2012-08-28 | 2013-03-13 | 华南理工大学 | Static detection method on basis of embedded software and system thereof |
JP2015130026A (en) * | 2014-01-07 | 2015-07-16 | Necソリューションイノベータ株式会社 | Diagnosis system, diagnosis method and program |
JP2016081400A (en) * | 2014-10-21 | 2016-05-16 | 日本電信電話株式会社 | Rule deviation application discovery device, rule deviation application discovery system, and rule deviation application discovery method |
JP2016151855A (en) * | 2015-02-17 | 2016-08-22 | 日本電信電話株式会社 | Program analyzer, error detector, program analyzing method, error detection method, program analyzing program and error detection program |
JP2018028879A (en) * | 2016-08-19 | 2018-02-22 | 日本電信電話株式会社 | Program analyzer, program analysis method and program analysis program |
Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JPH0793144A (en) * | 1993-09-20 | 1995-04-07 | Fujitsu Ltd | Program analyzer |
JPH0869380A (en) * | 1994-08-29 | 1996-03-12 | Fujitsu Ltd | Source program check device |
JPH08101771A (en) * | 1994-09-30 | 1996-04-16 | Hitachi Software Eng Co Ltd | General purpose check system for source program |
JP2001109644A (en) * | 1999-10-07 | 2001-04-20 | Fujitsu Ltd | Method and device for verifying program |
JP2002132544A (en) * | 2000-10-25 | 2002-05-10 | Hitachi Ltd | Output method for information of program variable |
-
2002
- 2002-10-21 JP JP2002306063A patent/JP4257096B2/en not_active Expired - Fee Related
Patent Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JPH0793144A (en) * | 1993-09-20 | 1995-04-07 | Fujitsu Ltd | Program analyzer |
JPH0869380A (en) * | 1994-08-29 | 1996-03-12 | Fujitsu Ltd | Source program check device |
JPH08101771A (en) * | 1994-09-30 | 1996-04-16 | Hitachi Software Eng Co Ltd | General purpose check system for source program |
JP2001109644A (en) * | 1999-10-07 | 2001-04-20 | Fujitsu Ltd | Method and device for verifying program |
JP2002132544A (en) * | 2000-10-25 | 2002-05-10 | Hitachi Ltd | Output method for information of program variable |
Cited By (10)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
KR100692172B1 (en) | 2005-03-30 | 2007-03-12 | 아이티플러스 주식회사 | Universal string analyzer and method thereof |
WO2007072652A1 (en) * | 2005-12-22 | 2007-06-28 | Syunichi Niihara | Program processing pattern automatic analysis processing device |
US8166451B2 (en) | 2006-12-18 | 2012-04-24 | International Business Machines Corporation | Simultaneous static analysis on disparate resource types |
JP2008226208A (en) * | 2007-03-16 | 2008-09-25 | Hitachi Information Systems Ltd | Program verification method, system and program |
JP4679540B2 (en) * | 2007-03-16 | 2011-04-27 | 株式会社日立情報システムズ | Program verification method, system, and program |
CN102968367A (en) * | 2012-08-28 | 2013-03-13 | 华南理工大学 | Static detection method on basis of embedded software and system thereof |
JP2015130026A (en) * | 2014-01-07 | 2015-07-16 | Necソリューションイノベータ株式会社 | Diagnosis system, diagnosis method and program |
JP2016081400A (en) * | 2014-10-21 | 2016-05-16 | 日本電信電話株式会社 | Rule deviation application discovery device, rule deviation application discovery system, and rule deviation application discovery method |
JP2016151855A (en) * | 2015-02-17 | 2016-08-22 | 日本電信電話株式会社 | Program analyzer, error detector, program analyzing method, error detection method, program analyzing program and error detection program |
JP2018028879A (en) * | 2016-08-19 | 2018-02-22 | 日本電信電話株式会社 | Program analyzer, program analysis method and program analysis program |
Also Published As
Publication number | Publication date |
---|---|
JP4257096B2 (en) | 2009-04-22 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US7530014B2 (en) | Data processing and difference computation for generating addressing information | |
JPWO2006033159A1 (en) | Business model diagram creation support program, business model diagram creation support method, and business model diagram creation support device | |
EP1170667B1 (en) | Software package verification | |
US20050188323A1 (en) | Template creation apparatus and creation method | |
JP2003280924A (en) | Method for processing event having hierarchical structure in communication equipment system | |
CN110083360A (en) | A kind of Compilation Method of application code, device, equipment and storage medium | |
JP4257096B2 (en) | Static analysis device for source program | |
JPH0793186A (en) | Reusing method for existing test program | |
JP5405684B1 (en) | Source program programming language converter | |
JP4702194B2 (en) | Program development support apparatus, program development support method, and program development support program | |
CN112596706A (en) | Patterned code generation method, device and computer readable storage medium | |
US7308677B2 (en) | Program generating apparatus, program generating method and program generator | |
JP2008197897A (en) | Test pattern generation apparatus and generation method | |
JP6714742B1 (en) | Program generation system, computer program thereof, and recording medium | |
JP3641090B2 (en) | Programming support apparatus and method | |
JP2008299423A (en) | Information processor and information processing program | |
JPH0981371A (en) | Automatic version-up method and device for source code | |
JPH0667871A (en) | Automatic program updating system | |
CN117389958B (en) | Searching and processing method for mo file | |
JPH056272A (en) | Software designing device | |
JP4679540B2 (en) | Program verification method, system, and program | |
JP5508933B2 (en) | Software specification proof support apparatus and proof support method | |
JPH11329929A (en) | Electron beam lithography data producing apparatus | |
EP2166452B1 (en) | Restart support program and restart support device | |
JP4904712B2 (en) | Program automatic generation apparatus, method, and program |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
A621 | Written request for application examination |
Free format text: JAPANESE INTERMEDIATE CODE: A621 Effective date: 20040804 |
|
A977 | Report on retrieval |
Free format text: JAPANESE INTERMEDIATE CODE: A971007 Effective date: 20061212 |
|
A131 | Notification of reasons for refusal |
Free format text: JAPANESE INTERMEDIATE CODE: A131 Effective date: 20070109 |
|
A521 | Written amendment |
Free format text: JAPANESE INTERMEDIATE CODE: A523 Effective date: 20070312 |
|
A131 | Notification of reasons for refusal |
Free format text: JAPANESE INTERMEDIATE CODE: A131 Effective date: 20080219 |
|
A521 | Written amendment |
Free format text: JAPANESE INTERMEDIATE CODE: A523 Effective date: 20080421 |
|
TRDD | Decision of grant or rejection written | ||
A01 | Written decision to grant a patent or to grant a registration (utility model) |
Free format text: JAPANESE INTERMEDIATE CODE: A01 Effective date: 20090120 |
|
A01 | Written decision to grant a patent or to grant a registration (utility model) |
Free format text: JAPANESE INTERMEDIATE CODE: A01 |
|
A61 | First payment of annual fees (during grant procedure) |
Free format text: JAPANESE INTERMEDIATE CODE: A61 Effective date: 20090202 |
|
FPAY | Renewal fee payment (event date is renewal date of database) |
Free format text: PAYMENT UNTIL: 20120206 Year of fee payment: 3 |
|
R150 | Certificate of patent or registration of utility model |
Free format text: JAPANESE INTERMEDIATE CODE: R150 |
|
FPAY | Renewal fee payment (event date is renewal date of database) |
Free format text: PAYMENT UNTIL: 20120206 Year of fee payment: 3 |
|
FPAY | Renewal fee payment (event date is renewal date of database) |
Free format text: PAYMENT UNTIL: 20130206 Year of fee payment: 4 |
|
FPAY | Renewal fee payment (event date is renewal date of database) |
Free format text: PAYMENT UNTIL: 20130206 Year of fee payment: 4 |
|
FPAY | Renewal fee payment (event date is renewal date of database) |
Free format text: PAYMENT UNTIL: 20140206 Year of fee payment: 5 |
|
LAPS | Cancellation because of no payment of annual fees |