summaryrefslogtreecommitdiff
path: root/src/debug/createdump/createdump.cpp
blob: f6ea1db7de944ef3d415a38f22c16ec45576524f (plain)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#include "createdump.h"

bool g_diagnostics = false;

//
// The common create dump code
//
bool 
CreateDumpCommon(const char* programPath, const char* dumpPathTemplate, MINIDUMP_TYPE minidumpType, CrashInfo* crashInfo)
{
    ReleaseHolder<DumpWriter> dumpWriter = new DumpWriter(*crashInfo);
    bool result = false;

    ArrayHolder<char> dumpPath = new char[PATH_MAX];
    snprintf(dumpPath, PATH_MAX, dumpPathTemplate, crashInfo->Pid());

    const char* dumpType = "minidump";
    switch (minidumpType)
    {
        case MiniDumpWithPrivateReadWriteMemory:
            dumpType = "minidump with heap";
            break;

        case MiniDumpFilterTriage:
            dumpType = "triage minidump";
            break;

        case MiniDumpWithFullMemory:
            dumpType = "full dump";
            break;

        default:
            break;
    }
    printf("Writing %s to file %s\n", dumpType, (char*)dumpPath);

    // Suspend all the threads in the target process and build the list of threads
    if (!crashInfo->EnumerateAndSuspendThreads())
    {
        goto exit;
    }
    // Gather all the info about the process, threads (registers, etc.) and memory regions
    if (!crashInfo->GatherCrashInfo(programPath, minidumpType))
    {
        goto exit;
    }
    if (!dumpWriter->OpenDump(dumpPath))
    {
        goto exit;
    }
    if (!dumpWriter->WriteDump())
    {
        goto exit;
    }
    result = true;
exit:
    crashInfo->ResumeThreads();
    return result;
}

//
// Entry point for SOS createdump command
//
bool 
CreateDumpForSOS(const char* programPath, const char* dumpPathTemplate, pid_t pid, MINIDUMP_TYPE minidumpType, ICLRDataTarget* dataTarget)
{
    ReleaseHolder<CrashInfo> crashInfo = new CrashInfo(pid, dataTarget, true);
    return CreateDumpCommon(programPath, dumpPathTemplate, minidumpType, crashInfo);
}