File: debugger_class_options.pas

package info (click to toggle)
lazarus 2.2.6%2Bdfsg2-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 219,980 kB
  • sloc: pascal: 1,944,919; xml: 357,634; makefile: 270,608; cpp: 57,115; sh: 3,249; java: 609; perl: 297; sql: 222; ansic: 137
file content (716 lines) | stat: -rw-r--r-- 23,247 bytes parent folder | download
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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
{
 ***************************************************************************
 *                                                                         *
 *   This source 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.                                   *
 *                                                                         *
 *   This code 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.                              *
 *                                                                         *
 *   A copy of the GNU General Public License is available on the World    *
 *   Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also      *
 *   obtain it by writing to the Free Software Foundation,                 *
 *   Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1335, USA.   *
 *                                                                         *
 ***************************************************************************
}
unit debugger_class_options;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, TypInfo,
  // LCL
  Forms, Controls, StdCtrls, ExtCtrls, Buttons, Dialogs, ComCtrls, Menus,
  // LazUtils
  FileUtil, LazFileUtils, LazStringUtils, LazFileCache, LazLoggerBase, LazUTF8,
  // DebuggerIntf
  DbgIntfDebuggerBase,
  // IdeIntf
  PropEdits, ObjectInspector, IDEOptionsIntf, IDEOptEditorIntf, IDEUtils,
  GDBMIDebugger,
  // IDE
  TransferMacros, LazarusIDEStrConsts, PathEditorDlg, IDEProcs, DialogProcs,
  InputHistory, EnvironmentOpts, BaseDebugManager, Debugger;

type

  { TDebuggerClassOptionsFrame }

  TDebuggerClassOptionsFrame = class(TAbstractIDEOptionsEditor)
    BtnEditClass: TButton;
    cmbDebuggerPath: TComboBox;
    cmbDebuggerType: TComboBox;
    cmdOpenAdditionalPath: TButton;
    cmdOpenDebuggerPath: TButton;
    edName: TEdit;
    gbAdditionalSearchPath: TGroupBox;
    gbDebuggerSpecific: TGroupBox;
    gbDebuggerType: TGroupBox;
    LblWarnClassChange: TLabel;
    lblName: TLabel;
    Panel1: TPanel;
    tbDropMenu: TPopupMenu;
    ToolBar1: TToolBar;
    tbSelect: TToolButton;
    tbAddNew: TToolButton;
    ToolButton2: TToolButton;
    tbDelete: TToolButton;
    tbCopy: TToolButton;
    ToolButton3: TToolButton;
    txtAdditionalPath: TEdit;
    procedure BtnEditClassClick(Sender: TObject);
    procedure cmbDebuggerPathEditingDone(Sender: TObject);
    procedure cmbDebuggerTypeEditingDone(Sender: TObject);
    procedure cmdOpenAdditionalPathClick(Sender: TObject);
    procedure cmdOpenDebuggerPathClick(Sender: TObject);
    procedure edNameExit(Sender: TObject);
    procedure tbAddNewClick(Sender: TObject);
    procedure tbCopyClick(Sender: TObject);
    procedure tbDeleteClick(Sender: TObject);
  private
    FDebuggerFileHistory: TStringList;
    FInOdNameExit: Boolean;
    PropertyGrid: TOIPropertyGrid;
    FPropertyEditorHook: TPropertyEditorHook;
    FCopiedDbgPropertiesConfigList: TDebuggerPropertiesConfigList;
    FSelectedDbgPropertiesConfig: TDebuggerPropertiesConfig;
    FLastCheckedDebuggerPath: String;
    function SelectedDebuggerClass: TDebuggerClass; // currently shown debugger class
    function SelectedDebuggerProperties: TDebuggerProperties;

    procedure DoNameSelected(Sender: TObject);
    procedure FillDebuggerClassDropDown;
    procedure UpdateDebuggerClass;
    procedure UpdateDebuggerClassDropDown;
    procedure UpdateDebuggerPathHistory;
    procedure FetchDebuggerSpecificOptions;
    function  GetDebuggerClassFromDropDown: TDebuggerClass;
    function  GetUniqueName(AName: String): String;
    procedure ClearDbgProperties;
    procedure FillNameDropDown;
    procedure HookGetCheckboxForBoolean(var Value: Boolean);
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    function Check: Boolean; override;
    function GetTitle: String; override;
    procedure Setup({%H-}ADialog: TAbstractOptionsEditorDialog); override;
    procedure ReadSettings({%H-}AOptions: TAbstractIDEOptions); override;
    procedure WriteSettings({%H-}AOptions: TAbstractIDEOptions); override;
    class function SupportedOptionsClass: TAbstractIDEOptionsClass; override;
  end;

implementation

{$R *.lfm}

{ TDebuggerClassOptionsFrame }

procedure TDebuggerClassOptionsFrame.cmbDebuggerPathEditingDone(Sender: TObject
  );
var
  ParsedFName: String;
begin
  UpdateDebuggerPathHistory;
  if FSelectedDbgPropertiesConfig = nil then
    exit;

  if assigned(SelectedDebuggerClass) and SelectedDebuggerClass.NeedsExePath and
     (FSelectedDbgPropertiesConfig.DebuggerFilename <> cmbDebuggerPath.Text) and
     (FLastCheckedDebuggerPath <> cmbDebuggerPath.Text)
  then begin
    FLastCheckedDebuggerPath := cmbDebuggerPath.Text;
    ParsedFName := EnvironmentOptions.GetParsedValue(eopDebuggerFilename, FLastCheckedDebuggerPath);
    if ParsedFName = '' then
      ParsedFName := FLastCheckedDebuggerPath;
    if not CheckExecutable(FSelectedDbgPropertiesConfig.DebuggerFilename, ParsedFName,
          lisEnvOptDlgInvalidDebuggerFilename,
          lisEnvOptDlgInvalidDebuggerFilenameMsg)
    then
      exit;
  end;

  FSelectedDbgPropertiesConfig.DebuggerFilename := cmbDebuggerPath.Text;
end;

procedure TDebuggerClassOptionsFrame.BtnEditClassClick(Sender: TObject);
begin
  cmbDebuggerType.Enabled := True;
  BtnEditClass.Visible := False;
  LblWarnClassChange.Visible := True;
end;

procedure TDebuggerClassOptionsFrame.cmdOpenAdditionalPathClick(
  Sender: TObject);
begin
  PathEditorDialog.Path:=txtAdditionalPath.Text;
  PathEditorDialog.Templates:=GetForcedPathDelims(
        '$(LazarusDir)/include/$(TargetOS)'
      +';$(FPCSrcDir)/rtl/inc/'
      +';$(FPCSrcDir)/rtl/$(SrcOS)'
      +';$(FPCSrcDir)/rtl/$(TargetOS)'
      );
  if PathEditorDialog.ShowModal=mrOk then
    txtAdditionalPath.Text:=PathEditorDialog.Path;
end;

procedure TDebuggerClassOptionsFrame.cmdOpenDebuggerPathClick(Sender: TObject);
var
  OpenDialog: TOpenDialog;
  AFilename, ParsedFName: string;
  lDirText : string;
  lExpandedName: string; // Expanded name before Dialog
  lDirName, lDirNameF : string;
begin
  if FSelectedDbgPropertiesConfig = nil then
    exit;

  OpenDialog:=TOpenDialog.Create(nil);
  try
    InputHistories.ApplyFileDialogSettings(OpenDialog);
    OpenDialog.Options:=OpenDialog.Options+[ofPathMustExist];
    OpenDialog.Title:=lisChooseDebuggerExecutable;

    lDirName := EnvironmentOptions.GetParsedValue(eopDebuggerFilename, lDirText{%H-});
    lExpandedName := CleanAndExpandFilename(lDirName);
    lDirName := GetValidDirectory(lDirName, {out} lDirNameF);
    OpenDialog.InitialDir := lDirName;
    OpenDialog.FileName := lDirNameF;

    if OpenDialog.Execute then begin
      AFilename:=CleanAndExpandFilename(OpenDialog.Filename);
      ParsedFName := EnvironmentOptions.GetParsedValue(eopDebuggerFilename, AFilename);
      if ParsedFName = '' then
        ParsedFName := AFilename;
      if CheckExecutable(FSelectedDbgPropertiesConfig.DebuggerFilename, ParsedFName,
        lisEnvOptDlgInvalidDebuggerFilename,
        lisEnvOptDlgInvalidDebuggerFilenameMsg)
      then
        if CompareText(lExpandedName, AFilename) <> 0 then begin // Changed ?
          SetComboBoxText(cmbDebuggerPath,AFilename,cstFilename);
          FSelectedDbgPropertiesConfig.DebuggerFilename := AFilename;
        end;
    end;
    InputHistories.StoreFileDialogSettings(OpenDialog);
  finally
    OpenDialog.Free;
  end;
end;

procedure TDebuggerClassOptionsFrame.edNameExit(Sender: TObject);
var
  n: String;
  i: Integer;
begin
  if FSelectedDbgPropertiesConfig = nil then
    exit;
  try
    FInOdNameExit := True;
    n := GetUniqueName(edName.Text);
    if n <> edName.Text then
      edName.Text := n;
    if FSelectedDbgPropertiesConfig.ConfigName <> n then begin
      FSelectedDbgPropertiesConfig.ConfigName := n;
      i := FCopiedDbgPropertiesConfigList.IndexOfObject(FSelectedDbgPropertiesConfig);
      FCopiedDbgPropertiesConfigList[i] := n;
      FillNameDropDown;
    end;
  finally
    FInOdNameExit := False;
  end;
end;

procedure TDebuggerClassOptionsFrame.tbAddNewClick(Sender: TObject);
begin
  UpdateDebuggerPathHistory;
  edNameExit(nil);
  UpdateDebuggerClass;
  cmbDebuggerPathEditingDone(nil);

  FSelectedDbgPropertiesConfig := TDebuggerPropertiesConfig.CreateForDebuggerClass(TGDBMIDebugger);
  FSelectedDbgPropertiesConfig.ConfigName := GetUniqueName(lisNew);
  FCopiedDbgPropertiesConfigList.AddObject(FSelectedDbgPropertiesConfig.ConfigName, FSelectedDbgPropertiesConfig);

  FillNameDropDown;
  UpdateDebuggerClassDropDown;
  FetchDebuggerSpecificOptions;

  cmbDebuggerType.Enabled := True;
  BtnEditClass.Visible := False;
  LblWarnClassChange.Visible := False;
end;

procedure TDebuggerClassOptionsFrame.tbCopyClick(Sender: TObject);
var
  pc: TDebuggerPropertiesConfig;
  s: String;
begin
  UpdateDebuggerPathHistory;
  if FSelectedDbgPropertiesConfig = nil then
    exit;

  edNameExit(nil);
  UpdateDebuggerClass;
  cmbDebuggerPathEditingDone(nil);

  pc := FSelectedDbgPropertiesConfig;
  s := pc.ConfigName;
  if s = '' then
    s := lisNew;
  FSelectedDbgPropertiesConfig := TDebuggerPropertiesConfig.CreateCopy(pc);
  FSelectedDbgPropertiesConfig.ConfigName := GetUniqueName(s);
  FCopiedDbgPropertiesConfigList.AddObject(FSelectedDbgPropertiesConfig.ConfigName, FSelectedDbgPropertiesConfig);

  FillNameDropDown;
  UpdateDebuggerClassDropDown;
  FetchDebuggerSpecificOptions;

  cmbDebuggerType.Enabled := True;
  BtnEditClass.Visible := False;
  LblWarnClassChange.Visible := False;
end;

procedure TDebuggerClassOptionsFrame.tbDeleteClick(Sender: TObject);
var
  i: Integer;
begin
  if FSelectedDbgPropertiesConfig = nil then
    exit;

  i := FCopiedDbgPropertiesConfigList.IndexOfObject(FSelectedDbgPropertiesConfig);
  FSelectedDbgPropertiesConfig.MarkAsDeleted;
  FSelectedDbgPropertiesConfig := nil;
  FCopiedDbgPropertiesConfigList[i] := ''; // remove from named part of list

  FillNameDropDown;
  UpdateDebuggerClassDropDown;
  FetchDebuggerSpecificOptions;
end;

function TDebuggerClassOptionsFrame.SelectedDebuggerClass: TDebuggerClass;
begin
  if FSelectedDbgPropertiesConfig = nil then
    Result := nil
  else
    Result := FSelectedDbgPropertiesConfig.DebuggerClass;
end;

function TDebuggerClassOptionsFrame.SelectedDebuggerProperties: TDebuggerProperties;
begin
  if FSelectedDbgPropertiesConfig = nil then
    Result := nil
  else
    Result := FSelectedDbgPropertiesConfig.DebuggerProperties;
end;

procedure TDebuggerClassOptionsFrame.FillDebuggerClassDropDown;
var
  List: TStringListUTF8Fast;
  i: Integer;
  d: TDebuggerClass;
begin
  List := TStringListUTF8Fast.Create;
  for i := 0 to TBaseDebugManagerIntf.DebuggerCount - 1 do begin
    d := TBaseDebugManagerIntf.Debuggers[i];
    List.AddObject(d.Caption, TObject(d));
  end;
  List.Sorted := True;
  cmbDebuggerType.Items.Assign(List);
  FreeAndNil(List);

  UpdateDebuggerClassDropDown;
end;

procedure TDebuggerClassOptionsFrame.cmbDebuggerTypeEditingDone(
  Sender: TObject);
begin
  UpdateDebuggerClass;
  FetchDebuggerSpecificOptions;
end;

procedure TDebuggerClassOptionsFrame.UpdateDebuggerClass;
var
  c: TDebuggerClass;
begin
  cmbDebuggerType.Enabled := False;
  BtnEditClass.Visible := True;
  LblWarnClassChange.Visible := False;

  if FSelectedDbgPropertiesConfig = nil then
    exit;
  c := GetDebuggerClassFromDropDown;
  if SelectedDebuggerClass = c then
    exit;

  UpdateDebuggerPathHistory;

  FSelectedDbgPropertiesConfig.ChangeDebuggerClass(c, True);
  // TOOD: Ask user?
  FSelectedDbgPropertiesConfig.ConfigName := GetUniqueName(FSelectedDbgPropertiesConfig.ConfigName);
  try
    FInOdNameExit := True;
    edName.Text := FSelectedDbgPropertiesConfig.ConfigName;
  finally
    FInOdNameExit := False;
  end;
  FillNameDropDown;
end;

procedure TDebuggerClassOptionsFrame.UpdateDebuggerClassDropDown;
begin
  if SelectedDebuggerClass = nil
  then SetComboBoxText(cmbDebuggerType, '(none)',cstCaseInsensitive)
  else SetComboBoxText(cmbDebuggerType, SelectedDebuggerClass.Caption,cstCaseInsensitive);
end;

procedure TDebuggerClassOptionsFrame.UpdateDebuggerPathHistory;
var
  i: Integer;
begin
  if FSelectedDbgPropertiesConfig = nil then
    exit;
  i := FDebuggerFileHistory.IndexOf(SelectedDebuggerClass.ExePathsMruGroup.ClassName);
  Assert((i>=0) or (not SelectedDebuggerClass.NeedsExePath), 'Missing dbg lru');
  if i >= 0 then // not found if not NeedExePath
    TStringList(FDebuggerFileHistory.Objects[i]).Assign(cmbDebuggerPath.Items);
end;

procedure TDebuggerClassOptionsFrame.DoNameSelected(Sender: TObject);
var
  idx: PtrInt;
begin
  UpdateDebuggerPathHistory;
  idx := TMenuItem(Sender).Tag;

  edNameExit(nil);
  UpdateDebuggerClass;
  cmbDebuggerPathEditingDone(nil);

  FSelectedDbgPropertiesConfig := FCopiedDbgPropertiesConfigList.Opt[idx];
  FillNameDropDown;

  UpdateDebuggerClassDropDown;
  FetchDebuggerSpecificOptions;
end;

procedure TDebuggerClassOptionsFrame.FetchDebuggerSpecificOptions;
var
  S, S2, S3: String;
  Prop: TDebuggerProperties;
  lru: TStringList;
  i: Integer;
begin
  PropertyGrid.Selection.Clear;

  if FSelectedDbgPropertiesConfig = nil then begin
    cmbDebuggerPath.Items.Clear;
    cmbDebuggerPath.Text := '';
    edName.Text := '';
    PropertyGrid.BuildPropertyList;
    exit;
  end;

  if SelectedDebuggerClass.NeedsExePath then begin
    cmbDebuggerPath.Enabled := True;
    cmdOpenDebuggerPath.Enabled := True;
    i := FDebuggerFileHistory.IndexOf(SelectedDebuggerClass.ExePathsMruGroup.ClassName);
    if i >= 0 then begin
      lru := TStringList(FDebuggerFileHistory.Objects[i]);
    end
    else begin
      lru := TStringList.Create;
      lru.Assign(EnvironmentOptions.DebuggerFileHistory[SelectedDebuggerClass.ExePathsMruGroup.ClassName]);
      FDebuggerFileHistory.AddObject(SelectedDebuggerClass.ExePathsMruGroup.ClassName, lru);
    end;

    with cmbDebuggerPath.Items do begin
      BeginUpdate;
      Assign(lru);
      if  (Count = 0)
      and (SelectedDebuggerClass <> nil)
      then begin
        S := SelectedDebuggerClass.ExePaths;
        while S <> '' do
        begin
          S2 := GetPart([], [';'], S);
          S3 := S2;
          if GlobalMacroList.SubstituteStr(S2)
          then Add(S2)
          else Add(S3);
          if S <> '' then System.Delete(S, 1, 1);
        end;
      end;
      EndUpdate;
    end;

    SetComboBoxText(cmbDebuggerPath,FSelectedDbgPropertiesConfig.DebuggerFilename,cstFilename,20);
  end
  else begin
    cmbDebuggerPath.Items.Clear;
    cmbDebuggerPath.Text := '';
    cmbDebuggerPath.Enabled := False;
    cmdOpenDebuggerPath.Enabled := False;
  end;

  edName.Text := FSelectedDbgPropertiesConfig.ConfigName;

//  txtAdditionalPath.Text:=EnvironmentOptions.GetParsedDebuggerSearchPath;

  // get ptoperties
  Prop := SelectedDebuggerProperties;
  if Prop<>nil then
    PropertyGrid.Selection.Add(Prop);
  PropertyGrid.BuildPropertyList;
end;

function TDebuggerClassOptionsFrame.GetDebuggerClassFromDropDown: TDebuggerClass;
var
  idx: PtrInt;
begin
  Result := nil;

  idx := cmbDebuggerType.ItemIndex;
  if idx = -1 then Exit;
  Result := TDebuggerClass(cmbDebuggerType.Items.Objects[idx]);
end;

function TDebuggerClassOptionsFrame.GetUniqueName(AName: String): String;
  function TrimNumber(s: string): string;
  var
    i: Integer;
  begin
    Result := s;
    i := Length(s);
    if (i=0) or (s[i] <> ')') then
      exit;
    dec(i);
    while (i > 0) and (s[i] in ['0'..'9']) do
      dec(i);
    if (i=0) or (s[i] <> '(') then
      exit;
    dec(i);
    if (i<=1) or (s[i] <> ' ') then
      exit;
    Result := copy(s, 1, i-1);
  end;
var
  i, j: Integer;
begin
  Result := Trim(AName);
  if Result = '' then begin
    i := FCopiedDbgPropertiesConfigList.Count - 1;
    while i >= 0 do
      if (FCopiedDbgPropertiesConfigList[i] <> '') or
         (FCopiedDbgPropertiesConfigList.Opt[i].DebuggerClass <> SelectedDebuggerClass) or
         (FCopiedDbgPropertiesConfigList.Opt[i].IsDeleted) or
         (FCopiedDbgPropertiesConfigList.Opt[i] = FSelectedDbgPropertiesConfig)
      then
        dec(i)
      else
        break;
    if i < 0 then
      exit;
  end
  else begin
    i := FCopiedDbgPropertiesConfigList.IndexOf(Result);
    if (i < 0) or (FCopiedDbgPropertiesConfigList.Opt[i] = FSelectedDbgPropertiesConfig) then
      exit;
  end;

  Result := TrimNumber(Result);
  i := 1;
  repeat
    inc(i);
    j := FCopiedDbgPropertiesConfigList.IndexOf(Result+' ('+IntToStr(i)+')');
    if (j >= 0) and (FCopiedDbgPropertiesConfigList.Opt[j]= FSelectedDbgPropertiesConfig)
    then
      j := -1;
  until j < 0;

  Result := Result+' ('+IntToStr(i)+')';
end;

procedure TDebuggerClassOptionsFrame.ClearDbgProperties;
begin
  PropertyGrid.Selection.Clear;
  FCopiedDbgPropertiesConfigList.ClearAll;
end;

procedure TDebuggerClassOptionsFrame.FillNameDropDown;
var
  m: TMenuItem;
  i: Integer;
begin
  {$IFDEF linux}
  // Workaround for issue https://bugs.freepascal.org/view.php?id=36305 https://bugs.freepascal.org/view.php?id=36306
  tbDropMenu := TPopupMenu.Create(Self);
  tbSelect.DropdownMenu := tbDropMenu;
  {$ENDIF}
  tbDropMenu.Items.Clear;
  for i := 0 to FCopiedDbgPropertiesConfigList.Count - 1 do
    if (not FCopiedDbgPropertiesConfigList.Opt[i].IsDeleted) and
       (FCopiedDbgPropertiesConfigList.Opt[i].IsLoaded)
    then begin
      m := TMenuItem.Create(tbDropMenu);
      m.Caption := FCopiedDbgPropertiesConfigList.Opt[i].DisplayName;
      m.Tag := i;
      m.OnClick := @DoNameSelected;
      m.Checked := FCopiedDbgPropertiesConfigList.Opt[i] = FSelectedDbgPropertiesConfig;
      tbDropMenu.Items.Add(m);
    end;
  if FSelectedDbgPropertiesConfig <> nil then
    tbSelect.Caption := FSelectedDbgPropertiesConfig.DisplayName
  else
    tbSelect.Caption := '---';
  tbSelect.Enabled := FCopiedDbgPropertiesConfigList.Count > 0;
  Panel1.Enabled := FSelectedDbgPropertiesConfig <> nil;
  tbCopy.Enabled := FSelectedDbgPropertiesConfig <> nil;
  tbDelete.Enabled := FSelectedDbgPropertiesConfig <> nil;
end;

procedure TDebuggerClassOptionsFrame.HookGetCheckboxForBoolean(var Value: Boolean);
begin
  Value := EnvironmentOptions.ObjectInspectorOptions.CheckboxForBoolean;
end;

constructor TDebuggerClassOptionsFrame.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  // create the PropertyEditorHook (the interface to the properties)
  FPropertyEditorHook:=TPropertyEditorHook.Create(Self);
  FPropertyEditorHook.AddHandlerGetCheckboxForBoolean(@HookGetCheckboxForBoolean);

  FDebuggerFileHistory := TStringList.Create;
  FDebuggerFileHistory.OwnsObjects := True;
  FCopiedDbgPropertiesConfigList := TDebuggerPropertiesConfigList.Create;
  // create the PropertyGrid
  PropertyGrid:=TOIPropertyGrid.CreateWithParams(Self,FPropertyEditorHook
      ,[tkUnknown, tkInteger, tkChar, tkEnumeration, tkFloat, tkSet{, tkMethod}
      , tkSString, tkLString, tkAString, tkWString, tkVariant
      {, tkArray, tkRecord, tkInterface}, tkClass, tkObject, tkWChar, tkBool
      , tkInt64, tkQWord],
      0);
  with PropertyGrid do
  begin
    Name:='PropertyGrid';
    Parent := gbDebuggerSpecific;
    BorderSpacing.Around := 6;
    Visible := True;
    Align := alClient;
    PreferredSplitterX := 200;
    SplitterX := 200;
    Layout := oilHorizontal;
  end;
end;

destructor TDebuggerClassOptionsFrame.Destroy;
begin
  ClearDbgProperties;
  PropertyGrid.Selection.Clear;
  FreeAndNil(FPropertyEditorHook);
  FreeAndNil(FCopiedDbgPropertiesConfigList);
  FreeAndNil(FDebuggerFileHistory);
  inherited Destroy;
end;

function TDebuggerClassOptionsFrame.Check: Boolean;
begin
  if FSelectedDbgPropertiesConfig = nil then
    exit(True);

  edNameExit(nil);
  UpdateDebuggerClass; // TODO: might edit the name
  FLastCheckedDebuggerPath := 'X'+cmbDebuggerPath.Text; // ensure a new check is done
  cmbDebuggerPathEditingDone(nil);

  Result := (FSelectedDbgPropertiesConfig.DebuggerFilename = cmbDebuggerPath.Text);
end;

function TDebuggerClassOptionsFrame.GetTitle: String;
begin
  Result := lisDebugOptionsFrmBackend;
end;

procedure TDebuggerClassOptionsFrame.Setup(ADialog: TAbstractOptionsEditorDialog);
begin
  tbAddNew.Caption := lisAdd;
  tbCopy.Caption := lisCopy;
  tbDelete.Caption := lisDelete;
  lblName.Caption := lisDebugOptionsFrmName;
  BtnEditClass.Caption := lisDebugOptionsFrmEditClass;
  LblWarnClassChange.Caption := lisDebugOptionsFrmEditClassWarn;
  gbDebuggerType.Caption := dlgDebugType;
  gbAdditionalSearchPath.Caption := lisDebugOptionsFrmAdditionalSearchPath;
  gbDebuggerSpecific.Caption := lisDebugOptionsFrmDebuggerSpecific;
end;

procedure TDebuggerClassOptionsFrame.ReadSettings(AOptions: TAbstractIDEOptions);
var
  i: Integer;
begin
  ClearDbgProperties;
  with EnvironmentOptions do
  begin
    ObjectInspectorOptions.AssignTo(PropertyGrid);

    FDebuggerFileHistory.Clear;
    FCopiedDbgPropertiesConfigList.ClearAll;
    for i := 0 to DebuggerPropertiesConfigList.Count - 1 do
      FCopiedDbgPropertiesConfigList.AddObject(DebuggerPropertiesConfigList[i],
        TDebuggerPropertiesConfig.CreateCopy(DebuggerPropertiesConfigList.Opt[i], True, True) );
    // Find our copy of the current entry
    if CurrentDebuggerPropertiesConfig = nil then
      FSelectedDbgPropertiesConfig := nil
    else
      FSelectedDbgPropertiesConfig := FCopiedDbgPropertiesConfigList.EntryByName(
        CurrentDebuggerPropertiesConfig.ConfigName, CurrentDebuggerPropertiesConfig.ConfigClass);

    FillNameDropDown;
    FillDebuggerClassDropDown;
    FetchDebuggerSpecificOptions;
  end;
end;

procedure TDebuggerClassOptionsFrame.WriteSettings(AOptions: TAbstractIDEOptions);
var
  i: Integer;
  EnvConf: TDebuggerPropertiesConfigList;
begin
  UpdateDebuggerPathHistory;
  with EnvironmentOptions do
  begin
    for i := 0 to FDebuggerFileHistory.Count - 1 do
      DebuggerFileHistory[FDebuggerFileHistory[i]].Assign(TStringList(FDebuggerFileHistory.Objects[i]));

//    DebuggerSearchPath := TrimSearchPath(txtAdditionalPath.Text,'');

    EnvConf := DebuggerPropertiesConfigList;
    EnvConf.ClearAll;
    for i := 0 to FCopiedDbgPropertiesConfigList.Count - 1 do
      EnvConf.AddObject(FCopiedDbgPropertiesConfigList[i],
        TDebuggerPropertiesConfig.CreateCopy(FCopiedDbgPropertiesConfigList.Opt[i], True, True) );
    if FSelectedDbgPropertiesConfig = nil then
      CurrentDebuggerPropertiesConfig := nil
    else
      CurrentDebuggerPropertiesConfig := DebuggerPropertiesConfigList.EntryByName(
        FSelectedDbgPropertiesConfig.ConfigName, FSelectedDbgPropertiesConfig.ConfigClass);
    SaveDebuggerPropertiesList; // Update XML
  end;
end;

class function TDebuggerClassOptionsFrame.SupportedOptionsClass: TAbstractIDEOptionsClass;
begin
  Result := TDebuggerOptions;
end;

initialization
  RegisterIDEOptionsEditor(GroupDebugger, TDebuggerClassOptionsFrame, DbgOptionsGeneral);
end.