private static bool GetInternalSRAM(ITarget2 target, out IAddressSpace addressSpace, out IMemorySegment memorySegment) { addressSpace = null; memorySegment = null; if (target.Device.Architecture.StartsWith("AVR8") == false) { return(false); } foreach (IAddressSpace mem in target.Device.AddressSpaces) { foreach (IMemorySegment seg in mem.MemorySegments) { if (seg.Type.IndexOf("RAM", StringComparison.OrdinalIgnoreCase) < 0) { continue; } if ((seg.Name.IndexOf("IRAM", StringComparison.OrdinalIgnoreCase) >= 0) || (seg.Name.IndexOf("INTERNAL_SRAM", StringComparison.OrdinalIgnoreCase) >= 0)) { addressSpace = mem; memorySegment = seg; return(true); } } } return(false); }
public void ReadData_UseRealObject_ThrowException() { var db = new FakeDatabase(); _target2 = new Target2(db); Assert.Throws <NotImplementedException>(() => _target2.GetData()); }
public static bool GetStackUsage(ITarget2 target, out ulong current, out ulong max) { current = 0; max = 0; IAddressSpace ramAddressSpace; IMemorySegment ramSegment; if (GetInternalSRAM(target, out ramAddressSpace, out ramSegment) == false) { return(false); } ulong?start = null; ulong?end = null; try { MemoryErrorRange[] errorRange; byte[] result = target.GetMemory( target.GetAddressSpaceName(ramAddressSpace.Name), ramSegment.Start, 1, (int)ramSegment.Size, 0, out errorRange); for (ulong i = 0; i < (ulong)(result.Length - 3); i += 4) { if ((result[i + 0] == STACK_INSTRUMENT_PATTERN[0]) && (result[i + 1] == STACK_INSTRUMENT_PATTERN[1]) && (result[i + 2] == STACK_INSTRUMENT_PATTERN[2]) && (result[i + 3] == STACK_INSTRUMENT_PATTERN[3])) { if (end.HasValue == false) { end = i; } } else if (end.HasValue) { start = i; break; } } } catch { } current = ramSegment.Size - (start ?? 0); max = ramSegment.Size - (end ?? 0); return(true); }
void UpdateStackUsageInfo() { ITarget2 target = mTargetService.GetLaunchedTarget(); if (target == null) { return; } Dispatcher.Invoke(new Action( () => { stackUsageProgress.IsIndeterminate = true; deviceName.Text = target.Device.Name; deviceName.FontStyle = FontStyles.Normal; stackUsageVal.Text = "(Calculating...)"; })); ulong currentUsage, maxUsage; if (StackUsageCalculator.GetStackUsage(target, out currentUsage, out maxUsage)) { Dispatcher.Invoke(new Action( () => { stackUsageProgress.Maximum = maxUsage; stackUsageProgress.Value = currentUsage; stackUsageProgress.IsIndeterminate = false; stackUsageVal.FontStyle = FontStyles.Normal; stackUsageVal.Text = string.Format("{0}/{1} ({2}%)", stackUsageProgress.Value.ToString(), stackUsageProgress.Maximum.ToString(), Math.Min(100, Math.Ceiling((100.0 * stackUsageProgress.Value) / stackUsageProgress.Maximum))); })); } else { Dispatcher.Invoke(new Action( () => { stackUsageProgress.IsIndeterminate = false; stackUsageVal.Text = "(Unsupported Device)"; })); } }
public void TearDown() { _target2 = null; _fakeDatabase = null; }
public void Setup() { _fakeDatabase = Substitute.For <IFakeDatabase>(); _target2 = new Target2(_fakeDatabase); }