btdecode.sh 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #!/usr/bin/env bash
  2. ############################################################################
  3. # tools/esp32/btdecode.sh
  4. #
  5. # Licensed to the Apache Software Foundation (ASF) under one or more
  6. # contributor license agreements. See the NOTICE file distributed with
  7. # this work for additional information regarding copyright ownership. The
  8. # ASF licenses this file to you under the Apache License, Version 2.0 (the
  9. # "License"); you may not use this file except in compliance with the
  10. # License. You may obtain a copy of the License at
  11. #
  12. # http://www.apache.org/licenses/LICENSE-2.0
  13. #
  14. # Unless required by applicable law or agreed to in writing, software
  15. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  16. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  17. # License for the specific language governing permissions and limitations
  18. # under the License.
  19. #
  20. ############################################################################
  21. # This script can be used to decode the backtrace that's dumped on assertions.
  22. #
  23. # On assertions we can find the raw backtrace dump similar to:
  24. # ...
  25. # xtensa_btdump: Backtrace0: 400d3ed7:3ffb1300
  26. # xtensa_btdump: Backtrace1: 400d3f33:3ffb1320
  27. # xtensa_btdump: Backtrace2: 400d2875:3ffb1340
  28. # xtensa_btdump: BACKTRACE CONTINUES...
  29. # ...
  30. #
  31. # Copy that to a file and call this script as:
  32. # ./tools/esp32/btdecode.sh backtrace_file
  33. #
  34. # The result should be similar to the following:
  35. # 0x400d3ed7: xtensa_assert at xtensa_assert.c:108
  36. # 0x400d3f33: up_assert at xtensa_assert.c:184 (discriminator 2)
  37. # 0x400d2875: _assert at lib_assert.c:36
  38. USAGE="USAGE: ${0} backtrace_file"
  39. # Make sure we have the required argument(s)
  40. if [ -z "$1" ]; then
  41. echo "No backtrace supplied!"
  42. echo "$USAGE"
  43. exit 1
  44. fi
  45. # Make sure the project was built
  46. if [ ! -f nuttx ]; then
  47. echo "NuttX binaries not found!"
  48. exit 2
  49. fi
  50. # Check that the toolchain is in the PATH
  51. if [ ! -x "$(command -v xtensa-esp32-elf-addr2line)" ]; then
  52. echo "ESP32 toolchain not found!"
  53. exit 3
  54. fi
  55. # Decode backtrace
  56. for bt in `cat $1 | cut -d':' -f3`; do
  57. xtensa-esp32-elf-addr2line -pfiaCs -e nuttx $bt
  58. done