From a1b61028fa311b6cf12d01c6e78b3b4d7b3d3cc2 Mon Sep 17 00:00:00 2001 From: Martin Date: Fri, 3 Feb 2023 17:13:19 +0100 Subject: [PATCH] IDE: Run/Debug, search for LaunchApp and HostApp in Project-dir and %Path. issue #32331 - Search in %PATH was done by "run without debug", but not by debug. - Checking for an exe relative to the project-dir was added for both. - A plain file-name will be first checked in the project-dir, and after that in %PATH --- ide/debugmanager.pas | 25 ++++++++++++++++++++++++- ide/main.pp | 10 ++-------- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/ide/debugmanager.pas b/ide/debugmanager.pas index 02c12a705d..777cb37b4e 100644 --- a/ide/debugmanager.pas +++ b/ide/debugmanager.pas @@ -55,7 +55,7 @@ uses IdeDebuggerStringConstants, // IDE CompilerOptions, EnvironmentOpts, SourceEditor, ProjectDefs, Project, - InputHistory, Debugger, LazarusIDEStrConsts, TransferMacros, MainBar, + InputHistory, LazConf, Debugger, LazarusIDEStrConsts, TransferMacros, MainBar, MainIntf, MainBase, BaseBuildManager, SourceMarks, DebuggerDlg, Watchesdlg, BreakPointsdlg, BreakPropertyDlg, LocalsDlg, WatchPropertyDlg, CallStackDlg, EvaluateDlg, RegistersDlg, AssemblerDlg, DebugOutputForm, ExceptionDlg, @@ -308,6 +308,7 @@ function GetDebugManager: TDebugManager; property DebugBossMgr: TDebugManager read GetDebugManager; function DBGDateTimeFormatter(const aValue: string): string; +function ResolveLocationForLaunchApplication(ALaunchApp: String): String; implementation @@ -340,6 +341,25 @@ begin Result := aValue; end; +function ResolveLocationForLaunchApplication(ALaunchApp: String): String; +var + tmp: String; +begin + Result := ALaunchApp; + if not FilenameIsAbsolute(ALaunchApp) then begin + tmp := CreateAbsolutePath(ALaunchApp, Project1.Directory); + if FileIsExecutable(tmp) then begin + Result := tmp; + end + else + if ExtractFilePath(ALaunchApp) = '' then begin + tmp := FindDefaultExecutablePath(ALaunchApp); + if tmp <> '' then + Result := tmp; + end; + end; +end; + type { TManagedBreakPoint } @@ -2514,6 +2534,9 @@ begin LaunchingCmdLine := BuildBoss.GetRunCommandLine; SplitCmdLine(LaunchingCmdLine, LaunchingApplication, LaunchingParams); + if NewDebuggerClass.RequiresLocalExecutable then + LaunchingApplication := ResolveLocationForLaunchApplication(LaunchingApplication); + (* TODO: workaround for http://bugs.freepascal.org/view.php?id=21834 Se Debugger.RequiresLocalExecutable *) diff --git a/ide/main.pp b/ide/main.pp index e3902f6b9a..973bff29cb 100644 --- a/ide/main.pp +++ b/ide/main.pp @@ -7402,7 +7402,7 @@ begin if ConsoleVerbosity>0 then DebugLn(['Hint: (lazarus) [TMainIDE.DoInitProjectRun] ProgramFilename=',ProgramFilename]); if ((DebugClass = nil) or DebugClass.RequiresLocalExecutable) - and not FileExistsUTF8(ProgramFilename) + and not FileExistsUTF8(ResolveLocationForLaunchApplication(ProgramFilename)) then begin debugln(['Info: (lazarus) [TMainIDE.DoInitProjectRun] File TargetFile found: "',ProgramFilename,'"']); IDEMessageDialog(lisFileNotFound, @@ -7520,13 +7520,7 @@ begin ExeFile := Params[0]; Params.Delete(0); //debugln('TMainIDE.DoRunProjectWithoutDebug ExeFile=',ExeFile); - if not FilenameIsAbsolute(ExeFile) then - begin - aFilename:=FindDefaultExecutablePath(ExeFile); - if aFilename<>'' then - ExeFile:=aFilename; - end; - + ExeFile := ResolveLocationForLaunchApplication(ExeFile); Process.Executable := ExeFile; Process.Parameters.Assign(Params);