shijie.xiong | 1beacb2 | 2023-06-06 16:08:52 +0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright (c) 2021-2022 Amlogic, Inc. All rights reserved. |
| 4 | # |
| 5 | # SPDX-License-Identifier: MIT |
| 6 | # |
| 7 | |
| 8 | #RTOS root directory |
| 9 | RTOS_BASE_DIR=$(realpath $(dirname $(readlink -f ${BASH_SOURCE[0]:-$0}))/..) |
| 10 | |
| 11 | function usage() { |
| 12 | echo -e "\033[41;33m Notice: parameter error !!! \033[0m" |
| 13 | echo -e "\033[33m usage: ./coredump_process.sh (elf_file_path) (log_file_path)\033[0m" |
| 14 | exit 1 |
| 15 | } |
| 16 | |
shijie.xiong | a00a043 | 2023-08-22 14:52:11 +0800 | [diff] [blame] | 17 | if [ -z "$ARCH" ]; then |
| 18 | echo -e "\033[41;33m Please execute source scripts/env.sh \033[0m" |
| 19 | exit 1 |
| 20 | fi |
| 21 | |
shijie.xiong | 1beacb2 | 2023-06-06 16:08:52 +0800 | [diff] [blame] | 22 | if [ -s "$1" ] && [ -s "$2" ]; then |
| 23 | COREDUMP_LOG=$(readlink -f "$2") |
| 24 | COREDUMP_BIN=$(dirname "$COREDUMP_LOG")/coredump.bin |
| 25 | COREDUMP_ELF=$(readlink -f "$1") |
| 26 | |
| 27 | # Parse coredump log file. |
| 28 | $RTOS_BASE_DIR/lib/utilities/coredump/scripts/coredump_serial_log_parser.py $COREDUMP_LOG $COREDUMP_BIN |
| 29 | |
| 30 | if [ $? -ne 0 ]; then |
| 31 | echo "Failed to parse coredump file ! $COREDUMP_LOG" |
| 32 | exit 1 |
| 33 | fi |
| 34 | |
| 35 | # Start gdbstub server. |
| 36 | $RTOS_BASE_DIR/lib/utilities/coredump/scripts/coredump_gdbserver.py $COREDUMP_ELF $COREDUMP_BIN & |
| 37 | |
| 38 | if [ $? -ne 0 ]; then |
| 39 | echo "Failed to start gdbstub service !" |
| 40 | exit 1 |
| 41 | fi |
| 42 | |
| 43 | # Start gdbstub terminal |
shijie.xiong | a00a043 | 2023-08-22 14:52:11 +0800 | [diff] [blame] | 44 | if [ "$ARCH" = "riscv" ]; then |
| 45 | echo "riscv coredump process" |
| 46 | pushd $RTOS_BASE_DIR/output/toolchains/gcc-riscv-none/bin |
| 47 | riscv-none-embed-gdb $COREDUMP_ELF |
| 48 | popd |
| 49 | else |
| 50 | echo "arm64 coredump process" |
| 51 | pushd $RTOS_BASE_DIR/output/toolchains/gcc-aarch64-none-elf/bin |
| 52 | aarch64-none-elf-gdb $COREDUMP_ELF |
| 53 | popd |
| 54 | fi |
shijie.xiong | 6813346 | 2023-06-26 17:14:04 +0800 | [diff] [blame] | 55 | |
| 56 | # Clean up the abnormal exit problem of gdbstub |
| 57 | pid=$(lsof -t -i :1234) |
| 58 | |
| 59 | if [ -n "$pid" ]; then |
| 60 | kill $pid |
| 61 | fi |
shijie.xiong | 1beacb2 | 2023-06-06 16:08:52 +0800 | [diff] [blame] | 62 | else |
| 63 | usage |
| 64 | fi |