1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/misc/exc.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,125 @@
1.4 +// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// e32test\misc\exc.cpp
1.18 +// Utility generating various kinds of exceptions. Useful to test
1.19 +// debuggers.
1.20 +//
1.21 +//
1.22 +
1.23 +#include <e32std.h>
1.24 +#include <e32std_private.h>
1.25 +
1.26 +void InfiniteRecursion()
1.27 + {
1.28 + InfiniteRecursion();
1.29 + }
1.30 +
1.31 +#ifdef __ARMCC__
1.32 +#pragma Ono_inline // prevent compile time errors
1.33 +#endif
1.34 +void Store42(TInt*& p)
1.35 + {
1.36 + *p = 42;
1.37 + }
1.38 +
1.39 +void Foo()
1.40 + {
1.41 + // uninitialised pointer on stack - may not crash
1.42 + TInt* p;
1.43 + Store42(p);
1.44 + }
1.45 +void Foo1(TUint8 *ps)
1.46 + {
1.47 + TInt32* p = (TInt32*)ps;
1.48 + *p = 0x42;
1.49 + }
1.50 +void Foo2(TUint8 *ps)
1.51 + {
1.52 + TInt16* p = (TInt16*)ps;
1.53 + *p = 0x42;
1.54 + }
1.55 +
1.56 +TInt E32Main()
1.57 + {
1.58 + TBuf<32> cmd;
1.59 + User::CommandLine(cmd);
1.60 + TLex lex(cmd);
1.61 + TInt n=0;
1.62 + lex.Val(n);
1.63 +
1.64 + typedef void (*TPfn)();
1.65 +
1.66 + switch (n)
1.67 + {
1.68 + default:
1.69 + case 0:
1.70 + {
1.71 + // data abort - accessing non-existent memory
1.72 + TInt* p = (TInt*) 0x1000;
1.73 + *p = 0x42;
1.74 + }
1.75 + break;
1.76 + case 1:
1.77 + // data abort - stack overflow
1.78 + InfiniteRecursion();
1.79 + break;
1.80 + case 2:
1.81 + {
1.82 + // data abort - pointer in deleted heap cell
1.83 + // May not crash on UREL builds
1.84 + struct S { TInt* iPtr; };
1.85 + S* p = new S;
1.86 + p->iPtr = new TInt;
1.87 + delete p->iPtr;
1.88 + delete p;
1.89 + *(p->iPtr) = 42;
1.90 + }
1.91 + break;
1.92 + case 3:
1.93 + // data abort - uninitialised pointer on stack
1.94 + Foo();
1.95 + break;
1.96 + case 4:
1.97 + {
1.98 + // data abort - misaligned access to 32 bit word
1.99 + TUint8 buffer[16];
1.100 + Foo1(buffer+2);
1.101 + }
1.102 + break;
1.103 + case 5:
1.104 + {
1.105 + // data abort - misaligned access to 16 bit word
1.106 + TUint8 buffer[16];
1.107 + Foo2 (buffer+1);
1.108 + }
1.109 + break;
1.110 + case 6:
1.111 + {
1.112 + // prefetch abort
1.113 + TPfn f = NULL;
1.114 + f();
1.115 + }
1.116 + break;
1.117 + case 7:
1.118 + {
1.119 + // undefined instruction
1.120 + TUint32 undef = 0xE6000010;
1.121 + TPfn f = (TPfn) &undef;
1.122 + f();
1.123 + }
1.124 + break;
1.125 + }
1.126 +
1.127 + return 0;
1.128 + }