[llvm-commits] [test-suite] r128423 - in /test-suite/trunk: CollectDebugInfoUsingLLDB.py CompareDebugInfo.py Makefile.programs TEST.dbg.Makefile

Devang Patel dpatel at apple.com
Mon Mar 28 13:25:47 PDT 2011


Author: dpatel
Date: Mon Mar 28 15:25:47 2011
New Revision: 128423

URL: http://llvm.org/viewvc/llvm-project?rev=128423&view=rev
Log:
Tidy up TEST=dbg reports.

Added:
    test-suite/trunk/CollectDebugInfoUsingLLDB.py   (with props)
    test-suite/trunk/CompareDebugInfo.py   (with props)
Modified:
    test-suite/trunk/Makefile.programs
    test-suite/trunk/TEST.dbg.Makefile

Added: test-suite/trunk/CollectDebugInfoUsingLLDB.py
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/CollectDebugInfoUsingLLDB.py?rev=128423&view=auto
==============================================================================
--- test-suite/trunk/CollectDebugInfoUsingLLDB.py (added)
+++ test-suite/trunk/CollectDebugInfoUsingLLDB.py Mon Mar 28 15:25:47 2011
@@ -0,0 +1,237 @@
+#!/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
+#
+# This script collect debugging information using LLDB. This script is
+# used by TEST=dbg in llvm testsuite to measure quality of debug info in
+# optimized builds.
+#
+# Usage:
+# export PYTHONPATH=...
+# ./CollectDebugInfUsingLLDB.py program bp_file out_file
+#     program - Executable program with debug info.
+#     bp_file - Simple text file listing breakpoints.
+#               <absolute file name> <line number>
+#     out_file - Output file where the debug info will be emitted.
+#----------------------------------------------------------------------
+
+import lldb
+import os
+import sys
+import time
+
+# AlreadyPrintedValues - A place to keep track of recursive values.
+AlreadyPrintedValues = {}
+
+# ISAlreadyPrinted - Return true if value is already printed.
+def IsAlreadyPrinted(value_name):
+        if AlreadyPrintedValues.get(value_name) is None:
+                AlreadyPrintedValues[value_name] = 1
+                return False
+        return True
+
+
+# print_var_value - Print a variable's value.
+def print_var_value (v, file, frame):
+        if v.IsValid() == False:
+                return
+        if IsAlreadyPrinted(v.GetName()):
+                return
+        total_children = v.GetNumChildren()
+        if total_children > 0:
+            c = 0
+            while (c < total_children) :
+                    child = v.GetChildAtIndex(c)
+                    if child is None:
+                        file.write("None")
+                    else:
+                        if (child.GetName()) is None:
+                                file.write("None")
+                        else:
+                                file.write(child.GetName())
+                                file.write('=')
+                                print_var_value(child, file, frame)
+                                file.write(',')
+                    c = c + 1
+        else:
+            if v.GetValue(frame) is None:
+                file.write("None")
+            else:
+                file.write(v.GetValue(frame))
+
+def disable_bp(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)
+	            # print " disabled [", str(bp.GetThreadID()), ":", str(bp.GetID()), "]"
+        else:
+            bp_loc = bp.FindLocationByID(thread.GetStopReasonDataAtIndex(i+1))
+            if bp_loc.IsValid():
+                bid = bp_loc.GetBreakPoint().GetID()
+                tid = bp_loc.ThreadGetID()
+                bp_loc.SetEnabled(False);
+	        # print " disabled [", str(bp.GetThreadID()), ":", str(bp.GetID()), "]"
+
+# print_vars - Print variable values in output file.
+def print_vars (tag, vars, fname, line, file, frame, target, thread):
+
+    bid = 0
+    tid = 0
+    count = thread.GetStopReasonDataCount()
+    # print "count = ",count
+    for i in range(count):
+        # print "i =", i
+        id = thread.GetStopReasonDataAtIndex(i)
+        bp = target.FindBreakpointByID(id)
+        if bp.IsValid():
+		bid = bp.GetID()
+		tid = bp.GetThreadID()
+                # print "bp is valid", bid, tid
+		for j in range(vars.GetSize()):
+			v = vars.GetValueAtIndex(j)
+			if v.GetName() is not None:
+				file.write(tag)
+				file.write(fname)
+				file.write(':')
+				file.write(str(line))
+				file.write(' ')
+				file.write(str(tid))
+				file.write(':')
+				file.write(str(bid))
+				file.write(' ')
+				file.write(v.GetName())
+				file.write(' ')
+				AlreadyPrintedValues.clear()
+				print_var_value (v, file, frame)
+				file.write('\n')
+
+# set_breakpoints_old - set breakpoints as listed in input file.
+def set_breakpoints_old (target, breakpoint_filename, file):
+    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]))
+        file.write("#Breakpoint ")
+        file.write(str(c[0]))
+        file.write(':')
+        file.write(str(c[1]))
+        file.write(' ')
+        file.write(str(bp.GetThreadID()))
+        file.write(':')
+        file.write(str(bp.GetID()))
+        file.write('\n')
+    f.close()
+
+# stopeed_at_breakpoint - Return True if process is stopeed at a
+# set_breakpoints - set breakpoints as listed in input file.
+def set_breakpoints (target, breakpoint_filename, file):
+    f = open(breakpoint_filename, "r")
+    lines = f.readlines()
+    for l in range(len(lines)):
+	l2 = len(lines[l])
+	l3 = l2 - 1
+        # print "setting break point - ", lines[l][0:l3]
+        bp = target.BreakpointCreateByName (str(lines[l][0:l3]))
+        # print "setting break point - ", lines[l][0:l3],
+	# print " [", str(bp.GetThreadID()), ":", str(bp.GetID()), "]"
+        file.write("#Breakpoint ")
+        file.write(str(1))
+        file.write(':')
+        file.write(str(2))
+        file.write(' ')
+        file.write(str(bp.GetThreadID()))
+        file.write(':')
+        file.write(str(bp.GetID()))
+        file.write(' ')
+        file.write(str(lines[l][0:l3]))
+        file.write('\n')
+    f.close()
+
+# stopeed_at_breakpoint - Return True if process is stopeed at a
+# breakpoint.
+def stopped_at_breakpoint (process):
+    # print "stopped"
+    if process.IsValid():
+        # print "stopped process"
+        state = process.GetState()
+        # print "stopped process", state
+        if state == lldb.eStateStopped:
+                # print "stopped process state is stopped"
+                thread = process.GetThreadAtIndex(0)
+                if thread.IsValid():
+                        # print "thread is valid"
+                        if thread.GetStopReason() == lldb.eStopReasonBreakpoint:
+                        	# print "thread stopped at breakpoint"
+                                return True
+    return False
+
+# 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"
+    file=open(str(sys.argv[3]), 'w')    
+    set_breakpoints (target, sys.argv[2], file)
+
+    # Launch the process. Since we specified synchronous mode, we won't return
+    # from this function until we hit the breakpoint at main
+    sberror = lldb.SBError()
+    process = target.Launch (None, None, os.ctermid(), os.ctermid(), os.ctermid(), None, 0, False, sberror)
+    # Make sure the launch went ok
+    while stopped_at_breakpoint(process):
+        # print "stopped at a bp"
+        thread = process.GetThreadAtIndex (0)
+	# print "num of frames ", thread.GetNumFrames()
+        frame = thread.GetFrameAtIndex (0)
+        if not frame.IsValid():
+		for fi in range(thread.GetNumFrames()):
+			# print "checking frame no : ", fi
+			frame = thread.GetFrameAtIndex(fi)
+			if frame.IsValid():
+				fi = thread.GetNumFrames()
+        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
+                line = frame.GetLineEntry().GetLine()
+                vars = frame.GetVariables(1,0,0,0)
+                print_vars ("#Argument ", vars, fname, line, file, frame, target, thread)
+                # vars = frame.GetVariables(0,1,0,0)
+                # print_vars ("#Variables ", vars, fname, line, file, frame, target, thread)
+	disable_bp(thread)
+        process.Continue()
+    file.close()
+
+lldb.SBDebugger.Terminate()

Propchange: test-suite/trunk/CollectDebugInfoUsingLLDB.py
------------------------------------------------------------------------------
    svn:executable = *

Added: test-suite/trunk/CompareDebugInfo.py
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/CompareDebugInfo.py?rev=128423&view=auto
==============================================================================
--- test-suite/trunk/CompareDebugInfo.py (added)
+++ test-suite/trunk/CompareDebugInfo.py Mon Mar 28 15:25:47 2011
@@ -0,0 +1,193 @@
+#!/usr/bin/python
+
+import os
+import sys
+
+DBG_OUTPUT_FILE="Output/" + sys.argv[1] + ".dbg.out"
+OPT_DBG_OUTPUT_FILE="Output/" + sys.argv[1] + ".dbg.opt.out"
+LOG_FILE="Output/" + sys.argv[1] + ".log"
+NATIVE_DBG_OUTPUT_FILE="Output/" + sys.argv[1] + ".native.dbg.out"
+NATIVE_OPT_DBG_OUTPUT_FILE="Output/" + sys.argv[1] + ".native.dbg.opt.out"
+NATIVE_LOG_FILE="Output/" + sys.argv[1] + ".native.log"
+REPORT_FILE="Output/" + sys.argv[1] + ".dbg.report.txt"
+
+class BreakPoint:
+    def __init__(self, bp_name):
+        self.name = bp_name
+        self.values = {}
+        self.missing_args = []
+        self.matching_args = []
+        self.notmatching_args = []
+        self.missing_bp = False
+
+    def setMissing(self):
+        self.missing_bp = True
+
+    def getArgCount(self):
+        return len(self.values)
+
+    def getMissingArgCount(self):
+        if self.missing_bp == True:
+            return len(self.values)
+        return len(self.missing_args)
+
+    def getMatchingArgCount(self):
+        if self.missing_bp == True:
+            return 0
+        return len(self.matching_args)
+
+    def getNotMatchingArgCount(self):
+        if self.missing_bp == True:
+            return 0
+        return len(self.notmatching_args)
+
+    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 compare_args(self, other, file):
+        myitems = self.values.items()
+        otheritems = other.values.items()
+        match = False
+        for i in range(len(myitems)):
+            if i >= len(otheritems):
+                match = True
+                self.missing_args.append(myitems[i][0])
+            elif cmp(myitems[i][1], otheritems[i][1]):
+                match = True
+                self.notmatching_args.append(myitems[i][0])
+            else:
+                self.matching_args.append(myitems[i][0])
+
+        self.print_list(self.matching_args, " Matching arguments ", file)
+        self.print_list(self.notmatching_args, " Not Matching arguments ", file)
+        self.print_list(self.missing_args, " Missing arguments ", file)
+        return match
+
+    def print_list(self, items, txt, pfile):
+        if len(items) == 0:
+            return
+        pfile.write(self.name)
+        pfile.write(txt)
+        for e in items:
+            pfile.write(e)
+            pfile.write(' ')
+        pfile.write('\n')
+
+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] == "#Breakpoint":
+            bp = dict.get(c[2])
+            if bp is None:
+                bp = BreakPoint(c[1])
+            dict[c[2]] = bp
+        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])
+    return
+
+f1_breakpoints = {}
+read_input(DBG_OUTPUT_FILE, f1_breakpoints)
+f1_items = f1_breakpoints.items()
+
+f2_breakpoints = {}
+read_input(OPT_DBG_OUTPUT_FILE, f2_breakpoints)
+f2_items = f2_breakpoints.items()
+    
+f = open(LOG_FILE, "w")
+f.write("Log output\n")
+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:
+        bp.setMissing()
+    else:
+        bp1.compare_args(bp,f)
+f.close()
+
+nf1_breakpoints = {}
+read_input(NATIVE_DBG_OUTPUT_FILE, nf1_breakpoints)
+nf1_items = nf1_breakpoints.items()
+
+nf2_breakpoints = {}
+read_input(NATIVE_OPT_DBG_OUTPUT_FILE, nf2_breakpoints)
+nf2_items = nf2_breakpoints.items()
+    
+nfl = open(NATIVE_LOG_FILE, "w")
+for nf2bp in range(len(nf2_items)):
+    id = nf2_items[nf2bp][0]
+    bp = nf2_items[nf2bp][1]
+    bp1 = nf1_breakpoints.get(id)
+    if bp1 is None:
+        bp.setMissing()
+    else:
+        bp1.compare_args(bp,nfl)
+nfl.close()
+
+f1_arg_count = 0
+f1_matching_arg_count = 0
+f1_notmatching_arg_count = 0
+f1_missing_arg_count = 0
+for idx in range(len(f1_items)):
+    bp = f1_items[idx][1]
+    f1_arg_count = f1_arg_count + bp.getArgCount()
+    f1_matching_arg_count = f1_matching_arg_count + bp.getMatchingArgCount()
+    f1_notmatching_arg_count = f1_notmatching_arg_count + bp.getNotMatchingArgCount()
+    f1_missing_arg_count = f1_missing_arg_count + bp.getMissingArgCount()
+
+nf1_arg_count = 0
+nf1_matching_arg_count = 0
+nf1_notmatching_arg_count = 0
+nf1_missing_arg_count = 0
+for idx in range(len(nf1_items)):
+    bp = nf1_items[idx][1]
+    nf1_arg_count = nf1_arg_count + bp.getArgCount()
+    nf1_matching_arg_count = nf1_matching_arg_count + bp.getMatchingArgCount()
+    nf1_notmatching_arg_count = nf1_notmatching_arg_count + bp.getNotMatchingArgCount()
+    nf1_missing_arg_count = nf1_missing_arg_count + bp.getMissingArgCount()
+
+rf = open(REPORT_FILE, "w")
+rf.write("---------------------------------------------------------------\n");
+rf.write(">>> ========= '")
+rf.write(sys.argv[1])
+rf.write("'")
+rf.write(" Program\n")
+rf.write("---------------------------------------------------------------\n\n");
+rf.write("GCC Total Arguments: ") 
+rf.write(str(nf1_arg_count))
+rf.write("\n")
+rf.write("GCC Matching Arguments: ") 
+rf.write(str(nf1_matching_arg_count))
+rf.write("\n")
+rf.write("GCC Not Matching Arguments: ") 
+rf.write(str(nf1_notmatching_arg_count))
+rf.write("\n")
+rf.write("GCC Missing Arguments: ") 
+rf.write(str(nf1_missing_arg_count))
+rf.write("\n")
+rf.write("LLVM Total Arguments: ") 
+rf.write(str(f1_arg_count))
+rf.write("\n")
+rf.write("LLVM Matching Arguments: ") 
+rf.write(str(f1_matching_arg_count))
+rf.write("\n")
+rf.write("LLVM Not Matching Arguments: ") 
+rf.write(str(f1_notmatching_arg_count))
+rf.write("\n")
+rf.write("LLVM Missing Arguments: ") 
+rf.write(str(f1_missing_arg_count))
+rf.write("\n")
+rf.close()

Propchange: test-suite/trunk/CompareDebugInfo.py
------------------------------------------------------------------------------
    svn:executable = *

Modified: test-suite/trunk/Makefile.programs
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/Makefile.programs?rev=128423&r1=128422&r2=128423&view=diff
==============================================================================
--- test-suite/trunk/Makefile.programs (original)
+++ test-suite/trunk/Makefile.programs Mon Mar 28 15:25:47 2011
@@ -995,30 +995,6 @@
 
 report.dbgopt: report.dbgopt.header report.$(TEST).txtonly
 
-report.dbg.html: $(REPORT_DEPENDENCIES) $(TestMakefile)
-	$(MAKE) $(FORCE_SERIAL_ARG) TEST=$(TEST)
-	@echo "<h1> Quality of debug info in optimized builds at -O3</h1>" > $@
-	@echo "<table border=\"0\">" >> $@
-	@echo "<tr><td></td><td>|</td>" >> $@
-	@echo "<td><b>GCC</b></td><td></td><td></td><td></td>" >> $@
-	@echo "<td>|</td>" >> $@
-	@echo "<td><b>LLVM</b></td><td></td><td></td><td></td>" >> $@
-	@echo "</tr>" >> $@
-	@echo "<tr>"  >> $@
-	@echo "<td>Name</td><td>|</td>" >> $@
-	@echo "<td>Total<br>Arguments</td>" >> $@
-	@echo "<td>Valid<br>Arguments</td>" >> $@
-	@echo "<td>Missing<br>Arguments</td>" >> $@
-	@echo "<td>Invalid<br>Arguments</td>" >> $@
-	@echo "<td>|</td>" >> $@
-	@echo "<td>Total<br>Arguments</td>" >> $@
-	@echo "<td>Valid<br>Arguments</td>" >> $@
-	@echo "<td>Missing<br>Arguments</td>" >> $@
-	@echo "<td>Invalid<br>Arguments</td>" >> $@
-	@echo "</tr>" >> $@
-	find . -name \*.$(TEST).report.html -exec cat {} \; >> $@
-	@echo "</table>" >> $@
-
 endif
 
 clean::

Modified: test-suite/trunk/TEST.dbg.Makefile
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/TEST.dbg.Makefile?rev=128423&r1=128422&r2=128423&view=diff
==============================================================================
--- test-suite/trunk/TEST.dbg.Makefile (original)
+++ test-suite/trunk/TEST.dbg.Makefile Mon Mar 28 15:25:47 2011
@@ -15,6 +15,7 @@
 CURDIR  := $(shell cd .; pwd)
 PROGDIR := $(PROJ_SRC_ROOT)
 RELDIR  := $(subst $(PROGDIR),,$(CURDIR))
+COLLECTOR := $(PROJ_SRC_ROOT)/CollectDebugInfoUsingLLDB.py 
 
 REPORTS_TO_GEN := dbg
 REPORTS_SUFFIX := $(addsuffix .report.txt, $(REPORTS_TO_GEN))
@@ -56,11 +57,20 @@
 	if test "$*" == "exptree"; then \
 	  is_skip=1; \
 	fi; \
+	if test "$*" == "ray"; then \
+	  is_skip=1; \
+	fi; \
+	if test "$*" == "oscar"; then \
+	  is_skip=1; \
+	fi; \
+	if test "$*" == "spirit"; then \
+	  is_skip=1; \
+	fi; \
 	if test $$is_skip == 0; then \
-	  $(LLVM_SRC_ROOT)/utils/CollectDebugInfoUsingLLDB.py Output/$*.dbg Output/$*.bp Output/$*.dbg.out; \
-	  $(LLVM_SRC_ROOT)/utils/CollectDebugInfoUsingLLDB.py Output/$*.dbg.opt Output/$*.bp Output/$*.dbg.opt.out; \
-	  $(LLVM_SRC_ROOT)/utils/CollectDebugInfoUsingLLDB.py Output/$*.native.dbg Output/$*.bp Output/$*.native.dbg.out; \
-	  $(LLVM_SRC_ROOT)/utils/CollectDebugInfoUsingLLDB.py Output/$*.native.dbg.opt Output/$*.bp Output/$*.native.dbg.opt.out; \
-	  $(LLVM_SRC_ROOT)/utils/CompareDebugInfo.py $*; \
+	  $(COLLECTOR) Output/$*.dbg Output/$*.bp Output/$*.dbg.out; \
+	  $(COLLECTOR) Output/$*.dbg.opt Output/$*.bp Output/$*.dbg.opt.out; \
+	  $(COLLECTOR) Output/$*.native.dbg Output/$*.bp Output/$*.native.dbg.out; \
+	  $(COLLECTOR) Output/$*.native.dbg.opt Output/$*.bp Output/$*.native.dbg.opt.out; \
+	  $(PROJ_SRC_ROOT)/CompareDebugInfo.py $*; \
 	fi
 





More information about the llvm-commits mailing list