-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoreDumpOfACrash.cpp
More file actions
48 lines (38 loc) · 1.22 KB
/
CoreDumpOfACrash.cpp
File metadata and controls
48 lines (38 loc) · 1.22 KB
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
#include <fcntl.h>
#include <mach/mach.h>
#include <pthread.h>
#include <unistd.h>
#include "MMD/FileOStream.hpp"
#include "MMD/MacMiniDump.hpp"
void SignalHandler (int /*signal*/, siginfo_t* /*pSigInfo*/, void* pContext)
{
__darwin_ucontext* ucontext = (__darwin_ucontext*) pContext;
MMDCrashContext crashContext = {};
crashContext.mcontext = *reinterpret_cast<__darwin_mcontext64*> (ucontext->uc_mcontext);
pthread_threadid_np (NULL, &crashContext.crashedTID);
const char* pCorePath = "/tmp/test.core";
// Make sure the destination file exists and is empty
int fd = open (pCorePath, O_WRONLY | O_CREAT | O_TRUNC, 0666);
if (fd >= 0)
close (fd);
MMD::FileOStream fos (pCorePath);
MiniDumpWriteDump (mach_task_self (), &fos);
kill (getpid (), SIGKILL);
}
void SetupSignalHandler (void (*handler) (int, siginfo_t*, void*))
{
struct sigaction sa;
sa.sa_sigaction = handler;
sa.sa_flags = SA_SIGINFO | SA_NODEFER;
sigemptyset (&sa.sa_mask);
sigaction (SIGSEGV, &sa, nullptr);
sigaction (SIGBUS, &sa, nullptr);
sigaction (SIGILL, &sa, nullptr);
sigaction (SIGABRT, &sa, nullptr);
sigaction (SIGFPE, &sa, nullptr);
}
int main ()
{
SetupSignalHandler (SignalHandler);
[[maybe_unused]] int i = *(volatile int*) 0;
}