ppudump.pp 74 KB

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