内存访问出错源代码定位及调用栈信息和代码片段

Inspector XE 可以查找程序的内存访问和线程访问的出错源代码。

一般而言,软件测试工程师使用此工具的命令行编写脚本文件,定时地运行软件,可以监控项目的质量,如果发现错误,可以把报错的问题和源文件的行号等信息送给相应的开发人员。

如:

# inspxe-cl -collect mi3 -- ./tachyon.find_and_fix_memory_errors ./dat/simpleballs.dat

# inspxe-cl -report problems
Used suppression file(s):
P1: Error: Mismatched allocation/deallocation
 New Problem P1.1: Mismatched allocation/deallocation
  /home/peter/tachyon_insp_xe/src/find_and_fix_memory_errors/find_and_fix_memory_errors.cpp(170): Error X24: Allocation site: Function operator(): Module /home/peter/tachyon_insp_xe/tachyon.find_and_fix_memory_errors
  /home/peter/tachyon_insp_xe/src/find_and_fix_memory_errors/find_and_fix_memory_errors.cpp(175): Error X23: Mismatched deallocation site: Function operator(): Module /home/peter/tachyon_insp_xe/tachyon.find_and_fix_memory_errors

问题来了,如果经过检查,源文件的本身没有问题,而是函数调用者的问题,我们需要调用信息栈的信息,以便把错误发给函数的调用者。

此处使用 “-verbose” 开关,输出更多的有用信息。

# inspxe-cl -report problems -verbose | more
Used suppression file(s):
P1: Error: Mismatched allocation/deallocation
 New Problem P1.1: Mismatched allocation/deallocation
  /home/peter/tachyon_insp_xe/src/find_and_fix_memory_errors/find_and_fix_memory
_errors.cpp(170): Error X24: Allocation site: Function operator(): Module /home/
peter/tachyon_insp_xe/tachyon.find_and_fix_memory_errors
  Code snippet:
   168          for (int y = r.begin(); y != r.end(); ++y) {
   169                          {
  >170                                  drawing_area * drawing = new drawing_are
a(startx, totaly-y, stopx-startx, 1);
   171                                  for (int x = startx ; x < stopx; x++) {
   172                                          color_t c = render_one_pixel (x,
 y, local_mbox, serial, startx, stopx, starty, stopy);

  Stack (1 of 1 instance(s))
  >tachyon.find_and_fix_memory_errors!operator() - /home/peter/tachyon_insp_xe/s
rc/find_and_fix_memory_errors/find_and_fix_memory_errors.cpp:170
   tachyon.find_and_fix_memory_errors!execute - /home/peter/tachyon_insp_xe/tbbf
orexamples/include/tbb/parallel_for.h:91
   libtbb_debug.so.2!local_wait_for_all - /nfs/fx/disks/fx_home_disk2/tbbtest/it
t/branch_tbb30/tbb/1.0/build/fxeolin09icc11_1_64_debug/../../src/tbb/custom_sche
duler.h:308
   libtbb_debug.so.2!local_spawn_root_and_wait - /nfs/fx/disks/fx_home_disk2/tbb
test/itt/branch_tbb30/tbb/1.0/build/fxeolin09icc11_1_64_debug/../../src/tbb/sche
duler.cpp:742
   libtbb_debug.so.2!spawn_root_and_wait - /nfs/fx/disks/fx_home_disk2/tbbtest/i
tt/branch_tbb30/tbb/1.0/build/fxeolin09icc11_1_64_debug/../../src/tbb/scheduler.
h:535
   tachyon.find_and_fix_memory_errors!spawn_root_and_wait - /home/peter/tachyon_
insp_xe/tbbforexamples/include/tbb/task.h:621
   tachyon.find_and_fix_memory_errors!run - /home/peter/tachyon_insp_xe/tbbforex
amples/include/tbb/parallel_for.h:75
   tachyon.find_and_fix_memory_errors!parallel_for<tbb::blocked_range<int>, draw
_task> - /home/peter/tachyon_insp_xe/tbbforexamples/include/tbb/parallel_for.h:1
38
   tachyon.find_and_fix_memory_errors!thread_trace - /home/peter/tachyon_insp_xe
/src/find_and_fix_memory_errors/find_and_fix_memory_errors.cpp:209
   tachyon.find_and_fix_memory_errors!trace_shm - /home/peter/tachyon_insp_xe/sr
c/trace_rest.cpp:110
   tachyon.find_and_fix_memory_errors!trace_region - /home/peter/tachyon_insp_xe
/src/trace_rest.cpp:123
   tachyon.find_and_fix_memory_errors!renderscene - /home/peter/tachyon_insp_xe/
src/render.cpp:93
   tachyon.find_and_fix_memory_errors!rt_renderscene - /home/peter/tachyon_insp_
xe/src/api.cpp:124
   tachyon.find_and_fix_memory_errors!on_process - /home/peter/tachyon_insp_xe/s
rc/video.cpp:159
   tachyon.find_and_fix_memory_errors!main_loop - /home/peter/tachyon_insp_xe/co
mmon/gui/xvideo.cpp:258
   tachyon.find_and_fix_memory_errors!main - /home/peter/tachyon_insp_xe/src/vid
eo.cpp:205
   libc.so.6!__libc_start_main - /lib64/libc.so.6:0x1d990

  /home/peter/tachyon_insp_xe/src/find_and_fix_memory_errors/find_and_fix_memory
_errors.cpp(175): Error X23: Mismatched deallocation site: Function operator():
Module /home/peter/tachyon_insp_xe/tachyon.find_and_fix_memory_errors
  Code snippet:
   173                                          drawing->put_pixel(c);
   174                                  }
  >175                                  free(drawing);  //Memory Error: use dele
te instead of free
   176                                  //delete drawing;
   177                          }

 

Para obter mais informações sobre otimizações de compiladores, consulte Aviso sobre otimizações.