offsetOf method

PCOffset? offsetOf(
  1. int address
)

The PCOffset for the given absolute program counter address.

Implementation

PCOffset? offsetOf(int address) {
  if (_isolateStart == null || _vmStart == null) return null;
  var vmOffset = address - _vmStart!;
  var unitOffset = address - _isolateStart!;
  var unitBuildId = _buildId;
  var unitId = constants.rootLoadingUnitId;
  if (units != null) {
    for (final unit in units!.values) {
      final newOffset = address - unit.start;
      if (newOffset == _closestOffset(unitOffset, newOffset)) {
        unitOffset = newOffset;
        unitBuildId = unit.buildId;
        unitId = unit.id;
      }
    }
  }
  if (unitOffset == _closestOffset(vmOffset, unitOffset)) {
    return PCOffset(unitOffset, InstructionsSection.isolate,
        os: _os,
        architecture: _arch,
        compressedPointers: _compressed,
        usingSimulator: _simulated,
        buildId: unitBuildId,
        unitId: unitId);
  }
  // The VM section is always stored in the root loading unit.
  return PCOffset(vmOffset, InstructionsSection.vm,
      os: _os,
      architecture: _arch,
      compressedPointers: _compressed,
      usingSimulator: _simulated,
      buildId: _buildId,
      unitId: constants.rootLoadingUnitId);
}