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