ppudump.pp 56 KB

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