From cfa79c4dc7dcac628c2fc7983ab062e4cf9639f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Pedro?= Date: Sat, 26 Aug 2017 22:45:33 +0100 Subject: [PATCH] Move Cosmos.Debug.Symbols to IL2CPU. --- Build.sln | 2 +- IDE.sln | 2 +- Kernel.sln | 2 +- Test.sln | 2 +- .../BochsSupport.cs | 2 +- .../Cosmos.Build.MSBuild.csproj | 3 +- .../ExtractMapFromElfFile.cs | 2 +- .../Cosmos.Debug.Common.csproj | 2 +- source/Cosmos.Debug.Common/ObjDump.cs | 137 --- .../Cosmos.Debug.Hosts/Bochs.Configuration.cs | 1 + .../Cosmos.Debug.Hosts.csproj | 2 +- source/Cosmos.Debug.Symbols/CacheHelper.cs | 35 - .../Cosmos.Debug.Symbols.csproj | 30 - source/Cosmos.Debug.Symbols/DebugInfo.cs | 836 ------------------ source/Cosmos.Debug.Symbols/DebugModel.cs | 459 ---------- .../Cosmos.Debug.Symbols/DebugSymbolReader.cs | 322 ------- .../Hashing/TypeHashingAlgorithms.cs | 251 ------ source/Cosmos.Debug.Symbols/ITokenResolver.cs | 23 - .../LocalTypeGenericContext.cs | 17 - .../Cosmos.Debug.Symbols/LocalTypeProvider.cs | 177 ---- .../Metadata/CachingMetadataStringDecoder.cs | 193 ---- .../Metadata/MetadataHelper.cs | 105 --- .../Cosmos.Debug.Symbols/ModuleExtensions.cs | 37 - .../ModuleScopeTokenResolver.cs | 34 - source/Cosmos.Debug.Symbols/ObjectReader.cs | 253 ------ .../Pdb/ILLocalVariable.cs | 28 - .../Pdb/ILSequencePoint.cs | 26 - .../Pdb/PdbSymbolReader.cs | 19 - .../Pdb/PortablePdbSymbolReader.cs | 151 ---- .../Pdb/UnmanagedPdbSymbolReader.cs | 274 ------ source/Cosmos.Debug.Symbols/SQL.cs | 93 -- source/Cosmos.Debug.Symbols/SQLite.sql | 93 -- source/Cosmos.Debug.Symbols/SQLiteIndexes.sql | 26 - source/Cosmos.Debug.Symbols/SourceInfo.cs | 27 - source/Cosmos.Debug.Symbols/SqliteBulkCopy.cs | 75 -- .../Cosmos.VS.DebugEngine.csproj | 2 +- .../Cosmos.VS.ProjectSystem/ProfilePresets.cs | 4 +- 37 files changed, 13 insertions(+), 3734 deletions(-) rename source/{Cosmos.Debug.Common => Cosmos.Build.Common}/BochsSupport.cs (99%) delete mode 100644 source/Cosmos.Debug.Common/ObjDump.cs delete mode 100644 source/Cosmos.Debug.Symbols/CacheHelper.cs delete mode 100644 source/Cosmos.Debug.Symbols/Cosmos.Debug.Symbols.csproj delete mode 100644 source/Cosmos.Debug.Symbols/DebugInfo.cs delete mode 100644 source/Cosmos.Debug.Symbols/DebugModel.cs delete mode 100644 source/Cosmos.Debug.Symbols/DebugSymbolReader.cs delete mode 100644 source/Cosmos.Debug.Symbols/Hashing/TypeHashingAlgorithms.cs delete mode 100644 source/Cosmos.Debug.Symbols/ITokenResolver.cs delete mode 100644 source/Cosmos.Debug.Symbols/LocalTypeGenericContext.cs delete mode 100644 source/Cosmos.Debug.Symbols/LocalTypeProvider.cs delete mode 100644 source/Cosmos.Debug.Symbols/Metadata/CachingMetadataStringDecoder.cs delete mode 100644 source/Cosmos.Debug.Symbols/Metadata/MetadataHelper.cs delete mode 100644 source/Cosmos.Debug.Symbols/ModuleExtensions.cs delete mode 100644 source/Cosmos.Debug.Symbols/ModuleScopeTokenResolver.cs delete mode 100644 source/Cosmos.Debug.Symbols/ObjectReader.cs delete mode 100644 source/Cosmos.Debug.Symbols/Pdb/ILLocalVariable.cs delete mode 100644 source/Cosmos.Debug.Symbols/Pdb/ILSequencePoint.cs delete mode 100644 source/Cosmos.Debug.Symbols/Pdb/PdbSymbolReader.cs delete mode 100644 source/Cosmos.Debug.Symbols/Pdb/PortablePdbSymbolReader.cs delete mode 100644 source/Cosmos.Debug.Symbols/Pdb/UnmanagedPdbSymbolReader.cs delete mode 100644 source/Cosmos.Debug.Symbols/SQL.cs delete mode 100644 source/Cosmos.Debug.Symbols/SQLite.sql delete mode 100644 source/Cosmos.Debug.Symbols/SQLiteIndexes.sql delete mode 100644 source/Cosmos.Debug.Symbols/SourceInfo.cs delete mode 100644 source/Cosmos.Debug.Symbols/SqliteBulkCopy.cs diff --git a/Build.sln b/Build.sln index 80458195e5..4073c99fef 100644 --- a/Build.sln +++ b/Build.sln @@ -52,7 +52,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IL2CPU", "..\IL2CPU\source\ EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cosmos.IL2CPU", "..\IL2CPU\source\Cosmos.IL2CPU\Cosmos.IL2CPU.csproj", "{3C45A898-4AA9-476F-8302-63391D6ED044}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cosmos.Debug.Symbols", "source\Cosmos.Debug.Symbols\Cosmos.Debug.Symbols.csproj", "{2E740096-911F-47D0-A46D-998DBB76FC5D}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cosmos.Debug.Symbols", "..\IL2CPU\source\Cosmos.Debug.Symbols\Cosmos.Debug.Symbols.csproj", "{2E740096-911F-47D0-A46D-998DBB76FC5D}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cosmos.Debug.DebugConnectors", "source\Cosmos.Debug.DebugConnectors\Cosmos.Debug.DebugConnectors.csproj", "{BC91BCEF-D146-4EB0-BE63-C637880C5800}" EndProject diff --git a/IDE.sln b/IDE.sln index 926d3a65dd..e037ab0d2f 100644 --- a/IDE.sln +++ b/IDE.sln @@ -22,7 +22,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cosmos.Debug.GDB", "source\ EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cosmos.Debug.Hosts", "source\Cosmos.Debug.Hosts\Cosmos.Debug.Hosts.csproj", "{C9826909-2E5E-4453-93FA-B6BE4503DF02}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cosmos.Debug.Symbols", "source\Cosmos.Debug.Symbols\Cosmos.Debug.Symbols.csproj", "{ECC4319F-A844-45B8-BF63-2FD04F05E56A}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cosmos.Debug.Symbols", "..\IL2CPU\source\Cosmos.Debug.Symbols\Cosmos.Debug.Symbols.csproj", "{ECC4319F-A844-45B8-BF63-2FD04F05E56A}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cosmos.Deploy.Pixie", "source\Cosmos.Deploy.Pixie\Cosmos.Deploy.Pixie.csproj", "{D4BA64B3-D7F6-4A3A-AF1D-74E41B49D865}" EndProject diff --git a/Kernel.sln b/Kernel.sln index cdac43af7b..976904e6aa 100644 --- a/Kernel.sln +++ b/Kernel.sln @@ -72,7 +72,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cosmos.IL2CPU", "..\IL2CPU\ EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cosmos.Build.Common", "source\Cosmos.Build.Common\Cosmos.Build.Common.csproj", "{67FD9912-CE63-4EB2-880C-F4F0D9AED7CA}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cosmos.Debug.Symbols", "source\Cosmos.Debug.Symbols\Cosmos.Debug.Symbols.csproj", "{4E9B8F31-AEA0-402D-9B3A-223100F2156D}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cosmos.Debug.Symbols", "..\IL2CPU\source\Cosmos.Debug.Symbols\Cosmos.Debug.Symbols.csproj", "{4E9B8F31-AEA0-402D-9B3A-223100F2156D}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cosmos.Plugs.TapRoot", "source\Kernel-X86\91-Plugs\Cosmos.Plugs.TapRoot\Cosmos.Plugs.TapRoot.csproj", "{BEEDA0BE-0105-40BF-BD8D-7F6A2BC3B05C}" EndProject diff --git a/Test.sln b/Test.sln index 90a6380710..c8fedd0e6d 100644 --- a/Test.sln +++ b/Test.sln @@ -30,7 +30,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cosmos.Core.DebugStub", "so EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cosmos.Debug.Hosts", "source\Cosmos.Debug.Hosts\Cosmos.Debug.Hosts.csproj", "{C9826909-2E5E-4453-93FA-B6BE4503DF02}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cosmos.Debug.Symbols", "source\Cosmos.Debug.Symbols\Cosmos.Debug.Symbols.csproj", "{ECC4319F-A844-45B8-BF63-2FD04F05E56A}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cosmos.Debug.Symbols", "..\IL2CPU\source\Cosmos.Debug.Symbols\Cosmos.Debug.Symbols.csproj", "{ECC4319F-A844-45B8-BF63-2FD04F05E56A}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cosmos.HAL2", "source\Cosmos.HAL2\Cosmos.HAL2.csproj", "{1425715D-1C93-44C7-8BB5-F124F195A41A}" EndProject diff --git a/source/Cosmos.Debug.Common/BochsSupport.cs b/source/Cosmos.Build.Common/BochsSupport.cs similarity index 99% rename from source/Cosmos.Debug.Common/BochsSupport.cs rename to source/Cosmos.Build.Common/BochsSupport.cs index 2d0d425ab7..df125fac41 100644 --- a/source/Cosmos.Debug.Common/BochsSupport.cs +++ b/source/Cosmos.Build.Common/BochsSupport.cs @@ -6,7 +6,7 @@ using Microsoft.Win32; -namespace Cosmos.Debug.Common +namespace Cosmos.Build.Common { /// An helper class that is used from both Cosmos.VS.ProjectSystem and Cosmos.VS.DebugEngine for /// Bochs emulator support. diff --git a/source/Cosmos.Build.MSBuild/Cosmos.Build.MSBuild.csproj b/source/Cosmos.Build.MSBuild/Cosmos.Build.MSBuild.csproj index 09a2d73241..20bad6bd47 100644 --- a/source/Cosmos.Build.MSBuild/Cosmos.Build.MSBuild.csproj +++ b/source/Cosmos.Build.MSBuild/Cosmos.Build.MSBuild.csproj @@ -23,8 +23,7 @@ - - + diff --git a/source/Cosmos.Build.MSBuild/ExtractMapFromElfFile.cs b/source/Cosmos.Build.MSBuild/ExtractMapFromElfFile.cs index f5da8b5179..bde78a2855 100644 --- a/source/Cosmos.Build.MSBuild/ExtractMapFromElfFile.cs +++ b/source/Cosmos.Build.MSBuild/ExtractMapFromElfFile.cs @@ -3,7 +3,7 @@ using System.IO; using Microsoft.Build.Framework; -using Cosmos.Debug.Common; +using Cosmos.Debug.Symbols; namespace Cosmos.Build.MSBuild { public class ExtractMapFromElfFile : BaseToolTask { diff --git a/source/Cosmos.Debug.Common/Cosmos.Debug.Common.csproj b/source/Cosmos.Debug.Common/Cosmos.Debug.Common.csproj index 0cbffc634a..5271b00633 100644 --- a/source/Cosmos.Debug.Common/Cosmos.Debug.Common.csproj +++ b/source/Cosmos.Debug.Common/Cosmos.Debug.Common.csproj @@ -8,7 +8,7 @@ - + diff --git a/source/Cosmos.Debug.Common/ObjDump.cs b/source/Cosmos.Debug.Common/ObjDump.cs deleted file mode 100644 index 4c05cd21d0..0000000000 --- a/source/Cosmos.Debug.Common/ObjDump.cs +++ /dev/null @@ -1,137 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.IO; - -using Cosmos.Debug.Symbols; - -namespace Cosmos.Debug.Common -{ - public class ObjDump - { - [Obsolete("We're not using ELF Format anymore")] - public static SortedList GetLabelByAddressMapping(string aKernel, string aObjDumpExe) - { - string[] xSymbolsContents; - #region Run ObjDump - string xTempFile = Path.GetTempFileName(); - var xRandom = new Random(78367); - string xBatFile = String.Empty; - do - { - xBatFile = Path.GetTempPath(); - xBatFile = Path.Combine(xBatFile, BitConverter.GetBytes(xRandom.NextDouble()).Aggregate("", (r, b) => r += b.ToString("X2").ToUpper()) + ".bat"); - } while (File.Exists(xBatFile)); - string xObjDumpFile = aObjDumpExe; - File.WriteAllText(xBatFile, String.Format("@ECHO OFF\r\n\"{0}\" --syms --wide \"{1}\" > \"{2}\"", xObjDumpFile, aKernel, xTempFile)); - using (var xProcess = Process.Start(xBatFile)) - { - xProcess.WaitForExit(); - } - xSymbolsContents = File.ReadAllLines(xTempFile); - File.Delete(xTempFile); - File.Delete(xBatFile); - #endregion - - var xResult = new SortedList(); - foreach (var xLabel in ExtractMapSymbolsForElfFile(xSymbolsContents)) - { - xResult.Add((uint)xLabel.Address, xLabel.Name); - } - return xResult; - } - - /// - /// Sequentially parse symbols from the lines sequence. - /// - /// Sequence of lines which contain map files. - /// Sequence of parsed label. - public static IEnumerable - + diff --git a/source/Cosmos.Debug.Symbols/CacheHelper.cs b/source/Cosmos.Debug.Symbols/CacheHelper.cs deleted file mode 100644 index f4a8b46b55..0000000000 --- a/source/Cosmos.Debug.Symbols/CacheHelper.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System; - -namespace Cosmos.Debug.Symbols -{ - public class CacheHelper - where TKey: IEquatable - { - public CacheHelper(Func getValueFunc) - { - if (getValueFunc == null) - { - throw new ArgumentNullException("getValueFunc"); - } - mGetValueFunc = getValueFunc; - } - - private readonly Func mGetValueFunc; - private TValue mCachedValue; - private TKey mCachedKey; - private bool mHasCachedValue = false; - - public TValue GetValue(TKey key) - { - if (mHasCachedValue && mCachedKey.Equals(key)) - { - return mCachedValue; - } - - mCachedValue = mGetValueFunc(key); - mCachedKey = key; - mHasCachedValue = true; - return mCachedValue; - } - } -} diff --git a/source/Cosmos.Debug.Symbols/Cosmos.Debug.Symbols.csproj b/source/Cosmos.Debug.Symbols/Cosmos.Debug.Symbols.csproj deleted file mode 100644 index 1521ac5bf6..0000000000 --- a/source/Cosmos.Debug.Symbols/Cosmos.Debug.Symbols.csproj +++ /dev/null @@ -1,30 +0,0 @@ - - - - netstandard2.0 - True - True - ..\..\Cosmos.snk - - - - - - - - - - - - - - - - - - - - - - - diff --git a/source/Cosmos.Debug.Symbols/DebugInfo.cs b/source/Cosmos.Debug.Symbols/DebugInfo.cs deleted file mode 100644 index f18afcc8c0..0000000000 --- a/source/Cosmos.Debug.Symbols/DebugInfo.cs +++ /dev/null @@ -1,836 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Data; -using System.IO; -using System.Linq; -using System.Reflection; -using Microsoft.Data.Sqlite; - -using Dapper; -using DapperExtensions; -using DapperExtensions.Mapper; -using DapperExtensions.Sql; - -namespace Cosmos.Debug.Symbols -{ - using SourceInfos = SortedList; - - public class DebugInfo : IDisposable - { - /// - /// Current id of the generation. - /// - private static long mLastGuid = 0; - - /// - /// Range for the id generation process. - /// - private static long mPrefix = 0; - - /// - /// Specifies range which is used by the assembler during compilation phase. - /// - public const long AssemblerDebugSymbolsRange = 0x0L; - - /// - /// Specifies range which is used by the Elf map extraction process. - /// - public const long ElfFileMapExtractionRange = 0x1000000000000000L; - - /// - /// Specifies range which is used by the Nasm map extraction process. - /// - public const long NAsmMapExtractionRange = 0x4000000000000000L; - - // Please beware this field, it may cause issues if used incorrectly. - public static DebugInfo CurrentInstance { get; private set; } - - public class Field_Map - { - public string TypeName { get; set; } - public List FieldNames = new List(); - } - - protected SqliteConnection mConnection; - protected string mDbName; - // Dont use DbConnectionStringBuilder class, it doesnt work with LocalDB properly. - //protected mDataSouce = @".\SQLEXPRESS"; - protected string mConnStr; - - public void DeleteDB(string aDbName, string aPathname) - { - File.Delete(aDbName); - } - - public DebugInfo(string aPathname, bool aCreate = false, bool aCreateIndexes = false) - { - InitializeCache(); - CurrentInstance = this; - - if (aPathname != ":memory:") - { - if (aCreate) - { - File.Delete(aPathname); - } - - aCreate = !File.Exists(aPathname); - } - - // Manually register the data provider. Do not remove this otherwise the data provider doesn't register properly. - //mConnStr = string.Format("data source={0};journal mode=Memory;synchronous=Off;foreign keys=True;BinaryGuid=false", aPathname); - mConnStr = string.Format("data source={0}", aPathname); - // Use the SQLiteConnectionFactory as the default database connection - // Do not open mConnection before mEntities.CreateDatabase - mConnection = new SqliteConnection(mConnStr); - - DapperExtensions.DapperExtensions.DefaultMapper = typeof(PluralizedAutoClassMapper<>); - DapperExtensions.DapperExtensions.SqlDialect = new SqliteDialect(); - - if (aCreate) - { - mConnection.Open(); - var xSQL = new SQL(mConnection); - xSQL.CreateDB(); - - // Be careful with indexes, they slow down inserts. So on tables that we have a - // lot of inserts, but limited look ups, dont add them. - // - if (aCreateIndexes) - { - this.CreateIndexes(); - } - } - - if (mConnection.State == ConnectionState.Closed) - { - mConnection.Open(); - } - } - - /// - /// Create indexes inside the database. - /// - public void CreateIndexes() - { - var xSQL = new SQL(mConnection); - - xSQL.MakeIndex("Labels", "Address", false); - xSQL.MakeIndex("Labels", "Name", true); - xSQL.MakeIndex("Methods", "DocumentID", false); - - xSQL.ExecuteAssemblyResource("SQLiteIndexes.sql"); - } - - // The GUIDs etc are populated by the MSBuild task, so they wont be loaded when the debugger runs. - // Because of this, we also allow manual loading. - public void LoadLookups() - { - foreach (var xDoc in mConnection.GetList()) - { - DocumentGUIDs.Add(xDoc.Pathname.ToLower(), xDoc.ID); - } - } - - private void InitializeCache() - { - mSourceInfosCache = new CacheHelper(a => DoGetSourceInfos(a)); - mLabelsCache = new CacheHelper(a => DoGetLabels(a)); - mFirstMethodIlOpByLabelNameCache = new CacheHelper(n => mConnection.GetList(Predicates.Field(q => q.LabelName, Operator.Eq, n)).FirstOrDefault()); - mMethodCache = new CacheHelper(i => mConnection.Get(i)); - mAllLocalsAndArgumentsInfosByMethodLabelNameCache = new CacheHelper(a => mConnection.GetList(Predicates.Field(q => q.METHODLABELNAME, Operator.Eq, a)).ToArray()); - - mDocumentIdByNameCache = new CacheHelper(n => - { - long xId; - var xHasResult = DocumentGUIDs.TryGetValue(n, out xId); - if (xHasResult) - { - return xId; - } - else - { - return null; - } - }); - - mAssemblyFileByIdCache = new CacheHelper(i => mConnection.Get(i)); - mAddressOfLabelCache = new CacheHelper(l => DoGetAddressOfLabel(l)); - mFieldMapCache = new CacheHelper(t => DoGetFieldMap(t)); - mFieldInfoByNameCache = new CacheHelper(n => mConnection.GetList(Predicates.Field(q => q.NAME, Operator.Eq, n)).First()); - } - - private CacheHelper mSourceInfosCache; - public SourceInfos GetSourceInfos(uint aAddress) - { - return mSourceInfosCache.GetValue(aAddress); - } - - private CacheHelper mLabelsCache; - public string[] GetLabels(uint aAddress) - { - return mLabelsCache.GetValue(aAddress); - } - - private CacheHelper mFirstMethodIlOpByLabelNameCache; - public MethodIlOp TryGetFirstMethodIlOpByLabelName(string aLabelName) - { - return mFirstMethodIlOpByLabelNameCache.GetValue(aLabelName); - } - - private CacheHelper mMethodCache; - public Method GetMethod(long aMethodId) - { - return mMethodCache.GetValue(aMethodId); - } - - - private CacheHelper mAllLocalsAndArgumentsInfosByMethodLabelNameCache; - public LOCAL_ARGUMENT_INFO[] GetAllLocalsAndArgumentsInfosByMethodLabelName(string aLabelName) - { - return mAllLocalsAndArgumentsInfosByMethodLabelNameCache.GetValue(aLabelName); - } - - private CacheHelper mDocumentIdByNameCache; - public bool TryGetDocumentIdByName(string aDocumentName, out long oDocumentId) - { - var xValue = mDocumentIdByNameCache.GetValue(aDocumentName); - oDocumentId = xValue.GetValueOrDefault(); - return xValue != null; - } - - private CacheHelper mAssemblyFileByIdCache; - public AssemblyFile GetAssemblyFileById(long aId) - { - return mAssemblyFileByIdCache.GetValue(aId); - } - - private CacheHelper mAddressOfLabelCache; - public uint GetAddressOfLabel(string aLabelName) - { - return mAddressOfLabelCache.GetValue(aLabelName); - } - - private CacheHelper mFieldMapCache; - public DebugInfo.Field_Map GetFieldMap(string aTypeName) - { - return mFieldMapCache.GetValue(aTypeName); - } - - private CacheHelper mFieldInfoByNameCache; - public FIELD_INFO GetFieldInfoByName(string aName) - { - return mFieldInfoByNameCache.GetValue(aName); - } - - private uint DoGetAddressOfLabel(string aLabel) - { - var xRow = mConnection.GetList