Project

General

Profile

MachineInstructionsTraceWithGDB ยป gdb-logparse.rb

ko1 (Koichi Sasada), 06/07/2012 03:27 PM

 
require 'pp'

def parse lines
trace = {}
st_func = Hash.new(0)
st_line = Hash.new(0)

lines.each_line{|line|
case line
when /^\d: x\/i\ \$pc/ # output
if trace[:line]
file = "#{trace[:file]}:#{trace[:line]}"
else
file = ''
end

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

st_func[trace[:func]] += 1
st_line[file] += 1

# 0x81c4b8e <vm_exec+14>: call 0x805c3c0 <__i686.get_pc_thunk.bx>
when /^0x[\da-z]+ <(.+?)>:\s+(.+)/
trace[:func] = trace[:func_off] = $1
trace[:asm] = $2
if /(.+)\+(\d+)/ =~ $1
trace[:func] = $1
trace[:off] = $2
end
# Line 104 of "../clean-trunk/vm_exec.c" starts at address 0x81be1fc <vm_exec_core+76> and ends at 0x81be202 <vm_exec_core+82>.
when /^Line (\d+) of \"(.+)\"/
trace[:line] = $1
trace[:file] = $2
# No line number information available for address 0x805bab0 <_setjmp@plt>
when /^No line number information available for address 0x[\da-f]+ <(.+)>/
trace[:line] = nil
trace[:file] = nil
end
}

[st_func, st_line].each{|st|
st.sort_by{|k,v| -v}.each{|k,v| puts "#{k}\t#{v}"}
puts
}
end

parse open(ARGV.shift || 'gdb.txt')
    (1-1/1)