gdbmicon.pas 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. {
  2. Copyright (c) 2015 by Nikolay Nikolov
  3. Copyright (c) 1998 by Peter Vreman
  4. This is a replacement for GDBCon, implemented on top of GDB/MI,
  5. instead of LibGDB. This allows integration of GDB/MI support in the
  6. text mode IDE.
  7. See the file COPYING.FPC, included in this distribution,
  8. for details about the copyright.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. **********************************************************************}
  13. unit gdbmicon;
  14. {$MODE fpc}{$H-}
  15. interface
  16. uses
  17. gdbmiint, gdbmiwrap;
  18. type
  19. TGDBController = object(TGDBInterface)
  20. protected
  21. TBreakNumber,
  22. start_break_number: LongInt;
  23. in_command: LongInt;
  24. procedure CommandBegin(const s: string); virtual;
  25. procedure CommandEnd(const s: string); virtual;
  26. public
  27. constructor Init;
  28. destructor Done;
  29. procedure Command(const s: string);
  30. procedure Reset; virtual;
  31. { tracing }
  32. procedure StartTrace;
  33. procedure Run; virtual;
  34. procedure TraceStep;
  35. procedure TraceNext;
  36. procedure TraceStepI;
  37. procedure TraceNextI;
  38. procedure Continue; virtual;
  39. procedure UntilReturn; virtual;
  40. procedure SetTBreak(tbreakstring : string);
  41. function LoadFile(var fn: string): Boolean;
  42. procedure SetDir(const s: string);
  43. procedure SetArgs(const s: string);
  44. end;
  45. implementation
  46. {$ifdef Windows}
  47. uses
  48. Windebug;
  49. {$endif Windows}
  50. procedure UnixDir(var s : string);
  51. var i : longint;
  52. begin
  53. for i:=1 to length(s) do
  54. if s[i]='\' then
  55. {$ifdef windows}
  56. { Don't touch at '\ ' used to escapes spaces in windows file names PM }
  57. if (i=length(s)) or (s[i+1]<>' ') then
  58. {$endif windows}
  59. s[i]:='/';
  60. {$ifdef windows}
  61. { if we are using cygwin, we need to convert e:\ into /cygdriveprefix/e/ PM }
  62. if using_cygwin_gdb and (length(s)>2) and (s[2]=':') and (s[3]='/') then
  63. s:=CygDrivePrefix+'/'+s[1]+copy(s,3,length(s));
  64. {$endif windows}
  65. end;
  66. constructor TGDBController.Init;
  67. begin
  68. inherited Init;
  69. end;
  70. destructor TGDBController.Done;
  71. begin
  72. inherited Done;
  73. end;
  74. procedure TGDBController.CommandBegin(const s: string);
  75. begin
  76. end;
  77. procedure TGDBController.Command(const s: string);
  78. begin
  79. Inc(in_command);
  80. CommandBegin(s);
  81. GDBOutputBuf.Reset;
  82. GDBErrorBuf.Reset;
  83. i_gdb_command(s);
  84. CommandEnd(s);
  85. Dec(in_command);
  86. end;
  87. procedure TGDBController.CommandEnd(const s: string);
  88. begin
  89. end;
  90. procedure TGDBController.Reset;
  91. begin
  92. end;
  93. procedure TGDBController.StartTrace;
  94. begin
  95. Command('-break-insert -t PASCALMAIN');
  96. start_break_number := GDB.ResultRecord.Parameters['bkpt'].AsTuple['number'].AsLongInt;
  97. Run;
  98. end;
  99. procedure TGDBController.Run;
  100. begin
  101. UserScreen;
  102. Command('-exec-run');
  103. WaitForProgramStop;
  104. end;
  105. procedure TGDBController.TraceStep;
  106. begin
  107. UserScreen;
  108. Command('-exec-step');
  109. WaitForProgramStop;
  110. end;
  111. procedure TGDBController.TraceNext;
  112. begin
  113. UserScreen;
  114. Command('-exec-next');
  115. WaitForProgramStop;
  116. end;
  117. procedure TGDBController.TraceStepI;
  118. begin
  119. UserScreen;
  120. Command('-exec-step-instruction');
  121. WaitForProgramStop;
  122. end;
  123. procedure TGDBController.TraceNextI;
  124. begin
  125. UserScreen;
  126. Command('-exec-next-instruction');
  127. WaitForProgramStop;
  128. end;
  129. procedure TGDBController.Continue;
  130. begin
  131. UserScreen;
  132. Command('-exec-continue');
  133. WaitForProgramStop;
  134. end;
  135. procedure TGDBController.UntilReturn;
  136. begin
  137. UserScreen;
  138. Command('-exec-finish');
  139. WaitForProgramStop;
  140. end;
  141. procedure TGDBController.SetTBreak(tbreakstring : string);
  142. begin
  143. Command('-break-insert -t ' + tbreakstring);
  144. TBreakNumber := GDB.ResultRecord.Parameters['bkpt'].AsTuple['number'].AsLongInt;
  145. end;
  146. function TGDBController.LoadFile(var fn: string): Boolean;
  147. var
  148. cmd: string;
  149. begin
  150. getdir(0,cmd);
  151. UnixDir(cmd);
  152. Command('-environment-cd ' + cmd);
  153. GDBOutputBuf.Reset;
  154. GDBErrorBuf.Reset;
  155. UnixDir(fn);
  156. Command('-file-exec-and-symbols ' + fn);
  157. LoadFile := True;
  158. end;
  159. procedure TGDBController.SetDir(const s: string);
  160. var
  161. hs: string;
  162. begin
  163. hs:=s;
  164. UnixDir(hs);
  165. Command('-environment-cd ' + hs);
  166. end;
  167. procedure TGDBController.SetArgs(const s: string);
  168. begin
  169. Command('-exec-arguments ' + s);
  170. end;
  171. end.