ppudump.pp 75 KB

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