class CrashRecoveryContext

Declaration

class CrashRecoveryContext { /* full declaration omitted */ };

Description

Crash recovery helper object. This class implements support for running operations in a safe context so that crashes (memory errors, stack overflow, assertion violations) can be detected and control restored to the crashing thread. Crash detection is purely "best effort", the exact set of failures which can be recovered from is platform dependent. Clients make use of this code by first calling CrashRecoveryContext::Enable(), and then executing unsafe operations via a CrashRecoveryContext object. For example: To assist recovery the class allows specifying set of actions that will be executed in any case, whether crash occurs or not. These actions may be used to reclaim resources in the case of crash.

Declared at: llvm/include/llvm/Support/CrashRecoveryContext.h:46

Member Variables

public int RetCode = 0
In case of a crash, this is the crash identifier.
public bool DumpStackAndCleanupOnFailure = false
Selects whether handling of failures should be done in the same way as for regular crashes. When this is active, a crash would print the callstack, clean-up any temporary files and create a coredump/minidump.

Method Overview

Methods

CrashRecoveryContext()

Declared at: llvm/include/llvm/Support/CrashRecoveryContext.h:51

static void Disable()

Description

Disable crash recovery.

Declared at: llvm/include/llvm/Support/CrashRecoveryContext.h:65

static void Enable()

Description

Enable crash recovery.

Declared at: llvm/include/llvm/Support/CrashRecoveryContext.h:62

static llvm::CrashRecoveryContext* GetCurrent()

Description

Return the active context, if the code is currently executing in a thread which is in a protected context.

Declared at: llvm/include/llvm/Support/CrashRecoveryContext.h:69

void HandleExit(int RetCode)

Description

Explicitly trigger a crash recovery in the current process, and return failure from RunSafely(). This function does not return.

Declared at: llvm/include/llvm/Support/CrashRecoveryContext.h:103

Parameters

int RetCode

bool RunSafely(function_ref<void()> Fn)

Description

Execute the provided callback function (with the given arguments) in a protected context.

Declared at: llvm/include/llvm/Support/CrashRecoveryContext.h:81

Parameters

function_ref<void()> Fn

Returns

True if the function completed successfully, and false if the function crashed (or HandleCrash was called explicitly). Clients should make as little assumptions as possible about the program state when RunSafely has returned false.

bool RunSafely(void (*)(void*) Fn, void* UserData)

Declared at: llvm/include/llvm/Support/CrashRecoveryContext.h:82

Parameters

void (*)(void*) Fn
void* UserData

bool RunSafelyOnThread(
    function_ref<void()>,
    unsigned int RequestedStackSize = 0)

Description

Execute the provide callback function (with the given arguments) in a protected context which is run in another thread (optionally with a requested stack size). See RunSafely() and llvm_execute_on_thread(). On Darwin, if PRIO_DARWIN_BG is set on the calling thread, it will be propagated to the new thread as well.

Declared at: llvm/include/llvm/Support/CrashRecoveryContext.h:94

Parameters

function_ref<void()>
unsigned int RequestedStackSize = 0

bool RunSafelyOnThread(
    void (*)(void*) Fn,
    void* UserData,
    unsigned int RequestedStackSize = 0)

Declared at: llvm/include/llvm/Support/CrashRecoveryContext.h:95

Parameters

void (*)(void*) Fn
void* UserData
unsigned int RequestedStackSize = 0

static bool isRecoveringFromCrash()

Description

Return true if the current thread is recovering from a crash.

Declared at: llvm/include/llvm/Support/CrashRecoveryContext.h:72

void registerCleanup(
    llvm::CrashRecoveryContextCleanup* cleanup)

Description

Register cleanup handler, which is used when the recovery context is finished. The recovery context owns the handler.

Declared at: llvm/include/llvm/Support/CrashRecoveryContext.h:57

Parameters

llvm::CrashRecoveryContextCleanup* cleanup

void unregisterCleanup(
    llvm::CrashRecoveryContextCleanup* cleanup)

Declared at: llvm/include/llvm/Support/CrashRecoveryContext.h:59

Parameters

llvm::CrashRecoveryContextCleanup* cleanup

~CrashRecoveryContext()

Declared at: llvm/include/llvm/Support/CrashRecoveryContext.h:52