fpdebug.pas 98 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610
  1. {
  2. $Id$
  3. This file is part of the Free Pascal Integrated Development Environment
  4. Copyright (c) 1998-2000 by Pierre Muller
  5. Debugger call routines for the IDE
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. unit FPDebug;
  13. interface
  14. uses
  15. Objects,Dialogs,Drivers,Views,
  16. GDBCon,GDBInt,Menus,
  17. WViews,
  18. FPViews;
  19. type
  20. PDebugController=^TDebugController;
  21. TDebugController=object(TGDBController)
  22. InvalidSourceLine : boolean;
  23. { if true the current debugger raw will stay in middle of
  24. editor window when debugging PM }
  25. CenterDebuggerRow : boolean;
  26. LastFileName : string;
  27. LastSource : PView; {PsourceWindow !! }
  28. HiddenStepsCount : longint;
  29. { no need to switch if using another terminal }
  30. NoSwitch : boolean;
  31. RunCount : longint;
  32. constructor Init(const exefn:string);
  33. destructor Done;
  34. procedure DoSelectSourceline(const fn:string;line:longint);virtual;
  35. { procedure DoStartSession;virtual;
  36. procedure DoBreakSession;virtual;}
  37. procedure DoEndSession(code:longint);virtual;
  38. procedure AnnotateError;
  39. procedure InsertBreakpoints;
  40. procedure RemoveBreakpoints;
  41. procedure ReadWatches;
  42. procedure ResetBreakpointsValues;
  43. procedure DoDebuggerScreen;virtual;
  44. procedure DoUserScreen;virtual;
  45. procedure Reset;virtual;
  46. procedure ResetDebuggerRows;
  47. procedure Run;virtual;
  48. procedure Continue;virtual;
  49. procedure UntilReturn;virtual;
  50. procedure CommandBegin(const s:string);virtual;
  51. procedure CommandEnd(const s:string);virtual;
  52. function IsRunning : boolean;
  53. function AllowQuit : boolean;virtual;
  54. function GetValue(Const expr : string) : pchar;
  55. end;
  56. BreakpointType = (bt_function,bt_file_line,bt_watch,bt_awatch,bt_rwatch,bt_invalid);
  57. BreakpointState = (bs_enabled,bs_disabled,bs_deleted);
  58. PBreakpointCollection=^TBreakpointCollection;
  59. PBreakpoint=^TBreakpoint;
  60. TBreakpoint=object(TObject)
  61. typ : BreakpointType;
  62. state : BreakpointState;
  63. owner : PBreakpointCollection;
  64. Name : PString; { either function name or expr to watch }
  65. FileName : PString;
  66. OldValue,CurrentValue : Pstring;
  67. Line : Longint; { only used for bt_file_line type }
  68. Conditions : PString; { conditions relative to that breakpoint }
  69. IgnoreCount : Longint; { how many counts should be ignored }
  70. Commands : pchar; { commands that should be executed on breakpoint }
  71. GDBIndex : longint;
  72. GDBState : BreakpointState;
  73. constructor Init_function(Const AFunc : String);
  74. constructor Init_Empty;
  75. constructor Init_file_line(AFile : String; ALine : longint);
  76. constructor Init_type(atyp : BreakpointType;Const AnExpr : String);
  77. constructor Load(var S: TStream);
  78. procedure Store(var S: TStream);
  79. procedure Insert;
  80. procedure Remove;
  81. procedure Enable;
  82. procedure Disable;
  83. procedure UpdateSource;
  84. procedure ResetValues;
  85. destructor Done;virtual;
  86. end;
  87. TBreakpointCollection=object(TCollection)
  88. function At(Index: Integer): PBreakpoint;
  89. function GetGDB(index : longint) : PBreakpoint;
  90. function GetType(typ : BreakpointType;Const s : String) : PBreakpoint;
  91. function ToggleFileLine(FileName: String;LineNr : Longint) : boolean;
  92. procedure Update;
  93. procedure ShowBreakpoints(W : PSourceWindow);
  94. procedure ShowAllBreakpoints;
  95. end;
  96. PBreakpointItem = ^TBreakpointItem;
  97. TBreakpointItem = object(TObject)
  98. Breakpoint : PBreakpoint;
  99. constructor Init(ABreakpoint : PBreakpoint);
  100. function GetText(MaxLen: Sw_integer): string; virtual;
  101. procedure Selected; virtual;
  102. function GetModuleName: string; virtual;
  103. end;
  104. PBreakpointsListBox = ^TBreakpointsListBox;
  105. TBreakpointsListBox = object(THSListBox)
  106. Transparent : boolean;
  107. NoSelection : boolean;
  108. MaxWidth : Sw_integer;
  109. (* ModuleNames : PStoreCollection; *)
  110. constructor Init(var Bounds: TRect; AHScrollBar, AVScrollBar: PScrollBar);
  111. procedure AddBreakpoint(P: PBreakpointItem); virtual;
  112. function GetText(Item,MaxLen: Sw_Integer): String; virtual;
  113. function GetLocalMenu: PMenu;virtual;
  114. procedure Clear; virtual;
  115. procedure TrackSource; virtual;
  116. procedure EditNew; virtual;
  117. procedure EditCurrent; virtual;
  118. procedure DeleteCurrent; virtual;
  119. procedure ToggleCurrent;
  120. procedure Draw; virtual;
  121. procedure HandleEvent(var Event: TEvent); virtual;
  122. constructor Load(var S: TStream);
  123. procedure Store(var S: TStream);
  124. destructor Done; virtual;
  125. end;
  126. PBreakpointsWindow = ^TBreakpointsWindow;
  127. TBreakpointsWindow = object(TDlgWindow)
  128. BreakLB : PBreakpointsListBox;
  129. constructor Init;
  130. procedure AddBreakpoint(ABreakpoint : PBreakpoint);
  131. procedure ClearBreakpoints;
  132. procedure ReloadBreakpoints;
  133. procedure Close; virtual;
  134. procedure SizeLimits(var Min, Max: TPoint);virtual;
  135. procedure HandleEvent(var Event: TEvent); virtual;
  136. procedure Update; virtual;
  137. constructor Load(var S: TStream);
  138. procedure Store(var S: TStream);
  139. destructor Done; virtual;
  140. end;
  141. PBreakpointItemDialog = ^TBreakpointItemDialog;
  142. TBreakpointItemDialog = object(TCenterDialog)
  143. constructor Init(ABreakpoint: PBreakpoint);
  144. function Execute: Word; virtual;
  145. private
  146. Breakpoint : PBreakpoint;
  147. TypeRB : PRadioButtons;
  148. NameIL : PInputLine;
  149. ConditionsIL: PInputLine;
  150. LineIL : PInputLine;
  151. IgnoreIL : PInputLine;
  152. end;
  153. PWatch = ^TWatch;
  154. TWatch = Object(TObject)
  155. constructor Init(s : string);
  156. constructor Load(var S: TStream);
  157. procedure Store(var S: TStream);
  158. procedure rename(s : string);
  159. procedure Get_new_value;
  160. destructor done;virtual;
  161. private
  162. expr : pstring;
  163. last_value,current_value : pchar;
  164. end;
  165. PWatchesCollection = ^TWatchesCollection;
  166. TWatchesCollection = Object(TCollection)
  167. constructor Init;
  168. procedure Insert(Item: Pointer); virtual;
  169. function At(Index: Integer): PWatch;
  170. procedure Update;
  171. private
  172. MaxW : integer;
  173. end;
  174. PWatchesListBox = ^TWatchesListBox;
  175. TWatchesListBox = object(THSListBox)
  176. Transparent : boolean;
  177. MaxWidth : Sw_integer;
  178. constructor Init(var Bounds: TRect; AHScrollBar, AVScrollBar: PScrollBar);
  179. (* procedure AddWatch(P: PWatch); virtual; *)
  180. procedure Update(AMaxWidth : integer);
  181. function GetIndentedText(Item,Indent,MaxLen: Sw_Integer): String; virtual;
  182. function GetLocalMenu: PMenu;virtual;
  183. (* procedure Clear; virtual;
  184. procedure TrackSource; virtual;*)
  185. procedure EditNew; virtual;
  186. procedure EditCurrent; virtual;
  187. procedure DeleteCurrent; virtual;
  188. (*procedure ToggleCurrent; *)
  189. procedure Draw; virtual;
  190. procedure HandleEvent(var Event: TEvent); virtual;
  191. constructor Load(var S: TStream);
  192. procedure Store(var S: TStream);
  193. destructor Done; virtual;
  194. end;
  195. PWatchItemDialog = ^TWatchItemDialog;
  196. TWatchItemDialog = object(TCenterDialog)
  197. constructor Init(AWatch: PWatch);
  198. function Execute: Word; virtual;
  199. private
  200. Watch : PWatch;
  201. NameIL : PInputLine;
  202. TextST : PAdvancedStaticText;
  203. end;
  204. PWatchesWindow = ^TWatchesWindow;
  205. TWatchesWindow = Object(TDlgWindow)
  206. WLB : PWatchesListBox;
  207. Constructor Init;
  208. constructor Load(var S: TStream);
  209. procedure Store(var S: TStream);
  210. procedure Update; virtual;
  211. destructor Done; virtual;
  212. end;
  213. PFramesListBox = ^TFramesListBox;
  214. TFramesListBox = object(TMessageListBox)
  215. constructor Init(var Bounds: TRect; AHScrollBar, AVScrollBar: PScrollBar);
  216. procedure Update;
  217. function GetLocalMenu: PMenu;virtual;
  218. procedure GotoSource; virtual;
  219. procedure HandleEvent(var Event: TEvent); virtual;
  220. destructor Done; virtual;
  221. end;
  222. PStackWindow = ^TStackWindow;
  223. TStackWindow = Object(TDlgWindow)
  224. FLB : PFramesListBox;
  225. Constructor Init;
  226. constructor Load(var S: TStream);
  227. procedure Store(var S: TStream);
  228. procedure Update; virtual;
  229. destructor Done; virtual;
  230. end;
  231. {$ifdef TP} dword = longint; {$endif}
  232. TIntRegs = record
  233. eax,ebx,ecx,edx,eip,esi,edi,esp,ebp : dword;
  234. cs,ds,es,ss,fs,gs : word;
  235. eflags : dword;
  236. end;
  237. PRegistersView = ^TRegistersView;
  238. TRegistersView = object(TView)
  239. OldReg : TIntRegs;
  240. constructor Init(var Bounds: TRect);
  241. procedure Draw;virtual;
  242. destructor Done; virtual;
  243. end;
  244. PRegistersWindow = ^TRegistersWindow;
  245. TRegistersWindow = Object(TDlgWindow)
  246. RV : PRegistersView;
  247. Constructor Init;
  248. constructor Load(var S: TStream);
  249. procedure Store(var S: TStream);
  250. procedure Update; virtual;
  251. destructor Done; virtual;
  252. end;
  253. TFPURegs = record
  254. end;
  255. PFPUView = ^TFPUView;
  256. TFPUView = object(TView)
  257. OldReg : TFPURegs;
  258. constructor Init(var Bounds: TRect);
  259. procedure Draw;virtual;
  260. destructor Done; virtual;
  261. end;
  262. PFPUWindow = ^TFPUWindow;
  263. TFPUWindow = Object(TDlgWindow)
  264. RV : PFPUView;
  265. Constructor Init;
  266. constructor Load(var S: TStream);
  267. procedure Store(var S: TStream);
  268. procedure Update; virtual;
  269. destructor Done; virtual;
  270. end;
  271. const
  272. StackWindow : PStackWindow = nil;
  273. RegistersWindow : PRegistersWindow = nil;
  274. FPUWindow : PFPUWindow = nil;
  275. procedure InitStackWindow;
  276. procedure DoneStackWindow;
  277. procedure InitRegistersWindow;
  278. procedure DoneRegistersWindow;
  279. function ActiveBreakpoints : boolean;
  280. function GDBFileName(st : string) : string;
  281. const
  282. BreakpointTypeStr : Array[BreakpointType] of String[9]
  283. = ( 'function','file-line','watch','awatch','rwatch','invalid' );
  284. BreakpointStateStr : Array[BreakpointState] of String[8]
  285. = ( 'enabled','disabled','invalid' );
  286. DebuggeeTTY : string = '';
  287. var
  288. Debugger : PDebugController;
  289. BreakpointsCollection : PBreakpointCollection;
  290. WatchesCollection : PwatchesCollection;
  291. procedure InitDebugger;
  292. procedure DoneDebugger;
  293. procedure InitGDBWindow;
  294. procedure DoneGDBWindow;
  295. procedure InitBreakpoints;
  296. procedure DoneBreakpoints;
  297. procedure InitWatches;
  298. procedure DoneWatches;
  299. procedure RegisterFPDebugViews;
  300. procedure UpdateDebugViews;
  301. implementation
  302. uses
  303. Dos,Mouse,Video,
  304. App,Commands,Strings,
  305. {$ifdef win32}
  306. Windebug,
  307. {$endif win32}
  308. Systems,
  309. FPVars,FPUtils,FPConst,FPSwitch,
  310. FPIntf,FPCompile,FPIde,FPHelp,
  311. Validate,WEditor,WUtils;
  312. const
  313. RBreakpointsWindow: TStreamRec = (
  314. ObjType: 1701;
  315. VmtLink: Ofs(TypeOf(TBreakpointsWindow)^);
  316. Load: @TBreakpointsWindow.Load;
  317. Store: @TBreakpointsWindow.Store
  318. );
  319. RBreakpointsListBox : TStreamRec = (
  320. ObjType: 1702;
  321. VmtLink: Ofs(TypeOf(TBreakpointsListBox)^);
  322. Load: @TBreakpointsListBox.Load;
  323. Store: @TBreakpointsListBox.Store
  324. );
  325. RWatchesWindow: TStreamRec = (
  326. ObjType: 1703;
  327. VmtLink: Ofs(TypeOf(TWatchesWindow)^);
  328. Load: @TWatchesWindow.Load;
  329. Store: @TWatchesWindow.Store
  330. );
  331. RWatchesListBox: TStreamRec = (
  332. ObjType: 1704;
  333. VmtLink: Ofs(TypeOf(TWatchesListBox)^);
  334. Load: @TWatchesListBox.Load;
  335. Store: @TWatchesListBox.Store
  336. );
  337. RStackWindow: TStreamRec = (
  338. ObjType: 1705;
  339. VmtLink: Ofs(TypeOf(TStackWindow)^);
  340. Load: @TStackWindow.Load;
  341. Store: @TStackWindow.Store
  342. );
  343. RFramesListBox: TStreamRec = (
  344. ObjType: 1706;
  345. VmtLink: Ofs(TypeOf(TFramesListBox)^);
  346. Load: @TFramesListBox.Load;
  347. Store: @TFramesListBox.Store
  348. );
  349. RBreakpoint: TStreamRec = (
  350. ObjType: 1707;
  351. VmtLink: Ofs(TypeOf(TBreakpoint)^);
  352. Load: @TBreakpoint.Load;
  353. Store: @TBreakpoint.Store
  354. );
  355. RWatch: TStreamRec = (
  356. ObjType: 1708;
  357. VmtLink: Ofs(TypeOf(TWatch)^);
  358. Load: @TWatch.Load;
  359. Store: @TWatch.Store
  360. );
  361. RBreakpointCollection: TStreamRec = (
  362. ObjType: 1709;
  363. VmtLink: Ofs(TypeOf(TBreakpointCollection)^);
  364. Load: @TBreakpointCollection.Load;
  365. Store: @TBreakpointCollection.Store
  366. );
  367. RWatchesCollection: TStreamRec = (
  368. ObjType: 1710;
  369. VmtLink: Ofs(TypeOf(TWatchesCollection)^);
  370. Load: @TWatchesCollection.Load;
  371. Store: @TWatchesCollection.Store
  372. );
  373. RRegistersWindow: TStreamRec = (
  374. ObjType: 1711;
  375. VmtLink: Ofs(TypeOf(TRegistersWindow)^);
  376. Load: @TRegistersWindow.Load;
  377. Store: @TRegistersWindow.Store
  378. );
  379. RRegistersView: TStreamRec = (
  380. ObjType: 1712;
  381. VmtLink: Ofs(TypeOf(TRegistersView)^);
  382. Load: @TRegistersView.Load;
  383. Store: @TRegistersView.Store
  384. );
  385. RFPUWindow: TStreamRec = (
  386. ObjType: 1713;
  387. VmtLink: Ofs(TypeOf(TFPUWindow)^);
  388. Load: @TFPUWindow.Load;
  389. Store: @TFPUWindow.Store
  390. );
  391. RFPUView: TStreamRec = (
  392. ObjType: 1714;
  393. VmtLink: Ofs(TypeOf(TFPUView)^);
  394. Load: @TFPUView.Load;
  395. Store: @TFPUView.Store
  396. );
  397. {$ifdef TP}
  398. function HexStr(Value: longint; Len: byte): string;
  399. begin
  400. HexStr:=IntToHexL(Value,Len);
  401. end;
  402. {$endif}
  403. function GDBFileName(st : string) : string;
  404. {$ifndef Linux}
  405. var i : longint;
  406. {$endif Linux}
  407. begin
  408. {$ifdef Linux}
  409. GDBFileName:=st;
  410. {$else}
  411. { should we also use / chars ? }
  412. for i:=1 to Length(st) do
  413. if st[i]='\' then
  414. st[i]:='/';
  415. {$ifdef win32}
  416. { for win32 we should convert e:\ into //e/ PM }
  417. if (length(st)>2) and (st[2]=':') and (st[3]='/') then
  418. st:='//'+st[1]+copy(st,3,length(st));
  419. {$endif win32}
  420. {$ifdef go32v2}
  421. { for go32v2 we should convert //e/ back into e:/ PM }
  422. if (length(st)>3) and (st[1]='/') and (st[2]='/') and (st[4]='/') then
  423. st:=st[3]+':/'+copy(st,5,length(st));
  424. {$endif go32v2}
  425. GDBFileName:=LowerCaseStr(st);
  426. {$endif}
  427. end;
  428. {****************************************************************************
  429. TDebugController
  430. ****************************************************************************}
  431. procedure UpdateDebugViews;
  432. begin
  433. DeskTop^.Lock;
  434. If assigned(StackWindow) then
  435. StackWindow^.Update;
  436. If assigned(RegistersWindow) then
  437. RegistersWindow^.Update;
  438. If assigned(Debugger) then
  439. Debugger^.ReadWatches;
  440. If assigned(FPUWindow) then
  441. FPUWindow^.Update;
  442. DeskTop^.UnLock;
  443. end;
  444. constructor TDebugController.Init(const exefn:string);
  445. var f: string;
  446. begin
  447. inherited Init;
  448. CenterDebuggerRow:=IniCenterDebuggerRow;
  449. f := GetShortName(GDBFileName(exefn));
  450. NoSwitch:=False;
  451. LoadFile(f);
  452. SetArgs(GetRunParameters);
  453. Debugger:=@self;
  454. {$ifndef GABOR}
  455. switch_to_user:=true;
  456. {$endif}
  457. InsertBreakpoints;
  458. ReadWatches;
  459. end;
  460. procedure TDebugController.InsertBreakpoints;
  461. procedure DoInsert(PB : PBreakpoint);
  462. begin
  463. PB^.Insert;
  464. end;
  465. begin
  466. BreakpointsCollection^.ForEach(@DoInsert);
  467. end;
  468. procedure TDebugController.ReadWatches;
  469. procedure DoRead(PB : PWatch);
  470. begin
  471. PB^.Get_new_value;
  472. end;
  473. begin
  474. WatchesCollection^.ForEach(@DoRead);
  475. If Assigned(WatchesWindow) then
  476. WatchesWindow^.Update;
  477. end;
  478. procedure TDebugController.RemoveBreakpoints;
  479. procedure DoDelete(PB : PBreakpoint);
  480. begin
  481. PB^.Remove;
  482. end;
  483. begin
  484. BreakpointsCollection^.ForEach(@DoDelete);
  485. end;
  486. procedure TDebugController.ResetBreakpointsValues;
  487. procedure DoResetVal(PB : PBreakpoint);
  488. begin
  489. PB^.ResetValues;
  490. end;
  491. begin
  492. BreakpointsCollection^.ForEach(@DoResetVal);
  493. end;
  494. function ActiveBreakpoints : boolean;
  495. var
  496. IsActive : boolean;
  497. procedure TestActive(PB : PBreakpoint);
  498. begin
  499. If PB^.state=bs_enabled then
  500. IsActive:=true;
  501. end;
  502. begin
  503. IsActive:=false;
  504. If assigned(BreakpointsCollection) then
  505. BreakpointsCollection^.ForEach(@TestActive);
  506. ActiveBreakpoints:=IsActive;
  507. end;
  508. destructor TDebugController.Done;
  509. begin
  510. { kill the program if running }
  511. Reset;
  512. RemoveBreakpoints;
  513. inherited Done;
  514. end;
  515. procedure TDebugController.Run;
  516. begin
  517. ResetBreakpointsValues;
  518. {$ifdef win32}
  519. { Run the debugge in another console }
  520. if DebuggeeTTY<>'' then
  521. Command('set new-console on')
  522. else
  523. Command('set new-console off');
  524. NoSwitch:=DebuggeeTTY<>'';
  525. {$endif win32}
  526. {$ifdef linux}
  527. { Run the debuggee in another tty }
  528. Command('set tty '+DebuggeeTTY);
  529. NoSwitch:=DebuggeeTTY<>'';
  530. {$endif win32}
  531. { Switch to user screen to get correct handles }
  532. UserScreen;
  533. inherited Run;
  534. DebuggerScreen;
  535. IDEApp.SetCmdState([cmResetDebugger,cmUntilReturn],true);
  536. UpdateDebugViews;
  537. end;
  538. function TDebugController.IsRunning : boolean;
  539. begin
  540. IsRunning:=debuggee_started;
  541. end;
  542. procedure TDebugController.Continue;
  543. begin
  544. {$ifdef NODEBUG}
  545. NoDebugger;
  546. {$else}
  547. if not debuggee_started then
  548. Run
  549. else
  550. inherited Continue;
  551. UpdateDebugViews;
  552. {$endif NODEBUG}
  553. end;
  554. procedure TDebugController.UntilReturn;
  555. begin
  556. Command('finish');
  557. UpdateDebugViews;
  558. { We could try to get the return value !
  559. Not done yet }
  560. end;
  561. procedure TDebugController.CommandBegin(const s:string);
  562. begin
  563. if assigned(GDBWindow) and (in_command>1) then
  564. begin
  565. { We should do something special for errors !! }
  566. If StrLen(GetError)>0 then
  567. GDBWindow^.WriteErrorText(GetError);
  568. GDBWindow^.WriteOutputText(GetOutput);
  569. end;
  570. if assigned(GDBWindow) then
  571. GDBWindow^.WriteString(S);
  572. end;
  573. procedure TDebugController.CommandEnd(const s:string);
  574. begin
  575. if assigned(GDBWindow) and (in_command=0) then
  576. begin
  577. { We should do something special for errors !! }
  578. If StrLen(GetError)>0 then
  579. GDBWindow^.WriteErrorText(GetError);
  580. GDBWindow^.WriteOutputText(GetOutput);
  581. GDBWindow^.Editor^.TextEnd;
  582. end;
  583. end;
  584. function TDebugController.AllowQuit : boolean;
  585. begin
  586. if ConfirmBox('Really quit editor?',nil,true)=cmOK then
  587. begin
  588. Message(@IDEApp,evCommand,cmQuit,nil);
  589. end
  590. else
  591. AllowQuit:=false;
  592. end;
  593. procedure TDebugController.ResetDebuggerRows;
  594. procedure ResetDebuggerRow(P: PView); {$ifndef FPC}far;{$endif}
  595. begin
  596. if assigned(P) and
  597. (TypeOf(P^)=TypeOf(TSourceWindow)) then
  598. PSourceWindow(P)^.Editor^.SetDebuggerRow(-1);
  599. end;
  600. begin
  601. Desktop^.ForEach(@ResetDebuggerRow);
  602. end;
  603. procedure TDebugController.Reset;
  604. begin
  605. inherited Reset;
  606. NoSwitch:=false;
  607. IDEApp.SetCmdState([cmResetDebugger,cmUntilReturn],false);
  608. ResetDebuggerRows;
  609. end;
  610. procedure TDebugController.AnnotateError;
  611. var errornb : longint;
  612. begin
  613. if error then
  614. begin
  615. errornb:=error_num;
  616. UpdateDebugViews;
  617. ErrorBox(#3'Error within GDB'#13#3'Error code = %d',@errornb);
  618. end;
  619. end;
  620. function TDebugController.GetValue(Const expr : string) : pchar;
  621. var
  622. p,p2,p3 : pchar;
  623. begin
  624. Command('p '+expr);
  625. p:=GetOutput;
  626. p3:=nil;
  627. if assigned(p) and (p[strlen(p)-1]=#10) then
  628. begin
  629. p3:=p+strlen(p)-1;
  630. p3^:=#0;
  631. end;
  632. if assigned(p) then
  633. p2:=strpos(p,'=')
  634. else
  635. p2:=nil;
  636. if assigned(p2) then
  637. p:=p2+1;
  638. while p^ in [' ',TAB] do
  639. inc(p);
  640. { get rid of type }
  641. if p^ = '(' then
  642. p:=strpos(p,')')+1;
  643. while p^ in [' ',TAB] do
  644. inc(p);
  645. if assigned(p) then
  646. GetValue:=StrNew(p)
  647. else
  648. GetValue:=StrNew(GetError);
  649. if assigned(p3) then
  650. p3^:=#10;
  651. got_error:=false;
  652. end;
  653. procedure TDebugController.DoSelectSourceLine(const fn:string;line:longint);
  654. var
  655. W: PSourceWindow;
  656. Found : boolean;
  657. PB : PBreakpoint;
  658. S : String;
  659. BreakIndex : longint;
  660. begin
  661. BreakIndex:=stop_breakpoint_number;
  662. Desktop^.Lock;
  663. { 0 based line count in Editor }
  664. if Line>0 then
  665. dec(Line);
  666. if (fn=LastFileName) then
  667. begin
  668. W:=PSourceWindow(LastSource);
  669. if assigned(W) then
  670. begin
  671. W^.Editor^.SetCurPtr(0,Line);
  672. W^.Editor^.TrackCursor(CenterDebuggerRow);
  673. W^.Editor^.SetDebuggerRow(Line);
  674. UpdateDebugViews;
  675. {if Not assigned(GDBWindow) or not GDBWindow^.GetState(sfActive) then
  676. handled by SelectInDebugSession}
  677. W^.SelectInDebugSession;
  678. InvalidSourceLine:=false;
  679. end
  680. else
  681. InvalidSourceLine:=true;
  682. end
  683. else
  684. begin
  685. if fn='' then
  686. W:=nil
  687. else
  688. W:=TryToOpenFile(nil,fn,0,Line,false);
  689. if assigned(W) then
  690. begin
  691. W^.Editor^.SetDebuggerRow(Line);
  692. W^.Editor^.TrackCursor(CenterDebuggerRow);
  693. UpdateDebugViews;
  694. {if Not assigned(GDBWindow) or not GDBWindow^.GetState(sfActive) then
  695. handled by SelectInDebugSession}
  696. W^.SelectInDebugSession;
  697. LastSource:=W;
  698. InvalidSourceLine:=false;
  699. end
  700. { only search a file once }
  701. else
  702. begin
  703. Desktop^.UnLock;
  704. if fn='' then
  705. Found:=false
  706. else
  707. Found:=IDEApp.OpenSearch(fn);
  708. Desktop^.Lock;
  709. if not Found then
  710. begin
  711. InvalidSourceLine:=true;
  712. LastSource:=Nil;
  713. { Show the stack in that case }
  714. InitStackWindow;
  715. UpdateDebugViews;
  716. StackWindow^.MakeFirst;
  717. end
  718. else
  719. begin
  720. { should now be open }
  721. W:=TryToOpenFile(nil,fn,0,Line,true);
  722. W^.Editor^.SetDebuggerRow(Line);
  723. W^.Editor^.TrackCursor(CenterDebuggerRow);
  724. UpdateDebugViews;
  725. {if Not assigned(GDBWindow) or not GDBWindow^.GetState(sfActive) then
  726. handled by SelectInDebugSession}
  727. W^.SelectInDebugSession;
  728. LastSource:=W;
  729. InvalidSourceLine:=false;
  730. end;
  731. end;
  732. end;
  733. LastFileName:=fn;
  734. Desktop^.UnLock;
  735. if BreakIndex>0 then
  736. begin
  737. PB:=BreakpointsCollection^.GetGDB(BreakIndex);
  738. { For watch we should get old and new value !! }
  739. if (Not assigned(GDBWindow) or not GDBWindow^.GetState(sfActive)) and
  740. (PB^.typ<>bt_file_line) and (PB^.typ<>bt_function) then
  741. begin
  742. Command('p '+GetStr(PB^.Name));
  743. S:=GetPChar(GetOutput);
  744. got_error:=false;
  745. If Pos('=',S)>0 then
  746. S:=Copy(S,Pos('=',S)+1,255);
  747. If S[Length(S)]=#10 then
  748. Delete(S,Length(S),1);
  749. if Assigned(PB^.OldValue) then
  750. DisposeStr(PB^.OldValue);
  751. PB^.OldValue:=PB^.CurrentValue;
  752. PB^.CurrentValue:=NewStr(S);
  753. If PB^.typ=bt_function then
  754. WarningBox(#3'GDB stopped due to'#13+
  755. #3+BreakpointTypeStr[PB^.typ]+' '+GetStr(PB^.Name),nil)
  756. else if (GetStr(PB^.OldValue)<>S) then
  757. WarningBox(#3'GDB stopped due to'#13+
  758. #3+BreakpointTypeStr[PB^.typ]+' '+GetStr(PB^.Name)+#13+
  759. #3+'Old value = '+GetStr(PB^.OldValue)+#13+
  760. #3+'New value = '+GetStr(PB^.CurrentValue),nil)
  761. else
  762. WarningBox(#3'GDB stopped due to'#13+
  763. #3+BreakpointTypeStr[PB^.typ]+' '+GetStr(PB^.Name)+#13+
  764. #3+' value = '+GetStr(PB^.CurrentValue),nil);
  765. end;
  766. end;
  767. end;
  768. procedure TDebugController.DoEndSession(code:longint);
  769. var P :Array[1..2] of longint;
  770. begin
  771. IDEApp.SetCmdState([cmResetDebugger],false);
  772. ResetDebuggerRows;
  773. LastExitCode:=Code;
  774. If HiddenStepsCount=0 then
  775. InformationBox(#3'Program exited with '#13#3'exitcode = %d',@code)
  776. else
  777. begin
  778. P[1]:=code;
  779. P[2]:=HiddenStepsCount;
  780. WarningBox(#3'Program exited with '#13+
  781. #3'exitcode = %d'#13+
  782. #3'hidden steps = %d',@P);
  783. end;
  784. end;
  785. procedure TDebugController.DoDebuggerScreen;
  786. begin
  787. if NoSwitch then
  788. begin
  789. PopStatus;
  790. end
  791. else
  792. begin
  793. IDEApp.ShowIDEScreen;
  794. Message(Application,evBroadcast,cmDebuggerStopped,pointer(RunCount));
  795. PopStatus;
  796. end;
  797. {$ifdef win32}
  798. ChangeDebuggeeWindowTitleTo(Stopped_State);
  799. {$endif win32}
  800. end;
  801. procedure TDebugController.DoUserScreen;
  802. begin
  803. Inc(RunCount);
  804. if NoSwitch then
  805. begin
  806. PushStatus('Executable running in another window..');
  807. end
  808. else
  809. begin
  810. PushStatus('Running...');
  811. IDEApp.ShowUserScreen;
  812. end;
  813. {$ifdef win32}
  814. ChangeDebuggeeWindowTitleTo(Running_State);
  815. {$endif win32}
  816. end;
  817. {****************************************************************************
  818. TBreakpoint
  819. ****************************************************************************}
  820. constructor TBreakpoint.Init_function(Const AFunc : String);
  821. begin
  822. typ:=bt_function;
  823. state:=bs_enabled;
  824. GDBState:=bs_deleted;
  825. Name:=NewStr(AFunc);
  826. FileName:=nil;
  827. Line:=0;
  828. IgnoreCount:=0;
  829. Commands:=nil;
  830. Conditions:=nil;
  831. OldValue:=nil;
  832. CurrentValue:=nil;
  833. end;
  834. constructor TBreakpoint.Init_Empty;
  835. begin
  836. typ:=bt_function;
  837. state:=bs_enabled;
  838. GDBState:=bs_deleted;
  839. Name:=Nil;
  840. FileName:=nil;
  841. Line:=0;
  842. IgnoreCount:=0;
  843. Commands:=nil;
  844. Conditions:=nil;
  845. OldValue:=nil;
  846. CurrentValue:=nil;
  847. end;
  848. constructor TBreakpoint.Init_type(atyp : BreakpointType;Const AnExpr : String);
  849. begin
  850. typ:=atyp;
  851. state:=bs_enabled;
  852. GDBState:=bs_deleted;
  853. Name:=NewStr(AnExpr);
  854. IgnoreCount:=0;
  855. Commands:=nil;
  856. Conditions:=nil;
  857. OldValue:=nil;
  858. CurrentValue:=nil;
  859. end;
  860. constructor TBreakpoint.Init_file_line(AFile : String; ALine : longint);
  861. begin
  862. typ:=bt_file_line;
  863. state:=bs_enabled;
  864. GDBState:=bs_deleted;
  865. { d:test.pas:12 does not work !! }
  866. { I do not know how to solve this if
  867. if (Length(AFile)>1) and (AFile[2]=':') then
  868. AFile:=Copy(AFile,3,255); }
  869. FileName:=NewStr(GDBFileName(AFile));
  870. Name:=nil;
  871. Line:=ALine;
  872. IgnoreCount:=0;
  873. Commands:=nil;
  874. Conditions:=nil;
  875. OldValue:=nil;
  876. CurrentValue:=nil;
  877. end;
  878. constructor TBreakpoint.Load(var S: TStream);
  879. var
  880. FName : PString;
  881. begin
  882. S.Read(typ,SizeOf(BreakpointType));
  883. S.Read(state,SizeOf(BreakpointState));
  884. GDBState:=bs_deleted;
  885. case typ of
  886. bt_file_line :
  887. begin
  888. { convert to current target }
  889. FName:=S.ReadStr;
  890. FileName:=NewStr(GDBFileName(GetStr(FName)));
  891. If Assigned(FName) then
  892. DisposeStr(FName);
  893. S.Read(Line,SizeOf(Line));
  894. Name:=nil;
  895. end;
  896. else
  897. begin
  898. Name:=S.ReadStr;
  899. Line:=0;
  900. FileName:=nil;
  901. end;
  902. end;
  903. S.Read(IgnoreCount,SizeOf(IgnoreCount));
  904. Commands:=S.StrRead;
  905. Conditions:=S.ReadStr;
  906. OldValue:=nil;
  907. CurrentValue:=nil;
  908. end;
  909. procedure TBreakpoint.Store(var S: TStream);
  910. begin
  911. S.Write(typ,SizeOf(BreakpointType));
  912. S.Write(state,SizeOf(BreakpointState));
  913. case typ of
  914. bt_file_line :
  915. begin
  916. S.WriteStr(FileName);
  917. S.Write(Line,SizeOf(Line));
  918. end;
  919. else
  920. begin
  921. S.WriteStr(Name);
  922. end;
  923. end;
  924. S.Write(IgnoreCount,SizeOf(IgnoreCount));
  925. S.StrWrite(Commands);
  926. S.WriteStr(Conditions);
  927. end;
  928. procedure TBreakpoint.Insert;
  929. begin
  930. If not assigned(Debugger) then Exit;
  931. Remove;
  932. Debugger^.last_breakpoint_number:=0;
  933. if (GDBState=bs_deleted) and (state=bs_enabled) then
  934. begin
  935. if (typ=bt_file_line) and assigned(FileName) then
  936. Debugger^.Command('break '+NameAndExtOf(FileName^)+':'+IntToStr(Line))
  937. else if (typ=bt_function) and assigned(name) then
  938. Debugger^.Command('break '+name^)
  939. else if (typ=bt_watch) and assigned(name) then
  940. Debugger^.Command('watch '+name^)
  941. else if (typ=bt_awatch) and assigned(name) then
  942. Debugger^.Command('awatch '+name^)
  943. else if (typ=bt_rwatch) and assigned(name) then
  944. Debugger^.Command('rwatch '+name^);
  945. if Debugger^.last_breakpoint_number<>0 then
  946. begin
  947. GDBIndex:=Debugger^.last_breakpoint_number;
  948. GDBState:=bs_enabled;
  949. Debugger^.Command('cond '+IntToStr(GDBIndex)+' '+GetStr(Conditions));
  950. If IgnoreCount>0 then
  951. Debugger^.Command('ignore '+IntToStr(GDBIndex)+' '+IntToStr(IgnoreCount));
  952. If Assigned(Commands) then
  953. begin
  954. {Commands are not handled yet }
  955. end;
  956. end
  957. else
  958. { Here there was a problem !! }
  959. begin
  960. GDBIndex:=0;
  961. if (typ=bt_file_line) and assigned(FileName) then
  962. ErrorBox(#3'Could not set Breakpoint'#13+
  963. #3+NameAndExtOf(FileName^)+':'+IntToStr(Line),nil)
  964. else
  965. ErrorBox(#3'Could not set Breakpoint'#13+
  966. #3+BreakpointTypeStr[typ]+' '+GetStr(Name),nil);
  967. state:=bs_disabled;
  968. end;
  969. end
  970. else if (GDBState=bs_disabled) and (state=bs_enabled) then
  971. Enable
  972. else if (GDBState=bs_enabled) and (state=bs_disabled) then
  973. Disable;
  974. end;
  975. procedure TBreakpoint.Remove;
  976. begin
  977. If not assigned(Debugger) then Exit;
  978. if GDBIndex>0 then
  979. Debugger^.Command('delete '+IntToStr(GDBIndex));
  980. GDBIndex:=0;
  981. GDBState:=bs_deleted;
  982. end;
  983. procedure TBreakpoint.Enable;
  984. begin
  985. If not assigned(Debugger) then Exit;
  986. if GDBIndex>0 then
  987. Debugger^.Command('enable '+IntToStr(GDBIndex))
  988. else
  989. Insert;
  990. GDBState:=bs_enabled;
  991. end;
  992. procedure TBreakpoint.Disable;
  993. begin
  994. If not assigned(Debugger) then Exit;
  995. if GDBIndex>0 then
  996. Debugger^.Command('disable '+IntToStr(GDBIndex));
  997. GDBState:=bs_disabled;
  998. end;
  999. procedure TBreakpoint.ResetValues;
  1000. begin
  1001. if assigned(OldValue) then
  1002. DisposeStr(OldValue);
  1003. OldValue:=nil;
  1004. if assigned(CurrentValue) then
  1005. DisposeStr(CurrentValue);
  1006. CurrentValue:=nil;
  1007. end;
  1008. procedure TBreakpoint.UpdateSource;
  1009. var W: PSourceWindow;
  1010. b : boolean;
  1011. begin
  1012. if typ=bt_file_line then
  1013. begin
  1014. W:=SearchOnDesktop(GetStr(FileName),false);
  1015. If assigned(W) then
  1016. begin
  1017. if state=bs_enabled then
  1018. b:=true
  1019. else
  1020. b:=false;
  1021. W^.Editor^.SetLineBreakState(Line,b);
  1022. end;
  1023. end;
  1024. end;
  1025. destructor TBreakpoint.Done;
  1026. begin
  1027. Remove;
  1028. ResetValues;
  1029. if assigned(Name) then
  1030. DisposeStr(Name);
  1031. if assigned(FileName) then
  1032. DisposeStr(FileName);
  1033. if assigned(Conditions) then
  1034. DisposeStr(Conditions);
  1035. if assigned(Commands) then
  1036. StrDispose(Commands);
  1037. inherited Done;
  1038. end;
  1039. {****************************************************************************
  1040. TBreakpointCollection
  1041. ****************************************************************************}
  1042. function TBreakpointCollection.At(Index: Integer): PBreakpoint;
  1043. begin
  1044. At:=inherited At(Index);
  1045. end;
  1046. procedure TBreakpointCollection.Update;
  1047. begin
  1048. if assigned(Debugger) then
  1049. begin
  1050. Debugger^.RemoveBreakpoints;
  1051. Debugger^.InsertBreakpoints;
  1052. end;
  1053. if assigned(BreakpointsWindow) then
  1054. BreakpointsWindow^.Update;
  1055. end;
  1056. function TBreakpointCollection.GetGDB(index : longint) : PBreakpoint;
  1057. function IsNum(P : PBreakpoint) : boolean;{$ifndef FPC}far;{$endif}
  1058. begin
  1059. IsNum:=P^.GDBIndex=index;
  1060. end;
  1061. begin
  1062. if index=0 then
  1063. GetGDB:=nil
  1064. else
  1065. GetGDB:=FirstThat(@IsNum);
  1066. end;
  1067. procedure TBreakpointCollection.ShowBreakpoints(W : PSourceWindow);
  1068. procedure SetInSource(P : PBreakpoint);{$ifndef FPC}far;{$endif}
  1069. begin
  1070. If assigned(P^.FileName) and
  1071. (GDBFileName(FExpand(P^.FileName^))=GDBFileName(FExpand(W^.Editor^.FileName))) then
  1072. W^.Editor^.SetLineBreakState(P^.Line,P^.state=bs_enabled);
  1073. end;
  1074. begin
  1075. ForEach(@SetInSource);
  1076. end;
  1077. procedure TBreakpointCollection.ShowAllBreakpoints;
  1078. procedure SetInSource(P : PBreakpoint);{$ifndef FPC}far;{$endif}
  1079. var
  1080. W : PSourceWindow;
  1081. begin
  1082. If assigned(P^.FileName) then
  1083. begin
  1084. W:=SearchOnDesktop(P^.FileName^,false);
  1085. if assigned(W) then
  1086. W^.Editor^.SetLineBreakState(P^.Line,P^.state=bs_enabled);
  1087. end;
  1088. end;
  1089. begin
  1090. ForEach(@SetInSource);
  1091. end;
  1092. function TBreakpointCollection.GetType(typ : BreakpointType;Const s : String) : PBreakpoint;
  1093. function IsThis(P : PBreakpoint) : boolean;{$ifndef FPC}far;{$endif}
  1094. begin
  1095. IsThis:=(P^.typ=typ) and (GetStr(P^.Name)=S);
  1096. end;
  1097. begin
  1098. GetType:=FirstThat(@IsThis);
  1099. end;
  1100. function TBreakpointCollection.ToggleFileLine(FileName: String;LineNr : Longint) : boolean;
  1101. var PB : PBreakpoint;
  1102. function IsThere(P : PBreakpoint) : boolean;{$ifndef FPC}far;{$endif}
  1103. begin
  1104. IsThere:=(P^.typ=bt_file_line) and (P^.FileName^=FileName) and (P^.Line=LineNr);
  1105. end;
  1106. begin
  1107. FileName:=GDBFileName(FileName);
  1108. PB:=FirstThat(@IsThere);
  1109. ToggleFileLine:=false;
  1110. If Assigned(PB) then
  1111. if PB^.state=bs_disabled then
  1112. begin
  1113. PB^.state:=bs_enabled;
  1114. ToggleFileLine:=true;
  1115. end
  1116. else if PB^.state=bs_enabled then
  1117. PB^.state:=bs_disabled;
  1118. If not assigned(PB) then
  1119. begin
  1120. PB:= New(PBreakpoint,Init_file_line(FileName,LineNr));
  1121. if assigned(PB) then
  1122. Begin
  1123. Insert(PB);
  1124. ToggleFileLine:=true;
  1125. End;
  1126. end;
  1127. if assigned(PB) then
  1128. PB^.UpdateSource;
  1129. Update;
  1130. end;
  1131. {****************************************************************************
  1132. TBreakpointItem
  1133. ****************************************************************************}
  1134. constructor TBreakpointItem.Init(ABreakpoint : PBreakpoint);
  1135. begin
  1136. inherited Init;
  1137. Breakpoint:=ABreakpoint;
  1138. end;
  1139. function TBreakpointItem.GetText(MaxLen: Sw_integer): string;
  1140. var S: string;
  1141. begin
  1142. with Breakpoint^ do
  1143. begin
  1144. S:=BreakpointTypeStr[typ];
  1145. While Length(S)<10 do
  1146. S:=S+' ';
  1147. S:=S+'|';
  1148. S:=S+BreakpointStateStr[state]+' ';
  1149. While Length(S)<20 do
  1150. S:=S+' ';
  1151. S:=S+'|';
  1152. if (typ=bt_file_line) then
  1153. S:=S+NameAndExtOf(GetStr(FileName))+':'+IntToStr(Line)
  1154. else
  1155. S:=S+GetStr(name);
  1156. While Length(S)<40 do
  1157. S:=S+' ';
  1158. S:=S+'|';
  1159. if IgnoreCount>0 then
  1160. S:=S+IntToStr(IgnoreCount);
  1161. While Length(S)<49 do
  1162. S:=S+' ';
  1163. S:=S+'|';
  1164. if assigned(Conditions) then
  1165. S:=S+' '+GetStr(Conditions);
  1166. if length(S)>MaxLen then S:=copy(S,1,MaxLen-2)+'..';
  1167. GetText:=S;
  1168. end;
  1169. end;
  1170. procedure TBreakpointItem.Selected;
  1171. begin
  1172. end;
  1173. function TBreakpointItem.GetModuleName: string;
  1174. begin
  1175. if breakpoint^.typ=bt_file_line then
  1176. GetModuleName:=GetStr(breakpoint^.FileName)
  1177. else
  1178. GetModuleName:='';
  1179. end;
  1180. {****************************************************************************
  1181. TBreakpointsListBox
  1182. ****************************************************************************}
  1183. constructor TBreakpointsListBox.Init(var Bounds: TRect; AHScrollBar, AVScrollBar: PScrollBar);
  1184. begin
  1185. inherited Init(Bounds,1,AHScrollBar, AVScrollBar);
  1186. GrowMode:=gfGrowLoX+gfGrowHiX+gfGrowHiY;
  1187. NoSelection:=true;
  1188. end;
  1189. function TBreakpointsListBox.GetLocalMenu: PMenu;
  1190. var M: PMenu;
  1191. begin
  1192. if (Owner<>nil) and (Owner^.GetState(sfModal)) then M:=nil else
  1193. M:=NewMenu(
  1194. NewItem('~G~oto source','',kbNoKey,cmMsgGotoSource,hcMsgGotoSource,
  1195. NewItem('~E~dit breakpoint','',kbNoKey,cmEditBreakpoint,hcEditBreakpoint,
  1196. NewItem('~N~ew breakpoint','',kbNoKey,cmNewBreakpoint,hcNewBreakpoint,
  1197. NewItem('~D~elete breakpoint','',kbNoKey,cmDeleteBreakpoint,hcDeleteBreakpoint,
  1198. NewItem('~T~oggle state','',kbNoKey,cmToggleBreakpoint,hcToggleBreakpoint,
  1199. nil))))));
  1200. GetLocalMenu:=M;
  1201. end;
  1202. procedure TBreakpointsListBox.HandleEvent(var Event: TEvent);
  1203. var DontClear: boolean;
  1204. begin
  1205. case Event.What of
  1206. evKeyDown :
  1207. begin
  1208. DontClear:=false;
  1209. case Event.KeyCode of
  1210. kbEnter :
  1211. Message(@Self,evCommand,cmMsgGotoSource,nil);
  1212. kbIns :
  1213. Message(@Self,evCommand,cmNewBreakpoint,nil);
  1214. kbDel :
  1215. Message(@Self,evCommand,cmDeleteBreakpoint,nil);
  1216. else
  1217. DontClear:=true;
  1218. end;
  1219. if not DontClear then
  1220. ClearEvent(Event);
  1221. end;
  1222. evBroadcast :
  1223. case Event.Command of
  1224. cmListItemSelected :
  1225. if Event.InfoPtr=@Self then
  1226. Message(@Self,evCommand,cmEditBreakpoint,nil);
  1227. end;
  1228. evCommand :
  1229. begin
  1230. DontClear:=false;
  1231. case Event.Command of
  1232. cmMsgTrackSource :
  1233. if Range>0 then
  1234. TrackSource;
  1235. cmEditBreakpoint :
  1236. EditCurrent;
  1237. cmToggleBreakpoint :
  1238. ToggleCurrent;
  1239. cmDeleteBreakpoint :
  1240. DeleteCurrent;
  1241. cmNewBreakpoint :
  1242. EditNew;
  1243. cmMsgClear :
  1244. Clear;
  1245. else
  1246. DontClear:=true;
  1247. end;
  1248. if not DontClear then
  1249. ClearEvent(Event);
  1250. end;
  1251. end;
  1252. inherited HandleEvent(Event);
  1253. end;
  1254. procedure TBreakpointsListBox.AddBreakpoint(P: PBreakpointItem);
  1255. var W : integer;
  1256. begin
  1257. if List=nil then New(List, Init(20,20));
  1258. W:=length(P^.GetText(255));
  1259. if W>MaxWidth then
  1260. begin
  1261. MaxWidth:=W;
  1262. if HScrollBar<>nil then
  1263. HScrollBar^.SetRange(0,MaxWidth);
  1264. end;
  1265. List^.Insert(P);
  1266. SetRange(List^.Count);
  1267. if Focused=List^.Count-1-1 then
  1268. FocusItem(List^.Count-1);
  1269. P^.Breakpoint^.UpdateSource;
  1270. DrawView;
  1271. end;
  1272. (* function TBreakpointsListBox.AddModuleName(const Name: string): PString;
  1273. var P: PString;
  1274. begin
  1275. if ModuleNames<>nil then
  1276. P:=ModuleNames^.Add(Name)
  1277. else
  1278. P:=nil;
  1279. AddModuleName:=P;
  1280. end; *)
  1281. function TBreakpointsListBox.GetText(Item,MaxLen: Sw_Integer): String;
  1282. var P: PBreakpointItem;
  1283. S: string;
  1284. begin
  1285. P:=List^.At(Item);
  1286. S:=P^.GetText(MaxLen);
  1287. GetText:=copy(S,1,MaxLen);
  1288. end;
  1289. procedure TBreakpointsListBox.Clear;
  1290. begin
  1291. if assigned(List) then
  1292. Dispose(List, Done);
  1293. List:=nil;
  1294. MaxWidth:=0;
  1295. (* if assigned(ModuleNames) then
  1296. ModuleNames^.FreeAll; *)
  1297. SetRange(0); DrawView;
  1298. Message(Application,evBroadcast,cmClearLineHighlights,@Self);
  1299. end;
  1300. procedure TBreakpointsListBox.TrackSource;
  1301. var W: PSourceWindow;
  1302. P: PBreakpointItem;
  1303. R: TRect;
  1304. (* Row,Col: sw_integer; *)
  1305. begin
  1306. (*Message(Application,evBroadcast,cmClearLineHighlights,@Self);
  1307. if Range=0 then Exit;*)
  1308. P:=List^.At(Focused);
  1309. if P^.GetModuleName='' then Exit;
  1310. Desktop^.Lock;
  1311. GetNextEditorBounds(R);
  1312. R.B.Y:=Owner^.Origin.Y;
  1313. W:=EditorWindowFile(P^.GetModuleName);
  1314. if assigned(W) then
  1315. begin
  1316. W^.GetExtent(R);
  1317. R.B.Y:=Owner^.Origin.Y;
  1318. W^.ChangeBounds(R);
  1319. W^.Editor^.SetCurPtr(1,P^.Breakpoint^.Line);
  1320. end
  1321. else
  1322. W:=TryToOpenFile(@R,P^.GetModuleName,1,P^.Breakpoint^.Line,true);
  1323. if W<>nil then
  1324. begin
  1325. W^.Select;
  1326. W^.Editor^.TrackCursor(true);
  1327. W^.Editor^.SetHighlightRow(P^.Breakpoint^.Line);
  1328. end;
  1329. if Assigned(Owner) then
  1330. Owner^.Select;
  1331. Desktop^.UnLock;
  1332. end;
  1333. procedure TBreakpointsListBox.ToggleCurrent;
  1334. var
  1335. P: PBreakpointItem;
  1336. begin
  1337. if Range=0 then Exit;
  1338. P:=List^.At(Focused);
  1339. if P=nil then Exit;
  1340. if P^.Breakpoint^.state=bs_enabled then
  1341. P^.Breakpoint^.state:=bs_disabled
  1342. else if P^.Breakpoint^.state=bs_disabled then
  1343. P^.Breakpoint^.state:=bs_enabled;
  1344. P^.Breakpoint^.UpdateSource;
  1345. BreakpointsCollection^.Update;
  1346. end;
  1347. procedure TBreakpointsListBox.EditCurrent;
  1348. var
  1349. P: PBreakpointItem;
  1350. begin
  1351. if Range=0 then Exit;
  1352. P:=List^.At(Focused);
  1353. if P=nil then Exit;
  1354. Application^.ExecuteDialog(New(PBreakpointItemDialog,Init(P^.Breakpoint)),nil);
  1355. P^.Breakpoint^.UpdateSource;
  1356. BreakpointsCollection^.Update;
  1357. end;
  1358. procedure TBreakpointsListBox.DeleteCurrent;
  1359. var
  1360. P: PBreakpointItem;
  1361. begin
  1362. if Range=0 then Exit;
  1363. P:=List^.At(Focused);
  1364. if P=nil then Exit;
  1365. { delete it form source window }
  1366. P^.Breakpoint^.state:=bs_disabled;
  1367. P^.Breakpoint^.UpdateSource;
  1368. BreakpointsCollection^.free(P^.Breakpoint);
  1369. List^.free(P);
  1370. BreakpointsCollection^.Update;
  1371. end;
  1372. procedure TBreakpointsListBox.EditNew;
  1373. var
  1374. P: PBreakpoint;
  1375. begin
  1376. P:=New(PBreakpoint,Init_Empty);
  1377. if Application^.ExecuteDialog(New(PBreakpointItemDialog,Init(P)),nil)<>cmCancel then
  1378. begin
  1379. P^.UpdateSource;
  1380. BreakpointsCollection^.Insert(P);
  1381. BreakpointsCollection^.Update;
  1382. end
  1383. else
  1384. dispose(P,Done);
  1385. end;
  1386. procedure TBreakpointsListBox.Draw;
  1387. var
  1388. I, J, Item: Sw_Integer;
  1389. NormalColor, SelectedColor, FocusedColor, Color: Word;
  1390. ColWidth, CurCol, Indent: Integer;
  1391. B: TDrawBuffer;
  1392. Text: String;
  1393. SCOff: Byte;
  1394. TC: byte;
  1395. procedure MT(var C: word); begin if TC<>0 then C:=(C and $ff0f) or (TC and $f0); end;
  1396. begin
  1397. if (Owner<>nil) then TC:=ord(Owner^.GetColor(6)) else TC:=0;
  1398. if State and (sfSelected + sfActive) = (sfSelected + sfActive) then
  1399. begin
  1400. NormalColor := GetColor(1);
  1401. FocusedColor := GetColor(3);
  1402. SelectedColor := GetColor(4);
  1403. end else
  1404. begin
  1405. NormalColor := GetColor(2);
  1406. SelectedColor := GetColor(4);
  1407. end;
  1408. if Transparent then
  1409. begin MT(NormalColor); MT(SelectedColor); end;
  1410. if NoSelection then
  1411. SelectedColor:=NormalColor;
  1412. if HScrollBar <> nil then Indent := HScrollBar^.Value
  1413. else Indent := 0;
  1414. ColWidth := Size.X div NumCols + 1;
  1415. for I := 0 to Size.Y - 1 do
  1416. begin
  1417. for J := 0 to NumCols-1 do
  1418. begin
  1419. Item := J*Size.Y + I + TopItem;
  1420. CurCol := J*ColWidth;
  1421. if (State and (sfSelected + sfActive) = (sfSelected + sfActive)) and
  1422. (Focused = Item) and (Range > 0) then
  1423. begin
  1424. Color := FocusedColor;
  1425. SetCursor(CurCol+1,I);
  1426. SCOff := 0;
  1427. end
  1428. else if (Item < Range) and IsSelected(Item) then
  1429. begin
  1430. Color := SelectedColor;
  1431. SCOff := 2;
  1432. end
  1433. else
  1434. begin
  1435. Color := NormalColor;
  1436. SCOff := 4;
  1437. end;
  1438. MoveChar(B[CurCol], ' ', Color, ColWidth);
  1439. if Item < Range then
  1440. begin
  1441. Text := GetText(Item, ColWidth + Indent);
  1442. Text := Copy(Text,Indent,ColWidth);
  1443. MoveStr(B[CurCol+1], Text, Color);
  1444. if ShowMarkers then
  1445. begin
  1446. WordRec(B[CurCol]).Lo := Byte(SpecialChars[SCOff]);
  1447. WordRec(B[CurCol+ColWidth-2]).Lo := Byte(SpecialChars[SCOff+1]);
  1448. end;
  1449. end;
  1450. MoveChar(B[CurCol+ColWidth-1], #179, GetColor(5), 1);
  1451. end;
  1452. WriteLine(0, I, Size.X, 1, B);
  1453. end;
  1454. end;
  1455. constructor TBreakpointsListBox.Load(var S: TStream);
  1456. begin
  1457. inherited Load(S);
  1458. end;
  1459. procedure TBreakpointsListBox.Store(var S: TStream);
  1460. var OL: PCollection;
  1461. OldR : integer;
  1462. begin
  1463. OL:=List;
  1464. OldR:=Range;
  1465. Range:=0;
  1466. New(List, Init(1,1));
  1467. inherited Store(S);
  1468. Dispose(List, Done);
  1469. Range:=OldR;
  1470. List:=OL;
  1471. { ^^^ nasty trick - has anyone a better idea how to avoid storing the
  1472. collection? Pasting here a modified version of TListBox.Store+
  1473. TAdvancedListBox.Store isn't a better solution, since by eventually
  1474. changing the obj-hierarchy you'll always have to modify this, too - BG }
  1475. end;
  1476. destructor TBreakpointsListBox.Done;
  1477. begin
  1478. inherited Done;
  1479. if List<>nil then Dispose(List, Done);
  1480. (* if ModuleNames<>nil then Dispose(ModuleNames, Done);*)
  1481. end;
  1482. {****************************************************************************
  1483. TBreakpointsWindow
  1484. ****************************************************************************}
  1485. constructor TBreakpointsWindow.Init;
  1486. var R,R2: TRect;
  1487. HSB,VSB: PScrollBar;
  1488. ST: PStaticText;
  1489. S: String;
  1490. X,X1 : Sw_integer;
  1491. const White = 15;
  1492. begin
  1493. Desktop^.GetExtent(R); R.A.Y:=R.B.Y-18;
  1494. inherited Init(R, 'Breakpoint list', wnNoNumber);
  1495. HelpCtx:=hcBreakpointListWindow;
  1496. GetExtent(R); R.Grow(-1,-1); R.B.Y:=R.A.Y+1;
  1497. S:=' Type | State | Position | Ignore | Conditions ';
  1498. New(ST, Init(R,S));
  1499. ST^.GrowMode:=gfGrowHiX;
  1500. Insert(ST);
  1501. GetExtent(R); R.Grow(-1,-1); Inc(R.A.Y,1); R.B.Y:=R.A.Y+1;
  1502. New(ST, Init(R, CharStr('Ä', MaxViewWidth)));
  1503. ST^.GrowMode:=gfGrowHiX;
  1504. Insert(ST);
  1505. GetExtent(R); R.Grow(-1,-1); Inc(R.A.Y,2);Dec(R.B.Y,5);
  1506. R2.Copy(R); Inc(R2.B.Y); R2.A.Y:=R2.B.Y-1;
  1507. New(HSB, Init(R2)); HSB^.GrowMode:=gfGrowLoY+gfGrowHiY+gfGrowHiX; Insert(HSB);
  1508. R2.Copy(R); Inc(R2.B.X); R2.A.X:=R2.B.X-1;
  1509. New(VSB, Init(R2)); VSB^.GrowMode:=gfGrowLoX+gfGrowHiX+gfGrowHiY; Insert(VSB);
  1510. New(BreakLB, Init(R,HSB,VSB));
  1511. BreakLB^.GrowMode:=gfGrowHiX+gfGrowHiY;
  1512. BreakLB^.Transparent:=true;
  1513. Insert(BreakLB);
  1514. GetExtent(R);R.Grow(-1,-1);
  1515. Dec(R.B.Y);
  1516. R.A.Y:=R.B.Y-2;
  1517. X:=(R.B.X-R.A.X) div 4;
  1518. X1:=R.A.X+(X div 2);
  1519. R.A.X:=X1-3;R.B.X:=X1+7;
  1520. Insert(New(PButton, Init(R, '~C~lose', cmClose, bfDefault)));
  1521. X1:=X1+X;
  1522. R.A.X:=X1-3;R.B.X:=X1+7;
  1523. Insert(New(PButton, Init(R, '~N~ew', cmNewBreakpoint, bfNormal)));
  1524. X1:=X1+X;
  1525. R.A.X:=X1-3;R.B.X:=X1+7;
  1526. Insert(New(PButton, Init(R, '~E~dit', cmEditBreakpoint, bfNormal)));
  1527. X1:=X1+X;
  1528. R.A.X:=X1-3;R.B.X:=X1+7;
  1529. Insert(New(PButton, Init(R, '~D~elete', cmDeleteBreakpoint, bfNormal)));
  1530. BreakLB^.Select;
  1531. Update;
  1532. BreakpointsWindow:=@self;
  1533. end;
  1534. constructor TBreakpointsWindow.Load(var S: TStream);
  1535. begin
  1536. inherited Load(S);
  1537. GetSubViewPtr(S,BreakLB);
  1538. end;
  1539. procedure TBreakpointsWindow.Store(var S: TStream);
  1540. begin
  1541. inherited Store(S);
  1542. PutSubViewPtr(S,BreakLB);
  1543. end;
  1544. procedure TBreakpointsWindow.AddBreakpoint(ABreakpoint : PBreakpoint);
  1545. begin
  1546. BreakLB^.AddBreakpoint(New(PBreakpointItem, Init(ABreakpoint)));
  1547. end;
  1548. procedure TBreakpointsWindow.ClearBreakpoints;
  1549. begin
  1550. BreakLB^.Clear;
  1551. ReDraw;
  1552. end;
  1553. procedure TBreakpointsWindow.ReloadBreakpoints;
  1554. procedure InsertInBreakLB(P : PBreakpoint);
  1555. begin
  1556. BreakLB^.AddBreakpoint(New(PBreakpointItem, Init(P)));
  1557. end;
  1558. begin
  1559. If not assigned(BreakpointsCollection) then
  1560. exit;
  1561. BreakpointsCollection^.ForEach(@InsertInBreakLB);
  1562. ReDraw;
  1563. end;
  1564. procedure TBreakpointsWindow.SizeLimits(var Min, Max: TPoint);
  1565. begin
  1566. inherited SizeLimits(Min,Max);
  1567. Min.X:=40; Min.Y:=18;
  1568. end;
  1569. procedure TBreakpointsWindow.Close;
  1570. begin
  1571. Hide;
  1572. end;
  1573. procedure TBreakpointsWindow.HandleEvent(var Event: TEvent);
  1574. var DontClear : boolean;
  1575. begin
  1576. case Event.What of
  1577. evKeyDown :
  1578. begin
  1579. if (Event.KeyCode=kbEnter) or (Event.KeyCode=kbEsc) then
  1580. begin
  1581. ClearEvent(Event);
  1582. Hide;
  1583. end;
  1584. end;
  1585. evCommand :
  1586. begin
  1587. DontClear:=False;
  1588. case Event.Command of
  1589. cmNewBreakpoint :
  1590. BreakLB^.EditNew;
  1591. cmEditBreakpoint :
  1592. BreakLB^.EditCurrent;
  1593. cmDeleteBreakpoint :
  1594. BreakLB^.DeleteCurrent;
  1595. cmClose :
  1596. Hide;
  1597. else
  1598. DontClear:=true;
  1599. end;
  1600. if not DontClear then
  1601. ClearEvent(Event);
  1602. end;
  1603. evBroadcast :
  1604. case Event.Command of
  1605. cmUpdate :
  1606. Update;
  1607. end;
  1608. end;
  1609. inherited HandleEvent(Event);
  1610. end;
  1611. procedure TBreakpointsWindow.Update;
  1612. begin
  1613. ClearBreakpoints;
  1614. ReloadBreakpoints;
  1615. end;
  1616. destructor TBreakpointsWindow.Done;
  1617. begin
  1618. inherited Done;
  1619. BreakpointsWindow:=nil;
  1620. end;
  1621. {****************************************************************************
  1622. TBreakpointItemDialog
  1623. ****************************************************************************}
  1624. constructor TBreakpointItemDialog.Init(ABreakpoint: PBreakpoint);
  1625. var R,R2,R3: TRect;
  1626. Items: PSItem;
  1627. I : BreakpointType;
  1628. KeyCount: sw_integer;
  1629. begin
  1630. KeyCount:=longint(high(BreakpointType));
  1631. R.Assign(0,0,60,Max(3+KeyCount,18));
  1632. inherited Init(R,'Modify/New Breakpoint');
  1633. Breakpoint:=ABreakpoint;
  1634. GetExtent(R); R.Grow(-3,-2); R3.Copy(R);
  1635. Inc(R.A.Y); R.B.Y:=R.A.Y+1; R.B.X:=R.A.X+36;
  1636. New(NameIL, Init(R, 128)); Insert(NameIL);
  1637. R2.Copy(R); R2.Move(-1,-1); Insert(New(PLabel, Init(R2, '~N~ame', NameIL)));
  1638. R.Move(0,3);
  1639. New(LineIL, Init(R, 128)); Insert(LineIL);
  1640. LineIL^.SetValidator(New(PRangeValidator, Init(0,MaxInt)));
  1641. R2.Copy(R); R2.Move(-1,-1); Insert(New(PLabel, Init(R2, '~L~ine', LineIL)));
  1642. R.Move(0,3);
  1643. New(ConditionsIL, Init(R, 128)); Insert(ConditionsIL);
  1644. R2.Copy(R); R2.Move(-1,-1); Insert(New(PLabel, Init(R2, 'Conditions', ConditionsIL)));
  1645. R.Move(0,3);
  1646. New(IgnoreIL, Init(R, 128)); Insert(IgnoreIL);
  1647. IgnoreIL^.SetValidator(New(PRangeValidator, Init(0,MaxInt)));
  1648. R2.Copy(R); R2.Move(-1,-1); Insert(New(PLabel, Init(R2, '~I~gnore count', IgnoreIL)));
  1649. R.Copy(R3); Inc(R.A.X,38); R.B.Y:=R.A.Y+KeyCount;
  1650. Items:=nil;
  1651. for I:=high(BreakpointType) downto low(BreakpointType) do
  1652. Items:=NewSItem(BreakpointTypeStr[I], Items);
  1653. New(TypeRB, Init(R, Items));
  1654. Insert(TypeRB);
  1655. InsertButtons(@Self);
  1656. NameIL^.Select;
  1657. end;
  1658. function TBreakpointItemDialog.Execute: Word;
  1659. var R: word;
  1660. S1: string;
  1661. err: word;
  1662. L: longint;
  1663. begin
  1664. R:=longint(Breakpoint^.typ);
  1665. TypeRB^.SetData(R);
  1666. If Breakpoint^.typ=bt_file_line then
  1667. S1:=GetStr(Breakpoint^.FileName)
  1668. else
  1669. S1:=GetStr(Breakpoint^.name);
  1670. NameIL^.SetData(S1);
  1671. If Breakpoint^.typ=bt_file_line then
  1672. S1:=IntToStr(Breakpoint^.Line)
  1673. else
  1674. S1:='0';
  1675. LineIL^.SetData(S1);
  1676. S1:=IntToStr(Breakpoint^.IgnoreCount);
  1677. IgnoreIL^.SetData(S1);
  1678. S1:=GetStr(Breakpoint^.Conditions);
  1679. ConditionsIL^.SetData(S1);
  1680. R:=inherited Execute;
  1681. if R=cmOK then
  1682. begin
  1683. TypeRB^.GetData(R);
  1684. L:=R;
  1685. Breakpoint^.typ:=BreakpointType(L);
  1686. NameIL^.GetData(S1);
  1687. If Breakpoint^.typ=bt_file_line then
  1688. begin
  1689. If assigned(Breakpoint^.FileName) then
  1690. DisposeStr(Breakpoint^.FileName);
  1691. Breakpoint^.FileName:=NewStr(S1);
  1692. end
  1693. else
  1694. begin
  1695. If assigned(Breakpoint^.Name) then
  1696. DisposeStr(Breakpoint^.Name);
  1697. Breakpoint^.name:=NewStr(S1);
  1698. end;
  1699. If Breakpoint^.typ=bt_file_line then
  1700. begin
  1701. LineIL^.GetData(S1);
  1702. Val(S1,L,err);
  1703. Breakpoint^.Line:=L;
  1704. end;
  1705. IgnoreIL^.GetData(S1);
  1706. Val(S1,L,err);
  1707. Breakpoint^.IgnoreCount:=L;
  1708. ConditionsIL^.GetData(S1);
  1709. If assigned(Breakpoint^.Conditions) then
  1710. DisposeStr(Breakpoint^.Conditions);
  1711. Breakpoint^.Conditions:=NewStr(S1);
  1712. end;
  1713. Execute:=R;
  1714. end;
  1715. {****************************************************************************
  1716. TWatch
  1717. ****************************************************************************}
  1718. constructor TWatch.Init(s : string);
  1719. begin
  1720. expr:=NewStr(s);
  1721. last_value:=nil;
  1722. current_value:=nil;
  1723. Get_new_value;
  1724. end;
  1725. constructor TWatch.Load(var S: TStream);
  1726. begin
  1727. expr:=S.ReadStr;
  1728. last_value:=nil;
  1729. current_value:=nil;
  1730. Get_new_value;
  1731. end;
  1732. procedure TWatch.Store(var S: TStream);
  1733. begin
  1734. S.WriteStr(expr);
  1735. end;
  1736. procedure TWatch.rename(s : string);
  1737. begin
  1738. if assigned(expr) then
  1739. begin
  1740. if GetStr(expr)=S then
  1741. exit;
  1742. DisposeStr(expr);
  1743. end;
  1744. expr:=NewStr(s);
  1745. if assigned(last_value) then
  1746. StrDispose(last_value);
  1747. last_value:=nil;
  1748. if assigned(current_value) then
  1749. StrDispose(current_value);
  1750. current_value:=nil;
  1751. Get_new_value;
  1752. end;
  1753. procedure TWatch.Get_new_value;
  1754. var p, q : pchar;
  1755. i, j, curframe, startframe : longint;
  1756. error : integer;
  1757. c : char;
  1758. s,s2 : string;
  1759. loop_higher, found, last_removed : boolean;
  1760. function GetValue(var s : string) : boolean;
  1761. begin
  1762. Debugger^.command('p '+s);
  1763. if not Debugger^.Error then
  1764. begin
  1765. s:=StrPas(Debugger^.GetOutput);
  1766. GetValue:=true;
  1767. end
  1768. else
  1769. begin
  1770. s:=StrPas(Debugger^.GetError);
  1771. GetValue:=false;
  1772. { do not open a messagebox for such errors }
  1773. Debugger^.got_error:=false;
  1774. end;
  1775. end;
  1776. begin
  1777. If not assigned(Debugger) then
  1778. exit;
  1779. if assigned(last_value) then
  1780. strdispose(last_value);
  1781. last_value:=current_value;
  1782. s:=GetStr(expr);
  1783. found:=GetValue(s);
  1784. Debugger^.got_error:=false;
  1785. loop_higher:=not found;
  1786. curframe:=Debugger^.get_current_frame;
  1787. startframe:=curframe;
  1788. while loop_higher do
  1789. begin
  1790. s:='parent_ebp';
  1791. if GetValue(s) then
  1792. begin
  1793. repeat
  1794. inc(curframe);
  1795. if not Debugger^.set_current_frame(curframe) then
  1796. loop_higher:=false;
  1797. s2:='/x $ebp';
  1798. getValue(s2);
  1799. j:=pos('=',s2);
  1800. if j>0 then
  1801. s2:=copy(s2,j+1,length(s2));
  1802. while s2[1] in [' ',TAB] do
  1803. delete(s2,1,1);
  1804. if pos(s2,s)>0 then
  1805. loop_higher :=false;
  1806. until not loop_higher;
  1807. { try again at that level }
  1808. s:=GetStr(expr);
  1809. loop_higher:=not GetValue(s);
  1810. end
  1811. else
  1812. loop_higher:=false;
  1813. end;
  1814. s:=GetStr(expr);
  1815. if GetValue(s) then
  1816. p:=StrNew(Debugger^.GetOutput)
  1817. else
  1818. p:=StrNew(Debugger^.GetError);
  1819. Debugger^.got_error:=false;
  1820. { We should try here to find the expr in parent
  1821. procedure if there are
  1822. I will implement this as I added a
  1823. parent_ebp pseudo local var to local procedure
  1824. in stabs debug info PM }
  1825. { But there are some pitfalls like
  1826. locals redefined in other sublocals that call the function }
  1827. Debugger^.set_current_frame(startframe);
  1828. q:=nil;
  1829. if assigned(p) and (p[0]='$') then
  1830. q:=StrPos(p,'=');
  1831. if not assigned(q) then
  1832. q:=p;
  1833. if assigned(q) then
  1834. i:=strlen(q)
  1835. else
  1836. i:=0;
  1837. if (i>0) and (q[i-1]=#10) then
  1838. begin
  1839. q[i-1]:=#0;
  1840. last_removed:=true;
  1841. end
  1842. else
  1843. last_removed:=false;
  1844. if assigned(q) then
  1845. current_value:=strnew(q)
  1846. else
  1847. current_value:=strnew('');
  1848. if last_removed then
  1849. q[i-1]:=#10;
  1850. strdispose(p);
  1851. end;
  1852. destructor TWatch.Done;
  1853. begin
  1854. if assigned(expr) then
  1855. disposestr(expr);
  1856. if assigned(last_value) then
  1857. strdispose(last_value);
  1858. if assigned(current_value) then
  1859. strdispose(current_value);
  1860. inherited done;
  1861. end;
  1862. {****************************************************************************
  1863. TWatchesCollection
  1864. ****************************************************************************}
  1865. constructor TWatchesCollection.Init;
  1866. begin
  1867. inherited Init(10,10);
  1868. end;
  1869. procedure TWatchesCollection.Insert(Item: Pointer);
  1870. begin
  1871. PWatch(Item)^.Get_new_value;
  1872. Inherited Insert(Item);
  1873. Update;
  1874. end;
  1875. procedure TWatchesCollection.Update;
  1876. var
  1877. W,W1 : integer;
  1878. procedure GetMax(P : PWatch);
  1879. begin
  1880. if assigned(P^.Current_value) then
  1881. begin
  1882. W1:=StrLen(P^.Current_value)+2+Length(GetStr(P^.expr));
  1883. if W1>W then
  1884. W:=W1;
  1885. end;
  1886. end;
  1887. begin
  1888. W:=0;
  1889. ForEach(@GetMax);
  1890. MaxW:=W;
  1891. If assigned(WatchesWindow) then
  1892. WatchesWindow^.WLB^.Update(MaxW);
  1893. end;
  1894. function TWatchesCollection.At(Index: Integer): PWatch;
  1895. begin
  1896. At:=Inherited At(Index);
  1897. end;
  1898. {****************************************************************************
  1899. TWatchesListBox
  1900. ****************************************************************************}
  1901. constructor TWatchesListBox.Init(var Bounds: TRect; AHScrollBar, AVScrollBar: PScrollBar);
  1902. begin
  1903. inherited Init(Bounds,1,AHScrollBar,AVScrollBar);
  1904. If assigned(List) then
  1905. dispose(list,done);
  1906. List:=WatchesCollection;
  1907. end;
  1908. procedure TWatchesListBox.Update(AMaxWidth : integer);
  1909. var R : TRect;
  1910. begin
  1911. GetExtent(R);
  1912. MaxWidth:=AMaxWidth;
  1913. if HScrollBar<>nil then
  1914. HScrollBar^.SetRange(0,MaxWidth);
  1915. if R.B.X-R.A.X>MaxWidth then
  1916. HScrollBar^.Hide
  1917. else
  1918. HScrollBar^.Show;
  1919. SetRange(List^.Count);
  1920. if R.B.Y-R.A.Y>Range then
  1921. VScrollBar^.Hide
  1922. else
  1923. VScrollBar^.Show;
  1924. if Focused=List^.Count-1-1 then
  1925. FocusItem(List^.Count-1);
  1926. DrawView;
  1927. end;
  1928. function TWatchesListBox.GetIndentedText(Item,Indent,MaxLen: Sw_Integer): String;
  1929. var
  1930. PW : PWatch;
  1931. ValOffset : Sw_integer;
  1932. S : String;
  1933. begin
  1934. PW:=WatchesCollection^.At(Item);
  1935. ValOffset:=Length(GetStr(PW^.Expr))+2;
  1936. if Indent<ValOffset then
  1937. begin
  1938. if not assigned(PW^.current_value) then
  1939. S:=' '+GetStr(PW^.Expr)+' <Unknown value>'
  1940. else if not assigned(PW^.last_value) or
  1941. (strcomp(PW^.Last_value,PW^.Current_value)=0) then
  1942. S:=' '+GetStr(PW^.Expr)+' '+GetPChar(PW^.Current_value)
  1943. else
  1944. S:='!'+GetStr(PW^.Expr)+'!'+GetPchar(PW^.Current_value);
  1945. GetIndentedText:=Copy(S,Indent,MaxLen);
  1946. end
  1947. else
  1948. begin
  1949. if not assigned(PW^.Current_value) or
  1950. (StrLen(PW^.Current_value)<Indent-Valoffset) then
  1951. S:=''
  1952. else
  1953. S:=GetStr(@(PW^.Current_Value[Indent-Valoffset]));
  1954. GetIndentedText:=Copy(S,1,MaxLen);
  1955. end;
  1956. end;
  1957. procedure TWatchesListBox.EditCurrent;
  1958. var
  1959. P: PWatch;
  1960. begin
  1961. if Range=0 then Exit;
  1962. P:=WatchesCollection^.At(Focused);
  1963. if P=nil then Exit;
  1964. Application^.ExecuteDialog(New(PWatchItemDialog,Init(P)),nil);
  1965. WatchesCollection^.Update;
  1966. end;
  1967. procedure TWatchesListBox.DeleteCurrent;
  1968. var
  1969. P: PWatch;
  1970. begin
  1971. if Range=0 then Exit;
  1972. P:=WatchesCollection^.At(Focused);
  1973. if P=nil then Exit;
  1974. WatchesCollection^.free(P);
  1975. WatchesCollection^.Update;
  1976. end;
  1977. procedure TWatchesListBox.EditNew;
  1978. var
  1979. P: PWatch;
  1980. begin
  1981. P:=New(PWatch,Init(''));
  1982. if Application^.ExecuteDialog(New(PWatchItemDialog,Init(P)),nil)<>cmCancel then
  1983. begin
  1984. WatchesCollection^.Insert(P);
  1985. WatchesCollection^.Update;
  1986. end
  1987. else
  1988. dispose(P,Done);
  1989. end;
  1990. procedure TWatchesListBox.Draw;
  1991. var
  1992. I, J, Item: Sw_Integer;
  1993. NormalColor, SelectedColor, FocusedColor, Color: Word;
  1994. ColWidth, CurCol, Indent: Integer;
  1995. B: TDrawBuffer;
  1996. Text: String;
  1997. SCOff: Byte;
  1998. TC: byte;
  1999. procedure MT(var C: word); begin if TC<>0 then C:=(C and $ff0f) or (TC and $f0); end;
  2000. begin
  2001. if (Owner<>nil) then TC:=ord(Owner^.GetColor(6)) else TC:=0;
  2002. if State and (sfSelected + sfActive) = (sfSelected + sfActive) then
  2003. begin
  2004. NormalColor := GetColor(1);
  2005. FocusedColor := GetColor(3);
  2006. SelectedColor := GetColor(4);
  2007. end else
  2008. begin
  2009. NormalColor := GetColor(2);
  2010. SelectedColor := GetColor(4);
  2011. end;
  2012. if Transparent then
  2013. begin MT(NormalColor); MT(SelectedColor); end;
  2014. (* if NoSelection then
  2015. SelectedColor:=NormalColor;*)
  2016. if HScrollBar <> nil then Indent := HScrollBar^.Value
  2017. else Indent := 0;
  2018. ColWidth := Size.X div NumCols + 1;
  2019. for I := 0 to Size.Y - 1 do
  2020. begin
  2021. for J := 0 to NumCols-1 do
  2022. begin
  2023. Item := J*Size.Y + I + TopItem;
  2024. CurCol := J*ColWidth;
  2025. if (State and (sfSelected + sfActive) = (sfSelected + sfActive)) and
  2026. (Focused = Item) and (Range > 0) then
  2027. begin
  2028. Color := FocusedColor;
  2029. SetCursor(CurCol+1,I);
  2030. SCOff := 0;
  2031. end
  2032. else if (Item < Range) and IsSelected(Item) then
  2033. begin
  2034. Color := SelectedColor;
  2035. SCOff := 2;
  2036. end
  2037. else
  2038. begin
  2039. Color := NormalColor;
  2040. SCOff := 4;
  2041. end;
  2042. MoveChar(B[CurCol], ' ', Color, ColWidth);
  2043. if Item < Range then
  2044. begin
  2045. (* Text := GetText(Item, ColWidth + Indent);
  2046. Text := Copy(Text,Indent,ColWidth); *)
  2047. Text:=GetIndentedText(Item,Indent,ColWidth);
  2048. MoveStr(B[CurCol+1], Text, Color);
  2049. if ShowMarkers then
  2050. begin
  2051. WordRec(B[CurCol]).Lo := Byte(SpecialChars[SCOff]);
  2052. WordRec(B[CurCol+ColWidth-2]).Lo := Byte(SpecialChars[SCOff+1]);
  2053. end;
  2054. end;
  2055. MoveChar(B[CurCol+ColWidth-1], #179, GetColor(5), 1);
  2056. end;
  2057. WriteLine(0, I, Size.X, 1, B);
  2058. end;
  2059. end;
  2060. function TWatchesListBox.GetLocalMenu: PMenu;
  2061. var M: PMenu;
  2062. begin
  2063. if (Owner<>nil) and (Owner^.GetState(sfModal)) then M:=nil else
  2064. M:=NewMenu(
  2065. NewItem('~E~dit watch','',kbNoKey,cmEdit,hcNoContext,
  2066. NewItem('~N~ew watch','',kbNoKey,cmNew,hcNoContext,
  2067. NewItem('~D~elete watch','',kbNoKey,cmDelete,hcNoContext,
  2068. nil))));
  2069. GetLocalMenu:=M;
  2070. end;
  2071. procedure TWatchesListBox.HandleEvent(var Event: TEvent);
  2072. var DontClear: boolean;
  2073. begin
  2074. case Event.What of
  2075. evKeyDown :
  2076. begin
  2077. DontClear:=false;
  2078. case Event.KeyCode of
  2079. kbEnter :
  2080. Message(@Self,evCommand,cmEdit,nil);
  2081. kbIns :
  2082. Message(@Self,evCommand,cmNew,nil);
  2083. kbDel :
  2084. Message(@Self,evCommand,cmDelete,nil);
  2085. else
  2086. DontClear:=true;
  2087. end;
  2088. if not DontClear then
  2089. ClearEvent(Event);
  2090. end;
  2091. evBroadcast :
  2092. case Event.Command of
  2093. cmListItemSelected :
  2094. if Event.InfoPtr=@Self then
  2095. Message(@Self,evCommand,cmEdit,nil);
  2096. end;
  2097. evCommand :
  2098. begin
  2099. DontClear:=false;
  2100. case Event.Command of
  2101. cmEdit :
  2102. EditCurrent;
  2103. cmDelete :
  2104. DeleteCurrent;
  2105. cmNew :
  2106. EditNew;
  2107. else
  2108. DontClear:=true;
  2109. end;
  2110. if not DontClear then
  2111. ClearEvent(Event);
  2112. end;
  2113. end;
  2114. inherited HandleEvent(Event);
  2115. end;
  2116. constructor TWatchesListBox.Load(var S: TStream);
  2117. begin
  2118. inherited Load(S);
  2119. If assigned(List) then
  2120. dispose(list,done);
  2121. List:=WatchesCollection;
  2122. { we must set Range PM }
  2123. SetRange(List^.count);
  2124. end;
  2125. procedure TWatchesListBox.Store(var S: TStream);
  2126. var OL: PCollection;
  2127. OldRange : Sw_integer;
  2128. begin
  2129. OL:=List;
  2130. OldRange:=Range;
  2131. Range:=0;
  2132. New(List, Init(1,1));
  2133. inherited Store(S);
  2134. Dispose(List, Done);
  2135. List:=OL;
  2136. { ^^^ nasty trick - has anyone a better idea how to avoid storing the
  2137. collection? Pasting here a modified version of TListBox.Store+
  2138. TAdvancedListBox.Store isn't a better solution, since by eventually
  2139. changing the obj-hierarchy you'll always have to modify this, too - BG }
  2140. SetRange(OldRange);
  2141. end;
  2142. destructor TWatchesListBox.Done;
  2143. begin
  2144. List:=nil;
  2145. inherited Done;
  2146. end;
  2147. {****************************************************************************
  2148. TWatchesWindow
  2149. ****************************************************************************}
  2150. Constructor TWatchesWindow.Init;
  2151. var
  2152. HSB,VSB: PScrollBar;
  2153. R,R2 : trect;
  2154. begin
  2155. Desktop^.GetExtent(R);
  2156. R.A.Y:=R.B.Y-5;
  2157. inherited Init(R, 'Watches', wnNoNumber);
  2158. Palette:=wpCyanWindow;
  2159. GetExtent(R);
  2160. HelpCtx:=hcWatches;
  2161. R.Grow(-1,-1);
  2162. R2.Copy(R);
  2163. Inc(R2.B.Y);
  2164. R2.A.Y:=R2.B.Y-1;
  2165. New(HSB, Init(R2));
  2166. HSB^.GrowMode:=gfGrowLoY+gfGrowHiY+gfGrowHiX;
  2167. Insert(HSB);
  2168. R2.Copy(R);
  2169. Inc(R2.B.X);
  2170. R2.A.X:=R2.B.X-1;
  2171. New(VSB, Init(R2));
  2172. VSB^.GrowMode:=gfGrowLoX+gfGrowHiX+gfGrowHiY;
  2173. Insert(VSB);
  2174. New(WLB,Init(R,HSB,VSB));
  2175. WLB^.GrowMode:=gfGrowHiX+gfGrowHiY;
  2176. WLB^.Transparent:=true;
  2177. Insert(WLB);
  2178. If assigned(WatchesWindow) then
  2179. dispose(WatchesWindow,done);
  2180. WatchesWindow:=@Self;
  2181. Update;
  2182. end;
  2183. procedure TWatchesWindow.Update;
  2184. begin
  2185. WatchesCollection^.Update;
  2186. Draw;
  2187. end;
  2188. constructor TWatchesWindow.Load(var S: TStream);
  2189. begin
  2190. inherited Load(S);
  2191. GetSubViewPtr(S,WLB);
  2192. If assigned(WatchesWindow) then
  2193. dispose(WatchesWindow,done);
  2194. WatchesWindow:=@Self;
  2195. end;
  2196. procedure TWatchesWindow.Store(var S: TStream);
  2197. begin
  2198. inherited Store(S);
  2199. PutSubViewPtr(S,WLB);
  2200. end;
  2201. Destructor TWatchesWindow.Done;
  2202. begin
  2203. WatchesWindow:=nil;
  2204. Dispose(WLB,done);
  2205. inherited done;
  2206. end;
  2207. {****************************************************************************
  2208. TWatchItemDialog
  2209. ****************************************************************************}
  2210. constructor TWatchItemDialog.Init(AWatch: PWatch);
  2211. var R,R2: TRect;
  2212. begin
  2213. R.Assign(0,0,50,10);
  2214. inherited Init(R,'Edit Watch');
  2215. Watch:=AWatch;
  2216. GetExtent(R); R.Grow(-3,-2);
  2217. Inc(R.A.Y); R.B.Y:=R.A.Y+1; R.B.X:=R.A.X+36;
  2218. New(NameIL, Init(R, 255)); Insert(NameIL);
  2219. R2.Copy(R); R2.Move(-1,-1);
  2220. Insert(New(PLabel, Init(R2, '~E~xpression to watch', NameIL)));
  2221. GetExtent(R);
  2222. R.Grow(-1,-1);
  2223. R.A.Y:=R.A.Y+3;
  2224. R.B.X:=R.A.X+36;
  2225. TextST:=New(PAdvancedStaticText, Init(R, 'Watch values'));
  2226. Insert(TextST);
  2227. InsertButtons(@Self);
  2228. NameIL^.Select;
  2229. end;
  2230. function TWatchItemDialog.Execute: Word;
  2231. var R: word;
  2232. S1,S2: string;
  2233. begin
  2234. S1:=GetStr(Watch^.expr);
  2235. NameIL^.SetData(S1);
  2236. if assigned(Watch^.Current_value) then
  2237. S1:=GetPChar(Watch^.Current_value)
  2238. else
  2239. S1:='';
  2240. if assigned(Watch^.Last_value) then
  2241. S2:=GetPChar(Watch^.Last_value)
  2242. else
  2243. S2:='';
  2244. if assigned(Watch^.Last_value) and
  2245. assigned(Watch^.Current_value) and
  2246. (strcomp(Watch^.Last_value,Watch^.Current_value)=0) then
  2247. S1:='Current value: '+#13+S1
  2248. else
  2249. S1:='Current value: '+#13+S1+#13+
  2250. 'Previous value: '+#13+S2;
  2251. TextST^.SetText(S1);
  2252. R:=inherited Execute;
  2253. if R=cmOK then
  2254. begin
  2255. NameIL^.GetData(S1);
  2256. Watch^.Rename(S1);
  2257. If assigned(Debugger) then
  2258. Debugger^.ReadWatches;
  2259. end;
  2260. Execute:=R;
  2261. end;
  2262. {****************************************************************************
  2263. TRegistersView
  2264. ****************************************************************************}
  2265. function GetIntRegs(var rs : TIntRegs) : boolean;
  2266. var
  2267. p,po : pchar;
  2268. p1 : pchar;
  2269. reg,value : string;
  2270. buffer : array[0..255] of char;
  2271. v : dword;
  2272. code : word;
  2273. begin
  2274. GetIntRegs:=false;
  2275. {$ifndef NODEBUG}
  2276. Debugger^.Command('info registers');
  2277. if Debugger^.Error then
  2278. exit
  2279. else
  2280. begin
  2281. po:=StrNew(Debugger^.GetOutput);
  2282. p:=po;
  2283. if assigned(p) then
  2284. begin
  2285. fillchar(rs,sizeof(rs),0);
  2286. p1:=strscan(p,' ');
  2287. while assigned(p1) do
  2288. begin
  2289. strlcopy(buffer,p,p1-p);
  2290. reg:=strpas(buffer);
  2291. p:=strscan(p,'$');
  2292. p1:=strscan(p,#9);
  2293. strlcopy(buffer,p,p1-p);
  2294. value:=strpas(buffer);
  2295. val(value,v,code);
  2296. if reg='eax' then
  2297. rs.eax:=v
  2298. else if reg='ebx' then
  2299. rs.ebx:=v
  2300. else if reg='ecx' then
  2301. rs.ecx:=v
  2302. else if reg='edx' then
  2303. rs.edx:=v
  2304. else if reg='eip' then
  2305. rs.eip:=v
  2306. else if reg='esi' then
  2307. rs.esi:=v
  2308. else if reg='edi' then
  2309. rs.edi:=v
  2310. else if reg='esp' then
  2311. rs.esp:=v
  2312. else if reg='ebp' then
  2313. rs.ebp:=v
  2314. { under win32 flags are on a register named ps !! PM }
  2315. else if (reg='eflags') or (reg='ps') then
  2316. rs.eflags:=v
  2317. else if reg='cs' then
  2318. rs.cs:=v
  2319. else if reg='ds' then
  2320. rs.ds:=v
  2321. else if reg='es' then
  2322. rs.es:=v
  2323. else if reg='fs' then
  2324. rs.fs:=v
  2325. else if reg='gs' then
  2326. rs.gs:=v
  2327. else if reg='ss' then
  2328. rs.ss:=v;
  2329. p:=strscan(p1,#10);
  2330. if assigned(p) then
  2331. begin
  2332. p1:=strscan(p,' ');
  2333. inc(p);
  2334. end
  2335. else
  2336. break;
  2337. end;
  2338. { free allocated memory }
  2339. strdispose(po);
  2340. end
  2341. else
  2342. exit;
  2343. end;
  2344. { do not open a messagebox for such errors }
  2345. Debugger^.got_error:=false;
  2346. GetIntRegs:=true;
  2347. {$endif}
  2348. end;
  2349. constructor TRegistersView.Init(var Bounds: TRect);
  2350. begin
  2351. inherited init(Bounds);
  2352. end;
  2353. procedure TRegistersView.Draw;
  2354. var
  2355. rs : tintregs;
  2356. color :byte;
  2357. procedure SetColor(x,y : longint);
  2358. begin
  2359. if x=y then
  2360. color:=7
  2361. else
  2362. color:=8;
  2363. end;
  2364. begin
  2365. inherited draw;
  2366. If not assigned(Debugger) then
  2367. begin
  2368. WriteStr(1,0,'<no values available>',7);
  2369. exit;
  2370. end;
  2371. if GetIntRegs(rs) then
  2372. begin
  2373. SetColor(rs.eax,OldReg.eax);
  2374. WriteStr(1,0,'EAX '+HexStr(rs.eax,8),color);
  2375. SetColor(rs.ebx,OldReg.ebx);
  2376. WriteStr(1,1,'EBX '+HexStr(rs.ebx,8),color);
  2377. SetColor(rs.ecx,OldReg.ecx);
  2378. WriteStr(1,2,'ECX '+HexStr(rs.ecx,8),color);
  2379. SetColor(rs.edx,OldReg.edx);
  2380. WriteStr(1,3,'EDX '+HexStr(rs.edx,8),color);
  2381. SetColor(rs.eip,OldReg.eip);
  2382. WriteStr(1,4,'EIP '+HexStr(rs.eip,8),color);
  2383. SetColor(rs.esi,OldReg.esi);
  2384. WriteStr(1,5,'ESI '+HexStr(rs.esi,8),color);
  2385. SetColor(rs.edi,OldReg.edi);
  2386. WriteStr(1,6,'EDI '+HexStr(rs.edi,8),color);
  2387. SetColor(rs.esp,OldReg.esp);
  2388. WriteStr(1,7,'ESP '+HexStr(rs.esp,8),color);
  2389. SetColor(rs.ebp,OldReg.ebp);
  2390. WriteStr(1,8,'EBP '+HexStr(rs.ebp,8),color);
  2391. SetColor(rs.cs,OldReg.cs);
  2392. WriteStr(14,0,'CS '+HexStr(rs.cs,4),color);
  2393. SetColor(rs.ds,OldReg.ds);
  2394. WriteStr(14,1,'DS '+HexStr(rs.ds,4),color);
  2395. SetColor(rs.es,OldReg.es);
  2396. WriteStr(14,2,'ES '+HexStr(rs.es,4),color);
  2397. SetColor(rs.fs,OldReg.fs);
  2398. WriteStr(14,3,'FS '+HexStr(rs.fs,4),color);
  2399. SetColor(rs.gs,OldReg.gs);
  2400. WriteStr(14,4,'GS '+HexStr(rs.gs,4),color);
  2401. SetColor(rs.ss,OldReg.ss);
  2402. WriteStr(14,5,'SS '+HexStr(rs.ss,4),color);
  2403. SetColor(rs.eflags and $1,OldReg.eflags and $1);
  2404. WriteStr(22,0,'c='+chr(byte((rs.eflags and $1)<>0)+48),color);
  2405. SetColor(rs.eflags and $20,OldReg.eflags and $20);
  2406. WriteStr(22,1,'z='+chr(byte((rs.eflags and $20)<>0)+48),color);
  2407. SetColor(rs.eflags and $80,OldReg.eflags and $80);
  2408. WriteStr(22,2,'s='+chr(byte((rs.eflags and $80)<>0)+48),color);
  2409. SetColor(rs.eflags and $800,OldReg.eflags and $800);
  2410. WriteStr(22,3,'o='+chr(byte((rs.eflags and $800)<>0)+48),color);
  2411. SetColor(rs.eflags and $4,OldReg.eflags and $4);
  2412. WriteStr(22,4,'p='+chr(byte((rs.eflags and $4)<>0)+48),color);
  2413. SetColor(rs.eflags and $200,OldReg.eflags and $200);
  2414. WriteStr(22,5,'i='+chr(byte((rs.eflags and $200)<>0)+48),color);
  2415. SetColor(rs.eflags and $10,OldReg.eflags and $10);
  2416. WriteStr(22,6,'a='+chr(byte((rs.eflags and $10)<>0)+48),color);
  2417. SetColor(rs.eflags and $400,OldReg.eflags and $400);
  2418. WriteStr(22,7,'d='+chr(byte((rs.eflags and $400)<>0)+48),color);
  2419. OldReg:=rs;
  2420. end
  2421. else
  2422. WriteStr(0,0,'<debugger error>',7);
  2423. end;
  2424. destructor TRegistersView.Done;
  2425. begin
  2426. inherited done;
  2427. end;
  2428. {****************************************************************************
  2429. TRegistersWindow
  2430. ****************************************************************************}
  2431. constructor TRegistersWindow.Init;
  2432. var
  2433. R : TRect;
  2434. begin
  2435. Desktop^.GetExtent(R);
  2436. R.A.X:=R.B.X-28;
  2437. R.B.Y:=R.A.Y+11;
  2438. inherited Init(R,'Register View', wnNoNumber);
  2439. Flags:=wfClose or wfMove;
  2440. Palette:=wpCyanWindow;
  2441. HelpCtx:=hcRegisters;
  2442. R.Assign(1,1,26,10);
  2443. RV:=new(PRegistersView,init(R));
  2444. Insert(RV);
  2445. If assigned(RegistersWindow) then
  2446. dispose(RegistersWindow,done);
  2447. RegistersWindow:=@Self;
  2448. Update;
  2449. end;
  2450. constructor TRegistersWindow.Load(var S: TStream);
  2451. begin
  2452. inherited load(S);
  2453. GetSubViewPtr(S,RV);
  2454. If assigned(RegistersWindow) then
  2455. dispose(RegistersWindow,done);
  2456. RegistersWindow:=@Self;
  2457. end;
  2458. procedure TRegistersWindow.Store(var S: TStream);
  2459. begin
  2460. inherited Store(s);
  2461. PutSubViewPtr(S,RV);
  2462. end;
  2463. procedure TRegistersWindow.Update;
  2464. begin
  2465. ReDraw;
  2466. end;
  2467. destructor TRegistersWindow.Done;
  2468. begin
  2469. RegistersWindow:=nil;
  2470. inherited done;
  2471. end;
  2472. {****************************************************************************
  2473. TFPUView
  2474. ****************************************************************************}
  2475. function GetFPURegs(var rs : TFPURegs) : boolean;
  2476. var
  2477. p,po : pchar;
  2478. p1 : pchar;
  2479. reg,value : string;
  2480. buffer : array[0..255] of char;
  2481. v : dword;
  2482. code : word;
  2483. begin
  2484. GetFPURegs:=false;
  2485. {$ifndef NODEBUG}
  2486. Debugger^.Command('info registers');
  2487. if Debugger^.Error then
  2488. exit
  2489. else
  2490. begin
  2491. po:=StrNew(Debugger^.GetOutput);
  2492. p:=po;
  2493. if assigned(p) then
  2494. begin
  2495. fillchar(rs,sizeof(rs),0);
  2496. p1:=strscan(p,' ');
  2497. while assigned(p1) do
  2498. begin
  2499. {
  2500. strlcopy(buffer,p,p1-p);
  2501. reg:=strpas(buffer);
  2502. p:=strscan(p,'$');
  2503. p1:=strscan(p,#9);
  2504. strlcopy(buffer,p,p1-p);
  2505. value:=strpas(buffer);
  2506. val(value,v,code);
  2507. if reg='eax' then
  2508. rs.eax:=v
  2509. else if reg='ebx' then
  2510. rs.ebx:=v
  2511. else if reg='ecx' then
  2512. rs.ecx:=v
  2513. else if reg='edx' then
  2514. rs.edx:=v
  2515. else if reg='eip' then
  2516. rs.eip:=v
  2517. else if reg='esi' then
  2518. rs.esi:=v
  2519. else if reg='edi' then
  2520. rs.edi:=v
  2521. else if reg='esp' then
  2522. rs.esp:=v
  2523. else if reg='ebp' then
  2524. rs.ebp:=v
  2525. under win32 flags are on a register named ps !! PM
  2526. else if (reg='eflags') or (reg='ps') then
  2527. rs.eflags:=v
  2528. else if reg='cs' then
  2529. rs.cs:=v
  2530. else if reg='ds' then
  2531. rs.ds:=v
  2532. else if reg='es' then
  2533. rs.es:=v
  2534. else if reg='fs' then
  2535. rs.fs:=v
  2536. else if reg='gs' then
  2537. rs.gs:=v
  2538. else if reg='ss' then
  2539. rs.ss:=v;
  2540. p:=strscan(p1,#10);
  2541. if assigned(p) then
  2542. begin
  2543. p1:=strscan(p,' ');
  2544. inc(p);
  2545. end
  2546. else
  2547. break;
  2548. }
  2549. end;
  2550. { free allocated memory }
  2551. strdispose(po);
  2552. end
  2553. else
  2554. exit;
  2555. end;
  2556. { do not open a messagebox for such errors }
  2557. Debugger^.got_error:=false;
  2558. GetFPURegs:=true;
  2559. {$endif}
  2560. end;
  2561. constructor TFPUView.Init(var Bounds: TRect);
  2562. begin
  2563. inherited init(Bounds);
  2564. end;
  2565. procedure TFPUView.Draw;
  2566. var
  2567. rs : tfpuregs;
  2568. color :byte;
  2569. procedure SetColor(x,y : longint);
  2570. begin
  2571. if x=y then
  2572. color:=7
  2573. else
  2574. color:=8;
  2575. end;
  2576. begin
  2577. inherited draw;
  2578. If not assigned(Debugger) then
  2579. begin
  2580. WriteStr(1,0,'<no values available>',7);
  2581. exit;
  2582. end;
  2583. if GetFPURegs(rs) then
  2584. begin
  2585. {
  2586. SetColor(rs.eax,OldReg.eax);
  2587. WriteStr(1,0,'EAX '+HexStr(rs.eax,8),color);
  2588. SetColor(rs.ebx,OldReg.ebx);
  2589. WriteStr(1,1,'EBX '+HexStr(rs.ebx,8),color);
  2590. SetColor(rs.ecx,OldReg.ecx);
  2591. WriteStr(1,2,'ECX '+HexStr(rs.ecx,8),color);
  2592. SetColor(rs.edx,OldReg.edx);
  2593. WriteStr(1,3,'EDX '+HexStr(rs.edx,8),color);
  2594. SetColor(rs.eip,OldReg.eip);
  2595. WriteStr(1,4,'EIP '+HexStr(rs.eip,8),color);
  2596. SetColor(rs.esi,OldReg.esi);
  2597. WriteStr(1,5,'ESI '+HexStr(rs.esi,8),color);
  2598. SetColor(rs.edi,OldReg.edi);
  2599. WriteStr(1,6,'EDI '+HexStr(rs.edi,8),color);
  2600. SetColor(rs.esp,OldReg.esp);
  2601. WriteStr(1,7,'ESP '+HexStr(rs.esp,8),color);
  2602. SetColor(rs.ebp,OldReg.ebp);
  2603. WriteStr(1,8,'EBP '+HexStr(rs.ebp,8),color);
  2604. SetColor(rs.cs,OldReg.cs);
  2605. WriteStr(14,0,'CS '+HexStr(rs.cs,4),color);
  2606. SetColor(rs.ds,OldReg.ds);
  2607. WriteStr(14,1,'DS '+HexStr(rs.ds,4),color);
  2608. SetColor(rs.es,OldReg.es);
  2609. WriteStr(14,2,'ES '+HexStr(rs.es,4),color);
  2610. SetColor(rs.fs,OldReg.fs);
  2611. WriteStr(14,3,'FS '+HexStr(rs.fs,4),color);
  2612. SetColor(rs.gs,OldReg.gs);
  2613. WriteStr(14,4,'GS '+HexStr(rs.gs,4),color);
  2614. SetColor(rs.ss,OldReg.ss);
  2615. WriteStr(14,5,'SS '+HexStr(rs.ss,4),color);
  2616. SetColor(rs.eflags and $1,OldReg.eflags and $1);
  2617. WriteStr(22,0,'c='+chr(byte((rs.eflags and $1)<>0)+48),color);
  2618. SetColor(rs.eflags and $20,OldReg.eflags and $20);
  2619. WriteStr(22,1,'z='+chr(byte((rs.eflags and $20)<>0)+48),color);
  2620. SetColor(rs.eflags and $80,OldReg.eflags and $80);
  2621. WriteStr(22,2,'s='+chr(byte((rs.eflags and $80)<>0)+48),color);
  2622. SetColor(rs.eflags and $800,OldReg.eflags and $800);
  2623. WriteStr(22,3,'o='+chr(byte((rs.eflags and $800)<>0)+48),color);
  2624. SetColor(rs.eflags and $4,OldReg.eflags and $4);
  2625. WriteStr(22,4,'p='+chr(byte((rs.eflags and $4)<>0)+48),color);
  2626. SetColor(rs.eflags and $200,OldReg.eflags and $200);
  2627. WriteStr(22,5,'i='+chr(byte((rs.eflags and $200)<>0)+48),color);
  2628. SetColor(rs.eflags and $10,OldReg.eflags and $10);
  2629. WriteStr(22,6,'a='+chr(byte((rs.eflags and $10)<>0)+48),color);
  2630. SetColor(rs.eflags and $400,OldReg.eflags and $400);
  2631. WriteStr(22,7,'d='+chr(byte((rs.eflags and $400)<>0)+48),color);
  2632. OldReg:=rs;
  2633. }
  2634. end
  2635. else
  2636. WriteStr(0,0,'<debugger error>',7);
  2637. end;
  2638. destructor TFPUView.Done;
  2639. begin
  2640. inherited done;
  2641. end;
  2642. {****************************************************************************
  2643. TFPUWindow
  2644. ****************************************************************************}
  2645. constructor TFPUWindow.Init;
  2646. var
  2647. R : TRect;
  2648. begin
  2649. Desktop^.GetExtent(R);
  2650. R.A.X:=R.B.X-28;
  2651. R.B.Y:=R.A.Y+11;
  2652. inherited Init(R,'FPU View', wnNoNumber);
  2653. Flags:=wfClose or wfMove;
  2654. Palette:=wpCyanWindow;
  2655. HelpCtx:=hcRegisters;
  2656. R.Assign(1,1,26,10);
  2657. RV:=new(PFPUView,init(R));
  2658. Insert(RV);
  2659. If assigned(FPUWindow) then
  2660. dispose(FPUWindow,done);
  2661. FPUWindow:=@Self;
  2662. Update;
  2663. end;
  2664. constructor TFPUWindow.Load(var S: TStream);
  2665. begin
  2666. inherited load(S);
  2667. GetSubViewPtr(S,RV);
  2668. If assigned(FPUWindow) then
  2669. dispose(FPUWindow,done);
  2670. FPUWindow:=@Self;
  2671. end;
  2672. procedure TFPUWindow.Store(var S: TStream);
  2673. begin
  2674. inherited Store(s);
  2675. PutSubViewPtr(S,RV);
  2676. end;
  2677. procedure TFPUWindow.Update;
  2678. begin
  2679. ReDraw;
  2680. end;
  2681. destructor TFPUWindow.Done;
  2682. begin
  2683. FPUWindow:=nil;
  2684. inherited done;
  2685. end;
  2686. {****************************************************************************
  2687. TStackWindow
  2688. ****************************************************************************}
  2689. constructor TFramesListBox.Init(var Bounds: TRect; AHScrollBar, AVScrollBar: PScrollBar);
  2690. begin
  2691. Inherited Init(Bounds,AHScrollBar,AVScrollBar);
  2692. end;
  2693. procedure TFramesListBox.Update;
  2694. var i : longint;
  2695. W : PSourceWindow;
  2696. begin
  2697. { call backtrace command }
  2698. If not assigned(Debugger) then
  2699. exit;
  2700. {$ifndef NODEBUG}
  2701. DeskTop^.Lock;
  2702. Clear;
  2703. { forget all old frames }
  2704. Debugger^.clear_frames;
  2705. Debugger^.Command('backtrace');
  2706. { generate list }
  2707. { all is in tframeentry }
  2708. for i:=0 to Debugger^.frame_count-1 do
  2709. begin
  2710. with Debugger^.frames[i]^ do
  2711. begin
  2712. if assigned(file_name) then
  2713. AddItem(new(PMessageItem,init(0,GetPChar(function_name)+GetPChar(args),
  2714. AddModuleName(GetPChar(file_name)),line_number,1)))
  2715. else
  2716. AddItem(new(PMessageItem,init(0,HexStr(address,8)+' '+GetPChar(function_name)+GetPChar(args),
  2717. AddModuleName(''),line_number,1)));
  2718. W:=SearchOnDesktop(GetPChar(file_name),false);
  2719. { First reset all Debugger rows }
  2720. If assigned(W) then
  2721. W^.Editor^.SetDebuggerRow(-1);
  2722. end;
  2723. end;
  2724. { Now set all Debugger rows }
  2725. for i:=0 to Debugger^.frame_count-1 do
  2726. begin
  2727. with Debugger^.frames[i]^ do
  2728. begin
  2729. W:=SearchOnDesktop(GetPChar(file_name),false);
  2730. If assigned(W) then
  2731. begin
  2732. If W^.Editor^.DebuggerRow=-1 then
  2733. W^.Editor^.SetDebuggerRow(line_number-1);
  2734. end;
  2735. end;
  2736. end;
  2737. if List^.Count > 0 then
  2738. FocusItem(0);
  2739. DeskTop^.Unlock;
  2740. {$endif}
  2741. end;
  2742. function TFramesListBox.GetLocalMenu: PMenu;
  2743. begin
  2744. GetLocalMenu:=Inherited GetLocalMenu;
  2745. end;
  2746. procedure TFramesListBox.GotoSource;
  2747. begin
  2748. { select frame for watches }
  2749. If not assigned(Debugger) then
  2750. exit;
  2751. {$ifndef NODEBUG}
  2752. Debugger^.Command('f '+IntToStr(Focused));
  2753. { for local vars }
  2754. Debugger^.ReadWatches;
  2755. {$endif}
  2756. { goto source }
  2757. inherited GotoSource;
  2758. end;
  2759. procedure TFramesListBox.HandleEvent(var Event: TEvent);
  2760. begin
  2761. inherited HandleEvent(Event);
  2762. end;
  2763. destructor TFramesListBox.Done;
  2764. begin
  2765. Inherited Done;
  2766. end;
  2767. Constructor TStackWindow.Init;
  2768. var
  2769. HSB,VSB: PScrollBar;
  2770. R,R2 : trect;
  2771. begin
  2772. Desktop^.GetExtent(R);
  2773. R.A.Y:=R.B.Y-5;
  2774. inherited Init(R, 'Call Stack', wnNoNumber);
  2775. Palette:=wpCyanWindow;
  2776. GetExtent(R);
  2777. HelpCtx:=hcStack;
  2778. R.Grow(-1,-1);
  2779. R2.Copy(R);
  2780. Inc(R2.B.Y);
  2781. R2.A.Y:=R2.B.Y-1;
  2782. New(HSB, Init(R2));
  2783. HSB^.GrowMode:=gfGrowLoY+gfGrowHiY+gfGrowHiX;
  2784. Insert(HSB);
  2785. R2.Copy(R);
  2786. Inc(R2.B.X);
  2787. R2.A.X:=R2.B.X-1;
  2788. New(VSB, Init(R2));
  2789. VSB^.GrowMode:=gfGrowLoX+gfGrowHiX+gfGrowHiY;
  2790. Insert(VSB);
  2791. New(FLB,Init(R,HSB,VSB));
  2792. FLB^.GrowMode:=gfGrowHiX+gfGrowHiY;
  2793. Insert(FLB);
  2794. If assigned(StackWindow) then
  2795. dispose(StackWindow,done);
  2796. StackWindow:=@Self;
  2797. Update;
  2798. end;
  2799. procedure TStackWindow.Update;
  2800. begin
  2801. FLB^.Update;
  2802. DrawView;
  2803. end;
  2804. constructor TStackWindow.Load(var S: TStream);
  2805. begin
  2806. inherited Load(S);
  2807. GetSubViewPtr(S,FLB);
  2808. If assigned(StackWindow) then
  2809. dispose(StackWindow,done);
  2810. StackWindow:=@Self;
  2811. end;
  2812. procedure TStackWindow.Store(var S: TStream);
  2813. begin
  2814. inherited Store(S);
  2815. PutSubViewPtr(S,FLB);
  2816. end;
  2817. Destructor TStackWindow.Done;
  2818. begin
  2819. StackWindow:=nil;
  2820. Dispose(FLB,done);
  2821. inherited done;
  2822. end;
  2823. {****************************************************************************
  2824. Init/Final
  2825. ****************************************************************************}
  2826. procedure InitDebugger;
  2827. {$ifdef DEBUG}
  2828. var s : string;
  2829. i,p : longint;
  2830. {$endif DEBUG}
  2831. var
  2832. NeedRecompileExe : boolean;
  2833. cm : longint;
  2834. begin
  2835. {$ifdef DEBUG}
  2836. Assign(gdb_file,GDBOutFileName);
  2837. {$I-}
  2838. Rewrite(gdb_file);
  2839. if InOutRes<>0 then
  2840. begin
  2841. s:=GDBOutFileName;
  2842. p:=pos('.',s);
  2843. if p>1 then
  2844. for i:=0 to 9 do
  2845. begin
  2846. s:=copy(s,1,p-2)+chr(i+ord('0'))+copy(s,p,length(s));
  2847. InOutRes:=0;
  2848. Assign(gdb_file,s);
  2849. rewrite(gdb_file);
  2850. if InOutRes=0 then
  2851. break;
  2852. end;
  2853. end;
  2854. if IOResult=0 then
  2855. Use_gdb_file:=true;
  2856. {$I+}
  2857. {$endif}
  2858. NeedRecompileExe:=false;
  2859. if TargetSwitches^.GetCurrSelParam<>source_os.shortname then
  2860. begin
  2861. cm:=ConfirmBox(#3'Sorry, can not debug'#13#3'programs compiled for '
  2862. +TargetSwitches^.GetCurrSelParam+'.'#13#3
  2863. +'Change target to '
  2864. +source_os.shortname+'?',nil,true);
  2865. if cm=cmCancel then
  2866. Exit;
  2867. if cm=cmYes then
  2868. begin
  2869. { force recompilation }
  2870. PrevMainFile:='';
  2871. NeedRecompileExe:=true;
  2872. TargetSwitches^.SetCurrSelParam(source_os.shortname);
  2873. If DebugInfoSwitches^.GetCurrSelParam='-' then
  2874. DebugInfoSwitches^.SetCurrSelParam('l');
  2875. end;
  2876. end;
  2877. if not NeedRecompileExe then
  2878. NeedRecompileExe:=(not ExistsFile(ExeFile)) or (CompilationPhase<>cpDone) or
  2879. (PrevMainFile<>MainFile) or NeedRecompile(false);
  2880. if Not NeedRecompileExe and Not MainHasDebugInfo then
  2881. begin
  2882. cm:=ConfirmBox(#3'Warning, the program'#13#3'was compiled without'#13#3
  2883. +'debugging info.'#13#3
  2884. +'Recompile it?',nil,true);
  2885. if cm=cmCancel then
  2886. Exit;
  2887. if cm=cmYes then
  2888. begin
  2889. { force recompilation }
  2890. PrevMainFile:='';
  2891. NeedRecompileExe:=true;
  2892. DebugInfoSwitches^.SetCurrSelParam('l');
  2893. end;
  2894. end;
  2895. if NeedRecompileExe then
  2896. DoCompile(cRun);
  2897. if CompilationPhase<>cpDone then
  2898. Exit;
  2899. if (EXEFile='') then
  2900. begin
  2901. ErrorBox('Oooops, nothing to debug.',nil);
  2902. Exit;
  2903. end;
  2904. {$ifdef DEBUG}
  2905. PushStatus('Starting debugger');
  2906. {$endif DEBUG}
  2907. { init debugcontroller }
  2908. if assigned(Debugger) then
  2909. dispose(Debugger,Done);
  2910. new(Debugger,Init(ExeFile));
  2911. {$ifdef GDBWINDOW}
  2912. InitGDBWindow;
  2913. {$endif def GDBWINDOW}
  2914. {$ifdef DEBUG}
  2915. PopStatus;
  2916. {$endif DEBUG}
  2917. end;
  2918. procedure DoneDebugger;
  2919. begin
  2920. {$ifdef DEBUG}
  2921. { PushStatus('Closing debugger');
  2922. No its called after App.Done !! }
  2923. {$endif}
  2924. if assigned(Debugger) then
  2925. dispose(Debugger,Done);
  2926. Debugger:=nil;
  2927. {$ifdef DEBUG}
  2928. If Use_gdb_file then
  2929. Close(GDB_file);
  2930. Use_gdb_file:=false;
  2931. {PopStatus;}
  2932. {$endif DEBUG}
  2933. {DoneGDBWindow;}
  2934. end;
  2935. procedure InitGDBWindow;
  2936. var
  2937. R : TRect;
  2938. begin
  2939. if GDBWindow=nil then
  2940. begin
  2941. DeskTop^.GetExtent(R);
  2942. new(GDBWindow,init(R));
  2943. DeskTop^.Insert(GDBWindow);
  2944. end;
  2945. end;
  2946. procedure DoneGDBWindow;
  2947. begin
  2948. if assigned(GDBWindow) then
  2949. begin
  2950. DeskTop^.Delete(GDBWindow);
  2951. GDBWindow:=nil;
  2952. end;
  2953. end;
  2954. procedure InitStackWindow;
  2955. begin
  2956. if StackWindow=nil then
  2957. begin
  2958. new(StackWindow,init);
  2959. DeskTop^.Insert(StackWindow);
  2960. end;
  2961. end;
  2962. procedure DoneStackWindow;
  2963. begin
  2964. if assigned(StackWindow) then
  2965. begin
  2966. DeskTop^.Delete(StackWindow);
  2967. StackWindow:=nil;
  2968. end;
  2969. end;
  2970. procedure InitRegistersWindow;
  2971. begin
  2972. if RegistersWindow=nil then
  2973. begin
  2974. new(RegistersWindow,init);
  2975. DeskTop^.Insert(RegistersWindow);
  2976. end;
  2977. end;
  2978. procedure DoneRegistersWindow;
  2979. begin
  2980. if assigned(RegistersWindow) then
  2981. begin
  2982. DeskTop^.Delete(RegistersWindow);
  2983. RegistersWindow:=nil;
  2984. end;
  2985. end;
  2986. procedure InitBreakpoints;
  2987. begin
  2988. New(BreakpointsCollection,init(10,10));
  2989. end;
  2990. procedure DoneBreakpoints;
  2991. begin
  2992. Dispose(BreakpointsCollection,Done);
  2993. BreakpointsCollection:=nil;
  2994. end;
  2995. procedure InitWatches;
  2996. begin
  2997. New(WatchesCollection,init);
  2998. end;
  2999. procedure DoneWatches;
  3000. begin
  3001. Dispose(WatchesCollection,Done);
  3002. WatchesCollection:=nil;
  3003. end;
  3004. procedure RegisterFPDebugViews;
  3005. begin
  3006. RegisterType(RWatchesWindow);
  3007. RegisterType(RBreakpointsWindow);
  3008. RegisterType(RWatchesListBox);
  3009. RegisterType(RBreakpointsListBox);
  3010. RegisterType(RStackWindow);
  3011. RegisterType(RFramesListBox);
  3012. RegisterType(RBreakpoint);
  3013. RegisterType(RWatch);
  3014. RegisterType(RBreakpointCollection);
  3015. RegisterType(RWatchesCollection);
  3016. RegisterType(RRegistersWindow);
  3017. RegisterType(RRegistersView);
  3018. RegisterType(RFPUWindow);
  3019. RegisterType(RFPUView);
  3020. end;
  3021. end.
  3022. {
  3023. $Log$
  3024. Revision 1.57 2000-03-14 14:22:30 pierre
  3025. + generate cmDebuggerStopped broadcast
  3026. Revision 1.56 2000/03/08 16:57:01 pierre
  3027. * Wrong highlighted line while debugging fixed
  3028. + Check if exe has debugging info
  3029. Revision 1.55 2000/03/07 21:52:54 pierre
  3030. + TDebugController.GetValue
  3031. Revision 1.54 2000/03/06 11:34:25 pierre
  3032. + windebug unit for Window Title change when debugging
  3033. Revision 1.53 2000/02/07 12:51:32 pierre
  3034. * typo fix
  3035. Revision 1.52 2000/02/07 11:50:30 pierre
  3036. Gabor changes for TP
  3037. Revision 1.51 2000/02/06 23:43:57 pierre
  3038. * breakpoint path problems fixes
  3039. Revision 1.50 2000/02/05 01:27:58 pierre
  3040. * bug with Toggle Break fixed, hopefully
  3041. + search for local vars in parent procs avoiding
  3042. wrong results (see test.pas source)
  3043. Revision 1.49 2000/02/04 23:18:05 pierre
  3044. * no pushstatus in DoneDebugger because its called after App.done
  3045. Revision 1.48 2000/02/04 14:34:46 pierre
  3046. readme.txt
  3047. Revision 1.47 2000/02/04 00:10:58 pierre
  3048. * Breakpoint line in Source Window better handled
  3049. Revision 1.46 2000/02/01 10:59:58 pierre
  3050. * allow FP to debug itself
  3051. Revision 1.45 2000/01/28 22:38:21 pierre
  3052. * CrtlF9 starts debugger if there are active breakpoints
  3053. Revision 1.44 2000/01/27 22:30:38 florian
  3054. * start of FPU window
  3055. * current executed line color has a higher priority then a breakpoint now
  3056. Revision 1.43 2000/01/20 00:31:53 pierre
  3057. * uses ShortName of exe to start GDB
  3058. Revision 1.42 2000/01/10 17:49:40 pierre
  3059. * Get RegisterView to Update correctly
  3060. * Write in white changed regs (keeping a copy of previous values)
  3061. Revision 1.41 2000/01/10 16:20:50 florian
  3062. * working register window
  3063. Revision 1.40 2000/01/10 13:20:57 pierre
  3064. + debug only possible on source target
  3065. Revision 1.39 2000/01/10 00:25:06 pierre
  3066. * RegisterWindow problem fixed
  3067. Revision 1.38 2000/01/09 21:05:51 florian
  3068. * some fixes for register view
  3069. Revision 1.37 2000/01/08 18:26:20 florian
  3070. + added a register window, doesn't work yet
  3071. Revision 1.36 1999/12/20 14:23:16 pierre
  3072. * MyApp renamed IDEApp
  3073. * TDebugController.ResetDebuggerRows added to
  3074. get resetting of debugger rows
  3075. Revision 1.35 1999/11/24 14:03:16 pierre
  3076. + Executing... in status line if in another window
  3077. Revision 1.34 1999/11/10 17:19:58 pierre
  3078. + Other window for Debuggee code
  3079. Revision 1.33 1999/10/25 16:39:03 pierre
  3080. + GetPChar to avoid nil pointer problems
  3081. Revision 1.32 1999/09/16 14:34:57 pierre
  3082. + TBreakpoint and TWatch registering
  3083. + WatchesCollection and BreakpointsCollection stored in desk file
  3084. * Syntax highlighting was broken
  3085. Revision 1.31 1999/09/13 16:24:43 peter
  3086. + clock
  3087. * backspace unident like tp7
  3088. Revision 1.30 1999/09/09 16:36:30 pierre
  3089. * Breakpoint storage problem corrected
  3090. Revision 1.29 1999/09/09 16:31:45 pierre
  3091. * some breakpoint related fixes and Help contexts
  3092. Revision 1.28 1999/09/09 14:20:05 pierre
  3093. + Stack Window
  3094. Revision 1.27 1999/08/24 22:04:33 pierre
  3095. + TCodeEditor.SetDebuggerRow
  3096. works like SetHighlightRow but is only disposed by a SetDebuggerRow(-1)
  3097. so the current stop point in debugging is not lost if
  3098. we move the cursor
  3099. Revision 1.26 1999/08/22 22:26:48 pierre
  3100. + Registration of Breakpoint/Watches windows
  3101. Revision 1.25 1999/08/16 18:25:15 peter
  3102. * Adjusting the selection when the editor didn't contain any line.
  3103. * Reserved word recognition redesigned, but this didn't affect the overall
  3104. syntax highlight speed remarkably (at least not on my Amd-K6/350).
  3105. The syntax scanner loop is a bit slow but the main problem is the
  3106. recognition of special symbols. Switching off symbol processing boosts
  3107. the performance up to ca. 200%...
  3108. * The editor didn't allow copying (for ex to clipboard) of a single character
  3109. * 'File|Save as' caused permanently run-time error 3. Not any more now...
  3110. * Compiler Messages window (actually the whole desktop) did not act on any
  3111. keypress when compilation failed and thus the window remained visible
  3112. + Message windows are now closed upon pressing Esc
  3113. + At 'Run' the IDE checks whether any sources are modified, and recompiles
  3114. only when neccessary
  3115. + BlockRead and BlockWrite (Ctrl+K+R/W) implemented in TCodeEditor
  3116. + LineSelect (Ctrl+K+L) implemented
  3117. * The IDE had problems closing help windows before saving the desktop
  3118. Revision 1.24 1999/08/03 20:22:28 peter
  3119. + TTab acts now on Ctrl+Tab and Ctrl+Shift+Tab...
  3120. + Desktop saving should work now
  3121. - History saved
  3122. - Clipboard content saved
  3123. - Desktop saved
  3124. - Symbol info saved
  3125. * syntax-highlight bug fixed, which compared special keywords case sensitive
  3126. (for ex. 'asm' caused asm-highlighting, while 'ASM' didn't)
  3127. * with 'whole words only' set, the editor didn't found occourences of the
  3128. searched text, if the text appeared previously in the same line, but didn't
  3129. satisfied the 'whole-word' condition
  3130. * ^QB jumped to (SelStart.X,SelEnd.X) instead of (SelStart.X,SelStart.Y)
  3131. (ie. the beginning of the selection)
  3132. * when started typing in a new line, but not at the start (X=0) of it,
  3133. the editor inserted the text one character more to left as it should...
  3134. * TCodeEditor.HideSelection (Ctrl-K+H) didn't update the screen
  3135. * Shift shouldn't cause so much trouble in TCodeEditor now...
  3136. * Syntax highlight had problems recognizing a special symbol if it was
  3137. prefixed by another symbol character in the source text
  3138. * Auto-save also occours at Dos shell, Tool execution, etc. now...
  3139. Revision 1.23 1999/07/28 23:11:17 peter
  3140. * fixes from gabor
  3141. Revision 1.22 1999/07/12 13:14:15 pierre
  3142. * LineEnd bug corrected, now goes end of text even if selected
  3143. + Until Return for debugger
  3144. + Code for Quit inside GDB Window
  3145. Revision 1.21 1999/07/11 00:35:14 pierre
  3146. * fix problems for wrong watches
  3147. Revision 1.20 1999/07/10 01:24:14 pierre
  3148. + First implementation of watches window
  3149. Revision 1.19 1999/06/30 23:58:12 pierre
  3150. + BreakpointsList Window implemented
  3151. with Edit/New/Delete functions
  3152. + Individual breakpoint dialog with support for all types
  3153. ignorecount and conditions
  3154. (commands are not yet implemented, don't know if this wolud be useful)
  3155. awatch and rwatch have problems because GDB does not annotate them
  3156. I fixed v4.16 for this
  3157. Revision 1.18 1999/03/16 00:44:42 peter
  3158. * forgotten in last commit :(
  3159. Revision 1.17 1999/03/02 13:48:28 peter
  3160. * fixed far problem is fpdebug
  3161. * tile/cascading with message window
  3162. * grep fixes
  3163. Revision 1.16 1999/03/01 15:41:52 peter
  3164. + Added dummy entries for functions not yet implemented
  3165. * MenuBar didn't update itself automatically on command-set changes
  3166. * Fixed Debugging/Profiling options dialog
  3167. * TCodeEditor converts spaces to tabs at save only if efUseTabChars is
  3168. set
  3169. * efBackSpaceUnindents works correctly
  3170. + 'Messages' window implemented
  3171. + Added '$CAP MSG()' and '$CAP EDIT' to available tool-macros
  3172. + Added TP message-filter support (for ex. you can call GREP thru
  3173. GREP2MSG and view the result in the messages window - just like in TP)
  3174. * A 'var' was missing from the param-list of THelpFacility.TopicSearch,
  3175. so topic search didn't work...
  3176. * In FPHELP.PAS there were still context-variables defined as word instead
  3177. of THelpCtx
  3178. * StdStatusKeys() was missing from the statusdef for help windows
  3179. + Topic-title for index-table can be specified when adding a HTML-files
  3180. Revision 1.15 1999/02/20 15:18:29 peter
  3181. + ctrl-c capture with confirm dialog
  3182. + ascii table in the tools menu
  3183. + heapviewer
  3184. * empty file fixed
  3185. * fixed callback routines in fpdebug to have far for tp7
  3186. Revision 1.14 1999/02/16 12:47:36 pierre
  3187. * GDBWindow does not popup on F7 or F8 anymore
  3188. Revision 1.13 1999/02/16 10:43:54 peter
  3189. * use -dGDB for the compiler
  3190. * only use gdb_file when -dDEBUG is used
  3191. * profiler switch is now a toggle instead of radiobutton
  3192. Revision 1.12 1999/02/11 19:07:20 pierre
  3193. * GDBWindow redesigned :
  3194. normal editor apart from
  3195. that any kbEnter will send the line (for begin to cursor)
  3196. to GDB command !
  3197. GDBWindow opened in Debugger Menu
  3198. still buggy :
  3199. -echo should not be present if at end of text
  3200. -GDBWindow becomes First after each step (I don't know why !)
  3201. Revision 1.11 1999/02/11 13:10:03 pierre
  3202. + GDBWindow only with -dGDBWindow for now : still buggy !!
  3203. Revision 1.10 1999/02/10 09:55:07 pierre
  3204. + added OldValue and CurrentValue field for watchpoints
  3205. + InitBreakpoints and DoneBreakpoints
  3206. + MessageBox if GDB stops bacause of a watchpoint !
  3207. Revision 1.9 1999/02/08 17:43:43 pierre
  3208. * RestDebugger or multiple running of debugged program now works
  3209. + added DoContToCursor(F4)
  3210. * Breakpoints are now inserted correctly (was mainlyy a problem
  3211. of directories)
  3212. Revision 1.8 1999/02/05 17:21:52 pierre
  3213. Invalid_line renamed InvalidSourceLine
  3214. Revision 1.7 1999/02/05 13:08:41 pierre
  3215. + new breakpoint types added
  3216. Revision 1.6 1999/02/05 12:11:53 pierre
  3217. + SourceDir that stores directories for sources that the
  3218. compiler should not know about
  3219. Automatically asked for addition when a new file that
  3220. needed filedialog to be found is in an unknown directory
  3221. Stored and retrieved from INIFile
  3222. + Breakpoints conditions added to INIFile
  3223. * Breakpoints insterted and removed at debin and end of debug session
  3224. Revision 1.5 1999/02/04 17:54:22 pierre
  3225. + several commands added
  3226. Revision 1.4 1999/02/04 13:32:02 pierre
  3227. * Several things added (I cannot commit them independently !)
  3228. + added TBreakpoint and TBreakpointCollection
  3229. + added cmResetDebugger,cmGrep,CmToggleBreakpoint
  3230. + Breakpoint list in INIFile
  3231. * Select items now also depend of SwitchMode
  3232. * Reading of option '-g' was not possible !
  3233. + added search for -Fu args pathes in TryToOpen
  3234. + added code for automatic opening of FileDialog
  3235. if source not found
  3236. Revision 1.3 1999/02/02 16:41:38 peter
  3237. + automatic .pas/.pp adding by opening of file
  3238. * better debuggerscreen changes
  3239. Revision 1.2 1999/01/22 18:14:09 pierre
  3240. * adaptd to changes in gdbint and gdbcon for to /
  3241. Revision 1.1 1999/01/22 10:24:03 peter
  3242. * first debugger things
  3243. }