ppudump.pp 66 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360
  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_always = $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_always)<>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 readobjectdefoptions;
  1071. type
  1072. tobjectoption=(oo_none,
  1073. oo_is_forward, { the class is only a forward declared yet }
  1074. oo_has_virtual, { the object/class has virtual methods }
  1075. oo_has_private,
  1076. oo_has_protected,
  1077. oo_has_strictprivate,
  1078. oo_has_strictprotected,
  1079. oo_has_constructor, { the object/class has a constructor }
  1080. oo_has_destructor, { the object/class has a destructor }
  1081. oo_has_vmt, { the object/class has a vmt }
  1082. oo_has_msgstr,
  1083. oo_has_msgint,
  1084. oo_can_have_published,{ the class has rtti, i.e. you can publish properties }
  1085. oo_has_default_property
  1086. );
  1087. tobjectoptions=set of tobjectoption;
  1088. tsymopt=record
  1089. mask : tobjectoption;
  1090. str : string[30];
  1091. end;
  1092. const
  1093. symopts=13;
  1094. symopt : array[1..symopts] of tsymopt=(
  1095. (mask:oo_has_virtual; str:'IsForward'),
  1096. (mask:oo_has_virtual; str:'HasVirtual'),
  1097. (mask:oo_has_private; str:'HasPrivate'),
  1098. (mask:oo_has_protected; str:'HasProtected'),
  1099. (mask:oo_has_strictprivate; str:'HasStrictPrivate'),
  1100. (mask:oo_has_strictprotected;str:'HasStrictProtected'),
  1101. (mask:oo_has_constructor; str:'HasConstructor'),
  1102. (mask:oo_has_destructor; str:'HasDestructor'),
  1103. (mask:oo_has_vmt; str:'HasVMT'),
  1104. (mask:oo_has_msgstr; str:'HasMsgStr'),
  1105. (mask:oo_has_msgint; str:'HasMsgInt'),
  1106. (mask:oo_can_have_published; str:'CanHavePublished'),
  1107. (mask:oo_has_default_property;str:'HasDefaultProperty')
  1108. );
  1109. var
  1110. symoptions : tobjectoptions;
  1111. i : longint;
  1112. first : boolean;
  1113. begin
  1114. ppufile.getsmallset(symoptions);
  1115. if symoptions<>[] then
  1116. begin
  1117. first:=true;
  1118. for i:=1to symopts do
  1119. if (symopt[i].mask in symoptions) then
  1120. begin
  1121. if first then
  1122. first:=false
  1123. else
  1124. write(', ');
  1125. write(symopt[i].str);
  1126. end;
  1127. end;
  1128. writeln;
  1129. end;
  1130. procedure readarraydefoptions;
  1131. type
  1132. tarraydefoption=(ado_none,
  1133. ado_IsConvertedPointer,
  1134. ado_IsDynamicArray,
  1135. ado_IsVariant,
  1136. ado_IsConstructor,
  1137. ado_IsArrayOfConst,
  1138. ado_IsConstString
  1139. );
  1140. tarraydefoptions=set of tarraydefoption;
  1141. tsymopt=record
  1142. mask : tarraydefoption;
  1143. str : string[30];
  1144. end;
  1145. const
  1146. symopts=6;
  1147. symopt : array[1..symopts] of tsymopt=(
  1148. (mask:ado_IsConvertedPointer;str:'ConvertedPointer'),
  1149. (mask:ado_IsDynamicArray; str:'IsDynamicArray'),
  1150. (mask:ado_IsVariant; str:'IsVariant'),
  1151. (mask:ado_IsConstructor; str:'IsConstructor'),
  1152. (mask:ado_IsArrayOfConst; str:'ArrayOfConst'),
  1153. (mask:ado_IsConstString; str:'ConstString')
  1154. );
  1155. var
  1156. symoptions : tarraydefoptions;
  1157. i : longint;
  1158. first : boolean;
  1159. begin
  1160. ppufile.getsmallset(symoptions);
  1161. if symoptions<>[] then
  1162. begin
  1163. first:=true;
  1164. for i:=1to symopts do
  1165. if (symopt[i].mask in symoptions) then
  1166. begin
  1167. if first then
  1168. first:=false
  1169. else
  1170. write(', ');
  1171. write(symopt[i].str);
  1172. end;
  1173. end;
  1174. writeln;
  1175. end;
  1176. procedure readnodetree;
  1177. var
  1178. l : longint;
  1179. p : pointer;
  1180. begin
  1181. with ppufile do
  1182. begin
  1183. if space<>'' then
  1184. Writeln(space,'------ nodetree ------');
  1185. if readentry=ibnodetree then
  1186. begin
  1187. l:=entrysize;
  1188. Writeln(space,'Tree size : ',l);
  1189. { Read data to prevent error that entry is not completly read }
  1190. getmem(p,l);
  1191. getdata(p^,l);
  1192. freemem(p);
  1193. end
  1194. else
  1195. begin
  1196. Writeln('!! ibnodetree not found');
  1197. end;
  1198. end;
  1199. end;
  1200. {****************************************************************************
  1201. Read Symbols Part
  1202. ****************************************************************************}
  1203. procedure readsymbols(const s:string);
  1204. type
  1205. pguid = ^tguid;
  1206. tguid = packed record
  1207. D1: LongWord;
  1208. D2: Word;
  1209. D3: Word;
  1210. D4: array[0..7] of Byte;
  1211. end;
  1212. absolutetyp = (tovar,toasm,toaddr);
  1213. tconsttyp = (constnone,
  1214. constord,conststring,constreal,
  1215. constset,constpointer,constnil,
  1216. constresourcestring,constwstring,constguid
  1217. );
  1218. var
  1219. b : byte;
  1220. pc : pchar;
  1221. totalsyms,
  1222. symcnt,
  1223. i,j,len : longint;
  1224. guid : tguid;
  1225. tempbuf : array[0..127] of char;
  1226. varoptions : tvaroptions;
  1227. begin
  1228. symcnt:=1;
  1229. with ppufile do
  1230. begin
  1231. if space<>'' then
  1232. Writeln(space,'------ ',s,' ------');
  1233. if readentry=ibstartsyms then
  1234. begin
  1235. totalsyms:=getlongint;
  1236. Writeln(space,'Number of symbols : ',totalsyms);
  1237. Writeln(space,'Symtable datasize : ',getlongint);
  1238. Writeln(space,'Symtable alignment: ',getlongint);
  1239. end
  1240. else
  1241. begin
  1242. totalsyms:=-1;
  1243. Writeln('!! ibstartsym not found');
  1244. end;
  1245. repeat
  1246. b:=readentry;
  1247. if not (b in [iberror,ibendsyms]) then
  1248. inc(symcnt);
  1249. case b of
  1250. ibunitsym :
  1251. readcommonsym('Unit symbol ');
  1252. iblabelsym :
  1253. readcommonsym('Label symbol ');
  1254. ibtypesym :
  1255. begin
  1256. readcommonsym('Type symbol ');
  1257. write(space,' Result Type : ');
  1258. readtype;
  1259. end;
  1260. ibprocsym :
  1261. begin
  1262. readcommonsym('Procedure symbol ');
  1263. len:=ppufile.getword;
  1264. for i:=1 to len do
  1265. begin
  1266. write(space,' Definition : ');
  1267. readderef;
  1268. end;
  1269. end;
  1270. ibconstsym :
  1271. begin
  1272. readcommonsym('Constant symbol ');
  1273. b:=getbyte;
  1274. case tconsttyp(b) of
  1275. constord :
  1276. begin
  1277. write (space,' OrdinalType : ');
  1278. readtype;
  1279. writeln(space,' Value : ',getint64);
  1280. end;
  1281. constpointer :
  1282. begin
  1283. write (space,' PointerType : ');
  1284. readtype;
  1285. writeln(space,' Value : ',getlongint)
  1286. end;
  1287. conststring,
  1288. constresourcestring :
  1289. begin
  1290. len:=getlongint;
  1291. getmem(pc,len+1);
  1292. getdata(pc^,len);
  1293. (pc+len)^:= #0;
  1294. writeln(space,' Length : ',len);
  1295. writeln(space,' Value : "',pc,'"');
  1296. freemem(pc,len+1);
  1297. if tconsttyp(b)=constresourcestring then
  1298. writeln(space,' Index : ',getlongint);
  1299. end;
  1300. constreal :
  1301. writeln(space,' Value : ',getreal);
  1302. constset :
  1303. begin
  1304. write (space,' Set Type : ');
  1305. readtype;
  1306. for i:=1to 4 do
  1307. begin
  1308. write (space,' Value : ');
  1309. for j:=1to 8 do
  1310. begin
  1311. if j>1 then
  1312. write(',');
  1313. write(hexb(getbyte));
  1314. end;
  1315. writeln;
  1316. end;
  1317. end;
  1318. constwstring:
  1319. begin
  1320. end;
  1321. constguid:
  1322. begin
  1323. getdata(guid,sizeof(guid));
  1324. write (space,' IID String: {',hexstr(guid.d1,8),'-',hexstr(guid.d2,4),'-',hexstr(guid.d3,4),'-');
  1325. for i:=0 to 7 do
  1326. begin
  1327. write(hexstr(guid.d4[i],2));
  1328. if i=1 then write('-');
  1329. end;
  1330. writeln('}');
  1331. end
  1332. else
  1333. Writeln ('!! Invalid unit format : Invalid const type encountered: ',b);
  1334. end;
  1335. end;
  1336. ibabsolutevarsym :
  1337. begin
  1338. readabstractvarsym('Absolute variable symbol ',varoptions);
  1339. Write (space,' Relocated to ');
  1340. b:=getbyte;
  1341. case absolutetyp(b) of
  1342. tovar :
  1343. readsymlist(space+' Sym : ');
  1344. toasm :
  1345. Writeln('Assembler name : ',getstring);
  1346. toaddr :
  1347. begin
  1348. Write('Address : ',getlongint);
  1349. if tsystemcpu(ppufile.header.cpu)=cpu_i386 then
  1350. WriteLn(' (Far: ',getbyte<>0,')');
  1351. end;
  1352. else
  1353. Writeln ('!! Invalid unit format : Invalid absolute type encountered: ',b);
  1354. end;
  1355. end;
  1356. ibfieldvarsym :
  1357. begin
  1358. readabstractvarsym('Field Variable symbol ',varoptions);
  1359. writeln(space,' Address : ',getlongint);
  1360. end;
  1361. ibglobalvarsym :
  1362. begin
  1363. readabstractvarsym('Global Variable symbol ',varoptions);
  1364. write (space,' DefaultConst : ');
  1365. readderef;
  1366. if (vo_has_mangledname in varoptions) then
  1367. writeln(space,' Mangledname : ',getstring);
  1368. end;
  1369. iblocalvarsym :
  1370. begin
  1371. readabstractvarsym('Local Variable symbol ',varoptions);
  1372. write (space,' DefaultConst : ');
  1373. readderef;
  1374. end;
  1375. ibparavarsym :
  1376. begin
  1377. readabstractvarsym('Parameter Variable symbol ',varoptions);
  1378. write (space,' DefaultConst : ');
  1379. readderef;
  1380. writeln(space,' ParaNr : ',getword);
  1381. if (vo_has_explicit_paraloc in varoptions) then
  1382. begin
  1383. i:=getbyte;
  1384. getdata(tempbuf,i);
  1385. end;
  1386. end;
  1387. ibenumsym :
  1388. begin
  1389. readcommonsym('Enumeration symbol ');
  1390. write (space,' Definition : ');
  1391. readderef;
  1392. writeln(space,' Value : ',getlongint);
  1393. end;
  1394. ibsyssym :
  1395. begin
  1396. readcommonsym('Internal system symbol ');
  1397. writeln(space,' Internal Nr : ',getlongint);
  1398. end;
  1399. ibrttisym :
  1400. begin
  1401. readcommonsym('RTTI symbol ');
  1402. writeln(space,' RTTI Type : ',getbyte);
  1403. end;
  1404. ibmacrosym :
  1405. begin
  1406. readcommonsym('Macro symbol ');
  1407. writeln(space,' Name: ',getstring);
  1408. writeln(space,' Defined: ',getbyte);
  1409. writeln(space,' Compiler var: ',getbyte);
  1410. len:=getlongint;
  1411. writeln(space,' Value length: ',len);
  1412. if len > 0 then
  1413. begin
  1414. getmem(pc,len+1);
  1415. getdata(pc^,len);
  1416. (pc+len)^:= #0;
  1417. writeln(space,' Value: "',pc,'"');
  1418. freemem(pc,len+1);
  1419. end;
  1420. end;
  1421. ibtypedconstsym :
  1422. begin
  1423. readcommonsym('Typed constant ');
  1424. write (space,' Constant Type : ');
  1425. readtype;
  1426. writeln(space,' ReallyConst : ',(getbyte<>0));
  1427. end;
  1428. ibpropertysym :
  1429. begin
  1430. readcommonsym('Property ');
  1431. i:=getlongint;
  1432. writeln(space,' PropOptions : ',i);
  1433. if (i and 32)>0 then
  1434. begin
  1435. write (space,' OverrideProp : ');
  1436. readderef;
  1437. end
  1438. else
  1439. begin
  1440. write (space,' Prop Type : ');
  1441. readtype;
  1442. writeln(space,' Index : ',getlongint);
  1443. writeln(space,' Default : ',getlongint);
  1444. write (space,' Index Type : ');
  1445. readtype;
  1446. write (space,' Readaccess : ');
  1447. readsymlist(space+' Sym: ');
  1448. write (space,' Writeaccess : ');
  1449. readsymlist(space+' Sym: ');
  1450. write (space,' Storedaccess : ');
  1451. readsymlist(space+' Sym: ');
  1452. end;
  1453. end;
  1454. iberror :
  1455. begin
  1456. Writeln('!! Error in PPU');
  1457. exit;
  1458. end;
  1459. ibendsyms :
  1460. break;
  1461. else
  1462. WriteLn('!! Skipping unsupported PPU Entry in Symbols: ',b);
  1463. end;
  1464. if not EndOfEntry then
  1465. Writeln('!! Entry has more information stored');
  1466. until false;
  1467. if (totalsyms<>-1) and (symcnt-1<>totalsyms) then
  1468. Writeln('!! Only read ',symcnt-1,' of ',totalsyms,' symbols');
  1469. end;
  1470. end;
  1471. {****************************************************************************
  1472. Read defintions Part
  1473. ****************************************************************************}
  1474. procedure readdefinitions(const s:string;start_read : boolean);
  1475. type
  1476. tsettype = (normset,smallset,varset);
  1477. tbasetype = (
  1478. uvoid,
  1479. u8bit,u16bit,u32bit,u64bit,
  1480. s8bit,s16bit,s32bit,s64bit,
  1481. bool8bit,bool16bit,bool32bit,
  1482. uchar,uwidechar,scurrency
  1483. );
  1484. tobjectdeftype = (odt_none,
  1485. odt_class,
  1486. odt_object,
  1487. odt_interfacecom,
  1488. odt_interfacecorba,
  1489. odt_cppclass
  1490. );
  1491. tvarianttype = (
  1492. vt_normalvariant,vt_olevariant
  1493. );
  1494. var
  1495. b : byte;
  1496. totaldefs,l,j,
  1497. defcnt : longint;
  1498. calloption : tproccalloption;
  1499. procoptions : tprocoptions;
  1500. procinfooptions : tprocinfoflag;
  1501. begin
  1502. defcnt:=0;
  1503. with ppufile do
  1504. begin
  1505. if space<>'' then
  1506. Writeln(space,'------ ',s,' ------');
  1507. if not start_read then
  1508. if readentry=ibstartdefs then
  1509. begin
  1510. totaldefs:=getlongint;
  1511. Writeln(space,'Number of definitions: ',totaldefs);
  1512. end
  1513. else
  1514. begin
  1515. totaldefs:=-1;
  1516. Writeln('!! ibstartdef not found');
  1517. end;
  1518. repeat
  1519. b:=readentry;
  1520. if not (b in [iberror,ibenddefs]) then
  1521. inc(defcnt);
  1522. case b of
  1523. ibpointerdef :
  1524. begin
  1525. readcommondef('Pointer definition');
  1526. write (space,' Pointed Type : ');
  1527. readtype;
  1528. writeln(space,' Is Far : ',(getbyte<>0));
  1529. end;
  1530. iborddef :
  1531. begin
  1532. readcommondef('Ordinal definition');
  1533. write (space,' Base type : ');
  1534. b:=getbyte;
  1535. case tbasetype(b) of
  1536. uvoid : writeln('uvoid');
  1537. u8bit : writeln('u8bit');
  1538. u16bit : writeln('u16bit');
  1539. u32bit : writeln('s32bit');
  1540. u64bit : writeln('u64bit');
  1541. s8bit : writeln('s8bit');
  1542. s16bit : writeln('s16bit');
  1543. s32bit : writeln('s32bit');
  1544. s64bit : writeln('s64bit');
  1545. bool8bit : writeln('bool8bit');
  1546. bool16bit : writeln('bool16bit');
  1547. bool32bit : writeln('bool32bit');
  1548. uchar : writeln('uchar');
  1549. uwidechar : writeln('uwidechar');
  1550. scurrency : writeln('ucurrency');
  1551. else writeln('!! Warning: Invalid base type ',b);
  1552. end;
  1553. writeln(space,' Range : ',getint64,' to ',getint64);
  1554. end;
  1555. ibfloatdef :
  1556. begin
  1557. readcommondef('Float definition');
  1558. writeln(space,' Float type : ',getbyte);
  1559. end;
  1560. ibarraydef :
  1561. begin
  1562. readcommondef('Array definition');
  1563. write (space,' Element type : ');
  1564. readtype;
  1565. write (space,' Range Type : ');
  1566. readtype;
  1567. writeln(space,' Range : ',getlongint,' to ',getlongint);
  1568. write (space,' Options : ');
  1569. readarraydefoptions;
  1570. end;
  1571. ibprocdef :
  1572. begin
  1573. readcommondef('Procedure definition');
  1574. read_abstract_proc_def(calloption,procoptions);
  1575. if (po_has_mangledname in procoptions) then
  1576. writeln(space,' Mangled name : ',getstring);
  1577. writeln(space,' Number : ',getword);
  1578. writeln(space,' Level : ',getbyte);
  1579. write (space,' Class : ');
  1580. readderef;
  1581. write (space,' Procsym : ');
  1582. readderef;
  1583. write (space,' File Pos : ');
  1584. readposinfo;
  1585. write (space,' SymOptions : ');
  1586. readsymoptions;
  1587. if tsystemcpu(ppufile.header.cpu)=cpu_powerpc then
  1588. begin
  1589. { library symbol for AmigaOS/MorphOS }
  1590. write (space,' Library symbol : ');
  1591. readderef;
  1592. end;
  1593. if (po_inline in procoptions) then
  1594. begin
  1595. write (space,' FuncretSym : ');
  1596. readderef;
  1597. ppufile.getsmallset(procinfooptions);
  1598. writeln(space,' ProcInfoOptions : ',dword(procinfooptions));
  1599. b := ppufile.getbyte;
  1600. writeln(space,' Inline node tree : ',b);
  1601. end;
  1602. if not EndOfEntry then
  1603. Writeln('!! Entry has more information stored');
  1604. space:=' '+space;
  1605. { parast }
  1606. readdefinitions('parast',false);
  1607. readsymbols('parast');
  1608. { localst }
  1609. if (po_has_inlininginfo in procoptions) or
  1610. ((ppufile.header.flags and uf_local_browser)<>0) then
  1611. begin
  1612. readdefinitions('localst',false);
  1613. readsymbols('localst');
  1614. end;
  1615. if (po_has_inlininginfo in procoptions) then
  1616. readnodetree;
  1617. delete(space,1,4);
  1618. end;
  1619. ibprocvardef :
  1620. begin
  1621. readcommondef('Procedural type (ProcVar) definition');
  1622. read_abstract_proc_def(calloption,procoptions);
  1623. if not EndOfEntry then
  1624. Writeln('!! Entry has more information stored');
  1625. space:=' '+space;
  1626. { parast }
  1627. readdefinitions('parast',false);
  1628. readsymbols('parast');
  1629. delete(space,1,4);
  1630. end;
  1631. ibshortstringdef :
  1632. begin
  1633. readcommondef('ShortString definition');
  1634. writeln(space,' Length : ',getbyte);
  1635. end;
  1636. ibwidestringdef :
  1637. begin
  1638. readcommondef('WideString definition');
  1639. writeln(space,' Length : ',getlongint);
  1640. end;
  1641. ibansistringdef :
  1642. begin
  1643. readcommondef('AnsiString definition');
  1644. writeln(space,' Length : ',getlongint);
  1645. end;
  1646. iblongstringdef :
  1647. begin
  1648. readcommondef('Longstring definition');
  1649. writeln(space,' Length : ',getlongint);
  1650. end;
  1651. ibrecorddef :
  1652. begin
  1653. readcommondef('Record definition');
  1654. writeln(space,' DataSize : ',getlongint);
  1655. writeln(space,' FieldAlign : ',getbyte);
  1656. writeln(space,' RecordAlign : ',getbyte);
  1657. writeln(space,' PadAlign : ',getbyte);
  1658. if not EndOfEntry then
  1659. Writeln('!! Entry has more information stored');
  1660. {read the record definitions and symbols}
  1661. space:=' '+space;
  1662. readdefinitions('fields',false);
  1663. readsymbols('fields');
  1664. Delete(space,1,4);
  1665. end;
  1666. ibobjectdef :
  1667. begin
  1668. readcommondef('Object/Class definition');
  1669. b:=getbyte;
  1670. write (space,' Type : ');
  1671. case tobjectdeftype(b) of
  1672. odt_class : writeln('class');
  1673. odt_object : writeln('object');
  1674. odt_interfacecom : writeln('interfacecom');
  1675. odt_interfacecorba : writeln('interfacecorba');
  1676. odt_cppclass : writeln('cppclass');
  1677. else writeln('!! Warning: Invalid object type ',b);
  1678. end;
  1679. writeln(space,' Name of Class : ',getstring);
  1680. writeln(space,' DataSize : ',getlongint);
  1681. writeln(space,' FieldAlign : ',getbyte);
  1682. writeln(space,' RecordAlign : ',getbyte);
  1683. writeln(space,' Vmt offset : ',getlongint);
  1684. write (space, ' Ancestor Class : ');
  1685. readderef;
  1686. write (space,' Options : ');
  1687. readobjectdefoptions;
  1688. if tobjectdeftype(b) in [odt_interfacecom,odt_interfacecorba] then
  1689. begin
  1690. { IIDGUID }
  1691. for j:=1to 16 do
  1692. getbyte;
  1693. writeln(space,' IID String : ',getstring);
  1694. writeln(space,' Last VTable idx : ',getlongint);
  1695. end;
  1696. if tobjectdeftype(b) in [odt_class,odt_interfacecorba] then
  1697. begin
  1698. l:=getlongint;
  1699. writeln(space,' Impl Intf Count : ',l);
  1700. for j:=1 to l do
  1701. begin
  1702. write (space,' - Definition : ');
  1703. readderef;
  1704. writeln(space,' IOffset : ',getlongint);
  1705. end;
  1706. end;
  1707. if not EndOfEntry then
  1708. Writeln('!! Entry has more information stored');
  1709. {read the record definitions and symbols}
  1710. space:=' '+space;
  1711. readdefinitions('fields',false);
  1712. readsymbols('fields');
  1713. Delete(space,1,4);
  1714. end;
  1715. ibfiledef :
  1716. begin
  1717. ReadCommonDef('File definition');
  1718. write (space,' Type : ');
  1719. case getbyte of
  1720. 0 : writeln('Text');
  1721. 1 : begin
  1722. writeln('Typed');
  1723. write (space,' File of Type : ');
  1724. Readtype;
  1725. end;
  1726. 2 : writeln('Untyped');
  1727. end;
  1728. end;
  1729. ibformaldef :
  1730. readcommondef('Generic definition (void-typ)');
  1731. ibundefineddef :
  1732. readcommondef('Undefined definition (generic parameter)');
  1733. ibenumdef :
  1734. begin
  1735. readcommondef('Enumeration type definition');
  1736. write(space,'Base enumeration type : ');
  1737. readderef;
  1738. writeln(space,' Smallest element : ',getlongint);
  1739. writeln(space,' Largest element : ',getlongint);
  1740. writeln(space,' Size : ',getlongint);
  1741. end;
  1742. ibclassrefdef :
  1743. begin
  1744. readcommondef('Class reference definition');
  1745. write (space,' Pointed Type : ');
  1746. readtype;
  1747. end;
  1748. ibsetdef :
  1749. begin
  1750. readcommondef('Set definition');
  1751. write (space,' Element type : ');
  1752. readtype;
  1753. b:=getbyte;
  1754. case tsettype(b) of
  1755. smallset : writeln(space,' Set with 32 Elements');
  1756. normset : writeln(space,' Set with 256 Elements');
  1757. varset : writeln(space,' Set with ',getlongint,' Elements');
  1758. else writeln('!! Warning: Invalid set type ',b);
  1759. end;
  1760. end;
  1761. ibvariantdef :
  1762. begin
  1763. readcommondef('Variant definition');
  1764. write (space,' Varianttype : ');
  1765. b:=getbyte;
  1766. case tvarianttype(b) of
  1767. vt_normalvariant :
  1768. writeln('Normal');
  1769. vt_olevariant :
  1770. writeln('OLE');
  1771. else
  1772. writeln('!! Warning: Invalid varianttype ',b);
  1773. end;
  1774. end;
  1775. iberror :
  1776. begin
  1777. Writeln('!! Error in PPU');
  1778. exit;
  1779. end;
  1780. ibenddefs :
  1781. break;
  1782. else
  1783. WriteLn('!! Skipping unsupported PPU Entry in definitions: ',b);
  1784. end;
  1785. if not EndOfEntry then
  1786. Writeln('!! Entry has more information stored');
  1787. until false;
  1788. if (totaldefs<>-1) and (defcnt<>totaldefs) then
  1789. Writeln('!! Only read ',defcnt,' of ',totaldefs,' definitions');
  1790. end;
  1791. end;
  1792. {****************************************************************************
  1793. Read General Part
  1794. ****************************************************************************}
  1795. procedure readinterface;
  1796. var
  1797. b : byte;
  1798. sourcenumber : longint;
  1799. begin
  1800. with ppufile do
  1801. begin
  1802. repeat
  1803. b:=readentry;
  1804. case b of
  1805. ibmodulename :
  1806. Writeln('Module Name: ',getstring);
  1807. ibsourcefiles :
  1808. begin
  1809. sourcenumber:=1;
  1810. while not EndOfEntry do
  1811. begin
  1812. Writeln('Source file ',sourcenumber,' : ',getstring,' ',filetimestring(getlongint));
  1813. inc(sourcenumber);
  1814. end;
  1815. end;
  1816. {$IFDEF MACRO_DIFF_HINT}
  1817. ibusedmacros :
  1818. begin
  1819. while not EndOfEntry do
  1820. begin
  1821. Write('Conditional ',getstring);
  1822. b:=getbyte;
  1823. if boolean(b)=true then
  1824. write(' defined at startup')
  1825. else
  1826. write(' not defined at startup');
  1827. b:=getbyte;
  1828. if boolean(b)=true then
  1829. writeln(' was used')
  1830. else
  1831. writeln;
  1832. end;
  1833. end;
  1834. {$ENDIF}
  1835. ibloadunit :
  1836. ReadLoadUnit;
  1837. iblinkunitofiles :
  1838. ReadLinkContainer('Link unit object file: ');
  1839. iblinkunitstaticlibs :
  1840. ReadLinkContainer('Link unit static lib: ');
  1841. iblinkunitsharedlibs :
  1842. ReadLinkContainer('Link unit shared lib: ');
  1843. iblinkotherofiles :
  1844. ReadLinkContainer('Link other object file: ');
  1845. iblinkotherstaticlibs :
  1846. ReadLinkContainer('Link other static lib: ');
  1847. iblinkothersharedlibs :
  1848. ReadLinkContainer('Link other shared lib: ');
  1849. iblinkdlls :
  1850. ReadLinkContainer('Link DLLs: ');
  1851. ibderefdata :
  1852. ReadDerefData;
  1853. ibderefmap :
  1854. ReadDerefMap;
  1855. iberror :
  1856. begin
  1857. Writeln('Error in PPU');
  1858. exit;
  1859. end;
  1860. ibendinterface :
  1861. break;
  1862. else
  1863. WriteLn('!! Skipping unsupported PPU Entry in General Part: ',b);
  1864. end;
  1865. until false;
  1866. end;
  1867. end;
  1868. {****************************************************************************
  1869. Read Implementation Part
  1870. ****************************************************************************}
  1871. procedure readimplementation;
  1872. var
  1873. b : byte;
  1874. begin
  1875. with ppufile do
  1876. begin
  1877. repeat
  1878. b:=readentry;
  1879. case b of
  1880. ibasmsymbols :
  1881. ReadAsmSymbols;
  1882. ibloadunit :
  1883. ReadLoadUnit;
  1884. iberror :
  1885. begin
  1886. Writeln('Error in PPU');
  1887. exit;
  1888. end;
  1889. ibendimplementation :
  1890. break;
  1891. else
  1892. WriteLn('!! Skipping unsupported PPU Entry in Implementation: ',b);
  1893. end;
  1894. until false;
  1895. end;
  1896. end;
  1897. {****************************************************************************
  1898. Read Browser Part
  1899. ****************************************************************************}
  1900. procedure readbrowser;
  1901. var
  1902. b : byte;
  1903. const indent : string = '';
  1904. begin
  1905. Writeln(indent,'Start of symtable browser');
  1906. indent:=indent+'**';
  1907. with ppufile do
  1908. begin
  1909. repeat
  1910. b:=readentry;
  1911. case b of
  1912. ibbeginsymtablebrowser :
  1913. begin
  1914. { here we must read object and record symtables !! }
  1915. indent:=indent+' ';
  1916. Writeln(indent,'Record/Object symtable');
  1917. readbrowser;
  1918. Indent:=Copy(Indent,1,Length(Indent)-2);
  1919. end;
  1920. ibsymref :
  1921. begin
  1922. readderef;
  1923. readref;
  1924. end;
  1925. ibdefref :
  1926. begin
  1927. readderef;
  1928. readref;
  1929. if ((ppufile.header.flags and uf_local_browser)<>0) and
  1930. (UnitIndex=0) then
  1931. begin
  1932. { parast and localst }
  1933. indent:=indent+' ';
  1934. b:=ppufile.readentry;
  1935. if b=ibbeginsymtablebrowser then
  1936. readbrowser;
  1937. b:=ppufile.readentry;
  1938. if b=ibbeginsymtablebrowser then
  1939. readbrowser;
  1940. Indent:=Copy(Indent,1,Length(Indent)-2);
  1941. end;
  1942. end;
  1943. iberror :
  1944. begin
  1945. Writeln('Error in PPU');
  1946. exit;
  1947. end;
  1948. ibendsymtablebrowser :
  1949. break;
  1950. else
  1951. begin
  1952. WriteLn('!! Skipping unsupported PPU Entry in Browser: ',b);
  1953. Halt;
  1954. end;
  1955. end;
  1956. until false;
  1957. end;
  1958. Indent:=Copy(Indent,1,Length(Indent)-2);
  1959. Writeln(Indent,'End of symtable browser');
  1960. end;
  1961. procedure dofile (filename : string);
  1962. var
  1963. b : byte;
  1964. begin
  1965. { reset }
  1966. space:='';
  1967. { fix filename }
  1968. if pos('.',filename)=0 then
  1969. filename:=filename+'.ppu';
  1970. ppufile:=tppufile.create(filename);
  1971. if not ppufile.openfile then
  1972. begin
  1973. writeln ('IO-Error when opening : ',filename,', Skipping');
  1974. exit;
  1975. end;
  1976. { PPU File is open, check for PPU Id }
  1977. if not ppufile.CheckPPUID then
  1978. begin
  1979. writeln(Filename,' : Not a valid PPU file, Skipping');
  1980. exit;
  1981. end;
  1982. { Check PPU Version }
  1983. Writeln('Analyzing ',filename,' (v',ppufile.GetPPUVersion,')');
  1984. if ppufile.GetPPUVersion<16 then
  1985. begin
  1986. writeln(Filename,' : Old PPU Formats (<v16) are not supported, Skipping');
  1987. exit;
  1988. end;
  1989. { Write PPU Header Information }
  1990. if (verbose and v_header)<>0 then
  1991. begin
  1992. Writeln;
  1993. Writeln('Header');
  1994. Writeln('-------');
  1995. with ppufile.header do
  1996. begin
  1997. Writeln('Compiler version : ',ppufile.header.compiler shr 14,'.',
  1998. (ppufile.header.compiler shr 7) and $7f,'.',
  1999. ppufile.header.compiler and $7f);
  2000. WriteLn('Target processor : ',Cpu2Str(cpu));
  2001. WriteLn('Target operating system : ',Target2Str(target));
  2002. Writeln('Unit flags : ',PPUFlags2Str(flags));
  2003. Writeln('FileSize (w/o header) : ',size);
  2004. Writeln('Checksum : ',hexstr(checksum,8));
  2005. Writeln('Interface Checksum : ',hexstr(interface_checksum,8));
  2006. end;
  2007. end;
  2008. {read the general stuff}
  2009. if (verbose and v_interface)<>0 then
  2010. begin
  2011. Writeln;
  2012. Writeln('Interface section');
  2013. Writeln('------------------');
  2014. readinterface;
  2015. end
  2016. else
  2017. ppufile.skipuntilentry(ibendinterface);
  2018. {read the definitions}
  2019. if (verbose and v_defs)<>0 then
  2020. begin
  2021. Writeln;
  2022. Writeln('Interface definitions');
  2023. Writeln('----------------------');
  2024. readdefinitions('interface',false);
  2025. end
  2026. else
  2027. ppufile.skipuntilentry(ibenddefs);
  2028. {read the symbols}
  2029. if (verbose and v_syms)<>0 then
  2030. begin
  2031. Writeln;
  2032. Writeln('Interface Symbols');
  2033. Writeln('------------------');
  2034. readsymbols('interface');
  2035. end
  2036. else
  2037. ppufile.skipuntilentry(ibendsyms);
  2038. {read the macro symbols}
  2039. if (verbose and v_syms)<>0 then
  2040. begin
  2041. Writeln;
  2042. Writeln('Interface Macro Symbols');
  2043. Writeln('-----------------------');
  2044. end;
  2045. if ppufile.readentry<>ibexportedmacros then
  2046. begin
  2047. Writeln('!! Error in PPU');
  2048. exit;
  2049. end;
  2050. if boolean(ppufile.getbyte) then
  2051. begin
  2052. {skip the definition section for macros (since they are never used) }
  2053. ppufile.skipuntilentry(ibenddefs);
  2054. {read the macro symbols}
  2055. if (verbose and v_syms)<>0 then
  2056. readsymbols('interface macro')
  2057. else
  2058. ppufile.skipuntilentry(ibendsyms);
  2059. end
  2060. else
  2061. Writeln('(no exported macros)');
  2062. {read the implementation stuff}
  2063. if (verbose and v_implementation)<>0 then
  2064. begin
  2065. Writeln;
  2066. Writeln('Implementation section');
  2067. Writeln('-----------------------');
  2068. readimplementation;
  2069. end
  2070. else
  2071. ppufile.skipuntilentry(ibendimplementation);
  2072. {read the static browser units stuff}
  2073. if (ppufile.header.flags and uf_local_symtable)<>0 then
  2074. begin
  2075. if (verbose and v_defs)<>0 then
  2076. begin
  2077. Writeln;
  2078. Writeln('Static definitions');
  2079. Writeln('----------------------');
  2080. readdefinitions('implementation',false);
  2081. end
  2082. else
  2083. ppufile.skipuntilentry(ibenddefs);
  2084. {read the symbols}
  2085. if (verbose and v_syms)<>0 then
  2086. begin
  2087. Writeln;
  2088. Writeln('Static Symbols');
  2089. Writeln('------------------');
  2090. readsymbols('implementation');
  2091. end
  2092. else
  2093. ppufile.skipuntilentry(ibendsyms);
  2094. end;
  2095. {read the browser units stuff}
  2096. if (ppufile.header.flags and uf_has_browser)<>0 then
  2097. begin
  2098. if (verbose and v_browser)<>0 then
  2099. begin
  2100. Writeln;
  2101. Writeln('Browser section');
  2102. Writeln('---------------');
  2103. UnitIndex:=0;
  2104. repeat
  2105. b:=ppufile.readentry;
  2106. if b = ibendbrowser then break;
  2107. if b=ibbeginsymtablebrowser then
  2108. begin
  2109. Writeln('Unit ',UnitIndex);
  2110. readbrowser;
  2111. Inc(UnitIndex);
  2112. end
  2113. else
  2114. Writeln('Wrong end browser entry ',b,' should be ',ibendbrowser);
  2115. until false;
  2116. end;
  2117. end;
  2118. {read the static browser units stuff}
  2119. if (ppufile.header.flags and uf_local_browser)<>0 then
  2120. begin
  2121. if (verbose and v_browser)<>0 then
  2122. begin
  2123. Writeln;
  2124. Writeln('Static browser section');
  2125. Writeln('---------------');
  2126. UnitIndex:=0;
  2127. b:=ppufile.readentry;
  2128. if b=ibbeginsymtablebrowser then
  2129. readbrowser
  2130. else
  2131. Writeln('Wrong end browser entry ',b,' should be ',ibendbrowser);
  2132. end;
  2133. end;
  2134. {shutdown ppufile}
  2135. ppufile.closefile;
  2136. ppufile.free;
  2137. Writeln;
  2138. end;
  2139. procedure help;
  2140. begin
  2141. writeln('usage: ppudump [options] <filename1> <filename2>...');
  2142. writeln;
  2143. writeln('[options] can be:');
  2144. writeln(' -V<verbose> Set verbosity to <verbose>');
  2145. writeln(' H - Show header info');
  2146. writeln(' I - Show interface');
  2147. writeln(' M - Show implementation');
  2148. writeln(' S - Show interface symbols');
  2149. writeln(' D - Show interface definitions');
  2150. writeln(' B - Show browser info');
  2151. writeln(' A - Show all');
  2152. writeln(' -h, -? This helpscreen');
  2153. halt;
  2154. end;
  2155. var
  2156. startpara,
  2157. nrfile,i : longint;
  2158. para : string;
  2159. begin
  2160. writeln(Title+' '+Version);
  2161. writeln(Copyright);
  2162. writeln;
  2163. if paramcount<1 then
  2164. begin
  2165. writeln('usage: dumpppu [options] <filename1> <filename2>...');
  2166. halt(1);
  2167. end;
  2168. { turn verbose on by default }
  2169. verbose:=v_all;
  2170. { read options }
  2171. startpara:=1;
  2172. while copy(paramstr(startpara),1,1)='-' do
  2173. begin
  2174. para:=paramstr(startpara);
  2175. case upcase(para[2]) of
  2176. 'V' : begin
  2177. verbose:=0;
  2178. for i:=3 to length(para) do
  2179. case upcase(para[i]) of
  2180. 'H' : verbose:=verbose or v_header;
  2181. 'I' : verbose:=verbose or v_interface;
  2182. 'M' : verbose:=verbose or v_implementation;
  2183. 'D' : verbose:=verbose or v_defs;
  2184. 'S' : verbose:=verbose or v_syms;
  2185. 'B' : verbose:=verbose or v_browser;
  2186. 'A' : verbose:=verbose or v_all;
  2187. end;
  2188. end;
  2189. 'H' : help;
  2190. '?' : help;
  2191. end;
  2192. inc(startpara);
  2193. end;
  2194. { process files }
  2195. for nrfile:=startpara to paramcount do
  2196. dofile (paramstr(nrfile));
  2197. if has_errors then
  2198. Halt(1);
  2199. end.