ppudump.pp 50 KB

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