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++

16.  使用 dbx 调试 Fortran

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

18.  在机器指令级调试

19.  将 dbx 与 Korn Shell 配合使用

20.  调试共享库

A.  修改程序状态

B.  事件管理

事件处理程序

事件安全

创建事件处理程序

操作事件处理程序

使用事件计数器

设置事件规范

断点事件规范

in function

at [filename: ]line_number

at address_expression

infile filename

infunction function

inmember function inmethod function

inclass classname [-recurse | -norecurse]

inobject object-expression [-recurse | -norecurse]

数据更改事件规范

access mode address-expression [, byte-size-expression ]

change variable

cond condition-expression

系统事件规范

dlopen [ lib-path ] dlclose [ lib-path ]

fault fault

lwp_exit

sig signal

sig signal sub-code

sysin code | name

sysout code | name

sysin | sysout

执行进度事件规范

exit exitcode

next

returns

returns function

step

其他事件规范

attach

detach

lastrites

proc_gone

prog_new

stop

sync

syncrtld

thr_create [thread_id ]

thr_exit

throw

throw type

throw -unhandled

throw -unexpected

timer seconds

事件规范修饰符

-if condition

-resumeone

-in function

-disable

-count n -count infinity

-temp

-instr

-thread thread_id

-lwp lwp_id

-hidden

-perm

分析和二义性

使用预定义变量

when 命令有效的变量

$handlerid

when 命令和特定事件有效的变量

事件处理程序示例

为存储到数组成员设置断点

执行简单跟踪

在函数内时启用处理程序 (in function)

确定已执行的行数

确定源代码行执行的指令数

事件发生后启用断点

重放重置应用程序文件

检查程序状态

捕获浮点异常

C.  宏

D.  命令参考

索引

事件处理程序示例

以下是设置事件处理程序的一些示例。

为存储到数组成员设置断点

要在 array[99] 设置数据更改断点,请键入:

(dbx) stop access w &array[99]
(2) stop access w &array[99], 4
(dbx) run
Running: watch.x2
watchpoint array[99] (0x2ca88[4]) at line 22 in file "watch.c"    
   22    array[i] = i;

执行简单跟踪

要实现简单跟踪,请键入:

(dbx) when step { echo at line $lineno; }

在函数内时启用处理程序 (in function)

要在函数内时启用处理程序,请键入:

<dbx> trace step -in foo

它等效于:

    # create handler in disabled state
    when step -disable { echo Stepped to $line; }
    t=$newhandlerid    # remember handler id
    when in foo {
    # when entered foo enable the trace
    handler -enable "$t"
    # arrange so that upon returning from foo,
    # the trace is disabled.
    when returns { handler -disable "$t"; };
    }

确定已执行的行数

要了解在小程序中已执行了多少行,请键入:

(dbx) stop step -count infinity     # step and stop when count=inf
(2) stop step -count 0/infinity
(dbx) run
...
(dbx) status
(2) stop step -count 133/infinity

程序永远不会停止,程序只会终止。执行的行数为 133。此进程速度非常慢。它对多次调用的函数中的断点用处最大。

确定源代码行执行的指令数

要计算一行代码执行了多少个指令,请键入:

(dbx) ...                        # get to the line in question
(dbx) stop step -instr -count infinity
(dbx) step ...
(dbx) status
(3) stop step -count 48/infinity # 48 instructions were executed

如果步过的行进行函数调用,则该函数中的行也计入在内。可以使用 next 事件而非 step 计算指令数(不包括被调用函数)。

事件发生后启用断点

只在另一事件发生后启用断点。例如,如果程序的执行在函数 hash 中开始不正常,但只是发生在第 1300 次符号查找后,可键入:

(dbx) when in lookup -count 1300 {
    stop in hash
    hash_bpt=$newhandlerid
    when proc_gone -temp { delete $hash_bpt; }
}

注 - $newhandlerid 是指刚执行的 stop in 命令。


重放重置应用程序文件

如果应用程序处理需要在 replay 期间重置的文件,可以编写一个处理程序,在每次运行程序时执行该操作:

(dbx) when sync { sh regen ./database; }
(dbx) run < ./database... # during which database gets clobbered
(dbx) save
...              # implies a RUN, which implies the SYNC event which
(dbx) restore # causes regen to run

检查程序状态

要快速查看程序运行时的位置,请键入:

(dbx) ignore sigint
(dbx) when sig sigint { where; cancel; }

然后键入 ^C 在不停止程序的情况下查看程序的堆栈跟踪。

这基本上是收集器人工示例模式的任务(还有更多)。可使用 SIGQUIT (^\)^C 已用尽的情况下中断程序。

捕获浮点异常

要只捕获特定的浮点异常(例如 IEEE 下溢),请键入:

(dbx) ignore FPE               # turn off default handler
(dbx) help signals | grep FPE  # can’t remember the subcode name
...
(dbx) stop sig fpe FPE_FLTUND
...