ppudump.pp 67 KB

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