ppudump.pp 70 KB

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