ppudump.pp 75 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633
  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[6]=('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'
  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[30];
  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 ;str: 'Java method')
  1069. );
  1070. var
  1071. proctypeoption : tproctypeoption;
  1072. i : longint;
  1073. first : boolean;
  1074. tempbuf : array[0..255] of byte;
  1075. begin
  1076. write(space,' Return type : ');
  1077. readderef('');
  1078. writeln(space,' Fpu used : ',ppufile.getbyte);
  1079. proctypeoption:=tproctypeoption(ppufile.getbyte);
  1080. write(space,' TypeOption : ');
  1081. first:=true;
  1082. for i:=1 to high(proctypeopt) do
  1083. if (proctypeopt[i].mask=proctypeoption) then
  1084. begin
  1085. if first then
  1086. first:=false
  1087. else
  1088. write(', ');
  1089. write(proctypeopt[i].str);
  1090. end;
  1091. writeln;
  1092. proccalloption:=tproccalloption(ppufile.getbyte);
  1093. writeln(space,' CallOption : ',proccalloptionStr[proccalloption]);
  1094. ppufile.getnormalset(procoptions);
  1095. if procoptions<>[] then
  1096. begin
  1097. write(space,' Options : ');
  1098. first:=true;
  1099. for i:=1 to high(procopt) do
  1100. if (procopt[i].mask in procoptions) then
  1101. begin
  1102. if first then
  1103. first:=false
  1104. else
  1105. write(', ');
  1106. write(procopt[i].str);
  1107. end;
  1108. writeln;
  1109. end;
  1110. if (po_explicitparaloc in procoptions) then
  1111. begin
  1112. i:=ppufile.getbyte;
  1113. ppufile.getdata(tempbuf,i);
  1114. end;
  1115. end;
  1116. { type tvaroption is in unit symconst }
  1117. { register variable }
  1118. { type tvarregable is in unit symconst }
  1119. procedure readabstractvarsym(const s:string;var varoptions:tvaroptions);
  1120. type
  1121. tvaropt=record
  1122. mask : tvaroption;
  1123. str : string[30];
  1124. end;
  1125. const
  1126. varopt : array[1..ord(high(tvaroption))] of tvaropt=(
  1127. (mask:vo_is_external; str:'External'),
  1128. (mask:vo_is_dll_var; str:'DLLVar'),
  1129. (mask:vo_is_thread_var; str:'ThreadVar'),
  1130. (mask:vo_has_local_copy; str:'HasLocalCopy'),
  1131. (mask:vo_is_const; str:'Constant'),
  1132. (mask:vo_is_public; str:'Public'),
  1133. (mask:vo_is_high_para; str:'HighValue'),
  1134. (mask:vo_is_funcret; str:'Funcret'),
  1135. (mask:vo_is_self; str:'Self'),
  1136. (mask:vo_is_vmt; str:'VMT'),
  1137. (mask:vo_is_result; str:'Result'),
  1138. (mask:vo_is_parentfp; str:'ParentFP'),
  1139. (mask:vo_is_loop_counter; str:'LoopCounter'),
  1140. (mask:vo_is_hidden_para; str:'Hidden'),
  1141. (mask:vo_has_explicit_paraloc;str:'ExplicitParaloc'),
  1142. (mask:vo_is_syscall_lib; str:'SysCallLib'),
  1143. (mask:vo_has_mangledname; str:'HasMangledName'),
  1144. (mask:vo_is_typed_const; str:'TypedConst'),
  1145. (mask:vo_is_range_check; str:'RangeCheckSwitch'),
  1146. (mask:vo_is_overflow_check; str:'OverflowCheckSwitch'),
  1147. (mask:vo_is_typinfo_para; str:'TypeInfo'),
  1148. (mask:vo_is_msgsel;str:'MsgSel'),
  1149. (mask:vo_is_weak_external;str:'WeakExternal'),
  1150. (mask:vo_is_first_field;str:'IsFirstField'),
  1151. (mask:vo_volatile;str:'Volatile'),
  1152. (mask:vo_has_section;str:'HasSection'),
  1153. (mask:vo_force_finalize;str:'ForceFinalize')
  1154. );
  1155. var
  1156. i : longint;
  1157. first : boolean;
  1158. begin
  1159. readcommonsym(s);
  1160. writeln(space,' Spez : ',Varspez2Str(ppufile.getbyte));
  1161. writeln(space,' Regable : ',Varregable2Str(ppufile.getbyte));
  1162. writeln(space,' Addr Taken : ',(ppufile.getbyte<>0));
  1163. write (space,' Var Type : ');
  1164. readderef('');
  1165. ppufile.getsmallset(varoptions);
  1166. if varoptions<>[] then
  1167. begin
  1168. write(space,' Options : ');
  1169. first:=true;
  1170. for i:=1 to high(varopt) do
  1171. if (varopt[i].mask in varoptions) then
  1172. begin
  1173. if first then
  1174. first:=false
  1175. else
  1176. write(', ');
  1177. write(varopt[i].str);
  1178. if varopt[i].mask = vo_has_section then
  1179. writeln('Section name:',ppufile.getansistring);
  1180. end;
  1181. writeln;
  1182. end;
  1183. end;
  1184. procedure readobjectdefoptions;
  1185. type
  1186. tsymopt=record
  1187. mask : tobjectoption;
  1188. str : string[30];
  1189. end;
  1190. const
  1191. symopt : array[1..ord(high(tobjectoption))] of tsymopt=(
  1192. (mask:oo_is_forward; str:'IsForward'),
  1193. (mask:oo_is_abstract; str:'IsAbstract'),
  1194. (mask:oo_is_sealed; str:'IsSealed'),
  1195. (mask:oo_has_virtual; str:'HasVirtual'),
  1196. (mask:oo_has_private; str:'HasPrivate'),
  1197. (mask:oo_has_protected; str:'HasProtected'),
  1198. (mask:oo_has_strictprivate; str:'HasStrictPrivate'),
  1199. (mask:oo_has_strictprotected;str:'HasStrictProtected'),
  1200. (mask:oo_has_constructor; str:'HasConstructor'),
  1201. (mask:oo_has_destructor; str:'HasDestructor'),
  1202. (mask:oo_has_vmt; str:'HasVMT'),
  1203. (mask:oo_has_msgstr; str:'HasMsgStr'),
  1204. (mask:oo_has_msgint; str:'HasMsgInt'),
  1205. (mask:oo_can_have_published; str:'CanHavePublished'),
  1206. (mask:oo_has_default_property;str:'HasDefaultProperty'),
  1207. (mask:oo_has_valid_guid; str:'HasValidGUID'),
  1208. (mask:oo_has_enumerator_movenext; str:'HasEnumeratorMoveNext'),
  1209. (mask:oo_has_enumerator_current; str:'HasEnumeratorCurrent'),
  1210. (mask:oo_is_external; str:'External'),
  1211. (mask:oo_is_formal; str:'Formal'),
  1212. (mask:oo_is_classhelper; str:'Class Helper/Category'),
  1213. (mask:oo_has_class_constructor; str:'HasClassConstructor'),
  1214. (mask:oo_has_class_destructor; str:'HasClassDestructor')
  1215. );
  1216. var
  1217. i : longint;
  1218. first : boolean;
  1219. begin
  1220. ppufile.getsmallset(current_objectoptions);
  1221. if current_objectoptions<>[] then
  1222. begin
  1223. first:=true;
  1224. for i:=1 to high(symopt) do
  1225. if (symopt[i].mask in current_objectoptions) then
  1226. begin
  1227. if first then
  1228. first:=false
  1229. else
  1230. write(', ');
  1231. write(symopt[i].str);
  1232. end;
  1233. end;
  1234. writeln;
  1235. end;
  1236. procedure readarraydefoptions;
  1237. { type tarraydefoption is in unit symconst }
  1238. type
  1239. tsymopt=record
  1240. mask : tarraydefoption;
  1241. str : string[30];
  1242. end;
  1243. const
  1244. symopt : array[1..ord(high(tarraydefoption))] of tsymopt=(
  1245. (mask:ado_IsConvertedPointer;str:'ConvertedPointer'),
  1246. (mask:ado_IsDynamicArray; str:'IsDynamicArray'),
  1247. (mask:ado_IsVariant; str:'IsVariant'),
  1248. (mask:ado_IsConstructor; str:'IsConstructor'),
  1249. (mask:ado_IsArrayOfConst; str:'ArrayOfConst'),
  1250. (mask:ado_IsConstString; str:'ConstString'),
  1251. (mask:ado_IsBitPacked; str:'BitPacked')
  1252. );
  1253. var
  1254. symoptions : tarraydefoptions;
  1255. i : longint;
  1256. first : boolean;
  1257. begin
  1258. ppufile.getsmallset(symoptions);
  1259. if symoptions<>[] then
  1260. begin
  1261. first:=true;
  1262. for i:=1 to high(symopt) do
  1263. if (symopt[i].mask in symoptions) then
  1264. begin
  1265. if first then
  1266. first:=false
  1267. else
  1268. write(', ');
  1269. write(symopt[i].str);
  1270. end;
  1271. end;
  1272. writeln;
  1273. end;
  1274. procedure readnodetree;
  1275. var
  1276. l : longint;
  1277. p : pointer;
  1278. begin
  1279. with ppufile do
  1280. begin
  1281. if space<>'' then
  1282. Writeln(space,'------ nodetree ------');
  1283. if readentry=ibnodetree then
  1284. begin
  1285. l:=entrysize;
  1286. Writeln(space,'Tree size : ',l);
  1287. { Read data to prevent error that entry is not completly read }
  1288. getmem(p,l);
  1289. getdata(p^,l);
  1290. freemem(p);
  1291. end
  1292. else
  1293. begin
  1294. WriteError('!! ibnodetree not found');
  1295. end;
  1296. end;
  1297. end;
  1298. procedure ReadCreatedObjTypes;
  1299. var
  1300. i,j,
  1301. len,
  1302. bssize: longint;
  1303. bs: pbyte;
  1304. begin
  1305. if ppufile.readentry<>ibcreatedobjtypes then
  1306. begin
  1307. writeln('!! ibcreatedobjtypes entry not found');
  1308. ppufile.skipdata(ppufile.entrysize);
  1309. has_errors:=true;
  1310. exit
  1311. end;
  1312. writeln;
  1313. writeln(space,'WPO info');
  1314. writeln(space,'--------');
  1315. len:=ppufile.getlongint;
  1316. writeln(space,'** Instantiated Object/Class types: ',len,' **');
  1317. space:=space+' ';
  1318. for i:=0 to len-1 do
  1319. readderef(space);
  1320. setlength(space,length(space)-2);
  1321. len:=ppufile.getlongint;
  1322. writeln(space,'** Instantiated ClassRef types: ',len,' **');
  1323. space:=space+' ';
  1324. for i:=0 to len-1 do
  1325. readderef(space);
  1326. setlength(space,length(space)-2);
  1327. len:=ppufile.getlongint;
  1328. writeln(space,'** Possibly instantiated ClassRef types : ',len,' **');
  1329. space:=space+' ';
  1330. for i:=0 to len-1 do
  1331. readderef(space);
  1332. setlength(space,length(space)-2);
  1333. len:=ppufile.getlongint;
  1334. writeln(space,'** Class types with called virtual methods info : ',len,' **');
  1335. space:=space+' ';
  1336. for i:=0 to len-1 do
  1337. begin
  1338. write(space,'Class def : ');
  1339. readderef('');
  1340. write(space+' ','Called vmtentries : ');
  1341. bssize:=ppufile.getlongint;
  1342. getmem(bs,bssize);
  1343. ppufile.readdata(bs^,bssize);
  1344. for j:=0 to bssize*8-1 do
  1345. if (((bs+j shr 3)^ shr (j and 7)) and 1) <> 0 then
  1346. write(j,', ');
  1347. writeln;
  1348. freemem(bs);
  1349. end;
  1350. setlength(space,length(space)-2);
  1351. end;
  1352. {****************************************************************************
  1353. Read Symbols Part
  1354. ****************************************************************************}
  1355. procedure readsymbols(const s:string);
  1356. type
  1357. pguid = ^tguid;
  1358. tguid = packed record
  1359. D1: LongWord;
  1360. D2: Word;
  1361. D3: Word;
  1362. D4: array[0..7] of Byte;
  1363. end;
  1364. var
  1365. b : byte;
  1366. pc : pchar;
  1367. ch : dword;
  1368. startnewline : boolean;
  1369. i,j,len : longint;
  1370. guid : tguid;
  1371. realvalue : extended;
  1372. tempbuf : array[0..127] of char;
  1373. pw : pcompilerwidestring;
  1374. varoptions : tvaroptions;
  1375. begin
  1376. with ppufile do
  1377. begin
  1378. if space<>'' then
  1379. Writeln(space,'------ ',s,' ------');
  1380. if readentry=ibstartsyms then
  1381. begin
  1382. Writeln(space,'Symtable datasize : ',getlongint);
  1383. Writeln(space,'Symtable alignment: ',getlongint);
  1384. end
  1385. else
  1386. Writeln('!! ibstartsym not found');
  1387. repeat
  1388. b:=readentry;
  1389. case b of
  1390. ibunitsym :
  1391. readcommonsym('Unit symbol ');
  1392. iblabelsym :
  1393. readcommonsym('Label symbol ');
  1394. ibtypesym :
  1395. begin
  1396. readcommonsym('Type symbol ');
  1397. write(space,' Result Type : ');
  1398. readderef('');
  1399. end;
  1400. ibprocsym :
  1401. begin
  1402. readcommonsym('Procedure symbol ');
  1403. len:=ppufile.getword;
  1404. for i:=1 to len do
  1405. begin
  1406. write(space,' Definition : ');
  1407. readderef('');
  1408. end;
  1409. end;
  1410. ibconstsym :
  1411. begin
  1412. readcommonsym('Constant symbol ');
  1413. b:=getbyte;
  1414. case tconsttyp(b) of
  1415. constord :
  1416. begin
  1417. write (space,' OrdinalType : ');
  1418. readderef('');
  1419. writeln(space,' Value : ',constexp.tostr(getexprint));
  1420. end;
  1421. constpointer :
  1422. begin
  1423. write (space,' PointerType : ');
  1424. readderef('');
  1425. writeln(space,' Value : ',getaint)
  1426. end;
  1427. conststring,
  1428. constresourcestring :
  1429. begin
  1430. len:=getlongint;
  1431. getmem(pc,len+1);
  1432. getdata(pc^,len);
  1433. (pc+len)^:= #0;
  1434. writeln(space,' Length : ',len);
  1435. writeln(space,' Value : "',pc,'"');
  1436. freemem(pc,len+1);
  1437. end;
  1438. constreal :
  1439. begin
  1440. if entryleft=sizeof(extended) then
  1441. realvalue:=getrealsize(sizeof(extended))
  1442. else if entryleft=sizeof(double) then
  1443. realvalue:=getrealsize(sizeof(double))
  1444. else
  1445. begin
  1446. realvalue:=0.0;
  1447. has_errors:=true;
  1448. end;
  1449. writeln(space,' Value : ',realvalue);
  1450. end;
  1451. constset :
  1452. begin
  1453. write (space,' Set Type : ');
  1454. readderef('');
  1455. for i:=1to 4 do
  1456. begin
  1457. write (space,' Value : ');
  1458. for j:=1to 8 do
  1459. begin
  1460. if j>1 then
  1461. write(',');
  1462. write(hexstr(getbyte,2));
  1463. end;
  1464. writeln;
  1465. end;
  1466. end;
  1467. constnil:
  1468. writeln(space,' NIL pointer.');
  1469. constwstring :
  1470. begin
  1471. initwidestring(pw);
  1472. setlengthwidestring(pw,getlongint);
  1473. if widecharsize=2 then
  1474. { don't use getdata, because the compilerwidechars may have to
  1475. be byteswapped
  1476. }
  1477. begin
  1478. for i:=0 to pw^.len-1 do
  1479. pw^.data[i]:=ppufile.getword;
  1480. end
  1481. else if widecharsize=4 then
  1482. begin
  1483. for i:=0 to pw^.len-1 do
  1484. pw^.data[i]:=cardinal(ppufile.getlongint);
  1485. end
  1486. else
  1487. begin
  1488. WriteError('Unsupported tcompilerwidechar size');
  1489. end;
  1490. Writeln(space,'Wide string type');
  1491. startnewline:=true;
  1492. for i:=0 to pw^.len-1 do
  1493. begin
  1494. if startnewline then
  1495. begin
  1496. write(space);
  1497. startnewline:=false;
  1498. end;
  1499. ch:=pw^.data[i];
  1500. if widecharsize=2 then
  1501. write(hexstr(ch,4))
  1502. else
  1503. write(hexstr(ch,8));
  1504. if (i mod 8)= 0 then
  1505. startnewline:=true
  1506. else
  1507. write(', ');
  1508. end;
  1509. donewidestring(pw);
  1510. end;
  1511. constguid:
  1512. begin
  1513. getdata(guid,sizeof(guid));
  1514. write (space,' IID String: {',hexstr(guid.d1,8),'-',hexstr(guid.d2,4),'-',hexstr(guid.d3,4),'-');
  1515. for i:=0 to 7 do
  1516. begin
  1517. write(hexstr(guid.d4[i],2));
  1518. if i=1 then write('-');
  1519. end;
  1520. writeln('}');
  1521. end
  1522. else
  1523. Writeln ('!! Invalid unit format : Invalid const type encountered: ',b);
  1524. end;
  1525. end;
  1526. ibabsolutevarsym :
  1527. begin
  1528. readabstractvarsym('Absolute variable symbol ',varoptions);
  1529. Write (space,' Relocated to ');
  1530. b:=getbyte;
  1531. case absolutetyp(b) of
  1532. tovar :
  1533. readpropaccesslist(space+' Sym : ');
  1534. toasm :
  1535. Writeln('Assembler name : ',getstring);
  1536. toaddr :
  1537. begin
  1538. Write('Address : ',getlongint);
  1539. if tsystemcpu(ppufile.header.cpu)=cpu_i386 then
  1540. WriteLn(' (Far: ',getbyte<>0,')');
  1541. end;
  1542. else
  1543. Writeln ('!! Invalid unit format : Invalid absolute type encountered: ',b);
  1544. end;
  1545. end;
  1546. ibfieldvarsym :
  1547. begin
  1548. readabstractvarsym('Field Variable symbol ',varoptions);
  1549. writeln(space,' Address : ',getaint);
  1550. end;
  1551. ibstaticvarsym :
  1552. begin
  1553. readabstractvarsym('Global Variable symbol ',varoptions);
  1554. write (space,' DefaultConst : ');
  1555. readderef('');
  1556. if (vo_has_mangledname in varoptions) then
  1557. {$ifdef symansistr}
  1558. writeln(space,' Mangledname : ',getansistring);
  1559. {$else symansistr}
  1560. writeln(space,' Mangledname : ',getstring);
  1561. {$endif symansistr}
  1562. end;
  1563. iblocalvarsym :
  1564. begin
  1565. readabstractvarsym('Local Variable symbol ',varoptions);
  1566. write (space,' DefaultConst : ');
  1567. readderef('');
  1568. end;
  1569. ibparavarsym :
  1570. begin
  1571. readabstractvarsym('Parameter Variable symbol ',varoptions);
  1572. write (space,' DefaultConst : ');
  1573. readderef('');
  1574. writeln(space,' ParaNr : ',getword);
  1575. writeln(space,' Univ : ',boolean(getbyte));
  1576. writeln(space,' VarState : ',getbyte);
  1577. if (vo_has_explicit_paraloc in varoptions) then
  1578. begin
  1579. i:=getbyte;
  1580. getdata(tempbuf,i);
  1581. end;
  1582. end;
  1583. ibenumsym :
  1584. begin
  1585. readcommonsym('Enumeration symbol ');
  1586. write (space,' Definition : ');
  1587. readderef('');
  1588. writeln(space,' Value : ',getlongint);
  1589. end;
  1590. ibsyssym :
  1591. begin
  1592. readcommonsym('Internal system symbol ');
  1593. writeln(space,' Internal Nr : ',getlongint);
  1594. end;
  1595. ibmacrosym :
  1596. begin
  1597. readcommonsym('Macro symbol ');
  1598. writeln(space,' Name: ',getstring);
  1599. writeln(space,' Defined: ',getbyte);
  1600. writeln(space,' Compiler var: ',getbyte);
  1601. len:=getlongint;
  1602. writeln(space,' Value length: ',len);
  1603. if len > 0 then
  1604. begin
  1605. getmem(pc,len+1);
  1606. getdata(pc^,len);
  1607. (pc+len)^:= #0;
  1608. writeln(space,' Value: "',pc,'"');
  1609. freemem(pc,len+1);
  1610. end;
  1611. end;
  1612. ibpropertysym :
  1613. begin
  1614. readcommonsym('Property ');
  1615. i:=getlongint;
  1616. writeln(space,' PropOptions : ',i);
  1617. write (space,' OverrideProp : ');
  1618. readderef('');
  1619. write (space,' Prop Type : ');
  1620. readderef('');
  1621. writeln(space,' Index : ',getlongint);
  1622. writeln(space,' Default : ',getlongint);
  1623. write (space,' Index Type : ');
  1624. readderef('');
  1625. { palt_none }
  1626. readpropaccesslist('');
  1627. write (space,' Readaccess : ');
  1628. readpropaccesslist(space+' Sym: ');
  1629. write (space,' Writeaccess : ');
  1630. readpropaccesslist(space+' Sym: ');
  1631. write (space,' Storedaccess : ');
  1632. readpropaccesslist(space+' Sym: ');
  1633. end;
  1634. iberror :
  1635. begin
  1636. WriteError('!! Error in PPU');
  1637. exit;
  1638. end;
  1639. ibendsyms :
  1640. break;
  1641. else
  1642. begin
  1643. WriteLn('!! Skipping unsupported PPU Entry in Symbols: ',b);
  1644. has_errors:=true;
  1645. end;
  1646. end;
  1647. if not EndOfEntry then
  1648. HasMoreInfos;
  1649. until false;
  1650. end;
  1651. end;
  1652. {****************************************************************************
  1653. Read defintions Part
  1654. ****************************************************************************}
  1655. procedure readdefinitions(const s:string);
  1656. { type tordtype is in symconst unit }
  1657. {
  1658. uvoid,
  1659. u8bit,u16bit,u32bit,u64bit,
  1660. s8bit,s16bit,s32bit,s64bit,
  1661. bool8bit,bool16bit,bool32bit,bool64bit,
  1662. uchar,uwidechar,scurrency
  1663. ); }
  1664. { type tobjecttyp is in symconst unit }
  1665. { type tvarianttype is in symconst unit }
  1666. var
  1667. b : byte;
  1668. l,j : longint;
  1669. calloption : tproccalloption;
  1670. procoptions : tprocoptions;
  1671. procinfooptions : tprocinfoflag;
  1672. defoptions: tdefoptions;
  1673. begin
  1674. with ppufile do
  1675. begin
  1676. if space<>'' then
  1677. Writeln(space,'------ ',s,' ------');
  1678. if readentry<>ibstartdefs then
  1679. Writeln('!! ibstartdefs not found');
  1680. repeat
  1681. b:=readentry;
  1682. case b of
  1683. ibpointerdef :
  1684. begin
  1685. readcommondef('Pointer definition',defoptions);
  1686. write (space,' Pointed Type : ');
  1687. readderef('');
  1688. writeln(space,' Is Far : ',(getbyte<>0));
  1689. writeln(space,' Has Pointer Math : ',(getbyte<>0));
  1690. end;
  1691. iborddef :
  1692. begin
  1693. readcommondef('Ordinal definition',defoptions);
  1694. write (space,' Base type : ');
  1695. b:=getbyte;
  1696. case tordtype(b) of
  1697. uvoid : writeln('uvoid');
  1698. u8bit : writeln('u8bit');
  1699. u16bit : writeln('u16bit');
  1700. u32bit : writeln('s32bit');
  1701. u64bit : writeln('u64bit');
  1702. s8bit : writeln('s8bit');
  1703. s16bit : writeln('s16bit');
  1704. s32bit : writeln('s32bit');
  1705. s64bit : writeln('s64bit');
  1706. bool8bit : writeln('bool8bit');
  1707. bool16bit : writeln('bool16bit');
  1708. bool32bit : writeln('bool32bit');
  1709. bool64bit : writeln('bool64bit');
  1710. uchar : writeln('uchar');
  1711. uwidechar : writeln('uwidechar');
  1712. scurrency : writeln('ucurrency');
  1713. else writeln('!! Warning: Invalid base type ',b);
  1714. end;
  1715. writeln(space,' Range : ',constexp.tostr(getexprint),' to ',constexp.tostr(getexprint));
  1716. end;
  1717. ibfloatdef :
  1718. begin
  1719. readcommondef('Float definition',defoptions);
  1720. writeln(space,' Float type : ',getbyte);
  1721. end;
  1722. ibarraydef :
  1723. begin
  1724. readcommondef('Array definition',defoptions);
  1725. write (space,' Element type : ');
  1726. readderef('');
  1727. write (space,' Range Type : ');
  1728. readderef('');
  1729. writeln(space,' Range : ',getaint,' to ',getaint);
  1730. write (space,' Options : ');
  1731. readarraydefoptions;
  1732. readsymtableoptions('symbols');
  1733. readdefinitions('symbols');
  1734. readsymbols('symbols');
  1735. end;
  1736. ibprocdef :
  1737. begin
  1738. readcommondef('Procedure definition',defoptions);
  1739. read_abstract_proc_def(calloption,procoptions);
  1740. if (po_has_mangledname in procoptions) then
  1741. {$ifdef symansistr}
  1742. writeln(space,' Mangled name : ',getansistring);
  1743. {$else symansistr}
  1744. writeln(space,' Mangled name : ',getstring);
  1745. {$endif symansistr}
  1746. writeln(space,' Number : ',getword);
  1747. writeln(space,' Level : ',getbyte);
  1748. write (space,' Class : ');
  1749. readderef('');
  1750. write (space,' Procsym : ');
  1751. readderef('');
  1752. write (space,' File Pos : ');
  1753. readposinfo;
  1754. writeln(space,' Visibility : ',Visibility2Str(ppufile.getbyte));
  1755. write (space,' SymOptions : ');
  1756. readsymoptions(space+' ');
  1757. if tsystemcpu(ppufile.header.cpu)=cpu_powerpc then
  1758. begin
  1759. { library symbol for AmigaOS/MorphOS }
  1760. write (space,' Library symbol : ');
  1761. readderef('');
  1762. end;
  1763. if (po_has_importdll in procoptions) then
  1764. writeln(space,' Import DLL : ',getstring);
  1765. if (po_has_importname in procoptions) then
  1766. writeln(space,' Import Name : ',getstring);
  1767. writeln(space,' Import Nr : ',getword);
  1768. if (po_msgint in procoptions) then
  1769. writeln(space,' MsgInt : ',getlongint);
  1770. if (po_msgstr in procoptions) then
  1771. writeln(space,' MsgStr : ',getstring);
  1772. if (po_dispid in procoptions) then
  1773. writeln(space,' DispID: ',ppufile.getlongint);
  1774. if (po_has_inlininginfo in procoptions) then
  1775. begin
  1776. write (space,' FuncretSym : ');
  1777. readderef('');
  1778. ppufile.getsmallset(procinfooptions);
  1779. writeln(space,' ProcInfoOptions : ',dword(procinfooptions));
  1780. end;
  1781. b:=ppufile.getbyte;
  1782. if b<>0 then
  1783. begin
  1784. write (space,' Alias names : ');
  1785. for j:=1 to b do
  1786. begin
  1787. write(ppufile.getstring);
  1788. if j<b then
  1789. write(', ');
  1790. end;
  1791. writeln;
  1792. end;
  1793. if not EndOfEntry then
  1794. HasMoreInfos;
  1795. space:=' '+space;
  1796. { parast }
  1797. readsymtableoptions('parast');
  1798. readdefinitions('parast');
  1799. readsymbols('parast');
  1800. { localst }
  1801. if (po_has_inlininginfo in procoptions) then
  1802. begin
  1803. readsymtableoptions('localst');
  1804. readdefinitions('localst');
  1805. readsymbols('localst');
  1806. end;
  1807. if (po_has_inlininginfo in procoptions) then
  1808. readnodetree;
  1809. delete(space,1,4);
  1810. end;
  1811. ibprocvardef :
  1812. begin
  1813. readcommondef('Procedural type (ProcVar) definition',defoptions);
  1814. read_abstract_proc_def(calloption,procoptions);
  1815. writeln(space,' Symtable level :',ppufile.getbyte);
  1816. if not EndOfEntry then
  1817. HasMoreInfos;
  1818. space:=' '+space;
  1819. { parast }
  1820. readsymtableoptions('parast');
  1821. readdefinitions('parast');
  1822. readsymbols('parast');
  1823. delete(space,1,4);
  1824. end;
  1825. ibshortstringdef :
  1826. begin
  1827. readcommondef('ShortString definition',defoptions);
  1828. writeln(space,' Length : ',getbyte);
  1829. end;
  1830. ibwidestringdef :
  1831. begin
  1832. readcommondef('WideString definition',defoptions);
  1833. writeln(space,' Length : ',getaint);
  1834. end;
  1835. ibunicodestringdef :
  1836. begin
  1837. readcommondef('UnicodeString definition',defoptions);
  1838. writeln(space,' Length : ',getaint);
  1839. end;
  1840. ibansistringdef :
  1841. begin
  1842. readcommondef('AnsiString definition',defoptions);
  1843. writeln(space,' Length : ',getaint);
  1844. end;
  1845. iblongstringdef :
  1846. begin
  1847. readcommondef('Longstring definition',defoptions);
  1848. writeln(space,' Length : ',getaint);
  1849. end;
  1850. ibrecorddef :
  1851. begin
  1852. readcommondef('Record definition',defoptions);
  1853. writeln(space,' Name of Record : ',getstring);
  1854. writeln(space,' Import lib/pkg : ',getstring);
  1855. write (space,' Options : ');
  1856. readobjectdefoptions;
  1857. if (df_copied_def in defoptions) then
  1858. begin
  1859. write(space,' Copied from : ');
  1860. readderef('');
  1861. end
  1862. else
  1863. begin
  1864. writeln(space,' FieldAlign : ',shortint(getbyte));
  1865. writeln(space,' RecordAlign : ',shortint(getbyte));
  1866. writeln(space,' PadAlign : ',shortint(getbyte));
  1867. writeln(space,'UseFieldAlignment : ',shortint(getbyte));
  1868. writeln(space,' DataSize : ',getasizeint);
  1869. writeln(space,' PaddingSize : ',getword);
  1870. end;
  1871. if not EndOfEntry then
  1872. HasMoreInfos;
  1873. {read the record definitions and symbols}
  1874. space:=' '+space;
  1875. readrecsymtableoptions;
  1876. readsymtableoptions('fields');
  1877. readdefinitions('fields');
  1878. readsymbols('fields');
  1879. Delete(space,1,4);
  1880. end;
  1881. ibobjectdef :
  1882. begin
  1883. readcommondef('Object/Class definition',defoptions);
  1884. writeln(space,' Name of Class : ',getstring);
  1885. writeln(space,' Import lib/pkg : ',getstring);
  1886. write (space,' Options : ');
  1887. readobjectdefoptions;
  1888. b:=getbyte;
  1889. write (space,' Type : ');
  1890. case tobjecttyp(b) of
  1891. odt_class : writeln('class');
  1892. odt_object : writeln('object');
  1893. odt_interfacecom : writeln('interfacecom');
  1894. odt_interfacecorba : writeln('interfacecorba');
  1895. odt_cppclass : writeln('cppclass');
  1896. odt_dispinterface : writeln('dispinterface');
  1897. odt_objcclass : writeln('objcclass');
  1898. odt_objcprotocol : writeln('objcprotocol');
  1899. odt_helper : writeln('helper');
  1900. odt_objccategory : writeln('objccategory');
  1901. odt_javaclass : writeln('Java class');
  1902. odt_interfacejava : writeln('Java interface');
  1903. else writeln('!! Warning: Invalid object type ',b);
  1904. end;
  1905. writeln(space,' External name : ',getstring);
  1906. writeln(space,' DataSize : ',getasizeint);
  1907. writeln(space,' PaddingSize : ',getword);
  1908. writeln(space,' FieldAlign : ',shortint(getbyte));
  1909. writeln(space,' RecordAlign : ',shortint(getbyte));
  1910. writeln(space,' Vmt offset : ',getlongint);
  1911. write (space, ' Ancestor Class : ');
  1912. readderef('');
  1913. if tobjecttyp(b) in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  1914. begin
  1915. { IIDGUID }
  1916. for j:=1to 16 do
  1917. getbyte;
  1918. writeln(space,' IID String : ',getstring);
  1919. end;
  1920. if (tobjecttyp(b)=odt_helper) or
  1921. (oo_is_classhelper in current_objectoptions) then
  1922. begin
  1923. write(space,' Helper parent : ');
  1924. readderef('');
  1925. end;
  1926. l:=getlongint;
  1927. writeln(space,' VMT entries: ',l);
  1928. for j:=1 to l do
  1929. begin
  1930. write(space,' ');
  1931. readderef('');
  1932. writeln(space,' Visibility: ',Visibility2Str(getbyte));
  1933. end;
  1934. if tobjecttyp(b) in [odt_class,odt_interfacecorba,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava] then
  1935. begin
  1936. l:=getlongint;
  1937. writeln(space,' Impl Intf Count : ',l);
  1938. for j:=1 to l do
  1939. begin
  1940. write (space,' - Definition : ');
  1941. readderef('');
  1942. writeln(space,' IOffset : ',getlongint);
  1943. end;
  1944. end;
  1945. if df_copied_def in current_defoptions then
  1946. begin
  1947. writeln(' Copy of def: ');
  1948. readderef('');
  1949. end;
  1950. if not EndOfEntry then
  1951. HasMoreInfos;
  1952. if not(df_copied_def in current_defoptions) then
  1953. begin
  1954. {read the record definitions and symbols}
  1955. space:=' '+space;
  1956. readrecsymtableoptions;
  1957. readsymtableoptions('fields');
  1958. readdefinitions('fields');
  1959. readsymbols('fields');
  1960. Delete(space,1,4);
  1961. end;
  1962. end;
  1963. ibfiledef :
  1964. begin
  1965. ReadCommonDef('File definition',defoptions);
  1966. write (space,' Type : ');
  1967. case getbyte of
  1968. 0 : writeln('Text');
  1969. 1 : begin
  1970. writeln('Typed');
  1971. write (space,' File of Type : ');
  1972. readderef('');
  1973. end;
  1974. 2 : writeln('Untyped');
  1975. end;
  1976. end;
  1977. ibformaldef :
  1978. begin
  1979. readcommondef('Generic definition (void-typ)',defoptions);
  1980. writeln(space,' Is Typed : ',(getbyte<>0));
  1981. end;
  1982. ibundefineddef :
  1983. readcommondef('Undefined definition (generic parameter)',defoptions);
  1984. ibenumdef :
  1985. begin
  1986. readcommondef('Enumeration type definition',defoptions);
  1987. writeln(space,' Smallest element : ',getaint);
  1988. writeln(space,' Largest element : ',getaint);
  1989. writeln(space,' Size : ',getaint);
  1990. {$ifdef jvm}
  1991. write(space,' Class def : ');
  1992. readderef('');
  1993. {$endif}
  1994. if df_copied_def in defoptions then
  1995. begin
  1996. write(space,'Base enumeration type : ');
  1997. readderef('');
  1998. end
  1999. else
  2000. begin
  2001. space:=' '+space;
  2002. readsymtableoptions('elements');
  2003. readdefinitions('elements');
  2004. readsymbols('elements');
  2005. delete(space,1,4);
  2006. end;
  2007. end;
  2008. ibclassrefdef :
  2009. begin
  2010. readcommondef('Class reference definition',defoptions);
  2011. write (space,' Pointed Type : ');
  2012. readderef('');
  2013. end;
  2014. ibsetdef :
  2015. begin
  2016. readcommondef('Set definition',defoptions);
  2017. write (space,' Element type : ');
  2018. readderef('');
  2019. writeln(space,' Size : ',getaint);
  2020. writeln(space,' Set Base : ',getaint);
  2021. writeln(space,' Set Max : ',getaint);
  2022. end;
  2023. ibvariantdef :
  2024. begin
  2025. readcommondef('Variant definition',defoptions);
  2026. write (space,' Varianttype : ');
  2027. b:=getbyte;
  2028. case tvarianttype(b) of
  2029. vt_normalvariant :
  2030. writeln('Normal');
  2031. vt_olevariant :
  2032. writeln('OLE');
  2033. else
  2034. writeln('!! Warning: Invalid varianttype ',b);
  2035. end;
  2036. end;
  2037. iberror :
  2038. begin
  2039. WriteError('!! Error in PPU');
  2040. exit;
  2041. end;
  2042. ibenddefs :
  2043. break;
  2044. else
  2045. begin
  2046. WriteLn('!! Skipping unsupported PPU Entry in definitions: ',b);
  2047. has_errors:=true;
  2048. end;
  2049. end;
  2050. if not EndOfEntry then
  2051. HasMoreInfos;
  2052. until false;
  2053. end;
  2054. end;
  2055. procedure readmoduleoptions(space : string);
  2056. type
  2057. { tmoduleoption type is in unit fmodule }
  2058. tmoduleoption = (mo_none,
  2059. mo_hint_deprecated,
  2060. mo_hint_platform,
  2061. mo_hint_library,
  2062. mo_hint_unimplemented,
  2063. mo_hint_experimental,
  2064. mo_has_deprecated_msg
  2065. );
  2066. tmoduleoptions = set of tmoduleoption;
  2067. tmoduleopt=record
  2068. mask : tmoduleoption;
  2069. str : string[30];
  2070. end;
  2071. const
  2072. moduleopts=ord(high(tmoduleoption));
  2073. moduleopt : array[1..moduleopts] of tmoduleopt=(
  2074. (mask:mo_hint_deprecated; str:'Hint Deprecated'),
  2075. (mask:mo_hint_platform; str:'Hint Platform'),
  2076. (mask:mo_hint_library; str:'Hint Library'),
  2077. (mask:mo_hint_unimplemented; str:'Hint Unimplemented'),
  2078. (mask:mo_hint_experimental; str:'Hint Experimental'),
  2079. (mask:mo_has_deprecated_msg; str:'Has Deprecated Message')
  2080. );
  2081. var
  2082. moduleoptions : tmoduleoptions;
  2083. i : longint;
  2084. first : boolean;
  2085. begin
  2086. ppufile.getsmallset(moduleoptions);
  2087. if moduleoptions<>[] then
  2088. begin
  2089. first:=true;
  2090. for i:=1to moduleopts do
  2091. if (moduleopt[i].mask in moduleoptions) then
  2092. begin
  2093. if first then
  2094. first:=false
  2095. else
  2096. write(', ');
  2097. write(moduleopt[i].str);
  2098. end;
  2099. end;
  2100. writeln;
  2101. if mo_has_deprecated_msg in moduleoptions then
  2102. writeln(space,'Deprecated : ', ppufile.getstring);
  2103. end;
  2104. {****************************************************************************
  2105. Read General Part
  2106. ****************************************************************************}
  2107. procedure readinterface;
  2108. var
  2109. b : byte;
  2110. sourcenumber : longint;
  2111. begin
  2112. with ppufile do
  2113. begin
  2114. repeat
  2115. b:=readentry;
  2116. case b of
  2117. ibmodulename :
  2118. Writeln('Module Name: ',getstring);
  2119. ibmoduleoptions:
  2120. readmoduleoptions(' ');
  2121. ibsourcefiles :
  2122. begin
  2123. sourcenumber:=1;
  2124. while not EndOfEntry do
  2125. begin
  2126. Writeln('Source file ',sourcenumber,' : ',getstring,' ',filetimestring(getlongint));
  2127. inc(sourcenumber);
  2128. end;
  2129. end;
  2130. {$IFDEF MACRO_DIFF_HINT}
  2131. ibusedmacros :
  2132. begin
  2133. while not EndOfEntry do
  2134. begin
  2135. Write('Conditional ',getstring);
  2136. b:=getbyte;
  2137. if boolean(b)=true then
  2138. write(' defined at startup')
  2139. else
  2140. write(' not defined at startup');
  2141. b:=getbyte;
  2142. if boolean(b)=true then
  2143. writeln(' was used')
  2144. else
  2145. writeln;
  2146. end;
  2147. end;
  2148. {$ENDIF}
  2149. ibloadunit :
  2150. ReadLoadUnit;
  2151. iblinkunitofiles :
  2152. ReadLinkContainer('Link unit object file: ');
  2153. iblinkunitstaticlibs :
  2154. ReadLinkContainer('Link unit static lib: ');
  2155. iblinkunitsharedlibs :
  2156. ReadLinkContainer('Link unit shared lib: ');
  2157. iblinkotherofiles :
  2158. ReadLinkContainer('Link other object file: ');
  2159. iblinkotherstaticlibs :
  2160. ReadLinkContainer('Link other static lib: ');
  2161. iblinkothersharedlibs :
  2162. ReadLinkContainer('Link other shared lib: ');
  2163. iblinkotherframeworks:
  2164. ReadLinkContainer('Link framework: ');
  2165. ibmainname:
  2166. Writeln('Specified main program symbol name: ',getstring);
  2167. ibImportSymbols :
  2168. ReadImportSymbols;
  2169. ibderefdata :
  2170. ReadDerefData;
  2171. ibderefmap :
  2172. ReadDerefMap;
  2173. ibwpofile :
  2174. ReadWpoFileInfo;
  2175. ibresources :
  2176. ReadLinkContainer('Resource file: ');
  2177. iberror :
  2178. begin
  2179. WriteError('Error in PPU');
  2180. exit;
  2181. end;
  2182. ibendinterface :
  2183. break;
  2184. else
  2185. begin
  2186. WriteLn('!! Skipping unsupported PPU Entry in General Part: ',b);
  2187. has_errors:=true;
  2188. end;
  2189. end;
  2190. until false;
  2191. end;
  2192. end;
  2193. {****************************************************************************
  2194. Read Implementation Part
  2195. ****************************************************************************}
  2196. procedure readimplementation;
  2197. var
  2198. b : byte;
  2199. begin
  2200. with ppufile do
  2201. begin
  2202. repeat
  2203. b:=readentry;
  2204. case b of
  2205. ibasmsymbols :
  2206. ReadAsmSymbols;
  2207. ibloadunit :
  2208. ReadLoadUnit;
  2209. iberror :
  2210. begin
  2211. WriteError('Error in PPU');
  2212. exit;
  2213. end;
  2214. ibendimplementation :
  2215. break;
  2216. else
  2217. begin
  2218. WriteLn('!! Skipping unsupported PPU Entry in Implementation: ',b);
  2219. has_errors:=true;
  2220. end;
  2221. end;
  2222. until false;
  2223. end;
  2224. end;
  2225. procedure dofile (filename : string);
  2226. begin
  2227. { reset }
  2228. space:='';
  2229. { fix filename }
  2230. if pos('.',filename)=0 then
  2231. filename:=filename+'.ppu';
  2232. ppufile:=tppufile.create(filename);
  2233. if not ppufile.openfile then
  2234. begin
  2235. WriteError('IO-Error when opening : '+filename+', Skipping');
  2236. exit;
  2237. end;
  2238. { PPU File is open, check for PPU Id }
  2239. if not ppufile.CheckPPUID then
  2240. begin
  2241. writeln(Filename,' : Not a valid PPU file, Skipping');
  2242. has_errors:=true;
  2243. exit;
  2244. end;
  2245. { Check PPU Version }
  2246. ppuversion:=ppufile.GetPPUVersion;
  2247. Writeln('Analyzing ',filename,' (v',PPUVersion,')');
  2248. if PPUVersion<16 then
  2249. begin
  2250. writeln(Filename,' : Old PPU Formats (<v16) are not supported, Skipping');
  2251. has_errors:=true;
  2252. exit;
  2253. end;
  2254. { Write PPU Header Information }
  2255. if (verbose and v_header)<>0 then
  2256. begin
  2257. Writeln;
  2258. Writeln('Header');
  2259. Writeln('-------');
  2260. with ppufile.header do
  2261. begin
  2262. Writeln('Compiler version : ',ppufile.header.compiler shr 14,'.',
  2263. (ppufile.header.compiler shr 7) and $7f,'.',
  2264. ppufile.header.compiler and $7f);
  2265. WriteLn('Target processor : ',Cpu2Str(cpu));
  2266. WriteLn('Target operating system : ',Target2Str(target));
  2267. Writeln('Unit flags : ',PPUFlags2Str(flags));
  2268. Writeln('FileSize (w/o header) : ',size);
  2269. Writeln('Checksum : ',hexstr(checksum,8));
  2270. Writeln('Interface Checksum : ',hexstr(interface_checksum,8));
  2271. Writeln('Indirect Checksum : ',hexstr(indirect_checksum,8));
  2272. Writeln('Definitions stored : ',tostr(deflistsize));
  2273. Writeln('Symbols stored : ',tostr(symlistsize));
  2274. end;
  2275. end;
  2276. {read the general stuff}
  2277. if (verbose and v_interface)<>0 then
  2278. begin
  2279. Writeln;
  2280. Writeln('Interface section');
  2281. Writeln('------------------');
  2282. readinterface;
  2283. end
  2284. else
  2285. ppufile.skipuntilentry(ibendinterface);
  2286. Writeln;
  2287. Writeln('Interface symtable');
  2288. Writeln('----------------------');
  2289. readsymtableoptions('interface');
  2290. {read the definitions}
  2291. if (verbose and v_defs)<>0 then
  2292. begin
  2293. Writeln;
  2294. Writeln('Interface definitions');
  2295. Writeln('----------------------');
  2296. readdefinitions('interface');
  2297. end
  2298. else
  2299. ppufile.skipuntilentry(ibenddefs);
  2300. {read the symbols}
  2301. if (verbose and v_syms)<>0 then
  2302. begin
  2303. Writeln;
  2304. Writeln('Interface Symbols');
  2305. Writeln('------------------');
  2306. readsymbols('interface');
  2307. end
  2308. else
  2309. ppufile.skipuntilentry(ibendsyms);
  2310. {read the macro symbols}
  2311. if (verbose and v_syms)<>0 then
  2312. begin
  2313. Writeln;
  2314. Writeln('Interface Macro Symbols');
  2315. Writeln('-----------------------');
  2316. end;
  2317. if ppufile.readentry<>ibexportedmacros then
  2318. begin
  2319. WriteError('!! Error in PPU');
  2320. exit;
  2321. end;
  2322. if boolean(ppufile.getbyte) then
  2323. begin
  2324. readsymtableoptions('interface macro');
  2325. {skip the definition section for macros (since they are never used) }
  2326. ppufile.skipuntilentry(ibenddefs);
  2327. {read the macro symbols}
  2328. if (verbose and v_syms)<>0 then
  2329. readsymbols('interface macro')
  2330. else
  2331. ppufile.skipuntilentry(ibendsyms);
  2332. end
  2333. else
  2334. Writeln('(no exported macros)');
  2335. {read the implementation stuff}
  2336. if (verbose and v_implementation)<>0 then
  2337. begin
  2338. Writeln;
  2339. Writeln('Implementation section');
  2340. Writeln('-----------------------');
  2341. readimplementation;
  2342. end
  2343. else
  2344. ppufile.skipuntilentry(ibendimplementation);
  2345. {read the static symtable}
  2346. Writeln;
  2347. Writeln('Implementation symtable');
  2348. Writeln('----------------------');
  2349. readsymtableoptions('implementation');
  2350. if (ppufile.header.flags and uf_local_symtable)<>0 then
  2351. begin
  2352. if (verbose and v_defs)<>0 then
  2353. begin
  2354. Writeln;
  2355. Writeln('Static definitions');
  2356. Writeln('----------------------');
  2357. readdefinitions('implementation');
  2358. end
  2359. else
  2360. ppufile.skipuntilentry(ibenddefs);
  2361. {read the symbols}
  2362. if (verbose and v_syms)<>0 then
  2363. begin
  2364. Writeln;
  2365. Writeln('Static Symbols');
  2366. Writeln('------------------');
  2367. readsymbols('implementation');
  2368. end
  2369. else
  2370. ppufile.skipuntilentry(ibendsyms);
  2371. end;
  2372. ReadCreatedObjTypes;
  2373. FreeDerefdata;
  2374. {shutdown ppufile}
  2375. ppufile.closefile;
  2376. ppufile.free;
  2377. Writeln;
  2378. end;
  2379. procedure help;
  2380. begin
  2381. writeln('usage: ppudump [options] <filename1> <filename2>...');
  2382. writeln;
  2383. writeln('[options] can be:');
  2384. writeln(' -M Exit with ExitCode=2 if more information is available');
  2385. writeln(' -V<verbose> Set verbosity to <verbose>');
  2386. writeln(' H - Show header info');
  2387. writeln(' I - Show interface');
  2388. writeln(' M - Show implementation');
  2389. writeln(' S - Show interface symbols');
  2390. writeln(' D - Show interface definitions');
  2391. // writeln(' B - Show browser info');
  2392. writeln(' A - Show all');
  2393. writeln(' -h, -? This helpscreen');
  2394. halt;
  2395. end;
  2396. var
  2397. startpara,
  2398. nrfile,i : longint;
  2399. para : string;
  2400. const
  2401. error_on_more : boolean = false;
  2402. begin
  2403. writeln(Title+' '+Version);
  2404. writeln(Copyright);
  2405. writeln;
  2406. if paramcount<1 then
  2407. begin
  2408. writeln('usage: dumpppu [options] <filename1> <filename2>...');
  2409. halt(1);
  2410. end;
  2411. { turn verbose on by default }
  2412. verbose:=v_all;
  2413. { read options }
  2414. startpara:=1;
  2415. while copy(paramstr(startpara),1,1)='-' do
  2416. begin
  2417. para:=paramstr(startpara);
  2418. case upcase(para[2]) of
  2419. 'M' : error_on_more:=true;
  2420. 'V' : begin
  2421. verbose:=0;
  2422. for i:=3 to length(para) do
  2423. case upcase(para[i]) of
  2424. 'H' : verbose:=verbose or v_header;
  2425. 'I' : verbose:=verbose or v_interface;
  2426. 'M' : verbose:=verbose or v_implementation;
  2427. 'D' : verbose:=verbose or v_defs;
  2428. 'S' : verbose:=verbose or v_syms;
  2429. 'A' : verbose:=verbose or v_all;
  2430. end;
  2431. end;
  2432. 'H' : help;
  2433. '?' : help;
  2434. end;
  2435. inc(startpara);
  2436. end;
  2437. { process files }
  2438. for nrfile:=startpara to paramcount do
  2439. dofile (paramstr(nrfile));
  2440. if has_errors then
  2441. Halt(1);
  2442. if error_on_more and has_more_infos then
  2443. Halt(2);
  2444. end.