kernel debug tools...

This commit is contained in:
gatieme
2017-03-30 13:07:38 +08:00
parent 62b53701c3
commit 94b32eff7c
57 changed files with 108 additions and 0 deletions
@@ -0,0 +1,83 @@
# ------------------------------------------------------------------------------
#
# Makefile for the LDD-LinuxDeviceDrivers.
#
# Author: gatieme
# Create: 2016-07-29 15:50:46
# Last modified: 2016-07-29 16:10:29
# Description:
# This program is loaded as a kernel(v2.6.18 or later) module.
# Use "make install" to load it into kernel.
# Use "make remove" to remove the module out of kernel.
#
# ------------------------------------------------------------------------------
ROOT=..
#PLATFORM=$(shell $(ROOT)/systype.sh)
#include $(ROOT)/Make.defines.$(PLATFORM)
# my driver description
DRIVER_VERSION := "1.0.0"
DRIVER_AUTHOR := "Gatieme @ AderStep Inc..."
DRIVER_DESC := "Linux input module for Elo MultiTouch(MT) devices"
DRIVER_LICENSE := "Dual BSD/GPL"
MODULE_NAME := my_debugfs
MODCFLAGS:=-O6 -Wall -DMODULE -D__KERNEL__ -DLINUX -std=c99
ifneq ($(KERNELRELEASE),)
#CFG_FLAGS += -O2 -I./
#EXTRA_CFLAGS += $(C_FLAGS) $(CFG_INC) $(CFG_INC)
obj-m := $(MODULE_NAME).o #print_vmarea.o
else
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
modules:
make -C $(KERNELDIR) M=$(PWD) modules
modules_install:
make -C $(KERNELDIR) M=$(PWD) modules_install
insmod:
sudo insmod $(MODULE_NAME).ko
reinsmod:
sudo rmmod $(MODULE_NAME)
sudo insmod $(MODULE_NAME).ko
github:
cd $(ROOT) && make github
rmmod:
sudo rmmod $(MODULE_NAME)
test :
cat /sys/kernel/debug/mydebug/a
cat /sys/kernel/debug/mydebug/b
cat /sys/kernel/debug/mydebug/subdir/c
clean:
make -C $(KERNELDIR) M=$(PWD) clean
rm -f modules.order Module.symvers Module.markers
.PHNOY:
modules modules_install clean
endif
@@ -0,0 +1,75 @@
#include <linux/init.h>
#include <linux/module.h>
#include <linux/debugfs.h> /* this is for DebugFS libraries */
#include <linux/fs.h>
// http://opensourceforu.com/2010/10/debugging-linux-kernel-with-debugfs/
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Surya Prabhakar <surya_prabhakar@dell.com>");
MODULE_DESCRIPTION("sample code for DebugFS functionality");
#define len 200
u64 intvalue,hexvalue;
struct dentry *dirret,*fileret,*u64int,*u64hex;
char ker_buf[len];
int filevalue;
/* read file operation */
static ssize_t myreader(struct file *fp,
char __user *user_buffer,
size_t count,
loff_t *position)
{
return simple_read_from_buffer(user_buffer, count, position, ker_buf, len);
}
/* write file operation */
static ssize_t mywriter(struct file *fp, const char __user *user_buffer,
size_t count, loff_t *position)
{
if(count > len)
return -EINVAL;
return simple_write_to_buffer(ker_buf, len, position, user_buffer, count);
}
static const struct file_operations fops_debug = {
.read = myreader,
.write = mywriter,
};
static int __init init_debug(void)
{
/* create a directory by the name dell in /sys/kernel/debugfs */
dirret = debugfs_create_dir("gatieme_mydebug", NULL);
/* create a file in the above directory
This requires read and write file operations */
fileret = debugfs_create_file("text", 0644, dirret, &filevalue, &fops_debug);
/* create a file which takes in a int(64) value */
u64int = debugfs_create_u64("number", 0644, dirret, &intvalue);
if (!u64int) {
printk("error creating int file");
return (-ENODEV);
}
/* takes a hex decimal value */
u64hex = debugfs_create_x64("hexnum", 0644, dirret, &hexvalue );
if (!u64hex) {
printk("error creating hex file");
return (-ENODEV);
}
return (0);
}
module_init(init_debug);
static void __exit exit_debug(void)
{
/* removing the directory recursively which
in turn cleans all the file */
debugfs_remove_recursive(dirret);
}
module_exit(exit_debug);