FpDebugServer: Added option to run all debug-commands in a (script) file

git-svn-id: trunk@49164 -
This commit is contained in:
joost 2015-05-25 08:37:43 +00:00
parent 2d5ab7fba6
commit 172dbb56d6
4 changed files with 107 additions and 3 deletions

1
.gitattributes vendored
View File

@ -1346,6 +1346,7 @@ components/fpdebug/app/fpdd/fpdumpdwarf.lpr svneol=native#text/pascal
components/fpdebug/app/fpdserver/Info.plist svneol=native#text/plain
components/fpdebug/app/fpdserver/debugconsoleserver.pas svneol=native#text/plain
components/fpdebug/app/fpdserver/debuginoutputprocessor.pas svneol=native#text/plain
components/fpdebug/app/fpdserver/debugscriptserver.pas svneol=native#text/plain
components/fpdebug/app/fpdserver/debugtcpserver.pas svneol=native#text/plain
components/fpdebug/app/fpdserver/debugthread.pas svneol=native#text/plain
components/fpdebug/app/fpdserver/debugthreadcommand.pas svneol=native#text/plain

View File

@ -0,0 +1,82 @@
unit DebugScriptServer;
{$mode objfpc}{$H+}
interface
uses
Classes,
SysUtils,
debugthread,
DebugInOutputProcessor;
type
{ TFpDebugScriptServer }
TFpDebugScriptServer = class(TThread, IFpDebugListener)
private
FDebugThread: TFpDebugThread;
FConnectionIdentifier: integer;
FFileContents: TStringList;
FInOutputProcessor: TJSonInOutputProcessor;
protected
procedure Execute; override;
public
constructor create(ADebugThread: TFpDebugThread; AFileName: string);
function GetOrigin: string;
procedure SendEvent(AnEvent: TFpDebugEvent);
destructor Destroy; override;
end;
implementation
{ TFpDebugScriptServer }
procedure TFpDebugScriptServer.Execute;
var
ACommand: TFpDebugThreadCommand;
i: Integer;
begin
FInOutputProcessor := TJSonInOutputProcessor.create(FConnectionIdentifier, @FDebugThread.SendLogMessage);
try
for i := 0 to FFileContents.Count-1 do
begin
ACommand := FInOutputProcessor.TextToCommand(FFileContents.Strings[i]);
FDebugThread.QueueCommand(ACommand);
if Terminated then
Break;
end;
finally
FInOutputProcessor.Free;
end;
Terminate;
end;
constructor TFpDebugScriptServer.create(ADebugThread: TFpDebugThread; AFileName: string);
begin
inherited Create(false);
FDebugThread:=ADebugThread;
FConnectionIdentifier := FDebugThread.AddListener(self);
FFileContents := TStringList.Create;
FFileContents.LoadFromFile(AFileName);
end;
function TFpDebugScriptServer.GetOrigin: string;
begin
result := 'File input';
end;
procedure TFpDebugScriptServer.SendEvent(AnEvent: TFpDebugEvent);
begin
// Ignore
end;
destructor TFpDebugScriptServer.Destroy;
begin
FFileContents.Free;
inherited Destroy;
end;
end.

View File

@ -37,7 +37,7 @@
<PackageName Value="fpdebug"/>
</Item2>
</RequiredPackages>
<Units Count="6">
<Units Count="7">
<Unit0>
<Filename Value="fpdserver.lpr"/>
<IsPartOfProject Value="True"/>
@ -67,6 +67,11 @@
<IsPartOfProject Value="True"/>
<UnitName Value="DebugConsoleServer"/>
</Unit5>
<Unit6>
<Filename Value="debugscriptserver.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="debugscriptserver"/>
</Unit6>
</Units>
</ProjectOptions>
<CompilerOptions>

View File

@ -30,7 +30,8 @@ uses
DebugThreadCommand,
DebugInOutputProcessor,
DebugTCPServer,
DebugConsoleServer;
DebugConsoleServer,
debugscriptserver;
type
@ -51,14 +52,16 @@ var
ErrorMsg: String;
DebugThread: TFpDebugThread;
TCPServerThread: TFpDebugTcpServer;
ScriptServerThread: TFpDebugScriptServer;
ConsoleServerThread: TFpDebugConsoleServer;
Port: integer;
SensePorts: integer;
ACommand: TFpDebugThreadCommand;
ScriptFile: string;
CommandStr: string;
begin
// quick check parameters
ErrorMsg:=CheckOptions('hf:tdp:a::i', ['help','filename:','tcp','daemon','port:','autoport::','interactive'], True);
ErrorMsg:=CheckOptions('hf:tdp:a::is:', ['help','filename:','tcp','daemon','port:','autoport::','interactive','script:'], True);
if not HasOption('i','interactive') then
begin
@ -136,6 +139,12 @@ begin
FlushThread;
end;
ScriptFile := GetOptionValue('s','script');
if ScriptFile<>'' then
ScriptServerThread := TFpDebugScriptServer.create(DebugThread, ScriptFile)
else
ScriptServerThread := nil;
CommandStr := GetOptionValue('f', 'filename');
if CommandStr<>'' then
begin
@ -158,16 +167,22 @@ begin
ConsoleServerThread.Terminate;
if assigned(TCPServerThread) then
TCPServerThread.StopListening;
if assigned(ScriptServerThread) then
ScriptServerThread.Terminate;
if assigned(ConsoleServerThread) then
ConsoleServerThread.WaitFor;
if assigned(TCPServerThread) then
TCPServerThread.WaitFor;
if assigned(ScriptServerThread) then
ScriptServerThread.WaitFor;
if assigned(TCPServerThread) then
TCPServerThread.Free;
if assigned(ConsoleServerThread) then
ConsoleServerThread.Free;
if assigned(ScriptServerThread) then
ScriptServerThread.Free;
DebugThread.Terminate;
DebugThread.WaitFor;
@ -191,6 +206,7 @@ begin
writeln(' -f --filename Set the filename of the executable to debug');
writeln(' -p --port Set the port (9159) to listen for incoming tcp-connections');
writeln(' -a --autoport Try to bind to n (5) sequential ports when a port is in use');
writeln(' -s --script Load script with debug-commands');
end;
var