proc文件系统中可以查看一些正在运行的变量如device-tree

sh-3.2# cat /proc/device-tree/
#address-cells fixedregulator@9/
#size-cells gpio-keys/
atf_logger/ interrupt-parent
chosen/ lcm/
clocks/ mediatek,connectivity-combo/
compatible memory@00000000/
cpus/ model
cust_accel@0/ mt8167_audio_codec/
cust_gyro@0/ mtcpufreq/
cust_mag@0/ name
ethernet@11180000/ opp_table0/
fixedregulator@0/ panel@0/
fixedregulator@1/ pmu/
fixedregulator@10/ psci/
fixedregulator@11/ reserved-memory/
fixedregulator@12/ sdio@11130000/
fixedregulator@2/ soc/
fixedregulator@4/ sound/
fixedregulator@5/ timer/
fixedregulator@6/ tlv320/
fixedregulator@7/ tonly-power-leds/
fixedregulator@8/ vibrator@0/
sh-3.2# cat /proc/device-tree/gpio-keys/
button@0/ button@2/ button@4/ name pinctrl-names
button@1/ button@3/ compatible pinctrl-0
sh-3.2# cat /proc/device-tree/gpio-keys/compatible
gpio-keys sh-3.2#
 

module_param值修改方法

module_param(musbfsh_debug, int, 0644);
 

修改方法

echo 1 > sys/module/musbfsh_core/parameters/musbfsh_debug

编译时判断宏变量是否定义:编译时打印宏变量

#ifdef CONFIG_DWMAC_MESON
#pragma message("CONFIG_DWMAC_MESON active\n") 编译的时候的打印会有提示,搜索即可:
note: #pragma message:
CONFIG_DWMAC_MESON active #pragma message("CONFIG_DWMAC_MESON active\n")
 

重定义打印宏,显示特定打印结构

#ifdef pr_debug
#undef pr_debug
#define pr_debug(fmt, ...) \
printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
#else
#define pr_debug(fmt, ...) \
printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
#endif
 有格式的打印,便于分析别人代码

#ifdef pr_debug
#undef pr_debug
#define pr_debug(fmt,...) printk(KERN_INFO"%s:%s :%d\n "fmt, __FILE__ , __FUNCTION__ , __LINE__ , ##__VA_ARGS__)
#else
#define pr_debug(fmt, ...) printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
#endif
 

  1) VA_ARGS 是一个可变参数的宏,很少人知道这个宏,这个可变参数的宏是新的C99规范中新增的,目前似乎只有gcc支持(VC6.0的编译器不支持)。宏前面加上##的作用在于,当可变参数的个数为0时,这里的##起到把前面多余的”,”去掉的作用,否则会编译出错, 你可以试试。
  2) FILE 宏在预编译时会替换成当前的源文件名
  3) LINE宏在预编译时会替换成当前的行号
  4) FUNCTION宏在预编译时会替换成当前的函数名称

#ifndef _OSD_LOG_H_
#define _OSD_LOG_H_ #include <stdarg.h>
#include <linux/printk.h> #define OSD_LOG_LEVEL_NULL 0
#define OSD_LOG_LEVEL_DEBUG 1
#define OSD_LOG_LEVEL_DEBUG2 2
#define OSD_LOG_LEVEL_DEBUG3 3 extern unsigned int osd_log_level; #undef pr_fmt
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #define osd_log_info(fmt, ...) \
pr_info(fmt, ##__VA_ARGS__) #define osd_log_err(fmt, ...) \
pr_err(fmt, ##__VA_ARGS__) #define osd_log_dbg(fmt, ...) \
do { \
if (osd_log_level >= OSD_LOG_LEVEL_DEBUG) { \
pr_info(fmt, ##__VA_ARGS__); \
} \
} while (0) #define osd_log_dbg2(fmt, ...) \
do { \
if (osd_log_level >= OSD_LOG_LEVEL_DEBUG2) { \
pr_info(fmt, ##__VA_ARGS__); \
} \
} while (0) #define osd_log_dbg3(fmt, ...) \
do { \
if (osd_log_level >= OSD_LOG_LEVEL_DEBUG3) { \
pr_info(fmt, ##__VA_ARGS__); \
} \
} while (0) #endif
 

通过menuconfig配置将打印打开:

+CONFIG_DEBUG_OBJECTS=y
+CONFIG_DEBUG_OBJECTS_TIMERS=y
+CONFIG_DEBUG_OBJECTS_WORK=y
+CONFIG_SLUB_DEBUG_ON=y
+CONFIG_DEBUG_STACK_USAGE=y
+CONFIG_DEBUG_MEMORY_INIT=y
+CONFIG_DEBUG_PER_CPU_MAPS=y
+CONFIG_DEBUG_SHIRQ=y
+CONFIG_LOCKUP_DETECTOR=y
+CONFIG_BOOTPARAM_HARDLOCKUP_PANIC=y
+CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC=y
+CONFIG_BOOTPARAM_HUNG_TASK_PANIC=y
+CONFIG_PANIC_ON_OOPS=y
+CONFIG_DEBUG_KOBJECT=y
+CONFIG_DEBUG_DRIVER=y
 将会有更细节的打印:功能都在菜单的kernel hacking里
<7>[    2.625859@0] kobject: 'rtc-hym8563' (ffffffc0246c78c0): kobject_uevent_env
<7>[ 2.625876@0] kobject: 'rtc-hym8563' (ffffffc0246c78c0): fill_kobj_path: path = '/bus/i2c/drivers/rtc-hym8563'
<7>[ 2.626050@0] bus: 'amba': add driver rtc-pl031
<7>[ 2.626066@0] kobject: 'rtc-pl031' (ffffffc0246c66c0): kobject_add_internal: parent: 'drivers', set: 'drivers'
<7>[ 2.626121@0] kobject: 'rtc-pl031' (ffffffc0246c66c0): kobject_uevent_env
<7>[ 2.626136@0] kobject: 'rtc-pl031' (ffffffc0246c66c0): fill_kobj_path: path = '/bus/amba/drivers/rtc-pl031'
<6>[ 2.626267@0] i2c /dev entries driver
<7>[ 2.629519@0] device class 'i2c-dev': registering
<7>[ 2.629534@0] kobject: 'i2c-dev' (ffffffc0244bc398): kobject_add_internal: parent: 'class', set: 'class'
<7>[ 2.629555@0] kobject: 'i2c-dev' (ffffffc0244bc398): kobject_uevent_env
<7>[ 2.629568@0] kobject: 'i2c-dev' (ffffffc0244bc398): fill_kobj_path: path = '/class/i2c-dev'
<7>[ 2.629724@0] device: 'i2c-2': device_add
<7>[ 2.629737@0] kobject: 'i2c-dev' (ffffffc0246f5200): kobject_add_internal: parent: 'i2c-2', set: '(null)'
 

打开pr_debug的打印,修改打印级别:

kernel/printk/printk.c

#define DEFAULT_CONSOLE_LOGLEVEL 8 /* anything MORE serious than KERN_DEBUG */

或在include/linux/printk.h中打开宏,则系统增加全局pr_debug打印
#define DEBUG
 

利用动态打印,在内核中添加配置,并重新编译烧录内核

CONFIG_DYNAMIC_DEBUG=y
 

在文件系统中生成如下节点

/sys/kernel/debug/dynamic_debug/control
 

查看支持的动态调试选项

/sys/kernel/debug/dynamic_debug # cat control
# filename:lineno [module]function flags format
init/main.c:712 [main]initcall_blacklist =p "blacklisting initcall %s\012"
init/main.c:736 [main]initcall_blacklisted =p "initcall %s blacklisted\012"
init/initramfs.c:483 [initramfs]unpack_to_rootfs =_ "Detected %s compressed data\012"
arch/arm/vfp/vfpmodule.c:456 [vfp]vfp_pm_suspend =_ "%s: saving vfp state\012"
arch/arm/vfp/vfpmodule.c:304 [vfp]vfp_emulate_instruction =_ "VFP: emulate: INST=0x%08x SCR=0x%08x\012"
arch/arm/vfp/vfpmodule.c:260 [vfp]vfp_raise_exceptions =_ "VFP: raising exceptions %08x\012"
arch/arm/vfp/vfpmodule.c:340 [vfp]VFP_bounce =_ "VFP: bounce: trigger %08x fpexc %08x\012"
arch/arm/vfp/vfpsingle.c:51 [vfp]vfp_single_dump =_ "VFP: %s: sign=%d exponent=%d significand=%08x\012"
arch/arm/vfp/vfpsingle.c:849 [vfp]vfp_single_multiply =_ "VFP: swapping M <-> N\012"
arch/arm/vfp/vfpsingle.c:694 [vfp]vfp_single_ftosi =_ "VFP: ftosi: d(s%d)=%08x exceptions=%08x\012"
arch/arm/vfp/vfpsingle.c:615 [vfp]vfp_single_ftoui =_ "VFP: ftoui: d(s%d)=%08x exceptions=%08x\012"
arch/arm/vfp/vfpsingle.c:145 [vfp]__vfp_single_normaliseround =_ "VFP: rounding increment = 0x%08x\012"
arch/arm/vfp/vfpsingle.c:1059 [vfp]vfp_single_fdiv =_ "VFP: s%u = %08x\012"
arch/arm/vfp/vfpsingle.c:996 [vfp]vfp_single_fnmul =_ "VFP: s%u = %08x\012"
arch/arm/vfp/vfpsingle.c:1020 [vfp]vfp_single_fadd =_ "VFP: s%u = %08x\012"
arch/arm/vfp/vfpsingle.c:973 [vfp]vfp_single_fmul =_ "VFP: s%u = %08x\012"
arch/arm/vfp/vfpsingle.c:902 [vfp]vfp_single_multiply_accumulate =_ "VFP: s%u = %08x\012"
arch/arm/vfp/vfpsingle.c:916 [vfp]vfp_single_multiply_accumulate =_ "VFP: s%u = %08x\012"
 

如下操作,使能对应的打印 

echo -n 'file svcsock.c line 1603 +p' > <debugfs>/dynamic_debug/control 打开某个文件某一行的日志
// enable all the messages in file svcsock.c 打开某个文件的所有日志 nullarbor:~ # echo -n 'file svcsock.c +p' > <debugfs>/dynamic_debug/control
// enable all the messages in the NFS server module 打开某个模块的所有日志 nullarbor:~ # echo -n 'module nfsd +p' > <debugfs>/dynamic_debug/control
// enable all 12 messages in the function svc_process() 打开某个函数的所有日志 nullarbor:~ # echo -n 'func svc_process +p' > <debugfs>/dynamic_debug/control
// disable all 12 messages in the function svc_process() 关闭某个文件的所有日志 nullarbor:~ # echo -n 'func svc_process -p' > <debugfs>/dynamic_debug/control
// enable messages for NFS calls READ, READLINK, READDIR and READDIR+. nullarbor:~ # echo -n 'format "nfsd: READ" +p' > <debugfs>/dynamic_debug/control

Linux debug的更多相关文章

  1. linux debug (DOS模拟器,模拟debug)

    最近学习王爽那本<汇编语言>,但其实验均为windows环境,需要用到dos.但最为一个unixer,岂能在windows下开发?所以,要用linux下的工具. 汇编器masm可以用gcc ...

  2. linux debug tools

    linux modules: IO schedule.VFS.OOM.memory.net.process schedule kernel debug: perf(IO bound\CPU bound ...

  3. 使用VS+VisualGDB编译Linux版本RCF

    RPC通信框架--RCF介绍中说了,RCF本身是支持跨平台的,其代码放到Linux平台,是可以通过gcc.make等工具,编译通过的. 官方提供的源码中,只有cmake编译脚本,并没有提供Makefi ...

  4. linux/unix 段错误捕获【续】

    本文为“在C/C++中捕获段错误,打印出错的具体位置”的续篇,进一步解决涉及动态链接库的情况.   背景知识: ·linux/unix下动态链接库的基本原理 ·/proc/pid/maps文件的基本格 ...

  5. 使用VS+VisualGDB编译Linux版本RCF(相当于Linux也有COM版本了)

    阅读目录 通过向导配置项目 配置目录结构 修改项目配置 添加RCF源代码 完成配置并进行编译 添加测试程序 添加测试代码——通过TCP进行通信 运行测试程序并查看测试结果 VisualGDB生成的所有 ...

  6. Linux 驱动开发

    linux驱动开发总结(一) 基础性总结 1, linux驱动一般分为3大类: * 字符设备 * 块设备 * 网络设备 2, 开发环境构建: * 交叉工具链构建 * NFS和tftp服务器安装 3, ...

  7. linux yum配置本地iso镜像

    1.本地源配置:cdiso.repo 将iso镜像文件中所有内容复制到/public/software/cdrom 中,节点将本地yum指向此处. [root@node19 ~]# vim /etc/ ...

  8. linux/unix 段错误捕获_转

    转自:linux/unix 段错误捕获[续] 本文为“在C/C++中捕获段错误,打印出错的具体位置”的续篇,进一步解决涉及动态链接库的情况.   背景知识: ·linux/unix下动态链接库的基本原 ...

  9. UE4关于编译配置的参考(Debug,DebugGame,Development,Shipping,Test等)

    https://docs.unrealengine.com/latest/CHN/Programming/Development/BuildConfigurations/index.html 编译配置 ...

随机推荐

  1. Mysql 多表数据拼接插入及子查询结果集随机取一条

    最近遇到一个测试数据的需求,需要往一个表中插入4个来源的数据. 往orders 表中插入 来自 sql_person cm_user_car_model cm_sp_product_new 部分固定数 ...

  2. idea基本使用1

    首先推荐两个快捷键 alt+Ent        相当于eclipse中的crtl+1 alt+ins         :能创建包,类等,还能生成getter,setter,和构造函数 首先创建一个w ...

  3. linux git 保存账号密码

    vi .git/config [credential] helper = store git pull 输入用户名.密码自动保存

  4. samba、ftp和ssh服务

    samba服务 Smb主要作为网络通信协议; Smb是基于cs架构: 完成Linux与windows之间的共享:linux与linux之间共享用NFS 第一步:安装samba [root@ken ~] ...

  5. 接口与继承:方法覆盖(super)

    源代码 //父类Parent class Parent{ int x; int y; Parent() { x = ; y = ; } public void Set(int a,int b) { x ...

  6. sql语句case when 以及left()

    select count(CASE jyje WHEN '1300' THEN '2' ELSE '1' END) as count  from tpent_orders where cplx = 6 ...

  7. python selenium 基本常用操作

    最近学习UI自动化,把一些常用的方法总结一下,方便自己以后查阅需要.因本人水平有限,有不对之处多多包涵!欢迎指正! 一.xpath模糊匹配定位元素 武林至尊,宝刀屠龙刀(xpath),倚天不出(css ...

  8. 小程序2-基本架构讲解(一)WXML 模板

    项目里边生成了不同类型的文件: .json 后缀的 JSON 配置文件 .wxml 后缀的 WXML 模板文件 .wxss 后缀的 WXSS 样式文件 .js 后缀的 JS 脚本逻辑文件 WXML 模 ...

  9. thinkphp中上传图片以及制成缩略图

    form表单中必须有的一个属性: enctype=”multipart/form-data” html的写法: <form action="__SELF__" method= ...

  10. (python基础 函数)

    关键字参数:关键字参数和函数调用关系紧密,函数调用使用关键字参数来确定传入的参数值.使用关键字参数允许函数调用时参数的顺序与声明时不一致,因为 Python 解释器能够用参数名匹配参数值 必需参数:必 ...