⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 debug.c

📁 Linux下的类似softice的调试工具
💻 C
字号:
/****************************************************************************** * * Copyright (c) 2003 Gerhard W. Gruber * * PROJECT: pICE * $Source: /cvsroot/pice/pice/module/debug.c,v $ * $Revision: 1.5 $ * $Date: 2004/02/17 23:07:36 $ * $Author: lightweave $ * $Name:  $ * * $Log: debug.c,v $ * Revision 1.5  2004/02/17 23:07:36  lightweave * * Improved the DEBUG facillity and replaced the configuration handler with a * new code which now can read MS Windows INI style files. See CHANGES.txt for * more details. * Also added a macro which prevents compiling for kernels before 2.4.19. * * Revision 1.4  2003/06/18 22:00:22  lightweave * DEBUG and DEBUG_SERIAL added * * *****************************************************************************/static char *ident = "$Header: /cvsroot/pice/pice/module/debug.c,v 1.5 2004/02/17 23:07:36 lightweave Exp $";/*++Copyright (c) 1998-2001 Klaus P. GerlicherModule Name:    debug.cAbstract:    debug outputEnvironment:    LINUX 2.2.X    Kernel mode onlyAuthor:     Klaus P. GerlicherRevision History:    04-Feb-1999:    created    15-Nov-2000:    general cleanup of source filesCopyright notice:  This file may be distributed under the terms of the GNU Public License.--*/////////////////////////////////////////////////////// INCLUDES////#include "remods.h"#include <asm/io.h>#include <stdarg.h>#include "precomp.h"#include "serial.h" #include "serial_port.h"////////////////////////////////////////////////////// GLOBALS////LONG lDebugLevel = 1000;static spinlock_t ulDebugLock;static ULONG ulDebugFlags;USHORT usDebugPortBase;ULONG g_port,g_baudrate;static char tempDebug[1024];static char tempBuffer[1024];static UBYTE gDebugLevel[DBL_COUNT] = "IWE";#ifdef CONFIG_SMPstatic char tempPrefix[1024];#endif////////////////////////////////////////////////////// FUNCTIONS////void DebugSetupSerial(ULONG port, ULONG baudrate);//************************************************************************* // Pice_dprintf() // // internal debug print//************************************************************************* VOID PICE_dprintf(PCHAR File, PCHAR Function, int Line, DEBUG_TYPE DebugTyp, DEBUG_LEVEL DebugLevel, PCHAR DebugMessage, ...){	 if(debug_permission.Mode != DBG_NONE)	 {		  // Errors are always printed.		  if(DebugLevel != DBL_ERROR)		  {			   if(debug_permission.Permission[DebugTyp] == FALSE)					goto Quit;		  }	 }	 va_list ap;	 LONG i;	 va_start(ap, DebugMessage);	 spin_lock_irqsave(&ulDebugLock,ulDebugFlags);#ifdef CONFIG_SMP	 PICE_sdprintf(tempDebug, "[CPU #%u]: ", current->processor);#endif	 DebugSendByte('[');	 for(i = 0; i < debug_permission.Nesting; i++)		  DebugSendByte(' ');	 PICE_sdprintf("%s:%s:%u:%c] ", Function, File, Line, gDebugLevel[DebugLevel]);	 PICE_sprintf(tempBuffer,  "%s", DebugMessage);	 PICE_vsprintf(tempDebug, tempBuffer, ap);	 DebugSendString(tempDebug);	 spin_unlock_irqrestore(&ulDebugLock,ulDebugFlags);	 va_end(ap);Quit:	 return;}//************************************************************************// SendByte()//// Output a character to the serial port //************************************************************************BOOLEAN DebugSendByte(UCHAR x){   ULONG timeout;   timeout = 0x00FFFFL;   // Wait for transmitter to clear    while((inportb((USHORT)(usDebugPortBase + LSR)) & XMTRDY) == 0)   {		if(!(--timeout))		{			 // re-setup the COMM port			 DebugSetupSerial(g_port,g_baudrate);			 return FALSE;		}   }   outportb((USHORT)(usDebugPortBase + TXR), x);   return TRUE;}ULONG DebugPrintNumber(long num, int base, int size, int precision, int type){	 UBYTE str[100];	 	 PICE_number(str, num, base, size, precision, type); 	 return(DebugSendValidString(str));}//************************************************************************* // PICE_dsprint() //// This function is similar to dprintf with the difference that it works // only with valid strings and numbers. You can call this function from// anywhere to output strings to the debug port, but you have to make sure// that the memory is available as it doesn't check this and will crash if// not.//************************************************************************* VOID PICE_dprint(PCHAR File, PCHAR Function, int Line, DEBUG_TYPE DebugTyp, DEBUG_LEVEL DebugLevel, PCHAR DebugMessage, ...){	 if(debug_permission.Mode != DBG_NONE)	 {		  // Errors are always printed, otherwise we check if the report is valid.		  if(DebugLevel != DBL_ERROR)		  {			   if(debug_permission.Permission[DebugTyp] == FALSE)					goto Quit;		  }	 }	 va_list ap;	 LONG i;	 va_start(ap, DebugMessage);	 if(DebugTyp == DBT_FUNCTION)	 {		  if(DebugMessage[0] == 'E')			   debug_permission.Nesting++;	 }	 DebugSendByte('[');	 for(i = 0; i < debug_permission.Nesting; i++)		  DebugSendByte(' ');	 DebugSendValidString(Function);	 DebugSendByte(':');	 DebugSendValidString(File);	 DebugSendByte(':');	 DebugPrintNumber(Line, 10, -1, -1, 0);	 DebugSendByte(':');	 DebugSendByte(gDebugLevel[DebugLevel]);	 DebugSendValidString("] ");	 PICE_vdprintf(DebugMessage, ap);	 if(DebugTyp == DBT_FUNCTION)	 {		  if(DebugMessage[0] == 'L')			   debug_permission.Nesting--;	 }	 va_end(ap);Quit:	 return;}//************************************************************************* // DebugSendValidString() // // This function is intended to be used to print debug info when the normal// function doesn't work. The assumption here is, that the address is valid// and doesn't have to be checked.//************************************************************************* ULONG DebugSendValidString(UBYTE *str){	 ULONG rc = 0;     // We have to do this here the hard way, because we can not use     // normal functions as this will cause a recursion on most functions     // because they rely on IsAddressValid.#ifdef DEBUG_SERIAL	 while(*str != 0)	 {		  DebugSendByte(*str);		  str++;		  rc++;	 }#endif	 return(rc);}///************************************************************************// DebugSetSpeed()/////************************************************************************void DebugSendString(LPSTR s){    ULONG len = strlen(s),i;    for(i=0;i<len;i++)    {       DebugSendByte(s[i]);    }}///************************************************************************// DebugSetSpeed()/////************************************************************************void DebugSetSpeed(ULONG baudrate){    UCHAR c;    ULONG divisor;    divisor = (ULONG) (115200L/baudrate);    c = inportb((USHORT)(usDebugPortBase + LCR));    outportb((USHORT)(usDebugPortBase + LCR), (UCHAR)(c | 0x80)); // Set DLAB     outportb((USHORT)(usDebugPortBase + DLL), (UCHAR)(divisor & 0x00FF));    outportb((USHORT)(usDebugPortBase + DLH), (UCHAR)((divisor >> 8) & 0x00FF));    outportb((USHORT)(usDebugPortBase + LCR), c);          // Reset DLAB }///************************************************************************// DebugSetOthers()//// Set other communications parameters //************************************************************************void DebugSetOthers(ULONG Parity, ULONG Bits, ULONG StopBit){    ULONG setting;    UCHAR c;    if (usDebugPortBase == 0)					return ;    if (Bits < 5 || Bits > 8)				return ;    if (StopBit != 1 && StopBit != 2)			return ;    if (Parity != NO_PARITY && Parity != ODD_PARITY && Parity != EVEN_PARITY)							return;    setting  = Bits-5;    setting |= ((StopBit == 1) ? 0x00 : 0x04);    setting |= Parity;    c = inportb((USHORT)(usDebugPortBase + LCR));    outportb((USHORT)(usDebugPortBase + LCR), (UCHAR)(c & ~0x80)); // Reset DLAB     // no ints    outportb((USHORT)(usDebugPortBase + IER), (UCHAR)0);    outportb((USHORT)(usDebugPortBase + FCR), (UCHAR)0);    outportb((USHORT)(usDebugPortBase + LCR), (UCHAR)setting);    outportb((USHORT)(usDebugPortBase + MCR),  DTR | RTS);    return ;}///************************************************************************// DebugSetupSerial()/////************************************************************************void DebugSetupSerial(ULONG port,ULONG baudrate){	USHORT ports[]={COM1BASE,COM2BASE};    spin_lock_init(&ulDebugLock);    g_port = port;    g_baudrate = baudrate;    usDebugPortBase = ports[port-1];    DebugSetOthers(NO_PARITY,8,1);    DebugSetSpeed(baudrate);	debug_permission.Mode = DBG_SERIAL;	PICE_dprint(__FILE__, __FUNCTION__, __LINE__, DBT_DEBUG, DBL_INFO, "**** serial debug initialized ****\n");}// EOF

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -