ppudump.pp 73 KB

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