ppudump.pp 65 KB

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