ppudump.pp 63 KB

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