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