diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index d83480fa0a..a328568c0d 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -5158,13 +5158,6 @@ mat4 Application::getHMDSensorPose() const { return mat4(); } -void Application::crashApplication() { - qCDebug(interfaceapp) << "Intentionally crashed Interface"; - QObject* object = nullptr; - bool value = object->isWindowType(); - Q_UNUSED(value); -} - void Application::deadlockApplication() { qCDebug(interfaceapp) << "Intentionally deadlocked Interface"; // Using a loop that will *technically* eventually exit (in ~600 billion years) diff --git a/interface/src/Application.h b/interface/src/Application.h index 0d170bd0c2..838c81c250 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -275,7 +275,6 @@ public slots: void updateHeartbeat() const; - static void crashApplication(); static void deadlockApplication(); void rotationModeChanged() const; diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 7be498623e..1fa4a6fe29 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -13,8 +13,11 @@ #include #include +#include + #include #include +#include #include #include #include @@ -587,10 +590,41 @@ Menu::Menu() { // Developer > Display Crash Options addCheckableActionToQMenuAndActionHash(developerMenu, MenuOption::DisplayCrashOptions, 0, true); - // Developer > Crash Application - addActionToQMenuAndActionHash(developerMenu, MenuOption::CrashInterface, 0, qApp, SLOT(crashApplication())); - // Developer > Deadlock Application - addActionToQMenuAndActionHash(developerMenu, MenuOption::DeadlockInterface, 0, qApp, SLOT(deadlockApplication())); + + // Developer > Crash >>> + MenuWrapper* crashMenu = developerMenu->addMenu("Crash"); + + addActionToQMenuAndActionHash(crashMenu, MenuOption::DeadlockInterface, 0, qApp, SLOT(deadlockApplication())); + + action = addActionToQMenuAndActionHash(crashMenu, MenuOption::CrashPureVirtualFunction); + connect(action, &QAction::triggered, qApp, []() { crash::pureVirtualCall(); }); + action = addActionToQMenuAndActionHash(crashMenu, MenuOption::CrashPureVirtualFunctionThreaded); + connect(action, &QAction::triggered, qApp, []() { std::thread([]() { crash::pureVirtualCall(); }); }); + + action = addActionToQMenuAndActionHash(crashMenu, MenuOption::CrashDoubleFree); + connect(action, &QAction::triggered, qApp, []() { crash::doubleFree(); }); + action = addActionToQMenuAndActionHash(crashMenu, MenuOption::CrashDoubleFreeThreaded); + connect(action, &QAction::triggered, qApp, []() { std::thread([]() { crash::doubleFree(); }); }); + + action = addActionToQMenuAndActionHash(crashMenu, MenuOption::CrashAbort); + connect(action, &QAction::triggered, qApp, []() { crash::doAbort(); }); + action = addActionToQMenuAndActionHash(crashMenu, MenuOption::CrashAbortThreaded); + connect(action, &QAction::triggered, qApp, []() { std::thread([]() { crash::doAbort(); }); }); + + action = addActionToQMenuAndActionHash(crashMenu, MenuOption::CrashNullDereference); + connect(action, &QAction::triggered, qApp, []() { crash::nullDeref(); }); + action = addActionToQMenuAndActionHash(crashMenu, MenuOption::CrashNullDereferenceThreaded); + connect(action, &QAction::triggered, qApp, []() { std::thread([]() { crash::nullDeref(); }); }); + + action = addActionToQMenuAndActionHash(crashMenu, MenuOption::CrashOutOfBoundsVectorAccess); + connect(action, &QAction::triggered, qApp, []() { crash::outOfBoundsVectorCrash(); }); + action = addActionToQMenuAndActionHash(crashMenu, MenuOption::CrashOutOfBoundsVectorAccessThreaded); + connect(action, &QAction::triggered, qApp, []() { std::thread([]() { crash::outOfBoundsVectorCrash(); }); }); + + action = addActionToQMenuAndActionHash(crashMenu, MenuOption::CrashNewFault); + connect(action, &QAction::triggered, qApp, []() { crash::newFault(); }); + action = addActionToQMenuAndActionHash(crashMenu, MenuOption::CrashNewFaultThreaded); + connect(action, &QAction::triggered, qApp, []() { std::thread([]() { crash::newFault(); }); }); // Developer > Log... addActionToQMenuAndActionHash(developerMenu, MenuOption::Log, Qt::CTRL | Qt::SHIFT | Qt::Key_L, diff --git a/interface/src/Menu.h b/interface/src/Menu.h index 2c1d2c9ee7..600632d125 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -66,7 +66,18 @@ namespace MenuOption { const QString CopyAddress = "Copy Address to Clipboard"; const QString CopyPath = "Copy Path to Clipboard"; const QString CoupleEyelids = "Couple Eyelids"; - const QString CrashInterface = "Crash Interface"; + const QString CrashPureVirtualFunction = "Pure Virtual Function Call"; + const QString CrashPureVirtualFunctionThreaded = "Pure Virtual Function Call (threaded)"; + const QString CrashDoubleFree = "Double Free"; + const QString CrashDoubleFreeThreaded = "Double Free (threaded)"; + const QString CrashNullDereference = "Null Dereference"; + const QString CrashNullDereferenceThreaded = "Null Dereference (threaded)"; + const QString CrashAbort = "Abort"; + const QString CrashAbortThreaded = "Abort (threaded)"; + const QString CrashOutOfBoundsVectorAccess = "Out of Bounds Vector Access"; + const QString CrashOutOfBoundsVectorAccessThreaded = "Out of Bounds Vector Access (threaded)"; + const QString CrashNewFault = "New Fault"; + const QString CrashNewFaultThreaded = "New Fault (threaded)"; const QString DeadlockInterface = "Deadlock Interface"; const QString DecreaseAvatarSize = "Decrease Avatar Size"; const QString DeleteBookmark = "Delete Bookmark..."; diff --git a/libraries/shared/src/CrashHelpers.h b/libraries/shared/src/CrashHelpers.h new file mode 100644 index 0000000000..dae39d4a99 --- /dev/null +++ b/libraries/shared/src/CrashHelpers.h @@ -0,0 +1,82 @@ +// +// CrashHelpers.h +// libraries/shared/src +// +// Created by Ryan Huffman on 11 April 2016. +// Copyright 2016 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#pragma once + +#ifndef hifi_CrashHelpers_h +#define hifi_CrashHelpers_h + +namespace crash { + +class B; +class A { +public: + A(B* b) : _b(b) { } + ~A(); + virtual void virtualFunction() = 0; + +private: + B* _b; +}; + +class B : public A { +public: + B() : A(this) { } + virtual void virtualFunction() { } +}; + +A::~A() { + _b->virtualFunction(); +} + +void pureVirtualCall() { + qDebug() << "About to make a pure virtual call"; + B b; +} + +void doubleFree() { + qDebug() << "About to double delete memory"; + int* blah = new int(200); + delete blah; + delete blah; +} + +void nullDeref() { + qDebug() << "About to dereference a null pointer"; + int* p = nullptr; + *p = 1; +} + +void doAbort() { + qDebug() << "About to abort"; + abort(); +} + +void outOfBoundsVectorCrash() { + qDebug() << "std::vector out of bounds crash!"; + std::vector v; + v[0] = 42; +} + +void newFault() { + qDebug() << "About to crash inside new fault"; + + // Force crash with multiple large allocations + while (true) { + const size_t GIGABYTE = 1024 * 1024 * 1024; + new char[GIGABYTE]; + } + +} + +} + +#endif // hifi_CrashHelpers_h