ppudump.pp 65 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306
  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. tdefoption=(df_none,
  686. { init data has been generated }
  687. df_has_inittable,
  688. { rtti data has been generated }
  689. df_has_rttitable,
  690. { dwarf debug info has been generated }
  691. df_has_dwarf_dbg_info,
  692. { type is unique, i.e. declared with type = type <tdef>; }
  693. df_unique,
  694. { type is a generic }
  695. df_generic,
  696. { type is a specialization of a generic type }
  697. df_specialization
  698. );
  699. tdefoptions=set of tdefoption;
  700. tdefopt=record
  701. mask : tdefoption;
  702. str : string[30];
  703. end;
  704. const
  705. defopts=6;
  706. defopt : array[1..defopts] of tdefopt=(
  707. (mask:df_has_inittable; str:'InitTable'),
  708. (mask:df_has_rttitable; str:'RTTITable'),
  709. (mask:df_has_dwarf_dbg_info; str:'Dwarf DbgInfo'),
  710. (mask:df_unique; str:'Unique Type'),
  711. (mask:df_generic; str:'Generic'),
  712. (mask:df_specialization; str:'Specialization')
  713. );
  714. var
  715. defoptions : tdefoptions;
  716. i : longint;
  717. first : boolean;
  718. tokenbufsize : longint;
  719. tokenbuf : pbyte;
  720. begin
  721. writeln(space,'** Definition Id ',ppufile.getlongint,' **');
  722. writeln(space,s);
  723. write (space,' Type symbol : ');
  724. readderef;
  725. write (space,' DefOptions : ');
  726. ppufile.getsmallset(defoptions);
  727. if defoptions<>[] then
  728. begin
  729. first:=true;
  730. for i:=1to defopts do
  731. if (defopt[i].mask in defoptions) then
  732. begin
  733. if first then
  734. first:=false
  735. else
  736. write(', ');
  737. write(defopt[i].str);
  738. end;
  739. end;
  740. writeln;
  741. if df_unique in defoptions then
  742. writeln (space,' Unique type symbol');
  743. if df_generic in defoptions then
  744. begin
  745. tokenbufsize:=ppufile.getlongint;
  746. writeln(space,' Tokenbuffer size : ',tokenbufsize);
  747. tokenbuf:=allocmem(tokenbufsize);
  748. ppufile.getdata(tokenbuf^,tokenbufsize);
  749. i:=0;
  750. write(space,' Tokens: ');
  751. while i<tokenbufsize do
  752. begin
  753. if ttoken(tokenbuf[i])<>_GENERICSPECIALTOKEN then
  754. write(arraytokeninfo[ttoken(tokenbuf[i])].str);
  755. case ttoken(tokenbuf[i]) of
  756. _CWCHAR,
  757. _CWSTRING :
  758. begin
  759. inc(i);
  760. {
  761. replaytokenbuf.read(wlen,sizeof(SizeInt));
  762. setlengthwidestring(patternw,wlen);
  763. replaytokenbuf.read(patternw^.data^,patternw^.len*sizeof(tcompilerwidechar));
  764. pattern:='';
  765. }
  766. end;
  767. _CCHAR,
  768. _CSTRING,
  769. _INTCONST,
  770. _REALNUMBER :
  771. begin
  772. inc(i);
  773. {
  774. replaytokenbuf.read(pattern[0],1);
  775. replaytokenbuf.read(pattern[1],length(pattern));
  776. orgpattern:='';
  777. }
  778. end;
  779. _ID :
  780. begin
  781. inc(i);
  782. inc(i);
  783. write(' ',pshortstring(@tokenbuf[i])^);
  784. inc(i,tokenbuf[i]+1);
  785. {
  786. replaytokenbuf.read(orgpattern[0],1);
  787. replaytokenbuf.read(orgpattern[1],length(orgpattern));
  788. pattern:=upper(orgpattern);
  789. }
  790. end;
  791. _GENERICSPECIALTOKEN:
  792. begin
  793. inc(i);
  794. case tspecialgenerictoken(tokenbuf[i]) of
  795. ST_LOADSETTINGS:
  796. begin
  797. inc(i);
  798. write('Settings');
  799. inc(i,sizeof(tsettings));
  800. end;
  801. ST_LINE:
  802. begin
  803. inc(i);
  804. write('Line: ',pdword(@tokenbuf[i])^);
  805. inc(i,4);
  806. end;
  807. ST_COLUMN:
  808. begin
  809. inc(i);
  810. write('Col: ',pword(@tokenbuf[i])^);
  811. inc(i,2);
  812. end;
  813. ST_FILEINDEX:
  814. begin
  815. inc(i);
  816. write('File: ',pword(@tokenbuf[i])^);
  817. inc(i,2);
  818. end;
  819. end;
  820. {
  821. replaytokenbuf.read(specialtoken,1);
  822. case specialtoken of
  823. ST_LOADSETTINGS:
  824. begin
  825. replaytokenbuf.read(current_settings,sizeof(current_settings));
  826. end
  827. else
  828. internalerror(2006103010);
  829. end;
  830. continue;
  831. }
  832. end;
  833. else
  834. inc(i);
  835. end;
  836. if i<tokenbufsize then
  837. write(',');
  838. end;
  839. writeln;
  840. freemem(tokenbuf);
  841. end;
  842. if df_specialization in defoptions then
  843. begin
  844. write (space,' Orig. GenericDef : ');
  845. readderef;
  846. end;
  847. end;
  848. { Read abstract procdef and return if inline procdef }
  849. type
  850. tproccalloption=(pocall_none,
  851. { procedure uses C styled calling }
  852. pocall_cdecl,
  853. { C++ calling conventions }
  854. pocall_cppdecl,
  855. { Far16 for OS/2 }
  856. pocall_far16,
  857. { Old style FPC default calling }
  858. pocall_oldfpccall,
  859. { Procedure has compiler magic}
  860. pocall_internproc,
  861. { procedure is a system call, applies e.g. to MorphOS and PalmOS }
  862. pocall_syscall,
  863. { pascal standard left to right }
  864. pocall_pascal,
  865. { procedure uses register (fastcall) calling }
  866. pocall_register,
  867. { safe call calling conventions }
  868. pocall_safecall,
  869. { procedure uses stdcall call }
  870. pocall_stdcall,
  871. { Special calling convention for cpus without a floating point
  872. unit. Floating point numbers are passed in integer registers
  873. instead of floating point registers. Depending on the other
  874. available calling conventions available for the cpu
  875. this replaces either pocall_fastcall or pocall_stdcall.
  876. }
  877. pocall_softfloat,
  878. { Metrowerks Pascal. Special case on Mac OS (X): passes all }
  879. { constant records by reference. }
  880. pocall_mwpascal
  881. );
  882. tproccalloptions=set of tproccalloption;
  883. tproctypeoption=(potype_none,
  884. potype_proginit, { Program initialization }
  885. potype_unitinit, { unit initialization }
  886. potype_unitfinalize, { unit finalization }
  887. potype_constructor, { Procedure is a constructor }
  888. potype_destructor, { Procedure is a destructor }
  889. potype_operator, { Procedure defines an operator }
  890. potype_procedure,
  891. potype_function
  892. );
  893. tproctypeoptions=set of tproctypeoption;
  894. tprocoption=(po_none,
  895. po_classmethod, { class method }
  896. po_virtualmethod, { Procedure is a virtual method }
  897. po_abstractmethod, { Procedure is an abstract method }
  898. po_staticmethod, { static method }
  899. po_overridingmethod, { method with override directive }
  900. po_methodpointer, { method pointer, only in procvardef, also used for 'with object do' }
  901. po_interrupt, { Procedure is an interrupt handler }
  902. po_iocheck, { IO checking should be done after a call to the procedure }
  903. po_assembler, { Procedure is written in assembler }
  904. po_msgstr, { method for string message handling }
  905. po_msgint, { method for int message handling }
  906. po_exports, { Procedure has export directive (needed for OS/2) }
  907. po_external, { Procedure is external (in other object or lib)}
  908. po_overload, { procedure is declared with overload directive }
  909. po_varargs, { printf like arguments }
  910. po_internconst, { procedure has constant evaluator intern }
  911. { flag that only the address of a method is returned and not a full methodpointer }
  912. po_addressonly,
  913. { procedure is exported }
  914. po_public,
  915. { calling convention is specified explicitly }
  916. po_hascallingconvention,
  917. { reintroduce flag }
  918. po_reintroduce,
  919. { location of parameters is given explicitly as it is necessary for some syscall
  920. conventions like that one of MorphOS }
  921. po_explicitparaloc,
  922. { no stackframe will be generated, used by lowlevel assembler like get_frame }
  923. po_nostackframe,
  924. po_has_mangledname,
  925. po_has_public_name,
  926. po_forward,
  927. po_global,
  928. po_has_inlininginfo,
  929. { The different kind of syscalls on MorphOS }
  930. po_syscall_legacy,
  931. po_syscall_sysv,
  932. po_syscall_basesysv,
  933. po_syscall_sysvbase,
  934. po_syscall_r12base,
  935. po_local,
  936. { Procedure can be inlined }
  937. po_inline,
  938. { Procedure is used for internal compiler calls }
  939. po_compilerproc,
  940. { importing }
  941. po_has_importdll,
  942. po_has_importname,
  943. po_kylixlocal
  944. );
  945. tprocoptions=set of tprocoption;
  946. procedure read_abstract_proc_def(var proccalloption:tproccalloption;var procoptions:tprocoptions);
  947. type
  948. tproccallopt=record
  949. mask : tproccalloption;
  950. str : string[30];
  951. end;
  952. tproctypeopt=record
  953. mask : tproctypeoption;
  954. str : string[30];
  955. end;
  956. tprocopt=record
  957. mask : tprocoption;
  958. str : string[30];
  959. end;
  960. const
  961. proccalloptionStr : array[tproccalloption] of string[14]=('',
  962. 'CDecl',
  963. 'CPPDecl',
  964. 'Far16',
  965. 'OldFPCCall',
  966. 'InternProc',
  967. 'SysCall',
  968. 'Pascal',
  969. 'Register',
  970. 'SafeCall',
  971. 'StdCall',
  972. 'SoftFloat',
  973. 'MWPascal'
  974. );
  975. proctypeopts=8;
  976. proctypeopt : array[1..proctypeopts] of tproctypeopt=(
  977. (mask:potype_proginit; str:'ProgInit'),
  978. (mask:potype_unitinit; str:'UnitInit'),
  979. (mask:potype_unitfinalize;str:'UnitFinalize'),
  980. (mask:potype_constructor; str:'Constructor'),
  981. (mask:potype_destructor; str:'Destructor'),
  982. (mask:potype_operator; str:'Operator'),
  983. (mask:potype_function; str:'Function'),
  984. (mask:potype_procedure; str:'Procedure')
  985. );
  986. procopts=38;
  987. procopt : array[1..procopts] of tprocopt=(
  988. (mask:po_classmethod; str:'ClassMethod'),
  989. (mask:po_virtualmethod; str:'VirtualMethod'),
  990. (mask:po_abstractmethod; str:'AbstractMethod'),
  991. (mask:po_staticmethod; str:'StaticMethod'),
  992. (mask:po_overridingmethod;str:'OverridingMethod'),
  993. (mask:po_methodpointer; str:'MethodPointer'),
  994. (mask:po_interrupt; str:'Interrupt'),
  995. (mask:po_iocheck; str:'IOCheck'),
  996. (mask:po_assembler; str:'Assembler'),
  997. (mask:po_msgstr; str:'MsgStr'),
  998. (mask:po_msgint; str:'MsgInt'),
  999. (mask:po_exports; str:'Exports'),
  1000. (mask:po_external; str:'External'),
  1001. (mask:po_overload; str:'Overload'),
  1002. (mask:po_varargs; str:'VarArgs'),
  1003. (mask:po_internconst; str:'InternConst'),
  1004. (mask:po_addressonly; str:'AddressOnly'),
  1005. (mask:po_public; str:'Public'),
  1006. (mask:po_hascallingconvention;str:'HasCallingConvention'),
  1007. (mask:po_reintroduce; str:'ReIntroduce'),
  1008. (mask:po_explicitparaloc; str:'ExplicitParaloc'),
  1009. (mask:po_nostackframe; str:'NoStackFrame'),
  1010. (mask:po_has_mangledname; str:'HasMangledName'),
  1011. (mask:po_has_public_name; str:'HasPublicName'),
  1012. (mask:po_forward; str:'Forward'),
  1013. (mask:po_global; str:'Global'),
  1014. (mask:po_has_inlininginfo;str:'HasInliningInfo'),
  1015. (mask:po_syscall_legacy; str:'SyscallLegacy'),
  1016. (mask:po_syscall_sysv; str:'SyscallSysV'),
  1017. (mask:po_syscall_basesysv;str:'SyscallBaseSysV'),
  1018. (mask:po_syscall_sysvbase;str:'SyscallSysVBase'),
  1019. (mask:po_syscall_r12base; str:'SyscallR12Base'),
  1020. (mask:po_local; str:'Local'),
  1021. (mask:po_inline; str:'Inline'),
  1022. (mask:po_compilerproc; str:'CompilerProc'),
  1023. (mask:po_has_importdll; str:'HasImportDLL'),
  1024. (mask:po_has_importname; str:'HasImportName'),
  1025. (mask:po_kylixlocal; str:'KylixLocal')
  1026. );
  1027. var
  1028. proctypeoption : tproctypeoption;
  1029. i : longint;
  1030. first : boolean;
  1031. tempbuf : array[0..255] of byte;
  1032. begin
  1033. write(space,' Return type : ');
  1034. readderef;
  1035. writeln(space,' Fpu used : ',ppufile.getbyte);
  1036. proctypeoption:=tproctypeoption(ppufile.getbyte);
  1037. write(space,' TypeOption : ');
  1038. first:=true;
  1039. for i:=1 to proctypeopts do
  1040. if (proctypeopt[i].mask=proctypeoption) then
  1041. begin
  1042. if first then
  1043. first:=false
  1044. else
  1045. write(', ');
  1046. write(proctypeopt[i].str);
  1047. end;
  1048. writeln;
  1049. proccalloption:=tproccalloption(ppufile.getbyte);
  1050. writeln(space,' CallOption : ',proccalloptionStr[proccalloption]);
  1051. ppufile.getnormalset(procoptions);
  1052. if procoptions<>[] then
  1053. begin
  1054. write(space,' Options : ');
  1055. first:=true;
  1056. for i:=1to procopts do
  1057. if (procopt[i].mask in procoptions) then
  1058. begin
  1059. if first then
  1060. first:=false
  1061. else
  1062. write(', ');
  1063. write(procopt[i].str);
  1064. end;
  1065. writeln;
  1066. end;
  1067. if (po_explicitparaloc in procoptions) then
  1068. begin
  1069. i:=ppufile.getbyte;
  1070. ppufile.getdata(tempbuf,i);
  1071. end;
  1072. end;
  1073. type
  1074. { options for variables }
  1075. tvaroption=(vo_none,
  1076. vo_is_C_var,
  1077. vo_is_external,
  1078. vo_is_dll_var,
  1079. vo_is_thread_var,
  1080. vo_has_local_copy,
  1081. vo_is_const, { variable is declared as const (parameter) and can't be written to }
  1082. vo_is_exported,
  1083. vo_is_high_para,
  1084. vo_is_funcret,
  1085. vo_is_self,
  1086. vo_is_vmt,
  1087. vo_is_result, { special result variable }
  1088. vo_is_parentfp,
  1089. vo_is_loop_counter, { used to detect assignments to loop counter }
  1090. vo_is_hidden_para,
  1091. vo_has_explicit_paraloc,
  1092. vo_is_syscall_lib,
  1093. vo_has_mangledname
  1094. );
  1095. tvaroptions=set of tvaroption;
  1096. { register variable }
  1097. tvarregable=(vr_none,
  1098. vr_intreg,
  1099. vr_fpureg,
  1100. vr_mmreg
  1101. );
  1102. procedure readabstractvarsym(const s:string;var varoptions:tvaroptions);
  1103. type
  1104. tvaropt=record
  1105. mask : tvaroption;
  1106. str : string[30];
  1107. end;
  1108. const
  1109. varopts=18;
  1110. varopt : array[1..varopts] of tvaropt=(
  1111. (mask:vo_is_C_var; str:'CVar'),
  1112. (mask:vo_is_external; str:'External'),
  1113. (mask:vo_is_dll_var; str:'DLLVar'),
  1114. (mask:vo_is_thread_var; str:'ThreadVar'),
  1115. (mask:vo_has_local_copy; str:'HasLocalCopy'),
  1116. (mask:vo_is_const; str:'Constant'),
  1117. (mask:vo_is_exported; str:'Exported'),
  1118. (mask:vo_is_high_para; str:'HighValue'),
  1119. (mask:vo_is_funcret; str:'Funcret'),
  1120. (mask:vo_is_self; str:'Self'),
  1121. (mask:vo_is_vmt; str:'VMT'),
  1122. (mask:vo_is_result; str:'Result'),
  1123. (mask:vo_is_parentfp; str:'ParentFP'),
  1124. (mask:vo_is_loop_counter; str:'LoopCounter'),
  1125. (mask:vo_is_hidden_para; str:'Hidden'),
  1126. (mask:vo_has_explicit_paraloc;str:'ExplicitParaloc'),
  1127. (mask:vo_is_syscall_lib; str:'SysCallLib'),
  1128. (mask:vo_has_mangledname; str:'HasMangledName')
  1129. );
  1130. var
  1131. i : longint;
  1132. first : boolean;
  1133. begin
  1134. readcommonsym(s);
  1135. writeln(space,' Spez : ',Varspez2Str(ppufile.getbyte));
  1136. writeln(space,' Regable : ',Varregable2Str(ppufile.getbyte));
  1137. write (space,' Var Type : ');
  1138. readderef;
  1139. ppufile.getsmallset(varoptions);
  1140. if varoptions<>[] then
  1141. begin
  1142. write(space,' Options : ');
  1143. first:=true;
  1144. for i:=1to varopts do
  1145. if (varopt[i].mask in varoptions) then
  1146. begin
  1147. if first then
  1148. first:=false
  1149. else
  1150. write(', ');
  1151. write(varopt[i].str);
  1152. end;
  1153. writeln;
  1154. end;
  1155. end;
  1156. procedure readobjectdefoptions;
  1157. type
  1158. tobjectoption=(oo_none,
  1159. oo_is_forward, { the class is only a forward declared yet }
  1160. oo_has_virtual, { the object/class has virtual methods }
  1161. oo_has_private,
  1162. oo_has_protected,
  1163. oo_has_strictprivate,
  1164. oo_has_strictprotected,
  1165. oo_has_constructor, { the object/class has a constructor }
  1166. oo_has_destructor, { the object/class has a destructor }
  1167. oo_has_vmt, { the object/class has a vmt }
  1168. oo_has_msgstr,
  1169. oo_has_msgint,
  1170. oo_can_have_published,{ the class has rtti, i.e. you can publish properties }
  1171. oo_has_default_property
  1172. );
  1173. tobjectoptions=set of tobjectoption;
  1174. tsymopt=record
  1175. mask : tobjectoption;
  1176. str : string[30];
  1177. end;
  1178. const
  1179. symopts=13;
  1180. symopt : array[1..symopts] of tsymopt=(
  1181. (mask:oo_has_virtual; str:'IsForward'),
  1182. (mask:oo_has_virtual; str:'HasVirtual'),
  1183. (mask:oo_has_private; str:'HasPrivate'),
  1184. (mask:oo_has_protected; str:'HasProtected'),
  1185. (mask:oo_has_strictprivate; str:'HasStrictPrivate'),
  1186. (mask:oo_has_strictprotected;str:'HasStrictProtected'),
  1187. (mask:oo_has_constructor; str:'HasConstructor'),
  1188. (mask:oo_has_destructor; str:'HasDestructor'),
  1189. (mask:oo_has_vmt; str:'HasVMT'),
  1190. (mask:oo_has_msgstr; str:'HasMsgStr'),
  1191. (mask:oo_has_msgint; str:'HasMsgInt'),
  1192. (mask:oo_can_have_published; str:'CanHavePublished'),
  1193. (mask:oo_has_default_property;str:'HasDefaultProperty')
  1194. );
  1195. var
  1196. symoptions : tobjectoptions;
  1197. i : longint;
  1198. first : boolean;
  1199. begin
  1200. ppufile.getsmallset(symoptions);
  1201. if symoptions<>[] then
  1202. begin
  1203. first:=true;
  1204. for i:=1to symopts do
  1205. if (symopt[i].mask in symoptions) then
  1206. begin
  1207. if first then
  1208. first:=false
  1209. else
  1210. write(', ');
  1211. write(symopt[i].str);
  1212. end;
  1213. end;
  1214. writeln;
  1215. end;
  1216. procedure readarraydefoptions;
  1217. type
  1218. tarraydefoption=(ado_none,
  1219. ado_IsConvertedPointer,
  1220. ado_IsDynamicArray,
  1221. ado_IsVariant,
  1222. ado_IsConstructor,
  1223. ado_IsArrayOfConst,
  1224. ado_IsConstString
  1225. );
  1226. tarraydefoptions=set of tarraydefoption;
  1227. tsymopt=record
  1228. mask : tarraydefoption;
  1229. str : string[30];
  1230. end;
  1231. const
  1232. symopts=6;
  1233. symopt : array[1..symopts] of tsymopt=(
  1234. (mask:ado_IsConvertedPointer;str:'ConvertedPointer'),
  1235. (mask:ado_IsDynamicArray; str:'IsDynamicArray'),
  1236. (mask:ado_IsVariant; str:'IsVariant'),
  1237. (mask:ado_IsConstructor; str:'IsConstructor'),
  1238. (mask:ado_IsArrayOfConst; str:'ArrayOfConst'),
  1239. (mask:ado_IsConstString; str:'ConstString')
  1240. );
  1241. var
  1242. symoptions : tarraydefoptions;
  1243. i : longint;
  1244. first : boolean;
  1245. begin
  1246. ppufile.getsmallset(symoptions);
  1247. if symoptions<>[] then
  1248. begin
  1249. first:=true;
  1250. for i:=1to symopts do
  1251. if (symopt[i].mask in symoptions) then
  1252. begin
  1253. if first then
  1254. first:=false
  1255. else
  1256. write(', ');
  1257. write(symopt[i].str);
  1258. end;
  1259. end;
  1260. writeln;
  1261. end;
  1262. procedure readnodetree;
  1263. var
  1264. l : longint;
  1265. p : pointer;
  1266. begin
  1267. with ppufile do
  1268. begin
  1269. if space<>'' then
  1270. Writeln(space,'------ nodetree ------');
  1271. if readentry=ibnodetree then
  1272. begin
  1273. l:=entrysize;
  1274. Writeln(space,'Tree size : ',l);
  1275. { Read data to prevent error that entry is not completly read }
  1276. getmem(p,l);
  1277. getdata(p^,l);
  1278. freemem(p);
  1279. end
  1280. else
  1281. begin
  1282. Writeln('!! ibnodetree not found');
  1283. end;
  1284. end;
  1285. end;
  1286. {****************************************************************************
  1287. Read Symbols Part
  1288. ****************************************************************************}
  1289. procedure readsymbols(const s:string);
  1290. type
  1291. pguid = ^tguid;
  1292. tguid = packed record
  1293. D1: LongWord;
  1294. D2: Word;
  1295. D3: Word;
  1296. D4: array[0..7] of Byte;
  1297. end;
  1298. absolutetyp = (tovar,toasm,toaddr);
  1299. tconsttyp = (constnone,
  1300. constord,conststring,constreal,
  1301. constset,constpointer,constnil,
  1302. constresourcestring,constwstring,constguid
  1303. );
  1304. var
  1305. b : byte;
  1306. pc : pchar;
  1307. i,j,len : longint;
  1308. guid : tguid;
  1309. tempbuf : array[0..127] of char;
  1310. varoptions : tvaroptions;
  1311. begin
  1312. with ppufile do
  1313. begin
  1314. if space<>'' then
  1315. Writeln(space,'------ ',s,' ------');
  1316. if readentry=ibstartsyms then
  1317. begin
  1318. Writeln(space,'Symtable datasize : ',getlongint);
  1319. Writeln(space,'Symtable alignment: ',getlongint);
  1320. end
  1321. else
  1322. Writeln('!! ibstartsym not found');
  1323. repeat
  1324. b:=readentry;
  1325. case b of
  1326. ibunitsym :
  1327. readcommonsym('Unit symbol ');
  1328. iblabelsym :
  1329. readcommonsym('Label symbol ');
  1330. ibtypesym :
  1331. begin
  1332. readcommonsym('Type symbol ');
  1333. write(space,' Result Type : ');
  1334. readderef;
  1335. end;
  1336. ibprocsym :
  1337. begin
  1338. readcommonsym('Procedure symbol ');
  1339. len:=ppufile.getword;
  1340. for i:=1 to len do
  1341. begin
  1342. write(space,' Definition : ');
  1343. readderef;
  1344. end;
  1345. end;
  1346. ibconstsym :
  1347. begin
  1348. readcommonsym('Constant symbol ');
  1349. b:=getbyte;
  1350. case tconsttyp(b) of
  1351. constord :
  1352. begin
  1353. write (space,' OrdinalType : ');
  1354. readderef;
  1355. writeln(space,' Value : ',getint64);
  1356. end;
  1357. constpointer :
  1358. begin
  1359. write (space,' PointerType : ');
  1360. readderef;
  1361. writeln(space,' Value : ',getlongint)
  1362. end;
  1363. conststring,
  1364. constresourcestring :
  1365. begin
  1366. len:=getlongint;
  1367. getmem(pc,len+1);
  1368. getdata(pc^,len);
  1369. (pc+len)^:= #0;
  1370. writeln(space,' Length : ',len);
  1371. writeln(space,' Value : "',pc,'"');
  1372. freemem(pc,len+1);
  1373. if tconsttyp(b)=constresourcestring then
  1374. writeln(space,' Index : ',getlongint);
  1375. end;
  1376. constreal :
  1377. writeln(space,' Value : ',getreal);
  1378. constset :
  1379. begin
  1380. write (space,' Set Type : ');
  1381. readderef;
  1382. for i:=1to 4 do
  1383. begin
  1384. write (space,' Value : ');
  1385. for j:=1to 8 do
  1386. begin
  1387. if j>1 then
  1388. write(',');
  1389. write(hexb(getbyte));
  1390. end;
  1391. writeln;
  1392. end;
  1393. end;
  1394. constwstring:
  1395. begin
  1396. end;
  1397. constguid:
  1398. begin
  1399. getdata(guid,sizeof(guid));
  1400. write (space,' IID String: {',hexstr(guid.d1,8),'-',hexstr(guid.d2,4),'-',hexstr(guid.d3,4),'-');
  1401. for i:=0 to 7 do
  1402. begin
  1403. write(hexstr(guid.d4[i],2));
  1404. if i=1 then write('-');
  1405. end;
  1406. writeln('}');
  1407. end
  1408. else
  1409. Writeln ('!! Invalid unit format : Invalid const type encountered: ',b);
  1410. end;
  1411. end;
  1412. ibabsolutevarsym :
  1413. begin
  1414. readabstractvarsym('Absolute variable symbol ',varoptions);
  1415. Write (space,' Relocated to ');
  1416. b:=getbyte;
  1417. case absolutetyp(b) of
  1418. tovar :
  1419. readpropaccesslist(space+' Sym : ');
  1420. toasm :
  1421. Writeln('Assembler name : ',getstring);
  1422. toaddr :
  1423. begin
  1424. Write('Address : ',getlongint);
  1425. if tsystemcpu(ppufile.header.cpu)=cpu_i386 then
  1426. WriteLn(' (Far: ',getbyte<>0,')');
  1427. end;
  1428. else
  1429. Writeln ('!! Invalid unit format : Invalid absolute type encountered: ',b);
  1430. end;
  1431. end;
  1432. ibfieldvarsym :
  1433. begin
  1434. readabstractvarsym('Field Variable symbol ',varoptions);
  1435. writeln(space,' Address : ',getaint);
  1436. end;
  1437. ibglobalvarsym :
  1438. begin
  1439. readabstractvarsym('Global Variable symbol ',varoptions);
  1440. write (space,' DefaultConst : ');
  1441. readderef;
  1442. if (vo_has_mangledname in varoptions) then
  1443. writeln(space,' Mangledname : ',getstring);
  1444. end;
  1445. iblocalvarsym :
  1446. begin
  1447. readabstractvarsym('Local Variable symbol ',varoptions);
  1448. write (space,' DefaultConst : ');
  1449. readderef;
  1450. end;
  1451. ibparavarsym :
  1452. begin
  1453. readabstractvarsym('Parameter Variable symbol ',varoptions);
  1454. write (space,' DefaultConst : ');
  1455. readderef;
  1456. writeln(space,' ParaNr : ',getword);
  1457. writeln(space,' VarState : ',getbyte);
  1458. if (vo_has_explicit_paraloc in varoptions) then
  1459. begin
  1460. i:=getbyte;
  1461. getdata(tempbuf,i);
  1462. end;
  1463. end;
  1464. ibenumsym :
  1465. begin
  1466. readcommonsym('Enumeration symbol ');
  1467. write (space,' Definition : ');
  1468. readderef;
  1469. writeln(space,' Value : ',getlongint);
  1470. end;
  1471. ibsyssym :
  1472. begin
  1473. readcommonsym('Internal system symbol ');
  1474. writeln(space,' Internal Nr : ',getlongint);
  1475. end;
  1476. ibmacrosym :
  1477. begin
  1478. readcommonsym('Macro symbol ');
  1479. writeln(space,' Name: ',getstring);
  1480. writeln(space,' Defined: ',getbyte);
  1481. writeln(space,' Compiler var: ',getbyte);
  1482. len:=getlongint;
  1483. writeln(space,' Value length: ',len);
  1484. if len > 0 then
  1485. begin
  1486. getmem(pc,len+1);
  1487. getdata(pc^,len);
  1488. (pc+len)^:= #0;
  1489. writeln(space,' Value: "',pc,'"');
  1490. freemem(pc,len+1);
  1491. end;
  1492. end;
  1493. ibtypedconstsym :
  1494. begin
  1495. readcommonsym('Typed constant ');
  1496. write (space,' Constant Type : ');
  1497. readderef;
  1498. writeln(space,' ReallyConst : ',(getbyte<>0));
  1499. end;
  1500. ibpropertysym :
  1501. begin
  1502. readcommonsym('Property ');
  1503. i:=getlongint;
  1504. writeln(space,' PropOptions : ',i);
  1505. write (space,' OverrideProp : ');
  1506. readderef;
  1507. write (space,' Prop Type : ');
  1508. readderef;
  1509. writeln(space,' Index : ',getlongint);
  1510. writeln(space,' Default : ',getlongint);
  1511. write (space,' Index Type : ');
  1512. readderef;
  1513. write (space,' Readaccess : ');
  1514. readpropaccesslist(space+' Sym: ');
  1515. write (space,' Writeaccess : ');
  1516. readpropaccesslist(space+' Sym: ');
  1517. write (space,' Storedaccess : ');
  1518. readpropaccesslist(space+' Sym: ');
  1519. end;
  1520. iberror :
  1521. begin
  1522. Writeln('!! Error in PPU');
  1523. exit;
  1524. end;
  1525. ibendsyms :
  1526. break;
  1527. else
  1528. WriteLn('!! Skipping unsupported PPU Entry in Symbols: ',b);
  1529. end;
  1530. if not EndOfEntry then
  1531. Writeln('!! Entry has more information stored');
  1532. until false;
  1533. end;
  1534. end;
  1535. {****************************************************************************
  1536. Read defintions Part
  1537. ****************************************************************************}
  1538. procedure readdefinitions(const s:string);
  1539. type
  1540. tsettype = (normset,smallset,varset);
  1541. tordtype = (
  1542. uvoid,
  1543. u8bit,u16bit,u32bit,u64bit,
  1544. s8bit,s16bit,s32bit,s64bit,
  1545. bool8bit,bool16bit,bool32bit,
  1546. uchar,uwidechar,scurrency
  1547. );
  1548. tobjecttyp = (odt_none,
  1549. odt_class,
  1550. odt_object,
  1551. odt_interfacecom,
  1552. odt_interfacecorba,
  1553. odt_cppclass,
  1554. odt_dispinterface
  1555. );
  1556. tvarianttype = (
  1557. vt_normalvariant,vt_olevariant
  1558. );
  1559. var
  1560. b : byte;
  1561. l,j : longint;
  1562. calloption : tproccalloption;
  1563. procoptions : tprocoptions;
  1564. procinfooptions : tprocinfoflag;
  1565. begin
  1566. with ppufile do
  1567. begin
  1568. if space<>'' then
  1569. Writeln(space,'------ ',s,' ------');
  1570. if readentry<>ibstartdefs then
  1571. Writeln('!! ibstartdefs not found');
  1572. repeat
  1573. b:=readentry;
  1574. case b of
  1575. ibpointerdef :
  1576. begin
  1577. readcommondef('Pointer definition');
  1578. write (space,' Pointed Type : ');
  1579. readderef;
  1580. writeln(space,' Is Far : ',(getbyte<>0));
  1581. end;
  1582. iborddef :
  1583. begin
  1584. readcommondef('Ordinal definition');
  1585. write (space,' Base type : ');
  1586. b:=getbyte;
  1587. case tordtype(b) of
  1588. uvoid : writeln('uvoid');
  1589. u8bit : writeln('u8bit');
  1590. u16bit : writeln('u16bit');
  1591. u32bit : writeln('s32bit');
  1592. u64bit : writeln('u64bit');
  1593. s8bit : writeln('s8bit');
  1594. s16bit : writeln('s16bit');
  1595. s32bit : writeln('s32bit');
  1596. s64bit : writeln('s64bit');
  1597. bool8bit : writeln('bool8bit');
  1598. bool16bit : writeln('bool16bit');
  1599. bool32bit : writeln('bool32bit');
  1600. uchar : writeln('uchar');
  1601. uwidechar : writeln('uwidechar');
  1602. scurrency : writeln('ucurrency');
  1603. else writeln('!! Warning: Invalid base type ',b);
  1604. end;
  1605. writeln(space,' Range : ',getint64,' to ',getint64);
  1606. end;
  1607. ibfloatdef :
  1608. begin
  1609. readcommondef('Float definition');
  1610. writeln(space,' Float type : ',getbyte);
  1611. end;
  1612. ibarraydef :
  1613. begin
  1614. readcommondef('Array definition');
  1615. write (space,' Element type : ');
  1616. readderef;
  1617. write (space,' Range Type : ');
  1618. readderef;
  1619. writeln(space,' Range : ',getaint,' to ',getaint);
  1620. write (space,' Options : ');
  1621. readarraydefoptions;
  1622. end;
  1623. ibprocdef :
  1624. begin
  1625. readcommondef('Procedure definition');
  1626. read_abstract_proc_def(calloption,procoptions);
  1627. if (po_has_mangledname in procoptions) then
  1628. writeln(space,' Mangled name : ',getstring);
  1629. writeln(space,' Number : ',getword);
  1630. writeln(space,' Level : ',getbyte);
  1631. write (space,' Class : ');
  1632. readderef;
  1633. write (space,' Procsym : ');
  1634. readderef;
  1635. write (space,' File Pos : ');
  1636. readposinfo;
  1637. write (space,' SymOptions : ');
  1638. readsymoptions;
  1639. if tsystemcpu(ppufile.header.cpu)=cpu_powerpc then
  1640. begin
  1641. { library symbol for AmigaOS/MorphOS }
  1642. write (space,' Library symbol : ');
  1643. readderef;
  1644. end;
  1645. if (po_has_importdll in procoptions) then
  1646. writeln(space,' Import DLL : ',getstring);
  1647. if (po_has_importname in procoptions) then
  1648. writeln(space,' Import Name : ',getstring);
  1649. writeln(space,' Import Nr : ',getword);
  1650. if (po_msgint in procoptions) then
  1651. writeln(space,' MsgInt : ',getlongint);
  1652. if (po_msgstr in procoptions) then
  1653. writeln(space,' MsgStr : ',getstring);
  1654. if (po_has_inlininginfo in procoptions) then
  1655. begin
  1656. write (space,' FuncretSym : ');
  1657. readderef;
  1658. ppufile.getsmallset(procinfooptions);
  1659. writeln(space,' ProcInfoOptions : ',dword(procinfooptions));
  1660. end;
  1661. if not EndOfEntry then
  1662. Writeln('!! Entry has more information stored');
  1663. space:=' '+space;
  1664. { parast }
  1665. readdefinitions('parast');
  1666. readsymbols('parast');
  1667. { localst }
  1668. if (po_has_inlininginfo in procoptions) then
  1669. begin
  1670. readdefinitions('localst');
  1671. readsymbols('localst');
  1672. end;
  1673. if (po_has_inlininginfo in procoptions) then
  1674. readnodetree;
  1675. delete(space,1,4);
  1676. end;
  1677. ibprocvardef :
  1678. begin
  1679. readcommondef('Procedural type (ProcVar) definition');
  1680. read_abstract_proc_def(calloption,procoptions);
  1681. if not EndOfEntry then
  1682. Writeln('!! Entry has more information stored');
  1683. space:=' '+space;
  1684. { parast }
  1685. readdefinitions('parast');
  1686. readsymbols('parast');
  1687. delete(space,1,4);
  1688. end;
  1689. ibshortstringdef :
  1690. begin
  1691. readcommondef('ShortString definition');
  1692. writeln(space,' Length : ',getbyte);
  1693. end;
  1694. ibwidestringdef :
  1695. begin
  1696. readcommondef('WideString definition');
  1697. writeln(space,' Length : ',getlongint);
  1698. end;
  1699. ibansistringdef :
  1700. begin
  1701. readcommondef('AnsiString definition');
  1702. writeln(space,' Length : ',getlongint);
  1703. end;
  1704. iblongstringdef :
  1705. begin
  1706. readcommondef('Longstring definition');
  1707. writeln(space,' Length : ',getlongint);
  1708. end;
  1709. ibrecorddef :
  1710. begin
  1711. readcommondef('Record definition');
  1712. writeln(space,' DataSize : ',getaint);
  1713. writeln(space,' FieldAlign : ',getbyte);
  1714. writeln(space,' RecordAlign : ',getbyte);
  1715. writeln(space,' PadAlign : ',getbyte);
  1716. writeln(space,'UseFieldAlignment : ',getbyte);
  1717. if not EndOfEntry then
  1718. Writeln('!! Entry has more information stored');
  1719. {read the record definitions and symbols}
  1720. space:=' '+space;
  1721. readdefinitions('fields');
  1722. readsymbols('fields');
  1723. Delete(space,1,4);
  1724. end;
  1725. ibobjectdef :
  1726. begin
  1727. readcommondef('Object/Class definition');
  1728. b:=getbyte;
  1729. write (space,' Type : ');
  1730. case tobjecttyp(b) of
  1731. odt_class : writeln('class');
  1732. odt_object : writeln('object');
  1733. odt_interfacecom : writeln('interfacecom');
  1734. odt_interfacecorba : writeln('interfacecorba');
  1735. odt_cppclass : writeln('cppclass');
  1736. else writeln('!! Warning: Invalid object type ',b);
  1737. end;
  1738. writeln(space,' Name of Class : ',getstring);
  1739. writeln(space,' DataSize : ',getaint);
  1740. writeln(space,' FieldAlign : ',getbyte);
  1741. writeln(space,' RecordAlign : ',getbyte);
  1742. writeln(space,' Vmt offset : ',getlongint);
  1743. write (space, ' Ancestor Class : ');
  1744. readderef;
  1745. write (space,' Options : ');
  1746. readobjectdefoptions;
  1747. if tobjecttyp(b) in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  1748. begin
  1749. { IIDGUID }
  1750. for j:=1to 16 do
  1751. getbyte;
  1752. writeln(space,' IID String : ',getstring);
  1753. writeln(space,' Last VTable idx : ',getlongint);
  1754. end;
  1755. if tobjecttyp(b) in [odt_class,odt_interfacecorba] then
  1756. begin
  1757. l:=getlongint;
  1758. writeln(space,' Impl Intf Count : ',l);
  1759. for j:=1 to l do
  1760. begin
  1761. write (space,' - Definition : ');
  1762. readderef;
  1763. writeln(space,' IOffset : ',getlongint);
  1764. end;
  1765. end;
  1766. if not EndOfEntry then
  1767. Writeln('!! Entry has more information stored');
  1768. {read the record definitions and symbols}
  1769. space:=' '+space;
  1770. readdefinitions('fields');
  1771. readsymbols('fields');
  1772. Delete(space,1,4);
  1773. end;
  1774. ibfiledef :
  1775. begin
  1776. ReadCommonDef('File definition');
  1777. write (space,' Type : ');
  1778. case getbyte of
  1779. 0 : writeln('Text');
  1780. 1 : begin
  1781. writeln('Typed');
  1782. write (space,' File of Type : ');
  1783. readderef;
  1784. end;
  1785. 2 : writeln('Untyped');
  1786. end;
  1787. end;
  1788. ibformaldef :
  1789. readcommondef('Generic definition (void-typ)');
  1790. ibundefineddef :
  1791. readcommondef('Undefined definition (generic parameter)');
  1792. ibenumdef :
  1793. begin
  1794. readcommondef('Enumeration type definition');
  1795. write(space,'Base enumeration type : ');
  1796. readderef;
  1797. writeln(space,' Smallest element : ',getaint);
  1798. writeln(space,' Largest element : ',getaint);
  1799. writeln(space,' Size : ',getaint);
  1800. end;
  1801. ibclassrefdef :
  1802. begin
  1803. readcommondef('Class reference definition');
  1804. write (space,' Pointed Type : ');
  1805. readderef;
  1806. end;
  1807. ibsetdef :
  1808. begin
  1809. readcommondef('Set definition');
  1810. write (space,' Element type : ');
  1811. readderef;
  1812. b:=getbyte;
  1813. case tsettype(b) of
  1814. smallset : writeln(space,' Set with 32 Elements');
  1815. normset : writeln(space,' Set with 256 Elements');
  1816. varset : writeln(space,' Set with ',getlongint,' Elements');
  1817. else writeln('!! Warning: Invalid set type ',b);
  1818. end;
  1819. end;
  1820. ibvariantdef :
  1821. begin
  1822. readcommondef('Variant definition');
  1823. write (space,' Varianttype : ');
  1824. b:=getbyte;
  1825. case tvarianttype(b) of
  1826. vt_normalvariant :
  1827. writeln('Normal');
  1828. vt_olevariant :
  1829. writeln('OLE');
  1830. else
  1831. writeln('!! Warning: Invalid varianttype ',b);
  1832. end;
  1833. end;
  1834. iberror :
  1835. begin
  1836. Writeln('!! Error in PPU');
  1837. exit;
  1838. end;
  1839. ibenddefs :
  1840. break;
  1841. else
  1842. WriteLn('!! Skipping unsupported PPU Entry in definitions: ',b);
  1843. end;
  1844. if not EndOfEntry then
  1845. Writeln('!! Entry has more information stored');
  1846. until false;
  1847. end;
  1848. end;
  1849. {****************************************************************************
  1850. Read General Part
  1851. ****************************************************************************}
  1852. procedure readinterface;
  1853. var
  1854. b : byte;
  1855. sourcenumber : longint;
  1856. begin
  1857. with ppufile do
  1858. begin
  1859. repeat
  1860. b:=readentry;
  1861. case b of
  1862. ibmodulename :
  1863. Writeln('Module Name: ',getstring);
  1864. ibsourcefiles :
  1865. begin
  1866. sourcenumber:=1;
  1867. while not EndOfEntry do
  1868. begin
  1869. Writeln('Source file ',sourcenumber,' : ',getstring,' ',filetimestring(getlongint));
  1870. inc(sourcenumber);
  1871. end;
  1872. end;
  1873. {$IFDEF MACRO_DIFF_HINT}
  1874. ibusedmacros :
  1875. begin
  1876. while not EndOfEntry do
  1877. begin
  1878. Write('Conditional ',getstring);
  1879. b:=getbyte;
  1880. if boolean(b)=true then
  1881. write(' defined at startup')
  1882. else
  1883. write(' not defined at startup');
  1884. b:=getbyte;
  1885. if boolean(b)=true then
  1886. writeln(' was used')
  1887. else
  1888. writeln;
  1889. end;
  1890. end;
  1891. {$ENDIF}
  1892. ibloadunit :
  1893. ReadLoadUnit;
  1894. iblinkunitofiles :
  1895. ReadLinkContainer('Link unit object file: ');
  1896. iblinkunitstaticlibs :
  1897. ReadLinkContainer('Link unit static lib: ');
  1898. iblinkunitsharedlibs :
  1899. ReadLinkContainer('Link unit shared lib: ');
  1900. iblinkotherofiles :
  1901. ReadLinkContainer('Link other object file: ');
  1902. iblinkotherstaticlibs :
  1903. ReadLinkContainer('Link other static lib: ');
  1904. iblinkothersharedlibs :
  1905. ReadLinkContainer('Link other shared lib: ');
  1906. ibImportSymbols :
  1907. ReadImportSymbols;
  1908. ibderefdata :
  1909. ReadDerefData;
  1910. ibderefmap :
  1911. ReadDerefMap;
  1912. iberror :
  1913. begin
  1914. Writeln('Error in PPU');
  1915. exit;
  1916. end;
  1917. ibendinterface :
  1918. break;
  1919. else
  1920. WriteLn('!! Skipping unsupported PPU Entry in General Part: ',b);
  1921. end;
  1922. until false;
  1923. end;
  1924. end;
  1925. {****************************************************************************
  1926. Read Implementation Part
  1927. ****************************************************************************}
  1928. procedure readimplementation;
  1929. var
  1930. b : byte;
  1931. begin
  1932. with ppufile do
  1933. begin
  1934. repeat
  1935. b:=readentry;
  1936. case b of
  1937. ibasmsymbols :
  1938. ReadAsmSymbols;
  1939. ibloadunit :
  1940. ReadLoadUnit;
  1941. iberror :
  1942. begin
  1943. Writeln('Error in PPU');
  1944. exit;
  1945. end;
  1946. ibendimplementation :
  1947. break;
  1948. else
  1949. WriteLn('!! Skipping unsupported PPU Entry in Implementation: ',b);
  1950. end;
  1951. until false;
  1952. end;
  1953. end;
  1954. procedure dofile (filename : string);
  1955. begin
  1956. { reset }
  1957. space:='';
  1958. { fix filename }
  1959. if pos('.',filename)=0 then
  1960. filename:=filename+'.ppu';
  1961. ppufile:=tppufile.create(filename);
  1962. if not ppufile.openfile then
  1963. begin
  1964. writeln ('IO-Error when opening : ',filename,', Skipping');
  1965. exit;
  1966. end;
  1967. { PPU File is open, check for PPU Id }
  1968. if not ppufile.CheckPPUID then
  1969. begin
  1970. writeln(Filename,' : Not a valid PPU file, Skipping');
  1971. exit;
  1972. end;
  1973. { Check PPU Version }
  1974. Writeln('Analyzing ',filename,' (v',ppufile.GetPPUVersion,')');
  1975. if ppufile.GetPPUVersion<16 then
  1976. begin
  1977. writeln(Filename,' : Old PPU Formats (<v16) are not supported, Skipping');
  1978. exit;
  1979. end;
  1980. { Write PPU Header Information }
  1981. if (verbose and v_header)<>0 then
  1982. begin
  1983. Writeln;
  1984. Writeln('Header');
  1985. Writeln('-------');
  1986. with ppufile.header do
  1987. begin
  1988. Writeln('Compiler version : ',ppufile.header.compiler shr 14,'.',
  1989. (ppufile.header.compiler shr 7) and $7f,'.',
  1990. ppufile.header.compiler and $7f);
  1991. WriteLn('Target processor : ',Cpu2Str(cpu));
  1992. WriteLn('Target operating system : ',Target2Str(target));
  1993. Writeln('Unit flags : ',PPUFlags2Str(flags));
  1994. Writeln('FileSize (w/o header) : ',size);
  1995. Writeln('Checksum : ',hexstr(checksum,8));
  1996. Writeln('Interface Checksum : ',hexstr(interface_checksum,8));
  1997. Writeln('Definitions stored : ',tostr(deflistsize));
  1998. Writeln('Symbols stored : ',tostr(symlistsize));
  1999. end;
  2000. end;
  2001. {read the general stuff}
  2002. if (verbose and v_interface)<>0 then
  2003. begin
  2004. Writeln;
  2005. Writeln('Interface section');
  2006. Writeln('------------------');
  2007. readinterface;
  2008. end
  2009. else
  2010. ppufile.skipuntilentry(ibendinterface);
  2011. {read the definitions}
  2012. if (verbose and v_defs)<>0 then
  2013. begin
  2014. Writeln;
  2015. Writeln('Interface definitions');
  2016. Writeln('----------------------');
  2017. readdefinitions('interface');
  2018. end
  2019. else
  2020. ppufile.skipuntilentry(ibenddefs);
  2021. {read the symbols}
  2022. if (verbose and v_syms)<>0 then
  2023. begin
  2024. Writeln;
  2025. Writeln('Interface Symbols');
  2026. Writeln('------------------');
  2027. readsymbols('interface');
  2028. end
  2029. else
  2030. ppufile.skipuntilentry(ibendsyms);
  2031. {read the macro symbols}
  2032. if (verbose and v_syms)<>0 then
  2033. begin
  2034. Writeln;
  2035. Writeln('Interface Macro Symbols');
  2036. Writeln('-----------------------');
  2037. end;
  2038. if ppufile.readentry<>ibexportedmacros then
  2039. begin
  2040. Writeln('!! Error in PPU');
  2041. exit;
  2042. end;
  2043. if boolean(ppufile.getbyte) then
  2044. begin
  2045. {skip the definition section for macros (since they are never used) }
  2046. ppufile.skipuntilentry(ibenddefs);
  2047. {read the macro symbols}
  2048. if (verbose and v_syms)<>0 then
  2049. readsymbols('interface macro')
  2050. else
  2051. ppufile.skipuntilentry(ibendsyms);
  2052. end
  2053. else
  2054. Writeln('(no exported macros)');
  2055. {read the implementation stuff}
  2056. if (verbose and v_implementation)<>0 then
  2057. begin
  2058. Writeln;
  2059. Writeln('Implementation section');
  2060. Writeln('-----------------------');
  2061. readimplementation;
  2062. end
  2063. else
  2064. ppufile.skipuntilentry(ibendimplementation);
  2065. {read the static symtable}
  2066. if (ppufile.header.flags and uf_local_symtable)<>0 then
  2067. begin
  2068. if (verbose and v_defs)<>0 then
  2069. begin
  2070. Writeln;
  2071. Writeln('Static definitions');
  2072. Writeln('----------------------');
  2073. readdefinitions('implementation');
  2074. end
  2075. else
  2076. ppufile.skipuntilentry(ibenddefs);
  2077. {read the symbols}
  2078. if (verbose and v_syms)<>0 then
  2079. begin
  2080. Writeln;
  2081. Writeln('Static Symbols');
  2082. Writeln('------------------');
  2083. readsymbols('implementation');
  2084. end
  2085. else
  2086. ppufile.skipuntilentry(ibendsyms);
  2087. end;
  2088. {shutdown ppufile}
  2089. ppufile.closefile;
  2090. ppufile.free;
  2091. Writeln;
  2092. end;
  2093. procedure help;
  2094. begin
  2095. writeln('usage: ppudump [options] <filename1> <filename2>...');
  2096. writeln;
  2097. writeln('[options] can be:');
  2098. writeln(' -V<verbose> Set verbosity to <verbose>');
  2099. writeln(' H - Show header info');
  2100. writeln(' I - Show interface');
  2101. writeln(' M - Show implementation');
  2102. writeln(' S - Show interface symbols');
  2103. writeln(' D - Show interface definitions');
  2104. // writeln(' B - Show browser info');
  2105. writeln(' A - Show all');
  2106. writeln(' -h, -? This helpscreen');
  2107. halt;
  2108. end;
  2109. var
  2110. startpara,
  2111. nrfile,i : longint;
  2112. para : string;
  2113. begin
  2114. writeln(Title+' '+Version);
  2115. writeln(Copyright);
  2116. writeln;
  2117. if paramcount<1 then
  2118. begin
  2119. writeln('usage: dumpppu [options] <filename1> <filename2>...');
  2120. halt(1);
  2121. end;
  2122. { turn verbose on by default }
  2123. verbose:=v_all;
  2124. { read options }
  2125. startpara:=1;
  2126. while copy(paramstr(startpara),1,1)='-' do
  2127. begin
  2128. para:=paramstr(startpara);
  2129. case upcase(para[2]) of
  2130. 'V' : begin
  2131. verbose:=0;
  2132. for i:=3 to length(para) do
  2133. case upcase(para[i]) of
  2134. 'H' : verbose:=verbose or v_header;
  2135. 'I' : verbose:=verbose or v_interface;
  2136. 'M' : verbose:=verbose or v_implementation;
  2137. 'D' : verbose:=verbose or v_defs;
  2138. 'S' : verbose:=verbose or v_syms;
  2139. 'A' : verbose:=verbose or v_all;
  2140. end;
  2141. end;
  2142. 'H' : help;
  2143. '?' : help;
  2144. end;
  2145. inc(startpara);
  2146. end;
  2147. { process files }
  2148. for nrfile:=startpara to paramcount do
  2149. dofile (paramstr(nrfile));
  2150. if has_errors then
  2151. Halt(1);
  2152. end.