public PacketData RemoveBreakpoint( [Argument(Separator = ',')] BreakpointType type, [Argument(Separator = ',', Encoding = ArgumentAttribute.ArgumentEncoding.HexNumber)] uint address, [Argument(Separator = ';', Encoding = ArgumentAttribute.ArgumentEncoding.HexNumber)] uint kind) { switch (type) { case BreakpointType.MemoryBreakpoint: manager.Cpu.RemoveHook(address, MemoryBreakpointHook); break; case BreakpointType.HardwareBreakpoint: manager.Cpu.RemoveHook(address, HardwareBreakpointHook); break; case BreakpointType.AccessWatchpoint: RemoveWatchpointsCoveringMemoryArea(address, kind, Access.ReadAndWrite, AccessWatchpointHook); break; case BreakpointType.ReadWatchpoint: RemoveWatchpointsCoveringMemoryArea(address, kind, Access.Read, ReadWatchpointHook); break; case BreakpointType.WriteWatchpoint: RemoveWatchpointsCoveringMemoryArea(address, kind, Access.Write, WriteWatchpointHook); break; default: Logger.LogAs(this, LogLevel.Warning, "Unsupported breakpoint type: {0}, not removing.", type); return(PacketData.ErrorReply(0)); } return(PacketData.Success); }
public PacketData Execute( [Argument(Encoding = ArgumentAttribute.ArgumentEncoding.HexNumber)] int registerNumber) { var content = new StringBuilder(); // if register exists in emulated core return current value of this if (manager.Cpu.GetRegisters().Any(x => x.Index == registerNumber)) { foreach (var b in manager.Cpu.GetRegisterUnsafe(registerNumber).GetBytes()) { content.AppendFormat("{0:x2}", b); } return(new PacketData(content.ToString())); } // if register no exists in emulated core but is defined in a feature // return a cero value with number of bytes defined in the feature var selectedRegisters = manager.Cpu.GDBFeatures.SelectMany(f => f.Registers) .Where(r => r.Number == registerNumber); if (selectedRegisters.Any()) { for (var b = 0; b < selectedRegisters.First().Size / 8; b++) { content.AppendFormat("00"); } return(new PacketData(content.ToString())); } // else return error return(PacketData.ErrorReply(1)); }
public PacketData Execute( [Argument(Separator = '=')] int registerNumber, [Argument(Encoding = ArgumentAttribute.ArgumentEncoding.HexBytesString)] uint value) { if (!manager.Cpu.GetRegisters().Contains(registerNumber)) { return(PacketData.ErrorReply(0)); } manager.Cpu.SetRegisterUnsafe(registerNumber, value); return(PacketData.Success); }
public PacketData Execute( [Argument(Encoding = ArgumentAttribute.ArgumentEncoding.HexNumber, Separator = '=')] int registerNumber, [Argument(Encoding = ArgumentAttribute.ArgumentEncoding.HexBytesString)] byte[] value) { if (!manager.Cpu.GetRegisters().Any(x => x.Index == registerNumber)) { return(PacketData.ErrorReply(0)); } manager.Cpu.SetRegisterUnsafe(registerNumber, BitConverter.ToUInt32(value, 0)); return(PacketData.Success); }
public PacketData WriteBinaryData( [Argument(Separator = ',', Encoding = ArgumentAttribute.ArgumentEncoding.HexNumber)] ulong address, [Argument(Separator = ':', Encoding = ArgumentAttribute.ArgumentEncoding.HexNumber)] uint length, [Argument(Encoding = ArgumentAttribute.ArgumentEncoding.BinaryBytes)] byte[] data) { if (data.Length != length) { Logger.LogAs(this, LogLevel.Warning, "length argument does not match the size of sent data."); return(PacketData.ErrorReply(Error.InvalidArgument)); } return(WriteData(address, data)); }
public PacketData Execute( [Argument(Encoding = ArgumentAttribute.ArgumentEncoding.HexNumber, Separator = '=')] int registerNumber, [Argument(Encoding = ArgumentAttribute.ArgumentEncoding.HexBytesString)] byte[] value) { var reg = manager.Cpu.GetRegisters().SingleOrDefault(x => x.Index == registerNumber); if (reg.Width == 0) { return(PacketData.ErrorReply(0)); } manager.Cpu.SetRegisterUnsafe(registerNumber, reg.ValueFromBytes(value)); return(PacketData.Success); }
public PacketData SendQueryXml( [Argument(Separator = ':', Encoding = ArgumentAttribute.ArgumentEncoding.String)] string command, [Argument(Separator = ':', Encoding = ArgumentAttribute.ArgumentEncoding.String)] string objectType, [Argument(Separator = ':', Encoding = ArgumentAttribute.ArgumentEncoding.String)] string operation, [Argument(Separator = ':', Encoding = ArgumentAttribute.ArgumentEncoding.String)] string annex, [Argument(Separator = ',', Encoding = ArgumentAttribute.ArgumentEncoding.HexNumber)] int offset, [Argument(Encoding = ArgumentAttribute.ArgumentEncoding.HexNumber)] int length ) { if ((objectType != "features" && objectType != "threads") || operation != "read") { return(PacketData.Empty); } if ((objectType == "features" && annex != "target.xml") || offset > length) { return(PacketData.ErrorReply()); } var xmlFile = new StringBuilder(); if (objectType == "features") { xmlFile.Append("<?xml version=\"1.0\"?>\n<!DOCTYPE feature SYSTEM \"gdb-target.dtd\">\n<target version=\"1.0\">\n"); xmlFile.Append($"<architecture>{manager.Cpu.GDBArchitecture}</architecture>\n"); foreach (var feature in manager.Cpu.GDBFeatures) { xmlFile.Append($"<feature name=\"{feature.Name}\">\n"); foreach (var register in feature.Registers) { xmlFile.Append($"<reg name=\"{register.Name}\" bitsize=\"{register.Size}\" regnum=\"{register.Number}\" type=\"{register.Type}\" group=\"{register.Group}\"/>\n"); } xmlFile.Append("</feature>\n"); } xmlFile.Append("</target>\n"); } else if (objectType == "threads") { xmlFile.Append("<?xml version=\"1.0\"?>\n<threads>\n"); foreach (var cpu in manager.ManagedCpus) { xmlFile.Append($"<thread id=\"{cpu.Key}\" core=\"{cpu.Key - 1}\" name=\"{cpu.Value.Name}\"></thread>\n"); } xmlFile.Append("</threads>\n"); } var prefix = offset + length >= xmlFile.Length ? "l" : "m"; var xmlSubstring = xmlFile.ToString().Substring(offset, Math.Min(length, xmlFile.Length - offset)); return(new PacketData(prefix + xmlSubstring)); }
public PacketData Run([Argument(Encoding = ArgumentAttribute.ArgumentEncoding.HexString)] string arg) { if (!openOcdOverlay.TryProcess(arg, out var result)) { var monitor = ObjectCreator.Instance.GetSurrogate <Monitor>(); var eater = new CommandInteractionEater(); if (!monitor.Parse(arg, eater)) { return(PacketData.ErrorReply(1)); } result = eater.GetContents(); } return((result == null) ? PacketData.Success : new PacketData(string.Join(string.Empty, Encoding.UTF8.GetBytes(result).Select(x => x.ToString("X2"))))); }
private PacketData WriteData(ulong address, byte[] data) { if (IsAccessAcrossPages(address, (ulong)data.Length)) { return(PacketData.ErrorReply()); } if (!TryTranslateAddress(address, out var translatedAddress, write: true)) { return(PacketData.ErrorReply(Error.BadAddress)); } manager.Machine.SystemBus.WriteBytes(data, translatedAddress); return(PacketData.Success); }
public PacketData Execute( [Argument(Encoding = ArgumentAttribute.ArgumentEncoding.HexNumber)] int registerNumber) { if (!manager.Cpu.GetRegisters().Any(x => x.Index == registerNumber)) { return(PacketData.ErrorReply(1)); } var content = new StringBuilder(); foreach (var b in manager.Cpu.GetRegisterUnsafe(registerNumber).GetBytes()) { content.AppendFormat("{0:x2}", b); } return(new PacketData(content.ToString())); }
private PacketData WriteData(ulong address, byte[] data) { var accesses = GetTranslatedAccesses(address, (ulong)data.Length, write: true); if (accesses == null) { return(PacketData.ErrorReply(Error.BadAddress)); } int startingIndex = 0; foreach (var access in accesses) { manager.Machine.SystemBus.WriteBytes(data, access.Address, startingIndex, (long)access.Length); startingIndex += (int)access.Length; } return(PacketData.Success); }
public PacketData InsertBreakpoint( [Argument(Separator = ',')] BreakpointType type, [Argument(Separator = ',', Encoding = ArgumentAttribute.ArgumentEncoding.HexNumber)] ulong address, [Argument(Separator = ';', Encoding = ArgumentAttribute.ArgumentEncoding.HexNumber)] uint kind) { switch (type) { case BreakpointType.MemoryBreakpoint: foreach (var cpu in manager.ManagedCpus.Values) { cpu.AddHook(address, MemoryBreakpointHook); } break; case BreakpointType.HardwareBreakpoint: foreach (var cpu in manager.ManagedCpus.Values) { cpu.AddHook(address, HardwareBreakpointHook); } break; case BreakpointType.AccessWatchpoint: AddWatchpointsCoveringMemoryArea(address, kind, Access.ReadAndWrite, AccessWatchpointHook); break; case BreakpointType.ReadWatchpoint: AddWatchpointsCoveringMemoryArea(address, kind, Access.Read, ReadWatchpointHook); break; case BreakpointType.WriteWatchpoint: AddWatchpointsCoveringMemoryArea(address, kind, Access.Write, WriteWatchpointHook); break; default: Logger.LogAs(this, LogLevel.Warning, "Unsupported breakpoint type: {0}, not inserting.", type); return(PacketData.ErrorReply()); } return(PacketData.Success); }
public PacketData Continue([Argument(Encoding = ArgumentAttribute.ArgumentEncoding.String)] string data) { if (!TryParseData(data, out var operations)) { return(PacketData.ErrorReply()); } if (manager.BlockOnStep) { if (!TryHandleBlockingExecution(ref operations)) { return(PacketData.ErrorReply()); } } foreach (var operation in operations) { ManageOperation(operation); } return(null); }
public PacketData Execute( [Argument(Separator = ',', Encoding = ArgumentAttribute.ArgumentEncoding.HexNumber)] ulong address, [Argument(Encoding = ArgumentAttribute.ArgumentEncoding.HexNumber)] ulong length) { var content = new StringBuilder(); var accesses = GetTranslatedAccesses(address, length, write: false); if (accesses == null) { return(PacketData.ErrorReply(Error.BadAddress)); } foreach (var access in accesses) { foreach (var b in manager.Machine.SystemBus.ReadBytes(access.Address, (int)access.Length)) { content.AppendFormat("{0:x2}", b); } } return(new PacketData(content.ToString())); }
public PacketData Execute( [Argument(Separator = ',', Encoding = ArgumentAttribute.ArgumentEncoding.HexNumber)] ulong address, [Argument(Encoding = ArgumentAttribute.ArgumentEncoding.HexNumber)] ulong length) { var content = new StringBuilder(); if (IsAccessAcrossPages(address, length)) { return(PacketData.ErrorReply()); } if (!TryTranslateAddress(address, out var translatedAddress, write: false)) { return(PacketData.ErrorReply(Error.BadAddress)); } foreach (var b in manager.Machine.SystemBus.ReadBytes(translatedAddress, (int)length)) { content.AppendFormat("{0:x2}", b); } return(new PacketData(content.ToString())); }
public PacketData Execute( [Argument(Encoding = ArgumentAttribute.ArgumentEncoding.HexNumber, Separator = '=')] int registerNumber, [Argument(Encoding = ArgumentAttribute.ArgumentEncoding.HexBytesString)] byte[] value) { var isLittleEndian = manager.Cpu.Endianness == Endianess.LittleEndian; var reg = manager.Cpu.GetRegisters().SingleOrDefault(x => x.Index == registerNumber); if (reg.Width == 0) { manager.Cpu.Log(LogLevel.Warning, "Writing to register #{0} failed, register doesn't exit.", registerNumber); return(PacketData.ErrorReply()); } // register may have been reported with bigger Width, try to truncate the value var width = reg.Width / 8; if (value.Length > width) { // split value into excess and proper value var excess = value.Skip(isLittleEndian ? width : 0).Take(value.Length - width); value = value.Skip(isLittleEndian ? 0 : value.Length - width).Take(width).ToArray(); // Allow excess to be filled with zeros and (for two's complement support) 0xff when msb is set. // All bytes in excess need to be the same and checked, // use sample byte to test value and check if all bytes equal to the sample. var sampleByte = excess.First(); var msb = value[isLittleEndian ? value.Length - 1 : 0] >> 7; if (!(sampleByte == 0 || (sampleByte == 0xff && msb == 1)) || excess.Any(b => b != sampleByte)) { manager.Cpu.Log(LogLevel.Warning, "Writing to register #{0} failed, sent value doesn't fit in {1} bits.", registerNumber, reg.Width); return(PacketData.ErrorReply()); } } manager.Cpu.SetRegisterUnsafe(registerNumber, reg.ValueFromBytes(value)); return(PacketData.Success); }
public PacketData Execute( [Argument(Separator = ',', Encoding = ArgumentAttribute.ArgumentEncoding.HexNumber)] ulong address, [Argument(Encoding = ArgumentAttribute.ArgumentEncoding.HexNumber)] ulong length) { var content = new StringBuilder(); var accesses = GetTranslatedAccesses(address, length, write: false); if (accesses == null) { return(PacketData.ErrorReply(Error.BadAddress)); } foreach (var access in accesses) { if (manager.Machine.SystemBus.WhatIsAt(access.Address, context: manager.Cpu) == null) { return(PacketData.ErrorReply(Error.BadAddress)); } byte[] data; try { data = manager.Machine.SystemBus.ReadBytes(access.Address, (int)access.Length, onlyMemory: true, context: manager.Cpu); } catch (RecoverableException) { return(PacketData.ErrorReply(Error.BadAddress)); } foreach (var b in data) { content.AppendFormat("{0:x2}", b); } } return(new PacketData(content.ToString())); }