; ; calltrace ; ; Display a backtrace of the call stack ; ; © 1994-1998 Straylight ; ;----- Licensing note ------------------------------------------------------- ; ; This file is part of Straylight's Steel library. ; ; Steel is free software; you can redistribute it and/or modify ; it under the terms of the GNU General Public License as published by ; the Free Software Foundation; either version 2, or (at your option) ; any later version. ; ; Steel is distributed in the hope that it will be useful, ; but WITHOUT ANY WARRANTY; without even the implied warranty of ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ; GNU General Public License for more details. ; ; You should have received a copy of the GNU General Public License ; along with Steel. If not, write to the Free Software Foundation, ; 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. GET libs:header GET libs:swis IMPORT |_kernel_unwind| IMPORT |_kernel_procname| AREA |C$$Code|,CODE,READONLY 99 DCB "_calltrace",0 ALIGN DCD &FF000000+{PC}-%b99 EXPORT |_calltrace| |_calltrace| ROUT MOV ip,sp STMFD sp!,{fp,ip,lr,pc} SUB fp,ip,#4 SUB sp,sp,#20 ;Make a small buffer ; --- Start displaying the command window --- ADR a1,wintitle SWI Wimp_CommandWindow SWI XOS_WriteI+14 ; --- Set up dunny `frame pointer' --- MOV ip,fp 00 ; --- Print address from which it's called --- LDR a1,[ip,#-4] ;Get the link regiser BIC a1,a1,#&FC000003 ;Strip off saved PSR SUB a1,a1,#4 ;Find the call address MOV a2,sp ;Point to the buffer MOV a3,#20 ;Buffer size SWI XOS_ConvertHex8 ;Convert the address SWI XOS_Write0 ;Display it on screen SWI XOS_WriteI+' ' SWI XOS_WriteI+'(' ; --- Print procedure name --- LDR ip,[ip,#-12] LDR a4,[ip,#0] ;Where's the stacked pc? BIC a4,a4,#&FC000003 ;Mask off the PSR bits SUB a4,a4,#20 ;Point to procedure word LDR a2,[a4,#0] ;And load it AND a3,a2,#&FF000000 ;Check the top byte is right CMP a3,#&FF000000 ;Is it the right pattern? BICEQ a3,a2,#&FF000000 ;Yes: Find the string length SUBEQ a1,a4,a3 ; Point to the proc name ADRNE a1,anon ;No: Point to `anonymous' SWI XOS_Write0 ;Display the procedure name SWI XOS_WriteI+')' SWI XOS_NewLine ;Move on to next line ; --- Unwind the stack another level --- LDR a1,[ip,#-12] ;Get the stacked frame ptr CMP a1,#0 ;Is there a real stack frame? BNE %00 ;Yes -- dump that one out ; --- Turn the command window off --- 01 SWI Wimp_CommandWindow LDMDB fp,{fp,sp,pc}^ wintitle DCB "Stack backtrace",0 anon DCB "Anonymous function",0 LTORG END