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

📄 trclib.c

📁 VxWorks BSP框架源代码包含头文件和驱动
💻 C
📖 第 1 页 / 共 2 页
字号:
/* trcLib.c - MC680X0 stack trace library *//* Copyright 1984-2002 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------02a,18jan02,aeg  added 1 byte to name buffer passed to symFindByValue().01z,12may95,p_m  adapted to support host based tt().01y,15oct92,kdl  made trcCountArgs recognized multiple ADDQ's at return addr		 (SPR #1650).01x,24sep92,yao  made document consistent with change 01u.01w,14sep92,yao  made trcStack NOMANUAL.01v,26may92,rrr  the tree shuffle01u,30mar92,yao  added third paramatet tid to trcStack().  changed copyright		 notice.  shut up ANSI warnings.01t,04oct91,rrr  passed through the ansification filter                  -changed functions to ansi style		  -changed VOID to void		  -changed copyright notice01s,20may91,jdi  documentation tweaks.01r,30mar91,jdi  documentation cleanup; doc review by dnw.01q,10jun90,dnw  changed to print default number of args (5) if unable to		   determine actual number from call.  default args shown as		   "([..])".		 improved ability to trace without LINK by using symbol tbl01p,10aug90,dnw  added forward declarations for void functions.01o,15jcf90,jcf  changed symbol type to SYM_TYPE.01n,09aug89,gae  fixed documentation example for taskRegsGet.01m,30may88,dnw  changed to v4 names.01l,27jan88,jcf  documentation.01k,04nov87,ecs  documentation.01j,01apr87,ecs  minor documentation about vxTaskRegs in trcStack.01i,24mar87,jlf  documentation01h,19mar87,ecs  fixed bug in trcStack introduced in 01g. Did this by moving		    test for NULL fp from trcStack to trcStackLvl.		 removed unnecessary sp parameter from trcStackLvl.01g,25feb87,ecs  changed trcFollowBra to not follow branches to odd addresses,		    nor to follow (immediately) circular branches.		 changed trcCountArgs to say "8" when confronted with		    MOVE.L (xxx,A6),A7.		 added includes of symLib.h and sysSymTbl.h.		 changed trcFindFuncStart to use symbol table as a lower bound.01f,21dec86,dnw  changed handling of NULL print routine to appease Green Hills.		 changed to not get include files from default directories.01e,05dec86,ecs  fixed trcCountArgs to handle MOVE.L xxx,(A7).01d,18nov86,llk  fixed trcCountArgs.  Gets the number of args for ADDQ.W.01c,27jul86,llk  prints error messages to standard error (uses printErr)01b,02jul86,dnw  deleted obsolete trcTask() and trcTaskXP() routines.		 documentation.01a,03mar86,dnw  extracted from dbgLib.c		 changed to handle routines that start w/BRA to LINK.		 fixed bug of not handling negative displacements in BRAs.		 changed to handle 68020 32-bit displacement form of BRAs.*//*This module provides a routine, trcStack(), which traces a stackgiven the current frame pointer, stack pointer, and program counter.The resulting stack trace lists the nested routine calls and their arguments.This module provides the low-level stack trace facility.A higher-level symbolic stack trace, implemented on top of this facility,is provided by the routine tt() in dbgLib.SEE ALSO: dbgLib, tt(),.pG "Debugging"*/#include "vxWorks.h"#include "regs.h"#include "stdio.h"#include "symLib.h"#include "sysSymTbl.h"#include "private/funcBindP.h"#define MAX_TRACE_DEPTH 40 /* maximum number of levels of stack to trace *//* instruction words */#define LINK_A6		0x4e56		/* LINK A6,... */#define RTS		0x4e75		/* RTS */#define JSR_ABS		0x4eb9		/* JSR abs */#define ADD_W		0xdefc		/* ADD.W */#define ADD_L		0xdffc		/* ADD.L */#define ADDQ_W		0x504f		/* ADDQ.W A7 */#define ADDQ_L		0x508f		/* ADDQ.L A7 */#define LEA_A7		0x4fef		/* LEA $x(A7),A7 */#define MOVE_L_A7	0x2e80		/* MOVE.L xxx,(A7) */#define MOVE_L_A6_A7	0x2e75		/* MOVE.L (xxx,A6),A7 *//* globals */int trcDefaultArgs = 5;			/* default # of args to print if trc					 * can't figure out how many *//* forward static functions */static void trcStackLvl (int *fp, INSTR *pc, int depth, FUNCPTR printRtn);static void trcDefaultPrint (INSTR *callAdrs, INSTR *funcAdrs, int nargs, int		*args);static INSTR *trcFindCall (INSTR *returnAdrs);static INSTR *trcFindDest (INSTR *callAdrs);static int trcCountArgs (INSTR *returnAdrs);static INSTR *trcFindFuncStart (int *fp, INSTR *pc);static INSTR *trcFollowBra (INSTR *adrs);/********************************************************************************* trcStack - print a trace of function calls from the stack** This routine provides the low-level stack trace function.  A higher-level* symbolic stack trace, built on top of trcStack(), is provided by tt() in* dbgLib.** This routine prints a list of the nested routine calls that are on the* stack, showing each routine with its parameters.** The stack being traced should be quiescent.  The caller should avoid* tracing its own stack.** PRINT ROUTINE* In order to allow symbolic or alternative printout formats, the call to* this routine includes the <printRtn> parameter, which specifies a* user-supplied routine to be called at each nesting level to print out the* routine name and its arguments.  This routine should be declared as* follows:* .ne 7* .CS*     void printRtn (callAdrs, rtnAdrs, nargs, args)*         INSTR  *callAdrs;  /@ address from which routine was called **         int    rtnAdrs;    /@ address of routine called **         int    nargs;	     /@ number of arguments in call **         int    *args;	     /@ pointer to arguments ** .CE* If <printRtn> is NULL, a default routine will be used that prints out just* the call address, the function address, and the arguments as hexadecimal* values.** CAVEAT* In order to do the trace, a number of assumptions are made.  In general,* the trace will work for all C language routines and for assembly language* routines that start with a LINK instruction.  Most VxWorks assembly* language routines include LINK instructions for exactly this reason.* However, routines written in other languages, strange entries into* routines, or tasks with corrupted stacks can confuse the trace.  Also, all* parameters are assumed to be 32-bit quantities, therefore structures* passed as parameters will be displayed as a number of long integers.** .ne 14* EXAMPLE* The following sequence can be used to trace a VxWorks task given a pointer* to the task's TCB:* .CS* REG_SET regSet;  /@ task's data registers *** taskRegsGet (taskId, &regSet);* trcStack (&regSet, (FUNCPTR)NULL, taskId);* .CE** RETURNS: N/A** SEE ALSO: tt()** NOMANUAL*/void trcStack    (    REG_SET *pRegSet,		/* pointer to register set */    FUNCPTR printRtn,           /* routine to print single function call */    int     tid			/* task's id */    )    {    int		val;			/* address gotten from symbol table */    char	name[MAX_SYS_SYM_LEN + 1]; /* string associated with val */    SYM_TYPE	type;			/* type associated with val */    INSTR	instr;			/* next instruction */    int		stackSave;    FAST INSTR *pc = pRegSet->pc;    FAST int *fp = (int *) pRegSet->fpReg;    FAST int *sp = (int *) pRegSet->spReg;    /* use default print routine if none specified */    if (printRtn == NULL)	printRtn = (FUNCPTR) trcDefaultPrint;    /*     * if the current routine doesn't have a stack frame, then we fake one     * by putting the old one on the stack and making fp point to that;     * we KNOW we don't have a stack frame in a few restricted but useful     * cases:     *  1) we are at a LINK or RTS instruction,     *  2) we are the first instruction of a subroutine (this may NOT be     *     a LINK instruction with some compilers)     */    instr = *trcFollowBra (pc);    if ((instr == LINK_A6) || (instr == RTS) ||        ((sysSymTbl != NULL) && (_func_symFindByValue != NULL) &&	 ((* _func_symFindByValue) (sysSymTbl, (int) pc, name, 				    &val, &type) == OK) &&	 (val == (int) pc)))	{	/* no stack frame - fake one */	stackSave = *(sp - 1);		/* save value we're going to clobber */	*(sp - 1) = (int)fp;		/* make new frame pointer by */					/* sticking old one on stack */	fp = sp - 1;			/* and pointing to it */	trcStackLvl (fp, pc, 0, printRtn);	/* do stack trace */	*(sp - 1) = stackSave;		/* restore stack */	}    else	{	trcStackLvl (fp, pc, 0, printRtn);	/* do stack trace */	}    }/************************************************************************** trcStackLvl - recursive stack trace routine** This routine is recursive, being called once for each level of routine* nesting.  The maximum recursion depth is limited to 40 to prevent* garbage stacks from causing this routine to continue unbounded.* The "depth" parameter on the original call should be 0.*/LOCAL void trcStackLvl    (    FAST int *fp,       /* stack frame pointer (A6) */    INSTR *pc,          /* program counter */    int depth,          /* recursion depth */    FUNCPTR printRtn    /* routine to print single function call */    )    {    FAST INSTR *returnAdrs;    if (fp == NULL)	return;			/* stack is untraceable */    returnAdrs = (INSTR *) *(fp + 1);    /* handle oldest calls first, up to MAX_TRACE_DEPTH of them */    if ((*fp != NULL) && (depth < MAX_TRACE_DEPTH))	trcStackLvl ((int *) *fp, returnAdrs, depth + 1, printRtn);    (* printRtn) (trcFindCall (returnAdrs), trcFindFuncStart (fp, pc),		  trcCountArgs (returnAdrs), fp + 2);    }/********************************************************************************* trcDefaultPrint - print a function call** This routine is called by trcStack() to print each level in turn.** If nargs is specified as 0, then a default number of args (trcDefaultArgs)* is printed in brackets ("[..]"), since this often indicates that the* number of args is unknown.*/LOCAL void trcDefaultPrint    (    INSTR *callAdrs,            /* address from which function was called */    INSTR *funcAdrs,            /* address of function called */    FAST int nargs,             /* number of arguments in function call */    int *args                   /* pointer to function args */    )    {    FAST int ix;    BOOL doingDefault = FALSE;    /* if there is no printErr routine do nothing */

⌨️ 快捷键说明

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