2
0

fpregs.pas 53 KB

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