blob: 04a2ae09026740d071692601652b4ad8556edbdf [file] [log] [blame]
shijie.xiong1beacb22023-06-06 16:08:52 +08001#!/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
9RTOS_BASE_DIR=$(realpath $(dirname $(readlink -f ${BASH_SOURCE[0]:-$0}))/..)
10
11function 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.xionga00a0432023-08-22 14:52:11 +080017if [ -z "$ARCH" ]; then
18 echo -e "\033[41;33m Please execute source scripts/env.sh \033[0m"
19 exit 1
20fi
21
shijie.xiong1beacb22023-06-06 16:08:52 +080022if [ -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.xionga00a0432023-08-22 14:52:11 +080044 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.xiong68133462023-06-26 17:14:04 +080055
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.xiong1beacb22023-06-06 16:08:52 +080062else
63 usage
64fi