ppudump.pp 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by the FPC Development Team
  4. Dumps the contents of a FPC unit file (PPU File)
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************}
  17. {$ifdef TP}
  18. {$N+,E+}
  19. {$endif}
  20. program pppdump;
  21. uses
  22. dos,
  23. ppu;
  24. const
  25. Version = 'Version 1.10';
  26. Title = 'PPU-Analyser';
  27. Copyright = 'Copyright (c) 1998-2002 by the Free Pascal Development Team';
  28. { verbosity }
  29. v_none = $0;
  30. v_header = $1;
  31. v_defs = $2;
  32. v_syms = $4;
  33. v_interface = $8;
  34. v_implementation = $10;
  35. v_browser = $20;
  36. v_all = $ff;
  37. type
  38. { Copied from systems.pas }
  39. ttargetcpu=
  40. (
  41. no_cpu, { 0 }
  42. i386, { 1 }
  43. m68k, { 2 }
  44. alpha, { 3 }
  45. powerpc, { 4 }
  46. sparc, { 5 }
  47. vm { 6 }
  48. );
  49. var
  50. ppufile : tppufile;
  51. space : string;
  52. read_member : boolean;
  53. unitindex : longint;
  54. verbose : longint;
  55. {****************************************************************************
  56. Helper Routines
  57. ****************************************************************************}
  58. const has_errors : boolean = false;
  59. Procedure Error(const S : string);
  60. Begin
  61. Writeln(S);
  62. has_errors:=true;
  63. End;
  64. Function Target2Str(w:longint):string;
  65. type
  66. { taken from systems.pas }
  67. ttarget =
  68. (
  69. target_none, { 0 }
  70. target_i386_GO32V1, { 1 }
  71. target_i386_GO32V2, { 2 }
  72. target_i386_linux, { 3 }
  73. target_i386_OS2, { 4 }
  74. target_i386_Win32, { 5 }
  75. target_i386_freebsd, { 6 }
  76. target_m68k_Amiga, { 7 }
  77. target_m68k_Atari, { 8 }
  78. target_m68k_Mac, { 9 }
  79. target_m68k_linux, { 10 }
  80. target_m68k_PalmOS, { 11 }
  81. target_alpha_linux, { 12 }
  82. target_powerpc_linux, { 13 }
  83. target_powerpc_macos, { 14 }
  84. target_i386_sunos, { 15 }
  85. target_i386_beos, { 16 }
  86. target_i386_netbsd, { 17 }
  87. target_m68k_netbsd, { 18 }
  88. target_i386_Netware, { 19 }
  89. target_i386_qnx, { 20 }
  90. target_i386_wdosx, { 21 }
  91. target_sparc_sunos, { 22 }
  92. target_sparc_linux, { 23 }
  93. target_i386_openbsd, { 24 }
  94. target_m68k_openbsd, { 25 }
  95. system_x86_64_linux, { 26 }
  96. system_powerpc_macosx { 27 }
  97. );
  98. const
  99. Targets : array[ttarget] of string[16]=(
  100. { 0 } 'none',
  101. { 1 } 'GO32V1',
  102. { 2 } 'GO32V2',
  103. { 3 } 'Linux-i386',
  104. { 4 } 'OS/2',
  105. { 5 } 'Win32',
  106. { 6 } 'FreeBSD-i386',
  107. { 7 } 'Amiga',
  108. { 8 } 'Atari',
  109. { 9 } 'MacOS-m68k',
  110. { 10 } 'Linux-m68k',
  111. { 11 } 'PalmOS-m68k',
  112. { 12 } 'Linux-alpha',
  113. { 13 } 'Linux-ppc',
  114. { 14 } 'MacOS-ppc',
  115. { 15 } 'Solaris-i386',
  116. { 16 } 'BeOS-i386',
  117. { 17 } 'NetBSD-i386',
  118. { 18 } 'NetBSD-m68k',
  119. { 19 } 'Netware',
  120. { 20 } 'Qnx-i386',
  121. { 21 } 'WDOSX-i386',
  122. { 22 } 'Solaris-sparc',
  123. { 23 } 'Linux-sparc',
  124. { 24 } 'OpenBSD-i386',
  125. { 25 } 'OpenBSD-m68k',
  126. { 26 } 'Linux-x86-64',
  127. { 27 } 'MacOSX-ppc'
  128. );
  129. begin
  130. if w<=ord(high(ttarget)) then
  131. Target2Str:=Targets[ttarget(w)]
  132. else
  133. Target2Str:='<Unknown>';
  134. end;
  135. Function Cpu2Str(w:longint):string;
  136. const
  137. CpuTxt : array[ttargetcpu] of string[7]=
  138. ('none','i386','m68k','alpha','powerpc','sparc','vis');
  139. begin
  140. if w<=ord(high(ttargetcpu)) then
  141. Cpu2Str:=CpuTxt[ttargetcpu(w)]
  142. else
  143. Cpu2Str:='<Unknown>';
  144. end;
  145. function PPUFlags2Str(flags:longint):string;
  146. type
  147. tflagopt=record
  148. mask : longint;
  149. str : string[30];
  150. end;
  151. const
  152. flagopts=16;
  153. flagopt : array[1..flagopts] of tflagopt=(
  154. (mask: $1 ;str:'init'),
  155. (mask: $2 ;str:'final'),
  156. (mask: $4 ;str:'big_endian'),
  157. (mask: $8 ;str:'dbx'),
  158. (mask: $10 ;str:'browser'),
  159. (mask: $20 ;str:'in_library'),
  160. (mask: $40 ;str:'smart_linked'),
  161. (mask: $80 ;str:'static_linked'),
  162. (mask: $100 ;str:'shared_linked'),
  163. (mask: $200 ;str:'local_browser'),
  164. (mask: $400 ;str:'no_link'),
  165. (mask: $800 ;str:'has_resources'),
  166. (mask: $1000 ;str:'little_endian'),
  167. (mask: $2000 ;str:'release'),
  168. (mask: $4000 ;str:'local_threadvars'),
  169. (mask: $8000 ;str:'fpu emulation on')
  170. );
  171. var
  172. i : longint;
  173. first : boolean;
  174. s : string;
  175. begin
  176. s:='';
  177. if flags<>0 then
  178. begin
  179. first:=true;
  180. for i:=1to flagopts do
  181. if (flags and flagopt[i].mask)<>0 then
  182. begin
  183. if first then
  184. first:=false
  185. else
  186. s:=s+', ';
  187. s:=s+flagopt[i].str;
  188. end;
  189. end
  190. else
  191. s:='none';
  192. PPUFlags2Str:=s;
  193. end;
  194. const
  195. HexTbl : array[0..15] of char='0123456789ABCDEF';
  196. function HexB(b:byte):string;
  197. begin
  198. HexB[0]:=#2;
  199. HexB[1]:=HexTbl[b shr 4];
  200. HexB[2]:=HexTbl[b and $f];
  201. end;
  202. function hexstr(val : cardinal;cnt : byte) : string;
  203. const
  204. HexTbl : array[0..15] of char='0123456789ABCDEF';
  205. var
  206. i : longint;
  207. begin
  208. hexstr[0]:=char(cnt);
  209. for i:=cnt downto 1 do
  210. begin
  211. hexstr[i]:=hextbl[val and $f];
  212. val:=val shr 4;
  213. end;
  214. end;
  215. Function L0(l:longint):string;
  216. {
  217. return the string of value l, if l<10 then insert a zero, so
  218. the string is always at least 2 chars '01','02',etc
  219. }
  220. var
  221. s : string;
  222. begin
  223. Str(l,s);
  224. if l<10 then
  225. s:='0'+s;
  226. L0:=s;
  227. end;
  228. function filetimestring( t : longint) : string;
  229. {
  230. convert dos datetime t to a string YY/MM/DD HH:MM:SS
  231. }
  232. var
  233. DT : DateTime;
  234. begin
  235. if t=-1 then
  236. begin
  237. FileTimeString:='Not Found';
  238. exit;
  239. end;
  240. unpacktime(t,DT);
  241. filetimestring:=L0(dt.Year)+'/'+L0(dt.Month)+'/'+L0(dt.Day)+' '+L0(dt.Hour)+':'+L0(dt.min)+':'+L0(dt.sec);
  242. end;
  243. {****************************************************************************
  244. Read Routines
  245. ****************************************************************************}
  246. function getint64:int64;
  247. var
  248. l1,l2 : longint;
  249. begin
  250. l1:=ppufile.getlongint;
  251. l2:=ppufile.getlongint;
  252. getint64:=(int64(l2) shl 32) or qword(l1);
  253. end;
  254. Procedure ReadLinkContainer(const prefix:string);
  255. {
  256. Read a serie of strings and write to the screen starting every line
  257. with prefix
  258. }
  259. function maskstr(m:longint):string;
  260. const
  261. { link options }
  262. link_none = $0;
  263. link_allways = $1;
  264. link_static = $2;
  265. link_smart = $4;
  266. link_shared = $8;
  267. var
  268. s : string;
  269. begin
  270. s:='';
  271. if (m and link_allways)<>0 then
  272. s:=s+'always ';
  273. if (m and link_static)<>0 then
  274. s:=s+'static ';
  275. if (m and link_smart)<>0 then
  276. s:=s+'smart ';
  277. if (m and link_shared)<>0 then
  278. s:=s+'shared ';
  279. maskstr:=s;
  280. end;
  281. var
  282. s : string;
  283. m : longint;
  284. begin
  285. while not ppufile.endofentry do
  286. begin
  287. s:=ppufile.getstring;
  288. m:=ppufile.getlongint;
  289. WriteLn(prefix,s,' (',maskstr(m),')');
  290. end;
  291. end;
  292. Procedure ReadContainer(const prefix:string);
  293. {
  294. Read a serie of strings and write to the screen starting every line
  295. with prefix
  296. }
  297. begin
  298. while not ppufile.endofentry do
  299. WriteLn(prefix,ppufile.getstring);
  300. end;
  301. Procedure ReadRef;
  302. begin
  303. if (verbose and v_browser)=0 then
  304. exit;
  305. while (not ppufile.endofentry) and (not ppufile.error) do
  306. Writeln(space,' - Refered : ',ppufile.getword,', (',ppufile.getlongint,',',ppufile.getword,')');
  307. end;
  308. Procedure ReadAsmSymbols;
  309. type
  310. { Copied from aasmbase.pas }
  311. TAsmsymbind=(AB_NONE,AB_EXTERNAL,AB_COMMON,AB_LOCAL,AB_GLOBAL);
  312. TAsmsymtype=(AT_NONE,AT_FUNCTION,AT_DATA,AT_SECTION);
  313. var
  314. s,
  315. bindstr,
  316. typestr : string;
  317. i : longint;
  318. begin
  319. writeln(space,'Number of AsmSymbols: ',ppufile.getlongint);
  320. i:=0;
  321. while (not ppufile.endofentry) and (not ppufile.error) do
  322. begin
  323. s:=ppufile.getstring;
  324. case tasmsymbind(ppufile.getbyte) of
  325. AB_EXTERNAL :
  326. bindstr:='External';
  327. AB_COMMON :
  328. bindstr:='Common';
  329. AB_LOCAL :
  330. bindstr:='Local';
  331. AB_GLOBAL :
  332. bindstr:='Global';
  333. else
  334. bindstr:='<Error !!>'
  335. end;
  336. case tasmsymtype(ppufile.getbyte) of
  337. AT_FUNCTION :
  338. typestr:='Function';
  339. AT_DATA :
  340. typestr:='Data';
  341. AT_SECTION :
  342. typestr:='Section';
  343. else
  344. typestr:='<Error !!>'
  345. end;
  346. Writeln(space,' ',i,' : ',s,' [',bindstr,',',typestr,']');
  347. inc(i);
  348. end;
  349. end;
  350. Procedure ReadPosInfo;
  351. var
  352. info : byte;
  353. fileindex,line,column : longint;
  354. begin
  355. with ppufile do
  356. begin
  357. {
  358. info byte layout in bits:
  359. 0-1 - amount of bytes for fileindex
  360. 2-3 - amount of bytes for line
  361. 4-5 - amount of bytes for column
  362. }
  363. info:=getbyte;
  364. case (info and $03) of
  365. 0 : fileindex:=getbyte;
  366. 1 : fileindex:=getword;
  367. 2 : fileindex:=(getbyte shl 16) or getword;
  368. 3 : fileindex:=getlongint;
  369. end;
  370. case ((info shr 2) and $03) of
  371. 0 : line:=getbyte;
  372. 1 : line:=getword;
  373. 2 : line:=(getbyte shl 16) or getword;
  374. 3 : line:=getlongint;
  375. end;
  376. case ((info shr 4) and $03) of
  377. 0 : column:=getbyte;
  378. 1 : column:=getword;
  379. 2 : column:=(getbyte shl 16) or getword;
  380. 3 : column:=getlongint;
  381. end;
  382. Writeln(fileindex,' (',line,',',column,')');
  383. end;
  384. end;
  385. function readderef(const s:string;skipnil:boolean):boolean;
  386. type
  387. tdereftype = (derefnil,derefaktrecordindex,derefaktstaticindex,
  388. derefunit,derefrecord,derefindex,
  389. dereflocal,derefpara,derefaktlocalindex);
  390. var
  391. b : tdereftype;
  392. begin
  393. readderef:=true;
  394. repeat
  395. b:=tdereftype(ppufile.getbyte);
  396. case b of
  397. derefnil :
  398. begin
  399. if not skipnil then
  400. writeln('nil');
  401. readderef:=false;
  402. break;
  403. end;
  404. derefaktrecordindex :
  405. begin
  406. writeln('AktRecord ',s,' ',ppufile.getword);
  407. break;
  408. end;
  409. derefaktstaticindex :
  410. begin
  411. writeln('AktStatic ',s,' ',ppufile.getword);
  412. break;
  413. end;
  414. derefaktlocalindex :
  415. begin
  416. writeln('AktLocal ',s,' ',ppufile.getword);
  417. break;
  418. end;
  419. derefunit :
  420. begin
  421. writeln('Unit ',ppufile.getword);
  422. break;
  423. end;
  424. derefrecord :
  425. begin
  426. write('RecordDef ',ppufile.getword,', ');
  427. end;
  428. derefpara :
  429. begin
  430. write('Parameter of procdef ',ppufile.getword,', ');
  431. end;
  432. dereflocal :
  433. begin
  434. write('Local of procdef ',ppufile.getword,', ');
  435. end;
  436. derefindex :
  437. begin
  438. write(s,' ',ppufile.getword,', ');
  439. end;
  440. else
  441. begin
  442. writeln('!! unsupported dereftyp: ',ord(b));
  443. break;
  444. end;
  445. end;
  446. until false;
  447. end;
  448. function readdefref:boolean;
  449. begin
  450. readdefref:=readderef('Definition',false);
  451. end;
  452. function readsymref:boolean;
  453. begin
  454. readsymref:=readderef('Symbol',false);
  455. end;
  456. procedure readtype;
  457. var
  458. b1,b2 : boolean;
  459. begin
  460. b1:=readderef('Definition',true);
  461. b2:=readderef('Symbol',true);
  462. if not(b1 or b2) then
  463. Writeln('nil')
  464. else
  465. if (b1 and b2) then
  466. Writeln('!! Type has both definition and symbol stored');
  467. end;
  468. procedure readsymlist(const s:string);
  469. type
  470. tsltype = (sl_none,
  471. sl_load,
  472. sl_call,
  473. sl_subscript,
  474. sl_vec
  475. );
  476. const
  477. slstr : array[tsltype] of string[9] = ('',
  478. 'load',
  479. 'call',
  480. 'subscript',
  481. 'vec'
  482. );
  483. var
  484. sl : tsltype;
  485. begin
  486. readdefref;
  487. repeat
  488. sl:=tsltype(ppufile.getbyte);
  489. if sl=sl_none then
  490. break;
  491. write(s,'(',slstr[sl],') ');
  492. case sl of
  493. sl_call,
  494. sl_load,
  495. sl_subscript :
  496. readsymref;
  497. sl_vec :
  498. writeln(ppufile.getlongint);
  499. end;
  500. until false;
  501. end;
  502. { Read abstract procdef and return if inline procdef }
  503. type
  504. tproccalloption=(pocall_none,
  505. pocall_cdecl, { procedure uses C styled calling }
  506. pocall_cppdecl, { C++ calling conventions }
  507. pocall_compilerproc, { Procedure is used for internal compiler calls }
  508. pocall_far16, { Far16 for OS/2 }
  509. pocall_fpccall, { FPC default calling }
  510. pocall_inline, { Procedure is an assembler macro }
  511. pocall_internproc, { Procedure has compiler magic}
  512. pocall_palmossyscall, { procedure is a PalmOS system call }
  513. pocall_pascal, { pascal standard left to right }
  514. pocall_register, { procedure uses register (fastcall) calling }
  515. pocall_safecall, { safe call calling conventions }
  516. pocall_stdcall, { procedure uses stdcall call }
  517. pocall_system { system call }
  518. );
  519. tproccalloptions=set of tproccalloption;
  520. tproctypeoption=(potype_none,
  521. potype_proginit, { Program initialization }
  522. potype_unitinit, { unit initialization }
  523. potype_unitfinalize, { unit finalization }
  524. potype_constructor, { Procedure is a constructor }
  525. potype_destructor, { Procedure is a destructor }
  526. potype_operator { Procedure defines an operator }
  527. );
  528. tproctypeoptions=set of tproctypeoption;
  529. tprocoption=(po_none,
  530. po_classmethod, { class method }
  531. po_virtualmethod, { Procedure is a virtual method }
  532. po_abstractmethod, { Procedure is an abstract method }
  533. po_staticmethod, { static method }
  534. po_overridingmethod, { method with override directive }
  535. po_methodpointer, { method pointer, only in procvardef, also used for 'with object do' }
  536. po_containsself, { self is passed explicit to the compiler }
  537. po_interrupt, { Procedure is an interrupt handler }
  538. po_iocheck, { IO checking should be done after a call to the procedure }
  539. po_assembler, { Procedure is written in assembler }
  540. po_msgstr, { method for string message handling }
  541. po_msgint, { method for int message handling }
  542. po_exports, { Procedure has export directive (needed for OS/2) }
  543. po_external, { Procedure is external (in other object or lib)}
  544. po_savestdregs, { save std regs cdecl and stdcall need that ! }
  545. po_saveregisters, { save all registers }
  546. po_overload, { procedure is declared with overload directive }
  547. po_varargs, { printf like arguments }
  548. po_leftright, { push arguments from left to right }
  549. po_clearstack, { caller clears the stack }
  550. po_internconst { procedure has constant evaluator intern }
  551. );
  552. tprocoptions=set of tprocoption;
  553. function read_abstract_proc_def:tproccalloption;
  554. type
  555. tproccallopt=record
  556. mask : tproccalloption;
  557. str : string[30];
  558. end;
  559. tproctypeopt=record
  560. mask : tproctypeoption;
  561. str : string[30];
  562. end;
  563. tprocopt=record
  564. mask : tprocoption;
  565. str : string[30];
  566. end;
  567. const
  568. proccalloptionStr : array[tproccalloption] of string[14]=('',
  569. 'CDecl',
  570. 'CPPDecl',
  571. 'CompilerProc',
  572. 'Far16',
  573. 'FPCCall',
  574. 'Inline',
  575. 'InternProc',
  576. 'PalmOSSysCall',
  577. 'Pascal',
  578. 'Register',
  579. 'SafeCall',
  580. 'StdCall',
  581. 'System'
  582. );
  583. proctypeopts=6;
  584. proctypeopt : array[1..proctypeopts] of tproctypeopt=(
  585. (mask:potype_proginit; str:'ProgInit'),
  586. (mask:potype_unitinit; str:'UnitInit'),
  587. (mask:potype_unitfinalize;str:'UnitFinalize'),
  588. (mask:potype_constructor; str:'Constructor'),
  589. (mask:potype_destructor; str:'Destructor'),
  590. (mask:potype_operator; str:'Operator')
  591. );
  592. procopts=21;
  593. procopt : array[1..procopts] of tprocopt=(
  594. (mask:po_classmethod; str:'ClassMethod'),
  595. (mask:po_virtualmethod; str:'VirtualMethod'),
  596. (mask:po_abstractmethod; str:'AbstractMethod'),
  597. (mask:po_staticmethod; str:'StaticMethod'),
  598. (mask:po_overridingmethod;str:'OverridingMethod'),
  599. (mask:po_methodpointer; str:'MethodPointer'),
  600. (mask:po_containsself; str:'ContainsSelf'),
  601. (mask:po_interrupt; str:'Interrupt'),
  602. (mask:po_iocheck; str:'IOCheck'),
  603. (mask:po_assembler; str:'Assembler'),
  604. (mask:po_msgstr; str:'MsgStr'),
  605. (mask:po_msgint; str:'MsgInt'),
  606. (mask:po_exports; str:'Exports'),
  607. (mask:po_external; str:'External'),
  608. (mask:po_savestdregs; str:'SaveStdRegs'),
  609. (mask:po_saveregisters; str:'SaveRegisters'),
  610. (mask:po_overload; str:'Overload'),
  611. (mask:po_varargs; str:'VarArgs'),
  612. (mask:po_leftright; str:'LeftRight'),
  613. (mask:po_clearstack; str:'ClearStack'),
  614. (mask:po_internconst; str:'InternConst')
  615. );
  616. tvarspez : array[0..3] of string[5]=('Value','Const','Var ','Out ');
  617. var
  618. proctypeoption : tproctypeoption;
  619. proccalloption : tproccalloption;
  620. procoptions : tprocoptions;
  621. i,params : longint;
  622. first : boolean;
  623. paraloc : array[0..9] of byte;
  624. begin
  625. write(space,' Return type : ');
  626. readtype;
  627. writeln(space,' Fpu used : ',ppufile.getbyte);
  628. proctypeoption:=tproctypeoption(ppufile.getbyte);
  629. if proctypeoption<>potype_none then
  630. begin
  631. write(space,' TypeOption : ');
  632. first:=true;
  633. for i:=1to proctypeopts do
  634. if (proctypeopt[i].mask=proctypeoption) then
  635. begin
  636. if first then
  637. first:=false
  638. else
  639. write(', ');
  640. write(proctypeopt[i].str);
  641. end;
  642. writeln;
  643. end;
  644. proccalloption:=tproccalloption(ppufile.getbyte);
  645. read_abstract_proc_def:=proccalloption;
  646. writeln(space,' CallOption : ',proccalloptionStr[proccalloption]);
  647. ppufile.getsmallset(procoptions);
  648. if procoptions<>[] then
  649. begin
  650. write(space,' Options : ');
  651. first:=true;
  652. for i:=1to procopts do
  653. if (procopt[i].mask in procoptions) then
  654. begin
  655. if first then
  656. first:=false
  657. else
  658. write(', ');
  659. write(procopt[i].str);
  660. end;
  661. writeln;
  662. end;
  663. params:=ppufile.getword;
  664. writeln(space,' Nr of parameters : ',params);
  665. if params>0 then
  666. begin
  667. repeat
  668. write(space,' - ',tvarspez[ppufile.getbyte],' : ');
  669. readtype;
  670. write(space,' Default : ');
  671. readsymref;
  672. write(space,' Symbol : ');
  673. readsymref;
  674. ppufile.getdata(paraloc,sizeof(paraloc));
  675. dec(params);
  676. until params=0;
  677. end;
  678. end;
  679. procedure readcommonsym(const s:string);
  680. type
  681. tsymoption=(sp_none,
  682. sp_public,
  683. sp_private,
  684. sp_published,
  685. sp_protected,
  686. sp_forwarddef,
  687. sp_static,
  688. sp_primary_typesym { this is for typesym, to know who is the primary symbol of a def }
  689. );
  690. tsymoptions=set of tsymoption;
  691. tsymopt=record
  692. mask : tsymoption;
  693. str : string[30];
  694. end;
  695. const
  696. symopts=7;
  697. symopt : array[1..symopts] of tsymopt=(
  698. (mask:sp_public; str:'Public'),
  699. (mask:sp_private; str:'Private'),
  700. (mask:sp_published; str:'Published'),
  701. (mask:sp_protected; str:'Protected'),
  702. (mask:sp_forwarddef; str:'ForwardDef'),
  703. (mask:sp_static; str:'Static'),
  704. (mask:sp_primary_typesym;str:'PrimaryTypeSym')
  705. );
  706. var
  707. symoptions : tsymoptions;
  708. i : longint;
  709. first : boolean;
  710. begin
  711. writeln(space,'** Symbol Nr. ',ppufile.getword,' **');
  712. writeln(space,s,ppufile.getstring);
  713. ppufile.getsmallset(symoptions);
  714. if symoptions<>[] then
  715. begin
  716. write(space,' File Pos: ');
  717. readposinfo;
  718. write(space,' SymOptions: ');
  719. first:=true;
  720. for i:=1to symopts do
  721. if (symopt[i].mask in symoptions) then
  722. begin
  723. if first then
  724. first:=false
  725. else
  726. write(', ');
  727. write(symopt[i].str);
  728. end;
  729. writeln;
  730. end;
  731. end;
  732. procedure readcommondef(const s:string);
  733. type
  734. tdefoption=(df_none,
  735. df_has_inittable, { init data has been generated }
  736. df_has_rttitable, { rtti data has been generated }
  737. df_unique
  738. );
  739. tdefoptions=set of tdefoption;
  740. var
  741. defopts : tdefoptions;
  742. begin
  743. writeln(space,'** Definition Nr. ',ppufile.getword,' **');
  744. writeln(space,s);
  745. write (space,' Type symbol : ');
  746. readsymref;
  747. ppufile.getsmallset(defopts);
  748. if df_unique in defopts then
  749. writeln (space,' Unique type symbol');
  750. if df_has_rttitable in defopts then
  751. begin
  752. write (space,' RTTI symbol : ');
  753. readsymref;
  754. end;
  755. if df_has_inittable in defopts then
  756. begin
  757. write (space,' Init symbol : ');
  758. readsymref;
  759. end;
  760. end;
  761. {****************************************************************************
  762. Read Symbols Part
  763. ****************************************************************************}
  764. procedure readsymbols;
  765. Const
  766. vo_is_C_var = 2;
  767. Type
  768. pguid = ^tguid;
  769. tguid = packed record
  770. D1: LongWord;
  771. D2: Word;
  772. D3: Word;
  773. D4: array[0..7] of Byte;
  774. end;
  775. absolutetyp = (tovar,toasm,toaddr);
  776. tconsttyp = (constnone,
  777. constord,conststring,constreal,constbool,
  778. constint,constchar,constset,constpointer,constnil,
  779. constresourcestring,constwstring,constwchar,constguid
  780. );
  781. var
  782. b : byte;
  783. pc : pchar;
  784. totalsyms,
  785. symcnt,
  786. i,j,len : longint;
  787. guid : tguid;
  788. begin
  789. symcnt:=1;
  790. with ppufile do
  791. begin
  792. if space<>'' then
  793. Writeln(space,'-----------------------------');
  794. if readentry=ibstartsyms then
  795. begin
  796. totalsyms:=getlongint;
  797. Writeln(space,'Number of symbols : ',totalsyms);
  798. Writeln(space,'Symtable datasize : ',getlongint);
  799. Writeln(space,'Symtable alignment: ',getlongint);
  800. end
  801. else
  802. begin
  803. totalsyms:=-1;
  804. Writeln('!! ibstartsym not found');
  805. end;
  806. repeat
  807. b:=readentry;
  808. if not (b in [iberror,ibendsyms]) then
  809. inc(symcnt);
  810. case b of
  811. ibunitsym :
  812. readcommonsym('Unit symbol ');
  813. iblabelsym :
  814. readcommonsym('Label symbol ');
  815. ibtypesym :
  816. begin
  817. readcommonsym('Type symbol ');
  818. write(space,' Result Type: ');
  819. readtype;
  820. end;
  821. ibprocsym :
  822. begin
  823. readcommonsym('Procedure symbol ');
  824. repeat
  825. write(space,' Definition: ');
  826. until not readdefref;
  827. end;
  828. ibconstsym :
  829. begin
  830. readcommonsym('Constant symbol ');
  831. b:=getbyte;
  832. case tconsttyp(b) of
  833. constord :
  834. begin
  835. write (space,'OrdinalType: ');
  836. readtype;
  837. writeln (space,' Value: ',getlongint)
  838. end;
  839. constpointer :
  840. begin
  841. write (space,' Pointer Type: ');
  842. readtype;
  843. writeln (space,' Value: ',getlongint)
  844. end;
  845. conststring,
  846. constresourcestring :
  847. begin
  848. len:=getlongint;
  849. getmem(pc,len+1);
  850. getdata(pc^,len);
  851. writeln(space,' Length: ',len);
  852. writeln(space,' Value: "',pc,'"');
  853. freemem(pc,len+1);
  854. if tconsttyp(b)=constresourcestring then
  855. writeln(space,' Index: ',getlongint);
  856. end;
  857. constreal :
  858. writeln(space,' Value: ',getreal);
  859. constbool :
  860. if getlongint<>0 then
  861. writeln (space,' Value : True')
  862. else
  863. writeln (space,' Value: False');
  864. constint :
  865. writeln(space,' Value: ',getint64);
  866. constchar :
  867. writeln(space,' Value: "'+chr(getlongint)+'"');
  868. constset :
  869. begin
  870. write (space,' Set Type: ');
  871. readtype;
  872. for i:=1to 4 do
  873. begin
  874. write (space,' Value: ');
  875. for j:=1to 8 do
  876. begin
  877. if j>1 then
  878. write(',');
  879. write(hexb(getbyte));
  880. end;
  881. writeln;
  882. end;
  883. end;
  884. constwstring:
  885. begin
  886. end;
  887. constwchar:
  888. writeln(space,' Value: #',getlongint);
  889. constguid:
  890. begin
  891. getdata(guid,sizeof(guid));
  892. write (space,' IID String: {',hexstr(guid.d1,8),'-',hexstr(guid.d2,4),'-',hexstr(guid.d3,4),'-');
  893. for i:=0 to 7 do
  894. begin
  895. write(hexstr(guid.d4[i],2));
  896. if i=1 then write('-');
  897. end;
  898. writeln('}');
  899. end
  900. else
  901. Writeln ('!! Invalid unit format : Invalid const type encountered: ',b);
  902. end;
  903. end;
  904. ibvarsym :
  905. begin
  906. readcommonsym('Variable symbol ');
  907. writeln(space,' Type: ',getbyte);
  908. writeln(space,' Address: ',getlongint);
  909. write (space,' Var Type: ');
  910. readtype;
  911. i:=getlongint;
  912. writeln(space,' Options: ',i);
  913. if (i and vo_is_C_var)<>0 then
  914. writeln(space,' Mangledname: ',getstring);
  915. end;
  916. ibenumsym :
  917. begin
  918. readcommonsym('Enumeration symbol ');
  919. write (space,' Definition: ');
  920. readdefref;
  921. writeln(space,' Value: ',getlongint);
  922. end;
  923. ibsyssym :
  924. begin
  925. readcommonsym('Internal system symbol ');
  926. writeln(space,' Internal Nr: ',getlongint);
  927. end;
  928. ibrttisym :
  929. begin
  930. readcommonsym('RTTI symbol ');
  931. writeln(space,' RTTI Type: ',getbyte);
  932. end;
  933. ibtypedconstsym :
  934. begin
  935. readcommonsym('Typed constant ');
  936. write (space,' Constant Type: ');
  937. readtype;
  938. writeln(space,' ReallyConst: ',(getbyte<>0));
  939. end;
  940. ibabsolutesym :
  941. begin
  942. readcommonsym('Absolute variable symbol ');
  943. writeln(space,' Type: ',getbyte);
  944. if read_member then
  945. writeln(space,' Address: ',getlongint);
  946. write (space,' Var Type: ');
  947. readtype;
  948. writeln(space,' Options: ',getlongint);
  949. Write (space,' Relocated to ');
  950. b:=getbyte;
  951. case absolutetyp(b) of
  952. tovar :
  953. Writeln('Name : ',getstring);
  954. toasm :
  955. Writeln('Assembler name : ',getstring);
  956. toaddr :
  957. begin
  958. Write('Address : ',getlongint);
  959. WriteLn(' (Far: ',getbyte<>0,')');
  960. end;
  961. else
  962. Writeln ('!! Invalid unit format : Invalid absolute type encountered: ',b);
  963. end;
  964. end;
  965. ibpropertysym :
  966. begin
  967. readcommonsym('Property ');
  968. i:=getlongint;
  969. writeln(space,' PropOptions: ',i);
  970. if (i and 32)>0 then
  971. begin
  972. write (space,'OverrideProp: ');
  973. readsymref;
  974. end
  975. else
  976. begin
  977. write (space,' Prop Type: ');
  978. readtype;
  979. writeln(space,' Index: ',getlongint);
  980. writeln(space,' Default: ',getlongint);
  981. write (space,' Index Type: ');
  982. readtype;
  983. write (space,' Readaccess: ');
  984. readsymlist(space+' Sym: ');
  985. write (space,' Writeaccess: ');
  986. readsymlist(space+' Sym: ');
  987. write (space,'Storedaccess: ');
  988. readsymlist(space+' Sym: ');
  989. end;
  990. end;
  991. ibfuncretsym :
  992. begin
  993. readcommonsym('Func return value ');
  994. write (space,' Return Type: ');
  995. readtype;
  996. writeln(space,' Address: ',getlongint);
  997. end;
  998. iberror :
  999. begin
  1000. Writeln('!! Error in PPU');
  1001. exit;
  1002. end;
  1003. ibendsyms :
  1004. break;
  1005. else
  1006. WriteLn('!! Skipping unsupported PPU Entry in Symbols: ',b);
  1007. end;
  1008. if not EndOfEntry then
  1009. Writeln('!! Entry has more information stored');
  1010. until false;
  1011. if (totalsyms<>-1) and (symcnt-1<>totalsyms) then
  1012. Writeln('!! Only read ',symcnt-1,' of ',totalsyms,' symbols');
  1013. end;
  1014. end;
  1015. {****************************************************************************
  1016. Read defintions Part
  1017. ****************************************************************************}
  1018. procedure getusedregisters_i386;
  1019. type
  1020. tregister = (R_NO,
  1021. R_EAX,R_ECX,R_EDX,R_EBX,R_ESP,R_EBP,R_ESI,R_EDI,
  1022. R_AX,R_CX,R_DX,R_BX,R_SP,R_BP,R_SI,R_DI,
  1023. R_AL,R_CL,R_DL,R_BL,R_AH,R_CH,R_BH,R_DH,
  1024. R_CS,R_DS,R_ES,R_SS,R_FS,R_GS,
  1025. R_ST,R_ST0,R_ST1,R_ST2,R_ST3,R_ST4,R_ST5,R_ST6,R_ST7,
  1026. R_DR0,R_DR1,R_DR2,R_DR3,R_DR6,R_DR7,
  1027. R_CR0,R_CR2,R_CR3,R_CR4,
  1028. R_TR3,R_TR4,R_TR5,R_TR6,R_TR7,
  1029. R_MM0,R_MM1,R_MM2,R_MM3,R_MM4,R_MM5,R_MM6,R_MM7,
  1030. R_XMM0,R_XMM1,R_XMM2,R_XMM3,R_XMM4,R_XMM5,R_XMM6,R_XMM7
  1031. );
  1032. tregisterset = set of tregister;
  1033. reg2strtable = array[tregister] of string[6];
  1034. const
  1035. std_reg2str : reg2strtable = ('',
  1036. 'eax','ecx','edx','ebx','esp','ebp','esi','edi',
  1037. 'ax','cx','dx','bx','sp','bp','si','di',
  1038. 'al','cl','dl','bl','ah','ch','bh','dh',
  1039. 'cs','ds','es','ss','fs','gs',
  1040. 'st','st(0)','st(1)','st(2)','st(3)','st(4)','st(5)','st(6)','st(7)',
  1041. 'dr0','dr1','dr2','dr3','dr6','dr7',
  1042. 'cr0','cr2','cr3','cr4',
  1043. 'tr3','tr4','tr5','tr6','tr7',
  1044. 'mm0','mm1','mm2','mm3','mm4','mm5','mm6','mm7',
  1045. 'xmm0','xmm1','xmm2','xmm3','xmm4','xmm5','xmm6','xmm7'
  1046. );
  1047. firstsaveintreg = R_EAX;
  1048. lastsaveintreg = R_EBX;
  1049. firstsavefpureg = R_NO;
  1050. lastsavefpureg = R_NO;
  1051. firstsavemmreg = R_MM0;
  1052. lastsavemmreg = R_MM7;
  1053. var
  1054. regs: tregisterset;
  1055. r: tregister;
  1056. first: boolean;
  1057. begin
  1058. first := true;
  1059. ppufile.getnormalset(regs);
  1060. for r := firstsaveintreg to lastsaveintreg do
  1061. if r in regs then
  1062. begin
  1063. if not first then
  1064. write(', ')
  1065. else
  1066. first := false;
  1067. write(std_reg2str[r])
  1068. end;
  1069. if (firstsavefpureg <> R_NO) then
  1070. for r := firstsavefpureg to lastsavefpureg do
  1071. if r in regs then
  1072. begin
  1073. if not first then
  1074. write(', ')
  1075. else
  1076. first := false;
  1077. write(std_reg2str[r])
  1078. end;
  1079. if (firstsavemmreg <> R_NO) then
  1080. for r := firstsavemmreg to lastsavemmreg do
  1081. if r in regs then
  1082. begin
  1083. if not first then
  1084. write(', ')
  1085. else
  1086. first := false;
  1087. write(std_reg2str[r])
  1088. end;
  1089. writeln;
  1090. end;
  1091. procedure readdefinitions(start_read : boolean);
  1092. type
  1093. tsettype = (normset,smallset,varset);
  1094. tbasetype = (
  1095. uvoid,
  1096. u8bit,u16bit,u32bit,u64bit,
  1097. s8bit,s16bit,s32bit,s64bit,
  1098. bool8bit,bool16bit,bool32bit,
  1099. uchar,uwidechar
  1100. );
  1101. tobjectdeftype = (odt_none,
  1102. odt_class,
  1103. odt_object,
  1104. odt_interfacecom,
  1105. odt_interfacecorba,
  1106. odt_cppclass
  1107. );
  1108. var
  1109. b : byte;
  1110. oldread_member : boolean;
  1111. totaldefs,l,j,
  1112. defcnt : longint;
  1113. calloption : tproccalloption;
  1114. regs : set of char;
  1115. begin
  1116. defcnt:=0;
  1117. with ppufile do
  1118. begin
  1119. if space<>'' then
  1120. Writeln(space,'-----------------------------');
  1121. if not start_read then
  1122. if readentry=ibstartdefs then
  1123. begin
  1124. totaldefs:=getlongint;
  1125. Writeln(space,'Number of definitions: ',totaldefs);
  1126. end
  1127. else
  1128. begin
  1129. totaldefs:=-1;
  1130. Writeln('!! ibstartdef not found');
  1131. end;
  1132. repeat
  1133. b:=readentry;
  1134. if not (b in [iberror,ibenddefs]) then
  1135. inc(defcnt);
  1136. case b of
  1137. ibpointerdef :
  1138. begin
  1139. readcommondef('Pointer definition');
  1140. write (space,' Pointed Type : ');
  1141. readtype;
  1142. writeln(space,' Is Far : ',(getbyte<>0));
  1143. end;
  1144. iborddef :
  1145. begin
  1146. readcommondef('Ordinal definition');
  1147. write (space,' Base type : ');
  1148. b:=getbyte;
  1149. case tbasetype(b) of
  1150. uvoid : writeln('uvoid');
  1151. u8bit : writeln('u8bit');
  1152. u16bit : writeln('u16bit');
  1153. u32bit : writeln('s32bit');
  1154. u64bit : writeln('u64bit');
  1155. s8bit : writeln('s8bit');
  1156. s16bit : writeln('s16bit');
  1157. s32bit : writeln('s32bit');
  1158. s64bit : writeln('s64bit');
  1159. bool8bit : writeln('bool8bit');
  1160. bool16bit : writeln('bool16bit');
  1161. bool32bit : writeln('bool32bit');
  1162. uchar : writeln('uchar');
  1163. uwidechar : writeln('uwidechar');
  1164. else writeln('!! Warning: Invalid base type ',b);
  1165. end;
  1166. writeln(space,' Range : ',getint64,' to ',getint64);
  1167. end;
  1168. ibfloatdef :
  1169. begin
  1170. readcommondef('Float definition');
  1171. writeln(space,' Float type : ',getbyte);
  1172. end;
  1173. ibarraydef :
  1174. begin
  1175. readcommondef('Array definition');
  1176. write (space,' Element type : ');
  1177. readtype;
  1178. write (space,' Range Type : ');
  1179. readtype;
  1180. writeln(space,' Range : ',getlongint,' to ',getlongint);
  1181. writeln(space,' Is Constructor : ',(getbyte<>0));
  1182. writeln(space,' Is Dynamic : ',(getbyte<>0));
  1183. end;
  1184. ibprocdef :
  1185. begin
  1186. readcommondef('Procedure definition');
  1187. calloption:=read_abstract_proc_def;
  1188. write (space,' Used Registers : ');
  1189. case ttargetcpu(header.cpu) of
  1190. i386 :
  1191. getusedregisters_i386
  1192. else
  1193. begin
  1194. getnormalset(regs);
  1195. writeln('<not yet implemented>');
  1196. end;
  1197. end;
  1198. if (getbyte<>0) then
  1199. writeln(space,' Mangled name : ',getstring);
  1200. writeln(space,' Overload Number : ',getword);
  1201. writeln(space,' Number : ',getword);
  1202. write (space,' Class : ');
  1203. readdefref;
  1204. write (space,' Procsym : ');
  1205. readsymref;
  1206. write (space,' File Pos : ');
  1207. readposinfo;
  1208. if (calloption=pocall_inline) then
  1209. begin
  1210. write (space,' FuncretSym : ');
  1211. readdefref;
  1212. end;
  1213. space:=' '+space;
  1214. { parast }
  1215. readdefinitions(false);
  1216. readsymbols;
  1217. { localst }
  1218. if (calloption=pocall_inline) or
  1219. ((ppufile.header.flags and uf_local_browser) <> 0) then
  1220. begin
  1221. readdefinitions(false);
  1222. readsymbols;
  1223. end;
  1224. delete(space,1,4);
  1225. end;
  1226. ibprocvardef :
  1227. begin
  1228. readcommondef('Procedural type (ProcVar) definition');
  1229. read_abstract_proc_def;
  1230. end;
  1231. ibshortstringdef :
  1232. begin
  1233. readcommondef('ShortString definition');
  1234. writeln(space,' Length : ',getbyte);
  1235. end;
  1236. ibwidestringdef :
  1237. begin
  1238. readcommondef('WideString definition');
  1239. writeln(space,' Length : ',getlongint);
  1240. end;
  1241. ibansistringdef :
  1242. begin
  1243. readcommondef('AnsiString definition');
  1244. writeln(space,' Length : ',getlongint);
  1245. end;
  1246. iblongstringdef :
  1247. begin
  1248. readcommondef('Longstring definition');
  1249. writeln(space,' Length : ',getlongint);
  1250. end;
  1251. ibrecorddef :
  1252. begin
  1253. readcommondef('Record definition');
  1254. writeln(space,' Size : ',getlongint);
  1255. {read the record definitions and symbols}
  1256. space:=' '+space;
  1257. oldread_member:=read_member;
  1258. read_member:=true;
  1259. readdefinitions(false);
  1260. readsymbols;
  1261. read_member:=oldread_member;
  1262. Delete(space,1,4);
  1263. end;
  1264. ibobjectdef :
  1265. begin
  1266. readcommondef('Object/Class definition');
  1267. b:=getbyte;
  1268. write (space,' Type : ');
  1269. case tobjectdeftype(b) of
  1270. odt_class : writeln('class');
  1271. odt_object : writeln('object');
  1272. odt_interfacecom : writeln('interfacecom');
  1273. odt_interfacecorba : writeln('interfacecorba');
  1274. odt_cppclass : writeln('cppclass');
  1275. else writeln('!! Warning: Invalid object type ',b);
  1276. end;
  1277. writeln(space,' Size : ',getlongint);
  1278. writeln(space,' Vmt offset : ',getlongint);
  1279. writeln(space,' Name of Class : ',getstring);
  1280. write(space, ' Ancestor Class : ');
  1281. readdefref;
  1282. writeln(space,' Options : ',getlongint);
  1283. if tobjectdeftype(b) in [odt_interfacecom,odt_interfacecorba] then
  1284. begin
  1285. writeln(space,' GUID Valid : ',(getbyte<>0));
  1286. { IIDGUID }
  1287. for j:=1to 16 do
  1288. getbyte;
  1289. writeln(space,' IID String : ',getstring);
  1290. writeln(space,' Last VTable idx : ',getlongint);
  1291. end;
  1292. if tobjectdeftype(b) in [odt_class,odt_interfacecorba] then
  1293. begin
  1294. l:=getlongint;
  1295. writeln(space,' Impl Intf Count : ',l);
  1296. for j:=1 to l do
  1297. begin
  1298. write (space,' - Definition : ');
  1299. readdefref;
  1300. writeln(space,' IOffset : ',getlongint);
  1301. end;
  1302. end;
  1303. {read the record definitions and symbols}
  1304. space:=' '+space;
  1305. oldread_member:=read_member;
  1306. read_member:=true;
  1307. readdefinitions(false);
  1308. readsymbols;
  1309. read_member:=oldread_member;
  1310. Delete(space,1,4);
  1311. end;
  1312. ibfiledef :
  1313. begin
  1314. ReadCommonDef('File definition');
  1315. write (space,' Type : ');
  1316. case getbyte of
  1317. 0 : writeln('Text');
  1318. 1 : begin
  1319. writeln('Typed');
  1320. write (space,' File of Type : ');
  1321. Readtype;
  1322. end;
  1323. 2 : writeln('Untyped');
  1324. end;
  1325. end;
  1326. ibformaldef :
  1327. readcommondef('Generic Definition (void-typ)');
  1328. ibenumdef :
  1329. begin
  1330. readcommondef('Enumeration type definition');
  1331. write(space,'Base enumeration type : ');
  1332. readdefref;
  1333. writeln(space,' Smallest element : ',getlongint);
  1334. writeln(space,' Largest element : ',getlongint);
  1335. writeln(space,' Size : ',getlongint);
  1336. end;
  1337. ibclassrefdef :
  1338. begin
  1339. readcommondef('Class reference definition');
  1340. write (space,' Pointed Type : ');
  1341. readtype;
  1342. end;
  1343. ibsetdef :
  1344. begin
  1345. readcommondef('Set definition');
  1346. write (space,' Element type : ');
  1347. readtype;
  1348. b:=getbyte;
  1349. case tsettype(b) of
  1350. smallset : writeln(space,' Set with 32 Elements');
  1351. normset : writeln(space,' Set with 256 Elements');
  1352. varset : writeln(space,' Set with ',getlongint,' Elements');
  1353. else writeln('!! Warning: Invalid set type ',b);
  1354. end;
  1355. end;
  1356. ibvariantdef :
  1357. begin
  1358. readcommondef('Variant definition');
  1359. end;
  1360. iberror :
  1361. begin
  1362. Writeln('!! Error in PPU');
  1363. exit;
  1364. end;
  1365. ibenddefs :
  1366. break;
  1367. else
  1368. WriteLn('!! Skipping unsupported PPU Entry in definitions: ',b);
  1369. end;
  1370. if not EndOfEntry then
  1371. Writeln('!! Entry has more information stored');
  1372. until false;
  1373. if (totaldefs<>-1) and (defcnt<>totaldefs) then
  1374. Writeln('!! Only read ',defcnt,' of ',totaldefs,' definitions');
  1375. end;
  1376. end;
  1377. {****************************************************************************
  1378. Read General Part
  1379. ****************************************************************************}
  1380. procedure readinterface;
  1381. var
  1382. b : byte;
  1383. sourcenumber,
  1384. unitnumber : word;
  1385. ucrc,uintfcrc : longint;
  1386. begin
  1387. with ppufile do
  1388. begin
  1389. repeat
  1390. b:=readentry;
  1391. case b of
  1392. ibmodulename :
  1393. Writeln('Module Name: ',getstring);
  1394. ibsourcefiles :
  1395. begin
  1396. sourcenumber:=1;
  1397. while not EndOfEntry do
  1398. begin
  1399. Writeln('Source file ',sourcenumber,' : ',getstring,' ',filetimestring(getlongint));
  1400. inc(sourcenumber);
  1401. end;
  1402. end;
  1403. ibusedmacros :
  1404. begin
  1405. while not EndOfEntry do
  1406. begin
  1407. Write('Conditional ',getstring);
  1408. b:=getbyte;
  1409. if boolean(b)=true then
  1410. write(' defined at startup')
  1411. else
  1412. write(' not defined at startup');
  1413. b:=getbyte;
  1414. if boolean(b)=true then
  1415. writeln(' was used')
  1416. else
  1417. writeln;
  1418. end;
  1419. end;
  1420. ibloadunit :
  1421. begin
  1422. unitnumber:=1;
  1423. while not EndOfEntry do
  1424. begin
  1425. write('Uses unit: ',getstring,' (Number: ',unitnumber,')');
  1426. ucrc:=getlongint;
  1427. uintfcrc:=getlongint;
  1428. write(' (Crc: ',hexstr(ucrc,8),', IntfcCrc: ',hexstr(uintfcrc,8),')');
  1429. if getbyte<>0 then
  1430. writeln(' (interface)')
  1431. else
  1432. writeln(' (implementation)');
  1433. inc(unitnumber);
  1434. end;
  1435. end;
  1436. iblinkunitofiles :
  1437. ReadLinkContainer('Link unit object file: ');
  1438. iblinkunitstaticlibs :
  1439. ReadLinkContainer('Link unit static lib: ');
  1440. iblinkunitsharedlibs :
  1441. ReadLinkContainer('Link unit shared lib: ');
  1442. iblinkotherofiles :
  1443. ReadLinkContainer('Link other object file: ');
  1444. iblinkotherstaticlibs :
  1445. ReadLinkContainer('Link other static lib: ');
  1446. iblinkothersharedlibs :
  1447. ReadLinkContainer('Link other shared lib: ');
  1448. iberror :
  1449. begin
  1450. Writeln('Error in PPU');
  1451. exit;
  1452. end;
  1453. ibendinterface :
  1454. break;
  1455. else
  1456. WriteLn('!! Skipping unsupported PPU Entry in General Part: ',b);
  1457. end;
  1458. until false;
  1459. end;
  1460. end;
  1461. {****************************************************************************
  1462. Read Implementation Part
  1463. ****************************************************************************}
  1464. procedure readimplementation;
  1465. var
  1466. b : byte;
  1467. begin
  1468. with ppufile do
  1469. begin
  1470. repeat
  1471. b:=readentry;
  1472. case b of
  1473. ibasmsymbols :
  1474. ReadAsmSymbols;
  1475. iberror :
  1476. begin
  1477. Writeln('Error in PPU');
  1478. exit;
  1479. end;
  1480. ibendimplementation :
  1481. break;
  1482. else
  1483. WriteLn('!! Skipping unsupported PPU Entry in Implementation: ',b);
  1484. end;
  1485. until false;
  1486. end;
  1487. end;
  1488. {****************************************************************************
  1489. Read Browser Part
  1490. ****************************************************************************}
  1491. procedure readbrowser;
  1492. var
  1493. b : byte;
  1494. const indent : string = '';
  1495. begin
  1496. Writeln(indent,'Start of symtable browser');
  1497. indent:=indent+'**';
  1498. with ppufile do
  1499. begin
  1500. repeat
  1501. b:=readentry;
  1502. case b of
  1503. ibbeginsymtablebrowser :
  1504. begin
  1505. { here we must read object and record symtables !! }
  1506. indent:=indent+' ';
  1507. Writeln(indent,'Record/Object symtable');
  1508. readbrowser;
  1509. Indent:=Copy(Indent,1,Length(Indent)-2);
  1510. end;
  1511. ibsymref :
  1512. begin
  1513. readsymref;
  1514. readref;
  1515. end;
  1516. ibdefref :
  1517. begin
  1518. readdefref;
  1519. readref;
  1520. if ((ppufile.header.flags and uf_local_browser)<>0) and
  1521. (UnitIndex=0) then
  1522. begin
  1523. { parast and localst }
  1524. indent:=indent+' ';
  1525. b:=ppufile.readentry;
  1526. if b=ibbeginsymtablebrowser then
  1527. readbrowser;
  1528. b:=ppufile.readentry;
  1529. if b=ibbeginsymtablebrowser then
  1530. readbrowser;
  1531. Indent:=Copy(Indent,1,Length(Indent)-2);
  1532. end;
  1533. end;
  1534. iberror :
  1535. begin
  1536. Writeln('Error in PPU');
  1537. exit;
  1538. end;
  1539. ibendsymtablebrowser :
  1540. break;
  1541. else
  1542. begin
  1543. WriteLn('!! Skipping unsupported PPU Entry in Browser: ',b);
  1544. Halt;
  1545. end;
  1546. end;
  1547. until false;
  1548. end;
  1549. Indent:=Copy(Indent,1,Length(Indent)-2);
  1550. Writeln(Indent,'End of symtable browser');
  1551. end;
  1552. procedure dofile (filename : string);
  1553. var
  1554. b : byte;
  1555. begin
  1556. { reset }
  1557. space:='';
  1558. { fix filename }
  1559. if pos('.',filename)=0 then
  1560. filename:=filename+'.ppu';
  1561. ppufile:=tppufile.create(filename);
  1562. if not ppufile.openfile then
  1563. begin
  1564. writeln ('IO-Error when opening : ',filename,', Skipping');
  1565. exit;
  1566. end;
  1567. { PPU File is open, check for PPU Id }
  1568. if not ppufile.CheckPPUID then
  1569. begin
  1570. writeln(Filename,' : Not a valid PPU file, Skipping');
  1571. exit;
  1572. end;
  1573. { Check PPU Version }
  1574. Writeln('Analyzing ',filename,' (v',ppufile.GetPPUVersion,')');
  1575. if ppufile.GetPPUVersion<16 then
  1576. begin
  1577. writeln(Filename,' : Old PPU Formats (<v16) are not supported, Skipping');
  1578. exit;
  1579. end;
  1580. { Write PPU Header Information }
  1581. if (verbose and v_header)<>0 then
  1582. begin
  1583. Writeln;
  1584. Writeln('Header');
  1585. Writeln('-------');
  1586. with ppufile.header do
  1587. begin
  1588. Writeln('Compiler version : ',ppufile.header.compiler shr 14,'.',
  1589. (ppufile.header.compiler shr 7) and $7f,'.',
  1590. ppufile.header.compiler and $7f);
  1591. WriteLn('Target processor : ',Cpu2Str(cpu));
  1592. WriteLn('Target operating system : ',Target2Str(target));
  1593. Writeln('Unit flags : ',PPUFlags2Str(flags));
  1594. Writeln('FileSize (w/o header) : ',size);
  1595. Writeln('Checksum : ',hexstr(checksum,8));
  1596. Writeln('Interface Checksum : ',hexstr(interface_checksum,8));
  1597. end;
  1598. end;
  1599. {read the general stuff}
  1600. if (verbose and v_interface)<>0 then
  1601. begin
  1602. Writeln;
  1603. Writeln('Interface section');
  1604. Writeln('------------------');
  1605. readinterface;
  1606. end
  1607. else
  1608. ppufile.skipuntilentry(ibendinterface);
  1609. {read the definitions}
  1610. if (verbose and v_defs)<>0 then
  1611. begin
  1612. Writeln;
  1613. Writeln('Interface definitions');
  1614. Writeln('----------------------');
  1615. readdefinitions(false);
  1616. end
  1617. else
  1618. ppufile.skipuntilentry(ibenddefs);
  1619. {read the symbols}
  1620. if (verbose and v_syms)<>0 then
  1621. begin
  1622. Writeln;
  1623. Writeln('Interface Symbols');
  1624. Writeln('------------------');
  1625. readsymbols;
  1626. end
  1627. else
  1628. ppufile.skipuntilentry(ibendsyms);
  1629. {read the implementation stuff}
  1630. if (verbose and v_implementation)<>0 then
  1631. begin
  1632. Writeln;
  1633. Writeln('Implementation section');
  1634. Writeln('-----------------------');
  1635. readimplementation;
  1636. end
  1637. else
  1638. ppufile.skipuntilentry(ibendimplementation);
  1639. {read the static browser units stuff}
  1640. if (ppufile.header.flags and uf_local_browser)<>0 then
  1641. begin
  1642. if (verbose and v_defs)<>0 then
  1643. begin
  1644. Writeln;
  1645. Writeln('Static definitions');
  1646. Writeln('----------------------');
  1647. readdefinitions(false);
  1648. end
  1649. else
  1650. ppufile.skipuntilentry(ibenddefs);
  1651. {read the symbols}
  1652. if (verbose and v_syms)<>0 then
  1653. begin
  1654. Writeln;
  1655. Writeln('Static Symbols');
  1656. Writeln('------------------');
  1657. readsymbols;
  1658. end;
  1659. end;
  1660. {read the browser units stuff}
  1661. if (ppufile.header.flags and uf_has_browser)<>0 then
  1662. begin
  1663. if (verbose and v_browser)<>0 then
  1664. begin
  1665. Writeln;
  1666. Writeln('Browser section');
  1667. Writeln('---------------');
  1668. UnitIndex:=0;
  1669. repeat
  1670. b:=ppufile.readentry;
  1671. if b = ibendbrowser then break;
  1672. if b=ibbeginsymtablebrowser then
  1673. begin
  1674. Writeln('Unit ',UnitIndex);
  1675. readbrowser;
  1676. Inc(UnitIndex);
  1677. end
  1678. else
  1679. Writeln('Wrong end browser entry ',b,' should be ',ibendbrowser);
  1680. until false;
  1681. end;
  1682. end;
  1683. {read the static browser units stuff}
  1684. if (ppufile.header.flags and uf_local_browser)<>0 then
  1685. begin
  1686. if (verbose and v_browser)<>0 then
  1687. begin
  1688. Writeln;
  1689. Writeln('Static browser section');
  1690. Writeln('---------------');
  1691. UnitIndex:=0;
  1692. b:=ppufile.readentry;
  1693. if b=ibbeginsymtablebrowser then
  1694. readbrowser
  1695. else
  1696. Writeln('Wrong end browser entry ',b,' should be ',ibendbrowser);
  1697. end;
  1698. end;
  1699. {shutdown ppufile}
  1700. ppufile.closefile;
  1701. ppufile.free;
  1702. Writeln;
  1703. end;
  1704. procedure help;
  1705. begin
  1706. writeln('usage: ppudump [options] <filename1> <filename2>...');
  1707. writeln;
  1708. writeln('[options] can be:');
  1709. writeln(' -V<verbose> Set verbosity to <verbose>');
  1710. writeln(' H - Show header info');
  1711. writeln(' I - Show interface');
  1712. writeln(' M - Show implementation');
  1713. writeln(' S - Show interface symbols');
  1714. writeln(' D - Show interface definitions');
  1715. writeln(' B - Show browser info');
  1716. writeln(' A - Show all');
  1717. writeln(' -? This helpscreen');
  1718. halt;
  1719. end;
  1720. var
  1721. startpara,
  1722. nrfile,i : longint;
  1723. para : string;
  1724. begin
  1725. writeln(Title+' '+Version);
  1726. writeln(Copyright);
  1727. writeln;
  1728. if paramcount<1 then
  1729. begin
  1730. writeln('usage: dumpppu [options] <filename1> <filename2>...');
  1731. halt(1);
  1732. end;
  1733. { turn verbose on by default }
  1734. verbose:=v_all;
  1735. { read options }
  1736. startpara:=1;
  1737. while copy(paramstr(startpara),1,1)='-' do
  1738. begin
  1739. para:=paramstr(startpara);
  1740. case upcase(para[2]) of
  1741. 'V' : begin
  1742. verbose:=0;
  1743. for i:=3to length(para) do
  1744. case upcase(para[i]) of
  1745. 'H' : verbose:=verbose or v_header;
  1746. 'I' : verbose:=verbose or v_interface;
  1747. 'M' : verbose:=verbose or v_implementation;
  1748. 'D' : verbose:=verbose or v_defs;
  1749. 'S' : verbose:=verbose or v_syms;
  1750. 'B' : verbose:=verbose or v_browser;
  1751. 'A' : verbose:=verbose or v_all;
  1752. end;
  1753. end;
  1754. '?' : help;
  1755. end;
  1756. inc(startpara);
  1757. end;
  1758. { process files }
  1759. for nrfile:=startpara to paramcount do
  1760. dofile (paramstr(nrfile));
  1761. if has_errors then
  1762. Halt(1);
  1763. end.
  1764. {
  1765. $Log$
  1766. Revision 1.33 2002-10-20 14:49:31 peter
  1767. * store original source time in ppu so it can be compared instead of
  1768. comparing with the ppu time
  1769. Revision 1.32 2002/10/06 12:25:53 florian
  1770. + dump of tdefoptions.df_unique
  1771. Revision 1.31 2002/09/27 21:22:04 carl
  1772. * update system information
  1773. Revision 1.30 2002/09/26 12:03:54 florian
  1774. + support of constguid and constwchar const symbols added
  1775. Revision 1.29 2002/08/20 16:54:40 peter
  1776. * write address of varsym always
  1777. Revision 1.28 2002/08/19 19:36:44 peter
  1778. * More fixes for cross unit inlining, all tnodes are now implemented
  1779. * Moved pocall_internconst to po_internconst because it is not a
  1780. calling type at all and it conflicted when inlining of these small
  1781. functions was requested
  1782. Revision 1.27 2002/08/15 15:15:56 carl
  1783. * jmpbuf size allocation for exceptions is now cpu specific (as it should)
  1784. * more generic nodes for maths
  1785. * several fixes for better m68k support
  1786. Revision 1.26 2002/08/11 13:24:20 peter
  1787. * saving of asmsymbols in ppu supported
  1788. * asmsymbollist global is removed and moved into a new class
  1789. tasmlibrarydata that will hold the info of a .a file which
  1790. corresponds with a single module. Added librarydata to tmodule
  1791. to keep the library info stored for the module. In the future the
  1792. objectfiles will also be stored to the tasmlibrarydata class
  1793. * all getlabel/newasmsymbol and friends are moved to the new class
  1794. Revision 1.25 2002/05/18 13:34:27 peter
  1795. * readded missing revisions
  1796. Revision 1.24 2002/05/16 19:46:54 carl
  1797. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  1798. + try to fix temp allocation (still in ifdef)
  1799. + generic constructor calls
  1800. + start of tassembler / tmodulebase class cleanup
  1801. Revision 1.22 2002/05/12 16:53:18 peter
  1802. * moved entry and exitcode to ncgutil and cgobj
  1803. * foreach gets extra argument for passing local data to the
  1804. iterator function
  1805. * -CR checks also class typecasts at runtime by changing them
  1806. into as
  1807. * fixed compiler to cycle with the -CR option
  1808. * fixed stabs with elf writer, finally the global variables can
  1809. be watched
  1810. * removed a lot of routines from cga unit and replaced them by
  1811. calls to cgobj
  1812. * u32bit-s32bit updates for and,or,xor nodes. When one element is
  1813. u32bit then the other is typecasted also to u32bit without giving
  1814. a rangecheck warning/error.
  1815. * fixed pascal calling method with reversing also the high tree in
  1816. the parast, detected by tcalcst3 test
  1817. Revision 1.21 2002/04/23 13:12:58 peter
  1818. * updated for posinfo change
  1819. * updated for mangledname change
  1820. * include i386 registers, removed reference to cpubase unit that would
  1821. make ppudump dependent on the source processor
  1822. Revision 1.20 2002/04/15 19:15:09 carl
  1823. + write std_reg2str instead of gas registers
  1824. Revision 1.19 2002/04/14 17:02:19 carl
  1825. + att_reg2str -> gas_reg2str
  1826. Revision 1.18 2002/04/07 10:23:36 carl
  1827. + added vm / sparc targets
  1828. Revision 1.17 2002/04/04 19:06:14 peter
  1829. * removed unused units
  1830. * use tlocation.size in cg.a_*loc*() routines
  1831. Revision 1.16 2002/04/04 18:50:27 carl
  1832. + added wdosx support (patch from Pavel)
  1833. Revision 1.15 2002/03/31 20:26:42 jonas
  1834. + a_loadfpu_* and a_loadmm_* methods in tcg
  1835. * register allocation is now handled by a class and is mostly processor
  1836. independent (+rgobj.pas and i386/rgcpu.pas)
  1837. * temp allocation is now handled by a class (+tgobj.pas, -i386\tgcpu.pas)
  1838. * some small improvements and fixes to the optimizer
  1839. * some register allocation fixes
  1840. * some fpuvaroffset fixes in the unary minus node
  1841. * push/popusedregisters is now called rg.save/restoreusedregisters and
  1842. (for i386) uses temps instead of push/pop's when using -Op3 (that code is
  1843. also better optimizable)
  1844. * fixed and optimized register saving/restoring for new/dispose nodes
  1845. * LOC_FPU locations now also require their "register" field to be set to
  1846. R_ST, not R_ST0 (the latter is used for LOC_CFPUREGISTER locations only)
  1847. - list field removed of the tnode class because it's not used currently
  1848. and can cause hard-to-find bugs
  1849. Revision 1.14 2002/03/28 20:48:52 carl
  1850. - remove go32v1 support
  1851. Revision 1.13 2002/03/28 16:44:59 armin
  1852. + new flag if unit has local threadvars
  1853. Revision 1.12 2002/03/01 14:08:47 peter
  1854. * parasym added
  1855. Revision 1.11 2002/01/06 12:08:16 peter
  1856. * removed uauto from orddef, use new range_to_basetype generating
  1857. the correct ordinal type for a range
  1858. }