diff options
Diffstat (limited to 'mrbgems/mruby-bin-debugger')
| -rw-r--r-- | mrbgems/mruby-bin-debugger/README.md | 63 | ||||
| -rw-r--r-- | mrbgems/mruby-bin-debugger/bintest/mrdb.rb | 112 | ||||
| -rw-r--r-- | mrbgems/mruby-bin-debugger/bintest/print.rb | 54 | ||||
| -rw-r--r-- | mrbgems/mruby-bin-debugger/mrbgem.rake | 1 | ||||
| -rw-r--r-- | mrbgems/mruby-bin-debugger/tools/mrdb/apibreak.c | 79 | ||||
| -rw-r--r-- | mrbgems/mruby-bin-debugger/tools/mrdb/apiprint.c | 13 | ||||
| -rw-r--r-- | mrbgems/mruby-bin-debugger/tools/mrdb/cmdbreak.c | 36 | ||||
| -rw-r--r-- | mrbgems/mruby-bin-debugger/tools/mrdb/cmdmisc.c | 48 | ||||
| -rw-r--r-- | mrbgems/mruby-bin-debugger/tools/mrdb/cmdprint.c | 44 | ||||
| -rw-r--r-- | mrbgems/mruby-bin-debugger/tools/mrdb/cmdrun.c | 4 | ||||
| -rw-r--r-- | mrbgems/mruby-bin-debugger/tools/mrdb/mrdb.c | 127 | ||||
| -rw-r--r-- | mrbgems/mruby-bin-debugger/tools/mrdb/mrdb.h | 8 |
12 files changed, 323 insertions, 266 deletions
diff --git a/mrbgems/mruby-bin-debugger/README.md b/mrbgems/mruby-bin-debugger/README.md new file mode 100644 index 0000000..64c25fa --- /dev/null +++ b/mrbgems/mruby-bin-debugger/README.md @@ -0,0 +1,63 @@ +# mruby-bin-debugger + +mrdb is the mruby debugger for debugging Ruby scripts. + +## Usage + +``` +mrdb [switches] programfile +``` + +### Options + +- `-b` - load and execute RiteBinary (mrb) file +- `-d` - specify source directory +- `--version` - print the version +- `--copyright` - print the copyright + +## Debugger Commands + +| Command | Abbreviation | Description | +| ------------------ | ------------ | --------------------------- | +| `break` | `b` | Set a breakpoint | +| `continue` | `c` | Continue execution | +| `delete` | `d` | Delete breakpoints | +| `disable` | `dis` | Disable breakpoints | +| `enable` | `en` | Enable breakpoints | +| `eval` | `ev` | Evaluate expression | +| `help` | `h` | Show help | +| `info breakpoints` | `i b` | Show breakpoint information | +| `info locals` | `i l` | Show local variables | +| `list` | `l` | List source code | +| `print` | `p` | Print expression value | +| `quit` | `q` | Quit debugger | +| `run` | `r` | Run program | +| `step` | `s` | Step into | +| `next` | `n` | Step over | + +## Examples + +```bash +# Start debugging a script +mrdb script.rb + +# Debug a compiled binary with source directory +mrdb -b -d /path/to/source script.mrb +``` + +### Debugging Session Example + +``` +$ mrdb script.rb +(mrdb) b 10 # Set breakpoint at line 10 +(mrdb) r # Run the program +(mrdb) p variable # Print variable value +(mrdb) n # Step to next line +(mrdb) i l # Show local variables +(mrdb) c # Continue execution +(mrdb) q # Quit +``` + +## License + +MIT License - see the mruby LICENSE file. diff --git a/mrbgems/mruby-bin-debugger/bintest/mrdb.rb b/mrbgems/mruby-bin-debugger/bintest/mrdb.rb index bc5dc45..00d327d 100644 --- a/mrbgems/mruby-bin-debugger/bintest/mrdb.rb +++ b/mrbgems/mruby-bin-debugger/bintest/mrdb.rb @@ -1,7 +1,7 @@ require 'open3' require 'tempfile' -class BinTest_MrubyBinDebugger +class BinTest_MRubyBinDebugger @debug1=false @debug2=true @debug3=true @@ -67,9 +67,9 @@ assert('mruby-bin-debugger(mrdb) command line') do cmd = "p a=#{str}" # test case - BinTest_MrubyBinDebugger.test(src, [{:cmd=>cmd[0...1023], :unexp=>'command line too long.'}]) - BinTest_MrubyBinDebugger.test(src, [{:cmd=>cmd[0...1024], :unexp=>'command line too long.'}]) - BinTest_MrubyBinDebugger.test(src, [{:cmd=>cmd[0...1025], :exp=>'command line too long.'}]) + BinTest_MRubyBinDebugger.test(src, [{:cmd=>cmd[0...1023], :unexp=>'command line too long.'}]) + BinTest_MRubyBinDebugger.test(src, [{:cmd=>cmd[0...1024], :unexp=>'command line too long.'}]) + BinTest_MRubyBinDebugger.test(src, [{:cmd=>cmd[0...1025], :exp=>'command line too long.'}]) end assert('mruby-bin-debugger(mrdb) command: "break"') do @@ -82,10 +82,10 @@ assert('mruby-bin-debugger(mrdb) command: "break"') do tc << {:cmd=>"br", :unexp=>INVCMD} tc << {:cmd=>"brea", :unexp=>INVCMD} tc << {:cmd=>"break", :unexp=>INVCMD} - BinTest_MrubyBinDebugger.test(src, tc) + BinTest_MRubyBinDebugger.test(src, tc) - BinTest_MrubyBinDebugger.test(src, [{:cmd=>"bl", :exp=>INVCMD}]) - BinTest_MrubyBinDebugger.test(src, [{:cmd=>"breaka", :exp=>INVCMD}]) + BinTest_MRubyBinDebugger.test(src, [{:cmd=>"bl", :exp=>INVCMD}]) + BinTest_MRubyBinDebugger.test(src, [{:cmd=>"breaka", :exp=>INVCMD}]) end assert('mruby-bin-debugger(mrdb) command: "continue"') do @@ -93,13 +93,13 @@ assert('mruby-bin-debugger(mrdb) command: "continue"') do src = "foo = 'foo'\n" # test case - BinTest_MrubyBinDebugger.test(src, [{:cmd=>"c", :unexp=>INVCMD}]) - BinTest_MrubyBinDebugger.test(src, [{:cmd=>"co", :unexp=>INVCMD}]) - BinTest_MrubyBinDebugger.test(src, [{:cmd=>"continu", :unexp=>INVCMD}]) - BinTest_MrubyBinDebugger.test(src, [{:cmd=>"continue", :unexp=>INVCMD}]) + BinTest_MRubyBinDebugger.test(src, [{:cmd=>"c", :unexp=>INVCMD}]) + BinTest_MRubyBinDebugger.test(src, [{:cmd=>"co", :unexp=>INVCMD}]) + BinTest_MRubyBinDebugger.test(src, [{:cmd=>"continu", :unexp=>INVCMD}]) + BinTest_MRubyBinDebugger.test(src, [{:cmd=>"continue", :unexp=>INVCMD}]) - BinTest_MrubyBinDebugger.test(src, [{:cmd=>"cn", :exp=>INVCMD}]) - BinTest_MrubyBinDebugger.test(src, [{:cmd=>"continuee", :exp=>INVCMD}]) + BinTest_MRubyBinDebugger.test(src, [{:cmd=>"cn", :exp=>INVCMD}]) + BinTest_MRubyBinDebugger.test(src, [{:cmd=>"continuee", :exp=>INVCMD}]) end assert('mruby-bin-debugger(mrdb) command: "delete"') do @@ -112,10 +112,10 @@ assert('mruby-bin-debugger(mrdb) command: "delete"') do tc << {:cmd=>"de 1", :unexp=>INVCMD} tc << {:cmd=>"delet 1", :unexp=>INVCMD} tc << {:cmd=>"delete 1", :unexp=>INVCMD} - BinTest_MrubyBinDebugger.test(src, tc) + BinTest_MRubyBinDebugger.test(src, tc) - BinTest_MrubyBinDebugger.test(src, [{:cmd=>"dd 1", :exp=>INVCMD}]) - BinTest_MrubyBinDebugger.test(src, [{:cmd=>"deletee 1", :exp=>INVCMD}]) + BinTest_MRubyBinDebugger.test(src, [{:cmd=>"dd 1", :exp=>INVCMD}]) + BinTest_MRubyBinDebugger.test(src, [{:cmd=>"deletee 1", :exp=>INVCMD}]) end assert('mruby-bin-debugger(mrdb) command: "disable"') do @@ -128,11 +128,11 @@ assert('mruby-bin-debugger(mrdb) command: "disable"') do tc << {:cmd=>"disa", :unexp=>INVCMD} tc << {:cmd=>"disabl", :unexp=>INVCMD} tc << {:cmd=>"disable", :unexp=>INVCMD} - BinTest_MrubyBinDebugger.test(src, tc) + BinTest_MRubyBinDebugger.test(src, tc) - BinTest_MrubyBinDebugger.test(src, [{:cmd=>"di", :exp=>INVCMD}]) - BinTest_MrubyBinDebugger.test(src, [{:cmd=>"disb", :exp=>INVCMD}]) - BinTest_MrubyBinDebugger.test(src, [{:cmd=>"disablee", :exp=>INVCMD}]) + BinTest_MRubyBinDebugger.test(src, [{:cmd=>"di", :exp=>INVCMD}]) + BinTest_MRubyBinDebugger.test(src, [{:cmd=>"disb", :exp=>INVCMD}]) + BinTest_MRubyBinDebugger.test(src, [{:cmd=>"disablee", :exp=>INVCMD}]) end assert('mruby-bin-debugger(mrdb) command: "enable"') do @@ -145,11 +145,11 @@ assert('mruby-bin-debugger(mrdb) command: "enable"') do tc << {:cmd=>"ena", :unexp=>INVCMD} tc << {:cmd=>"enabl", :unexp=>INVCMD} tc << {:cmd=>"enable", :unexp=>INVCMD} - BinTest_MrubyBinDebugger.test(src, tc) + BinTest_MRubyBinDebugger.test(src, tc) - BinTest_MrubyBinDebugger.test(src, [{:cmd=>"e", :exp=>INVCMD}]) - BinTest_MrubyBinDebugger.test(src, [{:cmd=>"enb", :exp=>INVCMD}]) - BinTest_MrubyBinDebugger.test(src, [{:cmd=>"enablee", :exp=>INVCMD}]) + BinTest_MRubyBinDebugger.test(src, [{:cmd=>"e", :exp=>INVCMD}]) + BinTest_MRubyBinDebugger.test(src, [{:cmd=>"enb", :exp=>INVCMD}]) + BinTest_MRubyBinDebugger.test(src, [{:cmd=>"enablee", :exp=>INVCMD}]) end assert('mruby-bin-debugger(mrdb) command: "eval"') do @@ -161,11 +161,11 @@ assert('mruby-bin-debugger(mrdb) command: "eval"') do tc << {:cmd=>"ev", :unexp=>INVCMD} tc << {:cmd=>"eva", :unexp=>INVCMD} tc << {:cmd=>"eval", :unexp=>INVCMD} - BinTest_MrubyBinDebugger.test(src, tc) + BinTest_MRubyBinDebugger.test(src, tc) - BinTest_MrubyBinDebugger.test(src, [{:cmd=>"e", :exp=>INVCMD}]) - BinTest_MrubyBinDebugger.test(src, [{:cmd=>"evl", :exp=>INVCMD}]) - BinTest_MrubyBinDebugger.test(src, [{:cmd=>"evall", :exp=>INVCMD}]) + BinTest_MRubyBinDebugger.test(src, [{:cmd=>"e", :exp=>INVCMD}]) + BinTest_MRubyBinDebugger.test(src, [{:cmd=>"evl", :exp=>INVCMD}]) + BinTest_MRubyBinDebugger.test(src, [{:cmd=>"evall", :exp=>INVCMD}]) end assert('mruby-bin-debugger(mrdb) command: "help"') do @@ -178,10 +178,10 @@ assert('mruby-bin-debugger(mrdb) command: "help"') do tc << {:cmd=>"he", :unexp=>INVCMD} tc << {:cmd=>"hel", :unexp=>INVCMD} tc << {:cmd=>"help", :unexp=>INVCMD} - BinTest_MrubyBinDebugger.test(src, tc) + BinTest_MRubyBinDebugger.test(src, tc) - BinTest_MrubyBinDebugger.test(src, [{:cmd=>"hl", :exp=>INVCMD}]) - BinTest_MrubyBinDebugger.test(src, [{:cmd=>"helpp", :exp=>INVCMD}]) + BinTest_MRubyBinDebugger.test(src, [{:cmd=>"hl", :exp=>INVCMD}]) + BinTest_MRubyBinDebugger.test(src, [{:cmd=>"helpp", :exp=>INVCMD}]) end assert('mruby-bin-debugger(mrdb) command: "info breakpoints"') do @@ -195,12 +195,12 @@ assert('mruby-bin-debugger(mrdb) command: "info breakpoints"') do tc << {:cmd=>"i br", :unexp=>INVCMD} tc << {:cmd=>"inf breakpoint", :unexp=>INVCMD} tc << {:cmd=>"info breakpoints", :unexp=>INVCMD} - BinTest_MrubyBinDebugger.test(src, tc) + BinTest_MRubyBinDebugger.test(src, tc) - BinTest_MrubyBinDebugger.test(src, [{:cmd=>"ii b", :exp=>INVCMD}]) - BinTest_MrubyBinDebugger.test(src, [{:cmd=>"i bb", :exp=>INVCMD}]) - BinTest_MrubyBinDebugger.test(src, [{:cmd=>"infoo breakpoints", :exp=>INVCMD}]) - BinTest_MrubyBinDebugger.test(src, [{:cmd=>"info breakpointss", :exp=>INVCMD}]) + BinTest_MRubyBinDebugger.test(src, [{:cmd=>"ii b", :exp=>INVCMD}]) + BinTest_MRubyBinDebugger.test(src, [{:cmd=>"i bb", :exp=>INVCMD}]) + BinTest_MRubyBinDebugger.test(src, [{:cmd=>"infoo breakpoints", :exp=>INVCMD}]) + BinTest_MRubyBinDebugger.test(src, [{:cmd=>"info breakpointss", :exp=>INVCMD}]) end assert('mruby-bin-debugger(mrdb) command: "list"') do @@ -213,10 +213,10 @@ assert('mruby-bin-debugger(mrdb) command: "list"') do tc << {:cmd=>"li", :unexp=>INVCMD} tc << {:cmd=>"lis", :unexp=>INVCMD} tc << {:cmd=>"list", :unexp=>INVCMD} - BinTest_MrubyBinDebugger.test(src, tc) + BinTest_MRubyBinDebugger.test(src, tc) - BinTest_MrubyBinDebugger.test(src, [{:cmd=>"ll", :exp=>INVCMD}]) - BinTest_MrubyBinDebugger.test(src, [{:cmd=>"listt", :exp=>INVCMD}]) + BinTest_MRubyBinDebugger.test(src, [{:cmd=>"ll", :exp=>INVCMD}]) + BinTest_MRubyBinDebugger.test(src, [{:cmd=>"listt", :exp=>INVCMD}]) end assert('mruby-bin-debugger(mrdb) command: "print"') do @@ -229,10 +229,10 @@ assert('mruby-bin-debugger(mrdb) command: "print"') do tc << {:cmd=>"pr", :unexp=>INVCMD} tc << {:cmd=>"prin", :unexp=>INVCMD} tc << {:cmd=>"print", :unexp=>INVCMD} - BinTest_MrubyBinDebugger.test(src, tc) + BinTest_MRubyBinDebugger.test(src, tc) - BinTest_MrubyBinDebugger.test(src, [{:cmd=>"pp", :exp=>INVCMD}]) - BinTest_MrubyBinDebugger.test(src, [{:cmd=>"printt", :exp=>INVCMD}]) + BinTest_MRubyBinDebugger.test(src, [{:cmd=>"pp", :exp=>INVCMD}]) + BinTest_MRubyBinDebugger.test(src, [{:cmd=>"printt", :exp=>INVCMD}]) end assert('mruby-bin-debugger(mrdb) command: "quit"') do @@ -240,13 +240,13 @@ assert('mruby-bin-debugger(mrdb) command: "quit"') do src = "foo = 'foo'\n" # test case - BinTest_MrubyBinDebugger.test(src, [{:cmd=>"q", :unexp=>INVCMD}]) - BinTest_MrubyBinDebugger.test(src, [{:cmd=>"qu", :unexp=>INVCMD}]) - BinTest_MrubyBinDebugger.test(src, [{:cmd=>"qui", :unexp=>INVCMD}]) - BinTest_MrubyBinDebugger.test(src, [{:cmd=>"quit", :unexp=>INVCMD}]) + BinTest_MRubyBinDebugger.test(src, [{:cmd=>"q", :unexp=>INVCMD}]) + BinTest_MRubyBinDebugger.test(src, [{:cmd=>"qu", :unexp=>INVCMD}]) + BinTest_MRubyBinDebugger.test(src, [{:cmd=>"qui", :unexp=>INVCMD}]) + BinTest_MRubyBinDebugger.test(src, [{:cmd=>"quit", :unexp=>INVCMD}]) - BinTest_MrubyBinDebugger.test(src, [{:cmd=>"qq", :exp=>INVCMD}]) - BinTest_MrubyBinDebugger.test(src, [{:cmd=>"quitt", :exp=>INVCMD}]) + BinTest_MRubyBinDebugger.test(src, [{:cmd=>"qq", :exp=>INVCMD}]) + BinTest_MRubyBinDebugger.test(src, [{:cmd=>"quitt", :exp=>INVCMD}]) end assert('mruby-bin-debugger(mrdb) command: "run"') do @@ -254,12 +254,12 @@ assert('mruby-bin-debugger(mrdb) command: "run"') do src = "foo = 'foo'\n" # test case - BinTest_MrubyBinDebugger.test(src, [{:cmd=>"r", :unexp=>INVCMD}]) - BinTest_MrubyBinDebugger.test(src, [{:cmd=>"ru", :unexp=>INVCMD}]) - BinTest_MrubyBinDebugger.test(src, [{:cmd=>"run", :unexp=>INVCMD}]) + BinTest_MRubyBinDebugger.test(src, [{:cmd=>"r", :unexp=>INVCMD}]) + BinTest_MRubyBinDebugger.test(src, [{:cmd=>"ru", :unexp=>INVCMD}]) + BinTest_MRubyBinDebugger.test(src, [{:cmd=>"run", :unexp=>INVCMD}]) - BinTest_MrubyBinDebugger.test(src, [{:cmd=>"rr", :exp=>INVCMD}]) - BinTest_MrubyBinDebugger.test(src, [{:cmd=>"runn", :exp=>INVCMD}]) + BinTest_MRubyBinDebugger.test(src, [{:cmd=>"rr", :exp=>INVCMD}]) + BinTest_MRubyBinDebugger.test(src, [{:cmd=>"runn", :exp=>INVCMD}]) end assert('mruby-bin-debugger(mrdb) command: "step"') do @@ -276,8 +276,8 @@ SRC tc << {:cmd=>"st", :unexp=>INVCMD} tc << {:cmd=>"ste", :unexp=>INVCMD} tc << {:cmd=>"step", :unexp=>INVCMD} - BinTest_MrubyBinDebugger.test(src, tc) + BinTest_MRubyBinDebugger.test(src, tc) - BinTest_MrubyBinDebugger.test(src, [{:cmd=>"ss", :exp=>INVCMD}]) - BinTest_MrubyBinDebugger.test(src, [{:cmd=>"stepp", :exp=>INVCMD}]) + BinTest_MRubyBinDebugger.test(src, [{:cmd=>"ss", :exp=>INVCMD}]) + BinTest_MRubyBinDebugger.test(src, [{:cmd=>"stepp", :exp=>INVCMD}]) end diff --git a/mrbgems/mruby-bin-debugger/bintest/print.rb b/mrbgems/mruby-bin-debugger/bintest/print.rb index 27a20e2..fc23c93 100644 --- a/mrbgems/mruby-bin-debugger/bintest/print.rb +++ b/mrbgems/mruby-bin-debugger/bintest/print.rb @@ -2,7 +2,7 @@ require 'open3' require 'tempfile' require 'strscan' -class BinTest_MrubyBinDebugger +class BinTest_MRubyBinDebugger # @debug1=false # @debug2=true def self.test(rubysource, testcase) @@ -64,7 +64,7 @@ assert('mruby-bin-debugger(print) invalid arguments') do tc = [] tc << {:cmd=>"p", :exp=>"Parameter not specified."} - BinTest_MrubyBinDebugger.test(src, tc) + BinTest_MRubyBinDebugger.test(src, tc) end assert('mruby-bin-debugger(print) normal') do @@ -84,7 +84,7 @@ SRC tc << {:cmd=>"s"} tc << {:cmd=>"p bar", :exp=>'$4 = "foofoo"'} - BinTest_MrubyBinDebugger.test(src, tc) + BinTest_MRubyBinDebugger.test(src, tc) end assert('mruby-bin-debugger(print) error') do @@ -96,7 +96,7 @@ assert('mruby-bin-debugger(print) error') do tc << {:cmd=>"p (1+2", :exp=>'$1 = line 1: syntax error'} tc << {:cmd=>"p bar", :exp=>'$2 = undefined method'} - BinTest_MrubyBinDebugger.test(src, tc) + BinTest_MRubyBinDebugger.test(src, tc) end # Kernel#instance_eval(string) doesn't work multiple statements. @@ -116,7 +116,7 @@ SRC tc << {:cmd=>"s",} tc << {:cmd=>"p x", :exp=>"3"} - BinTest_MrubyBinDebugger.test(src, tc) + BinTest_MRubyBinDebugger.test(src, tc) end =end @@ -128,7 +128,7 @@ assert('mruby-bin-debugger(print) scope:top') do tc = [] tc << {:cmd=>"p self", :exp=>'$1 = main'} - BinTest_MrubyBinDebugger.test(src, tc) + BinTest_MRubyBinDebugger.test(src, tc) end assert('mruby-bin-debugger(print) scope:class') do @@ -144,7 +144,7 @@ SRC tc << {:cmd=>"s"} tc << {:cmd=>"p self", :exp=>'$1 = TestClassScope'} - BinTest_MrubyBinDebugger.test(src, tc) + BinTest_MRubyBinDebugger.test(src, tc) end assert('mruby-bin-debugger(print) scope:module') do @@ -160,7 +160,7 @@ SRC tc << {:cmd=>"s"} tc << {:cmd=>"p self", :exp=>'$1 = TestModuleScope'} - BinTest_MrubyBinDebugger.test(src, tc) + BinTest_MRubyBinDebugger.test(src, tc) end assert('mruby-bin-debugger(print) scope:instance method') do @@ -179,7 +179,7 @@ SRC tc << {:cmd=>"r"} tc << {:cmd=>"p self", :exp=>'$1 = #<TestMethodScope:'} - BinTest_MrubyBinDebugger.test(src, tc) + BinTest_MRubyBinDebugger.test(src, tc) end assert('mruby-bin-debugger(print) scope:class method') do @@ -198,7 +198,7 @@ SRC tc << {:cmd=>"r"} tc << {:cmd=>"p self", :exp=>'$1 = TestClassMethodScope'} - BinTest_MrubyBinDebugger.test(src, tc) + BinTest_MRubyBinDebugger.test(src, tc) end assert('mruby-bin-debugger(print) scope:block') do @@ -231,7 +231,7 @@ SRC tc << {:cmd=>"c"} tc << {:cmd=>"p self", :exp=>'$3 = #<TestBlockScope:'} - BinTest_MrubyBinDebugger.test(src, tc) + BinTest_MRubyBinDebugger.test(src, tc) end assert('mruby-bin-debugger(print) same name:local variable') do @@ -261,7 +261,7 @@ SRC tc << {:cmd=>"c"} tc << {:cmd=>"p lv", :exp=>'$3 = "top"'} - BinTest_MrubyBinDebugger.test(src, tc) + BinTest_MRubyBinDebugger.test(src, tc) end assert('mruby-bin-debugger(print) same name:instance variable') do @@ -293,7 +293,7 @@ SRC tc << {:cmd=>"c"} tc << {:cmd=>"p @iv", :exp=>'$3 = "top"'} - BinTest_MrubyBinDebugger.test(src, tc) + BinTest_MRubyBinDebugger.test(src, tc) end # Kernel#instance_eval(string) doesn't work const. @@ -329,7 +329,7 @@ SRC 1.times { tc << {:cmd=>"s"} } tc << {:cmd=>"p CONST", :exp=>"top"} - BinTest_MrubyBinDebugger.test(src, tc) + BinTest_MRubyBinDebugger.test(src, tc) end =end @@ -353,7 +353,7 @@ assert('mruby-bin-debugger(print) Literal:Numeric') do tc << {:cmd=>"p 1e4", :exp=>'$11 = 10000'} tc << {:cmd=>"p -0.1e-2", :exp=>'$12 = -0.001'} - BinTest_MrubyBinDebugger.test(src, tc) + BinTest_MRubyBinDebugger.test(src, tc) end assert('mruby-bin-debugger(print) Literal:String') do @@ -394,7 +394,7 @@ SRC tc << {:cmd=>'p %q!\\C-a\\C-z!', :exp=>'$19 = "\\\\C-a\\\\C-z"'} tc << {:cmd=>'p %q!#{foo+bar}!', :exp=>'$20 = "\\#{foo+bar}"'} - BinTest_MrubyBinDebugger.test(src, tc) + BinTest_MRubyBinDebugger.test(src, tc) end assert('mruby-bin-debugger(print) Literal:Array') do @@ -416,7 +416,7 @@ SRC tc << {:cmd=>'p %w[3.14 A\ &\ B #{foo}]', :exp=>'$4 = ["3.14", "A & B", "\#{foo}"]'} tc << {:cmd=>'p %W[3.14 A\ &\ B #{foo}]', :exp=>'$5 = ["3.14", "A & B", "foo"]'} - BinTest_MrubyBinDebugger.test(src, tc) + BinTest_MRubyBinDebugger.test(src, tc) end assert('mruby-bin-debugger(print) Literal:Hash') do @@ -439,7 +439,7 @@ SRC tc << {:cmd=>'p {"one"=>1, zwei: 2, tres: 3}', :exp=>'$5 = {"one" => 1, zwei: 2, tres: 3}'} tc << {:cmd=>'p {foo: "#{foo}",bar: "#{bar}"}', :exp=>'$6 = {foo: "foo", bar: "bar"}'} - BinTest_MrubyBinDebugger.test(src, tc) + BinTest_MRubyBinDebugger.test(src, tc) end assert('mruby-bin-debugger(print) Literal:Range') do @@ -456,7 +456,7 @@ assert('mruby-bin-debugger(print) Literal:Range') do tc << {:cmd=>'p "1" .. "9"', :exp=>'$5 = "1".."9"'} tc << {:cmd=>'p "A" ... "Z"', :exp=>'$6 = "A"..."Z"'} - BinTest_MrubyBinDebugger.test(src, tc) + BinTest_MRubyBinDebugger.test(src, tc) end assert('mruby-bin-debugger(print) Literal:Symbol') do @@ -479,7 +479,7 @@ SRC tc << {:cmd=>'p :"#{foo} baz"', :exp=>'$5 = :"foo baz"'} tc << {:cmd=>'p %s!symsym!', :exp=>'$6 = :symsym'} - BinTest_MrubyBinDebugger.test(src, tc) + BinTest_MRubyBinDebugger.test(src, tc) end assert('mruby-bin-debugger(print) Unary operation') do @@ -495,7 +495,7 @@ assert('mruby-bin-debugger(print) Unary operation') do tc << {:cmd=>'p !nil', :exp=>'$5 = true'} tc << {:cmd=>'p !1', :exp=>'$6 = false'} - BinTest_MrubyBinDebugger.test(src, tc) + BinTest_MRubyBinDebugger.test(src, tc) end assert('mruby-bin-debugger(print) Binary operation') do @@ -545,7 +545,7 @@ SRC tc << {:cmd=>'p false or true', :exp=>'$24 = true'} tc << {:cmd=>'p false and true', :exp=>'$25 = false'} - BinTest_MrubyBinDebugger.test(src, tc) + BinTest_MRubyBinDebugger.test(src, tc) end assert('mruby-bin-debugger(print) Ternary operation') do @@ -569,7 +569,7 @@ SRC tc << {:cmd=>'p false ? "true" : "false"', :exp=>'$4 = "false"'} tc << {:cmd=>'p nil ? "true" : "false"', :exp=>'$5 = "false"'} - BinTest_MrubyBinDebugger.test(src, tc) + BinTest_MRubyBinDebugger.test(src, tc) end assert('mruby-bin-debugger(print) Substitution:simple') do @@ -593,7 +593,7 @@ SRC tc << {:cmd=>'p undefined=-1', :exp=>'$3 = -1'} tc << {:cmd=>'p "#{undefined}"', :exp=>'$4 = undefined method'} - BinTest_MrubyBinDebugger.test(src, tc) + BinTest_MRubyBinDebugger.test(src, tc) end assert('mruby-bin-debugger(print) Substitution:self') do @@ -631,7 +631,7 @@ SRC tc << {:cmd=>'p undefined=-1', :exp=>'$14 = -1'} tc << {:cmd=>'p "#{undefined}"', :exp=>'$15 = undefined method'} - BinTest_MrubyBinDebugger.test(src, tc) + BinTest_MRubyBinDebugger.test(src, tc) end assert('mruby-bin-debugger(print) Substitution:multiple') do @@ -661,7 +661,7 @@ SRC # tc << {:cmd=>'p a,*b=[123, 456, 789]'} # tc << {:cmd=>'p [a,b]', :exp=>'[123, [456, 789]]'} - BinTest_MrubyBinDebugger.test(src, tc) + BinTest_MRubyBinDebugger.test(src, tc) end assert('mruby-bin-debugger(print) Substitution:self') do @@ -699,5 +699,5 @@ SRC tc << {:cmd=>'p undefined=-1', :exp=>'$14 = -1'} tc << {:cmd=>'p "#{undefined}"', :exp=>'$15 = undefined method'} - BinTest_MrubyBinDebugger.test(src, tc) + BinTest_MRubyBinDebugger.test(src, tc) end diff --git a/mrbgems/mruby-bin-debugger/mrbgem.rake b/mrbgems/mruby-bin-debugger/mrbgem.rake index f51c9a3..3372950 100644 --- a/mrbgems/mruby-bin-debugger/mrbgem.rake +++ b/mrbgems/mruby-bin-debugger/mrbgem.rake @@ -4,6 +4,7 @@ MRuby::Gem::Specification.new('mruby-bin-debugger') do |spec| spec.summary = 'mruby debugger command' spec.build.defines << "MRB_USE_DEBUG_HOOK" spec.add_dependency('mruby-eval', :core => 'mruby-eval') + spec.add_test_dependency('mruby-bin-mrbc', :core => 'mruby-bin-mrbc') spec.bins = %w(mrdb) end diff --git a/mrbgems/mruby-bin-debugger/tools/mrdb/apibreak.c b/mrbgems/mruby-bin-debugger/tools/mrdb/apibreak.c index e3e0e66..942b9c4 100644 --- a/mrbgems/mruby-bin-debugger/tools/mrdb/apibreak.c +++ b/mrbgems/mruby-bin-debugger/tools/mrdb/apibreak.c @@ -65,21 +65,32 @@ static int32_t get_break_index(mrb_debug_context *dbg, uint32_t bpno) { uint32_t i; - int32_t index; - char hit = FALSE; for (i = 0; i < dbg->bpnum; i++) { - if (dbg->bp[i].bpno == bpno) { - hit = TRUE; - index = i; - break; - } + if (dbg->bp[i].bpno == bpno) return i; } + return MRB_DEBUG_BREAK_INVALID_NO; +} - if (hit == FALSE) { - return MRB_DEBUG_BREAK_INVALID_NO; +static int32_t +alloc_breakpoint(mrb_debug_context *dbg, mrb_debug_bptype type) +{ + int32_t index; + + if (dbg->bpnum >= MAX_BREAKPOINT) { + return MRB_DEBUG_BREAK_NUM_OVER; + } + if (dbg->next_bpno > MAX_BREAKPOINTNO) { + return MRB_DEBUG_BREAK_NO_OVER; } + index = dbg->bpnum; + dbg->bp[index].bpno = dbg->next_bpno; + dbg->next_bpno++; + dbg->bp[index].enable = TRUE; + dbg->bp[index].type = type; + dbg->bpnum++; + return index; } @@ -189,21 +200,12 @@ int32_t mrb_debug_set_break_line(mrb_state *mrb, mrb_debug_context *dbg, const char *file, uint16_t lineno) { int32_t index; - char* set_file; uint16_t result; if ((mrb == NULL)||(dbg == NULL)||(file == NULL)) { return MRB_DEBUG_INVALID_ARGUMENT; } - if (dbg->bpnum >= MAX_BREAKPOINT) { - return MRB_DEBUG_BREAK_NUM_OVER; - } - - if (dbg->next_bpno > MAX_BREAKPOINTNO) { - return MRB_DEBUG_BREAK_NO_OVER; - } - /* file and lineno check. */ result = check_file_lineno(mrb, dbg->root_irep, file, lineno); if (result == 0) { @@ -213,17 +215,11 @@ mrb_debug_set_break_line(mrb_state *mrb, mrb_debug_context *dbg, const char *fil return MRB_DEBUG_BREAK_INVALID_LINENO; } - set_file = mrdb_strdup(mrb, file); + index = alloc_breakpoint(dbg, MRB_DEBUG_BPTYPE_LINE); + if (index < 0) return index; - index = dbg->bpnum; - dbg->bp[index].bpno = dbg->next_bpno; - dbg->next_bpno++; - dbg->bp[index].enable = TRUE; - dbg->bp[index].type = MRB_DEBUG_BPTYPE_LINE; + dbg->bp[index].point.linepoint.file = mrdb_strdup(mrb, file); dbg->bp[index].point.linepoint.lineno = lineno; - dbg->bpnum++; - - dbg->bp[index].point.linepoint.file = set_file; return dbg->bp[index].bpno; } @@ -239,34 +235,21 @@ mrb_debug_set_break_method(mrb_state *mrb, mrb_debug_context *dbg, const char *c return MRB_DEBUG_INVALID_ARGUMENT; } - if (dbg->bpnum >= MAX_BREAKPOINT) { - return MRB_DEBUG_BREAK_NUM_OVER; - } - - if (dbg->next_bpno > MAX_BREAKPOINTNO) { - return MRB_DEBUG_BREAK_NO_OVER; - } - - if (class_name != NULL) { - set_class = mrdb_strdup(mrb, class_name); - } - else { - set_class = NULL; - } - + set_class = class_name != NULL ? mrdb_strdup(mrb, class_name) : NULL; set_method = mrdb_strdup(mrb, method_name); if (set_method == NULL) { mrb_free(mrb, set_class); } - index = dbg->bpnum; - dbg->bp[index].bpno = dbg->next_bpno; - dbg->next_bpno++; - dbg->bp[index].enable = TRUE; - dbg->bp[index].type = MRB_DEBUG_BPTYPE_METHOD; + index = alloc_breakpoint(dbg, MRB_DEBUG_BPTYPE_METHOD); + if (index < 0) { + mrb_free(mrb, set_method); + mrb_free(mrb, set_class); + return index; + } + dbg->bp[index].point.methodpoint.method_name = set_method; dbg->bp[index].point.methodpoint.class_name = set_class; - dbg->bpnum++; return dbg->bp[index].bpno; } diff --git a/mrbgems/mruby-bin-debugger/tools/mrdb/apiprint.c b/mrbgems/mruby-bin-debugger/tools/mrdb/apiprint.c index 49c93e2..6376daa 100644 --- a/mrbgems/mruby-bin-debugger/tools/mrdb/apiprint.c +++ b/mrbgems/mruby-bin-debugger/tools/mrdb/apiprint.c @@ -11,7 +11,7 @@ #include <mruby/error.h> #include <mruby/numeric.h> #include <mruby/string.h> -#include <mruby/presym.h> +#include <mruby/internal.h> #include "apiprint.h" static void @@ -70,12 +70,15 @@ mrb_debug_eval(mrb_state *mrb, mrb_debug_context *dbg, const char *expr, size_t v = mrb_funcall_argv(mrb, recv, MRB_SYM(instance_eval), 1, &ruby_code); } - - if (exc) { - *exc = mrb_obj_is_kind_of(mrb, v, E_EXCEPTION); + mrb_bool is_exc = mrb_obj_is_kind_of(mrb, v, E_EXCEPTION); + if (is_exc) { + s = mrb_exc_get_output(mrb, mrb_obj_ptr(v)); + } + else { + s = mrb_inspect(mrb, v); } - s = mrb_inspect(mrb, v); + if (exc) *exc = is_exc; /* enable code_fetch_hook */ mrb->code_fetch_hook = tmp; diff --git a/mrbgems/mruby-bin-debugger/tools/mrdb/cmdbreak.c b/mrbgems/mruby-bin-debugger/tools/mrdb/cmdbreak.c index 151c403..7dff7e2 100644 --- a/mrbgems/mruby-bin-debugger/tools/mrdb/cmdbreak.c +++ b/mrbgems/mruby-bin-debugger/tools/mrdb/cmdbreak.c @@ -397,40 +397,30 @@ dbgcmd_info_break(mrb_state *mrb, mrdb_state *mrdb) return DBGST_PROMPT; } -dbgcmd_state -dbgcmd_delete(mrb_state *mrb, mrdb_state *mrdb) +static dbgcmd_state +dbgcmd_set_breakpoint(mrb_state *mrb, mrdb_state *mrdb, + all_command_func all_func, select_command_func select_func) { - mrb_bool ret = FALSE; - - ret = exe_set_command_all(mrb, mrdb, mrb_debug_delete_break_all); - if (ret != TRUE) { - exe_set_command_select(mrb, mrdb, mrb_debug_delete_break); + if (!exe_set_command_all(mrb, mrdb, all_func)) { + exe_set_command_select(mrb, mrdb, select_func); } - return DBGST_PROMPT; } dbgcmd_state -dbgcmd_enable(mrb_state *mrb, mrdb_state *mrdb) +dbgcmd_delete(mrb_state *mrb, mrdb_state *mrdb) { - mrb_bool ret = FALSE; - - ret = exe_set_command_all(mrb, mrdb, mrb_debug_enable_break_all); - if (ret != TRUE) { - exe_set_command_select(mrb, mrdb, mrb_debug_enable_break); - } + return dbgcmd_set_breakpoint(mrb, mrdb, mrb_debug_delete_break_all, mrb_debug_delete_break); +} - return DBGST_PROMPT; +dbgcmd_state +dbgcmd_enable(mrb_state *mrb, mrdb_state *mrdb) +{ + return dbgcmd_set_breakpoint(mrb, mrdb, mrb_debug_enable_break_all, mrb_debug_enable_break); } dbgcmd_state dbgcmd_disable(mrb_state *mrb, mrdb_state *mrdb) { - mrb_bool ret = FALSE; - - ret = exe_set_command_all(mrb, mrdb, mrb_debug_disable_break_all); - if (ret != TRUE) { - exe_set_command_select(mrb, mrdb, mrb_debug_disable_break); - } - return DBGST_PROMPT; + return dbgcmd_set_breakpoint(mrb, mrdb, mrb_debug_disable_break_all, mrb_debug_disable_break); } diff --git a/mrbgems/mruby-bin-debugger/tools/mrdb/cmdmisc.c b/mrbgems/mruby-bin-debugger/tools/mrdb/cmdmisc.c index 4cf635b..6beed46 100644 --- a/mrbgems/mruby-bin-debugger/tools/mrdb/cmdmisc.c +++ b/mrbgems/mruby-bin-debugger/tools/mrdb/cmdmisc.c @@ -270,35 +270,37 @@ replace_ext(mrb_state *mrb, const char *filename, const char *ext) return s; } +/* parse: <lineno> | <filename>:<lineno> | <filename> */ +static void +parse_file_line_spec(mrb_state *mrb, char *arg, listcmd_parser_state *st) +{ + char *p = arg; + + if (parse_lineno(mrb, &p, st)) { + /* matched <lineno> or <lineno>,<lineno> */ + } + else if (parse_filename(mrb, &p, st)) { + if (skip_char(&p, ':') && !parse_lineno(mrb, &p, st)) { + st->parse_error = TRUE; + } + } + else { + st->parse_error = TRUE; + } + if (*p != '\0') { + st->parse_error = TRUE; + } +} + static mrb_bool parse_listcmd_args(mrb_state *mrb, mrdb_state *mrdb, listcmd_parser_state *st) { - char *p; - switch (mrdb->wcnt) { case 2: - p = mrdb->words[1]; - - /* mrdb->words[1] ::= <lineno> | <filename> ':' <lineno> | <filename> */ - if (!parse_lineno(mrb, &p, st)) { - if (parse_filename(mrb, &p, st)) { - if (skip_char(&p, ':')) { - if (!parse_lineno(mrb, &p, st)) { - st->parse_error = TRUE; - } - } - } - else { - st->parse_error = TRUE; - } - } - if (*p != '\0') { - st->parse_error = TRUE; - } + parse_file_line_spec(mrb, mrdb->words[1], st); break; case 1: case 0: - /* do nothing */ break; default: st->parse_error = TRUE; @@ -501,9 +503,7 @@ dbgcmd_quit(mrb_state *mrb, mrdb_state *mrdb) } if (mrdb->dbg->xm == DBG_QUIT) { - struct RClass *exc; - exc = mrb_define_class(mrb, "DebuggerExit", E_EXCEPTION); - mrb_raise(mrb, exc, "Exit mrdb"); + raise_debugger_exception(mrb, "DebuggerExit", "Exit mrdb"); } return DBGST_PROMPT; } diff --git a/mrbgems/mruby-bin-debugger/tools/mrdb/cmdprint.c b/mrbgems/mruby-bin-debugger/tools/mrdb/cmdprint.c index f78c1e1..1e09f6d 100644 --- a/mrbgems/mruby-bin-debugger/tools/mrdb/cmdprint.c +++ b/mrbgems/mruby-bin-debugger/tools/mrdb/cmdprint.c @@ -13,39 +13,38 @@ #include <mruby/string.h> #include "apiprint.h" +static uint32_t +next_print_no(mrdb_state *mrdb) +{ + uint32_t no = mrdb->print_no++; + if (mrdb->print_no == 0) mrdb->print_no = 1; + return no; +} + dbgcmd_state dbgcmd_print(mrb_state *mrb, mrdb_state *mrdb) { - mrb_value expr; - mrb_value result; - uint8_t wcnt; - int ai; - if (mrdb->wcnt <= 1) { puts("Parameter not specified."); return DBGST_PROMPT; } - ai = mrb_gc_arena_save(mrb); + int ai = mrb_gc_arena_save(mrb); /* eval expr */ - expr = mrb_str_new_cstr(mrb, NULL); - for (wcnt=1; wcnt<mrdb->wcnt; wcnt++) { + mrb_value expr = mrb_str_new_cstr(mrb, NULL); + for (uint8_t wcnt=1; wcnt<mrdb->wcnt; wcnt++) { expr = mrb_str_cat_lit(mrb, expr, " "); expr = mrb_str_cat_cstr(mrb, expr, mrdb->words[wcnt]); } - result = mrb_debug_eval(mrb, mrdb->dbg, RSTRING_PTR(expr), RSTRING_LEN(expr), NULL, 0); + mrb_value result = mrb_debug_eval(mrb, mrdb->dbg, RSTRING_PTR(expr), RSTRING_LEN(expr), NULL, 0); /* $print_no = result */ - printf("$%lu = ", (unsigned long)mrdb->print_no++); + printf("$%lu = ", (unsigned long)next_print_no(mrdb)); fwrite(RSTRING_PTR(result), RSTRING_LEN(result), 1, stdout); putc('\n', stdout); - if (mrdb->print_no == 0) { - mrdb->print_no = 1; - } - mrb_gc_arena_restore(mrb, ai); return DBGST_PROMPT; @@ -60,20 +59,11 @@ dbgcmd_eval(mrb_state *mrb, mrdb_state *mrdb) dbgcmd_state dbgcmd_info_local(mrb_state *mrb, mrdb_state *mrdb) { - mrb_value result; - mrb_value s; - int ai; - - ai = mrb_gc_arena_save(mrb); - - result = mrb_debug_eval(mrb, mrdb->dbg, "local_variables", 0, NULL, 1); + int ai = mrb_gc_arena_save(mrb); - s = mrb_str_cat_lit(mrb, result, "\0"); - printf("$%lu = %s\n", (unsigned long)mrdb->print_no++, RSTRING_PTR(s)); - - if (mrdb->print_no == 0) { - mrdb->print_no = 1; - } + mrb_value result = mrb_debug_eval(mrb, mrdb->dbg, "local_variables", 0, NULL, 1); + mrb_value s = mrb_str_cat_lit(mrb, result, "\0"); + printf("$%lu = %s\n", (unsigned long)next_print_no(mrdb), RSTRING_PTR(s)); mrb_gc_arena_restore(mrb, ai); diff --git a/mrbgems/mruby-bin-debugger/tools/mrdb/cmdrun.c b/mrbgems/mruby-bin-debugger/tools/mrdb/cmdrun.c index 1cd463e..dd914af 100644 --- a/mrbgems/mruby-bin-debugger/tools/mrdb/cmdrun.c +++ b/mrbgems/mruby-bin-debugger/tools/mrdb/cmdrun.c @@ -17,10 +17,8 @@ dbgcmd_run(mrb_state *mrb, mrdb_state *mrdb) else { dbg->xm = DBG_QUIT; if (dbg->xphase == DBG_PHASE_RUNNING){ - struct RClass *exc; puts("Start it from the beginning"); - exc = mrb_define_class(mrb, "DebuggerRestart", E_EXCEPTION); - mrb_raise(mrb, exc, "Restart mrdb"); + raise_debugger_exception(mrb, "DebuggerRestart", "Restart mrdb"); } } diff --git a/mrbgems/mruby-bin-debugger/tools/mrdb/mrdb.c b/mrbgems/mruby-bin-debugger/tools/mrdb/mrdb.c index 0413c0b..42fa2fa 100644 --- a/mrbgems/mruby-bin-debugger/tools/mrdb/mrdb.c +++ b/mrbgems/mruby-bin-debugger/tools/mrdb/mrdb.c @@ -322,12 +322,48 @@ pick_out_word(mrb_state *mrb, char **pp) return ps; } +/* find first command entry matching word1 (ignoring cmd2) */ +static debug_command* +find_command_by_word1(const char *word1) +{ + debug_command *cmd; + size_t wlen = strlen(word1); + + for (cmd=(debug_command*)debug_command_list; cmd->cmd1; cmd++) { + if (wlen >= cmd->len1 && strncmp(word1, cmd->cmd1, wlen) == 0) { + return cmd; + } + } + return NULL; +} + +/* find command entry matching both word1 and word2 */ +static debug_command* +find_command_by_words(const char *word1, const char *word2) +{ + debug_command *cmd; + size_t wlen; + + for (cmd=(debug_command*)debug_command_list; cmd->cmd1; cmd++) { + wlen = strlen(word1); + if (wlen < cmd->len1 || strncmp(word1, cmd->cmd1, wlen)) { + continue; + } + if (!cmd->cmd2) return cmd; /* word #1 only match */ + if (word2 == NULL) continue; /* word #2 not specified */ + wlen = strlen(word2); + if (wlen >= cmd->len2 && strncmp(word2, cmd->cmd2, wlen) == 0) { + return cmd; /* word #1 and #2 match */ + } + } + return NULL; +} + static debug_command* parse_command(mrb_state *mrb, mrdb_state *mrdb, char *buf) { - debug_command *cmd = NULL; + debug_command *cmd; char *p = buf; - size_t wlen; /* get word #1 */ mrdb->words[0] = pick_out_word(mrb, &p); @@ -342,51 +378,26 @@ parse_command(mrb_state *mrb, mrdb_state *mrdb, char *buf) mrdb->words[mrdb->wcnt++] = p; } - /* check word #1 */ - for (cmd=(debug_command*)debug_command_list; cmd->cmd1; cmd++) { - wlen = strlen(mrdb->words[0]); - if (wlen >= cmd->len1 && - strncmp(mrdb->words[0], cmd->cmd1, wlen) == 0) { - break; - } - } - - if (cmd->cmd2) { - if (mrdb->wcnt > 1) { - /* get word #2 */ - mrdb->words[1] = pick_out_word(mrb, &p); - if (mrdb->words[1]) { - /* update remain parameter */ - for (; *p && ISBLANK(*p); p++) - ; - if (*p) { - mrdb->words[mrdb->wcnt++] = p; - } - } - } - - /* check word #1,#2 */ - for (; cmd->cmd1; cmd++) { - wlen = strlen(mrdb->words[0]); - if (wlen < cmd->len1 || - strncmp(mrdb->words[0], cmd->cmd1, wlen)) { - continue; - } - - if (!cmd->cmd2) break; /* word #1 only */ - - if (mrdb->wcnt == 1) continue; /* word #2 not specified */ + cmd = find_command_by_word1(mrdb->words[0]); + if (!cmd) return NULL; - wlen = strlen(mrdb->words[1]); - if (wlen >= cmd->len2 && - strncmp(mrdb->words[1], cmd->cmd2, wlen) == 0) { - break; /* word #1 and #2 */ + /* if matched command has a sub-command, try word #1 + #2 */ + if (cmd->cmd2 && mrdb->wcnt > 1) { + mrdb->words[1] = pick_out_word(mrb, &p); + if (mrdb->words[1]) { + /* update remain parameter */ + for (; *p && ISBLANK(*p); p++) + ; + if (*p) { + mrdb->words[mrdb->wcnt++] = p; } } + cmd = find_command_by_words(mrdb->words[0], mrdb->words[1]); + if (!cmd) return NULL; } /* divide remain parameters */ - if (cmd->cmd1 && cmd->div) { + if (cmd->div) { p = mrdb->words[--mrdb->wcnt]; for (; mrdb->wcnt<MAX_COMMAND_WORD; mrdb->wcnt++) { mrdb->words[mrdb->wcnt] = pick_out_word(mrb, &p); @@ -396,7 +407,7 @@ parse_command(mrb_state *mrb, mrdb_state *mrdb, char *buf) } } - return cmd->cmd1 ? cmd : NULL; + return cmd; } static void @@ -548,6 +559,22 @@ check_method_breakpoint(mrb_state *mrb, const mrb_irep *irep, const mrb_code *pc return bpno; } +static int32_t +check_breakpoint_hit(mrb_state *mrb, mrb_debug_context *dbg, + const mrb_irep *irep, const mrb_code *pc, + const char *file, int32_t line, mrb_value *regs) +{ + int32_t bpno; + + bpno = check_method_breakpoint(mrb, irep, pc, regs); + if (bpno > 0) return bpno; + if (dbg->prvfile != file || dbg->prvline != line) { + bpno = mrb_debug_check_breakpoint_line(mrb, dbg, file, line); + if (bpno > 0) return bpno; + } + return 0; +} + static void mrb_code_fetch_hook(mrb_state *mrb, const mrb_irep *irep, const mrb_code *pc, mrb_value *regs) { @@ -597,23 +624,16 @@ mrb_code_fetch_hook(mrb_state *mrb, const mrb_irep *irep, const mrb_code *pc, mr break; case DBG_RUN: - bpno = check_method_breakpoint(mrb, irep, pc, regs); + bpno = check_breakpoint_hit(mrb, dbg, irep, pc, file, line, regs); if (bpno > 0) { dbg->stopped_bpno = bpno; dbg->bm = BRK_BREAK; break; } - if (dbg->prvfile != file || dbg->prvline != line) { - bpno = mrb_debug_check_breakpoint_line(mrb, dbg, file, line); - if (bpno > 0) { - dbg->stopped_bpno = bpno; - dbg->bm = BRK_BREAK; - break; - } - } dbg->prvfile = file; dbg->prvline = line; return; + case DBG_INIT: dbg->root_irep = irep; dbg->bm = BRK_INIT; @@ -673,8 +693,9 @@ main(int argc, char **argv) l_restart: - if (mrb == NULL) { - fputs("Invalid mrb_state, exiting mruby\n", stderr); + if (MRB_OPEN_FAILURE(mrb)) { + mrb_print_error(mrb); /* handles NULL */ + mrb_close(mrb); /* handles NULL */ return EXIT_FAILURE; } diff --git a/mrbgems/mruby-bin-debugger/tools/mrdb/mrdb.h b/mrbgems/mruby-bin-debugger/tools/mrdb/mrdb.h index 1d379f4..df7680a 100644 --- a/mrbgems/mruby-bin-debugger/tools/mrdb/mrdb.h +++ b/mrbgems/mruby-bin-debugger/tools/mrdb/mrdb.h @@ -7,6 +7,7 @@ #define MRDB_H #include <mruby.h> +#include <mruby/class.h> #include "mrdbconf.h" @@ -136,6 +137,13 @@ typedef struct mrdb_state { typedef dbgcmd_state (*debug_command_func)(mrb_state*, mrdb_state*); +static inline mrb_noreturn void +raise_debugger_exception(mrb_state *mrb, const char *name, const char *msg) +{ + struct RClass *exc = mrb_define_class(mrb, name, E_EXCEPTION); + mrb_raise(mrb, exc, msg); +} + /* cmdrun.c */ dbgcmd_state dbgcmd_run(mrb_state*, mrdb_state*); dbgcmd_state dbgcmd_continue(mrb_state*, mrdb_state*); |
