ppudump.pp 75 KB

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