ppudump.pp 65 KB

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