-
Notifications
You must be signed in to change notification settings - Fork 20
/
ExtendedCrashTester.ino
131 lines (118 loc) · 4.16 KB
/
ExtendedCrashTester.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
Example application to show how to save crash information
to ESP8266's flash using EspSaveCrash library
Please check repository below for details
Repository: https://github.com/krzychb/EspSaveCrash
File: ExtendedCrashTester.ino
Revision: 1.0.2
Date: 4-Apr-2020
Author: krzychb at gazeta.pl
Copyright (c) 2016 Krzysztof Budzynski. All rights reserved.
This application is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This application 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "EspSaveCrash.h"
//Offset and size parameters can be passed to the constructor
EspSaveCrash SaveCrash(0x0020, 0x0200);
void setup(void)
{
Serial.begin(115200);
Serial.println();
Serial.println("ExtendedCrashTester.ino\n");
SaveCrash.print();
Serial.println("\n? - help");
}
int* nullPointer = NULL;
void loop(void)
{
if (Serial.available() > 0)
{
char inChar = Serial.read();
switch (inChar)
{
case ' ':
SaveCrash.print();
break;
case 'c':
SaveCrash.clear();
Serial.println("Crash information cleared");
break;
case 's':
Serial.printf("Crashing with software WDT (%ld ms) ...\n", millis());
while (true)
{
// stay in an infinite loop doing nothing
// this way other process can not be executed
}
break;
case 'r':
Serial.printf("Reset ESP (%ld ms) ...\n", millis());
ESP.reset();
break;
case 't':
Serial.printf("Restart ESP (%ld ms) ...\n", millis());
ESP.restart();
break;
case 'h':
Serial.printf("Crashing with hardware WDT (%ld ms) ...\n", millis());
ESP.wdtDisable();
while (true)
{
// stay in an infinite loop doing nothing
// this way other process can not be executed
//
// Note:
// Hardware wdt kicks in if software wdt is unable to perfrom
// Nothing will be saved in EEPROM for the hardware wdt
}
break;
case '0':
Serial.printf("Crashing with 'division by zero' exeption (%ld ms) ...\n", millis());
int result, zero;
zero = 0;
result = 1 / zero;
Serial.printf("Result = %d\n", result);
break;
case 'e':
Serial.printf("Crashing with 'read through a pointer to no object' exeption (%ld ms) ...\n", millis());
// null pointer dereference - read
// attempt to read a value through a null pointer
Serial.print(*nullPointer);
break;
case 'x':
Serial.printf("Crashing with 'write through a pointer to no object' exeption (%ld ms) ...\n", millis());
// null pointer dereference - write
// attempt to write a value through a null pointer
*nullPointer = 0;
break;
case '?':
Serial.println("Press a key + <enter>");
Serial.println("<space> : print crash information");
Serial.println("c : clear crash information");
Serial.println("r/t : reset / restart module");
Serial.println("? : print help");
Serial.println("Crash this application with");
Serial.println("s/h : software / harware WDT");
Serial.println("0 : 'division by zero' exeption");
Serial.println("e : 'read through a pointer to no object' exeption");
Serial.println("x : 'write through a pointer to no object' exeption");
break;
case 0xa:
case 0xd:
// skip newline and carriage return
break;
default:
Serial.printf("Case? (%c) / ? - help\n", inChar);
break;
}
}
}