From 67def76f66bf316b71bb449243c58e982a234521 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Srbeck=C3=BD?= Date: Sun, 15 Apr 2012 23:33:49 +0100 Subject: [PATCH] Removed MemoryPad and ObjectGraphPad --- .../Debugger.AddIn/Debugger.AddIn.addin | 61 ---- .../Debugger.AddIn/Debugger.AddIn.csproj | 3 - .../Pads/Commands/MemoryPadCommands.cs | 127 ------- .../Debugger/Debugger.AddIn/Pads/MemoryPad.cs | 340 ------------------ .../Debugger.AddIn/Pads/ObjectGraphPad.cs | 60 ---- .../Debugger.Core/Interop/NativeMethods.cs | 165 --------- 6 files changed, 756 deletions(-) delete mode 100644 src/AddIns/Debugger/Debugger.AddIn/Pads/Commands/MemoryPadCommands.cs delete mode 100644 src/AddIns/Debugger/Debugger.AddIn/Pads/MemoryPad.cs delete mode 100644 src/AddIns/Debugger/Debugger.AddIn/Pads/ObjectGraphPad.cs diff --git a/src/AddIns/Debugger/Debugger.AddIn/Debugger.AddIn.addin b/src/AddIns/Debugger/Debugger.AddIn/Debugger.AddIn.addin index a17ec6120e..4352c6bc17 100644 --- a/src/AddIns/Debugger/Debugger.AddIn/Debugger.AddIn.addin +++ b/src/AddIns/Debugger/Debugger.AddIn/Debugger.AddIn.addin @@ -110,26 +110,12 @@ class = "ICSharpCode.SharpDevelop.Gui.Pads.ConsolePad" defaultPosition = "Bottom, Hidden" /> - - - - - - - - - - - - - @@ -191,44 +168,6 @@ /> - - - - - - - - - - - - - diff --git a/src/AddIns/Debugger/Debugger.AddIn/Debugger.AddIn.csproj b/src/AddIns/Debugger/Debugger.AddIn/Debugger.AddIn.csproj index 7083e1132f..ee2cf64816 100644 --- a/src/AddIns/Debugger/Debugger.AddIn/Debugger.AddIn.csproj +++ b/src/AddIns/Debugger/Debugger.AddIn/Debugger.AddIn.csproj @@ -106,12 +106,10 @@ Code - - DrawSurface.xaml Code @@ -137,7 +135,6 @@ DebuggingSymbolsPanel.cs - UserControl diff --git a/src/AddIns/Debugger/Debugger.AddIn/Pads/Commands/MemoryPadCommands.cs b/src/AddIns/Debugger/Debugger.AddIn/Pads/Commands/MemoryPadCommands.cs deleted file mode 100644 index c234d50292..0000000000 --- a/src/AddIns/Debugger/Debugger.AddIn/Pads/Commands/MemoryPadCommands.cs +++ /dev/null @@ -1,127 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) -using System; -using System.Windows.Controls; -using System.Windows.Input; - -using ICSharpCode.Core; - -namespace ICSharpCode.SharpDevelop.Gui.Pads -{ - public sealed class JumpToAddressCommand : AbstractComboBoxCommand - { - MemoryPad pad; - ComboBox comboBox; - - protected override void OnOwnerChanged(EventArgs e) - { - this.pad = this.Owner as MemoryPad; - if (this.pad == null) - return; - - comboBox = this.ComboBox as ComboBox; - - if (this.comboBox == null) - return; - - comboBox.KeyUp += (s, ea) => { if (ea.Key == Key.Enter) Run(); }; - comboBox.IsEditable = true; - comboBox.Width = 130; - - base.OnOwnerChanged(e); - } - - public override void Run() - { - if (this.pad != null && this.comboBox != null) { - pad.JumpToAddress(comboBox.Text); - } - base.Run(); - } - } - - public abstract class ItemMemoryCommand : AbstractCommand - { - protected MemoryPad pad; - - protected override void OnOwnerChanged(EventArgs e) - { - this.pad = this.Owner as MemoryPad; - if (this.pad == null) - return; - - base.OnOwnerChanged(e); - } - } - - public sealed class RefreshAddressCommand : ItemMemoryCommand - { - public override void Run() - { - if (this.pad == null) - return; - - this.pad.Refresh(); - } - } - - public sealed class NextAddressCommand : ItemMemoryCommand - { - public override void Run() - { - if (this.pad == null) - return; - - this.pad.MoveToNextAddress(); - } - } - - public sealed class PreviousAddressCommand : ItemMemoryCommand - { - public override void Run() - { - if (this.pad == null) - return; - - this.pad.MoveToPreviousAddress(); - } - } - - public sealed class DisplayByteSizeCommand : AbstractComboBoxCommand - { - MemoryPad pad; - ComboBox comboBox; - - protected override void OnOwnerChanged(EventArgs e) - { - this.pad = this.Owner as MemoryPad; - if (this.pad == null) - return; - - comboBox = this.ComboBox as ComboBox; - - if (this.comboBox == null) - return; - - comboBox.SelectionChanged += (s, ea) => { Run(); }; - - comboBox.Items.Add(1); - comboBox.Items.Add(2); - comboBox.Items.Add(4); - comboBox.Text = "1"; - comboBox.Width = 30; - comboBox.IsEditable = false; - - base.OnOwnerChanged(e); - } - - public override void Run() - { - if (this.pad != null && this.comboBox != null) { - pad.DisplayByteSize = Convert.ToByte(this.comboBox.SelectedValue); - pad.DisplayMemory(); - } - base.Run(); - } - } -} diff --git a/src/AddIns/Debugger/Debugger.AddIn/Pads/MemoryPad.cs b/src/AddIns/Debugger/Debugger.AddIn/Pads/MemoryPad.cs deleted file mode 100644 index 7874d6dbd1..0000000000 --- a/src/AddIns/Debugger/Debugger.AddIn/Pads/MemoryPad.cs +++ /dev/null @@ -1,340 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Globalization; -using System.Text; -using System.Text.RegularExpressions; -using System.Windows.Controls; -using Debugger; -using Debugger.Interop; -using ICSharpCode.Core; -using ICSharpCode.Core.Presentation; -using ICSharpCode.SharpDevelop.Debugging; -using ICSharpCode.SharpDevelop.Services; - -namespace ICSharpCode.SharpDevelop.Gui.Pads -{ - public sealed class MemoryPad : AbstractPadContent - { - DockPanel panel; - ToolBar toolbar; - - int currentAddressIndex; - ConsoleControl console; - int columnsNumber = 16; - byte displayByteSize = 1; - byte[] memory; - List> memoryAddresses = new List>(); - Dictionary addressesMapping = new Dictionary(); - - public override object Control { - get { - return panel; - } - } - - public Process debuggedProcess { - get { - return WindowsDebugger.CurrentProcess; - } - } - - /// - /// Gets or sets the number of columns in the display - /// - [DefaultValue(16)] - public int ColumnsNumber { - get { return columnsNumber; } - set { - if (value != columnsNumber) { - columnsNumber = value; - } - } - } - - /// - /// Gets or sets the display byte size: 1, 2, 4 - /// - [DefaultValue(1)] - public byte DisplayByteSize { - get { return displayByteSize; } - set { - // check is value is a power of 2 between 1 and 4. - if ((value & (value - 1)) != 0) - return; - if (value < 1 || value > 4) - return; - - if (displayByteSize != value) { - displayByteSize = value; - } - } - } - - public MemoryPad() - { - this.panel = new DockPanel(); - this.toolbar = ToolBarService.CreateToolBar(panel, this, "/SharpDevelop/Pads/MemoryPad/ToolBar"); - this.toolbar.SetValue(DockPanel.DockProperty, Dock.Top); - this.panel.Children.Add(toolbar); - - this.console = new ConsoleControl(); - this.panel.Children.Add(console); - this.console.Encoding = Encoding.Default; - Refresh(); - this.console.SetReadonly(); - - DebuggerService.DebugStopped += DebuggerService_DebugStopped; - } - - void DebuggerService_DebugStopped(object sender, EventArgs e) - { - memoryAddresses.Clear(); - addressesMapping.Clear(); - memory = null; - } - - public void JumpToAddress(string address) - { - try { - if (address.StartsWith("0x")) - address = address.Substring(2); - - long addr = Int64.Parse(address, NumberStyles.AllowHexSpecifier); - - memoryAddresses = debuggedProcess.GetVirtualMemoryAddresses(); - // find index for the address or the near addess - currentAddressIndex = memoryAddresses.BinarySearch(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 - if (!Refresh()) - return; - - // find line - long mod = addr % (columnsNumber * displayByteSize); - int line; - long key = addr - mod; - //int index = addressesMapping.BinarySearch(key); - if (addressesMapping.ContainsKey(key)) - line = addressesMapping[key]; - else - line = 1; - - // jump - console.SelectText(line, 0, 8); - console.JumpToLine(line); - - } catch (System.Exception ex) { - LoggingService.Error(ex.Message); - } - } - - public bool Refresh(object sender, DebuggerEventArgs dbg) - { - return Refresh(); - } - - public bool Refresh() - { - memoryAddresses = debuggedProcess.GetVirtualMemoryAddresses(); - currentAddressIndex = 0; - - if (console == null) - return false; - - console.Clear(); - if (debuggedProcess == null || debuggedProcess.IsRunning) { - console.Append(ResourceService.GetString("MainWindow.Windows.Debug.MemoryPad.NotDebuggingOrProcessRunning")); - return false; - } - - if (currentAddressIndex <= -1) { - console.Append(ResourceService.GetString("MainWindow.Windows.Debug.MemoryPad.NoMappings")); - currentAddressIndex = -1; - return false; - } - - if (memoryAddresses.Count == 0) { - console.Append(ResourceService.GetString("MainWindow.Windows.Debug.MemoryPad.NoMappings")); - return false; - } - - if (currentAddressIndex >= memoryAddresses.Count) { - console.Append(ResourceService.GetString("MainWindow.Windows.Debug.MemoryPad.NoMappings")); - currentAddressIndex = memoryAddresses.Count ; - return false; - } - - RetrieveMemory(); - return true; - } - - void RetrieveMemory() - { - // refresh data - addressesMapping.Clear(); - - // get current address - var item = memoryAddresses[currentAddressIndex]; - long address = item.Item1; - long size = item.Item2; - - memory = debuggedProcess.ReadProcessMemory(address, size); - if (memory == null) { - console.Append(string.Format(ResourceService.GetString("MainWindow.Windows.Debug.MemoryPad.UnableToReadFormat"), address.ToString("X8"), size)); - return; - } - - DisplayMemory(); - } - - public void DisplayMemory() - { - if (memory == null || memory.Length == 0) - return; - - if (console == null) - return; - - console.Clear(); - addressesMapping.Clear(); - var item = memoryAddresses[currentAddressIndex]; - long address = item.Item1; - - int totalBytesPerRow = columnsNumber * displayByteSize; - int numberOfLines = memory.Length / totalBytesPerRow; - int remainingMemory = memory.Length % totalBytesPerRow; - int currentLine = 2;// line in the console - int index = 0;// index in memory arrray of current line - - StringBuilder sb = new StringBuilder(); - sb.Append(string.Format(ResourceService.GetString("MainWindow.Windows.Debug.MemoryPad.ReadingFromFormat"), address.ToString("X8"), (address + memory.Length).ToString("X8"), memory.Length)); - sb.Append(Environment.NewLine); - - while (index < numberOfLines) { - addressesMapping.Add(address, currentLine); - // write address - sb.Append(address.ToString("X8")); - address += (long)totalBytesPerRow; - sb.Append(" "); - - // write bytes - int start = index * totalBytesPerRow; - for (int i = 0; i < columnsNumber; ++i) { - for (int j = 0; j < displayByteSize; ++j) { - sb.Append(memory[start++].ToString("X2")); - } - sb.Append(" "); - } - - // write chars - start = index * totalBytesPerRow; - StringBuilder sb1 = new StringBuilder(); - for (int i = 0; i < totalBytesPerRow; ++i) { - sb1.Append(((char)memory[start++]).ToString()); - } - 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); - sb.Append(s); - sb.Append(Environment.NewLine); - currentLine++; - index++; - } - - // write the rest of memory - if (remainingMemory != 0) { - addressesMapping.Add(address, currentLine); - // write address - sb.Append(address.ToString("X8")); - sb.Append(" "); - - // write bytes - int start = index * remainingMemory * displayByteSize; - for (int i = 0; i < remainingMemory; ++i) { - for (int j = 0; j < displayByteSize; j++) { - sb.Append(memory[start++].ToString("X2")); - } - sb.Append(" "); - } - - // write chars - start = index * remainingMemory * displayByteSize; - StringBuilder sb1 = new StringBuilder(); - for (int i = 0; i < remainingMemory * displayByteSize; ++i) { - sb1.Append(((char)memory[start++]).ToString()); - } - 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); - sb.Append(s); - } - - console.Append(sb.ToString()); - } - - public void MoveToPreviousAddress() - { - currentAddressIndex--; - Refresh(); - } - - public void MoveToNextAddress() - { - currentAddressIndex++; - Refresh(); - } - } - - internal static class MemoryPadExtensions - { - /// - /// Does a binary search when the Item1 from Tuple is sorted. - /// - /// Source of data. - /// Item to search. - /// The nearest index. - internal static int BinarySearch(this List> source, long item1) - { - // base checks - if (source == null) - throw new NullReferenceException("Source is null!"); - - if (source.Count == 0) - return -1; - - if (item1 < source[0].Item1) - return 0; - - if (item1 > source[source.Count - 1].Item1) - return source.Count; - - // do a binary search since the source is sorted - int first = 0; int last = source.Count; - while (first < last - 1) { - int middle = (first + last) / 2; - if (source[middle].Item1 == item1) - return middle; - else - if (source[middle].Item1 < item1) - first = middle; - else - last = middle; - } - - return first; - } - } -} diff --git a/src/AddIns/Debugger/Debugger.AddIn/Pads/ObjectGraphPad.cs b/src/AddIns/Debugger/Debugger.AddIn/Pads/ObjectGraphPad.cs deleted file mode 100644 index f2cdf0cd0d..0000000000 --- a/src/AddIns/Debugger/Debugger.AddIn/Pads/ObjectGraphPad.cs +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the BSD license (for details please see \src\AddIns\Debugger\Debugger.AddIn\license.txt) - -using System.Windows.Controls; -using ICSharpCode.Core; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Windows; -using Debugger; -using Debugger.AddIn.Visualizers.Graph; -using ICSharpCode.SharpDevelop.Services; - -namespace ICSharpCode.SharpDevelop.Gui.Pads -{ - /// - /// Description of ObjectGraphPad. - /// - public class ObjectGraphPad : AbstractPadContent - { - DockPanel panel; - ObjectGraphControl objectGraphControl; - static ObjectGraphPad instance; - - public override object Control { - get { return panel; } - } - - public ObjectGraphPad() - { - this.panel = new DockPanel(); - instance = this; - - objectGraphControl = new ObjectGraphControl(); - panel.Children.Add(objectGraphControl); - - WindowsDebugger.RefreshingPads += RefreshPad; - RefreshPad(); - } - - /// Always check if Instance is null, might be null if pad is not opened! - public static ObjectGraphPad Instance { - get { return instance; } - } - - void RefreshPad() - { - // BUG: if pad window is undocked and floats standalone, IsVisible == false (so pad won't refresh) - // REQUEST: need to refresh when pad becomes visible -> VisibleChanged event? - if (!objectGraphControl.IsVisible) { - return; - } - if (WindowsDebugger.CurrentStackFrame == null) { - this.objectGraphControl.Clear(); - } else { - this.objectGraphControl.RefreshView(); - } - } - } -} diff --git a/src/AddIns/Debugger/Debugger.Core/Interop/NativeMethods.cs b/src/AddIns/Debugger/Debugger.Core/Interop/NativeMethods.cs index 5c9e6c2d8d..54b585701d 100644 --- a/src/AddIns/Debugger/Debugger.Core/Interop/NativeMethods.cs +++ b/src/AddIns/Debugger/Debugger.Core/Interop/NativeMethods.cs @@ -12,89 +12,6 @@ using Debugger.Interop.CorDebug; namespace Debugger.Interop { - [StructLayout(LayoutKind.Sequential)] - public struct MEMORY_BASIC_INFORMATION - { - public IntPtr BaseAddress; - public IntPtr AllocationBase; - public uint AllocationProtect; - public IntPtr RegionSize; - public uint State; - public uint Protect; - public uint Type; - } - - [Flags] - public enum ProcessAccessFlags : uint - { - All = 0x001F0FFF, - Terminate = 0x00000001, - CreateThread = 0x00000002, - VMOperation = 0x00000008, - VMRead = 0x00000010, - VMWrite = 0x00000020, - DupHandle = 0x00000040, - SetInformation = 0x00000200, - QueryInformation = 0x00000400, - Synchronize = 0x00100000 - } - - [StructLayout(LayoutKind.Sequential)] - public struct SYSTEM_INFO - { - internal _PROCESSOR_INFO_UNION uProcessorInfo; - public uint dwPageSize; - public IntPtr lpMinimumApplicationAddress; - public IntPtr lpMaximumApplicationAddress; - public IntPtr dwActiveProcessorMask; - public uint dwNumberOfProcessors; - public uint dwProcessorType; - public uint dwAllocationGranularity; - public ushort dwProcessorLevel; - public ushort dwProcessorRevision; - } - - [StructLayout(LayoutKind.Explicit)] - public struct _PROCESSOR_INFO_UNION - { - [FieldOffset(0)] - internal uint dwOemId; - [FieldOffset(0)] - internal ushort wProcessorArchitecture; - [FieldOffset(2)] - internal ushort wReserved; - } - - [Flags] - public enum AllocationType - { - Commit = 0x1000, - Reserve = 0x2000, - Decommit = 0x4000, - Release = 0x8000, - Reset = 0x80000, - Physical = 0x400000, - TopDown = 0x100000, - WriteWatch = 0x200000, - LargePages = 0x20000000 - } - - [Flags] - public enum MemoryProtection - { - Execute = 0x10, - ExecuteRead = 0x20, - ExecuteReadWrite = 0x40, - ExecuteWriteCopy = 0x80, - NoAccess = 0x01, - ReadOnly = 0x02, - ReadWrite = 0x04, - WriteCopy = 0x08, - GuardModifierflag = 0x100, - NoCacheModifierflag = 0x200, - WriteCombineModifierflag = 0x400 - } - public static class NativeMethods { [DllImport("kernel32.dll", SetLastError = true)] @@ -108,88 +25,6 @@ namespace Debugger.Interop [DllImport("mscoree.dll", CharSet=CharSet.Unicode)] public static extern int GetRequestedRuntimeVersion(string exeFilename, [Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pVersion, Int32 cchBuffer, out Int32 dwLength); - - [DllImport("kernel32.dll", SetLastError = true)] - public static extern IntPtr OpenProcess(ProcessAccessFlags dwDesiredAccess, [MarshalAs(UnmanagedType.Bool)] bool bInheritHandle, int dwProcessId); - - [DllImport("kernel32.dll", SetLastError = true)] - public static extern bool VirtualQueryEx(IntPtr hProcess, - IntPtr lpAddress, - out MEMORY_BASIC_INFORMATION lpBuffer, - uint dwLength); - - [DllImport("kernel32.dll", SetLastError = true)] - public static extern bool VirtualProtectEx(IntPtr hProcess, IntPtr lpAddress, - UIntPtr dwSize, uint flNewProtect, out uint lpflOldProtect); - - [DllImport("kernel32.dll", SetLastError = true)] - public static extern bool ReadProcessMemory( - IntPtr hProcess, - IntPtr lpBaseAddress, - [Out] byte[] lpBuffer, - int dwSize, - out int lpNumberOfBytesRead - ); - - [DllImport("kernel32.dll", SetLastError = true)] - public static extern void GetSystemInfo(out SYSTEM_INFO lpSystemInfo); - - public static List> GetVirtualMemoryAddresses(this Process process) - { - var result = new List>(); - SYSTEM_INFO sysinfo = new SYSTEM_INFO(); - GetSystemInfo(out sysinfo); - - long address = 0; - MEMORY_BASIC_INFORMATION m = new MEMORY_BASIC_INFORMATION(); - IntPtr openedProcess = IntPtr.Zero; - try { - openedProcess = OpenProcess(ProcessAccessFlags.All, false, (int)process.Id); - - while (address < sysinfo.lpMaximumApplicationAddress.ToInt64()) - { - try { - if (!VirtualQueryEx(openedProcess, new IntPtr(address), out m, (uint)Marshal.SizeOf(m))) - continue; - } finally { - // next address - address = m.BaseAddress.ToInt64() + m.RegionSize.ToInt64(); - } - - result.Add(new Tuple(m.BaseAddress.ToInt64(), m.RegionSize.ToInt64())); - } - } finally { - if (openedProcess != IntPtr.Zero) - CloseHandle(openedProcess); - } - - return result; - } - - public static byte[] ReadProcessMemory(this Process process, long startAddress, long size) - { - IntPtr openedProcess = IntPtr.Zero; - byte[] temp = null; - try { - temp = new byte[size]; - openedProcess = OpenProcess(ProcessAccessFlags.All, false, (int)process.Id); - - int outSize; - bool success = ReadProcessMemory(openedProcess, new IntPtr(startAddress), temp, temp.Length, out outSize); - - if (!success || outSize == 0) { - var proc = System.Diagnostics.Process.GetProcessById((int)process.Id); - return process.ReadProcessMemory(proc.MainModule.BaseAddress.ToInt64(), (long)4096); - } - } catch { - return null; - } finally { - if (openedProcess != IntPtr.Zero) - CloseHandle(openedProcess); - } - - return temp; - } } }