/// <summary> /// Decode the mi results and create a bound breakpoint from it. /// </summary> /// <param name="bkpt">breakpoint description</param> /// <returns>null if breakpoint is pending</returns> private async Task <BoundBreakpoint> GetBoundBreakpoint(TupleValue bkpt) { string addrString = bkpt.TryFindString("addr"); MIBreakpointState state = StringToBreakpointState(addrString); if (state == MIBreakpointState.Multiple) { // MI gives no way to find the set of addresses a breakpoint is bound to. So bind the breakpoint to address zero until hit. // When the breakpoint is hit can rebind to actual address. bkpt.Content.RemoveAll((keyval) => { return(keyval.Name == "addr"); }); bkpt.Content.Add(new NamedResultValue("addr", new ConstValue("0"))); } else if (state == MIBreakpointState.Pending) { return(null); } else if (!string.IsNullOrEmpty(addrString) && bkpt.FindAddr("addr") == BreakpointManager.INVALID_ADDRESS) { return(null); } var bbp = new BoundBreakpoint(this, bkpt); // On GDB, the returned line information is from the pending breakpoint instead of the bound breakpoint. // Check the address mapping to make sure the line info is correct. if (this.DebuggedProcess.MICommandFactory.Mode == MIMode.Gdb && !string.IsNullOrEmpty(bbp.CompiledFileName)) { bbp.Line = await this.DebuggedProcess.LineForStartAddress(bbp.CompiledFileName, bbp.Addr); } return(bbp); }
internal async Task <uint> ReadProcessMemory(ulong address, uint count, byte[] bytes) { string cmd = "-data-read-memory-bytes " + EngineUtils.AsAddr(address) + " " + count.ToString(); Results results = await CmdAsync(cmd, ResultClass.None); if (results.ResultClass == ResultClass.error) { return(uint.MaxValue); } ValueListValue mem = results.Find <ValueListValue>("memory"); if (mem.IsEmpty()) { return(0); } TupleValue res = mem.Content[0] as TupleValue; if (res == null) { return(0); } ulong start = res.FindAddr("begin"); ulong end = res.FindAddr("end"); ulong offset = res.FindAddr("offset"); // for some reason this is formatted as hex string content = res.FindString("contents"); uint toRead = (uint)content.Length / 2; if (toRead > count) { toRead = count; } // ensure the buffer contains the desired bytes. if (start + offset != address) { throw new MIException(Constants.E_FAIL); } for (int pos = 0; pos < toRead; ++pos) { // Decode one byte string strByte = content.Substring(pos * 2, 2); bytes[pos] = Convert.ToByte(strByte, 16); } return(toRead); }
/// <summary> /// Decode the mi results and create a bound breakpoint from it. /// </summary> /// <param name="bkpt">breakpoint description</param> /// <returns>null if breakpoint is pending</returns> private BoundBreakpoint GetBoundBreakpoint(TupleValue bkpt) { string addrString = bkpt.TryFindString("addr"); MIBreakpointState state = StringToBreakpointState(addrString); if (state == MIBreakpointState.Multiple) { // MI gives no way to find the set of addresses a breakpoint is bound to. So bind the breakpoint to address zero until hit. // When the breakpoint is hit can rebind to actual address. bkpt.Content.RemoveAll((keyval) => { return(keyval.Name == "addr"); }); bkpt.Content.Add(new NamedResultValue("addr", new ConstValue("0"))); } else if (state == MIBreakpointState.Pending) { return(null); } else if (!string.IsNullOrEmpty(addrString) && bkpt.FindAddr("addr") == BreakpointManager.INVALID_ADDRESS) { return(null); } return(new BoundBreakpoint(this, bkpt)); }
/// <summary> /// Decode the mi results and create a bound breakpoint from it. /// </summary> /// <param name="bkpt">breakpoint description</param> /// <returns>null if breakpoint is pending</returns> private BoundBreakpoint GetBoundBreakpoint(TupleValue bkpt) { string addrString = bkpt.TryFindString("addr"); MIBreakpointState state = StringToBreakpointState(addrString); if (state == MIBreakpointState.Multiple) { // MI gives no way to find the set of addresses a breakpoint is bound to. So bind the breakpoint to address zero until hit. // When the breakpoint is hit can rebind to actual address. bkpt.Content.RemoveAll((keyval) => { return keyval.Name == "addr"; }); bkpt.Content.Add(new NamedResultValue("addr", new ConstValue("0"))); } else if (state == MIBreakpointState.Pending) { return null; } else if (!string.IsNullOrEmpty(addrString) && bkpt.FindAddr("addr") == BreakpointManager.INVALID_ADDRESS) { return null; } return new BoundBreakpoint(this, bkpt); }