debug 1.4.0 → 1.9.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +210 -6
  3. data/Gemfile +2 -0
  4. data/LICENSE.txt +0 -0
  5. data/README.md +161 -85
  6. data/Rakefile +33 -10
  7. data/TODO.md +8 -8
  8. data/debug.gemspec +9 -7
  9. data/exe/rdbg +23 -4
  10. data/ext/debug/debug.c +111 -21
  11. data/ext/debug/extconf.rb +23 -0
  12. data/ext/debug/iseq_collector.c +2 -0
  13. data/lib/debug/abbrev_command.rb +77 -0
  14. data/lib/debug/breakpoint.rb +102 -74
  15. data/lib/debug/client.rb +46 -12
  16. data/lib/debug/color.rb +0 -0
  17. data/lib/debug/config.rb +129 -36
  18. data/lib/debug/console.rb +46 -40
  19. data/lib/debug/dap_custom/traceInspector.rb +336 -0
  20. data/lib/debug/frame_info.rb +40 -25
  21. data/lib/debug/irb_integration.rb +37 -0
  22. data/lib/debug/local.rb +17 -11
  23. data/lib/debug/open.rb +0 -0
  24. data/lib/debug/open_nonstop.rb +0 -0
  25. data/lib/debug/prelude.rb +3 -2
  26. data/lib/debug/server.rb +126 -56
  27. data/lib/debug/server_cdp.rb +673 -248
  28. data/lib/debug/server_dap.rb +497 -261
  29. data/lib/debug/session.rb +899 -441
  30. data/lib/debug/source_repository.rb +122 -49
  31. data/lib/debug/start.rb +1 -1
  32. data/lib/debug/thread_client.rb +460 -155
  33. data/lib/debug/tracer.rb +10 -16
  34. data/lib/debug/version.rb +1 -1
  35. data/lib/debug.rb +7 -2
  36. data/misc/README.md.erb +106 -56
  37. metadata +14 -24
  38. data/.github/ISSUE_TEMPLATE/bug_report.md +0 -24
  39. data/.github/ISSUE_TEMPLATE/custom.md +0 -10
  40. data/.github/ISSUE_TEMPLATE/feature_request.md +0 -14
  41. data/.github/pull_request_template.md +0 -9
  42. data/.github/workflows/ruby.yml +0 -34
  43. data/.gitignore +0 -12
  44. data/bin/console +0 -14
  45. data/bin/gentest +0 -30
  46. data/bin/setup +0 -8
  47. data/lib/debug/bp.vim +0 -68
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a62295065b9bb4f9d498a21b32ea122ab680fd1e1b9794368ac2385858abf844
4
- data.tar.gz: 0dc6f9aeb1ff23a47e0c399ee32ac80953821520cc52b0c4e27e30d7600a67bd
3
+ metadata.gz: c242bce58b031f61da73507f6b42a26f1ed8322679d1f0b3460d8fbc8c4b7a23
4
+ data.tar.gz: 543feb5e53a2c99ba04583edae4a13378667c97b13662f5a4d456dd6bacb17b5
5
5
  SHA512:
6
- metadata.gz: 144d16fc2b8e377d7d25df0b09f088492647b76de2ffc1a841e09967caed2678f28fbaf24747fc351fd7e7d7c0d107cd39245ca0c8eff41547bce4f2ab35a8c3
7
- data.tar.gz: 4e62e36b0fe72a2c1ce8e1dd44e6bae646e06b0d4d8d07072db595f908d00595252e35525a9ba1fde09a53f9a57781165c73e63d8eaa8a59a5e93219bd4c9ed5
6
+ metadata.gz: b5f6c58f38114e3179c3d5c062294ac276b53533fc4a6543114a883198318b672a8506990064f1b40d9f9597d3e1a933cb7c2363ea4cdd4ba0e0571279a80c73
7
+ data.tar.gz: 142a78dcdc449df6e0148857f992500aa88375707af067f36f1e3391fe2adb7ac8ff0f66623806c5488e94292167a369ca901084475e97b8dc38e32257ccbba0
data/CONTRIBUTING.md CHANGED
@@ -14,15 +14,27 @@ If you spot any problem, please open an issue.
14
14
  ### Run all tests
15
15
 
16
16
  ```bash
17
- $ rake test
17
+ $ rake test_all
18
+ ```
19
+
20
+ ### Run all console tests
21
+
22
+ ```bash
23
+ $ rake test_console
24
+ ```
25
+
26
+ ### Run all protocol (DAP & CDP) tests
27
+
28
+ ```bash
29
+ $ rake test_protocol
18
30
  ```
19
31
 
20
32
  ### Run specific test(s)
21
33
 
22
34
 
23
35
  ```bash
24
- $ ruby test/debug/bp_test.rb # run all tests in the specified file
25
- $ ruby test/debug/bp_test.rb -h # to see all the test options
36
+ $ ruby test/console/break_test.rb # run all tests in the specified file
37
+ $ ruby test/console/break_test.rb -h # to see all the test options
26
38
  ```
27
39
 
28
40
  ## Generate Tests
@@ -137,10 +149,10 @@ If the file already exists, **only method** will be added to it.
137
149
  ```ruby
138
150
  # frozen_string_literal: true
139
151
 
140
- require_relative '../support/test_case'
152
+ require_relative '../support/console_test_case'
141
153
 
142
154
  module DEBUGGER__
143
- class FooTest < TestCase
155
+ class FooTest < ConsoleTestCase
144
156
  def program
145
157
  <<~RUBY
146
158
  1| module Foo
@@ -154,7 +166,7 @@ module DEBUGGER__
154
166
  9| end
155
167
  RUBY
156
168
  end
157
-
169
+
158
170
  def test_1629720194
159
171
  debug_code(program) do
160
172
  type 's'
@@ -249,6 +261,198 @@ Passes if `text` is not included in the last debugger log.
249
261
 
250
262
  Passes if `text` is included in the debuggee log.
251
263
 
264
+ ### Tests for DAP and CDP
265
+
266
+ Currently, there are 2 kinds of test frameworks for DAP and CDP.
267
+
268
+ 1. Protocol-based tests
269
+
270
+ If you want to write protocol-based tests, you should use the test generator.
271
+ To run the test generator, you can enter `$ bin/gentest target.rb --open=vscode` in the terminal, VSCode will be executed.
272
+ Also, if you enter `$ bin/gentest target.rb --open=chrome` there, Chrome will be executed.
273
+ If you need to modify existing tests, it is basically a good idea to regenerate them by the test generator instead of rewriting them directly.
274
+ Please refer to [the Microsoft "Debug Adapter Protocol" article](https://microsoft.github.io/debug-adapter-protocol/specification) to learn more about DAP formats.
275
+ Please refer to [the "Chrome DevTools Protocol" official documentation](https://chromedevtools.github.io/devtools-protocol/) to learn more about CDP formats.
276
+
277
+ 2. High-level tests
278
+
279
+ High-level tests are designed to test both DAP and CDP for a single method.
280
+ You can write tests as follows:
281
+ **NOTE:** Use `req_terminate_debuggee` to finish debugging. You can't use any methods such as `req_continue`, `req_next` and so on.
282
+
283
+ ```ruby
284
+ require_relative '../support/test_case'
285
+ module DEBUGGER__
286
+ class BreakTest < TestCase
287
+ # PROGRAM is the target script.
288
+ PROGRAM = <<~RUBY
289
+ 1| module Foo
290
+ 2| class Bar
291
+ 3| def self.a
292
+ 4| "hello"
293
+ 5| end
294
+ 6| end
295
+ 7| Bar.a
296
+ 8| bar = Bar.new
297
+ 9| end
298
+ RUBY
299
+
300
+ def test_break1
301
+ run_protocol_scenario PROGRAM do # Start debugging with DAP and CDP
302
+ req_add_breakpoint 5 # Set a breakpoint on line 5.
303
+ req_add_breakpoint 8 # Set a breakpoint on line 8.
304
+ req_continue # Resume the program.
305
+ assert_line_num 5 # Check if debugger stops at line 5.
306
+ req_continue # Resume the program.
307
+ assert_line_num 8 # Check if debugger stops at line 8.
308
+ req_terminate_debuggee # Terminate debugging.
309
+ end
310
+ end
311
+ end
312
+ end
313
+ ```
314
+
315
+ #### API
316
+
317
+ - run_protocol_scenario program, dap: true, cdp: true, &scenario
318
+
319
+ Execute debugging `program` with `&scenario`. If you want to test it only for DAP, you can write as follows:
320
+
321
+ `run_protocol_scenario program, cdp: false ...`
322
+
323
+ - attach_to_dap_server(terminate_debuggee:)
324
+
325
+ Attach to the running DAP server through UNIX Domain Socket.
326
+
327
+ - attach_to_cdp_server
328
+
329
+ Attach to the running CDP server through TCP/IP.
330
+
331
+ - req_dap_disconnect
332
+
333
+ Disconnect from the currently connected DAP server.
334
+
335
+ - req_cdp_disconnect
336
+
337
+ Disconnect from the currently connected CDP server.
338
+
339
+ - req_add_breakpoint(lineno, path: temp_file_path, cond: nil)
340
+
341
+ Sends request to rdbg to add a breakpoint.
342
+
343
+ - req_delete_breakpoint bpnum
344
+
345
+ Sends request to rdbg to delete a breakpoint.
346
+
347
+ - req_set_exception_breakpoints(breakpoints)
348
+
349
+ Sends request to rdbg to set exception breakpoints. e.g.
350
+
351
+ ```rb
352
+ req_set_exception_breakpoints([{ name: "RuntimeError", condition: "a == 1" }])
353
+ ```
354
+
355
+ Please note that `setExceptionBreakpoints` resets all exception breakpoints in every request.
356
+
357
+ So the following code will only set breakpoint for `Exception`.
358
+
359
+ ```rb
360
+ req_set_exception_breakpoints([{ name: "RuntimeError" }])
361
+ req_set_exception_breakpoints([{ name: "Exception" }])
362
+ ```
363
+
364
+ This means you can also use
365
+
366
+ ```rb
367
+ req_set_exception_breakpoints([])
368
+ ```
369
+
370
+ to clear all exception breakpoints.
371
+
372
+ - req_continue
373
+
374
+ Sends request to rdbg to resume the program.
375
+
376
+ - req_step
377
+
378
+ Sends request to rdbg to step into next method.
379
+
380
+ - req_next
381
+
382
+ Sends request to rdbg to step over next method.
383
+
384
+ - req_finish
385
+
386
+ Sends request to rdbg to step out of current method.
387
+
388
+ - req_step_back
389
+
390
+ Sends request to rdbg to step back from current method.
391
+
392
+ - req_terminate_debuggee
393
+
394
+ Sends request to rdbg to terminate the debuggee.
395
+
396
+ - assert_hover_result(expected, expression)
397
+
398
+ Passes if result of `expression` matches `expected`.
399
+
400
+ `expected` need to be a Hash object as follows:
401
+
402
+ `assert_hover_result({value: '2', type: 'Integer'}, 'a')`
403
+
404
+ NOTE: `value` and `type` need to be strings.
405
+
406
+ - assert_repl_result(expected, expression)
407
+
408
+ Passes if result of `expression` matches `expected`.
409
+
410
+ `expected` need to be a Hash object as follows:
411
+
412
+ `assert_repl_result({value: '2', type: 'Integer'}, 'a')`
413
+
414
+ NOTE: `value` and `type` need to be strings.
415
+
416
+ - assert_watch_result(expected, expression)
417
+
418
+ Passes if result of `expression` matches `expected`.
419
+
420
+ `expected` need to be a Hash object as follows:
421
+
422
+ `assert_watch_result({value: '2', type: 'Integer'}, 'a')`
423
+
424
+ NOTE: `value` and `type` need to be strings.
425
+
426
+ - assert_line_num(expected)
427
+
428
+ Passes if `expected` is equal to the location where debugger stops.
429
+
430
+ - assert_locals_result(expected)
431
+
432
+ Passes if all of `expected` local variable entries match the ones returned by debugger.
433
+
434
+ An variable entry looks like this: `{ name: "bar", value: "nil", type: "NilClass" }`.
435
+
436
+ Please note that both `value` and `type` need to be strings.
437
+
438
+ - assert_threads_result(expected)
439
+
440
+ Passes if both conditions are true:
441
+
442
+ 1. The number of expected patterns matches the number of threads.
443
+ 2. Every pattern matches a thread name. Notice that the order of threads info is not guaranteed.
444
+
445
+ Example:
446
+
447
+ ```
448
+ assert_threads_result(
449
+ [
450
+ /\.rb:\d:in `<main>'/,
451
+ /\.rb:\d:in `block in foo'/
452
+ ]
453
+ )
454
+ ```
455
+
252
456
  ## To Update README
253
457
 
254
458
  This project generates `README.md` from the template `misc/README.md.erb`
data/Gemfile CHANGED
@@ -6,3 +6,5 @@ gem "rake"
6
6
  gem "rake-compiler"
7
7
  gem "test-unit", "~> 3.0"
8
8
  gem "test-unit-rr"
9
+ gem "json-schema"
10
+ gem "test-unit-launchable"
data/LICENSE.txt CHANGED
File without changes