# Rcov & Ruby 1.8.5

**URL:** <https://www.ruby-forum.com/t/rcov-ruby-1-8-5/67177>\
**Category:** Ruby\
**Created:** [September 1, 2006, 7:18am UTC](https://www.ruby-forum.com/t/rcov-ruby-1-8-5/67177 "2006-09-01T07:18:01Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![amin1426](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4da419/32.png) [@amin1426](https://www.ruby-forum.com/u/amin1426)\
**Post date:** [September 1, 2006, 7:18am UTC](https://www.ruby-forum.com/t/rcov-ruby-1-8-5/67177/1 "2006-09-01T07:18:01Z")

</div>

Is it my fevered imagination, or has Ruby-1.8.5 clobbered rcov-0.7.0,  
causing it to segfault.

Here is a backtrace…  
#0 coverage\_mark\_caller () at rcovrt.c:81  
#1 0xb7b19535 in coverage\_event\_coverage\_hook (event=, node=0xb7bd9450, self=3082662880, mid=23425, klass=3082634620) at  
rcovrt.c:154  
#2 0x0805ded5 in rb\_call0 (klass=,  
recv=3082662880, id=23425, oid=23425, argc=0, argv=0x0, body=0xb7bd948c,  
flags=) at eval.c:5952  
#3 0x0805e751 in rb\_call (klass=3082634620, recv=3082662880, mid=23425,  
argc=0, argv=0x0, scope=0) at eval.c:6048  
#4 0x0805c010 in rb\_eval (self=3082629180, n=) at  
eval.c:3443  
#5 0x0805d3df in rb\_eval (self=3082629180, n=) at  
eval.c:3173  
#6 0x0805e344 in rb\_call0 (klass=,  
recv=3082629180, id=11049, oid=11049, argc=0, argv=0x8, body=0xb7be8ae0,  
flags=) at eval.c:5954  
#7 0x0805e751 in rb\_call (klass=3082663220, recv=3082629180, mid=11049,  
argc=0, argv=0x8, scope=3) at eval.c:6048  
#8 0x0806039e in rb\_call\_super (argc=0, argv=0x8) at eval.c:6216  
#9 0x0805af10 in rb\_eval (self=3082629180, n=) at  
eval.c:3505  
#10 0x0805e344 in rb\_call0 (klass=,  
recv=3082629180, id=11049, oid=11049, argc=0, argv=0x0, body=0xb7be5c78,  
flags=) at eval.c:5954  
#11 0x0805e751 in rb\_call (klass=3082663160, recv=3082629180, mid=11049,  
argc=0, argv=0x0, scope=0) at eval.c:6048  
#12 0x0805c010 in rb\_eval (self=3084253680, n=) at  
eval.c:3443  
#13 0x080692ae in ruby\_exec\_internal () at eval.c:1604  
#14 0x080692e6 in ruby\_exec () at eval.c:1624  
#15 0x08069311 in ruby\_run () at eval.c:1634  
#16 0x08052474 in main (argc=Cannot access memory at address 0x2  
) at main.c:46

Looking in coverage\_mark\_caller () at rcovrt.c:81  
for (; frame && (n = frame-\>node); frame = frame-\>prev) {  
if (frame-\>prev && frame-\>prev-\>last\_func) {  
if (frame-\>prev-\>node == n) continue;  
coverage\_increase\_counter\_uncached(n-\>nd\_file,  
nd\_line(n) - 1, 1);  
}  
else {  
-line 81–\> coverage\_increase\_counter\_uncached(n-\>nd\_file,  
nd\_line(n) - 1, 1);  
}  
break;  
}

if I print out n, it’s value is (NODE \*) 0x2

If I print frame the value is (struct FRAME \*) 0x0

p \*ruby\_frame  
$8 = {  
self = 3082662880,  
argc = 0,  
last\_func = 23425,  
orig\_func = 23425,  
last\_class = 3082634620,  
prev = 0xbfd285e4,  
tmp = 0x0,  
node = 0xb7be8a2c,  
iter = 2,  
flags = 0,  
uniq = 15318  
}

John C. Phone : (64)(3) 358 6639  
Tait Electronics Fax : (64)(3) 359 4632  
PO Box 1645 Christchurch Email : removed\_email\_address@domain.invalid  
New Zealand

…even the weariest river winds somewhere safe to sea.

---

<div class="post-metadata">

**Author:** ![amin1426](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4da419/32.png) [@amin1426](https://www.ruby-forum.com/u/amin1426)\
**Post date:** [September 1, 2006, 11:26pm UTC](https://www.ruby-forum.com/t/rcov-ruby-1-8-5/67177/2 "2006-09-01T23:26:14Z")

</div>

John C. wrote:

> Is it my fevered imagination, or has Ruby-1.8.5 clobbered rcov-0.7.0,  
> causing it to segfault.

I may not have exercised everything it can do, but for a contrary  
data point I can say that rcov-0.7.0 does run OK on Windows  
with ruby installed via OneClickInstaller 185-21 and rcov installed  
as a gem. I have run it ‘stand-alone’ from the command line and  
via rake using the Spec::Rake::SpecTask shipped with rSpec.

I guess it might be different on other platforms?

DJ

---

<div class="post-metadata">

**Author:** ![amin1426](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4da419/32.png) [@amin1426](https://www.ruby-forum.com/u/amin1426)\
**Post date:** [September 5, 2006, 4:00am UTC](https://www.ruby-forum.com/t/rcov-ruby-1-8-5/67177/3 "2006-09-05T04:00:49Z")

</div>

On Tue, 5 Sep 2006, Mauricio F. wrote:

> On Fri, Sep 01, 2006 at 02:16:58PM +0900, John C. wrote:
> 
> > Is it my fevered imagination, or has Ruby-1.8.5 clobbered rcov-0.7.0,  
> > causing it to segfault.

> This code was mostly taken from eval.c’s backtrace(). It was changed on  
> Jul 24, but the modification doesn’t seem to imply that the above would  
> segfault under 1.8.5. At any rate, here’s the patch to mirror the new  
> backtrace():
> 
> diff -rN -u old-head/ext/rcovrt/rcovrt.c new-head/ext/rcovrt/rcovrt.c

Yip. That fixed it!

Thanks!

John C. Phone : (64)(3) 358 6639  
Tait Electronics Fax : (64)(3) 359 4632  
PO Box 1645 Christchurch Email : removed\_email\_address@domain.invalid  
New Zealand

“We have more to fear from  
The Bungling of the Incompetent  
Than from the Machinations of the Wicked.” (source unknown)

---

<div class="post-metadata">

**Author:** ![amin1426](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4da419/32.png) [@amin1426](https://www.ruby-forum.com/u/amin1426)\
**Post date:** [September 5, 2006, 6:56pm UTC](https://www.ruby-forum.com/t/rcov-ruby-1-8-5/67177/4 "2006-09-05T18:56:06Z")

</div>

On Tue, Sep 05, 2006 at 10:53:42AM +0900, John C. wrote:

> > diff -rN -u old-head/ext/rcovrt/rcovrt.c new-head/ext/rcovrt/rcovrt.c
> 
> Yip. That fixed it!

That’s good news but I’d have liked to understand why 🙂

I’ll apply that patch for the next release; probably compiling it  
conditionally. While it looks like it should work with \<1.8.5, I’m  
obviously  
missing something because I don’t quite see why it fixed the segfault  
you  
reported 🙂 (iow. I have yet to find the modification that allowed  
frame-\>node to hold invalid pointers).

---

<div class="post-metadata">

**Author:** ![amin1426](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4da419/32.png) [@amin1426](https://www.ruby-forum.com/u/amin1426)\
**Post date:** [September 7, 2006, 2:45am UTC](https://www.ruby-forum.com/t/rcov-ruby-1-8-5/67177/5 "2006-09-07T02:45:27Z")

</div>

On Wed, 6 Sep 2006, Mauricio F. wrote:

> > > diff -rN -u old-head/ext/rcovrt/rcovrt.c new-head/ext/rcovrt/rcovrt.c
> > 
> > Yip. That fixed it!
> 
> That’s good news but I’d have liked to understand why 🙂

If you can think of some good way to instrument things to find out, I’ll  
gladly do it.

John C. Phone : (64)(3) 358 6639  
Tait Electronics Fax : (64)(3) 359 4632  
PO Box 1645 Christchurch Email : removed\_email\_address@domain.invalid  
New Zealand

“We have more to fear from  
The Bungling of the Incompetent  
Than from the Machinations of the Wicked.” (source unknown)

---

<div class="post-metadata">

**Author:** ![amin1426](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4da419/32.png) [@amin1426](https://www.ruby-forum.com/u/amin1426)\
**Post date:** [September 4, 2006, 6:19pm UTC](https://www.ruby-forum.com/t/rcov-ruby-1-8-5/67177/6 "2006-09-04T18:19:50Z")

</div>

On Fri, Sep 01, 2006 at 02:16:58PM +0900, John C. wrote:

> Is it my fevered imagination, or has Ruby-1.8.5 clobbered rcov-0.7.0,  
> causing it to segfault.

AFAIK it works with ruby 1.8.5 (I just ran it on Pimki’s tests to make  
sure) [1].

> Here is a backtrace…

> #0 coverage\_mark\_caller () at rcovrt.c:81  
> […]
> 
> - 1, 1);  
> }  
> break;  
> }
> 
> if I print out n, it’s value is (NODE \*) 0x2

This code was mostly taken from eval.c’s backtrace(). It was changed on  
Jul 24, but the modification doesn’t seem to imply that the above would  
segfault under 1.8.5. At any rate, here’s the patch to mirror the new  
backtrace():

diff -rN -u old-head/ext/rcovrt/rcovrt.c new-head/ext/rcovrt/rcovrt.c  
— old-head/ext/rcovrt/rcovrt.c 2006-09-04 16:46:46.000000000  
+0200  
+++ new-head/ext/rcovrt/rcovrt.c 2006-09-04 16:46:46.000000000  
+0200  
@@ -74,7 +74,9 @@  
}  
for (; frame && (n = frame-\>node); frame = frame-\>prev) {  
if (frame-\>prev && frame-\>prev-\>last\_func) {

- 

```
             if (frame->prev->node == n) continue;

```

- 

```
             if (frame->prev->node == n) {

```

- 

```
                     if (frame->prev->last_func == 

```

frame-\>last\_func) continue;

- 

```
             }
             coverage_increase_counter_uncached(n->nd_file, 

```

nd\_line(n) - 1, 1);  
}  
else {

I wouldn’t expect that to prevent the segfault (which I cannot reproduce  
anyway), but that’s the only patch I can think of right now.

We’re looking for either:

- a bug in coverage\_mark\_caller due to my misunderstanding of  
backtrace()'s  
code in eval.c
- a genuine bug in Ruby (why would a frame-\>node == 2)
- something caused by a buggy extension (the usual suspect used to be  
syck,  
but it’s gotten better as of late 😉

Is there any way to reproduce the segfault?

[1] 1.8.5 breaks rcov in pure-Ruby mode, but I don’t think anybody is  
using  
it anyway, since it’s over 100 times slower… I’ll try to fix that  
though.
