Bug Summary

File:tools/lldb/source/Plugins/Process/minidump/MinidumpTypes.cpp
Warning:line 219, column 7
Called C++ object pointer is uninitialized

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 LLDB_USE_BUILTIN_DEMANGLER -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I /build/llvm-toolchain-snapshot-7~svn337103/build-llvm/tools/lldb/source/Plugins/Process/minidump -I /build/llvm-toolchain-snapshot-7~svn337103/tools/lldb/source/Plugins/Process/minidump -I /build/llvm-toolchain-snapshot-7~svn337103/build-llvm/tools/lldb/include -I /build/llvm-toolchain-snapshot-7~svn337103/tools/lldb/include -I /build/llvm-toolchain-snapshot-7~svn337103/build-llvm/include -I /build/llvm-toolchain-snapshot-7~svn337103/include -I /usr/include/python2.7 -I /build/llvm-toolchain-snapshot-7~svn337103/tools/clang/include -I /build/llvm-toolchain-snapshot-7~svn337103/build-llvm/tools/lldb/../clang/include -I /build/llvm-toolchain-snapshot-7~svn337103/tools/lldb/source/. -U NDEBUG -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/c++/7.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/x86_64-linux-gnu/c++/7.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/x86_64-linux-gnu/c++/7.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/c++/7.3.0/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/7.3.0/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-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~svn337103/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-15-073923-5500-1 -x c++ /build/llvm-toolchain-snapshot-7~svn337103/tools/lldb/source/Plugins/Process/minidump/MinidumpTypes.cpp

/build/llvm-toolchain-snapshot-7~svn337103/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;
22 Status error = consumeObject(data, header);
23
24 const MinidumpHeaderConstants signature =
25 static_cast<const MinidumpHeaderConstants>(
26 static_cast<const uint32_t>(header->signature));
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 llvm::support::ulittle32_t *thread_count;
85 Status error = consumeObject(data, thread_count);
86 if (error.Fail() || *thread_count * sizeof(MinidumpThread) > data.size())
87 return {};
88
89 return llvm::ArrayRef<MinidumpThread>(
90 reinterpret_cast<const MinidumpThread *>(data.data()), *thread_count);
91}
92
93// MinidumpSystemInfo
94const MinidumpSystemInfo *
95MinidumpSystemInfo::Parse(llvm::ArrayRef<uint8_t> &data) {
96 const MinidumpSystemInfo *system_info;
97 Status error = consumeObject(data, system_info);
98 if (error.Fail())
99 return nullptr;
100
101 return system_info;
102}
103
104// MinidumpMiscInfo
105const MinidumpMiscInfo *MinidumpMiscInfo::Parse(llvm::ArrayRef<uint8_t> &data) {
106 const MinidumpMiscInfo *misc_info;
107 Status error = consumeObject(data, misc_info);
108 if (error.Fail())
109 return nullptr;
110
111 return misc_info;
112}
113
114llvm::Optional<lldb::pid_t> MinidumpMiscInfo::GetPid() const {
115 uint32_t pid_flag =
116 static_cast<const uint32_t>(MinidumpMiscInfoFlags::ProcessID);
117 if (flags1 & pid_flag)
118 return llvm::Optional<lldb::pid_t>(process_id);
119
120 return llvm::None;
121}
122
123// Linux Proc Status
124// it's stored as an ascii string in the file
125llvm::Optional<LinuxProcStatus>
126LinuxProcStatus::Parse(llvm::ArrayRef<uint8_t> &data) {
127 LinuxProcStatus result;
128 result.proc_status =
129 llvm::StringRef(reinterpret_cast<const char *>(data.data()), data.size());
130 data = data.drop_front(data.size());
131
132 llvm::SmallVector<llvm::StringRef, 0> lines;
133 result.proc_status.split(lines, '\n', 42);
134 // /proc/$pid/status has 41 lines, but why not use 42?
135 for (auto line : lines) {
136 if (line.consume_front("Pid:")) {
137 line = line.trim();
138 if (!line.getAsInteger(10, result.pid))
139 return result;
140 }
141 }
142
143 return llvm::None;
144}
145
146lldb::pid_t LinuxProcStatus::GetPid() const { return pid; }
147
148// Module stuff
149const MinidumpModule *MinidumpModule::Parse(llvm::ArrayRef<uint8_t> &data) {
150 const MinidumpModule *module = nullptr;
151 Status error = consumeObject(data, module);
152 if (error.Fail())
153 return nullptr;
154
155 return module;
156}
157
158llvm::ArrayRef<MinidumpModule>
159MinidumpModule::ParseModuleList(llvm::ArrayRef<uint8_t> &data) {
160
161 const llvm::support::ulittle32_t *modules_count;
162 Status error = consumeObject(data, modules_count);
163 if (error.Fail() || *modules_count * sizeof(MinidumpModule) > data.size())
164 return {};
165
166 return llvm::ArrayRef<MinidumpModule>(
167 reinterpret_cast<const MinidumpModule *>(data.data()), *modules_count);
168}
169
170// Exception stuff
171const MinidumpExceptionStream *
172MinidumpExceptionStream::Parse(llvm::ArrayRef<uint8_t> &data) {
173 const MinidumpExceptionStream *exception_stream = nullptr;
174 Status error = consumeObject(data, exception_stream);
175 if (error.Fail())
176 return nullptr;
177
178 return exception_stream;
179}
180
181llvm::ArrayRef<MinidumpMemoryDescriptor>
182MinidumpMemoryDescriptor::ParseMemoryList(llvm::ArrayRef<uint8_t> &data) {
183 const llvm::support::ulittle32_t *mem_ranges_count;
184 Status error = consumeObject(data, mem_ranges_count);
185 if (error.Fail() ||
186 *mem_ranges_count * sizeof(MinidumpMemoryDescriptor) > data.size())
187 return {};
188
189 return llvm::makeArrayRef(
190 reinterpret_cast<const MinidumpMemoryDescriptor *>(data.data()),
191 *mem_ranges_count);
192}
193
194std::pair<llvm::ArrayRef<MinidumpMemoryDescriptor64>, uint64_t>
195MinidumpMemoryDescriptor64::ParseMemory64List(llvm::ArrayRef<uint8_t> &data) {
196 const llvm::support::ulittle64_t *mem_ranges_count;
197 Status error = consumeObject(data, mem_ranges_count);
198 if (error.Fail() ||
199 *mem_ranges_count * sizeof(MinidumpMemoryDescriptor64) > data.size())
200 return {};
201
202 const llvm::support::ulittle64_t *base_rva;
203 error = consumeObject(data, base_rva);
204 if (error.Fail())
205 return {};
206
207 return std::make_pair(
208 llvm::makeArrayRef(
209 reinterpret_cast<const MinidumpMemoryDescriptor64 *>(data.data()),
210 *mem_ranges_count),
211 *base_rva);
212}
213
214std::vector<const MinidumpMemoryInfo *>
215MinidumpMemoryInfo::ParseMemoryInfoList(llvm::ArrayRef<uint8_t> &data) {
216 const MinidumpMemoryInfoListHeader *header;
1
'header' declared without an initial value
217 Status error = consumeObject(data, header);
2
Calling 'consumeObject<lldb_private::minidump::MinidumpMemoryInfoListHeader>'
6
Returning from 'consumeObject<lldb_private::minidump::MinidumpMemoryInfoListHeader>'
218 if (error.Fail() ||
7
Assuming the condition is false
219 header->size_of_header < sizeof(MinidumpMemoryInfoListHeader) ||
8
Called C++ object pointer is uninitialized
220 header->size_of_entry < sizeof(MinidumpMemoryInfo))
221 return {};
222
223 data = data.drop_front(header->size_of_header -
224 sizeof(MinidumpMemoryInfoListHeader));
225
226 if (header->size_of_entry * header->num_of_entries > data.size())
227 return {};
228
229 std::vector<const MinidumpMemoryInfo *> result;
230 for (uint64_t i = 0; i < header->num_of_entries; ++i) {
231 result.push_back(reinterpret_cast<const MinidumpMemoryInfo *>(
232 data.data() + i * header->size_of_entry));
233 }
234
235 return result;
236}

/build/llvm-toolchain-snapshot-7~svn337103/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_