Module: GDB

Defined in:
lib/misc/gdb.rb

Class Method Summary collapse

Class Method Details

.check_core(dir) ⇒ Object



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

.rename_core(core_path) ⇒ Object



65
66
67
68
69
70
71
72
73
# File 'lib/misc/gdb.rb', line 65

def rename_core(core_path)
  suffix = ".chkbuild."
  n = 1
  while File.exist?(new_path = "#{core_path}.chkbuild.#{n}")
    n += 1
  end
  File.rename(core_path, new_path)
  new_path
end