2
0

fpdebug.pas 98 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750
  1. {
  2. This file is part of the Free Pascal Integrated Development Environment
  3. Copyright (c) 1998-2000 by Pierre Muller
  4. Debugger call routines for the IDE
  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 FPDebug;
  12. {$ifdef NODEBUG}
  13. interface
  14. implementation
  15. end.
  16. {$else}
  17. interface
  18. {$i globdir.inc}
  19. uses
  20. {$ifdef Windows}
  21. Windows,
  22. {$endif Windows}
  23. Objects,Dialogs,Drivers,Views,
  24. {$ifndef NODEBUG}
  25. GDBCon,GDBInt,
  26. {$endif NODEBUG}
  27. Menus,
  28. WViews,WEditor,
  29. FPViews;
  30. type
  31. {$ifndef NODEBUG}
  32. PDebugController=^TDebugController;
  33. TDebugController=object(TGDBController)
  34. InvalidSourceLine : boolean;
  35. { if true the current debugger raw will stay in middle of
  36. editor window when debugging PM }
  37. CenterDebuggerRow : TCentre;
  38. Disableallinvalidbreakpoints : boolean;
  39. OrigPwd, { pwd at startup }
  40. LastFileName : string;
  41. LastSource : PView; {PsourceWindow !! }
  42. HiddenStepsCount : longint;
  43. { no need to switch if using another terminal }
  44. NoSwitch : boolean;
  45. HasExe : boolean;
  46. RunCount : longint;
  47. WindowWidth : longint;
  48. FPCBreakErrorNumber : longint;
  49. {$ifdef SUPPORT_REMOTE}
  50. isRemoteDebugging:boolean;
  51. {$endif SUPPORT_REMOTE}
  52. constructor Init;
  53. procedure SetExe(const exefn:string);
  54. procedure SetWidth(AWidth : longint);
  55. procedure SetSourceDirs;
  56. destructor Done;
  57. procedure DoSelectSourceline(const fn:string;line:longint);virtual;
  58. { procedure DoStartSession;virtual;
  59. procedure DoBreakSession;virtual;}
  60. procedure DoEndSession(code:longint);virtual;
  61. procedure DoUserSignal;virtual;
  62. procedure AnnotateError;
  63. procedure InsertBreakpoints;
  64. procedure RemoveBreakpoints;
  65. procedure ReadWatches;
  66. procedure RereadWatches;
  67. procedure ResetBreakpointsValues;
  68. procedure DoDebuggerScreen;virtual;
  69. procedure DoUserScreen;virtual;
  70. procedure Reset;virtual;
  71. procedure ResetDebuggerRows;
  72. procedure Run;virtual;
  73. procedure Continue;virtual;
  74. procedure UntilReturn;virtual;
  75. procedure CommandBegin(const s:string);virtual;
  76. procedure CommandEnd(const s:string);virtual;
  77. function IsRunning : boolean;
  78. function AllowQuit : boolean;virtual;
  79. function GetValue(Const expr : string) : pchar;
  80. function GetFramePointer : CORE_ADDR;
  81. function GetLongintAt(addr : CORE_ADDR) : longint;
  82. function GetPointerAt(addr : CORE_ADDR) : CORE_ADDR;
  83. end;
  84. {$endif NODEBUG}
  85. BreakpointType = (bt_function,bt_file_line,bt_watch,
  86. bt_awatch,bt_rwatch,bt_address,bt_invalid);
  87. BreakpointState = (bs_enabled,bs_disabled,bs_deleted,bs_delete_after);
  88. PBreakpointCollection=^TBreakpointCollection;
  89. PBreakpoint=^TBreakpoint;
  90. TBreakpoint=object(TObject)
  91. typ : BreakpointType;
  92. state : BreakpointState;
  93. owner : PBreakpointCollection;
  94. Name : PString; { either function name or expr to watch }
  95. FileName : PString;
  96. OldValue,CurrentValue : Pstring;
  97. Line : Longint; { only used for bt_file_line type }
  98. Conditions : PString; { conditions relative to that breakpoint }
  99. IgnoreCount : Longint; { how many counts should be ignored }
  100. Commands : pchar; { commands that should be executed on breakpoint }
  101. GDBIndex : longint;
  102. GDBState : BreakpointState;
  103. constructor Init_function(Const AFunc : String);
  104. constructor Init_Address(Const AAddress : String);
  105. constructor Init_Empty;
  106. constructor Init_file_line(AFile : String; ALine : longint);
  107. constructor Init_type(atyp : BreakpointType;Const AnExpr : String);
  108. constructor Load(var S: TStream);
  109. procedure Store(var S: TStream);
  110. procedure Insert;
  111. procedure Remove;
  112. procedure Enable;
  113. procedure Disable;
  114. procedure UpdateSource;
  115. procedure ResetValues;
  116. destructor Done;virtual;
  117. end;
  118. TBreakpointCollection=object(TCollection)
  119. function At(Index: Integer): PBreakpoint;
  120. function GetGDB(index : longint) : PBreakpoint;
  121. function GetType(typ : BreakpointType;Const s : String) : PBreakpoint;
  122. function ToggleFileLine(FileName: String;LineNr : Longint) : boolean;
  123. procedure Update;
  124. procedure ShowBreakpoints(W : PFPWindow);
  125. function FindBreakpointAt(Editor : PSourceEditor; Line : longint) : PBreakpoint;
  126. procedure AdaptBreakpoints(Editor : PSourceEditor; Pos, Change : longint);
  127. procedure ShowAllBreakpoints;
  128. end;
  129. PBreakpointItem = ^TBreakpointItem;
  130. TBreakpointItem = object(TObject)
  131. Breakpoint : PBreakpoint;
  132. constructor Init(ABreakpoint : PBreakpoint);
  133. function GetText(MaxLen: Sw_integer): string; virtual;
  134. procedure Selected; virtual;
  135. function GetModuleName: string; virtual;
  136. end;
  137. PBreakpointsListBox = ^TBreakpointsListBox;
  138. TBreakpointsListBox = object(THSListBox)
  139. Transparent : boolean;
  140. NoSelection : boolean;
  141. MaxWidth : Sw_integer;
  142. (* ModuleNames : PStoreCollection; *)
  143. constructor Init(var Bounds: TRect; AHScrollBar, AVScrollBar: PScrollBar);
  144. procedure AddBreakpoint(P: PBreakpointItem); virtual;
  145. function GetText(Item,MaxLen: Sw_Integer): String; virtual;
  146. function GetLocalMenu: PMenu;virtual;
  147. procedure Clear; virtual;
  148. procedure TrackSource; virtual;
  149. procedure EditNew; virtual;
  150. procedure EditCurrent; virtual;
  151. procedure DeleteCurrent; virtual;
  152. procedure ToggleCurrent;
  153. procedure Draw; virtual;
  154. procedure HandleEvent(var Event: TEvent); virtual;
  155. constructor Load(var S: TStream);
  156. procedure Store(var S: TStream);
  157. destructor Done; virtual;
  158. end;
  159. PBreakpointsWindow = ^TBreakpointsWindow;
  160. TBreakpointsWindow = object(TFPDlgWindow)
  161. BreakLB : PBreakpointsListBox;
  162. constructor Init;
  163. procedure AddBreakpoint(ABreakpoint : PBreakpoint);
  164. procedure ClearBreakpoints;
  165. procedure ReloadBreakpoints;
  166. procedure Close; virtual;
  167. procedure SizeLimits(var Min, Max: TPoint);virtual;
  168. procedure HandleEvent(var Event: TEvent); virtual;
  169. procedure Update; virtual;
  170. constructor Load(var S: TStream);
  171. procedure Store(var S: TStream);
  172. destructor Done; virtual;
  173. end;
  174. PBreakpointItemDialog = ^TBreakpointItemDialog;
  175. TBreakpointItemDialog = object(TCenterDialog)
  176. constructor Init(ABreakpoint: PBreakpoint);
  177. function Execute: Word; virtual;
  178. private
  179. Breakpoint : PBreakpoint;
  180. TypeRB : PRadioButtons;
  181. NameIL : PEditorInputLine;
  182. ConditionsIL: PEditorInputLine;
  183. LineIL : PEditorInputLine;
  184. IgnoreIL : PEditorInputLine;
  185. end;
  186. PWatch = ^TWatch;
  187. TWatch = Object(TObject)
  188. constructor Init(s : string);
  189. constructor Load(var S: TStream);
  190. procedure Store(var S: TStream);
  191. procedure rename(s : string);
  192. procedure Get_new_value;
  193. procedure Force_new_value;
  194. destructor done;virtual;
  195. expr : pstring;
  196. last_value,current_value : pchar;
  197. private
  198. GDBRunCount : longint;
  199. end;
  200. PWatchesCollection = ^TWatchesCollection;
  201. TWatchesCollection = Object(TCollection)
  202. constructor Init;
  203. procedure Insert(Item: Pointer); virtual;
  204. function At(Index: Integer): PWatch;
  205. procedure Update;
  206. private
  207. MaxW : integer;
  208. end;
  209. PWatchesListBox = ^TWatchesListBox;
  210. TWatchesListBox = object(THSListBox)
  211. Transparent : boolean;
  212. MaxWidth : Sw_integer;
  213. constructor Init(var Bounds: TRect; AHScrollBar, AVScrollBar: PScrollBar);
  214. (* procedure AddWatch(P: PWatch); virtual; *)
  215. procedure Update(AMaxWidth : integer);
  216. function GetText (Item: Sw_Integer; MaxLen: Sw_Integer): String; Virtual;
  217. function GetIndentedText(Item,Indent,MaxLen: Sw_Integer;var Modified : boolean): String; virtual;
  218. function GetLocalMenu: PMenu;virtual;
  219. (* procedure Clear; virtual;
  220. procedure TrackSource; virtual;*)
  221. procedure EditNew; virtual;
  222. procedure EditCurrent; virtual;
  223. procedure DeleteCurrent; virtual;
  224. (*procedure ToggleCurrent; *)
  225. procedure Draw; virtual;
  226. procedure HandleEvent(var Event: TEvent); virtual;
  227. constructor Load(var S: TStream);
  228. procedure Store(var S: TStream);
  229. destructor Done; virtual;
  230. end;
  231. PWatchItemDialog = ^TWatchItemDialog;
  232. TWatchItemDialog = object(TCenterDialog)
  233. constructor Init(AWatch: PWatch);
  234. function Execute: Word; virtual;
  235. private
  236. Watch : PWatch;
  237. NameIL : PEditorInputLine;
  238. TextST : PAdvancedStaticText;
  239. end;
  240. PWatchesWindow = ^TWatchesWindow;
  241. TWatchesWindow = Object(TFPDlgWindow)
  242. WLB : PWatchesListBox;
  243. Constructor Init;
  244. constructor Load(var S: TStream);
  245. procedure Store(var S: TStream);
  246. procedure Update; virtual;
  247. destructor Done; virtual;
  248. end;
  249. PFramesListBox = ^TFramesListBox;
  250. TFramesListBox = object(TMessageListBox)
  251. constructor Init(var Bounds: TRect; AHScrollBar, AVScrollBar: PScrollBar);
  252. procedure Update;
  253. function GetLocalMenu: PMenu;virtual;
  254. procedure GotoSource; virtual;
  255. procedure GotoAssembly; virtual;
  256. procedure HandleEvent(var Event: TEvent); virtual;
  257. destructor Done; virtual;
  258. end;
  259. PStackWindow = ^TStackWindow;
  260. TStackWindow = Object(TFPDlgWindow)
  261. FLB : PFramesListBox;
  262. Constructor Init;
  263. constructor Load(var S: TStream);
  264. procedure Store(var S: TStream);
  265. procedure Update; virtual;
  266. destructor Done; virtual;
  267. end;
  268. procedure InitStackWindow;
  269. procedure DoneStackWindow;
  270. function ActiveBreakpoints : boolean;
  271. function GDBFileName(st : string) : string;
  272. function OSFileName(st : string) : string;
  273. const
  274. BreakpointTypeStr : Array[BreakpointType] of String[9]
  275. = ( 'function','file-line','watch','awatch','rwatch','address','invalid');
  276. BreakpointStateStr : Array[BreakpointState] of String[8]
  277. = ( 'enabled','disabled','invalid',''{'to be deleted' should never be used});
  278. var
  279. {$ifndef NODEBUG}
  280. Debugger : PDebugController;
  281. {$endif NODEBUG}
  282. BreakpointsCollection : PBreakpointCollection;
  283. WatchesCollection : PwatchesCollection;
  284. procedure InitDebugger;
  285. procedure DoneDebugger;
  286. procedure InitGDBWindow;
  287. procedure DoneGDBWindow;
  288. procedure InitDisassemblyWindow;
  289. procedure DoneDisassemblyWindow;
  290. procedure InitBreakpoints;
  291. procedure DoneBreakpoints;
  292. procedure InitWatches;
  293. procedure DoneWatches;
  294. procedure RegisterFPDebugViews;
  295. procedure UpdateDebugViews;
  296. implementation
  297. uses
  298. Dos,
  299. {$ifdef fpc}
  300. Video,
  301. {$endif fpc}
  302. {$ifdef DOS}
  303. fpusrscr,
  304. {$endif DOS}
  305. App,Strings,
  306. FVConsts,
  307. {$ifdef Windows}
  308. Windebug,
  309. {$endif Windows}
  310. {$ifdef Unix}
  311. {$ifdef VER1_0}
  312. Linux,
  313. {$else}
  314. termio,
  315. {$endif}
  316. {$endif Unix}
  317. Systems,Globals,
  318. FPRegs,
  319. FPVars,FPUtils,FPConst,FPSwitch,
  320. FPIntf,FPCompil,FPIde,FPHelp,
  321. Validate,WUtils,Wconsts;
  322. const
  323. RBreakpointsWindow: TStreamRec = (
  324. ObjType: 1701;
  325. VmtLink: Ofs(TypeOf(TBreakpointsWindow)^);
  326. Load: @TBreakpointsWindow.Load;
  327. Store: @TBreakpointsWindow.Store
  328. );
  329. RBreakpointsListBox : TStreamRec = (
  330. ObjType: 1702;
  331. VmtLink: Ofs(TypeOf(TBreakpointsListBox)^);
  332. Load: @TBreakpointsListBox.Load;
  333. Store: @TBreakpointsListBox.Store
  334. );
  335. RWatchesWindow: TStreamRec = (
  336. ObjType: 1703;
  337. VmtLink: Ofs(TypeOf(TWatchesWindow)^);
  338. Load: @TWatchesWindow.Load;
  339. Store: @TWatchesWindow.Store
  340. );
  341. RWatchesListBox: TStreamRec = (
  342. ObjType: 1704;
  343. VmtLink: Ofs(TypeOf(TWatchesListBox)^);
  344. Load: @TWatchesListBox.Load;
  345. Store: @TWatchesListBox.Store
  346. );
  347. RStackWindow: TStreamRec = (
  348. ObjType: 1705;
  349. VmtLink: Ofs(TypeOf(TStackWindow)^);
  350. Load: @TStackWindow.Load;
  351. Store: @TStackWindow.Store
  352. );
  353. RFramesListBox: TStreamRec = (
  354. ObjType: 1706;
  355. VmtLink: Ofs(TypeOf(TFramesListBox)^);
  356. Load: @TFramesListBox.Load;
  357. Store: @TFramesListBox.Store
  358. );
  359. RBreakpoint: TStreamRec = (
  360. ObjType: 1707;
  361. VmtLink: Ofs(TypeOf(TBreakpoint)^);
  362. Load: @TBreakpoint.Load;
  363. Store: @TBreakpoint.Store
  364. );
  365. RWatch: TStreamRec = (
  366. ObjType: 1708;
  367. VmtLink: Ofs(TypeOf(TWatch)^);
  368. Load: @TWatch.Load;
  369. Store: @TWatch.Store
  370. );
  371. RBreakpointCollection: TStreamRec = (
  372. ObjType: 1709;
  373. VmtLink: Ofs(TypeOf(TBreakpointCollection)^);
  374. Load: @TBreakpointCollection.Load;
  375. Store: @TBreakpointCollection.Store
  376. );
  377. RWatchesCollection: TStreamRec = (
  378. ObjType: 1710;
  379. VmtLink: Ofs(TypeOf(TWatchesCollection)^);
  380. Load: @TWatchesCollection.Load;
  381. Store: @TWatchesCollection.Store
  382. );
  383. {$ifdef USERESSTRINGS}
  384. resourcestring
  385. {$else}
  386. const
  387. {$endif}
  388. button_OK = 'O~K~';
  389. button_Cancel = 'Cancel';
  390. button_New = '~N~ew';
  391. button_Edit = '~E~dit';
  392. button_Delete = '~D~elete';
  393. button_Close = '~C~lose';
  394. button_ToggleButton = '~T~oggle';
  395. { Watches local menu items }
  396. menu_watchlocal_edit = '~E~dit watch';
  397. menu_watchlocal_new = '~N~ew watch';
  398. menu_watchlocal_delete = '~D~elete watch';
  399. { Breakpoints window local menu items }
  400. menu_bplocal_gotosource = '~G~oto source';
  401. menu_bplocal_editbreakpoint = '~E~dit breakpoint';
  402. menu_bplocal_newbreakpoint = '~N~ew breakpoint';
  403. menu_bplocal_deletebreakpoint = '~D~elete breakpoint';
  404. menu_bplocal_togglestate = '~T~oggle state';
  405. { Debugger messages and status hints }
  406. msg_programexitedwithcodeandsteps = #3'Program exited with '#13+
  407. #3'exitcode = %d'#13+
  408. #3'hidden steps = %d';
  409. msg_programexitedwithexitcode = #3'Program exited with '#13+
  410. #3'exitcode = %d';
  411. msg_programsignal = #3'Program recieved signal %s'#13+
  412. #3'%s';
  413. msg_runningprogram = 'Running...';
  414. msg_runningremotely = 'Executable running remotely on ';
  415. msg_connectingto = 'Connecting to ';
  416. msg_getting_info_on = 'Getting infos from ';
  417. msg_runninginanotherwindow = 'Executable running in another window..';
  418. msg_couldnotsetbreakpointat = #3'Could not set Breakpoint'#13+
  419. #3+'%s:%d';
  420. msg_couldnotsetbreakpointtype = #3'Could not set Breakpoint'#13+
  421. #3+'%s %s';
  422. button_DisableAllBreakpoints = 'Dis. ~a~ll invalid';
  423. { Breakpoints window }
  424. dialog_breakpointlist = 'Breakpoint list';
  425. label_breakpointpropheader = ' Type | State | Position | Ignore | Conditions ';
  426. dialog_modifynewbreakpoint = 'Modify/New Breakpoint';
  427. label_breakpoint_name = '~N~ame';
  428. label_breakpoint_line = '~L~ine';
  429. label_breakpoint_conditions = '~C~onditions';
  430. label_breakpoint_ignorecount = '~I~gnore count';
  431. label_breakpoint_type = '~T~ype';
  432. { Watches window }
  433. dialog_watches = 'Watches';
  434. label_watch_expressiontowatch = '~E~xpression to watch';
  435. label_watch_values = 'Watch values';
  436. msg_watch_currentvalue = 'Current value: '+#13+
  437. '%s';
  438. msg_watch_currentandpreviousvalue = 'Current value: '+#13+
  439. '%s'+#13+
  440. 'Previous value: '+#13+
  441. '%s';
  442. dialog_callstack = 'Call Stack';
  443. menu_msglocal_saveas = 'Save ~a~s';
  444. msg_cantdebugchangetargetto = #3'Sorry, can not debug'#13+
  445. #3'programs compiled for %s.'#13+
  446. #3'Change target to %s?';
  447. msg_compiledwithoutdebuginforecompile =
  448. #3'Warning, the program'#13+
  449. #3'was compiled without'#13+
  450. #3'debugging info.'#13+
  451. #3'Recompile it?';
  452. msg_nothingtodebug = 'Oooops, nothing to debug.';
  453. msg_startingdebugger = 'Starting debugger';
  454. {$ifdef I386}
  455. const
  456. FrameName = '$ebp';
  457. {$define FrameNameKnown}
  458. {$endif i386}
  459. {$ifdef m68k}
  460. const
  461. FrameName = '$fp';
  462. {$define FrameNameKnown}
  463. {$endif m68k}
  464. {$ifdef powerpc}
  465. { stack and frame registers are the same on powerpc,
  466. so I am not sure that this will work PM }
  467. const
  468. FrameName = '$r1';
  469. {$define FrameNameKnown}
  470. {$endif powerpc}
  471. {$ifdef TP}
  472. function HexStr(Value: longint; Len: byte): string;
  473. begin
  474. HexStr:=IntToHex(Value,Len);
  475. end;
  476. {$endif}
  477. function GDBFileName(st : string) : string;
  478. {$ifndef Unix}
  479. var i : longint;
  480. {$endif Unix}
  481. begin
  482. {$ifdef NODEBUG}
  483. GDBFileName:=st;
  484. {$else NODEBUG}
  485. {$ifdef Unix}
  486. GDBFileName:=st;
  487. {$else}
  488. { should we also use / chars ? }
  489. for i:=1 to Length(st) do
  490. if st[i]='\' then
  491. {$ifdef Windows}
  492. { Don't touch at '\ ' used to escapes spaces in windows file names PM }
  493. if (i=length(st)) or (st[i+1]<>' ') then
  494. {$endif Windows}
  495. st[i]:='/';
  496. {$ifdef Windows}
  497. { for Windows we should convert e:\ into //e/ PM }
  498. if (length(st)>2) and (st[2]=':') and (st[3]='/') then
  499. st:=CygDrivePrefix+'/'+st[1]+copy(st,3,length(st));
  500. { support spaces in the name by escaping them but without changing '\ ' into '\\ ' }
  501. for i:=Length(st) downto 1 do
  502. if (st[i]=' ') and ((i=1) or (st[i-1]<>'\')) then
  503. st:=copy(st,1,i-1)+'\'+copy(st,i,length(st));
  504. {$endif Windows}
  505. {$ifdef go32v2}
  506. { for go32v2 we should convert //e/ back into e:/ PM }
  507. if (length(st)>3) and (st[1]='/') and (st[2]='/') and (st[4]='/') then
  508. st:=st[3]+':/'+copy(st,5,length(st));
  509. {$endif go32v2}
  510. GDBFileName:=LowerCaseStr(st);
  511. {$endif}
  512. {$endif NODEBUG}
  513. end;
  514. function OSFileName(st : string) : string;
  515. {$ifndef Unix}
  516. var i : longint;
  517. {$endif Unix}
  518. begin
  519. {$ifdef Unix}
  520. OSFileName:=st;
  521. {$else}
  522. {$ifdef Windows}
  523. {$ifndef NODEBUG}
  524. { for Windows we should convert /cygdrive/e/ into e:\ PM }
  525. if pos(CygDrivePrefix+'/',st)=1 then
  526. st:=st[Length(CygdrivePrefix)+2]+':\'+copy(st,length(CygdrivePrefix)+4,length(st));
  527. {$endif NODEBUG}
  528. {$endif Windows}
  529. { support spaces in the name by escaping them but without changing '\ ' into '\\ ' }
  530. for i:=Length(st) downto 2 do
  531. if (st[i]=' ') and (st[i-1]='\') then
  532. st:=copy(st,1,i-2)+copy(st,i,length(st));
  533. {$ifdef go32v2}
  534. { for go32v2 we should convert //e/ back into e:/ PM }
  535. if (length(st)>3) and (st[1]='/') and (st[2]='/') and (st[4]='/') then
  536. st:=st[3]+':\'+copy(st,5,length(st));
  537. {$endif go32v2}
  538. { should we also use / chars ? }
  539. for i:=1 to Length(st) do
  540. if st[i]='/' then
  541. st[i]:='\';
  542. OSFileName:=LowerCaseStr(st);
  543. {$endif}
  544. end;
  545. {****************************************************************************
  546. TDebugController
  547. ****************************************************************************}
  548. procedure UpdateDebugViews;
  549. begin
  550. {$ifdef SUPPORT_REMOTE}
  551. PushStatus(msg_getting_info_on+RemoteMachine);
  552. {$endif SUPPORT_REMOTE}
  553. DeskTop^.Lock;
  554. If assigned(StackWindow) then
  555. StackWindow^.Update;
  556. If assigned(RegistersWindow) then
  557. RegistersWindow^.Update;
  558. {$ifndef NODEBUG}
  559. If assigned(Debugger) then
  560. Debugger^.ReadWatches;
  561. {$endif NODEBUG}
  562. If assigned(FPUWindow) then
  563. FPUWindow^.Update;
  564. If assigned(VectorWindow) then
  565. VectorWindow^.Update;
  566. DeskTop^.UnLock;
  567. {$ifdef SUPPORT_REMOTE}
  568. PopStatus;
  569. {$endif SUPPORT_REMOTE}
  570. end;
  571. {$ifndef NODEBUG}
  572. constructor TDebugController.Init;
  573. begin
  574. inherited Init;
  575. CenterDebuggerRow:=IniCenterDebuggerRow;
  576. Disableallinvalidbreakpoints:=false;
  577. NoSwitch:=False;
  578. HasExe:=false;
  579. Debugger:=@self;
  580. WindowWidth:=-1;
  581. switch_to_user:=true;
  582. GetDir(0,OrigPwd);
  583. Command('set print object off');
  584. end;
  585. procedure TDebugController.SetExe(const exefn:string);
  586. var f : string;
  587. begin
  588. f := GDBFileName(GetShortName(exefn));
  589. if (f<>'') and ExistsFile(exefn) then
  590. begin
  591. LoadFile(f);
  592. HasExe:=true;
  593. Command('b FPC_BREAK_ERROR');
  594. FPCBreakErrorNumber:=last_breakpoint_number;
  595. {$ifdef FrameNameKnown}
  596. { this fails in GDB 5.1 because
  597. GDB replies that there is an attempt to dereference
  598. a generic pointer...
  599. test delayed in DoSourceLine... PM
  600. Command('cond '+IntToStr(FPCBreakErrorNumber)+
  601. ' (('+FrameName+' + 8)^ <> 0) or'+
  602. ' (('+FrameName+' + 12)^ <> 0)'); }
  603. {$endif FrameNameKnown}
  604. SetArgs(GetRunParameters);
  605. SetSourceDirs;
  606. InsertBreakpoints;
  607. ReadWatches;
  608. end
  609. else
  610. begin
  611. HasExe:=false;
  612. Command('file');
  613. end;
  614. end;
  615. procedure TDebugController.SetWidth(AWidth : longint);
  616. begin
  617. WindowWidth:=AWidth;
  618. Command('set width '+inttostr(WindowWidth));
  619. end;
  620. procedure TDebugController.SetSourceDirs;
  621. var f,s: ansistring;
  622. i : longint;
  623. Dir : SearchRec;
  624. begin
  625. f:=GetSourceDirectories+';'+OrigPwd;
  626. repeat
  627. i:=pos(';',f);
  628. if i=0 then
  629. s:=f
  630. else
  631. begin
  632. s:=copy(f,1,i-1);
  633. system.delete(f,1,i);
  634. end;
  635. DefaultReplacements(s);
  636. if (pos('*',s)=0) and ExistsDir(s) then
  637. Command('dir '+GDBFileName(GetShortName(s)))
  638. { we should also handle the /* cases of -Fu option }
  639. else if pos('*',s)>0 then
  640. begin
  641. Dos.FindFirst(s,Directory,Dir);
  642. { the '*' can only be in the last dir level }
  643. s:=DirOf(s);
  644. while Dos.DosError=0 do
  645. begin
  646. if ((Dir.attr and Directory) <> 0) and ExistsDir(s+Dir.Name) then
  647. Command('dir '+GDBFileName(GetShortName(s+Dir.Name)));
  648. Dos.FindNext(Dir);
  649. end;
  650. {$ifdef FPC}
  651. Dos.FindClose(Dir);
  652. {$endif def FPC}
  653. end;
  654. until i=0;
  655. end;
  656. procedure TDebugController.InsertBreakpoints;
  657. procedure DoInsert(PB : PBreakpoint);
  658. begin
  659. PB^.Insert;
  660. end;
  661. begin
  662. BreakpointsCollection^.ForEach(@DoInsert);
  663. Disableallinvalidbreakpoints:=false;
  664. end;
  665. procedure TDebugController.ReadWatches;
  666. procedure DoRead(PB : PWatch);
  667. begin
  668. PB^.Get_new_value;
  669. end;
  670. begin
  671. WatchesCollection^.ForEach(@DoRead);
  672. If Assigned(WatchesWindow) then
  673. WatchesWindow^.Update;
  674. end;
  675. procedure TDebugController.RereadWatches;
  676. procedure DoRead(PB : PWatch);
  677. begin
  678. PB^.Force_new_value;
  679. end;
  680. begin
  681. WatchesCollection^.ForEach(@DoRead);
  682. If Assigned(WatchesWindow) then
  683. WatchesWindow^.Update;
  684. end;
  685. procedure TDebugController.RemoveBreakpoints;
  686. procedure DoDelete(PB : PBreakpoint);
  687. begin
  688. PB^.Remove;
  689. end;
  690. begin
  691. BreakpointsCollection^.ForEach(@DoDelete);
  692. end;
  693. procedure TDebugController.ResetBreakpointsValues;
  694. procedure DoResetVal(PB : PBreakpoint);
  695. begin
  696. PB^.ResetValues;
  697. end;
  698. begin
  699. BreakpointsCollection^.ForEach(@DoResetVal);
  700. end;
  701. destructor TDebugController.Done;
  702. begin
  703. { kill the program if running }
  704. Reset;
  705. RemoveBreakpoints;
  706. inherited Done;
  707. end;
  708. procedure TDebugController.Run;
  709. {$ifdef Unix}
  710. var
  711. Debuggeefile : text;
  712. ResetOK, TTYUsed : boolean;
  713. {$endif Unix}
  714. {$ifdef PALMOSGDB}
  715. const
  716. TargetProtocol = 'palmos';
  717. {$else}
  718. const
  719. TargetProtocol = 'remote';
  720. {$endif PALMOSGDB}
  721. {$ifdef SUPPORT_REMOTE}
  722. var
  723. S,ErrorStr : string;
  724. {$endif SUPPORT_REMOTE}
  725. begin
  726. ResetBreakpointsValues;
  727. {$ifdef SUPPORT_REMOTE}
  728. NoSwitch:=true;
  729. isRemoteDebugging:=false;
  730. {$ifndef CROSSGDB}
  731. If (RemoteMachine<>'') and (RemotePort<>'') then
  732. {$else CROSSGDB}
  733. if true then
  734. {$endif CROSSGDB}
  735. begin
  736. isRemoteDebugging:=true;
  737. S:=RemoteMachine;
  738. If pos('@',S)>0 then
  739. S:=copy(S,pos('@',S)+1,High(S));
  740. If RemotePort<>'' then
  741. S:=S+':'+RemotePort;
  742. {$ifdef PALMOSGDB}
  743. { set the default value for PalmOS }
  744. If S='' then
  745. S:='localhost:2000';
  746. {$endif PALMOSGDB}
  747. PushStatus(msg_connectingto+S);
  748. Command('target '+TargetProtocol+' '+S);
  749. if Error then
  750. begin
  751. ErrorStr:=strpas(GetError);
  752. ErrorBox(#3'Error in "target '+TargetProtocol+'"'#13#3+ErrorStr,nil);
  753. PopStatus;
  754. exit;
  755. end;
  756. PopStatus;
  757. end
  758. else
  759. begin
  760. {$endif SUPPORT_REMOTE}
  761. {$ifdef Windows}
  762. { Run the debugge in another console }
  763. if DebuggeeTTY<>'' then
  764. Command('set new-console on')
  765. else
  766. Command('set new-console off');
  767. NoSwitch:=DebuggeeTTY<>'';
  768. {$endif Windows}
  769. {$ifdef Unix}
  770. { Run the debuggee in another tty }
  771. if DebuggeeTTY <> '' then
  772. begin
  773. {$I-}
  774. Assign(Debuggeefile,DebuggeeTTY);
  775. system.Reset(Debuggeefile);
  776. ResetOK:=IOResult=0;
  777. If ResetOK and {$ifdef ver1_0}IsATTY(textrec(Debuggeefile).handle){$else}(IsATTY(textrec(Debuggeefile).handle)<>-1){$endif} then
  778. begin
  779. Command('tty '+DebuggeeTTY);
  780. TTYUsed:=true;
  781. end
  782. else
  783. begin
  784. Command('tty ');
  785. TTYUsed:=false;
  786. end;
  787. if ResetOK then
  788. close(Debuggeefile);
  789. if TTYUsed and (DebuggeeTTY<>TTYName(stdout)) then
  790. NoSwitch:= true
  791. else
  792. NoSwitch:=false;
  793. end
  794. else
  795. begin
  796. if TTYName(input)<>'' then
  797. Command('tty '+TTYName(input));
  798. NoSwitch := false;
  799. end;
  800. {$endif Unix}
  801. {$ifdef SUPPORT_REMOTE}
  802. end;
  803. {$endif SUPPORT_REMOTE}
  804. { Switch to user screen to get correct handles }
  805. UserScreen;
  806. { Don't try to print GDB messages while in User Screen mode }
  807. If assigned(GDBWindow) then
  808. GDBWindow^.Editor^.Lock;
  809. {$ifdef SUPPORT_REMOTE}
  810. if isRemoteDebugging then
  811. begin
  812. inc(init_count);
  813. { pass the stop in start code }
  814. Command('continue');
  815. end else
  816. {$endif SUPPORT_REMOTE}
  817. { Set cwd for debuggee }
  818. SetDir(GetRunDir);
  819. inherited Run;
  820. { Restore cwd for IDE }
  821. SetDir(StartupDir);
  822. DebuggerScreen;
  823. If assigned(GDBWindow) then
  824. GDBWindow^.Editor^.UnLock;
  825. IDEApp.SetCmdState([cmResetDebugger,cmUntilReturn],true);
  826. IDEApp.UpdateRunMenu(true);
  827. UpdateDebugViews;
  828. end;
  829. function TDebugController.IsRunning : boolean;
  830. begin
  831. IsRunning:=debuggee_started;
  832. end;
  833. procedure TDebugController.Continue;
  834. begin
  835. {$ifdef NODEBUG}
  836. NoDebugger;
  837. {$else}
  838. if not debuggee_started then
  839. Run
  840. else
  841. inherited Continue;
  842. UpdateDebugViews;
  843. {$endif NODEBUG}
  844. end;
  845. procedure TDebugController.UntilReturn;
  846. begin
  847. Command('finish');
  848. UpdateDebugViews;
  849. { We could try to get the return value !
  850. Not done yet }
  851. end;
  852. procedure TDebugController.CommandBegin(const s:string);
  853. begin
  854. if assigned(GDBWindow) and (in_command>1) then
  855. begin
  856. { We should do something special for errors !! }
  857. If StrLen(GetError)>0 then
  858. GDBWindow^.WriteErrorText(GetError);
  859. GDBWindow^.WriteOutputText(GetOutput);
  860. end;
  861. if assigned(GDBWindow) then
  862. GDBWindow^.WriteString(S);
  863. end;
  864. procedure TDebugController.CommandEnd(const s:string);
  865. begin
  866. if assigned(GDBWindow) and (in_command<=1) then
  867. begin
  868. { We should do something special for errors !! }
  869. If StrLen(GetError)>0 then
  870. GDBWindow^.WriteErrorText(GetError);
  871. GDBWindow^.WriteOutputText(GetOutput);
  872. GDBWindow^.Editor^.TextEnd;
  873. end;
  874. end;
  875. function TDebugController.AllowQuit : boolean;
  876. begin
  877. if IsRunning then
  878. begin
  879. if ConfirmBox('Really quit GDB window'#13+
  880. 'and kill running program?',nil,true)=cmYes then
  881. begin
  882. Reset;
  883. DoneGDBWindow;
  884. {AllowQuit:=true;}
  885. AllowQuit:=false;
  886. end
  887. else
  888. AllowQuit:=false;
  889. end
  890. else if ConfirmBox('Really quit GDB window?',nil,true)=cmYes then
  891. begin
  892. DoneGDBWindow;
  893. {AllowQuit:=true;}
  894. AllowQuit:=false;
  895. end
  896. else
  897. AllowQuit:=false;
  898. end;
  899. procedure TDebugController.ResetDebuggerRows;
  900. procedure ResetDebuggerRow(P: PView); {$ifndef FPC}far;{$endif}
  901. begin
  902. if assigned(P) and
  903. (TypeOf(P^)=TypeOf(TSourceWindow)) then
  904. PSourceWindow(P)^.Editor^.SetLineFlagExclusive(lfDebuggerRow,-1);
  905. end;
  906. begin
  907. Desktop^.ForEach(@ResetDebuggerRow);
  908. end;
  909. procedure TDebugController.Reset;
  910. begin
  911. inherited Reset;
  912. { we need to free the executable
  913. if we want to recompile it }
  914. SetExe('');
  915. NoSwitch:=false;
  916. { In case we have something that the compiler touched }
  917. If IDEApp.IsRunning then
  918. begin
  919. IDEApp.SetCmdState([cmResetDebugger,cmUntilReturn],false);
  920. IDEApp.UpdateRunMenu(false);
  921. AskToReloadAllModifiedFiles;
  922. ResetDebuggerRows;
  923. end;
  924. end;
  925. procedure TDebugController.AnnotateError;
  926. var errornb : longint;
  927. begin
  928. if error then
  929. begin
  930. errornb:=error_num;
  931. UpdateDebugViews;
  932. ErrorBox(#3'Error within GDB'#13#3'Error code = %d',@errornb);
  933. end;
  934. end;
  935. function TDebugController.GetValue(Const expr : string) : pchar;
  936. var
  937. p,p2,p3 : pchar;
  938. begin
  939. if WindowWidth<>-1 then
  940. Command('set width 0xffffffff');
  941. Command('p '+expr);
  942. p:=GetOutput;
  943. p3:=nil;
  944. if assigned(p) and (p[strlen(p)-1]=#10) then
  945. begin
  946. p3:=p+strlen(p)-1;
  947. p3^:=#0;
  948. end;
  949. if assigned(p) then
  950. p2:=strpos(p,'=')
  951. else
  952. p2:=nil;
  953. if assigned(p2) then
  954. p:=p2+1;
  955. while p^ in [' ',TAB] do
  956. inc(p);
  957. { get rid of type }
  958. if p^ = '(' then
  959. p:=strpos(p,')')+1;
  960. while p^ in [' ',TAB] do
  961. inc(p);
  962. if assigned(p) then
  963. GetValue:=StrNew(p)
  964. else
  965. GetValue:=StrNew(GetError);
  966. if assigned(p3) then
  967. p3^:=#10;
  968. got_error:=false;
  969. if WindowWidth<>-1 then
  970. Command('set width '+IntToStr(WindowWidth));
  971. end;
  972. function TDebugController.GetFramePointer : CORE_ADDR;
  973. var
  974. st : string;
  975. p : longint;
  976. begin
  977. {$ifdef FrameNameKnown}
  978. Command('p /d '+FrameName);
  979. st:=strpas(GetOutput);
  980. p:=pos('=',st);
  981. while (p<length(st)) and (st[p+1] in [' ',#9]) do
  982. inc(p);
  983. Delete(st,1,p);
  984. p:=1;
  985. while (st[p] in ['0'..'9']) do
  986. inc(p);
  987. Delete(st,p,High(st));
  988. GetFramePointer:=StrToCard(st);
  989. {$else not FrameNameKnown}
  990. GetFramePointer:=0;
  991. {$endif not FrameNameKnown}
  992. end;
  993. function TDebugController.GetLongintAt(addr : CORE_ADDR) : longint;
  994. var
  995. st : string;
  996. p : longint;
  997. begin
  998. Command('x /wd 0x'+hexstr(longint(addr),8));
  999. st:=strpas(GetOutput);
  1000. p:=pos(':',st);
  1001. while (p<length(st)) and (st[p+1] in [' ',#9]) do
  1002. inc(p);
  1003. Delete(st,1,p);
  1004. p:=1;
  1005. while (st[p] in ['0'..'9']) do
  1006. inc(p);
  1007. Delete(st,p,High(st));
  1008. GetLongintAt:=StrToInt(st);
  1009. end;
  1010. function TDebugController.GetPointerAt(addr : CORE_ADDR) : CORE_ADDR;
  1011. var
  1012. st : string;
  1013. p : longint;
  1014. code : integer;
  1015. begin
  1016. Command('x /wx 0x'+hexstr(PtrInt(addr),sizeof(PtrInt)*2));
  1017. st:=strpas(GetOutput);
  1018. p:=pos(':',st);
  1019. while (p<length(st)) and (st[p+1] in [' ',#9]) do
  1020. inc(p);
  1021. if (p<length(st)) and (st[p+1]='$') then
  1022. inc(p);
  1023. Delete(st,1,p);
  1024. p:=1;
  1025. while (st[p] in ['0'..'9','A'..'F','a'..'f']) do
  1026. inc(p);
  1027. Delete(st,p,High(st));
  1028. Val('$'+st,GetPointerAt,code);
  1029. end;
  1030. procedure TDebugController.DoSelectSourceLine(const fn:string;line:longint);
  1031. var
  1032. W: PSourceWindow;
  1033. Found : boolean;
  1034. PB : PBreakpoint;
  1035. S : String;
  1036. BreakIndex : longint;
  1037. stop_addr : CORE_ADDR;
  1038. i,ExitCode : longint;
  1039. ExitAddr,ExitFrame : CORE_ADDR;
  1040. const
  1041. { try to find the parameters }
  1042. FirstArgOffset = -sizeof(pointer);
  1043. SecondArgOffset = 2*-sizeof(pointer);
  1044. ThirdArgOffset = 3*-sizeof(pointer);
  1045. begin
  1046. BreakIndex:=stop_breakpoint_number;
  1047. Desktop^.Lock;
  1048. { 0 based line count in Editor }
  1049. if Line>0 then
  1050. dec(Line);
  1051. S:=fn;
  1052. stop_addr:=current_pc;
  1053. if (BreakIndex=FPCBreakErrorNumber) then
  1054. begin
  1055. { Procedure HandleErrorAddrFrame
  1056. (Errno : longint;addr,frame : longint);
  1057. [public,alias:'FPC_BREAK_ERROR']; }
  1058. {$ifdef FrameNameKnown}
  1059. ExitCode:=GetLongintAt(GetFramePointer+FirstArgOffset);
  1060. ExitAddr:=GetPointerAt(GetFramePointer+SecondArgOffset);
  1061. ExitFrame:=GetPointerAt(GetFramePointer+ThirdArgOffset);
  1062. if (ExitCode=0) and (ExitAddr=0) then
  1063. begin
  1064. Desktop^.Unlock;
  1065. Command('continue');
  1066. exit;
  1067. end;
  1068. { forget all old frames }
  1069. clear_frames;
  1070. { record new frames }
  1071. Command('backtrace');
  1072. for i:=0 to frame_count-1 do
  1073. begin
  1074. with frames[i]^ do
  1075. begin
  1076. if ExitAddr=address then
  1077. begin
  1078. Command('f '+IntToStr(i));
  1079. if assigned(file_name) then
  1080. begin
  1081. s:=strpas(file_name);
  1082. line:=line_number;
  1083. stop_addr:=address;
  1084. end;
  1085. break;
  1086. end;
  1087. end;
  1088. end;
  1089. {$endif FrameNameKnown}
  1090. end;
  1091. { Update Disassembly position }
  1092. if Assigned(DisassemblyWindow) then
  1093. DisassemblyWindow^.SetCurAddress(stop_addr);
  1094. if (fn=LastFileName) then
  1095. begin
  1096. W:=PSourceWindow(LastSource);
  1097. if assigned(W) then
  1098. begin
  1099. W^.Editor^.SetCurPtr(0,Line);
  1100. W^.Editor^.TrackCursor(CenterDebuggerRow);
  1101. W^.Editor^.SetLineFlagExclusive(lfDebuggerRow,Line);
  1102. UpdateDebugViews;
  1103. {if Not assigned(GDBWindow) or not GDBWindow^.GetState(sfActive) then
  1104. handled by SelectInDebugSession}
  1105. W^.SelectInDebugSession;
  1106. InvalidSourceLine:=false;
  1107. end
  1108. else
  1109. InvalidSourceLine:=true;
  1110. end
  1111. else
  1112. begin
  1113. if s='' then
  1114. W:=nil
  1115. else
  1116. W:=TryToOpenFile(nil,s,0,Line,false);
  1117. if assigned(W) then
  1118. begin
  1119. W^.Editor^.SetLineFlagExclusive(lfDebuggerRow,Line);
  1120. W^.Editor^.TrackCursor(CenterDebuggerRow);
  1121. UpdateDebugViews;
  1122. {if Not assigned(GDBWindow) or not GDBWindow^.GetState(sfActive) then
  1123. handled by SelectInDebugSession}
  1124. W^.SelectInDebugSession;
  1125. LastSource:=W;
  1126. InvalidSourceLine:=false;
  1127. end
  1128. { only search a file once }
  1129. else
  1130. begin
  1131. Desktop^.UnLock;
  1132. if s='' then
  1133. Found:=false
  1134. else
  1135. { it is easier to handle with a * at the end }
  1136. Found:=IDEApp.OpenSearch(s+'*');
  1137. Desktop^.Lock;
  1138. if not Found then
  1139. begin
  1140. InvalidSourceLine:=true;
  1141. LastSource:=Nil;
  1142. { Show the stack in that case }
  1143. InitStackWindow;
  1144. UpdateDebugViews;
  1145. StackWindow^.MakeFirst;
  1146. end
  1147. else
  1148. begin
  1149. { should now be open }
  1150. W:=TryToOpenFile(nil,s,0,Line,true);
  1151. W^.Editor^.SetLineFlagExclusive(lfDebuggerRow,Line);
  1152. W^.Editor^.TrackCursor(CenterDebuggerRow);
  1153. UpdateDebugViews;
  1154. {if Not assigned(GDBWindow) or not GDBWindow^.GetState(sfActive) then
  1155. handled by SelectInDebugSession}
  1156. W^.SelectInDebugSession;
  1157. LastSource:=W;
  1158. InvalidSourceLine:=false;
  1159. end;
  1160. end;
  1161. end;
  1162. LastFileName:=s;
  1163. Desktop^.UnLock;
  1164. if BreakIndex>0 then
  1165. begin
  1166. PB:=BreakpointsCollection^.GetGDB(BreakIndex);
  1167. if (BreakIndex=FPCBreakErrorNumber) then
  1168. begin
  1169. if (ExitCode<>0) or (ExitAddr<>0) then
  1170. WarningBox(#3'Run Time Error '+IntToStr(ExitCode)+#13+
  1171. #3'Error address $'+HexStr(ExitAddr,8),nil)
  1172. else
  1173. WarningBox(#3'Run Time Error',nil);
  1174. end
  1175. else if not assigned(PB) then
  1176. begin
  1177. WarningBox(#3'Stopped by breakpoint '+IntToStr(BreakIndex),nil);
  1178. end
  1179. { For watch we should get old and new value !! }
  1180. else if (Not assigned(GDBWindow) or not GDBWindow^.GetState(sfActive)) and
  1181. (PB^.typ<>bt_file_line) and (PB^.typ<>bt_function) and
  1182. (PB^.typ<>bt_address) then
  1183. begin
  1184. Command('p '+GetStr(PB^.Name));
  1185. S:=GetPChar(GetOutput);
  1186. got_error:=false;
  1187. If Pos('=',S)>0 then
  1188. S:=Copy(S,Pos('=',S)+1,255);
  1189. If S[Length(S)]=#10 then
  1190. Delete(S,Length(S),1);
  1191. if Assigned(PB^.OldValue) then
  1192. DisposeStr(PB^.OldValue);
  1193. PB^.OldValue:=PB^.CurrentValue;
  1194. PB^.CurrentValue:=NewStr(S);
  1195. If PB^.typ=bt_function then
  1196. WarningBox(#3'GDB stopped due to'#13+
  1197. #3+BreakpointTypeStr[PB^.typ]+' '+GetStr(PB^.Name),nil)
  1198. else if (GetStr(PB^.OldValue)<>S) then
  1199. WarningBox(#3'GDB stopped due to'#13+
  1200. #3+BreakpointTypeStr[PB^.typ]+' '+GetStr(PB^.Name)+#13+
  1201. #3+'Old value = '+GetStr(PB^.OldValue)+#13+
  1202. #3+'New value = '+GetStr(PB^.CurrentValue),nil)
  1203. else
  1204. WarningBox(#3'GDB stopped due to'#13+
  1205. #3+BreakpointTypeStr[PB^.typ]+' '+GetStr(PB^.Name)+#13+
  1206. #3+' value = '+GetStr(PB^.CurrentValue),nil);
  1207. end;
  1208. end;
  1209. end;
  1210. procedure TDebugController.DoUserSignal;
  1211. var P :Array[1..2] of pstring;
  1212. S1, S2 : string;
  1213. begin
  1214. S1:=strpas(signal_name);
  1215. S2:=strpas(signal_string);
  1216. P[1]:=@S1;
  1217. P[2]:=@S2;
  1218. WarningBox(msg_programsignal,@P);
  1219. end;
  1220. procedure TDebugController.DoEndSession(code:longint);
  1221. var P :Array[1..2] of longint;
  1222. begin
  1223. IDEApp.SetCmdState([cmUntilReturn,cmResetDebugger],false);
  1224. IDEApp.UpdateRunMenu(false);
  1225. ResetDebuggerRows;
  1226. LastExitCode:=Code;
  1227. If HiddenStepsCount=0 then
  1228. InformationBox(msg_programexitedwithexitcode,@code)
  1229. else
  1230. begin
  1231. P[1]:=code;
  1232. P[2]:=HiddenStepsCount;
  1233. WarningBox(msg_programexitedwithcodeandsteps,@P);
  1234. end;
  1235. { In case we have something that the compiler touched }
  1236. AskToReloadAllModifiedFiles;
  1237. {$ifdef Windows}
  1238. main_pid_valid:=false;
  1239. {$endif Windows}
  1240. end;
  1241. procedure TDebugController.DoDebuggerScreen;
  1242. {$ifdef Windows}
  1243. var
  1244. IdeMode : DWord;
  1245. {$endif Windows}
  1246. begin
  1247. if NoSwitch then
  1248. begin
  1249. PopStatus;
  1250. end
  1251. else
  1252. begin
  1253. IDEApp.ShowIDEScreen;
  1254. Message(Application,evBroadcast,cmDebuggerStopped,pointer(ptrint(RunCount)));
  1255. PopStatus;
  1256. end;
  1257. {$ifdef Windows}
  1258. if NoSwitch then
  1259. begin
  1260. { Ctrl-C as normal char }
  1261. GetConsoleMode(GetStdHandle(cardinal(Std_Input_Handle)), @IdeMode);
  1262. IdeMode:=(IdeMode or ENABLE_MOUSE_INPUT or ENABLE_WINDOW_INPUT) and not ENABLE_PROCESSED_INPUT;
  1263. SetConsoleMode(GetStdHandle(cardinal(Std_Input_Handle)), IdeMode);
  1264. end;
  1265. ChangeDebuggeeWindowTitleTo(Stopped_State);
  1266. {$endif Windows}
  1267. end;
  1268. procedure TDebugController.DoUserScreen;
  1269. {$ifdef Windows}
  1270. var
  1271. IdeMode : DWord;
  1272. {$endif Windows}
  1273. begin
  1274. Inc(RunCount);
  1275. if NoSwitch then
  1276. begin
  1277. {$ifdef SUPPORT_REMOTE}
  1278. PushStatus(msg_runningremotely+RemoteMachine);
  1279. {$else not SUPPORT_REMOTE}
  1280. {$ifdef Unix}
  1281. PushStatus(msg_runninginanotherwindow+DebuggeeTTY);
  1282. {$else not Unix}
  1283. PushStatus(msg_runninginanotherwindow);
  1284. {$endif Unix}
  1285. {$endif not SUPPORT_REMOTE}
  1286. end
  1287. else
  1288. begin
  1289. PushStatus(msg_runningprogram);
  1290. IDEApp.ShowUserScreen;
  1291. end;
  1292. {$ifdef Windows}
  1293. if NoSwitch then
  1294. begin
  1295. { Ctrl-C as interrupt }
  1296. GetConsoleMode(GetStdHandle(cardinal(Std_Input_Handle)), @IdeMode);
  1297. IdeMode:=(IdeMode or ENABLE_MOUSE_INPUT or ENABLE_PROCESSED_INPUT or ENABLE_WINDOW_INPUT);
  1298. SetConsoleMode(GetStdHandle(cardinal(Std_Input_Handle)), IdeMode);
  1299. end;
  1300. ChangeDebuggeeWindowTitleTo(Running_State);
  1301. {$endif Windows}
  1302. end;
  1303. {$endif NODEBUG}
  1304. {****************************************************************************
  1305. TBreakpoint
  1306. ****************************************************************************}
  1307. function ActiveBreakpoints : boolean;
  1308. var
  1309. IsActive : boolean;
  1310. procedure TestActive(PB : PBreakpoint);
  1311. begin
  1312. If PB^.state=bs_enabled then
  1313. IsActive:=true;
  1314. end;
  1315. begin
  1316. IsActive:=false;
  1317. If assigned(BreakpointsCollection) then
  1318. BreakpointsCollection^.ForEach(@TestActive);
  1319. ActiveBreakpoints:=IsActive;
  1320. end;
  1321. constructor TBreakpoint.Init_function(Const AFunc : String);
  1322. begin
  1323. typ:=bt_function;
  1324. state:=bs_enabled;
  1325. GDBState:=bs_deleted;
  1326. Name:=NewStr(AFunc);
  1327. FileName:=nil;
  1328. Line:=0;
  1329. IgnoreCount:=0;
  1330. Commands:=nil;
  1331. Conditions:=nil;
  1332. OldValue:=nil;
  1333. CurrentValue:=nil;
  1334. end;
  1335. constructor TBreakpoint.Init_Address(Const AAddress : String);
  1336. begin
  1337. typ:=bt_address;
  1338. state:=bs_enabled;
  1339. GDBState:=bs_deleted;
  1340. Name:=NewStr(AAddress);
  1341. FileName:=nil;
  1342. Line:=0;
  1343. IgnoreCount:=0;
  1344. Commands:=nil;
  1345. Conditions:=nil;
  1346. OldValue:=nil;
  1347. CurrentValue:=nil;
  1348. end;
  1349. constructor TBreakpoint.Init_Empty;
  1350. begin
  1351. typ:=bt_function;
  1352. state:=bs_enabled;
  1353. GDBState:=bs_deleted;
  1354. Name:=Nil;
  1355. FileName:=nil;
  1356. Line:=0;
  1357. IgnoreCount:=0;
  1358. Commands:=nil;
  1359. Conditions:=nil;
  1360. OldValue:=nil;
  1361. CurrentValue:=nil;
  1362. end;
  1363. constructor TBreakpoint.Init_type(atyp : BreakpointType;Const AnExpr : String);
  1364. begin
  1365. typ:=atyp;
  1366. state:=bs_enabled;
  1367. GDBState:=bs_deleted;
  1368. Name:=NewStr(AnExpr);
  1369. IgnoreCount:=0;
  1370. Commands:=nil;
  1371. Conditions:=nil;
  1372. OldValue:=nil;
  1373. CurrentValue:=nil;
  1374. end;
  1375. constructor TBreakpoint.Init_file_line(AFile : String; ALine : longint);
  1376. var
  1377. CurDir : String;
  1378. begin
  1379. typ:=bt_file_line;
  1380. state:=bs_enabled;
  1381. GDBState:=bs_deleted;
  1382. AFile:=FEXpand(AFile);
  1383. (*
  1384. { d:test.pas:12 does not work !! }
  1385. { I do not know how to solve this if
  1386. if (Length(AFile)>1) and (AFile[2]=':') then
  1387. AFile:=Copy(AFile,3,255); }
  1388. {$ifdef Unix}
  1389. CurDir:=GetCurDir;
  1390. {$else}
  1391. CurDir:=LowerCaseStr(GetCurDir);
  1392. {$endif Unix}
  1393. if Pos(CurDir,OSFileName(AFile))=1 then
  1394. FileName:=NewStr(Copy(OSFileName(AFile),length(CurDir)+1,255))
  1395. else
  1396. *)
  1397. FileName:=NewStr(OSFileName(AFile));
  1398. Name:=nil;
  1399. Line:=ALine;
  1400. IgnoreCount:=0;
  1401. Commands:=nil;
  1402. Conditions:=nil;
  1403. OldValue:=nil;
  1404. CurrentValue:=nil;
  1405. end;
  1406. constructor TBreakpoint.Load(var S: TStream);
  1407. var
  1408. FName : PString;
  1409. begin
  1410. S.Read(typ,SizeOf(BreakpointType));
  1411. S.Read(state,SizeOf(BreakpointState));
  1412. GDBState:=bs_deleted;
  1413. case typ of
  1414. bt_file_line :
  1415. begin
  1416. { convert to current target }
  1417. FName:=S.ReadStr;
  1418. FileName:=NewStr(OSFileName(GetStr(FName)));
  1419. If Assigned(FName) then
  1420. DisposeStr(FName);
  1421. S.Read(Line,SizeOf(Line));
  1422. Name:=nil;
  1423. end;
  1424. else
  1425. begin
  1426. Name:=S.ReadStr;
  1427. Line:=0;
  1428. FileName:=nil;
  1429. end;
  1430. end;
  1431. S.Read(IgnoreCount,SizeOf(IgnoreCount));
  1432. Commands:=S.StrRead;
  1433. Conditions:=S.ReadStr;
  1434. OldValue:=nil;
  1435. CurrentValue:=nil;
  1436. end;
  1437. procedure TBreakpoint.Store(var S: TStream);
  1438. var
  1439. St : String;
  1440. begin
  1441. S.Write(typ,SizeOf(BreakpointType));
  1442. S.Write(state,SizeOf(BreakpointState));
  1443. case typ of
  1444. bt_file_line :
  1445. begin
  1446. st:=OSFileName(GetStr(FileName));
  1447. S.WriteStr(@St);
  1448. S.Write(Line,SizeOf(Line));
  1449. end;
  1450. else
  1451. begin
  1452. S.WriteStr(Name);
  1453. end;
  1454. end;
  1455. S.Write(IgnoreCount,SizeOf(IgnoreCount));
  1456. S.StrWrite(Commands);
  1457. S.WriteStr(Conditions);
  1458. end;
  1459. procedure TBreakpoint.Insert;
  1460. var
  1461. p,p2 : pchar;
  1462. st : string;
  1463. begin
  1464. {$ifndef NODEBUG}
  1465. If not assigned(Debugger) then Exit;
  1466. Remove;
  1467. Debugger^.last_breakpoint_number:=0;
  1468. if (GDBState=bs_deleted) and (state=bs_enabled) then
  1469. begin
  1470. if (typ=bt_file_line) and assigned(FileName) then
  1471. Debugger^.Command('break '+GDBFileName(NameAndExtOf(GetStr(FileName)))+':'+IntToStr(Line))
  1472. else if (typ=bt_function) and assigned(name) then
  1473. Debugger^.Command('break '+name^)
  1474. else if (typ=bt_address) and assigned(name) then
  1475. Debugger^.Command('break *0x'+name^)
  1476. else if (typ=bt_watch) and assigned(name) then
  1477. Debugger^.Command('watch '+name^)
  1478. else if (typ=bt_awatch) and assigned(name) then
  1479. Debugger^.Command('awatch '+name^)
  1480. else if (typ=bt_rwatch) and assigned(name) then
  1481. Debugger^.Command('rwatch '+name^);
  1482. if Debugger^.last_breakpoint_number<>0 then
  1483. begin
  1484. GDBIndex:=Debugger^.last_breakpoint_number;
  1485. GDBState:=bs_enabled;
  1486. Debugger^.Command('cond '+IntToStr(GDBIndex)+' '+GetStr(Conditions));
  1487. If IgnoreCount>0 then
  1488. Debugger^.Command('ignore '+IntToStr(GDBIndex)+' '+IntToStr(IgnoreCount));
  1489. If Assigned(Commands) then
  1490. begin
  1491. {Commands are not handled yet }
  1492. Debugger^.Command('command '+IntToStr(GDBIndex));
  1493. p:=commands;
  1494. while assigned(p) do
  1495. begin
  1496. p2:=strscan(p,#10);
  1497. if assigned(p2) then
  1498. p2^:=#0;
  1499. st:=strpas(p);
  1500. Debugger^.command(st);
  1501. if assigned(p2) then
  1502. p2^:=#10;
  1503. p:=p2;
  1504. if assigned(p) then
  1505. inc(p);
  1506. end;
  1507. Debugger^.Command('end');
  1508. end;
  1509. end
  1510. else
  1511. { Here there was a problem !! }
  1512. begin
  1513. GDBIndex:=0;
  1514. if not Debugger^.Disableallinvalidbreakpoints then
  1515. begin
  1516. if (typ=bt_file_line) and assigned(FileName) then
  1517. begin
  1518. ClearFormatParams;
  1519. AddFormatParamStr(NameAndExtOf(FileName^));
  1520. AddFormatParamInt(Line);
  1521. if ChoiceBox(msg_couldnotsetbreakpointat,@FormatParams,[btn_ok,button_DisableAllBreakpoints],false)=cmUserBtn2 then
  1522. Debugger^.Disableallinvalidbreakpoints:=true;
  1523. end
  1524. else
  1525. begin
  1526. ClearFormatParams;
  1527. AddFormatParamStr(BreakpointTypeStr[typ]);
  1528. AddFormatParamStr(GetStr(Name));
  1529. if ChoiceBox(msg_couldnotsetbreakpointtype,@FormatParams,[btn_ok,button_DisableAllBreakpoints],false)=cmUserBtn2 then
  1530. Debugger^.Disableallinvalidbreakpoints:=true;
  1531. end;
  1532. end;
  1533. state:=bs_disabled;
  1534. UpdateSource;
  1535. end;
  1536. end
  1537. else if (GDBState=bs_disabled) and (state=bs_enabled) then
  1538. Enable
  1539. else if (GDBState=bs_enabled) and (state=bs_disabled) then
  1540. Disable;
  1541. {$endif NODEBUG}
  1542. end;
  1543. procedure TBreakpoint.Remove;
  1544. begin
  1545. {$ifndef NODEBUG}
  1546. If not assigned(Debugger) then Exit;
  1547. if GDBIndex>0 then
  1548. Debugger^.Command('delete '+IntToStr(GDBIndex));
  1549. GDBIndex:=0;
  1550. GDBState:=bs_deleted;
  1551. {$endif NODEBUG}
  1552. end;
  1553. procedure TBreakpoint.Enable;
  1554. begin
  1555. {$ifndef NODEBUG}
  1556. If not assigned(Debugger) then Exit;
  1557. if GDBIndex>0 then
  1558. Debugger^.Command('enable '+IntToStr(GDBIndex))
  1559. else
  1560. Insert;
  1561. GDBState:=bs_disabled;
  1562. {$endif NODEBUG}
  1563. end;
  1564. procedure TBreakpoint.Disable;
  1565. begin
  1566. {$ifndef NODEBUG}
  1567. If not assigned(Debugger) then Exit;
  1568. if GDBIndex>0 then
  1569. Debugger^.Command('disable '+IntToStr(GDBIndex));
  1570. GDBState:=bs_disabled;
  1571. {$endif NODEBUG}
  1572. end;
  1573. procedure TBreakpoint.ResetValues;
  1574. begin
  1575. if assigned(OldValue) then
  1576. DisposeStr(OldValue);
  1577. OldValue:=nil;
  1578. if assigned(CurrentValue) then
  1579. DisposeStr(CurrentValue);
  1580. CurrentValue:=nil;
  1581. end;
  1582. procedure TBreakpoint.UpdateSource;
  1583. var W: PSourceWindow;
  1584. b : boolean;
  1585. begin
  1586. if typ=bt_file_line then
  1587. begin
  1588. W:=SearchOnDesktop(OSFileName(GetStr(FileName)),false);
  1589. If assigned(W) then
  1590. begin
  1591. if state=bs_enabled then
  1592. b:=true
  1593. else
  1594. b:=false;
  1595. W^.Editor^.SetLineFlagState(Line-1,lfBreakpoint,b);
  1596. end;
  1597. end;
  1598. end;
  1599. destructor TBreakpoint.Done;
  1600. begin
  1601. Remove;
  1602. ResetValues;
  1603. if assigned(Name) then
  1604. DisposeStr(Name);
  1605. if assigned(FileName) then
  1606. DisposeStr(FileName);
  1607. if assigned(Conditions) then
  1608. DisposeStr(Conditions);
  1609. if assigned(Commands) then
  1610. StrDispose(Commands);
  1611. inherited Done;
  1612. end;
  1613. {****************************************************************************
  1614. TBreakpointCollection
  1615. ****************************************************************************}
  1616. function TBreakpointCollection.At(Index: Integer): PBreakpoint;
  1617. begin
  1618. At:=inherited At(Index);
  1619. end;
  1620. procedure TBreakpointCollection.Update;
  1621. begin
  1622. {$ifndef NODEBUG}
  1623. if assigned(Debugger) then
  1624. begin
  1625. Debugger^.RemoveBreakpoints;
  1626. Debugger^.InsertBreakpoints;
  1627. end;
  1628. {$endif NODEBUG}
  1629. if assigned(BreakpointsWindow) then
  1630. BreakpointsWindow^.Update;
  1631. end;
  1632. function TBreakpointCollection.GetGDB(index : longint) : PBreakpoint;
  1633. function IsNum(P : PBreakpoint) : boolean;{$ifndef FPC}far;{$endif}
  1634. begin
  1635. IsNum:=P^.GDBIndex=index;
  1636. end;
  1637. begin
  1638. if index=0 then
  1639. GetGDB:=nil
  1640. else
  1641. GetGDB:=FirstThat(@IsNum);
  1642. end;
  1643. procedure TBreakpointCollection.ShowBreakpoints(W : PFPWindow);
  1644. procedure SetInSource(P : PBreakpoint);{$ifndef FPC}far;{$endif}
  1645. begin
  1646. If assigned(P^.FileName) and
  1647. (OSFileName(P^.FileName^)=OSFileName(FExpand(PSourceWindow(W)^.Editor^.FileName))) then
  1648. PSourceWindow(W)^.Editor^.SetLineFlagState(P^.Line-1,lfBreakpoint,P^.state=bs_enabled);
  1649. end;
  1650. procedure SetInDisassembly(P : PBreakpoint);{$ifndef FPC}far;{$endif}
  1651. var
  1652. PDL : PDisasLine;
  1653. S : string;
  1654. ps,qs,i : longint;
  1655. HAddr : PtrInt;
  1656. code : integer;
  1657. begin
  1658. for i:=0 to PDisassemblyWindow(W)^.Editor^.GetLineCount-1 do
  1659. begin
  1660. PDL:=PDisasLine(PDisassemblyWindow(W)^.Editor^.GetLine(i));
  1661. if PDL^.Address=0 then
  1662. begin
  1663. if (P^.typ=bt_file_line) then
  1664. begin
  1665. S:=PDisassemblyWindow(W)^.Editor^.GetDisplayText(i);
  1666. ps:=pos(':',S);
  1667. qs:=pos(' ',copy(S,ps+1,High(S)));
  1668. if (GDBFileName(P^.FileName^)=GDBFileName(FExpand(Copy(S,1,ps-1)))) and
  1669. (StrToInt(copy(S,ps+1,qs-1))=P^.line) then
  1670. PDisassemblyWindow(W)^.Editor^.SetLineFlagState(i,lfBreakpoint,P^.state=bs_enabled);
  1671. end;
  1672. end
  1673. else
  1674. begin
  1675. Val('$'+P^.Name^,HAddr,code);
  1676. If (P^.typ=bt_address) and (PDL^.Address=HAddr) then
  1677. PDisassemblyWindow(W)^.Editor^.SetLineFlagState(i,lfBreakpoint,P^.state=bs_enabled);
  1678. end;
  1679. end;
  1680. end;
  1681. begin
  1682. if W=PFPWindow(DisassemblyWindow) then
  1683. ForEach(@SetInDisassembly)
  1684. else
  1685. ForEach(@SetInSource);
  1686. end;
  1687. procedure TBreakpointCollection.AdaptBreakpoints(Editor : PSourceEditor; Pos, Change : longint);
  1688. procedure AdaptInSource(P : PBreakpoint);{$ifndef FPC}far;{$endif}
  1689. begin
  1690. If assigned(P^.FileName) and
  1691. (P^.FileName^=OSFileName(FExpand(Editor^.FileName))) then
  1692. begin
  1693. if P^.state=bs_enabled then
  1694. Editor^.SetLineFlagState(P^.Line-1,lfBreakpoint,false);
  1695. if P^.Line-1>=Pos then
  1696. begin
  1697. if (Change>0) or (P^.Line-1>=Pos-Change) then
  1698. P^.line:=P^.Line+Change
  1699. else
  1700. begin
  1701. { removing inside a ForEach call leads to problems }
  1702. { so we do that after PM }
  1703. P^.state:=bs_delete_after;
  1704. end;
  1705. end;
  1706. if P^.state=bs_enabled then
  1707. Editor^.SetLineFlagState(P^.Line-1,lfBreakpoint,true);
  1708. end;
  1709. end;
  1710. var
  1711. I : longint;
  1712. begin
  1713. ForEach(@AdaptInSource);
  1714. I:=Count-1;
  1715. While (I>=0) do
  1716. begin
  1717. if At(I)^.state=bs_delete_after then
  1718. AtFree(I);
  1719. Dec(I);
  1720. end;
  1721. end;
  1722. function TBreakpointCollection.FindBreakpointAt(Editor : PSourceEditor; Line : longint) : PBreakpoint;
  1723. function IsAtLine(P : PBreakpoint) : boolean;{$ifndef FPC}far;{$endif}
  1724. begin
  1725. If assigned(P^.FileName) and
  1726. (P^.FileName^=OSFileName(FExpand(Editor^.FileName))) and
  1727. (Line=P^.Line) then
  1728. IsAtLine:=true
  1729. else
  1730. IsAtLine:=false;
  1731. end;
  1732. begin
  1733. FindBreakpointAt:=FirstThat(@IsAtLine);
  1734. end;
  1735. procedure TBreakpointCollection.ShowAllBreakpoints;
  1736. procedure SetInSource(P : PBreakpoint);{$ifndef FPC}far;{$endif}
  1737. var
  1738. W : PSourceWindow;
  1739. begin
  1740. If assigned(P^.FileName) then
  1741. begin
  1742. W:=SearchOnDesktop(P^.FileName^,false);
  1743. if assigned(W) then
  1744. W^.Editor^.SetLineFlagState(P^.Line-1,lfBreakpoint,P^.state=bs_enabled);
  1745. end;
  1746. end;
  1747. begin
  1748. ForEach(@SetInSource);
  1749. end;
  1750. function TBreakpointCollection.GetType(typ : BreakpointType;Const s : String) : PBreakpoint;
  1751. function IsThis(P : PBreakpoint) : boolean;{$ifndef FPC}far;{$endif}
  1752. begin
  1753. IsThis:=(P^.typ=typ) and (GetStr(P^.Name)=S);
  1754. end;
  1755. begin
  1756. GetType:=FirstThat(@IsThis);
  1757. end;
  1758. function TBreakpointCollection.ToggleFileLine(FileName: String;LineNr : Longint) : boolean;
  1759. function IsThere(P : PBreakpoint) : boolean;{$ifndef FPC}far;{$endif}
  1760. begin
  1761. IsThere:=(P^.typ=bt_file_line) and assigned(P^.FileName) and
  1762. (OSFileName(P^.FileName^)=FileName) and (P^.Line=LineNr);
  1763. end;
  1764. var
  1765. PB : PBreakpoint;
  1766. begin
  1767. ToggleFileLine:=false;
  1768. FileName:=OSFileName(FExpand(FileName));
  1769. PB:=FirstThat(@IsThere);
  1770. If Assigned(PB) then
  1771. begin
  1772. { delete it form source window }
  1773. PB^.state:=bs_disabled;
  1774. PB^.UpdateSource;
  1775. { remove from collection }
  1776. BreakpointsCollection^.free(PB);
  1777. end
  1778. else
  1779. begin
  1780. PB:= New(PBreakpoint,Init_file_line(FileName,LineNr));
  1781. if assigned(PB) then
  1782. Begin
  1783. Insert(PB);
  1784. PB^.UpdateSource;
  1785. ToggleFileLine:=true;
  1786. End;
  1787. end;
  1788. Update;
  1789. end;
  1790. {****************************************************************************
  1791. TBreakpointItem
  1792. ****************************************************************************}
  1793. constructor TBreakpointItem.Init(ABreakpoint : PBreakpoint);
  1794. begin
  1795. inherited Init;
  1796. Breakpoint:=ABreakpoint;
  1797. end;
  1798. function TBreakpointItem.GetText(MaxLen: Sw_integer): string;
  1799. var S: string;
  1800. begin
  1801. with Breakpoint^ do
  1802. begin
  1803. S:=BreakpointTypeStr[typ];
  1804. While Length(S)<10 do
  1805. S:=S+' ';
  1806. S:=S+'|';
  1807. S:=S+BreakpointStateStr[state]+' ';
  1808. While Length(S)<20 do
  1809. S:=S+' ';
  1810. S:=S+'|';
  1811. if (typ=bt_file_line) then
  1812. S:=S+NameAndExtOf(GetStr(FileName))+':'+IntToStr(Line)
  1813. else
  1814. S:=S+GetStr(name);
  1815. While Length(S)<40 do
  1816. S:=S+' ';
  1817. S:=S+'|';
  1818. if IgnoreCount>0 then
  1819. S:=S+IntToStr(IgnoreCount);
  1820. While Length(S)<49 do
  1821. S:=S+' ';
  1822. S:=S+'|';
  1823. if assigned(Conditions) then
  1824. S:=S+' '+GetStr(Conditions);
  1825. if length(S)>MaxLen then S:=copy(S,1,MaxLen-2)+'..';
  1826. GetText:=S;
  1827. end;
  1828. end;
  1829. procedure TBreakpointItem.Selected;
  1830. begin
  1831. end;
  1832. function TBreakpointItem.GetModuleName: string;
  1833. begin
  1834. if breakpoint^.typ=bt_file_line then
  1835. GetModuleName:=GetStr(breakpoint^.FileName)
  1836. else
  1837. GetModuleName:='';
  1838. end;
  1839. {****************************************************************************
  1840. TBreakpointsListBox
  1841. ****************************************************************************}
  1842. constructor TBreakpointsListBox.Init(var Bounds: TRect; AHScrollBar, AVScrollBar: PScrollBar);
  1843. begin
  1844. inherited Init(Bounds,1,AHScrollBar, AVScrollBar);
  1845. GrowMode:=gfGrowLoX+gfGrowHiX+gfGrowHiY;
  1846. NoSelection:=true;
  1847. end;
  1848. function TBreakpointsListBox.GetLocalMenu: PMenu;
  1849. var M: PMenu;
  1850. begin
  1851. if (Owner<>nil) and (Owner^.GetState(sfModal)) then M:=nil else
  1852. M:=NewMenu(
  1853. NewItem(menu_bplocal_gotosource,'',kbNoKey,cmMsgGotoSource,hcMsgGotoSource,
  1854. NewItem(menu_bplocal_editbreakpoint,'',kbNoKey,cmEditBreakpoint,hcEditBreakpoint,
  1855. NewItem(menu_bplocal_newbreakpoint,'',kbNoKey,cmNewBreakpoint,hcNewBreakpoint,
  1856. NewItem(menu_bplocal_deletebreakpoint,'',kbNoKey,cmDeleteBreakpoint,hcDeleteBreakpoint,
  1857. NewItem(menu_bplocal_togglestate,'',kbNoKey,cmToggleBreakpoint,hcToggleBreakpoint,
  1858. nil))))));
  1859. GetLocalMenu:=M;
  1860. end;
  1861. procedure TBreakpointsListBox.HandleEvent(var Event: TEvent);
  1862. var DontClear: boolean;
  1863. begin
  1864. case Event.What of
  1865. evKeyDown :
  1866. begin
  1867. DontClear:=false;
  1868. case Event.KeyCode of
  1869. kbEnd :
  1870. FocusItem(List^.Count-1);
  1871. kbHome :
  1872. FocusItem(0);
  1873. kbEnter :
  1874. Message(@Self,evCommand,cmMsgGotoSource,nil);
  1875. kbIns :
  1876. Message(@Self,evCommand,cmNewBreakpoint,nil);
  1877. kbDel :
  1878. Message(@Self,evCommand,cmDeleteBreakpoint,nil);
  1879. else
  1880. DontClear:=true;
  1881. end;
  1882. if not DontClear then
  1883. ClearEvent(Event);
  1884. end;
  1885. evBroadcast :
  1886. case Event.Command of
  1887. cmListItemSelected :
  1888. if Event.InfoPtr=@Self then
  1889. Message(@Self,evCommand,cmEditBreakpoint,nil);
  1890. end;
  1891. evCommand :
  1892. begin
  1893. DontClear:=false;
  1894. case Event.Command of
  1895. cmMsgTrackSource :
  1896. if Range>0 then
  1897. TrackSource;
  1898. cmEditBreakpoint :
  1899. EditCurrent;
  1900. cmToggleBreakpoint :
  1901. ToggleCurrent;
  1902. cmDeleteBreakpoint :
  1903. DeleteCurrent;
  1904. cmNewBreakpoint :
  1905. EditNew;
  1906. cmMsgClear :
  1907. Clear;
  1908. else
  1909. DontClear:=true;
  1910. end;
  1911. if not DontClear then
  1912. ClearEvent(Event);
  1913. end;
  1914. end;
  1915. inherited HandleEvent(Event);
  1916. end;
  1917. procedure TBreakpointsListBox.AddBreakpoint(P: PBreakpointItem);
  1918. var W : integer;
  1919. begin
  1920. if List=nil then New(List, Init(20,20));
  1921. W:=length(P^.GetText(255));
  1922. if W>MaxWidth then
  1923. begin
  1924. MaxWidth:=W;
  1925. if HScrollBar<>nil then
  1926. HScrollBar^.SetRange(0,MaxWidth);
  1927. end;
  1928. List^.Insert(P);
  1929. SetRange(List^.Count);
  1930. if Focused=List^.Count-1-1 then
  1931. FocusItem(List^.Count-1);
  1932. P^.Breakpoint^.UpdateSource;
  1933. DrawView;
  1934. end;
  1935. function TBreakpointsListBox.GetText(Item,MaxLen: Sw_Integer): String;
  1936. var P: PBreakpointItem;
  1937. S: string;
  1938. begin
  1939. P:=List^.At(Item);
  1940. S:=P^.GetText(MaxLen);
  1941. GetText:=copy(S,1,MaxLen);
  1942. end;
  1943. procedure TBreakpointsListBox.Clear;
  1944. begin
  1945. if assigned(List) then
  1946. Dispose(List, Done);
  1947. List:=nil;
  1948. MaxWidth:=0;
  1949. SetRange(0); DrawView;
  1950. Message(Application,evBroadcast,cmClearLineHighlights,@Self);
  1951. end;
  1952. procedure TBreakpointsListBox.TrackSource;
  1953. var W: PSourceWindow;
  1954. P: PBreakpointItem;
  1955. R: TRect;
  1956. begin
  1957. (*Message(Application,evBroadcast,cmClearLineHighlights,@Self);
  1958. if Range=0 then Exit;*)
  1959. P:=List^.At(Focused);
  1960. if P^.GetModuleName='' then Exit;
  1961. Desktop^.Lock;
  1962. GetNextEditorBounds(R);
  1963. R.B.Y:=Owner^.Origin.Y;
  1964. W:=EditorWindowFile(P^.GetModuleName);
  1965. if assigned(W) then
  1966. begin
  1967. W^.GetExtent(R);
  1968. R.B.Y:=Owner^.Origin.Y;
  1969. W^.ChangeBounds(R);
  1970. W^.Editor^.SetCurPtr(1,P^.Breakpoint^.Line);
  1971. end
  1972. else
  1973. W:=TryToOpenFile(@R,P^.GetModuleName,1,P^.Breakpoint^.Line,true);
  1974. if W<>nil then
  1975. begin
  1976. W^.Select;
  1977. W^.Editor^.TrackCursor(do_centre);
  1978. W^.Editor^.SetLineFlagExclusive(lfHighlightRow,P^.Breakpoint^.Line);
  1979. end;
  1980. if Assigned(Owner) then
  1981. Owner^.Select;
  1982. Desktop^.UnLock;
  1983. end;
  1984. procedure TBreakpointsListBox.ToggleCurrent;
  1985. var
  1986. P: PBreakpointItem;
  1987. begin
  1988. if Range=0 then Exit;
  1989. P:=List^.At(Focused);
  1990. if P=nil then Exit;
  1991. if P^.Breakpoint^.state=bs_enabled then
  1992. P^.Breakpoint^.state:=bs_disabled
  1993. else if P^.Breakpoint^.state=bs_disabled then
  1994. P^.Breakpoint^.state:=bs_enabled;
  1995. P^.Breakpoint^.UpdateSource;
  1996. BreakpointsCollection^.Update;
  1997. end;
  1998. procedure TBreakpointsListBox.EditCurrent;
  1999. var
  2000. P: PBreakpointItem;
  2001. begin
  2002. if Range=0 then Exit;
  2003. P:=List^.At(Focused);
  2004. if P=nil then Exit;
  2005. Application^.ExecuteDialog(New(PBreakpointItemDialog,Init(P^.Breakpoint)),nil);
  2006. P^.Breakpoint^.UpdateSource;
  2007. BreakpointsCollection^.Update;
  2008. end;
  2009. procedure TBreakpointsListBox.DeleteCurrent;
  2010. var
  2011. P: PBreakpointItem;
  2012. begin
  2013. if Range=0 then Exit;
  2014. P:=List^.At(Focused);
  2015. if P=nil then Exit;
  2016. { delete it form source window }
  2017. P^.Breakpoint^.state:=bs_disabled;
  2018. P^.Breakpoint^.UpdateSource;
  2019. BreakpointsCollection^.free(P^.Breakpoint);
  2020. List^.free(P);
  2021. BreakpointsCollection^.Update;
  2022. end;
  2023. procedure TBreakpointsListBox.EditNew;
  2024. var
  2025. P: PBreakpoint;
  2026. begin
  2027. P:=New(PBreakpoint,Init_Empty);
  2028. if Application^.ExecuteDialog(New(PBreakpointItemDialog,Init(P)),nil)<>cmCancel then
  2029. begin
  2030. P^.UpdateSource;
  2031. BreakpointsCollection^.Insert(P);
  2032. BreakpointsCollection^.Update;
  2033. end
  2034. else
  2035. dispose(P,Done);
  2036. end;
  2037. procedure TBreakpointsListBox.Draw;
  2038. var
  2039. I, J, Item: Sw_Integer;
  2040. NormalColor, SelectedColor, FocusedColor, Color: Word;
  2041. ColWidth, CurCol, Indent: Integer;
  2042. B: TDrawBuffer;
  2043. Text: String;
  2044. SCOff: Byte;
  2045. TC: byte;
  2046. procedure MT(var C: word); begin if TC<>0 then C:=(C and $ff0f) or (TC and $f0); end;
  2047. begin
  2048. if (Owner<>nil) then TC:=ord(Owner^.GetColor(6)) else TC:=0;
  2049. if State and (sfSelected + sfActive) = (sfSelected + sfActive) then
  2050. begin
  2051. NormalColor := GetColor(1);
  2052. FocusedColor := GetColor(3);
  2053. SelectedColor := GetColor(4);
  2054. end else
  2055. begin
  2056. NormalColor := GetColor(2);
  2057. SelectedColor := GetColor(4);
  2058. end;
  2059. if Transparent then
  2060. begin MT(NormalColor); MT(SelectedColor); end;
  2061. if NoSelection then
  2062. SelectedColor:=NormalColor;
  2063. if HScrollBar <> nil then Indent := HScrollBar^.Value
  2064. else Indent := 0;
  2065. ColWidth := Size.X div NumCols + 1;
  2066. for I := 0 to Size.Y - 1 do
  2067. begin
  2068. for J := 0 to NumCols-1 do
  2069. begin
  2070. Item := J*Size.Y + I + TopItem;
  2071. CurCol := J*ColWidth;
  2072. if (State and (sfSelected + sfActive) = (sfSelected + sfActive)) and
  2073. (Focused = Item) and (Range > 0) then
  2074. begin
  2075. Color := FocusedColor;
  2076. SetCursor(CurCol+1,I);
  2077. SCOff := 0;
  2078. end
  2079. else if (Item < Range) and IsSelected(Item) then
  2080. begin
  2081. Color := SelectedColor;
  2082. SCOff := 2;
  2083. end
  2084. else
  2085. begin
  2086. Color := NormalColor;
  2087. SCOff := 4;
  2088. end;
  2089. MoveChar(B[CurCol], ' ', Color, ColWidth);
  2090. if Item < Range then
  2091. begin
  2092. Text := GetText(Item, ColWidth + Indent);
  2093. Text := Copy(Text,Indent,ColWidth);
  2094. MoveStr(B[CurCol+1], Text, Color);
  2095. if ShowMarkers then
  2096. begin
  2097. WordRec(B[CurCol]).Lo := Byte(SpecialChars[SCOff]);
  2098. WordRec(B[CurCol+ColWidth-2]).Lo := Byte(SpecialChars[SCOff+1]);
  2099. end;
  2100. end;
  2101. MoveChar(B[CurCol+ColWidth-1], #179, GetColor(5), 1);
  2102. end;
  2103. WriteLine(0, I, Size.X, 1, B);
  2104. end;
  2105. end;
  2106. constructor TBreakpointsListBox.Load(var S: TStream);
  2107. begin
  2108. inherited Load(S);
  2109. end;
  2110. procedure TBreakpointsListBox.Store(var S: TStream);
  2111. var OL: PCollection;
  2112. OldR : integer;
  2113. begin
  2114. OL:=List;
  2115. OldR:=Range;
  2116. Range:=0;
  2117. New(List, Init(1,1));
  2118. inherited Store(S);
  2119. Dispose(List, Done);
  2120. Range:=OldR;
  2121. List:=OL;
  2122. { ^^^ nasty trick - has anyone a better idea how to avoid storing the
  2123. collection? Pasting here a modified version of TListBox.Store+
  2124. TAdvancedListBox.Store isn't a better solution, since by eventually
  2125. changing the obj-hierarchy you'll always have to modify this, too - BG }
  2126. end;
  2127. destructor TBreakpointsListBox.Done;
  2128. begin
  2129. inherited Done;
  2130. if List<>nil then Dispose(List, Done);
  2131. end;
  2132. {****************************************************************************
  2133. TBreakpointsWindow
  2134. ****************************************************************************}
  2135. constructor TBreakpointsWindow.Init;
  2136. var R,R2: TRect;
  2137. HSB,VSB: PScrollBar;
  2138. ST: PStaticText;
  2139. S: String;
  2140. X,X1 : Sw_integer;
  2141. Btn: PButton;
  2142. const
  2143. NumButtons = 5;
  2144. begin
  2145. Desktop^.GetExtent(R); R.A.Y:=R.B.Y-18;
  2146. inherited Init(R, dialog_breakpointlist, wnNoNumber);
  2147. HelpCtx:=hcBreakpointListWindow;
  2148. GetExtent(R); R.Grow(-1,-1); R.B.Y:=R.A.Y+1;
  2149. S:=label_breakpointpropheader;
  2150. New(ST, Init(R,S));
  2151. ST^.GrowMode:=gfGrowHiX;
  2152. Insert(ST);
  2153. GetExtent(R); R.Grow(-1,-1); Inc(R.A.Y,1); R.B.Y:=R.A.Y+1;
  2154. New(ST, Init(R, CharStr('Ä', MaxViewWidth)));
  2155. ST^.GrowMode:=gfGrowHiX;
  2156. Insert(ST);
  2157. GetExtent(R); R.Grow(-1,-1); Inc(R.A.Y,2);Dec(R.B.Y,5);
  2158. R2.Copy(R); Inc(R2.B.Y); R2.A.Y:=R2.B.Y-1;
  2159. New(HSB, Init(R2)); HSB^.GrowMode:=gfGrowLoY+gfGrowHiY+gfGrowHiX; Insert(HSB);
  2160. HSB^.SetStep(R.B.X-R.A.X-2,1);
  2161. R2.Copy(R); Inc(R2.B.X); R2.A.X:=R2.B.X-1;
  2162. New(VSB, Init(R2)); VSB^.GrowMode:=gfGrowLoX+gfGrowHiX+gfGrowHiY; Insert(VSB);
  2163. VSB^.SetStep(R.B.Y-R.A.Y-2,1);
  2164. New(BreakLB, Init(R,HSB,VSB));
  2165. BreakLB^.GrowMode:=gfGrowHiX+gfGrowHiY;
  2166. BreakLB^.Transparent:=true;
  2167. Insert(BreakLB);
  2168. GetExtent(R);R.Grow(-1,-1);
  2169. Dec(R.B.Y);
  2170. R.A.Y:=R.B.Y-2;
  2171. X:=(R.B.X-R.A.X) div NumButtons;
  2172. X1:=R.A.X+(X div 2);
  2173. R.A.X:=X1-3;R.B.X:=X1+7;
  2174. New(Btn, Init(R, button_Close, cmClose, bfDefault));
  2175. Btn^.GrowMode:=gfGrowLoY+gfGrowHiY;
  2176. Insert(Btn);
  2177. X1:=X1+X;
  2178. R.A.X:=X1-3;R.B.X:=X1+7;
  2179. New(Btn, Init(R, button_New, cmNewBreakpoint, bfNormal));
  2180. Btn^.GrowMode:=gfGrowLoY+gfGrowHiY;
  2181. Insert(Btn);
  2182. X1:=X1+X;
  2183. R.A.X:=X1-3;R.B.X:=X1+7;
  2184. New(Btn, Init(R, button_Edit, cmEditBreakpoint, bfNormal));
  2185. Btn^.GrowMode:=gfGrowLoY+gfGrowHiY;
  2186. Insert(Btn);
  2187. X1:=X1+X;
  2188. R.A.X:=X1-3;R.B.X:=X1+7;
  2189. New(Btn, Init(R, button_ToggleButton, cmToggleBreakInList, bfNormal));
  2190. Btn^.GrowMode:=gfGrowLoY+gfGrowHiY;
  2191. Insert(Btn);
  2192. X1:=X1+X;
  2193. R.A.X:=X1-3;R.B.X:=X1+7;
  2194. New(Btn, Init(R, button_Delete, cmDeleteBreakpoint, bfNormal));
  2195. Btn^.GrowMode:=gfGrowLoY+gfGrowHiY;
  2196. Insert(Btn);
  2197. BreakLB^.Select;
  2198. Update;
  2199. BreakpointsWindow:=@self;
  2200. end;
  2201. constructor TBreakpointsWindow.Load(var S: TStream);
  2202. begin
  2203. inherited Load(S);
  2204. GetSubViewPtr(S,BreakLB);
  2205. end;
  2206. procedure TBreakpointsWindow.Store(var S: TStream);
  2207. begin
  2208. inherited Store(S);
  2209. PutSubViewPtr(S,BreakLB);
  2210. end;
  2211. procedure TBreakpointsWindow.AddBreakpoint(ABreakpoint : PBreakpoint);
  2212. begin
  2213. BreakLB^.AddBreakpoint(New(PBreakpointItem, Init(ABreakpoint)));
  2214. end;
  2215. procedure TBreakpointsWindow.ClearBreakpoints;
  2216. begin
  2217. BreakLB^.Clear;
  2218. ReDraw;
  2219. end;
  2220. procedure TBreakpointsWindow.ReloadBreakpoints;
  2221. procedure InsertInBreakLB(P : PBreakpoint);
  2222. begin
  2223. BreakLB^.AddBreakpoint(New(PBreakpointItem, Init(P)));
  2224. end;
  2225. begin
  2226. If not assigned(BreakpointsCollection) then
  2227. exit;
  2228. BreakpointsCollection^.ForEach(@InsertInBreakLB);
  2229. ReDraw;
  2230. end;
  2231. procedure TBreakpointsWindow.SizeLimits(var Min, Max: TPoint);
  2232. begin
  2233. inherited SizeLimits(Min,Max);
  2234. Min.X:=40; Min.Y:=18;
  2235. end;
  2236. procedure TBreakpointsWindow.Close;
  2237. begin
  2238. Hide;
  2239. end;
  2240. procedure TBreakpointsWindow.HandleEvent(var Event: TEvent);
  2241. var DontClear : boolean;
  2242. begin
  2243. case Event.What of
  2244. evKeyDown :
  2245. begin
  2246. if (Event.KeyCode=kbEnter) or (Event.KeyCode=kbEsc) then
  2247. begin
  2248. ClearEvent(Event);
  2249. Hide;
  2250. end;
  2251. end;
  2252. evCommand :
  2253. begin
  2254. DontClear:=False;
  2255. case Event.Command of
  2256. cmNewBreakpoint :
  2257. BreakLB^.EditNew;
  2258. cmEditBreakpoint :
  2259. BreakLB^.EditCurrent;
  2260. cmDeleteBreakpoint :
  2261. BreakLB^.DeleteCurrent;
  2262. cmToggleBreakInList :
  2263. BreakLB^.ToggleCurrent;
  2264. cmClose :
  2265. Hide;
  2266. else
  2267. DontClear:=true;
  2268. end;
  2269. if not DontClear then
  2270. ClearEvent(Event);
  2271. end;
  2272. evBroadcast :
  2273. case Event.Command of
  2274. cmUpdate :
  2275. Update;
  2276. end;
  2277. end;
  2278. inherited HandleEvent(Event);
  2279. end;
  2280. procedure TBreakpointsWindow.Update;
  2281. var
  2282. StoreFocus : longint;
  2283. begin
  2284. StoreFocus:=BreakLB^.Focused;
  2285. ClearBreakpoints;
  2286. ReloadBreakpoints;
  2287. If StoreFocus<BreakLB^.Range then
  2288. BreakLB^.FocusItem(StoreFocus);
  2289. end;
  2290. destructor TBreakpointsWindow.Done;
  2291. begin
  2292. inherited Done;
  2293. BreakpointsWindow:=nil;
  2294. end;
  2295. {****************************************************************************
  2296. TBreakpointItemDialog
  2297. ****************************************************************************}
  2298. constructor TBreakpointItemDialog.Init(ABreakpoint: PBreakpoint);
  2299. var R,R2,R3: TRect;
  2300. Items: PSItem;
  2301. I : BreakpointType;
  2302. KeyCount: sw_integer;
  2303. begin
  2304. KeyCount:=longint(high(BreakpointType));
  2305. R.Assign(0,0,60,Max(9+KeyCount,18));
  2306. inherited Init(R,dialog_modifynewbreakpoint);
  2307. Breakpoint:=ABreakpoint;
  2308. GetExtent(R); R.Grow(-3,-2); R3.Copy(R);
  2309. Inc(R.A.Y); R.B.Y:=R.A.Y+1; R.B.X:=R.B.X-3;
  2310. New(NameIL, Init(R, 255)); Insert(NameIL);
  2311. R2.Copy(R); R2.A.X:=R2.B.X; R2.B.X:=R2.A.X+3;
  2312. Insert(New(PHistory, Init(R2, NameIL, hidBreakPointDialogName)));
  2313. R.Copy(R3); Inc(R.A.Y); R.B.Y:=R.A.Y+1;
  2314. R2.Copy(R); R2.Move(-1,-1);
  2315. Insert(New(PLabel, Init(R2, label_breakpoint_name, NameIL)));
  2316. R.Move(0,3);
  2317. R.B.X:=R.B.X-3;
  2318. New(ConditionsIL, Init(R, 255)); Insert(ConditionsIL);
  2319. R2.Copy(R); R2.A.X:=R2.B.X; R2.B.X:=R2.A.X+3;
  2320. Insert(New(PHistory, Init(R2, ConditionsIL, hidBreakPointDialogCond)));
  2321. R2.Copy(R); R2.Move(-1,-1); Insert(New(PLabel, Init(R2, label_breakpoint_conditions, ConditionsIL)));
  2322. R.Move(0,3); R.B.X:=R.A.X+36;
  2323. New(LineIL, Init(R, 128)); Insert(LineIL);
  2324. LineIL^.SetValidator(New(PRangeValidator, Init(0,MaxInt)));
  2325. R2.Copy(R); R2.Move(-1,-1); Insert(New(PLabel, Init(R2, label_breakpoint_line, LineIL)));
  2326. R.Move(0,3);
  2327. New(IgnoreIL, Init(R, 128)); Insert(IgnoreIL);
  2328. IgnoreIL^.SetValidator(New(PRangeValidator, Init(0,MaxInt)));
  2329. R2.Copy(R); R2.Move(-1,-1); Insert(New(PLabel, Init(R2, label_breakpoint_ignorecount, IgnoreIL)));
  2330. R.Copy(R3); Inc(R.A.X,38); Inc(R.A.Y,7); R.B.Y:=R.A.Y+KeyCount;
  2331. Items:=nil;
  2332. { don't use invalid type }
  2333. for I:=pred(high(BreakpointType)) downto low(BreakpointType) do
  2334. Items:=NewSItem(BreakpointTypeStr[I], Items);
  2335. New(TypeRB, Init(R, Items));
  2336. R2.Copy(R); R2.Move(-1,-1); R2.B.Y:=R2.A.Y+1;
  2337. Insert(New(PLabel, Init(R2, label_breakpoint_type, TypeRB)));
  2338. Insert(TypeRB);
  2339. InsertButtons(@Self);
  2340. NameIL^.Select;
  2341. end;
  2342. function TBreakpointItemDialog.Execute: Word;
  2343. var R: sw_word;
  2344. S1: string;
  2345. err: word;
  2346. L: longint;
  2347. begin
  2348. R:=sw_word(Breakpoint^.typ);
  2349. TypeRB^.SetData(R);
  2350. If Breakpoint^.typ=bt_file_line then
  2351. S1:=GetStr(Breakpoint^.FileName)
  2352. else
  2353. S1:=GetStr(Breakpoint^.name);
  2354. NameIL^.SetData(S1);
  2355. If Breakpoint^.typ=bt_file_line then
  2356. S1:=IntToStr(Breakpoint^.Line)
  2357. else
  2358. S1:='0';
  2359. LineIL^.SetData(S1);
  2360. S1:=IntToStr(Breakpoint^.IgnoreCount);
  2361. IgnoreIL^.SetData(S1);
  2362. S1:=GetStr(Breakpoint^.Conditions);
  2363. ConditionsIL^.SetData(S1);
  2364. if assigned(FirstEditorWindow) then
  2365. FindReplaceEditor:=FirstEditorWindow^.Editor;
  2366. R:=inherited Execute;
  2367. FindReplaceEditor:=nil;
  2368. if R=cmOK then
  2369. begin
  2370. TypeRB^.GetData(R);
  2371. L:=R;
  2372. Breakpoint^.typ:=BreakpointType(L);
  2373. NameIL^.GetData(S1);
  2374. If Breakpoint^.typ=bt_file_line then
  2375. begin
  2376. If assigned(Breakpoint^.FileName) then
  2377. DisposeStr(Breakpoint^.FileName);
  2378. Breakpoint^.FileName:=NewStr(S1);
  2379. end
  2380. else
  2381. begin
  2382. If assigned(Breakpoint^.Name) then
  2383. DisposeStr(Breakpoint^.Name);
  2384. Breakpoint^.name:=NewStr(S1);
  2385. end;
  2386. If Breakpoint^.typ=bt_file_line then
  2387. begin
  2388. LineIL^.GetData(S1);
  2389. Val(S1,L,err);
  2390. Breakpoint^.Line:=L;
  2391. end;
  2392. IgnoreIL^.GetData(S1);
  2393. Val(S1,L,err);
  2394. Breakpoint^.IgnoreCount:=L;
  2395. ConditionsIL^.GetData(S1);
  2396. If assigned(Breakpoint^.Conditions) then
  2397. DisposeStr(Breakpoint^.Conditions);
  2398. Breakpoint^.Conditions:=NewStr(S1);
  2399. end;
  2400. Execute:=R;
  2401. end;
  2402. {****************************************************************************
  2403. TWatch
  2404. ****************************************************************************}
  2405. constructor TWatch.Init(s : string);
  2406. begin
  2407. expr:=NewStr(s);
  2408. last_value:=nil;
  2409. current_value:=nil;
  2410. Get_new_value;
  2411. GDBRunCount:=-1;
  2412. end;
  2413. constructor TWatch.Load(var S: TStream);
  2414. begin
  2415. expr:=S.ReadStr;
  2416. last_value:=nil;
  2417. current_value:=nil;
  2418. Get_new_value;
  2419. GDBRunCount:=-1;
  2420. end;
  2421. procedure TWatch.Store(var S: TStream);
  2422. begin
  2423. S.WriteStr(expr);
  2424. end;
  2425. procedure TWatch.rename(s : string);
  2426. begin
  2427. if assigned(expr) then
  2428. begin
  2429. if GetStr(expr)=S then
  2430. exit;
  2431. DisposeStr(expr);
  2432. end;
  2433. expr:=NewStr(s);
  2434. if assigned(last_value) then
  2435. StrDispose(last_value);
  2436. last_value:=nil;
  2437. if assigned(current_value) then
  2438. StrDispose(current_value);
  2439. current_value:=nil;
  2440. GDBRunCount:=-1;
  2441. Get_new_value;
  2442. end;
  2443. procedure TWatch.Get_new_value;
  2444. {$ifndef NODEBUG}
  2445. var p, q : pchar;
  2446. i, j, curframe, startframe : longint;
  2447. s,s2 : string;
  2448. loop_higher, found : boolean;
  2449. last_removed : char;
  2450. function GetValue(var s : string) : boolean;
  2451. begin
  2452. Debugger^.command('p '+s);
  2453. if not Debugger^.Error then
  2454. begin
  2455. s:=StrPas(Debugger^.GetOutput);
  2456. GetValue:=true;
  2457. end
  2458. else
  2459. begin
  2460. s:=StrPas(Debugger^.GetError);
  2461. GetValue:=false;
  2462. { do not open a messagebox for such errors }
  2463. Debugger^.got_error:=false;
  2464. end;
  2465. end;
  2466. begin
  2467. If not assigned(Debugger) or Not Debugger^.HasExe or
  2468. (GDBRunCount=Debugger^.RunCount) then
  2469. exit;
  2470. GDBRunCount:=Debugger^.RunCount;
  2471. if assigned(last_value) then
  2472. strdispose(last_value);
  2473. last_value:=current_value;
  2474. s:=GetStr(expr);
  2475. { Fix 2d array indexing, change [x,x] to [x][x] }
  2476. i:=pos('[',s);
  2477. if i>0 then
  2478. begin
  2479. while i<length(s) do
  2480. begin
  2481. if s[i]=',' then
  2482. begin
  2483. s[i]:='[';
  2484. insert(']',s,i);
  2485. inc(i);
  2486. end;
  2487. inc(i);
  2488. end;
  2489. end;
  2490. found:=GetValue(s);
  2491. Debugger^.got_error:=false;
  2492. loop_higher:=not found;
  2493. if not found then
  2494. begin
  2495. curframe:=Debugger^.get_current_frame;
  2496. startframe:=curframe;
  2497. end
  2498. else
  2499. begin
  2500. curframe:=0;
  2501. startframe:=0;
  2502. end;
  2503. while loop_higher do
  2504. begin
  2505. s:='parentfp';
  2506. if GetValue(s) then
  2507. begin
  2508. repeat
  2509. inc(curframe);
  2510. if not Debugger^.set_current_frame(curframe) then
  2511. loop_higher:=false;
  2512. {$ifdef FrameNameKnown}
  2513. s2:='/x '+FrameName;
  2514. {$else not FrameNameKnown}
  2515. s2:='/x $ebp';
  2516. {$endif FrameNameKnown}
  2517. getValue(s2);
  2518. j:=pos('=',s2);
  2519. if j>0 then
  2520. s2:=copy(s2,j+1,length(s2));
  2521. while s2[1] in [' ',TAB] do
  2522. delete(s2,1,1);
  2523. if pos(s2,s)>0 then
  2524. loop_higher :=false;
  2525. until not loop_higher;
  2526. { try again at that level }
  2527. s:=GetStr(expr);
  2528. found:=GetValue(s);
  2529. loop_higher:=not found;
  2530. end
  2531. else
  2532. loop_higher:=false;
  2533. end;
  2534. if found then
  2535. p:=StrNew(Debugger^.GetOutput)
  2536. else
  2537. begin
  2538. { get a reasonable output at least }
  2539. s:=GetStr(expr);
  2540. GetValue(s);
  2541. p:=StrNew(Debugger^.GetError);
  2542. end;
  2543. Debugger^.got_error:=false;
  2544. { We should try here to find the expr in parent
  2545. procedure if there are
  2546. I will implement this as I added a
  2547. parent_ebp pseudo local var to local procedure
  2548. in stabs debug info PM }
  2549. { But there are some pitfalls like
  2550. locals redefined in other sublocals that call the function }
  2551. if curframe<>startframe then
  2552. Debugger^.set_current_frame(startframe);
  2553. q:=nil;
  2554. if assigned(p) and (p[0]='$') then
  2555. q:=StrPos(p,'=');
  2556. if not assigned(q) then
  2557. q:=p;
  2558. if assigned(q) then
  2559. i:=strlen(q)
  2560. else
  2561. i:=0;
  2562. if (i>0) and (q[i-1]=#10) then
  2563. begin
  2564. while (i>1) and ((q[i-2]=' ') or (q[i-2]=#9)) do
  2565. dec(i);
  2566. last_removed:=q[i-1];
  2567. q[i-1]:=#0;
  2568. end
  2569. else
  2570. last_removed:=#0;
  2571. if assigned(q) then
  2572. current_value:=strnew(q)
  2573. else
  2574. current_value:=strnew('');
  2575. if last_removed<>#0 then
  2576. q[i-1]:=last_removed;
  2577. strdispose(p);
  2578. GDBRunCount:=Debugger^.RunCount;
  2579. end;
  2580. {$else NODEBUG}
  2581. begin
  2582. end;
  2583. {$endif NODEBUG}
  2584. procedure TWatch.Force_new_value;
  2585. begin
  2586. GDBRunCount:=-1;
  2587. Get_new_value;
  2588. end;
  2589. destructor TWatch.Done;
  2590. begin
  2591. if assigned(expr) then
  2592. disposestr(expr);
  2593. if assigned(last_value) then
  2594. strdispose(last_value);
  2595. if assigned(current_value) then
  2596. strdispose(current_value);
  2597. inherited done;
  2598. end;
  2599. {****************************************************************************
  2600. TWatchesCollection
  2601. ****************************************************************************}
  2602. constructor TWatchesCollection.Init;
  2603. begin
  2604. inherited Init(10,10);
  2605. end;
  2606. procedure TWatchesCollection.Insert(Item: Pointer);
  2607. begin
  2608. PWatch(Item)^.Get_new_value;
  2609. Inherited Insert(Item);
  2610. Update;
  2611. end;
  2612. procedure TWatchesCollection.Update;
  2613. var
  2614. W,W1 : integer;
  2615. procedure GetMax(P : PWatch);
  2616. begin
  2617. if assigned(P^.Current_value) then
  2618. W1:=StrLen(P^.Current_value)+3+Length(GetStr(P^.expr))
  2619. else
  2620. W1:=2+Length(GetStr(P^.expr));
  2621. if W1>W then
  2622. W:=W1;
  2623. end;
  2624. begin
  2625. W:=0;
  2626. ForEach(@GetMax);
  2627. MaxW:=W;
  2628. If assigned(WatchesWindow) then
  2629. WatchesWindow^.WLB^.Update(MaxW);
  2630. end;
  2631. function TWatchesCollection.At(Index: Integer): PWatch;
  2632. begin
  2633. At:=Inherited At(Index);
  2634. end;
  2635. {****************************************************************************
  2636. TWatchesListBox
  2637. ****************************************************************************}
  2638. constructor TWatchesListBox.Init(var Bounds: TRect; AHScrollBar, AVScrollBar: PScrollBar);
  2639. begin
  2640. inherited Init(Bounds,1,AHScrollBar,AVScrollBar);
  2641. If assigned(List) then
  2642. dispose(list,done);
  2643. List:=WatchesCollection;
  2644. end;
  2645. procedure TWatchesListBox.Update(AMaxWidth : integer);
  2646. var R : TRect;
  2647. begin
  2648. GetExtent(R);
  2649. MaxWidth:=AMaxWidth;
  2650. if (HScrollBar<>nil) and (R.B.X-R.A.X<MaxWidth) then
  2651. HScrollBar^.SetRange(0,MaxWidth-(R.B.X-R.A.X))
  2652. else
  2653. HScrollBar^.SetRange(0,0);
  2654. if R.B.X-R.A.X>MaxWidth then
  2655. HScrollBar^.Hide
  2656. else
  2657. HScrollBar^.Show;
  2658. SetRange(List^.Count+1);
  2659. if R.B.Y-R.A.Y>Range then
  2660. VScrollBar^.Hide
  2661. else
  2662. VScrollBar^.Show;
  2663. {if Focused=List^.Count-1-1 then
  2664. FocusItem(List^.Count-1);
  2665. What was that for ?? PM }
  2666. DrawView;
  2667. end;
  2668. function TWatchesListBox.GetIndentedText(Item,Indent,MaxLen: Sw_Integer;var Modified : boolean): String;
  2669. var
  2670. PW : PWatch;
  2671. ValOffset : Sw_integer;
  2672. S : String;
  2673. begin
  2674. Modified:=false;
  2675. if Item>=WatchesCollection^.Count then
  2676. begin
  2677. GetIndentedText:='';
  2678. exit;
  2679. end;
  2680. PW:=WatchesCollection^.At(Item);
  2681. ValOffset:=Length(GetStr(PW^.Expr))+2;
  2682. if not assigned(PW^.expr) then
  2683. GetIndentedText:=''
  2684. else if Indent<ValOffset then
  2685. begin
  2686. S:=GetStr(PW^.Expr);
  2687. if Indent=0 then
  2688. S:=' '+S
  2689. else
  2690. S:=Copy(S,Indent,High(S));
  2691. if not assigned(PW^.current_value) then
  2692. S:=S+' <Unknown value>'
  2693. else
  2694. S:=S+' '+GetPChar(PW^.Current_value);
  2695. GetIndentedText:=Copy(S,1,MaxLen);
  2696. end
  2697. else
  2698. begin
  2699. if not assigned(PW^.Current_value) or
  2700. (StrLen(PW^.Current_value)<Indent-Valoffset) then
  2701. S:=''
  2702. else
  2703. S:=GetPchar(@(PW^.Current_Value[Indent-Valoffset]));
  2704. GetIndentedText:=Copy(S,1,MaxLen);
  2705. end;
  2706. if assigned(PW^.current_value) and
  2707. assigned(PW^.last_value) and
  2708. (strcomp(PW^.Last_value,PW^.Current_value)<>0) then
  2709. Modified:=true;
  2710. end;
  2711. procedure TWatchesListBox.EditCurrent;
  2712. var
  2713. P: PWatch;
  2714. begin
  2715. if Range=0 then Exit;
  2716. if Focused<WatchesCollection^.Count then
  2717. P:=WatchesCollection^.At(Focused)
  2718. else
  2719. P:=New(PWatch,Init(''));
  2720. Application^.ExecuteDialog(New(PWatchItemDialog,Init(P)),nil);
  2721. WatchesCollection^.Update;
  2722. end;
  2723. function TWatchesListBox.GetText (Item: Sw_Integer; MaxLen: Sw_Integer): String;
  2724. var
  2725. Dummy_Modified : boolean;
  2726. begin
  2727. GetText:=GetIndentedText(Item, 0, MaxLen, Dummy_Modified);
  2728. end;
  2729. procedure TWatchesListBox.DeleteCurrent;
  2730. var
  2731. P: PWatch;
  2732. begin
  2733. if (Range=0) or
  2734. (Focused>=WatchesCollection^.Count) then
  2735. exit;
  2736. P:=WatchesCollection^.At(Focused);
  2737. WatchesCollection^.free(P);
  2738. WatchesCollection^.Update;
  2739. end;
  2740. procedure TWatchesListBox.EditNew;
  2741. var
  2742. P: PWatch;
  2743. S : string;
  2744. begin
  2745. if Focused<WatchesCollection^.Count then
  2746. begin
  2747. P:=WatchesCollection^.At(Focused);
  2748. S:=GetStr(P^.expr);
  2749. end
  2750. else
  2751. S:='';
  2752. P:=New(PWatch,Init(S));
  2753. if Application^.ExecuteDialog(New(PWatchItemDialog,Init(P)),nil)<>cmCancel then
  2754. begin
  2755. WatchesCollection^.AtInsert(Focused,P);
  2756. WatchesCollection^.Update;
  2757. end
  2758. else
  2759. dispose(P,Done);
  2760. end;
  2761. procedure TWatchesListBox.Draw;
  2762. var
  2763. I, J, Item: Sw_Integer;
  2764. NormalColor, SelectedColor, FocusedColor, Color: Word;
  2765. ColWidth, CurCol, Indent: Integer;
  2766. B: TDrawBuffer;
  2767. Modified : boolean;
  2768. Text: String;
  2769. SCOff: Byte;
  2770. TC: byte;
  2771. procedure MT(var C: word);
  2772. begin
  2773. if TC<>0 then C:=(C and $ff0f) or (TC and $f0);
  2774. end;
  2775. begin
  2776. if (Owner<>nil) then TC:=ord(Owner^.GetColor(6)) else TC:=0;
  2777. if State and (sfSelected + sfActive) = (sfSelected + sfActive) then
  2778. begin
  2779. NormalColor := GetColor(1);
  2780. FocusedColor := GetColor(3);
  2781. SelectedColor := GetColor(4);
  2782. end else
  2783. begin
  2784. NormalColor := GetColor(2);
  2785. SelectedColor := GetColor(4);
  2786. end;
  2787. if Transparent then
  2788. begin MT(NormalColor); MT(SelectedColor); end;
  2789. (* if NoSelection then
  2790. SelectedColor:=NormalColor;*)
  2791. if HScrollBar <> nil then Indent := HScrollBar^.Value
  2792. else Indent := 0;
  2793. ColWidth := Size.X div NumCols + 1;
  2794. for I := 0 to Size.Y - 1 do
  2795. begin
  2796. for J := 0 to NumCols-1 do
  2797. begin
  2798. Item := J*Size.Y + I + TopItem;
  2799. CurCol := J*ColWidth;
  2800. if (State and (sfSelected + sfActive) = (sfSelected + sfActive)) and
  2801. (Focused = Item) and (Range > 0) then
  2802. begin
  2803. Color := FocusedColor;
  2804. SetCursor(CurCol+1,I);
  2805. SCOff := 0;
  2806. end
  2807. else if (Item < Range) and IsSelected(Item) then
  2808. begin
  2809. Color := SelectedColor;
  2810. SCOff := 2;
  2811. end
  2812. else
  2813. begin
  2814. Color := NormalColor;
  2815. SCOff := 4;
  2816. end;
  2817. MoveChar(B[CurCol], ' ', Color, ColWidth);
  2818. if Item < Range then
  2819. begin
  2820. (* Text := GetText(Item, ColWidth + Indent);
  2821. Text := Copy(Text,Indent,ColWidth); *)
  2822. Text:=GetIndentedText(Item,Indent,ColWidth,Modified);
  2823. if modified then
  2824. begin
  2825. SCOff:=0;
  2826. Color:=(Color and $fff0) or Red;
  2827. end;
  2828. MoveStr(B[CurCol], Text, Color);
  2829. if {ShowMarkers or } Modified then
  2830. begin
  2831. WordRec(B[CurCol]).Lo := Byte(SpecialChars[SCOff]);
  2832. WordRec(B[CurCol+ColWidth-2]).Lo := Byte(SpecialChars[SCOff+1]);
  2833. WordRec(B[CurCol+ColWidth-2]).Hi := Color and $ff;
  2834. end;
  2835. end;
  2836. MoveChar(B[CurCol+ColWidth-1], #179, GetColor(5), 1);
  2837. end;
  2838. WriteLine(0, I, Size.X, 1, B);
  2839. end;
  2840. end;
  2841. function TWatchesListBox.GetLocalMenu: PMenu;
  2842. var M: PMenu;
  2843. begin
  2844. if (Owner<>nil) and (Owner^.GetState(sfModal)) then M:=nil else
  2845. M:=NewMenu(
  2846. NewItem(menu_watchlocal_edit,'',kbNoKey,cmEdit,hcNoContext,
  2847. NewItem(menu_watchlocal_new,'',kbNoKey,cmNew,hcNoContext,
  2848. NewItem(menu_watchlocal_delete,'',kbNoKey,cmDelete,hcNoContext,
  2849. NewLine(
  2850. NewItem(menu_msglocal_saveas,'',kbNoKey,cmSaveAs,hcSaveAs,
  2851. nil))))));
  2852. GetLocalMenu:=M;
  2853. end;
  2854. procedure TWatchesListBox.HandleEvent(var Event: TEvent);
  2855. var DontClear: boolean;
  2856. begin
  2857. case Event.What of
  2858. evKeyDown :
  2859. begin
  2860. DontClear:=false;
  2861. case Event.KeyCode of
  2862. kbEnter :
  2863. Message(@Self,evCommand,cmEdit,nil);
  2864. kbIns :
  2865. Message(@Self,evCommand,cmNew,nil);
  2866. kbDel :
  2867. Message(@Self,evCommand,cmDelete,nil);
  2868. else
  2869. DontClear:=true;
  2870. end;
  2871. if not DontClear then
  2872. ClearEvent(Event);
  2873. end;
  2874. evBroadcast :
  2875. case Event.Command of
  2876. cmListItemSelected :
  2877. if Event.InfoPtr=@Self then
  2878. Message(@Self,evCommand,cmEdit,nil);
  2879. end;
  2880. evCommand :
  2881. begin
  2882. DontClear:=false;
  2883. case Event.Command of
  2884. cmEdit :
  2885. EditCurrent;
  2886. cmDelete :
  2887. DeleteCurrent;
  2888. cmNew :
  2889. EditNew;
  2890. else
  2891. DontClear:=true;
  2892. end;
  2893. if not DontClear then
  2894. ClearEvent(Event);
  2895. end;
  2896. end;
  2897. inherited HandleEvent(Event);
  2898. end;
  2899. constructor TWatchesListBox.Load(var S: TStream);
  2900. begin
  2901. inherited Load(S);
  2902. If assigned(List) then
  2903. dispose(list,done);
  2904. List:=WatchesCollection;
  2905. { we must set Range PM }
  2906. SetRange(List^.count+1);
  2907. end;
  2908. procedure TWatchesListBox.Store(var S: TStream);
  2909. var OL: PCollection;
  2910. OldRange : Sw_integer;
  2911. begin
  2912. OL:=List;
  2913. OldRange:=Range;
  2914. Range:=0;
  2915. New(List, Init(1,1));
  2916. inherited Store(S);
  2917. Dispose(List, Done);
  2918. List:=OL;
  2919. { ^^^ nasty trick - has anyone a better idea how to avoid storing the
  2920. collection? Pasting here a modified version of TListBox.Store+
  2921. TAdvancedListBox.Store isn't a better solution, since by eventually
  2922. changing the obj-hierarchy you'll always have to modify this, too - BG }
  2923. SetRange(OldRange);
  2924. end;
  2925. destructor TWatchesListBox.Done;
  2926. begin
  2927. List:=nil;
  2928. inherited Done;
  2929. end;
  2930. {****************************************************************************
  2931. TWatchesWindow
  2932. ****************************************************************************}
  2933. Constructor TWatchesWindow.Init;
  2934. var
  2935. HSB,VSB: PScrollBar;
  2936. R,R2 : trect;
  2937. begin
  2938. Desktop^.GetExtent(R);
  2939. R.A.Y:=R.B.Y-7;
  2940. inherited Init(R, dialog_watches,SearchFreeWindowNo);
  2941. Palette:=wpCyanWindow;
  2942. GetExtent(R);
  2943. HelpCtx:=hcWatchesWindow;
  2944. R.Grow(-1,-1);
  2945. R2.Copy(R);
  2946. Inc(R2.B.Y);
  2947. R2.A.Y:=R2.B.Y-1;
  2948. New(HSB, Init(R2));
  2949. HSB^.GrowMode:=gfGrowLoY+gfGrowHiY+gfGrowHiX;
  2950. HSB^.SetStep(R.B.X-R.A.X,1);
  2951. Insert(HSB);
  2952. R2.Copy(R);
  2953. Inc(R2.B.X);
  2954. R2.A.X:=R2.B.X-1;
  2955. New(VSB, Init(R2));
  2956. VSB^.GrowMode:=gfGrowLoX+gfGrowHiX+gfGrowHiY;
  2957. Insert(VSB);
  2958. New(WLB,Init(R,HSB,VSB));
  2959. WLB^.GrowMode:=gfGrowHiX+gfGrowHiY;
  2960. WLB^.Transparent:=true;
  2961. Insert(WLB);
  2962. If assigned(WatchesWindow) then
  2963. dispose(WatchesWindow,done);
  2964. WatchesWindow:=@Self;
  2965. Update;
  2966. end;
  2967. procedure TWatchesWindow.Update;
  2968. begin
  2969. WatchesCollection^.Update;
  2970. Draw;
  2971. end;
  2972. constructor TWatchesWindow.Load(var S: TStream);
  2973. begin
  2974. inherited Load(S);
  2975. GetSubViewPtr(S,WLB);
  2976. If assigned(WatchesWindow) then
  2977. dispose(WatchesWindow,done);
  2978. WatchesWindow:=@Self;
  2979. end;
  2980. procedure TWatchesWindow.Store(var S: TStream);
  2981. begin
  2982. inherited Store(S);
  2983. PutSubViewPtr(S,WLB);
  2984. end;
  2985. Destructor TWatchesWindow.Done;
  2986. begin
  2987. WatchesWindow:=nil;
  2988. Dispose(WLB,done);
  2989. inherited done;
  2990. end;
  2991. {****************************************************************************
  2992. TWatchItemDialog
  2993. ****************************************************************************}
  2994. constructor TWatchItemDialog.Init(AWatch: PWatch);
  2995. var R,R2: TRect;
  2996. begin
  2997. R.Assign(0,0,50,10);
  2998. inherited Init(R,'Edit Watch');
  2999. Watch:=AWatch;
  3000. GetExtent(R); R.Grow(-3,-2);
  3001. Inc(R.A.Y); R.B.Y:=R.A.Y+1; R.B.X:=R.A.X+36;
  3002. New(NameIL, Init(R, 255)); Insert(NameIL);
  3003. R2.Copy(R); R2.A.X:=R2.B.X; R2.B.X:=R2.A.X+3;
  3004. Insert(New(PHistory, Init(R2, NameIL, hidWatchDialog)));
  3005. R2.Copy(R); R2.Move(-1,-1);
  3006. Insert(New(PLabel, Init(R2, label_watch_expressiontowatch, NameIL)));
  3007. GetExtent(R);
  3008. R.Grow(-3,-1);
  3009. R.A.Y:=R.A.Y+3;
  3010. TextST:=New(PAdvancedStaticText, Init(R, label_watch_values));
  3011. Insert(TextST);
  3012. InsertButtons(@Self);
  3013. NameIL^.Select;
  3014. end;
  3015. function TWatchItemDialog.Execute: Word;
  3016. var R: word;
  3017. S1,S2: string;
  3018. begin
  3019. S1:=GetStr(Watch^.expr);
  3020. NameIL^.SetData(S1);
  3021. S1:=GetPChar(Watch^.Current_value);
  3022. S2:=GetPChar(Watch^.Last_value);
  3023. ClearFormatParams;
  3024. AddFormatParamStr(S1);
  3025. AddFormatParamStr(S2);
  3026. if assigned(Watch^.Last_value) and
  3027. assigned(Watch^.Current_value) and
  3028. (strcomp(Watch^.Last_value,Watch^.Current_value)=0) then
  3029. S1:=FormatStrF(msg_watch_currentvalue,FormatParams)
  3030. else
  3031. S1:=FormatStrF(msg_watch_currentandpreviousvalue,FormatParams);
  3032. TextST^.SetText(S1);
  3033. if assigned(FirstEditorWindow) then
  3034. FindReplaceEditor:=FirstEditorWindow^.Editor;
  3035. R:=inherited Execute;
  3036. FindReplaceEditor:=nil;
  3037. if R=cmOK then
  3038. begin
  3039. NameIL^.GetData(S1);
  3040. Watch^.Rename(S1);
  3041. {$ifndef NODEBUG}
  3042. If assigned(Debugger) then
  3043. Debugger^.ReadWatches;
  3044. {$endif NODEBUG}
  3045. end;
  3046. Execute:=R;
  3047. end;
  3048. {****************************************************************************
  3049. TStackWindow
  3050. ****************************************************************************}
  3051. constructor TFramesListBox.Init(var Bounds: TRect; AHScrollBar, AVScrollBar: PScrollBar);
  3052. begin
  3053. Inherited Init(Bounds,AHScrollBar,AVScrollBar);
  3054. end;
  3055. procedure TFramesListBox.Update;
  3056. var i : longint;
  3057. W : PSourceWindow;
  3058. begin
  3059. {$ifndef NODEBUG}
  3060. { call backtrace command }
  3061. If not assigned(Debugger) then
  3062. exit;
  3063. DeskTop^.Lock;
  3064. Clear;
  3065. { forget all old frames }
  3066. Debugger^.clear_frames;
  3067. if Debugger^.WindowWidth<>-1 then
  3068. Debugger^.Command('set width 0xffffffff');
  3069. Debugger^.Command('backtrace');
  3070. { generate list }
  3071. { all is in tframeentry }
  3072. for i:=0 to Debugger^.frame_count-1 do
  3073. begin
  3074. with Debugger^.frames[i]^ do
  3075. begin
  3076. if assigned(file_name) then
  3077. AddItem(new(PMessageItem,init(0,GetPChar(function_name)+GetPChar(args),
  3078. AddModuleName(GetPChar(file_name)),line_number,1)))
  3079. else
  3080. AddItem(new(PMessageItem,init(0,HexStr(address,8)+' '+GetPChar(function_name)+GetPChar(args),
  3081. AddModuleName(''),line_number,1)));
  3082. W:=SearchOnDesktop(GetPChar(file_name),false);
  3083. { First reset all Debugger rows }
  3084. If assigned(W) then
  3085. begin
  3086. W^.Editor^.SetLineFlagExclusive(lfDebuggerRow,-1);
  3087. W^.Editor^.DebuggerRow:=-1;
  3088. end;
  3089. end;
  3090. end;
  3091. { Now set all Debugger rows }
  3092. for i:=0 to Debugger^.frame_count-1 do
  3093. begin
  3094. with Debugger^.frames[i]^ do
  3095. begin
  3096. W:=SearchOnDesktop(GetPChar(file_name),false);
  3097. If assigned(W) then
  3098. begin
  3099. If W^.Editor^.DebuggerRow=-1 then
  3100. begin
  3101. W^.Editor^.SetLineFlagState(line_number-1,lfDebuggerRow,true);
  3102. W^.Editor^.DebuggerRow:=line_number-1;
  3103. end;
  3104. end;
  3105. end;
  3106. end;
  3107. if Assigned(list) and (List^.Count > 0) then
  3108. FocusItem(0);
  3109. if Debugger^.WindowWidth<>-1 then
  3110. Debugger^.Command('set width '+IntToStr(Debugger^.WindowWidth));
  3111. DeskTop^.Unlock;
  3112. {$endif NODEBUG}
  3113. end;
  3114. function TFramesListBox.GetLocalMenu: PMenu;
  3115. begin
  3116. GetLocalMenu:=Inherited GetLocalMenu;
  3117. end;
  3118. procedure TFramesListBox.GotoSource;
  3119. begin
  3120. {$ifndef NODEBUG}
  3121. { select frame for watches }
  3122. If not assigned(Debugger) then
  3123. exit;
  3124. Debugger^.Command('f '+IntToStr(Focused));
  3125. { for local vars }
  3126. Debugger^.RereadWatches;
  3127. {$endif NODEBUG}
  3128. { goto source }
  3129. inherited GotoSource;
  3130. end;
  3131. procedure TFramesListBox.GotoAssembly;
  3132. begin
  3133. {$ifndef NODEBUG}
  3134. { select frame for watches }
  3135. If not assigned(Debugger) then
  3136. exit;
  3137. Debugger^.Command('f '+IntToStr(Focused));
  3138. { for local vars }
  3139. Debugger^.RereadWatches;
  3140. {$endif}
  3141. { goto source/assembly mixture }
  3142. InitDisassemblyWindow;
  3143. DisassemblyWindow^.LoadFunction('');
  3144. {$ifndef NODEBUG}
  3145. DisassemblyWindow^.SetCurAddress(Debugger^.frames[Focused]^.address);
  3146. DisassemblyWindow^.SelectInDebugSession;
  3147. {$endif NODEBUG}
  3148. end;
  3149. procedure TFramesListBox.HandleEvent(var Event: TEvent);
  3150. begin
  3151. if ((Event.What=EvKeyDown) and (Event.CharCode='i')) or
  3152. ((Event.What=EvCommand) and (Event.Command=cmDisassemble)) then
  3153. GotoAssembly;
  3154. inherited HandleEvent(Event);
  3155. end;
  3156. destructor TFramesListBox.Done;
  3157. begin
  3158. Inherited Done;
  3159. end;
  3160. Constructor TStackWindow.Init;
  3161. var
  3162. HSB,VSB: PScrollBar;
  3163. R,R2 : trect;
  3164. begin
  3165. Desktop^.GetExtent(R);
  3166. R.A.Y:=R.B.Y-5;
  3167. inherited Init(R, dialog_callstack, wnNoNumber);
  3168. Palette:=wpCyanWindow;
  3169. GetExtent(R);
  3170. HelpCtx:=hcStackWindow;
  3171. R.Grow(-1,-1);
  3172. R2.Copy(R);
  3173. Inc(R2.B.Y);
  3174. R2.A.Y:=R2.B.Y-1;
  3175. New(HSB, Init(R2));
  3176. HSB^.GrowMode:=gfGrowLoY+gfGrowHiY+gfGrowHiX;
  3177. Insert(HSB);
  3178. R2.Copy(R);
  3179. Inc(R2.B.X);
  3180. R2.A.X:=R2.B.X-1;
  3181. New(VSB, Init(R2));
  3182. VSB^.GrowMode:=gfGrowLoX+gfGrowHiX+gfGrowHiY;
  3183. Insert(VSB);
  3184. New(FLB,Init(R,HSB,VSB));
  3185. FLB^.GrowMode:=gfGrowHiX+gfGrowHiY;
  3186. Insert(FLB);
  3187. If assigned(StackWindow) then
  3188. dispose(StackWindow,done);
  3189. StackWindow:=@Self;
  3190. Update;
  3191. end;
  3192. procedure TStackWindow.Update;
  3193. begin
  3194. FLB^.Update;
  3195. DrawView;
  3196. end;
  3197. constructor TStackWindow.Load(var S: TStream);
  3198. begin
  3199. inherited Load(S);
  3200. GetSubViewPtr(S,FLB);
  3201. If assigned(StackWindow) then
  3202. dispose(StackWindow,done);
  3203. StackWindow:=@Self;
  3204. end;
  3205. procedure TStackWindow.Store(var S: TStream);
  3206. begin
  3207. inherited Store(S);
  3208. PutSubViewPtr(S,FLB);
  3209. end;
  3210. Destructor TStackWindow.Done;
  3211. begin
  3212. StackWindow:=nil;
  3213. Dispose(FLB,done);
  3214. inherited done;
  3215. end;
  3216. {****************************************************************************
  3217. Init/Final
  3218. ****************************************************************************}
  3219. function GetGDBTargetShortName : string;
  3220. begin
  3221. {$ifdef SUPPORT_REMOTE}
  3222. {$ifdef PALMOSGDB}
  3223. GetGDBTargetShortName:='palmos';
  3224. {$else}
  3225. GetGDBTargetShortName:='linux';
  3226. {$endif PALMOSGDB}
  3227. {$else not SUPPORT_REMOTE}
  3228. GetGDBTargetShortName:=source_info.shortname
  3229. {$endif not SUPPORT_REMOTE}
  3230. end;
  3231. procedure InitDebugger;
  3232. {$ifdef DEBUG}
  3233. var s : string;
  3234. i,p : longint;
  3235. {$endif DEBUG}
  3236. var
  3237. NeedRecompileExe : boolean;
  3238. cm : longint;
  3239. begin
  3240. {$ifdef DEBUG}
  3241. if not use_gdb_file then
  3242. begin
  3243. Assign(gdb_file,GDBOutFileName);
  3244. {$I-}
  3245. Rewrite(gdb_file);
  3246. if InOutRes<>0 then
  3247. begin
  3248. s:=GDBOutFileName;
  3249. p:=pos('.',s);
  3250. if p>1 then
  3251. for i:=0 to 9 do
  3252. begin
  3253. s:=copy(s,1,p-2)+chr(i+ord('0'))+copy(s,p,length(s));
  3254. InOutRes:=0;
  3255. Assign(gdb_file,s);
  3256. rewrite(gdb_file);
  3257. if InOutRes=0 then
  3258. break;
  3259. end;
  3260. end;
  3261. if IOResult=0 then
  3262. Use_gdb_file:=true;
  3263. end;
  3264. {$I+}
  3265. {$endif}
  3266. NeedRecompileExe:=false;
  3267. if UpCaseStr(TargetSwitches^.GetCurrSelParam)<>UpCaseStr(GetGDBTargetShortName) then
  3268. begin
  3269. ClearFormatParams;
  3270. AddFormatParamStr(TargetSwitches^.GetCurrSelParam);
  3271. AddFormatParamStr(GetGDBTargetShortName);
  3272. cm:=ConfirmBox(msg_cantdebugchangetargetto,@FormatParams,true);
  3273. if cm=cmCancel then
  3274. Exit;
  3275. if cm=cmYes then
  3276. begin
  3277. { force recompilation }
  3278. PrevMainFile:='';
  3279. NeedRecompileExe:=true;
  3280. TargetSwitches^.SetCurrSelParam(GetGDBTargetShortName);
  3281. If DebugInfoSwitches^.GetCurrSelParam='-' then
  3282. DebugInfoSwitches^.SetCurrSelParam('l');
  3283. IDEApp.UpdateTarget;
  3284. end;
  3285. end;
  3286. if not NeedRecompileExe then
  3287. NeedRecompileExe:=(not ExistsFile(ExeFile)) or (CompilationPhase<>cpDone) or
  3288. (PrevMainFile<>MainFile) or NeedRecompile(cRun,false);
  3289. if Not NeedRecompileExe and Not MainHasDebugInfo then
  3290. begin
  3291. ClearFormatParams;
  3292. cm:=ConfirmBox(msg_compiledwithoutdebuginforecompile,nil,true);
  3293. if cm=cmCancel then
  3294. Exit;
  3295. if cm=cmYes then
  3296. begin
  3297. { force recompilation }
  3298. PrevMainFile:='';
  3299. NeedRecompileExe:=true;
  3300. DebugInfoSwitches^.SetCurrSelParam('l');
  3301. end;
  3302. end;
  3303. if NeedRecompileExe then
  3304. DoCompile(cRun);
  3305. if CompilationPhase<>cpDone then
  3306. Exit;
  3307. if (EXEFile='') then
  3308. begin
  3309. ErrorBox(msg_nothingtodebug,nil);
  3310. Exit;
  3311. end;
  3312. { init debugcontroller }
  3313. {$ifndef NODEBUG}
  3314. if not assigned(Debugger) then
  3315. begin
  3316. PushStatus(msg_startingdebugger);
  3317. new(Debugger,Init);
  3318. PopStatus;
  3319. end;
  3320. Debugger^.SetExe(ExeFile);
  3321. {$endif NODEBUG}
  3322. {$ifdef GDBWINDOW}
  3323. InitGDBWindow;
  3324. {$endif def GDBWINDOW}
  3325. end;
  3326. procedure DoneDebugger;
  3327. begin
  3328. {$ifdef DEBUG}
  3329. If IDEApp.IsRunning then
  3330. PushStatus('Closing debugger');
  3331. {$endif}
  3332. {$ifndef NODEBUG}
  3333. if assigned(Debugger) then
  3334. dispose(Debugger,Done);
  3335. Debugger:=nil;
  3336. {$endif NODEBUG}
  3337. {$ifdef DOS}
  3338. If assigned(UserScreen) then
  3339. PDosScreen(UserScreen)^.FreeGraphBuffer;
  3340. {$endif DOS}
  3341. {$ifdef DEBUG}
  3342. If Use_gdb_file then
  3343. begin
  3344. Use_gdb_file:=false;
  3345. Close(GDB_file);
  3346. end;
  3347. If IDEApp.IsRunning then
  3348. PopStatus;
  3349. {$endif DEBUG}
  3350. end;
  3351. procedure InitGDBWindow;
  3352. var
  3353. R : TRect;
  3354. begin
  3355. if GDBWindow=nil then
  3356. begin
  3357. DeskTop^.GetExtent(R);
  3358. new(GDBWindow,init(R));
  3359. DeskTop^.Insert(GDBWindow);
  3360. end;
  3361. end;
  3362. procedure DoneGDBWindow;
  3363. begin
  3364. If IDEApp.IsRunning and
  3365. assigned(GDBWindow) then
  3366. begin
  3367. DeskTop^.Delete(GDBWindow);
  3368. end;
  3369. GDBWindow:=nil;
  3370. end;
  3371. procedure InitDisassemblyWindow;
  3372. var
  3373. R : TRect;
  3374. begin
  3375. if DisassemblyWindow=nil then
  3376. begin
  3377. DeskTop^.GetExtent(R);
  3378. new(DisassemblyWindow,init(R));
  3379. DeskTop^.Insert(DisassemblyWindow);
  3380. end;
  3381. end;
  3382. procedure DoneDisassemblyWindow;
  3383. begin
  3384. if assigned(DisassemblyWindow) then
  3385. begin
  3386. DeskTop^.Delete(DisassemblyWindow);
  3387. Dispose(DisassemblyWindow,Done);
  3388. DisassemblyWindow:=nil;
  3389. end;
  3390. end;
  3391. procedure InitStackWindow;
  3392. begin
  3393. if StackWindow=nil then
  3394. begin
  3395. new(StackWindow,init);
  3396. DeskTop^.Insert(StackWindow);
  3397. end;
  3398. end;
  3399. procedure DoneStackWindow;
  3400. begin
  3401. if assigned(StackWindow) then
  3402. begin
  3403. DeskTop^.Delete(StackWindow);
  3404. StackWindow:=nil;
  3405. end;
  3406. end;
  3407. procedure InitBreakpoints;
  3408. begin
  3409. New(BreakpointsCollection,init(10,10));
  3410. end;
  3411. procedure DoneBreakpoints;
  3412. begin
  3413. Dispose(BreakpointsCollection,Done);
  3414. BreakpointsCollection:=nil;
  3415. end;
  3416. procedure InitWatches;
  3417. begin
  3418. New(WatchesCollection,init);
  3419. end;
  3420. procedure DoneWatches;
  3421. begin
  3422. Dispose(WatchesCollection,Done);
  3423. WatchesCollection:=nil;
  3424. end;
  3425. procedure RegisterFPDebugViews;
  3426. begin
  3427. RegisterType(RWatchesWindow);
  3428. RegisterType(RBreakpointsWindow);
  3429. RegisterType(RWatchesListBox);
  3430. RegisterType(RBreakpointsListBox);
  3431. RegisterType(RStackWindow);
  3432. RegisterType(RFramesListBox);
  3433. RegisterType(RBreakpoint);
  3434. RegisterType(RWatch);
  3435. RegisterType(RBreakpointCollection);
  3436. RegisterType(RWatchesCollection);
  3437. end;
  3438. end.
  3439. {$endif NODEBUG}