Pi-Hsun Shih | d3121bb | 2020-07-09 07:41:12 | [diff] [blame] | 1 | #!/bin/bash |
Mike Frysinger | 8b0fc37 | 2022-09-08 07:24:24 | [diff] [blame] | 2 | # Copyright 2020 The ChromiumOS Authors |
Pi-Hsun Shih | d3121bb | 2020-07-09 07:41:12 | [diff] [blame] | 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
| 5 | |
| 6 | # Loads script libraries. |
| 7 | CONTRIB_DIR=$(dirname "$(readlink -f "$0")") |
| 8 | . "${CONTRIB_DIR}/common.sh" || exit 1 |
| 9 | |
| 10 | FLAGS_HELP=" |
| 11 | Decode kernel stack trace from kernel logs. |
| 12 | |
| 13 | Read kernel logs from stdin, and print the decoded stack trace to stdout. |
| 14 | |
| 15 | Usage: |
| 16 | kernel_decode_stack -b <board> |
| 17 | " |
| 18 | |
| 19 | # Flags |
| 20 | DEFINE_string board "${DEFAULT_BOARD}" "Which board to decode stack trace" b |
| 21 | |
| 22 | # Parse command line. |
| 23 | FLAGS "$@" || exit 1 |
| 24 | eval set -- "${FLAGS_ARGV}" |
| 25 | set -e |
| 26 | |
| 27 | # Script must be run inside the chroot. |
| 28 | assert_inside_chroot |
| 29 | |
| 30 | decode_stacktrace() { |
| 31 | local board="$1" |
| 32 | shift |
| 33 | |
| 34 | local CHOST |
| 35 | CHOST=$("portageq-${board}" envvar CHOST) |
| 36 | |
| 37 | local ARCH |
| 38 | ARCH=$("portageq-${board}" envvar ARCH) |
| 39 | |
Maksim Ivanov | 44a91d4 | 2023-08-29 10:14:25 | [diff] [blame] | 40 | # cros-kernel.eclass falls back to tc-arch-kernel when CHROMEOS_KERNEL_ARCH |
Pi-Hsun Shih | d3121bb | 2020-07-09 07:41:12 | [diff] [blame] | 41 | # is not set, but since tc-arch-kernel parse the arch from CHOST, we can just |
| 42 | # ignnore kernel_arch and use the original CHOST as CROSS_COMPILE in this |
| 43 | # case. |
| 44 | local kernel_arch |
| 45 | kernel_arch=$("portageq-${board}" envvar CHROMEOS_KERNEL_ARCH || true) |
| 46 | |
Maksim Ivanov | 44a91d4 | 2023-08-29 10:14:25 | [diff] [blame] | 47 | # This part is from cros-kernel.eclass |
Pi-Hsun Shih | d3121bb | 2020-07-09 07:41:12 | [diff] [blame] | 48 | # Support 64bit kernels w/32bit userlands. |
| 49 | local cross=${CHOST} |
| 50 | if [[ "${ARCH}:${kernel_arch}" == "arm:arm64" ]]; then |
| 51 | cross="aarch64-cros-linux-gnu" |
| 52 | fi |
| 53 | |
| 54 | # Note: This would point to some temporary path if the kernel is not worked |
| 55 | # on, but it's ok since the decode_stacktrace.sh only use this path to strip |
| 56 | # the output. |
| 57 | # |
| 58 | # This is also why we always use the decode_stacktrace.sh from |
| 59 | # kernel/upstream instead of using the one in kernel_source_path. |
| 60 | local kernel_source_path |
| 61 | kernel_source_path=$( |
Fei Shao | 597747e | 2023-01-05 04:34:25 | [diff] [blame] | 62 | objdump -WL "/build/${board}/usr/lib/debug/boot/vmlinux" 2>/dev/null | |
Pi-Hsun Shih | d3121bb | 2020-07-09 07:41:12 | [diff] [blame] | 63 | grep 'include/linux/compiler.h:$' | |
| 64 | head -1 | |
| 65 | sed 's|\(.*\)/include/linux/compiler.h:$|\1|') |
| 66 | |
Stephen Boyd | 0a36f43 | 2021-12-01 00:56:35 | [diff] [blame] | 67 | ARCH=${kernel_arch} CROSS_COMPILE="${cross}-" \ |
Pi-Hsun Shih | d3121bb | 2020-07-09 07:41:12 | [diff] [blame] | 68 | "${SRC_ROOT}/third_party/kernel/upstream/scripts/decode_stacktrace.sh" \ |
| 69 | "/build/${board}/usr/lib/debug/boot/vmlinux" \ |
| 70 | "${kernel_source_path}" \ |
| 71 | "/build/${board}/usr/lib/debug/lib/modules/"*/ |
| 72 | } |
| 73 | |
| 74 | main() { |
| 75 | if [[ -z "${FLAGS_board}" ]]; then |
| 76 | die "-b or --board required." |
| 77 | fi |
| 78 | |
| 79 | decode_stacktrace "${FLAGS_board}" "$@" |
| 80 | } |
| 81 | |
| 82 | main "$@" |