本节演示了使用断点的一些高级技巧:
使用断点计数
使用受限制的断点
拾取有用的断点计数
监视点
使用断点条件
使用弹出进行微重播
使用修复并继续
本节和示例程序受到了在 dbx 中发现的一个实际错误的启发,该错误的发现顺序与本节中所述的顺序相同。
源代码包含一个名为 in 的样例输入文件,该文件会在示例程序中触发一个错误。in 包含以下代码:
display nonexistent_var # should yield an error display var stop in X # will cause one "stopped" message and display stop in Y # will cause second "stopped" message and display run cont cont run cont cont
使用该输入文件运行程序时,输出如下所示:
$ a.out < in
> display nonexistent_var
error: Don't know about 'nonexistent_var'
> display var
will display 'var'
> stop in X
> stop in Y
> run
running ...
stopped in X
var = {
a = '100'
b = '101
c = '<error>'
d = '102
e = '103'
f = '104'
}
> cont
stopped in Y
var = {
a = '105'
b = '106'
c = '<error>'
d = '107'
e = '108'
f = '109'
}
> cont
exited
> run
running ...
stopped in X
var = {
a = '110'
b = '111'
c = '<error>'
d = '112'
e = '113'
f = '114'
}
> cont
stopped in Y
var = {
a = '115'
b = '116'
c = '<error>'
d = '117'
e = '118'
f = '119'
}
> cont
exited
> quit
Goodby
此输出可能看起来很长,但此示例的重点是展示长时间运行的复杂程序所使用的技术,在这些程序中,单步执行代码或仅仅进行跟踪是不切实际的。
请注意,显示字段 c 的值时,您将获取 <error> 的值。如果该字段包含错误地址,可能会发生这样的情形。