ppudump.pp 69 KB

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