自动软件修复工具GenProg的环境搭建与初步应用(基于Ubuntu)

使用的GenProg版本为V3.2:GenProg下载
将下载后的文件解压放在用户文件目录下

一、环境搭建

参考另一篇博客搭建Genprog运行环境、配置、安装。

首先使用Ubuntu16.04.5。
opam安装成功,版本号1.2.2
ocaml安装成功,版本号4.02.3
使用opam安装CIL成功,版本号1.7.3
环境构建完成。

在“编译repair”阶段,genprog-code-master/src目录下执行make时报错,错误信息如下:

clark@ubuntu:~/genprog-code-master/src$ make
ocamlopt -w Aelzv-7 -I /home/clark/.opam/system/lib/cil -c global.ml
File "global.ml", line 58, characters 0-7:
Warning 50: ambiguous documentation comment
File "global.ml", line 59, characters 0-59:
Warning 50: ambiguous documentation comment
File "global.ml", line 105, characters 0-7:
Warning 50: unattached documentation comment (ignored)
File "global.ml", line 187, characters 0-28:
Warning 50: unattached documentation comment (ignored)
File "global.ml", line 49, characters 0-15:
Warning 44: this open statement shadows the value identifier ref (which is later used)
File "global.ml", line 49, characters 0-15:
Warning 44: this open statement shadows the value identifier stdout (which is later used)
File "global.ml", line 49, characters 0-15:
Warning 44: this open statement shadows the value identifier not (which is later used)
File "global.ml", line 49, characters 0-15:
Warning 44: this open statement shadows the value identifier ! (which is later used)
File "global.ml", line 49, characters 0-15:
Warning 44: this open statement shadows the value identifier || (which is later used)
File "global.ml", line 49, characters 0-15:
Warning 44: this open statement shadows the value identifier output_string (which is later used)
File "global.ml", line 49, characters 0-15:
Warning 44: this open statement shadows the value identifier flush (which is later used)
File "global.ml", line 49, characters 0-15:
Warning 44: this open statement shadows the value identifier exit (which is later used)
File "global.ml", line 49, characters 0-15:
Warning 44: this open statement shadows the type identifier out_channel (which is later used)
File "global.ml", line 49, characters 0-15:
Warning 44: this open statement shadows the type identifier in_channel (which is later used)
File "global.ml", line 49, characters 0-15:
Warning 44: this open statement shadows the value identifier := (which is later used)
File "global.ml", line 49, characters 0-15:
Warning 44: this open statement shadows the value identifier incr (which is later used)
File "global.ml", line 49, characters 0-15:
Warning 44: this open statement shadows the value identifier == (which is later used)
File "global.ml", line 49, characters 0-15:
Warning 44: this open statement shadows the value identifier > (which is later used)
File "global.ml", line 49, characters 0-15:
Warning 44: this open statement shadows the value identifier = (which is later used)
File "global.ml", line 49, characters 0-15:
Warning 44: this open statement shadows the value identifier < (which is later used)
File "global.ml", line 49, characters 0-15:
Warning 44: this open statement shadows the value identifier pred (which is later used)
File "global.ml", line 49, characters 0-15:
Warning 44: this open statement shadows the value identifier + (which is later used)
File "global.ml", line 49, characters 0-15:
Warning 44: this open statement shadows the value identifier - (which is later used)
File "global.ml", line 49, characters 0-15:
Warning 44: this open statement shadows the value identifier compare (which is later used)
File "global.ml", line 49, characters 0-15:
Warning 44: this open statement shadows the value identifier <= (which is later used)
File "global.ml", line 49, characters 0-15:
Warning 44: this open statement shadows the value identifier >= (which is later used)
File "global.ml", line 49, characters 0-15:
Warning 44: this open statement shadows the value identifier fst (which is later used)
File "global.ml", line 49, characters 0-15:
Warning 44: this open statement shadows the value identifier +. (which is later used)
File "global.ml", line 49, characters 0-15:
Warning 44: this open statement shadows the value identifier /. (which is later used)
File "global.ml", line 49, characters 0-15:
Warning 44: this open statement shadows the value identifier -. (which is later used)
File "global.ml", line 49, characters 0-15:
Warning 44: this open statement shadows the value identifier max (which is later used)
File "global.ml", line 49, characters 0-15:
Warning 44: this open statement shadows the value identifier *. (which is later used)
File "global.ml", line 49, characters 0-15:
Warning 44: this open statement shadows the value identifier nan (which is later used)
File "global.ml", line 49, characters 0-15:
Warning 44: this open statement shadows the value identifier sqrt (which is later used)
File "global.ml", line 314, characters 9-31:
Error: Unbound value String.ascii_lowercase
Makefile:74: recipe for target 'global.cmx' failed
make: *** [global.cmx] Error 2

怀疑为系统版本问题导致工具不全,切换至Ubuntu20.04
opam安装成功,版本号2.0.5
ocaml安装成功,版本号4.08.1
运行opam install cil失败,结果如下:

clark@ubuntu:~$ opam install cil
Sorry, no solution found: there seems to be a problem with your request.

No solution found, exiting

于是不使用opam安装CIL,改为下载CIL包进行编译,CIL下载地址
将下载后的文件解压后放在用户目录下,按照之前参考的博客执行
cd cil-develop
./configure
然后执行make后报错:

clark@ubuntu:~/cil-develop$ make
make cilly install-findlib install-data PREFIX=. datarootdir=share DESTDIR= OCAMLFIND_DESTDIR=lib
make[1]: Entering directory '/home/clark/cil-develop'
export CIL_VERSION
MAKE=make ocamlbuild -build-dir _build -use-ocamlfind -no-links -classic-display src/cil.cma src/ext/simplemem.cma src/ext/canonicalize.cma src/ext/dataslicing.cma src/ext/liveness.cma src/ext/llvm.cma src/ext/heapify.cma src/ext/oneret.cma src/ext/logcalls.cma src/ext/pta.cma src/ext/inliner.cma src/ext/partial.cma src/ext/blockinggraph.cma src/ext/sfi.cma src/ext/simplify.cma src/ext/cqualann.cma src/ext/callgraph.cma src/ext/zrapp.cma src/ext/logwrites.cma src/ext/epicenter.cma src/ext/ccl.cma src/cil.cmxa src/cil.a src/ext/simplemem.cmxa src/ext/canonicalize.cmxa src/ext/dataslicing.cmxa src/ext/liveness.cmxa src/ext/llvm.cmxa src/ext/heapify.cmxa src/ext/oneret.cmxa src/ext/logcalls.cmxa src/ext/pta.cmxa src/ext/inliner.cmxa src/ext/partial.cmxa src/ext/blockinggraph.cmxa src/ext/sfi.cmxa src/ext/simplify.cmxa src/ext/cqualann.cmxa src/ext/callgraph.cmxa src/ext/zrapp.cmxa src/ext/logwrites.cmxa src/ext/epicenter.cmxa src/ext/ccl.cmxa src/ext/simplemem.cmxs src/ext/canonicalize.cmxs src/ext/dataslicing.cmxs src/ext/liveness.cmxs src/ext/llvm.cmxs src/ext/heapify.cmxs src/ext/oneret.cmxs src/ext/logcalls.cmxs src/ext/pta.cmxs src/ext/inliner.cmxs src/ext/partial.cmxs src/ext/blockinggraph.cmxs src/ext/sfi.cmxs src/ext/simplify.cmxs src/ext/cqualann.cmxs src/ext/callgraph.cmxs src/ext/zrapp.cmxs src/ext/logwrites.cmxs src/ext/epicenter.cmxs src/ext/ccl.cmxs src/ext/simplemem.a src/ext/canonicalize.a src/ext/dataslicing.a src/ext/liveness.a src/ext/llvm.a src/ext/heapify.a src/ext/oneret.a src/ext/logcalls.a src/ext/pta.a src/ext/inliner.a src/ext/partial.a src/ext/blockinggraph.a src/ext/sfi.a src/ext/simplify.a src/ext/cqualann.a src/ext/callgraph.a src/ext/zrapp.a src/ext/logwrites.a src/ext/epicenter.a src/ext/ccl.a src/cil.libfiles src/ext/simplemem.libfiles src/ext/canonicalize.libfiles src/ext/dataslicing.libfiles src/ext/liveness.libfiles src/ext/llvm.libfiles src/ext/heapify.libfiles src/ext/oneret.libfiles src/ext/logcalls.libfiles src/ext/pta.libfiles src/ext/inliner.libfiles src/ext/partial.libfiles src/ext/blockinggraph.libfiles src/ext/sfi.libfiles src/ext/simplify.libfiles src/ext/cqualann.libfiles src/ext/callgraph.libfiles src/ext/zrapp.libfiles src/ext/logwrites.libfiles src/ext/epicenter.libfiles src/ext/ccl.libfiles src/main.byte src/main.native cil.docdir/index.html
ocamlfind ocamlc -c -I src -I src/frontc -I src/ocamlutil -I src/ext -I src/ext/simplify -I src/ext/oneret -I src/ext/dataslicing -I src/ext/zrapp -I src/ext/canonicalize -I src/ext/inliner -I src/ext/simplemem -I src/ext/llvm -I src/ext/partial -I src/ext/logwrites -I src/ext/callgraph -I src/ext/sfi -I src/ext/epicenter -I src/ext/ccl -I src/ext/pta -I src/ext/heapify -I src/ext/blockinggraph -I src/ext/logcalls -I src/ext/cqualann -I src/ext/liveness -o src/cilint.cmi src/cilint.mli
+ ocamlfind ocamlc -c -I src -I src/frontc -I src/ocamlutil -I src/ext -I src/ext/simplify -I src/ext/oneret -I src/ext/dataslicing -I src/ext/zrapp -I src/ext/canonicalize -I src/ext/inliner -I src/ext/simplemem -I src/ext/llvm -I src/ext/partial -I src/ext/logwrites -I src/ext/callgraph -I src/ext/sfi -I src/ext/epicenter -I src/ext/ccl -I src/ext/pta -I src/ext/heapify -I src/ext/blockinggraph -I src/ext/logcalls -I src/ext/cqualann -I src/ext/liveness -o src/cilint.cmi src/cilint.mli
File "src/cilint.mli", line 6, characters 36-51:
6 | type cilint = Small of int | Big of Big_int.big_int
                                        ^^^^^^^^^^^^^^^
Error: Unbound module Big_int
Command exited with code 2.
make[1]: *** [Makefile:103: ocamlbuild] Error 10
make[1]: Leaving directory '/home/clark/cil-develop'
make: *** [Makefile:371: install-local] Error 2

CIL安装失败,怀疑是系统、opam、ocaml版本过高,切换至Ubuntu18.04
opam安装成功,版本号1.2.2
ocaml安装成功,版本号4.05.0
使用opam安装CIL成功,版本号1.7.3
环境构建完成。

在“编译repair”阶段,genprog-code-master/src目录下执行make时报错,错误信息如下:

clark@ubuntu:~/genprog-code-master/src$ make
Makefile:41: *** Could not find CIL include path. Is $CIL set correctly?.  Stop.

疑似CIL安装未完成,改用CIL包编译安装,下载地址。将下载后的文件解压后放在用户目录下,执行
cd cil-develop
./configure
然后执行make后报错:

fatal error: bits/libc-header-start.h: No such file or directory

是因为环境没有完善,缺少C库头文件,执行
sudo apt-get install gcc-multilib g++-multilib
再重新执行make
执行make cillib
环境搭建完成。

编译Genprog源代码生成repair修复工具
cd用户目录,执行 chmod -R 777 genprog-code-master/
cd到genprog-code-master/src目录下,执行make,执行成功之后会产生一个repair可执行文件

GenProg使用测试
Genprog内置的测试文件包含genprog-code-master/test/gcd-test/gcd.c,是一个计算两个输入数的最大公因数的小程序:

#include <stdio.h>

int main(int argc, char *argv[]) {
    
    
  double a,b,c;
  double r1, r2; 
  a = atoi(argv[1]); 
  b = atoi(argv[2]); 

  if (a == 0) {
    
    
    printf("%g\n", b); 
  } 
  {
    
    
    while (b != 0) {
    
    
      if (a > b) {
    
    
        a = a - b; 
      } else {
    
    
        b = b - a; 
      } 
    } 
    printf("%g\n", a); 
  } 

  return 0; 
} 

该程序存在缺陷,应当在第一个if块后添加return语句,正确形式如下:

#include <stdio.h>

int main(int argc, char *argv[]) {
    
    
  double a,b,c;
  double r1, r2; 
  a = atoi(argv[1]); 
  b = atoi(argv[2]); 

  if (a == 0) {
    
    
    printf("%g\n", b);
    return 0} 
  {
    
    
    while (b != 0) {
    
    
      if (a > b) {
    
    
        a = a - b; 
      } else {
    
    
        b = b - a; 
      } 
    } 
    printf("%g\n", a); 
  } 

  return 0; 
} 

使用GenProg工具修复该程序
进入genprog-code-master/test目录,执行
./gcd-1-findsrepair.test
如果有报错,忽略
进入genprog-code-master/test/gcd-test目录,执行
../../src/repair ../gcd-1-findsrepair.config
如果成功,会在genprog-code-master/test/gcd-test目录下生成修复所得到的repair.c,内容如下:

extern int ( /* missing proto */  atoi)() ;
extern int ( /* missing proto */  printf)() ;
int main(int argc , char **argv ) 
{
    
     
  double a ;
  double b ;
  double c ;
  double r1 ;
  double r2 ;
  int tmp ;
  int tmp___0 ;

  {
    
    
  tmp = atoi(*(argv + 1));
  a = (double )tmp;
  tmp___0 = atoi(*(argv + 2));
  b = (double )tmp___0;
  if (a == (double )0) {
    
    
    __repair_app_6__0: /* CIL Label */ 
    {
    
    
    printf("%g\n", b);
    return (0);
    }
  } else {
    
    

  }
  while (b != (double )0) {
    
    
    if (a > b) {
    
    
      a -= b;
    } else {
    
    
      b -= a;
    }
  }
  printf("%g\n", a);
  return (0);
}
}

修复成功。

猜你喜欢

转载自blog.csdn.net/ClarkCC/article/details/107590632