ppudump.pp 74 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573
  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(const derefspace: string);
  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(derefspace,'(',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. { Objective-C method }
  1066. po_objc,
  1067. { enumerator support }
  1068. po_enumerator_movenext,
  1069. { optional Objective-C protocol method }
  1070. po_optional
  1071. );
  1072. tprocoptions=set of tprocoption;
  1073. procedure read_abstract_proc_def(var proccalloption:tproccalloption;var procoptions:tprocoptions);
  1074. type
  1075. tproccallopt=record
  1076. mask : tproccalloption;
  1077. str : string[30];
  1078. end;
  1079. tproctypeopt=record
  1080. mask : tproctypeoption;
  1081. str : string[30];
  1082. end;
  1083. tprocopt=record
  1084. mask : tprocoption;
  1085. str : string[30];
  1086. end;
  1087. const
  1088. proccalloptionStr : array[tproccalloption] of string[14]=('',
  1089. 'CDecl',
  1090. 'CPPDecl',
  1091. 'Far16',
  1092. 'OldFPCCall',
  1093. 'InternProc',
  1094. 'SysCall',
  1095. 'Pascal',
  1096. 'Register',
  1097. 'SafeCall',
  1098. 'StdCall',
  1099. 'SoftFloat',
  1100. 'MWPascal'
  1101. );
  1102. proctypeopt : array[1..ord(high(tproctypeoption))] of tproctypeopt=(
  1103. (mask:potype_proginit; str:'ProgInit'),
  1104. (mask:potype_unitinit; str:'UnitInit'),
  1105. (mask:potype_unitfinalize;str:'UnitFinalize'),
  1106. (mask:potype_constructor; str:'Constructor'),
  1107. (mask:potype_destructor; str:'Destructor'),
  1108. (mask:potype_operator; str:'Operator'),
  1109. (mask:potype_procedure; str:'Procedure'),
  1110. (mask:potype_function; str:'Function')
  1111. );
  1112. procopt : array[1..ord(high(tprocoption))] of tprocopt=(
  1113. (mask:po_classmethod; str:'ClassMethod'),
  1114. (mask:po_virtualmethod; str:'VirtualMethod'),
  1115. (mask:po_abstractmethod; str:'AbstractMethod'),
  1116. (mask:po_finalmethod; str:'FinalMethod'),
  1117. (mask:po_staticmethod; str:'StaticMethod'),
  1118. (mask:po_overridingmethod;str:'OverridingMethod'),
  1119. (mask:po_methodpointer; str:'MethodPointer'),
  1120. (mask:po_interrupt; str:'Interrupt'),
  1121. (mask:po_iocheck; str:'IOCheck'),
  1122. (mask:po_assembler; str:'Assembler'),
  1123. (mask:po_msgstr; str:'MsgStr'),
  1124. (mask:po_msgint; str:'MsgInt'),
  1125. (mask:po_exports; str:'Exports'),
  1126. (mask:po_external; str:'External'),
  1127. (mask:po_overload; str:'Overload'),
  1128. (mask:po_varargs; str:'VarArgs'),
  1129. (mask:po_internconst; str:'InternConst'),
  1130. (mask:po_addressonly; str:'AddressOnly'),
  1131. (mask:po_public; str:'Public'),
  1132. (mask:po_hascallingconvention;str:'HasCallingConvention'),
  1133. (mask:po_reintroduce; str:'ReIntroduce'),
  1134. (mask:po_explicitparaloc; str:'ExplicitParaloc'),
  1135. (mask:po_nostackframe; str:'NoStackFrame'),
  1136. (mask:po_has_mangledname; str:'HasMangledName'),
  1137. (mask:po_has_public_name; str:'HasPublicName'),
  1138. (mask:po_forward; str:'Forward'),
  1139. (mask:po_global; str:'Global'),
  1140. (mask:po_has_inlininginfo;str:'HasInliningInfo'),
  1141. (mask:po_syscall_legacy; str:'SyscallLegacy'),
  1142. (mask:po_syscall_sysv; str:'SyscallSysV'),
  1143. (mask:po_syscall_basesysv;str:'SyscallBaseSysV'),
  1144. (mask:po_syscall_sysvbase;str:'SyscallSysVBase'),
  1145. (mask:po_syscall_r12base; str:'SyscallR12Base'),
  1146. (mask:po_local; str:'Local'),
  1147. (mask:po_inline; str:'Inline'),
  1148. (mask:po_compilerproc; str:'CompilerProc'),
  1149. (mask:po_has_importdll; str:'HasImportDLL'),
  1150. (mask:po_has_importname; str:'HasImportName'),
  1151. (mask:po_kylixlocal; str:'KylixLocal'),
  1152. (mask:po_dispid; str:'DispId'),
  1153. (mask:po_weakexternal; str:'WeakExternal'),
  1154. (mask:po_objc; str:'ObjC'),
  1155. (mask:po_enumerator_movenext; str:'EnumeratorMoveNext'),
  1156. (mask:po_optional; str: 'Optional')
  1157. );
  1158. var
  1159. proctypeoption : tproctypeoption;
  1160. i : longint;
  1161. first : boolean;
  1162. tempbuf : array[0..255] of byte;
  1163. begin
  1164. write(space,' Return type : ');
  1165. readderef('');
  1166. writeln(space,' Fpu used : ',ppufile.getbyte);
  1167. proctypeoption:=tproctypeoption(ppufile.getbyte);
  1168. write(space,' TypeOption : ');
  1169. first:=true;
  1170. for i:=1 to high(proctypeopt) do
  1171. if (proctypeopt[i].mask=proctypeoption) then
  1172. begin
  1173. if first then
  1174. first:=false
  1175. else
  1176. write(', ');
  1177. write(proctypeopt[i].str);
  1178. end;
  1179. writeln;
  1180. proccalloption:=tproccalloption(ppufile.getbyte);
  1181. writeln(space,' CallOption : ',proccalloptionStr[proccalloption]);
  1182. ppufile.getnormalset(procoptions);
  1183. if procoptions<>[] then
  1184. begin
  1185. write(space,' Options : ');
  1186. first:=true;
  1187. for i:=1 to high(procopt) do
  1188. if (procopt[i].mask in procoptions) then
  1189. begin
  1190. if first then
  1191. first:=false
  1192. else
  1193. write(', ');
  1194. write(procopt[i].str);
  1195. end;
  1196. writeln;
  1197. end;
  1198. if (po_explicitparaloc in procoptions) then
  1199. begin
  1200. i:=ppufile.getbyte;
  1201. ppufile.getdata(tempbuf,i);
  1202. end;
  1203. end;
  1204. type
  1205. tvaroption=(vo_none,
  1206. vo_is_external,
  1207. vo_is_dll_var,
  1208. vo_is_thread_var,
  1209. vo_has_local_copy,
  1210. vo_is_const, { variable is declared as const (parameter) and can't be written to }
  1211. vo_is_public,
  1212. vo_is_high_para,
  1213. vo_is_funcret,
  1214. vo_is_self,
  1215. vo_is_vmt,
  1216. vo_is_result, { special result variable }
  1217. vo_is_parentfp,
  1218. vo_is_loop_counter, { used to detect assignments to loop counter }
  1219. vo_is_hidden_para,
  1220. vo_has_explicit_paraloc,
  1221. vo_is_syscall_lib,
  1222. vo_has_mangledname,
  1223. vo_is_typed_const,
  1224. vo_is_range_check,
  1225. vo_is_overflow_check,
  1226. vo_is_typinfo_para,
  1227. vo_is_weak_external
  1228. );
  1229. tvaroptions=set of tvaroption;
  1230. { register variable }
  1231. tvarregable=(vr_none,
  1232. vr_intreg,
  1233. vr_fpureg,
  1234. vr_mmreg,
  1235. { does not mean "needs address register", but "if it's a parameter which is }
  1236. { passed by reference, then its address can be put in a register }
  1237. vr_addr
  1238. );
  1239. procedure readabstractvarsym(const s:string;var varoptions:tvaroptions);
  1240. type
  1241. tvaropt=record
  1242. mask : tvaroption;
  1243. str : string[30];
  1244. end;
  1245. const
  1246. varopt : array[1..ord(high(tvaroption))] of tvaropt=(
  1247. (mask:vo_is_external; str:'External'),
  1248. (mask:vo_is_dll_var; str:'DLLVar'),
  1249. (mask:vo_is_thread_var; str:'ThreadVar'),
  1250. (mask:vo_has_local_copy; str:'HasLocalCopy'),
  1251. (mask:vo_is_const; str:'Constant'),
  1252. (mask:vo_is_public; str:'Public'),
  1253. (mask:vo_is_high_para; str:'HighValue'),
  1254. (mask:vo_is_funcret; str:'Funcret'),
  1255. (mask:vo_is_self; str:'Self'),
  1256. (mask:vo_is_vmt; str:'VMT'),
  1257. (mask:vo_is_result; str:'Result'),
  1258. (mask:vo_is_parentfp; str:'ParentFP'),
  1259. (mask:vo_is_loop_counter; str:'LoopCounter'),
  1260. (mask:vo_is_hidden_para; str:'Hidden'),
  1261. (mask:vo_has_explicit_paraloc;str:'ExplicitParaloc'),
  1262. (mask:vo_is_syscall_lib; str:'SysCallLib'),
  1263. (mask:vo_has_mangledname; str:'HasMangledName'),
  1264. (mask:vo_is_typed_const; str:'TypedConst'),
  1265. (mask:vo_is_range_check; str:'RangeCheckSwitch'),
  1266. (mask:vo_is_overflow_check; str:'OverflowCheckSwitch'),
  1267. (mask:vo_is_typinfo_para; str:'TypeInfo'),
  1268. (mask:vo_is_weak_external;str:'WeakExternal')
  1269. );
  1270. var
  1271. i : longint;
  1272. first : boolean;
  1273. begin
  1274. readcommonsym(s);
  1275. writeln(space,' Spez : ',Varspez2Str(ppufile.getbyte));
  1276. writeln(space,' Regable : ',Varregable2Str(ppufile.getbyte));
  1277. writeln(space,' Addr Taken : ',(ppufile.getbyte<>0));
  1278. write (space,' Var Type : ');
  1279. readderef('');
  1280. ppufile.getsmallset(varoptions);
  1281. if varoptions<>[] then
  1282. begin
  1283. write(space,' Options : ');
  1284. first:=true;
  1285. for i:=1 to high(varopt) do
  1286. if (varopt[i].mask in varoptions) then
  1287. begin
  1288. if first then
  1289. first:=false
  1290. else
  1291. write(', ');
  1292. write(varopt[i].str);
  1293. end;
  1294. writeln;
  1295. end;
  1296. end;
  1297. procedure readobjectdefoptions;
  1298. type
  1299. tobjectoption=(oo_none,
  1300. oo_is_forward, { the class is only a forward declared yet }
  1301. oo_is_abstract, { the class is abstract - only descendants can be used }
  1302. oo_is_sealed, { the class is sealed - can't have descendants }
  1303. oo_has_virtual, { the object/class has virtual methods }
  1304. oo_has_private,
  1305. oo_has_protected,
  1306. oo_has_strictprivate,
  1307. oo_has_strictprotected,
  1308. oo_has_constructor, { the object/class has a constructor }
  1309. oo_has_destructor, { the object/class has a destructor }
  1310. oo_has_vmt, { the object/class has a vmt }
  1311. oo_has_msgstr,
  1312. oo_has_msgint,
  1313. oo_can_have_published,{ the class has rtti, i.e. you can publish properties }
  1314. oo_has_default_property,
  1315. oo_has_valid_guid,
  1316. oo_has_enumerator_movenext,
  1317. oo_has_enumerator_current,
  1318. oo_is_external, { the class is externally implemented (objcclass, cppclass) }
  1319. oo_is_anonymous, { the class is only formally defined in this module (objcclass x = class; external;) }
  1320. oo_is_classhelper { objcclasses that represent categories, and Delpi-style class helpers, are marked like this }
  1321. );
  1322. tobjectoptions=set of tobjectoption;
  1323. tsymopt=record
  1324. mask : tobjectoption;
  1325. str : string[30];
  1326. end;
  1327. const
  1328. symopt : array[1..ord(high(tobjectoption))] of tsymopt=(
  1329. (mask:oo_is_forward; str:'IsForward'),
  1330. (mask:oo_is_abstract; str:'IsAbstract'),
  1331. (mask:oo_is_sealed; str:'IsSealed'),
  1332. (mask:oo_has_virtual; str:'HasVirtual'),
  1333. (mask:oo_has_private; str:'HasPrivate'),
  1334. (mask:oo_has_protected; str:'HasProtected'),
  1335. (mask:oo_has_strictprivate; str:'HasStrictPrivate'),
  1336. (mask:oo_has_strictprotected;str:'HasStrictProtected'),
  1337. (mask:oo_has_constructor; str:'HasConstructor'),
  1338. (mask:oo_has_destructor; str:'HasDestructor'),
  1339. (mask:oo_has_vmt; str:'HasVMT'),
  1340. (mask:oo_has_msgstr; str:'HasMsgStr'),
  1341. (mask:oo_has_msgint; str:'HasMsgInt'),
  1342. (mask:oo_can_have_published; str:'CanHavePublished'),
  1343. (mask:oo_has_default_property;str:'HasDefaultProperty'),
  1344. (mask:oo_has_valid_guid; str:'HasValidGUID'),
  1345. (mask:oo_has_enumerator_movenext; str:'HasEnumeratorMoveNext'),
  1346. (mask:oo_has_enumerator_current; str:'HasEnumeratorCurrent'),
  1347. (mask:oo_is_external; str:'External'),
  1348. (mask:oo_is_anonymous; str:'Anonymous'),
  1349. (mask:oo_is_classhelper; str:'Class Helper/Category'));
  1350. var
  1351. symoptions : tobjectoptions;
  1352. i : longint;
  1353. first : boolean;
  1354. begin
  1355. ppufile.getsmallset(symoptions);
  1356. if symoptions<>[] then
  1357. begin
  1358. first:=true;
  1359. for i:=1 to high(symopt) do
  1360. if (symopt[i].mask in symoptions) then
  1361. begin
  1362. if first then
  1363. first:=false
  1364. else
  1365. write(', ');
  1366. write(symopt[i].str);
  1367. end;
  1368. end;
  1369. writeln;
  1370. end;
  1371. procedure readarraydefoptions;
  1372. type
  1373. tarraydefoption=(ado_none,
  1374. ado_IsConvertedPointer,
  1375. ado_IsDynamicArray,
  1376. ado_IsVariant,
  1377. ado_IsConstructor,
  1378. ado_IsArrayOfConst,
  1379. ado_IsConstString,
  1380. ado_IsBitPacked
  1381. );
  1382. tarraydefoptions=set of tarraydefoption;
  1383. tsymopt=record
  1384. mask : tarraydefoption;
  1385. str : string[30];
  1386. end;
  1387. const
  1388. symopt : array[1..ord(high(tarraydefoption))] of tsymopt=(
  1389. (mask:ado_IsConvertedPointer;str:'ConvertedPointer'),
  1390. (mask:ado_IsDynamicArray; str:'IsDynamicArray'),
  1391. (mask:ado_IsVariant; str:'IsVariant'),
  1392. (mask:ado_IsConstructor; str:'IsConstructor'),
  1393. (mask:ado_IsArrayOfConst; str:'ArrayOfConst'),
  1394. (mask:ado_IsConstString; str:'ConstString'),
  1395. (mask:ado_IsBitPacked; str:'BitPacked')
  1396. );
  1397. var
  1398. symoptions : tarraydefoptions;
  1399. i : longint;
  1400. first : boolean;
  1401. begin
  1402. ppufile.getsmallset(symoptions);
  1403. if symoptions<>[] then
  1404. begin
  1405. first:=true;
  1406. for i:=1 to high(symopt) do
  1407. if (symopt[i].mask in symoptions) then
  1408. begin
  1409. if first then
  1410. first:=false
  1411. else
  1412. write(', ');
  1413. write(symopt[i].str);
  1414. end;
  1415. end;
  1416. writeln;
  1417. end;
  1418. procedure readnodetree;
  1419. var
  1420. l : longint;
  1421. p : pointer;
  1422. begin
  1423. with ppufile do
  1424. begin
  1425. if space<>'' then
  1426. Writeln(space,'------ nodetree ------');
  1427. if readentry=ibnodetree then
  1428. begin
  1429. l:=entrysize;
  1430. Writeln(space,'Tree size : ',l);
  1431. { Read data to prevent error that entry is not completly read }
  1432. getmem(p,l);
  1433. getdata(p^,l);
  1434. freemem(p);
  1435. end
  1436. else
  1437. begin
  1438. Writeln('!! ibnodetree not found');
  1439. end;
  1440. end;
  1441. end;
  1442. procedure ReadCreatedObjTypes;
  1443. var
  1444. i,j,
  1445. len,
  1446. bssize: longint;
  1447. bs: pbyte;
  1448. begin
  1449. if ppufile.readentry<>ibcreatedobjtypes then
  1450. begin
  1451. writeln('!! ibcreatedobjtypes entry not found');
  1452. ppufile.skipdata(ppufile.entrysize);
  1453. exit
  1454. end;
  1455. writeln;
  1456. writeln(space,'WPO info');
  1457. writeln(space,'--------');
  1458. len:=ppufile.getlongint;
  1459. writeln(space,'** Instantiated Object/Class types: ',len,' **');
  1460. space:=space+' ';
  1461. for i:=0 to len-1 do
  1462. readderef(space);
  1463. setlength(space,length(space)-2);
  1464. len:=ppufile.getlongint;
  1465. writeln(space,'** Instantiated ClassRef types: ',len,' **');
  1466. space:=space+' ';
  1467. for i:=0 to len-1 do
  1468. readderef(space);
  1469. setlength(space,length(space)-2);
  1470. len:=ppufile.getlongint;
  1471. writeln(space,'** Possibly instantiated ClassRef types : ',len,' **');
  1472. space:=space+' ';
  1473. for i:=0 to len-1 do
  1474. readderef(space);
  1475. setlength(space,length(space)-2);
  1476. len:=ppufile.getlongint;
  1477. writeln(space,'** Class types with called virtual methods info : ',len,' **');
  1478. space:=space+' ';
  1479. for i:=0 to len-1 do
  1480. begin
  1481. write(space,'Class def : ');
  1482. readderef('');
  1483. write(space+' ','Called vmtentries : ');
  1484. bssize:=ppufile.getlongint;
  1485. getmem(bs,bssize);
  1486. ppufile.readdata(bs^,bssize);
  1487. for j:=0 to bssize*8-1 do
  1488. if (((bs+j shr 3)^ shr (j and 7)) and 1) <> 0 then
  1489. write(j,', ');
  1490. writeln;
  1491. freemem(bs);
  1492. end;
  1493. setlength(space,length(space)-2);
  1494. end;
  1495. {****************************************************************************
  1496. Read Symbols Part
  1497. ****************************************************************************}
  1498. procedure readsymbols(const s:string);
  1499. type
  1500. pguid = ^tguid;
  1501. tguid = packed record
  1502. D1: LongWord;
  1503. D2: Word;
  1504. D3: Word;
  1505. D4: array[0..7] of Byte;
  1506. end;
  1507. absolutetyp = (tovar,toasm,toaddr);
  1508. tconsttyp = (constnone,
  1509. constord,conststring,constreal,
  1510. constset,constpointer,constnil,
  1511. constresourcestring,constwstring,constguid
  1512. );
  1513. var
  1514. b : byte;
  1515. pc : pchar;
  1516. i,j,len : longint;
  1517. guid : tguid;
  1518. tempbuf : array[0..127] of char;
  1519. varoptions : tvaroptions;
  1520. begin
  1521. with ppufile do
  1522. begin
  1523. if space<>'' then
  1524. Writeln(space,'------ ',s,' ------');
  1525. if readentry=ibstartsyms then
  1526. begin
  1527. Writeln(space,'Symtable datasize : ',getlongint);
  1528. Writeln(space,'Symtable alignment: ',getlongint);
  1529. end
  1530. else
  1531. Writeln('!! ibstartsym not found');
  1532. repeat
  1533. b:=readentry;
  1534. case b of
  1535. ibunitsym :
  1536. readcommonsym('Unit symbol ');
  1537. iblabelsym :
  1538. readcommonsym('Label symbol ');
  1539. ibtypesym :
  1540. begin
  1541. readcommonsym('Type symbol ');
  1542. write(space,' Result Type : ');
  1543. readderef('');
  1544. end;
  1545. ibprocsym :
  1546. begin
  1547. readcommonsym('Procedure symbol ');
  1548. len:=ppufile.getword;
  1549. for i:=1 to len do
  1550. begin
  1551. write(space,' Definition : ');
  1552. readderef('');
  1553. end;
  1554. end;
  1555. ibconstsym :
  1556. begin
  1557. readcommonsym('Constant symbol ');
  1558. b:=getbyte;
  1559. case tconsttyp(b) of
  1560. constord :
  1561. begin
  1562. write (space,' OrdinalType : ');
  1563. readderef('');
  1564. writeln(space,' Value : ',constexp.tostr(getexprint));
  1565. end;
  1566. constpointer :
  1567. begin
  1568. write (space,' PointerType : ');
  1569. readderef('');
  1570. writeln(space,' Value : ',getlongint)
  1571. end;
  1572. conststring,
  1573. constresourcestring :
  1574. begin
  1575. len:=getlongint;
  1576. getmem(pc,len+1);
  1577. getdata(pc^,len);
  1578. (pc+len)^:= #0;
  1579. writeln(space,' Length : ',len);
  1580. writeln(space,' Value : "',pc,'"');
  1581. freemem(pc,len+1);
  1582. end;
  1583. constreal :
  1584. writeln(space,' Value : ',getreal);
  1585. constset :
  1586. begin
  1587. write (space,' Set Type : ');
  1588. readderef('');
  1589. for i:=1to 4 do
  1590. begin
  1591. write (space,' Value : ');
  1592. for j:=1to 8 do
  1593. begin
  1594. if j>1 then
  1595. write(',');
  1596. write(hexstr(getbyte,2));
  1597. end;
  1598. writeln;
  1599. end;
  1600. end;
  1601. constwstring:
  1602. begin
  1603. end;
  1604. constguid:
  1605. begin
  1606. getdata(guid,sizeof(guid));
  1607. write (space,' IID String: {',hexstr(guid.d1,8),'-',hexstr(guid.d2,4),'-',hexstr(guid.d3,4),'-');
  1608. for i:=0 to 7 do
  1609. begin
  1610. write(hexstr(guid.d4[i],2));
  1611. if i=1 then write('-');
  1612. end;
  1613. writeln('}');
  1614. end
  1615. else
  1616. Writeln ('!! Invalid unit format : Invalid const type encountered: ',b);
  1617. end;
  1618. end;
  1619. ibabsolutevarsym :
  1620. begin
  1621. readabstractvarsym('Absolute variable symbol ',varoptions);
  1622. Write (space,' Relocated to ');
  1623. b:=getbyte;
  1624. case absolutetyp(b) of
  1625. tovar :
  1626. readpropaccesslist(space+' Sym : ');
  1627. toasm :
  1628. Writeln('Assembler name : ',getstring);
  1629. toaddr :
  1630. begin
  1631. Write('Address : ',getlongint);
  1632. if tsystemcpu(ppufile.header.cpu)=cpu_i386 then
  1633. WriteLn(' (Far: ',getbyte<>0,')');
  1634. end;
  1635. else
  1636. Writeln ('!! Invalid unit format : Invalid absolute type encountered: ',b);
  1637. end;
  1638. end;
  1639. ibfieldvarsym :
  1640. begin
  1641. readabstractvarsym('Field Variable symbol ',varoptions);
  1642. writeln(space,' Address : ',getaint);
  1643. end;
  1644. ibstaticvarsym :
  1645. begin
  1646. readabstractvarsym('Global Variable symbol ',varoptions);
  1647. write (space,' DefaultConst : ');
  1648. readderef('');
  1649. if (vo_has_mangledname in varoptions) then
  1650. writeln(space,' Mangledname : ',getstring);
  1651. end;
  1652. iblocalvarsym :
  1653. begin
  1654. readabstractvarsym('Local Variable symbol ',varoptions);
  1655. write (space,' DefaultConst : ');
  1656. readderef('');
  1657. end;
  1658. ibparavarsym :
  1659. begin
  1660. readabstractvarsym('Parameter Variable symbol ',varoptions);
  1661. write (space,' DefaultConst : ');
  1662. readderef('');
  1663. writeln(space,' ParaNr : ',getword);
  1664. writeln(space,' VarState : ',getbyte);
  1665. if (vo_has_explicit_paraloc in varoptions) then
  1666. begin
  1667. i:=getbyte;
  1668. getdata(tempbuf,i);
  1669. end;
  1670. end;
  1671. ibenumsym :
  1672. begin
  1673. readcommonsym('Enumeration symbol ');
  1674. write (space,' Definition : ');
  1675. readderef('');
  1676. writeln(space,' Value : ',getlongint);
  1677. end;
  1678. ibsyssym :
  1679. begin
  1680. readcommonsym('Internal system symbol ');
  1681. writeln(space,' Internal Nr : ',getlongint);
  1682. end;
  1683. ibmacrosym :
  1684. begin
  1685. readcommonsym('Macro symbol ');
  1686. writeln(space,' Name: ',getstring);
  1687. writeln(space,' Defined: ',getbyte);
  1688. writeln(space,' Compiler var: ',getbyte);
  1689. len:=getlongint;
  1690. writeln(space,' Value length: ',len);
  1691. if len > 0 then
  1692. begin
  1693. getmem(pc,len+1);
  1694. getdata(pc^,len);
  1695. (pc+len)^:= #0;
  1696. writeln(space,' Value: "',pc,'"');
  1697. freemem(pc,len+1);
  1698. end;
  1699. end;
  1700. ibpropertysym :
  1701. begin
  1702. readcommonsym('Property ');
  1703. i:=getlongint;
  1704. writeln(space,' PropOptions : ',i);
  1705. write (space,' OverrideProp : ');
  1706. readderef('');
  1707. write (space,' Prop Type : ');
  1708. readderef('');
  1709. writeln(space,' Index : ',getlongint);
  1710. writeln(space,' Default : ',getlongint);
  1711. write (space,' Index Type : ');
  1712. readderef('');
  1713. write (space,' Readaccess : ');
  1714. readpropaccesslist(space+' Sym: ');
  1715. write (space,' Writeaccess : ');
  1716. readpropaccesslist(space+' Sym: ');
  1717. write (space,' Storedaccess : ');
  1718. readpropaccesslist(space+' Sym: ');
  1719. end;
  1720. iberror :
  1721. begin
  1722. Writeln('!! Error in PPU');
  1723. exit;
  1724. end;
  1725. ibendsyms :
  1726. break;
  1727. else
  1728. WriteLn('!! Skipping unsupported PPU Entry in Symbols: ',b);
  1729. end;
  1730. if not EndOfEntry then
  1731. Writeln('!! Entry has more information stored');
  1732. until false;
  1733. end;
  1734. end;
  1735. {****************************************************************************
  1736. Read defintions Part
  1737. ****************************************************************************}
  1738. procedure readdefinitions(const s:string);
  1739. type
  1740. tordtype = (
  1741. uvoid,
  1742. u8bit,u16bit,u32bit,u64bit,
  1743. s8bit,s16bit,s32bit,s64bit,
  1744. bool8bit,bool16bit,bool32bit,bool64bit,
  1745. uchar,uwidechar,scurrency
  1746. );
  1747. tobjecttyp = (odt_none,
  1748. odt_class,
  1749. odt_object,
  1750. odt_interfacecom,
  1751. odt_interfacecom_property,
  1752. odt_interfacecom_function,
  1753. odt_interfacecorba,
  1754. odt_cppclass,
  1755. odt_dispinterface,
  1756. odt_objcclass,
  1757. odt_objcprotocol
  1758. );
  1759. tvarianttype = (
  1760. vt_normalvariant,vt_olevariant
  1761. );
  1762. var
  1763. b : byte;
  1764. l,j : longint;
  1765. calloption : tproccalloption;
  1766. procoptions : tprocoptions;
  1767. procinfooptions : tprocinfoflag;
  1768. begin
  1769. with ppufile do
  1770. begin
  1771. if space<>'' then
  1772. Writeln(space,'------ ',s,' ------');
  1773. if readentry<>ibstartdefs then
  1774. Writeln('!! ibstartdefs not found');
  1775. repeat
  1776. b:=readentry;
  1777. case b of
  1778. ibpointerdef :
  1779. begin
  1780. readcommondef('Pointer definition');
  1781. write (space,' Pointed Type : ');
  1782. readderef('');
  1783. writeln(space,' Is Far : ',(getbyte<>0));
  1784. end;
  1785. iborddef :
  1786. begin
  1787. readcommondef('Ordinal definition');
  1788. write (space,' Base type : ');
  1789. b:=getbyte;
  1790. case tordtype(b) of
  1791. uvoid : writeln('uvoid');
  1792. u8bit : writeln('u8bit');
  1793. u16bit : writeln('u16bit');
  1794. u32bit : writeln('s32bit');
  1795. u64bit : writeln('u64bit');
  1796. s8bit : writeln('s8bit');
  1797. s16bit : writeln('s16bit');
  1798. s32bit : writeln('s32bit');
  1799. s64bit : writeln('s64bit');
  1800. bool8bit : writeln('bool8bit');
  1801. bool16bit : writeln('bool16bit');
  1802. bool32bit : writeln('bool32bit');
  1803. bool64bit : writeln('bool64bit');
  1804. uchar : writeln('uchar');
  1805. uwidechar : writeln('uwidechar');
  1806. scurrency : writeln('ucurrency');
  1807. else writeln('!! Warning: Invalid base type ',b);
  1808. end;
  1809. writeln(space,' Range : ',constexp.tostr(getexprint),' to ',constexp.tostr(getexprint));
  1810. end;
  1811. ibfloatdef :
  1812. begin
  1813. readcommondef('Float definition');
  1814. writeln(space,' Float type : ',getbyte);
  1815. end;
  1816. ibarraydef :
  1817. begin
  1818. readcommondef('Array definition');
  1819. write (space,' Element type : ');
  1820. readderef('');
  1821. write (space,' Range Type : ');
  1822. readderef('');
  1823. writeln(space,' Range : ',getaint,' to ',getaint);
  1824. write (space,' Options : ');
  1825. readarraydefoptions;
  1826. end;
  1827. ibprocdef :
  1828. begin
  1829. readcommondef('Procedure definition');
  1830. read_abstract_proc_def(calloption,procoptions);
  1831. if (po_has_mangledname in procoptions) then
  1832. writeln(space,' Mangled name : ',getstring);
  1833. writeln(space,' Number : ',getword);
  1834. writeln(space,' Level : ',getbyte);
  1835. write (space,' Class : ');
  1836. readderef('');
  1837. write (space,' Procsym : ');
  1838. readderef('');
  1839. write (space,' File Pos : ');
  1840. readposinfo;
  1841. writeln(space,' Visibility : ',Visibility2Str(ppufile.getbyte));
  1842. write (space,' SymOptions : ');
  1843. readsymoptions(space+' ');
  1844. if tsystemcpu(ppufile.header.cpu)=cpu_powerpc then
  1845. begin
  1846. { library symbol for AmigaOS/MorphOS }
  1847. write (space,' Library symbol : ');
  1848. readderef('');
  1849. end;
  1850. if (po_has_importdll in procoptions) then
  1851. writeln(space,' Import DLL : ',getstring);
  1852. if (po_has_importname in procoptions) then
  1853. writeln(space,' Import Name : ',getstring);
  1854. writeln(space,' Import Nr : ',getword);
  1855. if (po_msgint in procoptions) then
  1856. writeln(space,' MsgInt : ',getlongint);
  1857. if (po_msgstr in procoptions) then
  1858. writeln(space,' MsgStr : ',getstring);
  1859. if (po_dispid in procoptions) then
  1860. writeln(space,' DispID: ',ppufile.getlongint);
  1861. if (po_has_inlininginfo in procoptions) then
  1862. begin
  1863. write (space,' FuncretSym : ');
  1864. readderef('');
  1865. ppufile.getsmallset(procinfooptions);
  1866. writeln(space,' ProcInfoOptions : ',dword(procinfooptions));
  1867. end;
  1868. b:=ppufile.getbyte;
  1869. if b<>0 then
  1870. begin
  1871. write (space,' Alias names : ');
  1872. for j:=1 to b do
  1873. begin
  1874. write(ppufile.getstring);
  1875. if j<b then
  1876. write(', ');
  1877. end;
  1878. writeln;
  1879. end;
  1880. if not EndOfEntry then
  1881. Writeln('!! Entry has more information stored');
  1882. space:=' '+space;
  1883. { parast }
  1884. readdefinitions('parast');
  1885. readsymbols('parast');
  1886. { localst }
  1887. if (po_has_inlininginfo in procoptions) then
  1888. begin
  1889. readdefinitions('localst');
  1890. readsymbols('localst');
  1891. end;
  1892. if (po_has_inlininginfo in procoptions) then
  1893. readnodetree;
  1894. delete(space,1,4);
  1895. end;
  1896. ibprocvardef :
  1897. begin
  1898. readcommondef('Procedural type (ProcVar) definition');
  1899. read_abstract_proc_def(calloption,procoptions);
  1900. if not EndOfEntry then
  1901. Writeln('!! Entry has more information stored');
  1902. space:=' '+space;
  1903. { parast }
  1904. readdefinitions('parast');
  1905. readsymbols('parast');
  1906. delete(space,1,4);
  1907. end;
  1908. ibshortstringdef :
  1909. begin
  1910. readcommondef('ShortString definition');
  1911. writeln(space,' Length : ',getbyte);
  1912. end;
  1913. ibwidestringdef :
  1914. begin
  1915. readcommondef('WideString definition');
  1916. writeln(space,' Length : ',getlongint);
  1917. end;
  1918. ibansistringdef :
  1919. begin
  1920. readcommondef('AnsiString definition');
  1921. writeln(space,' Length : ',getlongint);
  1922. end;
  1923. iblongstringdef :
  1924. begin
  1925. readcommondef('Longstring definition');
  1926. writeln(space,' Length : ',getlongint);
  1927. end;
  1928. ibrecorddef :
  1929. begin
  1930. readcommondef('Record definition');
  1931. writeln(space,' FieldAlign : ',getbyte);
  1932. writeln(space,' RecordAlign : ',getbyte);
  1933. writeln(space,' PadAlign : ',getbyte);
  1934. writeln(space,'UseFieldAlignment : ',getbyte);
  1935. writeln(space,' DataSize : ',getaint);
  1936. if not EndOfEntry then
  1937. Writeln('!! Entry has more information stored');
  1938. {read the record definitions and symbols}
  1939. space:=' '+space;
  1940. readdefinitions('fields');
  1941. readsymbols('fields');
  1942. Delete(space,1,4);
  1943. end;
  1944. ibobjectdef :
  1945. begin
  1946. readcommondef('Object/Class definition');
  1947. b:=getbyte;
  1948. write (space,' Type : ');
  1949. case tobjecttyp(b) of
  1950. odt_class : writeln('class');
  1951. odt_object : writeln('object');
  1952. odt_interfacecom : writeln('interfacecom');
  1953. odt_interfacecorba : writeln('interfacecorba');
  1954. odt_cppclass : writeln('cppclass');
  1955. odt_dispinterface : writeln('dispinterface');
  1956. odt_objcclass : writeln('objcclass');
  1957. odt_objcprotocol : writeln('objcprotocol');
  1958. else writeln('!! Warning: Invalid object type ',b);
  1959. end;
  1960. writeln(space,' Name of Class : ',getstring);
  1961. writeln(space,' External name : ',getstring);
  1962. writeln(space,' Import lib : ',getstring);
  1963. writeln(space,' DataSize : ',getaint);
  1964. writeln(space,' FieldAlign : ',getbyte);
  1965. writeln(space,' RecordAlign : ',getbyte);
  1966. writeln(space,' Vmt offset : ',getlongint);
  1967. write (space, ' Ancestor Class : ');
  1968. readderef('');
  1969. write (space,' Options : ');
  1970. readobjectdefoptions;
  1971. if tobjecttyp(b) in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  1972. begin
  1973. { IIDGUID }
  1974. for j:=1to 16 do
  1975. getbyte;
  1976. writeln(space,' IID String : ',getstring);
  1977. writeln(space,' Last VTable idx : ',getlongint);
  1978. end;
  1979. l:=getlongint;
  1980. writeln(space,' VMT entries: ',l);
  1981. for j:=1 to l do
  1982. begin
  1983. write(space,' ');
  1984. readderef('');
  1985. writeln(space,' Visibility: ',Visibility2Str(getbyte));
  1986. end;
  1987. if tobjecttyp(b) in [odt_class,odt_interfacecorba,odt_objcclass,odt_objcprotocol] then
  1988. begin
  1989. l:=getlongint;
  1990. writeln(space,' Impl Intf Count : ',l);
  1991. for j:=1 to l do
  1992. begin
  1993. write (space,' - Definition : ');
  1994. readderef('');
  1995. writeln(space,' IOffset : ',getlongint);
  1996. end;
  1997. end;
  1998. if df_copied_def in current_defoptions then
  1999. begin
  2000. writeln(' Copy of def: ');
  2001. readderef('');
  2002. end;
  2003. if not EndOfEntry then
  2004. Writeln('!! Entry has more information stored');
  2005. if not(df_copied_def in current_defoptions) then
  2006. begin
  2007. {read the record definitions and symbols}
  2008. space:=' '+space;
  2009. readdefinitions('fields');
  2010. readsymbols('fields');
  2011. Delete(space,1,4);
  2012. end;
  2013. end;
  2014. ibfiledef :
  2015. begin
  2016. ReadCommonDef('File definition');
  2017. write (space,' Type : ');
  2018. case getbyte of
  2019. 0 : writeln('Text');
  2020. 1 : begin
  2021. writeln('Typed');
  2022. write (space,' File of Type : ');
  2023. readderef('');
  2024. end;
  2025. 2 : writeln('Untyped');
  2026. end;
  2027. end;
  2028. ibformaldef :
  2029. begin
  2030. readcommondef('Generic definition (void-typ)');
  2031. writeln(space,' Is Typed : ',(getbyte<>0));
  2032. end;
  2033. ibundefineddef :
  2034. readcommondef('Undefined definition (generic parameter)');
  2035. ibenumdef :
  2036. begin
  2037. readcommondef('Enumeration type definition');
  2038. write(space,'Base enumeration type : ');
  2039. readderef('');
  2040. writeln(space,' Smallest element : ',getaint);
  2041. writeln(space,' Largest element : ',getaint);
  2042. writeln(space,' Size : ',getaint);
  2043. end;
  2044. ibclassrefdef :
  2045. begin
  2046. readcommondef('Class reference definition');
  2047. write (space,' Pointed Type : ');
  2048. readderef('');
  2049. end;
  2050. ibsetdef :
  2051. begin
  2052. readcommondef('Set definition');
  2053. write (space,' Element type : ');
  2054. readderef('');
  2055. writeln(space,' Size : ',getaint);
  2056. writeln(space,' Set Base : ',getaint);
  2057. writeln(space,' Set Max : ',getaint);
  2058. end;
  2059. ibvariantdef :
  2060. begin
  2061. readcommondef('Variant definition');
  2062. write (space,' Varianttype : ');
  2063. b:=getbyte;
  2064. case tvarianttype(b) of
  2065. vt_normalvariant :
  2066. writeln('Normal');
  2067. vt_olevariant :
  2068. writeln('OLE');
  2069. else
  2070. writeln('!! Warning: Invalid varianttype ',b);
  2071. end;
  2072. end;
  2073. iberror :
  2074. begin
  2075. Writeln('!! Error in PPU');
  2076. exit;
  2077. end;
  2078. ibenddefs :
  2079. break;
  2080. else
  2081. WriteLn('!! Skipping unsupported PPU Entry in definitions: ',b);
  2082. end;
  2083. if not EndOfEntry then
  2084. Writeln('!! Entry has more information stored');
  2085. until false;
  2086. end;
  2087. end;
  2088. {****************************************************************************
  2089. Read General Part
  2090. ****************************************************************************}
  2091. procedure readinterface;
  2092. var
  2093. b : byte;
  2094. sourcenumber : longint;
  2095. begin
  2096. with ppufile do
  2097. begin
  2098. repeat
  2099. b:=readentry;
  2100. case b of
  2101. ibmodulename :
  2102. Writeln('Module Name: ',getstring);
  2103. ibsourcefiles :
  2104. begin
  2105. sourcenumber:=1;
  2106. while not EndOfEntry do
  2107. begin
  2108. Writeln('Source file ',sourcenumber,' : ',getstring,' ',filetimestring(getlongint));
  2109. inc(sourcenumber);
  2110. end;
  2111. end;
  2112. {$IFDEF MACRO_DIFF_HINT}
  2113. ibusedmacros :
  2114. begin
  2115. while not EndOfEntry do
  2116. begin
  2117. Write('Conditional ',getstring);
  2118. b:=getbyte;
  2119. if boolean(b)=true then
  2120. write(' defined at startup')
  2121. else
  2122. write(' not defined at startup');
  2123. b:=getbyte;
  2124. if boolean(b)=true then
  2125. writeln(' was used')
  2126. else
  2127. writeln;
  2128. end;
  2129. end;
  2130. {$ENDIF}
  2131. ibloadunit :
  2132. ReadLoadUnit;
  2133. iblinkunitofiles :
  2134. ReadLinkContainer('Link unit object file: ');
  2135. iblinkunitstaticlibs :
  2136. ReadLinkContainer('Link unit static lib: ');
  2137. iblinkunitsharedlibs :
  2138. ReadLinkContainer('Link unit shared lib: ');
  2139. iblinkotherofiles :
  2140. ReadLinkContainer('Link other object file: ');
  2141. iblinkotherstaticlibs :
  2142. ReadLinkContainer('Link other static lib: ');
  2143. iblinkothersharedlibs :
  2144. ReadLinkContainer('Link other shared lib: ');
  2145. iblinkotherframeworks:
  2146. ReadLinkContainer('Link framework: ');
  2147. ibmainname:
  2148. Writeln('Specified main program symbol name: ',getstring);
  2149. ibImportSymbols :
  2150. ReadImportSymbols;
  2151. ibderefdata :
  2152. ReadDerefData;
  2153. ibderefmap :
  2154. ReadDerefMap;
  2155. ibwpofile :
  2156. ReadWpoFileInfo;
  2157. ibresources :
  2158. ReadLinkContainer('Resource file: ');
  2159. iberror :
  2160. begin
  2161. Writeln('Error in PPU');
  2162. exit;
  2163. end;
  2164. ibendinterface :
  2165. break;
  2166. else
  2167. WriteLn('!! Skipping unsupported PPU Entry in General Part: ',b);
  2168. end;
  2169. until false;
  2170. end;
  2171. end;
  2172. {****************************************************************************
  2173. Read Implementation Part
  2174. ****************************************************************************}
  2175. procedure readimplementation;
  2176. var
  2177. b : byte;
  2178. begin
  2179. with ppufile do
  2180. begin
  2181. repeat
  2182. b:=readentry;
  2183. case b of
  2184. ibasmsymbols :
  2185. ReadAsmSymbols;
  2186. ibloadunit :
  2187. ReadLoadUnit;
  2188. iberror :
  2189. begin
  2190. Writeln('Error in PPU');
  2191. exit;
  2192. end;
  2193. ibendimplementation :
  2194. break;
  2195. else
  2196. WriteLn('!! Skipping unsupported PPU Entry in Implementation: ',b);
  2197. end;
  2198. until false;
  2199. end;
  2200. end;
  2201. procedure dofile (filename : string);
  2202. begin
  2203. { reset }
  2204. space:='';
  2205. { fix filename }
  2206. if pos('.',filename)=0 then
  2207. filename:=filename+'.ppu';
  2208. ppufile:=tppufile.create(filename);
  2209. if not ppufile.openfile then
  2210. begin
  2211. writeln ('IO-Error when opening : ',filename,', Skipping');
  2212. exit;
  2213. end;
  2214. { PPU File is open, check for PPU Id }
  2215. if not ppufile.CheckPPUID then
  2216. begin
  2217. writeln(Filename,' : Not a valid PPU file, Skipping');
  2218. exit;
  2219. end;
  2220. { Check PPU Version }
  2221. Writeln('Analyzing ',filename,' (v',ppufile.GetPPUVersion,')');
  2222. if ppufile.GetPPUVersion<16 then
  2223. begin
  2224. writeln(Filename,' : Old PPU Formats (<v16) are not supported, Skipping');
  2225. exit;
  2226. end;
  2227. { Write PPU Header Information }
  2228. if (verbose and v_header)<>0 then
  2229. begin
  2230. Writeln;
  2231. Writeln('Header');
  2232. Writeln('-------');
  2233. with ppufile.header do
  2234. begin
  2235. Writeln('Compiler version : ',ppufile.header.compiler shr 14,'.',
  2236. (ppufile.header.compiler shr 7) and $7f,'.',
  2237. ppufile.header.compiler and $7f);
  2238. WriteLn('Target processor : ',Cpu2Str(cpu));
  2239. WriteLn('Target operating system : ',Target2Str(target));
  2240. Writeln('Unit flags : ',PPUFlags2Str(flags));
  2241. Writeln('FileSize (w/o header) : ',size);
  2242. Writeln('Checksum : ',hexstr(checksum,8));
  2243. Writeln('Interface Checksum : ',hexstr(interface_checksum,8));
  2244. Writeln('Definitions stored : ',tostr(deflistsize));
  2245. Writeln('Symbols stored : ',tostr(symlistsize));
  2246. end;
  2247. end;
  2248. {read the general stuff}
  2249. if (verbose and v_interface)<>0 then
  2250. begin
  2251. Writeln;
  2252. Writeln('Interface section');
  2253. Writeln('------------------');
  2254. readinterface;
  2255. end
  2256. else
  2257. ppufile.skipuntilentry(ibendinterface);
  2258. {read the definitions}
  2259. if (verbose and v_defs)<>0 then
  2260. begin
  2261. Writeln;
  2262. Writeln('Interface definitions');
  2263. Writeln('----------------------');
  2264. readdefinitions('interface');
  2265. end
  2266. else
  2267. ppufile.skipuntilentry(ibenddefs);
  2268. {read the symbols}
  2269. if (verbose and v_syms)<>0 then
  2270. begin
  2271. Writeln;
  2272. Writeln('Interface Symbols');
  2273. Writeln('------------------');
  2274. readsymbols('interface');
  2275. end
  2276. else
  2277. ppufile.skipuntilentry(ibendsyms);
  2278. {read the macro symbols}
  2279. if (verbose and v_syms)<>0 then
  2280. begin
  2281. Writeln;
  2282. Writeln('Interface Macro Symbols');
  2283. Writeln('-----------------------');
  2284. end;
  2285. if ppufile.readentry<>ibexportedmacros then
  2286. begin
  2287. Writeln('!! Error in PPU');
  2288. exit;
  2289. end;
  2290. if boolean(ppufile.getbyte) then
  2291. begin
  2292. {skip the definition section for macros (since they are never used) }
  2293. ppufile.skipuntilentry(ibenddefs);
  2294. {read the macro symbols}
  2295. if (verbose and v_syms)<>0 then
  2296. readsymbols('interface macro')
  2297. else
  2298. ppufile.skipuntilentry(ibendsyms);
  2299. end
  2300. else
  2301. Writeln('(no exported macros)');
  2302. {read the implementation stuff}
  2303. if (verbose and v_implementation)<>0 then
  2304. begin
  2305. Writeln;
  2306. Writeln('Implementation section');
  2307. Writeln('-----------------------');
  2308. readimplementation;
  2309. end
  2310. else
  2311. ppufile.skipuntilentry(ibendimplementation);
  2312. {read the static symtable}
  2313. if (ppufile.header.flags and uf_local_symtable)<>0 then
  2314. begin
  2315. if (verbose and v_defs)<>0 then
  2316. begin
  2317. Writeln;
  2318. Writeln('Static definitions');
  2319. Writeln('----------------------');
  2320. readdefinitions('implementation');
  2321. end
  2322. else
  2323. ppufile.skipuntilentry(ibenddefs);
  2324. {read the symbols}
  2325. if (verbose and v_syms)<>0 then
  2326. begin
  2327. Writeln;
  2328. Writeln('Static Symbols');
  2329. Writeln('------------------');
  2330. readsymbols('implementation');
  2331. end
  2332. else
  2333. ppufile.skipuntilentry(ibendsyms);
  2334. end;
  2335. ReadCreatedObjTypes;
  2336. {shutdown ppufile}
  2337. ppufile.closefile;
  2338. ppufile.free;
  2339. Writeln;
  2340. end;
  2341. procedure help;
  2342. begin
  2343. writeln('usage: ppudump [options] <filename1> <filename2>...');
  2344. writeln;
  2345. writeln('[options] can be:');
  2346. writeln(' -V<verbose> Set verbosity to <verbose>');
  2347. writeln(' H - Show header info');
  2348. writeln(' I - Show interface');
  2349. writeln(' M - Show implementation');
  2350. writeln(' S - Show interface symbols');
  2351. writeln(' D - Show interface definitions');
  2352. // writeln(' B - Show browser info');
  2353. writeln(' A - Show all');
  2354. writeln(' -h, -? This helpscreen');
  2355. halt;
  2356. end;
  2357. var
  2358. startpara,
  2359. nrfile,i : longint;
  2360. para : string;
  2361. begin
  2362. writeln(Title+' '+Version);
  2363. writeln(Copyright);
  2364. writeln;
  2365. if paramcount<1 then
  2366. begin
  2367. writeln('usage: dumpppu [options] <filename1> <filename2>...');
  2368. halt(1);
  2369. end;
  2370. { turn verbose on by default }
  2371. verbose:=v_all;
  2372. { read options }
  2373. startpara:=1;
  2374. while copy(paramstr(startpara),1,1)='-' do
  2375. begin
  2376. para:=paramstr(startpara);
  2377. case upcase(para[2]) of
  2378. 'V' : begin
  2379. verbose:=0;
  2380. for i:=3 to length(para) do
  2381. case upcase(para[i]) of
  2382. 'H' : verbose:=verbose or v_header;
  2383. 'I' : verbose:=verbose or v_interface;
  2384. 'M' : verbose:=verbose or v_implementation;
  2385. 'D' : verbose:=verbose or v_defs;
  2386. 'S' : verbose:=verbose or v_syms;
  2387. 'A' : verbose:=verbose or v_all;
  2388. end;
  2389. end;
  2390. 'H' : help;
  2391. '?' : help;
  2392. end;
  2393. inc(startpara);
  2394. end;
  2395. { process files }
  2396. for nrfile:=startpara to paramcount do
  2397. dofile (paramstr(nrfile));
  2398. if has_errors then
  2399. Halt(1);
  2400. end.