Menu

[327ada]: / Source / CPUFrm.pas  Maximize  Restore  History

Download this file

343 lines (292 with data), 10.0 kB

  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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
{
This file is part of Dev-C++
Copyright (c) 2004 Bloodshed Software
Dev-C++ is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Dev-C++ is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Dev-C++; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
}
unit CPUFrm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Math, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, SynEdit, SynEditTypes, ClipBrd, StrUtils, ComCtrls, ExtCtrls, Menus;
type
TCPUForm = class(TForm)
edFunc: TComboBox;
lblFunc: TLabel;
CodeList: TSynEdit;
RegisterListbox: TListView;
DisasPanel: TPanel;
StackTrace: TListView;
RadioATT: TRadioButton;
RadioIntel: TRadioButton;
lblBacktrace: TLabel;
CPUPopup: TPopupMenu;
CPUCopy: TMenuItem;
CPUCopyAll: TMenuItem;
CPUPaste: TMenuItem;
CPUCut: TMenuItem;
N2: TMenuItem;
CPUSelectAll: TMenuItem;
RegPanel: TPanel;
TracePanel: TPanel;
VertSplit: TSplitter;
HorzSplit: TSplitter;
LeftPanel: TPanel;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure edFuncKeyPress(Sender: TObject; var Key: Char);
procedure FormCreate(Sender: TObject);
procedure gbSyntaxClick(Sender: TObject);
procedure CPUCopyClick(Sender: TObject);
procedure CPUCopyAllClick(Sender: TObject);
procedure CPUPasteClick(Sender: TObject);
procedure CPUCutClick(Sender: TObject);
procedure StackTraceClick(Sender: TObject);
procedure CPUSelectAllClick(Sender: TObject);
procedure FormShow(Sender: TObject);
private
fRegisters: TList;
fAssembler: TStringList;
fBacktrace: TList;
procedure LoadText;
public
procedure OnAssemblerReady;
procedure OnRegistersReady;
procedure OnBacktraceReady;
end;
var
CPUForm: TCPUForm = nil;
implementation
uses
main, version, MultiLangSupport, debugger, debugreader, DataFrm, utils,
devcfg, editor, Types;
{$R *.dfm}
procedure TCPUForm.FormClose(Sender: TObject; var Action: TCloseAction);
var
I: integer;
begin
for I := 0 to fRegisters.Count - 1 do
Dispose(PRegister(fRegisters.Items[I]));
fRegisters.Free;
fAssembler.Free;
for I := 0 to fBacktrace.Count - 1 do
Dispose(PTrace(fBacktrace.Items[I]));
fBackTrace.Free;
// Clear contents of the debug reader
MainForm.Debugger.Reader.Registers := nil;
MainForm.Debugger.Reader.Disassembly := nil;
MainForm.Debugger.Reader.Backtrace := nil;
// Save column widths of registerbox
devData.CPURegisterCol1 := RegisterListbox.Column[0].Width;
devData.CPURegisterCol2 := RegisterListbox.Column[1].Width;
devData.CPURegisterCol3 := RegisterListbox.Column[2].Width;
Action := caFree;
CPUForm := nil;
end;
procedure TCPUForm.edFuncKeyPress(Sender: TObject; var Key: Char);
var
propercmd: String;
begin
if MainForm.Debugger.Executing then begin
if Key = Chr(VK_RETURN) then begin
Key := #0;
// Although GDB omits void inside () in its own output, it only accepts C style empty parameter lists for input...
propercmd := edFunc.Text;
if EndsStr('()', propercmd) then
propercmd := ReplaceLastStr(propercmd, '()', '(void)');
MainForm.Debugger.SendCommand('disas', propercmd);
if (Length(edFunc.Text) > 0) and (edFunc.Items.IndexOf(edFunc.Text) = -1) then
edFunc.AddItem(edFunc.Text, nil);
end;
end;
end;
procedure TCPUForm.LoadText;
begin
// Set interface font
Font.Name := devData.InterfaceFont;
Font.Size := devData.InterfaceFontSize;
Caption := Lang[ID_CPU_CAPTION];
lblFunc.Caption := Lang[ID_CPU_FUNC];
lblBacktrace.Caption := Lang[ID_DEB_BACKTRACE];
CPUCut.Caption := Lang[ID_ITEM_CUT];
CPUCopy.Caption := Lang[ID_ITEM_COPY];
CPUCopyAll.Caption := Lang[ID_ITEM_COPYALL];
CPUPaste.Caption := Lang[ID_ITEM_PASTE];
CPUSelectAll.Caption := Lang[ID_ITEM_SELECTALL];
end;
procedure TCPUForm.OnBacktraceReady;
var
I: integer;
item: TListItem;
begin
StackTrace.Items.BeginUpdate;
StackTrace.Clear;
for I := 0 to fBacktrace.Count - 1 do begin
item := StackTrace.Items.Add;
item.Caption := PTrace(fBacktrace.Items[I])^.funcname;
item.SubItems.Add(PTrace(fBacktrace.Items[I])^.filename);
item.SubItems.Add(PTrace(fBacktrace.Items[I])^.line);
end;
StackTrace.Items.EndUpdate;
// Free list for reuse
for I := 0 to fBacktrace.Count - 1 do
Dispose(PTrace(fBacktrace.Items[I]));
fBacktrace.Clear;
end;
procedure TCPUForm.OnAssemblerReady;
var
I, activeline: integer;
begin
activeline := -1;
edFunc.Text := fAssembler.Strings[0];
CodeList.BeginUpdate;
try
CodeList.Clear;
for I := 1 to fAssembler.Count - 1 do begin
CodeList.Lines.Add(fAssembler.Strings[i]);
if StartsStr('=>', fAssembler.Strings[i]) then
activeline := i + 1;
end;
finally
CodeList.EndUpdate;
end;
// Free list for reuse
fAssembler.Clear;
if activeline <> -1 then
CodeList.CaretXY := BufferCoord(1, activeline);
end;
procedure TCPUForm.OnRegistersReady;
var
item: TListItem;
I: integer;
begin
RegisterListbox.Items.BeginUpdate;
RegisterListBox.Clear;
for I := 0 to fRegisters.Count - 1 do begin
item := RegisterListbox.Items.Add;
item.Caption := UpperCase(PRegister(fRegisters.Items[I])^.name);
item.SubItems.Add(PRegister(fRegisters.Items[I])^.valuehex);
item.SubItems.Add(PRegister(fRegisters.Items[I])^.valuedec);
end;
RegisterListBox.Items.EndUpdate;
// Free list for reuse
for I := 0 to fRegisters.Count - 1 do
Dispose(PRegister(fRegisters.Items[I]));
fRegisters.Clear;
end;
procedure TCPUForm.FormCreate(Sender: TObject);
begin
LoadText;
// Make it look a bit like a regular editor
devEditor.AssignEditor(CodeList,'main.cpp');
RadioATT.Checked := devData.UseATTSyntax;
RadioIntel.Checked := not devData.UseATTSyntax;
fRegisters := TList.Create;
fAssembler := TStringList.Create;
fBacktrace := TList.Create;
if MainForm.Debugger.Executing then begin
// Load the registers...
MainForm.Debugger.Reader.Registers := fRegisters;
MainForm.Debugger.SendCommand('info', 'registers');
// Set disassembly flavor and load the current function
MainForm.Debugger.Reader.Disassembly := fAssembler;
if devData.UseATTSyntax then // gbSyntaxClick has NOT been called yet...
gbSyntaxClick(nil);
// Obtain stack trace too
MainForm.Debugger.Reader.Backtrace := fBacktrace;
MainForm.Debugger.SendCommand('backtrace', '');
end;
end;
procedure TCPUForm.gbSyntaxClick(Sender: TObject);
var
key: Char;
begin
// Set disassembly flavor
if RadioAtt.Checked then begin
MainForm.Debugger.SendCommand('set disassembly-flavor', 'att');
RadioIntel.Checked := false;
devData.UseATTSyntax := true;
end else if RadioIntel.Checked then begin
MainForm.Debugger.SendCommand('set disassembly-flavor', 'intel');
RadioAtt.Checked := false;
devData.UseATTSyntax := false;
end;
// load the current function
key := Chr(VK_RETURN);
edFuncKeyPress(nil, key);
end;
procedure TCPUForm.CPUCutClick(Sender: TObject);
begin
if edFunc.Focused then begin
ClipBoard.AsText := edFunc.SelText;
edFunc.SelText := '';
end;
end;
procedure TCPUForm.CPUCopyClick(Sender: TObject);
begin
if edFunc.Focused then
ClipBoard.AsText := edFunc.SelText
else if CodeList.Focused then
CodeList.CopyToClipboard
else if StackTrace.Focused then
Clipboard.AsText := GetPrettyLine(StackTrace)
else if RegisterListbox.Focused then
Clipboard.AsText := GetPrettyLine(RegisterListbox);
end;
procedure TCPUForm.CPUCopyAllClick(Sender: TObject);
var
i: integer;
begin
if edFunc.Focused then
ClipBoard.AsText := edFunc.Text
else if CodeList.Focused then
CodeList.CopyToClipboard
else if StackTrace.Focused then begin
ClipBoard.AsText := '';
for i := 0 to pred(StackTrace.Items.Count) do
Clipboard.AsText := Clipboard.AsText + GetPrettyLine(StackTrace, i) + #13#10;
end else if RegisterListbox.Focused then begin
ClipBoard.AsText := '';
for i := 0 to pred(RegisterListbox.Items.Count) do
Clipboard.AsText := Clipboard.AsText + GetPrettyLine(RegisterListbox, i) + #13#10;
end;
end;
procedure TCPUForm.CPUPasteClick(Sender: TObject);
begin
if edFunc.Focused then
edFunc.SelText := ClipBoard.AsText;
end;
procedure TCPUForm.CPUSelectAllClick(Sender: TObject);
begin
if edFunc.Focused then
edFunc.SelectAll;
end;
procedure TCPUForm.StackTraceClick(Sender: TObject);
var
sel: TListItem;
e: TEditor;
begin
sel := StackTrace.Selected;
if Assigned(sel) then begin
e := MainForm.EditorList.GetEditorFromFileName(sel.SubItems[0]);
if Assigned(e) then begin
e.SetCaretPosAndActivate(StrToIntDef(sel.SubItems[1], 1), 1);
end;
end;
end;
procedure TCPUForm.FormShow(Sender: TObject);
begin
// Get column widths of registerbox
RegisterListbox.Column[0].Width := devData.CPURegisterCol1;
RegisterListbox.Column[1].Width := devData.CPURegisterCol2;
RegisterListbox.Column[2].Width := devData.CPURegisterCol3;
end;
end.
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.