LLDB mainline
VirtualDataExtractor.h
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
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_UTILITY_VIRTUALDATAEXTRACTOR_H
10#define LLDB_UTILITY_VIRTUALDATAEXTRACTOR_H
11
14#include "lldb/lldb-types.h"
15
16namespace lldb_private {
17
18/// A DataExtractor subclass that allows reading data at virtual addresses
19/// using a lookup table that maps virtual address ranges to physical offsets.
20///
21/// This class maintains a lookup table where each entry contains:
22/// - base: starting virtual address for this entry
23/// - size: size of this entry in bytes
24/// - data: physical offset in the underlying data buffer
25///
26/// Reads are translated from virtual addresses to physical offsets using
27/// this lookup table. Reads cannot cross entry boundaries and this is
28/// enforced with assertions.
30public:
31 /// Type alias for the range map used internally.
32 /// Maps virtual addresses (base) to physical offsets (data).
35
37
38 VirtualDataExtractor(const void *data, lldb::offset_t data_length,
39 lldb::ByteOrder byte_order, uint32_t addr_size,
40 LookupTable lookup_table);
41
43 lldb::ByteOrder byte_order, uint32_t addr_size,
44 LookupTable lookup_table);
45
47 LookupTable lookup_table);
48
49 lldb::DataExtractorSP Clone() const override {
50 return std::make_shared<VirtualDataExtractor>(*this);
51 }
52
53 const void *GetData(lldb::offset_t *offset_ptr,
54 lldb::offset_t length) const override;
55
56 const uint8_t *PeekData(lldb::offset_t offset,
57 lldb::offset_t length) const override;
58
60 lldb::offset_t length) override;
61
63
64 llvm::ArrayRef<uint8_t> GetData() const override;
65
66 /// GetByteSize is called by external users often, and we want to
67 /// return the virtual buffer size that the user expects to see.
68 uint64_t GetByteSize() const override { return GetVirtualByteSize(); }
69
70 /// BytesLeft is mostly called by DataExtractor internal methods, to
71 /// ensure we don't read past the end of the DataBuffer. Use the
72 /// physical buffer size.
73 lldb::offset_t BytesLeft(lldb::offset_t offset) const override {
74 return PhysicalBytesLeft(offset);
75 }
76
77 lldb::offset_t SetData(const void *bytes, lldb::offset_t length,
78 lldb::ByteOrder byte_order) override;
79
81 lldb::offset_t length) override;
82
84 lldb::offset_t offset = 0,
85 lldb::offset_t length = LLDB_INVALID_OFFSET) override;
86
87 /// Unchecked overrides
88 /// @{
89 uint8_t GetU8_unchecked(lldb::offset_t *offset_ptr) const override;
90 uint16_t GetU16_unchecked(lldb::offset_t *offset_ptr) const override;
91 uint32_t GetU32_unchecked(lldb::offset_t *offset_ptr) const override;
92 uint64_t GetU64_unchecked(lldb::offset_t *offset_ptr) const override;
93 /// @}
94
95protected:
96 /// Find the lookup entry that contains the given virtual address.
97 const LookupTable::Entry *FindEntry(lldb::offset_t virtual_addr) const;
98
99 /// Validate that a read at a virtual address is within bounds and
100 /// does not cross entry boundaries.
101 bool ValidateVirtualRead(lldb::offset_t virtual_addr,
102 lldb::offset_t length) const;
103
104 uint64_t GetVirtualByteSize() const;
105 uint64_t GetPhysicalByteSize() const;
106 lldb::offset_t VirtualBytesLeft(lldb::offset_t virtual_offset) const;
107 lldb::offset_t PhysicalBytesLeft(lldb::offset_t physical_offset) const;
108
110
111private:
113};
114
115} // namespace lldb_private
116
117#endif // LLDB_UTILITY_VIRTUALDATAEXTRACTOR_H
An data extractor class.
DataExtractor()
Default constructor.
RangeData< lldb::offset_t, lldb::offset_t, lldb::offset_t > Entry
Definition RangeMap.h:462
lldb::DataExtractorSP Clone() const override
Return a shared pointer to a copy of this object.
lldb::DataExtractorSP GetSubsetExtractorSP(lldb::offset_t offset, lldb::offset_t length) override
Return a new DataExtractor which represents a subset of an existing data extractor's bytes,...
lldb::offset_t BytesLeft(lldb::offset_t offset) const override
BytesLeft is mostly called by DataExtractor internal methods, to ensure we don't read past the end of...
uint32_t GetU32_unchecked(lldb::offset_t *offset_ptr) const override
const LookupTable::Entry * FindEntry(lldb::offset_t virtual_addr) const
Find the lookup entry that contains the given virtual address.
llvm::ArrayRef< uint8_t > GetData() const override
bool ValidateVirtualRead(lldb::offset_t virtual_addr, lldb::offset_t length) const
Validate that a read at a virtual address is within bounds and does not cross entry boundaries.
const uint8_t * PeekData(lldb::offset_t offset, lldb::offset_t length) const override
Peek at a bytes at offset.
uint8_t GetU8_unchecked(lldb::offset_t *offset_ptr) const override
Unchecked overrides.
uint64_t GetU64_unchecked(lldb::offset_t *offset_ptr) const override
RangeDataVector< lldb::offset_t, lldb::offset_t, lldb::offset_t > LookupTable
Type alias for the range map used internally.
lldb::offset_t SetData(const void *bytes, lldb::offset_t length, lldb::ByteOrder byte_order) override
Set data with a buffer that is caller owned.
uint64_t GetByteSize() const override
GetByteSize is called by external users often, and we want to return the virtual buffer size that the...
uint16_t GetU16_unchecked(lldb::offset_t *offset_ptr) const override
lldb::offset_t PhysicalBytesLeft(lldb::offset_t physical_offset) const
lldb::offset_t VirtualBytesLeft(lldb::offset_t virtual_offset) const
#define LLDB_INVALID_OFFSET
A class that represents a running process on the host machine.
uint64_t offset_t
Definition lldb-types.h:85
ByteOrder
Byte ordering definitions.
std::shared_ptr< lldb_private::DataBuffer > DataBufferSP
std::shared_ptr< lldb_private::DataExtractor > DataExtractorSP