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