1 <!-- summary: About the Debugger with the `mrdb` Command -->
3 # How to Use the mruby Debugger
5 copyright (c) 2014 Specified Non-Profit Corporation mruby Forum
9 This file documents the mruby debugger ('mrdb') methods.
11 ## 2 Debugging with mrdb
15 The trunk of the mruby source tree, with the most recent mrdb, can be checked out with the following command:
18 $ git clone https://github.com/mruby/mruby.git
21 To run the `make` command:
28 By default, the `make` command will install the debugger files into mruby/bin.
30 You can add the path for mrdb on your host environment with the following command:
33 $ echo "export PATH=\$PATH:MRUBY_ROOT/bin" >> ~/.bashrc
37 `*MRUBY_ROOT` is the directory in which mruby source code will be installed.
39 To confirm mrdb was installed properly, run mrdb with the `--version` option:
43 mruby 3.4.0 (2025-04-20)
46 ## 2.2 Basic Operation
48 ### 2.2.1 Debugging mruby Script Files (rb file) with mrdb
50 To invoke the mruby debugger, just type `mrdb`.
52 To specify the script file:
55 $ mrdb [option] filename
58 For example: Debugging sample.rb
64 You can execute the shell commands listed below:
66 | command | description |
67 | :--------------: | :------------------------------------------------------------------------ |
68 | run | execute programs |
69 | step | execute stepping |
70 | continue | execute continuing program |
71 | break | configure the breaking point |
72 | delete | deleting the breaking points |
73 | disable | disabling the breaking points |
74 | enable | enabling the breaking points |
75 | info breakpoints | showing list of the breaking points |
76 | print | evaluating and printing the values of the mruby expressions in the script |
77 | list | displaying the source cords |
78 | help | showing help |
79 | quit | terminating the mruby debugger |
81 ### 2.2.2 Debugging mruby Binary Files (mrb file) with mrdb
83 You can debug the mruby binary files.
85 #### 2.2.2.1 Debugging the binary files
88 To debug mruby binary files, you need to compile mruby files with option `-g`.
94 You can debug the mruby binary files with following command and the option `-b`.
100 Then you can execute all debugger shell commands.
104 You can use any breakpoint to stop the program by specifying the line number and method name.
105 The breakpoint list will be displayed after you have set the breakpoint successfully.
116 The breakpoint will be ordered in serial from 1.
117 The number, which was given to the deleted breakpoint, will never be given to another breakpoint again.
119 You can give multiple breakpoints to the specified the line number and method.
120 Be aware that the breakpoint command will not check the validity of the class name and method name.
122 You can get the current breakpoint information by the following options.
124 breakpoint breakpoint number : filename. line number
126 breakpoint breakpoint number : [class name,] method name
128 #### Continue Command
137 N: the next breakpoint number
139 When resuming the program, it will stop at breakpoint N (N-1 breakpoint will be ignored).
141 When you run the `continue` command without specifying N, the program will be stopped at the next breakpoint.
146 (foo.rb:1) continue 3
149 This will resume the program and stop it at the third breakpoint.
153 This will delete the specified breakpoint.
158 delete [breakpoint-no]
162 breakpoint-no: breakpoint number
170 This will delete all the breakpoints.
173 (foo.rb:1) delete 1 3
176 This will delete the breakpoint at 1 and 3.
180 This will disable the specified breakpoint.
185 disable [breakpoint-no]
189 reappointing: breakpoint number
197 Use `disable` if you would like to disable all the breakpoints.
200 (foo.rb:1) disable 1 3
203 This will disable the breakpoints at 1 and 3.
207 This will enable the specified breakpoints.
212 enable [breakpoint-no]
216 breakpoint-no: breakpoint number
224 Enabling all breakpoints
227 (foo.rb:1) enable 1 3
230 Enabling the breakpoint 1 and 3
234 Evaluating the string as source code and printing the value.
236 Same as print command, please see print command.
240 Displaying the help message.
249 Typing `help` without any options will display the command list.
251 #### Info Breakpoints Command
253 Displaying the specified breakpoint information.
258 info breakpoints [breakpoint-no]
262 breakpoint-no: breakpoint number
264 Typing "info breakpoints" without ant option will display all breakpoint information.
268 (sample.rb:1) info breakpoints
270 1 breakpoint y at sample.rb:3 -> filename,line number
271 2 breakpoint n in Sample_class:sample_class_method -> [class:]method name
272 3 breakpoint y in sample_global_method
275 Displaying the specified breakpoint number:
278 (foo.rb:1) info breakpoints 1 3
280 1 breakpoint y at sample.rb:3
281 3 breakpoint y in sample_global_method
286 To display the code of the source file.
291 list [filename:]first[,last]
292 l [filename]:first[,last]
295 first: the opening row number
296 last : the closing row number
298 When you specify the `first`, but not the `last` option, you will receive 10 rows.
299 When you do not specify both the `first` and `last` options, you will receive the next 10 rows.
304 Specifying filename and first row number
305 sample.rb:1) list sample2.rb:5
308 Specifying the filename and the first and last row number:
311 (sample.rb:1) list sample2.rb:6,7
316 Evaluating the string as source code and printing the value.
327 The expression is mandatory.
328 The displayed expressions will be serially ordered from 1.
329 If an exception occurs, the exception information will be displayed, and the debugging will be continued.
334 (sample.rb:1) print 1+2
336 (sample.rb:1) print self
340 Below is the case of the exception:
343 (sample.rb:1) print (1+2
344 $1 = SyntaxError: line 1: syntax error, unexpected $end, expecting ')'
349 Quitting the debugger.
360 Running the program and stopping at the first breakpoint.
371 This will run the program step by step.
372 When the method and the block are invoked, the program will stop at the first row.
373 The program, which is developed in C, will be ignored.