调试技术(第四章 )

1、输出文件/proc/kmsg的内容时,回应为里面的内容为空而将进程暂时阻塞,等到有数据是再输出。
2、在打印一条可能被重复的信息之前,应调用函数
     int printk_ratelimit(void);
     如果该函数返回一个非零值则可以继续并打印我们的消息,否则就应该跳过,例:
     if (printk_ratelimit()){
          printk(HERN_NOTICE " XXXXXXX");
     }
3、在/proc中实现文件
     int (*read_proc) (char *page, char **start, off_t offset, int count, int *eof, void * data);
     老的/proc接口:
     int (*get_info) (char *page, char **start, off_t offset, int count);
     创建自己的/proc文件:
     struct proc_dir_entry * create_proc_read_entry(const char *name, mode_t mode, struct proc_dir_entry *base, read_proc_t *read_proc, void *data);
     卸载模块时,remove_proc_entry函数:
     remove_proc_entry ("scullmem", NULL/*parent dir*/ );
注:不建议使用create_proc_read_entry接口,建议使用seq_file接口
4、包含<linux/seq_file.h>文件,必须定义四个迭代器对象:start、next、stop、show.
     函数原型:
     void *start(struct seq_file *sfile, loff_t *pos);
     void *next(struct seq_file *sfile, void *v, loff_t *pos);
     void stop(struct seq_file *sfile, void *v);
     void show(struct seq_file *sfile, void *v);
     其中show()函数可以有下面的几个函数实现:
     int seq_printf(strcut seq_file *sfile, const char *fmt, ...);
     int seq_putc(struct seq_file *sfile, char c);
     int seq_puts(struct seq_file *sfile, const char *s);
     int seq_escape(struct seq_file *sfile, const char *s, const char *esc);
     int seq_path(struct seq_file *sfile, struct vfsmount *m, struct dentry *dentry, char *sec);
scull必须把这些函数打包和/proc中的某个文件连接起来,首先填充搞一个seq_operations结构:
     static struct seq_operations scull_seq_ops = {
          .start = start;
          .next = next;
          .stop = stop;
          .show = show;
     };
接下来建立一个open方法将文件链接到seq_file操作。     
5、系统挂起:
     可以通过ALT+SysR+下面的任意键查看系统信息:
     r  关闭键盘的raw模式。当某个崩溃的应用程序让键盘处于一种奇怪的状态时,就可以用这个键关闭raw模式
     k  激活“留意安全键”功能。SAK将杀死当前控制台上运行的所有进程,留下一个干净的终端。
     s  对所有键盘进行紧急同步。
     u  尝试以只读模式重新挂载所有磁盘。
     b  重启系统
     p  打印当前处理器寄存器信息。
     t  打印当前的任务列表。
     m  打印内存信息。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值