1 | // Licensed to the .NET Foundation under one or more agreements. |
2 | // The .NET Foundation licenses this file to you under the MIT license. |
3 | // See the LICENSE file in the project root for more information. |
4 | |
5 | #include "createdump.h" |
6 | |
7 | bool g_diagnostics = false; |
8 | |
9 | // |
10 | // The common create dump code |
11 | // |
12 | bool |
13 | CreateDumpCommon(const char* dumpPathTemplate, MINIDUMP_TYPE minidumpType, CrashInfo* crashInfo) |
14 | { |
15 | ReleaseHolder<DumpWriter> dumpWriter = new DumpWriter(*crashInfo); |
16 | bool result = false; |
17 | |
18 | ArrayHolder<char> dumpPath = new char[PATH_MAX]; |
19 | snprintf(dumpPath, PATH_MAX, dumpPathTemplate, crashInfo->Pid()); |
20 | |
21 | const char* dumpType = "minidump" ; |
22 | switch (minidumpType) |
23 | { |
24 | case MiniDumpWithPrivateReadWriteMemory: |
25 | dumpType = "minidump with heap" ; |
26 | break; |
27 | |
28 | case MiniDumpFilterTriage: |
29 | dumpType = "triage minidump" ; |
30 | break; |
31 | |
32 | case MiniDumpWithFullMemory: |
33 | dumpType = "full dump" ; |
34 | break; |
35 | |
36 | default: |
37 | break; |
38 | } |
39 | printf("Writing %s to file %s\n" , dumpType, (char*)dumpPath); |
40 | |
41 | // Suspend all the threads in the target process and build the list of threads |
42 | if (!crashInfo->EnumerateAndSuspendThreads()) |
43 | { |
44 | goto exit; |
45 | } |
46 | // Gather all the info about the process, threads (registers, etc.) and memory regions |
47 | if (!crashInfo->GatherCrashInfo(minidumpType)) |
48 | { |
49 | goto exit; |
50 | } |
51 | if (!dumpWriter->OpenDump(dumpPath)) |
52 | { |
53 | goto exit; |
54 | } |
55 | if (!dumpWriter->WriteDump()) |
56 | { |
57 | goto exit; |
58 | } |
59 | result = true; |
60 | exit: |
61 | crashInfo->ResumeThreads(); |
62 | return result; |
63 | } |
64 | |
65 | // |
66 | // Entry point for SOS createdump command |
67 | // |
68 | bool |
69 | CreateDumpForSOS(const char* programPath, const char* dumpPathTemplate, pid_t pid, MINIDUMP_TYPE minidumpType, ICLRDataTarget* dataTarget) |
70 | { |
71 | ReleaseHolder<CrashInfo> crashInfo = new CrashInfo(pid, dataTarget, true); |
72 | return CreateDumpCommon(dumpPathTemplate, minidumpType, crashInfo); |
73 | } |
74 | |