1 //===-- MinidumpParser.h -----------------------------------------*- C++-*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_MinidumpParser_h_
11 #define liblldb_MinidumpParser_h_
13 #include "MinidumpTypes.h"
15 #include "lldb/Target/MemoryRegionInfo.h"
16 #include "lldb/Utility/ArchSpec.h"
17 #include "lldb/Utility/DataBuffer.h"
18 #include "lldb/Utility/Status.h"
19 #include "lldb/Utility/UUID.h"
21 #include "llvm/ADT/ArrayRef.h"
22 #include "llvm/ADT/DenseMap.h"
23 #include "llvm/ADT/Optional.h"
24 #include "llvm/ADT/StringRef.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) {}
46 class MinidumpParser {
48 static llvm::Optional<MinidumpParser>
49 Create(const lldb::DataBufferSP &data_buf_sp);
51 llvm::ArrayRef<uint8_t> GetData();
53 llvm::ArrayRef<uint8_t> GetStream(MinidumpStreamType stream_type);
55 llvm::Optional<std::string> GetMinidumpString(uint32_t rva);
57 UUID GetModuleUUID(const MinidumpModule* module);
59 llvm::ArrayRef<MinidumpThread> GetThreads();
61 llvm::ArrayRef<uint8_t>
62 GetThreadContext(const MinidumpLocationDescriptor &location);
64 llvm::ArrayRef<uint8_t> GetThreadContext(const MinidumpThread &td);
66 llvm::ArrayRef<uint8_t> GetThreadContextWow64(const MinidumpThread &td);
68 const MinidumpSystemInfo *GetSystemInfo();
70 ArchSpec GetArchitecture();
72 const MinidumpMiscInfo *GetMiscInfo();
74 llvm::Optional<LinuxProcStatus> GetLinuxProcStatus();
76 llvm::Optional<lldb::pid_t> GetPid();
78 llvm::ArrayRef<MinidumpModule> GetModuleList();
80 // There are cases in which there is more than one record in the ModuleList
81 // for the same module name.(e.g. when the binary has non contiguous segments)
82 // So this function returns a filtered module list - if it finds records that
83 // have the same name, it keeps the copy with the lowest load address.
84 std::vector<const MinidumpModule *> GetFilteredModuleList();
86 const MinidumpExceptionStream *GetExceptionStream();
88 llvm::Optional<Range> FindMemoryRange(lldb::addr_t addr);
90 llvm::ArrayRef<uint8_t> GetMemory(lldb::addr_t addr, size_t size);
92 MemoryRegionInfo GetMemoryRegionInfo(lldb::addr_t load_addr);
94 const MemoryRegionInfos &GetMemoryRegions();
96 // Perform consistency checks and initialize internal data structures
99 static llvm::StringRef GetStreamTypeAsString(uint32_t stream_type);
101 const llvm::DenseMap<uint32_t, MinidumpLocationDescriptor> &
102 GetDirectoryMap() const {
103 return m_directory_map;
107 MinidumpParser(const lldb::DataBufferSP &data_buf_sp);
109 MemoryRegionInfo FindMemoryRegion(lldb::addr_t load_addr) const;
112 lldb::DataBufferSP m_data_sp;
113 llvm::DenseMap<uint32_t, MinidumpLocationDescriptor> m_directory_map;
115 MemoryRegionInfos m_regions;
116 bool m_parsed_regions = false;
119 } // end namespace minidump
120 } // end namespace lldb_private
121 #endif // liblldb_MinidumpParser_h_