]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Plugins/Process/minidump/MinidumpParser.h
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / Plugins / Process / minidump / MinidumpParser.h
1 //===-- MinidumpParser.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_MinidumpParser_h_
11 #define liblldb_MinidumpParser_h_
12
13 #include "MinidumpTypes.h"
14
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"
20
21 #include "llvm/ADT/ArrayRef.h"
22 #include "llvm/ADT/DenseMap.h"
23 #include "llvm/ADT/Optional.h"
24 #include "llvm/ADT/StringRef.h"
25
26 // C includes
27
28 // C++ includes
29 #include <cstring>
30 #include <unordered_map>
31
32 namespace lldb_private {
33
34 namespace minidump {
35
36 // Describes a range of memory captured in the Minidump
37 struct Range {
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;
41
42   Range(lldb::addr_t start, llvm::ArrayRef<uint8_t> range_ref)
43       : start(start), range_ref(range_ref) {}
44 };
45
46 class MinidumpParser {
47 public:
48   static llvm::Optional<MinidumpParser>
49   Create(const lldb::DataBufferSP &data_buf_sp);
50
51   llvm::ArrayRef<uint8_t> GetData();
52
53   llvm::ArrayRef<uint8_t> GetStream(MinidumpStreamType stream_type);
54
55   llvm::Optional<std::string> GetMinidumpString(uint32_t rva);
56
57   UUID GetModuleUUID(const MinidumpModule* module);
58
59   llvm::ArrayRef<MinidumpThread> GetThreads();
60
61   llvm::ArrayRef<uint8_t>
62   GetThreadContext(const MinidumpLocationDescriptor &location);
63
64   llvm::ArrayRef<uint8_t> GetThreadContext(const MinidumpThread &td);
65
66   llvm::ArrayRef<uint8_t> GetThreadContextWow64(const MinidumpThread &td);
67
68   const MinidumpSystemInfo *GetSystemInfo();
69
70   ArchSpec GetArchitecture();
71
72   const MinidumpMiscInfo *GetMiscInfo();
73
74   llvm::Optional<LinuxProcStatus> GetLinuxProcStatus();
75
76   llvm::Optional<lldb::pid_t> GetPid();
77
78   llvm::ArrayRef<MinidumpModule> GetModuleList();
79
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();
85
86   const MinidumpExceptionStream *GetExceptionStream();
87
88   llvm::Optional<Range> FindMemoryRange(lldb::addr_t addr);
89
90   llvm::ArrayRef<uint8_t> GetMemory(lldb::addr_t addr, size_t size);
91
92   MemoryRegionInfo GetMemoryRegionInfo(lldb::addr_t load_addr);
93
94   const MemoryRegionInfos &GetMemoryRegions();
95
96   // Perform consistency checks and initialize internal data structures
97   Status Initialize();
98
99   static llvm::StringRef GetStreamTypeAsString(uint32_t stream_type);
100
101   const llvm::DenseMap<uint32_t, MinidumpLocationDescriptor> &
102   GetDirectoryMap() const {
103     return m_directory_map;
104   }
105
106 private:
107   MinidumpParser(const lldb::DataBufferSP &data_buf_sp);
108
109   MemoryRegionInfo FindMemoryRegion(lldb::addr_t load_addr) const;
110
111 private:
112   lldb::DataBufferSP m_data_sp;
113   llvm::DenseMap<uint32_t, MinidumpLocationDescriptor> m_directory_map;
114   ArchSpec m_arch;
115   MemoryRegionInfos m_regions;
116   bool m_parsed_regions = false;
117 };
118
119 } // end namespace minidump
120 } // end namespace lldb_private
121 #endif // liblldb_MinidumpParser_h_