00001 /* 00002 * Copyright (C) 2008 by Duane Ellis 00003 * 00004 * All rights reserved. 00005 * 00006 * The original code had been released as part of the LoastARM Project 00007 * under GPL Version 2 and is published here under the following license 00008 * with kind permission from the author: 00009 * 00010 * Redistribution and use in source and binary forms, with or without 00011 * modification, are permitted provided that the following conditions 00012 * are met: 00013 * 00014 * 1. Redistributions of source code must retain the above copyright 00015 * notice, this list of conditions and the following disclaimer. 00016 * 2. Redistributions in binary form must reproduce the above copyright 00017 * notice, this list of conditions and the following disclaimer in the 00018 * documentation and/or other materials provided with the distribution. 00019 * 3. Neither the name of the copyright holders nor the names of 00020 * contributors may be used to endorse or promote products derived 00021 * from this software without specific prior written permission. 00022 * 00023 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00024 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00025 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00026 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00027 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00028 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00029 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 00030 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 00031 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00032 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 00033 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00034 * SUCH DAMAGE. 00035 * 00036 * For additional information see http://lostarm.sourceforge.net/ 00037 */ 00038 00047 #include <stdio.h> 00048 #include <sys/ptrace.h> 00049 00050 #include <arch/arm/ptrace.h> 00051 00052 /* 00053 * The original code doesn't work for Nut/OS. Without understanding 00054 * the underlying frame layout, I found the solution by trial and 00055 * error. I assume, that the difference between Nut/OS and LostARM 00056 * is caused by compile options. 00057 * 00058 * This early release had been tested with an AT91SAM7SE512 (EIR 1.0C) 00059 * and data abort exceptions only. 00060 * 00061 * For Nut/OS we are save to use DEV_DEBUG with stdio. 00062 */ 00063 void 00064 ptrace_stackdump_from( const int *fp ) 00065 { 00066 int depth; 00067 const int *newfp; 00068 int pc; 00069 00070 puts("Backtrace:"); 00071 /* Added for Nut/OS. No idea why this is required. */ 00072 fp = (int *)fp[-4]; 00073 for(depth = 0; fp != NULL; depth++){ 00074 /* LostARM references fp[-1]. Why this differs? */ 00075 pc = fp[0]; 00076 printf(" %d) 0x%08x\n", depth, pc); 00077 00078 newfp = (const int *)fp[-3]; 00079 /* is new frame pointer some what valid? */ 00080 if( (newfp <= fp) || (newfp > &(fp[1024])) ){ 00081 /* no, then stop */ 00082 break; 00083 } 00084 fp = newfp; 00085 } 00086 } 00087 00088 void 00089 ptrace_stackdump_regs( struct pt_regs *p ) 00090 { 00091 ptrace_dump_regs( p ); 00092 ptrace_stackdump_from( (int *)(p->uregs[ PTRACE_R13_idx ]) ); 00093 } 00094 00095 void 00096 ptrace_stackdump_here( void ) 00097 { 00098 const int *fp; 00099 asm volatile ("mov %0,fp\n" : "=r" (fp) ); 00100 00101 ptrace_stackdump_from( fp ); 00102 }