ppudump.pp 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607
  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. program ppudump;
  17. {$mode objfpc}
  18. {$H+}
  19. {$define IN_PPUDUMP}
  20. uses
  21. { do NOT add symconst or globtype to make merging easier }
  22. { do include symconst and globtype now before splitting 2.5 PM 2011-06-15 }
  23. SysUtils,
  24. constexp,
  25. symconst,
  26. ppu,
  27. globals,
  28. globtype,
  29. widestr,
  30. tokens;
  31. const
  32. Version = 'Version 2.5.1';
  33. Title = 'PPU-Analyser';
  34. Copyright = 'Copyright (c) 1998-2010 by the Free Pascal Development Team';
  35. { verbosity }
  36. v_none = $0;
  37. v_header = $1;
  38. v_defs = $2;
  39. v_syms = $4;
  40. v_interface = $8;
  41. v_implementation = $10;
  42. // v_browser = $20;
  43. v_all = $ff;
  44. {$i systems.inc }
  45. { List of all supported cpus }
  46. const
  47. CpuTxt : array[tsystemcpu] of string[9]=
  48. (
  49. { 0 } 'none',
  50. { 1 } 'i386',
  51. { 2 } 'm68k',
  52. { 3 } 'alpha',
  53. { 4 } 'powerpc',
  54. { 5 } 'sparc',
  55. { 6 } 'vis',
  56. { 7 } 'ia64',
  57. { 8 } 'x86_64',
  58. { 9 } 'mips',
  59. { 10 } 'arm',
  60. { 11 } 'powerpc64',
  61. { 12 } 'avr',
  62. { 13 } 'mipsel'
  63. );
  64. { List of all supported system-cpu couples }
  65. const
  66. Targets : array[tsystem] of string[18]=(
  67. { 0 } 'none',
  68. { 1 } 'GO32V1 (obsolete)',
  69. { 2 } 'GO32V2',
  70. { 3 } 'Linux-i386',
  71. { 4 } 'OS/2',
  72. { 5 } 'Win32',
  73. { 6 } 'FreeBSD-i386',
  74. { 7 } 'Amiga',
  75. { 8 } 'Atari',
  76. { 9 } 'MacOS-m68k',
  77. { 10 } 'Linux-m68k',
  78. { 11 } 'PalmOS-m68k',
  79. { 12 } 'Linux-alpha',
  80. { 13 } 'Linux-ppc',
  81. { 14 } 'MacOS-ppc',
  82. { 15 } 'Solaris-i386',
  83. { 16 } 'BeOS-i386',
  84. { 17 } 'NetBSD-i386',
  85. { 18 } 'NetBSD-m68k',
  86. { 19 } 'Netware-i386-clib',
  87. { 20 } 'Qnx-i386',
  88. { 21 } 'WDOSX-i386',
  89. { 22 } 'Solaris-sparc',
  90. { 23 } 'Linux-sparc',
  91. { 24 } 'OpenBSD-i386',
  92. { 25 } 'OpenBSD-m68k',
  93. { 26 } 'Linux-x86-64',
  94. { 27 } 'MacOSX-ppc',
  95. { 28 } 'OS/2 via EMX',
  96. { 29 } 'NetBSD-powerpc',
  97. { 30 } 'OpenBSD-powerpc',
  98. { 31 } 'Linux-arm',
  99. { 32 } 'Watcom-i386',
  100. { 33 } 'MorphOS-powerpc',
  101. { 34 } 'FreeBSD-x86-64',
  102. { 35 } 'Netware-i386-libc',
  103. { 36 } 'Amiga-PowerPC',
  104. { 37 } 'Win64-x64',
  105. { 38 } 'WinCE-ARM',
  106. { 39 } 'Win64-iA64',
  107. { 40 } 'WinCE-i386',
  108. { 41 } 'Linux-x64',
  109. { 42 } 'GBA-arm',
  110. { 43 } 'Linux-powerpc64',
  111. { 44 } 'Darwin-i386',
  112. { 45 } 'PalmOS-arm',
  113. { 46 } 'MacOSX-powerpc64',
  114. { 47 } 'NDS-arm',
  115. { 48 } 'Embedded-i386',
  116. { 49 } 'Embedded-m68k',
  117. { 50 } 'Embedded-alpha',
  118. { 51 } 'Embedded-powerpc',
  119. { 52 } 'Embedded-sparc',
  120. { 53 } 'Embedded-vm',
  121. { 54 } 'Embedded-iA64',
  122. { 55 } 'Embedded-x64',
  123. { 56 } 'Embedded-mips',
  124. { 57 } 'Embedded-arm',
  125. { 58 } 'Embedded-powerpc64',
  126. { 59 } 'Symbian-i386',
  127. { 60 } 'Symbian-arm',
  128. { 61 } 'MacOSX-x64',
  129. { 62 } 'Embedded-avr',
  130. { 63 } 'Haiku-i386',
  131. { 64 } 'Darwin-ARM',
  132. { 65 } 'Solaris-x86-64',
  133. { 66 } 'Linux-MIPS',
  134. { 67 } 'Linux-MIPSel',
  135. { 68 } 'NativeNT-i386',
  136. { 69 } 'iPhoneSim-i386',
  137. { 70 } 'Wii-powerpc'
  138. );
  139. const
  140. { in widestr, we have the following definition
  141. type
  142. tcompilerwidechar = word;
  143. thus widecharsize seems to always be 2 bytes }
  144. widecharsize : longint = 2;
  145. type
  146. tspecialgenerictoken = (ST_LOADSETTINGS,ST_LINE,ST_COLUMN,ST_FILEINDEX);
  147. var
  148. ppufile : tppufile;
  149. ppuversion : dword;
  150. space : string;
  151. verbose : longint;
  152. derefdata : pbyte;
  153. derefdatalen : longint;
  154. {****************************************************************************
  155. Helper Routines
  156. ****************************************************************************}
  157. const has_errors : boolean = false;
  158. has_more_infos : boolean = false;
  159. Procedure HasMoreInfos;
  160. begin
  161. Writeln('!! Entry has more information stored');
  162. has_more_infos:=true;
  163. end;
  164. Procedure WriteError(const S : string);
  165. Begin
  166. Writeln(S);
  167. has_errors:=true;
  168. End;
  169. function Unknown(const st : string; val :longint) : string;
  170. Begin
  171. Unknown:='<!! Unknown'+st+' value '+tostr(val)+'>';
  172. has_errors:=true;
  173. end;
  174. function ToStr(w:longint):String;
  175. begin
  176. Str(w,ToStr);
  177. end;
  178. Function Target2Str(w:longint):string;
  179. begin
  180. if w<=ord(high(tsystem)) then
  181. Target2Str:=Targets[tsystem(w)]
  182. else
  183. Target2Str:=Unknown('target',w);
  184. end;
  185. Function Cpu2Str(w:longint):string;
  186. begin
  187. if w<=ord(high(tsystemcpu)) then
  188. Cpu2Str:=CpuTxt[tsystemcpu(w)]
  189. else
  190. Cpu2Str:=Unknown('cpu',w);
  191. end;
  192. Function Varspez2Str(w:longint):string;
  193. const
  194. { in symconst unit
  195. tvarspez = (vs_value,vs_const,vs_var,vs_out,vs_constref); }
  196. varspezstr : array[tvarspez] of string[6]=('Value','Const','Var','Out','Hidden');
  197. begin
  198. if w<=ord(high(varspezstr)) then
  199. Varspez2Str:=varspezstr[tvarspez(w)]
  200. else
  201. Varspez2Str:=Unknown('varspez',w);
  202. end;
  203. Function VarRegable2Str(w:longint):string;
  204. { tvarregable type is defined in symconst unit }
  205. const
  206. varregableStr : array[tvarregable] of string[6]=('None','IntReg','FPUReg','MMReg','Addr');
  207. begin
  208. if w<=ord(high(varregablestr)) then
  209. Varregable2Str:=varregablestr[tvarregable(w)]
  210. else
  211. Varregable2Str:=Unknown('regable',w);
  212. end;
  213. Function Visibility2Str(w:longint):string;
  214. const
  215. { tvisibility type is defined in symconst unit }
  216. visibilityName : array[tvisibility] of string[16] = (
  217. 'hidden','strict private','private','strict protected','protected',
  218. 'public','published'
  219. );
  220. begin
  221. if w<=ord(high(visibilityName)) then
  222. result:=visibilityName[tvisibility(w)]
  223. else
  224. result:=Unknown('visibility',w);
  225. end;
  226. function PPUFlags2Str(flags:longint):string;
  227. type
  228. tflagopt=record
  229. mask : longint;
  230. str : string[30];
  231. end;
  232. const
  233. flagopts=23;
  234. flagopt : array[1..flagopts] of tflagopt=(
  235. (mask: $1 ;str:'init'),
  236. (mask: $2 ;str:'final'),
  237. (mask: $4 ;str:'big_endian'),
  238. (mask: $8 ;str:'dbx'),
  239. // (mask: $10 ;str:'browser'),
  240. (mask: $20 ;str:'in_library'),
  241. (mask: $40 ;str:'smart_linked'),
  242. (mask: $80 ;str:'static_linked'),
  243. (mask: $100 ;str:'shared_linked'),
  244. // (mask: $200 ;str:'local_browser'),
  245. (mask: $400 ;str:'no_link'),
  246. (mask: $800 ;str:'has_resources'),
  247. (mask: $1000 ;str:'little_endian'),
  248. (mask: $2000 ;str:'release'),
  249. (mask: $4000 ;str:'local_threadvars'),
  250. (mask: $8000 ;str:'fpu_emulation_on'),
  251. (mask: $210000 ;str:'has_debug_info'),
  252. (mask: $10000 ;str:'stabs_debug_info'),
  253. (mask: $200000 ;str:'dwarf_debug_info'),
  254. (mask: $20000 ;str:'local_symtable'),
  255. (mask: $40000 ;str:'uses_variants'),
  256. (mask: $80000 ;str:'has_resourcefiles'),
  257. (mask: $100000 ;str:'has_exports'),
  258. (mask: $400000 ;str:'has_wideinits'),
  259. (mask: $800000 ;str:'has_classinits')
  260. );
  261. var
  262. i,ntflags : longint;
  263. first : boolean;
  264. s : string;
  265. begin
  266. s:='';
  267. if flags<>0 then
  268. begin
  269. ntflags:=flags;
  270. first:=true;
  271. for i:=1to flagopts do
  272. if (flags and flagopt[i].mask)<>0 then
  273. begin
  274. if first then
  275. first:=false
  276. else
  277. s:=s+', ';
  278. s:=s+flagopt[i].str;
  279. ntflags:=ntflags and (not flagopt[i].mask);
  280. end;
  281. end
  282. else
  283. s:='none';
  284. if ntflags<>0 then
  285. begin
  286. s:=s+' unknown '+hexstr(ntflags,8);
  287. has_errors:=true;
  288. end;
  289. PPUFlags2Str:=s;
  290. end;
  291. Function L0(l:longint):string;
  292. {
  293. return the string of value l, if l<10 then insert a zero, so
  294. the string is always at least 2 chars '01','02',etc
  295. }
  296. var
  297. s : string;
  298. begin
  299. Str(l,s);
  300. if l<10 then
  301. s:='0'+s;
  302. L0:=s;
  303. end;
  304. function filetimestring( t : longint) : string;
  305. {
  306. convert dos datetime t to a string YY/MM/DD HH:MM:SS
  307. }
  308. var
  309. DT : TDateTime;
  310. hsec : word;
  311. Year,Month,Day: Word;
  312. hour,min,sec : word;
  313. begin
  314. if t=-1 then
  315. begin
  316. Result := 'Not Found';
  317. has_errors:=true;
  318. exit;
  319. end;
  320. DT := FileDateToDateTime(t);
  321. DecodeTime(DT,hour,min,sec,hsec);
  322. DecodeDate(DT,year,month,day);
  323. Result := L0(Year)+'/'+L0(Month)+'/'+L0(Day)+' '+L0(Hour)+':'+L0(min)+':'+L0(sec);
  324. end;
  325. {****************************************************************************
  326. Read Routines
  327. ****************************************************************************}
  328. procedure readrecsymtableoptions;
  329. var
  330. usefieldalignment : shortint;
  331. begin
  332. if ppufile.readentry<>ibrecsymtableoptions then
  333. begin
  334. has_errors:=true;
  335. exit;
  336. end;
  337. writeln(space,' recordalignment: ',shortint(ppufile.getbyte));
  338. usefieldalignment:=shortint(ppufile.getbyte);
  339. writeln(space,' usefieldalignment: ',usefieldalignment);
  340. if (usefieldalignment=C_alignment) then
  341. writeln(space,' fieldalignment: ',shortint(ppufile.getbyte));
  342. end;
  343. procedure readsymtableoptions(const s: string);
  344. type
  345. tsymtblopt=record
  346. mask : tsymtableoption;
  347. str : string[30];
  348. end;
  349. const
  350. symtblopts=ord(high(tsymtableoption)) + 1;
  351. symtblopt : array[1..symtblopts] of tsymtblopt=(
  352. (mask:sto_has_helper; str:'Has helper')
  353. );
  354. var
  355. options : tsymtableoptions;
  356. first : boolean;
  357. i : integer;
  358. begin
  359. if ppufile.readentry<>ibsymtableoptions then
  360. begin
  361. has_errors:=true;
  362. exit;
  363. end;
  364. ppufile.getsmallset(options);
  365. if space<>'' then
  366. writeln(space,'------ ',s,' ------');
  367. write(space,'Symtable options: ');
  368. if options<>[] then
  369. begin
  370. first:=true;
  371. for i:=1 to symtblopts do
  372. if (symtblopt[i].mask in options) then
  373. begin
  374. if first then
  375. first:=false
  376. else
  377. write(', ');
  378. write(symtblopt[i].str);
  379. end;
  380. end
  381. else
  382. write('none');
  383. writeln;
  384. end;
  385. Procedure ReadLinkContainer(const prefix:string);
  386. {
  387. Read a serie of strings and write to the screen starting every line
  388. with prefix
  389. }
  390. function maskstr(m:longint):string;
  391. { link options are in globtype unit
  392. const
  393. link_none = $0;
  394. link_always = $1;
  395. link_static = $2;
  396. link_smart = $4;
  397. link_shared = $8; }
  398. var
  399. s : string;
  400. begin
  401. s:='';
  402. if (m and link_always)<>0 then
  403. s:=s+'always ';
  404. if (m and link_static)<>0 then
  405. s:=s+'static ';
  406. if (m and link_smart)<>0 then
  407. s:=s+'smart ';
  408. if (m and link_shared)<>0 then
  409. s:=s+'shared ';
  410. maskstr:=s;
  411. end;
  412. var
  413. s : string;
  414. m : longint;
  415. begin
  416. while not ppufile.endofentry do
  417. begin
  418. s:=ppufile.getstring;
  419. m:=ppufile.getlongint;
  420. WriteLn(prefix,s,' (',maskstr(m),')');
  421. end;
  422. end;
  423. Procedure ReadContainer(const prefix:string);
  424. {
  425. Read a serie of strings and write to the screen starting every line
  426. with prefix
  427. }
  428. begin
  429. while not ppufile.endofentry do
  430. WriteLn(prefix,ppufile.getstring);
  431. end;
  432. procedure ReadLoadUnit;
  433. var
  434. ucrc,uintfcrc, indcrc : cardinal;
  435. begin
  436. while not ppufile.EndOfEntry do
  437. begin
  438. write('Uses unit: ',ppufile.getstring);
  439. ucrc:=cardinal(ppufile.getlongint);
  440. uintfcrc:=cardinal(ppufile.getlongint);
  441. indcrc:=cardinal(ppufile.getlongint);
  442. writeln(' (Crc: ',hexstr(ucrc,8),', IntfcCrc: ',hexstr(uintfcrc,8),', IndCrc: ',hexstr(indcrc,8),')');
  443. end;
  444. end;
  445. Procedure ReadDerefmap;
  446. var
  447. i,mapsize : longint;
  448. begin
  449. mapsize:=ppufile.getlongint;
  450. writeln('DerefMapsize: ',mapsize);
  451. for i:=0 to mapsize-1 do
  452. writeln('DerefMap[',i,'] = ',ppufile.getstring);
  453. end;
  454. Procedure ReadImportSymbols;
  455. var
  456. extlibname : string;
  457. j,
  458. extsymcnt : longint;
  459. extsymname : string;
  460. extsymmangledname : string;
  461. extsymordnr : longint;
  462. extsymisvar : boolean;
  463. begin
  464. while not ppufile.endofentry do
  465. begin
  466. extlibname:=ppufile.getstring;
  467. extsymcnt:=ppufile.getlongint;
  468. writeln('External Library: ',extlibname,' (',extsymcnt,' imports)');
  469. for j:=0 to extsymcnt-1 do
  470. begin
  471. extsymname:=ppufile.getstring;
  472. if ppuversion>130 then
  473. extsymmangledname:=ppufile.getstring
  474. else
  475. extsymmangledname:=extsymname;
  476. extsymordnr:=ppufile.getlongint;
  477. extsymisvar:=ppufile.getbyte<>0;
  478. writeln(' ',extsymname,' as ',extsymmangledname,
  479. '(OrdNr: ',extsymordnr,' IsVar: ',extsymisvar,')');
  480. end;
  481. end;
  482. end;
  483. Procedure ReadDerefdata;
  484. begin
  485. derefdatalen:=ppufile.entrysize;
  486. if derefdatalen=0 then
  487. begin
  488. WriteError('!! Error: derefdatalen=0');
  489. exit;
  490. end;
  491. Writeln('Derefdata length: ',derefdatalen);
  492. derefdata:=allocmem(derefdatalen);
  493. ppufile.getdata(derefdata^,derefdatalen);
  494. end;
  495. Procedure FreeDerefdata;
  496. begin
  497. if assigned(derefdata) then
  498. begin
  499. FreeMem(derefdata);
  500. derefdata:=nil;
  501. derefdatalen:=0;
  502. end;
  503. end;
  504. Procedure ReadWpoFileInfo;
  505. begin
  506. Writeln('Compiled with input whole-program optimisation from ',ppufile.getstring,' ',filetimestring(ppufile.getlongint));
  507. end;
  508. Procedure ReadAsmSymbols;
  509. type
  510. { Copied from aasmbase.pas }
  511. TAsmsymbind=(
  512. AB_NONE,AB_EXTERNAL,AB_COMMON,AB_LOCAL,AB_GLOBAL,AB_WEAK_EXTERNAL,
  513. { global in the current program/library, but not visible outside it }
  514. AB_PRIVATE_EXTERN,AB_LAZY,AB_IMPORT);
  515. TAsmsymtype=(
  516. AT_NONE,AT_FUNCTION,AT_DATA,AT_SECTION,AT_LABEL,
  517. {
  518. the address of this code label is taken somewhere in the code
  519. so it must be taken care of it when creating pic
  520. }
  521. AT_ADDR
  522. );
  523. var
  524. s,
  525. bindstr,
  526. typestr : string;
  527. i : longint;
  528. begin
  529. writeln(space,'Number of AsmSymbols: ',ppufile.getlongint);
  530. i:=0;
  531. while (not ppufile.endofentry) and (not ppufile.error) do
  532. begin
  533. s:=ppufile.getstring;
  534. case tasmsymbind(ppufile.getbyte) of
  535. AB_EXTERNAL :
  536. bindstr:='External';
  537. AB_COMMON :
  538. bindstr:='Common';
  539. AB_LOCAL :
  540. bindstr:='Local';
  541. AB_GLOBAL :
  542. bindstr:='Global';
  543. AB_WEAK_EXTERNAL :
  544. bindstr:='Weak external';
  545. AB_PRIVATE_EXTERN :
  546. bindstr:='Private extern';
  547. AB_LAZY :
  548. bindstr:='Lazy';
  549. AB_IMPORT :
  550. bindstr:='Import';
  551. else
  552. begin
  553. bindstr:='<Error !!>';
  554. has_errors:=true;
  555. end;
  556. end;
  557. case tasmsymtype(ppufile.getbyte) of
  558. AT_FUNCTION :
  559. typestr:='Function';
  560. AT_DATA :
  561. typestr:='Data';
  562. AT_SECTION :
  563. typestr:='Section';
  564. AT_LABEL :
  565. typestr:='Label';
  566. AT_ADDR :
  567. typestr:='Label (with address taken)';
  568. else
  569. begin
  570. typestr:='<Error !!>';
  571. has_errors:=true;
  572. end;
  573. end;
  574. Writeln(space,' ',i,' : ',s,' [',bindstr,',',typestr,']');
  575. inc(i);
  576. end;
  577. end;
  578. function getexprint:Tconstexprint;
  579. begin
  580. getexprint.overflow:=false;
  581. getexprint.signed:=boolean(ppufile.getbyte);
  582. getexprint.svalue:=ppufile.getint64;
  583. end;
  584. Procedure ReadPosInfo;
  585. var
  586. info : byte;
  587. fileindex,line,column : longint;
  588. begin
  589. with ppufile do
  590. begin
  591. {
  592. info byte layout in bits:
  593. 0-1 - amount of bytes for fileindex
  594. 2-3 - amount of bytes for line
  595. 4-5 - amount of bytes for column
  596. }
  597. info:=getbyte;
  598. case (info and $03) of
  599. 0 : fileindex:=getbyte;
  600. 1 : fileindex:=getword;
  601. 2 : fileindex:=(getbyte shl 16) or getword;
  602. 3 : fileindex:=getlongint;
  603. end;
  604. case ((info shr 2) and $03) of
  605. 0 : line:=getbyte;
  606. 1 : line:=getword;
  607. 2 : line:=(getbyte shl 16) or getword;
  608. 3 : line:=getlongint;
  609. end;
  610. case ((info shr 4) and $03) of
  611. 0 : column:=getbyte;
  612. 1 : column:=getword;
  613. 2 : column:=(getbyte shl 16) or getword;
  614. 3 : column:=getlongint;
  615. end;
  616. Writeln(fileindex,' (',line,',',column,')');
  617. end;
  618. end;
  619. procedure readderef(const derefspace: string);
  620. var
  621. b : tdereftype;
  622. first : boolean;
  623. idx : longint;
  624. i,n : byte;
  625. pdata : pbyte;
  626. begin
  627. if not assigned(derefdata) then
  628. exit;
  629. first:=true;
  630. idx:=ppufile.getlongint;
  631. if (idx>derefdatalen) then
  632. begin
  633. writeln('!! Error: Deref idx ',idx,' > ',derefdatalen);
  634. has_errors:=true;
  635. exit;
  636. end;
  637. write(derefspace,'(',idx,') ');
  638. pdata:=@derefdata[idx];
  639. i:=0;
  640. n:=pdata[i];
  641. inc(i);
  642. if n<1 then
  643. begin
  644. WriteError('!! Error: Deref len < 1');
  645. exit;
  646. end;
  647. while (i<=n) do
  648. begin
  649. if not first then
  650. write(', ')
  651. else
  652. first:=false;
  653. b:=tdereftype(pdata[i]);
  654. inc(i);
  655. case b of
  656. deref_nil :
  657. write('Nil');
  658. deref_symid :
  659. begin
  660. idx:=pdata[i] shl 24 or pdata[i+1] shl 16 or pdata[i+2] shl 8 or pdata[i+3];
  661. inc(i,4);
  662. write('SymId ',idx);
  663. end;
  664. deref_defid :
  665. begin
  666. idx:=pdata[i] shl 24 or pdata[i+1] shl 16 or pdata[i+2] shl 8 or pdata[i+3];
  667. inc(i,4);
  668. write('DefId ',idx);
  669. end;
  670. deref_unit :
  671. begin
  672. idx:=pdata[i] shl 8 or pdata[i+1];
  673. inc(i,2);
  674. write('Unit ',idx);
  675. end;
  676. else
  677. begin
  678. writeln('!! unsupported dereftyp: ',ord(b));
  679. has_errors:=true;
  680. break;
  681. end;
  682. end;
  683. end;
  684. writeln;
  685. end;
  686. procedure readpropaccesslist(const s:string);
  687. { type tsltype is in symconst unit }
  688. const
  689. slstr : array[tsltype] of string[12] = (
  690. '',
  691. 'load',
  692. 'call',
  693. 'subscript',
  694. 'vec',
  695. 'typeconv',
  696. 'absolutetype'
  697. );
  698. var
  699. sl : tsltype;
  700. begin
  701. readderef('');
  702. repeat
  703. sl:=tsltype(ppufile.getbyte);
  704. if sl=sl_none then
  705. break;
  706. write(s,'(',slstr[sl],') ');
  707. case sl of
  708. sl_call,
  709. sl_load,
  710. sl_subscript :
  711. readderef('');
  712. sl_absolutetype,
  713. sl_typeconv :
  714. readderef('');
  715. sl_vec :
  716. begin
  717. writeln(ppufile.getlongint);
  718. readderef('');
  719. end;
  720. end;
  721. until false;
  722. end;
  723. procedure readsymoptions(space : string);
  724. type
  725. tsymopt=record
  726. mask : tsymoption;
  727. str : string[30];
  728. end;
  729. const
  730. symopts=ord(high(tsymoption)) - ord(low(tsymoption));
  731. { sp_none = 0 corresponds to nothing }
  732. symopt : array[1..symopts] of tsymopt=(
  733. (mask:sp_static; str:'Static'),
  734. (mask:sp_hint_deprecated; str:'Hint Deprecated'),
  735. (mask:sp_hint_platform; str:'Hint Platform'),
  736. (mask:sp_hint_library; str:'Hint Library'),
  737. (mask:sp_hint_unimplemented; str:'Hint Unimplemented'),
  738. (mask:sp_hint_experimental; str:'Hint Experimental'),
  739. (mask:sp_has_overloaded; str:'Has overloaded'),
  740. (mask:sp_internal; str:'Internal'),
  741. (mask:sp_implicitrename; str:'Implicit Rename'),
  742. (mask:sp_generic_para; str:'Generic Parameter'),
  743. (mask:sp_has_deprecated_msg; str:'Has Deprecated Message')
  744. );
  745. var
  746. symoptions : tsymoptions;
  747. i : longint;
  748. first : boolean;
  749. begin
  750. ppufile.getsmallset(symoptions);
  751. if symoptions<>[] then
  752. begin
  753. first:=true;
  754. for i:=1to symopts do
  755. if (symopt[i].mask in symoptions) then
  756. begin
  757. if first then
  758. first:=false
  759. else
  760. write(', ');
  761. write(symopt[i].str);
  762. end;
  763. end;
  764. writeln;
  765. if sp_has_deprecated_msg in symoptions then
  766. writeln(space,'Deprecated : ', ppufile.getstring);
  767. end;
  768. procedure readcommonsym(const s:string);
  769. begin
  770. writeln(space,'** Symbol Id ',ppufile.getlongint,' **');
  771. writeln(space,s,ppufile.getstring);
  772. write (space,' File Pos : ');
  773. readposinfo;
  774. writeln(space,' Visibility : ',Visibility2Str(ppufile.getbyte));
  775. write (space,' SymOptions : ');
  776. readsymoptions(space+' ');
  777. end;
  778. var
  779. { needed during tobjectdef parsing... }
  780. current_defoptions : tdefoptions;
  781. current_objectoptions : tobjectoptions;
  782. procedure readcommondef(const s:string; out defoptions: tdefoptions);
  783. type
  784. tdefopt=record
  785. mask : tdefoption;
  786. str : string[30];
  787. end;
  788. tdefstateinfo=record
  789. mask : tdefstate;
  790. str : string[30];
  791. end;
  792. ptoken=^ttoken;
  793. const
  794. defopt : array[1..ord(high(tdefoption))] of tdefopt=(
  795. (mask:df_unique; str:'Unique Type'),
  796. (mask:df_generic; str:'Generic'),
  797. (mask:df_specialization; str:'Specialization'),
  798. (mask:df_copied_def; str:'Copied Typedef')
  799. );
  800. defstate : array[1..ord(high(tdefstate))] of tdefstateinfo=(
  801. (mask:ds_vmt_written; str:'VMT Written'),
  802. (mask:ds_rtti_table_used; str:'RTTITable Used'),
  803. (mask:ds_init_table_used; str:'InitTable Used'),
  804. (mask:ds_rtti_table_written; str:'RTTITable Written'),
  805. (mask:ds_init_table_written; str:'InitTable Written'),
  806. (mask:ds_dwarf_dbg_info_used; str:'Dwarf DbgInfo Used'),
  807. (mask:ds_dwarf_dbg_info_written;str:'Dwarf DbgInfo Written')
  808. );
  809. var
  810. defstates : tdefstates;
  811. i : longint;
  812. first : boolean;
  813. tokenbufsize : longint;
  814. tokenbuf : pbyte;
  815. idtoken,
  816. token : ttoken;
  817. len : sizeint;
  818. wstring : widestring;
  819. astring : ansistring;
  820. function readtoken: ttoken;
  821. var
  822. b,b2 : byte;
  823. begin
  824. b:=tokenbuf[i];
  825. inc(i);
  826. if (b and $80)<>0 then
  827. begin
  828. b2:=tokenbuf[i];
  829. inc(i);
  830. result:=ttoken(((b and $7f) shl 8) or b2);
  831. end
  832. else
  833. result:=ttoken(b);
  834. end;
  835. begin
  836. writeln(space,'** Definition Id ',ppufile.getlongint,' **');
  837. writeln(space,s);
  838. write (space,' Type symbol : ');
  839. readderef('');
  840. write (space,' DefOptions : ');
  841. ppufile.getsmallset(defoptions);
  842. if defoptions<>[] then
  843. begin
  844. first:=true;
  845. for i:=1to high(defopt) do
  846. if (defopt[i].mask in defoptions) then
  847. begin
  848. if first then
  849. first:=false
  850. else
  851. write(', ');
  852. write(defopt[i].str);
  853. end;
  854. end;
  855. writeln;
  856. write (space,' DefStates : ');
  857. ppufile.getsmallset(defstates);
  858. if defstates<>[] then
  859. begin
  860. first:=true;
  861. for i:=1 to high(defstate) do
  862. if (defstate[i].mask in defstates) then
  863. begin
  864. if first then
  865. first:=false
  866. else
  867. write(', ');
  868. write(defstate[i].str);
  869. end;
  870. end;
  871. writeln;
  872. if df_generic in defoptions then
  873. begin
  874. tokenbufsize:=ppufile.getlongint;
  875. writeln(space,' Tokenbuffer size : ',tokenbufsize);
  876. tokenbuf:=allocmem(tokenbufsize);
  877. ppufile.getdata(tokenbuf^,tokenbufsize);
  878. i:=0;
  879. write(space,' Tokens: ');
  880. while i<tokenbufsize do
  881. begin
  882. token:=readtoken;
  883. if token<>_GENERICSPECIALTOKEN then
  884. begin
  885. write(arraytokeninfo[token].str);
  886. idtoken:=readtoken;
  887. end;
  888. case token of
  889. _CWCHAR,
  890. _CWSTRING :
  891. begin
  892. len:=psizeint(@tokenbuf[i])^;
  893. inc(i,sizeof(sizeint));
  894. setlength(wstring,len);
  895. move(tokenbuf[i],wstring[1],len*2);
  896. write(' ',wstring);
  897. inc(i,len*2);
  898. end;
  899. _CSTRING:
  900. begin
  901. len:=psizeint(@tokenbuf[i])^;
  902. inc(i,sizeof(sizeint));
  903. setlength(astring,len);
  904. move(tokenbuf[i],astring[1],len);
  905. write(' ',astring);
  906. inc(i,len);
  907. end;
  908. _CCHAR,
  909. _INTCONST,
  910. _REALNUMBER :
  911. begin
  912. write(' ',pshortstring(@tokenbuf[i])^);
  913. inc(i,tokenbuf[i]+1);
  914. end;
  915. _ID :
  916. begin
  917. write(' ',pshortstring(@tokenbuf[i])^);
  918. inc(i,tokenbuf[i]+1);
  919. {
  920. replaytokenbuf.read(orgpattern[0],1);
  921. replaytokenbuf.read(orgpattern[1],length(orgpattern));
  922. pattern:=upper(orgpattern);
  923. }
  924. end;
  925. _GENERICSPECIALTOKEN:
  926. begin
  927. if (tokenbuf[i] and $80)<>0 then
  928. begin
  929. write('Col: ',tokenbuf[i] and $7f);
  930. inc(i);
  931. end
  932. else
  933. case tspecialgenerictoken(tokenbuf[i]) of
  934. ST_LOADSETTINGS:
  935. begin
  936. inc(i);
  937. write('Settings');
  938. inc(i,sizeof(tsettings));
  939. end;
  940. ST_LINE:
  941. begin
  942. inc(i);
  943. write('Line: ',pdword(@tokenbuf[i])^);
  944. inc(i,4);
  945. end;
  946. ST_COLUMN:
  947. begin
  948. inc(i);
  949. write('Col: ',pword(@tokenbuf[i])^);
  950. inc(i,2);
  951. end;
  952. ST_FILEINDEX:
  953. begin
  954. inc(i);
  955. write('File: ',pword(@tokenbuf[i])^);
  956. inc(i,2);
  957. end;
  958. end;
  959. {
  960. replaytokenbuf.read(specialtoken,1);
  961. case specialtoken of
  962. ST_LOADSETTINGS:
  963. begin
  964. replaytokenbuf.read(current_settings,sizeof(current_settings));
  965. end
  966. else
  967. internalerror(2006103010);
  968. end;
  969. continue;
  970. }
  971. end;
  972. end;
  973. if i<tokenbufsize then
  974. write(',');
  975. end;
  976. writeln;
  977. freemem(tokenbuf);
  978. end;
  979. if df_specialization in defoptions then
  980. begin
  981. write (space,' Orig. GenericDef : ');
  982. readderef('');
  983. end;
  984. current_defoptions:=defoptions;
  985. end;
  986. { Read abstract procdef and return if inline procdef }
  987. { type tproccalloption is in globtype unit }
  988. { type tproctypeoption is in globtype unit }
  989. { type tprocoption is in globtype unit }
  990. procedure read_abstract_proc_def(var proccalloption:tproccalloption;var procoptions:tprocoptions);
  991. type
  992. tproccallopt=record
  993. mask : tproccalloption;
  994. str : string[30];
  995. end;
  996. tproctypeopt=record
  997. mask : tproctypeoption;
  998. str : string[30];
  999. end;
  1000. tprocopt=record
  1001. mask : tprocoption;
  1002. str : string[30];
  1003. end;
  1004. const
  1005. {proccalloptionStr is also in globtype unit }
  1006. proctypeopt : array[1..ord(high(tproctypeoption))] of tproctypeopt=(
  1007. (mask:potype_proginit; str:'ProgInit'),
  1008. (mask:potype_unitinit; str:'UnitInit'),
  1009. (mask:potype_unitfinalize; str:'UnitFinalize'),
  1010. (mask:potype_constructor; str:'Constructor'),
  1011. (mask:potype_destructor; str:'Destructor'),
  1012. (mask:potype_operator; str:'Operator'),
  1013. (mask:potype_procedure; str:'Procedure'),
  1014. (mask:potype_function; str:'Function'),
  1015. (mask:potype_class_constructor; str:'Class Constructor'),
  1016. (mask:potype_class_destructor; str:'Class Destructor'),
  1017. { Dispinterface property accessors }
  1018. (mask:potype_propgetter; str:'Property Getter'),
  1019. (mask:potype_propsetter; str:'Property Setter')
  1020. );
  1021. procopt : array[1..ord(high(tprocoption))] of tprocopt=(
  1022. (mask:po_classmethod; str:'ClassMethod'),
  1023. (mask:po_virtualmethod; str:'VirtualMethod'),
  1024. (mask:po_abstractmethod; str:'AbstractMethod'),
  1025. (mask:po_finalmethod; str:'FinalMethod'),
  1026. (mask:po_staticmethod; str:'StaticMethod'),
  1027. (mask:po_overridingmethod;str:'OverridingMethod'),
  1028. (mask:po_methodpointer; str:'MethodPointer'),
  1029. (mask:po_interrupt; str:'Interrupt'),
  1030. (mask:po_iocheck; str:'IOCheck'),
  1031. (mask:po_assembler; str:'Assembler'),
  1032. (mask:po_msgstr; str:'MsgStr'),
  1033. (mask:po_msgint; str:'MsgInt'),
  1034. (mask:po_exports; str:'Exports'),
  1035. (mask:po_external; str:'External'),
  1036. (mask:po_overload; str:'Overload'),
  1037. (mask:po_varargs; str:'VarArgs'),
  1038. (mask:po_internconst; str:'InternConst'),
  1039. (mask:po_addressonly; str:'AddressOnly'),
  1040. (mask:po_public; str:'Public'),
  1041. (mask:po_hascallingconvention;str:'HasCallingConvention'),
  1042. (mask:po_reintroduce; str:'ReIntroduce'),
  1043. (mask:po_explicitparaloc; str:'ExplicitParaloc'),
  1044. (mask:po_nostackframe; str:'NoStackFrame'),
  1045. (mask:po_has_mangledname; str:'HasMangledName'),
  1046. (mask:po_has_public_name; str:'HasPublicName'),
  1047. (mask:po_forward; str:'Forward'),
  1048. (mask:po_global; str:'Global'),
  1049. (mask:po_has_inlininginfo;str:'HasInliningInfo'),
  1050. (mask:po_syscall_legacy; str:'SyscallLegacy'),
  1051. (mask:po_syscall_sysv; str:'SyscallSysV'),
  1052. (mask:po_syscall_basesysv;str:'SyscallBaseSysV'),
  1053. (mask:po_syscall_sysvbase;str:'SyscallSysVBase'),
  1054. (mask:po_syscall_r12base; str:'SyscallR12Base'),
  1055. (mask:po_inline; str:'Inline'),
  1056. (mask:po_compilerproc; str:'CompilerProc'),
  1057. (mask:po_has_importdll; str:'HasImportDLL'),
  1058. (mask:po_has_importname; str:'HasImportName'),
  1059. (mask:po_kylixlocal; str:'KylixLocal'),
  1060. (mask:po_dispid; str:'DispId'),
  1061. (mask:po_weakexternal; str:'WeakExternal'),
  1062. (mask:po_objc; str:'ObjC'),
  1063. (mask:po_enumerator_movenext; str:'EnumeratorMoveNext'),
  1064. (mask:po_optional; str: 'Optional'),
  1065. (mask:po_delphi_nested_cc;str: 'Delphi-style nested frameptr')
  1066. );
  1067. var
  1068. proctypeoption : tproctypeoption;
  1069. i : longint;
  1070. first : boolean;
  1071. tempbuf : array[0..255] of byte;
  1072. begin
  1073. write(space,' Return type : ');
  1074. readderef('');
  1075. writeln(space,' Fpu used : ',ppufile.getbyte);
  1076. proctypeoption:=tproctypeoption(ppufile.getbyte);
  1077. write(space,' TypeOption : ');
  1078. first:=true;
  1079. for i:=1 to high(proctypeopt) do
  1080. if (proctypeopt[i].mask=proctypeoption) then
  1081. begin
  1082. if first then
  1083. first:=false
  1084. else
  1085. write(', ');
  1086. write(proctypeopt[i].str);
  1087. end;
  1088. writeln;
  1089. proccalloption:=tproccalloption(ppufile.getbyte);
  1090. writeln(space,' CallOption : ',proccalloptionStr[proccalloption]);
  1091. ppufile.getnormalset(procoptions);
  1092. if procoptions<>[] then
  1093. begin
  1094. write(space,' Options : ');
  1095. first:=true;
  1096. for i:=1 to high(procopt) do
  1097. if (procopt[i].mask in procoptions) then
  1098. begin
  1099. if first then
  1100. first:=false
  1101. else
  1102. write(', ');
  1103. write(procopt[i].str);
  1104. end;
  1105. writeln;
  1106. end;
  1107. if (po_explicitparaloc in procoptions) then
  1108. begin
  1109. i:=ppufile.getbyte;
  1110. ppufile.getdata(tempbuf,i);
  1111. end;
  1112. end;
  1113. { type tvaroption is in unit symconst }
  1114. { register variable }
  1115. { type tvarregable is in unit symconst }
  1116. procedure readabstractvarsym(const s:string;var varoptions:tvaroptions);
  1117. type
  1118. tvaropt=record
  1119. mask : tvaroption;
  1120. str : string[30];
  1121. end;
  1122. const
  1123. varopt : array[1..ord(high(tvaroption))] of tvaropt=(
  1124. (mask:vo_is_external; str:'External'),
  1125. (mask:vo_is_dll_var; str:'DLLVar'),
  1126. (mask:vo_is_thread_var; str:'ThreadVar'),
  1127. (mask:vo_has_local_copy; str:'HasLocalCopy'),
  1128. (mask:vo_is_const; str:'Constant'),
  1129. (mask:vo_is_public; str:'Public'),
  1130. (mask:vo_is_high_para; str:'HighValue'),
  1131. (mask:vo_is_funcret; str:'Funcret'),
  1132. (mask:vo_is_self; str:'Self'),
  1133. (mask:vo_is_vmt; str:'VMT'),
  1134. (mask:vo_is_result; str:'Result'),
  1135. (mask:vo_is_parentfp; str:'ParentFP'),
  1136. (mask:vo_is_loop_counter; str:'LoopCounter'),
  1137. (mask:vo_is_hidden_para; str:'Hidden'),
  1138. (mask:vo_has_explicit_paraloc;str:'ExplicitParaloc'),
  1139. (mask:vo_is_syscall_lib; str:'SysCallLib'),
  1140. (mask:vo_has_mangledname; str:'HasMangledName'),
  1141. (mask:vo_is_typed_const; str:'TypedConst'),
  1142. (mask:vo_is_range_check; str:'RangeCheckSwitch'),
  1143. (mask:vo_is_overflow_check; str:'OverflowCheckSwitch'),
  1144. (mask:vo_is_typinfo_para; str:'TypeInfo'),
  1145. (mask:vo_is_msgsel;str:'MsgSel'),
  1146. (mask:vo_is_weak_external;str:'WeakExternal'),
  1147. (mask:vo_is_first_field;str:'IsFirstField'),
  1148. (mask:vo_volatile;str:'Volatile'),
  1149. (mask:vo_has_section;str:'HasSection'),
  1150. (mask:vo_force_finalize;str:'ForceFinalize')
  1151. );
  1152. var
  1153. i : longint;
  1154. first : boolean;
  1155. begin
  1156. readcommonsym(s);
  1157. writeln(space,' Spez : ',Varspez2Str(ppufile.getbyte));
  1158. writeln(space,' Regable : ',Varregable2Str(ppufile.getbyte));
  1159. writeln(space,' Addr Taken : ',(ppufile.getbyte<>0));
  1160. write (space,' Var Type : ');
  1161. readderef('');
  1162. ppufile.getsmallset(varoptions);
  1163. if varoptions<>[] then
  1164. begin
  1165. write(space,' Options : ');
  1166. first:=true;
  1167. for i:=1 to high(varopt) do
  1168. if (varopt[i].mask in varoptions) then
  1169. begin
  1170. if first then
  1171. first:=false
  1172. else
  1173. write(', ');
  1174. write(varopt[i].str);
  1175. if varopt[i].mask = vo_has_section then
  1176. writeln('Section name:',ppufile.getansistring);
  1177. end;
  1178. writeln;
  1179. end;
  1180. end;
  1181. procedure readobjectdefoptions;
  1182. type
  1183. tsymopt=record
  1184. mask : tobjectoption;
  1185. str : string[30];
  1186. end;
  1187. const
  1188. symopt : array[1..ord(high(tobjectoption))] of tsymopt=(
  1189. (mask:oo_is_forward; str:'IsForward'),
  1190. (mask:oo_is_abstract; str:'IsAbstract'),
  1191. (mask:oo_is_sealed; str:'IsSealed'),
  1192. (mask:oo_has_virtual; str:'HasVirtual'),
  1193. (mask:oo_has_private; str:'HasPrivate'),
  1194. (mask:oo_has_protected; str:'HasProtected'),
  1195. (mask:oo_has_strictprivate; str:'HasStrictPrivate'),
  1196. (mask:oo_has_strictprotected;str:'HasStrictProtected'),
  1197. (mask:oo_has_constructor; str:'HasConstructor'),
  1198. (mask:oo_has_destructor; str:'HasDestructor'),
  1199. (mask:oo_has_vmt; str:'HasVMT'),
  1200. (mask:oo_has_msgstr; str:'HasMsgStr'),
  1201. (mask:oo_has_msgint; str:'HasMsgInt'),
  1202. (mask:oo_can_have_published; str:'CanHavePublished'),
  1203. (mask:oo_has_default_property;str:'HasDefaultProperty'),
  1204. (mask:oo_has_valid_guid; str:'HasValidGUID'),
  1205. (mask:oo_has_enumerator_movenext; str:'HasEnumeratorMoveNext'),
  1206. (mask:oo_has_enumerator_current; str:'HasEnumeratorCurrent'),
  1207. (mask:oo_is_external; str:'External'),
  1208. (mask:oo_is_formal; str:'Formal'),
  1209. (mask:oo_is_classhelper; str:'Class Helper/Category'),
  1210. (mask:oo_has_class_constructor; str:'HasClassConstructor'),
  1211. (mask:oo_has_class_destructor; str:'HasClassDestructor')
  1212. );
  1213. var
  1214. i : longint;
  1215. first : boolean;
  1216. begin
  1217. ppufile.getsmallset(current_objectoptions);
  1218. if current_objectoptions<>[] then
  1219. begin
  1220. first:=true;
  1221. for i:=1 to high(symopt) do
  1222. if (symopt[i].mask in current_objectoptions) then
  1223. begin
  1224. if first then
  1225. first:=false
  1226. else
  1227. write(', ');
  1228. write(symopt[i].str);
  1229. end;
  1230. end;
  1231. writeln;
  1232. end;
  1233. procedure readarraydefoptions;
  1234. { type tarraydefoption is in unit symconst }
  1235. type
  1236. tsymopt=record
  1237. mask : tarraydefoption;
  1238. str : string[30];
  1239. end;
  1240. const
  1241. symopt : array[1..ord(high(tarraydefoption))] of tsymopt=(
  1242. (mask:ado_IsConvertedPointer;str:'ConvertedPointer'),
  1243. (mask:ado_IsDynamicArray; str:'IsDynamicArray'),
  1244. (mask:ado_IsVariant; str:'IsVariant'),
  1245. (mask:ado_IsConstructor; str:'IsConstructor'),
  1246. (mask:ado_IsArrayOfConst; str:'ArrayOfConst'),
  1247. (mask:ado_IsConstString; str:'ConstString'),
  1248. (mask:ado_IsBitPacked; str:'BitPacked')
  1249. );
  1250. var
  1251. symoptions : tarraydefoptions;
  1252. i : longint;
  1253. first : boolean;
  1254. begin
  1255. ppufile.getsmallset(symoptions);
  1256. if symoptions<>[] then
  1257. begin
  1258. first:=true;
  1259. for i:=1 to high(symopt) do
  1260. if (symopt[i].mask in symoptions) then
  1261. begin
  1262. if first then
  1263. first:=false
  1264. else
  1265. write(', ');
  1266. write(symopt[i].str);
  1267. end;
  1268. end;
  1269. writeln;
  1270. end;
  1271. procedure readnodetree;
  1272. var
  1273. l : longint;
  1274. p : pointer;
  1275. begin
  1276. with ppufile do
  1277. begin
  1278. if space<>'' then
  1279. Writeln(space,'------ nodetree ------');
  1280. if readentry=ibnodetree then
  1281. begin
  1282. l:=entrysize;
  1283. Writeln(space,'Tree size : ',l);
  1284. { Read data to prevent error that entry is not completly read }
  1285. getmem(p,l);
  1286. getdata(p^,l);
  1287. freemem(p);
  1288. end
  1289. else
  1290. begin
  1291. WriteError('!! ibnodetree not found');
  1292. end;
  1293. end;
  1294. end;
  1295. procedure ReadCreatedObjTypes;
  1296. var
  1297. i,j,
  1298. len,
  1299. bssize: longint;
  1300. bs: pbyte;
  1301. begin
  1302. if ppufile.readentry<>ibcreatedobjtypes then
  1303. begin
  1304. writeln('!! ibcreatedobjtypes entry not found');
  1305. ppufile.skipdata(ppufile.entrysize);
  1306. has_errors:=true;
  1307. exit
  1308. end;
  1309. writeln;
  1310. writeln(space,'WPO info');
  1311. writeln(space,'--------');
  1312. len:=ppufile.getlongint;
  1313. writeln(space,'** Instantiated Object/Class types: ',len,' **');
  1314. space:=space+' ';
  1315. for i:=0 to len-1 do
  1316. readderef(space);
  1317. setlength(space,length(space)-2);
  1318. len:=ppufile.getlongint;
  1319. writeln(space,'** Instantiated ClassRef types: ',len,' **');
  1320. space:=space+' ';
  1321. for i:=0 to len-1 do
  1322. readderef(space);
  1323. setlength(space,length(space)-2);
  1324. len:=ppufile.getlongint;
  1325. writeln(space,'** Possibly instantiated ClassRef types : ',len,' **');
  1326. space:=space+' ';
  1327. for i:=0 to len-1 do
  1328. readderef(space);
  1329. setlength(space,length(space)-2);
  1330. len:=ppufile.getlongint;
  1331. writeln(space,'** Class types with called virtual methods info : ',len,' **');
  1332. space:=space+' ';
  1333. for i:=0 to len-1 do
  1334. begin
  1335. write(space,'Class def : ');
  1336. readderef('');
  1337. write(space+' ','Called vmtentries : ');
  1338. bssize:=ppufile.getlongint;
  1339. getmem(bs,bssize);
  1340. ppufile.readdata(bs^,bssize);
  1341. for j:=0 to bssize*8-1 do
  1342. if (((bs+j shr 3)^ shr (j and 7)) and 1) <> 0 then
  1343. write(j,', ');
  1344. writeln;
  1345. freemem(bs);
  1346. end;
  1347. setlength(space,length(space)-2);
  1348. end;
  1349. {****************************************************************************
  1350. Read Symbols Part
  1351. ****************************************************************************}
  1352. procedure readsymbols(const s:string);
  1353. type
  1354. pguid = ^tguid;
  1355. tguid = packed record
  1356. D1: LongWord;
  1357. D2: Word;
  1358. D3: Word;
  1359. D4: array[0..7] of Byte;
  1360. end;
  1361. var
  1362. b : byte;
  1363. pc : pchar;
  1364. ch : dword;
  1365. startnewline : boolean;
  1366. i,j,len : longint;
  1367. guid : tguid;
  1368. realvalue : extended;
  1369. tempbuf : array[0..127] of char;
  1370. pw : pcompilerwidestring;
  1371. varoptions : tvaroptions;
  1372. begin
  1373. with ppufile do
  1374. begin
  1375. if space<>'' then
  1376. Writeln(space,'------ ',s,' ------');
  1377. if readentry=ibstartsyms then
  1378. begin
  1379. Writeln(space,'Symtable datasize : ',getlongint);
  1380. Writeln(space,'Symtable alignment: ',getlongint);
  1381. end
  1382. else
  1383. Writeln('!! ibstartsym not found');
  1384. repeat
  1385. b:=readentry;
  1386. case b of
  1387. ibunitsym :
  1388. readcommonsym('Unit symbol ');
  1389. iblabelsym :
  1390. readcommonsym('Label symbol ');
  1391. ibtypesym :
  1392. begin
  1393. readcommonsym('Type symbol ');
  1394. write(space,' Result Type : ');
  1395. readderef('');
  1396. end;
  1397. ibprocsym :
  1398. begin
  1399. readcommonsym('Procedure symbol ');
  1400. len:=ppufile.getword;
  1401. for i:=1 to len do
  1402. begin
  1403. write(space,' Definition : ');
  1404. readderef('');
  1405. end;
  1406. end;
  1407. ibconstsym :
  1408. begin
  1409. readcommonsym('Constant symbol ');
  1410. b:=getbyte;
  1411. case tconsttyp(b) of
  1412. constord :
  1413. begin
  1414. write (space,' OrdinalType : ');
  1415. readderef('');
  1416. writeln(space,' Value : ',constexp.tostr(getexprint));
  1417. end;
  1418. constpointer :
  1419. begin
  1420. write (space,' PointerType : ');
  1421. readderef('');
  1422. writeln(space,' Value : ',getaint)
  1423. end;
  1424. conststring,
  1425. constresourcestring :
  1426. begin
  1427. len:=getlongint;
  1428. getmem(pc,len+1);
  1429. getdata(pc^,len);
  1430. (pc+len)^:= #0;
  1431. writeln(space,' Length : ',len);
  1432. writeln(space,' Value : "',pc,'"');
  1433. freemem(pc,len+1);
  1434. end;
  1435. constreal :
  1436. begin
  1437. if entryleft=sizeof(extended) then
  1438. realvalue:=getrealsize(sizeof(extended))
  1439. else if entryleft=sizeof(double) then
  1440. realvalue:=getrealsize(sizeof(double))
  1441. else
  1442. begin
  1443. realvalue:=0.0;
  1444. has_errors:=true;
  1445. end;
  1446. writeln(space,' Value : ',realvalue);
  1447. end;
  1448. constset :
  1449. begin
  1450. write (space,' Set Type : ');
  1451. readderef('');
  1452. for i:=1to 4 do
  1453. begin
  1454. write (space,' Value : ');
  1455. for j:=1to 8 do
  1456. begin
  1457. if j>1 then
  1458. write(',');
  1459. write(hexstr(getbyte,2));
  1460. end;
  1461. writeln;
  1462. end;
  1463. end;
  1464. constnil:
  1465. writeln(space,' NIL pointer.');
  1466. constwstring :
  1467. begin
  1468. initwidestring(pw);
  1469. setlengthwidestring(pw,getlongint);
  1470. if widecharsize=2 then
  1471. { don't use getdata, because the compilerwidechars may have to
  1472. be byteswapped
  1473. }
  1474. begin
  1475. for i:=0 to pw^.len-1 do
  1476. pw^.data[i]:=ppufile.getword;
  1477. end
  1478. else if widecharsize=4 then
  1479. begin
  1480. for i:=0 to pw^.len-1 do
  1481. pw^.data[i]:=cardinal(ppufile.getlongint);
  1482. end
  1483. else
  1484. begin
  1485. WriteError('Unsupported tcompilerwidechar size');
  1486. end;
  1487. Writeln(space,'Wide string type');
  1488. startnewline:=true;
  1489. for i:=0 to pw^.len-1 do
  1490. begin
  1491. if startnewline then
  1492. begin
  1493. write(space);
  1494. startnewline:=false;
  1495. end;
  1496. ch:=pw^.data[i];
  1497. if widecharsize=2 then
  1498. write(hexstr(ch,4))
  1499. else
  1500. write(hexstr(ch,8));
  1501. if (i mod 8)= 0 then
  1502. startnewline:=true
  1503. else
  1504. write(', ');
  1505. end;
  1506. donewidestring(pw);
  1507. end;
  1508. constguid:
  1509. begin
  1510. getdata(guid,sizeof(guid));
  1511. write (space,' IID String: {',hexstr(guid.d1,8),'-',hexstr(guid.d2,4),'-',hexstr(guid.d3,4),'-');
  1512. for i:=0 to 7 do
  1513. begin
  1514. write(hexstr(guid.d4[i],2));
  1515. if i=1 then write('-');
  1516. end;
  1517. writeln('}');
  1518. end
  1519. else
  1520. Writeln ('!! Invalid unit format : Invalid const type encountered: ',b);
  1521. end;
  1522. end;
  1523. ibabsolutevarsym :
  1524. begin
  1525. readabstractvarsym('Absolute variable symbol ',varoptions);
  1526. Write (space,' Relocated to ');
  1527. b:=getbyte;
  1528. case absolutetyp(b) of
  1529. tovar :
  1530. readpropaccesslist(space+' Sym : ');
  1531. toasm :
  1532. Writeln('Assembler name : ',getstring);
  1533. toaddr :
  1534. begin
  1535. Write('Address : ',getlongint);
  1536. if tsystemcpu(ppufile.header.cpu)=cpu_i386 then
  1537. WriteLn(' (Far: ',getbyte<>0,')');
  1538. end;
  1539. else
  1540. Writeln ('!! Invalid unit format : Invalid absolute type encountered: ',b);
  1541. end;
  1542. end;
  1543. ibfieldvarsym :
  1544. begin
  1545. readabstractvarsym('Field Variable symbol ',varoptions);
  1546. writeln(space,' Address : ',getaint);
  1547. end;
  1548. ibstaticvarsym :
  1549. begin
  1550. readabstractvarsym('Global Variable symbol ',varoptions);
  1551. write (space,' DefaultConst : ');
  1552. readderef('');
  1553. if (vo_has_mangledname in varoptions) then
  1554. writeln(space,' Mangledname : ',getstring);
  1555. end;
  1556. iblocalvarsym :
  1557. begin
  1558. readabstractvarsym('Local Variable symbol ',varoptions);
  1559. write (space,' DefaultConst : ');
  1560. readderef('');
  1561. end;
  1562. ibparavarsym :
  1563. begin
  1564. readabstractvarsym('Parameter Variable symbol ',varoptions);
  1565. write (space,' DefaultConst : ');
  1566. readderef('');
  1567. writeln(space,' ParaNr : ',getword);
  1568. writeln(space,' Univ : ',boolean(getbyte));
  1569. writeln(space,' VarState : ',getbyte);
  1570. if (vo_has_explicit_paraloc in varoptions) then
  1571. begin
  1572. i:=getbyte;
  1573. getdata(tempbuf,i);
  1574. end;
  1575. end;
  1576. ibenumsym :
  1577. begin
  1578. readcommonsym('Enumeration symbol ');
  1579. write (space,' Definition : ');
  1580. readderef('');
  1581. writeln(space,' Value : ',getlongint);
  1582. end;
  1583. ibsyssym :
  1584. begin
  1585. readcommonsym('Internal system symbol ');
  1586. writeln(space,' Internal Nr : ',getlongint);
  1587. end;
  1588. ibmacrosym :
  1589. begin
  1590. readcommonsym('Macro symbol ');
  1591. writeln(space,' Name: ',getstring);
  1592. writeln(space,' Defined: ',getbyte);
  1593. writeln(space,' Compiler var: ',getbyte);
  1594. len:=getlongint;
  1595. writeln(space,' Value length: ',len);
  1596. if len > 0 then
  1597. begin
  1598. getmem(pc,len+1);
  1599. getdata(pc^,len);
  1600. (pc+len)^:= #0;
  1601. writeln(space,' Value: "',pc,'"');
  1602. freemem(pc,len+1);
  1603. end;
  1604. end;
  1605. ibpropertysym :
  1606. begin
  1607. readcommonsym('Property ');
  1608. i:=getlongint;
  1609. writeln(space,' PropOptions : ',i);
  1610. write (space,' OverrideProp : ');
  1611. readderef('');
  1612. write (space,' Prop Type : ');
  1613. readderef('');
  1614. writeln(space,' Index : ',getlongint);
  1615. writeln(space,' Default : ',getlongint);
  1616. write (space,' Index Type : ');
  1617. readderef('');
  1618. { palt_none }
  1619. readpropaccesslist('');
  1620. write (space,' Readaccess : ');
  1621. readpropaccesslist(space+' Sym: ');
  1622. write (space,' Writeaccess : ');
  1623. readpropaccesslist(space+' Sym: ');
  1624. write (space,' Storedaccess : ');
  1625. readpropaccesslist(space+' Sym: ');
  1626. end;
  1627. iberror :
  1628. begin
  1629. WriteError('!! Error in PPU');
  1630. exit;
  1631. end;
  1632. ibendsyms :
  1633. break;
  1634. else
  1635. begin
  1636. WriteLn('!! Skipping unsupported PPU Entry in Symbols: ',b);
  1637. has_errors:=true;
  1638. end;
  1639. end;
  1640. if not EndOfEntry then
  1641. HasMoreInfos;
  1642. until false;
  1643. end;
  1644. end;
  1645. {****************************************************************************
  1646. Read defintions Part
  1647. ****************************************************************************}
  1648. procedure readdefinitions(const s:string);
  1649. { type tordtype is in symconst unit }
  1650. {
  1651. uvoid,
  1652. u8bit,u16bit,u32bit,u64bit,
  1653. s8bit,s16bit,s32bit,s64bit,
  1654. bool8bit,bool16bit,bool32bit,bool64bit,
  1655. uchar,uwidechar,scurrency
  1656. ); }
  1657. { type tobjecttyp is in symconst unit }
  1658. { type tvarianttype is in symconst unit }
  1659. var
  1660. b : byte;
  1661. l,j : longint;
  1662. calloption : tproccalloption;
  1663. procoptions : tprocoptions;
  1664. procinfooptions : tprocinfoflag;
  1665. defoptions: tdefoptions;
  1666. begin
  1667. with ppufile do
  1668. begin
  1669. if space<>'' then
  1670. Writeln(space,'------ ',s,' ------');
  1671. if readentry<>ibstartdefs then
  1672. Writeln('!! ibstartdefs not found');
  1673. repeat
  1674. b:=readentry;
  1675. case b of
  1676. ibpointerdef :
  1677. begin
  1678. readcommondef('Pointer definition',defoptions);
  1679. write (space,' Pointed Type : ');
  1680. readderef('');
  1681. writeln(space,' Is Far : ',(getbyte<>0));
  1682. writeln(space,' Has Pointer Math : ',(getbyte<>0));
  1683. end;
  1684. iborddef :
  1685. begin
  1686. readcommondef('Ordinal definition',defoptions);
  1687. write (space,' Base type : ');
  1688. b:=getbyte;
  1689. case tordtype(b) of
  1690. uvoid : writeln('uvoid');
  1691. u8bit : writeln('u8bit');
  1692. u16bit : writeln('u16bit');
  1693. u32bit : writeln('s32bit');
  1694. u64bit : writeln('u64bit');
  1695. s8bit : writeln('s8bit');
  1696. s16bit : writeln('s16bit');
  1697. s32bit : writeln('s32bit');
  1698. s64bit : writeln('s64bit');
  1699. bool8bit : writeln('bool8bit');
  1700. bool16bit : writeln('bool16bit');
  1701. bool32bit : writeln('bool32bit');
  1702. bool64bit : writeln('bool64bit');
  1703. uchar : writeln('uchar');
  1704. uwidechar : writeln('uwidechar');
  1705. scurrency : writeln('ucurrency');
  1706. else writeln('!! Warning: Invalid base type ',b);
  1707. end;
  1708. writeln(space,' Range : ',constexp.tostr(getexprint),' to ',constexp.tostr(getexprint));
  1709. end;
  1710. ibfloatdef :
  1711. begin
  1712. readcommondef('Float definition',defoptions);
  1713. writeln(space,' Float type : ',getbyte);
  1714. end;
  1715. ibarraydef :
  1716. begin
  1717. readcommondef('Array definition',defoptions);
  1718. write (space,' Element type : ');
  1719. readderef('');
  1720. write (space,' Range Type : ');
  1721. readderef('');
  1722. writeln(space,' Range : ',getaint,' to ',getaint);
  1723. write (space,' Options : ');
  1724. readarraydefoptions;
  1725. readsymtableoptions('symbols');
  1726. readdefinitions('symbols');
  1727. readsymbols('symbols');
  1728. end;
  1729. ibprocdef :
  1730. begin
  1731. readcommondef('Procedure definition',defoptions);
  1732. read_abstract_proc_def(calloption,procoptions);
  1733. if (po_has_mangledname in procoptions) then
  1734. writeln(space,' Mangled name : ',getstring);
  1735. writeln(space,' Number : ',getword);
  1736. writeln(space,' Level : ',getbyte);
  1737. write (space,' Class : ');
  1738. readderef('');
  1739. write (space,' Procsym : ');
  1740. readderef('');
  1741. write (space,' File Pos : ');
  1742. readposinfo;
  1743. writeln(space,' Visibility : ',Visibility2Str(ppufile.getbyte));
  1744. write (space,' SymOptions : ');
  1745. readsymoptions(space+' ');
  1746. if tsystemcpu(ppufile.header.cpu)=cpu_powerpc then
  1747. begin
  1748. { library symbol for AmigaOS/MorphOS }
  1749. write (space,' Library symbol : ');
  1750. readderef('');
  1751. end;
  1752. if (po_has_importdll in procoptions) then
  1753. writeln(space,' Import DLL : ',getstring);
  1754. if (po_has_importname in procoptions) then
  1755. writeln(space,' Import Name : ',getstring);
  1756. writeln(space,' Import Nr : ',getword);
  1757. if (po_msgint in procoptions) then
  1758. writeln(space,' MsgInt : ',getlongint);
  1759. if (po_msgstr in procoptions) then
  1760. writeln(space,' MsgStr : ',getstring);
  1761. if (po_dispid in procoptions) then
  1762. writeln(space,' DispID: ',ppufile.getlongint);
  1763. if (po_has_inlininginfo in procoptions) then
  1764. begin
  1765. write (space,' FuncretSym : ');
  1766. readderef('');
  1767. ppufile.getsmallset(procinfooptions);
  1768. writeln(space,' ProcInfoOptions : ',dword(procinfooptions));
  1769. end;
  1770. b:=ppufile.getbyte;
  1771. if b<>0 then
  1772. begin
  1773. write (space,' Alias names : ');
  1774. for j:=1 to b do
  1775. begin
  1776. write(ppufile.getstring);
  1777. if j<b then
  1778. write(', ');
  1779. end;
  1780. writeln;
  1781. end;
  1782. if not EndOfEntry then
  1783. HasMoreInfos;
  1784. space:=' '+space;
  1785. { parast }
  1786. readsymtableoptions('parast');
  1787. readdefinitions('parast');
  1788. readsymbols('parast');
  1789. { localst }
  1790. if (po_has_inlininginfo in procoptions) then
  1791. begin
  1792. readsymtableoptions('localst');
  1793. readdefinitions('localst');
  1794. readsymbols('localst');
  1795. end;
  1796. if (po_has_inlininginfo in procoptions) then
  1797. readnodetree;
  1798. delete(space,1,4);
  1799. end;
  1800. ibprocvardef :
  1801. begin
  1802. readcommondef('Procedural type (ProcVar) definition',defoptions);
  1803. read_abstract_proc_def(calloption,procoptions);
  1804. writeln(space,' Symtable level :',ppufile.getbyte);
  1805. if not EndOfEntry then
  1806. HasMoreInfos;
  1807. space:=' '+space;
  1808. { parast }
  1809. readsymtableoptions('parast');
  1810. readdefinitions('parast');
  1811. readsymbols('parast');
  1812. delete(space,1,4);
  1813. end;
  1814. ibshortstringdef :
  1815. begin
  1816. readcommondef('ShortString definition',defoptions);
  1817. writeln(space,' Length : ',getbyte);
  1818. end;
  1819. ibwidestringdef :
  1820. begin
  1821. readcommondef('WideString definition',defoptions);
  1822. writeln(space,' Length : ',getaint);
  1823. end;
  1824. ibunicodestringdef :
  1825. begin
  1826. readcommondef('UnicodeString definition',defoptions);
  1827. writeln(space,' Length : ',getaint);
  1828. end;
  1829. ibansistringdef :
  1830. begin
  1831. readcommondef('AnsiString definition',defoptions);
  1832. writeln(space,' Length : ',getaint);
  1833. end;
  1834. iblongstringdef :
  1835. begin
  1836. readcommondef('Longstring definition',defoptions);
  1837. writeln(space,' Length : ',getaint);
  1838. end;
  1839. ibrecorddef :
  1840. begin
  1841. readcommondef('Record definition',defoptions);
  1842. writeln(space,' Name of Record : ',getstring);
  1843. writeln(space,' Import lib/pkg : ',getstring);
  1844. write (space,' Options : ');
  1845. readobjectdefoptions;
  1846. writeln(space,' FieldAlign : ',shortint(getbyte));
  1847. writeln(space,' RecordAlign : ',shortint(getbyte));
  1848. writeln(space,' PadAlign : ',shortint(getbyte));
  1849. writeln(space,'UseFieldAlignment : ',shortint(getbyte));
  1850. writeln(space,' DataSize : ',getasizeint);
  1851. writeln(space,' PaddingSize : ',getword);
  1852. if not EndOfEntry then
  1853. HasMoreInfos;
  1854. {read the record definitions and symbols}
  1855. space:=' '+space;
  1856. readrecsymtableoptions;
  1857. readsymtableoptions('fields');
  1858. readdefinitions('fields');
  1859. readsymbols('fields');
  1860. Delete(space,1,4);
  1861. end;
  1862. ibobjectdef :
  1863. begin
  1864. readcommondef('Object/Class definition',defoptions);
  1865. writeln(space,' Name of Class : ',getstring);
  1866. writeln(space,' Import lib/pkg : ',getstring);
  1867. write (space,' Options : ');
  1868. readobjectdefoptions;
  1869. b:=getbyte;
  1870. write (space,' Type : ');
  1871. case tobjecttyp(b) of
  1872. odt_class : writeln('class');
  1873. odt_object : writeln('object');
  1874. odt_interfacecom : writeln('interfacecom');
  1875. odt_interfacecorba : writeln('interfacecorba');
  1876. odt_cppclass : writeln('cppclass');
  1877. odt_dispinterface : writeln('dispinterface');
  1878. odt_objcclass : writeln('objcclass');
  1879. odt_objcprotocol : writeln('objcprotocol');
  1880. odt_helper : writeln('helper');
  1881. else writeln('!! Warning: Invalid object type ',b);
  1882. end;
  1883. writeln(space,' External name : ',getstring);
  1884. writeln(space,' DataSize : ',getasizeint);
  1885. writeln(space,' PaddingSize : ',getword);
  1886. writeln(space,' FieldAlign : ',shortint(getbyte));
  1887. writeln(space,' RecordAlign : ',shortint(getbyte));
  1888. writeln(space,' Vmt offset : ',getlongint);
  1889. write (space, ' Ancestor Class : ');
  1890. readderef('');
  1891. if tobjecttyp(b) in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  1892. begin
  1893. { IIDGUID }
  1894. for j:=1to 16 do
  1895. getbyte;
  1896. writeln(space,' IID String : ',getstring);
  1897. end;
  1898. if (tobjecttyp(b)=odt_helper) or
  1899. (oo_is_classhelper in current_objectoptions) then
  1900. begin
  1901. write(space,' Helper parent : ');
  1902. readderef('');
  1903. end;
  1904. l:=getlongint;
  1905. writeln(space,' VMT entries: ',l);
  1906. for j:=1 to l do
  1907. begin
  1908. write(space,' ');
  1909. readderef('');
  1910. writeln(space,' Visibility: ',Visibility2Str(getbyte));
  1911. end;
  1912. if tobjecttyp(b) in [odt_class,odt_interfacecorba,odt_objcclass,odt_objcprotocol] then
  1913. begin
  1914. l:=getlongint;
  1915. writeln(space,' Impl Intf Count : ',l);
  1916. for j:=1 to l do
  1917. begin
  1918. write (space,' - Definition : ');
  1919. readderef('');
  1920. writeln(space,' IOffset : ',getlongint);
  1921. end;
  1922. end;
  1923. if df_copied_def in current_defoptions then
  1924. begin
  1925. writeln(' Copy of def: ');
  1926. readderef('');
  1927. end;
  1928. if not EndOfEntry then
  1929. HasMoreInfos;
  1930. if not(df_copied_def in current_defoptions) then
  1931. begin
  1932. {read the record definitions and symbols}
  1933. space:=' '+space;
  1934. readrecsymtableoptions;
  1935. readsymtableoptions('fields');
  1936. readdefinitions('fields');
  1937. readsymbols('fields');
  1938. Delete(space,1,4);
  1939. end;
  1940. end;
  1941. ibfiledef :
  1942. begin
  1943. ReadCommonDef('File definition',defoptions);
  1944. write (space,' Type : ');
  1945. case getbyte of
  1946. 0 : writeln('Text');
  1947. 1 : begin
  1948. writeln('Typed');
  1949. write (space,' File of Type : ');
  1950. readderef('');
  1951. end;
  1952. 2 : writeln('Untyped');
  1953. end;
  1954. end;
  1955. ibformaldef :
  1956. begin
  1957. readcommondef('Generic definition (void-typ)',defoptions);
  1958. writeln(space,' Is Typed : ',(getbyte<>0));
  1959. end;
  1960. ibundefineddef :
  1961. readcommondef('Undefined definition (generic parameter)',defoptions);
  1962. ibenumdef :
  1963. begin
  1964. readcommondef('Enumeration type definition',defoptions);
  1965. writeln(space,' Smallest element : ',getaint);
  1966. writeln(space,' Largest element : ',getaint);
  1967. writeln(space,' Size : ',getaint);
  1968. if df_copied_def in defoptions then
  1969. begin
  1970. write(space,'Base enumeration type : ');
  1971. readderef('');
  1972. end
  1973. else
  1974. begin
  1975. space:=' '+space;
  1976. readsymtableoptions('elements');
  1977. readdefinitions('elements');
  1978. readsymbols('elements');
  1979. delete(space,1,4);
  1980. end;
  1981. end;
  1982. ibclassrefdef :
  1983. begin
  1984. readcommondef('Class reference definition',defoptions);
  1985. write (space,' Pointed Type : ');
  1986. readderef('');
  1987. end;
  1988. ibsetdef :
  1989. begin
  1990. readcommondef('Set definition',defoptions);
  1991. write (space,' Element type : ');
  1992. readderef('');
  1993. writeln(space,' Size : ',getaint);
  1994. writeln(space,' Set Base : ',getaint);
  1995. writeln(space,' Set Max : ',getaint);
  1996. end;
  1997. ibvariantdef :
  1998. begin
  1999. readcommondef('Variant definition',defoptions);
  2000. write (space,' Varianttype : ');
  2001. b:=getbyte;
  2002. case tvarianttype(b) of
  2003. vt_normalvariant :
  2004. writeln('Normal');
  2005. vt_olevariant :
  2006. writeln('OLE');
  2007. else
  2008. writeln('!! Warning: Invalid varianttype ',b);
  2009. end;
  2010. end;
  2011. iberror :
  2012. begin
  2013. WriteError('!! Error in PPU');
  2014. exit;
  2015. end;
  2016. ibenddefs :
  2017. break;
  2018. else
  2019. begin
  2020. WriteLn('!! Skipping unsupported PPU Entry in definitions: ',b);
  2021. has_errors:=true;
  2022. end;
  2023. end;
  2024. if not EndOfEntry then
  2025. HasMoreInfos;
  2026. until false;
  2027. end;
  2028. end;
  2029. procedure readmoduleoptions(space : string);
  2030. type
  2031. { tmoduleoption type is in unit fmodule }
  2032. tmoduleoption = (mo_none,
  2033. mo_hint_deprecated,
  2034. mo_hint_platform,
  2035. mo_hint_library,
  2036. mo_hint_unimplemented,
  2037. mo_hint_experimental,
  2038. mo_has_deprecated_msg
  2039. );
  2040. tmoduleoptions = set of tmoduleoption;
  2041. tmoduleopt=record
  2042. mask : tmoduleoption;
  2043. str : string[30];
  2044. end;
  2045. const
  2046. moduleopts=ord(high(tmoduleoption));
  2047. moduleopt : array[1..moduleopts] of tmoduleopt=(
  2048. (mask:mo_hint_deprecated; str:'Hint Deprecated'),
  2049. (mask:mo_hint_platform; str:'Hint Platform'),
  2050. (mask:mo_hint_library; str:'Hint Library'),
  2051. (mask:mo_hint_unimplemented; str:'Hint Unimplemented'),
  2052. (mask:mo_hint_experimental; str:'Hint Experimental'),
  2053. (mask:mo_has_deprecated_msg; str:'Has Deprecated Message')
  2054. );
  2055. var
  2056. moduleoptions : tmoduleoptions;
  2057. i : longint;
  2058. first : boolean;
  2059. begin
  2060. ppufile.getsmallset(moduleoptions);
  2061. if moduleoptions<>[] then
  2062. begin
  2063. first:=true;
  2064. for i:=1to moduleopts do
  2065. if (moduleopt[i].mask in moduleoptions) then
  2066. begin
  2067. if first then
  2068. first:=false
  2069. else
  2070. write(', ');
  2071. write(moduleopt[i].str);
  2072. end;
  2073. end;
  2074. writeln;
  2075. if mo_has_deprecated_msg in moduleoptions then
  2076. writeln(space,'Deprecated : ', ppufile.getstring);
  2077. end;
  2078. {****************************************************************************
  2079. Read General Part
  2080. ****************************************************************************}
  2081. procedure readinterface;
  2082. var
  2083. b : byte;
  2084. sourcenumber : longint;
  2085. begin
  2086. with ppufile do
  2087. begin
  2088. repeat
  2089. b:=readentry;
  2090. case b of
  2091. ibmodulename :
  2092. Writeln('Module Name: ',getstring);
  2093. ibmoduleoptions:
  2094. readmoduleoptions(' ');
  2095. ibsourcefiles :
  2096. begin
  2097. sourcenumber:=1;
  2098. while not EndOfEntry do
  2099. begin
  2100. Writeln('Source file ',sourcenumber,' : ',getstring,' ',filetimestring(getlongint));
  2101. inc(sourcenumber);
  2102. end;
  2103. end;
  2104. {$IFDEF MACRO_DIFF_HINT}
  2105. ibusedmacros :
  2106. begin
  2107. while not EndOfEntry do
  2108. begin
  2109. Write('Conditional ',getstring);
  2110. b:=getbyte;
  2111. if boolean(b)=true then
  2112. write(' defined at startup')
  2113. else
  2114. write(' not defined at startup');
  2115. b:=getbyte;
  2116. if boolean(b)=true then
  2117. writeln(' was used')
  2118. else
  2119. writeln;
  2120. end;
  2121. end;
  2122. {$ENDIF}
  2123. ibloadunit :
  2124. ReadLoadUnit;
  2125. iblinkunitofiles :
  2126. ReadLinkContainer('Link unit object file: ');
  2127. iblinkunitstaticlibs :
  2128. ReadLinkContainer('Link unit static lib: ');
  2129. iblinkunitsharedlibs :
  2130. ReadLinkContainer('Link unit shared lib: ');
  2131. iblinkotherofiles :
  2132. ReadLinkContainer('Link other object file: ');
  2133. iblinkotherstaticlibs :
  2134. ReadLinkContainer('Link other static lib: ');
  2135. iblinkothersharedlibs :
  2136. ReadLinkContainer('Link other shared lib: ');
  2137. iblinkotherframeworks:
  2138. ReadLinkContainer('Link framework: ');
  2139. ibmainname:
  2140. Writeln('Specified main program symbol name: ',getstring);
  2141. ibImportSymbols :
  2142. ReadImportSymbols;
  2143. ibderefdata :
  2144. ReadDerefData;
  2145. ibderefmap :
  2146. ReadDerefMap;
  2147. ibwpofile :
  2148. ReadWpoFileInfo;
  2149. ibresources :
  2150. ReadLinkContainer('Resource file: ');
  2151. iberror :
  2152. begin
  2153. WriteError('Error in PPU');
  2154. exit;
  2155. end;
  2156. ibendinterface :
  2157. break;
  2158. else
  2159. begin
  2160. WriteLn('!! Skipping unsupported PPU Entry in General Part: ',b);
  2161. has_errors:=true;
  2162. end;
  2163. end;
  2164. until false;
  2165. end;
  2166. end;
  2167. {****************************************************************************
  2168. Read Implementation Part
  2169. ****************************************************************************}
  2170. procedure readimplementation;
  2171. var
  2172. b : byte;
  2173. begin
  2174. with ppufile do
  2175. begin
  2176. repeat
  2177. b:=readentry;
  2178. case b of
  2179. ibasmsymbols :
  2180. ReadAsmSymbols;
  2181. ibloadunit :
  2182. ReadLoadUnit;
  2183. iberror :
  2184. begin
  2185. WriteError('Error in PPU');
  2186. exit;
  2187. end;
  2188. ibendimplementation :
  2189. break;
  2190. else
  2191. begin
  2192. WriteLn('!! Skipping unsupported PPU Entry in Implementation: ',b);
  2193. has_errors:=true;
  2194. end;
  2195. end;
  2196. until false;
  2197. end;
  2198. end;
  2199. procedure dofile (filename : string);
  2200. begin
  2201. { reset }
  2202. space:='';
  2203. { fix filename }
  2204. if pos('.',filename)=0 then
  2205. filename:=filename+'.ppu';
  2206. ppufile:=tppufile.create(filename);
  2207. if not ppufile.openfile then
  2208. begin
  2209. WriteError('IO-Error when opening : '+filename+', Skipping');
  2210. exit;
  2211. end;
  2212. { PPU File is open, check for PPU Id }
  2213. if not ppufile.CheckPPUID then
  2214. begin
  2215. writeln(Filename,' : Not a valid PPU file, Skipping');
  2216. has_errors:=true;
  2217. exit;
  2218. end;
  2219. { Check PPU Version }
  2220. ppuversion:=ppufile.GetPPUVersion;
  2221. Writeln('Analyzing ',filename,' (v',PPUVersion,')');
  2222. if PPUVersion<16 then
  2223. begin
  2224. writeln(Filename,' : Old PPU Formats (<v16) are not supported, Skipping');
  2225. has_errors:=true;
  2226. exit;
  2227. end;
  2228. { Write PPU Header Information }
  2229. if (verbose and v_header)<>0 then
  2230. begin
  2231. Writeln;
  2232. Writeln('Header');
  2233. Writeln('-------');
  2234. with ppufile.header do
  2235. begin
  2236. Writeln('Compiler version : ',ppufile.header.compiler shr 14,'.',
  2237. (ppufile.header.compiler shr 7) and $7f,'.',
  2238. ppufile.header.compiler and $7f);
  2239. WriteLn('Target processor : ',Cpu2Str(cpu));
  2240. WriteLn('Target operating system : ',Target2Str(target));
  2241. Writeln('Unit flags : ',PPUFlags2Str(flags));
  2242. Writeln('FileSize (w/o header) : ',size);
  2243. Writeln('Checksum : ',hexstr(checksum,8));
  2244. Writeln('Interface Checksum : ',hexstr(interface_checksum,8));
  2245. Writeln('Indirect Checksum : ',hexstr(indirect_checksum,8));
  2246. Writeln('Definitions stored : ',tostr(deflistsize));
  2247. Writeln('Symbols stored : ',tostr(symlistsize));
  2248. end;
  2249. end;
  2250. {read the general stuff}
  2251. if (verbose and v_interface)<>0 then
  2252. begin
  2253. Writeln;
  2254. Writeln('Interface section');
  2255. Writeln('------------------');
  2256. readinterface;
  2257. end
  2258. else
  2259. ppufile.skipuntilentry(ibendinterface);
  2260. Writeln;
  2261. Writeln('Interface symtable');
  2262. Writeln('----------------------');
  2263. readsymtableoptions('interface');
  2264. {read the definitions}
  2265. if (verbose and v_defs)<>0 then
  2266. begin
  2267. Writeln;
  2268. Writeln('Interface definitions');
  2269. Writeln('----------------------');
  2270. readdefinitions('interface');
  2271. end
  2272. else
  2273. ppufile.skipuntilentry(ibenddefs);
  2274. {read the symbols}
  2275. if (verbose and v_syms)<>0 then
  2276. begin
  2277. Writeln;
  2278. Writeln('Interface Symbols');
  2279. Writeln('------------------');
  2280. readsymbols('interface');
  2281. end
  2282. else
  2283. ppufile.skipuntilentry(ibendsyms);
  2284. {read the macro symbols}
  2285. if (verbose and v_syms)<>0 then
  2286. begin
  2287. Writeln;
  2288. Writeln('Interface Macro Symbols');
  2289. Writeln('-----------------------');
  2290. end;
  2291. if ppufile.readentry<>ibexportedmacros then
  2292. begin
  2293. WriteError('!! Error in PPU');
  2294. exit;
  2295. end;
  2296. if boolean(ppufile.getbyte) then
  2297. begin
  2298. readsymtableoptions('interface macro');
  2299. {skip the definition section for macros (since they are never used) }
  2300. ppufile.skipuntilentry(ibenddefs);
  2301. {read the macro symbols}
  2302. if (verbose and v_syms)<>0 then
  2303. readsymbols('interface macro')
  2304. else
  2305. ppufile.skipuntilentry(ibendsyms);
  2306. end
  2307. else
  2308. Writeln('(no exported macros)');
  2309. {read the implementation stuff}
  2310. if (verbose and v_implementation)<>0 then
  2311. begin
  2312. Writeln;
  2313. Writeln('Implementation section');
  2314. Writeln('-----------------------');
  2315. readimplementation;
  2316. end
  2317. else
  2318. ppufile.skipuntilentry(ibendimplementation);
  2319. {read the static symtable}
  2320. Writeln;
  2321. Writeln('Implementation symtable');
  2322. Writeln('----------------------');
  2323. readsymtableoptions('implementation');
  2324. if (ppufile.header.flags and uf_local_symtable)<>0 then
  2325. begin
  2326. if (verbose and v_defs)<>0 then
  2327. begin
  2328. Writeln;
  2329. Writeln('Static definitions');
  2330. Writeln('----------------------');
  2331. readdefinitions('implementation');
  2332. end
  2333. else
  2334. ppufile.skipuntilentry(ibenddefs);
  2335. {read the symbols}
  2336. if (verbose and v_syms)<>0 then
  2337. begin
  2338. Writeln;
  2339. Writeln('Static Symbols');
  2340. Writeln('------------------');
  2341. readsymbols('implementation');
  2342. end
  2343. else
  2344. ppufile.skipuntilentry(ibendsyms);
  2345. end;
  2346. ReadCreatedObjTypes;
  2347. FreeDerefdata;
  2348. {shutdown ppufile}
  2349. ppufile.closefile;
  2350. ppufile.free;
  2351. Writeln;
  2352. end;
  2353. procedure help;
  2354. begin
  2355. writeln('usage: ppudump [options] <filename1> <filename2>...');
  2356. writeln;
  2357. writeln('[options] can be:');
  2358. writeln(' -M Exit with ExitCode=2 if more information is available');
  2359. writeln(' -V<verbose> Set verbosity to <verbose>');
  2360. writeln(' H - Show header info');
  2361. writeln(' I - Show interface');
  2362. writeln(' M - Show implementation');
  2363. writeln(' S - Show interface symbols');
  2364. writeln(' D - Show interface definitions');
  2365. // writeln(' B - Show browser info');
  2366. writeln(' A - Show all');
  2367. writeln(' -h, -? This helpscreen');
  2368. halt;
  2369. end;
  2370. var
  2371. startpara,
  2372. nrfile,i : longint;
  2373. para : string;
  2374. const
  2375. error_on_more : boolean = false;
  2376. begin
  2377. writeln(Title+' '+Version);
  2378. writeln(Copyright);
  2379. writeln;
  2380. if paramcount<1 then
  2381. begin
  2382. writeln('usage: dumpppu [options] <filename1> <filename2>...');
  2383. halt(1);
  2384. end;
  2385. { turn verbose on by default }
  2386. verbose:=v_all;
  2387. { read options }
  2388. startpara:=1;
  2389. while copy(paramstr(startpara),1,1)='-' do
  2390. begin
  2391. para:=paramstr(startpara);
  2392. case upcase(para[2]) of
  2393. 'M' : error_on_more:=true;
  2394. 'V' : begin
  2395. verbose:=0;
  2396. for i:=3 to length(para) do
  2397. case upcase(para[i]) of
  2398. 'H' : verbose:=verbose or v_header;
  2399. 'I' : verbose:=verbose or v_interface;
  2400. 'M' : verbose:=verbose or v_implementation;
  2401. 'D' : verbose:=verbose or v_defs;
  2402. 'S' : verbose:=verbose or v_syms;
  2403. 'A' : verbose:=verbose or v_all;
  2404. end;
  2405. end;
  2406. 'H' : help;
  2407. '?' : help;
  2408. end;
  2409. inc(startpara);
  2410. end;
  2411. { process files }
  2412. for nrfile:=startpara to paramcount do
  2413. dofile (paramstr(nrfile));
  2414. if has_errors then
  2415. Halt(1);
  2416. if error_on_more and has_more_infos then
  2417. Halt(2);
  2418. end.