mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 09:47:35 +00:00
Userland: Add a helpful little program for provoking different crashes.
Currently supported crash types: -s : Segmentation violation -d : Division by zero -i : Illegal instruction -a : Abort
This commit is contained in:
parent
cde3274ffb
commit
9308ce071f
1 changed files with 55 additions and 0 deletions
55
Userland/crash.cpp
Normal file
55
Userland/crash.cpp
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
#include <AK/AKString.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
static void print_usage_and_exit()
|
||||||
|
{
|
||||||
|
printf("usage: crash -[sdia]\n");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char** argv)
|
||||||
|
{
|
||||||
|
enum Mode { SegmentationViolation, DivisionByZero, IllegalInstruction, Abort };
|
||||||
|
Mode mode = SegmentationViolation;
|
||||||
|
|
||||||
|
if (argc != 2)
|
||||||
|
print_usage_and_exit();
|
||||||
|
|
||||||
|
if (String(argv[1]) == "-s")
|
||||||
|
mode = SegmentationViolation;
|
||||||
|
else if (String(argv[1]) == "-d")
|
||||||
|
mode = DivisionByZero;
|
||||||
|
else if (String(argv[1]) == "-i")
|
||||||
|
mode = IllegalInstruction;
|
||||||
|
else if (String(argv[1]) == "-a")
|
||||||
|
mode = Abort;
|
||||||
|
else
|
||||||
|
print_usage_and_exit();
|
||||||
|
|
||||||
|
if (mode == SegmentationViolation) {
|
||||||
|
volatile int* crashme = nullptr;
|
||||||
|
*crashme = 0xbeef;
|
||||||
|
ASSERT_NOT_REACHED();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mode == DivisionByZero) {
|
||||||
|
volatile int lala = 10;
|
||||||
|
volatile int zero = 0;
|
||||||
|
volatile int test = lala / zero;
|
||||||
|
ASSERT_NOT_REACHED();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mode == IllegalInstruction) {
|
||||||
|
asm volatile("ud2");
|
||||||
|
ASSERT_NOT_REACHED();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mode == Abort) {
|
||||||
|
abort();
|
||||||
|
ASSERT_NOT_REACHED();
|
||||||
|
}
|
||||||
|
|
||||||
|
ASSERT_NOT_REACHED();
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue