gdbmicon.pas 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. start_break_number: LongInt;
  22. in_command: LongInt;
  23. procedure CommandBegin(const s: string); virtual;
  24. procedure CommandEnd(const s: string); virtual;
  25. public
  26. constructor Init;
  27. destructor Done;
  28. procedure Command(const s: string);
  29. procedure Reset; virtual;
  30. { tracing }
  31. procedure StartTrace;
  32. procedure Run; virtual;
  33. procedure TraceStep;
  34. procedure TraceNext;
  35. procedure TraceStepI;
  36. procedure TraceNextI;
  37. procedure Continue; virtual;
  38. function LoadFile(var fn: string): Boolean;
  39. procedure SetDir(const s: string);
  40. procedure SetArgs(const s: string);
  41. end;
  42. implementation
  43. procedure UnixDir(var s : string);
  44. var i : longint;
  45. begin
  46. for i:=1 to length(s) do
  47. if s[i]='\' then
  48. {$ifdef win32}
  49. { Don't touch at '\ ' used to escapes spaces in windows file names PM }
  50. if (i=length(s)) or (s[i+1]<>' ') then
  51. {$endif win32}
  52. s[i]:='/';
  53. {$ifdef win32}
  54. {$ifndef USE_MINGW_GDB}
  55. { for win32 we should convert e:\ into //e/ PM }
  56. if (length(s)>2) and (s[2]=':') and (s[3]='/') then
  57. s:=CygDrivePrefix+'/'+s[1]+copy(s,3,length(s));
  58. {$endif USE_MINGW_GDB}
  59. {$endif win32}
  60. end;
  61. constructor TGDBController.Init;
  62. begin
  63. inherited Init;
  64. end;
  65. destructor TGDBController.Done;
  66. begin
  67. inherited Done;
  68. end;
  69. procedure TGDBController.CommandBegin(const s: string);
  70. begin
  71. end;
  72. procedure TGDBController.Command(const s: string);
  73. begin
  74. Inc(in_command);
  75. CommandBegin(s);
  76. GDBOutputBuf.Reset;
  77. GDBErrorBuf.Reset;
  78. i_gdb_command(s);
  79. CommandEnd(s);
  80. Dec(in_command);
  81. end;
  82. procedure TGDBController.CommandEnd(const s: string);
  83. begin
  84. end;
  85. procedure TGDBController.Reset;
  86. begin
  87. end;
  88. procedure TGDBController.StartTrace;
  89. begin
  90. Command('-break-insert -t PASCALMAIN');
  91. start_break_number := GDB.ResultRecord.Parameters['bkpt'].AsTuple['number'].AsLongInt;
  92. Run;
  93. end;
  94. procedure TGDBController.Run;
  95. begin
  96. UserScreen;
  97. Command('-exec-run');
  98. WaitForProgramStop;
  99. end;
  100. procedure TGDBController.TraceStep;
  101. begin
  102. UserScreen;
  103. Command('-exec-step');
  104. WaitForProgramStop;
  105. end;
  106. procedure TGDBController.TraceNext;
  107. begin
  108. UserScreen;
  109. Command('-exec-next');
  110. WaitForProgramStop;
  111. end;
  112. procedure TGDBController.TraceStepI;
  113. begin
  114. UserScreen;
  115. Command('-exec-step-instruction');
  116. WaitForProgramStop;
  117. end;
  118. procedure TGDBController.TraceNextI;
  119. begin
  120. UserScreen;
  121. Command('-exec-next-instruction');
  122. WaitForProgramStop;
  123. end;
  124. procedure TGDBController.Continue;
  125. begin
  126. UserScreen;
  127. Command('-exec-continue');
  128. WaitForProgramStop;
  129. end;
  130. function TGDBController.LoadFile(var fn: string): Boolean;
  131. var
  132. cmd: string;
  133. begin
  134. getdir(0,cmd);
  135. UnixDir(cmd);
  136. Command('-environment-cd ' + cmd);
  137. GDBOutputBuf.Reset;
  138. GDBErrorBuf.Reset;
  139. UnixDir(fn);
  140. Command('-file-exec-and-symbols ' + fn);
  141. LoadFile := True;
  142. end;
  143. procedure TGDBController.SetDir(const s: string);
  144. var
  145. hs: string;
  146. begin
  147. hs:=s;
  148. UnixDir(hs);
  149. Command('-environment-cd ' + hs);
  150. end;
  151. procedure TGDBController.SetArgs(const s: string);
  152. begin
  153. Command('-exec-arguments ' + s);
  154. end;
  155. end.