ppudump.pp 72 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495
  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 : 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. writeln(' (Crc: ',hexstr(ucrc,8),', IntfcCrc: ',hexstr(uintfcrc,8),')');
  444. end;
  445. end;
  446. Procedure ReadDerefmap;
  447. var
  448. i,mapsize : longint;
  449. begin
  450. mapsize:=ppufile.getlongint;
  451. writeln('DerefMapsize: ',mapsize);
  452. for i:=0 to mapsize-1 do
  453. writeln('DerefMap[',i,'] = ',ppufile.getstring);
  454. end;
  455. Procedure ReadImportSymbols;
  456. var
  457. extlibname : string;
  458. j,
  459. extsymcnt : longint;
  460. extsymname : string;
  461. extsymordnr : longint;
  462. extsymisvar : boolean;
  463. begin
  464. while not ppufile.endofentry do
  465. begin
  466. extlibname:=ppufile.getstring;
  467. extsymcnt:=ppufile.getlongint;
  468. writeln('External Library: ',extlibname,' (',extsymcnt,' imports)');
  469. for j:=0 to extsymcnt-1 do
  470. begin
  471. extsymname:=ppufile.getstring;
  472. extsymordnr:=ppufile.getlongint;
  473. extsymisvar:=ppufile.getbyte<>0;
  474. writeln(' ',extsymname,' (OrdNr: ',extsymordnr,' IsVar: ',extsymisvar,')');
  475. end;
  476. end;
  477. end;
  478. Procedure ReadDerefdata;
  479. begin
  480. derefdatalen:=ppufile.entrysize;
  481. if derefdatalen=0 then
  482. begin
  483. writeln('!! Error: derefdatalen=0');
  484. exit;
  485. end;
  486. Writeln('Derefdata length: ',derefdatalen);
  487. derefdata:=allocmem(derefdatalen);
  488. ppufile.getdata(derefdata^,derefdatalen);
  489. end;
  490. Procedure ReadWpoFileInfo;
  491. begin
  492. Writeln('Compiled with input whole-program optimisation from ',ppufile.getstring,' ',filetimestring(ppufile.getlongint));
  493. end;
  494. Procedure ReadAsmSymbols;
  495. type
  496. { Copied from aasmbase.pas }
  497. TAsmsymbind=(AB_NONE,AB_EXTERNAL,AB_COMMON,AB_LOCAL,AB_GLOBAL);
  498. TAsmsymtype=(AT_NONE,AT_FUNCTION,AT_DATA,AT_SECTION,AT_LABEL);
  499. var
  500. s,
  501. bindstr,
  502. typestr : string;
  503. i : longint;
  504. begin
  505. writeln(space,'Number of AsmSymbols: ',ppufile.getlongint);
  506. i:=0;
  507. while (not ppufile.endofentry) and (not ppufile.error) do
  508. begin
  509. s:=ppufile.getstring;
  510. case tasmsymbind(ppufile.getbyte) of
  511. AB_EXTERNAL :
  512. bindstr:='External';
  513. AB_COMMON :
  514. bindstr:='Common';
  515. AB_LOCAL :
  516. bindstr:='Local';
  517. AB_GLOBAL :
  518. bindstr:='Global';
  519. else
  520. bindstr:='<Error !!>'
  521. end;
  522. case tasmsymtype(ppufile.getbyte) of
  523. AT_FUNCTION :
  524. typestr:='Function';
  525. AT_DATA :
  526. typestr:='Data';
  527. AT_SECTION :
  528. typestr:='Section';
  529. AT_LABEL :
  530. typestr:='Label';
  531. else
  532. typestr:='<Error !!>'
  533. end;
  534. Writeln(space,' ',i,' : ',s,' [',bindstr,',',typestr,']');
  535. inc(i);
  536. end;
  537. end;
  538. function getexprint:Tconstexprint;
  539. begin
  540. getexprint.overflow:=false;
  541. getexprint.signed:=boolean(ppufile.getbyte);
  542. getexprint.svalue:=ppufile.getint64;
  543. end;
  544. Procedure ReadPosInfo;
  545. var
  546. info : byte;
  547. fileindex,line,column : longint;
  548. begin
  549. with ppufile do
  550. begin
  551. {
  552. info byte layout in bits:
  553. 0-1 - amount of bytes for fileindex
  554. 2-3 - amount of bytes for line
  555. 4-5 - amount of bytes for column
  556. }
  557. info:=getbyte;
  558. case (info and $03) of
  559. 0 : fileindex:=getbyte;
  560. 1 : fileindex:=getword;
  561. 2 : fileindex:=(getbyte shl 16) or getword;
  562. 3 : fileindex:=getlongint;
  563. end;
  564. case ((info shr 2) and $03) of
  565. 0 : line:=getbyte;
  566. 1 : line:=getword;
  567. 2 : line:=(getbyte shl 16) or getword;
  568. 3 : line:=getlongint;
  569. end;
  570. case ((info shr 4) and $03) of
  571. 0 : column:=getbyte;
  572. 1 : column:=getword;
  573. 2 : column:=(getbyte shl 16) or getword;
  574. 3 : column:=getlongint;
  575. end;
  576. Writeln(fileindex,' (',line,',',column,')');
  577. end;
  578. end;
  579. procedure readderef;
  580. type
  581. tdereftype = (deref_nil,
  582. deref_unit,
  583. deref_symid,
  584. deref_defid
  585. );
  586. var
  587. b : tdereftype;
  588. first : boolean;
  589. idx : longint;
  590. i,n : byte;
  591. pdata : pbyte;
  592. begin
  593. if not assigned(derefdata) then
  594. exit;
  595. first:=true;
  596. idx:=ppufile.getlongint;
  597. if (idx>derefdatalen) then
  598. begin
  599. writeln('!! Error: Deref idx ',idx,' > ',derefdatalen);
  600. exit;
  601. end;
  602. write('(',idx,') ');
  603. pdata:=@derefdata[idx];
  604. i:=0;
  605. n:=pdata[i];
  606. inc(i);
  607. if n<1 then
  608. begin
  609. writeln('!! Error: Deref len < 1');
  610. exit;
  611. end;
  612. while (i<=n) do
  613. begin
  614. if not first then
  615. write(', ')
  616. else
  617. first:=false;
  618. b:=tdereftype(pdata[i]);
  619. inc(i);
  620. case b of
  621. deref_nil :
  622. write('Nil');
  623. deref_symid :
  624. begin
  625. idx:=pdata[i] shl 24 or pdata[i+1] shl 16 or pdata[i+2] shl 8 or pdata[i+3];
  626. inc(i,4);
  627. write('SymId ',idx);
  628. end;
  629. deref_defid :
  630. begin
  631. idx:=pdata[i] shl 24 or pdata[i+1] shl 16 or pdata[i+2] shl 8 or pdata[i+3];
  632. inc(i,4);
  633. write('DefId ',idx);
  634. end;
  635. deref_unit :
  636. begin
  637. idx:=pdata[i] shl 8 or pdata[i+1];
  638. inc(i,2);
  639. write('Unit ',idx);
  640. end;
  641. else
  642. begin
  643. writeln('!! unsupported dereftyp: ',ord(b));
  644. break;
  645. end;
  646. end;
  647. end;
  648. writeln;
  649. end;
  650. procedure readpropaccesslist(const s:string);
  651. type
  652. tsltype = (sl_none,
  653. sl_load,
  654. sl_call,
  655. sl_subscript,
  656. sl_vec,
  657. sl_typeconv,
  658. sl_absolutetype
  659. );
  660. const
  661. slstr : array[tsltype] of string[12] = ('',
  662. 'load',
  663. 'call',
  664. 'subscript',
  665. 'vec',
  666. 'typeconv',
  667. 'absolutetype'
  668. );
  669. var
  670. sl : tsltype;
  671. begin
  672. readderef;
  673. repeat
  674. sl:=tsltype(ppufile.getbyte);
  675. if sl=sl_none then
  676. break;
  677. write(s,'(',slstr[sl],') ');
  678. case sl of
  679. sl_call,
  680. sl_load,
  681. sl_subscript :
  682. readderef;
  683. sl_absolutetype,
  684. sl_typeconv :
  685. readderef;
  686. sl_vec :
  687. begin
  688. writeln(ppufile.getlongint);
  689. readderef;
  690. end;
  691. end;
  692. until false;
  693. end;
  694. procedure readsymoptions(space : string);
  695. type
  696. { symbol options }
  697. tsymoption=(sp_none,
  698. sp_static,
  699. sp_hint_deprecated,
  700. sp_hint_platform,
  701. sp_hint_library,
  702. sp_hint_unimplemented,
  703. sp_hint_experimental,
  704. sp_has_overloaded,
  705. sp_internal, { internal symbol, not reported as unused }
  706. sp_implicitrename,
  707. sp_generic_para,
  708. sp_has_deprecated_msg
  709. );
  710. tsymoptions=set of tsymoption;
  711. tsymopt=record
  712. mask : tsymoption;
  713. str : string[30];
  714. end;
  715. const
  716. symopts=11;
  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. type
  764. { flags for a definition }
  765. tdefoption=(df_none,
  766. { type is unique, i.e. declared with type = type <tdef>; }
  767. df_unique,
  768. { type is a generic }
  769. df_generic,
  770. { type is a specialization of a generic type }
  771. df_specialization,
  772. { def has been copied from another def so symtable is not owned }
  773. df_copied_def
  774. );
  775. tdefoptions=set of tdefoption;
  776. var
  777. { needed during tobjectdef parsing... }
  778. current_defoptions : tdefoptions;
  779. procedure readcommondef(const s:string);
  780. type
  781. tdefstate=(ds_none,
  782. ds_vmt_written,
  783. ds_rtti_table_used,
  784. ds_init_table_used,
  785. ds_rtti_table_written,
  786. ds_init_table_written,
  787. ds_dwarf_dbg_info_used,
  788. ds_dwarf_dbg_info_written
  789. );
  790. tdefstates=set of tdefstate;
  791. tdefopt=record
  792. mask : tdefoption;
  793. str : string[30];
  794. end;
  795. tdefstateinfo=record
  796. mask : tdefstate;
  797. str : string[30];
  798. end;
  799. const
  800. defopt : array[1..ord(high(tdefoption))] of tdefopt=(
  801. (mask:df_unique; str:'Unique Type'),
  802. (mask:df_generic; str:'Generic'),
  803. (mask:df_specialization; str:'Specialization'),
  804. (mask:df_copied_def; str:'Copied Typedef')
  805. );
  806. defstate : array[1..ord(high(tdefstate))] of tdefstateinfo=(
  807. (mask:ds_vmt_written; str:'VMT Written'),
  808. (mask:ds_rtti_table_used; str:'RTTITable Used'),
  809. (mask:ds_init_table_used; str:'InitTable Used'),
  810. (mask:ds_rtti_table_written; str:'RTTITable Written'),
  811. (mask:ds_init_table_written; str:'InitTable Written'),
  812. (mask:ds_dwarf_dbg_info_used; str:'Dwarf DbgInfo Used'),
  813. (mask:ds_dwarf_dbg_info_written;str:'Dwarf DbgInfo Written')
  814. );
  815. var
  816. defoptions : tdefoptions;
  817. defstates : tdefstates;
  818. i : longint;
  819. first : boolean;
  820. tokenbufsize : longint;
  821. tokenbuf : pbyte;
  822. begin
  823. writeln(space,'** Definition Id ',ppufile.getlongint,' **');
  824. writeln(space,s);
  825. write (space,' Type symbol : ');
  826. readderef;
  827. write (space,' DefOptions : ');
  828. ppufile.getsmallset(defoptions);
  829. if defoptions<>[] then
  830. begin
  831. first:=true;
  832. for i:=1to high(defopt) do
  833. if (defopt[i].mask in defoptions) then
  834. begin
  835. if first then
  836. first:=false
  837. else
  838. write(', ');
  839. write(defopt[i].str);
  840. end;
  841. end;
  842. writeln;
  843. write (space,' DefStates : ');
  844. ppufile.getsmallset(defstates);
  845. if defstates<>[] then
  846. begin
  847. first:=true;
  848. for i:=1to high(defstate) do
  849. if (defstate[i].mask in defstates) then
  850. begin
  851. if first then
  852. first:=false
  853. else
  854. write(', ');
  855. write(defstate[i].str);
  856. end;
  857. end;
  858. writeln;
  859. if df_generic in defoptions then
  860. begin
  861. tokenbufsize:=ppufile.getlongint;
  862. writeln(space,' Tokenbuffer size : ',tokenbufsize);
  863. tokenbuf:=allocmem(tokenbufsize);
  864. ppufile.getdata(tokenbuf^,tokenbufsize);
  865. i:=0;
  866. write(space,' Tokens: ');
  867. while i<tokenbufsize do
  868. begin
  869. if ttoken(tokenbuf[i])<>_GENERICSPECIALTOKEN then
  870. write(arraytokeninfo[ttoken(tokenbuf[i])].str);
  871. case ttoken(tokenbuf[i]) of
  872. _CWCHAR,
  873. _CWSTRING :
  874. begin
  875. inc(i);
  876. {
  877. replaytokenbuf.read(wlen,sizeof(SizeInt));
  878. setlengthwidestring(patternw,wlen);
  879. replaytokenbuf.read(patternw^.data^,patternw^.len*sizeof(tcompilerwidechar));
  880. pattern:='';
  881. }
  882. end;
  883. _CCHAR,
  884. _CSTRING,
  885. _INTCONST,
  886. _REALNUMBER :
  887. begin
  888. inc(i);
  889. {
  890. replaytokenbuf.read(pattern[0],1);
  891. replaytokenbuf.read(pattern[1],length(pattern));
  892. orgpattern:='';
  893. }
  894. end;
  895. _ID :
  896. begin
  897. inc(i);
  898. inc(i);
  899. write(' ',pshortstring(@tokenbuf[i])^);
  900. inc(i,tokenbuf[i]+1);
  901. {
  902. replaytokenbuf.read(orgpattern[0],1);
  903. replaytokenbuf.read(orgpattern[1],length(orgpattern));
  904. pattern:=upper(orgpattern);
  905. }
  906. end;
  907. _GENERICSPECIALTOKEN:
  908. begin
  909. inc(i);
  910. case tspecialgenerictoken(tokenbuf[i]) of
  911. ST_LOADSETTINGS:
  912. begin
  913. inc(i);
  914. write('Settings');
  915. inc(i,sizeof(tsettings));
  916. end;
  917. ST_LINE:
  918. begin
  919. inc(i);
  920. write('Line: ',pdword(@tokenbuf[i])^);
  921. inc(i,4);
  922. end;
  923. ST_COLUMN:
  924. begin
  925. inc(i);
  926. write('Col: ',pword(@tokenbuf[i])^);
  927. inc(i,2);
  928. end;
  929. ST_FILEINDEX:
  930. begin
  931. inc(i);
  932. write('File: ',pword(@tokenbuf[i])^);
  933. inc(i,2);
  934. end;
  935. end;
  936. {
  937. replaytokenbuf.read(specialtoken,1);
  938. case specialtoken of
  939. ST_LOADSETTINGS:
  940. begin
  941. replaytokenbuf.read(current_settings,sizeof(current_settings));
  942. end
  943. else
  944. internalerror(2006103010);
  945. end;
  946. continue;
  947. }
  948. end;
  949. else
  950. inc(i);
  951. end;
  952. if i<tokenbufsize then
  953. write(',');
  954. end;
  955. writeln;
  956. freemem(tokenbuf);
  957. end;
  958. if df_specialization in defoptions then
  959. begin
  960. write (space,' Orig. GenericDef : ');
  961. readderef;
  962. end;
  963. current_defoptions:=defoptions;
  964. end;
  965. { Read abstract procdef and return if inline procdef }
  966. type
  967. tproccalloption=(pocall_none,
  968. { procedure uses C styled calling }
  969. pocall_cdecl,
  970. { C++ calling conventions }
  971. pocall_cppdecl,
  972. { Far16 for OS/2 }
  973. pocall_far16,
  974. { Old style FPC default calling }
  975. pocall_oldfpccall,
  976. { Procedure has compiler magic}
  977. pocall_internproc,
  978. { procedure is a system call, applies e.g. to MorphOS and PalmOS }
  979. pocall_syscall,
  980. { pascal standard left to right }
  981. pocall_pascal,
  982. { procedure uses register (fastcall) calling }
  983. pocall_register,
  984. { safe call calling conventions }
  985. pocall_safecall,
  986. { procedure uses stdcall call }
  987. pocall_stdcall,
  988. { Special calling convention for cpus without a floating point
  989. unit. Floating point numbers are passed in integer registers
  990. instead of floating point registers. Depending on the other
  991. available calling conventions available for the cpu
  992. this replaces either pocall_fastcall or pocall_stdcall.
  993. }
  994. pocall_softfloat,
  995. { Metrowerks Pascal. Special case on Mac OS (X): passes all }
  996. { constant records by reference. }
  997. pocall_mwpascal
  998. );
  999. tproccalloptions = set of tproccalloption;
  1000. tproctypeoption=(potype_none,
  1001. potype_proginit, { Program initialization }
  1002. potype_unitinit, { unit initialization }
  1003. potype_unitfinalize, { unit finalization }
  1004. potype_constructor, { Procedure is a constructor }
  1005. potype_destructor, { Procedure is a destructor }
  1006. potype_operator, { Procedure defines an operator }
  1007. potype_procedure,
  1008. potype_function
  1009. );
  1010. tproctypeoptions=set of tproctypeoption;
  1011. tprocoption=(po_none,
  1012. po_classmethod, { class method }
  1013. po_virtualmethod, { Procedure is a virtual method }
  1014. po_abstractmethod, { Procedure is an abstract method }
  1015. po_finalmethod, { Procedure is a final method }
  1016. po_staticmethod, { static method }
  1017. po_overridingmethod, { method with override directive }
  1018. po_methodpointer, { method pointer, only in procvardef, also used for 'with object do' }
  1019. po_interrupt, { Procedure is an interrupt handler }
  1020. po_iocheck, { IO checking should be done after a call to the procedure }
  1021. po_assembler, { Procedure is written in assembler }
  1022. po_msgstr, { method for string message handling }
  1023. po_msgint, { method for int message handling }
  1024. po_exports, { Procedure has export directive (needed for OS/2) }
  1025. po_external, { Procedure is external (in other object or lib)}
  1026. po_overload, { procedure is declared with overload directive }
  1027. po_varargs, { printf like arguments }
  1028. po_internconst, { procedure has constant evaluator intern }
  1029. { flag that only the address of a method is returned and not a full methodpointer }
  1030. po_addressonly,
  1031. { procedure is exported }
  1032. po_public,
  1033. { calling convention is specified explicitly }
  1034. po_hascallingconvention,
  1035. { reintroduce flag }
  1036. po_reintroduce,
  1037. { location of parameters is given explicitly as it is necessary for some syscall
  1038. conventions like that one of MorphOS }
  1039. po_explicitparaloc,
  1040. { no stackframe will be generated, used by lowlevel assembler like get_frame }
  1041. po_nostackframe,
  1042. po_has_mangledname,
  1043. po_has_public_name,
  1044. po_forward,
  1045. po_global,
  1046. po_has_inlininginfo,
  1047. { The different kind of syscalls on MorphOS }
  1048. po_syscall_legacy,
  1049. po_syscall_sysv,
  1050. po_syscall_basesysv,
  1051. po_syscall_sysvbase,
  1052. po_syscall_r12base,
  1053. po_local,
  1054. { Procedure can be inlined }
  1055. po_inline,
  1056. { Procedure is used for internal compiler calls }
  1057. po_compilerproc,
  1058. { importing }
  1059. po_has_importdll,
  1060. po_has_importname,
  1061. po_kylixlocal,
  1062. po_dispid,
  1063. { weakly linked (i.e., may or may not exist at run time) }
  1064. po_weakexternal,
  1065. po_objc,
  1066. po_enumerator_movenext
  1067. );
  1068. tprocoptions=set of tprocoption;
  1069. procedure read_abstract_proc_def(var proccalloption:tproccalloption;var procoptions:tprocoptions);
  1070. type
  1071. tproccallopt=record
  1072. mask : tproccalloption;
  1073. str : string[30];
  1074. end;
  1075. tproctypeopt=record
  1076. mask : tproctypeoption;
  1077. str : string[30];
  1078. end;
  1079. tprocopt=record
  1080. mask : tprocoption;
  1081. str : string[30];
  1082. end;
  1083. const
  1084. proccalloptionStr : array[tproccalloption] of string[14]=('',
  1085. 'CDecl',
  1086. 'CPPDecl',
  1087. 'Far16',
  1088. 'OldFPCCall',
  1089. 'InternProc',
  1090. 'SysCall',
  1091. 'Pascal',
  1092. 'Register',
  1093. 'SafeCall',
  1094. 'StdCall',
  1095. 'SoftFloat',
  1096. 'MWPascal'
  1097. );
  1098. proctypeopt : array[1..ord(high(tproctypeoption))] of tproctypeopt=(
  1099. (mask:potype_proginit; str:'ProgInit'),
  1100. (mask:potype_unitinit; str:'UnitInit'),
  1101. (mask:potype_unitfinalize;str:'UnitFinalize'),
  1102. (mask:potype_constructor; str:'Constructor'),
  1103. (mask:potype_destructor; str:'Destructor'),
  1104. (mask:potype_operator; str:'Operator'),
  1105. (mask:potype_procedure; str:'Procedure'),
  1106. (mask:potype_function; str:'Function')
  1107. );
  1108. procopt : array[1..ord(high(tprocoption))] of tprocopt=(
  1109. (mask:po_classmethod; str:'ClassMethod'),
  1110. (mask:po_virtualmethod; str:'VirtualMethod'),
  1111. (mask:po_abstractmethod; str:'AbstractMethod'),
  1112. (mask:po_finalmethod; str:'FinalMethod'),
  1113. (mask:po_staticmethod; str:'StaticMethod'),
  1114. (mask:po_overridingmethod;str:'OverridingMethod'),
  1115. (mask:po_methodpointer; str:'MethodPointer'),
  1116. (mask:po_interrupt; str:'Interrupt'),
  1117. (mask:po_iocheck; str:'IOCheck'),
  1118. (mask:po_assembler; str:'Assembler'),
  1119. (mask:po_msgstr; str:'MsgStr'),
  1120. (mask:po_msgint; str:'MsgInt'),
  1121. (mask:po_exports; str:'Exports'),
  1122. (mask:po_external; str:'External'),
  1123. (mask:po_overload; str:'Overload'),
  1124. (mask:po_varargs; str:'VarArgs'),
  1125. (mask:po_internconst; str:'InternConst'),
  1126. (mask:po_addressonly; str:'AddressOnly'),
  1127. (mask:po_public; str:'Public'),
  1128. (mask:po_hascallingconvention;str:'HasCallingConvention'),
  1129. (mask:po_reintroduce; str:'ReIntroduce'),
  1130. (mask:po_explicitparaloc; str:'ExplicitParaloc'),
  1131. (mask:po_nostackframe; str:'NoStackFrame'),
  1132. (mask:po_has_mangledname; str:'HasMangledName'),
  1133. (mask:po_has_public_name; str:'HasPublicName'),
  1134. (mask:po_forward; str:'Forward'),
  1135. (mask:po_global; str:'Global'),
  1136. (mask:po_has_inlininginfo;str:'HasInliningInfo'),
  1137. (mask:po_syscall_legacy; str:'SyscallLegacy'),
  1138. (mask:po_syscall_sysv; str:'SyscallSysV'),
  1139. (mask:po_syscall_basesysv;str:'SyscallBaseSysV'),
  1140. (mask:po_syscall_sysvbase;str:'SyscallSysVBase'),
  1141. (mask:po_syscall_r12base; str:'SyscallR12Base'),
  1142. (mask:po_local; str:'Local'),
  1143. (mask:po_inline; str:'Inline'),
  1144. (mask:po_compilerproc; str:'CompilerProc'),
  1145. (mask:po_has_importdll; str:'HasImportDLL'),
  1146. (mask:po_has_importname; str:'HasImportName'),
  1147. (mask:po_kylixlocal; str:'KylixLocal'),
  1148. (mask:po_dispid; str:'DispId'),
  1149. (mask:po_weakexternal; str:'WeakExternal'),
  1150. (mask:po_objc; str:'ObjC'),
  1151. (mask:po_enumerator_movenext; str:'EnumeratorMoveNext')
  1152. );
  1153. var
  1154. proctypeoption : tproctypeoption;
  1155. i : longint;
  1156. first : boolean;
  1157. tempbuf : array[0..255] of byte;
  1158. begin
  1159. write(space,' Return type : ');
  1160. readderef;
  1161. writeln(space,' Fpu used : ',ppufile.getbyte);
  1162. proctypeoption:=tproctypeoption(ppufile.getbyte);
  1163. write(space,' TypeOption : ');
  1164. first:=true;
  1165. for i:=1 to high(proctypeopt) do
  1166. if (proctypeopt[i].mask=proctypeoption) then
  1167. begin
  1168. if first then
  1169. first:=false
  1170. else
  1171. write(', ');
  1172. write(proctypeopt[i].str);
  1173. end;
  1174. writeln;
  1175. proccalloption:=tproccalloption(ppufile.getbyte);
  1176. writeln(space,' CallOption : ',proccalloptionStr[proccalloption]);
  1177. ppufile.getnormalset(procoptions);
  1178. if procoptions<>[] then
  1179. begin
  1180. write(space,' Options : ');
  1181. first:=true;
  1182. for i:=1 to high(procopt) do
  1183. if (procopt[i].mask in procoptions) then
  1184. begin
  1185. if first then
  1186. first:=false
  1187. else
  1188. write(', ');
  1189. write(procopt[i].str);
  1190. end;
  1191. writeln;
  1192. end;
  1193. if (po_explicitparaloc in procoptions) then
  1194. begin
  1195. i:=ppufile.getbyte;
  1196. ppufile.getdata(tempbuf,i);
  1197. end;
  1198. end;
  1199. type
  1200. tvaroption=(vo_none,
  1201. vo_is_external,
  1202. vo_is_dll_var,
  1203. vo_is_thread_var,
  1204. vo_has_local_copy,
  1205. vo_is_const, { variable is declared as const (parameter) and can't be written to }
  1206. vo_is_public,
  1207. vo_is_high_para,
  1208. vo_is_funcret,
  1209. vo_is_self,
  1210. vo_is_vmt,
  1211. vo_is_result, { special result variable }
  1212. vo_is_parentfp,
  1213. vo_is_loop_counter, { used to detect assignments to loop counter }
  1214. vo_is_hidden_para,
  1215. vo_has_explicit_paraloc,
  1216. vo_is_syscall_lib,
  1217. vo_has_mangledname,
  1218. vo_is_typed_const,
  1219. vo_is_range_check,
  1220. vo_is_overflow_check,
  1221. vo_is_typinfo_para,
  1222. vo_is_weak_external
  1223. );
  1224. tvaroptions=set of tvaroption;
  1225. { register variable }
  1226. tvarregable=(vr_none,
  1227. vr_intreg,
  1228. vr_fpureg,
  1229. vr_mmreg,
  1230. { does not mean "needs address register", but "if it's a parameter which is }
  1231. { passed by reference, then its address can be put in a register }
  1232. vr_addr
  1233. );
  1234. procedure readabstractvarsym(const s:string;var varoptions:tvaroptions);
  1235. type
  1236. tvaropt=record
  1237. mask : tvaroption;
  1238. str : string[30];
  1239. end;
  1240. const
  1241. varopt : array[1..ord(high(tvaroption))] of tvaropt=(
  1242. (mask:vo_is_external; str:'External'),
  1243. (mask:vo_is_dll_var; str:'DLLVar'),
  1244. (mask:vo_is_thread_var; str:'ThreadVar'),
  1245. (mask:vo_has_local_copy; str:'HasLocalCopy'),
  1246. (mask:vo_is_const; str:'Constant'),
  1247. (mask:vo_is_public; str:'Public'),
  1248. (mask:vo_is_high_para; str:'HighValue'),
  1249. (mask:vo_is_funcret; str:'Funcret'),
  1250. (mask:vo_is_self; str:'Self'),
  1251. (mask:vo_is_vmt; str:'VMT'),
  1252. (mask:vo_is_result; str:'Result'),
  1253. (mask:vo_is_parentfp; str:'ParentFP'),
  1254. (mask:vo_is_loop_counter; str:'LoopCounter'),
  1255. (mask:vo_is_hidden_para; str:'Hidden'),
  1256. (mask:vo_has_explicit_paraloc;str:'ExplicitParaloc'),
  1257. (mask:vo_is_syscall_lib; str:'SysCallLib'),
  1258. (mask:vo_has_mangledname; str:'HasMangledName'),
  1259. (mask:vo_is_typed_const; str:'TypedConst'),
  1260. (mask:vo_is_range_check; str:'RangeCheckSwitch'),
  1261. (mask:vo_is_overflow_check; str:'OverflowCheckSwitch'),
  1262. (mask:vo_is_typinfo_para; str:'TypeInfo'),
  1263. (mask:vo_is_weak_external;str:'WeakExternal')
  1264. );
  1265. var
  1266. i : longint;
  1267. first : boolean;
  1268. begin
  1269. readcommonsym(s);
  1270. writeln(space,' Spez : ',Varspez2Str(ppufile.getbyte));
  1271. writeln(space,' Regable : ',Varregable2Str(ppufile.getbyte));
  1272. writeln(space,' Addr Taken : ',(ppufile.getbyte<>0));
  1273. write (space,' Var Type : ');
  1274. readderef;
  1275. ppufile.getsmallset(varoptions);
  1276. if varoptions<>[] then
  1277. begin
  1278. write(space,' Options : ');
  1279. first:=true;
  1280. for i:=1 to high(varopt) do
  1281. if (varopt[i].mask in varoptions) then
  1282. begin
  1283. if first then
  1284. first:=false
  1285. else
  1286. write(', ');
  1287. write(varopt[i].str);
  1288. end;
  1289. writeln;
  1290. end;
  1291. end;
  1292. procedure readobjectdefoptions;
  1293. type
  1294. tobjectoption=(oo_none,
  1295. oo_is_forward, { the class is only a forward declared yet }
  1296. oo_is_abstract, { the class is abstract - only descendants can be used }
  1297. oo_is_sealed, { the class is sealed - can't have descendants }
  1298. oo_has_virtual, { the object/class has virtual methods }
  1299. oo_has_private,
  1300. oo_has_protected,
  1301. oo_has_strictprivate,
  1302. oo_has_strictprotected,
  1303. oo_has_constructor, { the object/class has a constructor }
  1304. oo_has_destructor, { the object/class has a destructor }
  1305. oo_has_vmt, { the object/class has a vmt }
  1306. oo_has_msgstr,
  1307. oo_has_msgint,
  1308. oo_can_have_published,{ the class has rtti, i.e. you can publish properties }
  1309. oo_has_default_property,
  1310. oo_has_valid_guid,
  1311. oo_has_enumerator_movenext,
  1312. oo_has_enumerator_current
  1313. );
  1314. tobjectoptions=set of tobjectoption;
  1315. tsymopt=record
  1316. mask : tobjectoption;
  1317. str : string[30];
  1318. end;
  1319. const
  1320. symopt : array[1..ord(high(tobjectoption))] of tsymopt=(
  1321. (mask:oo_is_forward; str:'IsForward'),
  1322. (mask:oo_is_abstract; str:'IsAbstract'),
  1323. (mask:oo_is_sealed; str:'IsSealed'),
  1324. (mask:oo_has_virtual; str:'HasVirtual'),
  1325. (mask:oo_has_private; str:'HasPrivate'),
  1326. (mask:oo_has_protected; str:'HasProtected'),
  1327. (mask:oo_has_strictprivate; str:'HasStrictPrivate'),
  1328. (mask:oo_has_strictprotected;str:'HasStrictProtected'),
  1329. (mask:oo_has_constructor; str:'HasConstructor'),
  1330. (mask:oo_has_destructor; str:'HasDestructor'),
  1331. (mask:oo_has_vmt; str:'HasVMT'),
  1332. (mask:oo_has_msgstr; str:'HasMsgStr'),
  1333. (mask:oo_has_msgint; str:'HasMsgInt'),
  1334. (mask:oo_can_have_published; str:'CanHavePublished'),
  1335. (mask:oo_has_default_property;str:'HasDefaultProperty'),
  1336. (mask:oo_has_valid_guid; str:'HasValidGUID'),
  1337. (mask:oo_has_enumerator_movenext; str:'HasEnumeratorMoveNext'),
  1338. (mask:oo_has_enumerator_current; str:'HasEnumeratorCurrent')
  1339. );
  1340. var
  1341. symoptions : tobjectoptions;
  1342. i : longint;
  1343. first : boolean;
  1344. begin
  1345. ppufile.getsmallset(symoptions);
  1346. if symoptions<>[] then
  1347. begin
  1348. first:=true;
  1349. for i:=1 to high(symopt) do
  1350. if (symopt[i].mask in symoptions) then
  1351. begin
  1352. if first then
  1353. first:=false
  1354. else
  1355. write(', ');
  1356. write(symopt[i].str);
  1357. end;
  1358. end;
  1359. writeln;
  1360. end;
  1361. procedure readarraydefoptions;
  1362. type
  1363. tarraydefoption=(ado_none,
  1364. ado_IsConvertedPointer,
  1365. ado_IsDynamicArray,
  1366. ado_IsVariant,
  1367. ado_IsConstructor,
  1368. ado_IsArrayOfConst,
  1369. ado_IsConstString,
  1370. ado_IsBitPacked
  1371. );
  1372. tarraydefoptions=set of tarraydefoption;
  1373. tsymopt=record
  1374. mask : tarraydefoption;
  1375. str : string[30];
  1376. end;
  1377. const
  1378. symopt : array[1..ord(high(tarraydefoption))] of tsymopt=(
  1379. (mask:ado_IsConvertedPointer;str:'ConvertedPointer'),
  1380. (mask:ado_IsDynamicArray; str:'IsDynamicArray'),
  1381. (mask:ado_IsVariant; str:'IsVariant'),
  1382. (mask:ado_IsConstructor; str:'IsConstructor'),
  1383. (mask:ado_IsArrayOfConst; str:'ArrayOfConst'),
  1384. (mask:ado_IsConstString; str:'ConstString'),
  1385. (mask:ado_IsBitPacked; str:'BitPacked')
  1386. );
  1387. var
  1388. symoptions : tarraydefoptions;
  1389. i : longint;
  1390. first : boolean;
  1391. begin
  1392. ppufile.getsmallset(symoptions);
  1393. if symoptions<>[] then
  1394. begin
  1395. first:=true;
  1396. for i:=1 to high(symopt) do
  1397. if (symopt[i].mask in symoptions) then
  1398. begin
  1399. if first then
  1400. first:=false
  1401. else
  1402. write(', ');
  1403. write(symopt[i].str);
  1404. end;
  1405. end;
  1406. writeln;
  1407. end;
  1408. procedure readnodetree;
  1409. var
  1410. l : longint;
  1411. p : pointer;
  1412. begin
  1413. with ppufile do
  1414. begin
  1415. if space<>'' then
  1416. Writeln(space,'------ nodetree ------');
  1417. if readentry=ibnodetree then
  1418. begin
  1419. l:=entrysize;
  1420. Writeln(space,'Tree size : ',l);
  1421. { Read data to prevent error that entry is not completly read }
  1422. getmem(p,l);
  1423. getdata(p^,l);
  1424. freemem(p);
  1425. end
  1426. else
  1427. begin
  1428. Writeln('!! ibnodetree not found');
  1429. end;
  1430. end;
  1431. end;
  1432. {****************************************************************************
  1433. Read Symbols Part
  1434. ****************************************************************************}
  1435. procedure readsymbols(const s:string);
  1436. type
  1437. pguid = ^tguid;
  1438. tguid = packed record
  1439. D1: LongWord;
  1440. D2: Word;
  1441. D3: Word;
  1442. D4: array[0..7] of Byte;
  1443. end;
  1444. absolutetyp = (tovar,toasm,toaddr);
  1445. tconsttyp = (constnone,
  1446. constord,conststring,constreal,
  1447. constset,constpointer,constnil,
  1448. constresourcestring,constwstring,constguid
  1449. );
  1450. var
  1451. b : byte;
  1452. pc : pchar;
  1453. i,j,len : longint;
  1454. guid : tguid;
  1455. tempbuf : array[0..127] of char;
  1456. varoptions : tvaroptions;
  1457. begin
  1458. with ppufile do
  1459. begin
  1460. if space<>'' then
  1461. Writeln(space,'------ ',s,' ------');
  1462. if readentry=ibstartsyms then
  1463. begin
  1464. Writeln(space,'Symtable datasize : ',getlongint);
  1465. Writeln(space,'Symtable alignment: ',getlongint);
  1466. end
  1467. else
  1468. Writeln('!! ibstartsym not found');
  1469. repeat
  1470. b:=readentry;
  1471. case b of
  1472. ibunitsym :
  1473. readcommonsym('Unit symbol ');
  1474. iblabelsym :
  1475. readcommonsym('Label symbol ');
  1476. ibtypesym :
  1477. begin
  1478. readcommonsym('Type symbol ');
  1479. write(space,' Result Type : ');
  1480. readderef;
  1481. end;
  1482. ibprocsym :
  1483. begin
  1484. readcommonsym('Procedure symbol ');
  1485. len:=ppufile.getword;
  1486. for i:=1 to len do
  1487. begin
  1488. write(space,' Definition : ');
  1489. readderef;
  1490. end;
  1491. end;
  1492. ibconstsym :
  1493. begin
  1494. readcommonsym('Constant symbol ');
  1495. b:=getbyte;
  1496. case tconsttyp(b) of
  1497. constord :
  1498. begin
  1499. write (space,' OrdinalType : ');
  1500. readderef;
  1501. writeln(space,' Value : ',constexp.tostr(getexprint));
  1502. end;
  1503. constpointer :
  1504. begin
  1505. write (space,' PointerType : ');
  1506. readderef;
  1507. writeln(space,' Value : ',getlongint)
  1508. end;
  1509. conststring,
  1510. constresourcestring :
  1511. begin
  1512. len:=getlongint;
  1513. getmem(pc,len+1);
  1514. getdata(pc^,len);
  1515. (pc+len)^:= #0;
  1516. writeln(space,' Length : ',len);
  1517. writeln(space,' Value : "',pc,'"');
  1518. freemem(pc,len+1);
  1519. end;
  1520. constreal :
  1521. writeln(space,' Value : ',getreal);
  1522. constset :
  1523. begin
  1524. write (space,' Set Type : ');
  1525. readderef;
  1526. for i:=1to 4 do
  1527. begin
  1528. write (space,' Value : ');
  1529. for j:=1to 8 do
  1530. begin
  1531. if j>1 then
  1532. write(',');
  1533. write(hexstr(getbyte,2));
  1534. end;
  1535. writeln;
  1536. end;
  1537. end;
  1538. constwstring:
  1539. begin
  1540. end;
  1541. constguid:
  1542. begin
  1543. getdata(guid,sizeof(guid));
  1544. write (space,' IID String: {',hexstr(guid.d1,8),'-',hexstr(guid.d2,4),'-',hexstr(guid.d3,4),'-');
  1545. for i:=0 to 7 do
  1546. begin
  1547. write(hexstr(guid.d4[i],2));
  1548. if i=1 then write('-');
  1549. end;
  1550. writeln('}');
  1551. end
  1552. else
  1553. Writeln ('!! Invalid unit format : Invalid const type encountered: ',b);
  1554. end;
  1555. end;
  1556. ibabsolutevarsym :
  1557. begin
  1558. readabstractvarsym('Absolute variable symbol ',varoptions);
  1559. Write (space,' Relocated to ');
  1560. b:=getbyte;
  1561. case absolutetyp(b) of
  1562. tovar :
  1563. readpropaccesslist(space+' Sym : ');
  1564. toasm :
  1565. Writeln('Assembler name : ',getstring);
  1566. toaddr :
  1567. begin
  1568. Write('Address : ',getlongint);
  1569. if tsystemcpu(ppufile.header.cpu)=cpu_i386 then
  1570. WriteLn(' (Far: ',getbyte<>0,')');
  1571. end;
  1572. else
  1573. Writeln ('!! Invalid unit format : Invalid absolute type encountered: ',b);
  1574. end;
  1575. end;
  1576. ibfieldvarsym :
  1577. begin
  1578. readabstractvarsym('Field Variable symbol ',varoptions);
  1579. writeln(space,' Address : ',getaint);
  1580. end;
  1581. ibstaticvarsym :
  1582. begin
  1583. readabstractvarsym('Global Variable symbol ',varoptions);
  1584. write (space,' DefaultConst : ');
  1585. readderef;
  1586. if (vo_has_mangledname in varoptions) then
  1587. writeln(space,' Mangledname : ',getstring);
  1588. end;
  1589. iblocalvarsym :
  1590. begin
  1591. readabstractvarsym('Local Variable symbol ',varoptions);
  1592. write (space,' DefaultConst : ');
  1593. readderef;
  1594. end;
  1595. ibparavarsym :
  1596. begin
  1597. readabstractvarsym('Parameter Variable symbol ',varoptions);
  1598. write (space,' DefaultConst : ');
  1599. readderef;
  1600. writeln(space,' ParaNr : ',getword);
  1601. writeln(space,' VarState : ',getbyte);
  1602. if (vo_has_explicit_paraloc in varoptions) then
  1603. begin
  1604. i:=getbyte;
  1605. getdata(tempbuf,i);
  1606. end;
  1607. end;
  1608. ibenumsym :
  1609. begin
  1610. readcommonsym('Enumeration symbol ');
  1611. write (space,' Definition : ');
  1612. readderef;
  1613. writeln(space,' Value : ',getlongint);
  1614. end;
  1615. ibsyssym :
  1616. begin
  1617. readcommonsym('Internal system symbol ');
  1618. writeln(space,' Internal Nr : ',getlongint);
  1619. end;
  1620. ibmacrosym :
  1621. begin
  1622. readcommonsym('Macro symbol ');
  1623. writeln(space,' Name: ',getstring);
  1624. writeln(space,' Defined: ',getbyte);
  1625. writeln(space,' Compiler var: ',getbyte);
  1626. len:=getlongint;
  1627. writeln(space,' Value length: ',len);
  1628. if len > 0 then
  1629. begin
  1630. getmem(pc,len+1);
  1631. getdata(pc^,len);
  1632. (pc+len)^:= #0;
  1633. writeln(space,' Value: "',pc,'"');
  1634. freemem(pc,len+1);
  1635. end;
  1636. end;
  1637. ibpropertysym :
  1638. begin
  1639. readcommonsym('Property ');
  1640. i:=getlongint;
  1641. writeln(space,' PropOptions : ',i);
  1642. write (space,' OverrideProp : ');
  1643. readderef;
  1644. write (space,' Prop Type : ');
  1645. readderef;
  1646. writeln(space,' Index : ',getlongint);
  1647. writeln(space,' Default : ',getlongint);
  1648. write (space,' Index Type : ');
  1649. readderef;
  1650. write (space,' Readaccess : ');
  1651. readpropaccesslist(space+' Sym: ');
  1652. write (space,' Writeaccess : ');
  1653. readpropaccesslist(space+' Sym: ');
  1654. write (space,' Storedaccess : ');
  1655. readpropaccesslist(space+' Sym: ');
  1656. end;
  1657. iberror :
  1658. begin
  1659. Writeln('!! Error in PPU');
  1660. exit;
  1661. end;
  1662. ibendsyms :
  1663. break;
  1664. else
  1665. WriteLn('!! Skipping unsupported PPU Entry in Symbols: ',b);
  1666. end;
  1667. if not EndOfEntry then
  1668. Writeln('!! Entry has more information stored');
  1669. until false;
  1670. end;
  1671. end;
  1672. {****************************************************************************
  1673. Read defintions Part
  1674. ****************************************************************************}
  1675. procedure readdefinitions(const s:string);
  1676. type
  1677. tordtype = (
  1678. uvoid,
  1679. u8bit,u16bit,u32bit,u64bit,
  1680. s8bit,s16bit,s32bit,s64bit,
  1681. bool8bit,bool16bit,bool32bit,bool64bit,
  1682. uchar,uwidechar,scurrency
  1683. );
  1684. tobjecttyp = (odt_none,
  1685. odt_class,
  1686. odt_object,
  1687. odt_interfacecom,
  1688. odt_interfacecorba,
  1689. odt_cppclass,
  1690. odt_dispinterface
  1691. );
  1692. tvarianttype = (
  1693. vt_normalvariant,vt_olevariant
  1694. );
  1695. var
  1696. b : byte;
  1697. l,j : longint;
  1698. calloption : tproccalloption;
  1699. procoptions : tprocoptions;
  1700. procinfooptions : tprocinfoflag;
  1701. begin
  1702. with ppufile do
  1703. begin
  1704. if space<>'' then
  1705. Writeln(space,'------ ',s,' ------');
  1706. if readentry<>ibstartdefs then
  1707. Writeln('!! ibstartdefs not found');
  1708. repeat
  1709. b:=readentry;
  1710. case b of
  1711. ibpointerdef :
  1712. begin
  1713. readcommondef('Pointer definition');
  1714. write (space,' Pointed Type : ');
  1715. readderef;
  1716. writeln(space,' Is Far : ',(getbyte<>0));
  1717. end;
  1718. iborddef :
  1719. begin
  1720. readcommondef('Ordinal definition');
  1721. write (space,' Base type : ');
  1722. b:=getbyte;
  1723. case tordtype(b) of
  1724. uvoid : writeln('uvoid');
  1725. u8bit : writeln('u8bit');
  1726. u16bit : writeln('u16bit');
  1727. u32bit : writeln('s32bit');
  1728. u64bit : writeln('u64bit');
  1729. s8bit : writeln('s8bit');
  1730. s16bit : writeln('s16bit');
  1731. s32bit : writeln('s32bit');
  1732. s64bit : writeln('s64bit');
  1733. bool8bit : writeln('bool8bit');
  1734. bool16bit : writeln('bool16bit');
  1735. bool32bit : writeln('bool32bit');
  1736. bool64bit : writeln('bool64bit');
  1737. uchar : writeln('uchar');
  1738. uwidechar : writeln('uwidechar');
  1739. scurrency : writeln('ucurrency');
  1740. else writeln('!! Warning: Invalid base type ',b);
  1741. end;
  1742. writeln(space,' Range : ',constexp.tostr(getexprint),' to ',constexp.tostr(getexprint));
  1743. end;
  1744. ibfloatdef :
  1745. begin
  1746. readcommondef('Float definition');
  1747. writeln(space,' Float type : ',getbyte);
  1748. end;
  1749. ibarraydef :
  1750. begin
  1751. readcommondef('Array definition');
  1752. write (space,' Element type : ');
  1753. readderef;
  1754. write (space,' Range Type : ');
  1755. readderef;
  1756. writeln(space,' Range : ',getaint,' to ',getaint);
  1757. write (space,' Options : ');
  1758. readarraydefoptions;
  1759. end;
  1760. ibprocdef :
  1761. begin
  1762. readcommondef('Procedure definition');
  1763. read_abstract_proc_def(calloption,procoptions);
  1764. if (po_has_mangledname in procoptions) then
  1765. writeln(space,' Mangled name : ',getstring);
  1766. writeln(space,' Number : ',getword);
  1767. writeln(space,' Level : ',getbyte);
  1768. write (space,' Class : ');
  1769. readderef;
  1770. write (space,' Procsym : ');
  1771. readderef;
  1772. write (space,' File Pos : ');
  1773. readposinfo;
  1774. writeln(space,' Visibility : ',Visibility2Str(ppufile.getbyte));
  1775. write (space,' SymOptions : ');
  1776. readsymoptions(space+' ');
  1777. if tsystemcpu(ppufile.header.cpu)=cpu_powerpc then
  1778. begin
  1779. { library symbol for AmigaOS/MorphOS }
  1780. write (space,' Library symbol : ');
  1781. readderef;
  1782. end;
  1783. if (po_has_importdll in procoptions) then
  1784. writeln(space,' Import DLL : ',getstring);
  1785. if (po_has_importname in procoptions) then
  1786. writeln(space,' Import Name : ',getstring);
  1787. writeln(space,' Import Nr : ',getword);
  1788. if (po_msgint in procoptions) then
  1789. writeln(space,' MsgInt : ',getlongint);
  1790. if (po_msgstr in procoptions) then
  1791. writeln(space,' MsgStr : ',getstring);
  1792. if (po_dispid in procoptions) then
  1793. writeln(space,' DispID: ',ppufile.getlongint);
  1794. if (po_has_inlininginfo in procoptions) then
  1795. begin
  1796. write (space,' FuncretSym : ');
  1797. readderef;
  1798. ppufile.getsmallset(procinfooptions);
  1799. writeln(space,' ProcInfoOptions : ',dword(procinfooptions));
  1800. end;
  1801. b:=ppufile.getbyte;
  1802. if b<>0 then
  1803. begin
  1804. write (space,' Alias names : ');
  1805. for j:=1 to b do
  1806. begin
  1807. write(ppufile.getstring);
  1808. if j<b then
  1809. write(', ');
  1810. end;
  1811. writeln;
  1812. end;
  1813. if not EndOfEntry then
  1814. Writeln('!! Entry has more information stored');
  1815. space:=' '+space;
  1816. { parast }
  1817. readdefinitions('parast');
  1818. readsymbols('parast');
  1819. { localst }
  1820. if (po_has_inlininginfo in procoptions) then
  1821. begin
  1822. readdefinitions('localst');
  1823. readsymbols('localst');
  1824. end;
  1825. if (po_has_inlininginfo in procoptions) then
  1826. readnodetree;
  1827. delete(space,1,4);
  1828. end;
  1829. ibprocvardef :
  1830. begin
  1831. readcommondef('Procedural type (ProcVar) definition');
  1832. read_abstract_proc_def(calloption,procoptions);
  1833. if not EndOfEntry then
  1834. Writeln('!! Entry has more information stored');
  1835. space:=' '+space;
  1836. { parast }
  1837. readdefinitions('parast');
  1838. readsymbols('parast');
  1839. delete(space,1,4);
  1840. end;
  1841. ibshortstringdef :
  1842. begin
  1843. readcommondef('ShortString definition');
  1844. writeln(space,' Length : ',getbyte);
  1845. end;
  1846. ibwidestringdef :
  1847. begin
  1848. readcommondef('WideString definition');
  1849. writeln(space,' Length : ',getlongint);
  1850. end;
  1851. ibansistringdef :
  1852. begin
  1853. readcommondef('AnsiString definition');
  1854. writeln(space,' Length : ',getlongint);
  1855. end;
  1856. iblongstringdef :
  1857. begin
  1858. readcommondef('Longstring definition');
  1859. writeln(space,' Length : ',getlongint);
  1860. end;
  1861. ibrecorddef :
  1862. begin
  1863. readcommondef('Record definition');
  1864. writeln(space,' FieldAlign : ',getbyte);
  1865. writeln(space,' RecordAlign : ',getbyte);
  1866. writeln(space,' PadAlign : ',getbyte);
  1867. writeln(space,'UseFieldAlignment : ',getbyte);
  1868. writeln(space,' DataSize : ',getaint);
  1869. if not EndOfEntry then
  1870. Writeln('!! Entry has more information stored');
  1871. {read the record definitions and symbols}
  1872. space:=' '+space;
  1873. readdefinitions('fields');
  1874. readsymbols('fields');
  1875. Delete(space,1,4);
  1876. end;
  1877. ibobjectdef :
  1878. begin
  1879. readcommondef('Object/Class definition');
  1880. b:=getbyte;
  1881. write (space,' Type : ');
  1882. case tobjecttyp(b) of
  1883. odt_class : writeln('class');
  1884. odt_object : writeln('object');
  1885. odt_interfacecom : writeln('interfacecom');
  1886. odt_interfacecorba : writeln('interfacecorba');
  1887. odt_cppclass : writeln('cppclass');
  1888. else writeln('!! Warning: Invalid object type ',b);
  1889. end;
  1890. writeln(space,' Name of Class : ',getstring);
  1891. writeln(space,' DataSize : ',getaint);
  1892. writeln(space,' FieldAlign : ',getbyte);
  1893. writeln(space,' RecordAlign : ',getbyte);
  1894. writeln(space,' Vmt offset : ',getlongint);
  1895. write (space, ' Ancestor Class : ');
  1896. readderef;
  1897. write (space,' Options : ');
  1898. readobjectdefoptions;
  1899. if tobjecttyp(b) in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  1900. begin
  1901. { IIDGUID }
  1902. for j:=1to 16 do
  1903. getbyte;
  1904. writeln(space,' IID String : ',getstring);
  1905. writeln(space,' Last VTable idx : ',getlongint);
  1906. end;
  1907. l:=getlongint;
  1908. writeln(space,' VMT entries: ',l);
  1909. for j:=1 to l do
  1910. begin
  1911. write(space,' ');
  1912. readderef;
  1913. writeln(space,' Visibility: ',Visibility2Str(getbyte));
  1914. end;
  1915. if tobjecttyp(b) in [odt_class,odt_interfacecorba] then
  1916. begin
  1917. l:=getlongint;
  1918. writeln(space,' Impl Intf Count : ',l);
  1919. for j:=1 to l do
  1920. begin
  1921. write (space,' - Definition : ');
  1922. readderef;
  1923. writeln(space,' IOffset : ',getlongint);
  1924. end;
  1925. end;
  1926. if df_copied_def in current_defoptions then
  1927. begin
  1928. writeln(' Copy of def: ');
  1929. readderef;
  1930. end;
  1931. if not EndOfEntry then
  1932. Writeln('!! Entry has more information stored');
  1933. if not(df_copied_def in current_defoptions) then
  1934. begin
  1935. {read the record definitions and symbols}
  1936. space:=' '+space;
  1937. readdefinitions('fields');
  1938. readsymbols('fields');
  1939. Delete(space,1,4);
  1940. end;
  1941. end;
  1942. ibfiledef :
  1943. begin
  1944. ReadCommonDef('File definition');
  1945. write (space,' Type : ');
  1946. case getbyte of
  1947. 0 : writeln('Text');
  1948. 1 : begin
  1949. writeln('Typed');
  1950. write (space,' File of Type : ');
  1951. readderef;
  1952. end;
  1953. 2 : writeln('Untyped');
  1954. end;
  1955. end;
  1956. ibformaldef :
  1957. begin
  1958. readcommondef('Generic definition (void-typ)');
  1959. writeln(space,' Is Typed : ',(getbyte<>0));
  1960. end;
  1961. ibundefineddef :
  1962. readcommondef('Undefined definition (generic parameter)');
  1963. ibenumdef :
  1964. begin
  1965. readcommondef('Enumeration type definition');
  1966. write(space,'Base enumeration type : ');
  1967. readderef;
  1968. writeln(space,' Smallest element : ',getaint);
  1969. writeln(space,' Largest element : ',getaint);
  1970. writeln(space,' Size : ',getaint);
  1971. end;
  1972. ibclassrefdef :
  1973. begin
  1974. readcommondef('Class reference definition');
  1975. write (space,' Pointed Type : ');
  1976. readderef;
  1977. end;
  1978. ibsetdef :
  1979. begin
  1980. readcommondef('Set definition');
  1981. write (space,' Element type : ');
  1982. readderef;
  1983. writeln(space,' Size : ',getaint);
  1984. writeln(space,' Set Base : ',getaint);
  1985. writeln(space,' Set Max : ',getaint);
  1986. end;
  1987. ibvariantdef :
  1988. begin
  1989. readcommondef('Variant definition');
  1990. write (space,' Varianttype : ');
  1991. b:=getbyte;
  1992. case tvarianttype(b) of
  1993. vt_normalvariant :
  1994. writeln('Normal');
  1995. vt_olevariant :
  1996. writeln('OLE');
  1997. else
  1998. writeln('!! Warning: Invalid varianttype ',b);
  1999. end;
  2000. end;
  2001. iberror :
  2002. begin
  2003. Writeln('!! Error in PPU');
  2004. exit;
  2005. end;
  2006. ibenddefs :
  2007. break;
  2008. else
  2009. WriteLn('!! Skipping unsupported PPU Entry in definitions: ',b);
  2010. end;
  2011. if not EndOfEntry then
  2012. Writeln('!! Entry has more information stored');
  2013. until false;
  2014. end;
  2015. end;
  2016. {****************************************************************************
  2017. Read General Part
  2018. ****************************************************************************}
  2019. procedure readinterface;
  2020. var
  2021. b : byte;
  2022. sourcenumber : longint;
  2023. begin
  2024. with ppufile do
  2025. begin
  2026. repeat
  2027. b:=readentry;
  2028. case b of
  2029. ibmodulename :
  2030. Writeln('Module Name: ',getstring);
  2031. ibsourcefiles :
  2032. begin
  2033. sourcenumber:=1;
  2034. while not EndOfEntry do
  2035. begin
  2036. Writeln('Source file ',sourcenumber,' : ',getstring,' ',filetimestring(getlongint));
  2037. inc(sourcenumber);
  2038. end;
  2039. end;
  2040. {$IFDEF MACRO_DIFF_HINT}
  2041. ibusedmacros :
  2042. begin
  2043. while not EndOfEntry do
  2044. begin
  2045. Write('Conditional ',getstring);
  2046. b:=getbyte;
  2047. if boolean(b)=true then
  2048. write(' defined at startup')
  2049. else
  2050. write(' not defined at startup');
  2051. b:=getbyte;
  2052. if boolean(b)=true then
  2053. writeln(' was used')
  2054. else
  2055. writeln;
  2056. end;
  2057. end;
  2058. {$ENDIF}
  2059. ibloadunit :
  2060. ReadLoadUnit;
  2061. iblinkunitofiles :
  2062. ReadLinkContainer('Link unit object file: ');
  2063. iblinkunitstaticlibs :
  2064. ReadLinkContainer('Link unit static lib: ');
  2065. iblinkunitsharedlibs :
  2066. ReadLinkContainer('Link unit shared lib: ');
  2067. iblinkotherofiles :
  2068. ReadLinkContainer('Link other object file: ');
  2069. iblinkotherstaticlibs :
  2070. ReadLinkContainer('Link other static lib: ');
  2071. iblinkothersharedlibs :
  2072. ReadLinkContainer('Link other shared lib: ');
  2073. iblinkotherframeworks:
  2074. ReadLinkContainer('Link framework: ');
  2075. ibmainname:
  2076. Writeln('Specified main program symbol name: ',getstring);
  2077. ibImportSymbols :
  2078. ReadImportSymbols;
  2079. ibderefdata :
  2080. ReadDerefData;
  2081. ibderefmap :
  2082. ReadDerefMap;
  2083. ibwpofile :
  2084. ReadWpoFileInfo;
  2085. ibresources :
  2086. ReadLinkContainer('Resource file: ');
  2087. iberror :
  2088. begin
  2089. Writeln('Error in PPU');
  2090. exit;
  2091. end;
  2092. ibendinterface :
  2093. break;
  2094. else
  2095. WriteLn('!! Skipping unsupported PPU Entry in General Part: ',b);
  2096. end;
  2097. until false;
  2098. end;
  2099. end;
  2100. {****************************************************************************
  2101. Read Implementation Part
  2102. ****************************************************************************}
  2103. procedure readimplementation;
  2104. var
  2105. b : byte;
  2106. begin
  2107. with ppufile do
  2108. begin
  2109. repeat
  2110. b:=readentry;
  2111. case b of
  2112. ibasmsymbols :
  2113. ReadAsmSymbols;
  2114. ibloadunit :
  2115. ReadLoadUnit;
  2116. iberror :
  2117. begin
  2118. Writeln('Error in PPU');
  2119. exit;
  2120. end;
  2121. ibendimplementation :
  2122. break;
  2123. else
  2124. WriteLn('!! Skipping unsupported PPU Entry in Implementation: ',b);
  2125. end;
  2126. until false;
  2127. end;
  2128. end;
  2129. procedure dofile (filename : string);
  2130. begin
  2131. { reset }
  2132. space:='';
  2133. { fix filename }
  2134. if pos('.',filename)=0 then
  2135. filename:=filename+'.ppu';
  2136. ppufile:=tppufile.create(filename);
  2137. if not ppufile.openfile then
  2138. begin
  2139. writeln ('IO-Error when opening : ',filename,', Skipping');
  2140. exit;
  2141. end;
  2142. { PPU File is open, check for PPU Id }
  2143. if not ppufile.CheckPPUID then
  2144. begin
  2145. writeln(Filename,' : Not a valid PPU file, Skipping');
  2146. exit;
  2147. end;
  2148. { Check PPU Version }
  2149. Writeln('Analyzing ',filename,' (v',ppufile.GetPPUVersion,')');
  2150. if ppufile.GetPPUVersion<16 then
  2151. begin
  2152. writeln(Filename,' : Old PPU Formats (<v16) are not supported, Skipping');
  2153. exit;
  2154. end;
  2155. { Write PPU Header Information }
  2156. if (verbose and v_header)<>0 then
  2157. begin
  2158. Writeln;
  2159. Writeln('Header');
  2160. Writeln('-------');
  2161. with ppufile.header do
  2162. begin
  2163. Writeln('Compiler version : ',ppufile.header.compiler shr 14,'.',
  2164. (ppufile.header.compiler shr 7) and $7f,'.',
  2165. ppufile.header.compiler and $7f);
  2166. WriteLn('Target processor : ',Cpu2Str(cpu));
  2167. WriteLn('Target operating system : ',Target2Str(target));
  2168. Writeln('Unit flags : ',PPUFlags2Str(flags));
  2169. Writeln('FileSize (w/o header) : ',size);
  2170. Writeln('Checksum : ',hexstr(checksum,8));
  2171. Writeln('Interface Checksum : ',hexstr(interface_checksum,8));
  2172. Writeln('Definitions stored : ',tostr(deflistsize));
  2173. Writeln('Symbols stored : ',tostr(symlistsize));
  2174. end;
  2175. end;
  2176. {read the general stuff}
  2177. if (verbose and v_interface)<>0 then
  2178. begin
  2179. Writeln;
  2180. Writeln('Interface section');
  2181. Writeln('------------------');
  2182. readinterface;
  2183. end
  2184. else
  2185. ppufile.skipuntilentry(ibendinterface);
  2186. {read the definitions}
  2187. if (verbose and v_defs)<>0 then
  2188. begin
  2189. Writeln;
  2190. Writeln('Interface definitions');
  2191. Writeln('----------------------');
  2192. readdefinitions('interface');
  2193. end
  2194. else
  2195. ppufile.skipuntilentry(ibenddefs);
  2196. {read the symbols}
  2197. if (verbose and v_syms)<>0 then
  2198. begin
  2199. Writeln;
  2200. Writeln('Interface Symbols');
  2201. Writeln('------------------');
  2202. readsymbols('interface');
  2203. end
  2204. else
  2205. ppufile.skipuntilentry(ibendsyms);
  2206. {read the macro symbols}
  2207. if (verbose and v_syms)<>0 then
  2208. begin
  2209. Writeln;
  2210. Writeln('Interface Macro Symbols');
  2211. Writeln('-----------------------');
  2212. end;
  2213. if ppufile.readentry<>ibexportedmacros then
  2214. begin
  2215. Writeln('!! Error in PPU');
  2216. exit;
  2217. end;
  2218. if boolean(ppufile.getbyte) then
  2219. begin
  2220. {skip the definition section for macros (since they are never used) }
  2221. ppufile.skipuntilentry(ibenddefs);
  2222. {read the macro symbols}
  2223. if (verbose and v_syms)<>0 then
  2224. readsymbols('interface macro')
  2225. else
  2226. ppufile.skipuntilentry(ibendsyms);
  2227. end
  2228. else
  2229. Writeln('(no exported macros)');
  2230. {read the implementation stuff}
  2231. if (verbose and v_implementation)<>0 then
  2232. begin
  2233. Writeln;
  2234. Writeln('Implementation section');
  2235. Writeln('-----------------------');
  2236. readimplementation;
  2237. end
  2238. else
  2239. ppufile.skipuntilentry(ibendimplementation);
  2240. {read the static symtable}
  2241. if (ppufile.header.flags and uf_local_symtable)<>0 then
  2242. begin
  2243. if (verbose and v_defs)<>0 then
  2244. begin
  2245. Writeln;
  2246. Writeln('Static definitions');
  2247. Writeln('----------------------');
  2248. readdefinitions('implementation');
  2249. end
  2250. else
  2251. ppufile.skipuntilentry(ibenddefs);
  2252. {read the symbols}
  2253. if (verbose and v_syms)<>0 then
  2254. begin
  2255. Writeln;
  2256. Writeln('Static Symbols');
  2257. Writeln('------------------');
  2258. readsymbols('implementation');
  2259. end
  2260. else
  2261. ppufile.skipuntilentry(ibendsyms);
  2262. end;
  2263. {shutdown ppufile}
  2264. ppufile.closefile;
  2265. ppufile.free;
  2266. Writeln;
  2267. end;
  2268. procedure help;
  2269. begin
  2270. writeln('usage: ppudump [options] <filename1> <filename2>...');
  2271. writeln;
  2272. writeln('[options] can be:');
  2273. writeln(' -V<verbose> Set verbosity to <verbose>');
  2274. writeln(' H - Show header info');
  2275. writeln(' I - Show interface');
  2276. writeln(' M - Show implementation');
  2277. writeln(' S - Show interface symbols');
  2278. writeln(' D - Show interface definitions');
  2279. // writeln(' B - Show browser info');
  2280. writeln(' A - Show all');
  2281. writeln(' -h, -? This helpscreen');
  2282. halt;
  2283. end;
  2284. var
  2285. startpara,
  2286. nrfile,i : longint;
  2287. para : string;
  2288. begin
  2289. writeln(Title+' '+Version);
  2290. writeln(Copyright);
  2291. writeln;
  2292. if paramcount<1 then
  2293. begin
  2294. writeln('usage: dumpppu [options] <filename1> <filename2>...');
  2295. halt(1);
  2296. end;
  2297. { turn verbose on by default }
  2298. verbose:=v_all;
  2299. { read options }
  2300. startpara:=1;
  2301. while copy(paramstr(startpara),1,1)='-' do
  2302. begin
  2303. para:=paramstr(startpara);
  2304. case upcase(para[2]) of
  2305. 'V' : begin
  2306. verbose:=0;
  2307. for i:=3 to length(para) do
  2308. case upcase(para[i]) of
  2309. 'H' : verbose:=verbose or v_header;
  2310. 'I' : verbose:=verbose or v_interface;
  2311. 'M' : verbose:=verbose or v_implementation;
  2312. 'D' : verbose:=verbose or v_defs;
  2313. 'S' : verbose:=verbose or v_syms;
  2314. 'A' : verbose:=verbose or v_all;
  2315. end;
  2316. end;
  2317. 'H' : help;
  2318. '?' : help;
  2319. end;
  2320. inc(startpara);
  2321. end;
  2322. { process files }
  2323. for nrfile:=startpara to paramcount do
  2324. dofile (paramstr(nrfile));
  2325. if has_errors then
  2326. Halt(1);
  2327. end.