$ cat /boot/config-4.13.0-38-generic | grep GDB
# CONFIG_CFG80211_INTERNAL_REGDB is not set
CONFIG_SERIAL_KGDB_NMI=y
CONFIG_GDB_SCRIPTS=y
CONFIG_HAVE_ARCH_KGDB=y
CONFIG_KGDB=y
CONFIG_KGDB_SERIAL_CONSOLE=y
# CONFIG_KGDB_TESTS is not set
CONFIG_KGDB_LOW_LEVEL_TRAP=y
CONFIG_KGDB_KDB=y
获取符号文件
下面我们来准备调试需要的符号文件。看一下该版本的 code name:
$ lsb_release -c
Codename: xenial
然后在下面的目录下新建文件 ddebs.list,其内容如下(注意看情况修改Codename):
$ cat /etc/apt/sources.list.d/ddebs.list
deb http://ddebs.ubuntu.com/ xenial main restricted universe multiverse
deb http://ddebs.ubuntu.com/ xenial-security main restricted universe multiverse
deb http://ddebs.ubuntu.com/ xenial-updates main restricted universe multiverse
deb http://ddebs.ubuntu.com/ xenial-proposed main restricted universe multiverse
#defineKERN_EMERG KERN_SOH "0" /* system is unusable */#defineKERN_ALERT KERN_SOH "1" /* action must be taken immediately */#defineKERN_CRIT KERN_SOH "2" /* critical conditions */#defineKERN_ERR KERN_SOH "3" /* error conditions */#defineKERN_WARNING KERN_SOH "4" /* warning conditions */#defineKERN_NOTICE KERN_SOH "5" /* normal but significant condition */#defineKERN_INFO KERN_SOH "6" /* informational */#defineKERN_DEBUG KERN_SOH "7" /* debug-level messages */
用法是:
printk(KERN_EMERG "hello world!\n"); // 中间没有逗号
而当前控制台的日志级别如下所示:
$ cat /proc/sys/kernel/printk
4 4 1 4
这 4 个数值在文件定义及默认值在如下所示:
// kernel/printk/printk.cint console_printk[4] = { CONSOLE_LOGLEVEL_DEFAULT, /* console_loglevel */ MESSAGE_LOGLEVEL_DEFAULT, /* default_message_loglevel */ CONSOLE_LOGLEVEL_MIN, /* minimum_console_loglevel */ CONSOLE_LOGLEVEL_DEFAULT, /* default_console_loglevel */};// include/linux/printk.h/* printk's without a loglevel use this.. */#defineMESSAGE_LOGLEVEL_DEFAULT CONFIG_MESSAGE_LOGLEVEL_DEFAULT/* We show everything that is MORE important than this.. */#defineCONSOLE_LOGLEVEL_MIN1 /* Minimum loglevel we let people use *//* * Default used to be hard-coded at 7, we're now allowing it to be set from * kernel config. */#defineCONSOLE_LOGLEVEL_DEFAULT CONFIG_CONSOLE_LOGLEVEL_DEFAULT#defineconsole_loglevel (console_printk[0])#definedefault_message_loglevel (console_printk[1])#defineminimum_console_loglevel (console_printk[2])#definedefault_console_loglevel (console_printk[3])