From 607af213ac70bd74e271f1ae2ad30d8930b04a43 Mon Sep 17 00:00:00 2001 From: joost Date: Sun, 9 Mar 2014 12:00:55 +0000 Subject: [PATCH] FpDbg: Refactored code to get module-name, to avoid double code for processes and libraries. git-svn-id: trunk@44387 - --- components/fpdebug/fpdbgclasses.pp | 6 -- components/fpdebug/fpdbgwinclasses.pas | 131 +++++++++++-------------- 2 files changed, 56 insertions(+), 81 deletions(-) diff --git a/components/fpdebug/fpdbgclasses.pp b/components/fpdebug/fpdbgclasses.pp index cf429b1d71..bdb1cca55d 100644 --- a/components/fpdebug/fpdbgclasses.pp +++ b/components/fpdebug/fpdbgclasses.pp @@ -97,7 +97,6 @@ type protected procedure LoadInfo; virtual; function InitializeLoader: TDbgImageLoader; virtual; - function GetModuleFileName(AModuleHandle: THandle): string; virtual; procedure SetName(const AValue: String); public constructor Create(const AProcess: TDbgProcess); virtual; @@ -302,11 +301,6 @@ begin result := nil; end; -function TDbgInstance.GetModuleFileName(AModuleHandle: THandle): string; -begin - result := ''; -end; - { TDbgLibrary } constructor TDbgLibrary.Create(const AProcess: TDbgProcess; const ADefaultName: String; const AModuleHandle: THandle; const ABaseAddr: TDbgPtr); diff --git a/components/fpdebug/fpdbgwinclasses.pas b/components/fpdebug/fpdbgwinclasses.pas index 6eb7254875..dd79bc0ad6 100644 --- a/components/fpdebug/fpdbgwinclasses.pas +++ b/components/fpdebug/fpdbgwinclasses.pas @@ -76,7 +76,6 @@ type private FInfo: TCreateProcessDebugInfo; protected - function GetModuleFileName(AModuleHandle: THandle): string; override; function GetHandle: THandle; override; function GetLastEventProcessIdentifier: THandle; override; function InitializeLoader: TDbgImageLoader; override; @@ -133,55 +132,7 @@ begin DebugLn('FpDbg-ERROR: ', GetLastErrorText); end; -{ tDbgWinLibrary } - -function tDbgWinLibrary.InitializeLoader: TDbgImageLoader; -begin - result := TDbgImageLoader.Create(FInfo.hFile); -end; - -constructor tDbgWinLibrary.Create(const AProcess: TDbgProcess; - const ADefaultName: String; const AModuleHandle: THandle; - const ABaseAddr: TDbgPtr; AInfo: TLoadDLLDebugInfo); -var - NamePtr: TDbgPtr; - S: String; - W: WideString; -begin - inherited Create(AProcess, ADefaultName, AModuleHandle, ABaseAddr); - FInfo := AInfo; - - W := ''; - if Process.ReadOrdinal(TDbgPtr(FInfo.lpImageName), NamePtr) - then begin - if FInfo.fUnicode<>0 - then begin - Process.ReadWString(NamePtr, MAX_PATH, W); - end - else begin - if Process.ReadString(NamePtr, MAX_PATH, S) - then W := S; - end; - end; - - if W = '' - then begin - W := GetModuleFileName(AModuleHandle); - end; - - if W = '' - then W := ADefaultName; - - SetName(W); - LoadInfo; - - - -end; - -{ TDbgWinProcess } - -function TDbgWinProcess.GetModuleFileName(AModuleHandle: THandle): string; +function GetModuleFileName(AModuleHandle: THandle): string; var s: string; len: Integer; @@ -197,6 +148,57 @@ begin result := s; end; +function GetProcFilename(AProcess: TDbgProcess; lpImageName: LPVOID; fUnicode: word; hFile: handle): string; +var + NamePtr: TDbgPtr; + S: String; + W: WideString; +begin + W := ''; + if (lpImageName<>nil) and AProcess.ReadOrdinal(TDbgPtr(lpImageName), NamePtr) + then begin + if fUnicode <> 0 + then begin + AProcess.ReadWString(NamePtr, MAX_PATH, W); + end + else begin + if AProcess.ReadString(NamePtr, MAX_PATH, S) + then W := S; + end; + end; + + if W = '' + then begin + W := GetModuleFileName(hFile); + end; + result := W; +end; + +{ tDbgWinLibrary } + +function tDbgWinLibrary.InitializeLoader: TDbgImageLoader; +begin + result := TDbgImageLoader.Create(FInfo.hFile); +end; + +constructor tDbgWinLibrary.Create(const AProcess: TDbgProcess; + const ADefaultName: String; const AModuleHandle: THandle; + const ABaseAddr: TDbgPtr; AInfo: TLoadDLLDebugInfo); +var + S: String; +begin + inherited Create(AProcess, ADefaultName, AModuleHandle, ABaseAddr); + FInfo := AInfo; + + s := GetProcFilename(AProcess, AInfo.lpImageName, AInfo.fUnicode, AInfo.hFile); + if s <> '' + then SetName(s); + + LoadInfo; +end; + +{ TDbgWinProcess } + function TDbgWinProcess.GetHandle: THandle; begin Result:=FInfo.hProcess; @@ -813,34 +815,13 @@ end; procedure TDbgWinProcess.StartProcess(const AInfo: TCreateProcessDebugInfo); var - NamePtr: TDbgPtr; - S: String; - W: WideString; + s: string; begin FInfo := AInfo; - W := ''; - if Process.ReadOrdinal(TDbgPtr(AInfo.lpImageName), NamePtr) - then begin - if AInfo.fUnicode <> 0 - then begin - Process.ReadWString(NamePtr, MAX_PATH, W); - end - else begin - if Process.ReadString(NamePtr, MAX_PATH, S) - then W := S; - end; - end; - - if W = '' - then begin - W := GetModuleFileName(AInfo.hFile); - end; - - if W = '' - then W := ADefaultName; - - SetName(W); + s := GetProcFilename(Self, AInfo.lpImageName, AInfo.fUnicode, AInfo.hFile); + if s <> '' + then SetName(s); LoadInfo;