diff options
author | Devang Patel <dpatel@apple.com> | 2010-12-07 00:34:59 +0000 |
---|---|---|
committer | Devang Patel <dpatel@apple.com> | 2010-12-07 00:34:59 +0000 |
commit | 8802f0b2d01be96a4062853990faa3f03eb3e3aa (patch) | |
tree | c871b0ccdb87ef6c87ebf1f0bc55a07262cf098f /utils | |
parent | f5f2300d2489ba1110b919abd18714ad707ec9a8 (diff) | |
download | external_llvm-8802f0b2d01be96a4062853990faa3f03eb3e3aa.zip external_llvm-8802f0b2d01be96a4062853990faa3f03eb3e3aa.tar.gz external_llvm-8802f0b2d01be96a4062853990faa3f03eb3e3aa.tar.bz2 |
Add python scripts to extract debug info using LLDB and do comparison.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@121079 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils')
-rwxr-xr-x | utils/CollectDebugInfoUsingLLDB.py | 143 | ||||
-rwxr-xr-x | utils/CompareDebugInfo.py | 64 |
2 files changed, 207 insertions, 0 deletions
diff --git a/utils/CollectDebugInfoUsingLLDB.py b/utils/CollectDebugInfoUsingLLDB.py new file mode 100755 index 0000000..6d67693 --- /dev/null +++ b/utils/CollectDebugInfoUsingLLDB.py @@ -0,0 +1,143 @@ +#!/usr/bin/python + +#---------------------------------------------------------------------- +# Be sure to add the python path that points to the LLDB shared library. +# On MacOSX csh, tcsh: +# setenv PYTHONPATH /Developer/Library/PrivateFrameworks/LLDB.framework/Resources/Python +# On MacOSX sh, bash: +# export PYTHONPATH=/Developer/Library/PrivateFrameworks/LLDB.framework/Resources/Python +#---------------------------------------------------------------------- + +import lldb +import os +import sys +import time + +def print_var_value (v, file, frame): + if v.GetNumChildren() > 0: + for c in range(v.GetNumChildren()): + if v.GetChildAtIndex(c) is None: + file.write("None") + else: + if (v.GetChildAtIndex(c).GetName()) is None: + file.write("None") + else: + file.write(v.GetChildAtIndex(c).GetName()) + file.write('=') + print_var_value(v.GetChildAtIndex(c), file, frame) + file.write(',') + else: + if v.GetValue(frame) is None: + file.write("None") + else: + file.write(v.GetValue(frame)) + + +def print_vars (vars, fname, line, file, frame, target, thread): + # disable this thread. + count = thread.GetStopReasonDataCount() + bid = 0 + tid = 0 + for i in range(count): + id = thread.GetStopReasonDataAtIndex(i) + bp = target.FindBreakpointByID(id) + if bp.IsValid(): + if bp.IsEnabled() == True: + bid = bp.GetID() + tid = bp.GetThreadID() + bp.SetEnabled(False) + else: + bp_loc = bp.FindLocationByID(thread.GetStopReasonDataAtIndex(i+1)) + if bp_loc.IsValid(): + bid = bp_loc.GetBreakPoint().GetID() + tid = bp_loc.ThreadGetID() + # print " { ", bp_loc.ThreadGetID(), " : ", bp_loc.GetBreakPoint().GetID(), " }} " + bp_loc.SetEnabled(False); + + for i in range(vars.GetSize()): + file.write("#Argument ") + file.write(fname) + file.write(':') + file.write(str(line)) + file.write(' ') + file.write(str(tid)) + file.write(':') + file.write(str(bid)) + file.write(' ') + v = vars.GetValueAtIndex(i) + file.write(v.GetName()) + file.write(' ') + print_var_value (v, file, frame) + file.write('\n') + +def set_breakpoints (target, breakpoint_filename): + f = open(breakpoint_filename, "r") + lines = f.readlines() + for l in range(len(lines)): + c = lines[l].split() + # print "setting break point - ", c + bp = target.BreakpointCreateByLocation (str(c[0]), int(c[1])) + f.close() + +def stop_at_breakpoint (process): + if process.IsValid(): + state = process.GetState() + if state != lldb.eStateStopped: + return lldb.eStateInvalid + thread = process.GetThreadAtIndex(0) + if thread.IsValid(): + if thread.GetStopReason() == lldb.eStopReasonBreakpoint: + return lldb.eStateStopped + else: + return lldb.eStateInvalid + else: + return lldb.eStateInvalid + else: + return lldb.eStateInvalid + +# Create a new debugger instance +debugger = lldb.SBDebugger.Create() + +# When we step or continue, don't return from the function until the process +# stops. We do this by setting the async mode to false. +debugger.SetAsync (False) + +# Create a target from a file and arch +##print "Creating a target for '%s'" % sys.argv[1] + +target = debugger.CreateTargetWithFileAndArch (sys.argv[1], lldb.LLDB_ARCH_DEFAULT) + +if target.IsValid(): + #print "target is valid" + set_breakpoints (target, sys.argv[2]) + #main_bp = target.BreakpointCreateByLocation ("byval-alignment.c", 11) + #main_bp2 = target.BreakpointCreateByLocation ("byval-alignment.c", 20) + + ##print main_bp + + # Launch the process. Since we specified synchronous mode, we won't return + # from this function until we hit the breakpoint at main + process = target.LaunchProcess ([''], [''], "/dev/stdout", 0, False) + file=open(str(sys.argv[3]), 'w') + # Make sure the launch went ok + while stop_at_breakpoint(process) == lldb.eStateStopped: + thread = process.GetThreadAtIndex (0) + frame = thread.GetFrameAtIndex (0) + if frame.IsValid(): + # #Print some simple frame info + ##print frame + #print "frame is valid" + function = frame.GetFunction() + if function.IsValid(): + fname = function.GetMangledName() + if fname is None: + fname = function.GetName() + #print "function : ",fname + vars = frame.GetVariables(1,0,0,0) + line = frame.GetLineEntry().GetLine() + print_vars (vars, fname, line, file, frame, target, thread) + #print vars + process.Continue() + file.close() + +lldb.SBDebugger.Terminate() diff --git a/utils/CompareDebugInfo.py b/utils/CompareDebugInfo.py new file mode 100755 index 0000000..12a086b --- /dev/null +++ b/utils/CompareDebugInfo.py @@ -0,0 +1,64 @@ +#!/usr/bin/python + +import os +import sys + +class BreakPoint: + def __init__(self, bp_name): + self.name = bp_name + self.values = {} + + def recordArgument(self, arg_name, value): + self.values[arg_name] = value + + def __repr__(self): + print self.name + items = self.values.items() + for i in range(len(items)): + print items[i][0]," = ",items[i][1] + return '' + + def __cmp__(self, other): + return cmp(self.values, other.values) + +def read_input(filename, dict): + f = open(filename, "r") + lines = f.readlines() + for l in range(len(lines)): + c = lines[l].split() + if c[0] == "#Argument": + bp = dict.get(c[2]) + if bp is None: + bp = BreakPoint(c[1]) + dict[c[2]] = bp + bp.recordArgument(c[3], c[4]) + + f.close() + return + +f1_breakpoints = {} +read_input(sys.argv[1], f1_breakpoints) +f1_items = f1_breakpoints.items() + +f2_breakpoints = {} +read_input(sys.argv[2], f2_breakpoints) +f2_items = f2_breakpoints.items() + +mismatch = 0 +for f2bp in range(len(f2_items)): + id = f2_items[f2bp][0] + bp = f2_items[f2bp][1] + bp1 = f1_breakpoints.get(id) + if bp1 is None: + print "bp is missing" + else: + if bp1 != bp: + mismatch = mismatch + 1 + +l2 = len(f2_items) +print "==========" +if l2 != 0: + print sys.argv[3]," success rate is", (l2-mismatch)*100/l2,"%" +else: + print sys.argv[3]," success rate is 100%" +print "==========" |