source: EcnlProtoTool/trunk/mruby-2.1.1/doc/guides/debugger.md@ 439

Last change on this file since 439 was 439, checked in by coas-nagasima, 4 years ago

mrubyを2.1.1に更新

File size: 7.1 KB
Line 
1# How to Use the mruby Debugger
2
3copyright (c) 2014 Specified Non-Profit Corporation mruby Forum
4
5## 1. Summary
6
7This file documents the mruby debugger ('mrdb') methods.
8
9## 2 Debugging with mrdb
10
11## 2.1 Building mrdb
12
13The trunk of the mruby source tree, with the most recent mrdb, can be checked out with the following command:
14
15```bash
16$ git clone https://github.com/mruby/mruby.git
17```
18
19To run the `make` command:
20
21```bash
22$ cd mruby
23$ make
24```
25
26By default, the `make` command will install the debugger files into mruby/bin.
27
28You can add the path for mrdb on your host environment with the following command:
29
30```bash
31$ echo "export PATH=\$PATH:MRUBY_ROOT/bin" >> ~/.bashrc
32$ source ~/.bashrc
33```
34
35`*MRUBY_ROOT` is the directory in which mruby source code will be installed.
36
37To confirm mrdb was installed properly, run mrdb with the `--version` option:
38
39```bash
40$ mrdb --version
41mruby 2.1.1 (2020-06-04)
42```
43
44## 2.2 Basic Operation
45
46### 2.2.1 Debugging mruby Script Files (rb file) with mrdb
47
48To invoke the mruby debugger, just type `mrdb`.
49
50To specify the script file:
51
52```bash
53$ mrdb [option] file name
54```
55
56For example: Debugging sample.rb
57
58```bash
59$ mrdb sample.rb
60```
61
62You can execute the shell commands listed below:
63
64|command|description|
65|:-:|:--|
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|
76|help|showing help|
77|quit|terminating the mruby debugger|
78
79### 2.2.2 Debugging mruby Binary Files (mrb file) with mrdb
80
81You can debug the mruby binary files.
82
83#### 2.2.2.1 Debugging the binary files
84
85* notice
86To debug mruby binary files, you need to compile mruby files with option `-g`.
87
88```bash
89$ mrbc -g sample.rb
90```
91
92You can debug the mruby binary files with following command and the option `-b`.
93
94```bash
95$ mrdb -b sample.mrb
96```
97
98Then you can execute all debugger shell commands.
99
100#### Break Command
101
102You can use any breakpoint to stop the program by specifying the line number and method name.
103The breakpoint list will be displayed after you have set the breakpoint successfully.
104
105Usage:
106
107```
108break [file:]linenum
109b [file:]linenum
110break [class:]method
111b [class:]method
112```
113
114The breakpoint will be ordered in serial from 1.
115The number, which was given to the deleted breakpoint, will never be given to another breakpoint again.
116
117You can give multiple breakpoints to specified the line number and method.
118Be ware that breakpoint command will not check the validity of the class name and method name.
119
120You can get the current breakpoint information by the following options.
121
122breakpoint breakpoint number : file name. line number
123
124breakpoint breakpoint number : [class name,] method name
125
126#### Continue Command
127
128Usage:
129
130```
131continue [N]
132c [N]
133```
134
135N: the next breakpoint number
136
137When resuming the program, it will stop at breakpoint N (N-1 breakpoint will be ignored).
138
139When you run the `continue` command without specifying N, the program will be stopped at the next breakpoint.
140
141Example:
142
143```
144(foo.rb:1) continue 3
145```
146
147This will resume the program and stop it at the third breakpoint.
148
149#### Delete Command
150
151This will delete the specified breakpoint.
152
153Usage:
154
155```
156delete [breakpoint-no]
157d [breakpoint-no]
158```
159
160breakpoint-no: breakpoint number
161
162Example:
163
164```
165(foo.rb:1) delete
166```
167
168This will delete all of the breakpoints.
169
170```
171(foo.rb:1) delete 1 3
172```
173
174This will delete the breakpoint at 1 and 3.
175
176#### Disable Command
177
178This will disable the specified breakpoint.
179
180Usage:
181
182```
183disable [breakpoint-no]
184dis [breakpoint-no]
185```
186
187reappointing: breakpoint number
188
189Example:
190
191```
192(foo.rb:1) disable
193```
194
195Use `disable` if you would like to disable all of the breakpoints.
196
197```
198(foo.rb:1) disable 1 3
199```
200
201This will disable the breakpoints at 1 and 3.
202
203#### Enable Command
204
205This will enable the specified breakpoints.
206
207Usage:
208
209```
210enable [breakpoint-no]
211e [breakpoint-no]
212```
213
214breakpoint-no: breakpoint number
215
216Example:
217
218```
219(foo.rb:1) enable
220```
221
222Enabling all breakpoints
223```
224(foo.rb:1) enable 1 3
225```
226
227Enabling the breakpoint 1 and 3
228
229#### eval command
230
231Evaluating the string as source code and printing the value.
232
233Same as print command, please see print command.
234
235#### help command
236
237Displaying the help message.
238
239Usage:
240
241```
242help [command]
243h [command]
244```
245
246Typing `help` without any options will display the command list.
247
248#### Info Breakpoints Command
249
250Displaying the specified breakpoint information.
251
252Usage:
253
254```
255info breakpoints [breakpoint-no]
256i b [breakpoint-no]
257```
258
259breakpoint-no: breakpoint number
260
261Typing "info breakpoints" without ant option will display all breakpoint information.
262Example:
263
264```
265(sample.rb:1) info breakpoints
266Num Type Enb What
2671 breakpoint y at sample.rb:3 -> file name,line number
2682 breakpoint n in Sample_class:sample_class_method -> [class:]method name
2693 breakpoint y in sample_global_method
270```
271
272Displaying the specified breakpoint number:
273
274```
275(foo.rb:1) info breakpoints 1 3
276Num Type Enb What
2771 breakpoint y at sample.rb:3
2783 breakpoint y in sample_global_method
279```
280
281#### List Command
282
283To display the code of the source file.
284
285Usage:
286
287```
288list [filename:]first[,last]
289l [filename]:first[,last]
290```
291
292first: the opening row number
293last : the closing row number
294
295When you specify the `first`, but not the `last` option, you will receive 10 rows.
296When you do not specify both the `first` and `last` options, you will receive the next 10 rows.
297
298Example:
299
300```
301Specifying file name and first row number
302sample.rb:1) list sample2.rb:5
303```
304
305Specifying the file name and the first and last row number:
306
307```
308(sample.rb:1) list sample2.rb:6,7
309```
310
311#### Print Command
312
313Evaluating the string as source code and printing the value.
314
315Usage:
316
317```
318print [expr]
319p [expr]
320```
321
322expr: expression
323
324The expression is mandatory.
325The displayed expressions will be serially ordered from 1.
326If an exception occurs, the exception information will be displayed and the debugging will be continued.
327
328Example:
329
330```
331(sample.rb:1) print 1+2
332$1 = 3
333(sample.rb:1) print self
334$2 = main
335```
336
337Below is the case of the exception:
338
339```
340(sample.rb:1) print (1+2
341$1 = SyntaxError: line 1: syntax error, unexpected $end, expecting ')'
342```
343
344#### Quit Command
345
346Quitting the debugger.
347
348Usage:
349
350```
351quit
352q
353```
354
355#### Run Command
356
357Running the program and stopping at the first breakpoint.
358
359Usage:
360
361```
362run
363r
364```
365
366#### Step Command
367
368This will run the program step by step.
369When the method and the block are invoked, the program will be stop at the first row.
370The program, which is developed in C, will be ignored.
Note: See TracBrowser for help on using the repository browser.