LLDB  mainline
MinidumpParser.h
Go to the documentation of this file.
1 //===-- MinidumpParser.h -----------------------------------------*- C++-*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLDB_SOURCE_PLUGINS_PROCESS_MINIDUMP_MINIDUMPPARSER_H
10 #define LLDB_SOURCE_PLUGINS_PROCESS_MINIDUMP_MINIDUMPPARSER_H
11 
12 #include "MinidumpTypes.h"
13 
15 #include "lldb/Utility/ArchSpec.h"
17 #include "lldb/Utility/Status.h"
18 #include "lldb/Utility/UUID.h"
19 
20 #include "llvm/ADT/ArrayRef.h"
21 #include "llvm/ADT/DenseMap.h"
22 #include "llvm/ADT/Optional.h"
23 #include "llvm/ADT/StringRef.h"
24 #include "llvm/Object/Minidump.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)
44 
45  friend bool operator==(const Range &lhs, const Range &rhs) {
46  return lhs.start == rhs.start && lhs.range_ref == rhs.range_ref;
47  }
48 };
49 
51 public:
52  static llvm::Expected<MinidumpParser>
53  Create(const lldb::DataBufferSP &data_buf_sp);
54 
55  llvm::ArrayRef<uint8_t> GetData();
56 
57  llvm::ArrayRef<uint8_t> GetStream(StreamType stream_type);
58 
59  UUID GetModuleUUID(const minidump::Module *module);
60 
61  llvm::ArrayRef<minidump::Thread> GetThreads();
62 
63  llvm::ArrayRef<uint8_t> GetThreadContext(const LocationDescriptor &location);
64 
65  llvm::ArrayRef<uint8_t> GetThreadContext(const minidump::Thread &td);
66 
67  llvm::ArrayRef<uint8_t> GetThreadContextWow64(const minidump::Thread &td);
68 
70 
72 
73  llvm::Optional<LinuxProcStatus> GetLinuxProcStatus();
74 
75  llvm::Optional<lldb::pid_t> GetPid();
76 
77  llvm::ArrayRef<minidump::Module> GetModuleList();
78 
79  // There are cases in which there is more than one record in the ModuleList
80  // for the same module name.(e.g. when the binary has non contiguous segments)
81  // So this function returns a filtered module list - if it finds records that
82  // have the same name, it keeps the copy with the lowest load address.
83  std::vector<const minidump::Module *> GetFilteredModuleList();
84 
85  const llvm::minidump::ExceptionStream *GetExceptionStream();
86 
87  llvm::Optional<Range> FindMemoryRange(lldb::addr_t addr);
88 
89  llvm::ArrayRef<uint8_t> GetMemory(lldb::addr_t addr, size_t size);
90 
91  /// Returns a list of memory regions and a flag indicating whether the list is
92  /// complete (includes all regions mapped into the process memory).
93  std::pair<MemoryRegionInfos, bool> BuildMemoryRegions();
94 
95  static llvm::StringRef GetStreamTypeAsString(StreamType stream_type);
96 
97  llvm::object::MinidumpFile &GetMinidumpFile() { return *m_file; }
98 
100  lldb::addr_t load_addr);
101 
102 private:
103  MinidumpParser(lldb::DataBufferSP data_sp,
104  std::unique_ptr<llvm::object::MinidumpFile> file);
105 
106  lldb::DataBufferSP m_data_sp;
107  std::unique_ptr<llvm::object::MinidumpFile> m_file;
109 };
110 
111 } // end namespace minidump
112 } // end namespace lldb_private
113 #endif // LLDB_SOURCE_PLUGINS_PROCESS_MINIDUMP_MINIDUMPPARSER_H
lldb_private::UUID
Definition: UUID.h:23
lldb_private::minidump::MinidumpMiscInfo
Definition: MinidumpTypes.h:75
lldb_private::ArchSpec
Definition: ArchSpec.h:33
lldb_private::minidump::MinidumpParser::GetLinuxProcStatus
llvm::Optional< LinuxProcStatus > GetLinuxProcStatus()
Definition: MinidumpParser.cpp:226
UUID.h
lldb_private::minidump::MinidumpParser::GetFilteredModuleList
std::vector< const minidump::Module * > GetFilteredModuleList()
Definition: MinidumpParser.cpp:347
lldb_private::minidump::MinidumpParser::GetExceptionStream
const llvm::minidump::ExceptionStream * GetExceptionStream()
Definition: MinidumpParser.cpp:423
lldb_private::minidump::MinidumpParser::m_arch
ArchSpec m_arch
Definition: MinidumpParser.h:108
MinidumpTypes.h
lldb_private::minidump::MinidumpParser::FindMemoryRange
llvm::Optional< Range > FindMemoryRange(lldb::addr_t addr)
Definition: MinidumpParser.cpp:435
lldb_private::minidump::Range::range_ref
llvm::ArrayRef< uint8_t > range_ref
Definition: MinidumpParser.h:40
lldb_private::minidump::MinidumpParser::GetModuleUUID
UUID GetModuleUUID(const minidump::Module *module)
Definition: MinidumpParser.cpp:51
lldb_private::minidump::MinidumpParser::GetPid
llvm::Optional< lldb::pid_t > GetPid()
Definition: MinidumpParser.cpp:235
lldb_private::minidump::MinidumpParser::GetThreadContext
llvm::ArrayRef< uint8_t > GetThreadContext(const LocationDescriptor &location)
Definition: MinidumpParser.cpp:94
lldb_private::MemoryRegionInfo
Definition: MemoryRegionInfo.h:21
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
lldb_private::minidump::MinidumpParser::GetArchitecture
ArchSpec GetArchitecture()
Definition: MinidumpParser.cpp:136
lldb_private::minidump::Range::Range
Range(lldb::addr_t start, llvm::ArrayRef< uint8_t > range_ref)
Definition: MinidumpParser.h:42
lldb_private::minidump::Range::start
lldb::addr_t start
Definition: MinidumpParser.h:38
lldb_private::minidump::Range::operator==
friend bool operator==(const Range &lhs, const Range &rhs)
Definition: MinidumpParser.h:45
lldb_private::minidump::MinidumpParser::GetStream
llvm::ArrayRef< uint8_t > GetStream(StreamType stream_type)
Definition: MinidumpParser.cpp:46
MemoryRegionInfo.h
lldb_private::minidump::MinidumpParser::GetStreamTypeAsString
static llvm::StringRef GetStreamTypeAsString(StreamType stream_type)
Definition: MinidumpParser.cpp:638
lldb_private::minidump::MinidumpParser
Definition: MinidumpParser.h:50
lldb_private::minidump::MinidumpParser::GetMinidumpFile
llvm::object::MinidumpFile & GetMinidumpFile()
Definition: MinidumpParser.h:97
lldb_private::MemoryRegionInfos
Definition: MemoryRegionInfo.h:164
lldb_private::minidump::MinidumpParser::GetThreads
llvm::ArrayRef< minidump::Thread > GetThreads()
Definition: MinidumpParser.cpp:82
lldb_private::minidump::MinidumpParser::m_data_sp
lldb::DataBufferSP m_data_sp
Definition: MinidumpParser.h:106
lldb_private::minidump::MinidumpParser::GetData
llvm::ArrayRef< uint8_t > GetData()
Definition: MinidumpParser.cpp:41
lldb_private::minidump::MinidumpParser::m_file
std::unique_ptr< llvm::object::MinidumpFile > m_file
Definition: MinidumpParser.h:107
lldb_private::minidump::MinidumpParser::GetThreadContextWow64
llvm::ArrayRef< uint8_t > GetThreadContextWow64(const minidump::Thread &td)
Definition: MinidumpParser.cpp:106
lldb_private::minidump::MinidumpParser::GetModuleList
llvm::ArrayRef< minidump::Module > GetModuleList()
Definition: MinidumpParser.cpp:249
ArchSpec.h
lldb_private::minidump::MinidumpParser::GetMiscInfo
const MinidumpMiscInfo * GetMiscInfo()
Definition: MinidumpParser.cpp:217
Status.h
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::minidump::MinidumpParser::GetMemoryRegionInfo
static MemoryRegionInfo GetMemoryRegionInfo(const MemoryRegionInfos &regions, lldb::addr_t load_addr)
Definition: MinidumpParser.cpp:691
lldb_private::minidump::Range
Definition: MinidumpParser.h:37
lldb_private::minidump::MinidumpParser::Create
static llvm::Expected< MinidumpParser > Create(const lldb::DataBufferSP &data_buf_sp)
Definition: MinidumpParser.cpp:28
lldb_private::minidump::MinidumpParser::BuildMemoryRegions
std::pair< MemoryRegionInfos, bool > BuildMemoryRegions()
Returns a list of memory regions and a flag indicating whether the list is complete (includes all reg...
Definition: MinidumpParser.cpp:611
lldb_private::minidump::MinidumpParser::GetMemory
llvm::ArrayRef< uint8_t > GetMemory(lldb::addr_t addr, size_t size)
Definition: MinidumpParser.cpp:496
DataBuffer.h
lldb_private::minidump::MinidumpParser::MinidumpParser
MinidumpParser(lldb::DataBufferSP data_sp, std::unique_ptr< llvm::object::MinidumpFile > file)
Definition: MinidumpParser.cpp:37