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.  使用运行时检查

10.  修复并继续

11.  调试多线程应用程序

12.  调试子进程

13.  调试 OpenMP 程序

14.  处理信号

15.  使用 dbx 调试 C++

使用 dbx 调试 C++

dbx 中的异常处理

异常处理命令

exception [-d | +d] 命令

intercept [-all] [-x] [-set] [ typename] 命令

unintercept [-all] [-x] [ typename] 命令

whocatches typename 命令

异常处理示例

使用 C++ 模板调试

模板示例

C++ 模板的命令

whereis name 命令

whatis name 命令

stop inclass classname 命令

stop infunction name 命令

stop in function 命令

call function_name( parameters) 命令

print 表达式

list 表达式

16.  使用 dbx 调试 Fortran

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

18.  在机器指令级调试

19.  将 dbx 与 Korn Shell 配合使用

20.  调试共享库

A.  修改程序状态

B.  事件管理

C.  宏

D.  命令参考

索引

dbx 中的异常处理

如果出现异常,程序便停止运行。异常会发送编程异常信号,例如:被零除或数组上溢。可以设置块来捕获代码中其他位置的表达式引起的异常。

调试程序时,您可以使用 dbx 完成以下操作:

如果在程序停止于异常抛出点后执行 step 命令,则将于堆栈展开期间执行的第一个析构函数的起始处返回控制。如果通过 step 命令步出堆栈展开期间执行的析构函数,则将于下一个析构函数的起始处返回控制。当所有析构函数都执行完毕后,step 命令将前进到处理异常抛出的 catch 块。

异常处理命令

exception [-d | +d] 命令

在调试期间,可以随时使用 exception 命令显示异常的类型。如果使用 exception 命令时不带选项,则所示类型由 dbx 环境变量 output_dynamic_type 的设置确定:

如果指定 -d+d 选项,则会覆盖环境变量的设置:

有关更多信息,请参见exception 命令

intercept [-all] [-x] [-set] [ typename] 命令

可以在堆栈展开之前拦截或捕获特定类型的异常。使用不带参数的 intercept 命令可列出正在拦截的类型。使用 -all 可拦截所有异常。使用 typename 可将类型添加到拦截列表中。使用 -x 可从排除列表中排除特定类型,从而不拦截该类型。使用 -set 可清除拦截列表和排除列表,并将列表设置为仅拦截或排除指定类型的抛出。

例如,要拦截除 int 之外的所有类型,可键入:

(dbx) intercept -all -x int

要拦截类型为 Error 的异常,可键入:

(dbx) intercept Error

如果拦截的 CommonError 异常过多,可键入以下内容排除这些异常:

(dbx) intercept -x CommonError

如果键入不带参数的 intercept 命令,则会发现拦截列表中包括未处理的异常和意外的异常(缺省情况下将拦截这些异常),以及 Error 类的异常(CommonError 类的异常除外)。

(dbx) intercept
-unhandled   -unexpected   class Error -x class CommonError

如果您随后意识到 Error 不是您需要的异常类,但是不知道要查找的异常类的名称,则可以通过键入以下内容来尝试拦截除 Error 类异常之外的所有异常:

(dbx) intercept -all -x Error

有关更多信息,请参见intercept 命令

unintercept [-all] [-x] [ typename] 命令

使用 unintercept 命令可从拦截列表或排除列表中删除异常类型。使用不带参数的命令可列出正在拦截的类型(与 intercept 命令相同)。使用 -all 可从拦截列表中删除所有类型。使用 typename 可从拦截列表中删除一个类型。使用 -x 可从排除列表中删除一个类型。

有关更多信息,请参见unintercept 命令

whocatches typename 命令

如果在当前执行点抛出异常,whocatches 命令会报告捕获类型为 typename 的异常的位置。使用此命令可查出从堆栈顶帧抛出异常时会发生什么情况。

捕获 typename 的 catch 子句的行号、函数名和帧号均会显示出来。如果捕获点所在函数与抛出异常的函数相同,则该命令返回 "type is unhandled"

有关更多信息,请参见whocatches 命令

异常处理示例

此示例通过一个包含异常的程序样例说明dbx 中如何进行异常处理。在函数 bar 中抛出类型为 int 的异常,并在后面的 catch 块中捕获该异常。

1  #include <stdio.h>
2
3  class c {
4      int x;
5    public:
6      c(int i) { x = i; }
7      ~c() {
8                printf("destructor for c(%d)\n", x);
9           }
10  };
11
12  void bar() {
13      c c1(3);
14      throw(99);
15  }
16
17  int main() {
18      try {
19          c c2(5);
20          bar();
21          return 0;
22      }
23      catch (int i) {
24          printf("caught exception %d\n", i);
25      }
26  }

下面摘录的程序示例显示了 dbx 中的异常处理功能。

(dbx) intercept
-unhandled -unexpected
(dbx) intercept int
<dbx> intercept
-unhandled -unexpected int
(dbx) stop in bar
(2) stop in bar()
(dbx)run
Running: a.out
(process id 304)
Stopped in bar at line 13 in file “foo.cc”
   13       c c1(3);
(dbx) whocatches int
int is caught at line 24, in function main (frame number 2)
(dbx) whocatches c
dbx: no runtime type info for class c (never thrown or caught)
(dbx) cont
Exception of type int is caught at line 24, in function main (frame number 4)
stopped in _exdbg_notify_of_throw at 0xef731494
0xef731494: _exdbg_notify_of_throw          :        jmp     %o7 + 0x8
Current function is bar
   14        throw(99);
(dbx) step
stopped in c::~c at line 8 in file "foo.cc"
    8         printf("destructor for c(%d)\n", x);
(dbx) step
destructor for c(3)
stopped in c::~c at line 9 in file "foo.cc"
    9       }
(dbx) step
stopped in c::~c at line 8 in file "foo.cc"
    8        printf("destructor for c(%d)\n", x);
(dbx) step
destructor for c(5)
stopped in c::~c at line 9 in file "foo.cc"
    9       )
(dbx) step
stopped in main at line 24 in file "foo.cc"
   24           printf("caught exception %d\n", i);
(dbx) step
caught exception 99
stopped in main at line 26 in file "foo.cc"
   26   }