Separated TargetMemoryAddressRange from TargetMemory.hpp

This commit is contained in:
Nav
2025-01-28 00:14:04 +00:00
parent 333c927454
commit 91db0eb6e8
34 changed files with 196 additions and 102 deletions

View File

@@ -5,6 +5,8 @@
#include "src/DebugServer/Gdb/ResponsePackets/ErrorResponsePacket.hpp"
#include "src/DebugServer/Gdb/ResponsePackets/ResponsePacket.hpp"
#include "src/Targets/TargetMemoryAddressRange.hpp"
#include "src/Services/StringService.hpp"
#include "src/Logger/Logger.hpp"

View File

@@ -2,7 +2,9 @@
#include <string>
#include "src/Targets/TargetMemoryAddressRange.hpp"
#include "src/Targets/Microchip/Avr8/OpcodeDecoder/Decoder.hpp"
#include "src/Services/Avr8InstructionService.hpp"
#include "src/Services/StringService.hpp"
#include "src/Services/PathService.hpp"

View File

@@ -1,5 +1,7 @@
#include "WriteMemory.hpp"
#include "src/Targets/TargetMemoryAddressRange.hpp"
#include "src/DebugServer/Gdb/ResponsePackets/ErrorResponsePacket.hpp"
#include "src/DebugServer/Gdb/ResponsePackets/OkResponsePacket.hpp"

View File

@@ -3,6 +3,7 @@
#include <set>
#include "src/Targets/TargetMemory.hpp"
#include "src/Targets/TargetMemoryAddressRange.hpp"
#include "src/Targets/TargetAddressSpaceDescriptor.hpp"
#include "src/Targets/TargetMemorySegmentDescriptor.hpp"

View File

@@ -1,5 +1,7 @@
#include "FlashDone.hpp"
#include "src/Targets/TargetMemoryAddressRange.hpp"
#include "src/DebugServer/Gdb/ResponsePackets/ErrorResponsePacket.hpp"
#include "src/DebugServer/Gdb/ResponsePackets/OkResponsePacket.hpp"

View File

@@ -2,6 +2,8 @@
#include <cassert>
#include "src/Targets/TargetMemoryAddressRange.hpp"
#include "src/DebugServer/Gdb/ResponsePackets/ErrorResponsePacket.hpp"
#include "src/DebugServer/Gdb/ResponsePackets/ResponsePacket.hpp"

View File

@@ -2,6 +2,8 @@
#include <string>
#include "src/Targets/TargetMemoryAddressRange.hpp"
#include "src/DebugServer/Gdb/ResponsePackets/OkResponsePacket.hpp"
#include "src/DebugServer/Gdb/ResponsePackets/EmptyResponsePacket.hpp"
#include "src/DebugServer/Gdb/ResponsePackets/ErrorResponsePacket.hpp"
@@ -9,8 +11,8 @@
#include "src/Targets/TargetBreakpoint.hpp"
#include "src/Services/StringService.hpp"
#include "src/Logger/Logger.hpp"
#include "src/Exceptions/Exception.hpp"
namespace DebugServer::Gdb::RiscVGdb::CommandPackets

View File

@@ -1,5 +1,7 @@
#include "WriteMemory.hpp"
#include "src/Targets/TargetMemoryAddressRange.hpp"
#include "src/DebugServer/Gdb/ResponsePackets/ErrorResponsePacket.hpp"
#include "src/DebugServer/Gdb/ResponsePackets/OkResponsePacket.hpp"

View File

@@ -15,6 +15,7 @@
#include "DebugModuleDescriptor.hpp"
#include "src/Targets/TargetMemory.hpp"
#include "src/Targets/TargetMemoryAddressRange.hpp"
#include "src/Targets/TargetAddressSpaceDescriptor.hpp"
#include "src/Targets/TargetMemorySegmentDescriptor.hpp"
#include "src/Targets/TargetState.hpp"

View File

@@ -15,6 +15,7 @@
#include "src/Targets/TargetState.hpp"
#include "src/Targets/TargetRegisterDescriptor.hpp"
#include "src/Targets/TargetMemory.hpp"
#include "src/Targets/TargetMemoryAddressRange.hpp"
#include "src/Targets/TargetBreakpoint.hpp"
namespace DebugToolDrivers::TargetInterfaces::Microchip::Avr8

View File

@@ -11,6 +11,7 @@
#include "src/Targets/TargetState.hpp"
#include "src/Targets/TargetRegisterDescriptor.hpp"
#include "src/Targets/TargetMemory.hpp"
#include "src/Targets/TargetMemoryAddressRange.hpp"
#include "src/Targets/TargetBreakpoint.hpp"
namespace DebugToolDrivers::TargetInterfaces::RiscV

View File

@@ -8,6 +8,7 @@
#include "src/Targets/TargetRegisterDescriptor.hpp"
#include "src/Targets/TargetMemory.hpp"
#include "src/Targets/TargetMemoryAddressRange.hpp"
#include "src/Targets/TargetAddressSpaceDescriptor.hpp"
#include "src/Targets/TargetMemorySegmentDescriptor.hpp"

View File

@@ -3,6 +3,7 @@
#include "InsightWorkerTask.hpp"
#include "src/Targets/TargetMemory.hpp"
#include "src/Targets/TargetMemoryAddressRange.hpp"
#include "src/Targets/TargetAddressSpaceDescriptor.hpp"
#include "src/Targets/TargetMemorySegmentDescriptor.hpp"

View File

@@ -3,6 +3,7 @@
#include <optional>
#include "src/Targets/TargetMemory.hpp"
#include "src/Targets/TargetMemoryAddressRange.hpp"
#include "src/Targets/TargetAddressSpaceDescriptor.hpp"
#include "src/Targets/TargetMemorySegmentDescriptor.hpp"

View File

@@ -7,6 +7,7 @@
#include <optional>
#include "src/Targets/TargetMemory.hpp"
#include "src/Targets/TargetMemoryAddressRange.hpp"
#include "src/Targets/TargetAddressSpaceDescriptor.hpp"
#include "src/Targets/TargetMemorySegmentDescriptor.hpp"
#include "src/Targets/TargetState.hpp"

View File

@@ -18,6 +18,7 @@
#include <QTimer>
#include "src/Targets/TargetMemory.hpp"
#include "src/Targets/TargetMemoryAddressRange.hpp"
#include "src/Targets/TargetAddressSpaceDescriptor.hpp"
#include "src/Targets/TargetMemorySegmentDescriptor.hpp"
#include "src/Targets/TargetState.hpp"

View File

@@ -6,7 +6,7 @@
#include <QJsonObject>
#include <utility>
#include "src/Targets/TargetMemory.hpp"
#include "src/Targets/TargetMemoryAddressRange.hpp"
#include "AddressType.hpp"
#include "src/Services/DateTimeService.hpp"

View File

@@ -10,7 +10,6 @@
#include <QStackedLayout>
#include <QAction>
#include "src/Targets/TargetMemory.hpp"
#include "src/Targets/TargetAddressSpaceDescriptor.hpp"
#include "src/Targets/TargetMemorySegmentDescriptor.hpp"

View File

@@ -13,7 +13,7 @@
#include "src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegion.hpp"
#include "src/Targets/TargetMemory.hpp"
#include "src/Targets/TargetMemoryAddressRange.hpp"
#include "src/Targets/TargetMemorySegmentDescriptor.hpp"
namespace Widgets

View File

@@ -2,7 +2,7 @@
#include "src/Insight/UserInterfaces/InsightWindow/Widgets/ListView/ListItem.hpp"
#include "src/Targets/TargetMemory.hpp"
#include "src/Targets/TargetMemoryAddressRange.hpp"
namespace Widgets
{

View File

@@ -10,7 +10,7 @@
#include "src/Insight/UserInterfaces/InsightWindow/Widgets/Label.hpp"
#include "src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/DifferentialHexViewerWidget/DifferentialHexViewerWidget.hpp"
#include "src/Targets/TargetMemory.hpp"
#include "src/Targets/TargetMemoryAddressRange.hpp"
#include "ChangeListItem.hpp"

View File

@@ -7,6 +7,8 @@
#include "src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/SnapshotDiffSettings.hpp"
#include "src/Targets/TargetMemoryAddressRange.hpp"
namespace Widgets
{
class DifferentialItemGraphicsScene final: public ItemGraphicsScene

View File

@@ -12,6 +12,7 @@
#include "src/Insight/UserInterfaces/InsightWindow/Widgets/PaneWidget.hpp"
#include "src/Targets/TargetMemory.hpp"
#include "src/Targets/TargetMemoryAddressRange.hpp"
#include "src/Targets/TargetAddressSpaceDescriptor.hpp"
#include "src/Targets/TargetMemorySegmentDescriptor.hpp"
#include "src/Targets/TargetState.hpp"

View File

@@ -19,6 +19,7 @@
#include "src/Targets/TargetPadDescriptor.hpp"
#include "src/Targets/TargetGpioPadState.hpp"
#include "src/Targets/TargetMemory.hpp"
#include "src/Targets/TargetMemoryAddressRange.hpp"
#include "src/Targets/TargetBreakpoint.hpp"
#include "src/Targets/PassthroughCommand.hpp"
#include "src/Targets/PassthroughResponse.hpp"

View File

@@ -10,6 +10,7 @@
#include "src/Targets/TargetMemorySegmentDescriptor.hpp"
#include "src/Targets/TargetMemorySegmentType.hpp"
#include "src/Targets/TargetMemory.hpp"
#include "src/Targets/TargetMemoryAddressRange.hpp"
namespace TargetController::Commands
{

View File

@@ -68,6 +68,7 @@
#include "src/Targets/Targets.hpp"
#include "src/Targets/TargetRegisterDescriptor.hpp"
#include "src/Targets/TargetMemory.hpp"
#include "src/Targets/TargetMemoryAddressRange.hpp"
#include "src/Targets/TargetAddressSpaceDescriptor.hpp"
#include "src/Targets/TargetMemorySegmentDescriptor.hpp"
#include "src/Targets/ProgramBreakpointRegistry.hpp"

View File

@@ -1,6 +1,7 @@
target_sources(
Bloom
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/TargetMemoryAddressRange.cpp
${CMAKE_CURRENT_SOURCE_DIR}/TargetDescriptor.cpp
${CMAKE_CURRENT_SOURCE_DIR}/TargetAddressSpaceDescriptor.cpp
${CMAKE_CURRENT_SOURCE_DIR}/TargetMemorySegmentDescriptor.cpp

View File

@@ -1,6 +1,7 @@
#include "DynamicRegisterValue.hpp"
#include <bitset>
#include <cassert>
namespace Targets
{

View File

@@ -16,6 +16,7 @@
#include "TargetState.hpp"
#include "TargetRegisterDescriptor.hpp"
#include "TargetMemory.hpp"
#include "TargetMemoryAddressRange.hpp"
#include "TargetBreakpoint.hpp"
#include "TargetPadDescriptor.hpp"
#include "TargetGpioPadState.hpp"

View File

@@ -7,6 +7,7 @@
#include <optional>
#include "TargetMemory.hpp"
#include "TargetMemoryAddressRange.hpp"
#include "TargetMemorySegmentDescriptor.hpp"
namespace Targets

View File

@@ -1,12 +1,8 @@
#pragma once
#include <cstdint>
#include <algorithm>
#include <vector>
#include <span>
#include <set>
#include <optional>
#include <cassert>
namespace Targets
{
@@ -25,98 +21,6 @@ namespace Targets
LITTLE,
};
struct TargetMemoryAddressRange
{
TargetMemoryAddress startAddress = 0;
TargetMemoryAddress endAddress = 0;
TargetMemoryAddressRange() = default;
TargetMemoryAddressRange(TargetMemoryAddress startAddress, TargetMemoryAddress endAddress)
: startAddress(startAddress)
, endAddress(endAddress)
{
assert(this->startAddress <= this->endAddress);
}
bool operator == (const TargetMemoryAddressRange& rhs) const {
return this->startAddress == rhs.startAddress && this->endAddress == rhs.endAddress;
}
bool operator < (const TargetMemoryAddressRange& rhs) const {
return this->startAddress < rhs.startAddress;
}
/**
* Returns the number of addresses in the range.
*
* Keep in mind that the number of addresses may not be equal to the number of bytes in the range. It depends
* on whether the address space is byte-addressable. See TargetAddressSpaceDescriptor::unitSize for more.
*
* @return
*/
[[nodiscard]] TargetMemorySize size() const {
return this->endAddress - this->startAddress + 1;
}
/**
* Checks if this range intersects with the given range.
*
* @param other
* @return
*/
[[nodiscard]] bool intersectsWith(const TargetMemoryAddressRange& other) const noexcept {
return this->startAddress <= other.endAddress && other.startAddress <= this->endAddress;
}
/**
* Returns the number of addresses in this range that intersect with the given range.
*
* @param other
* @return
*/
[[nodiscard]] TargetMemorySize intersectingSize(const TargetMemoryAddressRange& other) const noexcept {
return this->intersectsWith(other)
? std::min(this->endAddress, other.endAddress) - std::max(this->startAddress, other.startAddress) + 1
: 0;
}
/**
* Checks if the given address is contained within this range.
*
* @param address
* @return
*/
[[nodiscard]] bool contains(TargetMemoryAddress address) const noexcept {
return address >= this->startAddress && address <= this->endAddress;
}
/**
* Checks if the given range is completely contained within this range.
*
* @param addressRange
* @return
*/
[[nodiscard]] bool contains(const TargetMemoryAddressRange& addressRange) const noexcept {
return this->startAddress <= addressRange.startAddress && this->endAddress >= addressRange.endAddress;
}
/**
* Returns a set of all addresses within this range.
*
* @return
*/
[[nodiscard]] std::set<Targets::TargetMemoryAddress> addresses() const noexcept {
auto addresses = std::set<Targets::TargetMemoryAddress>{};
auto addressesIt = addresses.end();
for (auto i = this->startAddress; i <= this->endAddress; ++i) {
addressesIt = addresses.insert(addressesIt, i);
}
return addresses;
}
};
struct TargetMemoryAccess
{
bool readable = false;

View File

@@ -0,0 +1,79 @@
#include "TargetMemoryAddressRange.hpp"
#include <algorithm>
#include <cassert>
#include "src/Services/IntegerService.hpp"
namespace Targets
{
TargetMemoryAddressRange::TargetMemoryAddressRange(
TargetMemoryAddress startAddress,
TargetMemoryAddress endAddress
)
: startAddress(startAddress)
, endAddress(endAddress)
{
assert(this->startAddress <= this->endAddress);
}
bool TargetMemoryAddressRange::operator == (const TargetMemoryAddressRange& rhs) const {
return this->startAddress == rhs.startAddress && this->endAddress == rhs.endAddress;
}
bool TargetMemoryAddressRange::operator < (const TargetMemoryAddressRange& rhs) const {
return this->startAddress < rhs.startAddress;
}
TargetMemorySize TargetMemoryAddressRange::size() const {
return this->endAddress - this->startAddress + 1;
}
bool TargetMemoryAddressRange::intersectsWith(const TargetMemoryAddressRange& other) const noexcept {
return this->startAddress <= other.endAddress && other.startAddress <= this->endAddress;
}
TargetMemorySize TargetMemoryAddressRange::intersectingSize(const TargetMemoryAddressRange& other) const noexcept {
return this->intersectsWith(other)
? std::min(this->endAddress, other.endAddress) - std::max(this->startAddress, other.startAddress) + 1
: 0;
}
bool TargetMemoryAddressRange::contains(TargetMemoryAddress address) const noexcept {
return address >= this->startAddress && address <= this->endAddress;
}
bool TargetMemoryAddressRange::contains(const TargetMemoryAddressRange& addressRange) const noexcept {
return this->startAddress <= addressRange.startAddress && this->endAddress >= addressRange.endAddress;
}
std::set<Targets::TargetMemoryAddress> TargetMemoryAddressRange::addresses() const noexcept {
auto addresses = std::set<Targets::TargetMemoryAddress>{};
auto addressesIt = addresses.end();
for (auto i = this->startAddress; i <= this->endAddress; ++i) {
addressesIt = addresses.insert(addressesIt, i);
}
return addresses;
}
std::vector<TargetMemoryAddressRange> TargetMemoryAddressRange::blocks(TargetMemorySize blockSize) const noexcept {
const auto startBlock = this->startAddress / blockSize;
const auto endBlock = this->endAddress / blockSize;
auto output = std::vector<TargetMemoryAddressRange>{};
output.reserve(endBlock - startBlock + 1);
for (auto block = startBlock; block <= endBlock; ++block) {
const auto blockStartAddress = blockSize * block;
const auto blockEndAddress = blockStartAddress + blockSize - 1;
output.emplace_back(
std::max(blockStartAddress, this->startAddress),
std::min(blockEndAddress, this->endAddress)
);
}
return output;
}
}

View File

@@ -0,0 +1,78 @@
#pragma once
#include <set>
#include <vector>
#include "TargetMemory.hpp"
namespace Targets
{
struct TargetMemoryAddressRange
{
TargetMemoryAddress startAddress = 0;
TargetMemoryAddress endAddress = 0;
TargetMemoryAddressRange() = default;
TargetMemoryAddressRange(TargetMemoryAddress startAddress, TargetMemoryAddress endAddress);
bool operator == (const TargetMemoryAddressRange& rhs) const;
bool operator < (const TargetMemoryAddressRange& rhs) const;
/**
* Returns the number of addresses in the range.
*
* Keep in mind that the number of addresses may not be equal to the number of bytes in the range. It depends
* on whether the address space is byte-addressable. See TargetAddressSpaceDescriptor::unitSize for more.
*
* @return
*/
[[nodiscard]] TargetMemorySize size() const;
/**
* Checks if this range intersects with the given range.
*
* @param other
* @return
*/
[[nodiscard]] bool intersectsWith(const TargetMemoryAddressRange& other) const noexcept;
/**
* Returns the number of addresses in this range that intersect with the given range.
*
* @param other
* @return
*/
[[nodiscard]] TargetMemorySize intersectingSize(const TargetMemoryAddressRange& other) const noexcept;
/**
* Checks if the given address is contained within this range.
*
* @param address
* @return
*/
[[nodiscard]] bool contains(TargetMemoryAddress address) const noexcept;
/**
* Checks if the given range is completely contained within this range.
*
* @param addressRange
* @return
*/
[[nodiscard]] bool contains(const TargetMemoryAddressRange& addressRange) const noexcept;
/**
* Returns a set of all addresses within this range.
*
* @return
*/
[[nodiscard]] std::set<TargetMemoryAddress> addresses() const noexcept;
/**
* Splits the address range into a vector of blocks, with the given block size.
*
* @param blockSize
* @return
*/
[[nodiscard]] std::vector<TargetMemoryAddressRange> blocks(TargetMemorySize blockSize) const noexcept;
};
}

View File

@@ -6,6 +6,7 @@
#include <utility>
#include "TargetMemory.hpp"
#include "TargetMemoryAddressRange.hpp"
#include "TargetMemorySegmentType.hpp"
namespace Targets