[LLVM][NVPTX] Add support for griddepcontrol instruction (#123511)
[llvm-project.git] / lldb / source / Plugins / Process / minidump / MinidumpParser.h
blob2c5e6f19ff9a11374263b5def624963a0729a85b
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 //===----------------------------------------------------------------------===//
9 #ifndef LLDB_SOURCE_PLUGINS_PROCESS_MINIDUMP_MINIDUMPPARSER_H
10 #define LLDB_SOURCE_PLUGINS_PROCESS_MINIDUMP_MINIDUMPPARSER_H
12 #include "MinidumpTypes.h"
14 #include "lldb/Target/MemoryRegionInfo.h"
15 #include "lldb/Utility/ArchSpec.h"
16 #include "lldb/Utility/DataBuffer.h"
17 #include "lldb/Utility/Status.h"
18 #include "lldb/Utility/UUID.h"
20 #include "llvm/ADT/ArrayRef.h"
21 #include "llvm/ADT/DenseMap.h"
22 #include "llvm/ADT/StringRef.h"
23 #include "llvm/Object/Minidump.h"
25 // C includes
27 // C++ includes
28 #include <cstring>
29 #include <optional>
30 #include <unordered_map>
32 namespace lldb_private {
34 namespace minidump {
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;
42 Range(lldb::addr_t start, llvm::ArrayRef<uint8_t> range_ref)
43 : start(start), range_ref(range_ref) {}
45 friend bool operator==(const Range &lhs, const Range &rhs) {
46 return lhs.start == rhs.start && lhs.range_ref == rhs.range_ref;
50 using FallibleMemory64Iterator = llvm::object::MinidumpFile::FallibleMemory64Iterator;
51 using ExceptionStreamsIterator =
52 llvm::object::MinidumpFile::ExceptionStreamsIterator;
54 class MinidumpParser {
55 public:
56 static llvm::Expected<MinidumpParser>
57 Create(const lldb::DataBufferSP &data_buf_sp);
59 llvm::ArrayRef<uint8_t> GetData();
61 llvm::ArrayRef<uint8_t> GetStream(StreamType stream_type);
62 std::optional<llvm::ArrayRef<uint8_t>> GetRawStream(StreamType stream_type);
64 UUID GetModuleUUID(const minidump::Module *module);
66 llvm::ArrayRef<minidump::Thread> GetThreads();
68 llvm::ArrayRef<uint8_t> GetThreadContext(const LocationDescriptor &location);
70 llvm::ArrayRef<uint8_t> GetThreadContext(const minidump::Thread &td);
72 llvm::ArrayRef<uint8_t> GetThreadContextWow64(const minidump::Thread &td);
74 ArchSpec GetArchitecture();
76 const MinidumpMiscInfo *GetMiscInfo();
78 std::optional<LinuxProcStatus> GetLinuxProcStatus();
80 std::optional<lldb::pid_t> GetPid();
82 llvm::ArrayRef<minidump::Module> GetModuleList();
84 // There are cases in which there is more than one record in the ModuleList
85 // for the same module name.(e.g. when the binary has non contiguous segments)
86 // So this function returns a filtered module list - if it finds records that
87 // have the same name, it keeps the copy with the lowest load address.
88 std::vector<const minidump::Module *> GetFilteredModuleList();
90 llvm::iterator_range<ExceptionStreamsIterator> GetExceptionStreams();
92 std::optional<Range> FindMemoryRange(lldb::addr_t addr);
94 llvm::ArrayRef<uint8_t> GetMemory(lldb::addr_t addr, size_t size);
96 /// Returns a list of memory regions and a flag indicating whether the list is
97 /// complete (includes all regions mapped into the process memory).
98 std::pair<MemoryRegionInfos, bool> BuildMemoryRegions();
100 llvm::iterator_range<FallibleMemory64Iterator> GetMemory64Iterator(llvm::Error &err);
102 static llvm::StringRef GetStreamTypeAsString(StreamType stream_type);
104 llvm::object::MinidumpFile &GetMinidumpFile() { return *m_file; }
106 static MemoryRegionInfo GetMemoryRegionInfo(const MemoryRegionInfos &regions,
107 lldb::addr_t load_addr);
109 private:
110 MinidumpParser(lldb::DataBufferSP data_sp,
111 std::unique_ptr<llvm::object::MinidumpFile> file);
113 lldb::DataBufferSP m_data_sp;
114 std::unique_ptr<llvm::object::MinidumpFile> m_file;
115 ArchSpec m_arch;
118 } // end namespace minidump
119 } // end namespace lldb_private
120 #endif // LLDB_SOURCE_PLUGINS_PROCESS_MINIDUMP_MINIDUMPPARSER_H