JavaScript is required to for searching.
跳过导航链接
退出打印视图
Oracle Solaris Studio 12.3:使用 dbx 调试程序     Oracle Solaris Studio 12.3 Information Library (简体中文)
search filter icon
search icon

文档信息

前言

1.  dbx 入门

2.  启动 dbx

3.  定制 dbx

4.  查看和导航到代码

5.  控制程序执行

6.  设置断点和跟踪

7.  使用调用堆栈

8.  求值和显示数据

9.  使用运行时检查

运行时检查功能

何时使用运行时检查

运行时检查要求

使用运行时检查

启用内存使用和内存泄漏检查

启用内存访问检查

启用所有运行时检查

关闭运行时检查

运行程序

使用访问检查

理解内存访问错误报告

内存访问错误

使用内存泄漏检查

检测内存泄漏错误

可能的泄漏

检查泄漏

理解内存泄漏报告

生成泄漏报告

合并泄漏

修复内存泄漏

利用内存使用检查

抑制错误

抑制的类型

按作用域和类型抑制

抑制上一错误

限制报告的错误数

抑制错误示例

缺省抑制

使用抑制来管理错误

对子进程使用运行时检查

对连接的进程使用运行时检查

在运行 Solaris 的系统中

在运行 Linux 的系统中

结合使用修复并继续功能与运行时检查

运行时检查应用编程接口

在批处理模式下使用运行时检查

bcheck 语法

bcheck 示例

直接在 dbx 中启用批处理模式

疑难解答提示

运行时检查限制

具有更多符号和调试信息时工作效果会更好

SIGSEGVSIGALTSTACK 信号在 x86 平台上受限制

当 8 MB 的所有现有代码中具有足够的补丁区域时工作效果会更好(仅限 SPARC 平台)。

运行时检查错误

访问错误

错误释放 (baf) 错误

重复释放 (duf) 错误

未对齐释放 (maf) 错误

未对齐读 (mar) 错误

未对齐写 (maw) 错误

内存不足 (oom) 错误

从数组越界中读 (rob) 错误

从未分配的内存中读 (rua) 错误

从未初始化的内存中读 (rui) 错误

写入到数组越界内存 (wob) 错误

写入到只读内存 (wro) 错误

写入到未分配内存 (wua) 错误

内存泄漏错误

地址位于块内 (aib) 错误

地址位于寄存器内 (air) 错误

内存泄漏 (mel) 错误

10.  修复并继续

11.  调试多线程应用程序

12.  调试子进程

13.  调试 OpenMP 程序

14.  处理信号

15.  使用 dbx 调试 C++

16.  使用 dbx 调试 Fortran

17.  使用 dbx 调试 Java 应用程序

18.  在机器指令级调试

19.  将 dbx 与 Korn Shell 配合使用

20.  调试共享库

A.  修改程序状态

B.  事件管理

C.  宏

D.  命令参考

索引

对子进程使用运行时检查

要对子进程使用运行时检查,必须将 dbx 环境变量 rtc_inherit 设置为 on。缺省情况下,该变量设置为 off。(请参见设置 dbx 环境变量。)

如果针对父进程启用了运行时检查,且 dbx 环境变量 follow_fork_mode 设置为 child,则 dbx 支持对子进程使用运行时检查(请参见设置 dbx 环境变量)。

发生派生时,dbx 会自动对子进程使用运行时检查。如果程序调用 exec(),则调用 exec() 的程序的运行时检查设置会传递给该程序。

在任一时刻,运行时检查只能控制一个进程。下面是一个示例。

% cat -n program1.c
     1 #include <sys/types.h>
     2 #include <unistd.h>
     3 #include <stdio.h>
     4
     5 int
     6 main()
     7 {
     8      pid_t child_pid;
     9      int parent_i, parent_j;
    10
    11      parent_i = parent_j;
    12
    13      child_pid = fork();
    14
    15      if (child_pid == -1) {
    16          printf("parent: Fork failed\n");
    17          return 1;
    18      } else if (child_pid == 0) {
    19          int child_i, child_j;
    20
    21          printf("child: In child\n");
    22          child_i = child_j;
    23          if (execl("./program2", NULL) == -1) {
    24              printf("child: exec of program2 failed\n");
    25              exit(1);
    26          }
    27      } else {
    28          printf("parent: child’s pid = %d\n", child_pid);
    29      }
    30      return 0;
    31 }
 % cat -n program2.c
     1
     2 #include <stdio.h>
     3
     4 main()
     5 {
     6      int program2_i, program2_j;
     7
     8      printf ("program2: pid = %d\n", getpid());
     9      program2_i = program2_j;
    10
    11      malloc(8);
    12
    13      return 0;
    14 }
%
 % cc -g -o program1 program1.c
 % cc -g -o program2 program2.c
 % dbx -C program1
 Reading symbolic information for program1
 Reading symbolic information for rtld /usr/lib/ld.so.1
 Reading symbolic information for librtc.so
 Reading symbolic information for libc.so.1
 Reading symbolic information for libdl.so.1
 Reading symbolic information for libc_psr.so.1
 (dbx) check -all
 access checking - ON
 memuse checking - ON
 (dbx) dbxenv rtc_inherit on
 (dbx) dbxenv follow_fork_mode child
 (dbx) run
 Running: program1
 (process id 3885)
 Enabling Error Checking... done
RTC reports first error in the parent, program1
 Read from uninitialized (rui):
 Attempting to read 4 bytes at address 0xeffff110
     which is 104 bytes above the current stack pointer
 Variable is ’parent_j’
 Current function is main
   11       parent_i = parent_j;
(dbx) cont
 dbx: warning: Fork occurred; error checking disabled in parent
 detaching from process 3885
 Attached to process 3886
Because  follow_fork_mode is set to child, when the fork occurs error checking is switched from the parent
to the child process
 stopped in _fork at 0xef6b6040
 0xef6b6040: _fork+0x0008:    bgeu    _fork+0x30
 Current function is main
    13       child_pid = fork();
 parent: child’s pid = 3886
 (dbx) cont
 child: In child
 Read from uninitialized (rui):
 Attempting to read 4 bytes at address 0xeffff108
     which is 96 bytes above the current stack pointer
RTC reports an error in the child
 Variable is ’child_j’
 Current function is main
    22       child_i = child_j;
 (dbx) cont
 dbx: process 3886 about to exec("./program2")
 dbx: program "./program2" just exec’ed
 dbx: to go back to the original program use "debug $oprog"
 Reading symbolic information for program2
 Skipping ld.so.1, already read
 Skipping librtc.so, already read
 Skipping libc.so.1, already read
 Skipping libdl.so.1, already read
 Skipping libc_psr.so.1, already read
When the exec of program2 occurs, the RTC settings are inherited by program2 so access and memory use checking
are enabled for that process
 Enabling Error Checking... done
 stopped in main at line 8 in file "program2.c"
     8       printf ("program2: pid = %d\n", getpid());
(dbx) cont
 program2: pid = 3886
 Read from uninitialized (rui):
 Attempting to read 4 bytes at address 0xeffff13c
     which is 100 bytes above the current stack pointer
RTC reports an access error in the executed program, program2
 Variable is ’program2_j’
 Current function is main
     9       program2_i = program2_j;
 (dbx) cont
 Checking for memory leaks...
RTC prints a memory use and memory leak report for the process that exited while under RTC control, program2
Actual leaks report   (actual leaks:      1  total size:   8
 bytes)

 Total      Num of  Leaked     Allocation call stack
 Size       Blocks  Block
                    Address
==========  ====== ========== ====================================
         8       1    0x20c50  main
 Possible leaks report  (possible leaks:   0  total size:   0
 bytes)

 execution completed, exit code is 0