无涯教程-Ruby Debugger −函数

124 阅读2分钟

语言的易用性无关紧要,如果语言多于几行,通常会包含一些错误。为了帮助处理错误,Ruby的标准发行版包括调试器。

为了启动Ruby调试器,请使用命令行options -r debug 加载调试库。调试器在可执行代码的第一行之前停止,并要求输入用户命令。

使用语法

这是使用ruby调试器的用法语法-

$ruby -r debug filename[, ...]

Ruby调试器命令

这是命令的完整列表,您可以在调试程序时使用这些命令。在这里,不必使用complete关键字来发出命令,[...]内部给出的部分是options。

Sr.No. Command & Description
1

b[reak] [< file| class>:]< line| method>

将断点设置到某个位置。断点是您出于调试目的而希望暂停程序执行的地方。

2

wat [ch] expression

设置观察点。

3

cat [ch](exception|off)

将捕获点设置为异常。

4

b [reak]

显示断点和观察点。

5

del [ete] [n]

删除断点。

6

disp [lay] expression

显示 expression 的值。

7

undisp [lay] [n]

删除n的显示

8

c [ont]

继续执行。

9

s [tep] [n]

执行下n行,进入方法。

10

n [ext] [n]

执行下n行单步执行方法。

11

w [here]

显示堆叠框架

12

f [rame]

在哪里的同义词。

13

l[ist][<-| n- m>]

显示从n到m的源代码行。

14

上[n]

在堆栈帧中上移n个级别。

15

向下[n]

在堆栈帧中向下移动n个级别。

16

fin [ish]

完成当前方法的执行。

17

tr [ace] [on | off]

切换跟踪模式的开和关。

18

q [uit]

退出调试器。

19

v [ar] g [lob]

显示全局变量。

20

v [a] I[ocal]

显示局部变量。

21

v [ar] i [instance] object

显示对象的实例变量

22

v [ar] c [onst] object

显示对象的常量。

23

m[ethod] i[instance] object

显示对象的实例方法。

24

m[ethod] class | module

显示类或模块的实例方法。

25

th [read] l [ist]

显示线程。

26

th [read] c [ur [rent]]

显示当前线程。

27

th [read] n

停止指定的线程。

28

th[read] stop >

n [th]的同义词。

29

th[read] c[ur[rent]] n>

th [read] n的同义词

30

th[read] resume >

恢复线程n

31

p expression

判断表达式

32

h [elp]

显示帮助信息

33

everything else

判断。

考虑以下文件 hello.rb ,该文件需要调试-

#!/usr/bin/env ruby
class Hello
   def initialize( hello )
      @hello=hello
   end
   def hello
      @hello
   end
end

salute=Hello.new( "Hello, Mac!" ) puts salute.hello

这是捕获的一个交互式会话。给定的命令以粗体显示-

[root@ruby]# ruby -r debug hello.rb
Debug.rb
Emacs support available.

hello.rb:3:class Hello (rdb:1) v l salute => nil (rdb:1) b 10 Set breakpoint 1 at hello.rb:10 (rdb:1) c Hello, Mac! [root@ruby]#

参考链接

www.learnfk.com/ruby/ruby-d…