ppudump.pp 75 KB

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