ppudump.pp 54 KB

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