blob: c08fe91c5066fc1f946c9f5ae31c408d0fb7b11d [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
Dimitar Vlahovski2e50d8e2016-09-01 11:29:53 +000014#include "MinidumpTypes.h"
15
Pavel Labath5f19b902017-11-13 16:16:33 +000016#include "lldb/Utility/ArchSpec.h"
Zachary Turner666cc0b2017-03-04 01:30:05 +000017#include "lldb/Utility/DataBuffer.h"
Zachary Turner97206d52017-05-12 04:51:55 +000018#include "lldb/Utility/Status.h"
Leonard Mosescu9fecd372018-05-02 20:06:17 +000019#include "lldb/Utility/UUID.h"
Dimitar Vlahovski2e50d8e2016-09-01 11:29:53 +000020
21#include "llvm/ADT/ArrayRef.h"
22#include "llvm/ADT/DenseMap.h"
23#include "llvm/ADT/Optional.h"
Dimitar Vlahovski1d2859e2016-09-13 15:54:38 +000024#include "llvm/ADT/StringRef.h"
Dimitar Vlahovski2e50d8e2016-09-01 11:29:53 +000025
26// C includes
Dimitar Vlahovski36e21a32016-10-05 18:11:45 +000027
Dimitar Vlahovski2e50d8e2016-09-01 11:29:53 +000028// C++ includes
Dimitar Vlahovski36e21a32016-10-05 18:11:45 +000029#include <cstring>
30#include <unordered_map>
Dimitar Vlahovski2e50d8e2016-09-01 11:29:53 +000031
Kate Stoneb9c1b512016-09-06 20:57:50 +000032namespace lldb_private {
Dimitar Vlahovski2e50d8e2016-09-01 11:29:53 +000033
Kate Stoneb9c1b512016-09-06 20:57:50 +000034namespace minidump {
Dimitar Vlahovski2e50d8e2016-09-01 11:29:53 +000035
Dimitar Vlahovskib52206d2016-10-19 14:14:18 +000036// Describes a range of memory captured in the Minidump
37struct 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
Kate Stoneb9c1b512016-09-06 20:57:50 +000046class MinidumpParser {
Dimitar Vlahovski2e50d8e2016-09-01 11:29:53 +000047public:
Kate Stoneb9c1b512016-09-06 20:57:50 +000048 static llvm::Optional<MinidumpParser>
49 Create(const lldb::DataBufferSP &data_buf_sp);
Dimitar Vlahovski2e50d8e2016-09-01 11:29:53 +000050
Dimitar Vlahovski4c319072016-09-27 19:05:55 +000051 llvm::ArrayRef<uint8_t> GetData();
Dimitar Vlahovski2e50d8e2016-09-01 11:29:53 +000052
Dimitar Vlahovski1d2859e2016-09-13 15:54:38 +000053 llvm::ArrayRef<uint8_t> GetStream(MinidumpStreamType stream_type);
Dimitar Vlahovski2e50d8e2016-09-01 11:29:53 +000054
Dimitar Vlahovski1d2859e2016-09-13 15:54:38 +000055 llvm::Optional<std::string> GetMinidumpString(uint32_t rva);
56
Leonard Mosescu9fecd372018-05-02 20:06:17 +000057 UUID GetModuleUUID(const MinidumpModule* module);
58
Dimitar Vlahovski1d2859e2016-09-13 15:54:38 +000059 llvm::ArrayRef<MinidumpThread> GetThreads();
Dimitar Vlahovski2e50d8e2016-09-01 11:29:53 +000060
Dimitar Vlahovskib52206d2016-10-19 14:14:18 +000061 llvm::ArrayRef<uint8_t> GetThreadContext(const MinidumpThread &td);
62
Dimitar Vlahovski7b18dd42016-10-31 15:35:18 +000063 llvm::ArrayRef<uint8_t> GetThreadContextWow64(const MinidumpThread &td);
64
Kate Stoneb9c1b512016-09-06 20:57:50 +000065 const MinidumpSystemInfo *GetSystemInfo();
Dimitar Vlahovski2e50d8e2016-09-01 11:29:53 +000066
Kate Stoneb9c1b512016-09-06 20:57:50 +000067 ArchSpec GetArchitecture();
Dimitar Vlahovski2e50d8e2016-09-01 11:29:53 +000068
Kate Stoneb9c1b512016-09-06 20:57:50 +000069 const MinidumpMiscInfo *GetMiscInfo();
Dimitar Vlahovski2e50d8e2016-09-01 11:29:53 +000070
Dimitar Vlahovski1d2859e2016-09-13 15:54:38 +000071 llvm::Optional<LinuxProcStatus> GetLinuxProcStatus();
72
73 llvm::Optional<lldb::pid_t> GetPid();
74
75 llvm::ArrayRef<MinidumpModule> GetModuleList();
76
Dimitar Vlahovskib52206d2016-10-19 14:14:18 +000077 // There are cases in which there is more than one record in the ModuleList
78 // for the same module name.(e.g. when the binary has non contiguous segments)
79 // So this function returns a filtered module list - if it finds records that
80 // have the same name, it keeps the copy with the lowest load address.
81 std::vector<const MinidumpModule *> GetFilteredModuleList();
82
Dimitar Vlahovski1d2859e2016-09-13 15:54:38 +000083 const MinidumpExceptionStream *GetExceptionStream();
84
Dimitar Vlahovskib52206d2016-10-19 14:14:18 +000085 llvm::Optional<Range> FindMemoryRange(lldb::addr_t addr);
86
87 llvm::ArrayRef<uint8_t> GetMemory(lldb::addr_t addr, size_t size);
88
89 llvm::Optional<MemoryRegionInfo> GetMemoryRegionInfo(lldb::addr_t);
90
Leonard Mosescu2ae3ec32018-07-12 17:27:18 +000091 // Perform consistency checks and initialize internal data structures
92 Status Initialize();
93
94private:
95 MinidumpParser(const lldb::DataBufferSP &data_buf_sp);
96
Dimitar Vlahovski2e50d8e2016-09-01 11:29:53 +000097private:
Kate Stoneb9c1b512016-09-06 20:57:50 +000098 lldb::DataBufferSP m_data_sp;
Kate Stoneb9c1b512016-09-06 20:57:50 +000099 llvm::DenseMap<uint32_t, MinidumpLocationDescriptor> m_directory_map;
Greg Clayton19c8f392018-08-06 16:56:10 +0000100 ArchSpec m_arch;
Dimitar Vlahovski2e50d8e2016-09-01 11:29:53 +0000101};
102
Dimitar Vlahovski4c319072016-09-27 19:05:55 +0000103} // end namespace minidump
104} // end namespace lldb_private
Dimitar Vlahovski2e50d8e2016-09-01 11:29:53 +0000105#endif // liblldb_MinidumpParser_h_