Sync source edition with VCC Plus 3.7.0 build 63

This commit is contained in:
Brian Holman committed 2026-11-14 01:43:46 -07:00
1 parent c652a5276d
commit b2ecec4d87
86 files changed
+10519 -472

No files matched your search

+88 -5
View File
@@ -87,15 +87,55 @@ struct MachineSession::Impl final : MachineHost, VideoHost, CpuDebugHooks, Devic
}
return true;
}
struct ResidencyProof {
std::map<std::string, std::vector<std::string>> matchingOwners;
std::uint64_t fingerprint = 0;
bool contains(const DebugBankedModule& module) const {
const auto found = matchingOwners.find(module.overlayGroup);
return found != matchingOwners.end() && found->second.size() == 1 && found->second.front() == module.overlayOwner;
}
};
ResidencyProof bankedResidency(const MMUState& mmu) const {
// Re-read complete executable guards on the serialized machine queue.
// Guest stores do not increment the host program revision, and physical
// page identity alone cannot identify code that a loader has replaced.
std::map<std::string, std::map<std::string, bool>> owners;
for (const auto& module : developmentModules) if (!module.overlayGroup.empty()) {
auto& group = owners[module.overlayGroup];
const auto inserted = group.emplace(module.overlayOwner, true);
inserted.first->second = bankedModuleMatches(module, mmu) && inserted.first->second;
}
ResidencyProof result;
if (owners.empty()) return result;
std::uint64_t hash = 14695981039346656037ull;
auto number = [&](std::uint64_t value) {
for (unsigned i = 0; i < 8; ++i) { hash ^= (value >> (8*i)) & 255; hash *= 1099511628211ull; }
};
auto text = [&](const std::string& value) {
number(value.size()); for (unsigned char byte : value) { hash ^= byte; hash *= 1099511628211ull; }
};
for (const auto& group : owners) {
auto& matches = result.matchingOwners[group.first];
for (const auto& owner : group.second) if (owner.second) matches.push_back(owner.first);
text(group.first); number(matches.size());
for (const auto& owner : matches) text(owner);
}
result.fingerprint = hash ? hash : 1;
return result;
}
bool residentModuleMatches(const DebugBankedModule& module, const MMUState& mmu, const ResidencyProof& proof) const {
return module.overlayGroup.empty() ? bankedModuleMatches(module, mmu) : proof.contains(module);
}
bool bankedMatchesAt(std::uint16_t address, bool forBreakpoint = false) const {
const auto mmu = GetMMUState();
const auto residency = bankedResidency(mmu);
return std::any_of(developmentModules.begin(), developmentModules.end(), [&](const auto& module) {
if (forBreakpoint && module.breakpointAddresses &&
std::find(module.breakpointAddresses->begin(), module.breakpointAddresses->end(), address) == module.breakpointAddresses->end())
return false;
return std::any_of(module.guards.begin(), module.guards.end(), [&](const auto& guard) {
return address >= guard.address && std::size_t(address) - guard.address < guard.bytes.size();
}) && bankedModuleMatches(module, mmu);
}) && residentModuleMatches(module, mmu, residency);
});
}
// Independent of breakpoint ownership: Run releases its temporary entry breakpoint.
@@ -140,9 +180,10 @@ struct MachineSession::Impl final : MachineHost, VideoHost, CpuDebugHooks, Devic
auto found = candidates.first;
if (step.banked && found != candidates.second) {
const auto mmu = GetMMUState();
const auto residency = bankedResidency(mmu);
found = std::find_if(candidates.first, candidates.second, [&](const auto& item) {
return std::any_of(developmentModules.begin(), developmentModules.end(), [&](const auto& module) {
return module.identifier == item.second.moduleIdentifier && bankedModuleMatches(module, mmu);
return module.identifier == item.second.moduleIdentifier && residentModuleMatches(module, mmu, residency);
});
});
if (found == candidates.second) {
@@ -1436,6 +1477,9 @@ void MachineSession::debuggerArmBankedDevelopmentBreakpoints(const std::vector<s
const auto physicalPages = GetMMUState().RAMBytes / 8192;
std::vector<std::string> identifiers;
std::vector<std::bitset<65536>> moduleCoverage;
using PhysicalSpan = std::pair<std::uint32_t, std::uint32_t>;
std::vector<std::vector<PhysicalSpan>> physicalCoverage;
std::map<std::string, std::vector<std::string>> overlayOwners;
std::vector<bool> starts(65536, false);
std::size_t total = 0;
for (const auto& module : modules) {
@@ -1443,6 +1487,13 @@ void MachineSession::debuggerArmBankedDevelopmentBreakpoints(const std::vector<s
std::find(identifiers.begin(), identifiers.end(), module.identifier) != identifiers.end())
throw std::invalid_argument("Banked modules require unique bounded identifiers");
identifiers.push_back(module.identifier);
if (module.overlayGroup.empty() != module.overlayOwner.empty() || module.overlayGroup.size() > 128 || module.overlayOwner.size() > 128 ||
module.overlayGroup.find('\0') != std::string::npos || module.overlayOwner.find('\0') != std::string::npos)
throw std::invalid_argument("Physical-code overlay modules require bounded group and owner identities together");
if (!module.overlayGroup.empty()) {
auto& owners = overlayOwners[module.overlayGroup];
if (std::find(owners.begin(), owners.end(), module.overlayOwner) == owners.end()) owners.push_back(module.overlayOwner);
}
if (module.pages.empty() || module.pages.size() > 8 || module.guards.empty() || module.guards.size() > 65536)
throw std::invalid_argument("Banked modules require physical page mappings and verified code");
std::array<bool, 8> mapped{};
@@ -1452,6 +1503,7 @@ void MachineSession::debuggerArmBankedDevelopmentBreakpoints(const std::vector<s
mapped[page.logicalPage] = true;
}
std::bitset<65536> covered;
std::vector<PhysicalSpan> physical;
for (const auto& guard : module.guards) {
if (guard.bytes.empty() || std::size_t(guard.address) + guard.bytes.size() > 0xfe00)
throw std::invalid_argument("Banked code requires nonwrapping RAM ranges below FE00");
@@ -1464,7 +1516,18 @@ void MachineSession::debuggerArmBankedDevelopmentBreakpoints(const std::vector<s
throw std::invalid_argument("Each module's code must be nonoverlapping and fully mapped to physical RAM");
covered[at] = true;
}
for (std::size_t at = guard.address, end = at + guard.bytes.size(); at < end;) {
const auto next = std::min(end, (at / 8192 + 1) * 8192);
const auto page = std::find_if(module.pages.begin(), module.pages.end(), [&](const auto& page) { return page.logicalPage == at / 8192; });
const auto start = page->physicalPage * 8192 + static_cast<std::uint32_t>(at % 8192);
physical.emplace_back(start, start + static_cast<std::uint32_t>(next - at));
at = next;
}
}
std::sort(physical.begin(), physical.end());
for (std::size_t i = 1; i < physical.size(); ++i)
if (physical[i].first < physical[i-1].second)
throw std::invalid_argument("One module's executable code must not alias its own physical RAM");
if (module.breakpointAddresses) {
if (module.breakpointAddresses->size() > 1024)
throw std::invalid_argument("Too many module-qualified source breakpoints");
@@ -1480,16 +1543,32 @@ void MachineSession::debuggerArmBankedDevelopmentBreakpoints(const std::vector<s
}
for (std::size_t i = 0; i < moduleCoverage.size(); ++i) {
const auto& previous = modules[i];
const bool declaredOverlay = !module.overlayGroup.empty() && module.overlayGroup == previous.overlayGroup && module.overlayOwner != previous.overlayOwner;
const auto& oldPhysical = physicalCoverage[i];
std::size_t currentSpan = 0, oldSpan = 0;
bool aliases = false;
while (currentSpan < physical.size() && oldSpan < oldPhysical.size()) {
if (physical[currentSpan].first < oldPhysical[oldSpan].second && oldPhysical[oldSpan].first < physical[currentSpan].second) { aliases = true; break; }
if (physical[currentSpan].second <= oldPhysical[oldSpan].first) ++currentSpan;
else ++oldSpan;
}
if (aliases && !declaredOverlay)
throw std::invalid_argument("Shared physical code requires different owners in the same declared overlay group");
const bool exclusive = std::any_of(module.pages.begin(), module.pages.end(), [&](const auto& page) {
return std::any_of(previous.pages.begin(), previous.pages.end(), [&](const auto& old) {
return page.logicalPage == old.logicalPage && page.physicalPage != old.physicalPage;
});
});
if (!exclusive && (covered & moduleCoverage[i]).any())
if (!exclusive && !declaredOverlay && (covered & moduleCoverage[i]).any())
throw std::invalid_argument("Overlapping modules must have mutually exclusive physical mappings");
}
moduleCoverage.push_back(covered);
physicalCoverage.push_back(std::move(physical));
}
if (overlayOwners.size() > 64)
throw std::invalid_argument("Physical-code overlay declarations exceed 64 groups");
for (const auto& group : overlayOwners) if (group.second.size() < 2)
throw std::invalid_argument("A physical-code overlay group requires executable modules for at least two owners");
for (auto point : breakpoints)
if (!starts[point]) throw std::invalid_argument("Each banked breakpoint must name at least one qualified module code range");
// Validate everything before touching the running machine or its points.
@@ -1687,6 +1766,7 @@ Snapshot MachineSession::snapshot() const {
}
result.debuggerMappingFingerprint = mappingFingerprint(GetMMUState());
result.debuggerBankedDevelopment = !impl->developmentModules.empty();
if (result.debuggerBankedDevelopment) result.debuggerResidencyFingerprint = impl->bankedResidency(GetMMUState()).fingerprint;
if (!result.debuggerBankedDevelopment && !impl->developmentGuards.empty() && impl->state == RunState::Paused && impl->developmentAttached &&
!impl->flatGuardsMatch()) impl->developmentAttached = false;
result.debuggerDevelopmentAttached = result.debuggerBankedDevelopment ? impl->bankedMatchesAt(impl->CpuState().PC) :
@@ -1991,13 +2071,16 @@ DebugGraphicsCapture MachineSession::debuggerGraphicsCapture(const std::optional
void MachineSession::debuggerStepSource(SourceStepMode mode, const std::vector<DebugSourceInstruction>& instructions,
std::uint64_t expectedGeneration, std::uint64_t expectedProgramRevision,
std::uint64_t expectedMappingFingerprint, std::uint16_t expectedPC,
unsigned maximumInstructions, unsigned maximumFrames) {
unsigned maximumInstructions, unsigned maximumFrames, std::uint64_t expectedResidencyFingerprint) {
if (!impl || impl->state != RunState::Paused) throw std::logic_error("Pause at a verified C source location before stepping");
if (mode != SourceStepMode::Into && mode != SourceStepMode::Over && mode != SourceStepMode::Out)
throw std::invalid_argument("Unknown C stepping mode");
if (expectedGeneration != generation || expectedProgramRevision != debuggerProgramRevision ||
expectedMappingFingerprint != mappingFingerprint(GetMMUState()) || expectedPC != impl->CpuState().PC)
throw std::invalid_argument("The paused program changed; refresh before C stepping");
const auto residency = impl->bankedResidency(GetMMUState());
if (residency.fingerprint != expectedResidencyFingerprint)
throw std::invalid_argument("The resident physical-code overlay changed; refresh before C stepping");
if (instructions.empty() || instructions.size() > 65536 || !maximumInstructions || maximumInstructions > 1000000 || !maximumFrames || maximumFrames > 600)
throw std::invalid_argument("Invalid C step locations or execution limit");
Impl::SourceStep plan;
@@ -2037,7 +2120,7 @@ void MachineSession::debuggerStepSource(SourceStepMode mode, const std::vector<D
const auto mmu = GetMMUState();
found = std::find_if(candidates.first, candidates.second, [&](const auto& item) {
return std::any_of(impl->developmentModules.begin(), impl->developmentModules.end(), [&](const auto& module) {
return module.identifier == item.second.moduleIdentifier && impl->bankedModuleMatches(module, mmu);
return module.identifier == item.second.moduleIdentifier && impl->residentModuleMatches(module, mmu, residency);
});
});
}
+6 -1
View File
@@ -49,6 +49,9 @@ struct Snapshot {
std::uint64_t debuggerProgramRevision = 0, debuggerMappingFingerprint = 0;
bool debuggerDevelopmentAttached = false, debuggerAssemblyAttached = false, debuggerSourceStepping = false;
bool debuggerBankedDevelopment = false;
// Fresh group/owner residency proof, never inferred from a physical address.
// Zero identifies declarations without physical-code overlay groups.
std::uint64_t debuggerResidencyFingerprint = 0;
bool basicDebugAttached = false;
int basicStoppedLine = -1, basicSourceOffset = -1;
unsigned basicSourceLength = 0;
@@ -75,6 +78,7 @@ struct DebugBankedModule {
// Absent preserves logical-point behavior. An explicit set qualifies only
// these stops to this module; an empty set retains source/step evidence only.
std::optional<std::vector<std::uint16_t>> breakpointAddresses = std::nullopt;
std::string overlayGroup = {}, overlayOwner = {};
};
enum class SourceStepMode { Into, Over, Out };
struct DebugSourceInstruction {
@@ -257,7 +261,8 @@ public:
void debuggerStepSource(SourceStepMode mode, const std::vector<DebugSourceInstruction>& instructions,
std::uint64_t expectedGeneration, std::uint64_t expectedProgramRevision,
std::uint64_t expectedMappingFingerprint, std::uint16_t expectedPC,
unsigned maximumInstructions = 1000000, unsigned maximumFrames = 600);
unsigned maximumInstructions = 1000000, unsigned maximumFrames = 600,
std::uint64_t expectedResidencyFingerprint = 0);
void debuggerSetPC(std::uint16_t address); // paused only, same ForcePC semantics as Windows
void debuggerSetBreakpoints(std::vector<std::uint16_t> addresses);
void debuggerConfigureBreakpoints(std::vector<std::uint16_t> enabled, std::vector<std::uint16_t> disabled);