JavaScript is required to for searching.
跳过导航链接
退出打印视图
Oracle Solaris Studio 12.3:Discover 和 Uncover 用户指南     Oracle Solaris Studio 12.3 Information Library (简体中文)
search filter icon
search icon

文档信息

前言

1.  简介

2.  内存错误搜索工具 (Discover)

Discover 的使用要求

必须正确准备二进制文件

不能使用使用预装或审计的二进制文件

可以使用重新定义标准内存分配函数的二进制文件

快速入门

检测准备好的二进制文件

缓存共享库

检测共享库

忽略库

命令行选项

输出选项

检测选项

缓存选项

其他选项

bit.rc 初始化文件

SUNW_DISCOVER_OPTIONS 环境变量

SUNW_DISCOVER_FOLLOW_FORK_MODE 环境变量

运行检测过的二进制文件

分析 Discover 报告

分析 HTML 报告

使用 `Errors`(错误)选项卡

使用 `Warnings`(警告)选项卡

使用 `Memory Leaks`(内存泄漏)选项卡

使用控制面板

分析 ASCII 报告

内存访问错误和警告

内存访问错误

ABR

ABW

BFM

BRP

DFM

FMR

FMW

FRP

IMR

IMW

OLP

PIR

SBR

SBW

UAR

UAW

UMR

内存访问警告

AZS

解释 Discover 错误消息

部分初始化内存

可疑装入

未检测的代码

使用 Discover 时的限制

仅检测有注释的代码

计算机指令可能不同于源代码

编译器选项影响生成的代码

系统库可能会影响报告的错误

定制内存管理可能会影响数据的准确性

无法检测到静态和自动数组的超出边界错误

3.  代码覆盖工具 (Uncover)

索引

内存访问错误和警告

Discover 会检测和报告许多内存访问错误,并就可能是错误的访问向您发出警告。

内存访问错误

Discover 可检测到以下内存访问错误:

以下几部分列出了一些简单的示例程序,这些程序会生成上述某些错误。

ABR

  //  ABR: reading memory beyond array bounds at address 0x%1x (%d byte%s)"
  int *a = (int*) malloc(sizeof(int[5]));
  printf("a[5] = %d\n",a[5]);

ABW

  //  ABW:  writing to memory beyond array bounds
  int *a = (int*) malloc(sizeof(int[5]));
  a[5] = 5;

BFM

  //  BFM:  freeing wrong memory block
  int *p = (int*) malloc(sizeof(int));
  free(p+1);

BRP

  //  BRP is "bad address parameter for realloc 0x%1x"
  int *p = (int*) realloc(0,sizeof(int));
  int *q = (int*) realloc(p+20,sizeof(int[2]));

DFM

  // DFM is "double freeing memory"
  int *p = (int*) malloc(sizeof(int));
  free(p);
  free(p);'

FMR

  //  FMR is "reading from freed memory at address 0x%1x  (%d byte%s)"
  int *p = (int*) malloc(sizeof(int));
  free(p);
  printf("p = 0x%h\n",p);

FMW

  //  FMW is "writing to freed memory at address 0x%1x (%d byte%s)"
  int *p = (int*) malloc(sizeof(int));
  free(p);
  *p = 1;

FRP

  //  FRP:  freed pointer passed to realloc
  int *p = (int*) malloc(sizeof(int));
  free(0);
  int *q = (int*) realloc(p,sizeof(int[2]));

IMR

  //  IMR:  read from invalid memory address
  int *p = 0;
  int i = *p;   // generates Signal 11...

IMW

  //  IMW:  write to invalid memory address
  int *p = 0;
  *p = 1;       // generates Signal 11...

OLP

  char *s=(char *) malloc(15);
  memset(s, 'x', 15);
  memcpy(s, s+5, 10);
  return 0;

PIR

  //  PIR:  accessing partially initialized data
  int *p = (int*) malloc(sizeof(int));
  *((char*)p) = 'c';
  printf("*(p = %d\n",*(p+1)); 

SBR

  int a[2]={0,1};
  printf("a[-10]=%d\n",a[-10]);
  return 0;

SBW

  int a[2]={0,1)'
  a[-10]=2;
  return 0;

UAR

  //  UAR is "reading from unallocated memory"
  int *p = (int*) malloc(sizeof(int));
  printf("*(p+1) = %d\n",*(p+1));

UAW

  // UAW is "writing to unallocated memory"
  int *p = (int*) malloc(sizeof(int));
  *(p+1) = 1;

UMR

  // UMR is "accessing uninitialized data from address 0x%1x (A%d byte%s)"
  int *p = (int*) malloc(sizeof(int));
  printf("*p = %d\n",*p);

内存访问警告

Discover 会报告下列内存访问警告:

下面列出了一个会生成 AZS 警告的简单示例程序。

AZS

  //  AZS:  allocating zero size memory block
  int *p = malloc();