Bug Summary

File:build/llvm-toolchain-snapshot-16~++20220904122748+c444af1c20b3/lldb/source/Plugins/Process/minidump/MinidumpParser.cpp
Warning:line 62, column 54
Called C++ object pointer is null

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name MinidumpParser.cpp -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 -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -ffunction-sections -fdata-sections -fcoverage-compilation-dir=/build/llvm-toolchain-snapshot-16~++20220904122748+c444af1c20b3/build-llvm/tools/clang/stage2-bins -resource-dir /usr/lib/llvm-16/lib/clang/16.0.0 -isystem /usr/include/libxml2 -D HAVE_ROUND -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I tools/lldb/source/Plugins/Process/minidump -I /build/llvm-toolchain-snapshot-16~++20220904122748+c444af1c20b3/lldb/source/Plugins/Process/minidump -I /build/llvm-toolchain-snapshot-16~++20220904122748+c444af1c20b3/lldb/include -I tools/lldb/include -I include -I /build/llvm-toolchain-snapshot-16~++20220904122748+c444af1c20b3/llvm/include -I /usr/include/python3.9 -I /build/llvm-toolchain-snapshot-16~++20220904122748+c444af1c20b3/clang/include -I tools/lldb/../clang/include -I /build/llvm-toolchain-snapshot-16~++20220904122748+c444af1c20b3/lldb/source -I tools/lldb/source -D _FORTIFY_SOURCE=2 -D NDEBUG -U NDEBUG -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/x86_64-linux-gnu/c++/10 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/backward -internal-isystem /usr/lib/llvm-16/lib/clang/16.0.0/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fmacro-prefix-map=/build/llvm-toolchain-snapshot-16~++20220904122748+c444af1c20b3/build-llvm/tools/clang/stage2-bins=build-llvm/tools/clang/stage2-bins -fmacro-prefix-map=/build/llvm-toolchain-snapshot-16~++20220904122748+c444af1c20b3/= -fcoverage-prefix-map=/build/llvm-toolchain-snapshot-16~++20220904122748+c444af1c20b3/build-llvm/tools/clang/stage2-bins=build-llvm/tools/clang/stage2-bins -fcoverage-prefix-map=/build/llvm-toolchain-snapshot-16~++20220904122748+c444af1c20b3/= -O2 -Wno-unused-command-line-argument -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-maybe-uninitialized -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wno-comment -Wno-misleading-indentation -Wno-deprecated-declarations -Wno-unknown-pragmas -Wno-strict-aliasing -Wno-stringop-truncation -std=c++17 -fdeprecated-macro -fdebug-compilation-dir=/build/llvm-toolchain-snapshot-16~++20220904122748+c444af1c20b3/build-llvm/tools/clang/stage2-bins -fdebug-prefix-map=/build/llvm-toolchain-snapshot-16~++20220904122748+c444af1c20b3/build-llvm/tools/clang/stage2-bins=build-llvm/tools/clang/stage2-bins -fdebug-prefix-map=/build/llvm-toolchain-snapshot-16~++20220904122748+c444af1c20b3/= -ferror-limit 19 -fvisibility-inlines-hidden -stack-protector 2 -fgnuc-version=4.2.1 -fcolor-diagnostics -vectorize-loops -vectorize-slp -analyzer-output=html -analyzer-config stable-report-filename=true -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/scan-build-2022-09-04-125545-48738-1 -x c++ /build/llvm-toolchain-snapshot-16~++20220904122748+c444af1c20b3/lldb/source/Plugins/Process/minidump/MinidumpParser.cpp

/build/llvm-toolchain-snapshot-16~++20220904122748+c444af1c20b3/lldb/source/Plugins/Process/minidump/MinidumpParser.cpp

1//===-- MinidumpParser.cpp ------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "MinidumpParser.h"
10#include "NtStructures.h"
11#include "RegisterContextMinidump_x86_32.h"
12
13#include "Plugins/Process/Utility/LinuxProcMaps.h"
14#include "lldb/Utility/LLDBAssert.h"
15#include "lldb/Utility/LLDBLog.h"
16#include "lldb/Utility/Log.h"
17
18// C includes
19// C++ includes
20#include <algorithm>
21#include <map>
22#include <vector>
23#include <utility>
24
25using namespace lldb_private;
26using namespace minidump;
27
28llvm::Expected<MinidumpParser>
29MinidumpParser::Create(const lldb::DataBufferSP &data_sp) {
30 auto ExpectedFile = llvm::object::MinidumpFile::create(
31 llvm::MemoryBufferRef(toStringRef(data_sp->GetData()), "minidump"));
32 if (!ExpectedFile)
33 return ExpectedFile.takeError();
34
35 return MinidumpParser(data_sp, std::move(*ExpectedFile));
36}
37
38MinidumpParser::MinidumpParser(lldb::DataBufferSP data_sp,
39 std::unique_ptr<llvm::object::MinidumpFile> file)
40 : m_data_sp(std::move(data_sp)), m_file(std::move(file)) {}
41
42llvm::ArrayRef<uint8_t> MinidumpParser::GetData() {
43 return llvm::ArrayRef<uint8_t>(m_data_sp->GetBytes(),
44 m_data_sp->GetByteSize());
45}
46
47llvm::ArrayRef<uint8_t> MinidumpParser::GetStream(StreamType stream_type) {
48 return m_file->getRawStream(stream_type).value_or(llvm::ArrayRef<uint8_t>());
49}
50
51UUID MinidumpParser::GetModuleUUID(const minidump::Module *module) {
52 auto cv_record =
53 GetData().slice(module->CvRecord.RVA, module->CvRecord.DataSize);
54
55 // Read the CV record signature
56 const llvm::support::ulittle32_t *signature = nullptr;
1
'signature' initialized to a null pointer value
57 Status error = consumeObject(cv_record, signature);
2
Calling 'consumeObject<llvm::support::detail::packed_endian_specific_integral<unsigned int, llvm::support::little, 1, 1>>'
6
Returning from 'consumeObject<llvm::support::detail::packed_endian_specific_integral<unsigned int, llvm::support::little, 1, 1>>'
58 if (error.Fail())
7
Assuming the condition is false
8
Taking false branch
59 return UUID();
60
61 const CvSignature cv_signature =
62 static_cast<CvSignature>(static_cast<uint32_t>(*signature));
9
Called C++ object pointer is null
63
64 if (cv_signature == CvSignature::Pdb70) {
65 const UUID::CvRecordPdb70 *pdb70_uuid = nullptr;
66 Status error = consumeObject(cv_record, pdb70_uuid);
67 if (error.Fail())
68 return UUID();
69 if (GetArchitecture().GetTriple().isOSBinFormatELF()) {
70 if (pdb70_uuid->Age != 0)
71 return UUID(pdb70_uuid, sizeof(*pdb70_uuid));
72 return UUID(&pdb70_uuid->Uuid,
73 sizeof(pdb70_uuid->Uuid));
74 }
75 return UUID(*pdb70_uuid);
76 } else if (cv_signature == CvSignature::ElfBuildId)
77 return UUID(cv_record);
78
79 return UUID();
80}
81
82llvm::ArrayRef<minidump::Thread> MinidumpParser::GetThreads() {
83 auto ExpectedThreads = GetMinidumpFile().getThreadList();
84 if (ExpectedThreads)
85 return *ExpectedThreads;
86
87 LLDB_LOG_ERROR(GetLog(LLDBLog::Thread), ExpectedThreads.takeError(),do { ::lldb_private::Log *log_private = (GetLog(LLDBLog::Thread
)); ::llvm::Error error_private = (ExpectedThreads.takeError(
)); if (log_private && error_private) { log_private->
FormatError(::std::move(error_private), "lldb/source/Plugins/Process/minidump/MinidumpParser.cpp"
, __func__, "Failed to read thread list: {0}"); } else ::llvm
::consumeError(::std::move(error_private)); } while (0)
88 "Failed to read thread list: {0}")do { ::lldb_private::Log *log_private = (GetLog(LLDBLog::Thread
)); ::llvm::Error error_private = (ExpectedThreads.takeError(
)); if (log_private && error_private) { log_private->
FormatError(::std::move(error_private), "lldb/source/Plugins/Process/minidump/MinidumpParser.cpp"
, __func__, "Failed to read thread list: {0}"); } else ::llvm
::consumeError(::std::move(error_private)); } while (0)
;
89 return {};
90}
91
92llvm::ArrayRef<uint8_t>
93MinidumpParser::GetThreadContext(const LocationDescriptor &location) {
94 if (location.RVA + location.DataSize > GetData().size())
95 return {};
96 return GetData().slice(location.RVA, location.DataSize);
97}
98
99llvm::ArrayRef<uint8_t>
100MinidumpParser::GetThreadContext(const minidump::Thread &td) {
101 return GetThreadContext(td.Context);
102}
103
104llvm::ArrayRef<uint8_t>
105MinidumpParser::GetThreadContextWow64(const minidump::Thread &td) {
106 // On Windows, a 32-bit process can run on a 64-bit machine under WOW64. If
107 // the minidump was captured with a 64-bit debugger, then the CONTEXT we just
108 // grabbed from the mini_dump_thread is the one for the 64-bit "native"
109 // process rather than the 32-bit "guest" process we care about. In this
110 // case, we can get the 32-bit CONTEXT from the TEB (Thread Environment
111 // Block) of the 64-bit process.
112 auto teb_mem = GetMemory(td.EnvironmentBlock, sizeof(TEB64));
113 if (teb_mem.empty())
114 return {};
115
116 const TEB64 *wow64teb;
117 Status error = consumeObject(teb_mem, wow64teb);
118 if (error.Fail())
119 return {};
120
121 // Slot 1 of the thread-local storage in the 64-bit TEB points to a structure
122 // that includes the 32-bit CONTEXT (after a ULONG). See:
123 // https://msdn.microsoft.com/en-us/library/ms681670.aspx
124 auto context =
125 GetMemory(wow64teb->tls_slots[1] + 4, sizeof(MinidumpContext_x86_32));
126 if (context.size() < sizeof(MinidumpContext_x86_32))
127 return {};
128
129 return context;
130 // NOTE: We don't currently use the TEB for anything else. If we
131 // need it in the future, the 32-bit TEB is located according to the address
132 // stored in the first slot of the 64-bit TEB (wow64teb.Reserved1[0]).
133}
134
135ArchSpec MinidumpParser::GetArchitecture() {
136 if (m_arch.IsValid())
137 return m_arch;
138
139 // Set the architecture in m_arch
140 llvm::Expected<const SystemInfo &> system_info = m_file->getSystemInfo();
141
142 if (!system_info) {
143 LLDB_LOG_ERROR(GetLog(LLDBLog::Process), system_info.takeError(),do { ::lldb_private::Log *log_private = (GetLog(LLDBLog::Process
)); ::llvm::Error error_private = (system_info.takeError()); if
(log_private && error_private) { log_private->FormatError
(::std::move(error_private), "lldb/source/Plugins/Process/minidump/MinidumpParser.cpp"
, __func__, "Failed to read SystemInfo stream: {0}"); } else ::
llvm::consumeError(::std::move(error_private)); } while (0)
144 "Failed to read SystemInfo stream: {0}")do { ::lldb_private::Log *log_private = (GetLog(LLDBLog::Process
)); ::llvm::Error error_private = (system_info.takeError()); if
(log_private && error_private) { log_private->FormatError
(::std::move(error_private), "lldb/source/Plugins/Process/minidump/MinidumpParser.cpp"
, __func__, "Failed to read SystemInfo stream: {0}"); } else ::
llvm::consumeError(::std::move(error_private)); } while (0)
;
145 return m_arch;
146 }
147
148 // TODO what to do about big endiand flavors of arm ?
149 // TODO set the arm subarch stuff if the minidump has info about it
150
151 llvm::Triple triple;
152 triple.setVendor(llvm::Triple::VendorType::UnknownVendor);
153
154 switch (system_info->ProcessorArch) {
155 case ProcessorArchitecture::X86:
156 triple.setArch(llvm::Triple::ArchType::x86);
157 break;
158 case ProcessorArchitecture::AMD64:
159 triple.setArch(llvm::Triple::ArchType::x86_64);
160 break;
161 case ProcessorArchitecture::ARM:
162 triple.setArch(llvm::Triple::ArchType::arm);
163 break;
164 case ProcessorArchitecture::ARM64:
165 case ProcessorArchitecture::BP_ARM64:
166 triple.setArch(llvm::Triple::ArchType::aarch64);
167 break;
168 default:
169 triple.setArch(llvm::Triple::ArchType::UnknownArch);
170 break;
171 }
172
173 // TODO add all of the OSes that Minidump/breakpad distinguishes?
174 switch (system_info->PlatformId) {
175 case OSPlatform::Win32S:
176 case OSPlatform::Win32Windows:
177 case OSPlatform::Win32NT:
178 case OSPlatform::Win32CE:
179 triple.setOS(llvm::Triple::OSType::Win32);
180 triple.setVendor(llvm::Triple::VendorType::PC);
181 break;
182 case OSPlatform::Linux:
183 triple.setOS(llvm::Triple::OSType::Linux);
184 break;
185 case OSPlatform::MacOSX:
186 triple.setOS(llvm::Triple::OSType::MacOSX);
187 triple.setVendor(llvm::Triple::Apple);
188 break;
189 case OSPlatform::IOS:
190 triple.setOS(llvm::Triple::OSType::IOS);
191 triple.setVendor(llvm::Triple::Apple);
192 break;
193 case OSPlatform::Android:
194 triple.setOS(llvm::Triple::OSType::Linux);
195 triple.setEnvironment(llvm::Triple::EnvironmentType::Android);
196 break;
197 default: {
198 triple.setOS(llvm::Triple::OSType::UnknownOS);
199 auto ExpectedCSD = m_file->getString(system_info->CSDVersionRVA);
200 if (!ExpectedCSD) {
201 LLDB_LOG_ERROR(GetLog(LLDBLog::Process), ExpectedCSD.takeError(),do { ::lldb_private::Log *log_private = (GetLog(LLDBLog::Process
)); ::llvm::Error error_private = (ExpectedCSD.takeError()); if
(log_private && error_private) { log_private->FormatError
(::std::move(error_private), "lldb/source/Plugins/Process/minidump/MinidumpParser.cpp"
, __func__, "Failed to CSD Version string: {0}"); } else ::llvm
::consumeError(::std::move(error_private)); } while (0)
202 "Failed to CSD Version string: {0}")do { ::lldb_private::Log *log_private = (GetLog(LLDBLog::Process
)); ::llvm::Error error_private = (ExpectedCSD.takeError()); if
(log_private && error_private) { log_private->FormatError
(::std::move(error_private), "lldb/source/Plugins/Process/minidump/MinidumpParser.cpp"
, __func__, "Failed to CSD Version string: {0}"); } else ::llvm
::consumeError(::std::move(error_private)); } while (0)
;
203 } else {
204 if (ExpectedCSD->find("Linux") != std::string::npos)
205 triple.setOS(llvm::Triple::OSType::Linux);
206 }
207 break;
208 }
209 }
210 m_arch.SetTriple(triple);
211 return m_arch;
212}
213
214const MinidumpMiscInfo *MinidumpParser::GetMiscInfo() {
215 llvm::ArrayRef<uint8_t> data = GetStream(StreamType::MiscInfo);
216
217 if (data.size() == 0)
218 return nullptr;
219
220 return MinidumpMiscInfo::Parse(data);
221}
222
223llvm::Optional<LinuxProcStatus> MinidumpParser::GetLinuxProcStatus() {
224 llvm::ArrayRef<uint8_t> data = GetStream(StreamType::LinuxProcStatus);
225
226 if (data.size() == 0)
227 return llvm::None;
228
229 return LinuxProcStatus::Parse(data);
230}
231
232llvm::Optional<lldb::pid_t> MinidumpParser::GetPid() {
233 const MinidumpMiscInfo *misc_info = GetMiscInfo();
234 if (misc_info != nullptr) {
235 return misc_info->GetPid();
236 }
237
238 llvm::Optional<LinuxProcStatus> proc_status = GetLinuxProcStatus();
239 if (proc_status) {
240 return proc_status->GetPid();
241 }
242
243 return llvm::None;
244}
245
246llvm::ArrayRef<minidump::Module> MinidumpParser::GetModuleList() {
247 auto ExpectedModules = GetMinidumpFile().getModuleList();
248 if (ExpectedModules)
249 return *ExpectedModules;
250
251 LLDB_LOG_ERROR(GetLog(LLDBLog::Modules), ExpectedModules.takeError(),do { ::lldb_private::Log *log_private = (GetLog(LLDBLog::Modules
)); ::llvm::Error error_private = (ExpectedModules.takeError(
)); if (log_private && error_private) { log_private->
FormatError(::std::move(error_private), "lldb/source/Plugins/Process/minidump/MinidumpParser.cpp"
, __func__, "Failed to read module list: {0}"); } else ::llvm
::consumeError(::std::move(error_private)); } while (0)
252 "Failed to read module list: {0}")do { ::lldb_private::Log *log_private = (GetLog(LLDBLog::Modules
)); ::llvm::Error error_private = (ExpectedModules.takeError(
)); if (log_private && error_private) { log_private->
FormatError(::std::move(error_private), "lldb/source/Plugins/Process/minidump/MinidumpParser.cpp"
, __func__, "Failed to read module list: {0}"); } else ::llvm
::consumeError(::std::move(error_private)); } while (0)
;
253 return {};
254}
255
256static bool
257CreateRegionsCacheFromLinuxMaps(MinidumpParser &parser,
258 std::vector<MemoryRegionInfo> &regions) {
259 auto data = parser.GetStream(StreamType::LinuxMaps);
260 if (data.empty())
261 return false;
262
263 Log *log = GetLog(LLDBLog::Expressions);
264 ParseLinuxMapRegions(
265 llvm::toStringRef(data),
266 [&regions, &log](llvm::Expected<MemoryRegionInfo> region) -> bool {
267 if (region)
268 regions.push_back(*region);
269 else
270 LLDB_LOG_ERROR(log, region.takeError(),do { ::lldb_private::Log *log_private = (log); ::llvm::Error error_private
= (region.takeError()); if (log_private && error_private
) { log_private->FormatError(::std::move(error_private), "lldb/source/Plugins/Process/minidump/MinidumpParser.cpp"
, __func__, "Reading memory region from minidump failed: {0}"
); } else ::llvm::consumeError(::std::move(error_private)); }
while (0)
271 "Reading memory region from minidump failed: {0}")do { ::lldb_private::Log *log_private = (log); ::llvm::Error error_private
= (region.takeError()); if (log_private && error_private
) { log_private->FormatError(::std::move(error_private), "lldb/source/Plugins/Process/minidump/MinidumpParser.cpp"
, __func__, "Reading memory region from minidump failed: {0}"
); } else ::llvm::consumeError(::std::move(error_private)); }
while (0)
;
272 return true;
273 });
274 return !regions.empty();
275}
276
277/// Check for the memory regions starting at \a load_addr for a contiguous
278/// section that has execute permissions that matches the module path.
279///
280/// When we load a breakpad generated minidump file, we might have the
281/// /proc/<pid>/maps text for a process that details the memory map of the
282/// process that the minidump is describing. This checks the sorted memory
283/// regions for a section that has execute permissions. A sample maps files
284/// might look like:
285///
286/// 00400000-00401000 r--p 00000000 fd:01 2838574 /tmp/a.out
287/// 00401000-00402000 r-xp 00001000 fd:01 2838574 /tmp/a.out
288/// 00402000-00403000 r--p 00002000 fd:01 2838574 /tmp/a.out
289/// 00403000-00404000 r--p 00002000 fd:01 2838574 /tmp/a.out
290/// 00404000-00405000 rw-p 00003000 fd:01 2838574 /tmp/a.out
291/// ...
292///
293/// This function should return true when given 0x00400000 and "/tmp/a.out"
294/// is passed in as the path since it has a consecutive memory region for
295/// "/tmp/a.out" that has execute permissions at 0x00401000. This will help us
296/// differentiate if a file has been memory mapped into a process for reading
297/// and breakpad ends up saving a minidump file that has two module entries for
298/// a given file: one that is read only for the entire file, and then one that
299/// is the real executable that is loaded into memory for execution. For memory
300/// mapped files they will typically show up and r--p permissions and a range
301/// matcning the entire range of the file on disk:
302///
303/// 00800000-00805000 r--p 00000000 fd:01 2838574 /tmp/a.out
304/// 00805000-00806000 r-xp 00001000 fd:01 1234567 /usr/lib/libc.so
305///
306/// This function should return false when asked about 0x00800000 with
307/// "/tmp/a.out" as the path.
308///
309/// \param[in] path
310/// The path to the module to check for in the memory regions. Only sequential
311/// memory regions whose paths match this path will be considered when looking
312/// for execute permissions.
313///
314/// \param[in] regions
315/// A sorted list of memory regions obtained from a call to
316/// CreateRegionsCacheFromLinuxMaps.
317///
318/// \param[in] base_of_image
319/// The load address of this module from BaseOfImage in the modules list.
320///
321/// \return
322/// True if a contiguous region of memory belonging to the module with a
323/// matching path exists that has executable permissions. Returns false if
324/// \a regions is empty or if there are no regions with execute permissions
325/// that match \a path.
326
327static bool CheckForLinuxExecutable(ConstString path,
328 const MemoryRegionInfos &regions,
329 lldb::addr_t base_of_image) {
330 if (regions.empty())
331 return false;
332 lldb::addr_t addr = base_of_image;
333 MemoryRegionInfo region = MinidumpParser::GetMemoryRegionInfo(regions, addr);
334 while (region.GetName() == path) {
335 if (region.GetExecutable() == MemoryRegionInfo::eYes)
336 return true;
337 addr += region.GetRange().GetByteSize();
338 region = MinidumpParser::GetMemoryRegionInfo(regions, addr);
339 }
340 return false;
341}
342
343std::vector<const minidump::Module *> MinidumpParser::GetFilteredModuleList() {
344 Log *log = GetLog(LLDBLog::Modules);
345 auto ExpectedModules = GetMinidumpFile().getModuleList();
346 if (!ExpectedModules) {
347 LLDB_LOG_ERROR(log, ExpectedModules.takeError(),do { ::lldb_private::Log *log_private = (log); ::llvm::Error error_private
= (ExpectedModules.takeError()); if (log_private && error_private
) { log_private->FormatError(::std::move(error_private), "lldb/source/Plugins/Process/minidump/MinidumpParser.cpp"
, __func__, "Failed to read module list: {0}"); } else ::llvm
::consumeError(::std::move(error_private)); } while (0)
348 "Failed to read module list: {0}")do { ::lldb_private::Log *log_private = (log); ::llvm::Error error_private
= (ExpectedModules.takeError()); if (log_private && error_private
) { log_private->FormatError(::std::move(error_private), "lldb/source/Plugins/Process/minidump/MinidumpParser.cpp"
, __func__, "Failed to read module list: {0}"); } else ::llvm
::consumeError(::std::move(error_private)); } while (0)
;
349 return {};
350 }
351
352 // Create memory regions from the linux maps only. We do this to avoid issues
353 // with breakpad generated minidumps where if someone has mmap'ed a shared
354 // library into memory to accesss its data in the object file, we can get a
355 // minidump with two mappings for a binary: one whose base image points to a
356 // memory region that is read + execute and one that is read only.
357 MemoryRegionInfos linux_regions;
358 if (CreateRegionsCacheFromLinuxMaps(*this, linux_regions))
359 llvm::sort(linux_regions);
360
361 // map module_name -> filtered_modules index
362 typedef llvm::StringMap<size_t> MapType;
363 MapType module_name_to_filtered_index;
364
365 std::vector<const minidump::Module *> filtered_modules;
366
367 for (const auto &module : *ExpectedModules) {
368 auto ExpectedName = m_file->getString(module.ModuleNameRVA);
369 if (!ExpectedName) {
370 LLDB_LOG_ERROR(log, ExpectedName.takeError(),do { ::lldb_private::Log *log_private = (log); ::llvm::Error error_private
= (ExpectedName.takeError()); if (log_private && error_private
) { log_private->FormatError(::std::move(error_private), "lldb/source/Plugins/Process/minidump/MinidumpParser.cpp"
, __func__, "Failed to get module name: {0}"); } else ::llvm::
consumeError(::std::move(error_private)); } while (0)
371 "Failed to get module name: {0}")do { ::lldb_private::Log *log_private = (log); ::llvm::Error error_private
= (ExpectedName.takeError()); if (log_private && error_private
) { log_private->FormatError(::std::move(error_private), "lldb/source/Plugins/Process/minidump/MinidumpParser.cpp"
, __func__, "Failed to get module name: {0}"); } else ::llvm::
consumeError(::std::move(error_private)); } while (0)
;
372 continue;
373 }
374
375 MapType::iterator iter;
376 bool inserted;
377 // See if we have inserted this module aready into filtered_modules. If we
378 // haven't insert an entry into module_name_to_filtered_index with the
379 // index where we will insert it if it isn't in the vector already.
380 std::tie(iter, inserted) = module_name_to_filtered_index.try_emplace(
381 *ExpectedName, filtered_modules.size());
382
383 if (inserted) {
384 // This module has not been seen yet, insert it into filtered_modules at
385 // the index that was inserted into module_name_to_filtered_index using
386 // "filtered_modules.size()" above.
387 filtered_modules.push_back(&module);
388 } else {
389 // We have a duplicate module entry. Check the linux regions to see if
390 // either module is not really a mapped executable. If one but not the
391 // other is a real mapped executable, prefer the executable one. This
392 // can happen when a process mmap's in the file for an executable in
393 // order to read bytes from the executable file. A memory region mapping
394 // will exist for the mmap'ed version and for the loaded executable, but
395 // only one will have a consecutive region that is executable in the
396 // memory regions.
397 auto dup_module = filtered_modules[iter->second];
398 ConstString name(*ExpectedName);
399 bool is_executable =
400 CheckForLinuxExecutable(name, linux_regions, module.BaseOfImage);
401 bool dup_is_executable =
402 CheckForLinuxExecutable(name, linux_regions, dup_module->BaseOfImage);
403
404 if (is_executable != dup_is_executable) {
405 if (is_executable)
406 filtered_modules[iter->second] = &module;
407 continue;
408 }
409 // This module has been seen. Modules are sometimes mentioned multiple
410 // times when they are mapped discontiguously, so find the module with
411 // the lowest "base_of_image" and use that as the filtered module.
412 if (module.BaseOfImage < dup_module->BaseOfImage)
413 filtered_modules[iter->second] = &module;
414 }
415 }
416 return filtered_modules;
417}
418
419const minidump::ExceptionStream *MinidumpParser::GetExceptionStream() {
420 auto ExpectedStream = GetMinidumpFile().getExceptionStream();
421 if (ExpectedStream)
422 return &*ExpectedStream;
423
424 LLDB_LOG_ERROR(GetLog(LLDBLog::Process), ExpectedStream.takeError(),do { ::lldb_private::Log *log_private = (GetLog(LLDBLog::Process
)); ::llvm::Error error_private = (ExpectedStream.takeError()
); if (log_private && error_private) { log_private->
FormatError(::std::move(error_private), "lldb/source/Plugins/Process/minidump/MinidumpParser.cpp"
, __func__, "Failed to read minidump exception stream: {0}");
} else ::llvm::consumeError(::std::move(error_private)); } while
(0)
425 "Failed to read minidump exception stream: {0}")do { ::lldb_private::Log *log_private = (GetLog(LLDBLog::Process
)); ::llvm::Error error_private = (ExpectedStream.takeError()
); if (log_private && error_private) { log_private->
FormatError(::std::move(error_private), "lldb/source/Plugins/Process/minidump/MinidumpParser.cpp"
, __func__, "Failed to read minidump exception stream: {0}");
} else ::llvm::consumeError(::std::move(error_private)); } while
(0)
;
426 return nullptr;
427}
428
429llvm::Optional<minidump::Range>
430MinidumpParser::FindMemoryRange(lldb::addr_t addr) {
431 llvm::ArrayRef<uint8_t> data64 = GetStream(StreamType::Memory64List);
432 Log *log = GetLog(LLDBLog::Modules);
433
434 auto ExpectedMemory = GetMinidumpFile().getMemoryList();
435 if (!ExpectedMemory) {
436 LLDB_LOG_ERROR(log, ExpectedMemory.takeError(),do { ::lldb_private::Log *log_private = (log); ::llvm::Error error_private
= (ExpectedMemory.takeError()); if (log_private && error_private
) { log_private->FormatError(::std::move(error_private), "lldb/source/Plugins/Process/minidump/MinidumpParser.cpp"
, __func__, "Failed to read memory list: {0}"); } else ::llvm
::consumeError(::std::move(error_private)); } while (0)
437 "Failed to read memory list: {0}")do { ::lldb_private::Log *log_private = (log); ::llvm::Error error_private
= (ExpectedMemory.takeError()); if (log_private && error_private
) { log_private->FormatError(::std::move(error_private), "lldb/source/Plugins/Process/minidump/MinidumpParser.cpp"
, __func__, "Failed to read memory list: {0}"); } else ::llvm
::consumeError(::std::move(error_private)); } while (0)
;
438 } else {
439 for (const auto &memory_desc : *ExpectedMemory) {
440 const LocationDescriptor &loc_desc = memory_desc.Memory;
441 const lldb::addr_t range_start = memory_desc.StartOfMemoryRange;
442 const size_t range_size = loc_desc.DataSize;
443
444 if (loc_desc.RVA + loc_desc.DataSize > GetData().size())
445 return llvm::None;
446
447 if (range_start <= addr && addr < range_start + range_size) {
448 auto ExpectedSlice = GetMinidumpFile().getRawData(loc_desc);
449 if (!ExpectedSlice) {
450 LLDB_LOG_ERROR(log, ExpectedSlice.takeError(),do { ::lldb_private::Log *log_private = (log); ::llvm::Error error_private
= (ExpectedSlice.takeError()); if (log_private && error_private
) { log_private->FormatError(::std::move(error_private), "lldb/source/Plugins/Process/minidump/MinidumpParser.cpp"
, __func__, "Failed to get memory slice: {0}"); } else ::llvm
::consumeError(::std::move(error_private)); } while (0)
451 "Failed to get memory slice: {0}")do { ::lldb_private::Log *log_private = (log); ::llvm::Error error_private
= (ExpectedSlice.takeError()); if (log_private && error_private
) { log_private->FormatError(::std::move(error_private), "lldb/source/Plugins/Process/minidump/MinidumpParser.cpp"
, __func__, "Failed to get memory slice: {0}"); } else ::llvm
::consumeError(::std::move(error_private)); } while (0)
;
452 return llvm::None;
453 }
454 return minidump::Range(range_start, *ExpectedSlice);
455 }
456 }
457 }
458
459 // Some Minidumps have a Memory64ListStream that captures all the heap memory
460 // (full-memory Minidumps). We can't exactly use the same loop as above,
461 // because the Minidump uses slightly different data structures to describe
462 // those
463
464 if (!data64.empty()) {
465 llvm::ArrayRef<MinidumpMemoryDescriptor64> memory64_list;
466 uint64_t base_rva;
467 std::tie(memory64_list, base_rva) =
468 MinidumpMemoryDescriptor64::ParseMemory64List(data64);
469
470 if (memory64_list.empty())
471 return llvm::None;
472
473 for (const auto &memory_desc64 : memory64_list) {
474 const lldb::addr_t range_start = memory_desc64.start_of_memory_range;
475 const size_t range_size = memory_desc64.data_size;
476
477 if (base_rva + range_size > GetData().size())
478 return llvm::None;
479
480 if (range_start <= addr && addr < range_start + range_size) {
481 return minidump::Range(range_start,
482 GetData().slice(base_rva, range_size));
483 }
484 base_rva += range_size;
485 }
486 }
487
488 return llvm::None;
489}
490
491llvm::ArrayRef<uint8_t> MinidumpParser::GetMemory(lldb::addr_t addr,
492 size_t size) {
493 // I don't have a sense of how frequently this is called or how many memory
494 // ranges a Minidump typically has, so I'm not sure if searching for the
495 // appropriate range linearly each time is stupid. Perhaps we should build
496 // an index for faster lookups.
497 llvm::Optional<minidump::Range> range = FindMemoryRange(addr);
498 if (!range)
499 return {};
500
501 // There's at least some overlap between the beginning of the desired range
502 // (addr) and the current range. Figure out where the overlap begins and how
503 // much overlap there is.
504
505 const size_t offset = addr - range->start;
506
507 if (addr < range->start || offset >= range->range_ref.size())
508 return {};
509
510 const size_t overlap = std::min(size, range->range_ref.size() - offset);
511 return range->range_ref.slice(offset, overlap);
512}
513
514static bool
515CreateRegionsCacheFromMemoryInfoList(MinidumpParser &parser,
516 std::vector<MemoryRegionInfo> &regions) {
517 Log *log = GetLog(LLDBLog::Modules);
518 auto ExpectedInfo = parser.GetMinidumpFile().getMemoryInfoList();
519 if (!ExpectedInfo) {
520 LLDB_LOG_ERROR(log, ExpectedInfo.takeError(),do { ::lldb_private::Log *log_private = (log); ::llvm::Error error_private
= (ExpectedInfo.takeError()); if (log_private && error_private
) { log_private->FormatError(::std::move(error_private), "lldb/source/Plugins/Process/minidump/MinidumpParser.cpp"
, __func__, "Failed to read memory info list: {0}"); } else ::
llvm::consumeError(::std::move(error_private)); } while (0)
521 "Failed to read memory info list: {0}")do { ::lldb_private::Log *log_private = (log); ::llvm::Error error_private
= (ExpectedInfo.takeError()); if (log_private && error_private
) { log_private->FormatError(::std::move(error_private), "lldb/source/Plugins/Process/minidump/MinidumpParser.cpp"
, __func__, "Failed to read memory info list: {0}"); } else ::
llvm::consumeError(::std::move(error_private)); } while (0)
;
522 return false;
523 }
524 constexpr auto yes = MemoryRegionInfo::eYes;
525 constexpr auto no = MemoryRegionInfo::eNo;
526 for (const MemoryInfo &entry : *ExpectedInfo) {
527 MemoryRegionInfo region;
528 region.GetRange().SetRangeBase(entry.BaseAddress);
529 region.GetRange().SetByteSize(entry.RegionSize);
530
531 MemoryProtection prot = entry.Protect;
532 region.SetReadable(bool(prot & MemoryProtection::NoAccess) ? no : yes);
533 region.SetWritable(
534 bool(prot & (MemoryProtection::ReadWrite | MemoryProtection::WriteCopy |
535 MemoryProtection::ExecuteReadWrite |
536 MemoryProtection::ExeciteWriteCopy))
537 ? yes
538 : no);
539 region.SetExecutable(
540 bool(prot & (MemoryProtection::Execute | MemoryProtection::ExecuteRead |
541 MemoryProtection::ExecuteReadWrite |
542 MemoryProtection::ExeciteWriteCopy))
543 ? yes
544 : no);
545 region.SetMapped(entry.State != MemoryState::Free ? yes : no);
546 regions.push_back(region);
547 }
548 return !regions.empty();
549}
550
551static bool
552CreateRegionsCacheFromMemoryList(MinidumpParser &parser,
553 std::vector<MemoryRegionInfo> &regions) {
554 Log *log = GetLog(LLDBLog::Modules);
555 auto ExpectedMemory = parser.GetMinidumpFile().getMemoryList();
556 if (!ExpectedMemory) {
557 LLDB_LOG_ERROR(log, ExpectedMemory.takeError(),do { ::lldb_private::Log *log_private = (log); ::llvm::Error error_private
= (ExpectedMemory.takeError()); if (log_private && error_private
) { log_private->FormatError(::std::move(error_private), "lldb/source/Plugins/Process/minidump/MinidumpParser.cpp"
, __func__, "Failed to read memory list: {0}"); } else ::llvm
::consumeError(::std::move(error_private)); } while (0)
558 "Failed to read memory list: {0}")do { ::lldb_private::Log *log_private = (log); ::llvm::Error error_private
= (ExpectedMemory.takeError()); if (log_private && error_private
) { log_private->FormatError(::std::move(error_private), "lldb/source/Plugins/Process/minidump/MinidumpParser.cpp"
, __func__, "Failed to read memory list: {0}"); } else ::llvm
::consumeError(::std::move(error_private)); } while (0)
;
559 return false;
560 }
561 regions.reserve(ExpectedMemory->size());
562 for (const MemoryDescriptor &memory_desc : *ExpectedMemory) {
563 if (memory_desc.Memory.DataSize == 0)
564 continue;
565 MemoryRegionInfo region;
566 region.GetRange().SetRangeBase(memory_desc.StartOfMemoryRange);
567 region.GetRange().SetByteSize(memory_desc.Memory.DataSize);
568 region.SetReadable(MemoryRegionInfo::eYes);
569 region.SetMapped(MemoryRegionInfo::eYes);
570 regions.push_back(region);
571 }
572 regions.shrink_to_fit();
573 return !regions.empty();
574}
575
576static bool
577CreateRegionsCacheFromMemory64List(MinidumpParser &parser,
578 std::vector<MemoryRegionInfo> &regions) {
579 llvm::ArrayRef<uint8_t> data =
580 parser.GetStream(StreamType::Memory64List);
581 if (data.empty())
582 return false;
583 llvm::ArrayRef<MinidumpMemoryDescriptor64> memory64_list;
584 uint64_t base_rva;
585 std::tie(memory64_list, base_rva) =
586 MinidumpMemoryDescriptor64::ParseMemory64List(data);
587
588 if (memory64_list.empty())
589 return false;
590
591 regions.reserve(memory64_list.size());
592 for (const auto &memory_desc : memory64_list) {
593 if (memory_desc.data_size == 0)
594 continue;
595 MemoryRegionInfo region;
596 region.GetRange().SetRangeBase(memory_desc.start_of_memory_range);
597 region.GetRange().SetByteSize(memory_desc.data_size);
598 region.SetReadable(MemoryRegionInfo::eYes);
599 region.SetMapped(MemoryRegionInfo::eYes);
600 regions.push_back(region);
601 }
602 regions.shrink_to_fit();
603 return !regions.empty();
604}
605
606std::pair<MemoryRegionInfos, bool> MinidumpParser::BuildMemoryRegions() {
607 // We create the region cache using the best source. We start with
608 // the linux maps since they are the most complete and have names for the
609 // regions. Next we try the MemoryInfoList since it has
610 // read/write/execute/map data, and then fall back to the MemoryList and
611 // Memory64List to just get a list of the memory that is mapped in this
612 // core file
613 MemoryRegionInfos result;
614 const auto &return_sorted = [&](bool is_complete) {
615 llvm::sort(result);
616 return std::make_pair(std::move(result), is_complete);
617 };
618 if (CreateRegionsCacheFromLinuxMaps(*this, result))
619 return return_sorted(true);
620 if (CreateRegionsCacheFromMemoryInfoList(*this, result))
621 return return_sorted(true);
622 if (CreateRegionsCacheFromMemoryList(*this, result))
623 return return_sorted(false);
624 CreateRegionsCacheFromMemory64List(*this, result);
625 return return_sorted(false);
626}
627
628#define ENUM_TO_CSTR(ST)case StreamType::ST: return "ST" \
629 case StreamType::ST: \
630 return #ST
631
632llvm::StringRef
633MinidumpParser::GetStreamTypeAsString(StreamType stream_type) {
634 switch (stream_type) {
635 ENUM_TO_CSTR(Unused)case StreamType::Unused: return "Unused";
636 ENUM_TO_CSTR(ThreadList)case StreamType::ThreadList: return "ThreadList";
637 ENUM_TO_CSTR(ModuleList)case StreamType::ModuleList: return "ModuleList";
638 ENUM_TO_CSTR(MemoryList)case StreamType::MemoryList: return "MemoryList";
639 ENUM_TO_CSTR(Exception)case StreamType::Exception: return "Exception";
640 ENUM_TO_CSTR(SystemInfo)case StreamType::SystemInfo: return "SystemInfo";
641 ENUM_TO_CSTR(ThreadExList)case StreamType::ThreadExList: return "ThreadExList";
642 ENUM_TO_CSTR(Memory64List)case StreamType::Memory64List: return "Memory64List";
643 ENUM_TO_CSTR(CommentA)case StreamType::CommentA: return "CommentA";
644 ENUM_TO_CSTR(CommentW)case StreamType::CommentW: return "CommentW";
645 ENUM_TO_CSTR(HandleData)case StreamType::HandleData: return "HandleData";
646 ENUM_TO_CSTR(FunctionTable)case StreamType::FunctionTable: return "FunctionTable";
647 ENUM_TO_CSTR(UnloadedModuleList)case StreamType::UnloadedModuleList: return "UnloadedModuleList";
648 ENUM_TO_CSTR(MiscInfo)case StreamType::MiscInfo: return "MiscInfo";
649 ENUM_TO_CSTR(MemoryInfoList)case StreamType::MemoryInfoList: return "MemoryInfoList";
650 ENUM_TO_CSTR(ThreadInfoList)case StreamType::ThreadInfoList: return "ThreadInfoList";
651 ENUM_TO_CSTR(HandleOperationList)case StreamType::HandleOperationList: return "HandleOperationList";
652 ENUM_TO_CSTR(Token)case StreamType::Token: return "Token";
653 ENUM_TO_CSTR(JavascriptData)case StreamType::JavascriptData: return "JavascriptData";
654 ENUM_TO_CSTR(SystemMemoryInfo)case StreamType::SystemMemoryInfo: return "SystemMemoryInfo";
655 ENUM_TO_CSTR(ProcessVMCounters)case StreamType::ProcessVMCounters: return "ProcessVMCounters";
656 ENUM_TO_CSTR(LastReserved)case StreamType::LastReserved: return "LastReserved";
657 ENUM_TO_CSTR(BreakpadInfo)case StreamType::BreakpadInfo: return "BreakpadInfo";
658 ENUM_TO_CSTR(AssertionInfo)case StreamType::AssertionInfo: return "AssertionInfo";
659 ENUM_TO_CSTR(LinuxCPUInfo)case StreamType::LinuxCPUInfo: return "LinuxCPUInfo";
660 ENUM_TO_CSTR(LinuxProcStatus)case StreamType::LinuxProcStatus: return "LinuxProcStatus";
661 ENUM_TO_CSTR(LinuxLSBRelease)case StreamType::LinuxLSBRelease: return "LinuxLSBRelease";
662 ENUM_TO_CSTR(LinuxCMDLine)case StreamType::LinuxCMDLine: return "LinuxCMDLine";
663 ENUM_TO_CSTR(LinuxEnviron)case StreamType::LinuxEnviron: return "LinuxEnviron";
664 ENUM_TO_CSTR(LinuxAuxv)case StreamType::LinuxAuxv: return "LinuxAuxv";
665 ENUM_TO_CSTR(LinuxMaps)case StreamType::LinuxMaps: return "LinuxMaps";
666 ENUM_TO_CSTR(LinuxDSODebug)case StreamType::LinuxDSODebug: return "LinuxDSODebug";
667 ENUM_TO_CSTR(LinuxProcStat)case StreamType::LinuxProcStat: return "LinuxProcStat";
668 ENUM_TO_CSTR(LinuxProcUptime)case StreamType::LinuxProcUptime: return "LinuxProcUptime";
669 ENUM_TO_CSTR(LinuxProcFD)case StreamType::LinuxProcFD: return "LinuxProcFD";
670 ENUM_TO_CSTR(FacebookAppCustomData)case StreamType::FacebookAppCustomData: return "FacebookAppCustomData";
671 ENUM_TO_CSTR(FacebookBuildID)case StreamType::FacebookBuildID: return "FacebookBuildID";
672 ENUM_TO_CSTR(FacebookAppVersionName)case StreamType::FacebookAppVersionName: return "FacebookAppVersionName";
673 ENUM_TO_CSTR(FacebookJavaStack)case StreamType::FacebookJavaStack: return "FacebookJavaStack";
674 ENUM_TO_CSTR(FacebookDalvikInfo)case StreamType::FacebookDalvikInfo: return "FacebookDalvikInfo";
675 ENUM_TO_CSTR(FacebookUnwindSymbols)case StreamType::FacebookUnwindSymbols: return "FacebookUnwindSymbols";
676 ENUM_TO_CSTR(FacebookDumpErrorLog)case StreamType::FacebookDumpErrorLog: return "FacebookDumpErrorLog";
677 ENUM_TO_CSTR(FacebookAppStateLog)case StreamType::FacebookAppStateLog: return "FacebookAppStateLog";
678 ENUM_TO_CSTR(FacebookAbortReason)case StreamType::FacebookAbortReason: return "FacebookAbortReason";
679 ENUM_TO_CSTR(FacebookThreadName)case StreamType::FacebookThreadName: return "FacebookThreadName";
680 ENUM_TO_CSTR(FacebookLogcat)case StreamType::FacebookLogcat: return "FacebookLogcat";
681 }
682 return "unknown stream type";
683}
684
685MemoryRegionInfo
686MinidumpParser::GetMemoryRegionInfo(const MemoryRegionInfos &regions,
687 lldb::addr_t load_addr) {
688 MemoryRegionInfo region;
689 auto pos = llvm::upper_bound(regions, load_addr);
690 if (pos != regions.begin() &&
691 std::prev(pos)->GetRange().Contains(load_addr)) {
692 return *std::prev(pos);
693 }
694
695 if (pos == regions.begin())
696 region.GetRange().SetRangeBase(0);
697 else
698 region.GetRange().SetRangeBase(std::prev(pos)->GetRange().GetRangeEnd());
699
700 if (pos == regions.end())
701 region.GetRange().SetRangeEnd(UINT64_MAX(18446744073709551615UL));
702 else
703 region.GetRange().SetRangeEnd(pos->GetRange().GetRangeBase());
704
705 region.SetReadable(MemoryRegionInfo::eNo);
706 region.SetWritable(MemoryRegionInfo::eNo);
707 region.SetExecutable(MemoryRegionInfo::eNo);
708 region.SetMapped(MemoryRegionInfo::eNo);
709 return region;
710}

/build/llvm-toolchain-snapshot-16~++20220904122748+c444af1c20b3/lldb/source/Plugins/Process/minidump/MinidumpTypes.h

1//===-- MinidumpTypes.h -----------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLDB_SOURCE_PLUGINS_PROCESS_MINIDUMP_MINIDUMPTYPES_H
10#define LLDB_SOURCE_PLUGINS_PROCESS_MINIDUMP_MINIDUMPTYPES_H
11
12#include "lldb/Utility/Status.h"
13
14#include "llvm/ADT/ArrayRef.h"
15#include "llvm/ADT/BitmaskEnum.h"
16#include "llvm/ADT/Optional.h"
17#include "llvm/ADT/SmallVector.h"
18#include "llvm/ADT/StringRef.h"
19#include "llvm/BinaryFormat/Minidump.h"
20#include "llvm/Support/ConvertUTF.h"
21#include "llvm/Support/Endian.h"
22
23// C includes
24// C++ includes
25
26// Reference:
27// https://msdn.microsoft.com/en-us/library/windows/desktop/ms679293(v=vs.85).aspx
28// https://chromium.googlesource.com/breakpad/breakpad/
29
30namespace lldb_private {
31
32namespace minidump {
33
34using namespace llvm::minidump;
35
36LLVM_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^=
;
37
38enum class CvSignature : uint32_t {
39 Pdb70 = 0x53445352, // RSDS
40 ElfBuildId = 0x4270454c, // BpEL (Breakpad/Crashpad minidumps)
41};
42
43enum class MinidumpMiscInfoFlags : uint32_t {
44 ProcessID = (1 << 0),
45 ProcessTimes = (1 << 1),
46 LLVM_MARK_AS_BITMASK_ENUM(/* LargestValue = */ ProcessTimes)LLVM_BITMASK_LARGEST_ENUMERATOR = ProcessTimes
47};
48
49template <typename T>
50Status consumeObject(llvm::ArrayRef<uint8_t> &Buffer, const T *&Object) {
51 Status error;
52 if (Buffer.size() < sizeof(T)) {
3
Assuming the condition is true
4
Taking true branch
53 error.SetErrorString("Insufficient buffer!");
54 return error;
5
Returning without writing to 'Object'
55 }
56
57 Object = reinterpret_cast<const T *>(Buffer.data());
58 Buffer = Buffer.drop_front(sizeof(T));
59 return error;
60}
61
62struct MinidumpMemoryDescriptor64 {
63 llvm::support::ulittle64_t start_of_memory_range;
64 llvm::support::ulittle64_t data_size;
65
66 static std::pair<llvm::ArrayRef<MinidumpMemoryDescriptor64>, uint64_t>
67 ParseMemory64List(llvm::ArrayRef<uint8_t> &data);
68};
69static_assert(sizeof(MinidumpMemoryDescriptor64) == 16,
70 "sizeof MinidumpMemoryDescriptor64 is not correct!");
71
72// TODO misc2, misc3 ?
73// Reference:
74// https://msdn.microsoft.com/en-us/library/windows/desktop/ms680389(v=vs.85).aspx
75struct MinidumpMiscInfo {
76 llvm::support::ulittle32_t size;
77 // flags1 represents what info in the struct is valid
78 llvm::support::ulittle32_t flags1;
79 llvm::support::ulittle32_t process_id;
80 llvm::support::ulittle32_t process_create_time;
81 llvm::support::ulittle32_t process_user_time;
82 llvm::support::ulittle32_t process_kernel_time;
83
84 static const MinidumpMiscInfo *Parse(llvm::ArrayRef<uint8_t> &data);
85
86 llvm::Optional<lldb::pid_t> GetPid() const;
87};
88static_assert(sizeof(MinidumpMiscInfo) == 24,
89 "sizeof MinidumpMiscInfo is not correct!");
90
91// The /proc/pid/status is saved as an ascii string in the file
92class LinuxProcStatus {
93public:
94 llvm::StringRef proc_status;
95 lldb::pid_t pid;
96
97 static llvm::Optional<LinuxProcStatus> Parse(llvm::ArrayRef<uint8_t> &data);
98
99 lldb::pid_t GetPid() const;
100
101private:
102 LinuxProcStatus() = default;
103};
104
105} // namespace minidump
106} // namespace lldb_private
107#endif // LLDB_SOURCE_PLUGINS_PROCESS_MINIDUMP_MINIDUMPTYPES_H