xref: /llvm-project/lldb/include/lldb/Target/CoreFileMemoryRanges.h (revision 0975e2ac58b6d62429d51df54911fb4d03dcda05)
1 //===-- CoreFileMemoryRanges.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 #include "lldb/Utility/RangeMap.h"
10 #include "lldb/Utility/Status.h"
11 #include "lldb/Utility/StreamString.h"
12 
13 #include "llvm/ADT/AddressRanges.h"
14 
15 #ifndef LLDB_TARGET_COREFILEMEMORYRANGES_H
16 #define LLDB_TARGET_COREFILEMEMORYRANGES_H
17 
18 namespace lldb_private {
19 
20 struct CoreFileMemoryRange {
21   llvm::AddressRange range;  /// The address range to save into the core file.
22   uint32_t lldb_permissions; /// A bit set of lldb::Permissions bits.
23 
24   bool operator==(const CoreFileMemoryRange &rhs) const {
25     return range == rhs.range && lldb_permissions == rhs.lldb_permissions;
26   }
27 
28   bool operator!=(const CoreFileMemoryRange &rhs) const {
29     return !(*this == rhs);
30   }
31 
32   bool operator<(const CoreFileMemoryRange &rhs) const {
33     if (range < rhs.range)
34       return true;
35     if (range == rhs.range)
36       return lldb_permissions < rhs.lldb_permissions;
37     return false;
38   }
39 
40   std::string Dump() const {
41     lldb_private::StreamString stream;
42     stream << "[";
43     stream.PutHex64(range.start());
44     stream << '-';
45     stream.PutHex64(range.end());
46     stream << ")";
47     return stream.GetString().str();
48   }
49 };
50 
51 class CoreFileMemoryRanges
52     : public lldb_private::RangeDataVector<lldb::addr_t, lldb::addr_t,
53                                            CoreFileMemoryRange> {
54 public:
55   /// Finalize and merge all overlapping ranges in this collection. Ranges
56   /// will be seperated based on permissions.
57   Status FinalizeCoreFileSaveRanges();
58 };
59 } // namespace lldb_private
60 
61 #endif // LLDB_TARGET_COREFILEMEMORYRANGES_H
62