-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMainWindow.xaml.cs
239 lines (203 loc) · 9.2 KB
/
MainWindow.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
using Microsoft.Win32;
using System.Configuration;
using System.Windows;
using System.Windows.Controls.Primitives;
using System.Windows.Controls;
using static System.Net.Mime.MediaTypeNames;
using System.IO;
using ICSharpCode.AvalonEdit;
using System.Linq.Expressions;
using System;
using Microsoft.VisualBasic.ApplicationServices;
using System.Windows.Threading;
using System.Reflection;
namespace ESPEDfGK
{
//*****************************************************************************************
public partial class MainWindow : Window
{
Konfiguration konfiguration = null;
KonfigurationsHlpr hlpr = new();
HighlightCurrentLineBackgroundRenderer HCLBR;
//*****************************************************************************************
public MainWindow()
{
InitializeComponent();
Title = Title + " " + Assembly.GetExecutingAssembly().GetName().Version;
konfiguration = hlpr.LadeEinstellungen();
new ExceptionLogger(konfiguration.LoggerDateiname());
uiScaler.ScaleX = konfiguration.Ink(konfiguration.UIScale, 1.0);
uiScaler.ScaleY = konfiguration.Ink(konfiguration.UIScale, 1.0);
Top = konfiguration.Ink(konfiguration.Top, Top);
Left = konfiguration.Ink(konfiguration.Left, Left);
Height = konfiguration.Ink(konfiguration.Height, Height);
Width = konfiguration.Ink(konfiguration.Width, Width);
// Zeile visualisieren
HCLBR = new HighlightCurrentLineBackgroundRenderer(TBSourceCodeFilecontent);
TBSourceCodeFilecontent.TextArea.TextView.BackgroundRenderers.Add(HCLBR);
LBStyleInfo.Content = null;
LBExceptionInfo.Content = null;
CBsearchpathSketch.IsChecked = konfiguration.ElfFileSearchSpaceSketch == true;
CBsearchpathTEMP.IsChecked = konfiguration.ElfFileSearchSpaceTEMP == true;
tbaddr2line.Text = konfiguration.Addr2LineExe;
TBStackdump.Text = konfiguration.Stackdump;
TBElffile.Text = konfiguration.ElfFile;
TBStackdump.Height = konfiguration.Ink(konfiguration.SplitHeight, TBStackdump.Height);
}
//*****************************************************************************************
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
konfiguration.Top = Top;
konfiguration.Left = Left;
konfiguration.Height = Height;
konfiguration.Width = Width;
konfiguration.UIScale = uiScaler.ScaleX;
konfiguration.Addr2LineExe = tbaddr2line.Text;
konfiguration.Stackdump = TBStackdump.Text;
konfiguration.ElfFile = TBElffile.Text;
konfiguration.SplitHeight = TBStackdump.Height;
konfiguration.ElfFileSearchSpaceSketch = CBsearchpathSketch.IsChecked == true;
konfiguration.ElfFileSearchSpaceTEMP = CBsearchpathTEMP.IsChecked == true;
hlpr.SpeichereEinstellungen(konfiguration);
}
//*****************************************************************************************
private void BTSelectExecutable(object sender, RoutedEventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "Executable (*.exe)|*.exe|All files (*.*)|*.*";
if (ofd.ShowDialog() == true)
tbaddr2line.Text = ofd.FileName;
}
//*****************************************************************************************
private void BTFindExecutable(object sender, RoutedEventArgs e)
{
SetupHelper sh = new SetupHelper();
tbaddr2line.ItemsSource = sh.findAddr2LineExe();
tbaddr2line.SelectedIndex = 0;
tbaddr2line.IsDropDownOpen = true;
}
//*****************************************************************************************
private void BTSelectElffile(object sender, RoutedEventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "Elf-File (*.elf)|*.elf|All files (*.*)|*.*";
if (ofd.ShowDialog() == true)
TBElffile.Text = ofd.FileName;
}
//*****************************************************************************************
private void BTFindElffile(object sender, RoutedEventArgs e)
{
ElfListGetter getter = new();
TBElffile.DataContext = getter.GetFileList(
CBsearchpathSketch.IsChecked == true, CBsearchpathTEMP.IsChecked == true);
TBElffile.SelectedIndex = 0;
TBElffile.IsDropDownOpen = true;
}
//*****************************************************************************************
private void BTAnalyze(object sender, RoutedEventArgs e)
{
if (File.Exists(tbaddr2line.Text))
{
Addr2LineDecider decider = new();
Addr2LineBase? analyzer = decider.Decide(TBStackdump.Text);
if (analyzer == null)
{
LBStyleInfo.Content = "unable to analyze.";
return;
}
LBStyleInfo.Content = "CPU is: " + analyzer.AnalyserType();
analyzer.Execute(tbaddr2line.Text, TBElffile.Text, TBStackdump.Text);
BTnCopyToClipboard.IsEnabled = true;
LBExceptionList.ItemsSource = null;
LBExceptionList.Items.Clear(); // der xaml-code könnnte daten liefern....
LBExceptionList.ItemsSource = analyzer.DataList;
// Exception Ursache
if (analyzer.exceptioncause != null)
{
LBExceptionInfo.Content = "EC: " + analyzer.exceptioncause.Description;
}
else
{
LBExceptionInfo.Content = "";
}
// Wenn nix rauskommt, dann das Ausführungsergebnis anzeigen
if (analyzer.DataList.Count == 0)
{
TBSourceCodeFilecontent.Text = analyzer.addr2lineoutputresult;
}
else
{
TBSourceCodeFilecontent.Text = "";
}
}
else
{
LBStyleInfo.Content = "Settings: addr2line is invalid.";
BTnCopyToClipboard.IsEnabled = true;
}
}
//*****************************************************************************************
private int ParseLineNumber(string line)
{
int i=line.IndexOf(" (");
if (i >= 0)
{
line=line.Substring(0, i).Trim();
}
return int.Parse(line);
}
//*****************************************************************************************
private void SenderDoppelClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
TraceItem? item = ((ListViewItem)sender).Content as TraceItem;
if (item != null)
{
string scf = item.SourcecodeFile;
scf = scf.Replace("/", "\\");
if (File.Exists(scf))
{
int linenr = ParseLineNumber(item.SourcecodeLine);
HCLBR.LineNumber = linenr;
try
{
TBSourceCodeFilecontent.Text = File.ReadAllText(scf);
TBSourceCodeFilecontent.ScrollTo(linenr, 0);
}
catch
{
TBSourceCodeFilecontent.Text = "Can not access file.";
}
}
}
}
//*****************************************************************************************
private void BTCopyToClipboard(object sender, RoutedEventArgs e)
{
string clpboardtext = (string)LBStyleInfo.Content +
Environment.NewLine +
LBExceptionInfo.Content +
Environment.NewLine + Environment.NewLine;
foreach (TraceItem ti in LBExceptionList.ItemsSource)
{
clpboardtext += ti.Addr+" "+
ti.Name + " "+
ti.SourcecodeFile + " "+
ti.SourcecodeLine + " "+
Environment.NewLine;
}
Clipboard.SetText(clpboardtext);
// Visuelle Rückkopplung der Aktion
BTnCopyToClipboard.Visibility= Visibility.Collapsed;
BTnCopyToClipboardDone.Visibility= Visibility.Visible;
DispatcherTimer timer = new();
timer.Interval = TimeSpan.FromSeconds(2);
timer.Tick += (s, a) =>
{
BTnCopyToClipboard.Visibility = Visibility.Visible;
BTnCopyToClipboardDone.Visibility = Visibility.Collapsed;
timer.Stop();
};
timer.Start();
}
}
}