gppc386.pp 3.9 KB

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