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