From eab46e2cb09f7860eb4ea2ac13a87e79c7e75b6c Mon Sep 17 00:00:00 2001
From: geramy_cp <9e7fa7e69b77621edd7e7a6d0b0a26a273ab818fdM2WcnSD>
Date: Sun, 3 Feb 2013 16:10:16 +0000
Subject: [PATCH] Fixed asm stepping. also fixed IL2CPU Profiler and changed
Label replace chars with a compiled regex.
---
source/Cosmos.sln | 7 +-
source2/Cosmos.Assembler/LabelName.cs | 13 +--
.../Debug/Cosmos.Debug.Common/DebugInfo.cs | 15 +++-
.../Cosmos.IL2CPU.Profiler.csproj | 5 ++
.../Cosmos.IL2CPU.Profiler/FakeKernel.cs | 21 +++++
.../IL2CPU/Cosmos.IL2CPU.Profiler/Program.cs | 83 +++++++++++++------
source2/IL2CPU/Cosmos.IL2CPU/ILScanner.cs | 2 +-
source2/VSIP/Cosmos.VS.Windows/DebuggerUC.cs | 2 +-
.../VSIP/Cosmos.VS.Windows/StackUC.xaml.cs | 45 ++++++----
9 files changed, 140 insertions(+), 53 deletions(-)
create mode 100644 source2/IL2CPU/Cosmos.IL2CPU.Profiler/FakeKernel.cs
diff --git a/source/Cosmos.sln b/source/Cosmos.sln
index 227554ba6..b17f82cb6 100644
--- a/source/Cosmos.sln
+++ b/source/Cosmos.sln
@@ -88,7 +88,7 @@ Project("{E24C65DC-7377-472B-9ABA-BC803B73C61A}") = "Docs", "..\Docs", "{67E7DEF
Release.AspNetCompiler.ForceOverwrite = "true"
Release.AspNetCompiler.FixedNames = "false"
Release.AspNetCompiler.Debug = "False"
- VWDPort = "64695"
+ VWDPort = "1739"
EndProjectSection
EndProject
Project("{471EC4BB-E47E-4229-A789-D1F5F83B52D4}") = "Kudzu.Breakpoints", "..\source2\Users\Kudzu\Breakpoints\Kudzu.Breakpoints.Cosmos", "{E5647BFD-1507-4F02-A7D5-E0F9D6AECE3A}"
@@ -230,6 +230,11 @@ Project("{471EC4BB-E47E-4229-A789-D1F5F83B52D4}") = "GeramysTestBoot", "GeramysT
{DA4198CA-59DF-41B3-9884-867647900D76} = {DA4198CA-59DF-41B3-9884-867647900D76}
EndProjectSection
EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{21D9A04D-C5CC-4162-B7B4-C28940042A64}"
+ ProjectSection(SolutionItems) = preProject
+ Performance1.psess = Performance1.psess
+ EndProjectSection
+EndProject
Global
GlobalSection(TeamFoundationVersionControl) = preSolution
SccNumberOfProjects = 61
diff --git a/source2/Cosmos.Assembler/LabelName.cs b/source2/Cosmos.Assembler/LabelName.cs
index 7a3888986..e4efec995 100644
--- a/source2/Cosmos.Assembler/LabelName.cs
+++ b/source2/Cosmos.Assembler/LabelName.cs
@@ -36,19 +36,20 @@ namespace Cosmos.Assembler {
public static string Get(string aMethodLabel, int aIlPos) {
return aMethodLabel + ".IL_" + aIlPos.ToString("X4");
}
-
+ public static System.Text.RegularExpressions.Regex IllegalCharsReplace = new System.Text.RegularExpressions.Regex(@"[&.,+$<>{}\-\`\\'/\\ \(\)\[\]\*!=_]", System.Text.RegularExpressions.RegexOptions.Compiled);
public static string Final(string xName) {
- var xSB = new StringBuilder(xName);
-
+ //var xSB = new StringBuilder(xName);
+
// DataMember.FilterStringForIncorrectChars also does some filtering but replacing empties or non _ chars
// causes issues with legacy hardcoded values. So we have a separate function.
//
// For logging possibilities, we generate fuller names, and then strip out spacing/characters.
- const string xIllegalChars = "&.,+$<>{}-`\'/\\ ()[]*!=_";
+ /*const string xIllegalChars = "&.,+$<>{}-`\'/\\ ()[]*!=_";
foreach (char c in xIllegalChars) {
xSB.Replace(c.ToString(), "");
- }
-
+ }*/
+ xName = IllegalCharsReplace.Replace(xName, "");
+ var xSB = new StringBuilder(xName);
if (xSB.Length > MaxLengthWithoutSuffix) {
using (var xHash = MD5.Create()) {
var xValue = xHash.ComputeHash(Encoding.Default.GetBytes(xName));
diff --git a/source2/Debug/Cosmos.Debug.Common/DebugInfo.cs b/source2/Debug/Cosmos.Debug.Common/DebugInfo.cs
index f9b0b4624..bc5877847 100644
--- a/source2/Debug/Cosmos.Debug.Common/DebugInfo.cs
+++ b/source2/Debug/Cosmos.Debug.Common/DebugInfo.cs
@@ -82,10 +82,16 @@ namespace Cosmos.Debug.Common {
}
// Yes this throws an exception if the database doesnt exist, so we have to run it only if we
// know it exists. This will detach and also delete the physical files.
- using (var xCmd = xConn.CreateCommand())
+ try
+ {
+ using (var xCmd = xConn.CreateCommand())
+ {
+ xCmd.CommandText = "DROP DATABASE " + aDbName;
+ xCmd.ExecuteNonQuery();
+ }
+ }
+ catch
{
- xCmd.CommandText = "DROP DATABASE " + aDbName;
- xCmd.ExecuteNonQuery();
}
if (damagedDatabase)
{
@@ -409,8 +415,9 @@ namespace Cosmos.Debug.Common {
public void Dispose() {
if (mConnection != null) {
var xConn = mConnection;
- mConnection = null;
xConn.Close();
+ xConn = null;
+ mConnection = null;
// Dont set to null... causes problems because of bad code :(
// Need to fix the whole class, but its here for now.
//CurrentInstance = null;
diff --git a/source2/IL2CPU/Cosmos.IL2CPU.Profiler/Cosmos.IL2CPU.Profiler.csproj b/source2/IL2CPU/Cosmos.IL2CPU.Profiler/Cosmos.IL2CPU.Profiler.csproj
index 12ad93a4f..ee2a5be3a 100644
--- a/source2/IL2CPU/Cosmos.IL2CPU.Profiler/Cosmos.IL2CPU.Profiler.csproj
+++ b/source2/IL2CPU/Cosmos.IL2CPU.Profiler/Cosmos.IL2CPU.Profiler.csproj
@@ -59,11 +59,16 @@
+
+
+ {0462E82B-8C29-41A9-8265-9C89038ADB29}
+ Cosmos.Build.Common
+
{1116130E-28E0-428A-A597-F4B3B676C0CA}
Cosmos.Assembler
diff --git a/source2/IL2CPU/Cosmos.IL2CPU.Profiler/FakeKernel.cs b/source2/IL2CPU/Cosmos.IL2CPU.Profiler/FakeKernel.cs
new file mode 100644
index 000000000..8d35eb00f
--- /dev/null
+++ b/source2/IL2CPU/Cosmos.IL2CPU.Profiler/FakeKernel.cs
@@ -0,0 +1,21 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Cosmos.IL2CPU.Profiler
+{
+ public class FakeKernel: Cosmos.System.Kernel
+ {
+ protected override void BeforeRun()
+ {
+ Console.WriteLine("Cosmos booted successfully. Type a line of text to get it echoed back.");
+ }
+
+ protected override void Run()
+ {
+ Console.Write("Enter some text to be echoed back to you: ");
+ Console.WriteLine(Console.ReadLine());
+ }
+ }
+}
\ No newline at end of file
diff --git a/source2/IL2CPU/Cosmos.IL2CPU.Profiler/Program.cs b/source2/IL2CPU/Cosmos.IL2CPU.Profiler/Program.cs
index bfaf740bd..6c8128c0a 100644
--- a/source2/IL2CPU/Cosmos.IL2CPU.Profiler/Program.cs
+++ b/source2/IL2CPU/Cosmos.IL2CPU.Profiler/Program.cs
@@ -6,6 +6,9 @@ using System.Reflection;
using System.Reflection.Emit;
using System.Text;
using Cosmos.System;
+using Cosmos.Debug.Common;
+using Cosmos.Build.Common;
+using System.IO;
using Console = System.Console;
namespace Cosmos.IL2CPU.Profiler {
@@ -16,32 +19,64 @@ namespace Cosmos.IL2CPU.Profiler {
static void Main(string[] args) {
Program.DoScan();
+ Console.WriteLine("Press any key to continue.");
+ Console.ReadKey();
}
- private static void DoScan() {
- var xSW = new Stopwatch();
- xSW.Start();
-
- var xAsmblr = new Assembler();
- using (var xScanner = new ILScanner(xAsmblr)) {
- //TODO: Add plugs into the scanning equation to profile scanning them too
- //System.Reflection.MethodInfo[] name = typeof(SSchockeTest.Kernel).GetMethods();
- Type xFoundType = typeof(Kernel);
- var xCtor = xFoundType.GetConstructor(Type.EmptyTypes);
- typeof(Cosmos.System.Plugs.System.System.ConsoleImpl).IsSubclassOf(typeof(object));
- var xEntryPoint = typeof(Kernel).GetMethod("Start", BindingFlags.Public | BindingFlags.Instance);
- //var xEntryPoint = typeof(Program).GetMethod("ScannerEntryPoint", BindingFlags.NonPublic | BindingFlags.Static);
- //EnableLogging(pathToLogFile)
- xScanner.EnableLogging(AppDomain.CurrentDomain.BaseDirectory + "log.txt");
- //xScanner.TempDebug += new Action(xScanner_TempDebug);
- //xScanner.
- xScanner.Execute(xCtor);
+ private static void DoScan()
+ {
- xSW.Stop();
- Console.WriteLine("Total time : {0}", xSW.Elapsed);
- Console.WriteLine("Method count: {0}", xScanner.MethodCount);
- //Console.WriteLine("Instruction count: {0}", xScanner.InstructionCount);
- }
+ var xSW = new Stopwatch();
+ xSW.Start();
+ string MDFFile = AppDomain.CurrentDomain.BaseDirectory + "TestKernel.mdf";
+ if (File.Exists(MDFFile))
+ File.Delete(MDFFile);
+
+ var outFile = AppDomain.CurrentDomain.BaseDirectory + "TestKernel.out";
+ if (File.Exists(outFile))
+ File.Delete(outFile);
+
+ var logFile = AppDomain.CurrentDomain.BaseDirectory + "TestKernel.log";
+ if (File.Exists(logFile))
+ File.Delete(logFile);
+
+ var xAsmblr = new AppAssembler(1);
+ using (var xScanner = new ILScanner(xAsmblr))
+ {
+ using (var xDebugInfo = new DebugInfo(MDFFile, true))
+ {
+ xAsmblr.DebugInfo = xDebugInfo;
+ xAsmblr.DebugEnabled = true;
+ xAsmblr.DebugMode = DebugMode.Source;
+ xAsmblr.TraceAssemblies = TraceAssemblies.All;
+ xAsmblr.IgnoreDebugStubAttribute = false;
+
+ xAsmblr.Assembler.Initialize();
+ //TODO: Add plugs into the scanning equation to profile scanning them too
+ //System.Reflection.MethodInfo[] name = typeof(SSchockeTest.Kernel).GetMethods();
+ Type xFoundType = typeof(FakeKernel);
+ var xCtor = xFoundType.GetConstructor(Type.EmptyTypes);
+ typeof(Cosmos.System.Plugs.System.System.ConsoleImpl).IsSubclassOf(typeof(object));
+ var xEntryPoint = typeof(Kernel).GetMethod("Start", BindingFlags.Public | BindingFlags.Instance);
+ //var xEntryPoint = typeof(Program).GetMethod("ScannerEntryPoint", BindingFlags.NonPublic | BindingFlags.Static);
+ //EnableLogging(pathToLogFile)
+ xScanner.EnableLogging(logFile);
+ //xScanner.TempDebug += new Action(xScanner_TempDebug);
+ //xScanner.
+ xScanner.QueueMethod(xEntryPoint);
+ xScanner.Execute(xCtor);
+ using (var xOut = new StreamWriter(outFile, false))
+ {
+ //if (EmitDebugSymbols) {
+ xAsmblr.Assembler.FlushText(xOut);
+ xAsmblr.FinalizeDebugInfo();
+ }
+ xSW.Stop();
+ Console.WriteLine("Total time : {0}", xSW.Elapsed);
+ Console.WriteLine("Method count: {0}", xScanner.MethodCount);
+ //Console.WriteLine("Instruction count: {0}", xScanner.InstructionCount);
+ }
+ }
}
static void xScanner_TempDebug(string obj)
@@ -61,4 +96,4 @@ namespace Cosmos.IL2CPU.Profiler {
}
}
-}
+}
\ No newline at end of file
diff --git a/source2/IL2CPU/Cosmos.IL2CPU/ILScanner.cs b/source2/IL2CPU/Cosmos.IL2CPU/ILScanner.cs
index d99efa7ee..13a3102f4 100644
--- a/source2/IL2CPU/Cosmos.IL2CPU/ILScanner.cs
+++ b/source2/IL2CPU/Cosmos.IL2CPU/ILScanner.cs
@@ -372,7 +372,7 @@ namespace Cosmos.IL2CPU {
public int MethodCount {
get {
- return 0;
+ return mMethodUIDs.Count;
}
}
diff --git a/source2/VSIP/Cosmos.VS.Windows/DebuggerUC.cs b/source2/VSIP/Cosmos.VS.Windows/DebuggerUC.cs
index d4af3a860..21f174661 100644
--- a/source2/VSIP/Cosmos.VS.Windows/DebuggerUC.cs
+++ b/source2/VSIP/Cosmos.VS.Windows/DebuggerUC.cs
@@ -10,9 +10,9 @@ namespace Cosmos.VS.Windows {
protected byte[] mData = new byte[0];
public void Update(string aTag, byte[] aData) {
- mData = aData;
Dispatcher.Invoke(DispatcherPriority.Normal,
(Action)delegate() {
+ mData = aData;
DoUpdate(aTag);
}
);
diff --git a/source2/VSIP/Cosmos.VS.Windows/StackUC.xaml.cs b/source2/VSIP/Cosmos.VS.Windows/StackUC.xaml.cs
index bffa855db..ec9175f5f 100644
--- a/source2/VSIP/Cosmos.VS.Windows/StackUC.xaml.cs
+++ b/source2/VSIP/Cosmos.VS.Windows/StackUC.xaml.cs
@@ -59,25 +59,38 @@ namespace Cosmos.VS.Windows {
}
}
- public void UpdateFrame(byte[] aData) {
- var xValues = MemoryViewUC.Split(aData);
- int xCount = xValues.Count;
- memvEBP.Clear();
- for (int i = 0; i < xCount; i++) {
- // We start at EBP + 8, because lower is not transmitted
- // [EBP] is old EBP - not needed
- // [EBP + 4] is saved EIP - not needed
- memvEBP.Add("[EBP + " + (i * 4 + 8) + "]", xValues[i]);
- }
+ public void UpdateFrame(byte[] aData)
+ {
+ System.Windows.Threading.Dispatcher.CurrentDispatcher.Invoke(DispatcherPriority.Normal,
+ (Action)delegate()
+ {
+ var xValues = MemoryViewUC.Split(aData);
+ int xCount = xValues.Count;
+ memvEBP.Clear();
+ for (int i = 0; i < xCount; i++)
+ {
+ // We start at EBP + 8, because lower is not transmitted
+ // [EBP] is old EBP - not needed
+ // [EBP + 4] is saved EIP - not needed
+ memvEBP.Add("[EBP + " + (i * 4 + 8) + "]", xValues[i]);
+ }
+ }
+ );
}
public void UpdateStack(byte[] aData) {
- var xValues = MemoryViewUC.Split(aData);
- int xCount = xValues.Count;
- memvESP.Clear();
- for (int i = 0; i < xCount; i++) {
- memvESP.Add(("[EBP - " + ((xCount - i) * 4) + "]").PadRight(10) + " [ESP + " + (i * 4) + "]", xValues[i]);
- }
+ System.Windows.Threading.Dispatcher.CurrentDispatcher.Invoke(DispatcherPriority.Normal,
+ (Action)delegate()
+ {
+ var xValues = MemoryViewUC.Split(aData);
+ int xCount = xValues.Count;
+ memvESP.Clear();
+ for (int i = 0; i < xCount; i++)
+ {
+ memvESP.Add(("[EBP - " + ((xCount - i) * 4) + "]").PadRight(10) + " [ESP + " + (i * 4) + "]", xValues[i]);
+ }
+ }
+ );
}
}
}
\ No newline at end of file