ppudump.pp 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 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. {$ifdef go32v2}
  23. dpmiexcp,
  24. {$endif go32v2}
  25. ppu;
  26. const
  27. Version = 'Version 1.10';
  28. Title = 'PPU-Analyser';
  29. Copyright = 'Copyright (c) 1998-2001 by the Free Pascal Development Team';
  30. { verbosity }
  31. v_none = $0;
  32. v_header = $1;
  33. v_defs = $2;
  34. v_syms = $4;
  35. v_interface = $8;
  36. v_implementation = $10;
  37. v_browser = $20;
  38. v_all = $ff;
  39. var
  40. ppufile : tppufile;
  41. space : string;
  42. read_member : boolean;
  43. unitindex : longint;
  44. verbose : longint;
  45. {****************************************************************************
  46. Helper Routines
  47. ****************************************************************************}
  48. const has_errors : boolean = false;
  49. Procedure Error(const S : string);
  50. Begin
  51. Writeln(S);
  52. has_errors:=true;
  53. End;
  54. Function Target2Str(w:longint):string;
  55. type
  56. { taken from systems.pas }
  57. ttarget =
  58. (
  59. target_none, { 0 }
  60. target_i386_GO32V1, { 1 }
  61. target_i386_GO32V2, { 2 }
  62. target_i386_linux, { 3 }
  63. target_i386_OS2, { 4 }
  64. target_i386_Win32, { 5 }
  65. target_i386_freebsd, { 6 }
  66. target_m68k_Amiga, { 7 }
  67. target_m68k_Atari, { 8 }
  68. target_m68k_Mac, { 9 }
  69. target_m68k_linux, { 10 }
  70. target_m68k_PalmOS, { 11 }
  71. target_alpha_linux, { 12 }
  72. target_powerpc_linux, { 13 }
  73. target_powerpc_macos, { 14 }
  74. target_i386_sunos, { 15 }
  75. target_i386_beos, { 16 }
  76. target_i386_netbsd, { 17 }
  77. target_m68k_netbsd, { 18 }
  78. target_i386_Netware, { 19 }
  79. target_i386_qnx { 20 }
  80. );
  81. const
  82. Targets : array[ttarget] of string[12]=(
  83. { 0 } 'none',
  84. { 1 } 'GO32V1',
  85. { 2 } 'GO32V2',
  86. { 3 } 'Linux-i386',
  87. { 4 } 'OS/2',
  88. { 5 } 'Win32',
  89. { 6 } 'FreeBSD-i386',
  90. { 7 } 'Amiga',
  91. { 8 } 'Atari',
  92. { 9 } 'MacOS-m68k',
  93. { 10 } 'Linux-m68k',
  94. { 11 } 'PalmOS-m68k',
  95. { 12 } 'Linux-alpha',
  96. { 13 } 'Linux-ppc',
  97. { 14 } 'MacOS-ppc',
  98. { 15 } 'Solaris-i386',
  99. { 16 } 'BeOS-i386',
  100. { 17 } 'NetBSD-i386',
  101. { 18 } 'NetBSD-m68k',
  102. { 19 } 'Netware',
  103. { 20 } 'Qnx-i386'
  104. );
  105. begin
  106. if w<=ord(high(ttarget)) then
  107. Target2Str:=Targets[ttarget(w)]
  108. else
  109. Target2Str:='<Unknown>';
  110. end;
  111. Function Cpu2Str(w:longint):string;
  112. type
  113. { Copied from systems.pas }
  114. ttargetcpu=
  115. (
  116. no_cpu, { 0 }
  117. i386, { 1 }
  118. m68k, { 2 }
  119. alpha, { 3 }
  120. powerpc { 4 }
  121. );
  122. const
  123. CpuTxt : array[ttargetcpu] of string[7]=
  124. ('none','i386','m68k','alpha','powerpc');
  125. begin
  126. if w<=ord(high(ttargetcpu)) then
  127. Cpu2Str:=CpuTxt[ttargetcpu(w)]
  128. else
  129. Cpu2Str:='<Unknown>';
  130. end;
  131. function PPUFlags2Str(flags:longint):string;
  132. type
  133. tflagopt=record
  134. mask : longint;
  135. str : string[30];
  136. end;
  137. const
  138. flagopts=14;
  139. flagopt : array[1..flagopts] of tflagopt=(
  140. (mask: $1 ;str:'init'),
  141. (mask: $2 ;str:'final'),
  142. (mask: $4 ;str:'big_endian'),
  143. (mask: $8 ;str:'dbx'),
  144. (mask: $10 ;str:'browser'),
  145. (mask: $20 ;str:'in_library'),
  146. (mask: $40 ;str:'smart_linked'),
  147. (mask: $80 ;str:'static_linked'),
  148. (mask: $100 ;str:'shared_linked'),
  149. (mask: $200 ;str:'local_browser'),
  150. (mask: $400 ;str:'no_link'),
  151. (mask: $800 ;str:'has_resources'),
  152. (mask: $1000 ;str:'little_endian'),
  153. (mask: $2000 ;str:'release')
  154. );
  155. var
  156. i : longint;
  157. first : boolean;
  158. s : string;
  159. begin
  160. s:='';
  161. if flags<>0 then
  162. begin
  163. first:=true;
  164. for i:=1to flagopts do
  165. if (flags and flagopt[i].mask)<>0 then
  166. begin
  167. if first then
  168. first:=false
  169. else
  170. s:=s+', ';
  171. s:=s+flagopt[i].str;
  172. end;
  173. end
  174. else
  175. s:='none';
  176. PPUFlags2Str:=s;
  177. end;
  178. const
  179. HexTbl : array[0..15] of char='0123456789ABCDEF';
  180. function HexB(b:byte):string;
  181. begin
  182. HexB[0]:=#2;
  183. HexB[1]:=HexTbl[b shr 4];
  184. HexB[2]:=HexTbl[b and $f];
  185. end;
  186. function hexstr(val : cardinal;cnt : byte) : string;
  187. const
  188. HexTbl : array[0..15] of char='0123456789ABCDEF';
  189. var
  190. i : longint;
  191. begin
  192. hexstr[0]:=char(cnt);
  193. for i:=cnt downto 1 do
  194. begin
  195. hexstr[i]:=hextbl[val and $f];
  196. val:=val shr 4;
  197. end;
  198. end;
  199. {****************************************************************************
  200. Read Routines
  201. ****************************************************************************}
  202. Procedure ReadLinkContainer(const prefix:string);
  203. {
  204. Read a serie of strings and write to the screen starting every line
  205. with prefix
  206. }
  207. function maskstr(m:longint):string;
  208. const
  209. { link options }
  210. link_none = $0;
  211. link_allways = $1;
  212. link_static = $2;
  213. link_smart = $4;
  214. link_shared = $8;
  215. var
  216. s : string;
  217. begin
  218. s:='';
  219. if (m and link_allways)<>0 then
  220. s:=s+'always ';
  221. if (m and link_static)<>0 then
  222. s:=s+'static ';
  223. if (m and link_smart)<>0 then
  224. s:=s+'smart ';
  225. if (m and link_shared)<>0 then
  226. s:=s+'shared ';
  227. maskstr:=s;
  228. end;
  229. var
  230. s : string;
  231. m : longint;
  232. begin
  233. while not ppufile.endofentry do
  234. begin
  235. s:=ppufile.getstring;
  236. m:=ppufile.getlongint;
  237. WriteLn(prefix,s,' (',maskstr(m),')');
  238. end;
  239. end;
  240. Procedure ReadContainer(const prefix:string);
  241. {
  242. Read a serie of strings and write to the screen starting every line
  243. with prefix
  244. }
  245. begin
  246. while not ppufile.endofentry do
  247. WriteLn(prefix,ppufile.getstring);
  248. end;
  249. Procedure ReadRef;
  250. begin
  251. if (verbose and v_browser)=0 then
  252. exit;
  253. while (not ppufile.endofentry) and (not ppufile.error) do
  254. Writeln(space,' - Refered : ',ppufile.getword,', (',ppufile.getlongint,',',ppufile.getword,')');
  255. end;
  256. Procedure ReadPosInfo;
  257. begin
  258. Writeln(ppufile.getword,' (',ppufile.getlongint,',',ppufile.getword,')');
  259. end;
  260. function readderef(const s:string;skipnil:boolean):boolean;
  261. type
  262. tdereftype = (derefnil,derefaktrecordindex,derefaktstaticindex,
  263. derefunit,derefrecord,derefindex,
  264. dereflocal,derefpara,derefaktlocalindex);
  265. var
  266. b : tdereftype;
  267. begin
  268. readderef:=true;
  269. repeat
  270. b:=tdereftype(ppufile.getbyte);
  271. case b of
  272. derefnil :
  273. begin
  274. if not skipnil then
  275. writeln('nil');
  276. readderef:=false;
  277. break;
  278. end;
  279. derefaktrecordindex :
  280. begin
  281. writeln('AktRecord ',s,' ',ppufile.getword);
  282. break;
  283. end;
  284. derefaktstaticindex :
  285. begin
  286. writeln('AktStatic ',s,' ',ppufile.getword);
  287. break;
  288. end;
  289. derefaktlocalindex :
  290. begin
  291. writeln('AktLocal ',s,' ',ppufile.getword);
  292. break;
  293. end;
  294. derefunit :
  295. begin
  296. writeln('Unit ',ppufile.getword);
  297. break;
  298. end;
  299. derefrecord :
  300. begin
  301. write('RecordDef ',ppufile.getword,', ');
  302. end;
  303. derefpara :
  304. begin
  305. write('Parameter of procdef ',ppufile.getword,', ');
  306. end;
  307. dereflocal :
  308. begin
  309. write('Local of procdef ',ppufile.getword,', ');
  310. end;
  311. derefindex :
  312. begin
  313. write(s,' ',ppufile.getword,', ');
  314. end;
  315. else
  316. begin
  317. writeln('!! unsupported dereftyp: ',ord(b));
  318. break;
  319. end;
  320. end;
  321. until false;
  322. end;
  323. function readdefref:boolean;
  324. begin
  325. readdefref:=readderef('Definition',false);
  326. end;
  327. function readsymref:boolean;
  328. begin
  329. readsymref:=readderef('Symbol',false);
  330. end;
  331. procedure readtype;
  332. var
  333. b1,b2 : boolean;
  334. begin
  335. b1:=readderef('Definition',true);
  336. b2:=readderef('Symbol',true);
  337. if not(b1 or b2) then
  338. Writeln('nil')
  339. else
  340. if (b1 and b2) then
  341. Writeln('!! Type has both definition and symbol stored');
  342. end;
  343. procedure readsymlist(const s:string);
  344. type
  345. tsltype = (sl_none,
  346. sl_load,
  347. sl_call,
  348. sl_subscript,
  349. sl_vec
  350. );
  351. const
  352. slstr : array[tsltype] of string[9] = ('',
  353. 'load',
  354. 'call',
  355. 'subscript',
  356. 'vec'
  357. );
  358. var
  359. sl : tsltype;
  360. begin
  361. readdefref;
  362. repeat
  363. sl:=tsltype(ppufile.getbyte);
  364. if sl=sl_none then
  365. break;
  366. write(s,'(',slstr[sl],') ');
  367. case sl of
  368. sl_call,
  369. sl_load,
  370. sl_subscript :
  371. readsymref;
  372. sl_vec :
  373. writeln(ppufile.getlongint);
  374. end;
  375. until false;
  376. end;
  377. { Read abstract procdef and return if inline procdef }
  378. type
  379. tproccalloption=(pocall_none,
  380. pocall_cdecl, { procedure uses C styled calling }
  381. pocall_cppdecl, { C++ calling conventions }
  382. pocall_compilerproc, { Procedure is used for internal compiler calls }
  383. pocall_far16, { Far16 for OS/2 }
  384. pocall_fpccall, { FPC default calling }
  385. pocall_inline, { Procedure is an assembler macro }
  386. pocall_internconst, { procedure has constant evaluator intern }
  387. pocall_internproc, { Procedure has compiler magic}
  388. pocall_palmossyscall, { procedure is a PalmOS system call }
  389. pocall_pascal, { pascal standard left to right }
  390. pocall_register, { procedure uses register (fastcall) calling }
  391. pocall_safecall, { safe call calling conventions }
  392. pocall_stdcall, { procedure uses stdcall call }
  393. pocall_system { system call }
  394. );
  395. tproccalloptions=set of tproccalloption;
  396. tproctypeoption=(potype_none,
  397. potype_proginit, { Program initialization }
  398. potype_unitinit, { unit initialization }
  399. potype_unitfinalize, { unit finalization }
  400. potype_constructor, { Procedure is a constructor }
  401. potype_destructor, { Procedure is a destructor }
  402. potype_operator { Procedure defines an operator }
  403. );
  404. tproctypeoptions=set of tproctypeoption;
  405. tprocoption=(po_none,
  406. po_classmethod, { class method }
  407. po_virtualmethod, { Procedure is a virtual method }
  408. po_abstractmethod, { Procedure is an abstract method }
  409. po_staticmethod, { static method }
  410. po_overridingmethod, { method with override directive }
  411. po_methodpointer, { method pointer, only in procvardef, also used for 'with object do' }
  412. po_containsself, { self is passed explicit to the compiler }
  413. po_interrupt, { Procedure is an interrupt handler }
  414. po_iocheck, { IO checking should be done after a call to the procedure }
  415. po_assembler, { Procedure is written in assembler }
  416. po_msgstr, { method for string message handling }
  417. po_msgint, { method for int message handling }
  418. po_exports, { Procedure has export directive (needed for OS/2) }
  419. po_external, { Procedure is external (in other object or lib)}
  420. po_savestdregs, { save std regs cdecl and stdcall need that ! }
  421. po_saveregisters, { save all registers }
  422. po_overload, { procedure is declared with overload directive }
  423. po_varargs { printf like arguments }
  424. );
  425. tprocoptions=set of tprocoption;
  426. function read_abstract_proc_def:tproccalloption;
  427. type
  428. tproccallopt=record
  429. mask : tproccalloption;
  430. str : string[30];
  431. end;
  432. tproctypeopt=record
  433. mask : tproctypeoption;
  434. str : string[30];
  435. end;
  436. tprocopt=record
  437. mask : tprocoption;
  438. str : string[30];
  439. end;
  440. const
  441. proccalloptionStr : array[tproccalloption] of string[14]=('',
  442. 'CDecl',
  443. 'CPPDecl',
  444. 'CompilerProc',
  445. 'Far16',
  446. 'FPCCall',
  447. 'Inline',
  448. 'InternConst',
  449. 'InternProc',
  450. 'PalmOSSysCall',
  451. 'Pascal',
  452. 'Register',
  453. 'SafeCall',
  454. 'StdCall',
  455. 'System'
  456. );
  457. proctypeopts=6;
  458. proctypeopt : array[1..proctypeopts] of tproctypeopt=(
  459. (mask:potype_proginit; str:'ProgInit'),
  460. (mask:potype_unitinit; str:'UnitInit'),
  461. (mask:potype_unitfinalize;str:'UnitFinalize'),
  462. (mask:potype_constructor; str:'Constructor'),
  463. (mask:potype_destructor; str:'Destructor'),
  464. (mask:potype_operator; str:'Operator')
  465. );
  466. procopts=18;
  467. procopt : array[1..procopts] of tprocopt=(
  468. (mask:po_classmethod; str:'ClassMethod'),
  469. (mask:po_virtualmethod; str:'VirtualMethod'),
  470. (mask:po_abstractmethod; str:'AbstractMethod'),
  471. (mask:po_staticmethod; str:'StaticMethod'),
  472. (mask:po_overridingmethod;str:'OverridingMethod'),
  473. (mask:po_methodpointer; str:'MethodPointer'),
  474. (mask:po_containsself; str:'ContainsSelf'),
  475. (mask:po_interrupt; str:'Interrupt'),
  476. (mask:po_iocheck; str:'IOCheck'),
  477. (mask:po_assembler; str:'Assembler'),
  478. (mask:po_msgstr; str:'MsgStr'),
  479. (mask:po_msgint; str:'MsgInt'),
  480. (mask:po_exports; str:'Exports'),
  481. (mask:po_external; str:'External'),
  482. (mask:po_savestdregs; str:'SaveStdRegs'),
  483. (mask:po_saveregisters; str:'SaveRegisters'),
  484. (mask:po_overload; str:'Overload'),
  485. (mask:po_varargs; str:'VarArgs')
  486. );
  487. tvarspez : array[0..3] of string[5]=('Value','Const','Var ','Out ');
  488. var
  489. proctypeoption : tproctypeoption;
  490. proccalloption : tproccalloption;
  491. procoptions : tprocoptions;
  492. i,params : longint;
  493. first : boolean;
  494. begin
  495. write(space,' Return type : ');
  496. readtype;
  497. writeln(space,' Fpu used : ',ppufile.getbyte);
  498. proctypeoption:=tproctypeoption(ppufile.getbyte);
  499. if proctypeoption<>potype_none then
  500. begin
  501. write(space,' TypeOption : ');
  502. first:=true;
  503. for i:=1to proctypeopts do
  504. if (proctypeopt[i].mask=proctypeoption) then
  505. begin
  506. if first then
  507. first:=false
  508. else
  509. write(', ');
  510. write(proctypeopt[i].str);
  511. end;
  512. writeln;
  513. end;
  514. proccalloption:=tproccalloption(ppufile.getbyte);
  515. read_abstract_proc_def:=proccalloption;
  516. writeln(space,' CallOption : ',proccalloptionStr[proccalloption]);
  517. ppufile.getsmallset(procoptions);
  518. if procoptions<>[] then
  519. begin
  520. write(space,' Options : ');
  521. first:=true;
  522. for i:=1to procopts do
  523. if (procopt[i].mask in procoptions) then
  524. begin
  525. if first then
  526. first:=false
  527. else
  528. write(', ');
  529. write(procopt[i].str);
  530. end;
  531. writeln;
  532. end;
  533. params:=ppufile.getword;
  534. writeln(space,' Nr of parameters : ',params);
  535. if params>0 then
  536. begin
  537. repeat
  538. write(space,' - ',tvarspez[ppufile.getbyte],' : ');
  539. readtype;
  540. write(space,' Default : ');
  541. readsymref;
  542. dec(params);
  543. until params=0;
  544. end;
  545. end;
  546. procedure readcommonsym(const s:string);
  547. type
  548. tsymoption=(sp_none,
  549. sp_public,
  550. sp_private,
  551. sp_published,
  552. sp_protected,
  553. sp_forwarddef,
  554. sp_static,
  555. sp_primary_typesym { this is for typesym, to know who is the primary symbol of a def }
  556. );
  557. tsymoptions=set of tsymoption;
  558. tsymopt=record
  559. mask : tsymoption;
  560. str : string[30];
  561. end;
  562. const
  563. symopts=7;
  564. symopt : array[1..symopts] of tsymopt=(
  565. (mask:sp_public; str:'Public'),
  566. (mask:sp_private; str:'Private'),
  567. (mask:sp_published; str:'Published'),
  568. (mask:sp_protected; str:'Protected'),
  569. (mask:sp_forwarddef; str:'ForwardDef'),
  570. (mask:sp_static; str:'Static'),
  571. (mask:sp_primary_typesym;str:'PrimaryTypeSym')
  572. );
  573. var
  574. symoptions : tsymoptions;
  575. i : longint;
  576. first : boolean;
  577. begin
  578. writeln(space,'** Symbol Nr. ',ppufile.getword,' **');
  579. writeln(space,s,ppufile.getstring);
  580. ppufile.getsmallset(symoptions);
  581. if symoptions<>[] then
  582. begin
  583. write(space,' File Pos: ');
  584. readposinfo;
  585. write(space,' SymOptions: ');
  586. first:=true;
  587. for i:=1to symopts do
  588. if (symopt[i].mask in symoptions) then
  589. begin
  590. if first then
  591. first:=false
  592. else
  593. write(', ');
  594. write(symopt[i].str);
  595. end;
  596. writeln;
  597. end;
  598. end;
  599. procedure readcommondef(const s:string);
  600. type
  601. tdefoption=(df_none,
  602. df_has_inittable, { init data has been generated }
  603. df_has_rttitable { rtti data has been generated }
  604. );
  605. tdefoptions=set of tdefoption;
  606. var
  607. defopts : tdefoptions;
  608. begin
  609. writeln(space,'** Definition Nr. ',ppufile.getword,' **');
  610. writeln(space,s);
  611. write (space,' Type symbol : ');
  612. readsymref;
  613. ppufile.getsmallset(defopts);
  614. if df_has_rttitable in defopts then
  615. begin
  616. write (space,' RTTI symbol : ');
  617. readsymref;
  618. end;
  619. if df_has_inittable in defopts then
  620. begin
  621. write (space,' Init symbol : ');
  622. readsymref;
  623. end;
  624. end;
  625. {****************************************************************************
  626. Read Symbols Part
  627. ****************************************************************************}
  628. procedure readsymbols;
  629. Const
  630. vo_is_C_var = 2;
  631. Type
  632. absolutetyp = (tovar,toasm,toaddr);
  633. tconsttyp = (constnone,
  634. constord,conststring,constreal,constbool,
  635. constint,constchar,constset,constpointer,constnil,
  636. constresourcestring
  637. );
  638. var
  639. b : byte;
  640. pc : pchar;
  641. totalsyms,
  642. symcnt,
  643. i,j,len : longint;
  644. l1,l2 : longint;
  645. begin
  646. symcnt:=1;
  647. with ppufile do
  648. begin
  649. if space<>'' then
  650. Writeln(space,'-----------------------------');
  651. if readentry=ibstartsyms then
  652. begin
  653. totalsyms:=getlongint;
  654. Writeln(space,'Number of symbols : ',totalsyms);
  655. Writeln(space,'Symtable datasize : ',getlongint);
  656. Writeln(space,'Symtable alignment: ',getlongint);
  657. end
  658. else
  659. begin
  660. totalsyms:=-1;
  661. Writeln('!! ibstartsym not found');
  662. end;
  663. repeat
  664. b:=readentry;
  665. if not (b in [iberror,ibendsyms]) then
  666. inc(symcnt);
  667. case b of
  668. ibunitsym :
  669. readcommonsym('Unit symbol ');
  670. iblabelsym :
  671. readcommonsym('Label symbol ');
  672. ibtypesym :
  673. begin
  674. readcommonsym('Type symbol ');
  675. write(space,' Result Type: ');
  676. readtype;
  677. end;
  678. ibprocsym :
  679. begin
  680. readcommonsym('Procedure symbol ');
  681. repeat
  682. write(space,' Definition: ');
  683. until not readdefref;
  684. end;
  685. ibconstsym :
  686. begin
  687. readcommonsym('Constant symbol ');
  688. b:=getbyte;
  689. case tconsttyp(b) of
  690. constord :
  691. begin
  692. write (space,'OrdinalType: ');
  693. readtype;
  694. writeln (space,' Value: ',getlongint)
  695. end;
  696. constpointer :
  697. begin
  698. write (space,' Pointer Type: ');
  699. readtype;
  700. writeln (space,' Value: ',getlongint)
  701. end;
  702. conststring,
  703. constresourcestring :
  704. begin
  705. len:=getlongint;
  706. getmem(pc,len+1);
  707. getdata(pc^,len);
  708. writeln(space,' Length: ',len);
  709. writeln(space,' Value: "',pc,'"');
  710. freemem(pc,len+1);
  711. if tconsttyp(b)=constresourcestring then
  712. writeln(space,' Index: ',getlongint);
  713. end;
  714. constreal :
  715. writeln(space,' Value: ',getreal);
  716. constbool :
  717. if getlongint<>0 then
  718. writeln (space,' Value : True')
  719. else
  720. writeln (space,' Value: False');
  721. constint :
  722. begin
  723. l1:=getlongint;
  724. l2:=getlongint;
  725. writeln(space,' Value: ',int64(l2 shl 32) or l1);
  726. end;
  727. constchar :
  728. writeln(space,' Value: "'+chr(getlongint)+'"');
  729. constset :
  730. begin
  731. write (space,' Set Type: ');
  732. readtype;
  733. for i:=1to 4 do
  734. begin
  735. write (space,' Value: ');
  736. for j:=1to 8 do
  737. begin
  738. if j>1 then
  739. write(',');
  740. write(hexb(getbyte));
  741. end;
  742. writeln;
  743. end;
  744. end;
  745. else
  746. Writeln ('!! Invalid unit format : Invalid const type encountered: ',b);
  747. end;
  748. end;
  749. ibvarsym :
  750. begin
  751. readcommonsym('Variable symbol ');
  752. writeln(space,' Type: ',getbyte);
  753. if read_member then
  754. writeln(space,' Address: ',getlongint);
  755. write (space,' Var Type: ');
  756. readtype;
  757. i:=getlongint;
  758. writeln(space,' Options: ',i);
  759. if (i and vo_is_C_var)<>0 then
  760. writeln(space,' Mangledname: ',getstring);
  761. end;
  762. ibenumsym :
  763. begin
  764. readcommonsym('Enumeration symbol ');
  765. write (space,' Definition: ');
  766. readdefref;
  767. writeln(space,' Value: ',getlongint);
  768. end;
  769. ibsyssym :
  770. begin
  771. readcommonsym('Internal system symbol ');
  772. writeln(space,' Internal Nr: ',getlongint);
  773. end;
  774. ibrttisym :
  775. begin
  776. readcommonsym('RTTI symbol ');
  777. writeln(space,' RTTI Type: ',getbyte);
  778. end;
  779. ibtypedconstsym :
  780. begin
  781. readcommonsym('Typed constant ');
  782. write (space,' Constant Type: ');
  783. readtype;
  784. writeln(space,' Label: ',getstring);
  785. writeln(space,' ReallyConst: ',(getbyte<>0));
  786. end;
  787. ibabsolutesym :
  788. begin
  789. readcommonsym('Absolute variable symbol ');
  790. writeln(space,' Type: ',getbyte);
  791. if read_member then
  792. writeln(space,' Address: ',getlongint);
  793. write (space,' Var Type: ');
  794. readtype;
  795. writeln(space,' Options: ',getlongint);
  796. Write (space,' Relocated to ');
  797. b:=getbyte;
  798. case absolutetyp(b) of
  799. tovar :
  800. Writeln('Name : ',getstring);
  801. toasm :
  802. Writeln('Assembler name : ',getstring);
  803. toaddr :
  804. begin
  805. Write('Address : ',getlongint);
  806. WriteLn(' (Far: ',getbyte<>0,')');
  807. end;
  808. else
  809. Writeln ('!! Invalid unit format : Invalid absolute type encountered: ',b);
  810. end;
  811. end;
  812. ibpropertysym :
  813. begin
  814. readcommonsym('Property ');
  815. i:=getlongint;
  816. writeln(space,' PropOptions: ',i);
  817. if (i and 32)>0 then
  818. begin
  819. write (space,'OverrideProp: ');
  820. readsymref;
  821. end
  822. else
  823. begin
  824. write (space,' Prop Type: ');
  825. readtype;
  826. writeln(space,' Index: ',getlongint);
  827. writeln(space,' Default: ',getlongint);
  828. write (space,' Index Type: ');
  829. readtype;
  830. write (space,' Readaccess: ');
  831. readsymlist(space+' Sym: ');
  832. write (space,' Writeaccess: ');
  833. readsymlist(space+' Sym: ');
  834. write (space,'Storedaccess: ');
  835. readsymlist(space+' Sym: ');
  836. end;
  837. end;
  838. ibfuncretsym :
  839. begin
  840. readcommonsym('Func return value ');
  841. write (space,' Return Type: ');
  842. readtype;
  843. writeln(space,' Address: ',getlongint);
  844. end;
  845. iberror :
  846. begin
  847. Writeln('!! Error in PPU');
  848. exit;
  849. end;
  850. ibendsyms :
  851. break;
  852. else
  853. WriteLn('!! Skipping unsupported PPU Entry in Symbols: ',b);
  854. end;
  855. if not EndOfEntry then
  856. Writeln('!! Entry has more information stored');
  857. until false;
  858. if (totalsyms<>-1) and (symcnt-1<>totalsyms) then
  859. Writeln('!! Only read ',symcnt-1,' of ',totalsyms,' symbols');
  860. end;
  861. end;
  862. {****************************************************************************
  863. Read defintions Part
  864. ****************************************************************************}
  865. procedure readdefinitions(start_read : boolean);
  866. type
  867. tsettype = (normset,smallset,varset);
  868. tbasetype = (
  869. uauto,uvoid,uchar,
  870. u8bit,u16bit,u32bit,
  871. s8bit,s16bit,s32bit,
  872. bool8bit,bool16bit,bool32bit,
  873. u64bit,s64bit,uwidechar
  874. );
  875. tobjectdeftype = (odt_none,
  876. odt_class,
  877. odt_object,
  878. odt_interfacecom,
  879. odt_interfacecorba,
  880. odt_cppclass
  881. );
  882. var
  883. b : byte;
  884. oldread_member : boolean;
  885. totaldefs,l,j,
  886. defcnt : longint;
  887. calloption : tproccalloption;
  888. begin
  889. defcnt:=0;
  890. with ppufile do
  891. begin
  892. if space<>'' then
  893. Writeln(space,'-----------------------------');
  894. if not start_read then
  895. if readentry=ibstartdefs then
  896. begin
  897. totaldefs:=getlongint;
  898. Writeln(space,'Number of definitions: ',totaldefs);
  899. end
  900. else
  901. begin
  902. totaldefs:=-1;
  903. Writeln('!! ibstartdef not found');
  904. end;
  905. repeat
  906. b:=readentry;
  907. if not (b in [iberror,ibenddefs]) then
  908. inc(defcnt);
  909. case b of
  910. ibpointerdef :
  911. begin
  912. readcommondef('Pointer definition');
  913. write (space,' Pointed Type : ');
  914. readtype;
  915. writeln(space,' Is Far : ',(getbyte<>0));
  916. end;
  917. iborddef :
  918. begin
  919. readcommondef('Ordinal definition');
  920. write (space,' Base type : ');
  921. b:=getbyte;
  922. case tbasetype(b) of
  923. uauto : writeln('uauto');
  924. uvoid : writeln('uvoid');
  925. uchar : writeln('uchar');
  926. u8bit : writeln('u8bit');
  927. u16bit : writeln('u16bit');
  928. u32bit : writeln('s32bit');
  929. s8bit : writeln('s8bit');
  930. s16bit : writeln('s16bit');
  931. s32bit : writeln('s32bit');
  932. bool8bit : writeln('bool8bit');
  933. bool16bit : writeln('bool16bit');
  934. bool32bit : writeln('bool32bit');
  935. u64bit : writeln('u64bit');
  936. s64bit : writeln('s64bit');
  937. uwidechar : writeln('uwidechar');
  938. else writeln('!! Warning: Invalid base type ',b);
  939. end;
  940. writeln(space,' Range : ',getlongint,' to ',getlongint);
  941. end;
  942. ibfloatdef :
  943. begin
  944. readcommondef('Float definition');
  945. writeln(space,' Float type : ',getbyte);
  946. end;
  947. ibarraydef :
  948. begin
  949. readcommondef('Array definition');
  950. write (space,' Element type : ');
  951. readtype;
  952. write (space,' Range Type : ');
  953. readtype;
  954. writeln(space,' Range : ',getlongint,' to ',getlongint);
  955. writeln(space,' Is Constructor : ',(getbyte<>0));
  956. writeln(space,' Is Dynamic : ',(getbyte<>0));
  957. end;
  958. ibprocdef :
  959. begin
  960. readcommondef('Procedure definition');
  961. calloption:=read_abstract_proc_def;
  962. writeln(space,' Used Register : ',getbyte);
  963. writeln(space,' Mangled name : ',getstring);
  964. writeln(space,' Number : ',getlongint);
  965. write (space,' Class : ');
  966. readdefref;
  967. write (space,' Procsym : ');
  968. readsymref;
  969. write (space,' File Pos : ');
  970. readposinfo;
  971. if (calloption=pocall_inline) then
  972. begin
  973. write (space,' FuncretSym : ');
  974. readdefref;
  975. end;
  976. space:=' '+space;
  977. { parast }
  978. readdefinitions(false);
  979. readsymbols;
  980. { localst }
  981. if (calloption=pocall_inline) or
  982. ((ppufile.header.flags and uf_local_browser) <> 0) then
  983. begin
  984. readdefinitions(false);
  985. readsymbols;
  986. end;
  987. delete(space,1,4);
  988. end;
  989. ibprocvardef :
  990. begin
  991. readcommondef('Procedural type (ProcVar) definition');
  992. read_abstract_proc_def;
  993. end;
  994. ibshortstringdef :
  995. begin
  996. readcommondef('ShortString definition');
  997. writeln(space,' Length : ',getbyte);
  998. end;
  999. ibwidestringdef :
  1000. begin
  1001. readcommondef('WideString definition');
  1002. writeln(space,' Length : ',getlongint);
  1003. end;
  1004. ibansistringdef :
  1005. begin
  1006. readcommondef('AnsiString definition');
  1007. writeln(space,' Length : ',getlongint);
  1008. end;
  1009. iblongstringdef :
  1010. begin
  1011. readcommondef('Longstring definition');
  1012. writeln(space,' Length : ',getlongint);
  1013. end;
  1014. ibrecorddef :
  1015. begin
  1016. readcommondef('Record definition');
  1017. writeln(space,' Size : ',getlongint);
  1018. {read the record definitions and symbols}
  1019. space:=' '+space;
  1020. oldread_member:=read_member;
  1021. read_member:=true;
  1022. readdefinitions(false);
  1023. readsymbols;
  1024. read_member:=oldread_member;
  1025. Delete(space,1,4);
  1026. end;
  1027. ibobjectdef :
  1028. begin
  1029. readcommondef('Object/Class definition');
  1030. b:=getbyte;
  1031. write (space,' Type : ');
  1032. case tobjectdeftype(b) of
  1033. odt_class : writeln('class');
  1034. odt_object : writeln('object');
  1035. odt_interfacecom : writeln('interfacecom');
  1036. odt_interfacecorba : writeln('interfacecorba');
  1037. odt_cppclass : writeln('cppclass');
  1038. else writeln('!! Warning: Invalid object type ',b);
  1039. end;
  1040. writeln(space,' Size : ',getlongint);
  1041. writeln(space,' Vmt offset : ',getlongint);
  1042. writeln(space,' Name of Class : ',getstring);
  1043. write(space, ' Ancestor Class : ');
  1044. readdefref;
  1045. writeln(space,' Options : ',getlongint);
  1046. if tobjectdeftype(b) in [odt_interfacecom,odt_interfacecorba] then
  1047. begin
  1048. writeln(space,' GUID Valid : ',(getbyte<>0));
  1049. { IIDGUID }
  1050. for j:=1to 16 do
  1051. getbyte;
  1052. writeln(space,' IID String : ',getstring);
  1053. writeln(space,' Last VTable idx : ',getlongint);
  1054. end;
  1055. if tobjectdeftype(b) in [odt_class,odt_interfacecorba] then
  1056. begin
  1057. l:=getlongint;
  1058. writeln(space,' Impl Intf Count : ',l);
  1059. for j:=1 to l do
  1060. begin
  1061. write (space,' - Definition : ');
  1062. readdefref;
  1063. writeln(space,' IOffset : ',getlongint);
  1064. end;
  1065. end;
  1066. {read the record definitions and symbols}
  1067. space:=' '+space;
  1068. oldread_member:=read_member;
  1069. read_member:=true;
  1070. readdefinitions(false);
  1071. readsymbols;
  1072. read_member:=oldread_member;
  1073. Delete(space,1,4);
  1074. end;
  1075. ibfiledef :
  1076. begin
  1077. ReadCommonDef('File definition');
  1078. write (space,' Type : ');
  1079. case getbyte of
  1080. 0 : writeln('Text');
  1081. 1 : begin
  1082. writeln('Typed');
  1083. write (space,' File of Type : ');
  1084. Readtype;
  1085. end;
  1086. 2 : writeln('Untyped');
  1087. end;
  1088. end;
  1089. ibformaldef :
  1090. readcommondef('Generic Definition (void-typ)');
  1091. ibenumdef :
  1092. begin
  1093. readcommondef('Enumeration type definition');
  1094. write(space,'Base enumeration type : ');
  1095. readdefref;
  1096. writeln(space,' Smallest element : ',getlongint);
  1097. writeln(space,' Largest element : ',getlongint);
  1098. writeln(space,' Size : ',getlongint);
  1099. end;
  1100. ibclassrefdef :
  1101. begin
  1102. readcommondef('Class reference definition');
  1103. write (space,' Pointed Type : ');
  1104. readtype;
  1105. end;
  1106. ibsetdef :
  1107. begin
  1108. readcommondef('Set definition');
  1109. write (space,' Element type : ');
  1110. readtype;
  1111. b:=getbyte;
  1112. case tsettype(b) of
  1113. smallset : writeln(space,' Set with 32 Elements');
  1114. normset : writeln(space,' Set with 256 Elements');
  1115. varset : writeln(space,' Set with ',getlongint,' Elements');
  1116. else writeln('!! Warning: Invalid set type ',b);
  1117. end;
  1118. end;
  1119. ibvariantdef :
  1120. begin
  1121. readcommondef('Variant definition');
  1122. end;
  1123. iberror :
  1124. begin
  1125. Writeln('!! Error in PPU');
  1126. exit;
  1127. end;
  1128. ibenddefs :
  1129. break;
  1130. else
  1131. WriteLn('!! Skipping unsupported PPU Entry in definitions: ',b);
  1132. end;
  1133. if not EndOfEntry then
  1134. Writeln('!! Entry has more information stored');
  1135. until false;
  1136. if (totaldefs<>-1) and (defcnt<>totaldefs) then
  1137. Writeln('!! Only read ',defcnt,' of ',totaldefs,' definitions');
  1138. end;
  1139. end;
  1140. {****************************************************************************
  1141. Read General Part
  1142. ****************************************************************************}
  1143. procedure readinterface;
  1144. var
  1145. b : byte;
  1146. sourcenumber,
  1147. unitnumber : word;
  1148. ucrc,uintfcrc : longint;
  1149. begin
  1150. with ppufile do
  1151. begin
  1152. repeat
  1153. b:=readentry;
  1154. case b of
  1155. ibmodulename :
  1156. Writeln('Module Name: ',getstring);
  1157. ibsourcefiles :
  1158. begin
  1159. sourcenumber:=1;
  1160. while not EndOfEntry do
  1161. begin
  1162. Writeln('Source file ',sourcenumber,' : ',getstring);
  1163. inc(sourcenumber);
  1164. end;
  1165. end;
  1166. ibusedmacros :
  1167. begin
  1168. while not EndOfEntry do
  1169. begin
  1170. Write('Conditional ',getstring);
  1171. b:=getbyte;
  1172. if boolean(b)=true then
  1173. write(' defined at startup')
  1174. else
  1175. write(' not defined at startup');
  1176. b:=getbyte;
  1177. if boolean(b)=true then
  1178. writeln(' was used')
  1179. else
  1180. writeln;
  1181. end;
  1182. end;
  1183. ibloadunit :
  1184. begin
  1185. unitnumber:=1;
  1186. while not EndOfEntry do
  1187. begin
  1188. write('Uses unit: ',getstring,' (Number: ',unitnumber,')');
  1189. ucrc:=getlongint;
  1190. uintfcrc:=getlongint;
  1191. write(' (Crc: ',hexstr(ucrc,8),', IntfcCrc: ',hexstr(uintfcrc,8),')');
  1192. if getbyte<>0 then
  1193. writeln(' (interface)')
  1194. else
  1195. writeln(' (implementation)');
  1196. inc(unitnumber);
  1197. end;
  1198. end;
  1199. iblinkunitofiles :
  1200. ReadLinkContainer('Link unit object file: ');
  1201. iblinkunitstaticlibs :
  1202. ReadLinkContainer('Link unit static lib: ');
  1203. iblinkunitsharedlibs :
  1204. ReadLinkContainer('Link unit shared lib: ');
  1205. iblinkotherofiles :
  1206. ReadLinkContainer('Link other object file: ');
  1207. iblinkotherstaticlibs :
  1208. ReadLinkContainer('Link other static lib: ');
  1209. iblinkothersharedlibs :
  1210. ReadLinkContainer('Link other shared lib: ');
  1211. iberror :
  1212. begin
  1213. Writeln('Error in PPU');
  1214. exit;
  1215. end;
  1216. ibendinterface :
  1217. break;
  1218. else
  1219. WriteLn('!! Skipping unsupported PPU Entry in General Part: ',b);
  1220. end;
  1221. until false;
  1222. end;
  1223. end;
  1224. {****************************************************************************
  1225. Read Implementation Part
  1226. ****************************************************************************}
  1227. procedure readimplementation;
  1228. var
  1229. b : byte;
  1230. begin
  1231. with ppufile do
  1232. begin
  1233. repeat
  1234. b:=readentry;
  1235. case b of
  1236. iberror :
  1237. begin
  1238. Writeln('Error in PPU');
  1239. exit;
  1240. end;
  1241. ibendimplementation :
  1242. break;
  1243. else
  1244. WriteLn('!! Skipping unsupported PPU Entry in Implementation: ',b);
  1245. end;
  1246. until false;
  1247. end;
  1248. end;
  1249. {****************************************************************************
  1250. Read Browser Part
  1251. ****************************************************************************}
  1252. procedure readbrowser;
  1253. var
  1254. b : byte;
  1255. const indent : string = '';
  1256. begin
  1257. Writeln(indent,'Start of symtable browser');
  1258. indent:=indent+'**';
  1259. with ppufile do
  1260. begin
  1261. repeat
  1262. b:=readentry;
  1263. case b of
  1264. ibbeginsymtablebrowser :
  1265. begin
  1266. { here we must read object and record symtables !! }
  1267. indent:=indent+' ';
  1268. Writeln(indent,'Record/Object symtable');
  1269. readbrowser;
  1270. Indent:=Copy(Indent,1,Length(Indent)-2);
  1271. end;
  1272. ibsymref :
  1273. begin
  1274. readsymref;
  1275. readref;
  1276. end;
  1277. ibdefref :
  1278. begin
  1279. readdefref;
  1280. readref;
  1281. if ((ppufile.header.flags and uf_local_browser)<>0) and
  1282. (UnitIndex=0) then
  1283. begin
  1284. { parast and localst }
  1285. indent:=indent+' ';
  1286. b:=ppufile.readentry;
  1287. if b=ibbeginsymtablebrowser then
  1288. readbrowser;
  1289. b:=ppufile.readentry;
  1290. if b=ibbeginsymtablebrowser then
  1291. readbrowser;
  1292. Indent:=Copy(Indent,1,Length(Indent)-2);
  1293. end;
  1294. end;
  1295. iberror :
  1296. begin
  1297. Writeln('Error in PPU');
  1298. exit;
  1299. end;
  1300. ibendsymtablebrowser :
  1301. break;
  1302. else
  1303. begin
  1304. WriteLn('!! Skipping unsupported PPU Entry in Browser: ',b);
  1305. Halt;
  1306. end;
  1307. end;
  1308. until false;
  1309. end;
  1310. Indent:=Copy(Indent,1,Length(Indent)-2);
  1311. Writeln(Indent,'End of symtable browser');
  1312. end;
  1313. procedure dofile (filename : string);
  1314. var
  1315. b : byte;
  1316. begin
  1317. { reset }
  1318. space:='';
  1319. { fix filename }
  1320. if pos('.',filename)=0 then
  1321. filename:=filename+'.ppu';
  1322. ppufile:=tppufile.create(filename);
  1323. if not ppufile.openfile then
  1324. begin
  1325. writeln ('IO-Error when opening : ',filename,', Skipping');
  1326. exit;
  1327. end;
  1328. { PPU File is open, check for PPU Id }
  1329. if not ppufile.CheckPPUID then
  1330. begin
  1331. writeln(Filename,' : Not a valid PPU file, Skipping');
  1332. exit;
  1333. end;
  1334. { Check PPU Version }
  1335. Writeln('Analyzing ',filename,' (v',ppufile.GetPPUVersion,')');
  1336. if ppufile.GetPPUVersion<16 then
  1337. begin
  1338. writeln(Filename,' : Old PPU Formats (<v16) are not supported, Skipping');
  1339. exit;
  1340. end;
  1341. { Write PPU Header Information }
  1342. if (verbose and v_header)<>0 then
  1343. begin
  1344. Writeln;
  1345. Writeln('Header');
  1346. Writeln('-------');
  1347. with ppufile.header do
  1348. begin
  1349. Writeln('Compiler version : ',hi(ppufile.header.compiler and $ff),'.',lo(ppufile.header.compiler));
  1350. WriteLn('Target processor : ',Cpu2Str(cpu));
  1351. WriteLn('Target operating system : ',Target2Str(target));
  1352. Writeln('Unit flags : ',PPUFlags2Str(flags));
  1353. Writeln('FileSize (w/o header) : ',size);
  1354. Writeln('Checksum : ',hexstr(checksum,8));
  1355. Writeln('Interface Checksum : ',hexstr(interface_checksum,8));
  1356. end;
  1357. end;
  1358. {read the general stuff}
  1359. if (verbose and v_interface)<>0 then
  1360. begin
  1361. Writeln;
  1362. Writeln('Interface section');
  1363. Writeln('------------------');
  1364. readinterface;
  1365. end
  1366. else
  1367. ppufile.skipuntilentry(ibendinterface);
  1368. {read the definitions}
  1369. if (verbose and v_defs)<>0 then
  1370. begin
  1371. Writeln;
  1372. Writeln('Interface definitions');
  1373. Writeln('----------------------');
  1374. readdefinitions(false);
  1375. end
  1376. else
  1377. ppufile.skipuntilentry(ibenddefs);
  1378. {read the symbols}
  1379. if (verbose and v_syms)<>0 then
  1380. begin
  1381. Writeln;
  1382. Writeln('Interface Symbols');
  1383. Writeln('------------------');
  1384. readsymbols;
  1385. end
  1386. else
  1387. ppufile.skipuntilentry(ibendsyms);
  1388. {read the implementation stuff}
  1389. { Not used at the moment (PFV)
  1390. if (verbose and v_implementation)<>0 then
  1391. begin
  1392. Writeln;
  1393. Writeln('Implementation section');
  1394. Writeln('-----------------------');
  1395. readimplementation;
  1396. end
  1397. else}
  1398. ppufile.skipuntilentry(ibendimplementation);
  1399. {read the static browser units stuff}
  1400. if (ppufile.header.flags and uf_local_browser)<>0 then
  1401. begin
  1402. if (verbose and v_defs)<>0 then
  1403. begin
  1404. Writeln;
  1405. Writeln('Static definitions');
  1406. Writeln('----------------------');
  1407. readdefinitions(false);
  1408. end
  1409. else
  1410. ppufile.skipuntilentry(ibenddefs);
  1411. {read the symbols}
  1412. if (verbose and v_syms)<>0 then
  1413. begin
  1414. Writeln;
  1415. Writeln('Static Symbols');
  1416. Writeln('------------------');
  1417. readsymbols;
  1418. end;
  1419. end;
  1420. {read the browser units stuff}
  1421. if (ppufile.header.flags and uf_has_browser)<>0 then
  1422. begin
  1423. if (verbose and v_browser)<>0 then
  1424. begin
  1425. Writeln;
  1426. Writeln('Browser section');
  1427. Writeln('---------------');
  1428. UnitIndex:=0;
  1429. repeat
  1430. b:=ppufile.readentry;
  1431. if b = ibendbrowser then break;
  1432. if b=ibbeginsymtablebrowser then
  1433. begin
  1434. Writeln('Unit ',UnitIndex);
  1435. readbrowser;
  1436. Inc(UnitIndex);
  1437. end
  1438. else
  1439. Writeln('Wrong end browser entry ',b,' should be ',ibendbrowser);
  1440. until false;
  1441. end;
  1442. end;
  1443. {read the static browser units stuff}
  1444. if (ppufile.header.flags and uf_local_browser)<>0 then
  1445. begin
  1446. if (verbose and v_browser)<>0 then
  1447. begin
  1448. Writeln;
  1449. Writeln('Static browser section');
  1450. Writeln('---------------');
  1451. UnitIndex:=0;
  1452. b:=ppufile.readentry;
  1453. if b=ibbeginsymtablebrowser then
  1454. readbrowser
  1455. else
  1456. Writeln('Wrong end browser entry ',b,' should be ',ibendbrowser);
  1457. end;
  1458. end;
  1459. {shutdown ppufile}
  1460. ppufile.closefile;
  1461. ppufile.free;
  1462. Writeln;
  1463. end;
  1464. procedure help;
  1465. begin
  1466. writeln('usage: ppudump [options] <filename1> <filename2>...');
  1467. writeln;
  1468. writeln('[options] can be:');
  1469. writeln(' -V<verbose> Set verbosity to <verbose>');
  1470. writeln(' H - Show header info');
  1471. writeln(' I - Show interface');
  1472. writeln(' M - Show implementation');
  1473. writeln(' S - Show interface symbols');
  1474. writeln(' D - Show interface definitions');
  1475. writeln(' B - Show browser info');
  1476. writeln(' A - Show all');
  1477. writeln(' -? This helpscreen');
  1478. halt;
  1479. end;
  1480. var
  1481. startpara,
  1482. nrfile,i : longint;
  1483. para : string;
  1484. begin
  1485. writeln(Title+' '+Version);
  1486. writeln(Copyright);
  1487. writeln;
  1488. if paramcount<1 then
  1489. begin
  1490. writeln('usage: dumpppu [options] <filename1> <filename2>...');
  1491. halt(1);
  1492. end;
  1493. { turn verbose on by default }
  1494. verbose:=v_all;
  1495. { read options }
  1496. startpara:=1;
  1497. while copy(paramstr(startpara),1,1)='-' do
  1498. begin
  1499. para:=paramstr(startpara);
  1500. case upcase(para[2]) of
  1501. 'V' : begin
  1502. verbose:=0;
  1503. for i:=3to length(para) do
  1504. case upcase(para[i]) of
  1505. 'H' : verbose:=verbose or v_header;
  1506. 'I' : verbose:=verbose or v_interface;
  1507. 'M' : verbose:=verbose or v_implementation;
  1508. 'D' : verbose:=verbose or v_defs;
  1509. 'S' : verbose:=verbose or v_syms;
  1510. 'B' : verbose:=verbose or v_browser;
  1511. 'A' : verbose:=verbose or v_all;
  1512. end;
  1513. end;
  1514. '?' : help;
  1515. end;
  1516. inc(startpara);
  1517. end;
  1518. { process files }
  1519. for nrfile:=startpara to paramcount do
  1520. dofile (paramstr(nrfile));
  1521. if has_errors then
  1522. Halt(1);
  1523. end.
  1524. {
  1525. $Log$
  1526. Revision 1.10 2001-12-15 05:28:01 carl
  1527. + Added QNX target
  1528. Revision 1.9 2001/11/02 22:58:12 peter
  1529. * procsym definition rewrite
  1530. Revision 1.8 2001/09/22 04:52:27 carl
  1531. * updated targets
  1532. Revision 1.7 2001/08/30 20:55:02 peter
  1533. * rttisym support
  1534. Revision 1.6 2001/08/19 09:39:29 peter
  1535. * local browser support fixed
  1536. Revision 1.5 2001/06/29 19:42:18 peter
  1537. * new flags added
  1538. Revision 1.4 2001/06/04 11:53:15 peter
  1539. + varargs directive
  1540. Revision 1.3 2001/05/09 14:11:10 jonas
  1541. * range check error fixes from Peter
  1542. Revision 1.2 2001/05/06 14:49:19 peter
  1543. * ppu object to class rewrite
  1544. * move ppu read and write stuff to fppu
  1545. Revision 1.1 2001/04/25 22:40:07 peter
  1546. * compiler dependent utils in utils/ subdir
  1547. Revision 1.5 2001/04/10 21:21:41 peter
  1548. * variantdef support
  1549. * propertysym fixed
  1550. Revision 1.4 2001/04/04 22:42:59 peter
  1551. * updated for new objectdef with interfaces
  1552. Revision 1.3 2000/09/09 19:46:40 peter
  1553. * show dataalignment
  1554. Revision 1.2 2000/08/13 12:58:06 peter
  1555. * updated for ppu additions
  1556. Revision 1.1 2000/07/13 10:16:22 michael
  1557. + Initial import
  1558. Revision 1.15 2000/07/04 19:05:54 peter
  1559. * be optimistic: version 1.00 for some utils
  1560. Revision 1.14 2000/02/09 16:44:14 peter
  1561. * log truncated
  1562. Revision 1.13 2000/01/23 16:34:36 peter
  1563. * updated for new aktlocalindex
  1564. Revision 1.12 2000/01/07 16:46:03 daniel
  1565. * copyright 2000
  1566. Revision 1.11 1999/11/30 10:35:37 peter
  1567. * support new readtype
  1568. Revision 1.10 1999/11/08 14:06:45 florian
  1569. + indexref of propertysym is handle too now
  1570. Revision 1.9 1999/08/31 16:07:37 pierre
  1571. + support for writeusedmacros
  1572. Revision 1.8 1999/08/15 10:47:14 peter
  1573. * updates for new options
  1574. Revision 1.7 1999/08/13 21:25:35 peter
  1575. * updated flags
  1576. Revision 1.6 1999/07/27 23:45:29 peter
  1577. * updated for typesym writing
  1578. }