Bug Summary

File:tools/lldb/source/Plugins/Process/minidump/MinidumpTypes.cpp
Warning:line 26, column 39
Called C++ object pointer is null

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name MinidumpTypes.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-eagerly-assume -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -mrelocation-model pic -pic-level 2 -mthread-model posix -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -momit-leaf-frame-pointer -ffunction-sections -fdata-sections -resource-dir /usr/lib/llvm-7/lib/clang/7.0.0 -D HAVE_ROUND -D LLDB_CONFIGURATION_RELEASE -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I /build/llvm-toolchain-snapshot-7~svn338205/build-llvm/tools/lldb/source/Plugins/Process/minidump -I /build/llvm-toolchain-snapshot-7~svn338205/tools/lldb/source/Plugins/Process/minidump -I /build/llvm-toolchain-snapshot-7~svn338205/build-llvm/tools/lldb/include -I /build/llvm-toolchain-snapshot-7~svn338205/tools/lldb/include -I /build/llvm-toolchain-snapshot-7~svn338205/build-llvm/include -I /build/llvm-toolchain-snapshot-7~svn338205/include -I /usr/include/python2.7 -I /build/llvm-toolchain-snapshot-7~svn338205/tools/clang/include -I /build/llvm-toolchain-snapshot-7~svn338205/build-llvm/tools/lldb/../clang/include -I /build/llvm-toolchain-snapshot-7~svn338205/tools/lldb/source/. -U NDEBUG -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/8/../../../../include/x86_64-linux-gnu/c++/8 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/8/../../../../include/x86_64-linux-gnu/c++/8 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/backward -internal-isystem /usr/include/clang/7.0.0/include/ -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-7/lib/clang/7.0.0/include -internal-externc-isystem /usr/lib/gcc/x86_64-linux-gnu/8/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-maybe-uninitialized -Wno-class-memaccess -Wno-comment -Wno-deprecated-declarations -Wno-unknown-pragmas -Wno-strict-aliasing -Wno-deprecated-register -Wno-vla-extension -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /build/llvm-toolchain-snapshot-7~svn338205/build-llvm/tools/lldb/source/Plugins/Process/minidump -ferror-limit 19 -fmessage-length 0 -fvisibility-inlines-hidden -fobjc-runtime=gcc -fdiagnostics-show-option -vectorize-loops -vectorize-slp -analyzer-output=html -analyzer-config stable-report-filename=true -o /tmp/scan-build-2018-07-29-043837-17923-1 -x c++ /build/llvm-toolchain-snapshot-7~svn338205/tools/lldb/source/Plugins/Process/minidump/MinidumpTypes.cpp -faddrsig

/build/llvm-toolchain-snapshot-7~svn338205/tools/lldb/source/Plugins/Process/minidump/MinidumpTypes.cpp

1//===-- MinidumpTypes.cpp ---------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// Project includes
11#include "MinidumpTypes.h"
12
13// Other libraries and framework includes
14// C includes
15// C++ includes
16
17using namespace lldb_private;
18using namespace minidump;
19
20const MinidumpHeader *MinidumpHeader::Parse(llvm::ArrayRef<uint8_t> &data) {
21 const MinidumpHeader *header = nullptr;
1
'header' initialized to a null pointer value
22 Status error = consumeObject(data, header);
2
Calling 'consumeObject<lldb_private::minidump::MinidumpHeader>'
6
Returning from 'consumeObject<lldb_private::minidump::MinidumpHeader>'
23
24 const MinidumpHeaderConstants signature =
25 static_cast<const MinidumpHeaderConstants>(
26 static_cast<const uint32_t>(header->signature));
7
Called C++ object pointer is null
27 const MinidumpHeaderConstants version =
28 static_cast<const MinidumpHeaderConstants>(
29 static_cast<const uint32_t>(header->version) & 0x0000ffff);
30 // the high 16 bits of the version field are implementation specific
31
32 if (error.Fail() || signature != MinidumpHeaderConstants::Signature ||
33 version != MinidumpHeaderConstants::Version)
34 return nullptr;
35
36 return header;
37}
38
39// Minidump string
40llvm::Optional<std::string>
41lldb_private::minidump::parseMinidumpString(llvm::ArrayRef<uint8_t> &data) {
42 std::string result;
43
44 const uint32_t *source_length_ptr;
45 Status error = consumeObject(data, source_length_ptr);
46
47 // Copy non-aligned source_length data into aligned memory.
48 uint32_t source_length;
49 std::memcpy(&source_length, source_length_ptr, sizeof(source_length));
50
51 if (error.Fail() || source_length > data.size() || source_length % 2 != 0)
52 return llvm::None;
53
54 auto source_start = reinterpret_cast<const llvm::UTF16 *>(data.data());
55 // source_length is the length of the string in bytes we need the length of
56 // the string in UTF-16 characters/code points (16 bits per char) that's why
57 // it's divided by 2
58 const auto source_end = source_start + source_length / 2;
59 // resize to worst case length
60 result.resize(UNI_MAX_UTF8_BYTES_PER_CODE_POINT4 * source_length / 2);
61 auto result_start = reinterpret_cast<llvm::UTF8 *>(&result[0]);
62 const auto result_end = result_start + result.size();
63 llvm::ConvertUTF16toUTF8(&source_start, source_end, &result_start, result_end,
64 llvm::strictConversion);
65 const auto result_size =
66 std::distance(reinterpret_cast<llvm::UTF8 *>(&result[0]), result_start);
67 result.resize(result_size); // shrink to actual length
68
69 return result;
70}
71
72// MinidumpThread
73const MinidumpThread *MinidumpThread::Parse(llvm::ArrayRef<uint8_t> &data) {
74 const MinidumpThread *thread = nullptr;
75 Status error = consumeObject(data, thread);
76 if (error.Fail())
77 return nullptr;
78
79 return thread;
80}
81
82llvm::ArrayRef<MinidumpThread>
83MinidumpThread::ParseThreadList(llvm::ArrayRef<uint8_t> &data) {
84 const auto orig_size = data.size();
85 const llvm::support::ulittle32_t *thread_count;
86 Status error = consumeObject(data, thread_count);
87 if (error.Fail() || *thread_count * sizeof(MinidumpThread) > data.size())
88 return {};
89
90 // Compilers might end up padding an extra 4 bytes depending on how the
91 // structure is padded by the compiler and the #pragma pack settings.
92 if (4 + *thread_count * sizeof(MinidumpThread) < orig_size)
93 data = data.drop_front(4);
94
95 return llvm::ArrayRef<MinidumpThread>(
96 reinterpret_cast<const MinidumpThread *>(data.data()), *thread_count);
97}
98
99// MinidumpSystemInfo
100const MinidumpSystemInfo *
101MinidumpSystemInfo::Parse(llvm::ArrayRef<uint8_t> &data) {
102 const MinidumpSystemInfo *system_info;
103 Status error = consumeObject(data, system_info);
104 if (error.Fail())
105 return nullptr;
106
107 return system_info;
108}
109
110// MinidumpMiscInfo
111const MinidumpMiscInfo *MinidumpMiscInfo::Parse(llvm::ArrayRef<uint8_t> &data) {
112 const MinidumpMiscInfo *misc_info;
113 Status error = consumeObject(data, misc_info);
114 if (error.Fail())
115 return nullptr;
116
117 return misc_info;
118}
119
120llvm::Optional<lldb::pid_t> MinidumpMiscInfo::GetPid() const {
121 uint32_t pid_flag =
122 static_cast<const uint32_t>(MinidumpMiscInfoFlags::ProcessID);
123 if (flags1 & pid_flag)
124 return llvm::Optional<lldb::pid_t>(process_id);
125
126 return llvm::None;
127}
128
129// Linux Proc Status
130// it's stored as an ascii string in the file
131llvm::Optional<LinuxProcStatus>
132LinuxProcStatus::Parse(llvm::ArrayRef<uint8_t> &data) {
133 LinuxProcStatus result;
134 result.proc_status =
135 llvm::StringRef(reinterpret_cast<const char *>(data.data()), data.size());
136 data = data.drop_front(data.size());
137
138 llvm::SmallVector<llvm::StringRef, 0> lines;
139 result.proc_status.split(lines, '\n', 42);
140 // /proc/$pid/status has 41 lines, but why not use 42?
141 for (auto line : lines) {
142 if (line.consume_front("Pid:")) {
143 line = line.trim();
144 if (!line.getAsInteger(10, result.pid))
145 return result;
146 }
147 }
148
149 return llvm::None;
150}
151
152lldb::pid_t LinuxProcStatus::GetPid() const { return pid; }
153
154// Module stuff
155const MinidumpModule *MinidumpModule::Parse(llvm::ArrayRef<uint8_t> &data) {
156 const MinidumpModule *module = nullptr;
157 Status error = consumeObject(data, module);
158 if (error.Fail())
159 return nullptr;
160
161 return module;
162}
163
164llvm::ArrayRef<MinidumpModule>
165MinidumpModule::ParseModuleList(llvm::ArrayRef<uint8_t> &data) {
166 const auto orig_size = data.size();
167 const llvm::support::ulittle32_t *modules_count;
168 Status error = consumeObject(data, modules_count);
169 if (error.Fail() || *modules_count * sizeof(MinidumpModule) > data.size())
170 return {};
171
172 // Compilers might end up padding an extra 4 bytes depending on how the
173 // structure is padded by the compiler and the #pragma pack settings.
174 if (4 + *modules_count * sizeof(MinidumpModule) < orig_size)
175 data = data.drop_front(4);
176
177 return llvm::ArrayRef<MinidumpModule>(
178 reinterpret_cast<const MinidumpModule *>(data.data()), *modules_count);
179}
180
181// Exception stuff
182const MinidumpExceptionStream *
183MinidumpExceptionStream::Parse(llvm::ArrayRef<uint8_t> &data) {
184 const MinidumpExceptionStream *exception_stream = nullptr;
185 Status error = consumeObject(data, exception_stream);
186 if (error.Fail())
187 return nullptr;
188
189 return exception_stream;
190}
191
192llvm::ArrayRef<MinidumpMemoryDescriptor>
193MinidumpMemoryDescriptor::ParseMemoryList(llvm::ArrayRef<uint8_t> &data) {
194 const auto orig_size = data.size();
195 const llvm::support::ulittle32_t *mem_ranges_count;
196 Status error = consumeObject(data, mem_ranges_count);
197 if (error.Fail() ||
198 *mem_ranges_count * sizeof(MinidumpMemoryDescriptor) > data.size())
199 return {};
200
201 // Compilers might end up padding an extra 4 bytes depending on how the
202 // structure is padded by the compiler and the #pragma pack settings.
203 if (4 + *mem_ranges_count * sizeof(MinidumpMemoryDescriptor) < orig_size)
204 data = data.drop_front(4);
205
206 return llvm::makeArrayRef(
207 reinterpret_cast<const MinidumpMemoryDescriptor *>(data.data()),
208 *mem_ranges_count);
209}
210
211std::pair<llvm::ArrayRef<MinidumpMemoryDescriptor64>, uint64_t>
212MinidumpMemoryDescriptor64::ParseMemory64List(llvm::ArrayRef<uint8_t> &data) {
213 const llvm::support::ulittle64_t *mem_ranges_count;
214 Status error = consumeObject(data, mem_ranges_count);
215 if (error.Fail() ||
216 *mem_ranges_count * sizeof(MinidumpMemoryDescriptor64) > data.size())
217 return {};
218
219 const llvm::support::ulittle64_t *base_rva;
220 error = consumeObject(data, base_rva);
221 if (error.Fail())
222 return {};
223
224 return std::make_pair(
225 llvm::makeArrayRef(
226 reinterpret_cast<const MinidumpMemoryDescriptor64 *>(data.data()),
227 *mem_ranges_count),
228 *base_rva);
229}
230
231std::vector<const MinidumpMemoryInfo *>
232MinidumpMemoryInfo::ParseMemoryInfoList(llvm::ArrayRef<uint8_t> &data) {
233 const MinidumpMemoryInfoListHeader *header;
234 Status error = consumeObject(data, header);
235 if (error.Fail() ||
236 header->size_of_header < sizeof(MinidumpMemoryInfoListHeader) ||
237 header->size_of_entry < sizeof(MinidumpMemoryInfo))
238 return {};
239
240 data = data.drop_front(header->size_of_header -
241 sizeof(MinidumpMemoryInfoListHeader));
242
243 if (header->size_of_entry * header->num_of_entries > data.size())
244 return {};
245
246 std::vector<const MinidumpMemoryInfo *> result;
247 for (uint64_t i = 0; i < header->num_of_entries; ++i) {
248 result.push_back(reinterpret_cast<const MinidumpMemoryInfo *>(
249 data.data() + i * header->size_of_entry));
250 }
251
252 return result;
253}

/build/llvm-toolchain-snapshot-7~svn338205/tools/lldb/source/Plugins/Process/minidump/MinidumpTypes.h

1//===-- MinidumpTypes.h -----------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef liblldb_MinidumpTypes_h_
11#define liblldb_MinidumpTypes_h_
12
13// Project includes
14
15// Other libraries and framework includes
16#include "lldb/Utility/Status.h"
17
18#include "llvm/ADT/ArrayRef.h"
19#include "llvm/ADT/BitmaskEnum.h"
20#include "llvm/ADT/Optional.h"
21#include "llvm/ADT/SmallVector.h"
22#include "llvm/ADT/StringRef.h"
23#include "llvm/Support/ConvertUTF.h"
24#include "llvm/Support/Endian.h"
25
26// C includes
27// C++ includes
28
29// Reference:
30// https://msdn.microsoft.com/en-us/library/windows/desktop/ms679293(v=vs.85).aspx
31// https://chromium.googlesource.com/breakpad/breakpad/
32
33namespace lldb_private {
34
35namespace minidump {
36
37LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE()using ::llvm::BitmaskEnumDetail::operator~; using ::llvm::BitmaskEnumDetail
::operator|; using ::llvm::BitmaskEnumDetail::operator&; using
::llvm::BitmaskEnumDetail::operator^; using ::llvm::BitmaskEnumDetail
::operator|=; using ::llvm::BitmaskEnumDetail::operator&=
; using ::llvm::BitmaskEnumDetail::operator^=
;
38
39enum class MinidumpHeaderConstants : uint32_t {
40 Signature = 0x504d444d, // 'PMDM'
41 Version = 0x0000a793, // 42899
42 LLVM_MARK_AS_BITMASK_ENUM(/* LargestValue = */ Signature)LLVM_BITMASK_LARGEST_ENUMERATOR = Signature
43
44};
45
46enum class CvSignature : uint32_t {
47 Pdb70 = 0x53445352, // RSDS
48 ElfBuildId = 0x4270454c, // BpEL (Breakpad/Crashpad minidumps)
49};
50
51// Reference:
52// https://crashpad.chromium.org/doxygen/structcrashpad_1_1CodeViewRecordPDB70.html
53struct CvRecordPdb70 {
54 uint8_t Uuid[16];
55 llvm::support::ulittle32_t Age;
56 // char PDBFileName[];
57};
58static_assert(sizeof(CvRecordPdb70) == 20,
59 "sizeof CvRecordPdb70 is not correct!");
60
61// Reference:
62// https://msdn.microsoft.com/en-us/library/windows/desktop/ms680394.aspx
63enum class MinidumpStreamType : uint32_t {
64 Unused = 0,
65 Reserved0 = 1,
66 Reserved1 = 2,
67 ThreadList = 3,
68 ModuleList = 4,
69 MemoryList = 5,
70 Exception = 6,
71 SystemInfo = 7,
72 ThreadExList = 8,
73 Memory64List = 9,
74 CommentA = 10,
75 CommentW = 11,
76 HandleData = 12,
77 FunctionTable = 13,
78 UnloadedModuleList = 14,
79 MiscInfo = 15,
80 MemoryInfoList = 16,
81 ThreadInfoList = 17,
82 HandleOperationList = 18,
83 Token = 19,
84 JavascriptData = 20,
85 SystemMemoryInfo = 21,
86 ProcessVMCounters = 22,
87 LastReserved = 0x0000ffff,
88
89 /* Breakpad extension types. 0x4767 = "Gg" */
90 BreakpadInfo = 0x47670001,
91 AssertionInfo = 0x47670002,
92 /* These are additional minidump stream values which are specific to
93 * the linux breakpad implementation. */
94 LinuxCPUInfo = 0x47670003, /* /proc/cpuinfo */
95 LinuxProcStatus = 0x47670004, /* /proc/$x/status */
96 LinuxLSBRelease = 0x47670005, /* /etc/lsb-release */
97 LinuxCMDLine = 0x47670006, /* /proc/$x/cmdline */
98 LinuxEnviron = 0x47670007, /* /proc/$x/environ */
99 LinuxAuxv = 0x47670008, /* /proc/$x/auxv */
100 LinuxMaps = 0x47670009, /* /proc/$x/maps */
101 LinuxDSODebug = 0x4767000A
102};
103
104// for MinidumpSystemInfo.processor_arch
105enum class MinidumpCPUArchitecture : uint16_t {
106 X86 = 0, /* PROCESSOR_ARCHITECTURE_INTEL */
107 MIPS = 1, /* PROCESSOR_ARCHITECTURE_MIPS */
108 Alpha = 2, /* PROCESSOR_ARCHITECTURE_ALPHA */
109 PPC = 3, /* PROCESSOR_ARCHITECTURE_PPC */
110 SHX = 4, /* PROCESSOR_ARCHITECTURE_SHX (Super-H) */
111 ARM = 5, /* PROCESSOR_ARCHITECTURE_ARM */
112 IA64 = 6, /* PROCESSOR_ARCHITECTURE_IA64 */
113 Alpha64 = 7, /* PROCESSOR_ARCHITECTURE_ALPHA64 */
114 MSIL = 8, /* PROCESSOR_ARCHITECTURE_MSIL
115 * (Microsoft Intermediate Language) */
116 AMD64 = 9, /* PROCESSOR_ARCHITECTURE_AMD64 */
117 X86Win64 = 10, /* PROCESSOR_ARCHITECTURE_IA32_ON_WIN64 (WoW64) */
118 SPARC = 0x8001, /* Breakpad-defined value for SPARC */
119 PPC64 = 0x8002, /* Breakpad-defined value for PPC64 */
120 ARM64 = 0x8003, /* Breakpad-defined value for ARM64 */
121 MIPS64 = 0x8004, /* Breakpad-defined value for MIPS64 */
122 Unknown = 0xffff /* PROCESSOR_ARCHITECTURE_UNKNOWN */
123};
124
125// for MinidumpSystemInfo.platform_id
126enum class MinidumpOSPlatform : uint32_t {
127 Win32S = 0, /* VER_PLATFORM_WIN32s (Windows 3.1) */
128 Win32Windows = 1, /* VER_PLATFORM_WIN32_WINDOWS (Windows 95-98-Me) */
129 Win32NT = 2, /* VER_PLATFORM_WIN32_NT (Windows NT, 2000+) */
130 Win32CE = 3, /* VER_PLATFORM_WIN32_CE, VER_PLATFORM_WIN32_HH
131 * (Windows CE, Windows Mobile, "Handheld") */
132
133 /* The following values are Breakpad-defined. */
134 Unix = 0x8000, /* Generic Unix-ish */
135 MacOSX = 0x8101, /* Mac OS X/Darwin */
136 IOS = 0x8102, /* iOS */
137 Linux = 0x8201, /* Linux */
138 Solaris = 0x8202, /* Solaris */
139 Android = 0x8203, /* Android */
140 PS3 = 0x8204, /* PS3 */
141 NaCl = 0x8205 /* Native Client (NaCl) */
142};
143
144// For MinidumpCPUInfo.arm_cpu_info.elf_hwcaps.
145// This matches the Linux kernel definitions from <asm/hwcaps.h>
146enum class MinidumpPCPUInformationARMElfHwCaps : uint32_t {
147 SWP = (1 << 0),
148 Half = (1 << 1),
149 Thumb = (1 << 2),
150 _26BIT = (1 << 3),
151 FastMult = (1 << 4),
152 FPA = (1 << 5),
153 VFP = (1 << 6),
154 EDSP = (1 << 7),
155 Java = (1 << 8),
156 IWMMXT = (1 << 9),
157 Crunch = (1 << 10),
158 ThumbEE = (1 << 11),
159 Neon = (1 << 12),
160 VFPv3 = (1 << 13),
161 VFPv3D16 = (1 << 14),
162 TLS = (1 << 15),
163 VFPv4 = (1 << 16),
164 IDIVA = (1 << 17),
165 IDIVT = (1 << 18),
166 LLVM_MARK_AS_BITMASK_ENUM(/* LargestValue = */ IDIVT)LLVM_BITMASK_LARGEST_ENUMERATOR = IDIVT
167};
168
169enum class MinidumpMiscInfoFlags : uint32_t {
170 ProcessID = (1 << 0),
171 ProcessTimes = (1 << 1),
172 LLVM_MARK_AS_BITMASK_ENUM(/* LargestValue = */ ProcessTimes)LLVM_BITMASK_LARGEST_ENUMERATOR = ProcessTimes
173};
174
175template <typename T>
176Status consumeObject(llvm::ArrayRef<uint8_t> &Buffer, const T *&Object) {
177 Status error;
178 if (Buffer.size() < sizeof(T)) {
3
Assuming the condition is true
4
Taking true branch
179 error.SetErrorString("Insufficient buffer!");
180 return error;
181 }
182
183 Object = reinterpret_cast<const T *>(Buffer.data());
184 Buffer = Buffer.drop_front(sizeof(T));
185 return error;
186}
5
Returning without writing to 'Object'
187
188// parse a MinidumpString which is with UTF-16
189// Reference:
190// https://msdn.microsoft.com/en-us/library/windows/desktop/ms680395(v=vs.85).aspx
191llvm::Optional<std::string> parseMinidumpString(llvm::ArrayRef<uint8_t> &data);
192
193// Reference:
194// https://msdn.microsoft.com/en-us/library/windows/desktop/ms680378(v=vs.85).aspx
195struct MinidumpHeader {
196 llvm::support::ulittle32_t signature;
197 llvm::support::ulittle32_t
198 version; // The high 16 bits of version field are implementation specific
199 llvm::support::ulittle32_t streams_count;
200 llvm::support::ulittle32_t
201 stream_directory_rva; // offset of the stream directory
202 llvm::support::ulittle32_t checksum;
203 llvm::support::ulittle32_t time_date_stamp; // time_t format
204 llvm::support::ulittle64_t flags;
205
206 static const MinidumpHeader *Parse(llvm::ArrayRef<uint8_t> &data);
207};
208static_assert(sizeof(MinidumpHeader) == 32,
209 "sizeof MinidumpHeader is not correct!");
210
211// Reference:
212// https://msdn.microsoft.com/en-us/library/windows/desktop/ms680383.aspx
213struct MinidumpLocationDescriptor {
214 llvm::support::ulittle32_t data_size;
215 llvm::support::ulittle32_t rva;
216};
217static_assert(sizeof(MinidumpLocationDescriptor) == 8,
218 "sizeof MinidumpLocationDescriptor is not correct!");
219
220// Reference:
221// https://msdn.microsoft.com/en-us/library/windows/desktop/ms680384(v=vs.85).aspx
222struct MinidumpMemoryDescriptor {
223 llvm::support::ulittle64_t start_of_memory_range;
224 MinidumpLocationDescriptor memory;
225
226 static llvm::ArrayRef<MinidumpMemoryDescriptor>
227 ParseMemoryList(llvm::ArrayRef<uint8_t> &data);
228};
229static_assert(sizeof(MinidumpMemoryDescriptor) == 16,
230 "sizeof MinidumpMemoryDescriptor is not correct!");
231
232struct MinidumpMemoryDescriptor64 {
233 llvm::support::ulittle64_t start_of_memory_range;
234 llvm::support::ulittle64_t data_size;
235
236 static std::pair<llvm::ArrayRef<MinidumpMemoryDescriptor64>, uint64_t>
237 ParseMemory64List(llvm::ArrayRef<uint8_t> &data);
238};
239static_assert(sizeof(MinidumpMemoryDescriptor64) == 16,
240 "sizeof MinidumpMemoryDescriptor64 is not correct!");
241
242// Reference:
243// https://msdn.microsoft.com/en-us/library/windows/desktop/ms680365.aspx
244struct MinidumpDirectory {
245 llvm::support::ulittle32_t stream_type;
246 MinidumpLocationDescriptor location;
247};
248static_assert(sizeof(MinidumpDirectory) == 12,
249 "sizeof MinidumpDirectory is not correct!");
250
251// Reference:
252// https://msdn.microsoft.com/en-us/library/windows/desktop/ms680385(v=vs.85).aspx
253struct MinidumpMemoryInfoListHeader {
254 llvm::support::ulittle32_t size_of_header;
255 llvm::support::ulittle32_t size_of_entry;
256 llvm::support::ulittle64_t num_of_entries;
257};
258static_assert(sizeof(MinidumpMemoryInfoListHeader) == 16,
259 "sizeof MinidumpMemoryInfoListHeader is not correct!");
260
261// Reference:
262// https://msdn.microsoft.com/en-us/library/windows/desktop/ms680386(v=vs.85).aspx
263struct MinidumpMemoryInfo {
264 llvm::support::ulittle64_t base_address;
265 llvm::support::ulittle64_t allocation_base;
266 llvm::support::ulittle32_t allocation_protect;
267 llvm::support::ulittle32_t alignment1;
268 llvm::support::ulittle64_t region_size;
269 llvm::support::ulittle32_t state;
270 llvm::support::ulittle32_t protect;
271 llvm::support::ulittle32_t type;
272 llvm::support::ulittle32_t alignment2;
273
274 static std::vector<const MinidumpMemoryInfo *>
275 ParseMemoryInfoList(llvm::ArrayRef<uint8_t> &data);
276};
277static_assert(sizeof(MinidumpMemoryInfo) == 48,
278 "sizeof MinidumpMemoryInfo is not correct!");
279
280enum class MinidumpMemoryInfoState : uint32_t {
281 MemCommit = 0x1000,
282 MemFree = 0x10000,
283 MemReserve = 0x2000,
284 LLVM_MARK_AS_BITMASK_ENUM(/* LargestValue = */ MemFree)LLVM_BITMASK_LARGEST_ENUMERATOR = MemFree
285};
286
287enum class MinidumpMemoryInfoType : uint32_t {
288 MemImage = 0x1000000,
289 MemMapped = 0x40000,
290 MemPrivate = 0x20000,
291 LLVM_MARK_AS_BITMASK_ENUM(/* LargestValue = */ MemImage)LLVM_BITMASK_LARGEST_ENUMERATOR = MemImage
292};
293
294// Reference:
295// https://msdn.microsoft.com/en-us/library/windows/desktop/aa366786(v=vs.85).aspx
296enum class MinidumpMemoryProtectionContants : uint32_t {
297 PageExecute = 0x10,
298 PageExecuteRead = 0x20,
299 PageExecuteReadWrite = 0x40,
300 PageExecuteWriteCopy = 0x80,
301 PageNoAccess = 0x01,
302 PageReadOnly = 0x02,
303 PageReadWrite = 0x04,
304 PageWriteCopy = 0x08,
305 PageTargetsInvalid = 0x40000000,
306 PageTargetsNoUpdate = 0x40000000,
307
308 PageWritable = PageExecuteReadWrite | PageExecuteWriteCopy | PageReadWrite |
309 PageWriteCopy,
310 PageExecutable = PageExecute | PageExecuteRead | PageExecuteReadWrite |
311 PageExecuteWriteCopy,
312 LLVM_MARK_AS_BITMASK_ENUM(/* LargestValue = */ PageTargetsInvalid)LLVM_BITMASK_LARGEST_ENUMERATOR = PageTargetsInvalid
313};
314
315// Reference:
316// https://msdn.microsoft.com/en-us/library/windows/desktop/ms680517(v=vs.85).aspx
317struct MinidumpThread {
318 llvm::support::ulittle32_t thread_id;
319 llvm::support::ulittle32_t suspend_count;
320 llvm::support::ulittle32_t priority_class;
321 llvm::support::ulittle32_t priority;
322 llvm::support::ulittle64_t teb;
323 MinidumpMemoryDescriptor stack;
324 MinidumpLocationDescriptor thread_context;
325
326 static const MinidumpThread *Parse(llvm::ArrayRef<uint8_t> &data);
327
328 static llvm::ArrayRef<MinidumpThread>
329 ParseThreadList(llvm::ArrayRef<uint8_t> &data);
330};
331static_assert(sizeof(MinidumpThread) == 48,
332 "sizeof MinidumpThread is not correct!");
333
334// Reference:
335// https://msdn.microsoft.com/en-us/library/windows/desktop/ms680396(v=vs.85).aspx
336union MinidumpCPUInfo {
337 struct {
338 llvm::support::ulittle32_t vendor_id[3]; /* cpuid 0: ebx, edx, ecx */
339 llvm::support::ulittle32_t version_information; /* cpuid 1: eax */
340 llvm::support::ulittle32_t feature_information; /* cpuid 1: edx */
341 llvm::support::ulittle32_t
342 amd_extended_cpu_features; /* cpuid 0x80000001, ebx */
343 } x86_cpu_info;
344 struct {
345 llvm::support::ulittle32_t cpuid;
346 llvm::support::ulittle32_t elf_hwcaps; /* linux specific, 0 otherwise */
347 } arm_cpu_info;
348 struct {
349 llvm::support::ulittle64_t processor_features[2];
350 } other_cpu_info;
351};
352static_assert(sizeof(MinidumpCPUInfo) == 24,
353 "sizeof MinidumpCPUInfo is not correct!");
354
355// Reference:
356// https://msdn.microsoft.com/en-us/library/windows/desktop/ms680396(v=vs.85).aspx
357struct MinidumpSystemInfo {
358 llvm::support::ulittle16_t processor_arch;
359 llvm::support::ulittle16_t processor_level;
360 llvm::support::ulittle16_t processor_revision;
361
362 uint8_t number_of_processors;
363 uint8_t product_type;
364
365 llvm::support::ulittle32_t major_version;
366 llvm::support::ulittle32_t minor_version;
367 llvm::support::ulittle32_t build_number;
368 llvm::support::ulittle32_t platform_id;
369 llvm::support::ulittle32_t csd_version_rva;
370
371 llvm::support::ulittle16_t suit_mask;
372 llvm::support::ulittle16_t reserved2;
373
374 MinidumpCPUInfo cpu;
375
376 static const MinidumpSystemInfo *Parse(llvm::ArrayRef<uint8_t> &data);
377};
378static_assert(sizeof(MinidumpSystemInfo) == 56,
379 "sizeof MinidumpSystemInfo is not correct!");
380
381// TODO misc2, misc3 ?
382// Reference:
383// https://msdn.microsoft.com/en-us/library/windows/desktop/ms680389(v=vs.85).aspx
384struct MinidumpMiscInfo {
385 llvm::support::ulittle32_t size;
386 // flags1 represents what info in the struct is valid
387 llvm::support::ulittle32_t flags1;
388 llvm::support::ulittle32_t process_id;
389 llvm::support::ulittle32_t process_create_time;
390 llvm::support::ulittle32_t process_user_time;
391 llvm::support::ulittle32_t process_kernel_time;
392
393 static const MinidumpMiscInfo *Parse(llvm::ArrayRef<uint8_t> &data);
394
395 llvm::Optional<lldb::pid_t> GetPid() const;
396};
397static_assert(sizeof(MinidumpMiscInfo) == 24,
398 "sizeof MinidumpMiscInfo is not correct!");
399
400// The /proc/pid/status is saved as an ascii string in the file
401class LinuxProcStatus {
402public:
403 llvm::StringRef proc_status;
404 lldb::pid_t pid;
405
406 static llvm::Optional<LinuxProcStatus> Parse(llvm::ArrayRef<uint8_t> &data);
407
408 lldb::pid_t GetPid() const;
409
410private:
411 LinuxProcStatus() = default;
412};
413
414// MinidumpModule stuff
415struct MinidumpVSFixedFileInfo {
416 llvm::support::ulittle32_t signature;
417 llvm::support::ulittle32_t struct_version;
418 llvm::support::ulittle32_t file_version_hi;
419 llvm::support::ulittle32_t file_version_lo;
420 llvm::support::ulittle32_t product_version_hi;
421 llvm::support::ulittle32_t product_version_lo;
422 // file_flags_mask - identifies valid bits in fileFlags
423 llvm::support::ulittle32_t file_flags_mask;
424 llvm::support::ulittle32_t file_flags;
425 llvm::support::ulittle32_t file_os;
426 llvm::support::ulittle32_t file_type;
427 llvm::support::ulittle32_t file_subtype;
428 llvm::support::ulittle32_t file_date_hi;
429 llvm::support::ulittle32_t file_date_lo;
430};
431static_assert(sizeof(MinidumpVSFixedFileInfo) == 52,
432 "sizeof MinidumpVSFixedFileInfo is not correct!");
433
434struct MinidumpModule {
435 llvm::support::ulittle64_t base_of_image;
436 llvm::support::ulittle32_t size_of_image;
437 llvm::support::ulittle32_t checksum;
438 llvm::support::ulittle32_t time_date_stamp;
439 llvm::support::ulittle32_t module_name_rva;
440 MinidumpVSFixedFileInfo version_info;
441 MinidumpLocationDescriptor CV_record;
442 MinidumpLocationDescriptor misc_record;
443 llvm::support::ulittle32_t reserved0[2];
444 llvm::support::ulittle32_t reserved1[2];
445
446 static const MinidumpModule *Parse(llvm::ArrayRef<uint8_t> &data);
447
448 static llvm::ArrayRef<MinidumpModule>
449 ParseModuleList(llvm::ArrayRef<uint8_t> &data);
450};
451static_assert(sizeof(MinidumpModule) == 108,
452 "sizeof MinidumpVSFixedFileInfo is not correct!");
453
454// Exception stuff
455struct MinidumpException {
456 enum : unsigned {
457 ExceptonInfoMaxParams = 15,
458 DumpRequested = 0xFFFFFFFF,
459 };
460
461 llvm::support::ulittle32_t exception_code;
462 llvm::support::ulittle32_t exception_flags;
463 llvm::support::ulittle64_t exception_record;
464 llvm::support::ulittle64_t exception_address;
465 llvm::support::ulittle32_t number_parameters;
466 llvm::support::ulittle32_t unused_alignment;
467 llvm::support::ulittle64_t exception_information[ExceptonInfoMaxParams];
468};
469static_assert(sizeof(MinidumpException) == 152,
470 "sizeof MinidumpException is not correct!");
471
472struct MinidumpExceptionStream {
473 llvm::support::ulittle32_t thread_id;
474 llvm::support::ulittle32_t alignment;
475 MinidumpException exception_record;
476 MinidumpLocationDescriptor thread_context;
477
478 static const MinidumpExceptionStream *Parse(llvm::ArrayRef<uint8_t> &data);
479};
480static_assert(sizeof(MinidumpExceptionStream) == 168,
481 "sizeof MinidumpExceptionStream is not correct!");
482
483} // namespace minidump
484} // namespace lldb_private
485#endif // liblldb_MinidumpTypes_h_