gdbcon.pp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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.2 2000-07-13 11:33:15 michael
  207. + removed logs
  208. }