Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

scripts/decode_stacktrace.sh: symbol: preserve alignment

With lines having a symbol to decode, the script was only trying to
preserve the alignment for the timestamps, but not the rest, nor when the
caller was set (CONFIG_PRINTK_CALLER=y).

With this sample ...

[ 52.080924] Call Trace:
[ 52.080926] <TASK>
[ 52.080931] dump_stack_lvl+0x6f/0xb0

... the script was producing the following output:

[ 52.080924] Call Trace:
[ 52.080926] <TASK>
[ 52.080931] dump_stack_lvl (arch/x86/include/asm/irqflags.h:19)

(dump_stack_lvl is no longer aligned with <TASK>: one missing space)

With this other sample ...

[ 52.080924][ T48] Call Trace:
[ 52.080926][ T48] <TASK>
[ 52.080931][ T48] dump_stack_lvl+0x6f/0xb0

... the script was producing the following output:

[ 52.080924][ T48] Call Trace:
[ 52.080926][ T48] <TASK>
[ 52.080931][ T48] dump_stack_lvl (arch/x86/include/asm/irqflags.h:19)

(the misalignment is clearer here)

That's because the script had a workaround for CONFIG_PRINTK_TIME=y only,
see the previous comment called "Format timestamps with tabs".

To always preserve spaces, they need to be recorded along the words. That
is what is now done with the new 'spaces' array.

Some notes:

- 'extglob' is needed only for this operation, and that's why it is set
in a dedicated subshell.

- 'read' is used with '-r' not to treat a <backslash> character in any
special way, e.g. when followed by a space.

- When a word is removed from the 'words' array, the corresponding space
needs to be removed from the 'spaces' array as well.

With the last sample, we now have:

[ 52.080924][ T48] Call Trace:
[ 52.080926][ T48] <TASK>
[ 52.080931][ T48] dump_stack_lvl (arch/x86/include/asm/irqflags.h:19)

(the alignment is preserved)

Link: https://lkml.kernel.org/r/20250908-decode_strace_indent-v1-2-28e5e4758080@kernel.org
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Tested-by: Carlos Llamas <cmllamas@google.com>
Cc: Breno Leitao <leitao@debian.org>
Cc: Elliot Berman <quic_eberman@quicinc.com>
Cc: Luca Ceresoli <luca.ceresoli@bootlin.com>
Cc: Stephen Boyd <swboyd@chromium.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Matthieu Baerts (NGI0) and committed by
Andrew Morton
4a2fc489 d322f6a2

+12 -14
+12 -14
scripts/decode_stacktrace.sh
··· 255 255 basepath=${basepath%/init/main.c:*)} 256 256 fi 257 257 258 - local words 258 + local words spaces 259 259 260 - # Tokenize 261 - read -a words <<<"$1" 260 + # Tokenize: words and spaces to preserve the alignment 261 + read -ra words <<<"$1" 262 + IFS='#' read -ra spaces <<<"$(shopt -s extglob; echo "${1//+([^[:space:]])/#}")" 262 263 263 264 # Remove hex numbers. Do it ourselves until it happens in the 264 265 # kernel ··· 271 270 for i in "${!words[@]}"; do 272 271 # Remove the address 273 272 if [[ ${words[$i]} =~ \[\<([^]]+)\>\] ]]; then 274 - unset words[$i] 275 - fi 276 - 277 - # Format timestamps with tabs 278 - if [[ ${words[$i]} == \[ && ${words[$i+1]} == *\] ]]; then 279 - unset words[$i] 280 - words[$i+1]=$(printf "[%13s\n" "${words[$i+1]}") 273 + unset words[$i] spaces[$i] 281 274 fi 282 275 done 283 276 284 277 if [[ ${words[$last]} =~ ^[0-9a-f]+\] ]]; then 285 278 words[$last-1]="${words[$last-1]} ${words[$last]}" 286 - unset words[$last] 279 + unset words[$last] spaces[$last] 287 280 last=$(( $last - 1 )) 288 281 fi 289 282 ··· 289 294 local info_str="" 290 295 if [[ ${words[$last]} =~ \([A-Z]*\) ]]; then 291 296 info_str=${words[$last]} 292 - unset words[$last] 297 + unset words[$last] spaces[$last] 293 298 last=$(( $last - 1 )) 294 299 fi 295 300 ··· 306 311 modbuildid= 307 312 fi 308 313 symbol=${words[$last-1]} 309 - unset words[$last-1] 314 + unset words[$last-1] spaces[$last-1] 310 315 else 311 316 # The symbol is the last element, process it 312 317 symbol=${words[$last]} ··· 318 323 parse_symbol # modifies $symbol 319 324 320 325 # Add up the line number to the symbol 321 - echo "${words[@]}" "${symbol}${module:+ ${module}}${info_str:+ ${info_str}}" 326 + for i in "${!words[@]}"; do 327 + echo -n "${spaces[i]}${words[i]}" 328 + done 329 + echo "${spaces[$last]}${symbol}${module:+ ${module}}${info_str:+ ${info_str}}" 322 330 } 323 331 324 332 while read line; do