Linux调试中使用的proc和sys中的接口
2011-08-02 22:13
381 查看
在调试的过程中我们通常需要去不停的修改寄存器的值来调试效果,在现在发现有两个手段,分别利用的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). */ typedef int (read_proc_t)(char *page, char **start, off_t off, int count, int *eof, void *data); typedef int (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 attribute attr; 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
- (Ubuntu 以root用户登录)使用/proc/sys/vm/drop_caches手工释放linux内存
- (Ubuntu 以root用户登录)使用/proc/sys/vm/drop_caches手工释放linux内存
- [Linux]解决使用mdev时“cannot create /proc/sys/kernel/hotplug: nonexistent directory”错误
- 使用 ftrace 调试 Linux 内核,第 1 部分-debugfs挂载和调试接口
- Linux的sys接口和proc接口创建
- Linux安装、使用curl进行Get、Post接口调试
- 使用sys接口来调试驱动
- [转]手工释放linux内存——/proc/sys/vm/drop_caches
- libpqxx接口的在linux下的使用,解决psql:connections on Unix domain socket "/tmp/.s.PGSQL.5432"错误
- 使用 GDB 调试 Linux 软件
- Linux下gdb调试工具的使用方法
- linux debug fs (2)----Linux驱动调试的Debugfs的使用简介
- 在嵌入式Linux上使用CF接口的蓝牙模块
- Linux下使用gdb进行单步调试(一)
- Linux 中gdb调试工具的使用
- 使用 GDB 调试 Linux 软件
- Eclipse下使用Sysdeo Tomcat Plugin调试的问题
- linux 中数据的含义 /proc/sys/fs/file-nr
- linux 下使用魅族mx真机调试android程序