1 # How to Use the mruby Debugger
3 copyright (c) 2014 Specified Non-Profit Corporation mruby Forum
7 This file documents the mruby debugger ('mrdb') methods.
9 ## 2 Debugging with mrdb
13 The trunk of the mruby source tree, with the most recent mrdb, can be checked out with the following command:
16 $ git clone https://github.com/mruby/mruby.git
19 To run the `make` command:
26 By default, the `make` command will install the debugger files into mruby/bin.
28 You can add the path for mrdb on your host environment with the following command:
31 $ echo "export PATH=\$PATH:MRUBY_ROOT/bin" >> ~/.bashrc
35 `*MRUBY_ROOT` is the directory in which mruby source code will be installed.
37 To confirm mrdb was installed properly, run mrdb with the `--version` option:
41 mruby 2.1.2 (2020-08-06)
44 ## 2.2 Basic Operation
46 ### 2.2.1 Debugging mruby Script Files (rb file) with mrdb
48 To invoke the mruby debugger, just type `mrdb`.
50 To specify the script file:
53 $ mrdb [option] file name
56 For example: Debugging sample.rb
62 You can execute the shell commands listed below:
66 |run|execute programs|
67 |step|execute stepping|
68 |continue|execute continuing program|
69 |break|configure the breaking point|
70 |delete|deleting the breaking points|
71 |disable|disabling the breaking points|
72 |enable|enabling the breaking points|
73 |info breakpoints|showing list of the breaking points|
74 |print|evaluating and printing the values of the mruby expressions in the script|
75 |list|displaying the source cords|
77 |quit|terminating the mruby debugger|
79 ### 2.2.2 Debugging mruby Binary Files (mrb file) with mrdb
81 You can debug the mruby binary files.
83 #### 2.2.2.1 Debugging the binary files
86 To debug mruby binary files, you need to compile mruby files with option `-g`.
92 You can debug the mruby binary files with following command and the option `-b`.
98 Then you can execute all debugger shell commands.
102 You can use any breakpoint to stop the program by specifying the line number and method name.
103 The breakpoint list will be displayed after you have set the breakpoint successfully.
114 The breakpoint will be ordered in serial from 1.
115 The number, which was given to the deleted breakpoint, will never be given to another breakpoint again.
117 You can give multiple breakpoints to specified the line number and method.
118 Be ware that breakpoint command will not check the validity of the class name and method name.
120 You can get the current breakpoint information by the following options.
122 breakpoint breakpoint number : file name. line number
124 breakpoint breakpoint number : [class name,] method name
126 #### Continue Command
135 N: the next breakpoint number
137 When resuming the program, it will stop at breakpoint N (N-1 breakpoint will be ignored).
139 When you run the `continue` command without specifying N, the program will be stopped at the next breakpoint.
144 (foo.rb:1) continue 3
147 This will resume the program and stop it at the third breakpoint.
151 This will delete the specified breakpoint.
156 delete [breakpoint-no]
160 breakpoint-no: breakpoint number
168 This will delete all of the breakpoints.
171 (foo.rb:1) delete 1 3
174 This will delete the breakpoint at 1 and 3.
178 This will disable the specified breakpoint.
183 disable [breakpoint-no]
187 reappointing: breakpoint number
195 Use `disable` if you would like to disable all of the breakpoints.
198 (foo.rb:1) disable 1 3
201 This will disable the breakpoints at 1 and 3.
205 This will enable the specified breakpoints.
210 enable [breakpoint-no]
214 breakpoint-no: breakpoint number
222 Enabling all breakpoints
224 (foo.rb:1) enable 1 3
227 Enabling the breakpoint 1 and 3
231 Evaluating the string as source code and printing the value.
233 Same as print command, please see print command.
237 Displaying the help message.
246 Typing `help` without any options will display the command list.
248 #### Info Breakpoints Command
250 Displaying the specified breakpoint information.
255 info breakpoints [breakpoint-no]
259 breakpoint-no: breakpoint number
261 Typing "info breakpoints" without ant option will display all breakpoint information.
265 (sample.rb:1) info breakpoints
267 1 breakpoint y at sample.rb:3 -> file name,line number
268 2 breakpoint n in Sample_class:sample_class_method -> [class:]method name
269 3 breakpoint y in sample_global_method
272 Displaying the specified breakpoint number:
275 (foo.rb:1) info breakpoints 1 3
277 1 breakpoint y at sample.rb:3
278 3 breakpoint y in sample_global_method
283 To display the code of the source file.
288 list [filename:]first[,last]
289 l [filename]:first[,last]
292 first: the opening row number
293 last : the closing row number
295 When you specify the `first`, but not the `last` option, you will receive 10 rows.
296 When you do not specify both the `first` and `last` options, you will receive the next 10 rows.
301 Specifying file name and first row number
302 sample.rb:1) list sample2.rb:5
305 Specifying the file name and the first and last row number:
308 (sample.rb:1) list sample2.rb:6,7
313 Evaluating the string as source code and printing the value.
324 The expression is mandatory.
325 The displayed expressions will be serially ordered from 1.
326 If an exception occurs, the exception information will be displayed and the debugging will be continued.
331 (sample.rb:1) print 1+2
333 (sample.rb:1) print self
337 Below is the case of the exception:
340 (sample.rb:1) print (1+2
341 $1 = SyntaxError: line 1: syntax error, unexpected $end, expecting ')'
346 Quitting the debugger.
357 Running the program and stopping at the first breakpoint.
368 This will run the program step by step.
369 When the method and the block are invoked, the program will be stop at the first row.
370 The program, which is developed in C, will be ignored.