1 //===-- MinidumpParser.h -----------------------------------------*- C++-*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef liblldb_MinidumpParser_h_
10 #define liblldb_MinidumpParser_h_
12 #include "MinidumpTypes.h"
14 #include "lldb/Target/MemoryRegionInfo.h"
15 #include "lldb/Utility/ArchSpec.h"
16 #include "lldb/Utility/DataBuffer.h"
17 #include "lldb/Utility/Status.h"
18 #include "lldb/Utility/UUID.h"
20 #include "llvm/ADT/ArrayRef.h"
21 #include "llvm/ADT/DenseMap.h"
22 #include "llvm/ADT/Optional.h"
23 #include "llvm/ADT/StringRef.h"
24 #include "llvm/Object/Minidump.h"
30 #include <unordered_map>
32 namespace lldb_private {
36 // Describes a range of memory captured in the Minidump
38 lldb::addr_t start; // virtual address of the beginning of the range
39 // range_ref - absolute pointer to the first byte of the range and size
40 llvm::ArrayRef<uint8_t> range_ref;
42 Range(lldb::addr_t start, llvm::ArrayRef<uint8_t> range_ref)
43 : start(start), range_ref(range_ref) {}
45 friend bool operator==(const Range &lhs, const Range &rhs) {
46 return lhs.start == rhs.start && lhs.range_ref == rhs.range_ref;
50 class MinidumpParser {
52 static llvm::Expected<MinidumpParser>
53 Create(const lldb::DataBufferSP &data_buf_sp);
55 llvm::ArrayRef<uint8_t> GetData();
57 llvm::ArrayRef<uint8_t> GetStream(StreamType stream_type);
59 UUID GetModuleUUID(const minidump::Module *module);
61 llvm::ArrayRef<minidump::Thread> GetThreads();
63 llvm::ArrayRef<uint8_t> GetThreadContext(const LocationDescriptor &location);
65 llvm::ArrayRef<uint8_t> GetThreadContext(const minidump::Thread &td);
67 llvm::ArrayRef<uint8_t> GetThreadContextWow64(const minidump::Thread &td);
69 ArchSpec GetArchitecture();
71 const MinidumpMiscInfo *GetMiscInfo();
73 llvm::Optional<LinuxProcStatus> GetLinuxProcStatus();
75 llvm::Optional<lldb::pid_t> GetPid();
77 llvm::ArrayRef<minidump::Module> GetModuleList();
79 // There are cases in which there is more than one record in the ModuleList
80 // for the same module name.(e.g. when the binary has non contiguous segments)
81 // So this function returns a filtered module list - if it finds records that
82 // have the same name, it keeps the copy with the lowest load address.
83 std::vector<const minidump::Module *> GetFilteredModuleList();
85 const llvm::minidump::ExceptionStream *GetExceptionStream();
87 llvm::Optional<Range> FindMemoryRange(lldb::addr_t addr);
89 llvm::ArrayRef<uint8_t> GetMemory(lldb::addr_t addr, size_t size);
91 MemoryRegionInfo GetMemoryRegionInfo(lldb::addr_t load_addr);
93 const MemoryRegionInfos &GetMemoryRegions();
95 static llvm::StringRef GetStreamTypeAsString(StreamType stream_type);
97 llvm::object::MinidumpFile &GetMinidumpFile() { return *m_file; }
100 MinidumpParser(lldb::DataBufferSP data_sp,
101 std::unique_ptr<llvm::object::MinidumpFile> file);
103 MemoryRegionInfo FindMemoryRegion(lldb::addr_t load_addr) const;
106 lldb::DataBufferSP m_data_sp;
107 std::unique_ptr<llvm::object::MinidumpFile> m_file;
109 MemoryRegionInfos m_regions;
110 bool m_parsed_regions = false;
113 } // end namespace minidump
114 } // end namespace lldb_private
115 #endif // liblldb_MinidumpParser_h_