Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions src/debug/debug_stream/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
add_local_sources_ifdef(CONFIG_SOF_DEBUG_STREAM_SLOT sof debug_stream_slot.c)

add_local_sources_ifdef(CONFIG_SOF_DEBUG_STREAM_THREAD_INFO sof debug_stream_thread_info.c)

add_local_sources_ifdef(CONFIG_SOF_DEBUG_STREAM_TEXT_MSG sof debug_stream_text_msg.c)
9 changes: 9 additions & 0 deletions src/debug/debug_stream/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,13 @@ config SOF_DEBUG_STREAM_THREAD_INFO_INTERVAL
Decides how often thread info runs and checks execution cycle
statistics and stack usage.

config SOF_DEBUG_STREAM_TEXT_MSG
bool "Enable text message sending through Debug-Stream"
help
Enable debug message sending over debug stream. To use this
feature one only needs to enable debug stream with this
config option and print the debug messages with
ds_msg(). See include/user/debug_stream_text_msg.h for
prototype.

endif
37 changes: 37 additions & 0 deletions src/debug/debug_stream/debug_stream_text_msg.c
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 };
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.

Interesting, how does Python parse C structures - it probably assumes "normal" (default) packing, i.e. as if no __packed attribute was specified. Can you tell Python that the structure is packed?

Copy link
Copy Markdown
Contributor Author

@jsarha jsarha Dec 1, 2025

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.

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));
Comment thread
lgirdwood marked this conversation as 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);

1 change: 1 addition & 0 deletions src/include/user/debug_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,6 @@ struct debug_stream_record {
/* Debug Stream record identifiers */
#define DEBUG_STREAM_RECORD_ID_UNINITIALIZED 0 /* invalid record marker */
#define DEBUG_STREAM_RECORD_ID_THREAD_INFO 1 /* Thread info record */
#define DEBUG_STREAM_RECORD_ID_TEXT_MSG 2 /* Text message */

#endif /* __SOC_DEBUG_STREAM_H__ */
25 changes: 25 additions & 0 deletions src/include/user/debug_stream_text_msg.h
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__ */