Skip to content

Instantly share code, notes, and snippets.

@thbar
Created January 30, 2011 10:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save thbar/802773 to your computer and use it in GitHub Desktop.
Save thbar/802773 to your computer and use it in GitHub Desktop.
A git bisect run compatible script to track down the hpricot 0.8.3 segfaults
# an attempt to identify the commit when hpricot 0.8.3 segfaults
# were introduced.
#
# To be able to use git bisect run, I used fork to run the test-case,
# as otherwise the running process is left in a zombie I don't wanna leave state.
#
# Put this in hpricot source folder (with the Rakefile), then run:
#
# $ git checkout master
# $ git bisect start HEAD 0.8.2
# $ git bisect run ruby crash_it.rb
require 'neversaydie' # allows us to exit on some kind of crashes, apparently
def system!(cmd,silent=true)
cmd << " > /dev/null 2>&1" if silent
puts "#{cmd} failed!" unless system(cmd)
end
# return true if probable segfault
def attempt_to_seg_fault
# late loading, otherwise we wouldn't load the latest compiled version
$LOAD_PATH << File.dirname(__FILE__) + '/lib'
require 'hpricot'
read, write = IO.pipe
Process.fork do
15.times do |i|
data = "<item>"
50000.times do |j|
data << "<line>This is line #{j} for turn #{i}</line>"
end
data << "</item>"
doc = Hpricot(data)
end
write.puts "OK"
end
sleep(5)
write.close
read.read !~ /OK/
end
system!("rake clean")
system!("rm -rf tmp")
system!("rake compile")
result = attempt_to_seg_fault
# not sure if it's necessary
system!("git checkout -- ext/hpricot_scan/hpricot_css.c")
system!("git checkout -- ext/hpricot_scan/hpricot_scan.c")
if result
puts "Crash confirmed"
exit(1) # don't use -1 - git bisect run requires exit code between 0 and 127
else
puts "No crash"
exit
end
======== use with caution and verify - the output could be false if the git bisect run script is buggy ========
[master] thbar@~/git/hpricot: git bisect start HEAD 0.8.2
Already on 'master'
Bisecting: 13 revisions left to test after this (roughly 4 steps)
[22a1d183f6cb00b278b9e0ec9d02ea6c2e1e3bce] test case for the fix done for the issue#16
[(no branch)] thbar@~/git/hpricot: git bisect run ruby crash_it.rb
running ruby crash_it.rb
No crash
Bisecting: 6 revisions left to test after this (roughly 3 steps)
[6b03c0cd37a1d773bb41da40ccbcdfaffdc100f1] Ignore and clean .rbc
running ruby crash_it.rb
/Users/thbar/git/hpricot/lib/hpricot/parse.rb:33: [BUG] object allocation during garbage collection phase
ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-darwin10.4.1]
-- control frame ----------
c:0014 p:---- s:0049 b:0049 l:000048 d:000048 CFUNC :(null)
c:0013 p:---- s:0047 b:0047 l:000046 d:000046 CFUNC :scan
c:0012 p:0074 s:0042 b:0042 l:000041 d:000041 METHOD /Users/thbar/git/hpricot/lib/hpricot/parse.rb:33
c:0011 p:0030 s:0035 b:0035 l:000034 d:000034 METHOD /Users/thbar/git/hpricot/lib/hpricot/parse.rb:4
c:0010 p:0040 s:0029 b:0029 l:000011 d:000028 BLOCK crash_it.rb:30
c:0009 p:---- s:0024 b:0024 l:000023 d:000023 FINISH
c:0008 p:---- s:0022 b:0022 l:000021 d:000021 CFUNC :times
c:0007 p:0010 s:0019 b:0019 l:000011 d:000018 BLOCK crash_it.rb:24
c:0006 p:---- s:0017 b:0017 l:000016 d:000016 FINISH
c:0005 p:---- s:0015 b:0015 l:000014 d:000014 CFUNC :fork
c:0004 p:0077 s:0012 b:0012 l:000011 d:000011 METHOD crash_it.rb:23
c:0003 p:0091 s:0007 b:0007 l:001588 d:001fd0 EVAL crash_it.rb:45
c:0002 p:---- s:0004 b:0004 l:000003 d:000003 FINISH
c:0001 p:0000 s:0002 b:0002 l:001588 d:001588 TOP
---------------------------
-- Ruby level backtrace information ----------------------------------------
crash_it.rb:45:in `<main>'
crash_it.rb:23:in `attempt_to_seg_fault'
crash_it.rb:23:in `fork'
crash_it.rb:24:in `block in attempt_to_seg_fault'
crash_it.rb:24:in `times'
crash_it.rb:30:in `block (2 levels) in attempt_to_seg_fault'
/Users/thbar/git/hpricot/lib/hpricot/parse.rb:4:in `Hpricot'
/Users/thbar/git/hpricot/lib/hpricot/parse.rb:33:in `make'
/Users/thbar/git/hpricot/lib/hpricot/parse.rb:33:in `scan'
Crash confirmed
Bisecting: 3 revisions left to test after this (roughly 2 steps)
[4c84f1f49498584da53a8d9601725ab26b246c3d] Remove RSTRUCT craziness, don't break Array#at
running ruby crash_it.rb
dyld: lazy symbol binding failed: Symbol not found: _XFREE
Referenced from: /Users/thbar/git/hpricot/lib/hpricot_scan.bundle
Expected in: flat namespace
dyld: Symbol not found: _XFREE
Referenced from: /Users/thbar/git/hpricot/lib/hpricot_scan.bundle
Expected in: flat namespace
Crash confirmed
Bisecting: 0 revisions left to test after this (roughly 1 step)
[04ea3d8c35ab91084f609c6eb899e6a961f9b35b] Merge remote branch 'anusuyaceg/master'
running ruby crash_it.rb
No crash
4c84f1f49498584da53a8d9601725ab26b246c3d is the first bad commit
commit 4c84f1f49498584da53a8d9601725ab26b246c3d
Author: Evan Phoenix <ephoenix@engineyard.com>
Date: Thu Sep 9 15:17:54 2010 -0700
Remove RSTRUCT craziness, don't break Array#at
This fix allows Rubinius 1.1+ to run hpricot.
:040000 040000 d14ec5aa3bdf8054d0d06cc6c375175061415460 a6beb0541fa89847a6d5d57e572f0cb4dca51540 M ext
:040000 040000 ed02042f9609dedcf7c4a983d12d3f4ed70c98b1 3b1f974bf3d149d7c8f30a1cde13edbbe9c12e83 M lib
bisect run success
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment