blob: 48c752b541eb22c61ba0b69efa824f44d886622d [file] [log] [blame]
Dimitar Vlahovski36e21a32016-10-05 18:11:45 +00001//===-- MinidumpParser.h -----------------------------------------*- C++
2//-*-===//
Dimitar Vlahovski2e50d8e2016-09-01 11:29:53 +00003//
4// The LLVM Compiler Infrastructure
5//
6// This file is distributed under the University of Illinois Open Source
7// License. See LICENSE.TXT for details.
8//
Dimitar Vlahovski36e21a32016-10-05 18:11:45 +00009//===----------------------------------------------------------------------===//
Dimitar Vlahovski2e50d8e2016-09-01 11:29:53 +000010
11#ifndef liblldb_MinidumpParser_h_
12#define liblldb_MinidumpParser_h_
13
14// Project includes
15#include "MinidumpTypes.h"
16
Pavel Labath5f19b902017-11-13 16:16:33 +000017#include "lldb/Utility/ArchSpec.h"
Zachary Turner666cc0b2017-03-04 01:30:05 +000018#include "lldb/Utility/DataBuffer.h"
Zachary Turner97206d52017-05-12 04:51:55 +000019#include "lldb/Utility/Status.h"
Leonard Mosescu9fecd372018-05-02 20:06:17 +000020#include "lldb/Utility/UUID.h"
Dimitar Vlahovski2e50d8e2016-09-01 11:29:53 +000021
22#include "llvm/ADT/ArrayRef.h"
23#include "llvm/ADT/DenseMap.h"
24#include "llvm/ADT/Optional.h"
Dimitar Vlahovski1d2859e2016-09-13 15:54:38 +000025#include "llvm/ADT/StringRef.h"
Dimitar Vlahovski2e50d8e2016-09-01 11:29:53 +000026
27// C includes
Dimitar Vlahovski36e21a32016-10-05 18:11:45 +000028
Dimitar Vlahovski2e50d8e2016-09-01 11:29:53 +000029// C++ includes
Dimitar Vlahovski36e21a32016-10-05 18:11:45 +000030#include <cstring>
31#include <unordered_map>
Dimitar Vlahovski2e50d8e2016-09-01 11:29:53 +000032
Kate Stoneb9c1b512016-09-06 20:57:50 +000033namespace lldb_private {
Dimitar Vlahovski2e50d8e2016-09-01 11:29:53 +000034
Kate Stoneb9c1b512016-09-06 20:57:50 +000035namespace minidump {
Dimitar Vlahovski2e50d8e2016-09-01 11:29:53 +000036
Dimitar Vlahovskib52206d2016-10-19 14:14:18 +000037// Describes a range of memory captured in the Minidump
38struct Range {
39 lldb::addr_t start; // virtual address of the beginning of the range
40 // range_ref - absolute pointer to the first byte of the range and size
41 llvm::ArrayRef<uint8_t> range_ref;
42
43 Range(lldb::addr_t start, llvm::ArrayRef<uint8_t> range_ref)
44 : start(start), range_ref(range_ref) {}
45};
46
Kate Stoneb9c1b512016-09-06 20:57:50 +000047class MinidumpParser {
Dimitar Vlahovski2e50d8e2016-09-01 11:29:53 +000048public:
Kate Stoneb9c1b512016-09-06 20:57:50 +000049 static llvm::Optional<MinidumpParser>
50 Create(const lldb::DataBufferSP &data_buf_sp);
Dimitar Vlahovski2e50d8e2016-09-01 11:29:53 +000051
Dimitar Vlahovski4c319072016-09-27 19:05:55 +000052 llvm::ArrayRef<uint8_t> GetData();
Dimitar Vlahovski2e50d8e2016-09-01 11:29:53 +000053
Dimitar Vlahovski1d2859e2016-09-13 15:54:38 +000054 llvm::ArrayRef<uint8_t> GetStream(MinidumpStreamType stream_type);
Dimitar Vlahovski2e50d8e2016-09-01 11:29:53 +000055
Dimitar Vlahovski1d2859e2016-09-13 15:54:38 +000056 llvm::Optional<std::string> GetMinidumpString(uint32_t rva);
57
Leonard Mosescu9fecd372018-05-02 20:06:17 +000058 UUID GetModuleUUID(const MinidumpModule* module);
59
Dimitar Vlahovski1d2859e2016-09-13 15:54:38 +000060 llvm::ArrayRef<MinidumpThread> GetThreads();
Dimitar Vlahovski2e50d8e2016-09-01 11:29:53 +000061
Dimitar Vlahovskib52206d2016-10-19 14:14:18 +000062 llvm::ArrayRef<uint8_t> GetThreadContext(const MinidumpThread &td);
63
Dimitar Vlahovski7b18dd42016-10-31 15:35:18 +000064 llvm::ArrayRef<uint8_t> GetThreadContextWow64(const MinidumpThread &td);
65
Kate Stoneb9c1b512016-09-06 20:57:50 +000066 const MinidumpSystemInfo *GetSystemInfo();
Dimitar Vlahovski2e50d8e2016-09-01 11:29:53 +000067
Kate Stoneb9c1b512016-09-06 20:57:50 +000068 ArchSpec GetArchitecture();
Dimitar Vlahovski2e50d8e2016-09-01 11:29:53 +000069
Kate Stoneb9c1b512016-09-06 20:57:50 +000070 const MinidumpMiscInfo *GetMiscInfo();
Dimitar Vlahovski2e50d8e2016-09-01 11:29:53 +000071
Dimitar Vlahovski1d2859e2016-09-13 15:54:38 +000072 llvm::Optional<LinuxProcStatus> GetLinuxProcStatus();
73
74 llvm::Optional<lldb::pid_t> GetPid();
75
76 llvm::ArrayRef<MinidumpModule> GetModuleList();
77
Dimitar Vlahovskib52206d2016-10-19 14:14:18 +000078 // There are cases in which there is more than one record in the ModuleList
79 // for the same module name.(e.g. when the binary has non contiguous segments)
80 // So this function returns a filtered module list - if it finds records that
81 // have the same name, it keeps the copy with the lowest load address.
82 std::vector<const MinidumpModule *> GetFilteredModuleList();
83
Dimitar Vlahovski1d2859e2016-09-13 15:54:38 +000084 const MinidumpExceptionStream *GetExceptionStream();
85
Dimitar Vlahovskib52206d2016-10-19 14:14:18 +000086 llvm::Optional<Range> FindMemoryRange(lldb::addr_t addr);
87
88 llvm::ArrayRef<uint8_t> GetMemory(lldb::addr_t addr, size_t size);
89
90 llvm::Optional<MemoryRegionInfo> GetMemoryRegionInfo(lldb::addr_t);
91
Leonard Mosescu2ae3ec32018-07-12 17:27:18 +000092 // Perform consistency checks and initialize internal data structures
93 Status Initialize();
94
95private:
96 MinidumpParser(const lldb::DataBufferSP &data_buf_sp);
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;
Dimitar Vlahovski2e50d8e2016-09-01 11:29:53 +0000102};
103
Dimitar Vlahovski4c319072016-09-27 19:05:55 +0000104} // end namespace minidump
105} // end namespace lldb_private
Dimitar Vlahovski2e50d8e2016-09-01 11:29:53 +0000106#endif // liblldb_MinidumpParser_h_