ppudump.pp 73 KB

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