본문 바로가기

유용한 디버깅 팁/crash utility and vmcore

Crash 명령어

간단하다. 로그 버퍼를 볼 수 있다.

log -m

crash> log -m
<6>[194643.799885 02-09 21:16:26.949] bt_hc_worker (32565): undefined instruction: pc=c032ae1c
....

<0>[194643.799977 02-09 21:16:26.949] Internal error: Oops - BUG: 0 [#1] PREEMPT SMP ARM
<4>[194643.800007 02-09 21:16:26.949] Modules linked in:
<4>[194643.800038 02-09 21:16:26.949] CPU: 0    Tainted: G        W     (3.4.0-perf-g3d4c0e7-00001-g46f9c0a #1)
<4>[194643.800068 02-09 21:16:26.949] PC is at hs_start_rx_locked+0x2c/0x218
<4>[194643.800099 02-09 21:16:26.949] LR is at hs_start_rx_locked+0x2c/0x218
<4>[194643.800129 02-09 21:16:26.949] pc : c032ae1c    lr : c032ae1c    psr : 20000093

 

프로세서의 상태를 parent tree 포맷으로 나타내줌.

crash> ps -p

crash> ps -p
PID: 0      TASK: c0d4cbd8  CPU: 0   COMMAND: "swapper/0"
PID: 2      TASK: dc4403c0  CPU: 0   COMMAND: "kthreadd"
  PID: 75     TASK: eb66da40  CPU: 1   COMMAND: "smux_tx_wq"
 
PID: 0      TASK: c0d4cbd8  CPU: 0   COMMAND: "swapper/0"
PID: 2      TASK: dc4403c0  CPU: 0   COMMAND: "kthreadd"
  PID: 76     TASK: eb66de00  CPU: 1   COMMAND: "smux_rx_wq"

 

프로세서의상태를 다른 parent tree 포맷으로 나타내줌.

crash> ps -c

PID: 0      TASK: c0d4cbd8  CPU: 0   COMMAND: "swapper/0"
  PID: 0      TASK: c0d4cbd8  CPU: 0   COMMAND: "swapper/0"
  PID: 0      TASK: dc4421c0  CPU: 1   COMMAND: "swapper/1"
  PID: 1      TASK: dc440000  CPU: 0   COMMAND: "init"
  PID: 2      TASK: dc4403c0  CPU: 0   COMMAND: "kthreadd"
 
PID: 0      TASK: dc4421c0  CPU: 1   COMMAND: "swapper/1"
  (no children)
 
PID: 1      TASK: dc440000  CPU: 0   COMMAND: "init"
  PID: 142    TASK: eb5fe940  CPU: 0   COMMAND: "ueventd"
  PID: 321    TASK: eadd7c00  CPU: 0   COMMAND: "healthd"
  PID: 322    TASK: eadd5680  CPU: 1   COMMAND: "servicemanager"
  PID: 323    TASK: eadd52c0  CPU: 0   COMMAND: "vold"

 

process user space 상의 좀더 구체적인 정보를 보여줌

crash> ps -a

crash> ps -a
PID: 389    TASK: eb066940  CPU: 0   COMMAND: "sdcard"
ARG: /system/bin/sdcard -u 1023 -g 1023 -l /data/media /mnt/shell/emulated
ENV: VIBE_PIPE_PATH=/dev/pipes
     PATH=/sbin:/vendor/bin:/system/sbin:/system/bin:/system/xbin
     LD_LIBRARY_PATH=/vendor/lib:/system/lib
     ANDROID_BOOTLOGO=1
     ANDROID_ROOT=/system

 

process group 별로 process를 보여줌

crash> ps -g

crash> ps -g
PID: 330    TASK: eadd4b40  CPU: 0   COMMAND: "surfaceflinger"
  PID: 474    TASK: ea95c3c0  CPU: 1   COMMAND: "Binder_1"
  PID: 475    TASK: ea95fc00  CPU: 1   COMMAND: "DispSync"
  PID: 479    TASK: ea95e940  CPU: 0   COMMAND: "Binder_2"

 

아래명령어를 입력하면 process 당 동작 시간을 표시한다. 프로세스들의 stall 현상을 디버깅하기 유용하다.

crash> ps -t

PID: 32569  TASK: e04703c0  CPU: 0   COMMAND: "ContactsProvide"
    RUN TIME: 00:00:00
  START TIME: 194643
       UTIME: 1
       STIME: 0
 

 

커널쓰레드의 정보를 보여줌

crash> ps -k

crash> ps -k
   PID    PPID  CPU   TASK    ST  %MEM     VSZ    RSS  COMM
      0      0   0  c0d4cbd8  RU   0.0       0      0  [swapper/0]
      0      0   1  dc4421c0  RU   0.0       0      0  [swapper/1]
      2      0   0  dc4403c0  IN   0.0       0      0  [kthreadd]
      3      2   0  dc440780  IN   0.0       0      0  [ksoftirqd/0]
      6      2   0  dc4412c0  IN   0.0       0      0  [migration/0]

 

posix regular expression으로 process 정보를 보여줌

crash> ps 'msm*'

crash> ps 'msm*'
   PID    PPID  CPU   TASK    ST  %MEM     VSZ    RSS  COMM
     14      2   0  dc443480  IN   0.0       0      0  [irq/203-msmdata]
     18      2   0  dc6a83c0  IN   0.0       0      0  [msm_slim_ctrl_r]

 

특정프로세스(bt_hc_worker)에서 open하고 있는 파일의목록을 확인해보자.      

crash> files 32565

crash> files 32565
PID: 32565  TASK: c3ffb840  CPU: 0   COMMAND: "bt_hc_worker"
  3  eaef8780  eba79d80  ead3c8c0  CHR   /dev/log/main
  4  eae3de40  eba70780  ead3a190  CHR   /dev/log/radio
  5  ea7029c0  eba73780  ead3ad10  CHR   /dev/log/events
  6  ea74fc00  eba76d80  ead3bce0  CHR   /dev/log/system

 

프로세스의 backtrace(call stack)을 파악할 때 사용함.

crash> bt -tlf 107

crash> bt -tlf 107
PID: 107    TASK: eb66fc00  CPU: 0   COMMAND: "mmcqd/0"
      START: __schedule at c07f66d4
  [eb1a3d9c] handle_irq_event_percpu at c00dcba0
  [eb1a3da8] schedule_timeout at c07f4e20
  [eb1a3dcc] gic_eoi_irq at c001d500

 

디바이스에서사용하고 있는 character device의 목록을 확인할 수 있다.

커널패닉이 발생할 때 이외에 디바이스에 대해 첫 분석을 진행할 때 유용하게 사용할 수 있다.

crash> dev

crash> dev
CHRDEV    NAME              CDEV    OPERATIONS
   1      mem             eb33e2c0  memory_fops
   4      /dev/vc/0       c0f583a4  console_fops
   4      tty             dc668d88  tty_fops
   5      /dev/tty        c0f501ec  tty_fops
   5      /dev/console    c0f50228  console_fops
   5      /dev/ptmx       c0f50350  ptmx_fops
   7      vcs             eb341dc0  vcs_fops
  10      misc            dc67e340  misc_fops
  13      input           dc689c40  input_fops
  21      sg               (none)
  29      fb              dc67de00  fb_fops
  81      video4linux     eb0b0c80  v4l2_fops

 

struct나 주소의 아웃풋을 16진수로 표현하고 싶을 경우에 사용한다.

hex

crash> hex
output radix: 16 (hex)

 

sys 명령어로 현재 시스템의 상태를 파악할 수 있음.

아래와같이 빌드 시간/구동된 시간/메모리 사용량/패닉 reason을 알 수 있음.

crash> sys

crash> sys
      KERNEL: vmlinux
    DUMPFILE: rawdump
        CPUS: 2
        DATE: Sun Feb  9 21:16:26 2014
      UPTIME: 2 days, 06:04:03
LOAD AVERAGE: 8.65, 8.42, 7.68
       TASKS: 770
    NODENAME: localhost
     RELEASE: 3.4.0-perf-g3d4c0e7-00001-g46f9c0a
     VERSION: #1 SMP PREEMPT Tue Feb 4 11:21:16 KST 2014

 

아래명령어로 시스템 콜의 위치를 파악할 수 있음

crash> sys -c

 

설명할필요가 없다. Config 파일의 목록이다.

crash> sys config

crash> sys config
#
# Automatically generated file; DO NOT EDIT.
# Linux/arm 3.4.0 Kernel Configuration
#
CONFIG_ARM=y
CONFIG_ARM_HAS_SG_CHAIN=y

 

crash> struct -o task_struct | grep files

[0x2b8] struct files_struct *files;

 

심볼정보를 보고 싶은 경우 아래와 같은 명령어를 사용함

crash> whatis

crash> whatis linux_banner
const char linux_banner[];
crash> whatis init_task
struct task_struct init_task;

 

커널에서사용하고 있는 모든 타이머를 확인하고 싶은 경우

crash> timer

crash> timer
TVEC_BASES[0]: c0efa0c0
JIFFIES
19434365
EXPIRES  TIMER_LIST  FUNCTION
19434366   dc5838ac   c0403f34  <dhd_watchdog>
19434369   eb0a0c80   c009adc0  <delayed_work_timer_fn>
19434375   c0d4f8a8   c009adc0  <delayed_work_timer_fn>
19434376   eabe1434   c009adc0  <delayed_work_timer_fn>
19434377   d4295e88   c008eb44  <process_timeout>
19434380   c2d4a44c   c009adc0  <delayed_work_timer_fn>
19434385   eb6bf1f0   c009adc0  <delayed_work_timer_fn>
19434400   c0d77dc4   c03818bc  <pm_suspend_timer_fn>
19434400   c0d7ce94   c03818bc  <pm_suspend_timer_fn>
19434400   c2d4a204   c009adc0  <delayed_work_timer_fn>
19434400   eabe15d4   c009adc0  <delayed_work_timer_fn>

 

아래명령어로 심볼의 주소를 알아낼 수 있다.

crash> sym -l | grep start_kern

c07e53a4 (T) secondary_start_kernel
c0c004b0 (T) start_kernel

 

스케줄러의실행 queue를 출력함

crash> runq

crash> runq
CPU 0 RUNQUEUE: c2d4b700
  CURRENT: PID: 32565  TASK: c3ffb840  COMMAND: "bt_hc_worker"
  RT PRIO_ARRAY: c2d4b7d0
     [no tasks queued]
  CFS RB_ROOT: c2d4b770
     [120] PID: 32570  TASK: c3ffbc00  COMMAND: "BluetoothAdapte"
     [120] PID: 9961   TASK: e7aec000  COMMAND: "kworker/u:1"
     [120] PID: 107    TASK: eb66fc00  COMMAND: "mmcqd/0"
 
CPU 1 RUNQUEUE: c2d54700
  CURRENT: PID: 32315  TASK: c98c5a40  COMMAND: "Binder_2"
  RT PRIO_ARRAY: c2d547d0
     [no tasks queued]
  CFS RB_ROOT: c2d54770
     [120] PID: 32302  TASK: e30eb840  COMMAND: "ndroid.settings"
     [130] PID: 32280  TASK: cc63cf00  COMMAND: "Binder_4"

 

네트워크디바이스의 목록을 출력

crash> net

NET_DEVICE  NAME   IP ADDRESS(ES)
dc40b800   lo     127.0.0.1
dc40e000   dummy0

< '시스템 소프트웨어 개발을 위한 Arm 아키텍처의 구조와 원리' 저자>