gppc386.pp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. {
  2. $Id$
  3. Copyright (c) 2000-2002 by Pierre Muller
  4. This program allows to run the Makefiles
  5. with the compiler running inside GDB
  6. GDB only stops if there is something special
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU General Public License for more details.
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. ****************************************************************************}
  19. program fpc_with_gdb;
  20. {
  21. This program uses several files :
  22. -- 'gdb4fpc.ini' contains the standard breakpoints (see below)
  23. -- 'gdb.fpc' is an optional file that can contain any other
  24. instruction that GDB should do before starting.
  25. Note that if gdb.fpc is present, no "run" command is
  26. inserted if gdb4fpc.ini is found
  27. but it can be inserted in gdb.fpc itself
  28. }
  29. uses
  30. dos;
  31. const
  32. {$ifdef Unix}
  33. GDBExeName = 'gdbpas';
  34. GDBIniName = '.gdbinit';
  35. DefaultCompilerName = 'ppc386';
  36. {$else}
  37. GDBExeName = 'gdbpas.exe';
  38. GDBIniName = 'gdb.ini';
  39. DefaultCompilerName = 'ppc386.exe';
  40. {$endif not linux}
  41. { If you add a gdb.fpc file in a given directory }
  42. { GDB will read it; this allows you to add }
  43. { special tests in specific directories PM }
  44. FpcGDBIniName = 'gdb.fpc';
  45. GDBIniTempName = 'gdb4fpc.ini';
  46. var
  47. fpcgdbini : text;
  48. CompilerName,Dir,Name,Ext : String;
  49. GDBError,GDBExitCode,i : longint;
  50. begin
  51. fsplit(paramstr(0),Dir,Name,Ext);
  52. if (length(Name)>3) and (UpCase(Name[1])='G') then
  53. CompilerName:=Copy(Name,2,255)+Ext
  54. else
  55. CompilerName:=DefaultCompilerName;
  56. { support for info functions directly : used in makefiles }
  57. if (paramcount=1) and (pos('-i',Paramstr(1))=1) then
  58. begin
  59. Exec(fsearch(CompilerName,GetEnv('PATH')),Paramstr(1));
  60. exit;
  61. end;
  62. if fsearch(GDBIniTempName,'./')<>'' then
  63. begin
  64. Assign(fpcgdbini,GDBIniTempName);
  65. erase(fpcgdbini);
  66. end;
  67. Assign(fpcgdbini,GdbIniTempName);
  68. Rewrite(fpcgdbini);
  69. Writeln(fpcgdbini,'set language pascal');
  70. Writeln(fpcgdbini,'b SYSTEM_EXIT');
  71. Writeln(fpcgdbini,'cond 1 EXITCODE <> 0');
  72. Writeln(fpcgdbini,'b INTERNALERROR');
  73. Writeln(fpcgdbini,'b HANDLEERRORADDRFRAME');
  74. Writeln(fpcgdbini,'set $_exitcode := -1');
  75. Write(fpcgdbini,'set args');
  76. { this will not work correctly if there are " or '' inside the command line :( }
  77. for i:=1 to Paramcount do
  78. begin
  79. if pos(' ',Paramstr(i))>0 then
  80. Write(fpcgdbini,' "'+ParamStr(i)+'"')
  81. else
  82. Write(fpcgdbini,' '+ParamStr(i));
  83. end;
  84. Writeln(fpcgdbini);
  85. if fsearch(FpcGDBIniName,'./')<>'' then
  86. begin
  87. Writeln(fpcgdbini,'source '+FpcGDBIniName);
  88. end
  89. else
  90. Writeln(fpcgdbini,'run');
  91. Writeln(fpcgdbini,'if ($_exitcode = -1)');
  92. Writeln(fpcgdbini,' echo Program not completed');
  93. Writeln(fpcgdbini,'else');
  94. Writeln(fpcgdbini,' quit');
  95. Writeln(fpcgdbini,'end');
  96. Close(fpcgdbini);
  97. Exec(fsearch(GDBExeName,GetEnv('PATH')),
  98. {$ifdef win32}
  99. '--nw '+
  100. {$endif win32}
  101. '--nx --quiet --command='+GDBIniTempName+' '+CompilerName);
  102. GDBError:=DosError;
  103. GDBExitCode:=DosExitCode;
  104. if (GDBError<>0) or (GDBExitCode<>0) then
  105. begin
  106. Writeln('Error running GDB');
  107. if (GDBError<>0) then
  108. Writeln('DosError = ',GDBError);
  109. if (GDBExitCode<>0) then
  110. Writeln('DosExitCode = ',GDBExitCode);
  111. if GDBExitCode<>0 then
  112. RunError(GDBExitCode)
  113. else
  114. RunError(GDBError);
  115. end
  116. else
  117. Erase(fpcgdbini);
  118. end.
  119. {
  120. $Log$
  121. Revision 1.6 2004-02-22 14:52:59 hajny
  122. * compilation fixes + *w tools renamed to *
  123. Revision 1.5 2002/12/06 17:51:11 peter
  124. * merged cdecl and array fixes
  125. Revision 1.4 2002/06/02 09:44:17 marco
  126. * linux
  127. Revision 1.3 2002/05/18 13:34:27 peter
  128. * readded missing revisions
  129. }