ppudump.pp 67 KB

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