byebug 11.1.3 → 13.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +46 -0
  3. data/CONTRIBUTING.md +9 -9
  4. data/GUIDE.md +38 -38
  5. data/README.md +2 -4
  6. data/ext/byebug/breakpoint.c +51 -46
  7. data/ext/byebug/byebug.c +32 -26
  8. data/ext/byebug/byebug.h +2 -0
  9. data/ext/byebug/context.c +48 -52
  10. data/ext/byebug/threads.c +33 -9
  11. data/lib/byebug/breakpoint.rb +1 -18
  12. data/lib/byebug/commands/break.rb +7 -5
  13. data/lib/byebug/commands/enable/breakpoints.rb +1 -1
  14. data/lib/byebug/commands/finish.rb +1 -1
  15. data/lib/byebug/commands/help.rb +1 -1
  16. data/lib/byebug/commands/info.rb +1 -1
  17. data/lib/byebug/commands/irb.rb +2 -1
  18. data/lib/byebug/commands/set.rb +1 -1
  19. data/lib/byebug/commands/step.rb +1 -1
  20. data/lib/byebug/commands/thread/current.rb +1 -1
  21. data/lib/byebug/commands/thread/list.rb +1 -1
  22. data/lib/byebug/commands/thread/resume.rb +1 -1
  23. data/lib/byebug/commands/thread/stop.rb +1 -1
  24. data/lib/byebug/commands/tracevar.rb +1 -1
  25. data/lib/byebug/commands/untracevar.rb +2 -2
  26. data/lib/byebug/commands/var/args.rb +1 -1
  27. data/lib/byebug/commands/where.rb +14 -3
  28. data/lib/byebug/context.rb +1 -1
  29. data/lib/byebug/helpers/eval.rb +4 -6
  30. data/lib/byebug/helpers/file.rb +5 -1
  31. data/lib/byebug/helpers/parse.rb +9 -2
  32. data/lib/byebug/helpers/reflection.rb +1 -1
  33. data/lib/byebug/helpers/var.rb +17 -1
  34. data/lib/byebug/history.rb +14 -24
  35. data/lib/byebug/interface.rb +1 -1
  36. data/lib/byebug/interfaces/local_interface.rb +8 -8
  37. data/lib/byebug/option_setter.rb +1 -1
  38. data/lib/byebug/settings/savefile.rb +2 -2
  39. data/lib/byebug/version.rb +1 -1
  40. metadata +21 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 756ca67151133e7afeea4be781e49bb948a7b8dc7b2ece045a29e6c549409abc
4
- data.tar.gz: a301313d736ee29e15ec53d4e903359be8e4aa0b1bc1f6155d784937c636a0d6
3
+ metadata.gz: f8c848a8629ef3fc193536f1a7461445f0add1cfc2143ed53f5f93c2589241fb
4
+ data.tar.gz: f33dc257897c04065cf9208293ba4c8a7ae1ec809fcbfb259cbcfa3efe93388f
5
5
  SHA512:
6
- metadata.gz: 03f857ddb22761e243a99660869b5c1bc4863c6c860e2827e2c6a2569009a7bba7ada3a79804ff6fadd5d556f1974feeee215c49696415733425f542fa78b52e
7
- data.tar.gz: 585b54db0201a0ba6e1e23bceed21b7361064c56a1fa08d997e714d088a05e0ba74c1ffd4ed4fbcb763ad7719afb5a39118eacfad7e81c8e14fda850bc4b8265
6
+ metadata.gz: 9a83b9c70d31cd4b7e0647f408df9f33fedd566f00dcddc7b3943c73c10f7005292755de38daebf52348e1a0994d035ecb00b56c05f940b30e82fee7b9ab1051
7
+ data.tar.gz: 41356dc3dd9e2f9c3b08bcc3c56b5531de1c4b07416a71ed1d9599f78b3a5e3ab1ce8549583fbd165da72ee983eddd7ee8b5a8935eabaab4c874aa322e6e4556
data/CHANGELOG.md CHANGED
@@ -2,6 +2,44 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [13.0.0] - 2026-01-15
6
+
7
+ ### Fixed
8
+
9
+ * [#924](https://github.com/deivid-rodriguez/byebug/pull/924): Use typed data APIs to fix Ruby 4.0 deprecation ([@nobu]).
10
+ * [#876](https://github.com/deivid-rodriguez/byebug/pull/876): Add explicit require of `stringio` ([@pabloh]).
11
+ * [#909](https://github.com/deivid-rodriguez/byebug/pull/909): Avoid loading readline at all to play nice with Ruby 4.0.
12
+ * [#905](https://github.com/deivid-rodriguez/byebug/pull/905): Make reline an explicit dependency to fix Ruby 3.4 warnings.
13
+ * [#824](https://github.com/deivid-rodriguez/byebug/pull/824): Improve startup by loading IRB lazily ([@pocke]).
14
+ * [#848](https://github.com/deivid-rodriguez/byebug/pull/848): Grammar fixes in GUIDE.md ([@alexymik]).
15
+ * [#804](https://github.com/deivid-rodriguez/byebug/pull/804): Fix typo in context.rb documentation ([@ono-max]).
16
+
17
+ ### Removed
18
+
19
+ * Support for MRI 3.1. Byebug no longer installs on this platform.
20
+
21
+ ## [12.0.0] - 2025-03-25
22
+
23
+ ### Changed
24
+
25
+ * [#690](https://github.com/deivid-rodriguez/byebug/pull/690): `break` without any arguments now sets a breakpoint on the current line, just like `gdb` ([@sergioro9]).
26
+
27
+ ### Fixed
28
+
29
+ * [#741](https://github.com/deivid-rodriguez/byebug/pull/741): Small consistency issues in help messages.
30
+ * [#743](https://github.com/deivid-rodriguez/byebug/pull/743): `untracevar` command crashing when giving a non existent global variable.
31
+ * [#744](https://github.com/deivid-rodriguez/byebug/pull/744): Another punctuation tweak in `enable breakpoints` help message.
32
+ * [#736](https://github.com/deivid-rodriguez/byebug/pull/736): Skip warning about `$SAFE` global variable on ruby 2.7 when listing global variables.
33
+
34
+ ### Added
35
+
36
+ * [#847](https://github.com/deivid-rodriguez/byebug/pull/847) and [#850](https://github.com/deivid-rodriguez/byebug/pull/850): Support for MRI 3.1, 3.2, and 3.3 ([@marshall-lee]).
37
+ * [#688](https://github.com/deivid-rodriguez/byebug/pull/688): `where` command now receives an optional numeric argument `<n>` to print the nth first frames ([@sergioro9].
38
+
39
+ ### Removed
40
+
41
+ * Support for MRI 2.4, 2.5, 2.6, 2.7, and 3.0. Byebug no longer installs on this platform.
42
+
5
43
  ## [11.1.3] - 2020-04-23
6
44
 
7
45
  ### Fixed
@@ -821,6 +859,8 @@
821
859
  * Initial release.
822
860
 
823
861
  [Unreleased]: https://github.com/deivid-rodriguez/byebug/compare/v11.1.3...HEAD
862
+ [13.0.0]: https://github.com/deivid-rodriguez/byebug/compare/v12.0.0...v13.0.0
863
+ [12.0.0]: https://github.com/deivid-rodriguez/byebug/compare/v11.1.3...v12.0.0
824
864
  [11.1.3]: https://github.com/deivid-rodriguez/byebug/compare/v11.1.2...v11.1.3
825
865
  [11.1.2]: https://github.com/deivid-rodriguez/byebug/compare/v11.1.1...v11.1.2
826
866
  [11.1.1]: https://github.com/deivid-rodriguez/byebug/compare/v11.1.0...v11.1.1
@@ -903,6 +943,7 @@
903
943
  [1.0.0]: https://github.com/deivid-rodriguez/byebug/compare/v0.0.1...v1.0.0
904
944
 
905
945
  [@akaneko3]: https://github.com/akaneko3
946
+ [@alexymik]: https://github.com/alexymik
906
947
  [@andreychernih]: https://github.com/andreychernih
907
948
  [@ark6]: https://github.com/ark6
908
949
  [@astashov]: https://github.com/astashov
@@ -919,10 +960,15 @@
919
960
  [@k0kubun]: https://github.com/k0kubun
920
961
  [@ko1]: https://github.com/ko1
921
962
  [@luislavena]: https://github.com/luislavena
963
+ [@marshall-lee]: https://github.com/marshall-lee
922
964
  [@mrkn]: https://github.com/mrkn
923
965
  [@nobu]: https://github.com/nobu
924
966
  [@Olgagr]: https://github.com/Olgagr
967
+ [@ono-max]: https://github.com/ono-max
968
+ [@pabloh]: https://github.com/pabloh
969
+ [@pocke]: https://github.com/pocke
925
970
  [@sethk]: https://github.com/sethk
971
+ [@sergioro9]: https://github.com/sergioro9
926
972
  [@shuky19]: https://github.com/shuky19
927
973
  [@tacnoman]: https://github.com/tacnoman
928
974
  [@terceiro]: https://github.com/terceiro
data/CONTRIBUTING.md CHANGED
@@ -31,15 +31,15 @@ abide by its terms.
31
31
  * Run the test suite using the default rake task (`bin/rake`). This task is
32
32
  composed of 3 subtasks: `bin/rake compile`, `bin/rake test` & `bin/rake lint`.
33
33
  * If you want to run specific tests, use the provided test runner, like so:
34
- * Specific test files. For example, `bin/minitest test/commands/break_test.rb`
35
- * Specific test classes. For example, `bin/minitest BreakAtLinesTest`
36
- * Specific tests. For example,
37
- `bin/minitest test_catch_removes_specific_catchpoint`
38
- * Specific fully qualified tests. For example,
39
- `bin/minitest BreakAtLinesTest#test_setting_breakpoint_sets_correct_fields`
40
- * You can combine any of them and you will get the union of all filters. For
41
- example: `bin/minitest BreakAtLinesTest
42
- test_catch_removes_specific_catchpoint`
34
+ * Specific test files. For example, `bin/minitest test/commands/break_test.rb`
35
+ * Specific test classes. For example, `bin/minitest BreakAtLinesTest`
36
+ * Specific tests. For example,
37
+ `bin/minitest test_catch_removes_specific_catchpoint`
38
+ * Specific fully qualified tests. For example,
39
+ `bin/minitest BreakAtLinesTest#test_setting_breakpoint_sets_correct_fields`
40
+ * You can combine any of them and you will get the union of all filters. For
41
+ example: `bin/minitest BreakAtLinesTest
42
+ test_catch_removes_specific_catchpoint`
43
43
 
44
44
  ## Code style
45
45
 
data/GUIDE.md CHANGED
@@ -26,7 +26,7 @@ puts t
26
26
 
27
27
  Let's debug it.
28
28
 
29
- ```bash
29
+ ```console
30
30
  $ byebug /path/to/triangle.rb
31
31
 
32
32
  [1, 10] in /path/to/triangle.rb
@@ -62,7 +62,7 @@ accordingly so that only actual real lines of code are displayed.
62
62
 
63
63
  Now let us step through the program.
64
64
 
65
- ```bash
65
+ ```console
66
66
  (byebug) step
67
67
 
68
68
  [5, 14] in /path/to/triangle.rb
@@ -118,7 +118,7 @@ previously. However after issuing another `step` command we see that the value
118
118
  is 0 as expected. If every time we stop we want to see the value of `tri` to see
119
119
  how things are going, there is a better way by setting a display expression:
120
120
 
121
- ```bash
121
+ ```console
122
122
  (byebug) display tri
123
123
  1: tri = 0
124
124
  ```
@@ -127,7 +127,7 @@ Now let us run the program until right before we return from the function. We'll
127
127
  want to see which lines get run, so we turn on _line tracing_. If we don't want
128
128
  whole paths to be displayed when tracing, we can turn on _basename_.
129
129
 
130
- ```bash
130
+ ```console
131
131
  (byebug) set linetrace
132
132
  linetrace is on
133
133
  (byebug) set basename
@@ -207,7 +207,7 @@ Recall in the first section it was stated that before the `def` is run, the
207
207
  method it names is undefined. Let's check that out. First let's see what
208
208
  private methods we can call before running `def hanoi`.
209
209
 
210
- ```bash
210
+ ```console
211
211
  $ byebug path/to/hanoi.rb
212
212
 
213
213
  1: #
@@ -317,7 +317,7 @@ is stopped.
317
317
 
318
318
  Now let's see what happens after stepping:
319
319
 
320
- ```bash
320
+ ```console
321
321
  (byebug) step
322
322
 
323
323
  [5, 14] in /path/to/hanoi.rb
@@ -338,7 +338,7 @@ true
338
338
 
339
339
  Okay, lets go on and talk about program arguments.
340
340
 
341
- ```bash
341
+ ```console
342
342
  (byebug) $ARGV
343
343
  []
344
344
  ```
@@ -346,7 +346,7 @@ Okay, lets go on and talk about program arguments.
346
346
  Oops. We forgot to specify any parameters to this program. Let's try again. We
347
347
  can use the `restart` command here.
348
348
 
349
- ```bash
349
+ ```console
350
350
  (byebug) restart 3
351
351
  Re exec'ing:
352
352
  /path/to/exe/byebug /path/to/hanoi.rb 3
@@ -445,7 +445,7 @@ trace (see [callstyle]()).
445
445
 
446
446
  Now let's move around the callstack.
447
447
 
448
- ```bash
448
+ ```console
449
449
  (byebug) undisplay
450
450
  Clear all expressions? (y/n) y
451
451
  (byebug) n_args
@@ -554,7 +554,7 @@ def test_basic
554
554
 
555
555
  Now we run the program, requiring `byebug`
556
556
 
557
- ```bash
557
+ ```console
558
558
  $ ruby -rbyebug test_triangle.rb
559
559
  Run options: --seed 31679
560
560
 
@@ -579,7 +579,7 @@ list `solutions`.
579
579
 
580
580
  Now let's see where we are...
581
581
 
582
- ```bash
582
+ ```console
583
583
  (byebug) set nofullpath
584
584
  Displaying frame's full file names is off.
585
585
  (byebug) bt
@@ -671,7 +671,7 @@ SievePrime.new.next_prime do |prime|
671
671
  end
672
672
  ```
673
673
 
674
- ```bash
674
+ ```console
675
675
  $ byebug primes.rb
676
676
  [1, 10] in /path/to/primes.rb
677
677
  1: #
@@ -874,7 +874,7 @@ We instantiate a new company with an initial task and after running that
874
874
  company we expect the result to be printed in the screen, but it is not. Lets
875
875
  debug our sample program:
876
876
 
877
- ```bash
877
+ ```console
878
878
  [1, 10] in /path/to/company.rb
879
879
  => 1: class Company
880
880
  2: def initialize(task)
@@ -926,7 +926,7 @@ can then check that the threads are there using the `thread list` command. Now
926
926
  we want to debug both of this threads to check what's happening and look for the
927
927
  bug.
928
928
 
929
- ```bash
929
+ ```console
930
930
  (byebug) th switch 3
931
931
 
932
932
  [5, 14] in /path/to/company.rb
@@ -961,7 +961,7 @@ and don't want the program to finish while we are debugging. Notice that stopped
961
961
  threads are marked with the "$" symbol whereas the current thread is marked with
962
962
  the "+" symbol.
963
963
 
964
- ```bash
964
+ ```console
965
965
  (byebug) s
966
966
 
967
967
  [17, 26] in /path/to/company.rb
@@ -1061,7 +1061,7 @@ Everything seems fine in this thread. The first iteration the employee will do
1061
1061
  his job, and after that it will just check for new tasks and sleep. Let's debug
1062
1062
  the manager task now:
1063
1063
 
1064
- ```bash
1064
+ ```console
1065
1065
  (byebug) th resume 2
1066
1066
  2 #<Thread:0x000000019892d8@/path/to/company.rb:12 run> /path/to/company.rb:12
1067
1067
  (byebug) th switch 2
@@ -1088,7 +1088,7 @@ run a sleeping thread.
1088
1088
 
1089
1089
  Now we can investigate the problem in the employer's side:
1090
1090
 
1091
- ```bash
1091
+ ```console
1092
1092
  (byebug) s
1093
1093
  [30, 39] in /path/to/company.rb
1094
1094
  30:
@@ -1173,7 +1173,7 @@ If you don't need to pass dash options to your program, which might be confused
1173
1173
  with byebug options, then you don't need to add the `--`. To get a brief list of
1174
1174
  options and descriptions, use the `--help` option.
1175
1175
 
1176
- ```bash
1176
+ ```console
1177
1177
  $ byebug --help
1178
1178
 
1179
1179
  byebug 3.5.1
@@ -1181,7 +1181,7 @@ $ byebug --help
1181
1181
  Usage: byebug [options] <script.rb> -- <script.rb parameters>
1182
1182
 
1183
1183
  -d, --debug Set $DEBUG=true
1184
- -I, --include list Add to paths to $LOAD_PATH
1184
+ -I, --include list Add paths to $LOAD_PATH
1185
1185
  -m, --[no-]post-mortem Use post-mortem mode
1186
1186
  -q, --[no-]quit Quit when script finishes
1187
1187
  -x, --[no-]rc Run byebug initialization file
@@ -1241,7 +1241,7 @@ Turns on line tracing. Running `byebug --trace <rubyscript>.rb` is pretty much
1241
1241
  like running `ruby -rtracer <rubyscript>.rb`. If all you want to do however is
1242
1242
  get a line trace, `tracer` is most likely faster than `byebug`.
1243
1243
 
1244
- ```bash
1244
+ ```console
1245
1245
  $ time byebug --trace --no-stop hanoi.rb > /dev/null
1246
1246
 
1247
1247
  real 0m0.743s
@@ -1354,9 +1354,9 @@ program that you want to debug (In Rails, the
1354
1354
  `config/environments/development.rb` could be a good candidate).
1355
1355
 
1356
1356
  ```ruby
1357
- require "byebug/core"
1358
- Byebug.wait_connection = true
1359
- Byebug.start_server("localhost", <port>)
1357
+ require "byebug/core"
1358
+ Byebug.wait_connection = true
1359
+ Byebug.start_server("localhost", <port>)
1360
1360
  ```
1361
1361
 
1362
1362
  Once this piece gets executed, you can connect to the remote debugger from your
@@ -1366,9 +1366,9 @@ Next, at a place of program execution which gets run just before the code you
1366
1366
  want to debug, add a call to `byebug` as was done without remote execution:
1367
1367
 
1368
1368
  ```ruby
1369
- # work, work, work...
1370
- byebug
1371
- some ruby code # byebug will stop before this line is run
1369
+ # work, work, work...
1370
+ byebug
1371
+ some ruby code # byebug will stop before this line is run
1372
1372
  ```
1373
1373
 
1374
1374
  ## Byebug Command Reference
@@ -1388,7 +1388,7 @@ with a backslash.
1388
1388
  For example, you might want to enter the following code to compute the 5th
1389
1389
  Fibonacci number.
1390
1390
 
1391
- ```bash
1391
+ ```console
1392
1392
  (byebug) fib1=0; fib2=1; 5.times {|temp| temp=fib1; fib1=fib2; fib2 += temp }
1393
1393
  0
1394
1394
  1
@@ -1438,7 +1438,7 @@ Once inside `byebug` you can always ask it for information on its commands using
1438
1438
  the `help` command. You can use `help` (abbreviated `h`) with no arguments to
1439
1439
  display a short list of named classes of commands
1440
1440
 
1441
- ```bash
1441
+ ```console
1442
1442
  (byebug) help
1443
1443
 
1444
1444
  break -- Sets breakpoints in the source code
@@ -1455,7 +1455,7 @@ display a short list of named classes of commands
1455
1455
  frame -- Moves to a frame in the call stack
1456
1456
  help -- Helps you using byebug
1457
1457
  history -- Shows byebug's history of commands
1458
- info -- Shows several informations about the program being debugged
1458
+ info -- Shows information about the program being debugged
1459
1459
  interrupt -- Interrupts the program
1460
1460
  irb -- Starts an IRB session
1461
1461
  kill -- Sends a signal to the current process
@@ -1483,7 +1483,7 @@ display a short list of named classes of commands
1483
1483
 
1484
1484
  With a command name, `help` displays information on how to use the command.
1485
1485
 
1486
- ```bash
1486
+ ```console
1487
1487
  (byebug) help list
1488
1488
 
1489
1489
  l[ist][[-=]][ nn-mm]
@@ -1511,7 +1511,7 @@ as `help info breakpoints`.
1511
1511
 
1512
1512
  Some examples follow.
1513
1513
 
1514
- ```bash
1514
+ ```console
1515
1515
  (byebug) help info
1516
1516
  info[ subcommand]
1517
1517
 
@@ -1530,14 +1530,14 @@ info line -- Line number and filename of current position in source file
1530
1530
  info program -- Execution status of the program
1531
1531
  ```
1532
1532
 
1533
- ```bash
1533
+ ```console
1534
1534
  (byebug) help info breakpoints
1535
1535
  Status of user-settable breakpoints.
1536
1536
  Without argument, list info about all breakpoints.
1537
1537
  With an integer argument, list info on that breakpoint.
1538
1538
  ```
1539
1539
 
1540
- ```bash
1540
+ ```console
1541
1541
  (byebug) help info b
1542
1542
  Status of user-settable breakpoints.
1543
1543
  Without argument, list info about all breakpoints.
@@ -1582,7 +1582,7 @@ printed if line tracing is enabled. Each expression added to the list is given a
1582
1582
  number to identify it; to remove an expression from the list, you specify that
1583
1583
  number. The automatic display looks like this:
1584
1584
 
1585
- ```bash
1585
+ ```console
1586
1586
  (byebug) display n
1587
1587
  1: n = 3
1588
1588
  ```
@@ -1591,7 +1591,7 @@ This display shows item numbers, expressions and their current values. If the
1591
1591
  expression is undefined or illegal the expression will be printed but no value
1592
1592
  will appear.
1593
1593
 
1594
- ```bash
1594
+ ```console
1595
1595
  (byebug) display undefined_variable
1596
1596
  2: undefined_variable =
1597
1597
  (byebug) display 1/0
@@ -1631,7 +1631,7 @@ program. If you issue a `list` without location information, the default
1631
1631
  location used is the current line rather than the current position that may have
1632
1632
  got updated via a prior `list` command.
1633
1633
 
1634
- ```
1634
+ ```console
1635
1635
  $ byebug triangle.rb
1636
1636
  [1, 10] in /path/to/triangle.rb
1637
1637
  1: # Compute the n'th triangle number, the hard way: triangle(n) == (n*(n+1))/2
@@ -1712,7 +1712,7 @@ You can customize `byebug` to use any editor you want by using the `EDITOR`
1712
1712
  environment variable. The only restriction is that your editor (say `ex`) recognizes
1713
1713
  the following command-line syntax:
1714
1714
 
1715
- ```
1715
+ ```bash
1716
1716
  ex +nnn file
1717
1717
  ```
1718
1718
 
@@ -1784,7 +1784,7 @@ One such method is `each`. They are marked differently in the call stack to
1784
1784
  indicate that we cannot switch to those frames. This is because they have no
1785
1785
  source code in Ruby, so we can not debug them using Byebug.
1786
1786
 
1787
- ```bash
1787
+ ```console
1788
1788
  (byebug) where
1789
1789
  --> #0 Object.gcd(a#Fixnum, b#Fixnum) at line gcd.rb:6
1790
1790
  #1 at line gcd.rb:19
data/README.md CHANGED
@@ -41,9 +41,7 @@ more][Tidelift for enterprise].
41
41
 
42
42
  ## Requirements
43
43
 
44
- * _Required_: MRI 2.4.0 or higher.
45
- * _Recommended_: MRI 2.6.4 or higher (MRI 2.6.0 to 2.6.3 contain a regression
46
- causing unbalanced call/return events in some cases, breaking the `next` command).
44
+ * _Required_: MRI 3.2.0 or higher.
47
45
 
48
46
  ## Install
49
47
 
@@ -143,7 +141,7 @@ relying on `byebug`.
143
141
  ## Getting Started
144
142
 
145
143
  Read [byebug's markdown
146
- guide](https://github.com/deivid-rodriguez/byebug/blob/master/GUIDE.md) to get
144
+ guide](https://github.com/deivid-rodriguez/byebug/blob/main/GUIDE.md) to get
147
145
  started. Proper documentation will be eventually written.
148
146
 
149
147
  ## Related projects
@@ -21,6 +21,29 @@ eval_expression(VALUE args)
21
21
  return rb_funcall2(rb_mKernel, idEval, 2, RARRAY_PTR(args));
22
22
  }
23
23
 
24
+ static void
25
+ mark_breakpoint(void *data)
26
+ {
27
+ breakpoint_t *breakpoint = data;
28
+
29
+ rb_gc_mark(breakpoint->source);
30
+ rb_gc_mark(breakpoint->expr);
31
+ }
32
+
33
+ static const rb_data_type_t breakpoint_type = {
34
+ "Byebug::Breakpoint",
35
+ {mark_breakpoint, RUBY_TYPED_DEFAULT_FREE},
36
+ };
37
+
38
+ static breakpoint_t *
39
+ brkpt_ptr(VALUE self)
40
+ {
41
+ breakpoint_t *breakpoint;
42
+
43
+ TypedData_Get_Struct(self, breakpoint_t, &breakpoint_type, breakpoint);
44
+ return breakpoint;
45
+ }
46
+
24
47
  /*
25
48
  * call-seq:
26
49
  * breakpoint.enabled? -> bool
@@ -30,9 +53,8 @@ eval_expression(VALUE args)
30
53
  static VALUE
31
54
  brkpt_enabled(VALUE self)
32
55
  {
33
- breakpoint_t *breakpoint;
56
+ breakpoint_t *breakpoint = brkpt_ptr(self);
34
57
 
35
- Data_Get_Struct(self, breakpoint_t, breakpoint);
36
58
  return breakpoint->enabled;
37
59
  }
38
60
 
@@ -45,9 +67,8 @@ brkpt_enabled(VALUE self)
45
67
  static VALUE
46
68
  brkpt_set_enabled(VALUE self, VALUE enabled)
47
69
  {
48
- breakpoint_t *breakpoint;
70
+ breakpoint_t *breakpoint = brkpt_ptr(self);
49
71
 
50
- Data_Get_Struct(self, breakpoint_t, breakpoint);
51
72
  return breakpoint->enabled = enabled;
52
73
  }
53
74
 
@@ -61,9 +82,8 @@ brkpt_set_enabled(VALUE self, VALUE enabled)
61
82
  static VALUE
62
83
  brkpt_expr(VALUE self)
63
84
  {
64
- breakpoint_t *breakpoint;
85
+ breakpoint_t *breakpoint = brkpt_ptr(self);
65
86
 
66
- Data_Get_Struct(self, breakpoint_t, breakpoint);
67
87
  return breakpoint->expr;
68
88
  }
69
89
 
@@ -77,9 +97,8 @@ brkpt_expr(VALUE self)
77
97
  static VALUE
78
98
  brkpt_set_expr(VALUE self, VALUE expr)
79
99
  {
80
- breakpoint_t *breakpoint;
100
+ breakpoint_t *breakpoint = brkpt_ptr(self);
81
101
 
82
- Data_Get_Struct(self, breakpoint_t, breakpoint);
83
102
  breakpoint->expr = NIL_P(expr) ? expr : StringValue(expr);
84
103
  return expr;
85
104
  }
@@ -94,9 +113,8 @@ brkpt_set_expr(VALUE self, VALUE expr)
94
113
  static VALUE
95
114
  brkpt_hit_condition(VALUE self)
96
115
  {
97
- breakpoint_t *breakpoint;
116
+ breakpoint_t *breakpoint = brkpt_ptr(self);
98
117
 
99
- Data_Get_Struct(self, breakpoint_t, breakpoint);
100
118
  switch (breakpoint->hit_condition)
101
119
  {
102
120
  case HIT_COND_GE:
@@ -124,10 +142,15 @@ brkpt_hit_condition(VALUE self)
124
142
  static VALUE
125
143
  brkpt_set_hit_condition(VALUE self, VALUE value)
126
144
  {
127
- breakpoint_t *breakpoint;
145
+ breakpoint_t *breakpoint = brkpt_ptr(self);
128
146
  ID id_value;
129
147
 
130
- Data_Get_Struct(self, breakpoint_t, breakpoint);
148
+ if (NIL_P(value))
149
+ {
150
+ breakpoint->hit_condition = HIT_COND_NONE;
151
+ return value;
152
+ }
153
+
131
154
  id_value = rb_to_id(value);
132
155
 
133
156
  if (rb_intern("greater_or_equal") == id_value || rb_intern("ge") == id_value)
@@ -150,9 +173,8 @@ brkpt_set_hit_condition(VALUE self, VALUE value)
150
173
  static VALUE
151
174
  brkpt_hit_count(VALUE self)
152
175
  {
153
- breakpoint_t *breakpoint;
176
+ breakpoint_t *breakpoint = brkpt_ptr(self);
154
177
 
155
- Data_Get_Struct(self, breakpoint_t, breakpoint);
156
178
  return INT2FIX(breakpoint->hit_count);
157
179
  }
158
180
 
@@ -166,9 +188,8 @@ brkpt_hit_count(VALUE self)
166
188
  static VALUE
167
189
  brkpt_hit_value(VALUE self)
168
190
  {
169
- breakpoint_t *breakpoint;
191
+ breakpoint_t *breakpoint = brkpt_ptr(self);
170
192
 
171
- Data_Get_Struct(self, breakpoint_t, breakpoint);
172
193
  return INT2FIX(breakpoint->hit_value);
173
194
  }
174
195
 
@@ -182,9 +203,8 @@ brkpt_hit_value(VALUE self)
182
203
  static VALUE
183
204
  brkpt_set_hit_value(VALUE self, VALUE value)
184
205
  {
185
- breakpoint_t *breakpoint;
206
+ breakpoint_t *breakpoint = brkpt_ptr(self);
186
207
 
187
- Data_Get_Struct(self, breakpoint_t, breakpoint);
188
208
  breakpoint->hit_value = FIX2INT(value);
189
209
  return value;
190
210
  }
@@ -198,9 +218,8 @@ brkpt_set_hit_value(VALUE self, VALUE value)
198
218
  static VALUE
199
219
  brkpt_id(VALUE self)
200
220
  {
201
- breakpoint_t *breakpoint;
221
+ breakpoint_t *breakpoint = brkpt_ptr(self);
202
222
 
203
- Data_Get_Struct(self, breakpoint_t, breakpoint);
204
223
  return INT2FIX(breakpoint->id);
205
224
  }
206
225
 
@@ -214,9 +233,8 @@ brkpt_id(VALUE self)
214
233
  static VALUE
215
234
  brkpt_pos(VALUE self)
216
235
  {
217
- breakpoint_t *breakpoint;
236
+ breakpoint_t *breakpoint = brkpt_ptr(self);
218
237
 
219
- Data_Get_Struct(self, breakpoint_t, breakpoint);
220
238
  if (breakpoint->type == BP_METHOD_TYPE)
221
239
  return rb_str_new2(rb_id2name(breakpoint->pos.mid));
222
240
  else
@@ -232,33 +250,23 @@ brkpt_pos(VALUE self)
232
250
  static VALUE
233
251
  brkpt_source(VALUE self)
234
252
  {
235
- breakpoint_t *breakpoint;
253
+ breakpoint_t *breakpoint = brkpt_ptr(self);
236
254
 
237
- Data_Get_Struct(self, breakpoint_t, breakpoint);
238
255
  return breakpoint->source;
239
256
  }
240
257
 
241
- static void
242
- mark_breakpoint(breakpoint_t *breakpoint)
243
- {
244
- rb_gc_mark(breakpoint->source);
245
- rb_gc_mark(breakpoint->expr);
246
- }
247
-
248
258
  static VALUE
249
259
  brkpt_create(VALUE klass)
250
260
  {
251
- breakpoint_t *breakpoint = ALLOC(breakpoint_t);
261
+ breakpoint_t *breakpoint;
252
262
 
253
- return Data_Wrap_Struct(klass, mark_breakpoint, xfree, breakpoint);
263
+ return TypedData_Make_Struct(klass, breakpoint_t, &breakpoint_type, breakpoint);
254
264
  }
255
265
 
256
266
  static VALUE
257
267
  brkpt_initialize(VALUE self, VALUE source, VALUE pos, VALUE expr)
258
268
  {
259
- breakpoint_t *breakpoint;
260
-
261
- Data_Get_Struct(self, breakpoint_t, breakpoint);
269
+ breakpoint_t *breakpoint = brkpt_ptr(self);
262
270
 
263
271
  breakpoint->type = FIXNUM_P(pos) ? BP_POS_TYPE : BP_METHOD_TYPE;
264
272
  if (breakpoint->type == BP_POS_TYPE)
@@ -353,7 +361,7 @@ check_breakpoint_by_hit_condition(VALUE rb_breakpoint)
353
361
  if (NIL_P(rb_breakpoint))
354
362
  return 0;
355
363
 
356
- Data_Get_Struct(rb_breakpoint, breakpoint_t, breakpoint);
364
+ breakpoint = brkpt_ptr(rb_breakpoint);
357
365
  breakpoint->hit_count++;
358
366
 
359
367
  if (Qtrue != breakpoint->enabled)
@@ -363,20 +371,17 @@ check_breakpoint_by_hit_condition(VALUE rb_breakpoint)
363
371
  {
364
372
  case HIT_COND_NONE:
365
373
  return 1;
366
- case HIT_COND_GE:
367
- {
374
+ case HIT_COND_GE: {
368
375
  if (breakpoint->hit_count >= breakpoint->hit_value)
369
376
  return 1;
370
377
  break;
371
378
  }
372
- case HIT_COND_EQ:
373
- {
379
+ case HIT_COND_EQ: {
374
380
  if (breakpoint->hit_count == breakpoint->hit_value)
375
381
  return 1;
376
382
  break;
377
383
  }
378
- case HIT_COND_MOD:
379
- {
384
+ case HIT_COND_MOD: {
380
385
  if (breakpoint->hit_count % breakpoint->hit_value == 0)
381
386
  return 1;
382
387
  break;
@@ -393,7 +398,7 @@ check_breakpoint_by_pos(VALUE rb_breakpoint, char *file, int line)
393
398
  if (NIL_P(rb_breakpoint))
394
399
  return 0;
395
400
 
396
- Data_Get_Struct(rb_breakpoint, breakpoint_t, breakpoint);
401
+ breakpoint = brkpt_ptr(rb_breakpoint);
397
402
 
398
403
  if (Qfalse == breakpoint->enabled || breakpoint->type != BP_POS_TYPE
399
404
  || breakpoint->pos.line != line)
@@ -410,7 +415,7 @@ check_breakpoint_by_method(VALUE rb_breakpoint, VALUE klass, ID mid, VALUE self)
410
415
  if (NIL_P(rb_breakpoint))
411
416
  return 0;
412
417
 
413
- Data_Get_Struct(rb_breakpoint, breakpoint_t, breakpoint);
418
+ breakpoint = brkpt_ptr(rb_breakpoint);
414
419
 
415
420
  if (Qfalse == breakpoint->enabled || breakpoint->type != BP_METHOD_TYPE
416
421
  || breakpoint->pos.mid != mid)
@@ -433,7 +438,7 @@ check_breakpoint_by_expr(VALUE rb_breakpoint, VALUE bind)
433
438
  if (NIL_P(rb_breakpoint))
434
439
  return 0;
435
440
 
436
- Data_Get_Struct(rb_breakpoint, breakpoint_t, breakpoint);
441
+ breakpoint = brkpt_ptr(rb_breakpoint);
437
442
 
438
443
  if (Qfalse == breakpoint->enabled)
439
444
  return 0;