-
Notifications
You must be signed in to change notification settings - Fork 349
Debug stream text msg #10396
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Debug stream text msg #10396
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
06f5dc8
debug_stream: Add text message record type and a ds_msg() to send them
ca3e994
tools: debug_stream.py: Add support for text messages
537b5bd
app: Enable debug messages in debug_stream_overlay.conf
cc1a054
debug_stream: Kconfig: Improve help message
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| // SPDX-License-Identifier: BSD-3-Clause | ||
| // | ||
| // Copyright(c) 2024 Intel Corporation. | ||
|
|
||
| #include <sys/types.h> | ||
| #include <stdarg.h> | ||
| #include <stdio.h> | ||
| #include <soc.h> | ||
| #include <adsp_debug_window.h> | ||
| #include <sof/common.h> | ||
|
|
||
| #include <user/debug_stream_text_msg.h> | ||
|
|
||
| void ds_msg(const char *format, ...) | ||
| { | ||
| va_list args; | ||
| struct { | ||
| struct debug_stream_text_msg msg; | ||
| char text[128]; | ||
| } __packed buf = { 0 }; | ||
| ssize_t len; | ||
|
|
||
| va_start(args, format); | ||
| len = vsnprintf(buf.text, sizeof(buf.text), format, args); | ||
| va_end(args); | ||
|
|
||
| if (len < 0) | ||
| return; | ||
| len = MIN(len, sizeof(buf.text)); | ||
lgirdwood marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| buf.msg.hdr.id = DEBUG_STREAM_RECORD_ID_TEXT_MSG; | ||
| buf.msg.hdr.size_words = SOF_DIV_ROUND_UP(sizeof(buf.msg) + len, | ||
| sizeof(buf.msg.hdr.data[0])); | ||
| debug_stream_slot_send_record(&buf.msg.hdr); | ||
| } | ||
| EXPORT_SYMBOL(ds_msg); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| /* SPDX-License-Identifier: BSD-3-Clause | ||
| * | ||
| * Copyright(c) 2024 Intel Corporation. | ||
| */ | ||
|
|
||
| #ifndef __SOC_DEBUG_STREAM_TEXT_MSG_H__ | ||
| #define __SOC_DEBUG_STREAM_TEXT_MSG_H__ | ||
|
|
||
| #include <user/debug_stream_slot.h> | ||
|
|
||
| /* | ||
| * Debug Stream text message. | ||
| */ | ||
| struct debug_stream_text_msg { | ||
| struct debug_stream_record hdr; | ||
| char msg[]; | ||
| } __packed; | ||
|
|
||
| /* | ||
| * To send debug messages over debug stream. Enable | ||
| * CONFIG_SOF_DEBUG_STREAM_TEXT_MSG to enable this function. | ||
| */ | ||
| void ds_msg(const char *format, ...); | ||
|
|
||
| #endif /* __SOC_DEBUG_STREAM_TEXT_MSG_H__ */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,7 +46,6 @@ class DebugStreamRecord(ctypes.Structure): | |
| ("size_words", ctypes.c_uint), | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
@@ -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) | ||
|
|
||
|
|
||
|
|
@@ -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""" | ||
|
|
@@ -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): | ||
|
|
@@ -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): | ||
| """ | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, how does Python parse C structures - it probably assumes "normal" (default) packing, i.e. as if no
__packedattribute was specified. Can you tell Python that the structure is packed?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes,
"_pack_ = 1"in Class(ctypes.Structure) does it. But in this context it does not really matter as the "struct debug_stream_text_msg" size is 32-bit aligned and what remains after that is all cosidered utf-8 encoded string.