Linux调试中使用的proc和sys中的接口
来源:互联网 发布:淘宝代购上传身份证 编辑:程序博客网 时间:2024/05/22 03:04
在调试的过程中我们通常需要去不停的修改寄存器的值来调试效果,在现在发现有两个手段,分别利用的proc和sys
proc--|
|-----read_proc
|-----write_proc
sys---|
|-----show
|-----store
proc的方法不依赖与kobject,sys中show和store则依赖于kobject。
基本的使用如下:
----------------------------------------------------------------------
-------------------------- start proc ----------------------------
----------------------------------------------------------------------
对于read_proc和write_proc的定义则参考proc_fs.h中的定义即可以实现
----------------------------------------------------------------------
-------------------------- end proc ---------------------------
----------------------------------------------------------------------
相对的利用sys中实现接口调试则如下实现,前提是有device设备哦,亲。
---------------------------------------------------------------------
-------------------------- start sys --------------------------
---------------------------------------------------------------------
关于show和store的函数的定义则如下
---------------------------------------------------------------------
-------------------------- end sys --------------------------
----------------------------------------------------------------------
通过这两种方式可以在调试LCM或者是Camera的时候不必要重新编译了,对调试效果帮助很大。
proc--|
|-----read_proc
|-----write_proc
sys---|
|-----show
|-----store
proc的方法不依赖与kobject,sys中show和store则依赖于kobject。
基本的使用如下:
----------------------------------------------------------------------
-------------------------- start proc ----------------------------
----------------------------------------------------------------------
struct proc_dir_entry *prEntry; prEntry = create_proc_entry("driver/proc_func", 0, NULL); if (prEntry) { prEntry->read_proc = read_proc_func; prEntry->write_proc = write_proc_func; } else { printk("add /proc/driver/camsensor entry fail \n"); }
对于read_proc和write_proc的定义则参考proc_fs.h中的定义即可以实现
/* * This is not completely implemented yet. The idea is to * create an in-memory tree (like the actual /proc filesystem * tree) of these proc_dir_entries, so that we can dynamically * add new files to /proc. * * The "next" pointer creates a linked list of one /proc directory, * while parent/subdir create the directory structure (every * /proc file has a parent, but "subdir" is NULL for all * non-directory entries). */typedefint (read_proc_t)(char *page, char **start, off_t off, int count, int *eof, void *data);typedefint (write_proc_t)(struct file *file, const char __user *buffer, unsigned long count, void *data);
----------------------------------------------------------------------
-------------------------- end proc ---------------------------
----------------------------------------------------------------------
相对的利用sys中实现接口调试则如下实现,前提是有device设备哦,亲。
---------------------------------------------------------------------
-------------------------- start sys --------------------------
---------------------------------------------------------------------
static struct device_attribute test1_attr = {.attr = {.name = "test1",.mode = 0644,.owner = THIS_MODULE},.show = test1_show_func,.store = test1_store_func,};static struct device_attribute *test_attributes[] = {&test1_attr,&test2_attr,&test3_attr,};for (i = 0; i < ARRAY_SIZE(*test_attributes); i++) {ret = device_create_file(&dev,*test_attributes[i]);if (ret) {printk("failed: sysfs file %s\n",*test_attributes[i]->attr.name);goto failed_unregister_dev_file;}}
关于show和store的函数的定义则如下
/* interface for exporting device attributes */struct device_attribute {struct attributeattr;ssize_t (*show)(struct device *dev, struct device_attribute *attr,char *buf);ssize_t (*store)(struct device *dev, struct device_attribute *attr, const char *buf, size_t count);};
---------------------------------------------------------------------
-------------------------- end sys --------------------------
----------------------------------------------------------------------
通过这两种方式可以在调试LCM或者是Camera的时候不必要重新编译了,对调试效果帮助很大。
- Linux调试中使用的proc和sys中的接口
- Linux的sys接口和proc接口创建
- Linux的/proc/sys
- /proc/sys和/sys目录的区别
- linux 中数据的含义 /proc/sys/fs/file-nr
- linux下 /proc 和 /sys 详解
- 使用reboot命令失败的处理方法(/proc/sys/kernel/sysrq 和 /proc/sysrq-trigger )
- 对/proc和/sys的一些理解
- 浅入分析和Linux内核相关的文件夹/proc和/sys
- 使用sys接口来调试驱动
- 使用 /sys 文件系统访问 Linux 内核:比/proc 更为理想的访问内核数据的途径
- 使用 /sys 文件系统访问 Linux 内核:比/proc 更为理想的访问内核数据的途径
- 设置Linux打开文件句柄/proc/sys/fs/file-max和ulimit -n的区别
- Linux RTC驱动分析(三)----sys和proc文件系统
- linux的/proc/sys/net/ipv4下的一些参数
- Android下的两个文件系统:proc和sys(一)
- Android下的两个文件系统:proc和sys(二)
- Android下的两个文件系统:proc和sys(三)
- 在VS2008中配置QT
- qt 第一个窗口全屏,第二个窗口是个对话框,要始终显示在第一个全屏窗口上面
- 对于linux socket与epoll配合相关的一些心得记录(转载)
- 实践1. tomcat+myeclipse+sql2000 登陆
- apue.h头文件的配置
- Linux调试中使用的proc和sys中的接口
- 连接池未关闭问题的发现与解决
- 最新pcre库在windows平台编译完整过程
- 形态学函数cvErode、cvDilate使用说明
- MFC学习笔记之七————工具栏编程与状态栏编程
- android-Animation 四种基本动画
- 用memcache.php监测memcache的状况
- [扩展/新建swap]将文件或分区加载为swap
- java笔记总结_07_多线程