From d15212e123cdafeaf36b1195ab4db8278fff9f82 Mon Sep 17 00:00:00 2001 From: paul Date: Sat, 19 Oct 2013 15:53:15 +0000 Subject: [PATCH] debugger: add pid enumeration code for linux git-svn-id: trunk@43286 - --- debugger/debugattachdialog.pas | 48 ++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/debugger/debugattachdialog.pas b/debugger/debugattachdialog.pas index ffa0a30427..eb2adfa1e1 100644 --- a/debugger/debugattachdialog.pas +++ b/debugger/debugattachdialog.pas @@ -89,11 +89,59 @@ begin end; end; {$else} +{$ifdef linux} +uses + LazUTF8Classes; + +function EnumerateProcesses(AList: TRunningProcessInfoList): boolean; + + function GetProcName(Pid: THandle): String; + var + S: TStream; + Sz: Integer; + begin + S := TFileStreamUTF8.Create('/proc/' + IntToStr(Pid) + '/cmdline', fmOpenRead or fmShareDenyNone); + try + SetLength(Result, 255); + Sz := S.Read(Result[1], 255); + SetLength(Result, Sz); + finally + S.Free; + end; + end; + +var + Rec: TSearchRec; + ProcName: String; + Pid: THandle; + Code: Integer; + item: TRunningProcessInfo; +begin + Result := True; + + if not Assigned(AList) then + Exit; + + if FindFirstUTF8('/proc/*', faDirectory, Rec) = 0 then + begin + repeat + Val(Rec.Name, Pid, Code); + if (Code = 0) then + begin + ProcName := GetProcName(Pid); + item := TRunningProcessInfo.Create(Pid, ProcName); + AList.Add(item); + end; + until FindNextUTF8(Rec) <> 0; + end; +end; +{$else} function EnumerateProcesses(AList: TRunningProcessInfoList): boolean; begin Result := False; end; {$endif} +{$endif} { TRunningProcessInfo }