Chinaunix首页 | 论坛 | 博客
  • 博客访问: 157355
  • 博文数量: 40
  • 博客积分: 2010
  • 博客等级: 大尉
  • 技术积分: 355
  • 用 户 组: 普通用户
  • 注册时间: 2008-11-27 18:05
文章分类
文章存档

2011年(1)

2010年(9)

2009年(16)

2008年(14)

我的朋友

分类: LINUX

2008-12-09 18:47:23

 

打印调试

1.printk调试,加KERN_ALERT 或"<1>"

例printk("<1>hello world\n");

若终端没有出现信息,则可查询cat /var/log/messages


查询调试 /proc调试


 输出少量信息 linux/proc_fs.h(一页内存PAGE_SIZE ):
  

  struct proc_dir_entry *create_proc_read_entry(
           const char *name,//显示名字
           mode_t mode, //文件保护掩码缺省传0
           struct proc_dir_entry *base, //base是NULL则在/proc下创建
           read_proc_t *read_proc, //实现文件read_proc的函数
          void *data//传给read_proc的数据
   );
   //
  int (*read_proc)(
           char *page, // 写入的数据地址
           char **start, //

           off_t offset, // 要返回的数据大小

           int count,//
           int *eof, //值为1指示不再有数据返回
           void *data);//
   int (*get_info)(char *page, char **start, off_t offset, int

                     count);
      //老接口,所有的参数的含义同 read_proc 的相同, 但是没有 eof 和 data参数,此接口仍然支持, 但将来会消失

    remove_proc_entry(const char *name, struct proc_dir_entry

            *base /* parent dir */);
            //


  演示代码

文件: SProc.rar
大小: 0KB
下载: 下载


 大量信息linux/seq_file.h:


1.创建 4 个 iterator 方法, start, next, stop, show.
static struct seq_operations xxx_seq_ops = {
 .start = xxx_start,
 .next =xxx_next,
 .stop = xxx_stop,
 .show = xxx_show
}; //序列操作
void *start(struct seq_file *sfile, loff_t *pos);
//sfile 忽略.
//pos 是一个整型位置值, 指示读的位置
//返回一个 iterator 对象的指针,在next中是v.
void *next(struct seq_file *sfile, void *v, loff_t *pos);
//
void stop(struct seq_file *sfile, void *v);
int show(struct seq_file *sfile, void *v);
//将要输出的数据写入sfile中

向seq_file中写入数据专用函数
int seq_printf(struct seq_file *sfile, const char *fmt, ...);
//相当于 printf 然而. 若seq_printf 返回非零值, 意思是缓存区已填充, 输出被丢弃.但, 大部分实现忽略了返回值
int seq_putc(struct seq_file *sfile, char c);
int seq_puts(struct seq_file *sfile, const char *s);
//相当于用户空间 putc 和 puts
int seq_escape(struct seq_file *m, const char *s, const char *esc);
//这个函数是 seq_puts 的对等体, esc中的字符出现在s中,则以八进制格式打印.
int seq_path(struct seq_file *sfile, struct vfsmount *m, struct dentry *dentry, char *esc);
//在驱动中不使用


2.struct proc_dir_entry *create_proc_entry(const char *name,mode_t mode,struct proc_dir_entry *parent);
//同create_proc_read_entry
常常这样用

struct proc_dir_entry *entry;
if(entry)
 entry->proc_fops=&xxx_proc_ops

remove_proc_entry(const char *name, struct proc_dir_entry

            *base /* parent dir */);
            //


3.

static struct file_operations xxx_proc_ops = {
 .owner = THIS_MODULE,
 .open = xxx_proc_open,
// 连接文件结构和定义的序列操作
//static int xxx_proc_open(struct inode *inode, struct file *file)
//{
// return seq_open(file, &xxx_seq_ops); seq_open为内核函数
//}
 .read = seq_read,//seq_read默认的读
 .llseek = seq_lseek,//seq_lseek默认的
 .release = seq_release//seq_release默认的
};
//不要同注册设备时用到的混了,注册设备用的不能用这个,要另外定义一个file_operations


演示代码

文件: seq.rar
大小: 0KB
下载: 下载


 

 
阅读(1416) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~