diff --git a/tools/coredumper/sof-coredump-reader.py b/tools/coredumper/sof-coredump-reader.py old mode 100644 new mode 100755 index a6be20646d57..68d804719842 --- a/tools/coredumper/sof-coredump-reader.py +++ b/tools/coredumper/sof-coredump-reader.py @@ -11,7 +11,6 @@ import itertools import re import shutil -import fcntl import time from ctypes import LittleEndianStructure, BigEndianStructure, c_uint32, c_char from collections import namedtuple @@ -21,6 +20,9 @@ def stderr_print(*args, **kwargs): print(*args, file=sys.stderr, **kwargs) +def stdout_print(*args, **kwargs): + print(*args, file=sys.stdout, **kwargs) + try: from sty import fg, bg, ef, rs, Rule, Render CAN_COLOUR=True @@ -179,12 +181,10 @@ def parse_params(): },), ( ( '-l', '--columncount', ), { 'type' : int, - 'help' :'set how many colums to group the output in', + 'help' :'set how many colums to group the output in, ignored without -v', 'action':'store', 'nargs' : 1, },), - # below makes it impossible to have input file while getting stdin from pipe - ] + ([] if not sys.stdin.isatty() else [ ( ( '-i', '--infile' , ), { 'type' : str, 'help' :'path to sys dump bin', @@ -192,14 +192,15 @@ def parse_params(): 'nargs' : 1, }, inputMethod), - ])], + ]], key=lambda argtup: (argtup.parent.__hash__(), argtup.name) ) ] parsed = parser.parse_args() - if not sys.stdin.isatty(): - parsed.stdin = True + + if parsed.columncount and not parsed.verbose: + stderr_print("INFO: -l option will be ignored without -v") return parsed @@ -242,7 +243,7 @@ class Colourer(): #TODO: Add detection of 8bit/24bit terminal # Add 8bit/24bit colours (with flag, maybe --colour=24bit) # Use this below as fallback only - __print = partial(stderr_print) + __print = partial(stdout_print) if CAN_COLOUR == True: __style = { 'o' : fg.red, @@ -273,12 +274,6 @@ def __init__(self): r'\1' + r'\2' + self.enstyle( fg.green , r'\3') , - re.compile(r'(\|)(ar)([0-9]+)\b') - ), - ( - self.enstyle(bg.green + fg.black , r'\1') + - r'\2' + - self.enstyle( fg.green , r'\3') , re.compile(r'(\#)(ar)([0-9]+)\b') ), ( @@ -511,6 +506,15 @@ def to_string(self, is_gdb): [chunks(word, self.columncount) for word in [ ["arch", "totalsize", "stackoffset"], ["configidhi", "configidlo", "numaregs"], + ]] + ) + ]) + + string += "\n# CPU registers:\n\n" + + string += ''.join([self.fmt(is_gdb, x) + for x in flaten( + [chunks(word, self.columncount) for word in [ ["exccause", "excvaddr", "ps"], ["epc" + str(x) for x in range(1,7+1)], ["eps" + str(x) for x in range(2,7+1)], @@ -526,6 +530,7 @@ def to_string(self, is_gdb): ]] ) ]) + if not is_gdb: string += "\n" return string @@ -537,10 +542,7 @@ def fmt_pretty_form(self, separator = "|"): return separator + "{:" + str(self._longest_field) + "} {:08x} " def fmt_separator(self, name): - separator = "|" - if self.ar_regex.fullmatch(name): - if int(name[2:]) % AR_WINDOW_WIDTH == 0: - separator = "#" + separator = "# " return separator def fmt_pretty_auto(self, name): @@ -572,8 +574,8 @@ def windowstart_process(self): fnc_num += 1 else: header += " " - string += " {0}\n".format(header) - string += "windowstart: {0}\n".format(binary) + string += "# {0}\n".format(header) + string += "# windowstart: {0}\n".format(binary) fnc_num = 0 for iter, digit in enumerate(binary[1:]): @@ -581,7 +583,7 @@ def windowstart_process(self): reg = "ar{0}".format( self.windowbase_shift_right(AR_WINDOW_WIDTH * -iter) ) - string += "{0:2d} ".format(++fnc_num) + string += "# {0:2d} ".format(++fnc_num) string += self.fmt_pretty_auto(reg).format( reg, self.reg_from_string(reg) ) + "\n" @@ -608,7 +610,7 @@ def __init__(self, args): verbosePrint =\ colourer.print\ if IS_COLOUR else\ - stderr_print + stdout_print else: verbosePrint = lambda *discard_this: None @@ -625,7 +627,7 @@ def __init__(self, args): else: raise RuntimeError("CoreDumpReader: No output method.") - if args.stdin or not sys.stdin.isatty(): + if args.stdin: inStream = lambda: sys.stdin.buffer elif args.infile: inStream = lambda: open(args.infile, "rb") @@ -639,14 +641,15 @@ def __init__(self, args): ]] self.stack = cd_file.read() + verbosePrint("# Core header:\n") verbosePrint(self.core_dump.to_string(0)) verbosePrint(self.core_dump.windowstart_process()) - verbosePrint("Location: " + str(self.file_info)); + verbosePrint("# Location: " + str(self.file_info)); stack_base = self.core_dump.a[1] + 16 stack_dw_num = int(len(self.stack)/AR_WINDOW_WIDTH) - verbosePrint("Stack dumped from {:08x} dwords num {:d}" + verbosePrint("# Stack dumped from {:08x} dwords num {:d}" .format(stack_base, stack_dw_num)) stdoutOpen() @@ -663,8 +666,6 @@ def __init__(self, args): # TODO: if excsave1 is not empty, pc should be set to that value # (exception mode, not forced panic mode) - # dodac sobie przyklad - # ustawiac pc z stdoutPrint("set $pc=&arch_dump_regs_a\nbacktrace\n") stdoutClose() @@ -674,6 +675,6 @@ def __init__(self, args): if CAN_COLOUR: IS_COLOUR=True else: - stderr_print("Cannot color the output: module 'sty' not found!") + stderr_print("INFO: Cannot color the output: module 'sty' not found") CoreDumpReader(args)