-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgdb_hello_core.sh
More file actions
executable file
·47 lines (36 loc) · 1.16 KB
/
Copy pathgdb_hello_core.sh
File metadata and controls
executable file
·47 lines (36 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/bash
# This script runs gdb to analyze the specified core dump file.
# Bash script strict error handling
set -euo pipefail
# Set working directory and executable path
# WORKDIR="/home/jaytwo/workspace/coredump-workspace" # If not starting from the directory where the executable is located, be sure to set an absolute path.
WORKDIR="$(pwd)"
EXEC="${WORKDIR}/hello"
# Check arguments
if [ $# -ne 1 ]; then
echo "Usage: $0 <core_dump_file>"
echo "Example: $0 core.hello.18078.1766666152"
exit 1
fi
# To get the time info from core.<program>.<pid>.<timestamp>, use date -d "@timestamp" to convert.
# Example: date -d "@1766666152" '+%Y-%m-%d %H:%M:%S %Z'
# Or use the ./list_core_with_time.sh script.
CORE_FILE="$1"
# Change directory
cd "${WORKDIR}"
# Check if core file exists
if [ ! -f "${CORE_FILE}" ]; then
echo "Error: core file does not exist: ${CORE_FILE}"
exit 1
fi
# Check if executable exists
if [ ! -x "${EXEC}" ]; then
echo "Error: executable does not exist or is not executable: ${EXEC}"
exit 1
fi
echo "Run gdb:"
echo " exe : ${EXEC}"
echo " core: ${CORE_FILE}"
echo
# Run gdb
gdb "${EXEC}" "${CORE_FILE}"