コード例 #1
0
void stacktrace(){
	unsigned long framePointer;
	unsigned long savedEIP;
	unsigned long lowPC;
	unsigned long highPC;
	int functionFound = 0;
	int functionCount = 0;
	char * functionName;
	char * fileName;
	Dwarf_Die functionDie;

	// Find our current Function
	functionDie = dwarf_get_next_function(compilation_unit->root_die,compilation_unit);
	savedEIP = findAddress(CURRENT_EIP);
	while(!functionFound){
		lowPC = dwarf_function_starting_address(functionDie,compilation_unit);
		highPC = dwarf_function_ending_address(functionDie,compilation_unit);
		if((savedEIP >= lowPC) && (savedEIP < highPC)){
			fileName = dwarf_get_name(compilation_unit->root_die,compilation_unit);
			functionName = dwarf_get_name(functionDie,compilation_unit);
			printf("#%d %s(",functionCount,functionName);
			printPassedVariable(functionDie);
			printf(") at %s:%d\n",fileName,findLineNumber(savedEIP));
			functionFound = 1;
			++functionCount;
		}
		else
			functionDie = dwarf_get_next_function(functionDie,compilation_unit);
	}
	functionFound = 0;

	framePointer = findAddress(FRAME_POINTER);
	while(ptrace(PTRACE_PEEKTEXT,child,framePointer,NULL) != 0){
		savedEIP = ptrace(PTRACE_PEEKTEXT,child,framePointer+4,NULL);	// Give us our old EBP
		framePointer = ptrace(PTRACE_PEEKTEXT,child,framePointer,NULL);

		// Now look for function DIE
		functionDie = dwarf_get_next_function(compilation_unit->root_die,compilation_unit);
		while(!functionFound){
			lowPC = dwarf_function_starting_address(functionDie,compilation_unit);
			highPC = dwarf_function_ending_address(functionDie,compilation_unit);
			if((savedEIP >= lowPC) && (savedEIP < highPC)){
				fileName = dwarf_get_name(compilation_unit->root_die,compilation_unit);
				functionName = dwarf_get_name(functionDie,compilation_unit);
				printf("#%d %s() at %s:%d\n",functionCount,functionName,fileName,findLineNumber(savedEIP));
				functionFound = 1;
			}
			else
				functionDie = dwarf_get_next_function(functionDie,compilation_unit);
		}
		functionFound = 0;
	}
}
コード例 #2
0
ファイル: htmlPage.c プロジェクト: elmargb/kentUtils
static void tagVaWarn(struct htmlPage *page, struct htmlTag *tag, char *format, 
	va_list args)
/* Print warning message and some context of tag. */
{
char context[80];
strncpy(context, tag->start, sizeof(context));
context[sizeof(context)-1] = 0;
warn("Error near line %d of %s:\n %s", findLineNumber(page->htmlText, tag->start), 
	page->url, context);
vaWarn(format, args);
}