Skip to content

[Bug #19456] Fix incorrect line numbers in GC hook #7357

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 24, 2023

Conversation

peterzhu2118
Copy link
Member

If the previous instruction is not a leaf instruction, then the PC was incremented before the instruction was ran (meaning the currently executing instruction is actually the previous instruction), so we should not increment the PC otherwise we will calculate the source line for the next instruction.

This bug can be reproduced in the following script:

require "objspace"

ObjectSpace.trace_object_allocations_start
a =





  1.0 / 0.0
p [ObjectSpace.allocation_sourceline(a), ObjectSpace.allocation_sourcefile(a)]

Which outputs: [4, "test.rb"]

This is incorrect because the object was allocated on line 10 and not line 4. The behaviour is correct when we use a leaf instruction (e.g. if we replaced 1.0 / 0.0 with "hello"), then the output is: [10, "test.rb"].

@peterzhu2118 peterzhu2118 force-pushed the pz-event-hook-pc branch 7 times, most recently from 5bddfbc to f00892c Compare February 23, 2023 19:54
@__LINE__ can be nil which causes the inspect method to fail.
If the previous instruction is not a leaf instruction, then the PC was
incremented before the instruction was ran (meaning the currently
executing instruction is actually the previous instruction), so we
should not increment the PC otherwise we will calculate the source
line for the next instruction.

This bug can be reproduced in the following script:

```
require "objspace"

ObjectSpace.trace_object_allocations_start
a =

  1.0 / 0.0
p [ObjectSpace.allocation_sourceline(a), ObjectSpace.allocation_sourcefile(a)]
```

Which outputs: [4, "test.rb"]

This is incorrect because the object was allocated on line 10 and not
line 4. The behaviour is correct when we use a leaf instruction (e.g.
if we replaced `1.0 / 0.0` with `"hello"`), then the output is:
[10, "test.rb"].

[Bug #19456]
@peterzhu2118 peterzhu2118 merged commit 3e09822 into ruby:master Feb 24, 2023
@peterzhu2118 peterzhu2118 deleted the pz-event-hook-pc branch February 24, 2023 19:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant