fpregs.pas 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681
  1. {
  2. This file is part of the Free Pascal Integrated Development Environment
  3. Copyright (c) 1998-2000 by Pierre Muller
  4. Register debug routines for the IDE
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. unit FPRegs;
  12. {$H-}
  13. {$ifdef NODEBUG}
  14. interface
  15. implementation
  16. end.
  17. {$else NODEBUG}
  18. interface
  19. uses
  20. {$ifdef Windows}
  21. Windows,
  22. {$endif Windows}
  23. Objects,Dialogs,Drivers,Views,
  24. FPViews;
  25. const
  26. MaxRegs = 128;
  27. type
  28. {$undef cpu_known}
  29. TIntRegs = record
  30. {$ifndef test_generic_cpu}
  31. {$ifdef i386}
  32. {$define cpu_known}
  33. eax,ebx,ecx,edx,eip,esi,edi,esp,ebp : dword;
  34. cs,ds,es,ss,fs,gs : word;
  35. eflags : dword;
  36. {$endif i386}
  37. {$ifdef x86_64}
  38. {$define cpu_known}
  39. rax,rbx,rcx,rdx,rsi,rdi,rbp,rsp,
  40. r8,r9,r10,r11,r12,r13,r14,r15,
  41. rip : qword;
  42. cs,ds,es,ss,fs,gs : word;
  43. eflags : dword;
  44. {$endif x86_64}
  45. {$ifdef m68k}
  46. {$define cpu_known}
  47. d0,d1,d2,d3,d4,d5,d6,d7 : dword;
  48. a0,a1,a2,a3,a4,a5,fp,sp : dword;
  49. ps,pc : dword;
  50. {$endif m68k}
  51. {$ifdef powerpc}
  52. {$define cpu_known}
  53. r : array [0..31] of dword;
  54. pc,ps,cr,lr,ctr,xer : dword;
  55. {$endif powerpc}
  56. {$ifdef sparc}
  57. {$define cpu_known}
  58. o : array [0..7] of dword;
  59. i : array [0..7] of dword;
  60. l : array [0..7] of dword;
  61. g : array [0..7] of dword;
  62. y,psr,wim,tbr,pc,npc,fsr,csr : dword;
  63. {$endif sparc}
  64. {$endif not test_generic_cpu}
  65. {$ifndef cpu_known}
  66. reg : array [0..MaxRegs-1] of string;
  67. {$endif not cpu_known}
  68. end;
  69. PRegistersView = ^TRegistersView;
  70. TRegistersView = object(TView)
  71. NewReg,OldReg : TIntRegs;
  72. InDraw : boolean;
  73. GDBCount : longint;
  74. first : boolean;
  75. LastOK : boolean;
  76. constructor Init(var Bounds: TRect);
  77. procedure Draw;virtual;
  78. destructor Done; virtual;
  79. end;
  80. PRegistersWindow = ^TRegistersWindow;
  81. TRegistersWindow = Object(TFPDlgWindow)
  82. RV : PRegistersView;
  83. Constructor Init;
  84. constructor Load(var S: TStream);
  85. procedure Store(var S: TStream);
  86. procedure Update; virtual;
  87. destructor Done; virtual;
  88. end;
  89. TFPURegs = record
  90. {$ifndef test_generic_cpu}
  91. {$if defined(i386) or defined(x86_64)}
  92. st0,st1,st2,st3,st4,st5,st6,st7 :string;
  93. ftag,fop,fctrl,fstat,fiseg,foseg : word;
  94. fioff,fooff : cardinal;
  95. {$endif i386 or x86_64}
  96. {$ifdef m68k}
  97. fp0,fp1,fp2,fp3,fp4,fp5,fp6,fp7 : string;
  98. fpcontrol,fpstatus,fpiaddr : dword;
  99. {$endif m68k}
  100. {$ifdef powerpc}
  101. f : array [0..31] of string;
  102. {$endif powerpc}
  103. {$ifdef sparc}
  104. f : array [0..31] of string;
  105. {$endif sparc}
  106. {$endif not test_generic_cpu}
  107. {$ifndef cpu_known}
  108. freg : array [0..MaxRegs-1] of string;
  109. {$endif not cpu_known}
  110. end;
  111. PFPUView = ^TFPUView;
  112. TFPUView = object(TView)
  113. NewReg,OldReg : TFPURegs;
  114. InDraw : boolean;
  115. GDBCount : longint;
  116. {$ifndef cpu_known}
  117. UseInfoFloat : boolean;
  118. {$endif not cpu_known}
  119. first : boolean;
  120. LastOK : boolean;
  121. constructor Init(var Bounds: TRect);
  122. procedure Draw;virtual;
  123. destructor Done; virtual;
  124. end;
  125. PFPUWindow = ^TFPUWindow;
  126. TFPUWindow = Object(TFPDlgWindow)
  127. RV : PFPUView;
  128. Constructor Init;
  129. constructor Load(var S: TStream);
  130. procedure Store(var S: TStream);
  131. procedure Update; virtual;
  132. destructor Done; virtual;
  133. end;
  134. tssereg = record
  135. case byte of
  136. 1 : (bytearray : array[0..15] of byte);
  137. 2 : (wordarray : array[0..7] of word);
  138. 3 : (dwordarray : array[0..3] of dword);
  139. 4 : (qwordarray : array[0..1] of qword);
  140. 5 : (twordfield : array[0..1] of qword);
  141. 6 : (singlearray : array[0..3] of single);
  142. 7 : (doublearray : array[0..1] of double);
  143. end;
  144. tmmxreg = record
  145. case byte of
  146. 1 : (bytearray : array[0..7] of byte);
  147. 2 : (wordarray : array[0..3] of word);
  148. 3 : (dwordarray : array[0..1] of dword);
  149. 4 : (qwordfield : qword);
  150. 6 : (singlearray : array[0..1] of single);
  151. end;
  152. TVectorRegs = record
  153. {$ifndef test_generic_cpu}
  154. {$if defined(i386) or defined(x86_64)}
  155. xmm : array[0..7] of string;
  156. mmx : array[0..7] of string;
  157. mxcsr : string;
  158. {$endif i386 or x86_64}
  159. {$ifdef powerpc}
  160. m : array[0..31] of string;
  161. {$endif powerpc}
  162. {$endif not test_generic_cpu}
  163. {$ifndef cpu_known}
  164. vreg : array [0..MaxRegs-1] of string;
  165. {$endif not cpu_known}
  166. end;
  167. PVectorView = ^TVectorView;
  168. TVectorView = object(TView)
  169. NewReg,OldReg : TVectorRegs;
  170. InDraw : boolean;
  171. GDBCount : longint;
  172. {$ifndef cpu_known}
  173. UseInfoVector : boolean;
  174. {$endif not cpu_known}
  175. first : boolean;
  176. LastOK : boolean;
  177. constructor Init(var Bounds: TRect);
  178. procedure Draw;virtual;
  179. destructor Done; virtual;
  180. end;
  181. PVectorWindow = ^TVectorWindow;
  182. TVectorWindow = Object(TFPDlgWindow)
  183. RV : PVectorView;
  184. Constructor Init;
  185. constructor Load(var S: TStream);
  186. procedure Store(var S: TStream);
  187. procedure Update; virtual;
  188. destructor Done; virtual;
  189. end;
  190. procedure InitRegistersWindow;
  191. procedure DoneRegistersWindow;
  192. procedure InitFPUWindow;
  193. procedure DoneFPUWindow;
  194. procedure InitVectorWindow;
  195. procedure DoneVectorWindow;
  196. procedure RegisterFPRegsViews;
  197. implementation
  198. uses
  199. Strings,
  200. {$ifndef NODEBUG}
  201. {$ifdef GDBMI}
  202. GDBMICon, GDBMIInt,
  203. {$else GDBMI}
  204. GDBCon,GDBInt,
  205. {$endif GDBMI}
  206. {$endif NODEBUG}
  207. App,Menus,
  208. WViews,WEditor,
  209. wutils,
  210. FPConst,FPVars,
  211. FPDebug;
  212. Const
  213. RRegistersWindow: TStreamRec = (
  214. ObjType: 1711;
  215. VmtLink: Ofs(TypeOf(TRegistersWindow)^);
  216. Load: @TRegistersWindow.Load;
  217. Store: @TRegistersWindow.Store
  218. );
  219. RRegistersView: TStreamRec = (
  220. ObjType: 1712;
  221. VmtLink: Ofs(TypeOf(TRegistersView)^);
  222. Load: @TRegistersView.Load;
  223. Store: @TRegistersView.Store
  224. );
  225. RFPUWindow: TStreamRec = (
  226. ObjType: 1713;
  227. VmtLink: Ofs(TypeOf(TFPUWindow)^);
  228. Load: @TFPUWindow.Load;
  229. Store: @TFPUWindow.Store
  230. );
  231. RFPUView: TStreamRec = (
  232. ObjType: 1714;
  233. VmtLink: Ofs(TypeOf(TFPUView)^);
  234. Load: @TFPUView.Load;
  235. Store: @TFPUView.Store
  236. );
  237. RVectorView: TStreamRec = (
  238. ObjType: 1715;
  239. VmtLink: Ofs(TypeOf(TVectorView)^);
  240. Load: @TVectorView.Load;
  241. Store: @TVectorView.Store
  242. );
  243. {$ifdef useresstrings}
  244. resourcestring
  245. {$else}
  246. const
  247. {$endif}
  248. dialog_registers = 'Register View';
  249. dialog_fpu = 'FPU View';
  250. dialog_vector = 'Vector Unit View';
  251. msg_registervaluesnotavailable = '<no values available>';
  252. msg_registerwindowerror = '<debugger error>';
  253. {****************************************************************************
  254. TRegistersView
  255. ****************************************************************************}
  256. function GetIntRegs(var rs : TIntRegs) : boolean;
  257. var
  258. p,po : PAnsiChar;
  259. p1 : PAnsiChar;
  260. buffer : array[0..255] of AnsiChar;
  261. i : byte;
  262. begin
  263. GetIntRegs:=false;
  264. {$ifndef NODEBUG}
  265. {$ifdef cpu_known}
  266. {$ifdef i386}
  267. GetIntRegs :=
  268. Debugger^.GetIntRegister('eax', rs.eax) and
  269. Debugger^.GetIntRegister('ebx', rs.ebx) and
  270. Debugger^.GetIntRegister('ecx', rs.ecx) and
  271. Debugger^.GetIntRegister('edx', rs.edx) and
  272. Debugger^.GetIntRegister('esi', rs.esi) and
  273. Debugger^.GetIntRegister('edi', rs.edi) and
  274. Debugger^.GetIntRegister('ebp', rs.ebp) and
  275. Debugger^.GetIntRegister('esp', rs.esp) and
  276. Debugger^.GetIntRegister('eip', rs.eip) and
  277. { under Windows flags are on a register named ps !! PM }
  278. (Debugger^.GetIntRegister('eflags', rs.eflags) or Debugger^.GetIntRegister('ps', rs.eflags)) and
  279. Debugger^.GetIntRegister('cs', rs.cs) and
  280. Debugger^.GetIntRegister('ds', rs.ds) and
  281. Debugger^.GetIntRegister('es', rs.es) and
  282. Debugger^.GetIntRegister('fs', rs.fs) and
  283. Debugger^.GetIntRegister('gs', rs.gs) and
  284. Debugger^.GetIntRegister('ss', rs.ss);
  285. {$endif i386}
  286. {$ifdef x86_64}
  287. GetIntRegs :=
  288. Debugger^.GetIntRegister('rax', rs.rax) and
  289. Debugger^.GetIntRegister('rbx', rs.rbx) and
  290. Debugger^.GetIntRegister('rcx', rs.rcx) and
  291. Debugger^.GetIntRegister('rdx', rs.rdx) and
  292. Debugger^.GetIntRegister('rsi', rs.rsi) and
  293. Debugger^.GetIntRegister('rdi', rs.rdi) and
  294. Debugger^.GetIntRegister('rbp', rs.rbp) and
  295. Debugger^.GetIntRegister('rsp', rs.rsp) and
  296. Debugger^.GetIntRegister('r8', rs.r8) and
  297. Debugger^.GetIntRegister('r9', rs.r9) and
  298. Debugger^.GetIntRegister('r10', rs.r10) and
  299. Debugger^.GetIntRegister('r11', rs.r11) and
  300. Debugger^.GetIntRegister('r12', rs.r12) and
  301. Debugger^.GetIntRegister('r13', rs.r13) and
  302. Debugger^.GetIntRegister('r14', rs.r14) and
  303. Debugger^.GetIntRegister('r15', rs.r15) and
  304. Debugger^.GetIntRegister('rip', rs.rip) and
  305. { under Windows flags are on a register named ps !! PM }
  306. (Debugger^.GetIntRegister('eflags', rs.eflags) or Debugger^.GetIntRegister('ps', rs.eflags)) and
  307. Debugger^.GetIntRegister('cs', rs.cs) and
  308. Debugger^.GetIntRegister('ds', rs.ds) and
  309. Debugger^.GetIntRegister('es', rs.es) and
  310. Debugger^.GetIntRegister('fs', rs.fs) and
  311. Debugger^.GetIntRegister('gs', rs.gs) and
  312. Debugger^.GetIntRegister('ss', rs.ss);
  313. {$endif x86_64}
  314. {$ifdef m68k}
  315. GetIntRegs :=
  316. Debugger^.GetIntRegister('d0', rs.d0) and
  317. Debugger^.GetIntRegister('d1', rs.d1) and
  318. Debugger^.GetIntRegister('d2', rs.d2) and
  319. Debugger^.GetIntRegister('d3', rs.d3) and
  320. Debugger^.GetIntRegister('d4', rs.d4) and
  321. Debugger^.GetIntRegister('d5', rs.d5) and
  322. Debugger^.GetIntRegister('d6', rs.d6) and
  323. Debugger^.GetIntRegister('d7', rs.d7) and
  324. Debugger^.GetIntRegister('a0', rs.a0) and
  325. Debugger^.GetIntRegister('a1', rs.a1) and
  326. Debugger^.GetIntRegister('a2', rs.a2) and
  327. Debugger^.GetIntRegister('a3', rs.a3) and
  328. Debugger^.GetIntRegister('a4', rs.a4) and
  329. Debugger^.GetIntRegister('a5', rs.a5) and
  330. Debugger^.GetIntRegister('fp', rs.fp) and
  331. Debugger^.GetIntRegister('sp', rs.sp) and
  332. Debugger^.GetIntRegister('ps', rs.ps) and
  333. Debugger^.GetIntRegister('pc', rs.pc);
  334. {$endif m68k}
  335. {$ifdef powerpc}
  336. GetIntRegs := true;
  337. for i:=0 to 31 do
  338. GetIntRegs := GetIntRegs and Debugger^.GetIntRegister('r'+inttostr(i), rs.r[i]);
  339. { other regs
  340. pc,ps,cr,lr,ctr,xer : dword; }
  341. GetIntRegs := GetIntRegs and
  342. Debugger^.GetIntRegister('pc', rs.pc) and
  343. Debugger^.GetIntRegister('ps', rs.ps) and
  344. Debugger^.GetIntRegister('lr', rs.lr) and
  345. Debugger^.GetIntRegister('ctr', rs.ctr) and
  346. Debugger^.GetIntRegister('xer', rs.xer);
  347. {$endif powerpc}
  348. {$ifdef sparc}
  349. GetIntRegs := true;
  350. for i:=0 to 7 do
  351. GetIntRegs := GetIntRegs and Debugger^.GetIntRegister('o'+inttostr(i), rs.o[i]);
  352. for i:=0 to 7 do
  353. if i = 6 then
  354. GetIntRegs := GetIntRegs and (Debugger^.GetIntRegister('i6', rs.i[6]) or Debugger^.GetIntRegister('fp', rs.i[6]))
  355. else
  356. GetIntRegs := GetIntRegs and Debugger^.GetIntRegister('i'+inttostr(i), rs.i[i]);
  357. for i:=0 to 7 do
  358. GetIntRegs := GetIntRegs and Debugger^.GetIntRegister('l'+inttostr(i), rs.l[i]);
  359. for i:=0 to 7 do
  360. GetIntRegs := GetIntRegs and Debugger^.GetIntRegister('g'+inttostr(i), rs.g[i]);
  361. GetIntRegs := GetIntRegs and
  362. Debugger^.GetIntRegister('y', rs.y) and
  363. Debugger^.GetIntRegister('psr', rs.psr) and
  364. Debugger^.GetIntRegister('wim', rs.wim) and
  365. Debugger^.GetIntRegister('tbs', rs.tbr) and
  366. Debugger^.GetIntRegister('pc', rs.pc) and
  367. Debugger^.GetIntRegister('npc', rs.npc) and
  368. Debugger^.GetIntRegister('fsr', rs.fsr) and
  369. Debugger^.GetIntRegister('csr', rs.csr);
  370. {$endif sparc}
  371. {$else cpu_known}
  372. Debugger^.Command('info registers');
  373. if Debugger^.Error then
  374. exit
  375. else
  376. begin
  377. i:=0;
  378. po:=StrNew(Debugger^.GetOutput);
  379. p:=po;
  380. if assigned(p) then
  381. begin
  382. fillchar(rs,sizeof(rs),0);
  383. p1:=strscan(p,' ');
  384. while assigned(p1) do
  385. begin
  386. p1:=strscan(p,#10);
  387. if assigned(p1) then
  388. begin
  389. strlcopy(buffer,p,p1-p);
  390. rs.reg[i]:=ExtractTabs(strpas(buffer),8);
  391. if i<MaxRegs-1 then
  392. inc(i);
  393. end;
  394. p:=strscan(p1,#10);
  395. if assigned(p) then
  396. begin
  397. p1:=strscan(p,' ');
  398. inc(p);
  399. end
  400. else
  401. break;
  402. end;
  403. { free allocated memory }
  404. strdispose(po);
  405. end
  406. else
  407. exit;
  408. end;
  409. { do not open a messagebox for such errors }
  410. Debugger^.got_error:=false;
  411. GetIntRegs:=true;
  412. {$endif cpu_known}
  413. {$endif not NODEBUG}
  414. end;
  415. constructor TRegistersView.Init(var Bounds: TRect);
  416. begin
  417. inherited init(Bounds);
  418. InDraw:=false;
  419. first:=true;
  420. FillChar(OldReg,Sizeof(OldReg),#0);
  421. FillChar(NewReg,Sizeof(NewReg),#0);
  422. GrowMode:=gfGrowHiX or GfGrowHiY;
  423. GDBCount:=-1;
  424. end;
  425. procedure TRegistersView.Draw;
  426. var
  427. rs : tintregs;
  428. OK : boolean;
  429. color :byte;
  430. i : byte;
  431. procedure SetColor(x,y : longint);
  432. begin
  433. if x=y then
  434. color:=7
  435. else
  436. color:=8;
  437. end;
  438. procedure SetColor(x,y : qword);
  439. begin
  440. if x=y then
  441. color:=7
  442. else
  443. color:=8;
  444. end;
  445. procedure SetStrColor(const x,y : string);
  446. begin
  447. if x=y then
  448. color:=7
  449. else
  450. color:=8;
  451. end;
  452. begin
  453. inherited draw;
  454. {$ifdef NODEBUG}
  455. WriteStr(1,0,msg_registervaluesnotavailable,7);
  456. {$else NODEBUG}
  457. If (not assigned(Debugger)) or (not Debugger^.IsRunning) then
  458. begin
  459. WriteStr(1,0,msg_registervaluesnotavailable,7);
  460. exit;
  461. end;
  462. if InDraw then exit;
  463. InDraw:=true;
  464. if GDBCount<>Debugger^.RunCount then
  465. begin
  466. OldReg:=NewReg;
  467. OK:=GetIntRegs(rs);
  468. LastOK:=OK;
  469. NewReg:=rs;
  470. { get inital values }
  471. if first then
  472. begin
  473. OldReg:=NewReg;
  474. first:=false;
  475. end;
  476. GDBCount:=Debugger^.RunCount;
  477. end
  478. else
  479. begin
  480. rs:=NewReg;
  481. OK:=LastOK;
  482. end;
  483. if OK then
  484. begin
  485. {$ifdef cpu_known}
  486. {$ifdef i386}
  487. SetColor(rs.eax,OldReg.eax);
  488. WriteStr(1,0,'EAX '+HexStr(longint(rs.eax),8),color);
  489. SetColor(rs.ebx,OldReg.ebx);
  490. WriteStr(1,1,'EBX '+HexStr(longint(rs.ebx),8),color);
  491. SetColor(rs.ecx,OldReg.ecx);
  492. WriteStr(1,2,'ECX '+HexStr(longint(rs.ecx),8),color);
  493. SetColor(rs.edx,OldReg.edx);
  494. WriteStr(1,3,'EDX '+HexStr(longint(rs.edx),8),color);
  495. SetColor(rs.eip,OldReg.eip);
  496. WriteStr(1,4,'EIP '+HexStr(longint(rs.eip),8),color);
  497. SetColor(rs.esi,OldReg.esi);
  498. WriteStr(1,5,'ESI '+HexStr(longint(rs.esi),8),color);
  499. SetColor(rs.edi,OldReg.edi);
  500. WriteStr(1,6,'EDI '+HexStr(longint(rs.edi),8),color);
  501. SetColor(rs.esp,OldReg.esp);
  502. WriteStr(1,7,'ESP '+HexStr(longint(rs.esp),8),color);
  503. SetColor(rs.ebp,OldReg.ebp);
  504. WriteStr(1,8,'EBP '+HexStr(longint(rs.ebp),8),color);
  505. SetColor(rs.cs,OldReg.cs);
  506. WriteStr(14,0,'CS '+HexStr(rs.cs,4),color);
  507. SetColor(rs.ds,OldReg.ds);
  508. WriteStr(14,1,'DS '+HexStr(rs.ds,4),color);
  509. SetColor(rs.es,OldReg.es);
  510. WriteStr(14,2,'ES '+HexStr(rs.es,4),color);
  511. SetColor(rs.fs,OldReg.fs);
  512. WriteStr(14,3,'FS '+HexStr(rs.fs,4),color);
  513. SetColor(rs.gs,OldReg.gs);
  514. WriteStr(14,4,'GS '+HexStr(rs.gs,4),color);
  515. SetColor(rs.ss,OldReg.ss);
  516. WriteStr(14,5,'SS '+HexStr(rs.ss,4),color);
  517. SetColor(rs.eflags and $1,OldReg.eflags and $1);
  518. WriteStr(22,0,'c='+chr(byte((rs.eflags and $1)<>0)+48),color);
  519. SetColor(rs.eflags and $20,OldReg.eflags and $20);
  520. WriteStr(22,1,'z='+chr(byte((rs.eflags and $20)<>0)+48),color);
  521. SetColor(rs.eflags and $80,OldReg.eflags and $80);
  522. WriteStr(22,2,'s='+chr(byte((rs.eflags and $80)<>0)+48),color);
  523. SetColor(rs.eflags and $800,OldReg.eflags and $800);
  524. WriteStr(22,3,'o='+chr(byte((rs.eflags and $800)<>0)+48),color);
  525. SetColor(rs.eflags and $4,OldReg.eflags and $4);
  526. WriteStr(22,4,'p='+chr(byte((rs.eflags and $4)<>0)+48),color);
  527. SetColor(rs.eflags and $200,OldReg.eflags and $200);
  528. WriteStr(22,5,'i='+chr(byte((rs.eflags and $200)<>0)+48),color);
  529. SetColor(rs.eflags and $10,OldReg.eflags and $10);
  530. WriteStr(22,6,'a='+chr(byte((rs.eflags and $10)<>0)+48),color);
  531. SetColor(rs.eflags and $400,OldReg.eflags and $400);
  532. WriteStr(22,7,'d='+chr(byte((rs.eflags and $400)<>0)+48),color);
  533. {$endif i386}
  534. {$ifdef x86_64}
  535. SetColor(rs.rax,OldReg.rax);
  536. WriteStr(1,0,'RAX '+HexStr(rs.rax,16),color);
  537. SetColor(rs.rbx,OldReg.rbx);
  538. WriteStr(1,1,'RBX '+HexStr(rs.rbx,16),color);
  539. SetColor(rs.rcx,OldReg.rcx);
  540. WriteStr(1,2,'RCX '+HexStr(rs.rcx,16),color);
  541. SetColor(rs.rdx,OldReg.rdx);
  542. WriteStr(1,3,'RDX '+HexStr(rs.rdx,16),color);
  543. SetColor(rs.rsi,OldReg.rsi);
  544. WriteStr(1,4,'RSI '+HexStr(rs.rsi,16),color);
  545. SetColor(rs.rdi,OldReg.rdi);
  546. WriteStr(1,5,'RDI '+HexStr(rs.rdi,16),color);
  547. SetColor(rs.rbp,OldReg.rbp);
  548. WriteStr(1,6,'RBP '+HexStr(rs.rbp,16),color);
  549. SetColor(rs.rsp,OldReg.rsp);
  550. WriteStr(1,7,'RSP '+HexStr(rs.rsp,16),color);
  551. SetColor(rs.r8,OldReg.r8);
  552. WriteStr(1,8,'R8 '+HexStr(rs.r8,16),color);
  553. SetColor(rs.r9,OldReg.r9);
  554. WriteStr(1,9,'R9 '+HexStr(rs.r9,16),color);
  555. SetColor(rs.r10,OldReg.r10);
  556. WriteStr(1,10,'R10 '+HexStr(rs.r10,16),color);
  557. SetColor(rs.r11,OldReg.r11);
  558. WriteStr(1,11,'R11 '+HexStr(rs.r11,16),color);
  559. SetColor(rs.r12,OldReg.r12);
  560. WriteStr(1,12,'R12 '+HexStr(rs.r12,16),color);
  561. SetColor(rs.r13,OldReg.r13);
  562. WriteStr(1,13,'R13 '+HexStr(rs.r13,16),color);
  563. SetColor(rs.r14,OldReg.r14);
  564. WriteStr(1,14,'R14 '+HexStr(rs.r14,16),color);
  565. SetColor(rs.r15,OldReg.r15);
  566. WriteStr(1,15,'R15 '+HexStr(rs.r15,16),color);
  567. SetColor(rs.rip,OldReg.rip);
  568. WriteStr(1,16,'RIP '+HexStr(rs.rip,16),color);
  569. SetColor(rs.cs,OldReg.cs);
  570. WriteStr(22,11,'CS '+HexStr(rs.cs,4),color);
  571. SetColor(rs.ds,OldReg.ds);
  572. WriteStr(22,12,'DS '+HexStr(rs.ds,4),color);
  573. SetColor(rs.es,OldReg.es);
  574. WriteStr(22,13,'ES '+HexStr(rs.es,4),color);
  575. SetColor(rs.fs,OldReg.fs);
  576. WriteStr(22,14,'FS '+HexStr(rs.fs,4),color);
  577. SetColor(rs.gs,OldReg.gs);
  578. WriteStr(22,15,'GS '+HexStr(rs.gs,4),color);
  579. SetColor(rs.ss,OldReg.ss);
  580. WriteStr(22,16,'SS '+HexStr(rs.ss,4),color);
  581. SetColor(rs.eflags and $1,OldReg.eflags and $1);
  582. WriteStr(24,0,'c='+chr(byte((rs.eflags and $1)<>0)+48),color);
  583. SetColor(rs.eflags and $20,OldReg.eflags and $20);
  584. WriteStr(24,1,'z='+chr(byte((rs.eflags and $20)<>0)+48),color);
  585. SetColor(rs.eflags and $80,OldReg.eflags and $80);
  586. WriteStr(24,2,'s='+chr(byte((rs.eflags and $80)<>0)+48),color);
  587. SetColor(rs.eflags and $800,OldReg.eflags and $800);
  588. WriteStr(24,3,'o='+chr(byte((rs.eflags and $800)<>0)+48),color);
  589. SetColor(rs.eflags and $4,OldReg.eflags and $4);
  590. WriteStr(24,4,'p='+chr(byte((rs.eflags and $4)<>0)+48),color);
  591. SetColor(rs.eflags and $200,OldReg.eflags and $200);
  592. WriteStr(24,5,'i='+chr(byte((rs.eflags and $200)<>0)+48),color);
  593. SetColor(rs.eflags and $10,OldReg.eflags and $10);
  594. WriteStr(24,6,'a='+chr(byte((rs.eflags and $10)<>0)+48),color);
  595. SetColor(rs.eflags and $400,OldReg.eflags and $400);
  596. WriteStr(24,7,'d='+chr(byte((rs.eflags and $400)<>0)+48),color);
  597. {$endif x86_64}
  598. {$ifdef m68k}
  599. SetColor(rs.d0,OldReg.d0);
  600. WriteStr(1,0,'d0 '+HexStr(longint(rs.d0),8),color);
  601. SetColor(rs.d1,OldReg.d1);
  602. WriteStr(1,1,'d1 '+HexStr(longint(rs.d1),8),color);
  603. SetColor(rs.d2,OldReg.d2);
  604. WriteStr(1,2,'d2 '+HexStr(longint(rs.d2),8),color);
  605. SetColor(rs.d3,OldReg.d3);
  606. WriteStr(1,3,'d3 '+HexStr(longint(rs.d3),8),color);
  607. SetColor(rs.d4,OldReg.d4);
  608. WriteStr(1,4,'d4 '+HexStr(longint(rs.d4),8),color);
  609. SetColor(rs.d5,OldReg.d5);
  610. WriteStr(1,5,'d5 '+HexStr(longint(rs.d5),8),color);
  611. SetColor(rs.d6,OldReg.d6);
  612. WriteStr(1,6,'d6 '+HexStr(longint(rs.d6),8),color);
  613. SetColor(rs.d7,OldReg.d7);
  614. WriteStr(1,7,'d7 '+HexStr(longint(rs.d7),8),color);
  615. SetColor(rs.a0,OldReg.a0);
  616. WriteStr(14,0,'a0 '+HexStr(longint(rs.a0),8),color);
  617. SetColor(rs.a1,OldReg.a1);
  618. WriteStr(14,1,'a1 '+HexStr(longint(rs.a1),8),color);
  619. SetColor(rs.a2,OldReg.a2);
  620. WriteStr(14,2,'a2 '+HexStr(longint(rs.a2),8),color);
  621. SetColor(rs.a3,OldReg.a3);
  622. WriteStr(14,3,'a3 '+HexStr(longint(rs.a3),8),color);
  623. SetColor(rs.a4,OldReg.a4);
  624. WriteStr(14,4,'a4 '+HexStr(longint(rs.a4),8),color);
  625. SetColor(rs.a5,OldReg.a5);
  626. WriteStr(14,5,'a5 '+HexStr(longint(rs.a5),8),color);
  627. SetColor(rs.fp,OldReg.fp);
  628. WriteStr(14,6,'fp '+HexStr(longint(rs.fp),8),color);
  629. SetColor(rs.sp,OldReg.sp);
  630. WriteStr(14,7,'sp '+HexStr(longint(rs.sp),8),color);
  631. SetColor(rs.pc,OldReg.pc);
  632. WriteStr(1,8,'pc '+HexStr(longint(rs.pc),8),color);
  633. SetColor(rs.ps and $1,OldReg.ps and $1);
  634. WriteStr(22,8,' c'+chr(byte((rs.ps and $1)<>0)+48),color);
  635. SetColor(rs.ps and $2,OldReg.ps and $2);
  636. WriteStr(19,8,' v'+chr(byte((rs.ps and $2)<>0)+48),color);
  637. SetColor(rs.ps and $4,OldReg.ps and $4);
  638. WriteStr(16,8,' z'+chr(byte((rs.ps and $4)<>0)+48),color);
  639. SetColor(rs.ps and $8,OldReg.ps and $8);
  640. WriteStr(14,8, 'x'+chr(byte((rs.ps and $8)<>0)+48),color);
  641. {$endif m68k}
  642. {$ifdef powerpc}
  643. for i:=0 to 15 do
  644. begin
  645. SetColor(rs.r[i],OldReg.r[i]);
  646. if i<10 then
  647. WriteStr(1,i,'r'+IntToStr(i)+' '+HexStr(longint(rs.r[i]),8),color)
  648. else
  649. WriteStr(1,i,'r'+IntToStr(i)+' '+HexStr(longint(rs.r[i]),8),color);
  650. end;
  651. for i:=16 to 31 do
  652. begin
  653. SetColor(rs.r[i],OldReg.r[i]);
  654. WriteStr(15,i-16,'r'+IntToStr(i)+' '+HexStr(longint(rs.r[i]),8),color);
  655. end;
  656. { other regs pc,ps,cr,lr,ctr,xer : dword; }
  657. SetColor(rs.pc,OldReg.pc);
  658. WriteStr(1,16,'pc '+HexStr(longint(rs.pc),8),color);
  659. SetColor(rs.ps,OldReg.ps);
  660. WriteStr(15,16,'ps '+HexStr(longint(rs.ps),8),color);
  661. SetColor(rs.lr,OldReg.lr);
  662. WriteStr(1,17,'lr '+HexStr(longint(rs.lr),8),color);
  663. SetColor(rs.ctr,OldReg.ctr);
  664. WriteStr(15,17,'ctr '+HexStr(longint(rs.ctr),8),color);
  665. SetColor(rs.xer,OldReg.xer);
  666. WriteStr(15,18,'xer '+HexStr(longint(rs.xer),8),color);
  667. {$endif powerpc}
  668. {$ifdef sparc}
  669. for i:=0 to 7 do
  670. begin
  671. SetColor(rs.g[i],OldReg.g[i]);
  672. WriteStr(1,i,'g'+IntToStr(i)+' '+HexStr(longint(rs.g[i]),8),color);
  673. SetColor(rs.l[i],OldReg.l[i]);
  674. WriteStr(1,i+8,'l'+IntToStr(i)+' '+HexStr(longint(rs.l[i]),8),color);
  675. end;
  676. for i:=0 to 7 do
  677. begin
  678. SetColor(rs.i[i],OldReg.i[i]);
  679. if i=6 then
  680. WriteStr(15,i,'fp '+HexStr(longint(rs.i[i]),8),color)
  681. else
  682. WriteStr(15,i,'i'+IntToStr(i)+' '+HexStr(longint(rs.i[i]),8),color);
  683. SetColor(rs.o[i],OldReg.o[i]);
  684. WriteStr(15,i+8,'o'+IntToStr(i)+' '+HexStr(longint(rs.o[i]),8),color);
  685. end;
  686. SetColor(rs.pc,OldReg.pc);
  687. WriteStr(1,16,'pc '+HexStr(longint(rs.pc),8),color);
  688. SetColor(rs.y,OldReg.y);
  689. WriteStr(1,17,'y '+HexStr(longint(rs.y),8),color);
  690. SetColor(rs.psr,OldReg.psr);
  691. WriteStr(1,18,'psr '+HexStr(longint(rs.psr),8),color);
  692. SetColor(rs.csr,OldReg.csr);
  693. WriteStr(1,19,'csr '+HexStr(longint(rs.csr),8),color);
  694. SetColor(rs.npc,OldReg.npc);
  695. WriteStr(15,16,'npc '+HexStr(longint(rs.npc),8),color);
  696. SetColor(rs.tbr,OldReg.tbr);
  697. WriteStr(15,17,'tbr '+HexStr(longint(rs.tbr),8),color);
  698. SetColor(rs.wim,OldReg.wim);
  699. WriteStr(15,18,'wim '+HexStr(longint(rs.wim),8),color);
  700. SetColor(rs.fsr,OldReg.fsr);
  701. WriteStr(15,19,'fsr '+HexStr(longint(rs.fsr),8),color);
  702. {$endif sparc}
  703. {$else cpu_known}
  704. for i:=0 to MaxRegs-1 do
  705. begin
  706. SetStrColor(rs.reg[i],OldReg.reg[i]);
  707. WriteStr(1,i,rs.reg[i],color);
  708. end;
  709. {$endif cpu_known}
  710. end
  711. else
  712. WriteStr(0,0,msg_registerwindowerror,7);
  713. InDraw:=false;
  714. {$endif NODEBUG}
  715. end;
  716. destructor TRegistersView.Done;
  717. begin
  718. inherited done;
  719. end;
  720. {****************************************************************************
  721. TRegistersWindow
  722. ****************************************************************************}
  723. constructor TRegistersWindow.Init;
  724. var
  725. R : TRect;
  726. begin
  727. Desktop^.GetExtent(R);
  728. {$ifdef i386}
  729. R.A.X:=R.B.X-28;
  730. R.B.Y:=R.A.Y+11;
  731. {$endif i386}
  732. {$ifdef x86_64}
  733. R.A.X:=R.B.X-32;
  734. R.B.Y:=R.A.Y+19;
  735. {$endif x86_64}
  736. {$ifdef m68k}
  737. R.A.X:=R.B.X-28;
  738. R.B.Y:=R.A.Y+11;
  739. {$endif m68k}
  740. {$ifdef powerpc}
  741. R.A.X:=R.B.X-30;
  742. R.B.Y:=R.A.Y+21;
  743. {$endif powerpc}
  744. {$ifdef sparc}
  745. R.A.X:=R.B.X-30;
  746. R.B.Y:=R.A.Y+22;
  747. {$endif sparc}
  748. {$ifndef cpu_known}
  749. R.A.X:=R.B.X-28;
  750. R.B.Y:=R.A.Y+22;
  751. {$endif cpu_known}
  752. inherited Init(R,dialog_registers, wnNoNumber);
  753. Flags:=wfClose or wfMove;
  754. {$ifndef cpu_known}
  755. Flags:=Flags or wfgrow;
  756. {$endif cpu_known}
  757. Palette:=wpCyanWindow;
  758. HelpCtx:=hcRegistersWindow;
  759. R.Assign(1,1,Size.X-2,Size.Y-1);
  760. RV:=new(PRegistersView,init(R));
  761. Insert(RV);
  762. If assigned(RegistersWindow) then
  763. dispose(RegistersWindow,done);
  764. RegistersWindow:=@Self;
  765. Update;
  766. end;
  767. constructor TRegistersWindow.Load(var S: TStream);
  768. begin
  769. inherited load(S);
  770. GetSubViewPtr(S,RV);
  771. If assigned(RegistersWindow) then
  772. dispose(RegistersWindow,done);
  773. RegistersWindow:=@Self;
  774. end;
  775. procedure TRegistersWindow.Store(var S: TStream);
  776. begin
  777. inherited Store(s);
  778. PutSubViewPtr(S,RV);
  779. end;
  780. procedure TRegistersWindow.Update;
  781. begin
  782. ReDraw;
  783. end;
  784. destructor TRegistersWindow.Done;
  785. begin
  786. RegistersWindow:=nil;
  787. inherited done;
  788. end;
  789. {****************************************************************************
  790. TFPUView
  791. ****************************************************************************}
  792. function GetFPURegs(var rs : TFPURegs
  793. {$ifndef cpu_known}
  794. ; UseInfoFloat : boolean
  795. {$endif not cpu_known}
  796. ) : boolean;
  797. var
  798. p,po : PAnsiChar;
  799. p1 : PAnsiChar;
  800. {$ifndef NODEBUG}
  801. reg,value : string;
  802. buffer : array[0..255] of AnsiChar;
  803. v : string;
  804. res : cardinal;
  805. i : longint;
  806. err : word;
  807. {$endif}
  808. begin
  809. GetFPURegs:=false;
  810. {$ifndef NODEBUG}
  811. {$ifndef cpu_known}
  812. if UseInfoFloat then
  813. begin
  814. Debugger^.Command('info float');
  815. if Debugger^.Error then
  816. begin
  817. UseInfofloat:=false;
  818. Debugger^.Command('info all');
  819. end;
  820. end
  821. else
  822. {$endif not cpu_known}
  823. Debugger^.Command('info all');
  824. if Debugger^.Error then
  825. exit
  826. else
  827. begin
  828. po:=StrNew(Debugger^.GetOutput);
  829. p:=po;
  830. {$ifndef cpu_known}
  831. i:=0;
  832. {$endif not cpu_known}
  833. if assigned(p) then
  834. begin
  835. fillchar(rs,sizeof(rs),0);
  836. p1:=strscan(p,' ');
  837. while assigned(p1) do
  838. begin
  839. strlcopy(buffer,p,p1-p);
  840. reg:=strpas(buffer);
  841. {$ifndef cpu_known}
  842. p1:=strscan(p,#10);
  843. if assigned(p1) then
  844. begin
  845. strlcopy(buffer,p,p1-p);
  846. rs.freg[i]:=ExtractTabs(strpas(buffer),8);
  847. if i<MaxRegs-1 then
  848. inc(i);
  849. end;
  850. {$else cpu_known}
  851. p:=p1;
  852. while p^=' ' do
  853. inc(p);
  854. if p^='$' then
  855. p1:=strscan(p,#9)
  856. else
  857. p1:=strscan(p,#10);
  858. strlcopy(buffer,p,p1-p);
  859. v:=strpas(buffer);
  860. for i:=1 to length(v) do
  861. if v[i]=#9 then
  862. v[i]:=' ';
  863. val(v,res,err);
  864. {$if defined(i386) or defined(x86_64)}
  865. if reg='st0' then
  866. rs.st0:=v
  867. else if reg='st1' then
  868. rs.st1:=v
  869. else if reg='st2' then
  870. rs.st2:=v
  871. else if reg='st3' then
  872. rs.st3:=v
  873. else if reg='st4' then
  874. rs.st4:=v
  875. else if reg='st5' then
  876. rs.st5:=v
  877. else if reg='st6' then
  878. rs.st6:=v
  879. else if reg='st7' then
  880. rs.st7:=v
  881. else if reg='ftag' then
  882. rs.ftag:=res
  883. else if reg='fctrl' then
  884. rs.fctrl:=res
  885. else if reg='fstat' then
  886. rs.fstat:=res
  887. else if reg='fiseg' then
  888. rs.fiseg:=res
  889. else if reg='fioff' then
  890. rs.fioff:=res
  891. else if reg='foseg' then
  892. rs.foseg:=res
  893. else if reg='fooff' then
  894. rs.fooff:=res
  895. else if reg='fop' then
  896. rs.fop:=res;
  897. {$endif i386 or x86_64}
  898. {$ifdef m68k}
  899. if reg='fp0' then
  900. rs.fp0:=v
  901. else if reg='fp1' then
  902. rs.fp1:=v
  903. else if reg='fp2' then
  904. rs.fp2:=v
  905. else if reg='fp3' then
  906. rs.fp3:=v
  907. else if reg='fp4' then
  908. rs.fp4:=v
  909. else if reg='fp5' then
  910. rs.fp5:=v
  911. else if reg='fp6' then
  912. rs.fp6:=v
  913. else if reg='fp7' then
  914. rs.fp7:=v
  915. else if reg='fpcontrol' then
  916. rs.fpcontrol:=res
  917. else if reg='fpstatus' then
  918. rs.fpstatus:=res
  919. else if reg='fpiaddr' then
  920. rs.fpiaddr:=res;
  921. {$endif m68k}
  922. {$ifdef powerpc}
  923. if reg[1]='f' then
  924. for i:=0 to 31 do
  925. if reg='f'+inttostr(i) then
  926. rs.f[i]:=v;
  927. {$endif powerpc}
  928. {$ifdef sparc}
  929. if reg[1]='f' then
  930. for i:=0 to 31 do
  931. if reg='f'+inttostr(i) then
  932. rs.f[i]:=v;
  933. {$endif sparc}
  934. {$endif cpu_known}
  935. p:=strscan(p1,#10);
  936. if assigned(p) then
  937. begin
  938. p1:=strscan(p,' ');
  939. inc(p);
  940. end
  941. else
  942. break;
  943. end;
  944. { free allocated memory }
  945. strdispose(po);
  946. end
  947. else
  948. exit;
  949. end;
  950. { do not open a messagebox for such errors }
  951. Debugger^.got_error:=false;
  952. GetFPURegs:=true;
  953. {$endif}
  954. end;
  955. constructor TFPUView.Init(var Bounds: TRect);
  956. begin
  957. inherited init(Bounds);
  958. GrowMode:=gfGrowHiX or GfGrowHiY;
  959. InDraw:=false;
  960. first:=true;
  961. FillChar(OldReg,Sizeof(oldreg),#0);
  962. FillChar(NewReg,Sizeof(newreg),#0);
  963. GDBCount:=-1;
  964. {$ifndef cpu_known}
  965. UseInfoFloat:=true;
  966. {$endif not cpu_known}
  967. end;
  968. procedure TFPUView.Draw;
  969. var
  970. rs : tfpuregs;
  971. top : byte;
  972. color :byte;
  973. ok : boolean;
  974. i : byte;
  975. const
  976. TypeStr : Array[0..3] of string[6] =
  977. ('Valid ','Zero ','Spec ','Empty ');
  978. procedure SetColor(Const x,y : string);
  979. begin
  980. if x=y then
  981. color:=7
  982. else
  983. color:=8;
  984. end;
  985. procedure SetIColor(Const x,y : cardinal);
  986. begin
  987. if x=y then
  988. color:=7
  989. else
  990. color:=8;
  991. end;
  992. begin
  993. inherited draw;
  994. {$ifdef NODEBUG}
  995. WriteStr(1,0,msg_registervaluesnotavailable,7);
  996. {$else NODEBUG}
  997. If (not assigned(Debugger)) or (not Debugger^.IsRunning) then
  998. begin
  999. WriteStr(1,0,msg_registervaluesnotavailable,7);
  1000. exit;
  1001. end;
  1002. if InDraw then
  1003. exit;
  1004. InDraw:=true;
  1005. if GDBCount<>Debugger^.RunCount then
  1006. begin
  1007. OldReg:=NewReg;
  1008. OK:=GetFPURegs(rs
  1009. {$ifndef cpu_known}
  1010. ,UseInfoFloat
  1011. {$endif not cpu_known}
  1012. );
  1013. LastOK:=OK;
  1014. NewReg:=rs;
  1015. { get inital values }
  1016. if first then
  1017. begin
  1018. OldReg:=NewReg;
  1019. first:=false;
  1020. end;
  1021. GDBCount:=Debugger^.RunCount;
  1022. end
  1023. else
  1024. begin
  1025. rs:=newreg;
  1026. OK:=LastOK;
  1027. end;
  1028. if OK then
  1029. begin
  1030. {$ifdef cpu_known}
  1031. {$if defined(i386) or defined(x86_64)}
  1032. top:=(rs.fstat shr 11) and 7;
  1033. SetColor(rs.st0,OldReg.st0);
  1034. WriteStr(1,0,'ST0 '+TypeStr[(rs.ftag shr (2*((0+top) and 7))) and 3]+rs.st0,color);
  1035. SetColor(rs.st1,OldReg.st1);
  1036. WriteStr(1,1,'ST1 '+TypeStr[(rs.ftag shr (2*((1+top) and 7))) and 3]+rs.st1,color);
  1037. SetColor(rs.st2,OldReg.st2);
  1038. WriteStr(1,2,'ST2 '+TypeStr[(rs.ftag shr (2*((2+top) and 7))) and 3]+rs.st2,color);
  1039. SetColor(rs.st3,OldReg.st3);
  1040. WriteStr(1,3,'ST3 '+TypeStr[(rs.ftag shr (2*((3+top) and 7))) and 3]+rs.st3,color);
  1041. SetColor(rs.st4,OldReg.st4);
  1042. WriteStr(1,4,'ST4 '+TypeStr[(rs.ftag shr (2*((4+top) and 7))) and 3]+rs.st4,color);
  1043. SetColor(rs.st5,OldReg.st5);
  1044. WriteStr(1,5,'ST5 '+TypeStr[(rs.ftag shr (2*((5+top) and 7))) and 3]+rs.st5,color);
  1045. SetColor(rs.st6,OldReg.st6);
  1046. WriteStr(1,6,'ST6 '+TypeStr[(rs.ftag shr (2*((6+top) and 7))) and 3]+rs.st6,color);
  1047. SetColor(rs.st7,OldReg.st7);
  1048. WriteStr(1,7,'ST7 '+TypeStr[(rs.ftag shr (2*((7+top) and 7))) and 3]+rs.st7,color);
  1049. SetIColor(rs.ftag,OldReg.ftag);
  1050. WriteStr(1,8,'FTAG '+hexstr(rs.ftag,4),color);
  1051. SetIColor(rs.fctrl,OldReg.fctrl);
  1052. WriteStr(13,8,'FCTRL '+hexstr(rs.fctrl,4),color);
  1053. SetIColor(rs.fstat,OldReg.fstat);
  1054. WriteStr(1,9,'FSTAT '+hexstr(rs.fstat,4),color);
  1055. SetIColor(rs.fop,OldReg.fop);
  1056. WriteStr(13,9,'FOP '+hexstr(rs.fop,4),color);
  1057. if (rs.fiseg<>OldReg.fiseg) or
  1058. (rs.fioff<>OldReg.fioff) then
  1059. color:=8
  1060. else
  1061. color:=7;
  1062. WriteStr(1,10,'FI '+hexstr(rs.fiseg,4)+':'+hexstr(rs.fioff,8),color);
  1063. if (rs.foseg<>OldReg.foseg) or
  1064. (rs.fooff<>OldReg.fooff) then
  1065. color:=8
  1066. else
  1067. color:=7;
  1068. WriteStr(1,11,'FO '+hexstr(rs.foseg,4)+':'+hexstr(rs.fooff,8),color);
  1069. {$endif i386 or x86_64}
  1070. {$ifdef m68k}
  1071. SetColor(rs.fp0,OldReg.fp0);
  1072. WriteStr(1,0,'fp0 '+rs.fp0,color);
  1073. SetColor(rs.fp1,OldReg.fp1);
  1074. WriteStr(1,1,'fp1 '+rs.fp1,color);
  1075. SetColor(rs.fp2,OldReg.fp2);
  1076. WriteStr(1,2,'fp2 '+rs.fp2,color);
  1077. SetColor(rs.fp3,OldReg.fp3);
  1078. WriteStr(1,3,'fp3 '+rs.fp3,color);
  1079. SetColor(rs.fp4,OldReg.fp4);
  1080. WriteStr(1,4,'fp4 '+rs.fp4,color);
  1081. SetColor(rs.fp5,OldReg.fp5);
  1082. WriteStr(1,5,'fp5 '+rs.fp5,color);
  1083. SetColor(rs.fp6,OldReg.fp6);
  1084. WriteStr(1,6,'fp6 '+rs.fp6,color);
  1085. SetColor(rs.fp7,OldReg.fp7);
  1086. WriteStr(1,7,'fp7 '+rs.fp7,color);
  1087. SetIColor(rs.fpcontrol,OldReg.fpcontrol);
  1088. WriteStr(1,8,'fpcontrol '+hexstr(rs.fpcontrol,8),color);
  1089. SetIColor(rs.fpstatus,OldReg.fpstatus);
  1090. WriteStr(1,9,'fpstatus '+hexstr(rs.fpstatus,8),color);
  1091. SetIColor(rs.fpiaddr,OldReg.fpiaddr);
  1092. WriteStr(1,10,'fpiaddr '+hexstr(rs.fpiaddr,8),color);
  1093. {$endif m68k}
  1094. {$ifdef powerpc}
  1095. for i:=0 to 31 do
  1096. begin
  1097. SetColor(rs.f[i],OldReg.f[i]);
  1098. if i<10 then
  1099. WriteStr(1,i,'f'+IntToStr(i)+' '+rs.f[i],color)
  1100. else
  1101. WriteStr(1,i,'f'+IntToStr(i)+' '+rs.f[i],color);
  1102. end;
  1103. {$endif powerpc}
  1104. {$ifdef sparc}
  1105. for i:=0 to 31 do
  1106. begin
  1107. SetColor(rs.f[i],OldReg.f[i]);
  1108. if i<10 then
  1109. WriteStr(1,i,'f'+IntToStr(i)+' '+rs.f[i],color)
  1110. else
  1111. WriteStr(1,i,'f'+IntToStr(i)+' '+rs.f[i],color);
  1112. end;
  1113. {$endif sparc}
  1114. {$else not cpu_known}
  1115. for i:=0 to MaxRegs-1 do
  1116. begin
  1117. SetColor(rs.freg[i],OldReg.freg[i]);
  1118. WriteStr(1,i,rs.freg[i],color);
  1119. end;
  1120. {$endif cpu_known}
  1121. end
  1122. else
  1123. WriteStr(0,0,msg_registerwindowerror,7);
  1124. InDraw:=false;
  1125. {$endif NODEBUG}
  1126. end;
  1127. destructor TFPUView.Done;
  1128. begin
  1129. inherited done;
  1130. end;
  1131. {****************************************************************************
  1132. TFPUWindow
  1133. ****************************************************************************}
  1134. constructor TFPUWindow.Init;
  1135. var
  1136. R : TRect;
  1137. begin
  1138. Desktop^.GetExtent(R);
  1139. {$if defined(i386) or defined(x86_64)}
  1140. R.A.X:=R.B.X-44;
  1141. R.B.Y:=R.A.Y+14;
  1142. {$endif i386 or x86_64}
  1143. {$ifdef m68k}
  1144. R.A.X:=R.B.X-44;
  1145. R.B.Y:=R.A.Y+14;
  1146. {$endif m68k}
  1147. {$ifdef powerpc}
  1148. R.A.X:=R.B.X-44;
  1149. R.B.Y:=R.A.Y+33;
  1150. {$endif powerpc}
  1151. {$ifdef sparc}
  1152. R.A.X:=R.B.X-44;
  1153. R.B.Y:=R.A.Y+33;
  1154. {$endif sparc}
  1155. {$ifndef cpu_known}
  1156. R.A.X:=R.B.X-44;
  1157. R.B.Y:=R.A.Y+33;
  1158. {$endif cpu_known}
  1159. inherited Init(R,dialog_fpu, wnNoNumber);
  1160. Flags:=wfClose or wfMove or wfgrow;
  1161. Palette:=wpCyanWindow;
  1162. HelpCtx:=hcFPURegisters;
  1163. R.Assign(1,1,Size.X-2,Size.Y-1);
  1164. RV:=new(PFPUView,init(R));
  1165. Insert(RV);
  1166. If assigned(FPUWindow) then
  1167. dispose(FPUWindow,done);
  1168. FPUWindow:=@Self;
  1169. Update;
  1170. end;
  1171. constructor TFPUWindow.Load(var S: TStream);
  1172. begin
  1173. inherited load(S);
  1174. GetSubViewPtr(S,RV);
  1175. If assigned(FPUWindow) then
  1176. dispose(FPUWindow,done);
  1177. FPUWindow:=@Self;
  1178. end;
  1179. procedure TFPUWindow.Store(var S: TStream);
  1180. begin
  1181. inherited Store(s);
  1182. PutSubViewPtr(S,RV);
  1183. end;
  1184. procedure TFPUWindow.Update;
  1185. begin
  1186. ReDraw;
  1187. end;
  1188. destructor TFPUWindow.Done;
  1189. begin
  1190. FPUWindow:=nil;
  1191. inherited done;
  1192. end;
  1193. {****************************************************************************
  1194. TVectorView
  1195. ****************************************************************************}
  1196. function GetVectorRegs(var rs : TVectorRegs
  1197. {$ifndef cpu_known}
  1198. ; UseInfoVector : boolean
  1199. {$endif not cpu_known}
  1200. ) : boolean;
  1201. var
  1202. p,po : PAnsiChar;
  1203. p1 : PAnsiChar;
  1204. {$ifndef NODEBUG}
  1205. reg,value : string;
  1206. buffer : array[0..255] of AnsiChar;
  1207. v : string;
  1208. res : cardinal;
  1209. i : longint;
  1210. err : word;
  1211. {$endif}
  1212. begin
  1213. GetVectorRegs:=false;
  1214. {$ifndef NODEBUG}
  1215. {$ifndef cpu_known}
  1216. if UseInfoVector then
  1217. begin
  1218. Debugger^.Command('info vector');
  1219. if Debugger^.Error then
  1220. begin
  1221. UseInfoVector:=false;
  1222. Debugger^.Command('info all');
  1223. end;
  1224. end
  1225. else
  1226. {$endif not cpu_known}
  1227. Debugger^.Command('info vector');
  1228. if Debugger^.Error then
  1229. exit
  1230. else
  1231. begin
  1232. po:=StrNew(Debugger^.GetOutput);
  1233. p:=po;
  1234. {$ifndef cpu_known}
  1235. i:=0;
  1236. {$endif not cpu_known}
  1237. if assigned(p) then
  1238. begin
  1239. fillchar(rs,sizeof(rs),0);
  1240. p1:=strscan(p,' ');
  1241. while assigned(p1) do
  1242. begin
  1243. strlcopy(buffer,p,p1-p);
  1244. reg:=strpas(buffer);
  1245. {$ifndef cpu_known}
  1246. p1:=strscan(p,#10);
  1247. if assigned(p1) then
  1248. begin
  1249. strlcopy(buffer,p,p1-p);
  1250. rs.vreg[i]:=ExtractTabs(strpas(buffer),8);
  1251. if i<MaxRegs-1 then
  1252. inc(i);
  1253. end;
  1254. {$else cpu_known}
  1255. p:=p1;
  1256. while p^=' ' do
  1257. inc(p);
  1258. if p^='$' then
  1259. p1:=strscan(p,#9)
  1260. else
  1261. p1:=strscan(p,#10);
  1262. strlcopy(buffer,p,p1-p);
  1263. v:=strpas(buffer);
  1264. for i:=1 to length(v) do
  1265. if v[i]=#9 then
  1266. v[i]:=' ';
  1267. val(v,res,err);
  1268. {$if defined(i386) or defined(x86_64)}
  1269. if reg[1]='x' then
  1270. for i:=0 to 7 do
  1271. begin
  1272. if reg='xmm'+inttostr(i) then
  1273. rs.xmm[i]:=v
  1274. end
  1275. else if reg='mxcsr' then
  1276. rs.mxcsr:=v
  1277. else if reg[1]='m' then
  1278. for i:=0 to 7 do
  1279. begin
  1280. if reg='mm'+inttostr(i) then
  1281. rs.mmx[i]:=v;
  1282. end;
  1283. {$endif i386 or x86_64}
  1284. {$ifdef powerpc}
  1285. { !!!! fixme }
  1286. if reg[1]='v' then
  1287. for i:=0 to 31 do
  1288. if reg='v'+inttostr(i) then
  1289. rs.m[i]:=v;
  1290. {$endif powerpc}
  1291. {$ifdef sparc}
  1292. {$endif sparc}
  1293. {$endif cpu_known}
  1294. p:=strscan(p1,#10);
  1295. if assigned(p) then
  1296. begin
  1297. p1:=strscan(p,' ');
  1298. inc(p);
  1299. end
  1300. else
  1301. break;
  1302. end;
  1303. { free allocated memory }
  1304. strdispose(po);
  1305. end
  1306. else
  1307. exit;
  1308. end;
  1309. { do not open a messagebox for such errors }
  1310. Debugger^.got_error:=false;
  1311. GetVectorRegs:=true;
  1312. {$endif}
  1313. end;
  1314. constructor TVectorView.Init(var Bounds: TRect);
  1315. begin
  1316. inherited init(Bounds);
  1317. GrowMode:=gfGrowHiX or GfGrowHiY;
  1318. InDraw:=false;
  1319. first:=true;
  1320. FillChar(OldReg,Sizeof(oldreg),#0);
  1321. FillChar(NewReg,Sizeof(newreg),#0);
  1322. GDBCount:=-1;
  1323. {$ifndef cpu_known}
  1324. UseInfoVector:=true;
  1325. {$endif not cpu_known}
  1326. end;
  1327. procedure TVectorView.Draw;
  1328. var
  1329. rs : tVectorregs;
  1330. top : byte;
  1331. color :byte;
  1332. ok : boolean;
  1333. i : byte;
  1334. const
  1335. TypeStr : Array[0..3] of string[6] =
  1336. ('Valid ','Zero ','Spec ','Empty ');
  1337. procedure SetColor(Const x,y : string);
  1338. begin
  1339. if x=y then
  1340. color:=7
  1341. else
  1342. color:=8;
  1343. end;
  1344. procedure SetIColor(Const x,y : cardinal);
  1345. begin
  1346. if x=y then
  1347. color:=7
  1348. else
  1349. color:=8;
  1350. end;
  1351. begin
  1352. inherited draw;
  1353. {$ifdef NODEBUG}
  1354. WriteStr(1,0,msg_registervaluesnotavailable,7);
  1355. {$else NODEBUG}
  1356. If (not assigned(Debugger)) or (not Debugger^.IsRunning) then
  1357. begin
  1358. WriteStr(1,0,msg_registervaluesnotavailable,7);
  1359. exit;
  1360. end;
  1361. if InDraw then
  1362. exit;
  1363. InDraw:=true;
  1364. if GDBCount<>Debugger^.RunCount then
  1365. begin
  1366. OldReg:=NewReg;
  1367. OK:=GetVectorRegs(rs
  1368. {$ifndef cpu_known}
  1369. ,UseInfoVector
  1370. {$endif not cpu_known}
  1371. );
  1372. LastOK:=OK;
  1373. NewReg:=rs;
  1374. { get inital values }
  1375. if first then
  1376. begin
  1377. OldReg:=NewReg;
  1378. first:=false;
  1379. end;
  1380. GDBCount:=Debugger^.RunCount;
  1381. end
  1382. else
  1383. begin
  1384. rs:=newreg;
  1385. OK:=LastOK;
  1386. end;
  1387. if OK then
  1388. begin
  1389. {$ifdef cpu_known}
  1390. {$if defined(i386) or defined(x86_64)}
  1391. for i:=0 to 7 do
  1392. begin
  1393. SetColor(rs.xmm[i],OldReg.xmm[i]);
  1394. WriteStr(1,i,'xmm'+IntToStr(i)+' '+rs.xmm[i],color);
  1395. end;
  1396. SetColor(rs.mxcsr,OldReg.mxcsr);
  1397. WriteStr(1,8,'mxcsr'+IntToStr(i)+' '+rs.mxcsr,color);
  1398. for i:=0 to 7 do
  1399. begin
  1400. SetColor(rs.mmx[i],OldReg.mmx[i]);
  1401. WriteStr(1,i+9,'mmx'+IntToStr(i)+' '+rs.mmx[i],color);
  1402. end;
  1403. {$endif i386 or x86_64}
  1404. {$ifdef powerpc}
  1405. for i:=0 to 31 do
  1406. begin
  1407. SetColor(rs.m[i],OldReg.m[i]);
  1408. if i<10 then
  1409. WriteStr(1,i,'m'+IntToStr(i)+' '+rs.m[i],color)
  1410. else
  1411. WriteStr(1,i,'m'+IntToStr(i)+' '+rs.m[i],color);
  1412. end;
  1413. {$endif powerpc}
  1414. {$ifdef sparc}
  1415. { no mm regs on the sparc }
  1416. {$endif sparc}
  1417. {$else not cpu_known}
  1418. for i:=0 to MaxRegs-1 do
  1419. begin
  1420. SetColor(rs.vreg[i],OldReg.vreg[i]);
  1421. WriteStr(1,i,rs.vreg[i],color);
  1422. end;
  1423. {$endif cpu_known}
  1424. end
  1425. else
  1426. WriteStr(0,0,msg_registerwindowerror,7);
  1427. InDraw:=false;
  1428. {$endif NODEBUG}
  1429. end;
  1430. destructor TVectorView.Done;
  1431. begin
  1432. inherited done;
  1433. end;
  1434. {****************************************************************************
  1435. TVectorWindow
  1436. ****************************************************************************}
  1437. constructor TVectorWindow.Init;
  1438. var
  1439. R : TRect;
  1440. begin
  1441. Desktop^.GetExtent(R);
  1442. {$if defined(i386) or defined(x86_64)}
  1443. R.A.X:=R.B.X-60;
  1444. R.B.Y:=R.A.Y+20;
  1445. {$endif i386 or x86_64}
  1446. {$ifdef m68k}
  1447. R.A.X:=R.B.X-60;
  1448. R.B.Y:=R.A.Y+14;
  1449. {$endif m68k}
  1450. {$ifdef powerpc}
  1451. R.A.X:=R.B.X-60;
  1452. R.B.Y:=R.A.Y+33;
  1453. {$endif powerpc}
  1454. {$ifdef sparc}
  1455. R.A.X:=R.B.X-60;
  1456. R.B.Y:=R.A.Y+33;
  1457. {$endif sparc}
  1458. {$ifndef cpu_known}
  1459. R.A.X:=R.B.X-60;
  1460. R.B.Y:=R.A.Y+33;
  1461. {$endif cpu_known}
  1462. inherited Init(R,dialog_Vector, wnNoNumber);
  1463. Flags:=wfClose or wfMove or wfgrow;
  1464. Palette:=wpCyanWindow;
  1465. HelpCtx:=hcVectorRegisters;
  1466. R.Assign(1,1,Size.X-2,Size.Y-1);
  1467. RV:=new(PVectorView,init(R));
  1468. Insert(RV);
  1469. If assigned(VectorWindow) then
  1470. dispose(VectorWindow,done);
  1471. VectorWindow:=@Self;
  1472. Update;
  1473. end;
  1474. constructor TVectorWindow.Load(var S: TStream);
  1475. begin
  1476. inherited load(S);
  1477. GetSubViewPtr(S,RV);
  1478. If assigned(VectorWindow) then
  1479. dispose(VectorWindow,done);
  1480. VectorWindow:=@Self;
  1481. end;
  1482. procedure TVectorWindow.Store(var S: TStream);
  1483. begin
  1484. inherited Store(s);
  1485. PutSubViewPtr(S,RV);
  1486. end;
  1487. procedure TVectorWindow.Update;
  1488. begin
  1489. ReDraw;
  1490. end;
  1491. destructor TVectorWindow.Done;
  1492. begin
  1493. VectorWindow:=nil;
  1494. inherited done;
  1495. end;
  1496. procedure InitRegistersWindow;
  1497. begin
  1498. if RegistersWindow=nil then
  1499. begin
  1500. new(RegistersWindow,init);
  1501. DeskTop^.Insert(RegistersWindow);
  1502. end;
  1503. end;
  1504. procedure DoneRegistersWindow;
  1505. begin
  1506. if assigned(RegistersWindow) then
  1507. begin
  1508. DeskTop^.Delete(RegistersWindow);
  1509. RegistersWindow:=nil;
  1510. end;
  1511. end;
  1512. procedure InitFPUWindow;
  1513. begin
  1514. if FPUWindow=nil then
  1515. begin
  1516. new(FPUWindow,init);
  1517. DeskTop^.Insert(FPUWindow);
  1518. end;
  1519. end;
  1520. procedure DoneFPUWindow;
  1521. begin
  1522. if assigned(FPUWindow) then
  1523. begin
  1524. DeskTop^.Delete(FPUWindow);
  1525. FPUWindow:=nil;
  1526. end;
  1527. end;
  1528. procedure InitVectorWindow;
  1529. begin
  1530. if VectorWindow=nil then
  1531. begin
  1532. new(VectorWindow,init);
  1533. DeskTop^.Insert(VectorWindow);
  1534. end;
  1535. end;
  1536. procedure DoneVectorWindow;
  1537. begin
  1538. if assigned(VectorWindow) then
  1539. begin
  1540. DeskTop^.Delete(VectorWindow);
  1541. VectorWindow:=nil;
  1542. end;
  1543. end;
  1544. procedure RegisterFPRegsViews;
  1545. begin
  1546. RegisterType(RRegistersWindow);
  1547. RegisterType(RRegistersView);
  1548. RegisterType(RFPUWindow);
  1549. RegisterType(RFPUView);
  1550. RegisterType(RVectorView);
  1551. end;
  1552. end.
  1553. {$endif NODEBUG}