This is an automated email from the ASF dual-hosted git repository. btashton pushed a commit to branch py-style in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit 0b2d2e7b1e4e1f67a95a92634f3deda325ee1c15 Author: Brennan Ashton <[email protected]> AuthorDate: Sun Apr 4 17:06:30 2021 -0700 lint tools/parsecallstack.py --- tools/parsecallstack.py | 45 ++++++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/tools/parsecallstack.py b/tools/parsecallstack.py index bbddce0..821e215 100755 --- a/tools/parsecallstack.py +++ b/tools/parsecallstack.py @@ -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)
