Browse Source

* Try to improve directory handling of program

git-svn-id: trunk@16057 -
pierre 15 years ago
parent
commit
19e037dde7
1 changed files with 51 additions and 14 deletions
  1. 51 14
      compiler/utils/gppc386.pp

+ 51 - 14
compiler/utils/gppc386.pp

@@ -33,7 +33,9 @@ program fpc_with_gdb;
       instruction that GDB should do before starting.
       instruction that GDB should do before starting.
       Note that if gdb.fpc is present, no "run" command is
       Note that if gdb.fpc is present, no "run" command is
       inserted if gdb4fpc.ini is found
       inserted if gdb4fpc.ini is found
-      but it can be inserted in gdb.fpc itself
+      but it can be inserted in gdb.fpc itself.
+
+  Use EXTDEBUG conditional to get debug information.
 }
 }
 
 
 uses
 uses
@@ -41,22 +43,24 @@ uses
 
 
 const
 const
 {$ifdef Unix}
 {$ifdef Unix}
-  GDBExeName = 'gdbpas';
+  GDBExeName : String = 'gdbpas';
   GDBIniName = '.gdbinit';
   GDBIniName = '.gdbinit';
   DefaultCompilerName = 'ppc386';
   DefaultCompilerName = 'ppc386';
   PathSep=':';
   PathSep=':';
+  DirSep = '/';
 {$else}
 {$else}
-  GDBExeName = 'gdbpas.exe';
+  GDBExeName : String = 'gdbpas.exe';
   GDBIniName = 'gdb.ini';
   GDBIniName = 'gdb.ini';
   DefaultCompilerName = 'ppc386.exe';
   DefaultCompilerName = 'ppc386.exe';
   PathSep=';';
   PathSep=';';
+  DirSep = '\';
 {$endif not linux}
 {$endif not linux}
 
 
   { If you add a gdb.fpc file in a given directory }
   { If you add a gdb.fpc file in a given directory }
   { GDB will read it; this allows you to add       }
   { GDB will read it; this allows you to add       }
   { special tests in specific directories   PM     }
   { special tests in specific directories   PM     }
   FpcGDBIniName = 'gdb.fpc';
   FpcGDBIniName = 'gdb.fpc';
-  GDBIniTempName = 'gdb4fpc.ini';
+  GDBIniTempName : string = 'gdb4fpc.ini';
 
 
 var
 var
    fpcgdbini : text;
    fpcgdbini : text;
@@ -71,27 +75,37 @@ begin
   else
   else
     CompilerName:=DefaultCompilerName;
     CompilerName:=DefaultCompilerName;
 
 
+  CompilerName:=fsearch(CompilerName,Dir+PathSep+GetEnv('PATH'));
+
   { support for info functions directly : used in makefiles }
   { support for info functions directly : used in makefiles }
   if (paramcount=1) and (pos('-i',Paramstr(1))=1) then
   if (paramcount=1) and (pos('-i',Paramstr(1))=1) then
     begin
     begin
-      Exec(fsearch(CompilerName,Dir+PathSep+GetEnv('PATH')),Paramstr(1));
+      Exec(CompilerName,Paramstr(1));
       exit;
       exit;
     end;
     end;
 
 
-  if fsearch(GDBIniTempName,'./')<>'' then
+  {$ifdef EXTDEBUG}
+  writeln(stderr,'Using compiler "',CompilerName,'"');
+  flush(stderr);
+  {$endif}
+  if fsearch(GDBIniTempName,'.')<>'' then
     begin
     begin
       Assign(fpcgdbini,GDBIniTempName);
       Assign(fpcgdbini,GDBIniTempName);
+      {$ifdef EXTDEBUG}
+      writeln(stderr,'Erasing file "',GDBIniTempName,'"');
+      flush(stderr);
+      {$endif}
       erase(fpcgdbini);
       erase(fpcgdbini);
     end;
     end;
+  GDBIniTempName:=fexpand('.'+DirSep+GDBIniTempName);
   Assign(fpcgdbini,GdbIniTempName);
   Assign(fpcgdbini,GdbIniTempName);
+  {$ifdef EXTDEBUG}
+  writeln(stderr,'Creating file "',GDBIniTempName,'"');
+  flush(stderr);
+  {$endif}
   Rewrite(fpcgdbini);
   Rewrite(fpcgdbini);
 
 
   Writeln(fpcgdbini,'set language pascal');
   Writeln(fpcgdbini,'set language pascal');
-  Writeln(fpcgdbini,'b SYSTEM_EXIT');
-  Writeln(fpcgdbini,'cond 1 EXITCODE <> 0');
-  Writeln(fpcgdbini,'b INTERNALERROR');
-  Writeln(fpcgdbini,'b HANDLEERRORADDRFRAME');
-  Writeln(fpcgdbini,'set $_exitcode := -1');
   Write(fpcgdbini,'set args');
   Write(fpcgdbini,'set args');
 
 
   { this will not work correctly if there are " or '' inside the command line :( }
   { this will not work correctly if there are " or '' inside the command line :( }
@@ -103,6 +117,15 @@ begin
         Write(fpcgdbini,' '+ParamStr(i));
         Write(fpcgdbini,' '+ParamStr(i));
     end;
     end;
   Writeln(fpcgdbini);
   Writeln(fpcgdbini);
+  Writeln(fpcgdbini,'b SYSTEM_EXIT');
+  Writeln(fpcgdbini,'cond 1 EXITCODE <> 0');
+  Writeln(fpcgdbini,'set $_exitcode := -1');
+  { b INTERNALERROR sometimes fails ... Don't know why. PM 2010-08-28 }
+  Writeln(fpcgdbini,'info fun INTERNALERROR');
+  Writeln(fpcgdbini,'b INTERNALERROR');
+  Writeln(fpcgdbini,'b HANDLEERRORADDRFRAME');
+  { This one will fail unless sysutils unit is also loaded }
+  Writeln(fpcgdbini,'b RUNERRORTOEXCEPT');
   if fsearch(FpcGDBIniName,'./')<>'' then
   if fsearch(FpcGDBIniName,'./')<>'' then
     begin
     begin
       Writeln(fpcgdbini,'source '+FpcGDBIniName);
       Writeln(fpcgdbini,'source '+FpcGDBIniName);
@@ -115,12 +138,26 @@ begin
   Writeln(fpcgdbini,'  quit');
   Writeln(fpcgdbini,'  quit');
   Writeln(fpcgdbini,'end');
   Writeln(fpcgdbini,'end');
   Close(fpcgdbini);
   Close(fpcgdbini);
-
-  Exec(fsearch(GDBExeName,Dir+PathSep+GetEnv('PATH')),
+  {$ifdef EXTDEBUG}
+  writeln(stderr,'Closing file "',GDBIniTempName,'"');
+  flush(stderr);
+  {$endif}
+
+  GDBExeName:=fsearch(GDBExeName,Dir+PathSep+GetEnv('PATH'));
+  {$ifdef EXTDEBUG}
+  Writeln(stderr,'Starting ',GDBExeName,
+{$ifdef win32}
+    '--nw '+
+{$endif win32}
+    '--nx --command='+GDBIniTempName+' '+CompilerName);
+  flush(stderr);
+  {$endif}
+   DosError:=0;
+   Exec(GDBExeName,
 {$ifdef win32}
 {$ifdef win32}
     '--nw '+
     '--nw '+
 {$endif win32}
 {$endif win32}
-    '--nx --quiet --command='+GDBIniTempName+' '+CompilerName);
+    '--nx --command='+GDBIniTempName+' '+CompilerName);
   GDBError:=DosError;
   GDBError:=DosError;
   GDBExitCode:=DosExitCode;
   GDBExitCode:=DosExitCode;
   if (GDBError<>0) or (GDBExitCode<>0) then
   if (GDBError<>0) or (GDBExitCode<>0) then