From f1c6b38c384fedc09a0d9f5b8641225828705bfc Mon Sep 17 00:00:00 2001 From: Basile Burg Date: Sun, 17 Sep 2023 13:03:13 +0200 Subject: [PATCH] add a MRU for the customized executable used in gdb commander --- CHANGELOG.md | 1 + src/u_gdb.pas | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 87 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b4cbcc1b..cf58b930 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Enhancements - Editor, added the _Undo All_ action. +- GDB Commander, custom executables selected for debugging are now stored in a persistent MRU list. ## Bugx fixed diff --git a/src/u_gdb.pas b/src/u_gdb.pas index 62adefea..8c03b619 100644 --- a/src/u_gdb.pas +++ b/src/u_gdb.pas @@ -8,7 +8,7 @@ uses Classes, SysUtils, FileUtil, Forms, Controls, Graphics, RegExpr, ComCtrls, PropEdits, GraphPropEdits, RTTIGrids, Dialogs, ExtCtrls, Menus, Buttons, StdCtrls, process, fpjson, typinfo, {$IFDEF UNIX}Unix,{$ELSE} Windows,{$ENDIF} - ListViewFilterEdit, SynEdit, ObjectInspector, math, + ListViewFilterEdit, SynEdit, ObjectInspector, math, u_mru, u_common, u_interfaces, u_widget, u_processes, u_observer, u_synmemo, u_sharedres, u_stringrange, u_dsgncontrols, u_dialogs, u_dbgitf, u_ddemangle, u_writableComponent, EditBtn, strutils, u_controls; @@ -319,11 +319,13 @@ type fGdbPath: TFilename; fUseCustomCommandsHistory: boolean; fAutoDotCompletion: boolean; + fDebugRecentMru: TMRUFileList; procedure setIgnoredSignals(value: TStringList); procedure setCommandsHistory(value: TStringList); procedure setCustomEvalHistory(value: TStringList); procedure setShortcuts(value: TDebugShortcuts); procedure setMaxCallStackDepth(value: integer); + procedure setDebugRecentMru(value: TMRUFileList); procedure cleanInvalidHistoryEntries; published property asmSyntax: TAsmSyntax read fAsmSyntax write fAsmSyntax; @@ -338,6 +340,7 @@ type property coreBreakingSymbols: TDlangBreakpoints read fDlangBreakpoints write fDlangBreakpoints; property currentEvalKind: TGdbEvalKind read fCurrentEvalKind write fCurrentEvalKind; property customEvalHistory: TStringList read fCustomEvalHistory write setCustomEvalHistory; + property debugRecentMru: TMRUFileList read fDebugRecentMru write setDebugRecentMru; property gdbPath: TFilename read fGdbPath write fGdbPath; property hideCpuView: boolean read fHideCpuView write fHideCpuView default false; property ignoredSignals: TStringList read fIgnoredSignals write setIgnoredSignals; @@ -437,6 +440,7 @@ type Edit1: TComboBox; GroupBox3: TGroupBox; lstThreads: TListView; + mnuDebugRecent: TMenuItem; mnuSelCustom: TMenuItem; mnuEvalDeref: TMenuItem; mnuEvalSelected: TMenuItem; @@ -604,6 +608,10 @@ type function evaluate(const exp: string): string; procedure executeFromShortcut(sender: TObject); procedure itemCompletetionClick(sender: TObject); + procedure mruDebugRecentChange(Sender: TObject); + procedure mruDebugRecentClick(Sender: TObject); + procedure mruDebugRecentClearClick(Sender: TObject); + procedure mruDebugRecentDeleteInvalidClick(Sender: TObject); public constructor create(aOwner: TComponent); override; destructor destroy; override; @@ -717,6 +725,7 @@ begin fCustomEvalHistory := TstringList.Create; fCustomEvalHistory.Duplicates:= dupIgnore; fCustomEvalHistory.Sorted:=true; + fDebugRecentMru := TMRUFileList.create; for d in [low(TDlangBreakpoint) .. high(TDlangBreakpoint)] do include(fDlangBreakpoints, d); end; @@ -727,6 +736,7 @@ begin fCommandsHistory.Free; fCustomEvalHistory.Free; fShortcuts.Free; + fDebugRecentMru.free; inherited; end; @@ -769,6 +779,11 @@ begin fShortcuts.assign(value); end; +procedure TDebugOptionsBase.setDebugRecentMru(value: TMRUFileList); +begin + fDebugRecentMru.assign(value); +end; + procedure TDebugOptionsBase.setMaxCallStackDepth(value: integer); begin value := max(1, value); @@ -801,6 +816,7 @@ begin fCurrentEvalKind := src.fCurrentEvalKind; fUseCustomCommandsHistory:= src.fUseCustomCommandsHistory; fAutoDotCompletion:=src.fAutoDotCompletion; + fDebugRecentMru.assign(src.fDebugRecentMru); end else inherited; end; @@ -1278,6 +1294,7 @@ begin fSubj:= TDebugObserverSubject.Create; fOptions:= TDebugOptions.create(self); fOptions.onChangesApplied:=@optionsChangesApplied; + fOptions.debugRecentMru.OnChange:=@mruDebugRecentChange; fDebugeeOptions:= TDebugeeOptions.Create(self); Edit1.Items.Assign(fOptions.commandsHistory); fAddWatchPointKind := wpkWrite; @@ -1324,6 +1341,7 @@ begin end; end; + mruDebugRecentChange(nil); updateCpuViewVisibility; updateMenu; updateButtonsState; @@ -2023,6 +2041,7 @@ begin fLastFunction := ''; // gdb process killGdb; + fOptions.debugRecentMru.Insert(0, fExe); fGdb := TDexedProcess.create(nil); fGdb.Executable:= gdb; fgdb.Options:= [poUsePipes, poStderrToOutPut]; @@ -3064,6 +3083,72 @@ begin Edit1.Text := (sender as TMenuItem).Caption; end; +procedure TGdbWidget.mruDebugRecentChange(Sender: TObject); +var + srcLst: TMRUFileList; + itm: TMenuItem; + fname: string; + i: integer; + s: string; +begin + srcLst := fOptions.debugRecentMru; + mnuDebugRecent.Clear; + for i := 0 to srcLst.Count-1 do + begin + s := srcLst.Strings[i]; + fname := s.extractFileName; + itm := TMenuItem.Create(mnuDebugRecent); + itm.Hint := s; + itm.Caption := fname + ' - (' + itm.Hint + ')'; + itm.OnClick := @mruDebugRecentClick; + mnuDebugRecent.Add(itm); + end; + + mnuDebugRecent.AddSeparator; + itm := TMenuItem.Create(mnuDebugRecent); + itm.Caption := 'Clear all'; + itm.OnClick := @mruDebugRecentClearClick; + itm.Tag := PtrInt(srcLst); + mnuDebugRecent.Add(itm); + + itm := TMenuItem.Create(mnuDebugRecent); + itm.Caption := 'Remove invalid entries'; + itm.OnClick := @mruDebugRecentDeleteInvalidClick; + itm.Tag := PtrInt(srcLst); + mnuDebugRecent.Add(itm); +end; + +procedure TGdbWidget.mruDebugRecentClick(Sender: TObject); +begin + fCustomTargetFile := TMenuItem(sender).Hint; + fDebugTargetKind := dtkCustom; + mnuSelProj.Checked:=false; + mnuSelRunnable.Checked:=false; + mnuSelCustom.Checked:=true; + updateDebugeeOptionsEditor; + btnStart.Click(); +end; + +procedure TGdbWidget.mruDebugRecentClearClick(Sender: TObject); +begin + mnuDebugRecent.Clear; +end; + +procedure TGdbWidget.mruDebugRecentDeleteInvalidClick(Sender: TObject); +var + srcLst: TMRUFileList; + i: integer; +begin + srcLst := fOptions.debugRecentMru; + if srcLst.isNotAssigned then + exit; + srcLst.BeginUpdate; + for i := srcLst.Count-1 downto 0 do + if not srcLst.Strings[i].fileExists then + srcLst.Delete(i); + srcLst.EndUpdate; +end; + procedure TGdbWidget.btnSendComClick(Sender: TObject); begin sendCustomCommand;