Author: gedmurphy
Date: Thu May 28 23:09:41 2009
New Revision: 41187
URL:
http://svn.reactos.org/svn/reactos?rev=41187&view=rev
Log:
- Improve the diagnostics. Now includes function, file and line to assist debugging
- Remove the null checks from DockPanel and wrap it in try/catch blocks instead
(considering it shouldn't happen)
- Use RosDiagnostics.DebugTrace to add debug info now. The app now needs to make correct
use of exception handling
Added:
trunk/tools/reactosdbg/RosDBG/Diagnostics.cs
Modified:
trunk/tools/reactosdbg/RosDBG/MainWindow.cs
trunk/tools/reactosdbg/RosDBG/RosDBG.csproj
Added: trunk/tools/reactosdbg/RosDBG/Diagnostics.cs
URL:
http://svn.reactos.org/svn/reactos/trunk/tools/reactosdbg/RosDBG/Diagnostic…
==============================================================================
--- trunk/tools/reactosdbg/RosDBG/Diagnostics.cs (added)
+++ trunk/tools/reactosdbg/RosDBG/Diagnostics.cs [iso-8859-1] Thu May 28 23:09:41 2009
@@ -1,0 +1,61 @@
+using System;
+using System.IO;
+using System.Diagnostics;
+using System.Windows.Forms;
+
+namespace RosDBG
+{
+ static class RosDiagnostics
+ {
+ public enum TraceType
+ {
+ Info, Error, Exception
+ }
+
+ static public void SetupLogger()
+ {
+ try
+ {
+ if (Convert.ToBoolean(Settings.AppLogging))
+ {
+ File.Delete(Settings.AppLogFile);
+ FileStream traceLogFile = new FileStream(Settings.AppLogFile,
FileMode.OpenOrCreate);
+ Trace.Listeners.Add(new TextWriterTraceListener(traceLogFile));
+ Trace.AutoFlush = true;
+ }
+ }
+ catch (DirectoryNotFoundException)
+ {
+ MessageBox.Show(String.Format("Logging: {0} does not exist.\n"
+
+ "Please use the settings dialog to
correct this",
+ Settings.AppLogFile));
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(String.Format("Failed to setup logging. Unexpected
error:\n {0}",
+ ex.Message));
+ }
+ }
+
+ static public void DebugTrace(TraceType type, string msg)
+ {
+ StackTrace st = new StackTrace(true);
+ StackFrame sf = st.GetFrame(1);
+
+ string typeStr = "";
+ switch (type)
+ {
+ case TraceType.Info: typeStr = "Info"; break;
+ case TraceType.Error: typeStr = "Err"; break;
+ case TraceType.Exception: typeStr = "Exception"; break;
+ }
+
+ Trace.WriteLine(String.Format("{0, -9} : {1} {2}:{3} {4}",
+ typeStr,
+ msg,
+ sf.GetMethod().Name,
+ sf.GetFileName(),
+ sf.GetFileLineNumber()));
+ }
+ }
+}
Modified: trunk/tools/reactosdbg/RosDBG/MainWindow.cs
URL:
http://svn.reactos.org/svn/reactos/trunk/tools/reactosdbg/RosDBG/MainWindow…
==============================================================================
--- trunk/tools/reactosdbg/RosDBG/MainWindow.cs [iso-8859-1] (original)
+++ trunk/tools/reactosdbg/RosDBG/MainWindow.cs [iso-8859-1] Thu May 28 23:09:41 2009
@@ -46,27 +46,9 @@
InitializeComponent();
// Setup the logger
- try
- {
- if (Convert.ToBoolean(Settings.AppLogging))
- {
- File.Delete(Settings.AppLogFile);
- FileStream traceLogFile = new FileStream(Settings.AppLogFile,
FileMode.OpenOrCreate);
- Trace.Listeners.Add(new TextWriterTraceListener(traceLogFile));
- Trace.AutoFlush = true;
- }
- }
- catch (DirectoryNotFoundException)
- {
- MessageBox.Show(String.Format("Logging: {0} does not exist.\n"
+
- "Please use the settings dialog to
correct this",
- Settings.AppLogFile));
- }
- catch (Exception ex)
- {
- MessageBox.Show(String.Format("Failed to setup logging. Unexpected
error:\n {0}",
- ex.Message));
- }
+ RosDiagnostics.SetupLogger();
+
+ RosDiagnostics.DebugTrace(RosDiagnostics.TraceType.Info, "Initialising
application");
mSymbolContext = new SymbolContext();
@@ -177,6 +159,7 @@
private void MainWindowMDI_FormClosing(object sender, FormClosingEventArgs e)
{
+ RosDiagnostics.DebugTrace(RosDiagnostics.TraceType.Info, "Closing
application");
mConnection.Close(true);
}
@@ -371,7 +354,7 @@
private void dockPanel_ActiveDocumentChanged(object sender, EventArgs e)
{
- if ((dockPanel != null) && (dockPanel.ActiveDocument != null))
+ try
{
ToolWindow Wnd = (ToolWindow)dockPanel.ActiveDocument.DockHandler.Form;
@@ -381,6 +364,14 @@
printToolStripButton.Enabled =
Wnd.IsCmdEnabled(ToolWindow.Commands.Print);
printToolStripMenuItem.Enabled =
Wnd.IsCmdEnabled(ToolWindow.Commands.Print);
}
+ catch (NullReferenceException ex)
+ {
+ RosDiagnostics.DebugTrace(RosDiagnostics.TraceType.Exception, "Null
reference : " + ex.Message);
+ }
+ catch (Exception)
+ {
+ RosDiagnostics.DebugTrace(RosDiagnostics.TraceType.Exception,
"Unexpected error");
+ }
}
}
Modified: trunk/tools/reactosdbg/RosDBG/RosDBG.csproj
URL:
http://svn.reactos.org/svn/reactos/trunk/tools/reactosdbg/RosDBG/RosDBG.csp…
==============================================================================
--- trunk/tools/reactosdbg/RosDBG/RosDBG.csproj [iso-8859-1] (original)
+++ trunk/tools/reactosdbg/RosDBG/RosDBG.csproj [iso-8859-1] Thu May 28 23:09:41 2009
@@ -97,6 +97,7 @@
<Compile Include="Connect.Designer.cs">
<DependentUpon>Connect.cs</DependentUpon>
</Compile>
+ <Compile Include="Diagnostics.cs" />
<Compile Include="Dockable Objects\BackTrace.cs">
<SubType>Form</SubType>
</Compile>