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

📄 strace_cf.c

📁 umon bootloader source code, support mips cpu.
💻 C
字号:
/* strace.c:
 *
 *  Coldfire Stack Trace
 *
 *	General notice:
 *	This code is part of a boot-monitor package developed as a generic base
 *	platform for embedded system designs.  As such, it is likely to be
 *	distributed to various projects beyond the control of the original
 *	author.  Please notify the author of any enhancements made or bugs found
 *	so that all may benefit from the changes.  In addition, notification back
 *	to the author will allow the new user to pick up changes that may have
 *	been made by other users after this version of the code was distributed.
 *
 *	Note1: the majority of this code was edited with 4-space tabs.
 *	Note2: as more and more contributions are accepted, the term "author"
 *		   is becoming a mis-representation of credit.
 *
 *	Original author:	Ed Sutter
 *	Email:				esutter@lucent.com
 *	Phone:				908-582-2351
 *
 */
#include "config.h"
#if INCLUDE_STRACE
#include "tfs.h"
#include "tfsprivate.h"
#include "ctype.h"
#include "genlib.h"
#include "stddefs.h"
#include "cpu.h"

char *StraceHelp[] = {
    "Stack trace",
    "-[d:F:P:rs:v]",
    " -d #   max depth count (def=20)",
    " -F #   specify frame-pointer (don't use content of A6)",
    " -P #   specify PC (don't use content of PC)",
    " -r     dump regs",
    " -v     verbose",
    0,
};

int
Strace(int argc,char *argv[])
{
	char	*symfile, fname[64];
	TFILE	*tfp;
	ulong	*framepointer, pc, fp, offset;
    int		tfd, opt, maxdepth, pass, verbose, bullseye;

	tfd = fp = 0;
	maxdepth = 20;
	verbose = 0;
	pc = ExceptionAddr;
    while ((opt=getopt(argc,argv,"d:F:P:rs:v")) != -1) {
		switch(opt) {
		case 'd':
			maxdepth = atoi(optarg);
			break;
		case 'F':
			fp = strtoul(optarg,0,0);
			break;
		case 'P':
			pc = strtoul(optarg,0,0);
			break;
		case 'r':
			showregs();
			break;
		case 'v':
			verbose = 1;
			break;
	    default:
			return(0);
		}
	}
	
	if (!fp)
		getreg("A6", (ulong *)&framepointer);
	else
		framepointer = (ulong *)fp;

	/* Start by detecting the presence of a symbol table file... */
	symfile = getenv("SYMFILE");
	if (!symfile)
		symfile = SYMFILE;

	tfp = tfsstat(symfile);
	if (tfp)  {
		tfd = tfsopen(symfile,TFS_RDONLY,0);
		if (tfd < 0)
			tfp = (TFILE *)0;
	}

	/* Show current position: */
	printf("   0x%08lx",pc);
	if (tfp) {
		AddrToSym(tfd,pc,fname,&offset);
		printf(": %s()",fname);
		if (offset)
			printf(" + 0x%lx",offset);
	}
	putchar('\n');

	/* Now step through the stack frame... */
	bullseye = pass = 0;
	while(maxdepth) {
		/* If this is the top of the frame (pass == 0) and the
		 * offset is zero (indicating that trap occurred at the
		 * exact address of the function), then we need to 
		 * deal with this in a slightly different way...
		 */
		if ((pass == 0) && (offset == 0)) {
			ulong *sp;

			getreg("SP", (ulong *)&sp);
			pc = *(sp + 2);
			bullseye = 1;
			if (verbose)
				printf("BULLSEYE\n");
		}
		else if (bullseye) {
			pc = *(framepointer + 1);
			bullseye = 0;
		}
		else {
			if (pass != 0)
				framepointer = (ulong *)*framepointer;

			pc = *(framepointer + 1);
		}

		if (verbose) {
			printf("fp=0x%lx,*fp=0x%lx,pc=%lx\n", (ulong)framepointer,
				(ulong)*framepointer,pc);
		}

		if (((ulong)framepointer & 3) || (!framepointer) ||
			(!*framepointer) || (!pc)) {
			break;
		}

		printf("   0x%08lx",pc);
		if (tfp) {
			int match;

			match = AddrToSym(tfd,pc,fname,&offset);
			printf(": %s()",fname);
			if (offset)
				printf(" + 0x%lx",offset);
			if ((!match) || (!strcmp(fname,"start"))) {
				putchar('\n');
				break;
			}
		}
		putchar('\n');
		maxdepth--;
		pass++;
	}

	if (!maxdepth)
		printf("Max depth termination\n");
	
	if (tfp) {
		tfsclose(tfd,0);
	}
    return(0);
}

#endif

⌨️ 快捷键说明

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