debug fixes

This commit is contained in:
mterwoord_cp 2008-04-02 17:16:09 +00:00
parent d382dfbdc8
commit b16eaf1dda
7 changed files with 125 additions and 6 deletions

View file

@ -88,6 +88,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="ViewSourceWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<Compile Include="Builder.cs" />
@ -117,6 +121,9 @@
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<Compile Include="SourceInfo.cs" />
<Compile Include="ViewSourceWindow.xaml.cs">
<DependentUpon>ViewSourceWindow.xaml</DependentUpon>
</Compile>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>

View file

@ -6,6 +6,6 @@
<TextBlock Height="79" Name="textBlock1" VerticalAlignment="Top" TextWrapping="WrapWithOverflow">This is the debug window. Coming soon! For now, leave me open until you are done. Close and the application will terminate.</TextBlock>
<Label Height="28" Margin="11,55,140,0" Name="label1" VerticalAlignment="Top">Executing Instruction Pointer(EIP):</Label>
<Label Height="28" Margin="0,55,14,0" Name="lablEIP" VerticalAlignment="Top" HorizontalAlignment="Right" Width="126"></Label>
<ListBox FontFamily="Consolas" Margin="10,84,14,8" Name="lboxLog" />
<ListBox FontFamily="Consolas" Margin="10,84,14,8" Name="lboxLog" MouseDoubleClick="lboxLog_MouseDoubleClick" />
</Grid>
</Window>

View file

@ -14,6 +14,7 @@ using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Threading;
using Indy.IL2CPU;
using System.IO;
namespace Cosmos.Build.Windows {
public partial class DebugWindow: Window {
@ -76,13 +77,92 @@ namespace Cosmos.Build.Windows {
mCurrentPos = 0;
UInt32 xEIP = (UInt32)((mTCPData[0] << 24) | (mTCPData[1] << 16) | (mTCPData[2] << 8) | mTCPData[3]);
xStream.BeginRead(mTCPData, 0, mTCPData.Length, new AsyncCallback(TCPRead), xStream);
Dispatcher.BeginInvoke(DispatcherPriority.Normal, new DebugPacketRcvdDelegate(DebugPacketRcvd), xEIP);
Dispatcher.BeginInvoke(DispatcherPriority.Background, new DebugPacketRcvdDelegate(DebugPacketRcvd), xEIP);
} catch (System.IO.IOException ex) {
Dispatcher.BeginInvoke(DispatcherPriority.Normal, new ConnectionLostDelegate(ConnectionLost), ex);
Dispatcher.BeginInvoke(DispatcherPriority.Background, new ConnectionLostDelegate(ConnectionLost), ex);
}
}
private static void GetLineInfo(string aData, int aLineStart, int aColumnStart, int aLineEnd, int aColumnEnd, out int oCharStart, out int oCharCount) {
int xCurrentPos = 0;
int xCurrentLine = 1;
oCharCount = 0;
oCharStart = 0;
while (xCurrentPos < aData.Length) {
int xTempPos = aData.IndexOfAny(new char[] { '\r', '\n' }, xCurrentPos);
if (xTempPos == -1) {
if (oCharStart > 0) {
oCharCount = xCurrentPos - oCharStart;
}
return;
}
xCurrentLine += 1;
xCurrentPos = xTempPos;
if (aData[xCurrentPos] == '\r' && aData.Length > (xCurrentPos + 1) && aData[xCurrentPos + 1] == '\n') {
xCurrentPos += 2;
} else {
xCurrentPos += 1;
}
if (xCurrentLine == aLineStart) {
oCharStart = xCurrentPos + aColumnStart;
}
if (xCurrentLine == aLineEnd) {
oCharCount = (xCurrentPos + aColumnEnd) - oCharStart;
}
if (oCharCount > 0 && oCharStart > 0) {
return;
}
}
}
private void lboxLog_MouseDoubleClick(object sender, MouseButtonEventArgs e) {
var xItem = lboxLog.SelectedItem;
string xItemStr = xItem as String;
if (MessageBox.Show("Do you want to do analysis? (Press no if you dont know)", "Debug", MessageBoxButton.YesNo) != MessageBoxResult.Yes) {
if (!String.IsNullOrEmpty(xItemStr)) {
if (mDebugMode == DebugModeEnum.Source) {
var xSourceInfo = mSourceMappings.GetMapping(UInt32.Parse(xItemStr.Substring(2), System.Globalization.NumberStyles.HexNumber));
var xViewSrc = new ViewSourceWindow();
//int xCharStart;
//int xCharCount;
//GetLineInfo(xViewSrc.tboxSource.Text, xSourceInfo.Line, xSourceInfo.Column, xSourceInfo.LineEnd, xSourceInfo.ColumnEnd, out xCharStart, out xCharCount);
//if(
int xCharStart = xViewSrc.tboxSource.GetCharacterIndexFromLineIndex(xSourceInfo.Line);
int xCharEnd = xViewSrc.tboxSource.GetCharacterIndexFromLineIndex(xSourceInfo.LineEnd);
xCharStart += xSourceInfo.Column;
xCharEnd += xSourceInfo.ColumnEnd;
xViewSrc.tboxSource.Text = File.ReadAllText(xSourceInfo.SourceFile);
xViewSrc.tboxSource.ScrollToLine(xSourceInfo.Line);
xViewSrc.tboxSource.Select(xCharStart, xCharEnd - xCharStart);
xViewSrc.ShowDialog();
} else {
throw new Exception("Debug mode not supported!");
}
//xViewSrc.tboxSource.s
}
} else {
var xViewSrc = new ViewSourceWindow();
foreach (var xEIP in (from item in lboxLog.Items.Cast<string>()
select item).Distinct(StringComparer.InvariantCultureIgnoreCase)) {
var xSourceInfo = mSourceMappings.GetMapping(UInt32.Parse(xEIP.Substring(2), System.Globalization.NumberStyles.HexNumber));
if (xSourceInfo == null) {
//MessageBox.Show("No source found for " + xEIP);
continue;
}
//var xViewSrc = new ViewSourceWindow();
//int xCharStart;
//int xCharCount;
//GetLineInfo(xViewSrc.tboxSource.Text, xSourceInfo.Line, xSourceInfo.Column, xSourceInfo.LineEnd, xSourceInfo.ColumnEnd, out xCharStart, out xCharCount);
//if(
int xCharStart = xViewSrc.tboxSource.GetCharacterIndexFromLineIndex(xSourceInfo.Line);
int xCharEnd = xViewSrc.tboxSource.GetCharacterIndexFromLineIndex(xSourceInfo.LineEnd);
if ((xCharEnd - xCharStart) > 4) {
MessageBox.Show(xEIP);
break;
}
}
}
}
}
}

View file

@ -57,7 +57,6 @@ namespace Cosmos.Build.Windows {
} else {
throw new Exception("Debug mode not supported!");
}
xDebugWindow.ShowDialog();
}
}

View file

@ -10,8 +10,8 @@ using Indy.IL2CPU.IL;
namespace Cosmos.Build.Windows {
public class SourceInfos: SortedList<uint, SourceInfo> {
public SourceInfo GetIndexClosestSmallerMatch(uint aValue) {
for (int i = 0; i < Count; i++) {
public SourceInfo GetMapping(uint aValue) {
for (int i = Count - 1; i >=0; i--) {
if (Keys[i] <= aValue) {
return Values[i];
} else {

View file

@ -0,0 +1,10 @@
<Window x:Class="Cosmos.Build.Windows.ViewSourceWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="View Source" Height="500" Width="500">
<TextBox
x:Name="tboxSource"
HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Auto"
IsReadOnly="True" />
</Window>

View file

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace Cosmos.Build.Windows {
/// <summary>
/// Interaction logic for ViewSourceWindow.xaml
/// </summary>
public partial class ViewSourceWindow: Window {
public ViewSourceWindow() {
InitializeComponent();
}
}
}