Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 29 additions & 28 deletions tools/coredumper/sof-coredump-reader.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -179,27 +181,26 @@ 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',
'action' : argparse_readable_file,
'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

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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')
),
(
Expand Down Expand Up @@ -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)],
Expand All @@ -526,6 +530,7 @@ def to_string(self, is_gdb):
]]
)
])

if not is_gdb:
string += "\n"
return string
Expand All @@ -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):
Expand Down Expand Up @@ -572,16 +574,16 @@ 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:]):
if (digit == '1'):
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"
Expand All @@ -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

Expand All @@ -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")
Expand All @@ -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()
Expand All @@ -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()

Expand All @@ -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)