analyze_crashlog.sh 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/bin/bash
  2. # This script can be used for analyzing a crash report.
  3. # It tries to find a matching binary .elf either locally
  4. # or from github releases.
  5. #
  6. # Usage:
  7. # utils/analyze_crashlog.sh # paste log to console, press ctrl-D to end
  8. # utils/analyze_crashlog.sh log.txt # read log from file
  9. # utils/analyze_crashlog.sh log.txt path # read log from file and find firmware at path
  10. if [ "x$1" = "x" ]; then
  11. logfile=$(mktemp /tmp/crashlog-XXXXXXX)
  12. cat - > $logfile
  13. else
  14. logfile=$1
  15. fi
  16. repo="BlueSCSI/BlueSCSI-v2"
  17. # Find firmware compilation time
  18. fwtime=$(grep 'FW Version' $logfile | tail -n 1 | egrep -o '[A-Z][a-z][a-z] [0-9]+ [0-9]+ [0-9:]+')
  19. # Check if the firmware file is available locally
  20. echo "Searching for firmware compiled at $fwtime"
  21. scriptdir=$( dirname -- "${BASH_SOURCE[0]}" )
  22. fwfile=$(find $scriptdir/.. $2 -name '*.elf' -exec grep -q "$fwtime" {} \; -print -quit)
  23. # Search Github for artifacts uploaded within few minutes of the compilation time
  24. if [ "x$fwfile" = "x" ]; then
  25. echo "Searching on Github"
  26. enddate=$(date "+%Y-%m-%dT%H:%M" -d "$fwtime 180 seconds")
  27. runid=$(gh api repos/$repo/actions/artifacts \
  28. --jq ".artifacts[] | select(.created_at <= \"$enddate\") | .workflow_run.id" | head -n 1)
  29. if [ "x$runid" != "x" ]; then
  30. tmpdir=$(mktemp -d /tmp/crashlog-XXXXXXX)
  31. echo "Workflow run: https://github.com/$repo/actions/runs/$runid"
  32. echo "Downloading artifact to $tmpdir (if permission denied, use 'gh auth' to login)"
  33. (cd $tmpdir; gh run download -R $repo $runid)
  34. fwfile=$(find $tmpdir -name '*.elf' -exec grep -q "$fwtime" {} \; -print -quit)
  35. fi
  36. fi
  37. if [ "x$fwfile" = "x" ]; then
  38. echo "Did not find firmware built at $fwtime!"
  39. exit 1
  40. else
  41. echo "Found firmware at $fwfile"
  42. fi
  43. # Get crash addresses
  44. echo
  45. for addr in $(egrep -o '[ x][0-9a-fA-Z]{8}' $logfile | tr -d 'x'); do
  46. arm-none-eabi-addr2line -Cafsip -e "$fwfile" $addr | grep -v ?
  47. done