ppudump.pp 73 KB

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