diff options
author | Devang Patel <dpatel@apple.com> | 2010-12-07 21:12:05 +0000 |
---|---|---|
committer | Devang Patel <dpatel@apple.com> | 2010-12-07 21:12:05 +0000 |
commit | f57c2d3a3fa70af1325604e6edfa001f10a9d740 (patch) | |
tree | 4a371c70e6ff18ca3bc920d0fd6807d1add18664 /utils | |
parent | bdf714450b70509538aa5a8a676034418ce827b6 (diff) |
Handle recursive values. Add comments.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@121184 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils')
-rwxr-xr-x | utils/CollectDebugInfoUsingLLDB.py | 76 |
1 files changed, 53 insertions, 23 deletions
diff --git a/utils/CollectDebugInfoUsingLLDB.py b/utils/CollectDebugInfoUsingLLDB.py index 6d676937ef..b82a7c172e 100755 --- a/utils/CollectDebugInfoUsingLLDB.py +++ b/utils/CollectDebugInfoUsingLLDB.py @@ -1,11 +1,24 @@ #!/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 @@ -13,26 +26,46 @@ 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.GetNumChildren() > 0: - for c in range(v.GetNumChildren()): - if v.GetChildAtIndex(c) is None: + 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 (v.GetChildAtIndex(c).GetName()) is None: + else: + if (child.GetName()) is None: file.write("None") else: - file.write(v.GetChildAtIndex(c).GetName()) + file.write(child.GetName()) file.write('=') - print_var_value(v.GetChildAtIndex(c), file, frame) + 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)) - +# print_vars - Print variable values in output file. def print_vars (vars, fname, line, file, frame, target, thread): # disable this thread. count = thread.GetStopReasonDataCount() @@ -51,7 +84,6 @@ def print_vars (vars, fname, line, file, frame, target, thread): 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()): @@ -67,9 +99,11 @@ def print_vars (vars, fname, line, file, frame, target, thread): v = vars.GetValueAtIndex(i) file.write(v.GetName()) file.write(' ') + AlreadyPrintedValues.clear() print_var_value (v, file, frame) file.write('\n') +# set_breakpoints - set breakpoints as listed in input file. def set_breakpoints (target, breakpoint_filename): f = open(breakpoint_filename, "r") lines = f.readlines() @@ -79,21 +113,17 @@ def set_breakpoints (target, breakpoint_filename): bp = target.BreakpointCreateByLocation (str(c[0]), int(c[1])) f.close() -def stop_at_breakpoint (process): +# stopeed_at_breakpoint - Return True if process is stopeed at a +# breakpoint. +def stopped_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 + if state == lldb.eStateStopped: + thread = process.GetThreadAtIndex(0) + if thread.IsValid(): + if thread.GetStopReason() == lldb.eStopReasonBreakpoint: + return True + return False # Create a new debugger instance debugger = lldb.SBDebugger.Create() @@ -120,7 +150,7 @@ if target.IsValid(): 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: + while stopped_at_breakpoint(process): thread = process.GetThreadAtIndex (0) frame = thread.GetFrameAtIndex (0) if frame.IsValid(): |