Browse Source

Allow debug daemon on Windows (Lazarus)

Allow to debug deamon using Lazarus compiler on Windows (as a Service)
Program will run on Windows calling "pascalcoin_daemon.exe -r -d" and can be debugged on Lazarus. Will finish on pressed "q"
PascalCoin 4 years ago
parent
commit
6bfcbd4d26
3 changed files with 42 additions and 2 deletions
  1. 36 0
      src/core/upcdaemon.pas
  2. 2 2
      src/pascalcoin_daemon.lpi
  3. 4 0
      src/pascalcoin_daemon.pp

+ 36 - 0
src/core/upcdaemon.pas

@@ -26,6 +26,7 @@ uses
   Classes, SysUtils, daemonapp,
   Classes, SysUtils, daemonapp,
   SyncObjs, UOpenSSL, UCrypto, UNode, UFileStorage, UFolderHelper, UWallet, UConst, ULog, UNetProtocol,
   SyncObjs, UOpenSSL, UCrypto, UNode, UFileStorage, UFolderHelper, UWallet, UConst, ULog, UNetProtocol,
   IniFiles, UBaseTypes,
   IniFiles, UBaseTypes,
+  {$IF Defined(FPC) and Defined(WINDOWS)}windows,jwawinsvc,crt,{$ENDIF}
   UThread, URPC, UPoolMining, UAccounts, UPCDataTypes;
   UThread, URPC, UPoolMining, UAccounts, UPCDataTypes;
 
 
 Const
 Const
@@ -91,6 +92,7 @@ Type
   protected
   protected
     Procedure DoOnCreate; override;
     Procedure DoOnCreate; override;
     Procedure DoOnDestroy; override;
     Procedure DoOnDestroy; override;
+    Procedure DoOnRun; override;
   public
   public
   end;
   end;
 
 
@@ -412,5 +414,39 @@ begin
   end;
   end;
 end;
 end;
 
 
+procedure TPCDaemonMapper.DoOnRun;
+{$IF Defined(FPC) and Defined(WINDOWS)}
+var LDT : TPCDaemonThread;
+{$ENDIF}
+begin
+  inherited DoOnRun;
+  {$IF Defined(FPC) and Defined(WINDOWS)}
+  // We are running -r command on windows
+  if Application.HasOption('d','debug') then begin
+    LDT:=TPCDaemonThread.Create;
+    LDT.FreeOnTerminate:=True;
+    if (Application.HasOption('b','block')) then begin
+      LDT.MaxBlockToRead:=StrToInt64Def(Application.GetOptionValue('b','block'),$FFFFFFFF);
+      TLog.NewLog(ltinfo,ClassName,'Max block to read: '+IntToStr(LDT.MaxBlockToRead));
+    end;
+    LDT.Start;
+    repeat
+      CheckSynchronize(10);
+      Sleep(1);
+
+      if Keypressed then begin
+        if (ReadKey in ['q','Q']) then begin
+          LDT.Terminate;
+        end;
+      end;
+
+    until LDT.Terminated;
+    LDT.Terminate;
+    LDT.WaitFor;
+    Application.Terminate;
+  end;
+  {$ENDIF}
+end;
+
 end.
 end.
 
 

+ 2 - 2
src/pascalcoin_daemon.lpi

@@ -25,14 +25,14 @@
     </PublishOptions>
     </PublishOptions>
     <RunParams>
     <RunParams>
       <local>
       <local>
-        <CommandLineParams Value="-r"/>
+        <CommandLineParams Value="-r -d"/>
         <Display Use="True" Value=""/>
         <Display Use="True" Value=""/>
       </local>
       </local>
       <FormatVersion Value="2"/>
       <FormatVersion Value="2"/>
       <Modes Count="1">
       <Modes Count="1">
         <Mode0 Name="default">
         <Mode0 Name="default">
           <local>
           <local>
-            <CommandLineParams Value="-r"/>
+            <CommandLineParams Value="-r -d"/>
             <Display Use="True" Value=""/>
             <Display Use="True" Value=""/>
           </local>
           </local>
         </Mode0>
         </Mode0>

+ 4 - 0
src/pascalcoin_daemon.pp

@@ -31,7 +31,11 @@ end;
 
 
 begin
 begin
   Application.Title:='PascalCoin Daemon application';
   Application.Title:='PascalCoin Daemon application';
+  {$IF Defined(FPC) and Defined(WINDOWS)}
+  IsConsole := Not Application.HasOption('r','run');
+  {$ELSE}
   IsConsole:=False;
   IsConsole:=False;
+  {$ENDIF}
   RegisterDaemonClass(TPCDaemon);
   RegisterDaemonClass(TPCDaemon);
   RegisterDaemonMapper(TPCDaemonMapper);
   RegisterDaemonMapper(TPCDaemonMapper);
   Application.GUIMainLoop:[email protected];
   Application.GUIMainLoop:[email protected];