lint tools/parsecallstack.py

This commit is contained in:
Brennan Ashton 2021-04-04 17:06:30 -07:00 committed by Xiang Xiao
parent 38cb837838
commit 6b4e7d0fe7

View file

@ -20,9 +20,11 @@
import os
import argparse
def parse_args():
parser = argparse.ArgumentParser("""
parser = argparse.ArgumentParser(
"""
parsecallstack.py -c CPUTYPE -f FILENAME\n\
This file can get the call stack when you get the log with the
register values from R0 to R15, together with the stack dump.\n
@ -30,24 +32,34 @@ def parse_args():
in Trace32, load the symbol according to the indication, the call
stack will pop up.\n
Trace32 software is available at: https://www.lauterbach.com
""")
"""
)
parser.add_argument("-f", "--filename", action = "store",
help = "log file with registers and stack information")
parser.add_argument("-c", "--cputype", action = "store",
help = '''It supports ARM family CPU such as:
parser.add_argument(
"-f",
"--filename",
action="store",
help="log file with registers and stack information",
)
parser.add_argument(
"-c",
"--cputype",
action="store",
help='''It supports ARM family CPU such as:
"CortexM0" "CortexM1" "CortexM3" "CortexM4"
"CortexM7" "CortexM23" "CortexM33" "CortexM35P"
"CortexR5" "CortexR7" "CortexA5" "CortexA7"''')
"CortexR5" "CortexR7" "CortexA5" "CortexA7"''',
)
return parser.parse_args()
def get_regs(filename):
reglist = []
with open(filename, mode='r') as fl:
with open(filename, mode="r") as fl:
for line in fl:
lst = line.strip('\n').split(' ')
lst = line.strip("\n").split(" ")
if "R0:" in lst:
reglist = lst[-8:]
if "R8:" in lst:
@ -55,28 +67,30 @@ def get_regs(filename):
return reglist
def get_stackvalue(filename):
stackvalue = []
first = 1
with open(filename, mode='r') as fl:
with open(filename, mode="r") as fl:
for line in fl:
lst = line.strip('\n').split(' ')
lst = line.strip("\n").split(" ")
if "up_stackdump:" in lst:
if first == 1:
first += 1
# strip ":" of sp
sp = lst[-9].strip(':')
sp = lst[-9].strip(":")
# The first item is the sp to restore the stack.
stackvalue.append(sp)
stackvalue += lst[-8:]
return stackvalue
def generate_cmm(cpu, regs, stackvalue):
filename = os.path.join(os.getcwd(), 'callstack.cmm')
with open(filename, mode='w') as fl:
filename = os.path.join(os.getcwd(), "callstack.cmm")
with open(filename, mode="w") as fl:
# Select the CPU and symbol.
fl.write("SYStem.CPU %d\n" % cpu)
fl.write("SYS.M UP\n")
@ -100,6 +114,7 @@ def generate_cmm(cpu, regs, stackvalue):
fl.write("data.view %%sYmbol.long %x\n" % sp)
fl.write("frame.view /Locals /Caller\n")
if __name__ == "__main__":
args = parse_args()
regs = get_regs(args.filename)