Skip to content

Commit 5f952da

Browse files
niklas88Alexander Gordeev
authored andcommitted
s390/debug: Add debug_dump() to write debug view to a string buffer
The debug_dump() function allows to get the content of a debug log and view pair in a string buffer. One future application of this is to provide debug logs to the platform to be collected with hardware error logs during recovery. Reviewed-by: Halil Pasic <pasic@linux.ibm.com> Co-developed-by: Halil Pasic <pasic@linux.ibm.com> Signed-off-by: Halil Pasic <pasic@linux.ibm.com> Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com> Signed-off-by: Alexander Gordeev <agordeev@linux.ibm.com>
1 parent 460c52a commit 5f952da

2 files changed

Lines changed: 50 additions & 0 deletions

File tree

arch/s390/include/asm/debug.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ debug_info_t *debug_register_mode(const char *name, int pages, int nr_areas,
114114
int buf_size, umode_t mode, uid_t uid,
115115
gid_t gid);
116116

117+
ssize_t debug_dump(debug_info_t *id, struct debug_view *view,
118+
char *buf, size_t buf_size);
119+
117120
void debug_unregister(debug_info_t *id);
118121

119122
void debug_set_level(debug_info_t *id, int new_level);

arch/s390/kernel/debug.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,53 @@ static int debug_close(struct inode *inode, struct file *file)
632632
return 0; /* success */
633633
}
634634

635+
/**
636+
* debug_dump - Get a textual representation of debug info, or as much as fits
637+
* @id: Debug information to use
638+
* @view: View with which to dump the debug information
639+
* @buf: Buffer the textual debug data representation is written to
640+
* @buf_size: Size of the buffer, including the trailing '\0' byte
641+
*
642+
* This function may be used whenever a textual representation of the debug
643+
* information is required without using an s390dbf file.
644+
*
645+
* Note: It is the callers responsibility to supply a view that is compatible
646+
* with the debug information data.
647+
*
648+
* Return: On success returns the number of bytes written to the buffer not
649+
* including the trailing '\0' byte. If bug_size == 0 the function returns 0.
650+
* On failure an error code less than 0 is returned.
651+
*/
652+
ssize_t debug_dump(debug_info_t *id, struct debug_view *view,
653+
char *buf, size_t buf_size)
654+
{
655+
file_private_info_t *p_info;
656+
size_t size, offset = 0;
657+
658+
/* Need space for '\0' byte */
659+
if (buf_size < 1)
660+
return 0;
661+
buf_size--;
662+
663+
p_info = debug_file_private_alloc(id, view);
664+
if (!p_info)
665+
return -ENOMEM;
666+
667+
/* There is always at least the DEBUG_PROLOG_ENTRY */
668+
do {
669+
size = debug_format_entry(p_info);
670+
size = min(size, buf_size - offset);
671+
memcpy(buf + offset, p_info->temp_buf, size);
672+
offset += size;
673+
if (offset >= buf_size)
674+
break;
675+
} while (debug_next_entry(p_info));
676+
debug_file_private_free(p_info);
677+
buf[offset] = '\0';
678+
679+
return offset;
680+
}
681+
635682
/* Create debugfs entries and add to internal list. */
636683
static void _debug_register(debug_info_t *id)
637684
{

0 commit comments

Comments
 (0)