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 const void *GetData(lldb::offset_t *offset_ptr,
50 lldb::offset_t length) const override;
51
52 const uint8_t *PeekData(lldb::offset_t offset,
53 lldb::offset_t length) const override;
54
56 lldb::offset_t length) override;
57
59
60 llvm::ArrayRef<uint8_t> GetData() const override;
61
62 /// Unchecked overrides
63 /// @{
64 uint8_t GetU8_unchecked(lldb::offset_t *offset_ptr) const override;
65 uint16_t GetU16_unchecked(lldb::offset_t *offset_ptr) const override;
66 uint32_t GetU32_unchecked(lldb::offset_t *offset_ptr) const override;
67 uint64_t GetU64_unchecked(lldb::offset_t *offset_ptr) const override;
68 /// @}
69
70protected:
71 /// Find the lookup entry that contains the given virtual address.
72 const LookupTable::Entry *FindEntry(lldb::offset_t virtual_addr) const;
73
74 /// Validate that a read at a virtual address is within bounds and
75 /// does not cross entry boundaries.
76 bool ValidateVirtualRead(lldb::offset_t virtual_addr,
77 lldb::offset_t length) const;
78
79private:
81};
82
83} // namespace lldb_private
84
85#endif // LLDB_UTILITY_VIRTUALDATAEXTRACTOR_H
DataExtractor()
Default constructor.
RangeData< lldb::offset_t, lldb::offset_t, lldb::offset_t > Entry
Definition RangeMap.h:462
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,...
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.
uint16_t GetU16_unchecked(lldb::offset_t *offset_ptr) const override
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