gdbcon.pp 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. {
  2. $Id$
  3. Copyright (c) 1998 by Peter Vreman
  4. Lowlevel GDB interface which communicates directly with libgdb
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. unit GDBCon;
  12. interface
  13. uses
  14. GDBInt;
  15. type
  16. PGDBController=^TGDBController;
  17. TGDBController=object(TGDBInterface)
  18. progname : pchar;
  19. progargs : pchar;
  20. in_command,
  21. init_count : longint;
  22. constructor Init;
  23. destructor Done;
  24. procedure CommandBegin(const s:string);virtual;
  25. procedure Command(const s:string);
  26. procedure CommandEnd(const s:string);virtual;
  27. procedure Reset;virtual;
  28. { tracing }
  29. procedure StartTrace;
  30. procedure Run;virtual;
  31. procedure TraceStep;virtual;
  32. procedure TraceNext;virtual;
  33. procedure Continue;virtual;
  34. { needed for dos because newlines are only #10 (PM) }
  35. procedure WriteErrorBuf;
  36. procedure WriteOutputBuf;
  37. function GetOutput : Pchar;
  38. function GetError : Pchar;
  39. function LoadFile(var fn:string):boolean;
  40. procedure SetArgs(const s : string);
  41. procedure ClearSymbols;
  42. end;
  43. procedure UnixDir(var s : string);
  44. implementation
  45. uses
  46. strings;
  47. procedure UnixDir(var s : string);
  48. var i : longint;
  49. begin
  50. for i:=1 to length(s) do
  51. if s[i]='\' then s[i]:='/';
  52. end;
  53. constructor TGDBController.Init;
  54. begin
  55. inherited init;
  56. end;
  57. destructor TGDBController.Done;
  58. begin
  59. if assigned(progname) then
  60. strdispose(progname);
  61. if assigned(progargs) then
  62. strdispose(progargs);
  63. inherited done;
  64. end;
  65. procedure TGDBController.Command(const s:string);
  66. begin
  67. CommandBegin(s);
  68. gdboutputbuf.reset;
  69. gdberrorbuf.reset;
  70. inc(in_command);
  71. gdb_command(s);
  72. dec(in_command);
  73. {
  74. What is that for ?? PM
  75. I had to comment it because
  76. it resets the debuggere after each command !!
  77. Maybe it can happen on errors ??
  78. if in_command<0 then
  79. begin
  80. in_command:=0;
  81. inc(in_command);
  82. Reset;
  83. dec(in_command);
  84. end; }
  85. CommandEnd(s);
  86. end;
  87. procedure TGDBController.CommandBegin(const s:string);
  88. begin
  89. end;
  90. procedure TGDBController.CommandEnd(const s:string);
  91. begin
  92. end;
  93. function TGDBController.LoadFile(var fn:string):boolean;
  94. var
  95. cmd : string;
  96. begin
  97. getdir(0,cmd);
  98. UnixDir(cmd);
  99. cmd:='cd '+cmd;
  100. Command(cmd);
  101. GDB__Init;
  102. UnixDir(fn);
  103. if assigned(progname) then
  104. strdispose(progname);
  105. getmem(progname,length(fn)+1);
  106. strpcopy(progname,fn);
  107. Command('file '+fn);
  108. LoadFile:=true;
  109. end;
  110. procedure TGDBController.SetArgs(const s : string);
  111. begin
  112. if assigned(progargs) then
  113. strdispose(progargs);
  114. getmem(progargs,length(s)+1);
  115. strpcopy(progargs,s);
  116. command('set args '+s);
  117. end;
  118. procedure TGDBController.Reset;
  119. begin
  120. call_reset:=false;
  121. { DeleteBreakPoints(); }
  122. if debuggee_started then
  123. begin
  124. reset_command:=true;
  125. BreakSession;
  126. Command('kill');
  127. reset_command:=false;
  128. debuggee_started:=false;
  129. end;
  130. end;
  131. procedure TGDBController.StartTrace;
  132. begin
  133. Command('tbreak PASCALMAIN');
  134. Run;
  135. end;
  136. procedure TGDBController.Run;
  137. begin
  138. Command('run');
  139. inc(init_count);
  140. end;
  141. procedure TGDBController.TraceStep;
  142. begin
  143. Command('step');
  144. end;
  145. procedure TGDBController.TraceNext;
  146. begin
  147. Command('next');
  148. end;
  149. procedure TGDBController.Continue;
  150. begin
  151. Command('continue');
  152. end;
  153. procedure TGDBController.ClearSymbols;
  154. begin
  155. if debuggee_started then
  156. Reset;
  157. if init_count>0 then
  158. Command('file');
  159. end;
  160. procedure BufWrite(Buf : pchar);
  161. var p,pe : pchar;
  162. begin
  163. p:=buf;
  164. While assigned(p) do
  165. begin
  166. pe:=strscan(p,#10);
  167. if pe<>nil then
  168. pe^:=#0;
  169. Writeln(p);
  170. { restore for dispose }
  171. if pe<>nil then
  172. pe^:=#10;
  173. if pe=nil then
  174. p:=nil
  175. else
  176. begin
  177. p:=pe;
  178. inc(p);
  179. end;
  180. end;
  181. end;
  182. function TGDBController.GetOutput : Pchar;
  183. begin
  184. GetOutput:=gdboutputbuf.buf;
  185. end;
  186. function TGDBController.GetError : Pchar;
  187. var p : pchar;
  188. begin
  189. p:=gdberrorbuf.buf;
  190. if (p^=#0) and got_error then
  191. GetError:=pchar(longint(gdboutputbuf.buf)+gdboutputbuf.idx)
  192. else
  193. GetError:=p;
  194. end;
  195. procedure TGDBController.WriteErrorBuf;
  196. begin
  197. BufWrite(gdberrorbuf.buf);
  198. end;
  199. procedure TGDBController.WriteOutputBuf;
  200. begin
  201. BufWrite(gdboutputbuf.buf);
  202. end;
  203. end.
  204. {
  205. $Log$
  206. Revision 1.1 2000-07-13 06:33:58 michael
  207. + Initial import
  208. Revision 1.1 1999/11/24 23:36:32 peter
  209. * moved to packages dir
  210. Revision 1.3 1999/08/23 09:16:48 pierre
  211. * Better GetError code
  212. Revision 1.2 1999/07/12 13:08:19 pierre
  213. + added GDBVersion function
  214. * tries to intercept quit command from GDB Window
  215. + AllowQuit method
  216. Revision 1.1 1999/05/22 13:43:00 peter
  217. * moved
  218. Revision 1.12 1999/02/11 13:03:27 pierre
  219. Problem with last commit
  220. + added virtuals CommandBegin and CommandEnd
  221. + added command_level for TGDBInterface
  222. Revision 1.10 1999/02/10 09:00:42 pierre
  223. * duplicate call_reset removed
  224. * frames allocation and freeing corrected
  225. + GetError and GetOutput pchar function added
  226. + stop_breakpoint_number to know why the program stopped
  227. (used for watches)
  228. Revision 1.9 1999/02/08 17:35:09 pierre
  229. + added Run made TraceStep TraceNext Continue virtual
  230. Revision 1.8 1999/02/08 14:00:00 pierre
  231. - removed second debugger_started in TGDBController
  232. + StartTrace and Reset made virtual to be able to
  233. change CmResetDebugger state in IDE
  234. Revision 1.7 1999/02/08 11:37:13 pierre
  235. + added procargs var and SetArgs method
  236. Revision 1.6 1999/02/04 14:29:35 pierre
  237. + Continue command added
  238. * Reset inside command removed
  239. Revision 1.5 1999/01/22 18:07:44 pierre
  240. * Loadfile arg changed to var
  241. Revision 1.4 1999/01/22 18:05:40 pierre
  242. * change dir sep from to / for dos
  243. Revision 1.3 1999/01/22 10:23:49 peter
  244. * small update to get it working with the IDE
  245. Revision 1.2 1999/01/18 11:01:58 pierre
  246. + working version for go32v2
  247. Revision 1.1 1998/10/07 15:57:38 peter
  248. * initial version
  249. Revision 1.1 1998/10/07 15:48:20 peter
  250. * initial version
  251. }