Hi Lianbo,
It seems we have a problem printing disassembly blocks in the log after this patch (at
least on s390).
See number of empty lines printed below.
Before the patch:
[ 21.408784] Krnl GPRS: 000002aa3780c000 0000000000238c00 0000000015800000
0000000000001000
[ 21.408787] 0000000008e30000 00000000b0001000 0000000000000000
0000000000000a55
[ 21.408790] 0000000004c52300 000002aa3780c000 00000000084281d0
0000038000bfbd28
[ 21.408794] 00000000075e9500 0000000004c52300 0000038000bfbbf0
0000038000bfbb90
[ 21.408860] Krnl Code: 000000000e0acf48: c05fb0001000 llilf %r5,2952794112
000000000e0acf4e: ec4100b30659 risbgn %r4,%r1,0,179,6
#000000000e0acf54: 0e24 mvcl %r2,%r4
000000000e0acf56: a7280000 lhi %r2,0
000000000e0acf5a: eb6ff0a80004 lmg %r6,%r15,168(%r15)
000000000e0acf60: b9140022 lgfr %r2,%r2
000000000e0acf64: 07fe bcr 15,%r14
000000000e0acf66: 47000700 bc 0,1792
[ 21.408883] Call Trace:
After the patch:
[ 21.408784] Krnl GPRS: 000002aa3780c000 0000000000238c00 0000000015800000
0000000000001000
[ 21.408787] 0000000008e30000 00000000b0001000 0000000000000000
0000000000000a55
[ 21.408790] 0000000004c52300 000002aa3780c000 00000000084281d0
0000038000bfbd28
[ 21.408794] 00000000075e9500 0000000004c52300 0000038000bfbbf0
0000038000bfbb90
[ 21.408860]
Krnl Code: 000000000e0acf48: c05fb0001000 llilf %r5,2952794112
[ 21.408883] Call Trace:
I think your approach of storing printable characters in the buffer with the intention to
modify it
afterwards (see [1] below) instead of writing it character wise does not work when the
input data
contains several lines. Those '\n' are written one by one, what leads to the
result shown above.
You should probably buffer and 'demangle' each line separately.
On 9/8/2025 10:42 AM, Lianbo Jiang wrote:
Without the patch:
crash> log
...
[ 2174.308966] Call Trace:
[ 2174.311693] <TASK>
[ 2174.314033] dump_stack_lvl+0x5d/0x80
[ 2174.318125] panic+0x156/0x32a
[ 2174.321539] _RNvCscb18lrEyTSA_10rust_panic10area_in_hp+0xf7/0x120 [rust_panic]
[ 2174.329700] ? console_unlock+0x9c/0x140
[ 2174.334080] ? irq_work_queue+0x2d/0x50
[ 2174.338352] ? __pfx_init_module+0x10/0x10 [rust_panic]
[ 2174.344183] _RNvMCscb18lrEyTSA_10rust_panicNtB2_10HelloPanic8step_two+0x20/0xe0
[rust_panic]
[ 2174.353698] ? _printk+0x6b/0x90
...
With the patch:
crash> log
...
[ 2174.308966] Call Trace:
[ 2174.311693] <TASK>
[ 2174.314033] dump_stack_lvl+0x5d/0x80
[ 2174.318125] panic+0x156/0x32a
[ 2174.321539] rust_panic::area_in_hp+0xf7/0x120 [rust_panic]
[ 2174.329700] ? console_unlock+0x9c/0x140
[ 2174.334080] ? irq_work_queue+0x2d/0x50
[ 2174.338352] ? __pfx_init_module+0x10/0x10 [rust_panic]
[ 2174.344183] <rust_panic::HelloPanic>::step_two+0x20/0xe0 [rust_panic]
[ 2174.353698] ? _printk+0x6b/0x90
...
Signed-off-by: Lianbo Jiang <lijiang(a)redhat.com>
---
index 95db7e607e4c..ae28c4fa0b21 100644
--- a/printk.c
+++ b/printk.c
@@ -1,5 +1,6 @@
#include "defs.h"
#include <ctype.h>
+#include "demangle.h"
/* convenience struct for passing many values to helper functions */
struct prb_map {
@@ -201,14 +202,44 @@ dump_record(struct prb_map *m, unsigned long id, int msg_flags)
text = m->text_data + begin;
+ if (text_len > BUFSIZE) {
+ error(WARNING, "\nThe messages could be truncated!\n");
+ text_len = BUFSIZE;
+ }
+
for (i = 0, p = text; i < text_len; i++, p++) {
if (*p == '\n')
fprintf(fp, "\n%s", space(ilen));
else if (isprint(*p) || isspace(*p))
- fputc(*p, fp);
+ sprintf(&buf[i], "%c", *p);
[1]
else
fputc('.', fp);
}
+ /*
+ * Try to demangle a mangled Rust symbol(calltrace) from log buffer
+ */
+ char *p1 = strstr(buf, "_R");
+ if (!p1)
+ p1 = strstr(buf, "_ZN");
+ char *p2 = strchrnul(buf, '+');
+ if (p1 && p2) {
+ char mangled[BUFSIZE] = {0};
+ char demangled[BUFSIZE] = {0};
+ char *res;
+ size_t slen = p1 - buf;
+
+ if (slen)
+ memcpy(demangled, buf, slen);
+
+ memcpy(mangled, p1, p2-p1);
+ res = rust_demangle(mangled, DMGL_RUST);
+ if (res) {
+ snprintf(demangled+slen, BUFSIZE-slen, "%s%s", res, p2);
+ fprintf(fp, "%s",demangled);
+ free(res);
+ }
+ } else
+ fprintf(fp, "%s", buf);
if (msg_flags & SHOW_LOG_DICT) {
text = info + OFFSET(printk_info_dev_info) +
Thanks,
Mikhail