From bd82fa423801c4a12bfce184845beffec4802cea Mon Sep 17 00:00:00 2001 From: mterwoord_cp <7cd3fd84a0151ea055c2f79e4d2eef9576fe9afesxUZAwxD> Date: Fri, 11 Mar 2011 13:23:06 +0000 Subject: [PATCH] --- .../Debug/Cosmos.Debug.Common/DebugInfo.cs | 2 +- .../AD7.Impl/AD7Property.cs | 217 +++++++++--------- .../Cosmos.System.Plugs.System.csproj | 1 + .../DictionaryImpl.cs | 23 ++ .../IO/FileStreamImpl.cs | 7 +- .../Cosmos.System.Plugs.System/TypeImpl.cs | 7 + .../Core/Cosmos.Core.Plugs/StringImpl.cs | 6 + .../Matthijs/MatthijsPlayground/Kernel.cs | 32 ++- .../MatthijsPlaygroundBoot.Cosmos | 2 +- 9 files changed, 181 insertions(+), 116 deletions(-) create mode 100644 source2/Kernel/System/Cosmos.System.Plugs.System/DictionaryImpl.cs diff --git a/source2/Debug/Cosmos.Debug.Common/DebugInfo.cs b/source2/Debug/Cosmos.Debug.Common/DebugInfo.cs index 8e7bcf098..55af2a462 100644 --- a/source2/Debug/Cosmos.Debug.Common/DebugInfo.cs +++ b/source2/Debug/Cosmos.Debug.Common/DebugInfo.cs @@ -173,7 +173,7 @@ namespace Cosmos.Debug.Common + ", INDEXINMETHOD INT NOT NULL" + ", OFFSET INT NOT NULL" + ", NAME VARCHAR(255) NOT NULL" - + ", TYPENAME VARCHAR(255) NOT NULL" + + ", TYPENAME VARCHAR(4000) NOT NULL" + ");" ); diff --git a/source2/Debug/Cosmos.Debug.VSDebugEngine/AD7.Impl/AD7Property.cs b/source2/Debug/Cosmos.Debug.VSDebugEngine/AD7.Impl/AD7Property.cs index 9b4e963a9..70c9271e4 100644 --- a/source2/Debug/Cosmos.Debug.VSDebugEngine/AD7.Impl/AD7Property.cs +++ b/source2/Debug/Cosmos.Debug.VSDebugEngine/AD7.Impl/AD7Property.cs @@ -62,115 +62,116 @@ namespace Cosmos.Debug.VSDebugEngine if (dwFields.HasFlag(enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_VALUE)) { byte[] xData; - xData = mProcess.mDbgConnector.GetStackData(mDebugInfo.Offset, 4); - propertyInfo.bstrValue = xData.Aggregate("", (r, b) => r + " " + b.ToString("X2").ToUpper()); - //if (mDebugInfo.Type == typeof(string).AssemblyQualifiedName) - //{ - // #region string support - // const uint xStringLengthOffset = 16; - // const uint xStringFirstCharPtrOffset = 20; - // xData = mProcess.mDbgConnector.GetStackData(mDebugInfo.Offset, 4); - // uint xStrPointer = BitConverter.ToUInt32(xData, 0); - // if (xStrPointer == 0) - // { - // propertyInfo.bstrValue = "(null)"; - // } - // else - // { - // xData = mProcess.mDbgConnector.GetMemoryData(xStrPointer + xStringLengthOffset, 4, 4); - // uint xStringLength = BitConverter.ToUInt32(xData, 0); - // if (xStringLength > 100) - // { - // propertyInfo.bstrValue = "For now, strings larger than 100 chars are not supported.."; - // } else if (xStringLength == 0) { - // propertyInfo.bstrValue = "\"\""; - // }else - // { - // xData = mProcess.mDbgConnector.GetMemoryData(xStrPointer + xStringFirstCharPtrOffset, 4, 4); - // uint xFirstCharPtr = BitConverter.ToUInt32(xData, 0); - // xData = mProcess.mDbgConnector.GetMemoryData(xFirstCharPtr, xStringLength * 2, 2); - // propertyInfo.bstrValue = "\"" + Encoding.Unicode.GetString(xData) + "\""; - // } - // } - // #endregion string support - //} - //else if (mDebugInfo.Type == typeof(byte[]).AssemblyQualifiedName) - //{ - // const uint xArrayLengthOffset = 8; - // const uint xArrayFirstElementOffset = 16; - // xData = mProcess.mDbgConnector.GetStackData(mDebugInfo.Offset, 4); - // uint xArrayPointer = BitConverter.ToUInt32(xData, 0); - // if (xArrayPointer == 0) - // { - // propertyInfo.bstrValue = "(null)"; - // } - // else - // { - // xData = mProcess.mDbgConnector.GetMemoryData(xArrayPointer + xArrayLengthOffset, 4, 4); - // uint xDataLength = BitConverter.ToUInt32(xData, 0); - // bool xIsTooLong = xDataLength > 512; - // var xSB = new StringBuilder(); - // xSB.AppendFormat("Byte[{0}] at 0x{1} {{ ", xDataLength, xArrayPointer.ToString("X")); - // if (xIsTooLong) - // { - // xDataLength = 512; - // } - // xData = mProcess.mDbgConnector.GetMemoryData(xArrayPointer + xArrayFirstElementOffset, xDataLength); - // for (int i = 0; i < xData.Length; i++) - // { - // xSB.Append(xData[i].ToString("X2").ToUpper()); - // if (i < (xData.Length - 1)) - // { - // xSB.Append(" "); - // } - // } - // if (xIsTooLong) - // { - // xSB.Append(", .."); - // } + if (mDebugInfo.Type == typeof(string).AssemblyQualifiedName) + { + #region string support + const uint xStringLengthOffset = 16; + const uint xStringFirstCharPtrOffset = 20; + xData = mProcess.mDbgConnector.GetStackData(mDebugInfo.Offset, 4); + uint xStrPointer = BitConverter.ToUInt32(xData, 0); + if (xStrPointer == 0) + { + propertyInfo.bstrValue = "(null)"; + } + else + { + xData = mProcess.mDbgConnector.GetMemoryData(xStrPointer + xStringLengthOffset, 4, 4); + uint xStringLength = BitConverter.ToUInt32(xData, 0); + if (xStringLength > 100) + { + propertyInfo.bstrValue = "For now, strings larger than 100 chars are not supported.."; + } + else if (xStringLength == 0) + { + propertyInfo.bstrValue = "\"\""; + } + else + { + xData = mProcess.mDbgConnector.GetMemoryData(xStrPointer + xStringFirstCharPtrOffset, 4, 4); + uint xFirstCharPtr = BitConverter.ToUInt32(xData, 0); + xData = mProcess.mDbgConnector.GetMemoryData(xFirstCharPtr, xStringLength * 2, 2); + propertyInfo.bstrValue = "\"" + Encoding.Unicode.GetString(xData) + "\""; + } + } + #endregion string support + } + else if (mDebugInfo.Type == typeof(byte[]).AssemblyQualifiedName) + { + const uint xArrayLengthOffset = 8; + const uint xArrayFirstElementOffset = 16; + xData = mProcess.mDbgConnector.GetStackData(mDebugInfo.Offset, 4); + uint xArrayPointer = BitConverter.ToUInt32(xData, 0); + if (xArrayPointer == 0) + { + propertyInfo.bstrValue = "(null)"; + } + else + { + xData = mProcess.mDbgConnector.GetMemoryData(xArrayPointer + xArrayLengthOffset, 4, 4); + uint xDataLength = BitConverter.ToUInt32(xData, 0); + bool xIsTooLong = xDataLength > 512; + var xSB = new StringBuilder(); + xSB.AppendFormat("Byte[{0}] at 0x{1} {{ ", xDataLength, xArrayPointer.ToString("X")); + if (xIsTooLong) + { + xDataLength = 512; + } + xData = mProcess.mDbgConnector.GetMemoryData(xArrayPointer + xArrayFirstElementOffset, xDataLength); + for (int i = 0; i < xData.Length; i++) + { + xSB.Append(xData[i].ToString("X2").ToUpper()); + if (i < (xData.Length - 1)) + { + xSB.Append(" "); + } + } + if (xIsTooLong) + { + xSB.Append(", .."); + } - // xSB.Append(" }"); - // propertyInfo.bstrValue = xSB.ToString(); - // } - //} - //else if (mDebugInfo.Type == typeof(char).AssemblyQualifiedName) - //{ - // xData = mProcess.mDbgConnector.GetStackData(mDebugInfo.Offset, 2); - // var xTypedCharValue = BitConverter.ToChar(xData, 0); - // propertyInfo.bstrValue = String.Format("{0} '{1}'", (ushort)xTypedCharValue, xTypedCharValue); - //} - //else if (mDebugInfo.Type == typeof(int).AssemblyQualifiedName) - //{ - // xData = mProcess.mDbgConnector.GetStackData(mDebugInfo.Offset, 4); - // var xTypedIntValue = BitConverter.ToInt32(xData, 0); - // propertyInfo.bstrValue = String.Format("{0} (0x{1})", xTypedIntValue, xTypedIntValue.ToString("X").ToUpper()); - //} - //else if (mDebugInfo.Type == typeof(long).AssemblyQualifiedName) - //{ - // xData = mProcess.mDbgConnector.GetStackData(mDebugInfo.Offset, 8); - // if (xData.Length != 8) - // { - // throw new Exception("Length should have been 8, but is " + xData.Length); - // } - // var xTypedLongValue = BitConverter.ToInt64(xData, 0); - // propertyInfo.bstrValue = String.Format("{0} (0x{1})", xTypedLongValue, xTypedLongValue.ToString("X").ToUpper()); - //} - //else if (mDebugInfo.Type == typeof(ulong).AssemblyQualifiedName) - //{ - // xData = mProcess.mDbgConnector.GetStackData(mDebugInfo.Offset, 8); - // if (xData.Length != 8) - // { - // throw new Exception("Length should have been 8, but is " + xData.Length); - // } - // var xTypedULongValue = BitConverter.ToUInt64(xData, 0); - // propertyInfo.bstrValue = String.Format("{0} (0x{1})", xTypedULongValue, xTypedULongValue.ToString("X").ToUpper()); - //} - //else - //{ - // xData = mProcess.mDbgConnector.GetStackData(mDebugInfo.Offset, 4); - // var xTypedUIntValue = BitConverter.ToUInt32(xData, 0); - // propertyInfo.bstrValue = String.Format("{0} (0x{1})", xTypedUIntValue, xTypedUIntValue.ToString("X").ToUpper()); - //} + xSB.Append(" }"); + propertyInfo.bstrValue = xSB.ToString(); + } + } + else if (mDebugInfo.Type == typeof(char).AssemblyQualifiedName) + { + xData = mProcess.mDbgConnector.GetStackData(mDebugInfo.Offset, 2); + var xTypedCharValue = BitConverter.ToChar(xData, 0); + propertyInfo.bstrValue = String.Format("{0} '{1}'", (ushort)xTypedCharValue, xTypedCharValue); + } + else if (mDebugInfo.Type == typeof(int).AssemblyQualifiedName) + { + xData = mProcess.mDbgConnector.GetStackData(mDebugInfo.Offset, 4); + var xTypedIntValue = BitConverter.ToInt32(xData, 0); + propertyInfo.bstrValue = String.Format("{0} (0x{1})", xTypedIntValue, xTypedIntValue.ToString("X").ToUpper()); + } + else if (mDebugInfo.Type == typeof(long).AssemblyQualifiedName) + { + xData = mProcess.mDbgConnector.GetStackData(mDebugInfo.Offset, 8); + if (xData.Length != 8) + { + throw new Exception("Length should have been 8, but is " + xData.Length); + } + var xTypedLongValue = BitConverter.ToInt64(xData, 0); + propertyInfo.bstrValue = String.Format("{0} (0x{1})", xTypedLongValue, xTypedLongValue.ToString("X").ToUpper()); + } + else if (mDebugInfo.Type == typeof(ulong).AssemblyQualifiedName) + { + xData = mProcess.mDbgConnector.GetStackData(mDebugInfo.Offset, 8); + if (xData.Length != 8) + { + throw new Exception("Length should have been 8, but is " + xData.Length); + } + var xTypedULongValue = BitConverter.ToUInt64(xData, 0); + propertyInfo.bstrValue = String.Format("{0} (0x{1})", xTypedULongValue, xTypedULongValue.ToString("X").ToUpper()); + } + else + { + xData = mProcess.mDbgConnector.GetStackData(mDebugInfo.Offset, 4); + var xTypedUIntValue = BitConverter.ToUInt32(xData, 0); + propertyInfo.bstrValue = String.Format("{0} (0x{1})", xTypedUIntValue, xTypedUIntValue.ToString("X").ToUpper()); + } propertyInfo.dwFields |= enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_VALUE; } diff --git a/source2/Kernel/System/Cosmos.System.Plugs.System/Cosmos.System.Plugs.System.csproj b/source2/Kernel/System/Cosmos.System.Plugs.System/Cosmos.System.Plugs.System.csproj index 4b27131e3..3a940d0a5 100644 --- a/source2/Kernel/System/Cosmos.System.Plugs.System/Cosmos.System.Plugs.System.csproj +++ b/source2/Kernel/System/Cosmos.System.Plugs.System/Cosmos.System.Plugs.System.csproj @@ -67,6 +67,7 @@ + diff --git a/source2/Kernel/System/Cosmos.System.Plugs.System/DictionaryImpl.cs b/source2/Kernel/System/Cosmos.System.Plugs.System/DictionaryImpl.cs new file mode 100644 index 000000000..30b583b6c --- /dev/null +++ b/source2/Kernel/System/Cosmos.System.Plugs.System/DictionaryImpl.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Cosmos.IL2CPU.Plugs; + +namespace Cosmos.System.Plugs.System +{ + [Plug(Target=typeof(Dictionary))] + public static class DictionaryImpl + { + + public static void Ctor(Dictionary aThis, int capacity, IEqualityComparer comparer) + { + if (capacity != 0) + { + throw new Exception("Capacity != 0 not supported yet!"); + } + + } + + } +} diff --git a/source2/Kernel/System/Cosmos.System.Plugs.System/IO/FileStreamImpl.cs b/source2/Kernel/System/Cosmos.System.Plugs.System/IO/FileStreamImpl.cs index 4b5eb67df..71a68b96c 100644 --- a/source2/Kernel/System/Cosmos.System.Plugs.System/IO/FileStreamImpl.cs +++ b/source2/Kernel/System/Cosmos.System.Plugs.System/IO/FileStreamImpl.cs @@ -9,10 +9,15 @@ namespace Cosmos.System.Plugs.System.IO { [Plug(Target = typeof(IO::FileStream))] public class FileStreamImpl { - static public void FileStream(String aPathname, IO::FileMode aMode) { + static public void Ctor(IO::FileStream aThis, String aPathname, IO::FileMode aMode) { global::System.Console.WriteLine("File open"); } + static public void CCtor() + { + // plug cctor as it (indirectly) uses Thread.MemoryBarrier() + } + //static void Init(IO::FileStream aThis, string path, IO::FileMode mode, IO::FileAccess access, int rights, bool useRights, IO::FileShare share, int bufferSize // , IO::FileOptions options, Microsoft.Win32.Win32Native.SECURITY_ATTRIBUTES secAttrs, string msgPath, bool bFromProxy) { } diff --git a/source2/Kernel/System/Cosmos.System.Plugs.System/TypeImpl.cs b/source2/Kernel/System/Cosmos.System.Plugs.System/TypeImpl.cs index fa8701113..22cebaad3 100644 --- a/source2/Kernel/System/Cosmos.System.Plugs.System/TypeImpl.cs +++ b/source2/Kernel/System/Cosmos.System.Plugs.System/TypeImpl.cs @@ -24,6 +24,13 @@ namespace Cosmos.System.Plugs.System return ""; } + [PlugMethod(Signature="System_Boolean__System_Type_op_Equality_System_Type__System_Type_")] + public static bool op_Equality(uint left, uint right) + { + // for now, type info is the type id. + return left == right; + } + //System.Type System.Type.GetTypeFromHandle(System.RuntimeTypeHandle) } } diff --git a/source2/Kernel/System/Hardware/Core/Cosmos.Core.Plugs/StringImpl.cs b/source2/Kernel/System/Hardware/Core/Cosmos.Core.Plugs/StringImpl.cs index 0fd0f8b87..78cb48b35 100644 --- a/source2/Kernel/System/Hardware/Core/Cosmos.Core.Plugs/StringImpl.cs +++ b/source2/Kernel/System/Hardware/Core/Cosmos.Core.Plugs/StringImpl.cs @@ -7,6 +7,7 @@ using Cosmos.IL2CPU.Plugs; namespace Cosmos.Core.Plugs { //TODO: Move this and other FCL plugs to Cosmos.Plugs assembly. some plugs like Console need hardware // but these generics ones should be moved, this does not depend on kernel + [Plug(Target=typeof(string))] public class StringImpl { /*public int IndexOf(char c) { @@ -308,6 +309,11 @@ namespace Cosmos.Core.Plugs { return ChangeCasing(aThis, 97, 122, -32); } + public static string ToUpper(string aThis) + { + return ChangeCasing(aThis, 97, 122, -32); + } + private static string ChangeCasing(string aValue, int lowerAscii, int upperAscii, int offset) { char[] xChars = new char[aValue.Length]; diff --git a/source2/Users/Matthijs/MatthijsPlayground/Kernel.cs b/source2/Users/Matthijs/MatthijsPlayground/Kernel.cs index 0a1308286..651fa110e 100644 --- a/source2/Users/Matthijs/MatthijsPlayground/Kernel.cs +++ b/source2/Users/Matthijs/MatthijsPlayground/Kernel.cs @@ -3,11 +3,25 @@ using System.Collections.Generic; using System.Text; using Sys = Cosmos.System; using Cosmos.Common.Extensions; +using System.IO; +using Cosmos.Debug.Kernel; namespace MatthijsPlayground { public class Kernel : Sys.Kernel { + private class TestComparer : IEqualityComparer + { + public bool Equals(int x, int y) + { + return x == y; + } + + public int GetHashCode(int obj) + { + return obj.GetHashCode(); + } + } protected override void BeforeRun() { Console.WriteLine("Cosmos booted successfully. Type a line of text to get it echoed back."); @@ -23,18 +37,26 @@ namespace MatthijsPlayground private static void DoSomething() { - int xValue1 = 0x00000001; - int xValue2 = 0x00000002; - int xValue3 = 0x00000003; + Console.WriteLine("Before Everything"); - Console.WriteLine("Done"); - //WriteLine("Line1"); + var xString = ""; + var xDbg = new Debugger("kernel", "kernel"); + xDbg.Send(xString); + //var xSB = new StringBuilder(); + //xSB.Append("Hello"); + //xSB.Append("Hello"); + //var xDisplay = xSB.ToString(); + //Console.WriteLine(xDisplay.Length); + //Console.WriteLine(xDisplay); + + Console.WriteLine("After everything"); //WriteLine("Line2"); //WriteLine("Line3"); } private static void WriteLine(string line) { + var xTheLine = line.ToUpper(); Console.WriteLine(line); } } diff --git a/source2/Users/Matthijs/MatthijsPlayground/MatthijsPlaygroundBoot.Cosmos b/source2/Users/Matthijs/MatthijsPlayground/MatthijsPlaygroundBoot.Cosmos index 19b490bb5..f81281c73 100644 --- a/source2/Users/Matthijs/MatthijsPlayground/MatthijsPlaygroundBoot.Cosmos +++ b/source2/Users/Matthijs/MatthijsPlayground/MatthijsPlaygroundBoot.Cosmos @@ -17,7 +17,7 @@ bin\Debug\ MicrosoftNET False - True + False Source User VMWare