History

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)

Matthieu Baerts (NGI0) committed 1 year ago

Commit 4a2fc481 parent d322f6a1 file · +12 −14Browse files

Showing the changes to scripts/decode_stacktrace.sh (1 of 1 file). Show all

Unified · Split

scripts/decode_stacktrace.sh+12−14
@@ -255,10 +255,11 @@ handle_line() { · 254 unmodified lines
255255 basepath=${basepath%/init/main.c:*)}
256256 fi
257257
258− local words
258+ local words spaces
259259
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:]])/#}")"
262263
263264 # Remove hex numbers. Do it ourselves until it happens in the
264265 # kernel
@@ -270,19 +271,13 @@ handle_line() { · 5 unmodified lines
270271 for i in "${!words[@]}"; do
271272 # Remove the address
272273 if [[ ${words[$i]} =~ \[\<([^]]+)\>\] ]]; then
273− unset words[$i]
274− fi
275−
276− # Format timestamps with tabs
277− if [[ ${words[$i]} == \[ && ${words[$i+1]} == *\] ]]; then
278− unset words[$i]
279− words[$i+1]=$(printf "[%13s\n" "${words[$i+1]}")
274+ unset words[$i] spaces[$i]
280275 fi
281276 done
282277
283278 if [[ ${words[$last]} =~ ^[0-9a-f]+\] ]]; then
284279 words[$last-1]="${words[$last-1]} ${words[$last]}"
285− unset words[$last]
280+ unset words[$last] spaces[$last]
286281 last=$(( $last - 1 ))
287282 fi
288283
@@ -294,7 +289,7 @@ handle_line() { · 5 unmodified lines
294289 local info_str=""
295290 if [[ ${words[$last]} =~ \([A-Z]*\) ]]; then
296291 info_str=${words[$last]}
297− unset words[$last]
292+ unset words[$last] spaces[$last]
298293 last=$(( $last - 1 ))
299294 fi
300295
@@ -311,7 +306,7 @@ handle_line() { · 10 unmodified lines
311306 modbuildid=
312307 fi
313308 symbol=${words[$last-1]}
314− unset words[$last-1]
309+ unset words[$last-1] spaces[$last-1]
315310 else
316311 # The symbol is the last element, process it
317312 symbol=${words[$last]}
@@ -323,7 +318,10 @@ handle_line() { · 5 unmodified lines
323318 parse_symbol # modifies $symbol
324319
325320 # Add up the line number to the symbol
326− echo "${words[@]}" "${symbol}${module:+ ${module}}${info_str:+ ${info_str}}"
321+ for i in "${!words[@]}"; do
322+ echo -n "${spaces[i]}${words[i]}"
323+ done
324+ echo "${spaces[$last]}${symbol}${module:+ ${module}}${info_str:+ ${info_str}}"
327325 }
328326
329327 while read line; do