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

📄 output.c

📁 Linux下的类似softice的调试工具
💻 C
字号:
/****************************************************************************** * * Copyright (c) 2003 Gerhard W. Gruber * * PROJECT: pICE * $Source: /cvsroot/pice/pice/module/output.c,v $ * $Revision: 1.5 $ * $Date: 2004/02/17 23:07:36 $ * $Author: lightweave $ * $Name:  $ * * $Log: output.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/output.c,v 1.5 2004/02/17 23:07:36 lightweave Exp $";/*++Copyright (c) 1998-2001 Klaus P. GerlicherModule Name:    output.cAbstract:    catch debugging outputsEnvironment:    Kernel mode onlyAuthor:     Klaus P. GerlicherRevision History:    14-Nov-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 <linux/sched.h>#include <asm/io.h>#include <asm/page.h>#include <asm/pgtable.h>#include <linux/utsname.h>#include <linux/sched.h>#include <linux/console.h>#include <asm/delay.h>#include "precomp.h"static char tempOutput[1024],tempOutput2[1024];ULONG ulCountTimerEvents = 0;struct timer_list sPiceRunningTimer;ULONG ulPrintk=0;BOOLEAN bInPrintk = FALSE;BOOLEAN bIsDebugPrint = FALSE;#ifdef ACTIVATE_PRINTK_OVERRIDEasmlinkage int printk(const char *fmt, ...);EXPORT_SYMBOL(printk);//************************************************************************* // printk() // // this function overrides printk() in the kernel//************************************************************************* asmlinkage int printk(const char *fmt, ...){	ULONG len;    static ULONG ulOldJiffies = 0;	va_list args;	va_start(args, fmt);	if((len = PICE_strlen((LPSTR)fmt)) )	{		PICE_vsprintf(tempOutput, fmt, args);		bIsDebugPrint = TRUE;        // if the last debug print was longer than 5 timer ticks ago        // directly print it, else just add it to the ring buffer        // and let the timer process it.        if( (jiffies-ulOldJiffies) > (1*wWindow[OUTPUT_WINDOW].cy)/2)        {            ulOldJiffies = jiffies;		    Print(OUTPUT_WINDOW,tempOutput);        }        else        {		    AddToRingBuffer(tempOutput);        }		bIsDebugPrint = FALSE;	}	va_end(args);    return 0;}#endif // ACTIVATE_PRINTK_OVERRIDE//************************************************************************* // CountArgs() // // count occurrence of '%' in format string (except %%)// validity of whole format string must have been enforced//************************************************************************* ULONG CountArgs(LPSTR fmt){	ULONG count=0;	while(*fmt)	{		if(*fmt=='%' && *(fmt+1)!='%')			count++;		fmt++;	}	return count;}//************************************************************************* // PrintkCallback() // // called from HandleEntry() when processing INT3 placed//************************************************************************* void PrintkCallback(EXCEPTION_FRAME* pFrame){	LPSTR fmt,args;	ULONG ulAddress;	ULONG countArgs,i,len;	bInPrintk = TRUE;	// get the linear address of stack where string resides	ulAddress = GetLinearAddress(pFrame->ss,pFrame->esp);	if(ulAddress)	{		if(IsAddressValid(ulAddress+sizeof(char *)) )		{			fmt = (LPSTR)*(PULONG)(ulAddress+sizeof(char *));			// validate format string			if((len = PICE_strlen(fmt)) )			{				// skip debug prefix if present				if(len>=3 && *fmt=='<' && *(fmt+2)=='>')					fmt += 3;				if((countArgs = CountArgs(fmt))>0)				{										args = (LPSTR)(ulAddress+2*sizeof(char *));					if(IsAddressValid((ULONG)args))					{						// validate passed in args						for(i=0;i<countArgs;i++)						{							if(!IsRangeValid((ULONG)(args+i*sizeof(ULONG)),sizeof(ULONG)) )							{								PICE_sprintf(tempOutput,"printk(%s): argument #%u is not valid!\n",(LPSTR)fmt,i);								Print(OUTPUT_WINDOW,tempOutput);								bInPrintk = FALSE;								return;							}						}						PICE_vsprintf(tempOutput2, fmt, args);					}					else					{						Print(OUTPUT_WINDOW,"printk(): ARGS are passed in but not valid!\n");					}				}				else				{					PICE_strcpy(tempOutput2, fmt);				}    		    AddToRingBuffer(tempOutput2);			}		}	}	bInPrintk = FALSE;}//************************************************************************* // PiceRunningTimer() // //************************************************************************* void PiceRunningTimer(unsigned long param){	void DebuggerTimer(void);    if(ulCountTimerEvents++ > 10)    {        ulCountTimerEvents = 0;		DebuggerTimer();    }    mod_timer(&sPiceRunningTimer,jiffies + HZ/10);}//************************************************************************* // InitPiceRunningTimer() // //************************************************************************* void InitPiceRunningTimer(void){#ifdef ACTIVATE_TIMER    ENTER_FUNC();	if((eTerminalMode == TERMINAL_MODE_HERCULES_GRAPHICS) ||		(eTerminalMode == TERMINAL_MODE_HERCULES_TEXT) )	{		init_timer(&sPiceRunningTimer);		sPiceRunningTimer.data = 0;		sPiceRunningTimer.function = PiceRunningTimer;		sPiceRunningTimer.expires = jiffies + HZ;		add_timer(&sPiceRunningTimer);	}    LEAVE_FUNC();#endif // ACTIVATE_TIMER}//************************************************************************* // RemovePiceRunningTimer() // //************************************************************************* void RemovePiceRunningTimer(void){#ifdef ACTIVATE_TIMER    ENTER_FUNC();	if((eTerminalMode == TERMINAL_MODE_HERCULES_GRAPHICS) ||		(eTerminalMode == TERMINAL_MODE_HERCULES_TEXT) )	{		del_timer(&sPiceRunningTimer);	}    LEAVE_FUNC();#endif //ACTIVATE_TIMER}//************************************************************************* // InstallPrintkHook() // //************************************************************************* void InstallPrintkHook(void){#ifdef ACTIVATE_PRINTK_HOOK    ENTER_FUNC();    ScanSystemMap("printk",(PULONG)&ulPrintk);    if(ulPrintk)    {        InstallSWBreakpoint(ulPrintk,TRUE,PrintkCallback);    }    LEAVE_FUNC();#endif // ACTIVATE_PRINTK_HOOK}//************************************************************************* // DeInstallPrintkHook() // //************************************************************************* void DeInstallPrintkHook(void){#ifdef ACTIVATE_PRINTK_HOOK    ENTER_FUNC();    if(ulPrintk)    {		// will be done on exit debugger        DeInstallSWBreakpoint(ulPrintk);    }    LEAVE_FUNC();#endif // ACTIVATE_PRINTK_HOOK}

⌨️ 快捷键说明

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