|
|
|
@ -18,11 +18,13 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
@@ -18,11 +18,13 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
|
|
|
|
|
{ |
|
|
|
|
public sealed class MemoryPad : DebuggerPad |
|
|
|
|
{ |
|
|
|
|
Dictionary<long, int> addressesMapping = new Dictionary<long, int>(); |
|
|
|
|
int currentAddressIndex; |
|
|
|
|
ConsoleControl console; |
|
|
|
|
int addressStep = 16; |
|
|
|
|
|
|
|
|
|
Process debuggedProcess; |
|
|
|
|
List<Tuple<long, long>> memoryAddresses = new List<Tuple<long, long>>(); |
|
|
|
|
Dictionary<long, int> addressesMapping = new Dictionary<long, int>(); |
|
|
|
|
|
|
|
|
|
public MemoryPad() |
|
|
|
|
{ |
|
|
|
@ -40,13 +42,12 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
@@ -40,13 +42,12 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
|
|
|
|
|
|
|
|
|
|
protected override void SelectProcess(Process process) |
|
|
|
|
{ |
|
|
|
|
if (debuggedProcess != null) { |
|
|
|
|
debuggedProcess.Paused -= OnProcessPaused; |
|
|
|
|
} |
|
|
|
|
if (process == null) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
debuggedProcess = process; |
|
|
|
|
if (debuggedProcess != null) { |
|
|
|
|
debuggedProcess.Paused += OnProcessPaused; |
|
|
|
|
} |
|
|
|
|
memoryAddresses = debuggedProcess.GetMemoryAddresses(); |
|
|
|
|
currentAddressIndex = 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public override void RefreshPad() |
|
|
|
@ -62,16 +63,33 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
@@ -62,16 +63,33 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
|
|
|
|
|
address = address.Substring(2); |
|
|
|
|
|
|
|
|
|
long addr = Int64.Parse(address, NumberStyles.AllowHexSpecifier); |
|
|
|
|
long mod = addr % addressStep; |
|
|
|
|
|
|
|
|
|
// find index for the address or the near addess
|
|
|
|
|
currentAddressIndex = memoryAddresses.Search(addr); |
|
|
|
|
if (currentAddressIndex == -1) { |
|
|
|
|
MessageService.ShowMessage( |
|
|
|
|
string.Format(ResourceService.GetString("MainWindow.Windows.Debug.MemoryPad.AddressNotFound"), address), |
|
|
|
|
ResourceService.GetString("MainWindow.Windows.Debug.MemoryPad")); |
|
|
|
|
|
|
|
|
|
currentAddressIndex = 0; |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// refresh pad
|
|
|
|
|
Refresh(); |
|
|
|
|
|
|
|
|
|
// find line
|
|
|
|
|
long mod = addr % addressStep; |
|
|
|
|
int line; |
|
|
|
|
if (addressesMapping.ContainsKey(addr - mod)) |
|
|
|
|
line = addressesMapping[addr - mod]; |
|
|
|
|
else |
|
|
|
|
line = 1; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// jump
|
|
|
|
|
console.SelectText(line, 0, 8); |
|
|
|
|
console.JumpToLine(line); |
|
|
|
|
|
|
|
|
|
} catch (System.Exception ex) { |
|
|
|
|
#if DEBUG
|
|
|
|
|
LoggingService.Error(ex.Message); |
|
|
|
@ -79,34 +97,33 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
@@ -79,34 +97,33 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void Refresh(bool force = false) |
|
|
|
|
public void Refresh() |
|
|
|
|
{ |
|
|
|
|
if (debuggedProcess == null || debugger.IsProcessRunning) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
if (!force && addressesMapping.Count > 0) |
|
|
|
|
if (memoryAddresses.Count == 0) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
if (force) { |
|
|
|
|
addressesMapping.Clear(); |
|
|
|
|
console.Clear(); |
|
|
|
|
} |
|
|
|
|
console.Clear();addressesMapping.Clear(); |
|
|
|
|
|
|
|
|
|
long address; |
|
|
|
|
byte[] memory = debuggedProcess.ReadProcessMemory(out address); |
|
|
|
|
// get current address
|
|
|
|
|
var item = memoryAddresses[currentAddressIndex]; |
|
|
|
|
long address = item.Item1; |
|
|
|
|
long size = item.Item2; |
|
|
|
|
|
|
|
|
|
if (memory == null) |
|
|
|
|
return; |
|
|
|
|
byte[] memory = debuggedProcess.ReadProcessMemory(address, size); |
|
|
|
|
System.Diagnostics.Debug.Assert(memory != null); |
|
|
|
|
|
|
|
|
|
int index = 0; |
|
|
|
|
int div = memory.Length / addressStep; |
|
|
|
|
int mod = memory.Length % addressStep; |
|
|
|
|
int index = 0; |
|
|
|
|
|
|
|
|
|
while (index < div) { |
|
|
|
|
StringBuilder sb = new StringBuilder(); |
|
|
|
|
addressesMapping.Add(address, index + 1); |
|
|
|
|
// write address
|
|
|
|
|
sb.Append(address.ToString("X8"));address += addressStep; |
|
|
|
|
sb.Append(address.ToString("X8")); address += (long)addressStep; |
|
|
|
|
sb.Append(" "); |
|
|
|
|
|
|
|
|
|
// write bytes
|
|
|
|
@ -121,13 +138,12 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
@@ -121,13 +138,12 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
|
|
|
|
|
string s = sb1.ToString(); |
|
|
|
|
s = Regex.Replace(s, @"\r\n", string.Empty); |
|
|
|
|
s = Regex.Replace(s, @"\n", string.Empty); |
|
|
|
|
s = Regex.Replace(s, @"\r", string.Empty); |
|
|
|
|
s = Regex.Replace(s, @"\r", string.Empty); |
|
|
|
|
sb.Append(s); |
|
|
|
|
sb.Append(Environment.NewLine); |
|
|
|
|
|
|
|
|
|
// start writing in console
|
|
|
|
|
console.Append(sb.ToString()); |
|
|
|
|
|
|
|
|
|
index++; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -151,7 +167,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
@@ -151,7 +167,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
|
|
|
|
|
string s = sb1.ToString(); |
|
|
|
|
s = Regex.Replace(s, @"\r\n", string.Empty); |
|
|
|
|
s = Regex.Replace(s, @"\n", string.Empty); |
|
|
|
|
s = Regex.Replace(s, @"\r", string.Empty); |
|
|
|
|
s = Regex.Replace(s, @"\r", string.Empty); |
|
|
|
|
sb.Append(s); |
|
|
|
|
|
|
|
|
|
sb.Append(Environment.NewLine); |
|
|
|
@ -161,9 +177,46 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
@@ -161,9 +177,46 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void OnProcessPaused(object sender, ProcessEventArgs e) |
|
|
|
|
public void MoveToPreviousAddress() |
|
|
|
|
{ |
|
|
|
|
if (debuggedProcess == null || debugger.IsProcessRunning) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
if (currentAddressIndex == 0) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
currentAddressIndex--; |
|
|
|
|
Refresh(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void MoveToNextAddress() |
|
|
|
|
{ |
|
|
|
|
if (debuggedProcess == null || debugger.IsProcessRunning) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
if (currentAddressIndex == memoryAddresses.Count) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
currentAddressIndex++; |
|
|
|
|
Refresh(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
internal static class MemoryPadExtensions |
|
|
|
|
{ |
|
|
|
|
internal static int Search(this List<Tuple<long, long>> source, long item1) |
|
|
|
|
{ |
|
|
|
|
if (source == null) |
|
|
|
|
throw new NullReferenceException("Source is null!"); |
|
|
|
|
|
|
|
|
|
for (int i = 0; i < source.Count - 1; i++) { |
|
|
|
|
if (source[i + 1].Item1 < item1) |
|
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
return i; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|