author | sl |
Tue, 10 Jun 2014 14:32:02 +0200 | |
changeset 1 | 260cb5ec6c19 |
permissions | -rw-r--r-- |
sl@0 | 1 |
// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). |
sl@0 | 2 |
// All rights reserved. |
sl@0 | 3 |
// This component and the accompanying materials are made available |
sl@0 | 4 |
// under the terms of the License "Eclipse Public License v1.0" |
sl@0 | 5 |
// which accompanies this distribution, and is available |
sl@0 | 6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html". |
sl@0 | 7 |
// |
sl@0 | 8 |
// Initial Contributors: |
sl@0 | 9 |
// Nokia Corporation - initial contribution. |
sl@0 | 10 |
// |
sl@0 | 11 |
// Contributors: |
sl@0 | 12 |
// |
sl@0 | 13 |
// Description: |
sl@0 | 14 |
// e32test\misc\exc.cpp |
sl@0 | 15 |
// Utility generating various kinds of exceptions. Useful to test |
sl@0 | 16 |
// debuggers. |
sl@0 | 17 |
// |
sl@0 | 18 |
// |
sl@0 | 19 |
|
sl@0 | 20 |
#include <e32std.h> |
sl@0 | 21 |
#include <e32std_private.h> |
sl@0 | 22 |
|
sl@0 | 23 |
void InfiniteRecursion() |
sl@0 | 24 |
{ |
sl@0 | 25 |
InfiniteRecursion(); |
sl@0 | 26 |
} |
sl@0 | 27 |
|
sl@0 | 28 |
#ifdef __ARMCC__ |
sl@0 | 29 |
#pragma Ono_inline // prevent compile time errors |
sl@0 | 30 |
#endif |
sl@0 | 31 |
void Store42(TInt*& p) |
sl@0 | 32 |
{ |
sl@0 | 33 |
*p = 42; |
sl@0 | 34 |
} |
sl@0 | 35 |
|
sl@0 | 36 |
void Foo() |
sl@0 | 37 |
{ |
sl@0 | 38 |
// uninitialised pointer on stack - may not crash |
sl@0 | 39 |
TInt* p; |
sl@0 | 40 |
Store42(p); |
sl@0 | 41 |
} |
sl@0 | 42 |
void Foo1(TUint8 *ps) |
sl@0 | 43 |
{ |
sl@0 | 44 |
TInt32* p = (TInt32*)ps; |
sl@0 | 45 |
*p = 0x42; |
sl@0 | 46 |
} |
sl@0 | 47 |
void Foo2(TUint8 *ps) |
sl@0 | 48 |
{ |
sl@0 | 49 |
TInt16* p = (TInt16*)ps; |
sl@0 | 50 |
*p = 0x42; |
sl@0 | 51 |
} |
sl@0 | 52 |
|
sl@0 | 53 |
TInt E32Main() |
sl@0 | 54 |
{ |
sl@0 | 55 |
TBuf<32> cmd; |
sl@0 | 56 |
User::CommandLine(cmd); |
sl@0 | 57 |
TLex lex(cmd); |
sl@0 | 58 |
TInt n=0; |
sl@0 | 59 |
lex.Val(n); |
sl@0 | 60 |
|
sl@0 | 61 |
typedef void (*TPfn)(); |
sl@0 | 62 |
|
sl@0 | 63 |
switch (n) |
sl@0 | 64 |
{ |
sl@0 | 65 |
default: |
sl@0 | 66 |
case 0: |
sl@0 | 67 |
{ |
sl@0 | 68 |
// data abort - accessing non-existent memory |
sl@0 | 69 |
TInt* p = (TInt*) 0x1000; |
sl@0 | 70 |
*p = 0x42; |
sl@0 | 71 |
} |
sl@0 | 72 |
break; |
sl@0 | 73 |
case 1: |
sl@0 | 74 |
// data abort - stack overflow |
sl@0 | 75 |
InfiniteRecursion(); |
sl@0 | 76 |
break; |
sl@0 | 77 |
case 2: |
sl@0 | 78 |
{ |
sl@0 | 79 |
// data abort - pointer in deleted heap cell |
sl@0 | 80 |
// May not crash on UREL builds |
sl@0 | 81 |
struct S { TInt* iPtr; }; |
sl@0 | 82 |
S* p = new S; |
sl@0 | 83 |
p->iPtr = new TInt; |
sl@0 | 84 |
delete p->iPtr; |
sl@0 | 85 |
delete p; |
sl@0 | 86 |
*(p->iPtr) = 42; |
sl@0 | 87 |
} |
sl@0 | 88 |
break; |
sl@0 | 89 |
case 3: |
sl@0 | 90 |
// data abort - uninitialised pointer on stack |
sl@0 | 91 |
Foo(); |
sl@0 | 92 |
break; |
sl@0 | 93 |
case 4: |
sl@0 | 94 |
{ |
sl@0 | 95 |
// data abort - misaligned access to 32 bit word |
sl@0 | 96 |
TUint8 buffer[16]; |
sl@0 | 97 |
Foo1(buffer+2); |
sl@0 | 98 |
} |
sl@0 | 99 |
break; |
sl@0 | 100 |
case 5: |
sl@0 | 101 |
{ |
sl@0 | 102 |
// data abort - misaligned access to 16 bit word |
sl@0 | 103 |
TUint8 buffer[16]; |
sl@0 | 104 |
Foo2 (buffer+1); |
sl@0 | 105 |
} |
sl@0 | 106 |
break; |
sl@0 | 107 |
case 6: |
sl@0 | 108 |
{ |
sl@0 | 109 |
// prefetch abort |
sl@0 | 110 |
TPfn f = NULL; |
sl@0 | 111 |
f(); |
sl@0 | 112 |
} |
sl@0 | 113 |
break; |
sl@0 | 114 |
case 7: |
sl@0 | 115 |
{ |
sl@0 | 116 |
// undefined instruction |
sl@0 | 117 |
TUint32 undef = 0xE6000010; |
sl@0 | 118 |
TPfn f = (TPfn) &undef; |
sl@0 | 119 |
f(); |
sl@0 | 120 |
} |
sl@0 | 121 |
break; |
sl@0 | 122 |
} |
sl@0 | 123 |
|
sl@0 | 124 |
return 0; |
sl@0 | 125 |
} |