Yahoo Groups archive

Lpc2000

Index last updated: 2026-04-28 23:31 UTC

Thread

undef exception analysis

undef exception analysis

2005-11-30 by gm_muc

Hello,   
   
in my application I sporadically get UNDEFINED exceptions, though   
running from internal flash (LPC2138).   
   
Is there any public (assembler) source code available to analyze the   
stack for the location of the particular instruction causing the   
exception?  
   
Any general hints about the cause of such an exception, except the   
PC somehow gone to the woods, are appreciated...  
  
Gunter

RE: [lpc2000] undef exception analysis

2005-11-30 by Joel Winarske

> Any general hints about the cause of such an exception, except the
> PC somehow gone to the woods, are appreciated...

I seem to recall seeing when porting some AVR code.  It was calling a
function via pointer that was defined as NULL.

I'm curious what else triggers this.


Joel

Re: [lpc2000] undef exception analysis

2005-11-30 by 42Bastian Schick

Joel Winarske <joelw@...> schrieb am Wed, 30 Nov 2005 
02:14:46 -0800:

>> Any general hints about the cause of such an exception, except the
>> PC somehow gone to the woods, are appreciated...
>
> I seem to recall seeing when porting some AVR code.  It was calling a
> function via pointer that was defined as NULL.
>
> I'm curious what else triggers this.

A simple stack corruption.

void d(void);

void func(void)
{
	int a[2];
	d();			/* forces pushing of LR */
	a[2] = 0;
}

compile with:
arm-thumb-elf-gcc -fomit-frame-pointer -S -mthumb
you get:
         .code   16
         .file   "t.c"
         .text
         .align  2
         .global f
         .code 16
         .thumb_func
         .type   f, %function
f:
         push    {lr}
         sub     sp, sp, #8
         bl      d
         mov     r2, sp
         mov     r3, #0
         str     r3, [r2, #8]
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

         add     sp, sp, #8
         @ sp needed for prologue
         pop     {pc}
         .size   f, .-f
         .ident  "GCC: (GNU) 3.4.4"


Normaly not that obvious coded :-)

-- 
42Bastian Schick

Re: undef exception analysis

2005-11-30 by gm_muc

--- In lpc2000@yahoogroups.com, 42Bastian Schick <bastian42@m...>  
wrote:  
>   
> A simple stack corruption.  
>   
  
That was it: An intelligent piece of HW replied with a "cannot  
happen (TM)" number of bytes, and the following copy routine 
exceeded the array boundaries, and hence clobbered the stack.  
  
I am still interested to see some piece of code to dissect the stack  
when a UNDEF exception occurs, so I can pinpoint the cause more  
easily....   
  
> Normaly not that obvious coded :-)  
  
Exactly.... :-)  
  
Gunter

Re: [lpc2000] Re: undef exception analysis

2005-11-30 by 42Bastian Schick

gm_muc <ml@...> schrieb am Wed, 30 Nov 2005 14:22:57 -0000:

> I am still interested to see some piece of code to dissect the stack
> when a UNDEF exception occurs, so I can pinpoint the cause more
> easily....

Look at r14 (lr), it is the address of the insn which caused it or due to 
the pipeline 4 bytes behind.

-- 
42Bastian Schick

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.