9/24/2014

Kernel의 printk debug-1

1. Linux Kernel Debug 설정

linux kernel 의 config 설정과 관련된 부분

2. Linux Print 관련 Debug 

관련내용
  https://elinux.org/Debugging_by_printing

  • Kernel Config 설정확인 

$ cd linux
$ vi .config   


#
# printk and dmesg options
#
CONFIG_PRINTK_TIME=y                    //  printk의 time 정보  
CONFIG_MESSAGE_LOGLEVEL_DEFAULT=4       //  Log Level 설정  
# CONFIG_BOOT_PRINTK_DELAY is not set
# CONFIG_DYNAMIC_DEBUG is not set


Name String Meaning alias function
KERN_EMERG "0" Emergency messages, system is about to crash or is unstable pr_emerg
KERN_ALERT"1"Something bad happened and action must be taken immediatelypr_alert
KERN_CRIT"2"A critical condition occurred like a serious hardware/software failurepr_emerg
KERN_ERR"3"An error condition, often used by drivers to indicate difficulties with the hardwarepr_crit
KERN_WARNING"4"A warning, meaning nothing serious by itself but might indicate problemspr_err
KERN_NOTICE"5"Nothing serious, but notably nevertheless. Often used to report security events.pr_notice
KERN_INFO"6"Informational message e.g. startup information at driver initializationpr_info
KERN_DEBUG"7"Debug messagespr_debug
KERN_DEFAULT"d"The default kernel loglevel
KERN_CONT"""continued" line of log printoutpr_cont

아래와 같이 printk로 각각 debug 가능

printk(KERN_NOTICE "Kernel command line: %s\n", boot_command_line); 


  • 초기의 디버깅 
Kernel Boot 초기에 Print가 Serial 설정 및 초기화 문제로 아래와 같이 설정을 해줘야한다.
추후 필요 없다면 삭제

CONFIG_EARLY_PRINTK=y
CONFIG_DEBUG_KERNEL=y

Kernel Hacking-> Kernel low-level debugging functions

  http://forum.falinux.com/zbxe/index.php?mid=lecture_tip&page=82&document_srl=519453

  • 별도의 각각의 Device의 Debug가 필요하다면 설정 
ALSA Debug

CONFIG_SND_VERBOSE_PRINTK
CONFIG_SND_DEBUG

  https://cateee.net/lkddb/web-lkddb/SND_DEBUG.html


2.1 User에서 Kernel Message 설정 및 확인 

일반적인 Kernel Debug방법이며, printk를 이용하여 쉽게 debug가 가능하며, dmesg를 이용하여 boot time 역시 쉽게 알수 있다.

  • User에서 Kernel printk 설정 

$ cat /proc/sys/kernel/printk
7 4 1 3
current default minimum boot-time-default

$ sudo -s

$ echo 3 > /proc/sys/kernel/printk

$ cat /proc/sys/kernel/printk   // current 만 변경 
3 4 1 3

$ echo "7 4 1 7" > /proc/sys/kernel/printk

$ cat /proc/sys/kernel/printk  // reboot 되면 원래 설정으로 돌아감 
7 4 1 7

$ dmesg   // kernel message 확인 


  https://www.kernel.org/doc/Documentation/
  https://www.kernel.org/doc/Documentation/kernel-parameters.txt