33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/misc/gdb.rb', line 33
def check_core(dir)
binaries = {}
core_info = []
Find.find(dir.to_s) {|f|
stat = File.stat(f)
basename = File.basename(f)
binaries[basename] = f if stat.file? && stat.executable?
next if /\bcore\b/ !~ basename
next if /\.chkbuild\.\d+\z/ =~ basename
guess = `file #{f} 2>&1`
next if /\bcore\b.*from '(.*?)'/ !~ guess.sub(/\A.*?:/, '')
core_info << [f, $1]
}
gdb_command = nil
core_info.each {|core_path, binary|
next unless binary_path = binaries[binary]
core_path = rename_core(core_path)
unless gdb_command
gdb_command = Tempfile.new("gdb-bt")
gdb_command.puts "bt"
gdb_command.close
end
puts
puts "binary: #{binary_path}"
puts "core: #{core_path}"
command = %W[gdb -batch -n -x #{gdb_command.path} #{binary_path} #{core_path}]
gdb_output = `#{Escape.shell_command command}`
puts gdb_output
puts "gdb status: #{$?}"
}
end
|