ppudump.pp 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310
  1. {
  2. $Id$
  3. Copyright (c) 1995-98 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 ppu;
  22. const
  23. Version = 'Version 0.99.12';
  24. Title = 'PPU-Analyser';
  25. Copyright = 'Copyright (c) 1995-99 by the Free Pascal Development Team';
  26. { verbosity }
  27. v_none = $0;
  28. v_header = $1;
  29. v_defs = $2;
  30. v_syms = $4;
  31. v_interface = $8;
  32. v_implementation = $10;
  33. v_browser = $20;
  34. v_all = $ff;
  35. var
  36. ppufile : pppufile;
  37. space : string;
  38. symcnt,
  39. defcnt : longint;
  40. read_member : boolean;
  41. verbose : longint;
  42. {****************************************************************************
  43. Helper Routines
  44. ****************************************************************************}
  45. const has_errors : boolean = false;
  46. Procedure Error(const S : string);
  47. Begin
  48. Writeln(S);
  49. has_errors:=true;
  50. End;
  51. Function Target2Str(w:longint):string;
  52. type
  53. ttarget = (target_none
  54. ,target_i386_GO32V1,target_i386_GO32V2,target_i386_linux,
  55. target_i386_OS2,target_i386_Win32
  56. ,target_m68k_Amiga,target_m68k_Atari,target_m68k_Mac,
  57. target_m68k_linux,target_m68k_PalmOS
  58. );
  59. const
  60. Targets : array[ttarget] of string[10]=('none',
  61. 'GO32V1','GO32V2','Linux-i386','OS/2','Win32',
  62. 'Amiga','Mac68k','Atari','Linux-m68k','PalmOs');
  63. begin
  64. if w<=ord(high(ttarget)) then
  65. Target2Str:=Targets[ttarget(w)]
  66. else
  67. Target2Str:='<Unknown>';
  68. end;
  69. Function Cpu2Str(w:longint):string;
  70. type
  71. ttargetcpu=(no_cpu
  72. ,i386,m68k,alpha
  73. );
  74. const
  75. CpuTxt : array[ttargetcpu] of string[5]=
  76. ('none','i386','m68k','alpha');
  77. begin
  78. if w<=ord(high(ttargetcpu)) then
  79. Cpu2Str:=CpuTxt[ttargetcpu(w)]
  80. else
  81. Cpu2Str:='<Unknown>';
  82. end;
  83. const
  84. HexTbl : array[0..15] of char='0123456789ABCDEF';
  85. function HexB(b:byte):string;
  86. begin
  87. HexB[0]:=#2;
  88. HexB[1]:=HexTbl[b shr 4];
  89. HexB[2]:=HexTbl[b and $f];
  90. end;
  91. {****************************************************************************
  92. Read Routines
  93. ****************************************************************************}
  94. Procedure ReadContainer(const prefix:string);
  95. {
  96. Read a serie of strings and write to the screen starting every line
  97. with prefix
  98. }
  99. begin
  100. while not ppufile^.endofentry do
  101. WriteLn(prefix,ppufile^.getstring);
  102. end;
  103. Procedure ReadRef;
  104. begin
  105. if (verbose and v_browser)=0 then
  106. exit;
  107. while (not ppufile^.endofentry) and (not ppufile^.error) do
  108. Writeln(space,' - Refered : ',ppufile^.getword,', (',ppufile^.getlongint,',',ppufile^.getword,')');
  109. end;
  110. Procedure ReadPosInfo;
  111. begin
  112. Writeln(ppufile^.getword,' (',ppufile^.getlongint,',',ppufile^.getword,')');
  113. end;
  114. procedure readderef(const s:string);
  115. type
  116. tdereftype = (derefnil,derefaktrecordindex,derefaktstaticindex,derefunit,derefrecord,derefindex);
  117. var
  118. b : tdereftype;
  119. begin
  120. repeat
  121. b:=tdereftype(ppufile^.getbyte);
  122. case b of
  123. derefnil :
  124. begin
  125. writeln('nil');
  126. break;
  127. end;
  128. derefaktrecordindex :
  129. begin
  130. writeln('AktRecord ',s,' ',ppufile^.getword);
  131. break;
  132. end;
  133. derefaktstaticindex :
  134. begin
  135. writeln('AktStatic ',s,' ',ppufile^.getword);
  136. break;
  137. end;
  138. derefunit :
  139. begin
  140. writeln('Unit ',ppufile^.getword);
  141. break;
  142. end;
  143. derefrecord :
  144. begin
  145. write('RecordDef ',ppufile^.getword,', ');
  146. end;
  147. derefindex :
  148. begin
  149. write(s,' ',ppufile^.getword,', ');
  150. end;
  151. end;
  152. until false;
  153. end;
  154. procedure readdefref;
  155. begin
  156. readderef('Definition');
  157. end;
  158. procedure readsymref;
  159. begin
  160. readderef('Symbol');
  161. end;
  162. procedure read_abstract_proc_def;
  163. type
  164. tprocopt=record
  165. mask : longint;
  166. str : string[30];
  167. end;
  168. const
  169. procopts=24;
  170. procopt : array[1..procopts] of tprocopt=(
  171. (mask:1; str:'Exception handler'),
  172. (mask:2; str:'Virtual Method'),
  173. (mask:4; str:'Stack is not cleared'),
  174. (mask:8; str:'Constructor'),
  175. (mask:$10; str:'Destructor'),
  176. (mask:$20; str:'Internal Procedure'),
  177. (mask:$40; str:'Exported Procedure'),
  178. (mask:$80; str:'I/O-Checking'),
  179. (mask:$100; str:'Abstract method'),
  180. (mask:$200; str:'Interrupt Handler'),
  181. (mask:$400; str:'Inline Procedure'),
  182. (mask:$800; str:'Assembler Procedure'),
  183. (mask:$1000; str:'Overloaded Operator'),
  184. (mask:$2000; str:'External Procedure'),
  185. (mask:$4000; str:'Parameters from left to right'),
  186. (mask:$8000; str:'Main Program'),
  187. (mask:$10000; str:'Static Method'),
  188. (mask:$20000; str:'Method with Override Directive'),
  189. (mask:$40000; str:'Class Method'),
  190. (mask:$80000; str:'Unit Initialisation'),
  191. (mask:$100000; str:'Method Pointer'),
  192. (mask:$200000; str:'C Declaration'),
  193. (mask:$400000; str:'PalmOS Syscall'),
  194. (mask:$800000; str:'Has internal Constant Function')
  195. );
  196. tvarspez : array[0..2] of string[5]=('Value','Const','Var ');
  197. var
  198. procoptions,
  199. i,params : longint;
  200. first : boolean;
  201. begin
  202. write(space,' Return type : ');
  203. readdefref;
  204. writeln(space,' Fpu used : ',ppufile^.getbyte);
  205. procoptions:=ppufile^.getlongint;
  206. if procoptions<>0 then
  207. begin
  208. write(space,' Options : ');
  209. first:=true;
  210. for i:=1to procopts do
  211. if (procoptions and procopt[i].mask)<>0 then
  212. begin
  213. if first then
  214. first:=false
  215. else
  216. write(', ');
  217. write(procopt[i].str);
  218. end;
  219. writeln;
  220. end;
  221. params:=ppufile^.getword;
  222. writeln(space,' Nr of parameters : ',params);
  223. if params>0 then
  224. begin
  225. repeat
  226. write(space,' - ',tvarspez[ppufile^.getbyte],' ');
  227. readdefref;
  228. dec(params);
  229. until params=0;
  230. end;
  231. end;
  232. procedure readcommonsym(const s:string);
  233. type
  234. tsymopt=record
  235. mask : longint;
  236. str : string[30];
  237. end;
  238. const
  239. symopts=6;
  240. symopt : array[1..symopts] of tsymopt=(
  241. (mask:1; str:'Public'),
  242. (mask:2; str:'Private'),
  243. (mask:4; str:'Published'),
  244. (mask:8; str:'Protected'),
  245. (mask:$10; str:'ForwardDef'),
  246. (mask:$20; str:'Static')
  247. );
  248. var
  249. symoptions,
  250. i : longint;
  251. first : boolean;
  252. begin
  253. writeln(space,'** Symbol Nr. ',ppufile^.getword,' **');
  254. writeln(space,s,ppufile^.getstring);
  255. symoptions:=ppufile^.getbyte;
  256. if symoptions<>0 then
  257. begin
  258. write(space,' File Pos: ');
  259. readposinfo;
  260. write(space,' Options: ');
  261. first:=true;
  262. for i:=1to symopts do
  263. if (symoptions and symopt[i].mask)<>0 then
  264. begin
  265. if first then
  266. first:=false
  267. else
  268. write(', ');
  269. write(symopt[i].str);
  270. end;
  271. writeln;
  272. end;
  273. end;
  274. procedure readcommondef(const s:string);
  275. begin
  276. writeln(space,'** Definition Nr. ',ppufile^.getword,' **');
  277. writeln(space,s);
  278. write (space,' Type symbol : ');
  279. readsymref;
  280. end;
  281. {****************************************************************************
  282. Read Symbols Part
  283. ****************************************************************************}
  284. procedure readsymbols;
  285. Const
  286. vo_is_C_var = 2;
  287. Type
  288. absolutetyp = (tovar,toasm,toaddr);
  289. tconsttype = (constord,conststring,constreal,constbool,constint,constchar,constseta);
  290. var
  291. b : byte;
  292. totalsyms,
  293. symcnt,
  294. i,j : longint;
  295. begin
  296. symcnt:=1;
  297. with ppufile^ do
  298. begin
  299. if space<>'' then
  300. Writeln(space,'-----------------------------');
  301. if readentry=ibstartsyms then
  302. begin
  303. totalsyms:=getlongint;
  304. Writeln(space,'Number of symbols: ',totalsyms);
  305. Writeln(space,'Symtable datasize: ',getlongint);
  306. end
  307. else
  308. begin
  309. totalsyms:=-1;
  310. Writeln('!! ibstartsym not found');
  311. end;
  312. repeat
  313. b:=readentry;
  314. if not (b in [iberror,ibendsyms]) then
  315. inc(symcnt);
  316. case b of
  317. ibunitsym :
  318. readcommonsym('Unit symbol ');
  319. iblabelsym :
  320. readcommonsym('Label symbol ');
  321. ibtypesym :
  322. begin
  323. readcommonsym('Type symbol ');
  324. write(space,' Definition: ');
  325. readdefref;
  326. end;
  327. ibprocsym :
  328. begin
  329. readcommonsym('Procedure symbol ');
  330. write(space,' Definition: ');
  331. readdefref;
  332. end;
  333. ibconstsym :
  334. begin
  335. readcommonsym('Constant symbol ');
  336. b:=getbyte;
  337. case tconsttype(b) of
  338. constord :
  339. begin
  340. write (space,' Definition : ');
  341. readdefref;
  342. writeln (space,' Value : ',getlongint)
  343. end;
  344. conststring :
  345. writeln(space,' Value : "'+getstring+'"');
  346. constreal :
  347. writeln(space,' Value : ',getreal);
  348. constbool :
  349. if getlongint<>0 then
  350. writeln (space,' Value : True')
  351. else
  352. writeln (space,' Value : False');
  353. constint :
  354. writeln(space,' Value : ',getlongint);
  355. constchar :
  356. writeln(space,' Value : "'+chr(getlongint)+'"');
  357. constseta :
  358. begin
  359. write (space,' Definition : ');
  360. readdefref;
  361. for i:=1to 4 do
  362. begin
  363. write (space,' Value : ');
  364. for j:=1to 8 do
  365. begin
  366. if j>1 then
  367. write(',');
  368. write(hexb(getbyte));
  369. end;
  370. writeln;
  371. end;
  372. end;
  373. else
  374. Writeln ('!! Invalid unit format : Invalid const type encountered: ',b);
  375. end;
  376. end;
  377. ibvarsym :
  378. begin
  379. readcommonsym('Variable symbol ');
  380. writeln(space,' Type: ',getbyte);
  381. if read_member then
  382. writeln(space,' Address: ',getlongint);
  383. write (space,' Definition: ');
  384. readdefref;
  385. i:=getbyte;
  386. writeln(space,' Options: ',i);
  387. if (i and vo_is_C_var)<>0 then
  388. writeln(space,' Mangledname: ',getstring);
  389. end;
  390. ibenumsym :
  391. begin
  392. readcommonsym('Enumeration symbol ');
  393. write (space,' Definition: ');
  394. readdefref;
  395. writeln(space,' Value: ',getlongint);
  396. end;
  397. ibsyssym :
  398. begin
  399. readcommonsym('Internal system symbol ');
  400. writeln(space,' Internal Nr: ',getlongint);
  401. end;
  402. ibtypedconstsym :
  403. begin
  404. readcommonsym('Typed constant ');
  405. write (space,' Definition: ');
  406. readdefref;
  407. writeln(space,' Label: ',getstring);
  408. end;
  409. ibabsolutesym :
  410. begin
  411. readcommonsym('Absolute variable symbol ');
  412. writeln(space,' Type: ',getbyte);
  413. if read_member then
  414. writeln(space,' Address: ',getlongint);
  415. write (space,' Definition: ');
  416. readdefref;
  417. writeln(space,' Options: ',getbyte);
  418. Write (space,' Relocated to ');
  419. b:=getbyte;
  420. case absolutetyp(b) of
  421. tovar :
  422. Writeln('Name : ',getstring);
  423. toasm :
  424. Writeln('Assembler name : ',getstring);
  425. toaddr :
  426. begin
  427. Write('Address : ',getlongint);
  428. write(' (Far: ',getbyte<>0,')');
  429. end;
  430. else
  431. Writeln ('!! Invalid unit format : Invalid absolute type encountered: ',b);
  432. end;
  433. end;
  434. ibpropertysym :
  435. begin
  436. readcommonsym('Property ');
  437. write (space,' Definition: ');
  438. readdefref;
  439. writeln(space,' Options: ',getlongint);
  440. writeln(space,' Index: ',getlongint);
  441. writeln(space,' Default: ',getlongint);
  442. write(space,' Read symbol: ');
  443. readsymref;
  444. write(space,' Write symbol: ');
  445. readsymref;
  446. write(space,' Stored symbol: ');
  447. readsymref;
  448. {
  449. writeln(space,' Read Name: ',getstring);
  450. writeln(space,' Write Name: ',getstring);
  451. writeln(space,' Stored Name: ',getstring);
  452. }
  453. write(space,' Read Definition: ');
  454. readdefref;
  455. write(space,' Write Definition: ');
  456. readdefref;
  457. write(space,' Stored Definition: ');
  458. readdefref;
  459. end;
  460. ibfuncretsym :
  461. begin
  462. readcommonsym('Func return value ');
  463. write (space,' Definition: ');
  464. readdefref;
  465. writeln(space,' Address: ',getlongint);
  466. end;
  467. iberror :
  468. begin
  469. Writeln('!! Error in PPU');
  470. exit;
  471. end;
  472. ibendsyms :
  473. break;
  474. else
  475. WriteLn('!! Skipping unsupported PPU Entry in Symbols: ',b);
  476. end;
  477. if not EndOfEntry then
  478. Writeln('!! Entry has more information stored');
  479. until false;
  480. if (totalsyms<>-1) and (symcnt-1<>totalsyms) then
  481. Writeln('!! Only read ',symcnt-1,' of ',totalsyms,' symbols');
  482. end;
  483. end;
  484. {****************************************************************************
  485. Read defintions Part
  486. ****************************************************************************}
  487. procedure readdefinitions(start_read : boolean);
  488. type
  489. tsettype = (normset,smallset,varset);
  490. tbasetype = (uauto,uvoid,uchar,
  491. u8bit,u16bit,u32bit,
  492. s8bit,s16bit,s32bit,
  493. bool8bit,bool16bit,bool32bit);
  494. var
  495. b : byte;
  496. oldread_member : boolean;
  497. totaldefs,
  498. defcnt : longint;
  499. begin
  500. defcnt:=0;
  501. with ppufile^ do
  502. begin
  503. if space<>'' then
  504. Writeln(space,'-----------------------------');
  505. if not start_read then
  506. if readentry=ibstartdefs then
  507. begin
  508. totaldefs:=getlongint;
  509. Writeln(space,'Number of definitions: ',totaldefs);
  510. end
  511. else
  512. begin
  513. totaldefs:=-1;
  514. Writeln('!! ibstartdef not found');
  515. end;
  516. repeat
  517. b:=readentry;
  518. if not (b in [iberror,ibenddefs]) then
  519. inc(defcnt);
  520. case b of
  521. ibpointerdef :
  522. begin
  523. readcommondef('Pointer definition');
  524. write (space,' To Definition : ');
  525. readdefref;
  526. writeln(space,' Is Far : ',(getbyte<>0));
  527. end;
  528. iborddef :
  529. begin
  530. readcommondef('Ordinal definition');
  531. write (space,' Base type : ');
  532. b:=getbyte;
  533. case tbasetype(b) of
  534. uauto : writeln('uauto');
  535. uvoid : writeln('uvoid');
  536. uchar : writeln('uchar');
  537. u8bit : writeln('u8bit');
  538. u16bit : writeln('u16bit');
  539. u32bit : writeln('s32bit');
  540. s8bit : writeln('s8bit');
  541. s16bit : writeln('s16bit');
  542. s32bit : writeln('s32bit');
  543. bool8bit : writeln('bool8bit');
  544. bool16bit : writeln('bool16bit');
  545. bool32bit : writeln('bool32bit');
  546. else writeln('!! Warning: Invalid base type ',b);
  547. end;
  548. writeln(space,' Range : ',getlongint,' to ',getlongint);
  549. end;
  550. ibfloatdef :
  551. begin
  552. readcommondef('Float definition');
  553. writeln(space,' Float type : ',getbyte);
  554. end;
  555. ibarraydef :
  556. begin
  557. readcommondef('Array definition');
  558. write (space,' Element type : ');
  559. readdefref;
  560. write (space,' Range Type : ');
  561. readdefref;
  562. writeln(space,' Range : ',getlongint,' to ',getlongint);
  563. writeln(space,' Is Constructor : ',(getbyte<>0));
  564. end;
  565. ibprocdef :
  566. begin
  567. readcommondef('Procedure definition');
  568. read_abstract_proc_def;
  569. writeln(space,' Used Register : ',getbyte);
  570. writeln(space,' Mangled name : ',getstring);
  571. writeln(space,' Number : ',getlongint);
  572. write (space,' Next : ');
  573. readdefref;
  574. write (space,' Class : ');
  575. readdefref;
  576. write (space,' File Pos : ');
  577. readposinfo;
  578. end;
  579. ibprocvardef :
  580. begin
  581. readcommondef('Procedural type (ProcVar) definition');
  582. read_abstract_proc_def;
  583. end;
  584. ibshortstringdef :
  585. begin
  586. readcommondef('ShortString definition');
  587. writeln(space,' Length : ',getbyte);
  588. end;
  589. ibwidestringdef :
  590. begin
  591. readcommondef('WideString definition');
  592. writeln(space,' Length : ',getlongint);
  593. end;
  594. ibansistringdef :
  595. begin
  596. readcommondef('AnsiString definition');
  597. writeln(space,' Length : ',getlongint);
  598. end;
  599. iblongstringdef :
  600. begin
  601. readcommondef('Longstring definition');
  602. writeln(space,' Length : ',getlongint);
  603. end;
  604. ibrecorddef :
  605. begin
  606. readcommondef('Record definition');
  607. writeln(space,' Size : ',getlongint);
  608. {read the record definitions and symbols}
  609. space:=' '+space;
  610. oldread_member:=read_member;
  611. read_member:=true;
  612. readdefinitions(false);
  613. readsymbols;
  614. read_member:=oldread_member;
  615. Delete(space,1,4);
  616. end;
  617. ibobjectdef :
  618. begin
  619. readcommondef('Object/Class definition');
  620. writeln(space,' Size : ',getlongint);
  621. writeln(space,' Vmt offset : ',getlongint);
  622. writeln(space,' Name of Class : ',getstring);
  623. write(space, ' Ancestor Class : ');
  624. readdefref;
  625. writeln(space,' Options : ',getlongint);
  626. {read the record definitions and symbols}
  627. space:=' '+space;
  628. oldread_member:=read_member;
  629. read_member:=true;
  630. readdefinitions(false);
  631. readsymbols;
  632. read_member:=oldread_member;
  633. Delete(space,1,4);
  634. end;
  635. ibfiledef :
  636. begin
  637. ReadCommonDef('File definition');
  638. write (space,' Type : ');
  639. case getbyte of
  640. 0 : writeln('Text');
  641. 1 : begin
  642. write('Typed with definition ');
  643. readdefref;
  644. end;
  645. 2 : writeln('Untyped');
  646. end;
  647. end;
  648. ibformaldef :
  649. readcommondef('Generic Definition (void-typ)');
  650. ibenumdef :
  651. begin
  652. readcommondef('Enumeration type definition');
  653. write(space,'Base enumeration type : ');
  654. readdefref;
  655. writeln(space,' Smallest element : ',getlongint);
  656. writeln(space,' Largest element : ',getlongint);
  657. writeln(space,' Size : ',getlongint);
  658. end;
  659. ibclassrefdef :
  660. begin
  661. readcommondef('Class reference definition');
  662. write (space,' To definition : ');
  663. readdefref;
  664. end;
  665. ibsetdef :
  666. begin
  667. readcommondef('Set definition');
  668. write (space,' Element type : ');
  669. readdefref;
  670. b:=getbyte;
  671. case tsettype(b) of
  672. smallset : writeln(space,' Set with 32 Elements');
  673. normset : writeln(space,' Set with 256 Elements');
  674. varset : writeln(space,' Set with ',getlongint,' Elements');
  675. else writeln('!! Warning: Invalid set type ',b);
  676. end;
  677. end;
  678. iberror :
  679. begin
  680. Writeln('!! Error in PPU');
  681. exit;
  682. end;
  683. ibenddefs :
  684. break;
  685. else
  686. WriteLn('!! Skipping unsupported PPU Entry in definitions: ',b);
  687. end;
  688. if not EndOfEntry then
  689. Writeln('!! Entry has more information stored');
  690. until false;
  691. if (totaldefs<>-1) and (defcnt<>totaldefs) then
  692. Writeln('!! Only read ',defcnt,' of ',totaldefs,' definitions');
  693. end;
  694. end;
  695. {****************************************************************************
  696. Read General Part
  697. ****************************************************************************}
  698. procedure readinterface;
  699. var
  700. b : byte;
  701. sourcenumber,
  702. unitnumber : word;
  703. ucrc,uintfcrc : longint;
  704. begin
  705. with ppufile^ do
  706. begin
  707. repeat
  708. b:=readentry;
  709. case b of
  710. ibmodulename :
  711. Writeln('Module Name: ',getstring);
  712. ibsourcefiles :
  713. begin
  714. sourcenumber:=1;
  715. while not EndOfEntry do
  716. begin
  717. Writeln('Source file ',sourcenumber,' : ',getstring);
  718. inc(sourcenumber);
  719. end;
  720. end;
  721. ibloadunit :
  722. begin
  723. unitnumber:=1;
  724. while not EndOfEntry do
  725. begin
  726. write('Uses unit: ',getstring,' (Number: ',unitnumber,')');
  727. ucrc:=getlongint;
  728. uintfcrc:=getlongint;
  729. write(' (Crc: ',ucrc,', IntfcCrc: ',uintfcrc,')');
  730. if getbyte<>0 then
  731. writeln(' (interface)')
  732. else
  733. writeln(' (implementation)');
  734. inc(unitnumber);
  735. end;
  736. end;
  737. iblinkofiles :
  738. ReadContainer('Link object file: ');
  739. iblinkstaticlibs :
  740. ReadContainer('Link static lib: ');
  741. iblinksharedlibs :
  742. ReadContainer('Link shared lib: ');
  743. iblinkunitfiles :
  744. ReadContainer('Link unit file: ');
  745. iberror :
  746. begin
  747. Writeln('Error in PPU');
  748. exit;
  749. end;
  750. ibendinterface :
  751. break;
  752. else
  753. WriteLn('!! Skipping unsupported PPU Entry in General Part: ',b);
  754. end;
  755. until false;
  756. end;
  757. end;
  758. {****************************************************************************
  759. Read Implementation Part
  760. ****************************************************************************}
  761. procedure readimplementation;
  762. var
  763. b : byte;
  764. begin
  765. with ppufile^ do
  766. begin
  767. repeat
  768. b:=readentry;
  769. case b of
  770. iberror :
  771. begin
  772. Writeln('Error in PPU');
  773. exit;
  774. end;
  775. ibendimplementation :
  776. break;
  777. else
  778. WriteLn('!! Skipping unsupported PPU Entry in Implementation: ',b);
  779. end;
  780. until false;
  781. end;
  782. end;
  783. {****************************************************************************
  784. Read Browser Part
  785. ****************************************************************************}
  786. procedure readbrowser;
  787. var
  788. b : byte;
  789. const indent : string = '';
  790. begin
  791. Writeln(indent,'Start of symtable browser');
  792. indent:=indent+'**';
  793. with ppufile^ do
  794. begin
  795. repeat
  796. b:=readentry;
  797. case b of
  798. ibbeginsymtablebrowser :
  799. { here we must read object and record symtables !! }
  800. begin
  801. indent:=indent+' ';
  802. Writeln(indent,'Record/Object symtable');
  803. readbrowser;
  804. Indent:=Copy(Indent,1,Length(Indent)-2);
  805. end;
  806. ibsymref : begin
  807. readsymref;
  808. readref;
  809. end;
  810. ibdefref : begin
  811. readdefref;
  812. readref;
  813. if (ppufile^.header.flags and uf_local_browser)<>0 then
  814. begin
  815. { parast and localst }
  816. indent:=indent+' ';
  817. Writeln(indent,'Parasymtable for function');
  818. readdefinitions(false);
  819. readsymbols;
  820. b:=ppufile^.readentry;
  821. if b=ibbeginsymtablebrowser then
  822. readbrowser;
  823. Writeln(indent,'Localsymtable for function');
  824. readdefinitions(false);
  825. readsymbols;
  826. b:=ppufile^.readentry;
  827. if b=ibbeginsymtablebrowser then
  828. readbrowser;
  829. Indent:=Copy(Indent,1,Length(Indent)-2);
  830. end;
  831. end;
  832. iberror : begin
  833. Writeln('Error in PPU');
  834. exit;
  835. end;
  836. ibendsymtablebrowser : break;
  837. else
  838. begin
  839. WriteLn('!! Skipping unsupported PPU Entry in Browser: ',b);
  840. Halt;
  841. end;
  842. end;
  843. until false;
  844. end;
  845. Indent:=Copy(Indent,1,Length(Indent)-2);
  846. Writeln(Indent,'End of symtable browser');
  847. end;
  848. procedure dofile (filename : string);
  849. var
  850. b,unitindex : byte;
  851. begin
  852. { reset }
  853. space:='';
  854. defcnt:=0;
  855. symcnt:=0;
  856. { fix filename }
  857. if pos('.',filename)=0 then
  858. filename:=filename+'.ppu';
  859. ppufile:=new(pppufile,Init(filename));
  860. if not ppufile^.open then
  861. begin
  862. writeln ('IO-Error when opening : ',filename,', Skipping');
  863. exit;
  864. end;
  865. { PPU File is open, check for PPU Id }
  866. if not ppufile^.CheckPPUID then
  867. begin
  868. writeln(Filename,' : Not a valid PPU file, Skipping');
  869. exit;
  870. end;
  871. { Check PPU Version }
  872. Writeln('Analyzing ',filename,' (v',ppufile^.GetPPUVersion,')');
  873. if ppufile^.GetPPUVersion<16 then
  874. begin
  875. writeln(Filename,' : Old PPU Formats (<v16) are not supported, Skipping');
  876. exit;
  877. end;
  878. { Write PPU Header Information }
  879. if (verbose and v_header)<>0 then
  880. begin
  881. Writeln;
  882. Writeln('Header');
  883. Writeln('-------');
  884. with ppufile^.header do
  885. begin
  886. Writeln('Compiler version : ',hi(ppufile^.header.compiler and $ff),'.',lo(ppufile^.header.compiler));
  887. WriteLn('Target processor : ',Cpu2Str(cpu));
  888. WriteLn('Target operating system : ',Target2Str(target));
  889. Write ('Unit flags : ',flags,', ');
  890. if (flags and uf_init)<>0 then
  891. write('init ');
  892. if (flags and uf_big_endian)<>0 then
  893. write('big_endian ');
  894. if (flags and uf_finalize)<>0 then
  895. write('finalize ');
  896. if (flags and uf_has_dbx)<>0 then
  897. write('has_dbx ');
  898. if (flags and uf_has_browser)<>0 then
  899. write('has_browser ');
  900. if (flags and uf_smartlink)<>0 then
  901. write('smartlink ');
  902. if (flags and uf_in_library)<>0 then
  903. write('in_library ');
  904. if (flags and uf_shared_linked)<>0 then
  905. write('shared_linked ');
  906. if (flags and uf_static_linked)<>0 then
  907. write('static_linked ');
  908. if (flags and uf_local_browser)<>0 then
  909. write('local_browser ');
  910. if (flags and uf_obj_linked)<>0 then
  911. write('obj_linked ');
  912. if (flags=0) then
  913. write('(none)');
  914. writeln;
  915. Writeln('FileSize (w/o header) : ',size);
  916. Writeln('Checksum : ',checksum);
  917. Writeln('Interface Checksum : ',interface_checksum);
  918. end;
  919. end;
  920. {read the general stuff}
  921. if (verbose and v_interface)<>0 then
  922. begin
  923. Writeln;
  924. Writeln('Interface section');
  925. Writeln('------------------');
  926. readinterface;
  927. end
  928. else
  929. ppufile^.skipuntilentry(ibendinterface);
  930. {read the definitions}
  931. if (verbose and v_defs)<>0 then
  932. begin
  933. Writeln;
  934. Writeln('Interface definitions');
  935. Writeln('----------------------');
  936. readdefinitions(false);
  937. end
  938. else
  939. ppufile^.skipuntilentry(ibenddefs);
  940. {read the symbols}
  941. if (verbose and v_syms)<>0 then
  942. begin
  943. Writeln;
  944. Writeln('Interface Symbols');
  945. Writeln('------------------');
  946. readsymbols;
  947. end
  948. else
  949. ppufile^.skipuntilentry(ibendsyms);
  950. {read the implementation stuff}
  951. { Not used at the moment (PFV)
  952. if (verbose and v_implementation)<>0 then
  953. begin
  954. Writeln;
  955. Writeln('Implementation section');
  956. Writeln('-----------------------');
  957. readimplementation;
  958. end
  959. else}
  960. ppufile^.skipuntilentry(ibendimplementation);
  961. {read the static browser units stuff}
  962. if (ppufile^.header.flags and uf_local_browser)<>0 then
  963. begin
  964. if (verbose and v_defs)<>0 then
  965. begin
  966. Writeln;
  967. Writeln('Static definitions');
  968. Writeln('----------------------');
  969. readdefinitions(false);
  970. end
  971. else
  972. ppufile^.skipuntilentry(ibenddefs);
  973. {read the symbols}
  974. if (verbose and v_syms)<>0 then
  975. begin
  976. Writeln;
  977. Writeln('Static Symbols');
  978. Writeln('------------------');
  979. readsymbols;
  980. end;
  981. end;
  982. {read the browser units stuff}
  983. if (ppufile^.header.flags and uf_has_browser)<>0 then
  984. begin
  985. if (verbose and v_browser)<>0 then
  986. begin
  987. Writeln;
  988. Writeln('Browser section');
  989. Writeln('---------------');
  990. UnitIndex:=0;
  991. repeat
  992. b:=ppufile^.readentry;
  993. if b = ibendbrowser then break;
  994. if b=ibbeginsymtablebrowser then
  995. begin
  996. Writeln('Unit ',UnitIndex);
  997. readbrowser;
  998. Inc(UnitIndex);
  999. end
  1000. else
  1001. Writeln('Wrong end browser entry ',b,' should be ',ibendbrowser);
  1002. until false;
  1003. end;
  1004. end;
  1005. {read the static browser units stuff}
  1006. if (ppufile^.header.flags and uf_local_browser)<>0 then
  1007. begin
  1008. if (verbose and v_browser)<>0 then
  1009. begin
  1010. Writeln;
  1011. Writeln('Static browser section');
  1012. Writeln('---------------');
  1013. b:=ppufile^.readentry;
  1014. if b=ibbeginsymtablebrowser then
  1015. begin
  1016. Writeln('Unit ',UnitIndex);
  1017. readbrowser;
  1018. Inc(UnitIndex);
  1019. end
  1020. else
  1021. Writeln('Wrong end browser entry ',b,' should be ',ibendbrowser);
  1022. end;
  1023. end;
  1024. {shutdown ppufile}
  1025. ppufile^.close;
  1026. dispose(ppufile,done);
  1027. Writeln;
  1028. end;
  1029. procedure help;
  1030. begin
  1031. writeln('usage: ppudump [options] <filename1> <filename2>...');
  1032. writeln;
  1033. writeln('[options] can be:');
  1034. writeln(' -V<verbose> Set verbosity to <verbose>');
  1035. writeln(' H - Show header info');
  1036. writeln(' I - Show interface');
  1037. writeln(' M - Show implementation');
  1038. writeln(' S - Show interface symbols');
  1039. writeln(' D - Show interface definitions');
  1040. writeln(' B - Show browser info');
  1041. writeln(' A - Show all');
  1042. writeln(' -? This helpscreen');
  1043. halt;
  1044. end;
  1045. var
  1046. startpara,
  1047. nrfile,i : longint;
  1048. para : string;
  1049. begin
  1050. writeln(Title+' '+Version);
  1051. writeln(Copyright);
  1052. writeln;
  1053. if paramcount<1 then
  1054. begin
  1055. writeln('usage: dumpppu [options] <filename1> <filename2>...');
  1056. halt(1);
  1057. end;
  1058. { turn verbose on by default }
  1059. verbose:=v_all;
  1060. { read options }
  1061. startpara:=1;
  1062. while copy(paramstr(startpara),1,1)='-' do
  1063. begin
  1064. para:=paramstr(startpara);
  1065. case upcase(para[2]) of
  1066. 'V' : begin
  1067. verbose:=0;
  1068. for i:=3to length(para) do
  1069. case upcase(para[i]) of
  1070. 'H' : verbose:=verbose or v_header;
  1071. 'I' : verbose:=verbose or v_interface;
  1072. 'M' : verbose:=verbose or v_implementation;
  1073. 'D' : verbose:=verbose or v_defs;
  1074. 'S' : verbose:=verbose or v_syms;
  1075. 'B' : verbose:=verbose or v_browser;
  1076. 'A' : verbose:=verbose or v_all;
  1077. end;
  1078. end;
  1079. '?' : help;
  1080. end;
  1081. inc(startpara);
  1082. end;
  1083. { process files }
  1084. for nrfile:=startpara to paramcount do
  1085. dofile (paramstr(nrfile));
  1086. if has_errors then
  1087. Halt(1);
  1088. end.
  1089. {
  1090. $Log$
  1091. Revision 1.3.2.1 1999-07-05 21:43:08 peter
  1092. * merged property fixes
  1093. Revision 1.3 1999/06/08 22:16:06 peter
  1094. * version 0.99.12
  1095. Revision 1.2 1999/05/14 17:52:04 peter
  1096. * new deref
  1097. Revision 1.1 1999/05/12 16:11:39 peter
  1098. * moved
  1099. Revision 1.31 1999/04/29 17:22:34 peter
  1100. * fixed property sym
  1101. Revision 1.30 1999/04/26 18:27:39 peter
  1102. * more updates
  1103. Revision 1.29 1999/04/26 13:30:44 peter
  1104. * support new unit format
  1105. Revision 1.28 1999/04/26 09:35:04 peter
  1106. * support for v16
  1107. Revision 1.27 1999/03/16 21:00:03 peter
  1108. * fixed varsym
  1109. Revision 1.26 1999/03/02 22:54:54 peter
  1110. * merged some of my code back which was changed after pierres commit
  1111. Revision 1.25 1999/03/02 14:21:44 pierre
  1112. * adapted to symtable changes mainly local browser
  1113. Revision 1.24 1999/03/02 13:48:16 peter
  1114. * better procoptions display and easy maintainance
  1115. * removed implementation section printing, becuase it's not used
  1116. * linkunitfiles support
  1117. Revision 1.23 1999/02/22 13:22:00 pierre
  1118. + static browser reading
  1119. Revision 1.22 1999/02/16 00:48:42 peter
  1120. * updated for new flags
  1121. Revision 1.21 1998/11/28 16:21:02 peter
  1122. + support for dll variables
  1123. Revision 1.20 1998/11/12 11:36:43 peter
  1124. * fixed target name
  1125. Revision 1.19 1998/11/04 10:17:42 peter
  1126. + const,var,value is written for parameters
  1127. Revision 1.18 1998/10/13 13:06:14 peter
  1128. * updated for new target enum
  1129. Revision 1.17 1998/09/25 09:51:53 peter
  1130. + symtable size and # of symbols
  1131. Revision 1.16 1998/09/24 23:24:11 peter
  1132. * small update to support ibstartdef
  1133. Revision 1.12 1998/09/21 08:45:28 pierre
  1134. + added vmt_offset in tobjectdef.write for fututre use
  1135. (first steps to have objects without vmt if no virtual !!)
  1136. + added fpu_used field for tabstractprocdef :
  1137. sets this level to 2 if the functions return with value in FPU
  1138. (is then set to correct value at parsing of implementation)
  1139. THIS MIGHT refuse some code with FPU expression too complex
  1140. that were accepted before and even in some cases
  1141. that don't overflow in fact
  1142. ( like if f : float; is a forward that finally in implementation
  1143. only uses one fpu register !!)
  1144. Nevertheless I think that it will improve security on
  1145. FPU operations !!
  1146. * most other changes only for UseBrowser code
  1147. (added symtable references for record and objects)
  1148. local switch for refs to args and local of each function
  1149. (static symtable still missing)
  1150. UseBrowser still not stable and probably broken by
  1151. the definition hash array !!
  1152. Revision 1.11 1998/09/18 08:01:42 pierre
  1153. + improvement on the usebrowser part
  1154. (does not work correctly for now)
  1155. Revision 1.10 1998/09/01 17:35:33 peter
  1156. * update for new po's
  1157. Revision 1.9 1998/09/01 12:46:52 peter
  1158. + enum savesize
  1159. Revision 1.8 1998/08/26 10:01:18 peter
  1160. + set support
  1161. Revision 1.7 1998/08/20 13:01:41 peter
  1162. + object_options, new enumdef
  1163. Revision 1.6 1998/08/17 10:26:28 peter
  1164. * updated for new shared/static style
  1165. Revision 1.5 1998/08/13 10:56:28 peter
  1166. * check if a whole entry is read
  1167. + support for constset
  1168. Revision 1.4 1998/08/11 15:31:44 peter
  1169. * write extended to ppu file
  1170. * new version 0.99.7
  1171. Revision 1.3 1998/07/10 10:59:17 peter
  1172. + m68k target support
  1173. Revision 1.2 1998/06/17 13:58:28 peter
  1174. + symbol/def nrs are now listed
  1175. Revision 1.1 1998/06/13 00:05:01 peter
  1176. + new util to dump v15+ ppu
  1177. }