summaryrefslogtreecommitdiff
path: root/Userland/Utilities/crash.cpp
diff options
context:
space:
mode:
authorGunnar Beutner <gbeutner@serenityos.org>2021-06-06 17:40:48 +0200
committerAndreas Kling <kling@serenityos.org>2021-06-06 22:16:11 +0200
commit64754ba985d322219c13a16c0a1f2fb5e2dbfbd8 (patch)
treeeee008c9a3f5e2505127fae65843cf1d844eabea /Userland/Utilities/crash.cpp
parent89a38b72b7181b103aa524e8abd3fe98c8c75864 (diff)
downloadserenity-64754ba985d322219c13a16c0a1f2fb5e2dbfbd8.zip
Utilities: Add support for testing null deferencing a RefPtr
This adds the new flag -R for the crash utility which tests what happens when we dereference a null RefPtr. This is useful for testing the output of the assertion message.
Diffstat (limited to 'Userland/Utilities/crash.cpp')
-rw-r--r--Userland/Utilities/crash.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/Userland/Utilities/crash.cpp b/Userland/Utilities/crash.cpp
index c805268e17..e832915826 100644
--- a/Userland/Utilities/crash.cpp
+++ b/Userland/Utilities/crash.cpp
@@ -10,6 +10,7 @@
#include <AK/String.h>
#include <Kernel/IO.h>
#include <LibCore/ArgsParser.h>
+#include <LibCore/Object.h>
#include <LibTest/CrashTest.h>
#include <stdio.h>
#include <stdlib.h>
@@ -43,6 +44,7 @@ int main(int argc, char** argv)
bool do_read_cpu_counter = false;
bool do_pledge_violation = false;
bool do_failing_assertion = false;
+ bool do_deref_null_refptr = false;
auto args_parser = Core::ArgsParser();
args_parser.set_general_help(
@@ -67,6 +69,7 @@ int main(int argc, char** argv)
args_parser.add_option(do_read_cpu_counter, "Read the x86 TSC (Time Stamp Counter) directly", nullptr, 'c');
args_parser.add_option(do_pledge_violation, "Violate pledge()'d promises", nullptr, 'p');
args_parser.add_option(do_failing_assertion, "Perform a failing assertion", nullptr, 'n');
+ args_parser.add_option(do_deref_null_refptr, "Dereference a null RefPtr", nullptr, 'R');
if (argc != 2) {
args_parser.print_usage(stderr, argv[0]);
@@ -279,5 +282,13 @@ int main(int argc, char** argv)
}).run(run_type);
}
+ if (do_deref_null_refptr || do_all_crash_types) {
+ Crash("Dereference a null RefPtr", [] {
+ RefPtr<Core::Object> p;
+ *p;
+ return Crash::Failure::DidNotCrash;
+ }).run(run_type);
+ }
+
return 0;
}