fpmrun.inc 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  1. {
  2. $Id$
  3. This file is part of the Free Pascal Integrated Development Environment
  4. Copyright (c) 1998 by Berczi Gabor
  5. Run menu entries
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. {$define MODIFIEDINDEBUG}
  13. function TIDEApp.AskRecompileIfModified:boolean;
  14. var
  15. PW,PPW : PSourceWindow;
  16. Checkmodifiededitor : boolean;
  17. begin
  18. AskRecompileIfModified:=false;
  19. {$ifdef MODIFIEDINDEBUG}
  20. if not AskRecompileIfModifiedFlag then
  21. exit;
  22. Checkmodifiededitor:=false;
  23. PW:=FirstEditorWindow;
  24. PPW:=PW;
  25. while assigned(PW) do
  26. begin
  27. If PW^.HelpCtx=hcSourceWindow then
  28. begin
  29. if pw^.editor^.getmodified then
  30. if pw^.editor^.core^.getmodifytime > LastCompileTime then
  31. begin
  32. Checkmodifiededitor:=true;
  33. break;
  34. end;
  35. end;
  36. PW:=PSourceWindow(PW^.next);
  37. While assigned(PW) and (PW<>PPW) and (PW^.HelpCtx<>hcSourceWindow) do
  38. PW:=PSourceWindow(PW^.next);
  39. If PW=PPW then
  40. break;
  41. end;
  42. if Checkmodifiededitor then
  43. begin
  44. if (MessageBox(#3+'You''ve edited a file, recompile the project?',nil,mfinformation+mfyesbutton+mfnobutton)=cmYes) then
  45. begin
  46. {$IFNDEF NODEBUG}
  47. if Assigned(Debugger) then
  48. begin
  49. if Debugger^.IsRunning then
  50. RestartingDebugger:=true;
  51. end;
  52. DoResetDebugger;
  53. {$ENDIF}
  54. DoRun;
  55. AskRecompileIfModified:=true;
  56. end
  57. else
  58. AskRecompileIfModifiedFlag:=false;
  59. end;
  60. {$endif MODIFIEDINDEBUG}
  61. end;
  62. procedure TIDEApp.DoStepOver;
  63. begin
  64. {$ifndef NODEBUG}
  65. if not assigned(Debugger) or Not Debugger^.HasExe then
  66. begin
  67. InitDebugger;
  68. if not assigned(Debugger) then
  69. begin
  70. NoDebugger;
  71. exit;
  72. end;
  73. end;
  74. if not Debugger^.IsRunning then
  75. Debugger^.StartTrace
  76. else
  77. begin
  78. if AskRecompileIfModified then
  79. exit;
  80. if InDisassemblyWindow then
  81. Debugger^.TraceNextI
  82. else
  83. Debugger^.TraceNext;
  84. end;
  85. {While (Debugger^.InvalidSourceLine and
  86. Debugger^.IsRunning and
  87. not Debugger^.error) do
  88. begin
  89. Inc(Debugger^.HiddenStepsCount);
  90. if InDisassemblyWindow then
  91. Debugger^.TraceNextI
  92. else
  93. Debugger^.TraceNext;
  94. end;}
  95. Debugger^.AnnotateError;
  96. {$else NODEBUG}
  97. NoDebugger;
  98. {$endif NODEBUG}
  99. end;
  100. procedure TIDEApp.DoTraceInto;
  101. begin
  102. {$ifndef NODEBUG}
  103. if not assigned(Debugger) or Not Debugger^.HasExe then
  104. begin
  105. InitDebugger;
  106. if not assigned(Debugger) then
  107. begin
  108. NoDebugger;
  109. exit;
  110. end;
  111. end;
  112. if not debugger^.IsRunning then
  113. Debugger^.StartTrace
  114. else
  115. begin
  116. if AskRecompileIfModified then
  117. exit;
  118. if InDisassemblyWindow then
  119. Debugger^.TraceStepI
  120. else
  121. Debugger^.TraceStep;
  122. end;
  123. { I think we should not try to go deeper !
  124. if the source is not found PM }
  125. While (Debugger^.InvalidSourceLine and
  126. Debugger^.IsRunning and
  127. not Debugger^.error) do
  128. begin
  129. Inc(Debugger^.HiddenStepsCount);
  130. if InDisassemblyWindow then
  131. Debugger^.TraceNextI
  132. else
  133. Debugger^.TraceNext;
  134. end;
  135. Debugger^.AnnotateError;
  136. {$else NODEBUG}
  137. NoDebugger;
  138. {$endif NODEBUG}
  139. end;
  140. procedure TIDEApp.DoContUntilReturn;
  141. begin
  142. {$ifndef NODEBUG}
  143. if not assigned(Debugger) or Not Debugger^.HasExe then
  144. begin
  145. InitDebugger;
  146. if not assigned(Debugger) then
  147. begin
  148. NoDebugger;
  149. exit;
  150. end;
  151. end;
  152. if not debugger^.IsRunning then
  153. Debugger^.Run
  154. else
  155. begin
  156. if AskRecompileIfModified then
  157. exit;
  158. Debugger^.UntilReturn;
  159. end;
  160. Debugger^.AnnotateError;
  161. {$else NODEBUG}
  162. NoDebugger;
  163. {$endif NODEBUG}
  164. end;
  165. procedure TIDEApp.DoRun;
  166. var
  167. RunDirect : boolean;
  168. begin
  169. {$ifndef NODEBUG}
  170. if not assigned(Debugger) or not Debugger^.HasExe or not Debugger^.IsRunning then
  171. {$endif}
  172. begin
  173. if (not ExistsFile(ExeFile)) or (CompilationPhase<>cpDone) or
  174. NeedRecompile(cRun,false) then
  175. begin
  176. DoCompile(cRun);
  177. if CompilationPhase<>cpDone then
  178. Exit;
  179. if not Status.IsExe then
  180. begin
  181. ErrorBox(msg_cannotrununit,nil);
  182. Exit;
  183. end;
  184. if IsLibrary then
  185. begin
  186. ErrorBox(msg_cannotrunlibrary,nil);
  187. Exit;
  188. end;
  189. end;
  190. if (EXEFile='') then
  191. begin
  192. ErrorBox(msg_nothingtorun,nil);
  193. Exit;
  194. end;
  195. if not ExistsFile(ExeFile) then
  196. begin
  197. MsgParms[1].Ptr:=@EXEFile;
  198. ErrorBox(msg_invalidfilename,@MsgParms);
  199. Exit;
  200. end;
  201. RunDirect:=true;
  202. {$ifndef NODEBUG}
  203. { we use debugger if and only if there are active breakpoints
  204. AND the target is correct for debugging !! PM }
  205. if (ActiveBreakpoints or RestartingDebugger) and
  206. {$ifdef COMPILER_1_0}
  207. (target_os.shortname=source_os.shortname)
  208. {$else COMPILER_1_0}
  209. (target_info.shortname=source_info.shortname)
  210. {$endif COMPILER_1_0}
  211. then
  212. begin
  213. if not assigned(Debugger) or Not Debugger^.HasExe then
  214. InitDebugger;
  215. if assigned(Debugger) then
  216. begin
  217. if RestartingDebugger then
  218. begin
  219. RestartingDebugger:=false;
  220. Debugger^.StartTrace;
  221. end
  222. else
  223. Debugger^.Run;
  224. RunDirect:=false;
  225. end;
  226. end;
  227. {$endif ndef NODEBUG}
  228. if Not RunDirect then
  229. exit;
  230. {$ifdef Unix}
  231. if (DebuggeeTTY<>'') then
  232. DoExecute(ExeFile,GetRunParameters,DebuggeeTTY,DebuggeeTTY,DebuggeeTTY,exNormal)
  233. else
  234. {$endif Unix}
  235. DoExecute(ExeFile,GetRunParameters,'','','',exNormal);
  236. { In case we have something that the compiler touched }
  237. AskToReloadAllModifiedFiles;
  238. LastExitCode:=ExecuteResult;
  239. If IOStatus<>0 then
  240. begin
  241. MsgParms[1].Ptr:=@EXEFile;
  242. MsgParms[2].long:=IOStatus;
  243. InformationBox(msg_programnotrundoserroris,@MsgParms);
  244. end
  245. else If LastExitCode<>0 then
  246. begin
  247. MsgParms[1].Ptr:=@EXEFile;
  248. MsgParms[2].long:=LastExitCode;
  249. InformationBox(msg_programfileexitedwithexitcode,@MsgParms);
  250. end;
  251. end
  252. {$ifndef NODEBUG}
  253. else
  254. Debugger^.Continue
  255. {$endif}
  256. ;
  257. end;
  258. procedure TIDEApp.UpdateRunMenu(DebuggeeRunning : boolean);
  259. var MenuItem : PMenuItem;
  260. begin
  261. MenuItem:=PAdvancedMenuBar(MenuBar)^.GetMenuItem(cmRun);
  262. if assigned(MenuItem) then
  263. begin
  264. If assigned(MenuItem^.Name) then
  265. DisposeStr(MenuItem^.Name);
  266. if DebuggeeRunning then
  267. MenuItem^.Name:=NewStr(menu_run_continue)
  268. else
  269. MenuItem^.Name:=NewStr(menu_run_run);
  270. end;
  271. MenuItem:=PAdvancedMenuBar(MenuBar)^.GetMenuItem(cmResetDebugger);
  272. if assigned(MenuItem) then
  273. MenuItem^.Disabled:=not DebuggeeRunning;
  274. MenuItem:=PAdvancedMenuBar(MenuBar)^.GetMenuItem(cmUntilReturn);
  275. if assigned(MenuItem) then
  276. MenuItem^.Disabled:=not DebuggeeRunning;
  277. end;
  278. procedure TIDEApp.Parameters;
  279. var R,R2: TRect;
  280. D: PCenterDialog;
  281. IL: PEditorInputLine;
  282. begin
  283. R.Assign(0,0,round(ScreenWidth*54/80),4);
  284. New(D, Init(R, dialog_programparameters));
  285. with D^ do
  286. begin
  287. GetExtent(R); R.Grow(-2,-1); Inc(R.A.Y); R.B.Y:=R.A.Y+1;
  288. R2.Copy(R); R2.A.X:=16; Dec(R2.B.X,4);
  289. New(IL, Init(R2, 255));
  290. IL^.Data^:=GetRunParameters;
  291. Insert(IL);
  292. R2.Copy(R); R2.A.X:=R2.B.X-3; R2.B.X:=R2.A.X+3;
  293. Insert(New(PHistory, Init(R2, IL, hidRunParameters)));
  294. R2.Copy(R); R2.B.X:=16;
  295. Insert(New(PLabel, Init(R2, label_parameters_parameter, IL)));
  296. end;
  297. InsertButtons(D);
  298. IL^.Select;
  299. if Desktop^.ExecView(D)=cmOK then
  300. begin
  301. SetRunParameters(IL^.Data^);
  302. end;
  303. Dispose(D, Done);
  304. end;
  305. procedure TIDEApp.DoResetDebugger;
  306. begin
  307. {$ifndef NODEBUG}
  308. if assigned(Debugger) then
  309. DoneDebugger;
  310. UpdateScreen(true);
  311. {$else NODEBUG}
  312. NoDebugger;
  313. {$endif NODEBUG}
  314. end;
  315. procedure TIDEApp.DoContToCursor;
  316. {$ifndef NODEBUG}
  317. var
  318. W : PFPWindow;
  319. PDL : PDisasLine;
  320. S,FileName : string;
  321. P,CurY,LineNr : longint;
  322. {$endif}
  323. begin
  324. {$ifndef NODEBUG}
  325. if (DeskTop^.Current=nil) or
  326. ((TypeOf(DeskTop^.Current^)<>TypeOf(TSourceWindow)) and
  327. (TypeOf(DeskTop^.Current^)<>TypeOf(TDisassemblyWindow))) then
  328. Begin
  329. ErrorBox(msg_impossibletoreachcursor,nil);
  330. Exit;
  331. End;
  332. If not assigned(Debugger) or Not Debugger^.HasExe then
  333. begin
  334. InitDebugger;
  335. if not assigned(Debugger) then
  336. begin
  337. NoDebugger;
  338. exit;
  339. end;
  340. end;
  341. W:=PFPWindow(DeskTop^.Current);
  342. If assigned(W) then
  343. begin
  344. If TypeOf(W^)=TypeOf(TSourceWindow) then
  345. begin
  346. FileName:=PSourceWindow(W)^.Editor^.FileName;
  347. LineNr:=PSourceWindow(W)^.Editor^.CurPos.Y+1;
  348. Debugger^.Command('tbreak '+GDBFileName(NameAndExtOf(FileName))+':'+IntToStr(LineNr));
  349. Debugger^.Continue;
  350. end
  351. else
  352. begin
  353. CurY:=PDisassemblyWindow(W)^.Editor^.CurPos.Y;
  354. if CurY<PDisassemblyWindow(W)^.Editor^.GetLineCount then
  355. PDL:=PDisasLine(PDisassemblyWindow(W)^.Editor^.GetLine(CurY))
  356. else
  357. PDL:=nil;
  358. if assigned(PDL) then
  359. begin
  360. if PDL^.Address<>0 then
  361. begin
  362. Debugger^.Command('tbreak *0x'+IntToHex(PDL^.Address,8));
  363. end
  364. else
  365. begin
  366. S:=PDisassemblyWindow(W)^.Editor^.GetDisplayText(PDisassemblyWindow(W)^.Editor^.CurPos.Y);
  367. p:=pos(':',S);
  368. FileName:=Copy(S,1,p-1);
  369. S:=Copy(S,p+1,high(S));
  370. p:=pos(' ',S);
  371. S:=Copy(S,1,p-1);
  372. LineNr:=StrToInt(S);
  373. Debugger^.Command('tbreak '+GDBFileName(NameAndExtOf(FileName))+':'+IntToStr(LineNr));
  374. end;
  375. Debugger^.Continue;
  376. end;
  377. end;
  378. end;
  379. {$else NODEBUG}
  380. NoDebugger;
  381. {$endif NODEBUG}
  382. end;
  383. procedure TIDEApp.DoOpenGDBWindow;
  384. begin
  385. {$ifndef NODEBUG}
  386. InitGDBWindow;
  387. if not assigned(Debugger) then
  388. begin
  389. new(Debugger,Init);
  390. if assigned(Debugger) then
  391. Debugger^.SetExe(ExeFile);
  392. end;
  393. If assigned(GDBWindow) then
  394. GDBWindow^.MakeFirst;
  395. {$else NODEBUG}
  396. NoDebugger;
  397. {$endif NODEBUG}
  398. end;
  399. procedure TIDEApp.DoToggleBreak;
  400. {$ifndef NODEBUG}
  401. var
  402. W : PSourceWindow;
  403. WD : PDisassemblyWindow;
  404. PDL : PDisasLine;
  405. PB : PBreakpoint;
  406. S,FileName : string;
  407. b : boolean;
  408. CurY,P,LineNr : longint;
  409. {$endif}
  410. begin
  411. {$ifndef NODEBUG}
  412. if (DeskTop^.Current=nil) or
  413. (TypeOf(DeskTop^.Current^)<>TypeOf(TSourceWindow)) and
  414. (TypeOf(DeskTop^.Current^)<>TypeOf(TDisassemblyWindow)) then
  415. Begin
  416. ErrorBox(msg_impossibletosetbreakpoint,nil);
  417. Exit;
  418. End;
  419. if assigned (DeskTop^.Current) and
  420. (TypeOf(DeskTop^.Current^)=TypeOf(TSourceWindow)) then
  421. begin
  422. W:=PSourceWindow(DeskTop^.Current);
  423. FileName:=W^.Editor^.FileName;
  424. If FileName='' then
  425. begin
  426. W^.Editor^.SaveAs;
  427. FileName:=W^.Editor^.FileName;
  428. If FileName='' then
  429. Begin
  430. ErrorBox(msg_impossibletosetbreakpoint,nil);
  431. Exit;
  432. End;
  433. end;
  434. LineNr:=W^.Editor^.CurPos.Y+1;
  435. BreakpointsCollection^.ToggleFileLine(FileName,LineNr);
  436. end
  437. else if assigned (DeskTop^.Current) and
  438. (TypeOf(DeskTop^.Current^)=TypeOf(TDisassemblyWindow)) then
  439. begin
  440. WD:=PDisassemblyWindow(DeskTop^.Current);
  441. CurY:=WD^.Editor^.CurPos.Y;
  442. if CurY<WD^.Editor^.GetLineCount then
  443. PDL:=PDisasLine(WD^.Editor^.GetLine(CurY))
  444. else
  445. PDL:=nil;
  446. if assigned(PDL) then
  447. begin
  448. if PDL^.Address<>0 then
  449. begin
  450. PB:=New(PBreakpoint,init_address(IntToHex(PDL^.Address,8)));
  451. BreakpointsCollection^.Insert(PB);
  452. WD^.Editor^.SetLineFlagState(CurY,lfBreakpoint,true);
  453. end
  454. else
  455. begin
  456. S:=WD^.Editor^.GetDisplayText(WD^.Editor^.CurPos.Y);
  457. p:=pos(':',S);
  458. FileName:=Copy(S,1,p-1);
  459. S:=Copy(S,p+1,high(S));
  460. p:=pos(' ',S);
  461. S:=Copy(S,1,p-1);
  462. LineNr:=StrToInt(S);
  463. b:=BreakpointsCollection^.ToggleFileLine(FileName,LineNr);
  464. WD^.Editor^.SetLineFlagState(CurY,lfBreakpoint,b);
  465. end;
  466. end;
  467. end;
  468. {$else NODEBUG}
  469. NoDebugger;
  470. {$endif NODEBUG}
  471. end;
  472. {
  473. $Log$
  474. Revision 1.8 2002-12-18 01:21:42 pierre
  475. + Use TEditorInputLine instead of TInputLine
  476. Revision 1.7 2002/12/16 09:06:08 pierre
  477. * don't insert breakpoints in unsaved sources
  478. Revision 1.6 2002/10/12 19:43:07 hajny
  479. * missing HasSignal conditionals added (needed for FPC/2)
  480. Revision 1.5 2002/09/07 15:40:44 peter
  481. * old logs removed and tabs fixed
  482. Revision 1.4 2002/09/05 08:45:59 pierre
  483. * try to fix recompilation on changes problems
  484. Revision 1.3 2002/08/13 08:59:12 pierre
  485. + Run menu changes depending on wether the debuggee is running or not
  486. }