mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-08 19:25:47 +00:00
Handle recursive values. Add comments.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@121184 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -1,11 +1,24 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
#
|
||||||
# Be sure to add the python path that points to the LLDB shared library.
|
# Be sure to add the python path that points to the LLDB shared library.
|
||||||
# On MacOSX csh, tcsh:
|
# On MacOSX csh, tcsh:
|
||||||
# setenv PYTHONPATH /Developer/Library/PrivateFrameworks/LLDB.framework/Resources/Python
|
# setenv PYTHONPATH /Developer/Library/PrivateFrameworks/LLDB.framework/Resources/Python
|
||||||
# On MacOSX sh, bash:
|
# On MacOSX sh, bash:
|
||||||
# export PYTHONPATH=/Developer/Library/PrivateFrameworks/LLDB.framework/Resources/Python
|
# 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 lldb
|
||||||
@@ -13,26 +26,46 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
import time
|
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):
|
def print_var_value (v, file, frame):
|
||||||
if v.GetNumChildren() > 0:
|
if v.IsValid() == False:
|
||||||
for c in range(v.GetNumChildren()):
|
return
|
||||||
if v.GetChildAtIndex(c) is None:
|
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")
|
file.write("None")
|
||||||
else:
|
else:
|
||||||
if (v.GetChildAtIndex(c).GetName()) is None:
|
if (child.GetName()) is None:
|
||||||
file.write("None")
|
file.write("None")
|
||||||
else:
|
else:
|
||||||
file.write(v.GetChildAtIndex(c).GetName())
|
file.write(child.GetName())
|
||||||
file.write('=')
|
file.write('=')
|
||||||
print_var_value(v.GetChildAtIndex(c), file, frame)
|
print_var_value(child, file, frame)
|
||||||
file.write(',')
|
file.write(',')
|
||||||
|
c = c + 1
|
||||||
else:
|
else:
|
||||||
if v.GetValue(frame) is None:
|
if v.GetValue(frame) is None:
|
||||||
file.write("None")
|
file.write("None")
|
||||||
else:
|
else:
|
||||||
file.write(v.GetValue(frame))
|
file.write(v.GetValue(frame))
|
||||||
|
|
||||||
|
# print_vars - Print variable values in output file.
|
||||||
def print_vars (vars, fname, line, file, frame, target, thread):
|
def print_vars (vars, fname, line, file, frame, target, thread):
|
||||||
# disable this thread.
|
# disable this thread.
|
||||||
count = thread.GetStopReasonDataCount()
|
count = thread.GetStopReasonDataCount()
|
||||||
@@ -51,7 +84,6 @@ def print_vars (vars, fname, line, file, frame, target, thread):
|
|||||||
if bp_loc.IsValid():
|
if bp_loc.IsValid():
|
||||||
bid = bp_loc.GetBreakPoint().GetID()
|
bid = bp_loc.GetBreakPoint().GetID()
|
||||||
tid = bp_loc.ThreadGetID()
|
tid = bp_loc.ThreadGetID()
|
||||||
# print " { ", bp_loc.ThreadGetID(), " : ", bp_loc.GetBreakPoint().GetID(), " }} "
|
|
||||||
bp_loc.SetEnabled(False);
|
bp_loc.SetEnabled(False);
|
||||||
|
|
||||||
for i in range(vars.GetSize()):
|
for i in range(vars.GetSize()):
|
||||||
@@ -67,9 +99,11 @@ def print_vars (vars, fname, line, file, frame, target, thread):
|
|||||||
v = vars.GetValueAtIndex(i)
|
v = vars.GetValueAtIndex(i)
|
||||||
file.write(v.GetName())
|
file.write(v.GetName())
|
||||||
file.write(' ')
|
file.write(' ')
|
||||||
|
AlreadyPrintedValues.clear()
|
||||||
print_var_value (v, file, frame)
|
print_var_value (v, file, frame)
|
||||||
file.write('\n')
|
file.write('\n')
|
||||||
|
|
||||||
|
# set_breakpoints - set breakpoints as listed in input file.
|
||||||
def set_breakpoints (target, breakpoint_filename):
|
def set_breakpoints (target, breakpoint_filename):
|
||||||
f = open(breakpoint_filename, "r")
|
f = open(breakpoint_filename, "r")
|
||||||
lines = f.readlines()
|
lines = f.readlines()
|
||||||
@@ -79,21 +113,17 @@ def set_breakpoints (target, breakpoint_filename):
|
|||||||
bp = target.BreakpointCreateByLocation (str(c[0]), int(c[1]))
|
bp = target.BreakpointCreateByLocation (str(c[0]), int(c[1]))
|
||||||
f.close()
|
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():
|
if process.IsValid():
|
||||||
state = process.GetState()
|
state = process.GetState()
|
||||||
if state != lldb.eStateStopped:
|
if state == lldb.eStateStopped:
|
||||||
return lldb.eStateInvalid
|
thread = process.GetThreadAtIndex(0)
|
||||||
thread = process.GetThreadAtIndex(0)
|
if thread.IsValid():
|
||||||
if thread.IsValid():
|
if thread.GetStopReason() == lldb.eStopReasonBreakpoint:
|
||||||
if thread.GetStopReason() == lldb.eStopReasonBreakpoint:
|
return True
|
||||||
return lldb.eStateStopped
|
return False
|
||||||
else:
|
|
||||||
return lldb.eStateInvalid
|
|
||||||
else:
|
|
||||||
return lldb.eStateInvalid
|
|
||||||
else:
|
|
||||||
return lldb.eStateInvalid
|
|
||||||
|
|
||||||
# Create a new debugger instance
|
# Create a new debugger instance
|
||||||
debugger = lldb.SBDebugger.Create()
|
debugger = lldb.SBDebugger.Create()
|
||||||
@@ -120,7 +150,7 @@ if target.IsValid():
|
|||||||
process = target.LaunchProcess ([''], [''], "/dev/stdout", 0, False)
|
process = target.LaunchProcess ([''], [''], "/dev/stdout", 0, False)
|
||||||
file=open(str(sys.argv[3]), 'w')
|
file=open(str(sys.argv[3]), 'w')
|
||||||
# Make sure the launch went ok
|
# Make sure the launch went ok
|
||||||
while stop_at_breakpoint(process) == lldb.eStateStopped:
|
while stopped_at_breakpoint(process):
|
||||||
thread = process.GetThreadAtIndex (0)
|
thread = process.GetThreadAtIndex (0)
|
||||||
frame = thread.GetFrameAtIndex (0)
|
frame = thread.GetFrameAtIndex (0)
|
||||||
if frame.IsValid():
|
if frame.IsValid():
|
||||||
|
Reference in New Issue
Block a user