FpDebug: Allow to specify poNewConsole on windows

git-svn-id: trunk@59488 -
This commit is contained in:
martin 2018-11-07 23:13:11 +00:00
parent 96746c2c7c
commit c54639d227
6 changed files with 43 additions and 13 deletions

View File

@ -269,6 +269,9 @@ type
property BaseAddr: TDBGPtr read FBaseAddr; property BaseAddr: TDBGPtr read FBaseAddr;
end; end;
TStartInstanceFlag = (siRediretOutput, siForceNewConsole);
TStartInstanceFlags = set of TStartInstanceFlag;
{ TDbgProcess } { TDbgProcess }
TDbgProcess = class(TDbgInstance) TDbgProcess = class(TDbgInstance)
@ -305,7 +308,7 @@ type
// Should analyse why the debugger has stopped. // Should analyse why the debugger has stopped.
function AnalyseDebugEvent(AThread: TDbgThread): TFPDEvent; virtual; abstract; function AnalyseDebugEvent(AThread: TDbgThread): TFPDEvent; virtual; abstract;
public public
class function StartInstance(AFileName: string; AParams, AnEnvironment: TStrings; AWorkingDirectory, AConsoleTty: string; AOnLog: TOnLog; ReDirectOutput: boolean): TDbgProcess; virtual; class function StartInstance(AFileName: string; AParams, AnEnvironment: TStrings; AWorkingDirectory, AConsoleTty: string; AOnLog: TOnLog; AFlags: TStartInstanceFlags): TDbgProcess; virtual;
constructor Create(const AFileName: string; const AProcessID, AThreadID: Integer; AOnLog: TOnLog); virtual; constructor Create(const AFileName: string; const AProcessID, AThreadID: Integer; AOnLog: TOnLog); virtual;
destructor Destroy; override; destructor Destroy; override;
function AddBreak(const ALocation: TDBGPtr): TFpInternalBreakpoint; overload; function AddBreak(const ALocation: TDBGPtr): TFpInternalBreakpoint; overload;
@ -1086,8 +1089,9 @@ end;
resourcestring resourcestring
sNoDebugSupport = 'Debug support is not available for this platform .'; sNoDebugSupport = 'Debug support is not available for this platform .';
class function TDbgProcess.StartInstance(AFileName: string; AParams, class function TDbgProcess.StartInstance(AFileName: string; AParams, AnEnvironment: TStrings;
AnEnvironment: TStrings; AWorkingDirectory, AConsoleTty: string; AOnLog: TOnLog; ReDirectOutput: boolean): TDbgProcess; AWorkingDirectory, AConsoleTty: string; AOnLog: TOnLog;
AFlags: TStartInstanceFlags): TDbgProcess;
begin begin
if assigned(AOnLog) then if assigned(AOnLog) then
AOnLog(sNoDebugSupport, dllError) AOnLog(sNoDebugSupport, dllError)

View File

@ -129,6 +129,7 @@ type
private private
FEnvironment: TStrings; FEnvironment: TStrings;
FExecutableFilename: string; FExecutableFilename: string;
FForceNewConsoleWin: boolean;
FNextOnlyStopOnStartLine: boolean; FNextOnlyStopOnStartLine: boolean;
FOnCreateProcessEvent: TOnCreateProcessEvent; FOnCreateProcessEvent: TOnCreateProcessEvent;
FOnDebugInfoLoaded: TNotifyEvent; FOnDebugInfoLoaded: TNotifyEvent;
@ -179,6 +180,7 @@ type
property Environment: TStrings read FEnvironment write SetEnvironment; property Environment: TStrings read FEnvironment write SetEnvironment;
property WorkingDirectory: string read FWorkingDirectory write FWorkingDirectory; property WorkingDirectory: string read FWorkingDirectory write FWorkingDirectory;
property RedirectConsoleOutput: boolean read FRedirectConsoleOutput write FRedirectConsoleOutput; property RedirectConsoleOutput: boolean read FRedirectConsoleOutput write FRedirectConsoleOutput;
property ForceNewConsoleWin: boolean read FForceNewConsoleWin write FForceNewConsoleWin; // windows only
property ConsoleTty: string read FConsoleTty write FConsoleTty; property ConsoleTty: string read FConsoleTty write FConsoleTty;
// With this parameter set a 'next' will only stop if the current // With this parameter set a 'next' will only stop if the current
// instruction is the first instruction of a line according to the // instruction is the first instruction of a line according to the
@ -641,6 +643,8 @@ begin
end; end;
function TDbgController.Run: boolean; function TDbgController.Run: boolean;
var
Flags: TStartInstanceFlags;
begin begin
result := False; result := False;
if assigned(FMainProcess) then if assigned(FMainProcess) then
@ -661,7 +665,10 @@ begin
Exit; Exit;
end; end;
FCurrentProcess := OSDbgClasses.DbgProcessClass.StartInstance(FExecutableFilename, Params, Environment, WorkingDirectory, FConsoleTty , @Log, RedirectConsoleOutput); Flags := [];
if RedirectConsoleOutput then Include(Flags, siRediretOutput);
if ForceNewConsoleWin then Include(Flags, siForceNewConsole);
FCurrentProcess := OSDbgClasses.DbgProcessClass.StartInstance(FExecutableFilename, Params, Environment, WorkingDirectory, FConsoleTty , @Log, Flags);
if assigned(FCurrentProcess) then if assigned(FCurrentProcess) then
begin begin
FProcessMap.Add(FCurrentProcess.ProcessID, FCurrentProcess); FProcessMap.Add(FCurrentProcess.ProcessID, FCurrentProcess);

View File

@ -144,7 +144,7 @@ type
function CreateThread(AthreadIdentifier: THandle; out IsMainThread: boolean): TDbgThread; override; function CreateThread(AthreadIdentifier: THandle; out IsMainThread: boolean): TDbgThread; override;
function AnalyseDebugEvent(AThread: TDbgThread): TFPDEvent; override; function AnalyseDebugEvent(AThread: TDbgThread): TFPDEvent; override;
public public
class function StartInstance(AFileName: string; AParams, AnEnvironment: TStrings; AWorkingDirectory, AConsoleTty: string; AOnLog: TOnLog; ReDirectOutput: boolean): TDbgProcess; override; class function StartInstance(AFileName: string; AParams, AnEnvironment: TStrings; AWorkingDirectory, AConsoleTty: string; AOnLog: TOnLog; AFlags: TStartInstanceFlags): TDbgProcess; override;
constructor Create(const AName: string; const AProcessID, AThreadID: Integer; AOnLog: TOnLog); override; constructor Create(const AName: string; const AProcessID, AThreadID: Integer; AOnLog: TOnLog); override;
destructor Destroy; override; destructor Destroy; override;
@ -698,7 +698,9 @@ begin
inherited Destroy; inherited Destroy;
end; end;
class function TDbgDarwinProcess.StartInstance(AFileName: string; AParams, AnEnvironment: TStrings; AWorkingDirectory, AConsoleTty: string; AOnLog: TOnLog; ReDirectOutput: boolean): TDbgProcess; class function TDbgDarwinProcess.StartInstance(AFileName: string; AParams,
AnEnvironment: TStrings; AWorkingDirectory, AConsoleTty: string; AOnLog: TOnLog;
AFlags: TStartInstanceFlags): TDbgProcess;
var var
PID: TPid; PID: TPid;
AProcess: TProcessUTF8; AProcess: TProcessUTF8;
@ -725,7 +727,7 @@ begin
end; end;
AMasterPtyFd:=-1; AMasterPtyFd:=-1;
if ReDirectOutput then if siRediretOutput in AFlags then
begin begin
if AConsoleTty<>'' then if AConsoleTty<>'' then
AOnLog('It is of no use to provide a console-tty when the console output is being redirected.', dllInfo); AOnLog('It is of no use to provide a console-tty when the console output is being redirected.', dllInfo);

View File

@ -264,7 +264,9 @@ type
function CreateThread(AthreadIdentifier: THandle; out IsMainThread: boolean): TDbgThread; override; function CreateThread(AthreadIdentifier: THandle; out IsMainThread: boolean): TDbgThread; override;
function AnalyseDebugEvent(AThread: TDbgThread): TFPDEvent; override; function AnalyseDebugEvent(AThread: TDbgThread): TFPDEvent; override;
public public
class function StartInstance(AFileName: string; AParams, AnEnvironment: TStrings; AWorkingDirectory, AConsoleTty: string; AOnLog: TOnLog; ReDirectOutput: boolean): TDbgProcess; override; class function StartInstance(AFileName: string; AParams, AnEnvironment: TStrings;
AWorkingDirectory, AConsoleTty: string; AOnLog: TOnLog;
AFlags: TStartInstanceFlags): TDbgProcess; override;
constructor Create(const AName: string; const AProcessID, AThreadID: Integer; AOnLog: TOnLog); override; constructor Create(const AName: string; const AProcessID, AThreadID: Integer; AOnLog: TOnLog); override;
destructor Destroy; override; destructor Destroy; override;
@ -615,7 +617,7 @@ begin
end; end;
class function TDbgLinuxProcess.StartInstance(AFileName: string; AParams, AnEnvironment: TStrings; AWorkingDirectory, AConsoleTty: string; class function TDbgLinuxProcess.StartInstance(AFileName: string; AParams, AnEnvironment: TStrings; AWorkingDirectory, AConsoleTty: string;
AOnLog: TOnLog; ReDirectOutput: boolean): TDbgProcess; AOnLog: TOnLog; AFlags: TStartInstanceFlags): TDbgProcess;
var var
PID: TPid; PID: TPid;
AProcess: TProcessUTF8; AProcess: TProcessUTF8;
@ -638,7 +640,7 @@ begin
end; end;
AMasterPtyFd:=-1; AMasterPtyFd:=-1;
if ReDirectOutput then if siRediretOutput in AFlags then
begin begin
if AConsoleTty<>'' then if AConsoleTty<>'' then
AOnLog('It is of no use to provide a console-tty when the console output is being redirected.', dllInfo); AOnLog('It is of no use to provide a console-tty when the console output is being redirected.', dllInfo);

View File

@ -109,7 +109,7 @@ type
procedure Interrupt; procedure Interrupt;
function HandleDebugEvent(const ADebugEvent: TDebugEvent): Boolean; function HandleDebugEvent(const ADebugEvent: TDebugEvent): Boolean;
class function StartInstance(AFileName: string; AParams, AnEnvironment: TStrings; AWorkingDirectory, AConsoleTty: string; AOnLog: TOnLog; ReDirectOutput: boolean): TDbgProcess; override; class function StartInstance(AFileName: string; AParams, AnEnvironment: TStrings; AWorkingDirectory, AConsoleTty: string; AOnLog: TOnLog; AFlags: TStartInstanceFlags): TDbgProcess; override;
function Continue(AProcess: TDbgProcess; AThread: TDbgThread; SingleStep: boolean): boolean; override; function Continue(AProcess: TDbgProcess; AThread: TDbgThread; SingleStep: boolean): boolean; override;
function WaitForDebugEvent(out ProcessIdentifier, ThreadIdentifier: THandle): boolean; override; function WaitForDebugEvent(out ProcessIdentifier, ThreadIdentifier: THandle): boolean; override;
function AnalyseDebugEvent(AThread: TDbgThread): TFPDEvent; override; function AnalyseDebugEvent(AThread: TDbgThread): TFPDEvent; override;
@ -458,8 +458,9 @@ begin
end; end;
end; end;
class function TDbgWinProcess.StartInstance(AFileName: string; AParams, AnEnvironment: TStrings; AWorkingDirectory, AConsoleTty: string; class function TDbgWinProcess.StartInstance(AFileName: string; AParams,
AOnLog: TOnLog; ReDirectOutput: boolean): TDbgProcess; AnEnvironment: TStrings; AWorkingDirectory, AConsoleTty: string; AOnLog: TOnLog;
AFlags: TStartInstanceFlags): TDbgProcess;
var var
AProcess: TProcessUTF8; AProcess: TProcessUTF8;
begin begin
@ -467,6 +468,8 @@ begin
AProcess := TProcessUTF8.Create(nil); AProcess := TProcessUTF8.Create(nil);
try try
AProcess.Options:=[poDebugProcess, poNewProcessGroup]; AProcess.Options:=[poDebugProcess, poNewProcessGroup];
if siForceNewConsole in AFlags then
AProcess.Options:=AProcess.Options+[poNewConsole];
AProcess.Executable:=AFilename; AProcess.Executable:=AFilename;
AProcess.Parameters:=AParams; AProcess.Parameters:=AParams;
AProcess.Environment:=AnEnvironment; AProcess.Environment:=AnEnvironment;

View File

@ -61,6 +61,9 @@ type
TFpDebugDebuggerProperties = class(TDebuggerProperties) TFpDebugDebuggerProperties = class(TDebuggerProperties)
private private
FConsoleTty: string; FConsoleTty: string;
{$ifdef windows}
FForceNewConsole: boolean;
{$endif windows}
FNextOnlyStopOnStartLine: boolean; FNextOnlyStopOnStartLine: boolean;
public public
constructor Create; override; constructor Create; override;
@ -71,6 +74,9 @@ type
property ConsoleTty: string read FConsoleTty write FConsoleTty; property ConsoleTty: string read FConsoleTty write FConsoleTty;
published published
property NextOnlyStopOnStartLine: boolean read FNextOnlyStopOnStartLine write FNextOnlyStopOnStartLine; property NextOnlyStopOnStartLine: boolean read FNextOnlyStopOnStartLine write FNextOnlyStopOnStartLine;
{$ifdef windows}
property ForceNewConsole: boolean read FForceNewConsole write FForceNewConsole;
{$endif windows}
end; end;
{ TFpDebugDebugger } { TFpDebugDebugger }
@ -417,6 +423,9 @@ begin
if Source is TFpDebugDebuggerProperties then begin if Source is TFpDebugDebuggerProperties then begin
FNextOnlyStopOnStartLine := TFpDebugDebuggerProperties(Source).NextOnlyStopOnStartLine; FNextOnlyStopOnStartLine := TFpDebugDebuggerProperties(Source).NextOnlyStopOnStartLine;
FConsoleTty:=TFpDebugDebuggerProperties(Source).ConsoleTty; FConsoleTty:=TFpDebugDebuggerProperties(Source).ConsoleTty;
{$ifdef windows}
FForceNewConsole:=TFpDebugDebuggerProperties(Source).FForceNewConsole;
{$endif windows}
end; end;
end; end;
@ -1664,6 +1673,9 @@ begin
CommandToList(Arguments, FDbgController.Params); CommandToList(Arguments, FDbgController.Params);
FDbgController.WorkingDirectory:=WorkingDir; FDbgController.WorkingDirectory:=WorkingDir;
FDbgController.Environment:=Environment; FDbgController.Environment:=Environment;
{$ifdef windows}
FDbgController.ForceNewConsoleWin:=TFpDebugDebuggerProperties(GetProperties).ForceNewConsole;
{$endif windows}
FFpDebugThread := TFpDebugThread.Create(Self); FFpDebugThread := TFpDebugThread.Create(Self);
RTLeventWaitFor(FFpDebugThread.DebugLoopStoppedEvent); RTLeventWaitFor(FFpDebugThread.DebugLoopStoppedEvent);
RTLeventResetEvent(FFpDebugThread.DebugLoopStoppedEvent); RTLeventResetEvent(FFpDebugThread.DebugLoopStoppedEvent);