gdb-logparse.rb

Koichi Sasada, 06/07/2012 03:27 PM

Download (1.3 KB)

 
1
require 'pp'
2

    
3
def parse lines
4
  trace = {}
5
  st_func = Hash.new(0)
6
  st_line = Hash.new(0)
7

    
8
  lines.each_line{|line|
9
    case line
10
    when /^\d: x\/i\ \$pc/ # output
11
      if trace[:line]
12
        file = "#{trace[:file]}:#{trace[:line]}"
13
      else
14
        file = ''
15
      end
16

    
17
      if true # false
18
        puts "%-25s %-50s %s" % [trace[:func_off], trace[:asm], file]
19
      end
20

    
21
      st_func[trace[:func]] += 1
22
      st_line[file] += 1
23

    
24
    # 0x81c4b8e <vm_exec+14>:        call   0x805c3c0 <__i686.get_pc_thunk.bx>
25
    when /^0x[\da-z]+ <(.+?)>:\s+(.+)/
26
      trace[:func] = trace[:func_off] = $1
27
      trace[:asm] = $2
28
      if /(.+)\+(\d+)/ =~ $1
29
        trace[:func] = $1
30
        trace[:off] = $2
31
      end
32
    # Line 104 of "../clean-trunk/vm_exec.c" starts at address 0x81be1fc <vm_exec_core+76> and ends at 0x81be202 <vm_exec_core+82>.
33
    when /^Line (\d+) of \"(.+)\"/
34
      trace[:line] = $1
35
      trace[:file] = $2
36
    # No line number information available for address 0x805bab0 <_setjmp@plt>
37
    when /^No line number information available for address 0x[\da-f]+ <(.+)>/
38
      trace[:line] = nil
39
      trace[:file] = nil
40
    end
41
  }
42

    
43
  [st_func, st_line].each{|st|
44
    st.sort_by{|k,v| -v}.each{|k,v| puts "#{k}\t#{v}"}
45
    puts
46
  }
47
end
48

    
49
parse open(ARGV.shift || 'gdb.txt')