ppudump.pp 71 KB

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