blob: bc819cde24ac782da733f4824559ea4c32bd1449 [file] [log] [blame]
Greg Clayton026e1bf2018-12-14 19:36:01 +00001//===-- MinidumpParser.h -----------------------------------------*- C++-*-===//
Dimitar Vlahovski2e50d8e2016-09-01 11:29:53 +00002//
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//
Dimitar Vlahovski36e21a32016-10-05 18:11:45 +00008//===----------------------------------------------------------------------===//
Dimitar Vlahovski2e50d8e2016-09-01 11:29:53 +00009
10#ifndef liblldb_MinidumpParser_h_
11#define liblldb_MinidumpParser_h_
12
Dimitar Vlahovski2e50d8e2016-09-01 11:29:53 +000013#include "MinidumpTypes.h"
14
Pavel Labath5f19b902017-11-13 16:16:33 +000015#include "lldb/Utility/ArchSpec.h"
Zachary Turner666cc0b2017-03-04 01:30:05 +000016#include "lldb/Utility/DataBuffer.h"
Zachary Turner97206d52017-05-12 04:51:55 +000017#include "lldb/Utility/Status.h"
Leonard Mosescu9fecd372018-05-02 20:06:17 +000018#include "lldb/Utility/UUID.h"
Dimitar Vlahovski2e50d8e2016-09-01 11:29:53 +000019
20#include "llvm/ADT/ArrayRef.h"
21#include "llvm/ADT/DenseMap.h"
22#include "llvm/ADT/Optional.h"
Dimitar Vlahovski1d2859e2016-09-13 15:54:38 +000023#include "llvm/ADT/StringRef.h"
Dimitar Vlahovski2e50d8e2016-09-01 11:29:53 +000024
25// C includes
Dimitar Vlahovski36e21a32016-10-05 18:11:45 +000026
Dimitar Vlahovski2e50d8e2016-09-01 11:29:53 +000027// C++ includes
Dimitar Vlahovski36e21a32016-10-05 18:11:45 +000028#include <cstring>
29#include <unordered_map>
Dimitar Vlahovski2e50d8e2016-09-01 11:29:53 +000030
Kate Stoneb9c1b512016-09-06 20:57:50 +000031namespace lldb_private {
Dimitar Vlahovski2e50d8e2016-09-01 11:29:53 +000032
Kate Stoneb9c1b512016-09-06 20:57:50 +000033namespace minidump {
Dimitar Vlahovski2e50d8e2016-09-01 11:29:53 +000034
Dimitar Vlahovskib52206d2016-10-19 14:14:18 +000035// Describes a range of memory captured in the Minidump
36struct Range {
37 lldb::addr_t start; // virtual address of the beginning of the range
38 // range_ref - absolute pointer to the first byte of the range and size
39 llvm::ArrayRef<uint8_t> range_ref;
40
41 Range(lldb::addr_t start, llvm::ArrayRef<uint8_t> range_ref)
42 : start(start), range_ref(range_ref) {}
43};
44
Kate Stoneb9c1b512016-09-06 20:57:50 +000045class MinidumpParser {
Dimitar Vlahovski2e50d8e2016-09-01 11:29:53 +000046public:
Kate Stoneb9c1b512016-09-06 20:57:50 +000047 static llvm::Optional<MinidumpParser>
48 Create(const lldb::DataBufferSP &data_buf_sp);
Dimitar Vlahovski2e50d8e2016-09-01 11:29:53 +000049
Dimitar Vlahovski4c319072016-09-27 19:05:55 +000050 llvm::ArrayRef<uint8_t> GetData();
Dimitar Vlahovski2e50d8e2016-09-01 11:29:53 +000051
Dimitar Vlahovski1d2859e2016-09-13 15:54:38 +000052 llvm::ArrayRef<uint8_t> GetStream(MinidumpStreamType stream_type);
Dimitar Vlahovski2e50d8e2016-09-01 11:29:53 +000053
Dimitar Vlahovski1d2859e2016-09-13 15:54:38 +000054 llvm::Optional<std::string> GetMinidumpString(uint32_t rva);
55
Leonard Mosescu9fecd372018-05-02 20:06:17 +000056 UUID GetModuleUUID(const MinidumpModule* module);
57
Dimitar Vlahovski1d2859e2016-09-13 15:54:38 +000058 llvm::ArrayRef<MinidumpThread> GetThreads();
Dimitar Vlahovski2e50d8e2016-09-01 11:29:53 +000059
Dimitar Vlahovskib52206d2016-10-19 14:14:18 +000060 llvm::ArrayRef<uint8_t> GetThreadContext(const MinidumpThread &td);
61
Dimitar Vlahovski7b18dd42016-10-31 15:35:18 +000062 llvm::ArrayRef<uint8_t> GetThreadContextWow64(const MinidumpThread &td);
63
Kate Stoneb9c1b512016-09-06 20:57:50 +000064 const MinidumpSystemInfo *GetSystemInfo();
Dimitar Vlahovski2e50d8e2016-09-01 11:29:53 +000065
Kate Stoneb9c1b512016-09-06 20:57:50 +000066 ArchSpec GetArchitecture();
Dimitar Vlahovski2e50d8e2016-09-01 11:29:53 +000067
Kate Stoneb9c1b512016-09-06 20:57:50 +000068 const MinidumpMiscInfo *GetMiscInfo();
Dimitar Vlahovski2e50d8e2016-09-01 11:29:53 +000069
Dimitar Vlahovski1d2859e2016-09-13 15:54:38 +000070 llvm::Optional<LinuxProcStatus> GetLinuxProcStatus();
71
72 llvm::Optional<lldb::pid_t> GetPid();
73
74 llvm::ArrayRef<MinidumpModule> GetModuleList();
75
Dimitar Vlahovskib52206d2016-10-19 14:14:18 +000076 // There are cases in which there is more than one record in the ModuleList
77 // for the same module name.(e.g. when the binary has non contiguous segments)
78 // So this function returns a filtered module list - if it finds records that
79 // have the same name, it keeps the copy with the lowest load address.
80 std::vector<const MinidumpModule *> GetFilteredModuleList();
81
Dimitar Vlahovski1d2859e2016-09-13 15:54:38 +000082 const MinidumpExceptionStream *GetExceptionStream();
83
Dimitar Vlahovskib52206d2016-10-19 14:14:18 +000084 llvm::Optional<Range> FindMemoryRange(lldb::addr_t addr);
85
86 llvm::ArrayRef<uint8_t> GetMemory(lldb::addr_t addr, size_t size);
87
Greg Clayton026e1bf2018-12-14 19:36:01 +000088 MemoryRegionInfo GetMemoryRegionInfo(lldb::addr_t load_addr);
Dimitar Vlahovskib52206d2016-10-19 14:14:18 +000089
Leonard Mosescu2ae3ec32018-07-12 17:27:18 +000090 // Perform consistency checks and initialize internal data structures
91 Status Initialize();
92
93private:
94 MinidumpParser(const lldb::DataBufferSP &data_buf_sp);
95
Greg Clayton026e1bf2018-12-14 19:36:01 +000096 MemoryRegionInfo FindMemoryRegion(lldb::addr_t load_addr) const;
97
Dimitar Vlahovski2e50d8e2016-09-01 11:29:53 +000098private:
Kate Stoneb9c1b512016-09-06 20:57:50 +000099 lldb::DataBufferSP m_data_sp;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000100 llvm::DenseMap<uint32_t, MinidumpLocationDescriptor> m_directory_map;
Greg Clayton19c8f392018-08-06 16:56:10 +0000101 ArchSpec m_arch;
Greg Clayton026e1bf2018-12-14 19:36:01 +0000102 std::vector<MemoryRegionInfo> m_regions;
103 bool m_parsed_regions = false;
Dimitar Vlahovski2e50d8e2016-09-01 11:29:53 +0000104};
105
Dimitar Vlahovski4c319072016-09-27 19:05:55 +0000106} // end namespace minidump
107} // end namespace lldb_private
Dimitar Vlahovski2e50d8e2016-09-01 11:29:53 +0000108#endif // liblldb_MinidumpParser_h_