Skip to content
Merged
Changes from 1 commit
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
28 changes: 26 additions & 2 deletions tools/debug_stream/debug_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class DebugStreamRecord(ctypes.Structure):
("size_words", ctypes.c_uint),
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo in commit: sd_msg->ds_msg

]


class CPUInfo(ctypes.Structure):
"""
Thread Info record header
Expand All @@ -73,6 +72,17 @@ class ThreadInfo(ctypes.Structure):
]


class TextMsg(ctypes.Structure):
"""
Text Msg record header
"""

_pack_ = 1
_fields_ = [
("hdr", DebugStreamRecord),
]


WSIZE = ctypes.sizeof(ctypes.c_uint)


Expand All @@ -83,6 +93,7 @@ class RecordPrinter:

RECORD_ID_UNINITIALIZED = 0
RECORD_ID_THREAD_INFO = 1
RECORD_ID_TEXT_MSG = 2

def print_record(self, record, cpu):
"""prints debug-stream record"""
Expand All @@ -92,7 +103,9 @@ def print_record(self, record, cpu):
)
if recp.contents.id == self.RECORD_ID_THREAD_INFO:
return self.print_thread_info(record, cpu)
logging.warning("cpu %u: Unsupported recodrd type %u", cpu, recp.contents.id)
if recp.contents.id == self.RECORD_ID_TEXT_MSG:
return self.print_text_msg(record, cpu)
logging.warning("cpu %u: Unsupported record type %u", cpu, recp.contents.id)
return True

def print_thread_info(self, record, cpu):
Expand Down Expand Up @@ -141,6 +154,17 @@ def print_thread_info(self, record, cpu):
)
return True

def print_text_msg(self, record, cpu):
"""prints text-msg record"""
if len(record) - ctypes.sizeof(TextMsg) < 0:
logging.info("Buffer end reached, parsing failed")
return False
buffer = (
ctypes.c_ubyte * (len(record) - ctypes.sizeof(TextMsg))
).from_address(ctypes.addressof(record) + ctypes.sizeof(TextMsg))
msg = bytearray(buffer).decode("utf-8")
print("CPU %u: %s" % (cpu, msg))
return True

class DebugStreamSectionDescriptor(ctypes.Structure):
"""
Expand Down