调试信息过多造成dmesg无法完全显示怎么办?
#ifndef __KERNEL__
#define __KERNEL__
#endif
#ifndef MODULE
#define MODULE
#endif
#if defined(MODVERSIONS) && !defined(__GENKSYMS__)
#include
#endif
#ifdef DBGPRT_OUTVER
#include "dbgprint.ver" /* redefine "dbgprint" to include CRC */
#endif
#ifndef EXPORT_SYMTAB
#define EXPORT_SYMTAB
#endif
#include
#include
#include
#include
#include
//#include
#include
#include
#include "dbgprint.h"
EXPORT_SYMBOL(DbgPrint);
#ifndef DBGPRT_VER
#define DBGPRT_VER "0.90"
#endif
int dbgprt_major=65; //the major device number
char dbgprt_dev_name[]={"ALIDbg"}; //the name in /dev
char dbgprt_ver[]={DBGPRT_VER};
//module paramaters and infos
MODULE_AUTHOR("ALI_SHA");
MODULE_DESCRIPTION("Ali M3321 DEBUGER PRINT.");
MODULE_PARM(dbgprt_ver,"s");
MODULE_PARM_DESC(dbgprt_ver,DBGPRT_VER);
MODULE_PARM(dbgprt_major,"i");
MODULE_PARM_DESC(dbgprt_major,"65");
MODULE_PARM(dbgprt_dev_name,"s");
MODULE_PARM_DESC(dbgprt_dev_name,"ALIDbg");
wait_queue_head_t pSleep;
//used to manager the buffer
char chrgMessage[4096]; //the last 1024 don't use for overflow
char* pchEnd;
char* pchStart;
char fTurn; //pchEnd littl than pchStart
char* pchMessageEnd; //the end pointer of array
int nOverLen;
struct file_operations ALIDbgOps =
{
THIS_MODULE,
NULL,
DbgRead,
NULL, //ali_write,
NULL,
NULL,
DbgIoCtl,
NULL,
DbgOpen,
NULL,
DbgClose,
NULL,
NULL,
NULL,
NULL,
NULL
};
int init_module(void)
{
int nResult;
nResult = register_chrdev(dbgprt_major,dbgprt_dev_name,&ALIDbgOps);
if(nResult<0)
{
printk("can't register this device!\n");
return -1;
}
pchStart=chrgMessage;
pchEnd=chrgMessage;
pchMessageEnd=chrgMessage+3072;
fTurn=0;
init_waitqueue_head(&pSleep);
return 0;
}
int cleanup_module()
{
unregister_chrdev(dbgprt_major,dbgprt_dev_name);
return 0;
}
int DbgOpen(struct inode* i,struct file *f)
{
MOD_INC_USE_COUNT;
return 0;
}
int DbgClose(struct inode* i,struct file *f)
{
wake_up_interruptible(&pSleep);
MOD_DEC_USE_COUNT;
return 0;
}
ssize_t DbgRead (struct file* fileDbg, char* pchMsg, size_t nLen, loff_t* pOff)
{
int nMsgLen;
if(!fTurn && (pchStart==pchEnd) )
{
interruptible_sleep_on(&pSleep);
}
if(!fTurn)
{
nMsgLen=pchEnd-pchStart;
if(nLen {
copy_to_user(pchMsg,pchStart,nLen);
pchStart+=nLen;
return nLen;
}
copy_to_user(pchMsg,pchStart,nMsgLen);
}
else
{
if(nLen {
copy_to_user(pchMsg,pchStart,nLen);
pchStart+=nLen;
return nLen;
}
copy_to_user(pchMsg,pchStart,nOverLen);
fTurn=0;
nMsgLen=pchEnd-chrgMessage;
if( (nLen-nOverLen) {
copy_to_user(pchMsg+nOverLen,chrgMessage,nLen-nOverLen);
pchStart=chrgMessage+nLen-nOverLen;
return nLen;
}
copy_to_user(pchMsg+nOverLen,chrgMessage,nMsgLen);
nMsgLen+=nOverLen;
}
pchStart=chrgMessage;
pchEnd=chrgMessage;
return nMsgLen;
}
int DbgIoCtl(struct inode* i,struct file *f,unsigned int cmd,unsigned long arg)
{
switch(cmd)
{
case DBGPRT_IO_CANCLE:
wake_up_interruptible(&pSleep);
break;
default:
return -1;
}
return 0;
}
int DbgPrint(const char *fmt, ...)
{
va_list args;
int nMessageLen;
va_start(args, fmt);
nMessageLen=vsprintf(pchEnd,fmt,args);
va_end(args);
pchEnd+=nMessageLen;
if(pchEnd>=pchMessageEnd)
//the message overflowed
{
nOverLen=pchEnd-pchMessageEnd;
pchEnd=chrgMessage;
fTurn=1;
}
else
{
//the end pointer exceed the start pointor from back
if(fTurn && (pchEnd>pchStart))
{
pchStart=pchEnd;
*pchStart=255; //add a alarmer
}
}
wake_up_interruptible(&pSleep);
return nMessageLen;
}
我所说的版本问题已经解决了.
可以用ioctl来cancle掉被挂起的read.
#ifndef _DBGPRT_H_
#define _DBGPRT_H_
#define DBGPRT_IO_CANCLE 1
int DbgOpen(struct inode* i,struct file *f);
int DbgClose(struct inode* i,struct file *f);
ssize_t DbgRead (struct file* fileDbg, char* pchMsg, size_t nLen, loff_t* pOff);
int DbgIoCtl(struct inode* i,struct file *f,unsigned int cmd,unsigned long arg);
int DbgPrint(const char *fmt, ...);
#endif//_DBGPRT_H_