ppudump.pp 65 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325
  1. {
  2. Copyright (c) 1998-2002 by the FPC Development Team
  3. Dumps the contents of a FPC unit file (PPU File)
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************}
  16. {$ifdef TP}
  17. {$N+,E+}
  18. {$endif}
  19. program pppdump;
  20. uses
  21. dos,
  22. ppu,
  23. globals,
  24. tokens;
  25. const
  26. Version = 'Version 2.1.1';
  27. Title = 'PPU-Analyser';
  28. Copyright = 'Copyright (c) 1998-2006 by the Free Pascal Development Team';
  29. { verbosity }
  30. v_none = $0;
  31. v_header = $1;
  32. v_defs = $2;
  33. v_syms = $4;
  34. v_interface = $8;
  35. v_implementation = $10;
  36. // v_browser = $20;
  37. v_all = $ff;
  38. type
  39. tprocinfoflag=(
  40. {# procedure uses asm }
  41. pi_uses_asm,
  42. {# procedure does a call }
  43. pi_do_call,
  44. {# procedure has a try statement = no register optimization }
  45. pi_uses_exceptions,
  46. {# procedure is declared as @var(assembler), don't optimize}
  47. pi_is_assembler,
  48. {# procedure contains data which needs to be finalized }
  49. pi_needs_implicit_finally
  50. );
  51. tprocinfoflags=set of tprocinfoflag;
  52. { copied from scanner.pas }
  53. tspecialgenerictoken = (ST_LOADSETTINGS,ST_LINE,ST_COLUMN,ST_FILEINDEX);
  54. { Copied from systems.pas }
  55. tsystemcpu=
  56. (
  57. cpu_no, { 0 }
  58. cpu_i386, { 1 }
  59. cpu_m68k, { 2 }
  60. cpu_alpha, { 3 }
  61. cpu_powerpc, { 4 }
  62. cpu_sparc, { 5 }
  63. cpu_vm, { 6 }
  64. cpu_iA64, { 7 }
  65. cpu_x86_64, { 8 }
  66. cpu_mips, { 9 }
  67. cpu_arm { 10 }
  68. );
  69. var
  70. ppufile : tppufile;
  71. space : string;
  72. verbose : longint;
  73. derefdata : pbyte;
  74. derefdatalen : longint;
  75. {****************************************************************************
  76. Helper Routines
  77. ****************************************************************************}
  78. const has_errors : boolean = false;
  79. Procedure Error(const S : string);
  80. Begin
  81. Writeln(S);
  82. has_errors:=true;
  83. End;
  84. function ToStr(w:longint):String;
  85. begin
  86. Str(w,ToStr);
  87. end;
  88. Function Target2Str(w:longint):string;
  89. type
  90. { taken from systems.pas }
  91. ttarget =
  92. (
  93. target_none, { 0 }
  94. target_i386_GO32V1, { 1 }
  95. target_i386_GO32V2, { 2 }
  96. target_i386_linux, { 3 }
  97. target_i386_OS2, { 4 }
  98. target_i386_Win32, { 5 }
  99. target_i386_freebsd, { 6 }
  100. target_m68k_Amiga, { 7 }
  101. target_m68k_Atari, { 8 }
  102. target_m68k_Mac, { 9 }
  103. target_m68k_linux, { 10 }
  104. target_m68k_PalmOS, { 11 }
  105. target_alpha_linux, { 12 }
  106. target_powerpc_linux, { 13 }
  107. target_powerpc_macos, { 14 }
  108. target_i386_sunos, { 15 }
  109. target_i386_beos, { 16 }
  110. target_i386_netbsd, { 17 }
  111. target_m68k_netbsd, { 18 }
  112. target_i386_Netware, { 19 }
  113. target_i386_qnx, { 20 }
  114. target_i386_wdosx, { 21 }
  115. target_sparc_sunos, { 22 }
  116. target_sparc_linux, { 23 }
  117. target_i386_openbsd, { 24 }
  118. target_m68k_openbsd, { 25 }
  119. system_x86_64_linux, { 26 }
  120. system_powerpc_macosx, { 27 }
  121. target_i386_emx, { 28 }
  122. target_powerpc_netbsd, { 29 }
  123. target_powerpc_openbsd, { 30 }
  124. target_arm_linux, { 31 }
  125. target_i386_watcom, { 32 }
  126. target_powerpc_MorphOS, { 33 }
  127. target_x86_64_freebsd, { 34 }
  128. target_i386_netwlibc, { 35 }
  129. system_powerpc_Amiga, { 36 }
  130. system_x86_64_win64, { 37 }
  131. system_arm_wince, { 38 }
  132. system_ia64_win64, { 39 }
  133. system_i386_wince, { 40 }
  134. system_x86_6432_linux, { 41 }
  135. system_arm_gba { 42 }
  136. );
  137. const
  138. Targets : array[ttarget] of string[17]=(
  139. { 0 } 'none',
  140. { 1 } 'GO32V1',
  141. { 2 } 'GO32V2',
  142. { 3 } 'Linux-i386',
  143. { 4 } 'OS/2',
  144. { 5 } 'Win32',
  145. { 6 } 'FreeBSD-i386',
  146. { 7 } 'Amiga',
  147. { 8 } 'Atari',
  148. { 9 } 'MacOS-m68k',
  149. { 10 } 'Linux-m68k',
  150. { 11 } 'PalmOS-m68k',
  151. { 12 } 'Linux-alpha',
  152. { 13 } 'Linux-ppc',
  153. { 14 } 'MacOS-ppc',
  154. { 15 } 'Solaris-i386',
  155. { 16 } 'BeOS-i386',
  156. { 17 } 'NetBSD-i386',
  157. { 18 } 'NetBSD-m68k',
  158. { 19 } 'Netware-i386-clib',
  159. { 20 } 'Qnx-i386',
  160. { 21 } 'WDOSX-i386',
  161. { 22 } 'Solaris-sparc',
  162. { 23 } 'Linux-sparc',
  163. { 24 } 'OpenBSD-i386',
  164. { 25 } 'OpenBSD-m68k',
  165. { 26 } 'Linux-x86-64',
  166. { 27 } 'MacOSX-ppc',
  167. { 28 } 'OS/2 via EMX',
  168. { 29 } 'NetBSD-powerpc',
  169. { 30 } 'OpenBSD-powerpc',
  170. { 31 } 'Linux-arm',
  171. { 32 } 'Watcom-i386',
  172. { 33 } 'MorphOS-powerpc',
  173. { 34 } 'FreeBSD-x86-64',
  174. { 35 } 'Netware-i386-libc',
  175. { 36 } 'Amiga-PowerPC',
  176. { 37 } 'Win64-x64',
  177. { 38 } 'WinCE-ARM',
  178. { 39 } 'Win64-iA64',
  179. { 40 } 'WinCE-i386',
  180. { 41 } 'Linux-x64',
  181. { 42 } 'GBA-ARM'
  182. );
  183. begin
  184. if w<=ord(high(ttarget)) then
  185. Target2Str:=Targets[ttarget(w)]
  186. else
  187. Target2Str:='<!! Unknown target value '+tostr(w)+'>';
  188. end;
  189. Function Cpu2Str(w:longint):string;
  190. const
  191. CpuTxt : array[tsystemcpu] of string[8]=
  192. ('none','i386','m68k','alpha','powerpc','sparc','vis','ia64','x86_64','mips','arm');
  193. begin
  194. if w<=ord(high(tsystemcpu)) then
  195. Cpu2Str:=CpuTxt[tsystemcpu(w)]
  196. else
  197. Cpu2Str:='<!! Unknown cpu value '+tostr(w)+'>';
  198. end;
  199. Function Varspez2Str(w:longint):string;
  200. const
  201. varspezstr : array[0..4] of string[6]=('Value','Const','Var','Out','Hidden');
  202. begin
  203. if w<=ord(high(varspezstr)) then
  204. Varspez2Str:=varspezstr[w]
  205. else
  206. Varspez2Str:='<!! Unknown varspez value '+tostr(w)+'>';
  207. end;
  208. Function VarRegable2Str(w:longint):string;
  209. const
  210. varregableStr : array[0..4] of string[6]=('None','IntReg','FPUReg','MMReg','Addr');
  211. begin
  212. if w<=ord(high(varregablestr)) then
  213. Varregable2Str:=varregablestr[w]
  214. else
  215. Varregable2Str:='<!! Unknown regable value '+tostr(w)+'>';
  216. end;
  217. function PPUFlags2Str(flags:longint):string;
  218. type
  219. tflagopt=record
  220. mask : longint;
  221. str : string[30];
  222. end;
  223. const
  224. flagopts=17;
  225. flagopt : array[1..flagopts] of tflagopt=(
  226. (mask: $1 ;str:'init'),
  227. (mask: $2 ;str:'final'),
  228. (mask: $4 ;str:'big_endian'),
  229. (mask: $8 ;str:'dbx'),
  230. // (mask: $10 ;str:'browser'),
  231. (mask: $20 ;str:'in_library'),
  232. (mask: $40 ;str:'smart_linked'),
  233. (mask: $80 ;str:'static_linked'),
  234. (mask: $100 ;str:'shared_linked'),
  235. // (mask: $200 ;str:'local_browser'),
  236. (mask: $400 ;str:'no_link'),
  237. (mask: $800 ;str:'has_resources'),
  238. (mask: $1000 ;str:'little_endian'),
  239. (mask: $2000 ;str:'release'),
  240. (mask: $4000 ;str:'local_threadvars'),
  241. (mask: $8000 ;str:'fpu_emulation_on'),
  242. (mask: $10000 ;str:'has_debug_info'),
  243. (mask: $20000 ;str:'local_symtable'),
  244. (mask: $40000 ;str:'uses_variants')
  245. );
  246. var
  247. i : longint;
  248. first : boolean;
  249. s : string;
  250. begin
  251. s:='';
  252. if flags<>0 then
  253. begin
  254. first:=true;
  255. for i:=1to flagopts do
  256. if (flags and flagopt[i].mask)<>0 then
  257. begin
  258. if first then
  259. first:=false
  260. else
  261. s:=s+', ';
  262. s:=s+flagopt[i].str;
  263. end;
  264. end
  265. else
  266. s:='none';
  267. PPUFlags2Str:=s;
  268. end;
  269. const
  270. HexTbl : array[0..15] of char='0123456789ABCDEF';
  271. function HexB(b:byte):string;
  272. begin
  273. HexB[0]:=#2;
  274. HexB[1]:=HexTbl[b shr 4];
  275. HexB[2]:=HexTbl[b and $f];
  276. end;
  277. function hexstr(val : cardinal;cnt : byte) : string;
  278. const
  279. HexTbl : array[0..15] of char='0123456789ABCDEF';
  280. var
  281. i : longint;
  282. begin
  283. hexstr[0]:=char(cnt);
  284. for i:=cnt downto 1 do
  285. begin
  286. hexstr[i]:=hextbl[val and $f];
  287. val:=val shr 4;
  288. end;
  289. end;
  290. Function L0(l:longint):string;
  291. {
  292. return the string of value l, if l<10 then insert a zero, so
  293. the string is always at least 2 chars '01','02',etc
  294. }
  295. var
  296. s : string;
  297. begin
  298. Str(l,s);
  299. if l<10 then
  300. s:='0'+s;
  301. L0:=s;
  302. end;
  303. function filetimestring( t : longint) : string;
  304. {
  305. convert dos datetime t to a string YY/MM/DD HH:MM:SS
  306. }
  307. var
  308. DT : DateTime;
  309. begin
  310. if t=-1 then
  311. begin
  312. FileTimeString:='Not Found';
  313. exit;
  314. end;
  315. unpacktime(t,DT);
  316. filetimestring:=L0(dt.Year)+'/'+L0(dt.Month)+'/'+L0(dt.Day)+' '+L0(dt.Hour)+':'+L0(dt.min)+':'+L0(dt.sec);
  317. end;
  318. {****************************************************************************
  319. Read Routines
  320. ****************************************************************************}
  321. Procedure ReadLinkContainer(const prefix:string);
  322. {
  323. Read a serie of strings and write to the screen starting every line
  324. with prefix
  325. }
  326. function maskstr(m:longint):string;
  327. const
  328. { link options }
  329. link_none = $0;
  330. link_always = $1;
  331. link_static = $2;
  332. link_smart = $4;
  333. link_shared = $8;
  334. var
  335. s : string;
  336. begin
  337. s:='';
  338. if (m and link_always)<>0 then
  339. s:=s+'always ';
  340. if (m and link_static)<>0 then
  341. s:=s+'static ';
  342. if (m and link_smart)<>0 then
  343. s:=s+'smart ';
  344. if (m and link_shared)<>0 then
  345. s:=s+'shared ';
  346. maskstr:=s;
  347. end;
  348. var
  349. s : string;
  350. m : longint;
  351. begin
  352. while not ppufile.endofentry do
  353. begin
  354. s:=ppufile.getstring;
  355. m:=ppufile.getlongint;
  356. WriteLn(prefix,s,' (',maskstr(m),')');
  357. end;
  358. end;
  359. Procedure ReadContainer(const prefix:string);
  360. {
  361. Read a serie of strings and write to the screen starting every line
  362. with prefix
  363. }
  364. begin
  365. while not ppufile.endofentry do
  366. WriteLn(prefix,ppufile.getstring);
  367. end;
  368. procedure ReadLoadUnit;
  369. var
  370. ucrc,uintfcrc : cardinal;
  371. begin
  372. while not ppufile.EndOfEntry do
  373. begin
  374. write('Uses unit: ',ppufile.getstring);
  375. ucrc:=cardinal(ppufile.getlongint);
  376. uintfcrc:=cardinal(ppufile.getlongint);
  377. writeln(' (Crc: ',hexstr(ucrc,8),', IntfcCrc: ',hexstr(uintfcrc,8),')');
  378. end;
  379. end;
  380. Procedure ReadDerefmap;
  381. var
  382. i,mapsize : longint;
  383. begin
  384. mapsize:=ppufile.getlongint;
  385. writeln('DerefMapsize: ',mapsize);
  386. for i:=0 to mapsize-1 do
  387. writeln('DerefMap[',i,'] = ',ppufile.getstring);
  388. end;
  389. Procedure ReadImportSymbols;
  390. var
  391. extlibname : string;
  392. j,
  393. extsymcnt : longint;
  394. extsymname : string;
  395. extsymordnr : longint;
  396. extsymisvar : boolean;
  397. begin
  398. while not ppufile.endofentry do
  399. begin
  400. extlibname:=ppufile.getstring;
  401. extsymcnt:=ppufile.getlongint;
  402. writeln('External Library: ',extlibname,' (',extsymcnt,' imports)');
  403. for j:=0 to extsymcnt-1 do
  404. begin
  405. extsymname:=ppufile.getstring;
  406. extsymordnr:=ppufile.getlongint;
  407. extsymisvar:=ppufile.getbyte<>0;
  408. writeln(' ',extsymname,' (OrdNr: ',extsymordnr,' IsVar: ',extsymisvar,')');
  409. end;
  410. end;
  411. end;
  412. Procedure ReadDerefdata;
  413. begin
  414. derefdatalen:=ppufile.entrysize;
  415. if derefdatalen=0 then
  416. begin
  417. writeln('!! Error: derefdatalen=0');
  418. exit;
  419. end;
  420. Writeln('Derefdata length: ',derefdatalen);
  421. derefdata:=allocmem(derefdatalen);
  422. ppufile.getdata(derefdata^,derefdatalen);
  423. end;
  424. Procedure ReadAsmSymbols;
  425. type
  426. { Copied from aasmbase.pas }
  427. TAsmsymbind=(AB_NONE,AB_EXTERNAL,AB_COMMON,AB_LOCAL,AB_GLOBAL);
  428. TAsmsymtype=(AT_NONE,AT_FUNCTION,AT_DATA,AT_SECTION,AT_LABEL);
  429. var
  430. s,
  431. bindstr,
  432. typestr : string;
  433. i : longint;
  434. begin
  435. writeln(space,'Number of AsmSymbols: ',ppufile.getlongint);
  436. i:=0;
  437. while (not ppufile.endofentry) and (not ppufile.error) do
  438. begin
  439. s:=ppufile.getstring;
  440. case tasmsymbind(ppufile.getbyte) of
  441. AB_EXTERNAL :
  442. bindstr:='External';
  443. AB_COMMON :
  444. bindstr:='Common';
  445. AB_LOCAL :
  446. bindstr:='Local';
  447. AB_GLOBAL :
  448. bindstr:='Global';
  449. else
  450. bindstr:='<Error !!>'
  451. end;
  452. case tasmsymtype(ppufile.getbyte) of
  453. AT_FUNCTION :
  454. typestr:='Function';
  455. AT_DATA :
  456. typestr:='Data';
  457. AT_SECTION :
  458. typestr:='Section';
  459. AT_LABEL :
  460. typestr:='Label';
  461. else
  462. typestr:='<Error !!>'
  463. end;
  464. Writeln(space,' ',i,' : ',s,' [',bindstr,',',typestr,']');
  465. inc(i);
  466. end;
  467. end;
  468. Procedure ReadPosInfo;
  469. var
  470. info : byte;
  471. fileindex,line,column : longint;
  472. begin
  473. with ppufile do
  474. begin
  475. {
  476. info byte layout in bits:
  477. 0-1 - amount of bytes for fileindex
  478. 2-3 - amount of bytes for line
  479. 4-5 - amount of bytes for column
  480. }
  481. info:=getbyte;
  482. case (info and $03) of
  483. 0 : fileindex:=getbyte;
  484. 1 : fileindex:=getword;
  485. 2 : fileindex:=(getbyte shl 16) or getword;
  486. 3 : fileindex:=getlongint;
  487. end;
  488. case ((info shr 2) and $03) of
  489. 0 : line:=getbyte;
  490. 1 : line:=getword;
  491. 2 : line:=(getbyte shl 16) or getword;
  492. 3 : line:=getlongint;
  493. end;
  494. case ((info shr 4) and $03) of
  495. 0 : column:=getbyte;
  496. 1 : column:=getword;
  497. 2 : column:=(getbyte shl 16) or getword;
  498. 3 : column:=getlongint;
  499. end;
  500. Writeln(fileindex,' (',line,',',column,')');
  501. end;
  502. end;
  503. procedure readderef;
  504. type
  505. tdereftype = (deref_nil,
  506. deref_unit,
  507. deref_symid,
  508. deref_defid
  509. );
  510. var
  511. b : tdereftype;
  512. first : boolean;
  513. idx : longint;
  514. i,n : byte;
  515. pdata : pbyte;
  516. begin
  517. if not assigned(derefdata) then
  518. exit;
  519. first:=true;
  520. idx:=ppufile.getlongint;
  521. if (idx>derefdatalen) then
  522. begin
  523. writeln('!! Error: Deref idx ',idx,' > ',derefdatalen);
  524. exit;
  525. end;
  526. write('(',idx,') ');
  527. pdata:=@derefdata[idx];
  528. i:=0;
  529. n:=pdata[i];
  530. inc(i);
  531. if n<1 then
  532. begin
  533. writeln('!! Error: Deref len < 1');
  534. exit;
  535. end;
  536. while (i<=n) do
  537. begin
  538. if not first then
  539. write(', ')
  540. else
  541. first:=false;
  542. b:=tdereftype(pdata[i]);
  543. inc(i);
  544. case b of
  545. deref_nil :
  546. write('Nil');
  547. deref_symid :
  548. begin
  549. idx:=pdata[i] shl 24 or pdata[i+1] shl 16 or pdata[i+2] shl 8 or pdata[i+3];
  550. inc(i,4);
  551. write('SymId ',idx);
  552. end;
  553. deref_defid :
  554. begin
  555. idx:=pdata[i] shl 24 or pdata[i+1] shl 16 or pdata[i+2] shl 8 or pdata[i+3];
  556. inc(i,4);
  557. write('DefId ',idx);
  558. end;
  559. deref_unit :
  560. begin
  561. idx:=pdata[i] shl 8 or pdata[i+1];
  562. inc(i,2);
  563. write('Unit ',idx);
  564. end;
  565. else
  566. begin
  567. writeln('!! unsupported dereftyp: ',ord(b));
  568. break;
  569. end;
  570. end;
  571. end;
  572. writeln;
  573. end;
  574. procedure readpropaccesslist(const s:string);
  575. type
  576. tsltype = (sl_none,
  577. sl_load,
  578. sl_call,
  579. sl_subscript,
  580. sl_vec,
  581. sl_typeconv,
  582. sl_absolutetype
  583. );
  584. const
  585. slstr : array[tsltype] of string[12] = ('',
  586. 'load',
  587. 'call',
  588. 'subscript',
  589. 'vec',
  590. 'typeconv',
  591. 'absolutetype'
  592. );
  593. var
  594. sl : tsltype;
  595. begin
  596. readderef;
  597. repeat
  598. sl:=tsltype(ppufile.getbyte);
  599. if sl=sl_none then
  600. break;
  601. write(s,'(',slstr[sl],') ');
  602. case sl of
  603. sl_call,
  604. sl_load,
  605. sl_subscript :
  606. readderef;
  607. sl_absolutetype,
  608. sl_typeconv :
  609. readderef;
  610. sl_vec :
  611. begin
  612. writeln(ppufile.getlongint);
  613. readderef;
  614. end;
  615. end;
  616. until false;
  617. end;
  618. procedure readsymoptions;
  619. type
  620. tsymoption=(sp_none,
  621. sp_public,
  622. sp_private,
  623. sp_published,
  624. sp_protected,
  625. sp_static,
  626. sp_hint_deprecated,
  627. sp_hint_platform,
  628. sp_hint_library,
  629. sp_hint_unimplemented,
  630. sp_has_overloaded,
  631. sp_internal { internal symbol, not reported as unused }
  632. );
  633. tsymoptions=set of tsymoption;
  634. tsymopt=record
  635. mask : tsymoption;
  636. str : string[30];
  637. end;
  638. const
  639. symopts=11;
  640. symopt : array[1..symopts] of tsymopt=(
  641. (mask:sp_public; str:'Public'),
  642. (mask:sp_private; str:'Private'),
  643. (mask:sp_published; str:'Published'),
  644. (mask:sp_protected; str:'Protected'),
  645. (mask:sp_static; str:'Static'),
  646. (mask:sp_hint_deprecated;str:'Hint Deprecated'),
  647. (mask:sp_hint_deprecated;str:'Hint Platform'),
  648. (mask:sp_hint_deprecated;str:'Hint Library'),
  649. (mask:sp_hint_deprecated;str:'Hint Unimplemented'),
  650. (mask:sp_has_overloaded; str:'Has overloaded'),
  651. (mask:sp_internal; str:'Internal')
  652. );
  653. var
  654. symoptions : tsymoptions;
  655. i : longint;
  656. first : boolean;
  657. begin
  658. ppufile.getsmallset(symoptions);
  659. if symoptions<>[] then
  660. begin
  661. first:=true;
  662. for i:=1to symopts do
  663. if (symopt[i].mask in symoptions) then
  664. begin
  665. if first then
  666. first:=false
  667. else
  668. write(', ');
  669. write(symopt[i].str);
  670. end;
  671. end;
  672. writeln;
  673. end;
  674. procedure readcommonsym(const s:string);
  675. begin
  676. writeln(space,'** Symbol Id ',ppufile.getlongint,' **');
  677. writeln(space,s,ppufile.getstring);
  678. write(space,' File Pos : ');
  679. readposinfo;
  680. write(space,' SymOptions : ');
  681. readsymoptions;
  682. end;
  683. procedure readcommondef(const s:string);
  684. type
  685. { flags for a definition }
  686. tdefoption=(df_none,
  687. { type is unique, i.e. declared with type = type <tdef>; }
  688. df_unique,
  689. { type is a generic }
  690. df_generic,
  691. { type is a specialization of a generic type }
  692. df_specialization
  693. );
  694. tdefoptions=set of tdefoption;
  695. tdefstate=(ds_none,
  696. ds_vmt_written,
  697. ds_rtti_table_used,
  698. ds_init_table_used,
  699. ds_rtti_table_written,
  700. ds_init_table_written,
  701. ds_dwarf_dbg_info_used,
  702. ds_dwarf_dbg_info_written
  703. );
  704. tdefstates=set of tdefstate;
  705. tdefopt=record
  706. mask : tdefoption;
  707. str : string[30];
  708. end;
  709. tdefstateinfo=record
  710. mask : tdefstate;
  711. str : string[30];
  712. end;
  713. const
  714. defopts=3;
  715. defopt : array[1..defopts] of tdefopt=(
  716. (mask:df_unique; str:'Unique Type'),
  717. (mask:df_generic; str:'Generic'),
  718. (mask:df_specialization; str:'Specialization')
  719. );
  720. defstateinfos=7;
  721. defstate : array[1..defstateinfos] of tdefstateinfo=(
  722. (mask:ds_init_table_used; str:'InitTable Used'),
  723. (mask:ds_rtti_table_used; str:'RTTITable Used'),
  724. (mask:ds_init_table_written; str:'InitTable Written'),
  725. (mask:ds_rtti_table_written; str:'RTTITable Written'),
  726. (mask:ds_dwarf_dbg_info_used; str:'Dwarf DbgInfo Used'),
  727. (mask:ds_dwarf_dbg_info_written;str:'Dwarf DbgInfo Written'),
  728. (mask:ds_vmt_written; str:'VMT Written')
  729. );
  730. var
  731. defoptions : tdefoptions;
  732. i : longint;
  733. first : boolean;
  734. tokenbufsize : longint;
  735. tokenbuf : pbyte;
  736. begin
  737. writeln(space,'** Definition Id ',ppufile.getlongint,' **');
  738. writeln(space,s);
  739. write (space,' Type symbol : ');
  740. readderef;
  741. write (space,' DefOptions : ');
  742. ppufile.getsmallset(defoptions);
  743. if defoptions<>[] then
  744. begin
  745. first:=true;
  746. for i:=1to defopts do
  747. if (defopt[i].mask in defoptions) then
  748. begin
  749. if first then
  750. first:=false
  751. else
  752. write(', ');
  753. write(defopt[i].str);
  754. end;
  755. end;
  756. writeln;
  757. if df_unique in defoptions then
  758. writeln (space,' Unique type symbol');
  759. if df_generic in defoptions then
  760. begin
  761. tokenbufsize:=ppufile.getlongint;
  762. writeln(space,' Tokenbuffer size : ',tokenbufsize);
  763. tokenbuf:=allocmem(tokenbufsize);
  764. ppufile.getdata(tokenbuf^,tokenbufsize);
  765. i:=0;
  766. write(space,' Tokens: ');
  767. while i<tokenbufsize do
  768. begin
  769. if ttoken(tokenbuf[i])<>_GENERICSPECIALTOKEN then
  770. write(arraytokeninfo[ttoken(tokenbuf[i])].str);
  771. case ttoken(tokenbuf[i]) of
  772. _CWCHAR,
  773. _CWSTRING :
  774. begin
  775. inc(i);
  776. {
  777. replaytokenbuf.read(wlen,sizeof(SizeInt));
  778. setlengthwidestring(patternw,wlen);
  779. replaytokenbuf.read(patternw^.data^,patternw^.len*sizeof(tcompilerwidechar));
  780. pattern:='';
  781. }
  782. end;
  783. _CCHAR,
  784. _CSTRING,
  785. _INTCONST,
  786. _REALNUMBER :
  787. begin
  788. inc(i);
  789. {
  790. replaytokenbuf.read(pattern[0],1);
  791. replaytokenbuf.read(pattern[1],length(pattern));
  792. orgpattern:='';
  793. }
  794. end;
  795. _ID :
  796. begin
  797. inc(i);
  798. inc(i);
  799. write(' ',pshortstring(@tokenbuf[i])^);
  800. inc(i,tokenbuf[i]+1);
  801. {
  802. replaytokenbuf.read(orgpattern[0],1);
  803. replaytokenbuf.read(orgpattern[1],length(orgpattern));
  804. pattern:=upper(orgpattern);
  805. }
  806. end;
  807. _GENERICSPECIALTOKEN:
  808. begin
  809. inc(i);
  810. case tspecialgenerictoken(tokenbuf[i]) of
  811. ST_LOADSETTINGS:
  812. begin
  813. inc(i);
  814. write('Settings');
  815. inc(i,sizeof(tsettings));
  816. end;
  817. ST_LINE:
  818. begin
  819. inc(i);
  820. write('Line: ',pdword(@tokenbuf[i])^);
  821. inc(i,4);
  822. end;
  823. ST_COLUMN:
  824. begin
  825. inc(i);
  826. write('Col: ',pword(@tokenbuf[i])^);
  827. inc(i,2);
  828. end;
  829. ST_FILEINDEX:
  830. begin
  831. inc(i);
  832. write('File: ',pword(@tokenbuf[i])^);
  833. inc(i,2);
  834. end;
  835. end;
  836. {
  837. replaytokenbuf.read(specialtoken,1);
  838. case specialtoken of
  839. ST_LOADSETTINGS:
  840. begin
  841. replaytokenbuf.read(current_settings,sizeof(current_settings));
  842. end
  843. else
  844. internalerror(2006103010);
  845. end;
  846. continue;
  847. }
  848. end;
  849. else
  850. inc(i);
  851. end;
  852. if i<tokenbufsize then
  853. write(',');
  854. end;
  855. writeln;
  856. freemem(tokenbuf);
  857. end;
  858. if df_specialization in defoptions then
  859. begin
  860. write (space,' Orig. GenericDef : ');
  861. readderef;
  862. end;
  863. end;
  864. { Read abstract procdef and return if inline procdef }
  865. type
  866. tproccalloption=(pocall_none,
  867. { procedure uses C styled calling }
  868. pocall_cdecl,
  869. { C++ calling conventions }
  870. pocall_cppdecl,
  871. { Far16 for OS/2 }
  872. pocall_far16,
  873. { Old style FPC default calling }
  874. pocall_oldfpccall,
  875. { Procedure has compiler magic}
  876. pocall_internproc,
  877. { procedure is a system call, applies e.g. to MorphOS and PalmOS }
  878. pocall_syscall,
  879. { pascal standard left to right }
  880. pocall_pascal,
  881. { procedure uses register (fastcall) calling }
  882. pocall_register,
  883. { safe call calling conventions }
  884. pocall_safecall,
  885. { procedure uses stdcall call }
  886. pocall_stdcall,
  887. { Special calling convention for cpus without a floating point
  888. unit. Floating point numbers are passed in integer registers
  889. instead of floating point registers. Depending on the other
  890. available calling conventions available for the cpu
  891. this replaces either pocall_fastcall or pocall_stdcall.
  892. }
  893. pocall_softfloat,
  894. { Metrowerks Pascal. Special case on Mac OS (X): passes all }
  895. { constant records by reference. }
  896. pocall_mwpascal
  897. );
  898. tproccalloptions=set of tproccalloption;
  899. tproctypeoption=(potype_none,
  900. potype_proginit, { Program initialization }
  901. potype_unitinit, { unit initialization }
  902. potype_unitfinalize, { unit finalization }
  903. potype_constructor, { Procedure is a constructor }
  904. potype_destructor, { Procedure is a destructor }
  905. potype_operator, { Procedure defines an operator }
  906. potype_procedure,
  907. potype_function
  908. );
  909. tproctypeoptions=set of tproctypeoption;
  910. tprocoption=(po_none,
  911. po_classmethod, { class method }
  912. po_virtualmethod, { Procedure is a virtual method }
  913. po_abstractmethod, { Procedure is an abstract method }
  914. po_staticmethod, { static method }
  915. po_overridingmethod, { method with override directive }
  916. po_methodpointer, { method pointer, only in procvardef, also used for 'with object do' }
  917. po_interrupt, { Procedure is an interrupt handler }
  918. po_iocheck, { IO checking should be done after a call to the procedure }
  919. po_assembler, { Procedure is written in assembler }
  920. po_msgstr, { method for string message handling }
  921. po_msgint, { method for int message handling }
  922. po_exports, { Procedure has export directive (needed for OS/2) }
  923. po_external, { Procedure is external (in other object or lib)}
  924. po_overload, { procedure is declared with overload directive }
  925. po_varargs, { printf like arguments }
  926. po_internconst, { procedure has constant evaluator intern }
  927. { flag that only the address of a method is returned and not a full methodpointer }
  928. po_addressonly,
  929. { procedure is exported }
  930. po_public,
  931. { calling convention is specified explicitly }
  932. po_hascallingconvention,
  933. { reintroduce flag }
  934. po_reintroduce,
  935. { location of parameters is given explicitly as it is necessary for some syscall
  936. conventions like that one of MorphOS }
  937. po_explicitparaloc,
  938. { no stackframe will be generated, used by lowlevel assembler like get_frame }
  939. po_nostackframe,
  940. po_has_mangledname,
  941. po_has_public_name,
  942. po_forward,
  943. po_global,
  944. po_has_inlininginfo,
  945. { The different kind of syscalls on MorphOS }
  946. po_syscall_legacy,
  947. po_syscall_sysv,
  948. po_syscall_basesysv,
  949. po_syscall_sysvbase,
  950. po_syscall_r12base,
  951. po_local,
  952. { Procedure can be inlined }
  953. po_inline,
  954. { Procedure is used for internal compiler calls }
  955. po_compilerproc,
  956. { importing }
  957. po_has_importdll,
  958. po_has_importname,
  959. po_kylixlocal
  960. );
  961. tprocoptions=set of tprocoption;
  962. procedure read_abstract_proc_def(var proccalloption:tproccalloption;var procoptions:tprocoptions);
  963. type
  964. tproccallopt=record
  965. mask : tproccalloption;
  966. str : string[30];
  967. end;
  968. tproctypeopt=record
  969. mask : tproctypeoption;
  970. str : string[30];
  971. end;
  972. tprocopt=record
  973. mask : tprocoption;
  974. str : string[30];
  975. end;
  976. const
  977. proccalloptionStr : array[tproccalloption] of string[14]=('',
  978. 'CDecl',
  979. 'CPPDecl',
  980. 'Far16',
  981. 'OldFPCCall',
  982. 'InternProc',
  983. 'SysCall',
  984. 'Pascal',
  985. 'Register',
  986. 'SafeCall',
  987. 'StdCall',
  988. 'SoftFloat',
  989. 'MWPascal'
  990. );
  991. proctypeopts=8;
  992. proctypeopt : array[1..proctypeopts] of tproctypeopt=(
  993. (mask:potype_proginit; str:'ProgInit'),
  994. (mask:potype_unitinit; str:'UnitInit'),
  995. (mask:potype_unitfinalize;str:'UnitFinalize'),
  996. (mask:potype_constructor; str:'Constructor'),
  997. (mask:potype_destructor; str:'Destructor'),
  998. (mask:potype_operator; str:'Operator'),
  999. (mask:potype_function; str:'Function'),
  1000. (mask:potype_procedure; str:'Procedure')
  1001. );
  1002. procopts=38;
  1003. procopt : array[1..procopts] of tprocopt=(
  1004. (mask:po_classmethod; str:'ClassMethod'),
  1005. (mask:po_virtualmethod; str:'VirtualMethod'),
  1006. (mask:po_abstractmethod; str:'AbstractMethod'),
  1007. (mask:po_staticmethod; str:'StaticMethod'),
  1008. (mask:po_overridingmethod;str:'OverridingMethod'),
  1009. (mask:po_methodpointer; str:'MethodPointer'),
  1010. (mask:po_interrupt; str:'Interrupt'),
  1011. (mask:po_iocheck; str:'IOCheck'),
  1012. (mask:po_assembler; str:'Assembler'),
  1013. (mask:po_msgstr; str:'MsgStr'),
  1014. (mask:po_msgint; str:'MsgInt'),
  1015. (mask:po_exports; str:'Exports'),
  1016. (mask:po_external; str:'External'),
  1017. (mask:po_overload; str:'Overload'),
  1018. (mask:po_varargs; str:'VarArgs'),
  1019. (mask:po_internconst; str:'InternConst'),
  1020. (mask:po_addressonly; str:'AddressOnly'),
  1021. (mask:po_public; str:'Public'),
  1022. (mask:po_hascallingconvention;str:'HasCallingConvention'),
  1023. (mask:po_reintroduce; str:'ReIntroduce'),
  1024. (mask:po_explicitparaloc; str:'ExplicitParaloc'),
  1025. (mask:po_nostackframe; str:'NoStackFrame'),
  1026. (mask:po_has_mangledname; str:'HasMangledName'),
  1027. (mask:po_has_public_name; str:'HasPublicName'),
  1028. (mask:po_forward; str:'Forward'),
  1029. (mask:po_global; str:'Global'),
  1030. (mask:po_has_inlininginfo;str:'HasInliningInfo'),
  1031. (mask:po_syscall_legacy; str:'SyscallLegacy'),
  1032. (mask:po_syscall_sysv; str:'SyscallSysV'),
  1033. (mask:po_syscall_basesysv;str:'SyscallBaseSysV'),
  1034. (mask:po_syscall_sysvbase;str:'SyscallSysVBase'),
  1035. (mask:po_syscall_r12base; str:'SyscallR12Base'),
  1036. (mask:po_local; str:'Local'),
  1037. (mask:po_inline; str:'Inline'),
  1038. (mask:po_compilerproc; str:'CompilerProc'),
  1039. (mask:po_has_importdll; str:'HasImportDLL'),
  1040. (mask:po_has_importname; str:'HasImportName'),
  1041. (mask:po_kylixlocal; str:'KylixLocal')
  1042. );
  1043. var
  1044. proctypeoption : tproctypeoption;
  1045. i : longint;
  1046. first : boolean;
  1047. tempbuf : array[0..255] of byte;
  1048. begin
  1049. write(space,' Return type : ');
  1050. readderef;
  1051. writeln(space,' Fpu used : ',ppufile.getbyte);
  1052. proctypeoption:=tproctypeoption(ppufile.getbyte);
  1053. write(space,' TypeOption : ');
  1054. first:=true;
  1055. for i:=1 to proctypeopts do
  1056. if (proctypeopt[i].mask=proctypeoption) then
  1057. begin
  1058. if first then
  1059. first:=false
  1060. else
  1061. write(', ');
  1062. write(proctypeopt[i].str);
  1063. end;
  1064. writeln;
  1065. proccalloption:=tproccalloption(ppufile.getbyte);
  1066. writeln(space,' CallOption : ',proccalloptionStr[proccalloption]);
  1067. ppufile.getnormalset(procoptions);
  1068. if procoptions<>[] then
  1069. begin
  1070. write(space,' Options : ');
  1071. first:=true;
  1072. for i:=1to procopts do
  1073. if (procopt[i].mask in procoptions) then
  1074. begin
  1075. if first then
  1076. first:=false
  1077. else
  1078. write(', ');
  1079. write(procopt[i].str);
  1080. end;
  1081. writeln;
  1082. end;
  1083. if (po_explicitparaloc in procoptions) then
  1084. begin
  1085. i:=ppufile.getbyte;
  1086. ppufile.getdata(tempbuf,i);
  1087. end;
  1088. end;
  1089. type
  1090. { options for variables }
  1091. tvaroption=(vo_none,
  1092. vo_is_external,
  1093. vo_is_dll_var,
  1094. vo_is_thread_var,
  1095. vo_has_local_copy,
  1096. vo_is_const, { variable is declared as const (parameter) and can't be written to }
  1097. vo_is_public,
  1098. vo_is_high_para,
  1099. vo_is_funcret,
  1100. vo_is_self,
  1101. vo_is_vmt,
  1102. vo_is_result, { special result variable }
  1103. vo_is_parentfp,
  1104. vo_is_loop_counter, { used to detect assignments to loop counter }
  1105. vo_is_hidden_para,
  1106. vo_has_explicit_paraloc,
  1107. vo_is_syscall_lib,
  1108. vo_has_mangledname,
  1109. vo_is_typed_const
  1110. );
  1111. tvaroptions=set of tvaroption;
  1112. { register variable }
  1113. tvarregable=(vr_none,
  1114. vr_intreg,
  1115. vr_fpureg,
  1116. vr_mmreg,
  1117. vr_addr
  1118. );
  1119. procedure readabstractvarsym(const s:string;var varoptions:tvaroptions);
  1120. type
  1121. tvaropt=record
  1122. mask : tvaroption;
  1123. str : string[30];
  1124. end;
  1125. const
  1126. varopts=18;
  1127. varopt : array[1..varopts] of tvaropt=(
  1128. (mask:vo_is_external; str:'External'),
  1129. (mask:vo_is_dll_var; str:'DLLVar'),
  1130. (mask:vo_is_thread_var; str:'ThreadVar'),
  1131. (mask:vo_has_local_copy; str:'HasLocalCopy'),
  1132. (mask:vo_is_const; str:'Constant'),
  1133. (mask:vo_is_public; str:'Public'),
  1134. (mask:vo_is_high_para; str:'HighValue'),
  1135. (mask:vo_is_funcret; str:'Funcret'),
  1136. (mask:vo_is_self; str:'Self'),
  1137. (mask:vo_is_vmt; str:'VMT'),
  1138. (mask:vo_is_result; str:'Result'),
  1139. (mask:vo_is_parentfp; str:'ParentFP'),
  1140. (mask:vo_is_loop_counter; str:'LoopCounter'),
  1141. (mask:vo_is_hidden_para; str:'Hidden'),
  1142. (mask:vo_has_explicit_paraloc;str:'ExplicitParaloc'),
  1143. (mask:vo_is_syscall_lib; str:'SysCallLib'),
  1144. (mask:vo_has_mangledname; str:'HasMangledName'),
  1145. (mask:vo_is_typed_const; str:'TypedConst')
  1146. );
  1147. var
  1148. i : longint;
  1149. first : boolean;
  1150. begin
  1151. readcommonsym(s);
  1152. writeln(space,' Spez : ',Varspez2Str(ppufile.getbyte));
  1153. writeln(space,' Regable : ',Varregable2Str(ppufile.getbyte));
  1154. write (space,' Var Type : ');
  1155. readderef;
  1156. ppufile.getsmallset(varoptions);
  1157. if varoptions<>[] then
  1158. begin
  1159. write(space,' Options : ');
  1160. first:=true;
  1161. for i:=1to varopts do
  1162. if (varopt[i].mask in varoptions) then
  1163. begin
  1164. if first then
  1165. first:=false
  1166. else
  1167. write(', ');
  1168. write(varopt[i].str);
  1169. end;
  1170. writeln;
  1171. end;
  1172. end;
  1173. procedure readobjectdefoptions;
  1174. type
  1175. tobjectoption=(oo_none,
  1176. oo_is_forward, { the class is only a forward declared yet }
  1177. oo_has_virtual, { the object/class has virtual methods }
  1178. oo_has_private,
  1179. oo_has_protected,
  1180. oo_has_strictprivate,
  1181. oo_has_strictprotected,
  1182. oo_has_constructor, { the object/class has a constructor }
  1183. oo_has_destructor, { the object/class has a destructor }
  1184. oo_has_vmt, { the object/class has a vmt }
  1185. oo_has_msgstr,
  1186. oo_has_msgint,
  1187. oo_can_have_published,{ the class has rtti, i.e. you can publish properties }
  1188. oo_has_default_property,
  1189. oo_vmt_written
  1190. );
  1191. tobjectoptions=set of tobjectoption;
  1192. tsymopt=record
  1193. mask : tobjectoption;
  1194. str : string[30];
  1195. end;
  1196. const
  1197. symopts=14;
  1198. symopt : array[1..symopts] of tsymopt=(
  1199. (mask:oo_has_virtual; str:'IsForward'),
  1200. (mask:oo_has_virtual; str:'HasVirtual'),
  1201. (mask:oo_has_private; str:'HasPrivate'),
  1202. (mask:oo_has_protected; str:'HasProtected'),
  1203. (mask:oo_has_strictprivate; str:'HasStrictPrivate'),
  1204. (mask:oo_has_strictprotected;str:'HasStrictProtected'),
  1205. (mask:oo_has_constructor; str:'HasConstructor'),
  1206. (mask:oo_has_destructor; str:'HasDestructor'),
  1207. (mask:oo_has_vmt; str:'HasVMT'),
  1208. (mask:oo_has_msgstr; str:'HasMsgStr'),
  1209. (mask:oo_has_msgint; str:'HasMsgInt'),
  1210. (mask:oo_can_have_published; str:'CanHavePublished'),
  1211. (mask:oo_has_default_property;str:'HasDefaultProperty'),
  1212. (mask:oo_vmt_written; str:'VMTWritten')
  1213. );
  1214. var
  1215. symoptions : tobjectoptions;
  1216. i : longint;
  1217. first : boolean;
  1218. begin
  1219. ppufile.getsmallset(symoptions);
  1220. if symoptions<>[] then
  1221. begin
  1222. first:=true;
  1223. for i:=1to symopts do
  1224. if (symopt[i].mask in symoptions) then
  1225. begin
  1226. if first then
  1227. first:=false
  1228. else
  1229. write(', ');
  1230. write(symopt[i].str);
  1231. end;
  1232. end;
  1233. writeln;
  1234. end;
  1235. procedure readarraydefoptions;
  1236. type
  1237. tarraydefoption=(ado_none,
  1238. ado_IsConvertedPointer,
  1239. ado_IsDynamicArray,
  1240. ado_IsVariant,
  1241. ado_IsConstructor,
  1242. ado_IsArrayOfConst,
  1243. ado_IsConstString
  1244. );
  1245. tarraydefoptions=set of tarraydefoption;
  1246. tsymopt=record
  1247. mask : tarraydefoption;
  1248. str : string[30];
  1249. end;
  1250. const
  1251. symopts=6;
  1252. symopt : array[1..symopts] of tsymopt=(
  1253. (mask:ado_IsConvertedPointer;str:'ConvertedPointer'),
  1254. (mask:ado_IsDynamicArray; str:'IsDynamicArray'),
  1255. (mask:ado_IsVariant; str:'IsVariant'),
  1256. (mask:ado_IsConstructor; str:'IsConstructor'),
  1257. (mask:ado_IsArrayOfConst; str:'ArrayOfConst'),
  1258. (mask:ado_IsConstString; str:'ConstString')
  1259. );
  1260. var
  1261. symoptions : tarraydefoptions;
  1262. i : longint;
  1263. first : boolean;
  1264. begin
  1265. ppufile.getsmallset(symoptions);
  1266. if symoptions<>[] then
  1267. begin
  1268. first:=true;
  1269. for i:=1to symopts do
  1270. if (symopt[i].mask in symoptions) then
  1271. begin
  1272. if first then
  1273. first:=false
  1274. else
  1275. write(', ');
  1276. write(symopt[i].str);
  1277. end;
  1278. end;
  1279. writeln;
  1280. end;
  1281. procedure readnodetree;
  1282. var
  1283. l : longint;
  1284. p : pointer;
  1285. begin
  1286. with ppufile do
  1287. begin
  1288. if space<>'' then
  1289. Writeln(space,'------ nodetree ------');
  1290. if readentry=ibnodetree then
  1291. begin
  1292. l:=entrysize;
  1293. Writeln(space,'Tree size : ',l);
  1294. { Read data to prevent error that entry is not completly read }
  1295. getmem(p,l);
  1296. getdata(p^,l);
  1297. freemem(p);
  1298. end
  1299. else
  1300. begin
  1301. Writeln('!! ibnodetree not found');
  1302. end;
  1303. end;
  1304. end;
  1305. {****************************************************************************
  1306. Read Symbols Part
  1307. ****************************************************************************}
  1308. procedure readsymbols(const s:string);
  1309. type
  1310. pguid = ^tguid;
  1311. tguid = packed record
  1312. D1: LongWord;
  1313. D2: Word;
  1314. D3: Word;
  1315. D4: array[0..7] of Byte;
  1316. end;
  1317. absolutetyp = (tovar,toasm,toaddr);
  1318. tconsttyp = (constnone,
  1319. constord,conststring,constreal,
  1320. constset,constpointer,constnil,
  1321. constresourcestring,constwstring,constguid
  1322. );
  1323. var
  1324. b : byte;
  1325. pc : pchar;
  1326. i,j,len : longint;
  1327. guid : tguid;
  1328. tempbuf : array[0..127] of char;
  1329. varoptions : tvaroptions;
  1330. begin
  1331. with ppufile do
  1332. begin
  1333. if space<>'' then
  1334. Writeln(space,'------ ',s,' ------');
  1335. if readentry=ibstartsyms then
  1336. begin
  1337. Writeln(space,'Symtable datasize : ',getlongint);
  1338. Writeln(space,'Symtable alignment: ',getlongint);
  1339. end
  1340. else
  1341. Writeln('!! ibstartsym not found');
  1342. repeat
  1343. b:=readentry;
  1344. case b of
  1345. ibunitsym :
  1346. readcommonsym('Unit symbol ');
  1347. iblabelsym :
  1348. readcommonsym('Label symbol ');
  1349. ibtypesym :
  1350. begin
  1351. readcommonsym('Type symbol ');
  1352. write(space,' Result Type : ');
  1353. readderef;
  1354. end;
  1355. ibprocsym :
  1356. begin
  1357. readcommonsym('Procedure symbol ');
  1358. len:=ppufile.getword;
  1359. for i:=1 to len do
  1360. begin
  1361. write(space,' Definition : ');
  1362. readderef;
  1363. end;
  1364. end;
  1365. ibconstsym :
  1366. begin
  1367. readcommonsym('Constant symbol ');
  1368. b:=getbyte;
  1369. case tconsttyp(b) of
  1370. constord :
  1371. begin
  1372. write (space,' OrdinalType : ');
  1373. readderef;
  1374. writeln(space,' Value : ',getint64);
  1375. end;
  1376. constpointer :
  1377. begin
  1378. write (space,' PointerType : ');
  1379. readderef;
  1380. writeln(space,' Value : ',getlongint)
  1381. end;
  1382. conststring,
  1383. constresourcestring :
  1384. begin
  1385. len:=getlongint;
  1386. getmem(pc,len+1);
  1387. getdata(pc^,len);
  1388. (pc+len)^:= #0;
  1389. writeln(space,' Length : ',len);
  1390. writeln(space,' Value : "',pc,'"');
  1391. freemem(pc,len+1);
  1392. if tconsttyp(b)=constresourcestring then
  1393. writeln(space,' Index : ',getlongint);
  1394. end;
  1395. constreal :
  1396. writeln(space,' Value : ',getreal);
  1397. constset :
  1398. begin
  1399. write (space,' Set Type : ');
  1400. readderef;
  1401. for i:=1to 4 do
  1402. begin
  1403. write (space,' Value : ');
  1404. for j:=1to 8 do
  1405. begin
  1406. if j>1 then
  1407. write(',');
  1408. write(hexb(getbyte));
  1409. end;
  1410. writeln;
  1411. end;
  1412. end;
  1413. constwstring:
  1414. begin
  1415. end;
  1416. constguid:
  1417. begin
  1418. getdata(guid,sizeof(guid));
  1419. write (space,' IID String: {',hexstr(guid.d1,8),'-',hexstr(guid.d2,4),'-',hexstr(guid.d3,4),'-');
  1420. for i:=0 to 7 do
  1421. begin
  1422. write(hexstr(guid.d4[i],2));
  1423. if i=1 then write('-');
  1424. end;
  1425. writeln('}');
  1426. end
  1427. else
  1428. Writeln ('!! Invalid unit format : Invalid const type encountered: ',b);
  1429. end;
  1430. end;
  1431. ibabsolutevarsym :
  1432. begin
  1433. readabstractvarsym('Absolute variable symbol ',varoptions);
  1434. Write (space,' Relocated to ');
  1435. b:=getbyte;
  1436. case absolutetyp(b) of
  1437. tovar :
  1438. readpropaccesslist(space+' Sym : ');
  1439. toasm :
  1440. Writeln('Assembler name : ',getstring);
  1441. toaddr :
  1442. begin
  1443. Write('Address : ',getlongint);
  1444. if tsystemcpu(ppufile.header.cpu)=cpu_i386 then
  1445. WriteLn(' (Far: ',getbyte<>0,')');
  1446. end;
  1447. else
  1448. Writeln ('!! Invalid unit format : Invalid absolute type encountered: ',b);
  1449. end;
  1450. end;
  1451. ibfieldvarsym :
  1452. begin
  1453. readabstractvarsym('Field Variable symbol ',varoptions);
  1454. writeln(space,' Address : ',getaint);
  1455. end;
  1456. ibstaticvarsym :
  1457. begin
  1458. readabstractvarsym('Global Variable symbol ',varoptions);
  1459. write (space,' DefaultConst : ');
  1460. readderef;
  1461. if (vo_has_mangledname in varoptions) then
  1462. writeln(space,' Mangledname : ',getstring);
  1463. end;
  1464. iblocalvarsym :
  1465. begin
  1466. readabstractvarsym('Local Variable symbol ',varoptions);
  1467. write (space,' DefaultConst : ');
  1468. readderef;
  1469. end;
  1470. ibparavarsym :
  1471. begin
  1472. readabstractvarsym('Parameter Variable symbol ',varoptions);
  1473. write (space,' DefaultConst : ');
  1474. readderef;
  1475. writeln(space,' ParaNr : ',getword);
  1476. writeln(space,' VarState : ',getbyte);
  1477. if (vo_has_explicit_paraloc in varoptions) then
  1478. begin
  1479. i:=getbyte;
  1480. getdata(tempbuf,i);
  1481. end;
  1482. end;
  1483. ibenumsym :
  1484. begin
  1485. readcommonsym('Enumeration symbol ');
  1486. write (space,' Definition : ');
  1487. readderef;
  1488. writeln(space,' Value : ',getlongint);
  1489. end;
  1490. ibsyssym :
  1491. begin
  1492. readcommonsym('Internal system symbol ');
  1493. writeln(space,' Internal Nr : ',getlongint);
  1494. end;
  1495. ibmacrosym :
  1496. begin
  1497. readcommonsym('Macro symbol ');
  1498. writeln(space,' Name: ',getstring);
  1499. writeln(space,' Defined: ',getbyte);
  1500. writeln(space,' Compiler var: ',getbyte);
  1501. len:=getlongint;
  1502. writeln(space,' Value length: ',len);
  1503. if len > 0 then
  1504. begin
  1505. getmem(pc,len+1);
  1506. getdata(pc^,len);
  1507. (pc+len)^:= #0;
  1508. writeln(space,' Value: "',pc,'"');
  1509. freemem(pc,len+1);
  1510. end;
  1511. end;
  1512. ibpropertysym :
  1513. begin
  1514. readcommonsym('Property ');
  1515. i:=getlongint;
  1516. writeln(space,' PropOptions : ',i);
  1517. write (space,' OverrideProp : ');
  1518. readderef;
  1519. write (space,' Prop Type : ');
  1520. readderef;
  1521. writeln(space,' Index : ',getlongint);
  1522. writeln(space,' Default : ',getlongint);
  1523. write (space,' Index Type : ');
  1524. readderef;
  1525. write (space,' Readaccess : ');
  1526. readpropaccesslist(space+' Sym: ');
  1527. write (space,' Writeaccess : ');
  1528. readpropaccesslist(space+' Sym: ');
  1529. write (space,' Storedaccess : ');
  1530. readpropaccesslist(space+' Sym: ');
  1531. end;
  1532. iberror :
  1533. begin
  1534. Writeln('!! Error in PPU');
  1535. exit;
  1536. end;
  1537. ibendsyms :
  1538. break;
  1539. else
  1540. WriteLn('!! Skipping unsupported PPU Entry in Symbols: ',b);
  1541. end;
  1542. if not EndOfEntry then
  1543. Writeln('!! Entry has more information stored');
  1544. until false;
  1545. end;
  1546. end;
  1547. {****************************************************************************
  1548. Read defintions Part
  1549. ****************************************************************************}
  1550. procedure readdefinitions(const s:string);
  1551. type
  1552. tsettype = (normset,smallset,varset);
  1553. tordtype = (
  1554. uvoid,
  1555. u8bit,u16bit,u32bit,u64bit,
  1556. s8bit,s16bit,s32bit,s64bit,
  1557. bool8bit,bool16bit,bool32bit,
  1558. uchar,uwidechar,scurrency
  1559. );
  1560. tobjecttyp = (odt_none,
  1561. odt_class,
  1562. odt_object,
  1563. odt_interfacecom,
  1564. odt_interfacecorba,
  1565. odt_cppclass,
  1566. odt_dispinterface
  1567. );
  1568. tvarianttype = (
  1569. vt_normalvariant,vt_olevariant
  1570. );
  1571. var
  1572. b : byte;
  1573. l,j : longint;
  1574. calloption : tproccalloption;
  1575. procoptions : tprocoptions;
  1576. procinfooptions : tprocinfoflag;
  1577. begin
  1578. with ppufile do
  1579. begin
  1580. if space<>'' then
  1581. Writeln(space,'------ ',s,' ------');
  1582. if readentry<>ibstartdefs then
  1583. Writeln('!! ibstartdefs not found');
  1584. repeat
  1585. b:=readentry;
  1586. case b of
  1587. ibpointerdef :
  1588. begin
  1589. readcommondef('Pointer definition');
  1590. write (space,' Pointed Type : ');
  1591. readderef;
  1592. writeln(space,' Is Far : ',(getbyte<>0));
  1593. end;
  1594. iborddef :
  1595. begin
  1596. readcommondef('Ordinal definition');
  1597. write (space,' Base type : ');
  1598. b:=getbyte;
  1599. case tordtype(b) of
  1600. uvoid : writeln('uvoid');
  1601. u8bit : writeln('u8bit');
  1602. u16bit : writeln('u16bit');
  1603. u32bit : writeln('s32bit');
  1604. u64bit : writeln('u64bit');
  1605. s8bit : writeln('s8bit');
  1606. s16bit : writeln('s16bit');
  1607. s32bit : writeln('s32bit');
  1608. s64bit : writeln('s64bit');
  1609. bool8bit : writeln('bool8bit');
  1610. bool16bit : writeln('bool16bit');
  1611. bool32bit : writeln('bool32bit');
  1612. uchar : writeln('uchar');
  1613. uwidechar : writeln('uwidechar');
  1614. scurrency : writeln('ucurrency');
  1615. else writeln('!! Warning: Invalid base type ',b);
  1616. end;
  1617. writeln(space,' Range : ',getint64,' to ',getint64);
  1618. end;
  1619. ibfloatdef :
  1620. begin
  1621. readcommondef('Float definition');
  1622. writeln(space,' Float type : ',getbyte);
  1623. end;
  1624. ibarraydef :
  1625. begin
  1626. readcommondef('Array definition');
  1627. write (space,' Element type : ');
  1628. readderef;
  1629. write (space,' Range Type : ');
  1630. readderef;
  1631. writeln(space,' Range : ',getaint,' to ',getaint);
  1632. write (space,' Options : ');
  1633. readarraydefoptions;
  1634. end;
  1635. ibprocdef :
  1636. begin
  1637. readcommondef('Procedure definition');
  1638. read_abstract_proc_def(calloption,procoptions);
  1639. if (po_has_mangledname in procoptions) then
  1640. writeln(space,' Mangled name : ',getstring);
  1641. writeln(space,' Number : ',getword);
  1642. writeln(space,' Level : ',getbyte);
  1643. write (space,' Class : ');
  1644. readderef;
  1645. write (space,' Procsym : ');
  1646. readderef;
  1647. write (space,' File Pos : ');
  1648. readposinfo;
  1649. write (space,' SymOptions : ');
  1650. readsymoptions;
  1651. if tsystemcpu(ppufile.header.cpu)=cpu_powerpc then
  1652. begin
  1653. { library symbol for AmigaOS/MorphOS }
  1654. write (space,' Library symbol : ');
  1655. readderef;
  1656. end;
  1657. if (po_has_importdll in procoptions) then
  1658. writeln(space,' Import DLL : ',getstring);
  1659. if (po_has_importname in procoptions) then
  1660. writeln(space,' Import Name : ',getstring);
  1661. writeln(space,' Import Nr : ',getword);
  1662. if (po_msgint in procoptions) then
  1663. writeln(space,' MsgInt : ',getlongint);
  1664. if (po_msgstr in procoptions) then
  1665. writeln(space,' MsgStr : ',getstring);
  1666. if (po_has_inlininginfo in procoptions) then
  1667. begin
  1668. write (space,' FuncretSym : ');
  1669. readderef;
  1670. ppufile.getsmallset(procinfooptions);
  1671. writeln(space,' ProcInfoOptions : ',dword(procinfooptions));
  1672. end;
  1673. if not EndOfEntry then
  1674. Writeln('!! Entry has more information stored');
  1675. space:=' '+space;
  1676. { parast }
  1677. readdefinitions('parast');
  1678. readsymbols('parast');
  1679. { localst }
  1680. if (po_has_inlininginfo in procoptions) then
  1681. begin
  1682. readdefinitions('localst');
  1683. readsymbols('localst');
  1684. end;
  1685. if (po_has_inlininginfo in procoptions) then
  1686. readnodetree;
  1687. delete(space,1,4);
  1688. end;
  1689. ibprocvardef :
  1690. begin
  1691. readcommondef('Procedural type (ProcVar) definition');
  1692. read_abstract_proc_def(calloption,procoptions);
  1693. if not EndOfEntry then
  1694. Writeln('!! Entry has more information stored');
  1695. space:=' '+space;
  1696. { parast }
  1697. readdefinitions('parast');
  1698. readsymbols('parast');
  1699. delete(space,1,4);
  1700. end;
  1701. ibshortstringdef :
  1702. begin
  1703. readcommondef('ShortString definition');
  1704. writeln(space,' Length : ',getbyte);
  1705. end;
  1706. ibwidestringdef :
  1707. begin
  1708. readcommondef('WideString definition');
  1709. writeln(space,' Length : ',getlongint);
  1710. end;
  1711. ibansistringdef :
  1712. begin
  1713. readcommondef('AnsiString definition');
  1714. writeln(space,' Length : ',getlongint);
  1715. end;
  1716. iblongstringdef :
  1717. begin
  1718. readcommondef('Longstring definition');
  1719. writeln(space,' Length : ',getlongint);
  1720. end;
  1721. ibrecorddef :
  1722. begin
  1723. readcommondef('Record definition');
  1724. writeln(space,' FieldAlign : ',getbyte);
  1725. writeln(space,' RecordAlign : ',getbyte);
  1726. writeln(space,' PadAlign : ',getbyte);
  1727. writeln(space,'UseFieldAlignment : ',getbyte);
  1728. writeln(space,' DataSize : ',getaint);
  1729. if not EndOfEntry then
  1730. Writeln('!! Entry has more information stored');
  1731. {read the record definitions and symbols}
  1732. space:=' '+space;
  1733. readdefinitions('fields');
  1734. readsymbols('fields');
  1735. Delete(space,1,4);
  1736. end;
  1737. ibobjectdef :
  1738. begin
  1739. readcommondef('Object/Class definition');
  1740. b:=getbyte;
  1741. write (space,' Type : ');
  1742. case tobjecttyp(b) of
  1743. odt_class : writeln('class');
  1744. odt_object : writeln('object');
  1745. odt_interfacecom : writeln('interfacecom');
  1746. odt_interfacecorba : writeln('interfacecorba');
  1747. odt_cppclass : writeln('cppclass');
  1748. else writeln('!! Warning: Invalid object type ',b);
  1749. end;
  1750. writeln(space,' Name of Class : ',getstring);
  1751. writeln(space,' DataSize : ',getaint);
  1752. writeln(space,' FieldAlign : ',getbyte);
  1753. writeln(space,' RecordAlign : ',getbyte);
  1754. writeln(space,' Vmt offset : ',getlongint);
  1755. write (space, ' Ancestor Class : ');
  1756. readderef;
  1757. write (space,' Options : ');
  1758. readobjectdefoptions;
  1759. if tobjecttyp(b) in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  1760. begin
  1761. { IIDGUID }
  1762. for j:=1to 16 do
  1763. getbyte;
  1764. writeln(space,' IID String : ',getstring);
  1765. writeln(space,' Last VTable idx : ',getlongint);
  1766. end;
  1767. if tobjecttyp(b) in [odt_class,odt_interfacecorba] then
  1768. begin
  1769. l:=getlongint;
  1770. writeln(space,' Impl Intf Count : ',l);
  1771. for j:=1 to l do
  1772. begin
  1773. write (space,' - Definition : ');
  1774. readderef;
  1775. writeln(space,' IOffset : ',getlongint);
  1776. end;
  1777. end;
  1778. if not EndOfEntry then
  1779. Writeln('!! Entry has more information stored');
  1780. {read the record definitions and symbols}
  1781. space:=' '+space;
  1782. readdefinitions('fields');
  1783. readsymbols('fields');
  1784. Delete(space,1,4);
  1785. end;
  1786. ibfiledef :
  1787. begin
  1788. ReadCommonDef('File definition');
  1789. write (space,' Type : ');
  1790. case getbyte of
  1791. 0 : writeln('Text');
  1792. 1 : begin
  1793. writeln('Typed');
  1794. write (space,' File of Type : ');
  1795. readderef;
  1796. end;
  1797. 2 : writeln('Untyped');
  1798. end;
  1799. end;
  1800. ibformaldef :
  1801. readcommondef('Generic definition (void-typ)');
  1802. ibundefineddef :
  1803. readcommondef('Undefined definition (generic parameter)');
  1804. ibenumdef :
  1805. begin
  1806. readcommondef('Enumeration type definition');
  1807. write(space,'Base enumeration type : ');
  1808. readderef;
  1809. writeln(space,' Smallest element : ',getaint);
  1810. writeln(space,' Largest element : ',getaint);
  1811. writeln(space,' Size : ',getaint);
  1812. end;
  1813. ibclassrefdef :
  1814. begin
  1815. readcommondef('Class reference definition');
  1816. write (space,' Pointed Type : ');
  1817. readderef;
  1818. end;
  1819. ibsetdef :
  1820. begin
  1821. readcommondef('Set definition');
  1822. write (space,' Element type : ');
  1823. readderef;
  1824. b:=getbyte;
  1825. // skip savesize
  1826. getaint;
  1827. case tsettype(b) of
  1828. smallset : write(space,' SmallSet');
  1829. normset : write(space,' NormalSet');
  1830. varset : write(space,' VarSet');
  1831. else writeln('!! Warning: Invalid set type ',b);
  1832. end;
  1833. // set base
  1834. l:=getaint;
  1835. // set max
  1836. j:=getaint;
  1837. writeln(' with ',j-l,' elements');
  1838. end;
  1839. ibvariantdef :
  1840. begin
  1841. readcommondef('Variant definition');
  1842. write (space,' Varianttype : ');
  1843. b:=getbyte;
  1844. case tvarianttype(b) of
  1845. vt_normalvariant :
  1846. writeln('Normal');
  1847. vt_olevariant :
  1848. writeln('OLE');
  1849. else
  1850. writeln('!! Warning: Invalid varianttype ',b);
  1851. end;
  1852. end;
  1853. iberror :
  1854. begin
  1855. Writeln('!! Error in PPU');
  1856. exit;
  1857. end;
  1858. ibenddefs :
  1859. break;
  1860. else
  1861. WriteLn('!! Skipping unsupported PPU Entry in definitions: ',b);
  1862. end;
  1863. if not EndOfEntry then
  1864. Writeln('!! Entry has more information stored');
  1865. until false;
  1866. end;
  1867. end;
  1868. {****************************************************************************
  1869. Read General Part
  1870. ****************************************************************************}
  1871. procedure readinterface;
  1872. var
  1873. b : byte;
  1874. sourcenumber : longint;
  1875. begin
  1876. with ppufile do
  1877. begin
  1878. repeat
  1879. b:=readentry;
  1880. case b of
  1881. ibmodulename :
  1882. Writeln('Module Name: ',getstring);
  1883. ibsourcefiles :
  1884. begin
  1885. sourcenumber:=1;
  1886. while not EndOfEntry do
  1887. begin
  1888. Writeln('Source file ',sourcenumber,' : ',getstring,' ',filetimestring(getlongint));
  1889. inc(sourcenumber);
  1890. end;
  1891. end;
  1892. {$IFDEF MACRO_DIFF_HINT}
  1893. ibusedmacros :
  1894. begin
  1895. while not EndOfEntry do
  1896. begin
  1897. Write('Conditional ',getstring);
  1898. b:=getbyte;
  1899. if boolean(b)=true then
  1900. write(' defined at startup')
  1901. else
  1902. write(' not defined at startup');
  1903. b:=getbyte;
  1904. if boolean(b)=true then
  1905. writeln(' was used')
  1906. else
  1907. writeln;
  1908. end;
  1909. end;
  1910. {$ENDIF}
  1911. ibloadunit :
  1912. ReadLoadUnit;
  1913. iblinkunitofiles :
  1914. ReadLinkContainer('Link unit object file: ');
  1915. iblinkunitstaticlibs :
  1916. ReadLinkContainer('Link unit static lib: ');
  1917. iblinkunitsharedlibs :
  1918. ReadLinkContainer('Link unit shared lib: ');
  1919. iblinkotherofiles :
  1920. ReadLinkContainer('Link other object file: ');
  1921. iblinkotherstaticlibs :
  1922. ReadLinkContainer('Link other static lib: ');
  1923. iblinkothersharedlibs :
  1924. ReadLinkContainer('Link other shared lib: ');
  1925. ibImportSymbols :
  1926. ReadImportSymbols;
  1927. ibderefdata :
  1928. ReadDerefData;
  1929. ibderefmap :
  1930. ReadDerefMap;
  1931. iberror :
  1932. begin
  1933. Writeln('Error in PPU');
  1934. exit;
  1935. end;
  1936. ibendinterface :
  1937. break;
  1938. else
  1939. WriteLn('!! Skipping unsupported PPU Entry in General Part: ',b);
  1940. end;
  1941. until false;
  1942. end;
  1943. end;
  1944. {****************************************************************************
  1945. Read Implementation Part
  1946. ****************************************************************************}
  1947. procedure readimplementation;
  1948. var
  1949. b : byte;
  1950. begin
  1951. with ppufile do
  1952. begin
  1953. repeat
  1954. b:=readentry;
  1955. case b of
  1956. ibasmsymbols :
  1957. ReadAsmSymbols;
  1958. ibloadunit :
  1959. ReadLoadUnit;
  1960. iberror :
  1961. begin
  1962. Writeln('Error in PPU');
  1963. exit;
  1964. end;
  1965. ibendimplementation :
  1966. break;
  1967. else
  1968. WriteLn('!! Skipping unsupported PPU Entry in Implementation: ',b);
  1969. end;
  1970. until false;
  1971. end;
  1972. end;
  1973. procedure dofile (filename : string);
  1974. begin
  1975. { reset }
  1976. space:='';
  1977. { fix filename }
  1978. if pos('.',filename)=0 then
  1979. filename:=filename+'.ppu';
  1980. ppufile:=tppufile.create(filename);
  1981. if not ppufile.openfile then
  1982. begin
  1983. writeln ('IO-Error when opening : ',filename,', Skipping');
  1984. exit;
  1985. end;
  1986. { PPU File is open, check for PPU Id }
  1987. if not ppufile.CheckPPUID then
  1988. begin
  1989. writeln(Filename,' : Not a valid PPU file, Skipping');
  1990. exit;
  1991. end;
  1992. { Check PPU Version }
  1993. Writeln('Analyzing ',filename,' (v',ppufile.GetPPUVersion,')');
  1994. if ppufile.GetPPUVersion<16 then
  1995. begin
  1996. writeln(Filename,' : Old PPU Formats (<v16) are not supported, Skipping');
  1997. exit;
  1998. end;
  1999. { Write PPU Header Information }
  2000. if (verbose and v_header)<>0 then
  2001. begin
  2002. Writeln;
  2003. Writeln('Header');
  2004. Writeln('-------');
  2005. with ppufile.header do
  2006. begin
  2007. Writeln('Compiler version : ',ppufile.header.compiler shr 14,'.',
  2008. (ppufile.header.compiler shr 7) and $7f,'.',
  2009. ppufile.header.compiler and $7f);
  2010. WriteLn('Target processor : ',Cpu2Str(cpu));
  2011. WriteLn('Target operating system : ',Target2Str(target));
  2012. Writeln('Unit flags : ',PPUFlags2Str(flags));
  2013. Writeln('FileSize (w/o header) : ',size);
  2014. Writeln('Checksum : ',hexstr(checksum,8));
  2015. Writeln('Interface Checksum : ',hexstr(interface_checksum,8));
  2016. Writeln('Definitions stored : ',tostr(deflistsize));
  2017. Writeln('Symbols stored : ',tostr(symlistsize));
  2018. end;
  2019. end;
  2020. {read the general stuff}
  2021. if (verbose and v_interface)<>0 then
  2022. begin
  2023. Writeln;
  2024. Writeln('Interface section');
  2025. Writeln('------------------');
  2026. readinterface;
  2027. end
  2028. else
  2029. ppufile.skipuntilentry(ibendinterface);
  2030. {read the definitions}
  2031. if (verbose and v_defs)<>0 then
  2032. begin
  2033. Writeln;
  2034. Writeln('Interface definitions');
  2035. Writeln('----------------------');
  2036. readdefinitions('interface');
  2037. end
  2038. else
  2039. ppufile.skipuntilentry(ibenddefs);
  2040. {read the symbols}
  2041. if (verbose and v_syms)<>0 then
  2042. begin
  2043. Writeln;
  2044. Writeln('Interface Symbols');
  2045. Writeln('------------------');
  2046. readsymbols('interface');
  2047. end
  2048. else
  2049. ppufile.skipuntilentry(ibendsyms);
  2050. {read the macro symbols}
  2051. if (verbose and v_syms)<>0 then
  2052. begin
  2053. Writeln;
  2054. Writeln('Interface Macro Symbols');
  2055. Writeln('-----------------------');
  2056. end;
  2057. if ppufile.readentry<>ibexportedmacros then
  2058. begin
  2059. Writeln('!! Error in PPU');
  2060. exit;
  2061. end;
  2062. if boolean(ppufile.getbyte) then
  2063. begin
  2064. {skip the definition section for macros (since they are never used) }
  2065. ppufile.skipuntilentry(ibenddefs);
  2066. {read the macro symbols}
  2067. if (verbose and v_syms)<>0 then
  2068. readsymbols('interface macro')
  2069. else
  2070. ppufile.skipuntilentry(ibendsyms);
  2071. end
  2072. else
  2073. Writeln('(no exported macros)');
  2074. {read the implementation stuff}
  2075. if (verbose and v_implementation)<>0 then
  2076. begin
  2077. Writeln;
  2078. Writeln('Implementation section');
  2079. Writeln('-----------------------');
  2080. readimplementation;
  2081. end
  2082. else
  2083. ppufile.skipuntilentry(ibendimplementation);
  2084. {read the static symtable}
  2085. if (ppufile.header.flags and uf_local_symtable)<>0 then
  2086. begin
  2087. if (verbose and v_defs)<>0 then
  2088. begin
  2089. Writeln;
  2090. Writeln('Static definitions');
  2091. Writeln('----------------------');
  2092. readdefinitions('implementation');
  2093. end
  2094. else
  2095. ppufile.skipuntilentry(ibenddefs);
  2096. {read the symbols}
  2097. if (verbose and v_syms)<>0 then
  2098. begin
  2099. Writeln;
  2100. Writeln('Static Symbols');
  2101. Writeln('------------------');
  2102. readsymbols('implementation');
  2103. end
  2104. else
  2105. ppufile.skipuntilentry(ibendsyms);
  2106. end;
  2107. {shutdown ppufile}
  2108. ppufile.closefile;
  2109. ppufile.free;
  2110. Writeln;
  2111. end;
  2112. procedure help;
  2113. begin
  2114. writeln('usage: ppudump [options] <filename1> <filename2>...');
  2115. writeln;
  2116. writeln('[options] can be:');
  2117. writeln(' -V<verbose> Set verbosity to <verbose>');
  2118. writeln(' H - Show header info');
  2119. writeln(' I - Show interface');
  2120. writeln(' M - Show implementation');
  2121. writeln(' S - Show interface symbols');
  2122. writeln(' D - Show interface definitions');
  2123. // writeln(' B - Show browser info');
  2124. writeln(' A - Show all');
  2125. writeln(' -h, -? This helpscreen');
  2126. halt;
  2127. end;
  2128. var
  2129. startpara,
  2130. nrfile,i : longint;
  2131. para : string;
  2132. begin
  2133. writeln(Title+' '+Version);
  2134. writeln(Copyright);
  2135. writeln;
  2136. if paramcount<1 then
  2137. begin
  2138. writeln('usage: dumpppu [options] <filename1> <filename2>...');
  2139. halt(1);
  2140. end;
  2141. { turn verbose on by default }
  2142. verbose:=v_all;
  2143. { read options }
  2144. startpara:=1;
  2145. while copy(paramstr(startpara),1,1)='-' do
  2146. begin
  2147. para:=paramstr(startpara);
  2148. case upcase(para[2]) of
  2149. 'V' : begin
  2150. verbose:=0;
  2151. for i:=3 to length(para) do
  2152. case upcase(para[i]) of
  2153. 'H' : verbose:=verbose or v_header;
  2154. 'I' : verbose:=verbose or v_interface;
  2155. 'M' : verbose:=verbose or v_implementation;
  2156. 'D' : verbose:=verbose or v_defs;
  2157. 'S' : verbose:=verbose or v_syms;
  2158. 'A' : verbose:=verbose or v_all;
  2159. end;
  2160. end;
  2161. 'H' : help;
  2162. '?' : help;
  2163. end;
  2164. inc(startpara);
  2165. end;
  2166. { process files }
  2167. for nrfile:=startpara to paramcount do
  2168. dofile (paramstr(nrfile));
  2169. if has_errors then
  2170. Halt(1);
  2171. end.